/proc 中可能的内部套接字状态列表

发布于 2024-11-07 17:01:57 字数 3007 浏览 2 评论 0原文

我想知道 /proc/net/tcpst 列的可能值。我认为 st 列相当于 netstat(8)ss(8) 中的 STATE 列。

我成功地识别出三个代码:

sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
0: 0100007F:08A0 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7321 1 ffff81002f449980 3000 0 0 2 -1                     
1: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 6656 1 ffff81003a30c080 3000 0 0 2 -1                     
2: 00000000:0272 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 6733 1 ffff81003a30c6c0 3000 0 0 2 -1                     
3: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7411 1 ffff81002f448d00 3000 0 0 2 -1                     
4: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7520 1 ffff81002f4486c0 3000 0 0 2 -1                     
5: 0100007F:089F 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7339 1 ffff81002f449340 3000 0 0 2 -1           
6: 0100007F:E753 0100007F:0016 01 00000000:00000000 02:000AFA92 00000000   500        0 18198 2 ffff81002f448080 204 40 20 2 -1                   
7: 0100007F:E752 0100007F:0016 06 00000000:00000000 03:000005EC 00000000     0        0 0 2 ffff81000805dc00                                      

上面显示:

  • On line sl 0: tcp/2208 上的侦听端口。 st = 0A = LISTEN
  • 在线 sl 6:在 tcp/22 上建立的会话。 st = 01 = ESTABLISHED
  • 第 7 行:ssh 注销后套接字处于 TIME_WAIT 状态。没有索引节点。 st = 06 = TIME_WAIT

有人可以扩展此列表吗? proc(5) 联机帮助页在该主题上非常简洁,指出:

   /proc/net/tcp
          Holds a dump of the TCP socket table. Much of the information is not of use apart from debugging. The "sl" value is the kernel hash slot for the socket, the "local address" is  the  local  address  and
          port  number pair.  The "remote address" is the remote address and port number pair (if connected). ’St’ is the internal status of the socket.  The ’tx_queue’ and ’rx_queue’ are the outgoing and incom-
          ing data queue in terms of kernel memory usage.  The "tr", "tm->when", and "rexmits" fields hold internal information of the kernel socket state and are only useful  for  debugging.   The  "uid"  field
          holds the effective UID of the creator of the socket.

并且在相关说明中,上面的 /proc/net/tcp 输出显示了一些侦听进程(2208、62、111 等) 。但是,尽管显示了已建立状态和 time_wait 状态,但我看不到 tcp/22 上的侦听 tcp 连接。是的,我可以在 /proc/net/tcp6 中看到它们,但它们不应该出现在 /proc/net/tcp 中吗? Netstat 输出显示它与仅绑定到 ipv4 的应用程序不同。例如,

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4231/portmap        
tcp        0      0 :::22                       :::*                        LISTEN      4556/sshd           

非常感谢, -安德鲁

I would like to know the possible values of st column in /proc/net/tcp. I think the st column equates to STATE column from netstat(8) or ss(8).

I have managed to identify three codes:

sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
0: 0100007F:08A0 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7321 1 ffff81002f449980 3000 0 0 2 -1                     
1: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 6656 1 ffff81003a30c080 3000 0 0 2 -1                     
2: 00000000:0272 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 6733 1 ffff81003a30c6c0 3000 0 0 2 -1                     
3: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7411 1 ffff81002f448d00 3000 0 0 2 -1                     
4: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7520 1 ffff81002f4486c0 3000 0 0 2 -1                     
5: 0100007F:089F 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 7339 1 ffff81002f449340 3000 0 0 2 -1           
6: 0100007F:E753 0100007F:0016 01 00000000:00000000 02:000AFA92 00000000   500        0 18198 2 ffff81002f448080 204 40 20 2 -1                   
7: 0100007F:E752 0100007F:0016 06 00000000:00000000 03:000005EC 00000000     0        0 0 2 ffff81000805dc00                                      

The above shows:

  • On line sl 0: a listening port on tcp/2208. st = 0A = LISTEN
  • On line sl 6: An established session on tcp/22. st = 01 = ESTABLISHED
  • On line sl 7: An socket in TIME_WAIT state after ssh logout. No inode. st = 06 = TIME_WAIT

Can anyone expand on this list? The proc(5) manpage is quite terse on the subject stating:

   /proc/net/tcp
          Holds a dump of the TCP socket table. Much of the information is not of use apart from debugging. The "sl" value is the kernel hash slot for the socket, the "local address" is  the  local  address  and
          port  number pair.  The "remote address" is the remote address and port number pair (if connected). ’St’ is the internal status of the socket.  The ’tx_queue’ and ’rx_queue’ are the outgoing and incom-
          ing data queue in terms of kernel memory usage.  The "tr", "tm->when", and "rexmits" fields hold internal information of the kernel socket state and are only useful  for  debugging.   The  "uid"  field
          holds the effective UID of the creator of the socket.

And on a related note, the above /proc/net/tcp output is showing a few listening processes (2208, 62, 111 etc). However, I cannot see a listening tcp connection on tcp/22, althought the established and time_wait states are shown. Yes, I can see them in /proc/net/tcp6 but should they not be present in /proc/net/tcp also? Netstat output shows it differently to applications bound only to ipv4. E.g.

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4231/portmap        
tcp        0      0 :::22                       :::*                        LISTEN      4556/sshd           

Many thanks,
-Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我乃一代侩神 2024-11-14 17:01:57

它们应该与 ./include/net/tcp_states.h 在linux内核源代码中:

enum {
    TCP_ESTABLISHED = 1,
    TCP_SYN_SENT,
    TCP_SYN_RECV,
    TCP_FIN_WAIT1,
    TCP_FIN_WAIT2,
    TCP_TIME_WAIT,
    TCP_CLOSE,
    TCP_CLOSE_WAIT,
    TCP_LAST_ACK,
    TCP_LISTEN,
    TCP_CLOSING,    /* Now a valid state */

    TCP_MAX_STATES  /* Leave at the end! */
};

至于你的2.问题,你真的确定没有sshd在监听例如0.0.0.0:22 ?如果没有,我怀疑您所看到的与 v4-mapped-on-v6 套接字有关,请参见 man 7 ipv6

They should match to the enum in ./include/net/tcp_states.h in the linux kernel sources:

enum {
    TCP_ESTABLISHED = 1,
    TCP_SYN_SENT,
    TCP_SYN_RECV,
    TCP_FIN_WAIT1,
    TCP_FIN_WAIT2,
    TCP_TIME_WAIT,
    TCP_CLOSE,
    TCP_CLOSE_WAIT,
    TCP_LAST_ACK,
    TCP_LISTEN,
    TCP_CLOSING,    /* Now a valid state */

    TCP_MAX_STATES  /* Leave at the end! */
};

As for your 2. question, are you really sure there's not an sshd listening on e.g. 0.0.0.0:22 ? If not, I suspect what you're seeing is related to v4-mapped-on-v6 sockets, see e.g. man 7 ipv6

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文