Currently, the "net -s" command fails to show an IPv6 address. For
example:
crash> net -s
PID: 305524 TASK: ffff9bc449895580 CPU: 6 COMMAND: "sshd"
FD SOCKET SOCK FAMILY:TYPE SOURCE-PORT DESTINATION-PORT
3 ffff9bc446e9a680 ffff9bc4455b5940 UNIX:DGRAM
4 ffff9bc446e9c600 ffff9bc3b2b24e00 INET6:STREAM
With the patch:
crash> net -s
PID: 305524 TASK: ffff9bc449895580 CPU: 6 COMMAND: "sshd"
FD SOCKET SOCK FAMILY:TYPE SOURCE-PORT DESTINATION-PORT
3 ffff9bc446e9a680 ffff9bc4455b5940 UNIX:DGRAM
4 ffff9bc446e9c600 ffff9bc3b2b24e00 INET6:STREAM xxxx:xx:x:xxxx:xxxx:xxxx:xxxx:xxxx-22
yyyy:yy:y:yyyy:yyyy:yyyy:yyyy:yyyy-44870
Let's support displaying the IPv6 address and port in the SOURCE-PORT
and DESTINATION-PORT colums.
Reported-by: Buland Kumar Singh <bsingh(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
defs.h | 3 +++
net.c | 40 ++++++++++++++++++++++++++++------------
symbols.c | 6 ++++++
3 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/defs.h b/defs.h
index 33a823b7b67c..db20056dc3ed 100644
--- a/defs.h
+++ b/defs.h
@@ -2204,6 +2204,9 @@ struct offset_table { /* stash of commonly-used
offsets */
long maple_range_64_slot;
long maple_metadata_end;
long maple_metadata_gap;
+ long sock_sk_common;
+ long sock_common_skc_v6_daddr;
+ long sock_common_skc_v6_rcv_saddr;
};
struct size_table { /* stash of commonly-used sizes */
diff --git a/net.c b/net.c
index 7c9c8bd9c98d..7af299d0774d 100644
--- a/net.c
+++ b/net.c
@@ -198,6 +198,9 @@ net_init(void)
*/
MEMBER_OFFSET_INIT(sock_common_skc_family,
"sock_common", "skc_family");
+ MEMBER_OFFSET_INIT(sock_sk_common, "sock", "__sk_common");
+ MEMBER_OFFSET_INIT(sock_common_skc_v6_daddr, "sock_common",
"skc_v6_daddr");
+ MEMBER_OFFSET_INIT(sock_common_skc_v6_rcv_saddr, "sock_common",
"skc_v6_rcv_saddr");
MEMBER_OFFSET_INIT(sock_sk_type, "sock", "sk_type");
/*
* struct inet_sock {
@@ -1104,19 +1107,32 @@ get_sock_info(ulong sock, char *buf)
break;
case SOCK_V2:
- if (INVALID_MEMBER(ipv6_pinfo_rcv_saddr) ||
- INVALID_MEMBER(ipv6_pinfo_daddr))
- break;
-
- ipv6_rcv_saddr = ipv6_pinfo + OFFSET(ipv6_pinfo_rcv_saddr);
- ipv6_daddr = ipv6_pinfo + OFFSET(ipv6_pinfo_daddr);
-
- if (!readmem(ipv6_rcv_saddr, KVADDR, u6_addr16_src, SIZE(in6_addr),
- "ipv6_rcv_saddr buffer", QUIET|RETURN_ON_ERROR))
- break;
- if (!readmem(ipv6_daddr, KVADDR, u6_addr16_dest, SIZE(in6_addr),
- "ipv6_daddr buffer", QUIET|RETURN_ON_ERROR))
+ if (VALID_MEMBER(ipv6_pinfo_rcv_saddr) &&
+ VALID_MEMBER(ipv6_pinfo_daddr)) {
+ ipv6_rcv_saddr = ipv6_pinfo + OFFSET(ipv6_pinfo_rcv_saddr);
+ ipv6_daddr = ipv6_pinfo + OFFSET(ipv6_pinfo_daddr);
+
+ if (!readmem(ipv6_rcv_saddr, KVADDR, u6_addr16_src, SIZE(in6_addr),
+ "ipv6_rcv_saddr buffer", QUIET|RETURN_ON_ERROR))
+ break;
+ if (!readmem(ipv6_daddr, KVADDR, u6_addr16_dest, SIZE(in6_addr),
+ "ipv6_daddr buffer", QUIET|RETURN_ON_ERROR))
+ break;
+ } else if (VALID_MEMBER(sock_sk_common) &&
VALID_MEMBER(sock_common_skc_v6_daddr) &&
+ VALID_MEMBER(sock_common_skc_v6_rcv_saddr)) {
+ ipv6_rcv_saddr = sock + OFFSET(sock_sk_common) +
OFFSET(sock_common_skc_v6_rcv_saddr);
+ ipv6_daddr = sock + OFFSET(sock_sk_common) + OFFSET(sock_common_skc_v6_daddr);
+
+ if (!readmem(ipv6_rcv_saddr, KVADDR, u6_addr16_src, SIZE(in6_addr),
+ "ipv6_rcv_saddr buffer", QUIET|RETURN_ON_ERROR))
+ break;
+ if (!readmem(ipv6_daddr, KVADDR, u6_addr16_dest, SIZE(in6_addr),
+ "ipv6_daddr buffer", QUIET|RETURN_ON_ERROR))
+ break;
+ } else {
+ error(INFO, "Invalid member...\n");
break;
+ }
sprintf(&buf[strlen(buf)], "%*s ", BITS32() ? 22 : 12,
dump_in6_addr_port(u6_addr16_src, sport, buf2, &len));
diff --git a/symbols.c b/symbols.c
index e38df8aad0f5..d622de722ebd 100644
--- a/symbols.c
+++ b/symbols.c
@@ -9820,6 +9820,12 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(sock_sk_type));
fprintf(fp, " sock_common_skc_family: %ld\n",
OFFSET(sock_common_skc_family));
+ fprintf(fp, " sock_sk_common: %ld\n",
+ OFFSET(sock_sk_common));
+ fprintf(fp, " sock_common_skc_v6_daddr: %ld\n",
+ OFFSET(sock_common_skc_v6_daddr));
+ fprintf(fp, " sock_common_skc_v6_rcv_saddr: %ld\n",
+ OFFSET(sock_common_skc_v6_rcv_saddr));
fprintf(fp, " socket_alloc_vfs_inode: %ld\n",
OFFSET(socket_alloc_vfs_inode));
fprintf(fp, " inet_sock_inet: %ld\n",
--
2.37.1