[PATCH 2/2] tests: add check for decoding netlink get and new flags
JingPiao Chen
chenjingpiao at gmail.com
Wed Jun 7 15:35:19 UTC 2017
* tests/netlink_route.c: Add check for
NETLINK_ROUTE get and new flags.
* tests/netlink_sock_diag.c: Add check for
NETLINK_SOCK_DIAG get flags.
* tests/netlink_xfrm.c: Add check for
NETLINK_XFRM get and new flags.
---
tests/netlink_route.c | 43 +++++++++++++++++++++++++++++++++++++++++++
tests/netlink_sock_diag.c | 18 ++++++++++++++++++
tests/netlink_xfrm.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+)
diff --git a/tests/netlink_route.c b/tests/netlink_route.c
index 7946121..ec97256 100644
--- a/tests/netlink_route.c
+++ b/tests/netlink_route.c
@@ -50,6 +50,48 @@ test_nlmsg_type(const int fd)
fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
}
+static void
+test_nlmsg_flags(const int fd)
+{
+ long rc;
+ struct nlmsghdr nlh = {
+ .nlmsg_len = sizeof(nlh),
+ };
+
+ nlh.nlmsg_type = RTM_GETLINK;
+ nlh.nlmsg_flags = NLM_F_DUMP;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=RTM_GETLINK"
+ ", flags=NLM_F_DUMP, seq=0, pid=0}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+
+ nlh.nlmsg_type = RTM_DELACTION;
+ nlh.nlmsg_flags = NLM_F_DUMP;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=RTM_DELACTION"
+ ", flags=NLM_F_DUMP, seq=0, pid=0}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+
+ nlh.nlmsg_type = RTM_NEWLINK;
+ nlh.nlmsg_flags = NLM_F_REPLACE;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=RTM_NEWLINK"
+ ", flags=NLM_F_REPLACE, seq=0, pid=0}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+
+ nlh.nlmsg_type = RTM_DELLINK;
+ nlh.nlmsg_flags = NLM_F_REPLACE;
+ 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}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, NLM_F_REPLACE,
+ (unsigned) sizeof(nlh), sprintrc(rc));
+}
+
int main(void)
{
skip_if_unavailable("/proc/self/fd/");
@@ -57,6 +99,7 @@ int main(void)
int fd = create_nl_socket(NETLINK_ROUTE);
test_nlmsg_type(fd);
+ test_nlmsg_flags(fd);
printf("+++ exited with 0 +++\n");
diff --git a/tests/netlink_sock_diag.c b/tests/netlink_sock_diag.c
index 09eb2bf..943e90b 100644
--- a/tests/netlink_sock_diag.c
+++ b/tests/netlink_sock_diag.c
@@ -55,6 +55,23 @@ test_nlmsg_type(const int fd)
fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
}
+static void
+test_nlmsg_flags(const int fd)
+{
+ long rc;
+ struct nlmsghdr nlh = {
+ .nlmsg_len = sizeof(nlh),
+ .nlmsg_type = SOCK_DIAG_BY_FAMILY,
+ .nlmsg_flags = NLM_F_DUMP,
+ };
+
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+ ", flags=NLM_F_DUMP, seq=0, pid=0}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+}
+
int main(void)
{
skip_if_unavailable("/proc/self/fd/");
@@ -62,6 +79,7 @@ int main(void)
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
test_nlmsg_type(fd);
+ test_nlmsg_flags(fd);
printf("+++ exited with 0 +++\n");
diff --git a/tests/netlink_xfrm.c b/tests/netlink_xfrm.c
index fa50080..f75c43f 100644
--- a/tests/netlink_xfrm.c
+++ b/tests/netlink_xfrm.c
@@ -51,6 +51,40 @@ test_nlmsg_type(const int fd)
fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
}
+static void
+test_nlmsg_flags(const int fd)
+{
+ long rc;
+ struct nlmsghdr nlh = {
+ .nlmsg_len = sizeof(nlh),
+ };
+
+ nlh.nlmsg_type = XFRM_MSG_GETSA;
+ nlh.nlmsg_flags = NLM_F_DUMP;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=XFRM_MSG_GETSA"
+ ", flags=NLM_F_DUMP, 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_NEWSA;
+ nlh.nlmsg_flags = NLM_F_REPLACE;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=XFRM_MSG_NEWSA"
+ ", flags=NLM_F_REPLACE, 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_DELSA;
+ nlh.nlmsg_flags = NLM_F_REPLACE;
+ rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ printf("sendto(%d, {{len=%u, type=XFRM_MSG_DELSA"
+ ", flags=%#x /* NLM_F_??? */, seq=0, pid=0}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ fd, nlh.nlmsg_len, NLM_F_REPLACE,
+ (unsigned) sizeof(nlh), sprintrc(rc));
+}
+
int main(void)
{
skip_if_unavailable("/proc/self/fd/");
@@ -58,6 +92,7 @@ int main(void)
int fd = create_nl_socket(NETLINK_XFRM);
test_nlmsg_type(fd);
+ test_nlmsg_flags(fd);
printf("+++ exited with 0 +++\n");
--
2.7.4
More information about the Strace-devel
mailing list