Watt-32 tcp/ip  2.2 dev-rel.10
pctcp.h
Go to the documentation of this file.
1 
3 #ifndef _w32_PCTCP_H
4 #define _w32_PCTCP_H
5 
10 #define tcp_TIMEOUT 13000UL /* timeout during a connection */
11 #define tcp_LONGTIMEOUT (1000UL*sock_delay) /* timeout for open */
12 #define tcp_LASTACK_TIME 10000 /* timeout in the LASTACK state added AGW 5th Jan 2001 */
13 
14 #define DEF_OPEN_TO 1000UL /* # of msec in tcp-open (<=3s; RFC1122) */
15 #define DEF_CLOSE_TO 1000UL /* # of msec for CLOSEWT state */
16 #define DEF_RTO_ADD 100UL /* # of msec delay in RTT increment */
17 #define DEF_RTO_BASE 10UL /* # of msec in RTO recalculation */
18 #define DEF_RTO_SCALE 64 /* RTO scale factor in _tcp_sendsoon() */
19 #define DEF_RST_TIME 100UL /* # of msec before sending RST */
20 #define DEF_RETRAN_TIME 10UL /* do retransmit logic every 10ms */
21 #define DEF_RECV_WIN (16*1024) /* default receive window, 16kB */
22 
23 
24 /*
25  * S. Lawson - define a short TIME_WAIT timeout. It should be from
26  * .5 to 4 minutes (2MSL) but it's not really practical for us.
27  * 2 secs will hopefully handle the case where ACK must be retransmitted,
28  * but can't protect future connections on the same port from old packets.
29  */
30 #define tcp_TIMEWT_TO 2000UL
31 
32 #ifndef __NETINET_TCP_SEQ_H
33 
41  #define SEQ_LT(a,b) ((long)((a) - (b)) < 0)
42  #define SEQ_LEQ(a,b) ((long)((a) - (b)) <= 0)
43  #define SEQ_GT(a,b) ((long)((a) - (b)) > 0)
44  #define SEQ_GEQ(a,b) ((long)((a) - (b)) >= 0)
45  #define SEQ_BETWEEN(seq,lo,hi) ((seq - lo) <= (hi - lo))
46  /* (SEG_GEQ(seq,lo) && SEG_LEQ(seq,hi)) */
47 #endif
48 
55 #define INIT_SEQ() intel (Random(1,0xFFFFFFFF)) /* intel (set_timeout(1)) */
56 
60 #define DEF_MAX_VJSA 60000U
61 #define DEF_MAX_VJSD 20000U
62 #define INIT_VJSA 220
63 
67 #define TCPOPT_EOL 0
68 #define TCPOPT_NOP 1
69 #define TCPOPT_MAXSEG 2
70 #define TCPOPT_WINDOW 3
71 #define TCPOPT_SACK_PERM 4
72 #define TCPOPT_SACK 5
73 #define TCPOPT_ECHO 6
74 #define TCPOPT_ECHOREPLY 7
75 #define TCPOPT_TIMESTAMP 8
76 #define TCPOPT_CC 11
77 #define TCPOPT_CCNEW 12
78 #define TCPOPT_CCECHO 13
79 #define TCPOPT_CHKSUM_REQ 14
80 #define TCPOPT_CHKSUM_DAT 15
81 #define TCPOPT_SIGNATURE 19
82 #define TCPOPT_SIGN_LEN 16
83 
84 #define TCP_MAX_WINSHIFT 14
91 #define MSS_MAX (_mtu - TCP_OVERHEAD)
92 #define MSS_MIN (576 - TCP_OVERHEAD)
93 #define MSS_REDUCE 20 /* do better than this (exponentially decrease) */
94 
95 #define my_ip_addr W32_NAMESPACE (my_ip_addr)
96 #define sin_mask W32_NAMESPACE (sin_mask)
97 #define block_tcp W32_NAMESPACE (block_tcp)
98 #define block_udp W32_NAMESPACE (block_udp)
99 #define block_ip W32_NAMESPACE (block_ip)
100 #define block_icmp W32_NAMESPACE (block_icmp)
101 #define use_rand_lport W32_NAMESPACE (use_rand_lport)
102 
103 #define mtu_discover W32_NAMESPACE (mtu_discover)
104 #define mtu_blackhole W32_NAMESPACE (mtu_blackhole)
105 
106 #define tcp_nagle W32_NAMESPACE (tcp_nagle)
107 #define tcp_keep_idle W32_NAMESPACE (tcp_keep_idle)
108 #define tcp_keep_intvl W32_NAMESPACE (tcp_keep_intvl)
109 #define tcp_max_idle W32_NAMESPACE (tcp_max_idle)
110 #define tcp_opt_ts W32_NAMESPACE (tcp_opt_ts)
111 #define tcp_opt_sack W32_NAMESPACE (tcp_opt_sack)
112 #define tcp_opt_wscale W32_NAMESPACE (tcp_opt_wscale)
113 #define hostname W32_NAMESPACE (hostname)
114 
115 extern BOOL mtu_discover;
116 extern BOOL mtu_blackhole;
117 extern BOOL use_rand_lport;
118 extern BOOL tcp_nagle;
119 extern BOOL tcp_opt_ts;
120 extern BOOL tcp_opt_sack;
121 extern BOOL tcp_opt_wscale;
122 
123 extern char hostname [MAX_HOSTLEN+1];
124 
125 extern _tcp_Socket *_tcp_allsocs;
126 extern _udp_Socket *_udp_allsocs;
127 
128 extern void _udp_cancel (const in_Header *ip, int icmp_type, int icmp_code,
129  const char *msg, const void *arg);
130 
131 extern void _tcp_cancel (const in_Header *ip, int icmp_type, int icmp_code,
132  const char *msg, const void *arg);
133 
134 extern void _tcp_close (_tcp_Socket *s);
135 extern void tcp_rtt_add (const _tcp_Socket *s, UINT rto, UINT MTU);
136 extern void tcp_rtt_clr (const _tcp_Socket *s);
137 extern BOOL tcp_rtt_get (const _tcp_Socket *s, UINT *rto, UINT *MTU);
138 
139 extern int _tcp_send (_tcp_Socket *s, const char *file, unsigned line);
140 extern int _tcp_sendsoon (_tcp_Socket *s, const char *file, unsigned line);
141 extern int _tcp_keepalive (_tcp_Socket *s);
142 
143 extern void tcp_Retransmitter (BOOL force);
144 
145 extern _udp_Socket *_udp_handler (const in_Header *ip, BOOL broadcast);
146 extern _tcp_Socket *_tcp_handler (const in_Header *ip, BOOL broadcast);
147 extern _tcp_Socket *_tcp_unthread (_tcp_Socket *s, BOOL free_tx);
148 extern _tcp_Socket *_tcp_abort (_tcp_Socket *s, const char *file, unsigned line);
149 extern int _tcp_send_reset (_tcp_Socket *s, const in_Header *ip,
150  const tcp_Header *tcp, const char *file,
151  unsigned line);
152 
153 #define TCP_SEND(s) _tcp_send (s, __FILE__, __LINE__)
154 #define TCP_SENDSOON(s) _tcp_sendsoon (s, __FILE__, __LINE__)
155 #define TCP_ABORT(s) _tcp_abort (s, __FILE__, __LINE__)
156 
157 #define TCP_SEND_RESET(s, ip, tcp) \
158  _tcp_send_reset(s, ip, tcp, __FILE__, __LINE__)
159 
160 #define SET_ERR_MSG(s, msg) \
161  do { \
162  if (s && s->err_msg == NULL && msg != NULL) \
163  s->err_msg = _strlcpy (s->err_buf, msg, sizeof(s->err_buf)); \
164  } while (0)
165 
170 struct tcp_rtt {
171  DWORD ip;
172  UINT rto;
173  UINT MTU;
174  };
175 
176 #define RTTCACHE 16
179 #if defined(USE_BSD_API)
180  /*
181  * Operations for the '_bsd_socket_hook'.
182  */
183  enum BSD_SOCKET_OPS {
184  BSO_FIND_SOCK = 1, /* return a 'Socket*' from '_tcp_Socket*' */
185  BSO_SYN_CALLBACK, /* called on SYN received */
186  BSO_RST_CALLBACK, /* called on RST received */
187  BSO_IP4_RAW, /* called on IPv4 input. */
188  BSO_IP6_RAW, /* called on IPv6 input. */
189  BSO_DEBUG, /* called to perform SO_DEBUG stuff */
190  };
191 
192  extern void * (MS_CDECL *_bsd_socket_hook) (enum BSD_SOCKET_OPS op, ...);
193 #endif
194 
195 /* In ports.c
196  */
197 extern WORD init_localport (void);
198 extern WORD find_free_port (WORD oldport, BOOL sleep_msl);
199 extern int grab_localport (WORD port);
200 extern int reuse_localport (WORD port);
201 extern int maybe_reuse_localport (_tcp_Socket *s);
202 
203 #endif
UINT MTU
Path-MTU discovered for this entry.
Definition: pctcp.h:173
_tcp_Socket * _tcp_abort(_tcp_Socket *s, const char *file, unsigned line)
Abort a TCP connection.
Definition: pctcp.c:512
_tcp_Socket * _tcp_handler(const in_Header *ip, BOOL broadcast)
The main TCP input handler.
Definition: pctcp.c:645
UINT rto
Round-trip timeout for this entry.
Definition: pctcp.h:172
DWORD ip
IP-address of this entry.
Definition: pctcp.h:171
BOOL mtu_discover
Definition: pctcp.c:63
_tcp_Socket * _tcp_allsocs
list of tcp-sockets
Definition: pctcp.c:137
WORD init_localport(void)
Allocate the "lport_inuse" bit-array from heap.
Definition: ports.c:52
Definition: pctcp.h:170
_udp_Socket * _udp_allsocs
list of udp-sockets
Definition: pctcp.c:73
Definition: ip.h:67
void tcp_Retransmitter(BOOL force)
Called periodically to perform retransmissions.
Definition: pctcp.c:1209
void _tcp_cancel(const in_Header *ip, int icmp_type, int icmp_code, const char *msg, const void *arg)
Cancel a TCP socket.
Definition: pctcp.c:1735
BOOL mtu_blackhole
Definition: pctcp.c:64
void _tcp_close(_tcp_Socket *s)
Close a TCP connection.
Definition: pctcp.c:455
char hostname[MAX_HOSTLEN+1]
Our configured hostname.
Definition: pctcp.c:59
int _tcp_sendsoon(_tcp_Socket *s, const char *file, unsigned line)
Schedule a transmission pretty soon.
Definition: pctcp.c:555
void *MS_CDECL * _bsd_socket_hook(enum BSD_SOCKET_OPS op,...)
This hook is to prevent the BSD-socket API being linked in by default.
int _tcp_keepalive(_tcp_Socket *s)
TCP keepalive transmission.
Definition: pctcp.c:2698
void _udp_cancel(const in_Header *ip, int icmp_type, int icmp_code, const char *msg, const void *arg)
Cancel an UDP socket.
Definition: pctcp.c:1627
BOOL tcp_opt_ts
TCP option config flags (RFC 1323).
Definition: pctcp.c:125
int _tcp_send_reset(_tcp_Socket *s, const in_Header *ip, const tcp_Header *tcp, const char *file, unsigned line)
Format and send a reset (RST) tcp packet.
Definition: pctcp.c:2555
BOOL tcp_nagle
Misc TCP values.
Definition: pctcp.c:131
_tcp_Socket * _tcp_unthread(_tcp_Socket *s, BOOL free_tx)
Unthread a socket from the tcp socket list, if it's there.
Definition: pctcp.c:596
int _tcp_send(_tcp_Socket *s, const char *file, unsigned line)
Format and send an outgoing TCP segment.
Definition: pctcp.c:2339
_udp_Socket * _udp_handler(const in_Header *ip, BOOL broadcast)
Handler for incoming UDP packets.
Definition: pctcp.c:1031