mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[tcp] minor changes to FreeBSD-derived code for integration into OpenThread (#7190)
* update TCPlp #include guards to be TCPlp-specific * do not use sys/queue.h in tcp_var.h, to avoid polluting global namespace * avoid bitfields in TCP header structure * use int32_t instead of int in tcpcb and reorder fields to eliminate padding
This commit is contained in:
Vendored
+2
-2
@@ -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"
|
||||
|
||||
+2
-2
@@ -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). */
|
||||
/*
|
||||
|
||||
Vendored
+2
-2
@@ -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
|
||||
*/
|
||||
|
||||
Vendored
+2
-2
@@ -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 */
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -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"
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -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 <sys/cdefs.h>
|
||||
|
||||
Vendored
+18
-4
@@ -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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -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
|
||||
|
||||
Vendored
+2
-2
@@ -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"
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -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"
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -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);
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -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;
|
||||
/*
|
||||
|
||||
Vendored
+2
-2
@@ -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"
|
||||
|
||||
|
||||
Vendored
+9
-5
@@ -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));
|
||||
|
||||
Vendored
+2
-2
@@ -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"
|
||||
|
||||
|
||||
+1
-2
@@ -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;
|
||||
|
||||
Vendored
+53
-27
@@ -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 <string.h>
|
||||
@@ -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
|
||||
|
||||
Vendored
+2
-2
@@ -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 <stdint.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user