summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2021-08-03 19:40:01 +0200
committerDmitry V. Levin <ldv@strace.io>2021-08-03 17:40:01 +0000
commita9977b6e7f9c46b817eb38e7bdffa659da9cbda5 (patch)
tree2a72496c9a2f325f60f19fd75b40834262612fa0
parent622860bcff04de1086a591a08bf49e9a380bef7c (diff)
downloadstrace-a9977b6e7f9c46b817eb38e7bdffa659da9cbda5.tar.gz
rtnl_link: implement IFLA_PROTO_DOWN_REASON attribute decoding
IFLA_PROTO_DOWN_REASON is a nested attribute introduced by Linux commit v5.9-rc1~133^2~77. * src/xlat/rtnl_ifla_proto_down_reason_attrs.in: New file. * src/rtnl_link.c: Include "xlat/rtnl_ifla_proto_down_reason_attrs.h". (ifla_proto_down_reason_nla_decoders): New decoder table. (decode_ifla_proto_down_reason): New function. (ifinfomsg_nla_decoders) <[IFLA_PROTO_DOWN_REASON]>: New decoder, calls decode_ifla_proto_down_reason. * NEWS: Mention this. * tests/nlattr_ifla_proto_down_reason.c: New file. * tests/.gitignore: Add nlattr_ifla_proto_down_reason. * tests/pure_executables.list: Likewise. * tests/gen_tests.in (nlattr_ifla_proto_down_reason): New test.
-rw-r--r--NEWS1
-rw-r--r--src/rtnl_link.c21
-rw-r--r--src/xlat/rtnl_ifla_proto_down_reason_attrs.in5
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/gen_tests.in1
-rw-r--r--tests/nlattr_ifla_proto_down_reason.c82
-rwxr-xr-xtests/pure_executables.list1
7 files changed, 112 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 293fabcb2..c65d9dcf1 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Noteworthy changes in release ?.?? (????-??-??)
* Improvements
* Implemented decoding of memfd_secret and quotactl_fd syscalls,
introduced in Linux 5.14.
+ * Enhanced decoding of IFLA_* netlink attributes.
* Updated lists of BPF_*, IORING_*, MADV_*, SCTP_*, and UFFD_* constants.
* Bug fixes
diff --git a/src/rtnl_link.c b/src/rtnl_link.c
index 165d26bcb..2769ad917 100644
--- a/src/rtnl_link.c
+++ b/src/rtnl_link.c
@@ -30,6 +30,7 @@
#include "xlat/rtnl_ifla_info_data_bridge_attrs.h"
#include "xlat/rtnl_ifla_info_data_tun_attrs.h"
#include "xlat/rtnl_ifla_port_attrs.h"
+#include "xlat/rtnl_ifla_proto_down_reason_attrs.h"
#include "xlat/rtnl_ifla_vf_port_attrs.h"
#include "xlat/rtnl_ifla_xdp_attached_mode.h"
#include "xlat/rtnl_ifla_xdp_attrs.h"
@@ -926,6 +927,25 @@ decode_ifla_prop_list(struct tcb *const tcp,
return true;
}
+static const nla_decoder_t ifla_proto_down_reason_nla_decoders[] = {
+ [IFLA_PROTO_DOWN_REASON_UNSPEC] = NULL,
+ [IFLA_PROTO_DOWN_REASON_MASK] = decode_nla_x32,
+ [IFLA_PROTO_DOWN_REASON_VALUE] = decode_nla_x32,
+};
+
+static bool
+decode_ifla_proto_down_reason(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_proto_down_reason_attrs,
+ "IFLA_PROTO_DOWN_REASON_???",
+ ARRSZ_PAIR(ifla_proto_down_reason_nla_decoders),
+ opaque_data);
+
+ return true;
+}
static const nla_decoder_t ifinfomsg_nla_decoders[] = {
[IFLA_ADDRESS] = decode_ifla_hwaddr,
@@ -982,6 +1002,7 @@ static const nla_decoder_t ifinfomsg_nla_decoders[] = {
[IFLA_PROP_LIST] = decode_ifla_prop_list,
[IFLA_ALT_IFNAME] = decode_nla_str,
[IFLA_PERM_ADDRESS] = decode_ifla_hwaddr,
+ [IFLA_PROTO_DOWN_REASON] = decode_ifla_proto_down_reason,
};
DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
diff --git a/src/xlat/rtnl_ifla_proto_down_reason_attrs.in b/src/xlat/rtnl_ifla_proto_down_reason_attrs.in
new file mode 100644
index 000000000..4b5469b8d
--- /dev/null
+++ b/src/xlat/rtnl_ifla_proto_down_reason_attrs.in
@@ -0,0 +1,5 @@
+#unconditional
+#value_indexed
+IFLA_PROTO_DOWN_REASON_UNSPEC
+IFLA_PROTO_DOWN_REASON_MASK
+IFLA_PROTO_DOWN_REASON_VALUE
diff --git a/tests/.gitignore b/tests/.gitignore
index abf5eb767..abed1b4fd 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -522,6 +522,7 @@ nlattr_ifla_af_spec
nlattr_ifla_brport
nlattr_ifla_linkinfo
nlattr_ifla_port
+nlattr_ifla_proto_down_reason
nlattr_ifla_xdp
nlattr_ifla_xdp-y
nlattr_inet_diag_msg
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 60fce6a34..0442749c8 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -497,6 +497,7 @@ nlattr_ifla_af_spec +netlink_sock_diag.test
nlattr_ifla_brport +netlink_sock_diag.test
nlattr_ifla_linkinfo +netlink_sock_diag.test
nlattr_ifla_port +netlink_sock_diag.test
+nlattr_ifla_proto_down_reason +netlink_sock_diag.test
nlattr_ifla_xdp +netlink_sock_diag.test
nlattr_ifla_xdp-y +netlink_sock_diag.test -y; exec 9</dev/full
nlattr_inet_diag_msg +netlink_sock_diag.test
diff --git a/tests/nlattr_ifla_proto_down_reason.c b/tests/nlattr_ifla_proto_down_reason.c
new file mode 100644
index 000000000..94d72ded1
--- /dev/null
+++ b/tests/nlattr_ifla_proto_down_reason.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
+ * Copyright (c) 2017-2021 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <stdio.h>
+#include "test_nlattr.h"
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_link.h>
+#include <linux/rtnetlink.h>
+
+#define XLAT_MACROS_ONLY
+# include "xlat/rtnl_ifla_proto_down_reason_attrs.h"
+#undef XLAT_MACROS_ONLY
+
+#define IFLA_ATTR IFLA_PROTO_DOWN_REASON
+#include "nlattr_ifla.h"
+
+int
+main(void)
+{
+ skip_if_unavailable("/proc/self/fd/");
+
+ const union {
+ uint8_t bytes[4];
+ uint32_t num;
+ } num = { .num=0xabacdbcd };
+ const int fd = create_nl_socket(NETLINK_ROUTE);
+ void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
+ NLA_HDRLEN + sizeof(num));
+
+ static char pattern[4096];
+ fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
+
+ static const struct {
+ uint8_t val;
+ const char *str;
+ } inv_attrs[] = {
+ { ARG_STR(IFLA_PROTO_DOWN_REASON_UNSPEC) },
+ { ARG_STR(0x3) " /* IFLA_PROTO_DOWN_REASON_??? */" },
+ { ARG_STR(0xfe) " /* IFLA_PROTO_DOWN_REASON_??? */" },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(inv_attrs); i++) {
+ TEST_NESTED_NLATTR_OBJECT_EX_(fd, nlh0, hdrlen,
+ init_ifinfomsg, print_ifinfomsg,
+ inv_attrs[i].val,
+ inv_attrs[i].str,
+ pattern, num,
+ print_quoted_hex, 1,
+ printf("\"\\x%x\\x%x\\x%x\\x%x\"",
+ num.bytes[0], num.bytes[1],
+ num.bytes[2], num.bytes[3])
+ );
+ }
+
+ static const struct {
+ uint32_t val;
+ const char *str;
+ } attrs[] = {
+ { ARG_STR(IFLA_PROTO_DOWN_REASON_MASK) },
+ { ARG_STR(IFLA_PROTO_DOWN_REASON_VALUE) },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(attrs); i++) {
+ TEST_NESTED_NLATTR_OBJECT_EX_(fd, nlh0, hdrlen,
+ init_ifinfomsg, print_ifinfomsg,
+ attrs[i].val, attrs[i].str,
+ pattern, num,
+ print_quoted_hex, 1,
+ printf("%#x", num.num));
+ }
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index 892d87fc5..c940251ce 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -386,6 +386,7 @@ nlattr_ifla_af_spec
nlattr_ifla_brport
nlattr_ifla_linkinfo
nlattr_ifla_port
+nlattr_ifla_proto_down_reason
nlattr_ifla_xdp
nlattr_inet_diag_msg
nlattr_inet_diag_req_compat