18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * net/tipc/trace.c: TIPC tracepoints code 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2018, Ericsson AB 58c2ecf20Sopenharmony_ci * All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 118c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 128c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 148c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 158c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 168c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 178c2ecf20Sopenharmony_ci * this software without specific prior written permission. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 208c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 218c2ecf20Sopenharmony_ci * Software Foundation. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS" 248c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE 258c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 268c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 278c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 288c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 298c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 308c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 318c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 328c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 338c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define CREATE_TRACE_POINTS 378c2ecf20Sopenharmony_ci#include "trace.h" 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/** 408c2ecf20Sopenharmony_ci * socket tuples for filtering in socket traces: 418c2ecf20Sopenharmony_ci * (portid, sock type, name type, name lower, name upper) 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ciunsigned long sysctl_tipc_sk_filter[5] __read_mostly = {0, }; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/** 468c2ecf20Sopenharmony_ci * tipc_skb_dump - dump TIPC skb data 478c2ecf20Sopenharmony_ci * @skb: skb to be dumped 488c2ecf20Sopenharmony_ci * @more: dump more? 498c2ecf20Sopenharmony_ci * - false: dump only tipc msg data 508c2ecf20Sopenharmony_ci * - true: dump kernel-related skb data and tipc cb[] array as well 518c2ecf20Sopenharmony_ci * @buf: returned buffer of dump data in format 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ciint tipc_skb_dump(struct sk_buff *skb, bool more, char *buf) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci int i = 0; 568c2ecf20Sopenharmony_ci size_t sz = (more) ? SKB_LMAX : SKB_LMIN; 578c2ecf20Sopenharmony_ci struct tipc_msg *hdr; 588c2ecf20Sopenharmony_ci struct tipc_skb_cb *skbcb; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (!skb) { 618c2ecf20Sopenharmony_ci i += scnprintf(buf, sz, "msg: (null)\n"); 628c2ecf20Sopenharmony_ci return i; 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci hdr = buf_msg(skb); 668c2ecf20Sopenharmony_ci skbcb = TIPC_SKB_CB(skb); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci /* tipc msg data section */ 698c2ecf20Sopenharmony_ci i += scnprintf(buf, sz, "msg: %u", msg_user(hdr)); 708c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_type(hdr)); 718c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_hdr_sz(hdr)); 728c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_data_sz(hdr)); 738c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %x", msg_orignode(hdr)); 748c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %x", msg_destnode(hdr)); 758c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_seqno(hdr)); 768c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_ack(hdr)); 778c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bcast_ack(hdr)); 788c2ecf20Sopenharmony_ci switch (msg_user(hdr)) { 798c2ecf20Sopenharmony_ci case LINK_PROTOCOL: 808c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %c", msg_net_plane(hdr)); 818c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_probe(hdr)); 828c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_peer_stopping(hdr)); 838c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_session(hdr)); 848c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_next_sent(hdr)); 858c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_seq_gap(hdr)); 868c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bc_snd_nxt(hdr)); 878c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_bc_gap(hdr)); 888c2ecf20Sopenharmony_ci break; 898c2ecf20Sopenharmony_ci case TIPC_LOW_IMPORTANCE: 908c2ecf20Sopenharmony_ci case TIPC_MEDIUM_IMPORTANCE: 918c2ecf20Sopenharmony_ci case TIPC_HIGH_IMPORTANCE: 928c2ecf20Sopenharmony_ci case TIPC_CRITICAL_IMPORTANCE: 938c2ecf20Sopenharmony_ci case CONN_MANAGER: 948c2ecf20Sopenharmony_ci case SOCK_WAKEUP: 958c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " | %u", msg_origport(hdr)); 968c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_destport(hdr)); 978c2ecf20Sopenharmony_ci switch (msg_type(hdr)) { 988c2ecf20Sopenharmony_ci case TIPC_NAMED_MSG: 998c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1008c2ecf20Sopenharmony_ci msg_nametype(hdr)); 1018c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1028c2ecf20Sopenharmony_ci msg_nameinst(hdr)); 1038c2ecf20Sopenharmony_ci break; 1048c2ecf20Sopenharmony_ci case TIPC_MCAST_MSG: 1058c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1068c2ecf20Sopenharmony_ci msg_nametype(hdr)); 1078c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1088c2ecf20Sopenharmony_ci msg_namelower(hdr)); 1098c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1108c2ecf20Sopenharmony_ci msg_nameupper(hdr)); 1118c2ecf20Sopenharmony_ci break; 1128c2ecf20Sopenharmony_ci default: 1138c2ecf20Sopenharmony_ci break; 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " | %u", 1168c2ecf20Sopenharmony_ci msg_src_droppable(hdr)); 1178c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1188c2ecf20Sopenharmony_ci msg_dest_droppable(hdr)); 1198c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_errcode(hdr)); 1208c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", msg_reroute_cnt(hdr)); 1218c2ecf20Sopenharmony_ci break; 1228c2ecf20Sopenharmony_ci default: 1238c2ecf20Sopenharmony_ci /* need more? */ 1248c2ecf20Sopenharmony_ci break; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, "\n"); 1288c2ecf20Sopenharmony_ci if (!more) 1298c2ecf20Sopenharmony_ci return i; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci /* kernel-related skb data section */ 1328c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, "skb: %s", 1338c2ecf20Sopenharmony_ci (skb->dev) ? skb->dev->name : "n/a"); 1348c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->len); 1358c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->data_len); 1368c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->hdr_len); 1378c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb->truesize); 1388c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb_cloned(skb)); 1398c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %p", skb->sk); 1408c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skb_shinfo(skb)->nr_frags); 1418c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %llx", 1428c2ecf20Sopenharmony_ci ktime_to_ms(skb_get_ktime(skb))); 1438c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %llx\n", 1448c2ecf20Sopenharmony_ci ktime_to_ms(skb_hwtstamps(skb)->hwtstamp)); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci /* tipc skb cb[] data section */ 1478c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, "cb[]: %u", skbcb->bytes_read); 1488c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->orig_member); 1498c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", 1508c2ecf20Sopenharmony_ci jiffies_to_msecs(skbcb->nxt_retr)); 1518c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->validated); 1528c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u", skbcb->chain_imp); 1538c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " %u\n", skbcb->ackers); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci return i; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/** 1598c2ecf20Sopenharmony_ci * tipc_list_dump - dump TIPC skb list/queue 1608c2ecf20Sopenharmony_ci * @list: list of skbs to be dumped 1618c2ecf20Sopenharmony_ci * @more: dump more? 1628c2ecf20Sopenharmony_ci * - false: dump only the head & tail skbs 1638c2ecf20Sopenharmony_ci * - true: dump the first & last 5 skbs 1648c2ecf20Sopenharmony_ci * @buf: returned buffer of dump data in format 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ciint tipc_list_dump(struct sk_buff_head *list, bool more, char *buf) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci int i = 0; 1698c2ecf20Sopenharmony_ci size_t sz = (more) ? LIST_LMAX : LIST_LMIN; 1708c2ecf20Sopenharmony_ci u32 count, len; 1718c2ecf20Sopenharmony_ci struct sk_buff *hskb, *tskb, *skb, *tmp; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci if (!list) { 1748c2ecf20Sopenharmony_ci i += scnprintf(buf, sz, "(null)\n"); 1758c2ecf20Sopenharmony_ci return i; 1768c2ecf20Sopenharmony_ci } 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci len = skb_queue_len(list); 1798c2ecf20Sopenharmony_ci i += scnprintf(buf, sz, "len = %d\n", len); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci if (!len) 1828c2ecf20Sopenharmony_ci return i; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci if (!more) { 1858c2ecf20Sopenharmony_ci hskb = skb_peek(list); 1868c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " head "); 1878c2ecf20Sopenharmony_ci i += tipc_skb_dump(hskb, false, buf + i); 1888c2ecf20Sopenharmony_ci if (len > 1) { 1898c2ecf20Sopenharmony_ci tskb = skb_peek_tail(list); 1908c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " tail "); 1918c2ecf20Sopenharmony_ci i += tipc_skb_dump(tskb, false, buf + i); 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci } else { 1948c2ecf20Sopenharmony_ci count = 0; 1958c2ecf20Sopenharmony_ci skb_queue_walk_safe(list, skb, tmp) { 1968c2ecf20Sopenharmony_ci count++; 1978c2ecf20Sopenharmony_ci if (count == 6) 1988c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " .\n .\n"); 1998c2ecf20Sopenharmony_ci if (count > 5 && count <= len - 5) 2008c2ecf20Sopenharmony_ci continue; 2018c2ecf20Sopenharmony_ci i += scnprintf(buf + i, sz - i, " #%d ", count); 2028c2ecf20Sopenharmony_ci i += tipc_skb_dump(skb, false, buf + i); 2038c2ecf20Sopenharmony_ci } 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci return i; 2068c2ecf20Sopenharmony_ci} 207