]> granicus.if.org Git - strace/commitdiff
Change unix_diag requests to use exact match instead of full dump
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 31 Jan 2016 00:35:29 +0000 (00:35 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 3 Feb 2016 12:43:22 +0000 (12:43 +0000)
* socketutils.c (unix_send_query): Remove NLM_F_DUMP from nlmsg_flags,
initialize udiag_cookie.
* tests/netlink_unix_diag.c (send_query): Remove "family" and "proto"
arguments, add "inode" argument, remove NLM_F_DUMP from nlmsg_flags,
initialize udiag_ino and udiag_cookie.
(check_responses): Add "inode" argument, check inode match.
(main): Pass listening socket inode to send_query and check_responses.

socketutils.c
tests/netlink_unix_diag.c

index 6fbb8cfef5a317f93dffc3bc1ec3e8d46b3db168..7046d29897e1fd6fb264ca2c50d8740e5887d8c4 100644 (file)
@@ -209,13 +209,14 @@ unix_send_query(const int fd, const unsigned long inode)
                .nlh = {
                        .nlmsg_len = sizeof(req),
                        .nlmsg_type = SOCK_DIAG_BY_FAMILY,
-                       .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
+                       .nlmsg_flags = NLM_F_REQUEST
                },
                .udr = {
                        .sdiag_family = AF_UNIX,
                        .udiag_ino = inode,
                        .udiag_states = -1,
-                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER
+                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER,
+                       .udiag_cookie = { ~0U, ~0U }
                }
        };
        struct iovec iov = {
index 12033e0fc7f07a91ce05008d8bb9ffd0854becab..932a9e184e0dd533d08bc929a42812b5d59dcae7 100644 (file)
@@ -45,7 +45,7 @@
 #endif
 
 static void
-send_query(const int fd, const int family, const int proto)
+send_query(const int fd, const unsigned int inode)
 {
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
@@ -57,13 +57,14 @@ send_query(const int fd, const int family, const int proto)
                .nlh = {
                        .nlmsg_len = sizeof(req),
                        .nlmsg_type = SOCK_DIAG_BY_FAMILY,
-                       .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
+                       .nlmsg_flags = NLM_F_REQUEST
                },
                .udr = {
-                       .sdiag_family = family,
-                       .sdiag_protocol = proto,
+                       .sdiag_family = AF_UNIX,
+                       .udiag_ino = inode,
                        .udiag_states = -1,
-                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER
+                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER,
+                       .udiag_cookie = { ~0U, ~0U }
                }
        };
        struct iovec iov = {
@@ -82,7 +83,7 @@ send_query(const int fd, const int family, const int proto)
 }
 
 static void
-check_responses(const int fd)
+check_responses(const int fd, const unsigned int inode)
 {
        static char buf[8192];
        struct sockaddr_nl nladdr = {
@@ -120,6 +121,8 @@ check_responses(const int fd)
        const struct unix_diag_msg *diag = NLMSG_DATA(h);
        if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*diag)))
                error_msg_and_skip("short response");
+       if (diag->udiag_ino != inode)
+               error_msg_and_skip("inode mismatch");
 }
 
 #define SUN_PATH "netlink_unix_diag_socket"
@@ -147,7 +150,8 @@ int main(void)
        if (socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG) != 1)
                perror_msg_and_skip("socket AF_NETLINK");
 
-       send_query(1, AF_UNIX, 0);
-       check_responses(1);
+       unsigned int inode = inode_of_sockfd(0);
+       send_query(1, inode);
+       check_responses(1, inode);
        return 0;
 }