mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[tcp] add rewrite of TCPlp's interface code to support OpenThread's TCP API (#7190)
This commit is contained in:
Vendored
+15
-1
@@ -43,9 +43,23 @@
|
||||
#include "tcp_var.h"
|
||||
#include "tcp_timer.h"
|
||||
|
||||
/*
|
||||
* samkumar: these are TCPlp-specific constants that I added. They were not
|
||||
* present in the FreeBSD-derived code.
|
||||
*/
|
||||
|
||||
#define FRAMES_PER_SEG 5
|
||||
#define FRAMECAP_6LOWPAN (122 - 11 - 5)
|
||||
#define IP6HDR_SIZE (2 + 1 + 1 + 16 + 16) // IPHC header (2) + Next header (1) + Hop count (1) + Dest. addr (16) + Src. addr (16)
|
||||
#define MSS_6LOWPAN ((FRAMES_PER_SEG * FRAMECAP_6LOWPAN) - IP6HDR_SIZE - sizeof(struct tcphdr))
|
||||
|
||||
// I may change some of these flags later
|
||||
/*
|
||||
* samkumar: The remaining constants were present in the original FreeBSD code,
|
||||
* but I set their values.
|
||||
*/
|
||||
|
||||
#define hz 1000 // number of ticks per second, assuming millisecond ticks
|
||||
|
||||
enum tcp_input_consts {
|
||||
tcp_keepcnt = TCPTV_KEEPCNT,
|
||||
tcp_fast_finwait2_recycle = 0,
|
||||
|
||||
Vendored
+5
-5
@@ -48,12 +48,12 @@
|
||||
|
||||
#include "tcp_const.h"
|
||||
|
||||
/* samkumar: Eventually, replace this with OpenThread's random generator. */
|
||||
// A simple linear congruential number generator
|
||||
tcp_seq seed = (tcp_seq) 0xbeaddeed;
|
||||
/*
|
||||
* samkumar: This is rewritten to have the host network stack to generate the
|
||||
* ISN with appropriate randomness.
|
||||
*/
|
||||
tcp_seq tcp_new_isn(struct tcpcb* tp) {
|
||||
seed = (((tcp_seq) 0xfaded011) * seed) + (tcp_seq) 0x1ead1eaf;
|
||||
return seed;
|
||||
return (uint32_t) tcplp_sys_generate_isn();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Vendored
+23
-10
@@ -59,10 +59,11 @@ int V_tcp_pmtud_blackhole_activated_min_mss = 0;
|
||||
/*
|
||||
* samkumar: I changed these functions to accept "struct tcpcb* tp" their
|
||||
* argument instead of "void *xtp". This is possible since we're no longer
|
||||
* relying on FreeBSD's callout subsystem in TCPlp.
|
||||
* relying on FreeBSD's callout subsystem in TCPlp. I also changed them to
|
||||
* return 1 if the connection is dropped, or 0 otherwise.
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
tcp_timer_delack(struct tcpcb* tp)
|
||||
{
|
||||
/* samkumar: I added this, to replace the code I removed below. */
|
||||
@@ -80,9 +81,10 @@ tcp_timer_delack(struct tcpcb* tp)
|
||||
*/
|
||||
tp->t_flags |= TF_ACKNOW;
|
||||
(void) tcp_output(tp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
tcp_timer_keep(struct tcpcb* tp)
|
||||
{
|
||||
uint32_t ticks = tcplp_sys_get_ticks();
|
||||
@@ -158,17 +160,19 @@ tcp_timer_keep(struct tcpcb* tp)
|
||||
* that handled debug tracing/probes, vnet, and locking. I removed that
|
||||
* code.
|
||||
*/
|
||||
return;
|
||||
return 0;
|
||||
|
||||
dropit:
|
||||
tp = tcp_drop(tp, ETIMEDOUT);
|
||||
(void) tp; /* samkumar: prevent a compiler warning */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
tcp_timer_persist(struct tcpcb* tp)
|
||||
{
|
||||
uint32_t ticks = tcplp_sys_get_ticks();
|
||||
int dropped = 0;
|
||||
|
||||
/* samkumar: I added this, to replace the code I removed below. */
|
||||
KASSERT(tpistimeractive(tp, TT_PERSIST), ("Persist timer running, but unmarked\n"));
|
||||
@@ -202,6 +206,7 @@ tcp_timer_persist(struct tcpcb* tp)
|
||||
(ticks - tp->t_rcvtime >= tcp_maxpersistidle ||
|
||||
ticks - tp->t_rcvtime >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
|
||||
tp = tcp_drop(tp, ETIMEDOUT);
|
||||
dropped = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -212,6 +217,7 @@ tcp_timer_persist(struct tcpcb* tp)
|
||||
if (tp->t_state > TCPS_CLOSE_WAIT &&
|
||||
(ticks - tp->t_rcvtime) >= TCPTV_PERSMAX) {
|
||||
tp = tcp_drop(tp, ETIMEDOUT);
|
||||
dropped = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -227,13 +233,14 @@ out:
|
||||
* tracing/probes, vnet, and locking. I removed that code.
|
||||
*/
|
||||
(void) tp; /* samkumar: prevent a compiler warning */
|
||||
return;
|
||||
return dropped;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
tcp_timer_2msl(struct tcpcb* tp)
|
||||
{
|
||||
uint32_t ticks = tcplp_sys_get_ticks();
|
||||
int dropped = 0;
|
||||
|
||||
/* samkumar: I added this, to replace the code I removed below. */
|
||||
KASSERT(tpistimeractive(tp, TT_2MSL), ("2MSL timer running, but unmarked\n"));
|
||||
@@ -281,7 +288,8 @@ tcp_timer_2msl(struct tcpcb* tp)
|
||||
if (tp->t_state == TCP6S_TIME_WAIT) {
|
||||
tp = tcp_close(tp);
|
||||
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
|
||||
return;
|
||||
dropped = 1;
|
||||
return dropped;
|
||||
}
|
||||
/*
|
||||
* samkumar: This if statement also used to check that an inpcb is still
|
||||
@@ -297,6 +305,7 @@ tcp_timer_2msl(struct tcpcb* tp)
|
||||
tpiscantrcv(tp)) {
|
||||
tp = tcp_close(tp);
|
||||
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
|
||||
dropped = 1;
|
||||
} else {
|
||||
if (ticks - tp->t_rcvtime <= TP_MAXIDLE(tp)) {
|
||||
/*
|
||||
@@ -308,19 +317,22 @@ tcp_timer_2msl(struct tcpcb* tp)
|
||||
} else {
|
||||
tp = tcp_close(tp);
|
||||
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
|
||||
dropped = 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* samkumar: There used to be some code here that handled debug
|
||||
* tracing/probes, vnet, and locking. I removed that code.
|
||||
*/
|
||||
return dropped;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
tcp_timer_rexmt(struct tcpcb *tp)
|
||||
{
|
||||
int rexmt;
|
||||
uint32_t ticks = tcplp_sys_get_ticks();
|
||||
int dropped = 0;
|
||||
|
||||
/* samkumar: I added this, to replace the code I removed below. */
|
||||
KASSERT(tpistimeractive(tp, TT_REXMT), ("Rexmt timer running, but unmarked\n"));
|
||||
@@ -348,6 +360,7 @@ tcp_timer_rexmt(struct tcpcb *tp)
|
||||
|
||||
tp = tcp_drop(tp, tp->t_softerror ?
|
||||
tp->t_softerror : ETIMEDOUT);
|
||||
dropped = 1;
|
||||
goto out;
|
||||
}
|
||||
if (tp->t_state == TCPS_SYN_SENT) {
|
||||
@@ -450,7 +463,7 @@ out:
|
||||
* tracing/probes, vnet, and locking. I removed that code.
|
||||
*/
|
||||
(void) tp; /* samkumar: Prevent a compiler warning */
|
||||
return;
|
||||
return dropped;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Vendored
+9
-5
@@ -154,11 +154,15 @@ static const int tcp_backoff[TCP_MAXRXTSHIFT + 1] =
|
||||
|
||||
static const int tcp_totbackoff = 2559; /* sum of tcp_backoff[] */
|
||||
|
||||
void tcp_timer_delack(struct tcpcb* tp);
|
||||
void tcp_timer_keep(struct tcpcb* tp);
|
||||
void tcp_timer_persist(struct tcpcb* tp);
|
||||
void tcp_timer_2msl(struct tcpcb* tp);
|
||||
void tcp_timer_rexmt(struct tcpcb *tp);
|
||||
/*
|
||||
* samkumar: Changed return value to int to indicate whether connection was
|
||||
* dropped or not.
|
||||
*/
|
||||
int tcp_timer_delack(struct tcpcb* tp);
|
||||
int tcp_timer_keep(struct tcpcb* tp);
|
||||
int tcp_timer_persist(struct tcpcb* tp);
|
||||
int tcp_timer_2msl(struct tcpcb* tp);
|
||||
int tcp_timer_rexmt(struct tcpcb *tp);
|
||||
int tcp_timer_active(struct tcpcb *tp, uint32_t timer_type);
|
||||
|
||||
/*
|
||||
|
||||
Vendored
+1
-8
@@ -50,14 +50,6 @@ extern "C" {
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/message.h>
|
||||
|
||||
#define hz 1000 // number of ticks per second
|
||||
#define MICROS_PER_TICK 1000 // number of microseconds per tick
|
||||
|
||||
#define FRAMES_PER_SEG 5
|
||||
#define FRAMECAP_6LOWPAN (122 - 11 - 5)
|
||||
|
||||
#define IP6HDR_SIZE (2 + 1 + 1 + 16 + 16) // IPHC header (2) + Next header (1) + Hop count (1) + Dest. addr (16) + Src. addr (16)
|
||||
|
||||
#define RELOOKUP_REQUIRED -1
|
||||
#define CONN_LOST_NORMAL 0
|
||||
|
||||
@@ -85,6 +77,7 @@ void tcplp_sys_connection_lost(struct tcpcb* tcb, uint8_t errnum);
|
||||
void tcplp_sys_on_state_change(struct tcpcb* tcb, int newstate);
|
||||
void tcplp_sys_log(const char* format, ...);
|
||||
bool tcplp_sys_autobind(otInstance *aInstance, const otSockAddr *aPeer, otSockAddr *aToBind, bool aBindAddress, bool aBindPort);
|
||||
uint32_t tcplp_sys_generate_isn();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user