2 utcp.h -- Userspace TCP
3 Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #define PREP(l) char pkt[(l) + sizeof struct hdr]; struct hdr *hdr = &pkt;
37 #define AUX_TIMESTAMP 4
40 #define DEFAULT_SNDBUFSIZE 4096
41 #define DEFAULT_MAXSNDBUFSIZE 131072
42 #define DEFAULT_RCVBUFSIZE 0
43 #define DEFAULT_MAXRCVBUFSIZE 131072
45 #define MAX_UNRELIABLE_SIZE 65535
46 #define DEFAULT_MTU 1000
48 #define USEC_PER_SEC 1000000L
49 #define NSEC_PER_SEC 1000000000L
50 #define DEFAULT_USER_TIMEOUT 60
51 #define START_RTO (1 * USEC_PER_SEC)
52 #define MAX_RTO (3 * USEC_PER_SEC)
55 uint16_t src; // Source port
56 uint16_t dst; // Destination port
57 uint32_t seq; // Sequence number
58 uint32_t ack; // Acknowledgement number
59 uint32_t wnd; // Window size
60 uint16_t ctl; // Flags (SYN, ACK, FIN, RST)
61 uint16_t aux; // other stuff
78 static const char *strstate[] __attribute__((unused)) = {
81 [SYN_SENT] = "SYN_SENT",
82 [SYN_RECEIVED] = "SYN_RECEIVED",
83 [ESTABLISHED] = "ESTABLISHED",
84 [FIN_WAIT_1] = "FIN_WAIT_1",
85 [FIN_WAIT_2] = "FIN_WAIT_2",
86 [CLOSE_WAIT] = "CLOSE_WAIT",
87 [CLOSING] = "CLOSING",
88 [LAST_ACK] = "LAST_ACK",
89 [TIME_WAIT] = "TIME_WAIT"
105 struct utcp_connection {
144 struct timespec conn_timeout;
145 struct timespec rtrx_timeout;
146 struct timespec rtt_start;
151 uint32_t srtt; // usec
152 uint32_t rttvar; // usec
153 uint32_t rto; // usec
158 struct buffer sndbuf;
159 struct buffer rcvbuf;
160 struct sack sacks[NSACKS];
162 // Per-socket options
168 // Congestion avoidance state
170 struct timespec tlast;
179 utcp_accept_t accept;
180 utcp_pre_accept_t pre_accept;
181 utcp_retransmit_t retransmit;
188 // Global socket options
190 uint16_t mtu; // The maximum size of a UTCP packet, including headers.
191 uint16_t mss; // The maximum size of the payload of a UTCP packet.
194 // Connection management
196 struct utcp_connection **connections;