2011-05-13 17 views
19

我想知道/proc/net/tcpst列的可能值。我認爲st列等於來自netstat(8)ss(8)的STATE列。/proc中可能的內部插槽狀態列表

我已成功地識別三個碼:

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          

上面所示:

  • 論線SL 0:在TCP/2208監聽端口。 st = 0A = LISTEN
  • 在線sl 6:在tcp/22上建立的會話。 st = 01 = ESTABLISHED
  • 在線sl 7:在ssh註銷後處於TIME_WAIT狀態的套接字。沒有inode。 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 /淨/ TCP輸出呈現出幾個聽音過程(2208,62,111等)。但是,我看不到tcp/22上的監聽tcp連接,儘管顯示了已建立的和time_wait狀態。是的,我可以在/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   

非常感謝, -Andrew

+0

繼承人一些[更多閱讀](http://www.readmespot.com/question/f/21657/semantics-of-and-0-0-0-0-in-dual-stack- oses)在ipv4到ipv6映射,如果任何人有興趣 –

+0

現在這是一個死鏈接。我認爲這可能與此鏈接:http://serverfault.com/questions/21657/semantics-of-and-0-0-0-0-in-dual-stack-oses – user314104

回答

27

他們應該匹配到枚舉在./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

+0

謝謝,不知道爲什麼我沒有抓住這個來源。我想我正在嘗試匹配EST。 「0016」肯定沒有服務,所以它必須是你提到的v4到v6映射。新對我來說。 –

+0

另外,我不完全確定如何從'tcp_states.h'獲得十六進制值。我只能看到ESTABLISHED有一個像你上面粘貼的值,但其他州如何運作我們的和匹配? –

+2

這是一個枚舉,它從1開始。 TCP_SYN_SENT是2,TCP_LISTEN是10.而十進制中的10是'A',十六進制是你在/ proc/net/tcp中看到的'0A' – nos