]> granicus.if.org Git - strace/commitdiff
tests: check decoding of udev_monitor_netlink_header
authorHarsha Sharma <harshasharmaiitr@gmail.com>
Sun, 8 Apr 2018 18:18:56 +0000 (23:48 +0530)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 11 Apr 2018 22:01:37 +0000 (22:01 +0000)
* tests/netlink_kobject_uevent.c: Include <string.h>, <arpa/inet.h>,
and "netlink_kobject_uevent.h".
(test_nlmsg_type_udev, test_nlmsg_type_kernel): New functions.
(main): Use them.

tests/netlink_kobject_uevent.c

index 7edacd7d26677736ab421e5cc01cfe0bab89ff84..29cf85c2489e1323608b3002e03e99cf7c5f7bd6 100644 (file)
  */
 
 #include "tests.h"
+#include <string.h>
 #include <stdio.h>
 #include <sys/socket.h>
+#include <arpa/inet.h>
 #include "netlink.h"
+#include "netlink_kobject_uevent.h"
 
 static const char *errstr;
 
@@ -41,6 +44,79 @@ sys_send(const int fd, const void *const buf, const size_t len)
        return rc;
 }
 
+static void
+test_nlmsg_type_udev(const int fd)
+{
+       unsigned int offset = 8;
+       struct udev_monitor_netlink_header uh = {
+               .prefix = "libudev",
+               .magic = htonl(0xfeedcafe),
+               .header_size = sizeof(uh),
+               .properties_off = 40,
+               .properties_len = 299,
+               .filter_subsystem_hash = htonl(0xc370b302),
+               .filter_devtype_hash = htonl(0x10800000),
+               .filter_tag_bloom_hi = htonl(0x2000400),
+               .filter_tag_bloom_lo = htonl(0x10800000),
+       };
+       unsigned int len = sizeof(uh);
+       char buf[len + offset];
+       memcpy(buf, &uh, len);
+       memcpy(buf + len, "12345678", offset);
+
+       sys_send(fd, &uh, len);
+       printf("sendto(%d, {{prefix=\"%s\", magic=htonl(%#x)"
+              ", header_size=%u, properties_off=%u, properties_len=%u"
+              ", filter_subsystem_hash=htonl(%#x)"
+              ", filter_devtype_hash=htonl(%#x)"
+              ", filter_tag_bloom_hi=htonl(%#x)"
+              ", filter_tag_bloom_lo=htonl(%#x)}}, %u, MSG_DONTWAIT, NULL, "
+              "0) = %s\n"
+              , fd, uh.prefix,
+              ntohl(uh.magic), uh.header_size, uh.properties_off,
+              uh.properties_len, ntohl(uh.filter_subsystem_hash),
+              ntohl(uh.filter_devtype_hash), ntohl(uh.filter_tag_bloom_hi),
+              ntohl(uh.filter_tag_bloom_lo), len, errstr);
+
+       sys_send(fd, &buf, len + offset);
+       printf("sendto(%d, {{prefix=\"%s\", magic=htonl(%#x)"
+              ", header_size=%u, properties_off=%u, properties_len=%u"
+              ", filter_subsystem_hash=htonl(%#x)"
+              ", filter_devtype_hash=htonl(%#x)"
+              ", filter_tag_bloom_hi=htonl(%#x)"
+              ", filter_tag_bloom_lo=htonl(%#x)}, "
+              , fd, uh.prefix,
+              ntohl(uh.magic), uh.header_size, uh.properties_off,
+              uh.properties_len, ntohl(uh.filter_subsystem_hash),
+              ntohl(uh.filter_devtype_hash), ntohl(uh.filter_tag_bloom_hi),
+              ntohl(uh.filter_tag_bloom_lo));
+       print_quoted_memory(buf + len, offset);
+       printf("}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              len + offset, errstr);
+
+}
+
+static void
+test_nlmsg_type_kernel(const int fd)
+{
+       struct udev_monitor_netlink_header uh = {
+               .prefix = "change@",
+               .magic = htonl(0xfeedcafe),
+               .header_size = sizeof(uh),
+               .properties_off = 10,
+               .properties_len = 299,
+               .filter_subsystem_hash = htonl(0xfffffff),
+               .filter_devtype_hash = htonl(0x10000000),
+               .filter_tag_bloom_hi = htonl(0x2000400),
+       };
+
+       sys_send(fd, &uh, sizeof(uh));
+       printf("sendto(%d, ", fd);
+       print_quoted_memory(&uh, DEFAULT_STRLEN);
+       printf("..., %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              (unsigned) sizeof(uh), errstr);
+}
+
 int
 main(void)
 {
@@ -48,6 +124,8 @@ main(void)
 
        int fd = create_nl_socket(NETLINK_KOBJECT_UEVENT);
 
+       test_nlmsg_type_udev(fd);
+       test_nlmsg_type_kernel(fd);
        /* test using data that looks like a zero-length C string */
        char *const buf = tail_alloc(DEFAULT_STRLEN + 1);
        buf[0] = '=';