BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * Copyright (C) Ambroz Bizjak <ambrop7@gmail.com> |
||
3 | * Contributions: |
||
4 | * Transparent DNS: Copyright (C) Kerem Hadimli <kerem.hadimli@gmail.com> |
||
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions are met: |
||
8 | * 1. Redistributions of source code must retain the above copyright |
||
9 | * notice, this list of conditions and the following disclaimer. |
||
10 | * 2. Redistributions in binary form must reproduce the above copyright |
||
11 | * notice, this list of conditions and the following disclaimer in the |
||
12 | * documentation and/or other materials provided with the distribution. |
||
13 | * 3. Neither the name of the author nor the |
||
14 | * names of its contributors may be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #ifndef BADVPN_PROTOCOL_UDPGW_PROTO_H |
||
30 | #define BADVPN_PROTOCOL_UDPGW_PROTO_H |
||
31 | |||
32 | #include <stdint.h> |
||
33 | |||
34 | #include <misc/bsize.h> |
||
35 | #include <misc/packed.h> |
||
36 | |||
37 | #define UDPGW_CLIENT_FLAG_KEEPALIVE (1 << 0) |
||
38 | #define UDPGW_CLIENT_FLAG_REBIND (1 << 1) |
||
39 | #define UDPGW_CLIENT_FLAG_DNS (1 << 2) |
||
40 | #define UDPGW_CLIENT_FLAG_IPV6 (1 << 3) |
||
41 | |||
42 | B_START_PACKED |
||
43 | struct udpgw_header { |
||
44 | uint8_t flags; |
||
45 | uint16_t conid; |
||
46 | } B_PACKED; |
||
47 | B_END_PACKED |
||
48 | |||
49 | B_START_PACKED |
||
50 | struct udpgw_addr_ipv4 { |
||
51 | uint32_t addr_ip; |
||
52 | uint16_t addr_port; |
||
53 | } B_PACKED; |
||
54 | B_END_PACKED |
||
55 | |||
56 | B_START_PACKED |
||
57 | struct udpgw_addr_ipv6 { |
||
58 | uint8_t addr_ip[16]; |
||
59 | uint16_t addr_port; |
||
60 | } B_PACKED; |
||
61 | B_END_PACKED |
||
62 | |||
63 | static int udpgw_compute_mtu (int dgram_mtu) |
||
64 | { |
||
65 | bsize_t bs = bsize_add( |
||
66 | bsize_fromsize(sizeof(struct udpgw_header)), |
||
67 | bsize_add( |
||
68 | bsize_max( |
||
69 | bsize_fromsize(sizeof(struct udpgw_addr_ipv4)), |
||
70 | bsize_fromsize(sizeof(struct udpgw_addr_ipv6)) |
||
71 | ), |
||
72 | bsize_fromint(dgram_mtu) |
||
73 | ) |
||
74 | ); |
||
75 | |||
76 | int s; |
||
77 | if (!bsize_toint(bs, &s)) { |
||
78 | return -1; |
||
79 | } |
||
80 | |||
81 | return s; |
||
82 | } |
||
83 | |||
84 | #endif |