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>
37 # include <arpa/inet.h>
38 # include "test_nlattr.h"
39 # include <linux/rtnetlink.h>
40 # include <linux/smc_diag.h>
41 # include <linux/sock_diag.h>
50 static const char address[] = "12.34.56.78";
53 init_smc_diag_msg(struct nlmsghdr *const nlh, const unsigned int msg_len)
55 SET_STRUCT(struct nlmsghdr, nlh,
57 .nlmsg_type = SOCK_DIAG_BY_FAMILY,
58 .nlmsg_flags = NLM_F_DUMP
61 struct smc_diag_msg *const msg = NLMSG_DATA(nlh);
62 SET_STRUCT(struct smc_diag_msg, msg,
63 .diag_family = AF_SMC,
64 .diag_state = SMC_ACTIVE
67 if (!inet_pton(AF_INET, address, msg->id.idiag_src) ||
68 !inet_pton(AF_INET, address, msg->id.idiag_dst))
69 perror_msg_and_skip("inet_pton");
73 print_smc_diag_msg(const unsigned int msg_len)
75 printf("{len=%u, type=SOCK_DIAG_BY_FAMILY"
76 ", flags=NLM_F_DUMP, seq=0, pid=0}"
77 ", {diag_family=AF_SMC, diag_state=SMC_ACTIVE"
78 ", diag_fallback=0, diag_shutdown=0"
79 ", id={idiag_sport=htons(0), idiag_dport=htons(0)"
80 ", idiag_src=inet_addr(\"%s\")"
81 ", idiag_dst=inet_addr(\"%s\")"
82 ", idiag_if=0, idiag_cookie=[0, 0]}"
83 ", diag_uid=0, diag_inode=0}",
84 msg_len, address, address);
87 #define PRINT_FIELD_SMC_DIAG_CURSOR(prefix_, where_, field_) \
89 printf("%s%s=", (prefix_), #field_); \
90 PRINT_FIELD_U("{", (where_).field_, reserved); \
91 PRINT_FIELD_U(", ", (where_).field_, wrap); \
92 PRINT_FIELD_U(", ", (where_).field_, count); \
98 skip_if_unavailable("/proc/self/fd/");
100 int fd = create_nl_socket(NETLINK_SOCK_DIAG);
101 const unsigned int hdrlen = sizeof(struct smc_diag_msg);
102 void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
104 static char pattern[4096];
105 fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
107 static const struct smc_diag_conninfo cinfo = {
109 .sndbuf_size = 0xbcdaefad,
110 .rmbe_size = 0xcdbaefab,
111 .peer_rmbe_size = 0xdbcdedaf,
132 .rx_prod_flags = 0xff,
133 .rx_conn_state_flags = 0xff,
134 .tx_prod_flags = 0xff,
135 .tx_conn_state_flags = 0xff,
153 TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
154 init_smc_diag_msg, print_smc_diag_msg,
155 SMC_DIAG_CONNINFO, pattern, cinfo,
156 PRINT_FIELD_U("{", cinfo, token);
157 PRINT_FIELD_U(", ", cinfo, sndbuf_size);
158 PRINT_FIELD_U(", ", cinfo, rmbe_size);
159 PRINT_FIELD_U(", ", cinfo, peer_rmbe_size);
160 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_prod);
161 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_cons);
162 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prod);
163 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_cons);
164 printf(", rx_prod_flags=0xff");
165 printf(", rx_conn_state_flags=0xff");
166 printf(", tx_prod_flags=0xff");
167 printf(", tx_conn_state_flags=0xff");
168 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prep);
169 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_sent);
170 PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin);
173 static const struct smc_diag_lgrinfo linfo = {
183 TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
184 init_smc_diag_msg, print_smc_diag_msg,
185 SMC_DIAG_LGRINFO, pattern, linfo,
186 PRINT_FIELD_U("{lnk[0]={", linfo.lnk[0], link_id);
187 printf(", ibname=\"%s\"", linfo.lnk[0].ibname);
188 PRINT_FIELD_U(", ", linfo.lnk[0], ibport);
189 printf(", gid=\"%s\"", linfo.lnk[0].gid);
190 printf(", peer_gid=\"%s\"}", linfo.lnk[0].peer_gid);
191 printf(", role=SMC_CLNT}"));
193 printf("+++ exited with 0 +++\n");
199 SKIP_MAIN_UNDEFINED("AF_SMC")