diff --git a/third_party/tcplp/bsdtcp/cc.h b/third_party/tcplp/bsdtcp/cc.h index 408c5ced4..a213f5546 100644 --- a/third_party/tcplp/bsdtcp/cc.h +++ b/third_party/tcplp/bsdtcp/cc.h @@ -57,8 +57,8 @@ * the global linked list are removed. */ -#ifndef _NETINET_CC_H_ -#define _NETINET_CC_H_ +#ifndef TCPLP_NETINET_CC_H_ +#define TCPLP_NETINET_CC_H_ /* XXX: TCP_CA_NAME_MAX define lives in tcp.h for compat reasons. */ #include "tcp.h" diff --git a/third_party/tcplp/bsdtcp/cc/cc_module.h b/third_party/tcplp/bsdtcp/cc/cc_module.h index a38a1f353..9d83f296f 100644 --- a/third_party/tcplp/bsdtcp/cc/cc_module.h +++ b/third_party/tcplp/bsdtcp/cc/cc_module.h @@ -40,8 +40,8 @@ * http://caia.swin.edu.au/urp/newtcp/ */ -#ifndef _NETINET_CC_MODULE_H_ -#define _NETINET_CC_MODULE_H_ +#ifndef TCPLP_NETINET_CC_MODULE_H_ +#define TCPLP_NETINET_CC_MODULE_H_ /* samkumar: This was already commented out in FreeBSD (I didn't do it). */ /* diff --git a/third_party/tcplp/bsdtcp/icmp_var.h b/third_party/tcplp/bsdtcp/icmp_var.h index 4f0cc2d29..2767b8244 100644 --- a/third_party/tcplp/bsdtcp/icmp_var.h +++ b/third_party/tcplp/bsdtcp/icmp_var.h @@ -35,8 +35,8 @@ * weren't necessary (and often introduced additional dependencies). */ -#ifndef _NETINET_ICMP_VAR_H_ -#define _NETINET_ICMP_VAR_H_ +#ifndef TCPLP_NETINET_ICMP_VAR_H_ +#define TCPLP_NETINET_ICMP_VAR_H_ /* * Identifiers for ICMP sysctl nodes */ diff --git a/third_party/tcplp/bsdtcp/ip.h b/third_party/tcplp/bsdtcp/ip.h index 7f70196fe..247c6f816 100644 --- a/third_party/tcplp/bsdtcp/ip.h +++ b/third_party/tcplp/bsdtcp/ip.h @@ -31,8 +31,8 @@ * $FreeBSD$ */ -#ifndef _NETINET_IP_H_ -#define _NETINET_IP_H_ +#ifndef TCPLP_NETINET_IP_H_ +#define TCPLP_NETINET_IP_H_ #define IP_MAXPACKET 65535 /* maximum packet size */ diff --git a/third_party/tcplp/bsdtcp/ip6.h b/third_party/tcplp/bsdtcp/ip6.h index cc079240f..3326d266f 100644 --- a/third_party/tcplp/bsdtcp/ip6.h +++ b/third_party/tcplp/bsdtcp/ip6.h @@ -61,8 +61,8 @@ * @(#)ip.h 8.1 (Berkeley) 6/10/93 */ -#ifndef _NETINET_IP6_H_ -#define _NETINET_IP6_H_ +#ifndef TCPLP_NETINET_IP6_H_ +#define TCPLP_NETINET_IP6_H_ #include "types.h" diff --git a/third_party/tcplp/bsdtcp/sys/queue.h b/third_party/tcplp/bsdtcp/sys/queue.h index bbd1c46a9..4ed5c7c8f 100644 --- a/third_party/tcplp/bsdtcp/sys/queue.h +++ b/third_party/tcplp/bsdtcp/sys/queue.h @@ -30,8 +30,8 @@ * $FreeBSD$ */ -#ifndef _SYS_QUEUE_H_ -#define _SYS_QUEUE_H_ +#ifndef TCPLP_SYS_QUEUE_H_ +#define TCPLP_SYS_QUEUE_H_ /* samkumar: Removing this, as it adds yet another dependency. */ //#include diff --git a/third_party/tcplp/bsdtcp/tcp.h b/third_party/tcplp/bsdtcp/tcp.h index c51217a7e..63c66d02f 100644 --- a/third_party/tcplp/bsdtcp/tcp.h +++ b/third_party/tcplp/bsdtcp/tcp.h @@ -37,8 +37,8 @@ * we should look at that very closely, and consider rewriting it. */ -#ifndef _NETINET_TCP_H_ -#define _NETINET_TCP_H_ +#ifndef TCPLP_NETINET_TCP_H_ +#define TCPLP_NETINET_TCP_H_ #include #include @@ -61,14 +61,28 @@ struct tcphdr { uint16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ -#if 1 //BYTE_ORDER == LITTLE_ENDIAN + + /* + * samkumar: The original FreeBSD code used bit fields for the offset and + * unused bits, within this byte. I've rewritten it to avoid the use of + * bit fields, so that the code is more portable. The original code, which + * defined the order of bit fields based on the platform's endianness, is + * included below, commented out using "#if 0". + */ + uint8_t th_off_x2; /* data offset and unused bits */ +#define TH_OFF_SHIFT 4 + +#if 0 +#if BYTE_ORDER == LITTLE_ENDIAN uint8_t th_x2:4, /* (unused) */ th_off:4; /* data offset */ #endif -#if 0 //BYTE_ORDER == BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN uint8_t th_off:4, /* data offset */ th_x2:4; /* (unused) */ #endif +#endif + uint8_t th_flags; #define TH_FIN 0x01 #define TH_SYN 0x02 diff --git a/third_party/tcplp/bsdtcp/tcp_const.h b/third_party/tcplp/bsdtcp/tcp_const.h index 31af20944..6728fa6ed 100644 --- a/third_party/tcplp/bsdtcp/tcp_const.h +++ b/third_party/tcplp/bsdtcp/tcp_const.h @@ -35,8 +35,8 @@ * often serve to enable, disable, or configure certain TCP-related features. */ -#ifndef _TCP_CONST_H_ -#define _TCP_CONST_H_ +#ifndef TCPLP_TCP_CONST_H_ +#define TCPLP_TCP_CONST_H_ #include "../tcplp.h" diff --git a/third_party/tcplp/bsdtcp/tcp_fsm.h b/third_party/tcplp/bsdtcp/tcp_fsm.h index 110e9e3cc..4edc35127 100644 --- a/third_party/tcplp/bsdtcp/tcp_fsm.h +++ b/third_party/tcplp/bsdtcp/tcp_fsm.h @@ -33,8 +33,8 @@ /* samkumar: Removed some #ifdef guards around constants needed for TCPlp. */ -#ifndef _NETINET_TCP_FSM_H_ -#define _NETINET_TCP_FSM_H_ +#ifndef TCPLP_NETINET_TCP_FSM_H_ +#define TCPLP_NETINET_TCP_FSM_H_ #include "types.h" diff --git a/third_party/tcplp/bsdtcp/tcp_input.c b/third_party/tcplp/bsdtcp/tcp_input.c index b00a31a93..5c4773085 100644 --- a/third_party/tcplp/bsdtcp/tcp_input.c +++ b/third_party/tcplp/bsdtcp/tcp_input.c @@ -476,7 +476,7 @@ tcp_input(struct ip6_hdr* ip6, struct tcphdr* th, otMessage* msg, struct tcpcb* /* * samkumar: Logic that handled IPv4 was deleted below. I won't add a - * comment everytime this is done, but I'm putting it here (one of the + * comment every time this is done, but I'm putting it here (one of the * first instances of this) for clarity. */ iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff; @@ -485,7 +485,7 @@ tcp_input(struct ip6_hdr* ip6, struct tcphdr* th, otMessage* msg, struct tcpcb* * Check that TCP offset makes sense, * pull out TCP options and adjust length. XXX */ - off = th->th_off << 2; + off = (th->th_off_x2 >> TH_OFF_SHIFT) << 2; if (off < sizeof (struct tcphdr) || off > tlen) { goto drop; } @@ -1030,7 +1030,7 @@ tcp_do_segment(struct ip6_hdr* ip6, struct tcphdr *th, otMessage* msg, * Parse options on any incoming segment. */ tcp_dooptions(&to, (uint8_t *)(th + 1), - (th->th_off << 2) - sizeof(struct tcphdr), + ((th->th_off_x2 >> TH_OFF_SHIFT) << 2) - sizeof(struct tcphdr), (thflags & TH_SYN) ? TO_SYN : 0); /* diff --git a/third_party/tcplp/bsdtcp/tcp_output.c b/third_party/tcplp/bsdtcp/tcp_output.c index 695257b79..5f6139b06 100644 --- a/third_party/tcplp/bsdtcp/tcp_output.c +++ b/third_party/tcplp/bsdtcp/tcp_output.c @@ -1037,7 +1037,7 @@ send: th->th_ack = htonl(tp->rcv_nxt); if (optlen) { bcopy(opt, th + 1, optlen); - th->th_off = (sizeof (struct tcphdr) + optlen) >> 2; + th->th_off_x2 = ((sizeof (struct tcphdr) + optlen) >> 2) << TH_OFF_SHIFT; } th->th_flags = flags; /* diff --git a/third_party/tcplp/bsdtcp/tcp_seq.h b/third_party/tcplp/bsdtcp/tcp_seq.h index 09cbb1d29..c3caae453 100644 --- a/third_party/tcplp/bsdtcp/tcp_seq.h +++ b/third_party/tcplp/bsdtcp/tcp_seq.h @@ -30,8 +30,8 @@ * $FreeBSD$ */ -#ifndef _NETINET_TCP_SEQ_H_ -#define _NETINET_TCP_SEQ_H_ +#ifndef TCPLP_NETINET_TCP_SEQ_H_ +#define TCPLP_NETINET_TCP_SEQ_H_ #include "../tcplp.h" diff --git a/third_party/tcplp/bsdtcp/tcp_subr.c b/third_party/tcplp/bsdtcp/tcp_subr.c index 0774b478b..d90461c97 100644 --- a/third_party/tcplp/bsdtcp/tcp_subr.c +++ b/third_party/tcplp/bsdtcp/tcp_subr.c @@ -41,6 +41,7 @@ #include "tcp_var.h" #include "tcp_seq.h" #include "tcp_timer.h" +#include "sys/queue.h" #include "../lib/bitmap.h" #include "../lib/cbuf.h" #include "cc.h" @@ -234,15 +235,16 @@ tcpip_fillheaders(struct tcpcb* tp, otMessageInfo* ip_ptr, void *tcp_ptr) memcpy(&ip_ptr->mPeerAddr, &tp->faddr, sizeof(ip_ptr->mPeerAddr)); /* Fill in the TCP header */ - /* samkumar: I kept the old code for ports commented out, for reference. */ + /* samkumar: I kept the old code commented out, for reference. */ //th->th_sport = inp->inp_lport; //th->th_dport = inp->inp_fport; th->th_sport = tp->lport; th->th_dport = tp->fport; th->th_seq = 0; th->th_ack = 0; - th->th_x2 = 0; - th->th_off = 5; + // th->th_x2 = 0; + // th->th_off = 5; + th->th_off_x2 = (5 << TH_OFF_SHIFT); th->th_flags = 0; th->th_win = 0; th->th_urp = 0; @@ -309,8 +311,10 @@ tcp_respond(struct tcpcb *tp, otInstance* instance, struct ip6_hdr* ip6gen, stru nth->th_dport = thgen->th_sport; nth->th_seq = htonl(seq); nth->th_ack = htonl(ack); - nth->th_x2 = 0; - nth->th_off = sizeof(struct tcphdr) >> 2; + /* samkumar: original code for setting th_x2 and th_off, for reference. */ + // nth->th_x2 = 0; + // nth->th_off = (sizeof (struct tcphdr) + optlen) >> 2; + nth->th_off_x2 = (sizeof(struct tcphdr) >> 2) << TH_OFF_SHIFT; nth->th_flags = flags; if (tp != NULL) nth->th_win = htons((uint16_t) (win >> tp->rcv_scale)); diff --git a/third_party/tcplp/bsdtcp/tcp_timer.h b/third_party/tcplp/bsdtcp/tcp_timer.h index 331ac242e..03389f84a 100644 --- a/third_party/tcplp/bsdtcp/tcp_timer.h +++ b/third_party/tcplp/bsdtcp/tcp_timer.h @@ -38,8 +38,8 @@ * parameters) and global statistics (e.g. tcp_keepcnt). */ -#ifndef _NETINET_TCP_TIMER_H_ -#define _NETINET_TCP_TIMER_H_ +#ifndef TCPLP_NETINET_TCP_TIMER_H_ +#define TCPLP_NETINET_TCP_TIMER_H_ #include "tcp_var.h" diff --git a/third_party/tcplp/bsdtcp/tcp_timewait.c b/third_party/tcplp/bsdtcp/tcp_timewait.c index 07e2c9ecc..61ef74836 100644 --- a/third_party/tcplp/bsdtcp/tcp_timewait.c +++ b/third_party/tcplp/bsdtcp/tcp_timewait.c @@ -158,8 +158,7 @@ tcp_twrespond(struct tcpcb* tp, int flags) nth->th_dport = tp->fport; nth->th_seq = htonl(tp->snd_nxt); nth->th_ack = htonl(tp->rcv_nxt); - nth->th_x2 = 0; - nth->th_off = (sizeof(struct tcphdr) + optlen) >> 2; + nth->th_off_x2 = ((sizeof(struct tcphdr) + optlen) >> 2) << TH_OFF_SHIFT; nth->th_flags = flags; nth->th_win = htons(tp->tw_last_win); nth->th_urp = 0; diff --git a/third_party/tcplp/bsdtcp/tcp_var.h b/third_party/tcplp/bsdtcp/tcp_var.h index 489b80213..56890ff92 100644 --- a/third_party/tcplp/bsdtcp/tcp_var.h +++ b/third_party/tcplp/bsdtcp/tcp_var.h @@ -30,8 +30,8 @@ * $FreeBSD$ */ -#ifndef _NETINET_TCP_VAR_H_ -#define _NETINET_TCP_VAR_H_ +#ifndef TCPLP_NETINET_TCP_VAR_H_ +#define TCPLP_NETINET_TCP_VAR_H_ /* For memmove(). */ #include @@ -50,8 +50,6 @@ #include "types.h" #include "ip6.h" -#include "sys/queue.h" - /* Implement byte-order-specific functions using OpenThread. */ uint16_t tcplp_sys_hostswap16(uint16_t hostport); uint32_t tcplp_sys_hostswap32(uint32_t hostport); @@ -104,7 +102,19 @@ struct sackhole { tcp_seq start; /* start seq no. of hole */ tcp_seq end; /* end seq no. */ tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ - TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */ + + /* + * samkumar: I'm using this instead of the TAILQ_ENTRY macro to avoid + * including sys/queue.h from this file. It's undesirable to include + * sys/queue.h from this file because this file is part of the external + * interface to TCPlp, and sys/queue.h pollutes the global namespace. + * The original code that uses TAILQ_ENTRY is in a comment below. + */ + struct { + struct sackhole *tqe_next; /* next element */ + struct sackhole **tqe_prev; /* address of previous next element */ + } scblink; /* scoreboard linkage */ + // TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */ }; struct sackhint { @@ -200,7 +210,7 @@ struct tcpcb { int t_segqlen; /* segment reassembly queue length */ #endif - int t_dupacks; /* consecutive dup acks recd */ + int32_t t_dupacks; /* consecutive dup acks recd */ #if 0 struct tcp_timer *t_timers; /* All the TCP timers in one struct */ @@ -228,8 +238,8 @@ struct tcpcb { tcp_seq rcv_nxt; /* receive next */ tcp_seq rcv_adv; /* advertised window */ - uint64_t rcv_wnd; /* receive window */ tcp_seq rcv_up; /* receive urgent pointer */ + uint64_t rcv_wnd; /* receive window */ uint64_t snd_wnd; /* send window */ uint64_t snd_cwnd; /* congestion-controlled window */ @@ -251,22 +261,37 @@ struct tcpcb { // uint32_t t_bw_spare1; /* unused */ // tcp_seq t_bw_spare2; /* unused */ - int t_rxtcur; /* current retransmit value (ticks) */ + int32_t t_rxtcur; /* current retransmit value (ticks) */ uint32_t t_maxseg; /* maximum segment size */ - int t_srtt; /* smoothed round-trip time */ - int t_rttvar; /* variance in round-trip time */ + int32_t t_srtt; /* smoothed round-trip time */ + int32_t t_rttvar; /* variance in round-trip time */ - int t_rxtshift; /* log(2) of rexmt exp. backoff */ + int32_t t_rxtshift; /* log(2) of rexmt exp. backoff */ uint32_t t_rttmin; /* minimum rtt allowed */ uint32_t t_rttbest; /* best rtt we've seen */ + + int32_t t_softerror; /* possible error not yet reported */ + uint64_t t_rttupdated; /* number of times rtt sampled */ uint64_t max_sndwnd; /* largest window peer has offered */ - - int t_softerror; /* possible error not yet reported */ /* out-of-band data */ // char t_oobflags; /* have some */ // char t_iobc; /* input character */ + + tcp_seq last_ack_sent; +/* experimental */ + tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */ + uint64_t snd_cwnd_prev; /* cwnd prior to retransmit */ + uint64_t snd_ssthresh_prev; /* ssthresh prior to retransmit */ +// int t_sndzerowin; /* zero-window updates sent */ + uint32_t t_badrxtwin; /* window for retransmit recovery */ + uint8_t snd_limited; /* segments limited transmitted */ + /* RFC 1323 variables */ +/* + * samkumar: Moved "RFC 1323 variables" after "experimental" to reduce + * compiler-inserted padding. + */ uint8_t snd_scale; /* window scaling for send window */ uint8_t rcv_scale; /* window scaling for recv window */ uint8_t request_r_scale; /* pending window scaling */ @@ -274,27 +299,28 @@ struct tcpcb { uint32_t ts_recent_age; /* when last updated */ u_int32_t ts_offset; /* our timestamp offset */ - tcp_seq last_ack_sent; -/* experimental */ - uint64_t snd_cwnd_prev; /* cwnd prior to retransmit */ - uint64_t snd_ssthresh_prev; /* ssthresh prior to retransmit */ - tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */ -// int t_sndzerowin; /* zero-window updates sent */ - uint32_t t_badrxtwin; /* window for retransmit recovery */ - uint8_t snd_limited; /* segments limited transmitted */ - /* SACK related state */ - int snd_numholes; /* number of holes seen by sender */ - TAILQ_HEAD(sackhole_head, sackhole) snd_holes; + int32_t snd_numholes; /* number of holes seen by sender */ + /* + * samkumar: I replaced the TAILQ_HEAD macro invocation (commented out + * below) with the code it stands for, to avoid having to #include + * sys/queue.h in this file. See the comment above in struct sackhole for + * more info. + */ + struct sackhole_head { + struct sackhole *tqh_first; /* first element */ + struct sackhole **tqh_last; /* addr of last next element */ + } snd_holes; + // TAILQ_HEAD(sackhole_head, sackhole) snd_holes; /* SACK scoreboard (sorted) */ tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/ - int rcv_numsacks; /* # distinct sack blks present */ + int32_t rcv_numsacks; /* # distinct sack blks present */ struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ tcp_seq sack_newdata; /* New data xmitted in this recovery episode starts at this seq number */ struct sackhint sackhint; /* SACK scoreboard hint */ - int t_rttlow; /* smallest observed RTT */ + int32_t t_rttlow; /* smallest observed RTT */ #if 0 u_int32_t rfbuf_ts; /* recv buffer autoscaling timestamp */ int rfbuf_cnt; /* recv buffer autoscaling byte count */ @@ -303,7 +329,7 @@ struct tcpcb { // int t_sndrexmitpack; /* retransmit packets sent */ // int t_rcvoopack; /* out-of-order packets received */ // void *t_toe; /* TOE pcb pointer */ - int t_bytes_acked; /* # bytes acked during current RTT */ + int32_t t_bytes_acked; /* # bytes acked during current RTT */ // struct cc_algo *cc_algo; /* congestion control algorithm */ struct cc_var ccv[1]; /* congestion control specific vars */ #if 0 diff --git a/third_party/tcplp/bsdtcp/types.h b/third_party/tcplp/bsdtcp/types.h index 650eb15ce..cf1176cf5 100644 --- a/third_party/tcplp/bsdtcp/types.h +++ b/third_party/tcplp/bsdtcp/types.h @@ -46,8 +46,8 @@ * standard integer types (uint8_t, uint16_t, etc.). */ -#ifndef _SYS_TYPES_H_ -#define _SYS_TYPES_H_ +#ifndef TCPLP_SYS_TYPES_H_ +#define TCPLP_SYS_TYPES_H_ #include