]> git.meshlink.io Git - utcp/blob - utcp_priv.h
Move private struct declarations e.a. to utcp_priv.h.
[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 struct hdr {
34         uint16_t src; // Source port
35         uint16_t dst; // Destination port
36         uint32_t seq; // Sequence number
37         uint32_t ack; // Acknowledgement number
38         uint32_t wnd; // Window size
39         uint16_t ctl; // Flags (SYN, ACK, FIN, RST)
40         uint16_t aux; // other stuff
41 };
42
43 enum state {
44         CLOSED,
45         LISTEN,
46         SYN_SENT,
47         SYN_RECEIVED,
48         ESTABLISHED,
49         FIN_WAIT_1,
50         FIN_WAIT_2,
51         CLOSE_WAIT,
52         CLOSING,
53         LAST_ACK,
54         TIME_WAIT
55 };
56
57 static const char *strstate[] = {
58         [CLOSED] = "CLOSED",
59         [LISTEN] = "LISTEN",
60         [SYN_SENT] = "SYN_SENT",
61         [SYN_RECEIVED] = "SYN_RECEIVED",
62         [ESTABLISHED] = "ESTABLISHED",
63         [FIN_WAIT_1] = "FIN_WAIT_1",
64         [FIN_WAIT_2] = "FIN_WAIT_2",
65         [CLOSE_WAIT] = "CLOSE_WAIT",
66         [CLOSING] = "CLOSING",
67         [LAST_ACK] = "LAST_ACK",
68         [TIME_WAIT] = "TIME_WAIT"
69 };
70
71 struct utcp_connection {
72         void *priv;
73         struct utcp *utcp;
74         bool reapable;
75
76         uint16_t src;
77         uint16_t dst;
78         enum state state;
79
80         // The following two structures form the TCB
81
82         struct {
83                 uint32_t una;
84                 uint32_t nxt;
85                 uint32_t wnd;
86                 uint32_t iss;
87         } snd;
88
89         struct {
90                 uint32_t nxt;
91                 uint32_t wnd;
92                 uint32_t irs;
93         } rcv;
94
95         utcp_recv_t recv;
96
97         struct timeval conn_timeout;
98         struct timeval rtrx_timeout;
99
100         char *sndbuf;
101         uint32_t sndbufsize;
102 };
103
104 struct utcp {
105         void *priv;
106
107         utcp_accept_t accept;
108         utcp_pre_accept_t pre_accept;
109         utcp_send_t send;
110
111         uint16_t mtu;
112         int timeout;
113
114         struct utcp_connection **connections;
115         int nconnections;
116         int nallocated;
117 };
118
119 #endif