summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2022-07-24 14:44:50 +0200
committerDmitry V. Levin <ldv@strace.io>2022-07-31 21:03:01 +0000
commit70424e674b8644be675587389c31afdae29b9132 (patch)
tree22223c7783ba86211fc32b290f51e181732bb3e7
parent23ea5a07159ebc1826c5a6d6879bff761e3dec62 (diff)
downloadstrace-70424e674b8644be675587389c31afdae29b9132.tar.gz
netlink_inet_diag: decode INET_DIAG_PROTOCOL using decode_nla_ip_proto
* src/netlink_inet_diag.c (inet_diag_msg_nla_decoders) <[INET_DIAG_PROTOCOL]>: Change the value from decode_nla_u8 to decode_nla_ip_proto. * tests/nlattr_inet_diag_msg.c: Add checks. * NEWS: Mention it.
-rw-r--r--NEWS4
-rw-r--r--src/netlink_inet_diag.c2
-rw-r--r--tests/nlattr_inet_diag_msg.c18
3 files changed, 21 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 15a11001f..b546164c1 100644
--- a/NEWS
+++ b/NEWS
@@ -8,8 +8,8 @@ Noteworthy changes in release ?.?? (????-??-??)
* Improvements
* Implemented printing of Unix socket sun_path field's SELinux context.
- * Improved decoding of INET_DIAG_MD5SIG, INET_DIAG_REQ_PROTOCOL,
- INET_DIAG_SHUTDOWN, INET_DIAG_SK_BPF_STORAGES,
+ * Improved decoding of INET_DIAG_MD5SIG, INET_DIAG_PROTOCOL,
+ INET_DIAG_REQ_PROTOCOL, INET_DIAG_SHUTDOWN, INET_DIAG_SK_BPF_STORAGES,
and INET_DIAG_ULP_INFO NETLINK_SOCK_DIAG netlink attributes.
* Updated the list of NET_IPV4_CONF_* constants.
* Updated lists of ioctl commands from Linux 5.19.
diff --git a/src/netlink_inet_diag.c b/src/netlink_inet_diag.c
index c4a3d4e5a..8b1a6ac2f 100644
--- a/src/netlink_inet_diag.c
+++ b/src/netlink_inet_diag.c
@@ -677,7 +677,7 @@ static const nla_decoder_t inet_diag_msg_nla_decoders[] = {
[INET_DIAG_SKMEMINFO] = decode_nla_meminfo,
[INET_DIAG_SHUTDOWN] = decode_diag_shutdown,
[INET_DIAG_DCTCPINFO] = decode_tcp_dctcp_info,
- [INET_DIAG_PROTOCOL] = decode_nla_u8,
+ [INET_DIAG_PROTOCOL] = decode_nla_ip_proto,
[INET_DIAG_SKV6ONLY] = decode_nla_u8,
[INET_DIAG_LOCALS] = NULL, /* unimplemented */
[INET_DIAG_PEERS] = NULL, /* unimplemented */
diff --git a/tests/nlattr_inet_diag_msg.c b/tests/nlattr_inet_diag_msg.c
index fbfd326a2..5a3bf040c 100644
--- a/tests/nlattr_inet_diag_msg.c
+++ b/tests/nlattr_inet_diag_msg.c
@@ -336,6 +336,24 @@ main(void)
DEFAULT_STRLEN, str, DEFAULT_STRLEN,
printf("\"%s\"", str));
+ /* INET_DIAG_PROTOCOL */
+ static const struct strval8 protos[] = {
+ { 0, "IPPROTO_IP" },
+ { 2, "IPPROTO_IGMP" },
+ { 5, "0x5 /* IPPROTO_??? */" },
+ { 6, "IPPROTO_TCP" },
+ { 190, "0xbe /* IPPROTO_??? */" },
+ { 255, "IPPROTO_RAW" },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(protos); i++) {
+ TEST_NLATTR(fd, nlh0, hdrlen,
+ init_inet_diag_msg, print_inet_diag_msg,
+ INET_DIAG_PROTOCOL,
+ sizeof(uint8_t), &protos[i].val, sizeof(uint8_t),
+ printf("%s", protos[i].str));
+ }
+
/* INET_DIAG_MD5SIG */
struct tcp_diag_md5sig md5s_arr[ARRAY_SIZE(md5sig_vecs)];