PCTCP, the true worker of Waterloo TCP.
Definition in file PCTCP.C.
Go to the source code of this file.
Data Structures | |
| struct | ip4_packet |
| struct | ip6_packet |
| struct | tcp_pkt |
| struct | tcp6_pkt |
Functions | |
| void *MS_CDECL * | _bsd_socket_hook (enum BSD_SOCKET_OPS op,...)=NULL |
| This hook is to prevent the BSD-socket API being linked in by default. | |
| int | _tcp_fsm (_tcp_Socket **s, const in_Header *ip) |
| _tcp_Socket * | tcp_findseq (const in_Header *ip, const tcp_Header *tcp) |
Find the TCP socket that matches the tripplet: DESTADDR=MYADDR, DESTPORT=MYPORT and ACKNUM=SEQNUM+1 Can only be one socket. | |
| void | tcp_sockreset (_tcp_Socket *s, BOOL proxy) |
| Resets a TCP connection. | |
| void | tcp_no_arp (_tcp_Socket *s) |
| Called for a TCP socket when ARP lookup fails. | |
| void | tcp_rtt_win (_tcp_Socket *s) |
| Update retransmission timer, VJ algorithm and TCP windows. | |
| void | tcp_upd_win (_tcp_Socket *s, unsigned line) |
| Check if receive window needs an update. | |
| BOOL | tcp_checksum (const in_Header *ip, const tcp_Header *tcp, int len) |
| Verify the TCP header checksum. | |
| void | run_daemons (void) |
| Waterloo "background" daemon processes. | |
| void | udp_close (const _udp_Socket *s) |
| Since UDP is stateless, simply reclaim the local-port and unthread the socket from the list. | |
| int | udp_listen (_udp_Socket *s, WORD lport, DWORD ip, WORD port, ProtoHandler handler) |
| UDP passive open. | |
| int | udp_open (_udp_Socket *s, WORD lport, DWORD ip, WORD port, ProtoHandler handler) |
| UDP active open. | |
| void | udp_SetTTL (_udp_Socket *s, BYTE ttl) |
| Set the TTL on an outgoing UDP datagram. | |
| int | tcp_open (_tcp_Socket *s, WORD lport, DWORD ip, WORD rport, ProtoHandler handler) |
| Actively open a TCP connection. | |
| int | tcp_listen (_tcp_Socket *s, WORD lport, DWORD ip, WORD port, ProtoHandler handler, WORD timeout) |
| Passively opens TCP a connection. | |
| void | _tcp_close (_tcp_Socket *s) |
| Close a TCP connection. | |
| _tcp_Socket * | _tcp_abort (_tcp_Socket *s, const char *file, unsigned line) |
| Abort a TCP connection. | |
| int | _tcp_sendsoon (_tcp_Socket *s, const char *file, unsigned line) |
| Schedule a transmission pretty soon. | |
| _tcp_Socket * | _tcp_unthread (_tcp_Socket *ds, BOOL free_tx) |
| Unthread a socket from the tcp socket list, if it's there. | |
| int | tcp_established (const _tcp_Socket *s) |
| Returns 1 if TCP connection is established. | |
| _tcp_Socket * | _tcp_handler (const in_Header *ip, BOOL broadcast) |
| The main TCP input handler. | |
| BOOL | udp_checksum (const in_Header *ip, const udp_Header *udp, int len) |
| Verify checksum for an UDP packet. | |
| _udp_Socket * | udp_demux (const in_Header *ip, BOOL ip_bcast, DWORD destin, WORD srcPort, WORD dstPort, BOOL *udp_err) |
| Demultiplexer for incoming UDP packets. | |
| _udp_Socket * | _udp_handler (const in_Header *ip, BOOL broadcast) |
| Handler for incoming UDP packets. | |
| void | tcp_Retransmitter (BOOL force) |
| Called periodically to perform retransmissions. | |
| WORD | tcp_tick (sock_type *s) |
| Must be called periodically by user application (or BSD socket API). | |
| int | udp_write (_udp_Socket *s, const BYTE *data, int len) |
| Write an UDP packet. | |
| int | udp_read (_udp_Socket *s, BYTE *buf, int maxlen) |
| Read from UDP socket. | |
| void | sock_reduce_mss (sock_type *s, WORD MTU) |
| Reduce socket MSS upon receiving ICMP_UNREACH_NEEDFRAG. | |
| void | _udp_cancel (const in_Header *ip, int icmp_type, int icmp_code, const char *msg, const void *arg) |
| Cancel an UDP socket. | |
| BOOL | tcp_stress_test (_tcp_Socket *s, const char *msg) |
| void | _tcp_cancel (const in_Header *ip, int icmp_type, int icmp_code, const char *msg, const void *arg) |
| Cancel a TCP socket. | |
| int | tcp_read (_tcp_Socket *s, BYTE *buf, int maxlen) |
| Read from a TCP socket. | |
| int | tcp_write (_tcp_Socket *s, const BYTE *data, UINT len) |
| Write data to a TCP connection. | |
| __inline int | tcp_opt_maxsegment (const _tcp_Socket *s, BYTE *opt) |
| Insert MSS option. | |
| __inline int | tcp_opt_timestamp (_tcp_Socket *s, BYTE *opt, DWORD ts_echo) |
| Insert TimeStamp option. | |
| __inline int | tcp_opt_md5_sign (BYTE *opt) |
| __inline void | finalise_md5_sign (const in_Header *ip, const tcp_Header *tcp, WORD tcp_len, const char *secret) |
| __inline int | tcp_opt_padding (BYTE *opt, int len) |
| Pad options to multiple of 4 bytes. | |
| __inline int | tcp_opt_winscale (const _tcp_Socket *s, BYTE *opt) |
| __inline int | tcp_opt_sack_ok (const _tcp_Socket *s, BYTE *opt) |
| __inline int | tcp_opt_sack (const _tcp_Socket *s, BYTE *opt, const struct SACK_list *sack) |
| __inline int | tcp_options (_tcp_Socket *s, BYTE *opt, BOOL is_syn) |
| Append options to output TCP header. | |
| int | _tcp_send (_tcp_Socket *s, const char *file, unsigned line) |
| Format and send an outgoing TCP segment. | |
| int | _tcp_send_reset (_tcp_Socket *s, const in_Header *his_ip, const tcp_Header *org_tcp, const char *file, unsigned line) |
| Format and send a reset (RST) tcp packet. | |
| int | _tcp_keepalive (_tcp_Socket *tcp) |
| TCP keepalive transmission. | |
| int | sock_keepalive (sock_type *s) |
| WORD | sock_mode (sock_type *s, WORD mode) |
| void(*)(void) | sock_yield (_tcp_Socket *s, void(*fn)(void)) |
| Enable user defined yield function. | |
| void | sock_abort (sock_type *s) |
| Abort a UDP/TCP/Raw socket. | |
| int | raw_read (_raw_Socket *raw, BYTE *buf, int maxlen) |
| Read data from a raw-socket. | |
| int | sock_read (sock_type *s, BYTE *buf, int maxlen) |
| Read a socket with maximum 'maxlen' bytes. | |
| int | sock_fastread (sock_type *s, BYTE *buf, int len) |
| Read a socket with maximum 'len' bytes. | |
| int | sock_write (sock_type *s, const BYTE *data, int len) |
| Writes data and returns length written. | |
| int | sock_fastwrite (sock_type *s, const BYTE *data, int len) |
| Simpler, non-blocking (non-looping) version of sock_write(). | |
| int | sock_enqueue (sock_type *s, const BYTE *data, int len) |
| For UDP, this function is same as sock_write(). | |
| void | sock_noflush (sock_type *s) |
| Sets non-flush mode on next TCP write. | |
| void | sock_flush (sock_type *s) |
| Send pending TCP data. | |
| void | sock_flushnext (sock_type *s) |
| Causes next transmission to have a flush (PUSH bit set). | |
| int | sock_close (sock_type *s) |
| Close a UDP/TCP socket. | |
| int | addwattcpd (void(*func)(void)) |
| Add a function to background daemon list. | |
| int | delwattcpd (void(*func)(void)) |
| Remove a function from background daemon list. | |
| void | stopwattcpd (void) |
| void | tcp_rtt_add (const _tcp_Socket *s, UINT rto, UINT MTU) |
| BOOL | tcp_rtt_get (const _tcp_Socket *s, UINT *rto, UINT *MTU) |
| void | tcp_rtt_clr (const _tcp_Socket *s) |
Variables | |
| char | hostname [MAX_HOSTLEN+1] = "random-pc" |
| Our configured hostname. | |
| unsigned | _mss = ETH_MAX_DATA - TCP_OVERHEAD |
| unsigned | _mtu = ETH_MAX_DATA |
| BOOL | mtu_discover = 0 |
| BOOL | mtu_blackhole = 0 |
| BOOL | block_tcp = 0 |
| when application handles TCP itself | |
| BOOL | block_udp = 0 |
| when application handles UDP itself | |
| BOOL | block_icmp = 0 |
| when application handles ICMP itself | |
| BOOL | block_ip = 0 |
| when application handles IP itself | |
| DWORD | my_ip_addr = 0L |
| our IP address | |
| DWORD | sin_mask = 0xFFFFFF00L |
| our net-mask, 255.255.255.0 | |
| _udp_Socket * | _udp_allsocs = NULL |
| list of udp-sockets | |
| unsigned | tcp_OPEN_TO = DEF_OPEN_TO |
| Default open timeout. | |
| unsigned | tcp_CLOSE_TO = DEF_CLOSE_TO |
| Default close timeout. | |
| unsigned | tcp_RTO_ADD = DEF_RTO_ADD |
| Time added in RTO calculation. | |
| unsigned | tcp_RTO_BASE = DEF_RTO_BASE |
| Base time for RTO calculation. | |
| unsigned | tcp_RTO_SCALE = DEF_RTO_SCALE |
| Scaling used in RTO calculation. | |
| unsigned | tcp_RST_TIME = DEF_RST_TIME |
| Don't generate RST too often. | |
| unsigned | tcp_RETRAN_TIME = DEF_RETRAN_TIME |
| Default retransmission time. | |
| unsigned | tcp_MAX_VJSA = DEF_MAX_VJSA |
| Default max VJ std. | |
| unsigned | tcp_MAX_VJSD = DEF_MAX_VJSD |
| Default max VJ std. | |
| BOOL | tcp_opt_ts = FALSE |
| TCP option config flags (RFC 1323). | |
| BOOL | tcp_opt_wscale = FALSE |
| BOOL | tcp_opt_sack = FALSE |
| BOOL | tcp_nagle = TRUE |
| Nagle algo. | |
| unsigned | tcp_keep_idle = 2*60 |
| idle time before sending keepalive | |
| unsigned | tcp_keep_intvl = 30 |
| time between keepalive probes | |
| unsigned | tcp_max_idle = 60 |
| max idle time before kill | |
| DWORD | tcp_recv_win = DEF_RECV_WIN |
| RWIN for BSD sockets only. | |
| _tcp_Socket * | _tcp_allsocs = NULL |
| list of tcp-sockets | |
| DWORD | daemon_timer = 0UL |
| When to run "background" processes. | |
| void(* | system_yield )(void)=NULL |
| BYTE * | sign_opt |
| Prepare to insert MD5 option. | |
| struct { | |
| void(* func )(void) | |
| BOOL running | |
| } | MAX_DAEMONS |
| List of background processes. | |
| tcp_rtt | rtt_cache [RTTCACHE] |
| Round-trip timing cache routines. | |
|
||||||||||||
|
This hook is to prevent the BSD-socket API being linked in by default. It is only set from the BSD functions when needed. |
|
||||||||||||||||||||||||
|
Cancel a TCP socket. Called upon receiving ICMP errors: host/port UNREACH, REDIRECT, SOURCEQUENCH, TIMXCEED or PARAMPROB. See icmp_redirect() or icmp_handler(). Note: 'ip' is a small copy of the IP-packet originating the ICMP message. We may *not* have received a copy of the original TCP-header. But we probably won't do any harm if got less TCP-header data than needed. I.e. src_port/dst_port will be zero. Definition at line 1747 of file PCTCP.C. References _arp_resolve(), _ip_recursion, _tcp_allsocs, BYTE, _tcp_Socket::cwindow, in_Header::destination, DWORD, _tcp_Socket::next, _tcp_Socket::rto, sock_reduce_mss(), _tcp_Socket::state, _tcp_Socket::vj_sa, _tcp_Socket::vj_sd, WORD, and _tcp_Socket::wwindow. |
|
|
Close a TCP connection. Send a FIN on a particular port -- only works if it is open. Must still allow receives. Definition at line 464 of file PCTCP.C. References _tcp_unthread(), _tcp_Socket::flags, _tcp_Socket::rtt_time, set_timeout(), _tcp_Socket::state, _tcp_Socket::timeout, _tcp_Socket::tx_datalen, and _tcp_Socket::unhappy. |
|
||||||||||||
|
The main TCP input handler. All TCP input processing is done from here. Definition at line 653 of file PCTCP.C. References _ip6_tcp_checksum(), _tcp_allsocs, _tcp_Socket::adv_win, block_tcp, BYTE, in_Header::destination, in6_Header::destination, DWORD, _tcp_Socket::his6addr, _tcp_Socket::inactive_to, ip6_address, in6_Header::len, in_Header::length, _tcp_Socket::my6addr, _tcp_Socket::next, _tcp_Socket::recv_next, _tcp_Socket::safetysig, _tcp_Socket::safetytcp, set_timeout(), in_Header::source, in6_Header::source, tcp_checksum(), tcp_findseq(), tcp_rtt_win(), tcp_sockreset(), _tcp_Socket::unhappy, in_Header::ver, and WORD. |
|
|
TCP keepalive transmission. If connection is idle (tx_datalen == 0), force the peer to send us a segment by sending a keep-alive packet: * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> * |
|
||||||||||||||||
|
Format and send an outgoing TCP segment. Several packets may be sent depending on peer's window. Definition at line 2351 of file PCTCP.C. References _eth_formatpacket(), _ip4_output(), _ip6_checksum(), _ip6_output(), _pktserial, _tcp_Socket::adv_win, BYTE, tcp_PseudoHeader::checksum, _tcp_Socket::cwindow, tcp_PseudoHeader::dst, _tcp_Socket::flags, _tcp_Socket::his6addr, _tcp_Socket::karn_count, tcp_PseudoHeader::length, _tcp_Socket::max_seg, _tcp_Socket::my6addr, tcp_PseudoHeader::protocol, _tcp_Socket::recent, _tcp_Socket::recv_next, _tcp_Socket::rto, _tcp_Socket::rtt_lasttran, _tcp_Socket::rtt_time, _tcp_Socket::safetysig, _tcp_Socket::safetytcp, _tcp_Socket::secret, _tcp_Socket::send_next, _tcp_Socket::send_una, set_timeout(), tcp_PseudoHeader::src, tcp_options(), tcp_RTO_ADD, _tcp_Socket::tos, _tcp_Socket::tx_data, _tcp_Socket::tx_datalen, _tcp_Socket::tx_queue, _tcp_Socket::tx_queuelen, _tcp_Socket::unhappy, _tcp_Socket::vj_last, _tcp_Socket::window, and WORD. |
|
||||||||||||||||||||||||
|
Format and send a reset (RST) tcp packet.
References _default_ttl, _eth_formatpacket(), _ip4_output(), _ip6_checksum(), _ip6_output(), tcp_Header::acknum, BYTE, chk_timeout(), in6_Header::destination, in_Header::destination, tcp_Header::dstPort, DWORD, tcp_Header::flags, in6_Header::len, in_Header::length, tcp_Header::offset, _tcp_Socket::secret, tcp_Header::seqnum, set_timeout(), in6_Header::source, in_Header::source, tcp_Header::srcPort, tcp_RST_TIME, in_Header::tos, in_Header::ver, and WORD. |
|
||||||||||||||||
|
Schedule a transmission pretty soon. This one has an imperfection at midnight, but it is not significant to the connection performance.
References _tcp_send(), cmp_timers(), DWORD, _tcp_Socket::karn_count, _tcp_Socket::recent, _tcp_Socket::rto, _tcp_Socket::rtt_time, set_timeout(), _tcp_Socket::state, tcp_CLOSE_TO, tcp_OPEN_TO, tcp_RTO_BASE, tcp_RTO_SCALE, _tcp_Socket::tx_datalen, and _tcp_Socket::unhappy. |
|
||||||||||||
|
Unthread a socket from the tcp socket list, if it's there. Free Tx-buffer if set in tcp_SetWindow(). Definition at line 604 of file PCTCP.C. References _tcp_allsocs, DWORD, _tcp_Socket::next, _tcp_Socket::state, _tcp_Socket::tx_buf, _tcp_Socket::tx_data, and _tcp_Socket::tx_datalen. |
|
||||||||||||||||||||||||
|
Cancel an UDP socket. Called upon receiving ICMP errors: REDIRECT, TIMXCEED, PARAMPROB, or host/port UNREACH. See icmp_redirect() or icmp_handler(). Definition at line 1639 of file PCTCP.C. References _arp_resolve(), _ip_recursion, _udp_allsocs, BYTE, in_Header::destination, DWORD, _udp_Socket::next, sock_reduce_mss(), udp_close(), and WORD. |
|
||||||||||||||||
|
Read data from a raw-socket. Don't copy IP-header to buf. Definition at line 2860 of file PCTCP.C. References BYTE, _raw_Socket::ip, in_Header::length, and _raw_Socket::used. |
|
|
Waterloo "background" daemon processes. Called from tcp_tick() at each DAEMON_PERIOD interval. Definition at line 3178 of file PCTCP.C. |
|
||||||||||||||||
|
For UDP, this function is same as sock_write(). For TCP, this function enqueues 'data' to transmit queue.
|
|
||||||||||||||||
|
Read a socket with maximum 'len' bytes.
|
|
||||||||||||||||
|
Simpler, non-blocking (non-looping) version of sock_write().
|
|
|
Send pending TCP data. If there is Tx-data to be sent, set the PUSH bit. Definition at line 3109 of file PCTCP.C. |
|
||||||||||||||||
|
Read a socket with maximum 'maxlen' bytes.
|
|
||||||||||||
|
Reduce socket MSS upon receiving ICMP_UNREACH_NEEDFRAG. 'MTU' is next-hop suggested MTU or 0 if router doesn't support RFC-1191. Definition at line 1610 of file PCTCP.C. References _inet_ntoa(), sock_type::tcp, and WORD. |
|
||||||||||||||||
|
Writes data and returns length written.
|
|
|
Enable user defined yield function. Return address of previous yield function. Definition at line 2815 of file PCTCP.C. |
|
||||||||||||||||
|
Verify the TCP header checksum.
References tcp_PseudoHeader::checksum, in_Header::destination, tcp_PseudoHeader::dst, tcp_PseudoHeader::length, tcp_PseudoHeader::protocol, in_Header::source, and tcp_PseudoHeader::src. |
|
||||||||||||||||||||||||||||
|
Passively opens TCP a connection. Listen for a connection on a particular port <
|
|
|
Called for a TCP socket when ARP lookup fails. If socket allocated by BSD API, do a read wakeup on it. Definition at line 2024 of file PCTCP.C. References _bsd_socket_hook(). |
|
||||||||||||||||||||||||
|
Actively open a TCP connection. Make connection to a particular destination. Not used for IPv6 (see _TCP6_open()).
<
|
|
||||||||||||||||
|
Insert TimeStamp option. nmap uses TSval (ts_now) as indication of uptime, so send # of msec since started. Definition at line 2204 of file PCTCP.C. References BYTE, DWORD, set_timeout(), start_time, and _tcp_Socket::ts_sent. |
|
||||||||||||||||
|
Read from a TCP socket.
References _tcp_close(), BYTE, _tcp_Socket::missed_seq, _tcp_Socket::recv_next, _tcp_Socket::state, tcp_read(), and tcp_upd_win(). |
|
|
Called periodically to perform retransmissions.
< dup ACK counter ? <
< Definition at line 1217 of file PCTCP.C. References _tcp_allsocs, _tcp_unthread(), arp_lookup(), arp_lookup_pending(), BYTE, chk_timeout(), DWORD, get_timediff(), _tcp_Socket::next, _tcp_Socket::rtt_time, set_timeout(), sock_close(), _tcp_Socket::state, tcp_no_arp(), tcp_OPEN_TO, tcp_RETRAN_TIME, _tcp_Socket::timeout, and UINT. |
|
|
Update retransmission timer, VJ algorithm and TCP windows. Only called after we received something on socket.
References chk_timeout(), cmp_timers(), _tcp_Socket::cwindow, _tcp_Socket::datatimer, DWORD, get_timediff(), _tcp_Socket::karn_count, _tcp_Socket::max_seg, _tcp_Socket::rto, _tcp_Socket::rtt_time, _tcp_Socket::send_una, set_timeout(), tcp_MAX_VJSA, tcp_MAX_VJSD, tcp_RTO_ADD, tcp_RTO_BASE, _tcp_Socket::ts_echo, _tcp_Socket::ts_sent, _tcp_Socket::vj_last, _tcp_Socket::vj_sa, _tcp_Socket::vj_sd, and _tcp_Socket::wwindow. |
|
|
Must be called periodically by user application (or BSD socket API).
Don't enter this loop if reentered. That could return the same packet twice (before we call _eth_free() on the 1st packet).
References _arp_handler(), _eth_arrived(), _eth_free(), _ip4_handler(), _rarp_handler(), _tcp_unthread(), chk_timeout(), daemon_timer, pppoe_handler(), run_daemons(), set_timeout(), _tcp_Socket::state, sock_type::tcp, tcp_Retransmitter(), and WORD. |
|
||||||||||||||||
|
Write data to a TCP connection.
References BYTE, _tcp_Socket::datatimer, _tcp_Socket::max_seg, _tcp_Socket::max_tx_data, set_timeout(), _tcp_Socket::state, _tcp_Socket::tx_data, _tcp_Socket::tx_datalen, UINT, and _tcp_Socket::unhappy. |
|
||||||||||||||||||||||||||||
|
Demultiplexer for incoming UDP packets. Don't debug packet if no match was found (except if '*udp_err'). Demux to active sockets.
References _udp_allsocs, in6_Header::destination, DWORD, _udp_Socket::his6addr, ip6_address, _udp_Socket::my6addr, _udp_Socket::next, _udp_Socket::safetysig, sin_mask, in_Header::source, in6_Header::source, in_Header::ver, and WORD. |
|
||||||||||||||||||||||||
|
UDP passive open. Listen for a connection on a particular port. Definition at line 167 of file PCTCP.C. |
|
||||||||||||||||||||||||
|
UDP active open. Open a connection on a particular port. Definition at line 202 of file PCTCP.C. |
|
||||||||||||||||
|
Read from UDP socket.
References BYTE, and udp_read(). |
|
||||||||||||||||
|
Write an UDP packet.
References _default_tos, _eth_formatpacket(), _ip6_checksum(), _pktserial, BYTE, and _udp_Socket::his6addr. |
|
|
Our configured hostname. |
|
|
List of background processes.
|
|
|
|
|
|
|
|
|
Round-trip timing cache routines. These functions implement a very simple system for keeping track of network performance for future use in new connections. The emphasis here is on speed of update (rather than optimum cache hit ratio) since tcp_rtt_add() is called every time a TCP connection updates its round trip estimate.
|
|
|
Default max VJ std. |
|
|
Default max VJ std. |
|
|
Nagle algo. |
1.3.8