]> git.meshlink.io Git - utcp/blob - utcp_priv.h
Add socket option functions names similar to setsockopt()/ioctl() ones.
[utcp] / utcp_priv.h
1 /*
2     utcp.h -- Userspace TCP
3     Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef UTCP_PRIV_H
21 #define UTCP_PRIV_H
22
23 #define UTCP_INTERNAL
24 #include "utcp.h"
25
26 #define PREP(l) char pkt[(l) + sizeof struct hdr]; struct hdr *hdr = &pkt;
27
28 #define SYN 1
29 #define ACK 2
30 #define FIN 4
31 #define RST 8
32
33 #define DEFAULT_SNDBUFSIZE 4096
34 #define DEFAULT_MAXSNDBUFSIZE 131072
35
36 struct hdr {
37         uint16_t src; // Source port
38         uint16_t dst; // Destination port
39         uint32_t seq; // Sequence number
40         uint32_t ack; // Acknowledgement number
41         uint32_t wnd; // Window size
42         uint16_t ctl; // Flags (SYN, ACK, FIN, RST)
43         uint16_t aux; // other stuff
44 };
45
46 enum state {
47         CLOSED,
48         LISTEN,
49         SYN_SENT,
50         SYN_RECEIVED,
51         ESTABLISHED,
52         FIN_WAIT_1,
53         FIN_WAIT_2,
54         CLOSE_WAIT,
55         CLOSING,
56         LAST_ACK,
57         TIME_WAIT
58 };
59
60 static const char *strstate[] = {
61         [CLOSED] = "CLOSED",
62         [LISTEN] = "LISTEN",
63         [SYN_SENT] = "SYN_SENT",
64         [SYN_RECEIVED] = "SYN_RECEIVED",
65         [ESTABLISHED] = "ESTABLISHED",
66         [FIN_WAIT_1] = "FIN_WAIT_1",
67         [FIN_WAIT_2] = "FIN_WAIT_2",
68         [CLOSE_WAIT] = "CLOSE_WAIT",
69         [CLOSING] = "CLOSING",
70         [LAST_ACK] = "LAST_ACK",
71         [TIME_WAIT] = "TIME_WAIT"
72 };
73
74 struct utcp_connection {
75         void *priv;
76         struct utcp *utcp;
77         bool reapable;
78
79         bool nodelay;
80         bool keepalive;
81
82         uint16_t src;
83         uint16_t dst;
84         enum state state;
85
86         // The following two structures form the TCB
87
88         struct {
89                 uint32_t una;
90                 uint32_t nxt;
91                 uint32_t wnd;
92                 uint32_t iss;
93         } snd;
94
95         struct {
96                 uint32_t nxt;
97                 uint32_t wnd;
98                 uint32_t irs;
99         } rcv;
100
101         utcp_recv_t recv;
102
103         struct timeval conn_timeout;
104         struct timeval rtrx_timeout;
105
106         char *sndbuf;
107         uint32_t sndbufsize;
108         uint32_t maxsndbufsize;
109 };
110
111 struct utcp {
112         void *priv;
113
114         utcp_accept_t accept;
115         utcp_pre_accept_t pre_accept;
116         utcp_send_t send;
117
118         uint16_t mtu;
119         int timeout;
120
121         struct utcp_connection **connections;
122         int nconnections;
123         int nallocated;
124 };
125
126 #endif