]> granicus.if.org Git - strace/blob - rtnl_addrlabel.c
rtnl_link: print pad field in the struct ifla_port_vsi decoder
[strace] / rtnl_addrlabel.c
1 /*
2  * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4  * Copyright (c) 2016-2018 The strace developers.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11
12 #ifdef HAVE_STRUCT_IFADDRLBLMSG
13
14 # include "netlink_route.h"
15 # include "nlattr.h"
16 # include "print_fields.h"
17
18 # include <linux/if_addrlabel.h>
19 # include "netlink.h"
20
21 # include "xlat/rtnl_addrlabel_attrs.h"
22
23 static bool
24 decode_ifal_address(struct tcb *const tcp,
25                     const kernel_ulong_t addr,
26                     const unsigned int len,
27                     const void *const opaque_data)
28 {
29         const struct ifaddrlblmsg *const ifal = opaque_data;
30
31         decode_inet_addr(tcp, addr, len, ifal->ifal_family, NULL);
32
33         return true;
34 }
35
36 static const nla_decoder_t ifaddrlblmsg_nla_decoders[] = {
37         [IFAL_ADDRESS]  = decode_ifal_address,
38         [IFAL_LABEL]    = decode_nla_u32
39 };
40
41 DECL_NETLINK_ROUTE_DECODER(decode_ifaddrlblmsg)
42 {
43         struct ifaddrlblmsg ifal = { .ifal_family = family };
44         size_t offset = sizeof(ifal.ifal_family);
45         bool decode_nla = false;
46
47         PRINT_FIELD_XVAL("{", ifal, ifal_family, addrfams, "AF_???");
48
49         tprints(", ");
50         if (len >= sizeof(ifal)) {
51                 if (!umoven_or_printaddr(tcp, addr + offset,
52                                          sizeof(ifal) - offset,
53                                          (char *) &ifal + offset)) {
54                         PRINT_FIELD_U("", ifal, ifal_prefixlen);
55                         PRINT_FIELD_U(", ", ifal, ifal_flags);
56                         PRINT_FIELD_IFINDEX(", ", ifal, ifal_index);
57                         PRINT_FIELD_U(", ", ifal, ifal_seq);
58                         decode_nla = true;
59                 }
60         } else
61                 tprints("...");
62         tprints("}");
63
64         offset = NLMSG_ALIGN(sizeof(ifal));
65         if (decode_nla && len > offset) {
66                 tprints(", ");
67                 decode_nlattr(tcp, addr + offset, len - offset,
68                               rtnl_addrlabel_attrs, "IFAL_???",
69                               ifaddrlblmsg_nla_decoders,
70                               ARRAY_SIZE(ifaddrlblmsg_nla_decoders), &ifal);
71         }
72 }
73
74 #endif