2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017 The strace developers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/socket.h>
33 # define XLAT_MACROS_ONLY
34 # include "xlat/addrfams.h"
35 # undef XLAT_MACROS_ONLY
39 #include "netlink_sock_diag.h"
41 #include "print_fields.h"
43 #include <arpa/inet.h>
44 #include <linux/smc_diag.h>
46 #include "xlat/smc_decl_codes.h"
47 #include "xlat/smc_diag_attrs.h"
48 #include "xlat/smc_diag_extended_flags.h"
49 #include "xlat/smc_diag_mode.h"
50 #include "xlat/smc_link_group_roles.h"
51 #include "xlat/smc_states.h"
52 #include "xlat/sock_shutdown_flags.h"
54 DECL_NETLINK_DIAG_DECODER(decode_smc_diag_req)
56 struct smc_diag_req req = { .diag_family = family };
57 const size_t offset = sizeof(req.diag_family);
59 PRINT_FIELD_XVAL("{", req, diag_family, addrfams, "AF_???");
61 if (len >= sizeof(req)) {
62 if (!umoven_or_printaddr(tcp, addr + offset,
64 (void *) &req + offset)) {
65 PRINT_FIELD_FLAGS("", req, diag_ext,
66 smc_diag_extended_flags,
67 "1<<SMC_DIAG_\?\?\?-1");
69 * AF_SMC protocol family socket handler
70 * keeping the AF_INET sock address.
72 PRINT_FIELD_INET_DIAG_SOCKID(", ", req, id, AF_INET);
80 print_smc_diag_cursor(const struct smc_diag_cursor *const cursor)
82 PRINT_FIELD_U("{", *cursor, reserved);
83 PRINT_FIELD_U(", ", *cursor, wrap);
84 PRINT_FIELD_U(", ", *cursor, count);
88 # define PRINT_FIELD_SMC_DIAG_CURSOR(prefix_, where_, field_) \
90 tprintf("%s%s=", (prefix_), #field_); \
91 print_smc_diag_cursor(&(where_).field_); \
95 decode_smc_diag_conninfo(struct tcb *const tcp,
96 const kernel_ulong_t addr,
97 const unsigned int len,
98 const void *const opaque_data)
100 struct smc_diag_conninfo cinfo;
102 if (len < sizeof(cinfo))
104 if (umove_or_printaddr(tcp, addr, &cinfo))
107 PRINT_FIELD_U("{", cinfo, token);
108 PRINT_FIELD_U(", ", cinfo, sndbuf_size);
109 PRINT_FIELD_U(", ", cinfo, rmbe_size);
110 PRINT_FIELD_U(", ", cinfo, peer_rmbe_size);
111 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_prod);
112 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_cons);
113 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prod);
114 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_cons);
115 PRINT_FIELD_0X(", ", cinfo, rx_prod_flags);
116 PRINT_FIELD_0X(", ", cinfo, rx_conn_state_flags);
117 PRINT_FIELD_0X(", ", cinfo, tx_prod_flags);
118 PRINT_FIELD_0X(", ", cinfo, tx_conn_state_flags);
119 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prep);
120 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_sent);
121 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin);
128 decode_smc_diag_lgrinfo(struct tcb *const tcp,
129 const kernel_ulong_t addr,
130 const unsigned int len,
131 const void *const opaque_data)
133 struct smc_diag_lgrinfo linfo;
135 if (len < sizeof(linfo))
137 if (umove_or_printaddr(tcp, addr, &linfo))
140 tprints("{lnk[0]={");
141 PRINT_FIELD_U("", linfo.lnk[0], link_id);
142 PRINT_FIELD_CSTRING(", ", linfo.lnk[0], ibname);
143 PRINT_FIELD_U(", ", linfo.lnk[0], ibport);
144 PRINT_FIELD_CSTRING(", ", linfo.lnk[0], gid);
145 PRINT_FIELD_CSTRING(", ", linfo.lnk[0], peer_gid);
146 PRINT_FIELD_XVAL("}, ", linfo, role, smc_link_group_roles, "SMC_???");
153 decode_smc_diag_shutdown(struct tcb *const tcp,
154 const kernel_ulong_t addr,
155 const unsigned int len,
156 const void *const opaque_data)
158 const struct decode_nla_xlat_opts opts = {
159 ARRSZ_PAIR(sock_shutdown_flags), "???_SHUTDOWN",
163 return decode_nla_flags(tcp, addr, len, &opts);
167 decode_smc_diag_dmbinfo(struct tcb *const tcp,
168 const kernel_ulong_t addr,
169 const unsigned int len,
170 const void *const opaque_data)
172 struct smcd_diag_dmbinfo dinfo;
174 if (len < sizeof(dinfo))
176 if (umove_or_printaddr(tcp, addr, &dinfo))
179 PRINT_FIELD_U("{", dinfo, linkid);
180 PRINT_FIELD_X(", ", dinfo, peer_gid);
181 PRINT_FIELD_X(", ", dinfo, my_gid);
182 PRINT_FIELD_X(", ", dinfo, token);
183 PRINT_FIELD_X(", ", dinfo, peer_token);
189 decode_smc_diag_fallback(struct tcb *const tcp,
190 const kernel_ulong_t addr,
191 const unsigned int len,
192 const void *const opaque_data)
194 struct smc_diag_fallback fb;
196 if (len < sizeof(fb))
198 if (umove_or_printaddr(tcp, addr, &fb))
202 * We print them verbose since they are defined in a non-UAPI header,
206 printxval_search_ex(smc_decl_codes, fb.reason,
207 "SMC_CLC_DECL_???", XLAT_STYLE_VERBOSE);
208 tprints(", peer_diagnosis=");
209 printxval_search_ex(smc_decl_codes, fb.peer_diagnosis,
210 "SMC_CLC_DECL_???", XLAT_STYLE_VERBOSE);
216 static const nla_decoder_t smc_diag_msg_nla_decoders[] = {
217 [SMC_DIAG_CONNINFO] = decode_smc_diag_conninfo,
218 [SMC_DIAG_LGRINFO] = decode_smc_diag_lgrinfo,
219 [SMC_DIAG_SHUTDOWN] = decode_smc_diag_shutdown,
220 [SMC_DIAG_DMBINFO] = decode_smc_diag_dmbinfo,
221 [SMC_DIAG_FALLBACK] = decode_smc_diag_fallback,
224 DECL_NETLINK_DIAG_DECODER(decode_smc_diag_msg)
226 struct smc_diag_msg msg = { .diag_family = family };
227 size_t offset = sizeof(msg.diag_family);
228 bool decode_nla = false;
230 PRINT_FIELD_XVAL("{", msg, diag_family, addrfams, "AF_???");
232 if (len >= sizeof(msg)) {
233 if (!umoven_or_printaddr(tcp, addr + offset,
234 sizeof(msg) - offset,
235 (void *) &msg + offset)) {
236 PRINT_FIELD_XVAL("", msg, diag_state,
237 smc_states, "SMC_???");
238 PRINT_FIELD_XVAL_INDEX(", ", msg, diag_fallback,
240 "SMC_DIAG_MODE_???");
241 PRINT_FIELD_U(", ", msg, diag_shutdown);
243 * AF_SMC protocol family socket handler
244 * keeping the AF_INET sock address.
246 PRINT_FIELD_INET_DIAG_SOCKID(", ", msg, id, AF_INET);
247 PRINT_FIELD_U(", ", msg, diag_uid);
248 PRINT_FIELD_U(", ", msg, diag_inode);
255 offset = NLMSG_ALIGN(sizeof(msg));
256 if (decode_nla && len > offset) {
258 decode_nlattr(tcp, addr + offset, len - offset,
259 smc_diag_attrs, "SMC_DIAG_???",
260 smc_diag_msg_nla_decoders,
261 ARRAY_SIZE(smc_diag_msg_nla_decoders), NULL);