]> granicus.if.org Git - strace/blobdiff - rtnl_link.c
tests: move F_OFD_SETLK* checks from fcntl64.c to fcntl-common.c
[strace] / rtnl_link.c
index 9909684240526f5f11c985b0c5a73a7644da0c7a..2ef2d63a4cddf05342493d76ff3f3b4fc8235bf2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
- * Copyright (c) 2016-2017 The strace developers.
+ * Copyright (c) 2016-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <linux/rtnetlink.h>
 
 #include "xlat/rtnl_ifla_brport_attrs.h"
+#include "xlat/rtnl_ifla_events.h"
+#include "xlat/rtnl_ifla_info_attrs.h"
+#include "xlat/rtnl_ifla_port_attrs.h"
+#include "xlat/rtnl_ifla_vf_port_attrs.h"
+#include "xlat/rtnl_ifla_xdp_attrs.h"
 #include "xlat/rtnl_link_attrs.h"
+#include "xlat/xdp_flags.h"
 
 static bool
 decode_rtnl_link_stats(struct tcb *const tcp,
@@ -50,11 +56,15 @@ decode_rtnl_link_stats(struct tcb *const tcp,
        struct rtnl_link_stats st;
        const unsigned int min_size =
                offsetofend(struct rtnl_link_stats, tx_compressed);
-       const unsigned int size = len < sizeof(st) ? min_size : sizeof(st);
+       const unsigned int def_size = sizeof(st);
+       const unsigned int size =
+               (len >= def_size) ? def_size :
+                                   ((len == min_size) ? min_size : 0);
 
-       if (len < min_size)
+       if (!size)
                return false;
-       else if (!umoven_or_printaddr(tcp, addr, size, &st)) {
+
+       if (!umoven_or_printaddr(tcp, addr, size, &st)) {
                PRINT_FIELD_U("{", st, rx_packets);
                PRINT_FIELD_U(", ", st, tx_packets);
                PRINT_FIELD_U(", ", st, rx_bytes);
@@ -82,7 +92,7 @@ decode_rtnl_link_stats(struct tcb *const tcp,
                PRINT_FIELD_U(", ", st, rx_compressed);
                PRINT_FIELD_U(", ", st, tx_compressed);
 #ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER
-               if (len >= sizeof(st))
+               if (len >= def_size)
                        PRINT_FIELD_U(", ", st, rx_nohandler);
 #endif
                tprints("}");
@@ -103,10 +113,9 @@ decode_ifla_bridge_id(struct tcb *const tcp,
        if (len < sizeof(id))
                return false;
        else if (!umove_or_printaddr(tcp, addr, &id)) {
-               tprintf("{prio=[%u, %u], addr=%02x:%02x:%02x:%02x:%02x:%02x}",
-                       id.prio[0], id.prio[1],
-                       id.addr[0], id.addr[1], id.addr[2],
-                       id.addr[3], id.addr[4], id.addr[5]);
+               tprintf("{prio=[%u, %u]", id.prio[0], id.prio[1]);
+               PRINT_FIELD_MAC(", ", id, addr);
+               tprints("}");
        }
 
        return true;
@@ -186,6 +195,27 @@ decode_rtnl_link_ifmap(struct tcb *const tcp,
        return true;
 }
 
+static const nla_decoder_t ifla_linkinfo_nla_decoders[] = {
+       [IFLA_INFO_KIND]        = decode_nla_str,
+       [IFLA_INFO_DATA]        = NULL, /* unimplemented */
+       [IFLA_INFO_XSTATS]      = NULL, /* unimplemented */
+       [IFLA_INFO_SLAVE_KIND]  = decode_nla_str,
+       [IFLA_INFO_SLAVE_DATA]  = NULL, /* unimplemented */
+};
+
+static bool
+decode_ifla_linkinfo(struct tcb *const tcp,
+                    const kernel_ulong_t addr,
+                    const unsigned int len,
+                    const void *const opaque_data)
+{
+       decode_nlattr(tcp, addr, len, rtnl_ifla_info_attrs,
+                     "IFLA_INFO_???", ifla_linkinfo_nla_decoders,
+                     ARRAY_SIZE(ifla_linkinfo_nla_decoders), opaque_data);
+
+       return true;
+}
+
 static bool
 decode_rtnl_link_stats64(struct tcb *const tcp,
                         const kernel_ulong_t addr,
@@ -196,11 +226,15 @@ decode_rtnl_link_stats64(struct tcb *const tcp,
        struct rtnl_link_stats64 st;
        const unsigned int min_size =
                offsetofend(struct rtnl_link_stats64, tx_compressed);
-       const unsigned int size = len < sizeof(st) ? min_size : sizeof(st);
+       const unsigned int def_size = sizeof(st);
+       const unsigned int size =
+               (len >= def_size) ? def_size :
+                                   ((len == min_size) ? min_size : 0);
 
-       if (len < min_size)
+       if (!size)
                return false;
-       else if (!umoven_or_printaddr(tcp, addr, size, &st)) {
+
+       if (!umoven_or_printaddr(tcp, addr, size, &st)) {
                PRINT_FIELD_U("{", st, rx_packets);
                PRINT_FIELD_U(", ", st, tx_packets);
                PRINT_FIELD_U(", ", st, rx_bytes);
@@ -228,7 +262,7 @@ decode_rtnl_link_stats64(struct tcb *const tcp,
                PRINT_FIELD_U(", ", st, rx_compressed);
                PRINT_FIELD_U(", ", st, tx_compressed);
 #ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER
-               if (len >= sizeof(st))
+               if (len >= def_size)
                        PRINT_FIELD_U(", ", st, rx_nohandler);
 #endif
                tprints("}");
@@ -240,6 +274,123 @@ decode_rtnl_link_stats64(struct tcb *const tcp,
 #endif
 }
 
+static bool
+decode_ifla_port_vsi(struct tcb *const tcp,
+                    const kernel_ulong_t addr,
+                    const unsigned int len,
+                    const void *const opaque_data)
+{
+#ifdef HAVE_STRUCT_IFLA_PORT_VSI
+       struct ifla_port_vsi vsi;
+
+       if (len < sizeof(vsi))
+               return false;
+       else if (!umove_or_printaddr(tcp, addr, &vsi)) {
+               PRINT_FIELD_U("{", vsi, vsi_mgr_id);
+               PRINT_FIELD_STRING(", ", vsi, vsi_type_id,
+                                  sizeof(vsi.vsi_type_id), QUOTE_FORCE_HEX);
+               PRINT_FIELD_U(", ", vsi, vsi_type_version);
+               tprints("}");
+       }
+
+       return true;
+#else
+       return false;
+#endif
+}
+
+static const nla_decoder_t ifla_port_nla_decoders[] = {
+       [IFLA_PORT_VF]                  = decode_nla_u32,
+       [IFLA_PORT_PROFILE]             = decode_nla_str,
+       [IFLA_PORT_VSI_TYPE]            = decode_ifla_port_vsi,
+       [IFLA_PORT_INSTANCE_UUID]       = NULL, /* default parser */
+       [IFLA_PORT_HOST_UUID]           = NULL, /* default parser */
+       [IFLA_PORT_REQUEST]             = decode_nla_u8,
+       [IFLA_PORT_RESPONSE]            = decode_nla_u16
+};
+
+static bool
+decode_ifla_port(struct tcb *const tcp,
+                const kernel_ulong_t addr,
+                const unsigned int len,
+                const void *const opaque_data)
+{
+       decode_nlattr(tcp, addr, len, rtnl_ifla_port_attrs,
+                     "IFLA_VF_PORT_???", ifla_port_nla_decoders,
+                     ARRAY_SIZE(ifla_port_nla_decoders), opaque_data);
+
+       return true;
+}
+
+static const nla_decoder_t ifla_vf_port_nla_decoders[] = {
+       [IFLA_VF_PORT] = decode_ifla_port
+};
+
+static bool
+decode_ifla_vf_ports(struct tcb *const tcp,
+                    const kernel_ulong_t addr,
+                    const unsigned int len,
+                    const void *const opaque_data)
+{
+       decode_nlattr(tcp, addr, len, rtnl_ifla_vf_port_attrs,
+                     "IFLA_VF_PORT_???", ifla_vf_port_nla_decoders,
+                     ARRAY_SIZE(ifla_vf_port_nla_decoders), opaque_data);
+
+       return true;
+}
+
+static bool
+decode_ifla_xdp_flags(struct tcb *const tcp,
+                     const kernel_ulong_t addr,
+                     const unsigned int len,
+                     const void *const opaque_data)
+{
+       uint32_t flags;
+
+       if (len < sizeof(flags))
+               return false;
+       else if (!umove_or_printaddr(tcp, addr, &flags))
+               printflags(xdp_flags, flags, "XDP_FLAGS_???");
+
+       return true;
+}
+
+static const nla_decoder_t ifla_xdp_nla_decoders[] = {
+       [IFLA_XDP_FD]           = decode_nla_fd,
+       [IFLA_XDP_ATTACHED]     = decode_nla_u8,
+       [IFLA_XDP_FLAGS]        = decode_ifla_xdp_flags,
+       [IFLA_XDP_PROG_ID]      = decode_nla_u32
+};
+
+static bool
+decode_ifla_xdp(struct tcb *const tcp,
+               const kernel_ulong_t addr,
+               const unsigned int len,
+               const void *const opaque_data)
+{
+       decode_nlattr(tcp, addr, len, rtnl_ifla_xdp_attrs,
+                     "IFLA_XDP_???", ifla_xdp_nla_decoders,
+                     ARRAY_SIZE(ifla_xdp_nla_decoders), opaque_data);
+
+       return true;
+}
+
+static bool
+decode_ifla_event(struct tcb *const tcp,
+                 const kernel_ulong_t addr,
+                 const unsigned int len,
+                 const void *const opaque_data)
+{
+       uint32_t ev;
+
+       if (len < sizeof(ev))
+               return false;
+       else if (!umove_or_printaddr(tcp, addr, &ev))
+               printxval(rtnl_ifla_events, ev, "IFLA_EVENT_???");
+
+       return true;
+}
+
 static const nla_decoder_t ifinfomsg_nla_decoders[] = {
        [IFLA_ADDRESS]          = NULL, /* unimplemented */
        [IFLA_BROADCAST]        = NULL, /* unimplemented */
@@ -258,17 +409,17 @@ static const nla_decoder_t ifinfomsg_nla_decoders[] = {
        [IFLA_WEIGHT]           = decode_nla_u32,
        [IFLA_OPERSTATE]        = decode_nla_u8,
        [IFLA_LINKMODE]         = decode_nla_u8,
-       [IFLA_LINKINFO]         = NULL, /* unimplemented */
+       [IFLA_LINKINFO]         = decode_ifla_linkinfo,
        [IFLA_NET_NS_PID]       = decode_nla_u32,
        [IFLA_IFALIAS]          = decode_nla_str,
        [IFLA_NUM_VF]           = decode_nla_u32,
        [IFLA_VFINFO_LIST]      = NULL, /* unimplemented */
        [IFLA_STATS64]          = decode_rtnl_link_stats64,
-       [IFLA_VF_PORTS]         = NULL, /* unimplemented */
-       [IFLA_PORT_SELF]        = NULL, /* unimplemented */
+       [IFLA_VF_PORTS]         = decode_ifla_vf_ports,
+       [IFLA_PORT_SELF]        = decode_ifla_port,
        [IFLA_AF_SPEC]          = NULL, /* unimplemented */
        [IFLA_GROUP]            = decode_nla_u32,
-       [IFLA_NET_NS_FD]        = decode_nla_u32,
+       [IFLA_NET_NS_FD]        = decode_nla_fd,
        [IFLA_EXT_MASK]         = decode_nla_u32,
        [IFLA_PROMISCUITY]      = decode_nla_u32,
        [IFLA_NUM_TX_QUEUES]    = decode_nla_u32,
@@ -283,8 +434,13 @@ static const nla_decoder_t ifinfomsg_nla_decoders[] = {
        [IFLA_GSO_MAX_SEGS]     = decode_nla_u32,
        [IFLA_GSO_MAX_SIZE]     = decode_nla_u32,
        [IFLA_PAD]              = NULL,
-       [IFLA_XDP]              = NULL, /* unimplemented */
-       [IFLA_EVENT]            = decode_nla_u32
+       [IFLA_XDP]              = decode_ifla_xdp,
+       [IFLA_EVENT]            = decode_ifla_event,
+       [IFLA_NEW_NETNSID]      = decode_nla_s32,
+       [IFLA_IF_NETNSID]       = decode_nla_s32,
+       [IFLA_CARRIER_UP_COUNT] = decode_nla_u32,
+       [IFLA_CARRIER_DOWN_COUNT]       = decode_nla_u32,
+       [IFLA_NEW_IFINDEX]      = decode_nla_ifindex,
 };
 
 DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
@@ -299,7 +455,7 @@ DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
        if (len >= sizeof(ifinfo)) {
                if (!umoven_or_printaddr(tcp, addr + offset,
                                         sizeof(ifinfo) - offset,
-                                        (void *) &ifinfo + offset)) {
+                                        (char *) &ifinfo + offset)) {
                        PRINT_FIELD_XVAL("", ifinfo, ifi_type,
                                         arp_hardware_types, "ARPHRD_???");
                        PRINT_FIELD_IFINDEX(", ", ifinfo, ifi_index);