|
ginnOS
The reference: libc, the libraries and the kernel
|
TCP (see tcp.h). More...
#include "tcp.h"#include "byteorder.h"#include "checksum.h"#include "common/memory.h"#include "kernel/errno.h"#include "kernel/memory/heap.h"#include "kernel/random/random.h"#include "kernel/time/timer.h"#include "kernel/vfs/poll.h"#include "netif.h"Macros | |
| #define | HEADER_SIZE 20 |
| #define | OPTION_MSS 2 |
| #define | FLAG_FIN 0x01 |
| #define | FLAG_SYN 0x02 |
| #define | FLAG_RST 0x04 |
| #define | FLAG_PSH 0x08 |
| #define | FLAG_ACK 0x10 |
| #define | DEFAULT_MSS 536 |
| #define | INITIAL_RTO_MS 1000 |
| #define | MIN_RTO_MS 200 |
| #define | MAX_RTO_MS 60000 |
| #define | INITIAL_CWND 10 |
| #define | ORPHAN_FIN_WAIT_2_MS 60000 |
Functions | |
| uint32_t | tcp_send_room (const tcp_conn_t *c) |
| the room in the send buffer. | |
| bool | tcp_can_send (const tcp_conn_t *c) |
| true in the states where the user can send data. | |
| void | tcp_receive (netif_t *netif, const ipv4_header_t *ip, const uint8_t *seg, uint32_t length) |
| a received segment (net_lock held). | |
| tcp_conn_t * | tcp_connect (uint32_t local, uint16_t local_port, uint32_t remote, uint16_t remote_port) |
| start a connection: send a SYN (net_lock held). | |
| tcp_conn_t * | tcp_listen (uint32_t local, uint16_t local_port, uint32_t backlog) |
| a listener on a port (net_lock held). | |
| tcp_conn_t * | tcp_accept (tcp_conn_t *listener) |
| take the next connection from a listener's queue (net_lock held). | |
| uint32_t | tcp_write (tcp_conn_t *c, const uint8_t *data, uint32_t length) |
| put data into the send buffer and send what the windows allow (net_lock held). | |
| uint32_t | tcp_read (tcp_conn_t *c, uint8_t *out, uint32_t length, bool peek) |
| take data from the receive buffer (net_lock held). | |
| void | tcp_shutdown_write (tcp_conn_t *c) |
| no more data from the user: send FIN after the data (net_lock held). | |
| void | tcp_release (tcp_conn_t *c) |
| the socket lets the connection go (net_lock held): a listener resets the connections in its queue; a connection with data the user did not read is reset; any other is closed with FIN. | |
| void | tcp_timer (uint64_t now) |
| the timers, each tick (net_lock is taken here). | |
| void | tcp_init (void) |
| set up TCP (from net_init): the timer. | |
TCP (see tcp.h).
sequence numbers wrap, so they are compared with seq_lt and the others, which look at the signed difference.
| #define HEADER_SIZE 20 |
| #define OPTION_MSS 2 |
| #define FLAG_FIN 0x01 |
| #define FLAG_SYN 0x02 |
| #define FLAG_RST 0x04 |
| #define FLAG_PSH 0x08 |
| #define FLAG_ACK 0x10 |
| #define DEFAULT_MSS 536 |
| #define INITIAL_RTO_MS 1000 |
| #define MIN_RTO_MS 200 |
| #define MAX_RTO_MS 60000 |
| #define INITIAL_CWND 10 |
| #define ORPHAN_FIN_WAIT_2_MS 60000 |
| uint32_t tcp_send_room | ( | const tcp_conn_t * | c | ) |
the room in the send buffer.
| bool tcp_can_send | ( | const tcp_conn_t * | c | ) |
true in the states where the user can send data.
| void tcp_receive | ( | netif_t * | netif, |
| const ipv4_header_t * | ip, | ||
| const uint8_t * | seg, | ||
| uint32_t | length ) |
a received segment (net_lock held).
| tcp_conn_t * tcp_connect | ( | uint32_t | local, |
| uint16_t | local_port, | ||
| uint32_t | remote, | ||
| uint16_t | remote_port ) |
start a connection: send a SYN (net_lock held).
| tcp_conn_t * tcp_listen | ( | uint32_t | local, |
| uint16_t | local_port, | ||
| uint32_t | backlog ) |
a listener on a port (net_lock held).
| local | the address, or 0 for any. |
| tcp_conn_t * tcp_accept | ( | tcp_conn_t * | listener | ) |
take the next connection from a listener's queue (net_lock held).
| uint32_t tcp_write | ( | tcp_conn_t * | conn, |
| const uint8_t * | data, | ||
| uint32_t | length ) |
put data into the send buffer and send what the windows allow (net_lock held).
| uint32_t tcp_read | ( | tcp_conn_t * | conn, |
| uint8_t * | out, | ||
| uint32_t | length, | ||
| bool | peek ) |
take data from the receive buffer (net_lock held).
this opens the window again, and the peer is told when that matters.
| peek | leave the data in the buffer. |
| void tcp_shutdown_write | ( | tcp_conn_t * | c | ) |
no more data from the user: send FIN after the data (net_lock held).
| void tcp_release | ( | tcp_conn_t * | conn | ) |
the socket lets the connection go (net_lock held): a listener resets the connections in its queue; a connection with data the user did not read is reset; any other is closed with FIN.
the connection is freed when it is closed.
| void tcp_timer | ( | uint64_t | now | ) |
the timers, each tick (net_lock is taken here).
| void tcp_init | ( | void | ) |
set up TCP (from net_init): the timer.