[RFC 2/3] netlink: decode netlink message delete flags

JingPiao Chen chenjingpiao at gmail.com
Thu Sep 28 05:13:09 UTC 2017


* netlink.c: Include "xlat/netlink_delete_flags.h".
(decode_nlmsg_flags_crypto): Decode delete flags.
(decode_nlmsg_flags_route): Likewise.
(decode_nlmsg_flags_xfrm): Likewise.
* netlink.h (NLM_F_NONREC): New macro.
* xlat/netlink_delete_flags.in: New file.
* tests/netlink_crypto.c (test_nlmsg_flags): Check this.
* tests/netlink_route.c (test_nlmsg_flags): Likewise.
* tests/netlink_xfrm.c (test_nlmsg_flags): Likewise.
---
 netlink.c                    | 10 ++++++++++
 netlink.h                    |  3 +++
 tests/netlink_crypto.c       | 10 +++++++++-
 tests/netlink_route.c        |  7 +++----
 tests/netlink_xfrm.c         | 10 +++++++++-
 xlat/netlink_delete_flags.in |  1 +
 6 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 xlat/netlink_delete_flags.in

diff --git a/netlink.c b/netlink.c
index f3868bd..30e52db 100644
--- a/netlink.c
+++ b/netlink.c
@@ -34,6 +34,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
 #include "xlat/netlink_ack_flags.h"
+#include "xlat/netlink_delete_flags.h"
 #include "xlat/netlink_flags.h"
 #include "xlat/netlink_get_flags.h"
 #include "xlat/netlink_new_flags.h"
@@ -242,6 +243,9 @@ decode_nlmsg_flags_crypto(const uint16_t type)
 	switch (type) {
 	case CRYPTO_MSG_NEWALG:
 		return netlink_new_flags;
+	case CRYPTO_MSG_DELALG:
+	case CRYPTO_MSG_DELRNG:
+		return netlink_delete_flags;
 	case CRYPTO_MSG_GETALG:
 		return netlink_get_flags;
 	}
@@ -252,11 +256,14 @@ decode_nlmsg_flags_crypto(const uint16_t type)
 static const struct xlat *
 decode_nlmsg_flags_route(const uint16_t type)
 {
+	/* RTM_DELACTION use NLM_F_ROOT flags */
 	if (type == RTM_DELACTION)
 		return netlink_get_flags;
 	switch (type & 3) {
 	case  0:
 		return netlink_new_flags;
+	case  1:
+		return netlink_delete_flags;
 	case  2:
 		return netlink_get_flags;
 	}
@@ -280,6 +287,9 @@ decode_nlmsg_flags_xfrm(const uint16_t type)
 	case XFRM_MSG_NEWSADINFO:
 	case XFRM_MSG_NEWSPDINFO:
 		return netlink_new_flags;
+	case XFRM_MSG_DELSA:
+	case XFRM_MSG_DELPOLICY:
+		return netlink_delete_flags;
 	case XFRM_MSG_GETSA:
 	case XFRM_MSG_GETPOLICY:
 	case XFRM_MSG_GETAE:
diff --git a/netlink.h b/netlink.h
index 31b7876..42e7802 100644
--- a/netlink.h
+++ b/netlink.h
@@ -36,6 +36,9 @@
 # define NETLINK_SOCK_DIAG 4
 #endif
 
+#ifndef NLM_F_NONREC
+# define NLM_F_NONREC	0x100
+#endif
 #ifndef NLM_F_CAPPED
 # define NLM_F_CAPPED	0x100
 #endif
diff --git a/tests/netlink_crypto.c b/tests/netlink_crypto.c
index deb1644..d15c17c 100644
--- a/tests/netlink_crypto.c
+++ b/tests/netlink_crypto.c
@@ -78,9 +78,17 @@ test_nlmsg_flags(const int fd)
 	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
 
 	nlh.nlmsg_type = CRYPTO_MSG_DELALG;
-	nlh.nlmsg_flags = NLM_F_REPLACE;
+	nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_NONREC;
 	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
 	printf("sendto(%d, {len=%u, type=CRYPTO_MSG_DELALG"
+	       ", flags=NLM_F_ECHO|NLM_F_NONREC, seq=0, pid=0}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+
+	nlh.nlmsg_type = CRYPTO_MSG_UPDATEALG;
+	nlh.nlmsg_flags = NLM_F_REPLACE;
+	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+	printf("sendto(%d, {len=%u, type=CRYPTO_MSG_UPDATEALG"
 	       ", flags=%#x /* NLM_F_??? */, seq=0, pid=0}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, nlh.nlmsg_len, NLM_F_REPLACE,
diff --git a/tests/netlink_route.c b/tests/netlink_route.c
index 6af3b13..a1c7d1f 100644
--- a/tests/netlink_route.c
+++ b/tests/netlink_route.c
@@ -132,13 +132,12 @@ test_nlmsg_flags(const int fd)
 	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
 
 	nlh.nlmsg_type = RTM_DELLINK;
-	nlh.nlmsg_flags = NLM_F_REPLACE;
+	nlh.nlmsg_flags = NLM_F_NONREC;
 	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
 	printf("sendto(%d, {len=%u, type=RTM_DELLINK"
-	       ", flags=%#x /* NLM_F_??? */, seq=0, pid=0}"
+	       ", flags=NLM_F_NONREC, seq=0, pid=0}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
-	       fd, nlh.nlmsg_len, NLM_F_REPLACE,
-	       (unsigned) sizeof(nlh), sprintrc(rc));
+	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
 }
 
 static void
diff --git a/tests/netlink_xfrm.c b/tests/netlink_xfrm.c
index 27f62d1..862a9f6 100644
--- a/tests/netlink_xfrm.c
+++ b/tests/netlink_xfrm.c
@@ -76,9 +76,17 @@ test_nlmsg_flags(const int fd)
 	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
 
 	nlh.nlmsg_type = XFRM_MSG_DELSA;
-	nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_REPLACE;
+	nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_NONREC;
 	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
 	printf("sendto(%d, {len=%u, type=XFRM_MSG_DELSA"
+	       ", flags=NLM_F_ECHO|NLM_F_NONREC, seq=0, pid=0}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+
+	nlh.nlmsg_type = XFRM_MSG_ALLOCSPI;
+	nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_REPLACE;
+	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+	printf("sendto(%d, {len=%u, type=XFRM_MSG_ALLOCSPI"
 	       ", flags=NLM_F_ECHO|%#x, seq=0, pid=0}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, nlh.nlmsg_len, NLM_F_REPLACE,
diff --git a/xlat/netlink_delete_flags.in b/xlat/netlink_delete_flags.in
new file mode 100644
index 0000000..01af41d
--- /dev/null
+++ b/xlat/netlink_delete_flags.in
@@ -0,0 +1 @@
+NLM_F_NONREC
-- 
2.7.4





More information about the Strace-devel mailing list