Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr> |
| 3 | * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com> |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 4 | * Copyright (c) 2017-2018 The strace developers. |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 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 "tests.h" |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <stdint.h> |
| 34 | #include <unistd.h> |
| 35 | #include <sys/socket.h> |
| 36 | #include <arpa/inet.h> |
| 37 | #include <netinet/tcp.h> |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 38 | #include "test_netlink.h" |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 39 | #include <linux/if_ether.h> |
| 40 | #include <linux/inet_diag.h> |
| 41 | #include <linux/netlink_diag.h> |
| 42 | #include <linux/packet_diag.h> |
| 43 | #ifdef AF_SMC |
| 44 | # include <linux/smc_diag.h> |
| 45 | #endif |
| 46 | #include <linux/sock_diag.h> |
| 47 | #include <linux/unix_diag.h> |
| 48 | |
| 49 | #define SMC_ACTIVE 1 |
| 50 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 51 | #define TEST_SOCK_DIAG(fd_, nlh0_, \ |
| 52 | family_, type_, flags_, \ |
| 53 | obj_, print_family_, ...) \ |
| 54 | \ |
| 55 | do { \ |
| 56 | /* family only */ \ |
| 57 | uint8_t family = (family_); \ |
| 58 | TEST_NETLINK_((fd_), (nlh0_), \ |
| 59 | type_, #type_, \ |
| 60 | flags_, #flags_, \ |
| 61 | sizeof(family), &family, sizeof(family), \ |
| 62 | printf("{family=%s}", #family_)); \ |
| 63 | \ |
| 64 | /* family and string */ \ |
| 65 | char buf[sizeof(family) + 4]; \ |
| 66 | memcpy(buf, &family, sizeof(family)); \ |
| 67 | memcpy(buf + sizeof(family), "1234", 4); \ |
| 68 | TEST_NETLINK_((fd_), (nlh0_), \ |
| 69 | type_, #type_, \ |
| 70 | flags_, #flags_, \ |
| 71 | sizeof(buf), buf, sizeof(buf), \ |
| 72 | (print_family_); \ |
| 73 | printf(", ...}")); \ |
| 74 | \ |
| 75 | /* sizeof(obj_) */ \ |
| 76 | TEST_NETLINK_((fd_), (nlh0_), \ |
| 77 | type_, #type_, \ |
| 78 | flags_, #flags_, \ |
| 79 | sizeof(obj_), &(obj_), sizeof(obj_), \ |
| 80 | (print_family_); \ |
| 81 | __VA_ARGS__); \ |
| 82 | \ |
| 83 | /* short read of sizeof(obj_) */ \ |
| 84 | TEST_NETLINK_((fd_), (nlh0_), \ |
| 85 | type_, #type_, \ |
| 86 | flags_, #flags_, \ |
| 87 | sizeof(obj_), &(obj_), sizeof(obj_) - 1, \ |
| 88 | (print_family_); \ |
| 89 | printf(", %p}", \ |
| 90 | NLMSG_DATA(TEST_NETLINK_nlh) + 1));\ |
| 91 | } while (0) |
| 92 | |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 93 | static void |
| 94 | test_nlmsg_type(const int fd) |
| 95 | { |
| 96 | long rc; |
| 97 | struct nlmsghdr nlh = { |
| 98 | .nlmsg_len = sizeof(nlh), |
| 99 | .nlmsg_type = SOCK_DIAG_BY_FAMILY, |
| 100 | .nlmsg_flags = NLM_F_REQUEST, |
| 101 | }; |
| 102 | |
| 103 | rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0); |
| 104 | printf("sendto(%d, {len=%u, type=SOCK_DIAG_BY_FAMILY" |
| 105 | ", flags=NLM_F_REQUEST, seq=0, pid=0}" |
| 106 | ", %u, MSG_DONTWAIT, NULL, 0) = %s\n", |
| 107 | fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc)); |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | test_nlmsg_flags(const int fd) |
| 112 | { |
| 113 | long rc; |
| 114 | struct nlmsghdr nlh = { |
| 115 | .nlmsg_len = sizeof(nlh), |
| 116 | .nlmsg_type = SOCK_DIAG_BY_FAMILY, |
| 117 | .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP, |
| 118 | }; |
| 119 | |
| 120 | rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0); |
| 121 | printf("sendto(%d, {len=%u, type=SOCK_DIAG_BY_FAMILY" |
| 122 | ", flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}" |
| 123 | ", %u, MSG_DONTWAIT, NULL, 0) = %s\n", |
| 124 | fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc)); |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | test_odd_family_req(const int fd) |
| 129 | { |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 130 | uint8_t family = 0; |
| 131 | char buf[sizeof(family) + 4]; |
| 132 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(buf)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 133 | |
| 134 | /* unspecified family only */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 135 | TEST_NETLINK(fd, nlh0, |
| 136 | SOCK_DIAG_BY_FAMILY, |
| 137 | NLM_F_REQUEST, |
| 138 | sizeof(family), &family, sizeof(family), |
| 139 | printf("{family=AF_UNSPEC}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 140 | |
| 141 | /* unknown family only */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 142 | family = 0xff; |
| 143 | TEST_NETLINK(fd, nlh0, |
| 144 | SOCK_DIAG_BY_FAMILY, |
| 145 | NLM_F_REQUEST, |
| 146 | sizeof(family), &family, sizeof(family), |
| 147 | printf("{family=%#x /* AF_??? */}", family)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 148 | |
| 149 | /* short read of family */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 150 | TEST_NETLINK(fd, nlh0, |
| 151 | SOCK_DIAG_BY_FAMILY, |
| 152 | NLM_F_REQUEST, |
| 153 | sizeof(family), &family, sizeof(family) - 1, |
| 154 | printf("%p", NLMSG_DATA(TEST_NETLINK_nlh))); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 155 | |
| 156 | /* unspecified family and string */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 157 | family = 0; |
| 158 | memcpy(buf, &family, sizeof(family)); |
| 159 | memcpy(buf + sizeof(family), "1234", 4); |
| 160 | TEST_NETLINK(fd, nlh0, |
| 161 | SOCK_DIAG_BY_FAMILY, |
| 162 | NLM_F_REQUEST, |
| 163 | sizeof(buf), buf, sizeof(buf), |
| 164 | printf("{family=AF_UNSPEC, \"\\x31\\x32\\x33\\x34\"}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 165 | |
| 166 | /* unknown family and string */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 167 | family = 0xfd; |
| 168 | memcpy(buf, &family, sizeof(family)); |
| 169 | TEST_NETLINK(fd, nlh0, |
| 170 | SOCK_DIAG_BY_FAMILY, |
| 171 | NLM_F_REQUEST, |
| 172 | sizeof(buf), buf, sizeof(buf), |
| 173 | printf("{family=%#x /* AF_??? */" |
| 174 | ", \"\\x31\\x32\\x33\\x34\"}", family)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void |
| 178 | test_odd_family_msg(const int fd) |
| 179 | { |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 180 | uint8_t family = 0; |
| 181 | char buf[sizeof(family) + 4]; |
| 182 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(buf)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 183 | |
| 184 | /* unspecified family only */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 185 | TEST_NETLINK(fd, nlh0, |
| 186 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, |
| 187 | sizeof(family), &family, sizeof(family), |
| 188 | printf("{family=AF_UNSPEC}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 189 | |
| 190 | /* unknown family only */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 191 | family = 0xff; |
| 192 | TEST_NETLINK(fd, nlh0, |
| 193 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, |
| 194 | sizeof(family), &family, sizeof(family), |
| 195 | printf("{family=%#x /* AF_??? */}", family)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 196 | |
| 197 | /* short read of family */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 198 | TEST_NETLINK(fd, nlh0, |
| 199 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, |
| 200 | sizeof(family), &family, sizeof(family) - 1, |
| 201 | printf("%p", NLMSG_DATA(TEST_NETLINK_nlh))); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 202 | |
| 203 | /* unspecified family and string */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 204 | family = 0; |
| 205 | memcpy(buf, &family, sizeof(family)); |
| 206 | memcpy(buf + sizeof(family), "1234", 4); |
| 207 | TEST_NETLINK(fd, nlh0, |
| 208 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, |
| 209 | sizeof(buf), buf, sizeof(buf), |
| 210 | printf("{family=AF_UNSPEC, \"\\x31\\x32\\x33\\x34\"}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 211 | |
| 212 | /* unknown family and string */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 213 | family = 0xfd; |
| 214 | memcpy(buf, &family, sizeof(family)); |
| 215 | TEST_NETLINK(fd, nlh0, |
| 216 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, |
| 217 | sizeof(buf), buf, sizeof(buf), |
| 218 | printf("{family=%#x /* AF_??? */" |
| 219 | ", \"\\x31\\x32\\x33\\x34\"}", family)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void |
| 223 | test_unix_diag_req(const int fd) |
| 224 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 225 | static const struct unix_diag_req req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 226 | .sdiag_family = AF_UNIX, |
| 227 | .sdiag_protocol = 253, |
| 228 | .udiag_states = 1 << TCP_ESTABLISHED | 1 << TCP_LISTEN, |
| 229 | .udiag_ino = 0xfacefeed, |
| 230 | .udiag_show = UDIAG_SHOW_NAME, |
| 231 | .udiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 232 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 233 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 234 | TEST_SOCK_DIAG(fd, nlh0, AF_UNIX, |
| 235 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 236 | printf("{sdiag_family=AF_UNIX"), |
| 237 | PRINT_FIELD_U(", ", req, sdiag_protocol); |
| 238 | printf(", udiag_states=1<<TCP_ESTABLISHED|1<<TCP_LISTEN"); |
| 239 | PRINT_FIELD_U(", ", req, udiag_ino); |
| 240 | printf(", udiag_show=UDIAG_SHOW_NAME"); |
| 241 | PRINT_FIELD_COOKIE(", ", req, udiag_cookie); |
| 242 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void |
| 246 | test_unix_diag_msg(const int fd) |
| 247 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 248 | static const struct unix_diag_msg msg = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 249 | .udiag_family = AF_UNIX, |
| 250 | .udiag_type = SOCK_STREAM, |
| 251 | .udiag_state = TCP_FIN_WAIT1, |
| 252 | .udiag_ino = 0xfacefeed, |
| 253 | .udiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 254 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 255 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 256 | TEST_SOCK_DIAG(fd, nlh0, AF_UNIX, |
| 257 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, |
| 258 | printf("{udiag_family=AF_UNIX"), |
| 259 | printf(", udiag_type=SOCK_STREAM" |
| 260 | ", udiag_state=TCP_FIN_WAIT1"); |
| 261 | PRINT_FIELD_U(", ", msg, udiag_ino); |
| 262 | PRINT_FIELD_COOKIE(", ", msg, udiag_cookie); |
| 263 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static void |
| 267 | test_netlink_diag_req(const int fd) |
| 268 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 269 | struct netlink_diag_req req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 270 | .sdiag_family = AF_NETLINK, |
| 271 | .sdiag_protocol = NDIAG_PROTO_ALL, |
| 272 | .ndiag_ino = 0xfacefeed, |
| 273 | .ndiag_show = NDIAG_SHOW_MEMINFO, |
| 274 | .ndiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 275 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 276 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 277 | TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK, |
| 278 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 279 | printf("{sdiag_family=AF_NETLINK"), |
| 280 | printf(", sdiag_protocol=NDIAG_PROTO_ALL"); |
| 281 | PRINT_FIELD_U(", ", req, ndiag_ino); |
| 282 | printf(", ndiag_show=NDIAG_SHOW_MEMINFO"); |
| 283 | PRINT_FIELD_COOKIE(", ", req, ndiag_cookie); |
| 284 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 285 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 286 | req.sdiag_protocol = NETLINK_ROUTE; |
| 287 | req.ndiag_show = NDIAG_SHOW_GROUPS; |
| 288 | TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK, |
| 289 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 290 | printf("{sdiag_family=AF_NETLINK"), |
| 291 | printf(", sdiag_protocol=NETLINK_ROUTE"); |
| 292 | PRINT_FIELD_U(", ", req, ndiag_ino); |
| 293 | printf(", ndiag_show=NDIAG_SHOW_GROUPS"); |
| 294 | PRINT_FIELD_COOKIE(", ", req, ndiag_cookie); |
| 295 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static void |
| 299 | test_netlink_diag_msg(const int fd) |
| 300 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 301 | static const struct netlink_diag_msg msg = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 302 | .ndiag_family = AF_NETLINK, |
| 303 | .ndiag_type = SOCK_RAW, |
| 304 | .ndiag_protocol = NETLINK_ROUTE, |
| 305 | .ndiag_state = NETLINK_CONNECTED, |
| 306 | .ndiag_portid = 0xbadc0ded, |
| 307 | .ndiag_dst_portid = 0xdeadbeef, |
| 308 | .ndiag_dst_group = 0xfacefeed, |
| 309 | .ndiag_ino = 0xdaeefacd, |
| 310 | .ndiag_cookie = { 0xbadc0ded, 0xdeadbeef } |
| 311 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 312 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 313 | TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK, |
| 314 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, |
| 315 | printf("{ndiag_family=AF_NETLINK"), |
| 316 | printf(", ndiag_type=SOCK_RAW" |
| 317 | ", ndiag_protocol=NETLINK_ROUTE" |
| 318 | ", ndiag_state=NETLINK_CONNECTED"); |
| 319 | PRINT_FIELD_U(", ", msg, ndiag_portid); |
| 320 | PRINT_FIELD_U(", ", msg, ndiag_dst_portid); |
| 321 | PRINT_FIELD_U(", ", msg, ndiag_dst_group); |
| 322 | PRINT_FIELD_U(", ", msg, ndiag_ino); |
| 323 | PRINT_FIELD_COOKIE(", ", msg, ndiag_cookie); |
| 324 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static void |
| 328 | test_packet_diag_req(const int fd) |
| 329 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 330 | static const struct packet_diag_req req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 331 | .sdiag_family = AF_PACKET, |
| 332 | .sdiag_protocol = ETH_P_LOOP, |
| 333 | .pdiag_ino = 0xfacefeed, |
| 334 | .pdiag_show = PACKET_SHOW_INFO, |
| 335 | .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 336 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 337 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 338 | TEST_SOCK_DIAG(fd, nlh0, AF_PACKET, |
| 339 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 340 | printf("{sdiag_family=AF_PACKET"), |
| 341 | printf(", sdiag_protocol=ETH_P_LOOP"); |
| 342 | PRINT_FIELD_U(", ", req, pdiag_ino); |
| 343 | printf(", pdiag_show=PACKET_SHOW_INFO"); |
| 344 | PRINT_FIELD_COOKIE(", ", req, pdiag_cookie); |
| 345 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static void |
| 349 | test_packet_diag_msg(const int fd) |
| 350 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 351 | static const struct packet_diag_msg msg = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 352 | .pdiag_family = AF_PACKET, |
| 353 | .pdiag_type = SOCK_STREAM, |
| 354 | .pdiag_num = 0xbadc, |
| 355 | .pdiag_ino = 0xfacefeed, |
| 356 | .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 357 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 358 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg)); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 359 | TEST_SOCK_DIAG(fd, nlh0, AF_PACKET, |
| 360 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, |
| 361 | printf("{pdiag_family=AF_PACKET"), |
| 362 | printf(", pdiag_type=SOCK_STREAM"); |
| 363 | PRINT_FIELD_U(", ", msg, pdiag_num); |
| 364 | PRINT_FIELD_U(", ", msg, pdiag_ino); |
| 365 | PRINT_FIELD_COOKIE(", ", msg, pdiag_cookie); |
| 366 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static void |
| 370 | test_inet_diag_sockid(const int fd) |
| 371 | { |
| 372 | const char address[] = "12.34.56.78"; |
| 373 | const char address6[] = "12:34:56:78:90:ab:cd:ef"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 374 | struct inet_diag_req_v2 req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 375 | .sdiag_family = AF_INET, |
| 376 | .idiag_ext = 1 << (INET_DIAG_CONG - 1), |
| 377 | .sdiag_protocol = IPPROTO_TCP, |
| 378 | .idiag_states = 1 << TCP_CLOSE, |
| 379 | .id = { |
| 380 | .idiag_sport = 0xfacd, |
| 381 | .idiag_dport = 0xdead, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 382 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 383 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 384 | }, |
| 385 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 386 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 387 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 388 | if (!inet_pton(AF_INET, address, &req.id.idiag_src) || |
| 389 | !inet_pton(AF_INET, address, &req.id.idiag_dst)) |
| 390 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 391 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 392 | TEST_NETLINK(fd, nlh0, |
| 393 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, |
| 394 | sizeof(req), &req, sizeof(req), |
| 395 | printf("{sdiag_family=AF_INET"), |
| 396 | printf(", sdiag_protocol=IPPROTO_TCP" |
| 397 | ", idiag_ext=1<<(INET_DIAG_CONG-1)" |
| 398 | ", idiag_states=1<<TCP_CLOSE" |
| 399 | ", id={idiag_sport=htons(%u)" |
| 400 | ", idiag_dport=htons(%u)" |
| 401 | ", idiag_src=inet_addr(\"%s\")" |
| 402 | ", idiag_dst=inet_addr(\"%s\")", |
| 403 | ntohs(req.id.idiag_sport), |
| 404 | ntohs(req.id.idiag_dport), |
| 405 | address, address); |
| 406 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 407 | PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie); |
| 408 | printf("}}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 409 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 410 | req.sdiag_family = AF_INET6; |
| 411 | if (!inet_pton(AF_INET6, address6, &req.id.idiag_src) || |
| 412 | !inet_pton(AF_INET6, address6, &req.id.idiag_dst)) |
| 413 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 414 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 415 | TEST_NETLINK(fd, nlh0, |
| 416 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, |
| 417 | sizeof(req), &req, sizeof(req), |
| 418 | printf("{sdiag_family=AF_INET6"), |
| 419 | printf(", sdiag_protocol=IPPROTO_TCP" |
| 420 | ", idiag_ext=1<<(INET_DIAG_CONG-1)" |
| 421 | ", idiag_states=1<<TCP_CLOSE" |
| 422 | ", id={idiag_sport=htons(%u)" |
| 423 | ", idiag_dport=htons(%u)" |
| 424 | ", inet_pton(AF_INET6, \"%s\", &idiag_src)" |
| 425 | ", inet_pton(AF_INET6, \"%s\", &idiag_dst)", |
| 426 | ntohs(req.id.idiag_sport), |
| 427 | ntohs(req.id.idiag_dport), |
| 428 | address6, address6); |
| 429 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 430 | PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie); |
| 431 | printf("}}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void |
| 435 | test_inet_diag_req(const int fd) |
| 436 | { |
| 437 | const char address[] = "12.34.56.78"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 438 | struct inet_diag_req req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 439 | .idiag_family = AF_INET, |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 440 | .idiag_src_len = 0xde, |
| 441 | .idiag_dst_len = 0xba, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 442 | .idiag_ext = 1 << (INET_DIAG_TOS - 1), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 443 | .id = { |
| 444 | .idiag_sport = 0xdead, |
| 445 | .idiag_dport = 0xadcd, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 446 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 447 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 448 | }, |
| 449 | .idiag_states = 1 << TCP_LAST_ACK, |
| 450 | .idiag_dbs = 0xfacefeed, |
| 451 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 452 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 453 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 454 | if (!inet_pton(AF_INET, address, &req.id.idiag_src) || |
| 455 | !inet_pton(AF_INET, address, &req.id.idiag_dst)) |
| 456 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 457 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 458 | TEST_SOCK_DIAG(fd, nlh0, AF_INET, |
| 459 | TCPDIAG_GETSOCK, NLM_F_REQUEST, req, |
| 460 | printf("{idiag_family=AF_INET"), |
| 461 | PRINT_FIELD_U(", ", req, idiag_src_len); |
| 462 | PRINT_FIELD_U(", ", req, idiag_dst_len); |
| 463 | printf(", idiag_ext=1<<(INET_DIAG_TOS-1)"); |
| 464 | printf(", id={idiag_sport=htons(%u)" |
| 465 | ", idiag_dport=htons(%u)" |
| 466 | ", idiag_src=inet_addr(\"%s\")" |
| 467 | ", idiag_dst=inet_addr(\"%s\")", |
| 468 | ntohs(req.id.idiag_sport), |
| 469 | ntohs(req.id.idiag_dport), |
| 470 | address, address); |
| 471 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 472 | PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie); |
| 473 | printf("}, idiag_states=1<<TCP_LAST_ACK"); |
| 474 | PRINT_FIELD_U(", ", req, idiag_dbs); |
| 475 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
| 479 | test_inet_diag_req_v2(const int fd) |
| 480 | { |
| 481 | const char address[] = "87.65.43.21"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 482 | struct inet_diag_req_v2 req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 483 | .sdiag_family = AF_INET, |
| 484 | .idiag_ext = 1 << (INET_DIAG_CONG - 1), |
| 485 | .sdiag_protocol = IPPROTO_TCP, |
| 486 | .idiag_states = 1 << TCP_CLOSE, |
| 487 | .id = { |
| 488 | .idiag_sport = 0xfacd, |
| 489 | .idiag_dport = 0xdead, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 490 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 491 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 492 | }, |
| 493 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 494 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 495 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 496 | if (!inet_pton(AF_INET, address, &req.id.idiag_src) || |
| 497 | !inet_pton(AF_INET, address, &req.id.idiag_dst)) |
| 498 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 499 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 500 | TEST_SOCK_DIAG(fd, nlh0, AF_INET, |
| 501 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 502 | printf("{sdiag_family=AF_INET"), |
| 503 | printf(", sdiag_protocol=IPPROTO_TCP" |
| 504 | ", idiag_ext=1<<(INET_DIAG_CONG-1)" |
| 505 | ", idiag_states=1<<TCP_CLOSE" |
| 506 | ", id={idiag_sport=htons(%u)" |
| 507 | ", idiag_dport=htons(%u)" |
| 508 | ", idiag_src=inet_addr(\"%s\")" |
| 509 | ", idiag_dst=inet_addr(\"%s\")", |
| 510 | ntohs(req.id.idiag_sport), |
| 511 | ntohs(req.id.idiag_dport), |
| 512 | address, address); |
| 513 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 514 | PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie); |
| 515 | printf("}}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void |
| 519 | test_inet_diag_msg(const int fd) |
| 520 | { |
| 521 | const char address[] = "11.22.33.44"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 522 | struct inet_diag_msg msg = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 523 | .idiag_family = AF_INET, |
| 524 | .idiag_state = TCP_LISTEN, |
| 525 | .idiag_timer = 0xfa, |
| 526 | .idiag_retrans = 0xde, |
| 527 | .id = { |
| 528 | .idiag_sport = 0xfacf, |
| 529 | .idiag_dport = 0xdead, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 530 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 531 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded } |
| 532 | }, |
| 533 | .idiag_expires = 0xfacefeed, |
| 534 | .idiag_rqueue = 0xdeadbeef, |
| 535 | .idiag_wqueue = 0xadcdfafc, |
| 536 | .idiag_uid = 0xdecefaeb, |
| 537 | .idiag_inode = 0xbadc0ded, |
| 538 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 539 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 540 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 541 | if (!inet_pton(AF_INET, address, &msg.id.idiag_src) || |
| 542 | !inet_pton(AF_INET, address, &msg.id.idiag_dst)) |
| 543 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 544 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 545 | TEST_SOCK_DIAG(fd, nlh0, AF_INET, |
| 546 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, |
| 547 | printf("{idiag_family=AF_INET"), |
| 548 | printf(", idiag_state=TCP_LISTEN"); |
| 549 | PRINT_FIELD_U(", ", msg, idiag_timer); |
| 550 | PRINT_FIELD_U(", ", msg, idiag_retrans); |
| 551 | printf(", id={idiag_sport=htons(%u)" |
| 552 | ", idiag_dport=htons(%u)" |
| 553 | ", idiag_src=inet_addr(\"%s\")" |
| 554 | ", idiag_dst=inet_addr(\"%s\")", |
| 555 | ntohs(msg.id.idiag_sport), |
| 556 | ntohs(msg.id.idiag_dport), |
| 557 | address, address); |
| 558 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 559 | PRINT_FIELD_COOKIE(", ", msg.id, idiag_cookie); |
| 560 | PRINT_FIELD_U("}, ", msg, idiag_expires); |
| 561 | PRINT_FIELD_U(", ", msg, idiag_rqueue); |
| 562 | PRINT_FIELD_U(", ", msg, idiag_wqueue); |
| 563 | PRINT_FIELD_U(", ", msg, idiag_uid); |
| 564 | PRINT_FIELD_U(", ", msg, idiag_inode); |
| 565 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | #ifdef AF_SMC |
| 569 | static void |
| 570 | test_smc_diag_req(const int fd) |
| 571 | { |
| 572 | const char address[] = "43.21.56.78"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 573 | struct smc_diag_req req = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 574 | .diag_family = AF_SMC, |
| 575 | .diag_ext = 1 << (SMC_DIAG_CONNINFO - 1), |
| 576 | .id = { |
| 577 | .idiag_sport = 0xdead, |
| 578 | .idiag_dport = 0xadcd, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 579 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 580 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }, |
| 581 | }, |
| 582 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 583 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 584 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 585 | if (!inet_pton(AF_INET, address, &req.id.idiag_src) || |
| 586 | !inet_pton(AF_INET, address, &req.id.idiag_dst)) |
| 587 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 588 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 589 | TEST_SOCK_DIAG(fd, nlh0, AF_SMC, |
| 590 | SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, |
| 591 | printf("{diag_family=AF_SMC"), |
| 592 | printf(", diag_ext=1<<(SMC_DIAG_CONNINFO-1)"); |
| 593 | printf(", id={idiag_sport=htons(%u)" |
| 594 | ", idiag_dport=htons(%u)" |
| 595 | ", idiag_src=inet_addr(\"%s\")" |
| 596 | ", idiag_dst=inet_addr(\"%s\")", |
| 597 | ntohs(req.id.idiag_sport), |
| 598 | ntohs(req.id.idiag_dport), |
| 599 | address, address); |
| 600 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 601 | PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie); |
| 602 | printf("}}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static void |
| 606 | test_smc_diag_msg(const int fd) |
| 607 | { |
| 608 | const char address[] = "34.87.12.90"; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 609 | struct smc_diag_msg msg = { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 610 | .diag_family = AF_SMC, |
| 611 | .diag_state = SMC_ACTIVE, |
| 612 | .diag_fallback = 0xde, |
| 613 | .diag_shutdown = 0xba, |
| 614 | .id = { |
| 615 | .idiag_sport = 0xdead, |
| 616 | .idiag_dport = 0xadcd, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 617 | .idiag_if = ifindex_lo(), |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 618 | .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }, |
| 619 | }, |
| 620 | .diag_uid = 0xadcdfafc, |
| 621 | .diag_inode = 0xbadc0ded, |
| 622 | }; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 623 | void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg)); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 624 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 625 | if (!inet_pton(AF_INET, address, &msg.id.idiag_src) || |
| 626 | !inet_pton(AF_INET, address, &msg.id.idiag_dst)) |
| 627 | perror_msg_and_skip("inet_pton"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 628 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 629 | TEST_SOCK_DIAG(fd, nlh0, AF_SMC, |
| 630 | SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, |
| 631 | printf("{diag_family=AF_SMC"), |
| 632 | printf(", diag_state=SMC_ACTIVE"); |
| 633 | PRINT_FIELD_U(", ", msg, diag_fallback); |
| 634 | PRINT_FIELD_U(", ", msg, diag_shutdown); |
| 635 | printf(", id={idiag_sport=htons(%u)" |
| 636 | ", idiag_dport=htons(%u)" |
| 637 | ", idiag_src=inet_addr(\"%s\")" |
| 638 | ", idiag_dst=inet_addr(\"%s\")", |
| 639 | ntohs(msg.id.idiag_sport), |
| 640 | ntohs(msg.id.idiag_dport), |
| 641 | address, address); |
| 642 | printf(", idiag_if=" IFINDEX_LO_STR); |
| 643 | PRINT_FIELD_COOKIE(", ", msg.id, idiag_cookie); |
| 644 | PRINT_FIELD_U("}, ", msg, diag_uid); |
| 645 | PRINT_FIELD_U(", ", msg, diag_inode); |
| 646 | printf("}")); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 647 | } |
| 648 | #endif |
| 649 | |
| 650 | int |
| 651 | main(void) |
| 652 | { |
| 653 | skip_if_unavailable("/proc/self/fd/"); |
| 654 | |
| 655 | int fd = create_nl_socket(NETLINK_SOCK_DIAG); |
| 656 | |
| 657 | test_nlmsg_type(fd); |
| 658 | test_nlmsg_flags(fd); |
| 659 | test_odd_family_req(fd); |
| 660 | test_odd_family_msg(fd); |
| 661 | test_unix_diag_req(fd); |
| 662 | test_unix_diag_msg(fd); |
| 663 | test_netlink_diag_req(fd); |
| 664 | test_netlink_diag_msg(fd); |
| 665 | test_packet_diag_req(fd); |
| 666 | test_packet_diag_msg(fd); |
| 667 | test_inet_diag_sockid(fd); |
| 668 | test_inet_diag_req(fd); |
| 669 | test_inet_diag_req_v2(fd); |
| 670 | test_inet_diag_msg(fd); |
| 671 | #ifdef AF_SMC |
| 672 | test_smc_diag_req(fd); |
| 673 | test_smc_diag_msg(fd); |
| 674 | #endif |
| 675 | |
| 676 | printf("+++ exited with 0 +++\n"); |
| 677 | |
| 678 | return 0; |
| 679 | } |