我们这里讨论的是在程序不可控的情况下,比如别人的程序,又未使用SO_REUSEADDR选项,如何快 速终结TCP有限状态机的TIME_WAIT状态 。
参看这个链接"closing half-open connections"
http://www-mice.cs.ucl.ac.uk/multimedia/misc/tcp_ip/8707.mm.www/0009.html
1987年10月1日(可真够早的)cdjohns@nswc-g.arpa提供了一个shell script,用于
SunOS 4.x系统下快速终结TCP有限状态机的TIME_WAIT状态 。很奇怪,这个脚本并未
得到人们的足够重视并广泛流传,直到SunOS 4.x退出历史舞台,它也就销声匿迹了 。
昨天被backend从故纸堆里翻了出来,我们就趁机移植到SPARC/Solaris 8下来 。
参看UNP 图2.4了解TCP有限状态机的变迁过程 。
/usr/include/netinet里的文件多是为用户空间编程准备的,/usr/include/inet里
的文件多是为内核空间编程准备的 。下面内容取自SPARC/Solaris 8
--------------------------------------------------------------------------
/*
* /usr/include/inet/tcp.h
*/
/*
* TCP states
*/
#define TCPS_CLOSED -6
#define TCPS_IDLE -5 /* idle (opened, but not bound) */
#define TCPS_BOUND -4 /* bound, ready to connect or accept */
#define TCPS_LISTEN -3 /* listening for connection */
#define TCPS_SYN_SENT -2 /* active, have sent syn */
#define TCPS_SYN_RCVD -1 /* have received syn (and sent ours) */
/*
* states < TCPS_ESTABLISHED are those where connections not established
*/
#define TCPS_ESTABLISHED 0 /* established */
#define TCPS_CLOSE_WAIT 1 /* rcvd fin, waiting for close */
/*
* states > TCPS_CLOSE_WAIT are those where user has closed
*/
#define TCPS_FIN_WAIT_1 2 /* have closed and sent fin */
#define TCPS_CLOSING 3 /* closed, xchd FIN, await FIN ACK */
#define TCPS_LAST_ACK 4 /* had fin and close; await FIN ACK */
/*
* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN
*/
#define TCPS_FIN_WAIT_2 5 /* have closed, fin is acked */
#define TCPS_TIME_WAIT 6 /* in 2*msl quIEt wait after close */
#if (defined(_KERNEL) || defined(_KMEMUSER))
/*
* If the information represented by the field is required even in the
* TIME_WAIT state, it must be part of tcpb_t. Otherwise it must be part
* of tcp_t. In other Words, the tcp_t captures the information that is
* not required, after a connection has entered the TIME_WAIT state.
*/
typedef struct tcp_base_s
{
struct tcp_base_s *tcpb_bind_hash; /* Bind hash chain */
struct tcp_base_s **tcpb_ptpbhn; /* Pointer to previous bind hash next. */
struct tcp_base_s *tcpb_conn_hash; /* Connect hash chain */
struct tcp_base_s **tcpb_ptpchn; /* Pointer to previous conn hash next. */
struct tcp_base_s *tcpb_time_wait_next; /* Pointer to next T/W block */
struct tcp_base_s *tcpb_time_wait_prev; /* Pointer to previous T/W next */
/*
* /usr/include/sys/types.h
* typedef long clock_t;
* offset: 8 * 6 -> 48 -> 0x30,clock_t占8个字节(64-bit kernel mode)
*/
clock_t tcpb_time_wait_expire; /* time in hz when t/w expires */
clock_t tcpb_last_rcv_lbolt; /* lbolt on last packet, used for PAWS */
/*
* offset: 0x40
*/
int32_t tcpb_state;
int32_t tcpb_rcv_ws; /* My window scale power */
int32_t tcpb_snd_ws; /* Sender"s window scale power */
uint32_t tcpb_ts_recent; /* Timestamp of earliest unacked */
/*
* data segment
* offset: 0x50
*/
clock_t tcpb_rto; /* Round trip timeout */
uint32_t tcpb_snd_ts_ok : 1,
tcpb_snd_ws_ok : 1,
tcpb_is_secure : 1,
tcpb_reuseaddr : 1, /* SO_REUSEADDR "socket" option. */
tcpb_exclbind : 1, /* ``exclusive"" binding */
tcpb_junk_fill_thru_bit_31 : 27;
/*
* offset: 0x5c
*/
uint32_t tcpb_snxt; /* Senders next seq num */
uint32_t tcpb_swnd; /* Senders window (relative to suna) */
uint32_t tcpb_mss; /* Max segment size */
uint32_t tcpb_iss; /* Initial send seq num */
推荐阅读
- Solaris上的域名系统配置
- SUN Solaris 7重新安装手记
- SOLARIS+QMAIL+VPOPMAIL+IGENUS+QMAILAMDIN
- Solaris中的磁盘设备
- Solaris 的引导与初始化
- Solaris8 公用桌面环境管理--配置会话管理器
- 安装 Solaris 8 之后的几个常用步骤
- Sun Solaris 用户手册 -- 四.Unix 命令
- Solaris常见问题解答
- SUN SOLARIS 2.6 系统常用管理命令
