]> granicus.if.org Git - strace/commitdiff
socketeutils: extend receive_responses to handle other netlink types
authorMasatake YAMATO <yamato@redhat.com>
Sun, 11 Jun 2017 07:42:27 +0000 (16:42 +0900)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 12 Jun 2017 16:43:49 +0000 (16:43 +0000)
This is the first patch in series of implementing NETLINK_GENERIC
protocol decoder.

receive_responses was written for decoding kernel responses of type
SOCK_DIAG_BY_FAMILY, other types were ignored.

This change makes the type of netlink response a parameter
so the function can be used for other types of communication.

* socketutils.c (receive_responses): add a new parameter
expected_msg_type to handle types other than SOCK_DIAG_BY_FAMILY.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
socketutils.c

index a3aedb4e4d976fe924f9ec8115630b7bb3730919..01d369e1958ff92070648f6c2122cf8dfede37a3 100644 (file)
@@ -189,6 +189,7 @@ inet_parse_response(const char *const proto_name, const void *const data,
 
 static bool
 receive_responses(const int fd, const unsigned long inode,
+                 const unsigned long expected_msg_type,
                  const char *proto_name,
                  int (* parser) (const char *, const void *,
                                  int, unsigned long))
@@ -226,7 +227,7 @@ receive_responses(const int fd, const unsigned long inode,
                if (!NLMSG_OK(h, ret))
                        return false;
                for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {
-                       if (h->nlmsg_type != SOCK_DIAG_BY_FAMILY)
+                       if (h->nlmsg_type != expected_msg_type)
                                return false;
                        const int rc = parser(proto_name, NLMSG_DATA(h),
                                              h->nlmsg_len, inode);
@@ -396,7 +397,8 @@ static const char *
 unix_get(const int fd, const unsigned long inode)
 {
        return unix_send_query(fd, inode)
-               && receive_responses(fd, inode, "UNIX", unix_parse_response)
+               && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY,
+                                    "UNIX", unix_parse_response)
                ? get_sockaddr_by_inode_cached(inode) : NULL;
 }
 
@@ -405,7 +407,8 @@ inet_get(const int fd, const int family, const int protocol,
         const unsigned long inode, const char *proto_name)
 {
        return inet_send_query(fd, family, protocol)
-               && receive_responses(fd, inode, proto_name, inet_parse_response)
+               && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY,
+                                    proto_name, inet_parse_response)
                ? get_sockaddr_by_inode_cached(inode) : NULL;
 }
 
@@ -437,8 +440,8 @@ static const char *
 netlink_get(const int fd, const unsigned long inode)
 {
        return netlink_send_query(fd, inode)
-               && receive_responses(fd, inode, "NETLINK",
-                                    netlink_parse_response)
+               && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY,
+                                    "NETLINK", netlink_parse_response)
                ? get_sockaddr_by_inode_cached(inode) : NULL;
 }