]> granicus.if.org Git - strace/commitdiff
Change unix_diag requests back to use full dump instead of exact match
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 19 Feb 2016 01:30:34 +0000 (01:30 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 19 Feb 2016 01:44:33 +0000 (01:44 +0000)
Unfortunately, 64-bit linux kernel has a bug in matching inode numbers
greater than INT_MAX, so unix_diag exact match is not reliable.

This partially reverts commit 69bfc89770152033d4aa0bc5673fc46e65d89838.

* socketutils.c (unix_send_query): Add NLM_F_DUMP to nlmsg_flags,
remove initialization of udiag_cookie.
* tests/netlink_unix_diag.c (send_query): Remove "inode" argument,
add NLM_F_DUMP to nlmsg_flags, remove initialization of udiag_ino
and udiag_cookie.
(check_responses): Remove "inode" argument and its use.
(main): Remove invocation of inode_of_sockfd and passing of listening
socket inode to send_query and check_responses.

socketutils.c
tests/netlink_unix_diag.c

index 43758424a9a32019db881bdf8e1feacd866f0bc3..640c6732198c19e38e2b1a9e742e9b8d6e796a9e 100644 (file)
@@ -242,14 +242,13 @@ 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_REQUEST
+                       .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
                },
                .udr = {
                        .sdiag_family = AF_UNIX,
                        .udiag_ino = inode,
                        .udiag_states = -1,
-                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER,
-                       .udiag_cookie = { ~0U, ~0U }
+                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER
                }
        };
        struct iovec iov = {
index 932a9e184e0dd533d08bc929a42812b5d59dcae7..5d760a253757cbfae6333758cbf909439d6dd386 100644 (file)
@@ -45,7 +45,7 @@
 #endif
 
 static void
-send_query(const int fd, const unsigned int inode)
+send_query(const int fd)
 {
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
@@ -57,14 +57,12 @@ send_query(const int fd, const unsigned int inode)
                .nlh = {
                        .nlmsg_len = sizeof(req),
                        .nlmsg_type = SOCK_DIAG_BY_FAMILY,
-                       .nlmsg_flags = NLM_F_REQUEST
+                       .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP
                },
                .udr = {
                        .sdiag_family = AF_UNIX,
-                       .udiag_ino = inode,
                        .udiag_states = -1,
-                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER,
-                       .udiag_cookie = { ~0U, ~0U }
+                       .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER
                }
        };
        struct iovec iov = {
@@ -83,7 +81,7 @@ send_query(const int fd, const unsigned int inode)
 }
 
 static void
-check_responses(const int fd, const unsigned int inode)
+check_responses(const int fd)
 {
        static char buf[8192];
        struct sockaddr_nl nladdr = {
@@ -121,8 +119,6 @@ check_responses(const int fd, const unsigned int inode)
        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"
@@ -150,8 +146,7 @@ int main(void)
        if (socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG) != 1)
                perror_msg_and_skip("socket AF_NETLINK");
 
-       unsigned int inode = inode_of_sockfd(0);
-       send_query(1, inode);
-       check_responses(1, inode);
+       send_query(1);
+       check_responses(1);
        return 0;
 }