23#include <aquila/errno.h>
50 if (end - o < 2 || o[1] < 2 || o[1] > end - o)
53 if (o[0] == 2 && o[1] == 4)
54 s->
mss = o[2] << 8 | o[3];
68 pcb->mss =
MIN(peer ? peer : TCP_MSS_DEFAULT, ours);
76 tcp_rtt_update(pcb, arch_rtime_ns() - pcb->rtt_start);
191#define IN_WINDOW(x) (SEQ_GEQ(x, nxt) && SEQ_LT(x, nxt + wnd))
238 int fin_acked = pcb->
fin_queued && acked > buffered;
280 switch (pcb->
state) {
345 if (*p && (*p)->
seq == s->
seq && (*p)->len >= s->
len) {
379 if (skip < nb->
len) {
411 switch (pcb->
state) {
449 switch (pcb->
state) {
532 int waiting = pcb->
ooo !=
NULL;
535 fin_now =
fin && n == s->
len;
537 if (!fin_now && waiting)
590 if (nb->
len <
sizeof(*th) || (hlen = (th->
off >> 4) * 4) <
sizeof(*th) || hlen > nb->
len ||
608 .data = nb->
data + hlen,
609 .len = nb->
len - hlen,
void callout_stop(struct callout *c)
Cancels a callout, if it is pending.
struct netif * ipv4_route(uint32_t dst)
Chooses the interface to send a packet to dst through: the one whose link it is on,...
int ipv4_is_local(uint32_t ip)
Says whether an address is one of ours: a loopback address, or an interface's.
uint16_t inet_checksum_pseudo(uint32_t src, uint32_t dst, uint8_t proto, const void *data, size_t len)
Computes the Internet checksum of data with the IPv4 pseudo-header before it (the addresses,...
void netbuf_free(struct netbuf *nb)
Frees a netbuf.
static void ringbuf_discard(struct ringbuf *ring, size_t n)
Throws away the first n bytes of the ring, unread (at most what it holds).
unsigned short int uint16_t
A network interface (net/netif.c): a device that sends and receives Ethernet frames,...
struct netif::@020302303320120142126121344055047003105154122231 stats
A received segment, with its header in host byte order.
A connection (its control block, or PCB).
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.
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.
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.
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_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...