- TCP state cleanup added

This commit is contained in:
Wiesner András 2023-11-09 07:47:50 +01:00
parent 66121960d7
commit b39f302a63

View File

@ -48,6 +48,22 @@ static bool filtTcp(const PcktSieveFilterCondition *filtCond, const PcktProps *c
return ipProps->Protocol == ETH_TCP_PACKET_CLASS && references_us;
}
static inline TcpState * tcps_create() {
TcpState * tcps = dynmem_alloc(sizeof(TcpState));
tcps->txWin = tcpw_create(ETHLIB_DEF_TCP_WINDOW_SIZE);
return tcps;
}
static inline void tcps_remove_and_cleanup(const TcpState * tcps) {
if (tcps == NULL) {
return;
}
dynmem_free(tcps->txWin);
dynmem_free(tcps);
}
#define TCP_DEFAULT_MSS (1200)
#define TCP_DEFAULT_RETRY_LIMIT (5)
#define TCP_DEFAULT_RETRY_TO_HS (100)
@ -64,7 +80,6 @@ void tcps_init(TcpState *tcps, uint16_t localPort) {
tcps->rxAckNum = 0;
tcps->localWindow = ETHLIB_DEF_TCP_WINDOW_SIZE;
tcps->txWin = tcpw_create(ETHLIB_DEF_TCP_WINDOW_SIZE);
tcpw_set_seqnum_offset(tcps->txWin, tcps->txSeqNum);
tcps->retryLimit = TCP_DEFAULT_RETRY_LIMIT;
@ -263,6 +278,7 @@ int tcp_receive_segment_cb(const Pckt *pckt, PcktSieveLayerTag tag) {
// release descriptor if not meaningful anymore
if (ret == SIEVE_LAYER_REMOVE_THIS) {
cbdt_release(E.cbdt, tcps->d); // release descriptor
tcps_remove_and_cleanup(tcps); // release TCP state
}
return ret;
@ -330,7 +346,7 @@ static inline cbd tcp_new_connblock_filtcond(EthInterface *intf, ip4_addr ipAddr
ConnBlock ipConnB = ipv4_new_connblock(intf, ipAddr, NULL); // create new IPv4 connection block
PcktSieveLayerTag tag; // store TCP state into sieve layer's tag
TcpState *tcpState = dynmem_alloc(sizeof(TcpState));
TcpState *tcpState = tcps_create();
tcps_init(tcpState, port);
tcpState->userCb = cbFn;
tag.p = tcpState;