19#include <aquila/errno.h>
21#define RTO_MIN 1000000000ULL
22#define RTO_MAX 60000000000ULL
23#define RTT_GRANULARITY 2000000ULL
24#define DACK_DELAY 100000000ULL
55 if (room < cur || (room - cur) < step)
58 return room > 0xffff ? 0xffff : room;
78 ringbuf_read_noconsume(pcb->
sndbuf, off,
len, netbuf_put(nb,
len));
89 th->
off = (hlen / 4) << 4;
204 memset(rh, 0,
sizeof(*rh));
207 rh->
off = (
sizeof(*rh) / 4) << 4;
227 switch (pcb->
state) {
257 uint32_t unsent = buffered > flight ? buffered - flight : 0;
259 uint32_t usable = wnd > flight ? wnd - flight : 0;
267 if (len < pcb->mss && !fin) {
268 if (len == unsent && flight && !pcb->
nodelay)
271 if (len < unsent && len < pcb->snd_wnd / 2)
325 pcb->
srtt = (7 * pcb->
srtt + rtt) / 8;
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,...
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,...
int ipv4_output(struct netif *netif, uint32_t src, uint32_t dst, uint8_t proto, struct netbuf *nb)
Sends a packet through an interface: adds its IPv4 header and sends it to dst, or to the gateway if d...
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
static void * netbuf_push(struct netbuf *nb, size_t size)
Makes room for a header of size bytes before the data, and returns it.
struct netbuf * netbuf_alloc(void)
Allocates a netbuf, empty, with room for the headers that will be put in front of its data.
void net_callout_set(struct callout *c, uint64_t ns, void(*fn)(void *), void *arg)
Sets a callout that the network's thread runs: fn(arg) is called once ns ns have passed.
unsigned long long int uint64_t
unsigned short int uint16_t
A network interface (net/netif.c): a device that sends and receives Ethernet frames,...
A connection (its control block, or PCB).
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,...
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_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_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_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...
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.
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),...
static uint16_t our_mss(struct tcp_pcb *pcb)
Returns the most data a segment we send may carry: the interface's MTU, less the headers.
static int sending(struct tcp_pcb *pcb)
Returns whether data and the FIN may be sent in the connection's state.
static void rexmt_timeout(void *arg)
Handles the retransmission timer.
static int segment(struct tcp_pcb *pcb, uint32_t seq, int flags, size_t off, size_t len)
Sends a segment with sequence number seq, carrying len bytes of the send buffer from offset off,...
static void dack_timeout(void *arg)
Sends the delayed ACK, when its delay is over.
uint64_t arch_rtime_ns(void)
Reads the monotonic clock, which starts at boot.