Update strace to 4.25.
Bug: N/A
Test: adb shell strace date
Change-Id: I8c5e68b5fc174b267be9c47ce49bca07a0e5707b
diff --git a/socketutils.c b/socketutils.c
index a646b5b..c3f28a1 100644
--- a/socketutils.c
+++ b/socketutils.c
@@ -48,6 +48,10 @@
#include "xstring.h"
+#define XLAT_MACROS_ONLY
+# include "xlat/inet_protocols.h"
+#undef XLAT_MACROS_ONLY
+
typedef struct {
unsigned long inode;
char *details;
@@ -233,9 +237,9 @@
}
const struct nlmsghdr *h = &hdr_buf.hdr;
- if (!NLMSG_OK(h, ret))
+ if (!is_nlmsg_ok(h, ret))
return false;
- for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {
+ for (; is_nlmsg_ok(h, ret); h = NLMSG_NEXT(h, ret)) {
if (h->nlmsg_type != expected_msg_type)
return false;
const int rc = parser(NLMSG_DATA(h),
@@ -412,11 +416,12 @@
}
static const char *
-unix_get(struct tcb *tcp, const int fd, const unsigned long inode)
+unix_get(struct tcb *tcp, const int fd, const int family, const int proto,
+ const unsigned long inode, const char *name)
{
return unix_send_query(tcp, fd, inode)
&& receive_responses(tcp, fd, inode, SOCK_DIAG_BY_FAMILY,
- unix_parse_response, (void *) "UNIX")
+ unix_parse_response, (void *) name)
? get_sockaddr_by_inode_cached(inode) : NULL;
}
@@ -431,48 +436,63 @@
}
static const char *
-tcp_v4_get(struct tcb *tcp, const int fd, const unsigned long inode)
-{
- return inet_get(tcp, fd, AF_INET, IPPROTO_TCP, inode, "TCP");
-}
-
-static const char *
-udp_v4_get(struct tcb *tcp, const int fd, const unsigned long inode)
-{
- return inet_get(tcp, fd, AF_INET, IPPROTO_UDP, inode, "UDP");
-}
-
-static const char *
-tcp_v6_get(struct tcb *tcp, const int fd, const unsigned long inode)
-{
- return inet_get(tcp, fd, AF_INET6, IPPROTO_TCP, inode, "TCPv6");
-}
-
-static const char *
-udp_v6_get(struct tcb *tcp, const int fd, const unsigned long inode)
-{
- return inet_get(tcp, fd, AF_INET6, IPPROTO_UDP, inode, "UDPv6");
-}
-
-static const char *
-netlink_get(struct tcb *tcp, const int fd, const unsigned long inode)
+netlink_get(struct tcb *tcp, const int fd, const int family, const int protocol,
+ const unsigned long inode, const char *proto_name)
{
return netlink_send_query(tcp, fd, inode)
&& receive_responses(tcp, fd, inode, SOCK_DIAG_BY_FAMILY,
- netlink_parse_response, (void *) "NETLINK")
+ netlink_parse_response,
+ (void *) proto_name)
? get_sockaddr_by_inode_cached(inode) : NULL;
}
static const struct {
const char *const name;
- const char * (*const get)(struct tcb *, int, unsigned long);
+ const char * (*const get)(struct tcb *, int fd, int family,
+ int protocol, unsigned long inode,
+ const char *proto_name);
+ int family;
+ int proto;
} protocols[] = {
- [SOCK_PROTO_UNIX] = { "UNIX", unix_get },
- [SOCK_PROTO_TCP] = { "TCP", tcp_v4_get },
- [SOCK_PROTO_UDP] = { "UDP", udp_v4_get },
- [SOCK_PROTO_TCPv6] = { "TCPv6", tcp_v6_get },
- [SOCK_PROTO_UDPv6] = { "UDPv6", udp_v6_get },
- [SOCK_PROTO_NETLINK] = { "NETLINK", netlink_get }
+ [SOCK_PROTO_UNIX] = { "UNIX", unix_get, AF_UNIX},
+ /*
+ * inet_diag handlers are currently implemented only for TCP,
+ * UDP(lite), SCTP, RAW, and DCCP, but we try to resolve it for all
+ * protocols anyway, just in case.
+ */
+ [SOCK_PROTO_TCP] =
+ { "TCP", inet_get, AF_INET, IPPROTO_TCP },
+ [SOCK_PROTO_UDP] =
+ { "UDP", inet_get, AF_INET, IPPROTO_UDP },
+ [SOCK_PROTO_UDPLITE] =
+ { "UDPLITE", inet_get, AF_INET, IPPROTO_UDPLITE },
+ [SOCK_PROTO_DCCP] =
+ { "DCCP", inet_get, AF_INET, IPPROTO_DCCP },
+ [SOCK_PROTO_SCTP] =
+ { "SCTP", inet_get, AF_INET, IPPROTO_SCTP },
+ [SOCK_PROTO_L2TP_IP] =
+ { "L2TP/IP", inet_get, AF_INET, IPPROTO_L2TP },
+ [SOCK_PROTO_PING] =
+ { "PING", inet_get, AF_INET, IPPROTO_ICMP },
+ [SOCK_PROTO_RAW] =
+ { "RAW", inet_get, AF_INET, IPPROTO_RAW },
+ [SOCK_PROTO_TCPv6] =
+ { "TCPv6", inet_get, AF_INET6, IPPROTO_TCP },
+ [SOCK_PROTO_UDPv6] =
+ { "UDPv6", inet_get, AF_INET6, IPPROTO_UDP },
+ [SOCK_PROTO_UDPLITEv6] =
+ { "UDPLITEv6", inet_get, AF_INET6, IPPROTO_UDPLITE },
+ [SOCK_PROTO_DCCPv6] =
+ { "DCCPv6", inet_get, AF_INET6, IPPROTO_DCCP },
+ [SOCK_PROTO_SCTPv6] =
+ { "SCTPv6", inet_get, AF_INET6, IPPROTO_SCTP },
+ [SOCK_PROTO_L2TP_IPv6] =
+ { "L2TP/IPv6", inet_get, AF_INET6, IPPROTO_L2TP },
+ [SOCK_PROTO_PINGv6] =
+ { "PINGv6", inet_get, AF_INET6, IPPROTO_ICMP },
+ [SOCK_PROTO_RAWv6] =
+ { "RAWv6", inet_get, AF_INET6, IPPROTO_RAW },
+ [SOCK_PROTO_NETLINK] = { "NETLINK", netlink_get, AF_NETLINK },
};
enum sock_proto
@@ -487,6 +507,15 @@
return SOCK_PROTO_UNKNOWN;
}
+int
+get_family_by_proto(enum sock_proto proto)
+{
+ if ((size_t) proto < ARRAY_SIZE(protocols))
+ return protocols[proto].family;
+
+ return AF_UNSPEC;
+}
+
static const char *
get_sockaddr_by_inode_uncached(struct tcb *tcp, const unsigned long inode,
const enum sock_proto proto)
@@ -501,14 +530,20 @@
const char *details = NULL;
if (proto != SOCK_PROTO_UNKNOWN) {
- details = protocols[proto].get(tcp, fd, inode);
+ details = protocols[proto].get(tcp, fd, protocols[proto].family,
+ protocols[proto].proto, inode,
+ protocols[proto].name);
} else {
unsigned int i;
for (i = (unsigned int) SOCK_PROTO_UNKNOWN + 1;
i < ARRAY_SIZE(protocols); ++i) {
if (!protocols[i].get)
continue;
- details = protocols[i].get(tcp, fd, inode);
+ details = protocols[i].get(tcp, fd,
+ protocols[proto].family,
+ protocols[proto].proto,
+ inode,
+ protocols[proto].name);
if (details)
break;
}