Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3 : : * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4 : : * Copyright (c) 2017 The strace developers.
5 : : * All rights reserved.
6 : : *
7 : : * Redistribution and use in source and binary forms, with or without
8 : : * modification, are permitted provided that the following conditions
9 : : * are met:
10 : : * 1. Redistributions of source code must retain the above copyright
11 : : * notice, this list of conditions and the following disclaimer.
12 : : * 2. Redistributions in binary form must reproduce the above copyright
13 : : * notice, this list of conditions and the following disclaimer in the
14 : : * documentation and/or other materials provided with the distribution.
15 : : * 3. The name of the author may not be used to endorse or promote products
16 : : * derived from this software without specific prior written permission.
17 : : *
18 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 : : * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 : : */
29 : :
30 : : #include "defs.h"
31 : : #include "netlink.h"
32 : : #include "netlink_sock_diag.h"
33 : : #include "nlattr.h"
34 : : #include "print_fields.h"
35 : :
36 : : #include <linux/filter.h>
37 : : #include <linux/sock_diag.h>
38 : : #include <linux/packet_diag.h>
39 : :
40 : : #include "xlat/packet_diag_attrs.h"
41 : : #include "xlat/packet_diag_info_flags.h"
42 : : #include "xlat/packet_diag_show.h"
43 : :
44 : 6 : DECL_NETLINK_DIAG_DECODER(decode_packet_diag_req)
45 : : {
46 : 6 : struct packet_diag_req req = { .sdiag_family = family };
47 : 6 : const size_t offset = sizeof(req.sdiag_family);
48 : :
49 : 6 : PRINT_FIELD_XVAL("{", req, sdiag_family, addrfams, "AF_???");
50 : 6 : tprints(", ");
51 [ + + ]: 6 : if (len >= sizeof(req)) {
52 [ + + ]: 4 : if (!umoven_or_printaddr(tcp, addr + offset,
53 : : sizeof(req) - offset,
54 : : (void *) &req + offset)) {
55 : 2 : PRINT_FIELD_XVAL("", req, sdiag_protocol,
56 : : ethernet_protocols, "ETH_P_???");
57 : 2 : PRINT_FIELD_U(", ", req, pdiag_ino);
58 : 2 : PRINT_FIELD_FLAGS(", ", req, pdiag_show,
59 : : packet_diag_show, "PACKET_SHOW_???");
60 : 2 : PRINT_FIELD_COOKIE(", ", req, pdiag_cookie);
61 : : }
62 : : } else
63 : 2 : tprints("...");
64 : 6 : tprints("}");
65 : 6 : }
66 : :
67 : : static bool
68 : 6 : decode_packet_diag_info(struct tcb *const tcp,
69 : : const kernel_ulong_t addr,
70 : : const unsigned int len,
71 : : const void *const opaque_data)
72 : : {
73 : : struct packet_diag_info pinfo;
74 : :
75 [ + + ]: 6 : if (len < sizeof(pinfo))
76 : : return false;
77 [ + + ]: 4 : if (umove_or_printaddr(tcp, addr, &pinfo))
78 : : return true;
79 : :
80 : 2 : PRINT_FIELD_U("{", pinfo, pdi_index);
81 : 2 : PRINT_FIELD_U(", ", pinfo, pdi_version);
82 : 2 : PRINT_FIELD_U(", ", pinfo, pdi_reserve);
83 : 2 : PRINT_FIELD_U(", ", pinfo, pdi_copy_thresh);
84 : 2 : PRINT_FIELD_U(", ", pinfo, pdi_tstamp);
85 : 2 : PRINT_FIELD_FLAGS(", ", pinfo, pdi_flags,
86 : : packet_diag_info_flags, "PDI_???");
87 : 2 : tprints("}");
88 : :
89 : 2 : return true;
90 : : }
91 : :
92 : : static bool
93 : 8 : print_packet_diag_mclist(struct tcb *const tcp, void *const elem_buf,
94 : : const size_t elem_size, void *const opaque_data)
95 : : {
96 : 8 : struct packet_diag_mclist *dml = elem_buf;
97 : 8 : uint16_t alen = dml->pdmc_alen > sizeof(dml->pdmc_addr) ?
98 : 8 : sizeof(dml->pdmc_addr) : dml->pdmc_alen;
99 : :
100 : 8 : PRINT_FIELD_IFINDEX("{", *dml, pdmc_index);
101 : 8 : PRINT_FIELD_U(", ", *dml, pdmc_count);
102 : 8 : PRINT_FIELD_U(", ", *dml, pdmc_type);
103 : 8 : PRINT_FIELD_U(", ", *dml, pdmc_alen);
104 : 8 : PRINT_FIELD_STRING(", ", *dml, pdmc_addr, alen, QUOTE_FORCE_HEX);
105 : 8 : tprints("}");
106 : :
107 : 8 : return true;
108 : : }
109 : :
110 : : static bool
111 : 8 : decode_packet_diag_mclist(struct tcb *const tcp,
112 : : const kernel_ulong_t addr,
113 : : const unsigned int len,
114 : : const void *const opaque_data)
115 : : {
116 : : struct packet_diag_mclist dml;
117 : 8 : const size_t nmemb = len / sizeof(dml);
118 : :
119 [ + + ]: 8 : if (!nmemb)
120 : : return false;
121 : :
122 : 6 : print_array(tcp, addr, nmemb, &dml, sizeof(dml),
123 : : umoven_or_printaddr, print_packet_diag_mclist, 0);
124 : :
125 : 6 : return true;
126 : : }
127 : :
128 : : static bool
129 : 6 : decode_packet_diag_ring(struct tcb *const tcp,
130 : : const kernel_ulong_t addr,
131 : : const unsigned int len,
132 : : const void *const opaque_data)
133 : : {
134 : : struct packet_diag_ring pdr;
135 : :
136 [ + + ]: 6 : if (len < sizeof(pdr))
137 : : return false;
138 [ + + ]: 4 : if (umove_or_printaddr(tcp, addr, &pdr))
139 : : return true;
140 : :
141 : 2 : PRINT_FIELD_U("{", pdr, pdr_block_size);
142 : 2 : PRINT_FIELD_U(", ", pdr, pdr_block_nr);
143 : 2 : PRINT_FIELD_U(", ", pdr, pdr_frame_size);
144 : 2 : PRINT_FIELD_U(", ", pdr, pdr_frame_nr);
145 : 2 : PRINT_FIELD_U(", ", pdr, pdr_retire_tmo);
146 : 2 : PRINT_FIELD_U(", ", pdr, pdr_sizeof_priv);
147 : 2 : PRINT_FIELD_U(", ", pdr, pdr_features);
148 : 2 : tprints("}");
149 : :
150 : 2 : return true;
151 : : }
152 : :
153 : : static bool
154 : 8 : decode_packet_diag_filter(struct tcb *const tcp,
155 : : const kernel_ulong_t addr,
156 : : const unsigned int len,
157 : : const void *const opaque_data)
158 : : {
159 : 8 : const unsigned int nmemb = len / sizeof(struct sock_filter);
160 [ + + ][ + - ]: 8 : if (!nmemb || (unsigned short) nmemb != nmemb)
161 : : return false;
162 : :
163 : 6 : print_sock_fprog(tcp, addr, nmemb);
164 : :
165 : 6 : return true;
166 : : }
167 : :
168 : : static const nla_decoder_t packet_diag_msg_nla_decoders[] = {
169 : : [PACKET_DIAG_INFO] = decode_packet_diag_info,
170 : : [PACKET_DIAG_MCLIST] = decode_packet_diag_mclist,
171 : : [PACKET_DIAG_RX_RING] = decode_packet_diag_ring,
172 : : [PACKET_DIAG_TX_RING] = decode_packet_diag_ring,
173 : : [PACKET_DIAG_FANOUT] = decode_nla_u32,
174 : : [PACKET_DIAG_UID] = decode_nla_u32,
175 : : [PACKET_DIAG_MEMINFO] = decode_nla_meminfo,
176 : : [PACKET_DIAG_FILTER] = decode_packet_diag_filter
177 : : };
178 : :
179 : 34 : DECL_NETLINK_DIAG_DECODER(decode_packet_diag_msg)
180 : : {
181 : 34 : struct packet_diag_msg msg = { .pdiag_family = family };
182 : 34 : size_t offset = sizeof(msg.pdiag_family);
183 : 34 : bool decode_nla = false;
184 : :
185 : 34 : PRINT_FIELD_XVAL("{", msg, pdiag_family, addrfams, "AF_???");
186 : 34 : tprints(", ");
187 [ + + ]: 34 : if (len >= sizeof(msg)) {
188 [ + + ]: 32 : if (!umoven_or_printaddr(tcp, addr + offset,
189 : : sizeof(msg) - offset,
190 : : (void *) &msg + offset)) {
191 : 30 : PRINT_FIELD_XVAL("", msg, pdiag_type,
192 : : socktypes, "SOCK_???");
193 : 30 : PRINT_FIELD_U(", ", msg, pdiag_num);
194 : 30 : PRINT_FIELD_U(", ", msg, pdiag_ino);
195 : 30 : PRINT_FIELD_COOKIE(", ", msg, pdiag_cookie);
196 : 30 : decode_nla = true;
197 : : }
198 : : } else
199 : 2 : tprints("...");
200 : 34 : tprints("}");
201 : :
202 : 34 : offset = NLMSG_ALIGN(sizeof(msg));
203 [ + + ][ + + ]: 34 : if (decode_nla && len > offset) {
204 : 28 : tprints(", ");
205 : 28 : decode_nlattr(tcp, addr + offset, len - offset,
206 : : packet_diag_attrs, "PACKET_DIAG_???",
207 : : packet_diag_msg_nla_decoders,
208 : : ARRAY_SIZE(packet_diag_msg_nla_decoders), NULL);
209 : : }
210 : 34 : }
|