Created
September 26, 2017 12:19
-
-
Save surki/4b1a3d8d40328712b6586e151a0813c5 to your computer and use it in GitHub Desktop.
Getting a socket's 'struct sock' information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can get even more detailed information about a socket from kernel's internal socket struct. | |
For example, we will try to get nginx listening (on port 81) socket's backlog length | |
NOTE: You may need to install kernel debug info if not already installed | |
# yum-config-manager --enable "amzn-main-debuginfo" --enable "amzn-updates-debuginfo" | |
# yum -y install kernel-debuginfo kernel-devel | |
Or get socket info for listening socket on port 81 | |
# ss -len | grep :81 | |
tcp LISTEN 0 511 *:81 *:* ino:29842919 sk:55 <-> | |
Get its sk buff address | |
# grep 29842919 /proc/net/tcp | |
8: 00000000:0051 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 29842919 1 ffff8800e9d1da00 100 0 0 10 0 | |
Now get the details, for example, the backlog length | |
# gdb /usr/lib/debug/lib/modules/`uname -r`/vmlinux /proc/kcore | |
................ | |
................ | |
Reading symbols from /usr/lib/debug/lib/modules/4.4.51-40.69.amzn1.x86_64/vmlinux...done. | |
[New process 1] | |
Core was generated by `root=LABEL=/ console=tty1 console=ttyS0 selinux=0 LANG=en_US.UTF-8 KEYTABLE=us'. | |
................ | |
(gdb) set print pretty on | |
(gdb) p *(struct sock *)0xffff8800e9d1da00 | |
................ | |
................ | |
sk_ack_backlog = 0, | |
sk_max_ack_backlog = 511, | |
................ | |
................ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems kafka (and some other processes) are listening on ipv6 addresses (on ports 9092,9093 and 9094) (as you had noted), as shown by
inode
info for sockets on ipv6 are found in/proc/net/tcp6
as opposed to/proc/net/tcp
.Here the inode of socket in which we're interested in is present, but corresponding address (?) of socket is 0 (and hence socket can't be accessed using gdb.)
So, the problem, I think, boils down to "why socket address (?) is 0 for all active sockets in /proc/net/ipv6?".
But interestingly socket address is 0 also for all sockets in /proc/net/tcp.