162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * net/tipc/trace.c: TIPC tracepoints code 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2018, Ericsson AB 562306a36Sopenharmony_ci * All rights reserved. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 862306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 1162306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 1262306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 1362306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 1462306a36Sopenharmony_ci * documentation and/or other materials provided with the distribution. 1562306a36Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 1662306a36Sopenharmony_ci * contributors may be used to endorse or promote products derived from 1762306a36Sopenharmony_ci * this software without specific prior written permission. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 2062306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 2162306a36Sopenharmony_ci * Software Foundation. 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS" 2462306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE 2562306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2662306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2762306a36Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2862306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2962306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3062306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3162306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3262306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3362306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define CREATE_TRACE_POINTS 3762306a36Sopenharmony_ci#include "trace.h" 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * socket tuples for filtering in socket traces: 4162306a36Sopenharmony_ci * (portid, sock type, name type, name lower, name upper) 4262306a36Sopenharmony_ci */ 4362306a36Sopenharmony_ciunsigned long sysctl_tipc_sk_filter[5] __read_mostly = {0, }; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/** 4662306a36Sopenharmony_ci * tipc_skb_dump - dump TIPC skb data 4762306a36Sopenharmony_ci * @skb: skb to be dumped 4862306a36Sopenharmony_ci * @more: dump more? 4962306a36Sopenharmony_ci * - false: dump only tipc msg data 5062306a36Sopenharmony_ci * - true: dump kernel-related skb data and tipc cb[] array as well 5162306a36Sopenharmony_ci * @buf: returned buffer of dump data in format 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ciint tipc_skb_dump(struct sk_buff *skb, bool more, char *buf) 5462306a36Sopenharmony_ci{ 5562306a36Sopenharmony_ci int i = 0; 5662306a36Sopenharmony_ci size_t sz = (more) ? SKB_LMAX : SKB_LMIN; 5762306a36Sopenharmony_ci struct tipc_msg *hdr; 5862306a36Sopenharmony_ci struct tipc_skb_cb *skbcb; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci if (!skb) { 6162306a36Sopenharmony_ci i += scnprintf(buf, sz, "msg: (null)\n"); 6262306a36Sopenharmony_ci return i; 6362306a36Sopenharmony_ci } 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci hdr = buf_msg(skb); 6662306a36Sopenharmony_ci skbcb = TIPC_SKB_CB(skb); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci /* tipc msg data section */ 6962306a36Sopenharmony_ci i += scnprintf(buf, sz, "msg: %u", msg_user(hdr)); 7062306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_type(hdr)); 7162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_hdr_sz(hdr)); 7262306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_data_sz(hdr)); 7362306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %x", msg_orignode(hdr)); 7462306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %x", msg_destnode(hdr)); 7562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_seqno(hdr)); 7662306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_ack(hdr)); 7762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bcast_ack(hdr)); 7862306a36Sopenharmony_ci switch (msg_user(hdr)) { 7962306a36Sopenharmony_ci case LINK_PROTOCOL: 8062306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %c", msg_net_plane(hdr)); 8162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_probe(hdr)); 8262306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_peer_stopping(hdr)); 8362306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_session(hdr)); 8462306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_next_sent(hdr)); 8562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_seq_gap(hdr)); 8662306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bc_snd_nxt(hdr)); 8762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bc_gap(hdr)); 8862306a36Sopenharmony_ci break; 8962306a36Sopenharmony_ci case TIPC_LOW_IMPORTANCE: 9062306a36Sopenharmony_ci case TIPC_MEDIUM_IMPORTANCE: 9162306a36Sopenharmony_ci case TIPC_HIGH_IMPORTANCE: 9262306a36Sopenharmony_ci case TIPC_CRITICAL_IMPORTANCE: 9362306a36Sopenharmony_ci case CONN_MANAGER: 9462306a36Sopenharmony_ci case SOCK_WAKEUP: 9562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " | %u", msg_origport(hdr)); 9662306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_destport(hdr)); 9762306a36Sopenharmony_ci switch (msg_type(hdr)) { 9862306a36Sopenharmony_ci case TIPC_NAMED_MSG: 9962306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 10062306a36Sopenharmony_ci msg_nametype(hdr)); 10162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 10262306a36Sopenharmony_ci msg_nameinst(hdr)); 10362306a36Sopenharmony_ci break; 10462306a36Sopenharmony_ci case TIPC_MCAST_MSG: 10562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 10662306a36Sopenharmony_ci msg_nametype(hdr)); 10762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 10862306a36Sopenharmony_ci msg_namelower(hdr)); 10962306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 11062306a36Sopenharmony_ci msg_nameupper(hdr)); 11162306a36Sopenharmony_ci break; 11262306a36Sopenharmony_ci default: 11362306a36Sopenharmony_ci break; 11462306a36Sopenharmony_ci } 11562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " | %u", 11662306a36Sopenharmony_ci msg_src_droppable(hdr)); 11762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 11862306a36Sopenharmony_ci msg_dest_droppable(hdr)); 11962306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_errcode(hdr)); 12062306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_reroute_cnt(hdr)); 12162306a36Sopenharmony_ci break; 12262306a36Sopenharmony_ci default: 12362306a36Sopenharmony_ci /* need more? */ 12462306a36Sopenharmony_ci break; 12562306a36Sopenharmony_ci } 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, "\n"); 12862306a36Sopenharmony_ci if (!more) 12962306a36Sopenharmony_ci return i; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci /* kernel-related skb data section */ 13262306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, "skb: %s", 13362306a36Sopenharmony_ci (skb->dev) ? skb->dev->name : "n/a"); 13462306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->len); 13562306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->data_len); 13662306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->hdr_len); 13762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->truesize); 13862306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb_cloned(skb)); 13962306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %p", skb->sk); 14062306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb_shinfo(skb)->nr_frags); 14162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %llx", 14262306a36Sopenharmony_ci ktime_to_ms(skb_get_ktime(skb))); 14362306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %llx\n", 14462306a36Sopenharmony_ci ktime_to_ms(skb_hwtstamps(skb)->hwtstamp)); 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci /* tipc skb cb[] data section */ 14762306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, "cb[]: %u", skbcb->bytes_read); 14862306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->orig_member); 14962306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 15062306a36Sopenharmony_ci jiffies_to_msecs(skbcb->nxt_retr)); 15162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->validated); 15262306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->chain_imp); 15362306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u\n", skbcb->ackers); 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci return i; 15662306a36Sopenharmony_ci} 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci/** 15962306a36Sopenharmony_ci * tipc_list_dump - dump TIPC skb list/queue 16062306a36Sopenharmony_ci * @list: list of skbs to be dumped 16162306a36Sopenharmony_ci * @more: dump more? 16262306a36Sopenharmony_ci * - false: dump only the head & tail skbs 16362306a36Sopenharmony_ci * - true: dump the first & last 5 skbs 16462306a36Sopenharmony_ci * @buf: returned buffer of dump data in format 16562306a36Sopenharmony_ci */ 16662306a36Sopenharmony_ciint tipc_list_dump(struct sk_buff_head *list, bool more, char *buf) 16762306a36Sopenharmony_ci{ 16862306a36Sopenharmony_ci int i = 0; 16962306a36Sopenharmony_ci size_t sz = (more) ? LIST_LMAX : LIST_LMIN; 17062306a36Sopenharmony_ci u32 count, len; 17162306a36Sopenharmony_ci struct sk_buff *hskb, *tskb, *skb, *tmp; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci if (!list) { 17462306a36Sopenharmony_ci i += scnprintf(buf, sz, "(null)\n"); 17562306a36Sopenharmony_ci return i; 17662306a36Sopenharmony_ci } 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci len = skb_queue_len(list); 17962306a36Sopenharmony_ci i += scnprintf(buf, sz, "len = %d\n", len); 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci if (!len) 18262306a36Sopenharmony_ci return i; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci if (!more) { 18562306a36Sopenharmony_ci hskb = skb_peek(list); 18662306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " head "); 18762306a36Sopenharmony_ci i += tipc_skb_dump(hskb, false, buf + i); 18862306a36Sopenharmony_ci if (len > 1) { 18962306a36Sopenharmony_ci tskb = skb_peek_tail(list); 19062306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " tail "); 19162306a36Sopenharmony_ci i += tipc_skb_dump(tskb, false, buf + i); 19262306a36Sopenharmony_ci } 19362306a36Sopenharmony_ci } else { 19462306a36Sopenharmony_ci count = 0; 19562306a36Sopenharmony_ci skb_queue_walk_safe(list, skb, tmp) { 19662306a36Sopenharmony_ci count++; 19762306a36Sopenharmony_ci if (count == 6) 19862306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " .\n .\n"); 19962306a36Sopenharmony_ci if (count > 5 && count <= len - 5) 20062306a36Sopenharmony_ci continue; 20162306a36Sopenharmony_ci i += scnprintf(buf + i, sz - i, " #%d ", count); 20262306a36Sopenharmony_ci i += tipc_skb_dump(skb, false, buf + i); 20362306a36Sopenharmony_ci } 20462306a36Sopenharmony_ci } 20562306a36Sopenharmony_ci return i; 20662306a36Sopenharmony_ci} 207