50#define SEQ_LT(a, b) ((int32_t) ((a) - (b)) < 0)
51#define SEQ_LEQ(a, b) ((int32_t) ((a) - (b)) <= 0)
52#define SEQ_GT(a, b) ((int32_t) ((a) - (b)) > 0)
53#define SEQ_GEQ(a, b) ((int32_t) ((a) - (b)) >= 0)
56#define TCP_BUFSIZE 65536
59#define TCP_MSS_DEFAULT 536
unsigned long long int uint64_t
unsigned short int uint16_t
A function to call later, with its argument.
A hash table's node: an entry, with its key's hash.
A network interface (net/netif.c): a device that sends and receives Ethernet frames,...
A connection (its control block, or PCB).
struct tcp_pcb * accept_next
struct tcp_pcb * accept_head
struct tcp_pcb * accept_tail
struct hashmap_node * hnode
void tcp_established(struct tcp_pcb *pcb)
Moves a connection to ESTABLISHED: its congestion window starts, and a listener's connection is queue...
struct tcp_pcb * tcp_lookup(uint32_t laddr, uint16_t lport, uint32_t raddr, uint16_t rport)
Finds a connection by both ends' addresses and ports.
void tcp_send_syn(struct tcp_pcb *pcb)
Sends the SYN (or, in SYN_RECEIVED, the SYN and ACK), the first time or again, and starts the retrans...
void tcp_dack(struct tcp_pcb *pcb)
Acknowledges a received segment: at once if it's the second one not acknowledged yet,...
struct tcp_pcb * tcp_pcb_new(void)
Makes a connection, CLOSED, with its send and receive buffers, on the list of connections.
void tcp_reply_rst(struct netif *netif, const struct ipv4_hdr *ih, const struct tcp_hdr *th, size_t len)
Answers a segment that is for no connection with a reset (RFC 9293 3.10.7.1).
void tcp_closed(struct tcp_pcb *pcb)
Moves a connection to CLOSED: it leaves the hashmap, its timers stop, and its waiters wake up.
struct tcp_pcb * tcp_listener(uint32_t laddr, uint16_t lport)
Finds the listener for a local address and port: one bound to that address, or else one bound to any ...
void tcp_output(struct tcp_pcb *pcb)
Sends as much of the send buffer as the windows allow, in segments of at most mss bytes.
void tcp_wakeup(struct tcp_pcb *pcb)
Wakes up the threads waiting on a connection (in accept(), connect(), recv() or send()).
void tcp_fin_wait_2(struct tcp_pcb *pcb)
Handles our FIN being acknowledged (FIN_WAIT_2): if the socket is closed, the connection waits for th...
void tcp_send_rst(struct tcp_pcb *pcb)
Sends a reset on a connection.
void tcp_send_ack(struct tcp_pcb *pcb)
Sends an ACK, now.
void tcp_time_wait(struct tcp_pcb *pcb)
Moves a connection to TIME_WAIT, which it leaves after 2 MSL.
void tcp_rtt_update(struct tcp_pcb *pcb, uint64_t rtt)
Updates the round trip estimates with a new measurement, and the retransmission timeout from them (RF...
int tcp_insert(struct tcp_pcb *pcb)
Adds a connection to the hashmap of connections, by its addresses and ports, which it must have now.
struct tcp_pcb * tcp_pcbs
void tcp_input(struct netif *netif, struct netbuf *nb, const struct ipv4_hdr *ih)
Takes in a TCP segment that IPv4 received, and passes it to its connection or listener.
uint16_t tcp_rcv_window(struct tcp_pcb *pcb)
Computes the window to advertise: the room in the receive buffer.
void tcp_rexmt_start(struct tcp_pcb *pcb)
Starts the retransmission timer, if it isn't running.
uint32_t tcp_iss(struct tcp_pcb *pcb)
Chooses a connection's initial sequence number (RFC 6528): a clock that ticks every 4 us,...
void tcp_drop(struct tcp_pcb *pcb, int err)
Drops a connection that is lost, giving its socket an error.
void tcp_send_keepalive(struct tcp_pcb *pcb)
Sends a keepalive probe: a segment one byte before what the peer has acknowledged (with no data),...
void tcp_keepalive_reset(struct tcp_pcb *pcb)
Restarts the keepalive timer, when the peer was heard from.
void tcp_pcb_free(struct tcp_pcb *pcb)
Frees a connection: its timers stop, it leaves the lists, and its buffers and waiting segments are fr...