52 #include <sys/queue.h>
65 #define CNET_TCP_REASSEMBLE_COUNT 256
66 #define CNET_TCP_BACKLOG_COUNT 128
67 #define CNET_TCP_HALF_OPEN_COUNT 128
97 typedef uint32_t seq_t;
101 tstampLT(uint32_t a, uint32_t b)
103 return (int32_t)(a - b) < 0;
107 tstampLEQ(uint32_t a, uint32_t b)
109 return (int32_t)(a - b) <= 0;
113 tstampGEQ(uint32_t a, uint32_t b)
115 return (int32_t)(a - b) >= 0;
119 #define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * 1000)
137 #define TCP_INPUT_STATES \
139 "Free", "Closed", "Listen", "SYN Sent", "SYN Rcvd", "Established", "CloseWait", "Fin1", \
140 "Closing", "LastAck", "Fin2", "TimeWait", "DeleteTCB" \
143 #define TCPS_HAVE_RCVD_SYN(s) ((s) >= TCPS_SYN_RCVD)
144 #define TCPS_HAVE_ESTABLISHED (s)((s) >= TCPS_ESTABLISHED)
145 #define TCPS_HAVE_RCVD_FIN(s) ((s) >= TCPS_TIME_WAIT)
156 SYN_FIN = (TCP_SYN | TCP_FIN),
157 RST_ACK = (TCP_RST | TCP_ACK),
158 FIN_ACK = (TCP_FIN | TCP_ACK),
159 SYN_ACK = (TCP_SYN | TCP_ACK),
160 SYN_RST = (TCP_SYN | TCP_RST),
161 HDR_PREDIC = (TCP_SYN | TCP_FIN | TCP_RST | TCP_URG | TCP_ACK)
167 "FIN", "SYN", "RST", "PSH", "ACK", "URG" \
172 #define TCP_OUTPUT_FLAGS \
190 enum { SEND_EVENT, PERSIST_EVENT, RETRANSMIT_EVENT, DELETE_EVENT };
192 #define TCP_OUTPUT_EVENTS \
194 "Send", "Persist", "Rexmit", "Delete" \
209 #define TCP_OPT_SACK_LEN 2
210 #define TCP_OPT_MSS_LEN 4
211 #define TCP_OPT_WSOPT_LEN 3
212 #define TCP_OPT_TSTAMP_LEN 10
213 #define TCP_MAX_OPTIONS 32
219 #define TCP_MIN_MSS 64
221 #define TCP_NORMAL_MSS 1460
222 #define TCP_MAX_MSS (16384 - 64)
223 #define TCP_MSS_OVERHEAD 52
224 #define TCP_DEFAULT_HDR_SIZE 20
226 #ifndef ETHER_MAX_MTU
227 #define ETHER_MAX_MTU 65535
229 #define TCP_MAXWIN ETHER_MAX_MTU
230 #define TCP_MAX_WINSHIFT 14
231 #define TCP_INITIAL_CWND 4380
232 #define TCP_VEC_SIZE 1024
235 #define TCP_MSL_TV 60
237 #define TCP_REXMTMAX_TV 128
238 #define TCP_PERSMIN_TV 10
239 #define TCP_PERSMAX_TV 120
240 #define TCP_KEEP_INIT_TV 150
241 #define TCP_KEEP_IDLE_TV 14400
242 #define TCP_KEEPINTVL_TV 150
243 #define TCP_KEEPCNT_TV 8
244 #define TCP_SRTTBASE_TV 0
245 #define TCP_SRTTDFLT_TV 2
246 #define TCP_KEEPCNT_TV 8
248 #define TCP_RTT_SCALE 8
249 #define TCP_RTT_SHIFT 3
250 #define TCP_RTTVAR_SCALE 4
251 #define TCP_RTTVAR_SHIFT 2
253 #define TCP_ISSINCR 0x01000000
257 #define TCP_REXMT_TIMEOUT_MS 100UL
258 #define TCP_FAST_TIMEOUT_MS 200UL
259 #define TCP_SLOW_TIMEOUT_MS 500UL
275 #define tcpRexmtVal(_t) ((((_t)->srtt >> TCP_RTT_SHIFT) + (_t)->rttvar) / 500)
277 #define seqLT(a, b) ((int)((a) - (b)) < 0)
278 #define seqLEQ(a, b) ((int)((a) - (b)) <= 0)
279 #define seqGT(a, b) ((int)((a) - (b)) > 0)
280 #define seqGEQ(a, b) ((int)((a) - (b)) >= 0)
281 #define seqEQ(a, b) ((int)((a) - (b)) == 0)
282 #define seqNE(a, b) ((int)((a) - (b)) != 0)
284 #define TCP_MAXRXTSHIFT 12
285 #define TCP_RETRANSMIT_THRESHOLD 3
287 #define MAX_TCP_RCV_SIZE (128 * 1024)
288 #define MAX_TCP_SND_SIZE MAX_TCP_RCV_SIZE
291 #define reassPkt(_t) (*(pktmbuf_t **)&((_t)->tcp.src_port))
304 TAILQ_ENTRY(seg_entry) entry;
306 struct pcb_entry *pcb;
323 uint8_t opts[TCP_MAX_OPTIONS];
345 atomic_uint_least32_t cnt;
350 TAILQ_ENTRY(tcb_entry) entry;
353 struct tcp_q backlog_q;
354 struct tcp_q half_open_q;
357 struct tcp_entry *tcp;
358 struct pcb_entry *pcb;
359 struct pcb_entry *ppcb;
372 uint8_t req_recv_scale;
373 uint8_t req_send_scale;
375 uint32_t ts_recent_age;
387 uint32_t snd_ssthresh;
420 TCBF_FREE_BIT_1 = 0x80000000,
424 TCBF_FREE_BIT_2 = 0x04000000,
425 TCBF_FREE_BIT_3 = 0x08000000,
440 TCBF_FREE_BIT_4 = 0x00008000,
442 TCBF_FREE_BIT_5 = 0x00000100,
483 extern const char *tcb_in_states[];
488 TAILQ_ENTRY(tcb_entry) entry;
497 uint16_t default_MSS;
499 struct pcb_hd tcp_hd;
507 uint64_t S_TCPS_LISTEN;
508 uint64_t S_TCPS_SYN_SENT;
509 uint64_t S_TCPS_SYN_RCVD;
510 uint64_t S_TCPS_ESTABLISHED;
511 uint64_t S_TCPS_CLOSE_WAIT;
512 uint64_t S_TCPS_FIN_WAIT_1;
513 uint64_t S_TCPS_CLOSING;
514 uint64_t S_TCPS_LAST_ACK;
515 uint64_t S_TCPS_FIN_WAIT_2;
516 uint64_t S_TCPS_TIME_WAIT;
533 #define INC_TCP_STAT(x) \
535 this_stk->tcp_stats->S_##x++; \
539 tcp_send_seq_set(
struct tcb_entry *tcb,
int x)
541 struct tcp_entry *tcp = tcb->tcp;
543 tcb->snd_iss = tcp->snd_ISS;
545 tcb->snd_una = tcb->snd_nxt = tcb->snd_max = tcb->snd_iss;
548 static inline uint16_t
549 tcp_range_set(
int val,
int tvmin,
int tvmax)
551 return (uint16_t)((val < tvmin) ? tvmin : (val > tvmax) ? tvmax : val);
555 tcb_kill_timers(
struct tcb_entry *tcb)
557 uint64_t *p = (uint64_t *)(uintptr_t)tcb->timers;
565 static inline struct tcb_entry *
568 struct tcb_entry *tcb = NULL;
569 stk_t *stk = this_stk;
582 bit_set(stk->tcbs, idx);
590 tcb_free(
struct tcb_entry *tcb)
592 stk_t *stk = this_stk;
599 CNE_ERR(
"invalid TCB pointer\n");
602 bit_clear(stk->tcbs, idx);
603 memset(tcb, 0,
sizeof(
struct tcb_entry));
612 tcp_flags_dump(
const char *msg, uint8_t flags)
614 const char *flag_names[] = TCP_FLAGS;
618 for (
int i = 0; i < cne_countof(flag_names); i++) {
619 if (flags & (1 << i))
625 #if CNET_TCP_DUMP_ENABLED
626 #define TCP_DUMP(tcp) \
628 cne_printf("[cyan]([orange]%s[cyan]:[orange]%d[cyan]) ", __func__, __LINE__); \
629 cnet_tcp_dump(NULL, tcp); \
632 #define TCP_DUMP(tcp) \
#define CNE_NULL_RET(...)
CNDP_API int cne_printf(const char *fmt,...)
CNDP_API int cnet_tcp_connect(struct pcb_entry *pcb)
CNDP_API int cnet_tcp_close(struct pcb_entry *pcb)
CNDP_API void cnet_tcb_list(stk_t *stk, struct tcb_entry *tcb)
CNDP_API void cnet_tcp_dump(const char *msg, struct cne_tcp_hdr *tcp)
CNDP_API void cnet_tcp_abort(struct pcb_entry *pcb)
static struct tcb_entry * tcb_alloc(void)
struct tcp_stats tcp_stats_t
CNDP_API void cnet_tcp_output(struct tcb_entry *tcb)
CNDP_API int cnet_tcp_input(struct pcb_entry *pcb, pktmbuf_t *mbuf)
void * tcp_q_pop(struct tcp_q *tq)
CNDP_API struct tcb_entry * cnet_tcb_new(struct pcb_entry *pcb)
CNDP_API void cnet_tcb_dump(void)
CNDP_API int mempool_obj_index(mempool_t *mp, void *obj)
CNDP_API int mempool_get(mempool_t *mp, void **obj_p)
CNDP_API void mempool_put(mempool_t *mp, void *obj)
TAILQ_HEAD(pktdev_driver_list, pktdev_driver)
uint64_t S_data_predicted