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;
36 #define AUX_TIMESTAMP 4
39 #define DEFAULT_SNDBUFSIZE 4096
40 #define DEFAULT_MAXSNDBUFSIZE 131072
41 #define DEFAULT_RCVBUFSIZE 0
42 #define DEFAULT_MAXRCVBUFSIZE 131072
44 #define DEFAULT_MTU 1000
46 #define USEC_PER_SEC 1000000
47 #define DEFAULT_USER_TIMEOUT 60 // sec
48 #define CLOCK_GRANULARITY 1000 // usec
49 #define START_RTO 1000000 // usec
50 #define MAX_RTO 3000000 // usec
53 uint16_t src; // Source port
54 uint16_t dst; // Destination port
55 uint32_t seq; // Sequence number
56 uint32_t ack; // Acknowledgement number
57 uint32_t wnd; // Window size
58 uint16_t ctl; // Flags (SYN, ACK, FIN, RST)
59 uint16_t aux; // other stuff
76 static const char *strstate[] __attribute__((unused)) = {
79 [SYN_SENT] = "SYN_SENT",
80 [SYN_RECEIVED] = "SYN_RECEIVED",
81 [ESTABLISHED] = "ESTABLISHED",
82 [FIN_WAIT_1] = "FIN_WAIT_1",
83 [FIN_WAIT_2] = "FIN_WAIT_2",
84 [CLOSE_WAIT] = "CLOSE_WAIT",
85 [CLOSING] = "CLOSING",
86 [LAST_ACK] = "LAST_ACK",
87 [TIME_WAIT] = "TIME_WAIT"
103 struct utcp_connection {
141 struct timeval conn_timeout;
142 struct timeval rtrx_timeout;
143 struct timeval rtt_start;
148 struct buffer sndbuf;
149 struct buffer rcvbuf;
150 struct sack sacks[NSACKS];
152 // Per-socket options
158 // Congestion avoidance state
160 struct timeval tlast;
169 utcp_accept_t accept;
170 utcp_pre_accept_t pre_accept;
177 // Global socket options
179 uint16_t mtu; // The maximum size of a UTCP packet, including headers.
180 uint16_t mss; // The maximum size of the payload of a UTCP packet.
185 uint32_t srtt; // usec
186 uint32_t rttvar; // usec
187 uint32_t rto; // usec
189 // Connection management
191 struct utcp_connection **connections;