[PATCH v2 5/8] tests: check netlink family specific decoder of NETLINK_ROUTE
JingPiao Chen
chenjingpiao at gmail.com
Mon Jul 31 23:48:45 UTC 2017
* tests/netlink_route.c: Include <stdint.h>,
include "test_netlink.h" instead of "netlink.h".
(test_rtnl_unspec): New function.
(main): Use it.
Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
tests/netlink_route.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/tests/netlink_route.c b/tests/netlink_route.c
index 54a54b7..537ab93 100644
--- a/tests/netlink_route.c
+++ b/tests/netlink_route.c
@@ -28,9 +28,10 @@
#include "tests.h"
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
-#include "netlink.h"
+#include "test_netlink.h"
#include <linux/rtnetlink.h>
static void
@@ -92,6 +93,56 @@ test_nlmsg_flags(const int fd)
(unsigned) sizeof(nlh), sprintrc(rc));
}
+static void
+test_rtnl_unspec(const int fd)
+{
+ void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
+
+ /* unspecified family only */
+ uint8_t family = 0;
+ TEST_NETLINK_(fd, nlh0,
+ 0xffff, "0xffff /* RTM_??? */",
+ NLM_F_REQUEST, "NLM_F_REQUEST",
+ sizeof(family), &family, sizeof(family),
+ printf("{family=AF_UNSPEC}"));
+
+ /* unknown family only */
+ family = 0xff;
+ TEST_NETLINK_(fd, nlh0,
+ 0xffff, "0xffff /* RTM_??? */",
+ NLM_F_REQUEST, "NLM_F_REQUEST",
+ sizeof(family), &family, sizeof(family),
+ printf("{family=0xff /* AF_??? */}"));
+
+ /* short read of family */
+ TEST_NETLINK_(fd, nlh0,
+ 0xffff, "0xffff /* RTM_??? */",
+ NLM_F_REQUEST, "NLM_F_REQUEST",
+ sizeof(family), &family, sizeof(family) - 1,
+ printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
+
+ /* unspecified family and string */
+ char buf[sizeof(family) + 4];
+ family = 0;
+ memcpy(buf, &family, sizeof(family));
+ memcpy(buf + sizeof(family), "1234", 4);
+ TEST_NETLINK_(fd, nlh0,
+ 0xffff, "0xffff /* RTM_??? */",
+ NLM_F_REQUEST, "NLM_F_REQUEST",
+ sizeof(buf), buf, sizeof(buf),
+ printf("{family=AF_UNSPEC, \"\\x31\\x32\\x33\\x34\"}"));
+
+ /* unknown family and string */
+ family = 0xfd;
+ memcpy(buf, &family, sizeof(family));
+ TEST_NETLINK_(fd, nlh0,
+ 0xffff, "0xffff /* RTM_??? */",
+ NLM_F_REQUEST, "NLM_F_REQUEST",
+ sizeof(buf), buf, sizeof(buf),
+ printf("{family=%#x /* AF_??? */"
+ ", \"\\x31\\x32\\x33\\x34\"}", family));
+}
+
int main(void)
{
skip_if_unavailable("/proc/self/fd/");
@@ -100,6 +151,7 @@ int main(void)
test_nlmsg_type(fd);
test_nlmsg_flags(fd);
+ test_rtnl_unspec(fd);
printf("+++ exited with 0 +++\n");
--
2.7.4
More information about the Strace-devel
mailing list