date and time created 81/11/15 14:34:06 by wnj
[unix-history] / usr / src / sys / netinet / tcp_var.h
CommitLineData
eb44bfb2 1/* tcp_var.h 4.3 81/11/15 */
ad6d0022
BJ
2
3/*
4 * Kernel variables for tcp.
5 */
6
eb44bfb2
BJ
7/*
8 * Tcp+ip header, after ip options removed.
9 */
10struct tcpiphdr {
11 struct ipovly ti_i; /* overlaid ip structure */
12 struct tcphdr ti_t; /* tcp header */
13};
14#define ti_next ti_i.ih_next
15#define ti_prev ti_i.ih_prev
16#define ti_x1 ti_i.ih_x1
17#define ti_pr ti_i.ih_pr
18#define ti_len ti_i.ih_len
19#define ti_src ti_i.ih_src
20#define ti_dst ti_i.ih_dst
21#define ti_sport ti_t.th_sport
22#define ti_dport ti_t.th_dport
23#define ti_seq ti_t.th_seq
24#define ti_ackno ti_t.th_ackno
25#define ti_x2 ti_t.th_x2
26#define ti_off ti_t.th_off
27#define ti_flags ti_t.th_flags
28#define ti_win ti_t.th_win
29#define ti_sum ti_t.th_sum
30#define ti_urp ti_t.th_urp
31
ad6d0022
BJ
32/*
33 * Tcp control block.
34 */
53a5409e
BJ
35struct tcpcb {
36 struct tcpiphdr *seg_next,*seg_prev; /* seq queue */
37 struct tcpiphdr *t_template; /* skeletal packet for transmit */
38 struct inpcb *t_inpcb;
ad6d0022
BJ
39 seq_t iss; /* initial send seq # */
40 seq_t irs; /* initial recv seq # */
41 seq_t rcv_urp; /* rcv urgent pointer */
42 seq_t rcv_nxt; /* next seq # to rcv */
43 seq_t rcv_end; /* rcv eol pointer */
44 seq_t snd_off; /* seq # of first datum in send buf */
45 seq_t seq_fin; /* seq # of FIN sent */
46 seq_t snd_end; /* send eol pointer */
47 seq_t snd_urp; /* snd urgent pointer */
48 seq_t snd_lst; /* seq # of last sent datum */
49 seq_t snd_nxt; /* seq # of next datum to send */
50 seq_t snd_una; /* seq # of first unacked datum */
51 seq_t snd_wl; /* seq # of last sent window */
52 seq_t snd_hi; /* highest seq # sent */
53 seq_t snd_wnd; /* send window max */
54 seq_t t_rexmt_val; /* val saved in rexmt timer */
55 seq_t t_rtl_val; /* val saved in rexmt too long timer */
56 seq_t t_xmt_val; /* seq # sent when xmt timer started */
57 seq_t rcv_adv; /* advertised window */
53a5409e
BJ
58 struct mbuf *seg_unack; /* unacked message queue */
59 short seqcnt;
ad6d0022
BJ
60 u_short tc_flags; /* flags and state; see below */
61 u_short t_options;
62#define TO_EOL 0x01 /* eol mode */
63#define TO_URG 0x02 /* urgent mode */
ad6d0022
BJ
64 u_char t_state; /* state of this connection */
65 u_char t_xmtime; /* current rexmt time */
66/* timers... must be in order */
53a5409e 67 short t_init; /* init */
ad6d0022
BJ
68 short t_rexmt; /* retransmission */
69 short t_rexmttl; /* retransmit too long */
70 short t_persist; /* retransmit persistance */
71 short t_finack; /* fin acknowledged */
72 short t_xmt; /* round trip transmission time */
73/* end timers */
74};
75
76/* tc_flags values */
77#define TC_ACK_DUE 0x0001 /* must we send ACK */
78#define TC_CANCELLED 0x0002 /* retransmit timer cancelled */
53a5409e 79/* ... */
ad6d0022
BJ
80#define TC_FIN_RCVD 0x0008 /* FIN received */
81#define TC_FORCE_ONE 0x0010 /* force sending of one byte */
82#define TC_NEW_WINDOW 0x0020 /* received new window size */
83#define TC_REXMT 0x0040 /* this msg is a retransmission */
84#define TC_SND_FIN 0x0080 /* FIN should be sent */
85#define TC_SND_RST 0x0100 /* RST should be sent */
86#define TC_SND_URG 0x0200 /* urgent data to send */
87#define TC_SYN_ACKED 0x0400 /* SYN has been ACKed */
88#define TC_SYN_RCVD 0x0800 /* SYN has been received */
89#define TC_USR_CLOSED 0x1000 /* user has closed connection */
90#define TC_WAITED_2_ML 0x2000 /* wait time for FIN ACK is up */
91#define TC_NET_KEEP 0x4000 /* don't free this net input */
92#define TC_USR_ABORT 0x8000 /* user has closed and does not expect
93 to receive any more data */
94/*
95 * TCP timers.
96 */
97#define TINIT 0
98#define TREXMT 1
99#define TREXMTTL 2
100#define TPERSIST 3
101#define TFINACK 4
102#define TNTIMERS 5
103
53a5409e
BJ
104#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
105#define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
106
ad6d0022
BJ
107/*
108 * Tcp machine predicates
109 */
110#define ack_ok(x, y) \
eb44bfb2
BJ
111 (((y)->ti_flags&TH_ACK)==0 || \
112 ((x)->iss < (y)->ti_ackno && (y)->ti_ackno <= (x)->snd_hi))
ad6d0022
BJ
113
114#define syn_ok(x, y) \
eb44bfb2 115 ((y)->ti_flags&TH_SYN)
ad6d0022
BJ
116
117#define ack_fin(x, y) \
eb44bfb2 118 ((x)->seq_fin > (x)->iss && (y)->ti_ackno > (x)->seq_fin)
ad6d0022
BJ
119
120#define rcv_empty(x) \
121 (((x)->tc_flags&TC_USR_ABORT) || \
53a5409e
BJ
122 ((x)->t_inpcb->inp_socket->so_rcv.sb_mb == NULL && \
123 (x)->seg_next == (x)->seg_prev))
ad6d0022
BJ
124
125#define ISSINCR 128 /* increment for iss each second */
126#define TCPSIZE 20 /* size of TCP leader (bytes) */
127
128/*
129 * THESE NEED TO BE JUSTIFIED!
130 *
131 * *2 here is because slow timeout routine called every 1/2 second.
132 */
53a5409e 133#define T_INIT (30*2)
ad6d0022
BJ
134#define T_2ML (10*2) /* 2*maximum packet lifetime */
135#define T_PERS (5*2) /* persist time */
136#define T_REXMT (1*2) /* base for retransmission time */
137#define T_REXMTTL (30*2) /* retransmit too long timeout */
138#define T_REMAX (30*2) /* maximum retransmission time */
139
140#ifdef TCPDEBUG
141#define TDBSIZE 50
142/*
143 * Tcp debugging record.
144 */
145struct tcp_debug {
146 long td_tod; /* time of day */
53a5409e 147 struct tcbcb *td_tcb; /* -> tcb */
ad6d0022
BJ
148 char td_old; /* old state */
149 char td_inp; /* input */
150 char td_tim; /* timer id */
151 char td_new; /* new state */
152 seq_t td_sno; /* seq_t number */
153 seq_t td_ano; /* acknowledgement */
154 u_short td_wno; /* window */
155 u_short td_lno; /* length */
156 u_char td_flg; /* message flags */
157};
158#endif
159
160#ifdef KERNEL
ad6d0022
BJ
161seq_t tcp_iss; /* tcp initial send seq # */
162int tcpconsdebug; /* set to 1 traces on console */
53a5409e 163struct inpcb tcb;
ad6d0022
BJ
164#ifdef TCPDEBUG
165struct tcp_debug tcp_debug[TDBSIZE];
166#endif
167int tdbx; /* rotating index into tcp_debug */
53a5409e 168struct tcpiphdr *tcp_template();
ad6d0022
BJ
169#endif
170
171#define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
172#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
173#define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
174#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)