GitHub CI: update list of container images
[tinc] / src / ipv4.h
1 #ifndef TINC_IPV4_H
2 #define TINC_IPV4_H
3
4 /*
5     ipv4.h -- missing IPv4 related definitions
6     Copyright (C) 2005 Ivo Timmermans
7                   2006-2012 Guus Sliepen <guus@tinc-vpn.org>
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License along
20     with this program; if not, write to the Free Software Foundation, Inc.,
21     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #include "system.h"
25
26 #ifndef AF_INET
27 #define AF_INET 2
28 #endif
29
30 #ifndef IPPROTO_ICMP
31 #define IPPROTO_ICMP 1
32 #endif
33
34 #ifndef ICMP_DEST_UNREACH
35 #define ICMP_DEST_UNREACH 3
36 #endif
37
38 #ifndef ICMP_FRAG_NEEDED
39 #define ICMP_FRAG_NEEDED 4
40 #endif
41
42 #ifndef ICMP_NET_UNKNOWN
43 #define ICMP_NET_UNKNOWN 6
44 #endif
45
46 #ifndef ICMP_TIME_EXCEEDED
47 #define ICMP_TIME_EXCEEDED 11
48 #endif
49
50 #ifndef ICMP_EXC_TTL
51 #define ICMP_EXC_TTL 0
52 #endif
53
54 #ifndef ICMP_NET_UNREACH
55 #define ICMP_NET_UNREACH 0
56 #endif
57
58 #ifndef ICMP_NET_ANO
59 #define ICMP_NET_ANO 9
60 #endif
61
62 #ifndef IP_MSS
63 #define       IP_MSS          576
64 #endif
65
66 #ifndef HAVE_STRUCT_IP
67 #if __BYTE_ORDER == __LITTLE_ENDIAN
68 #define IP_NIBBLE1 ip_hl
69 #define IP_NIBBLE2 ip_v
70 #else
71 #define IP_NIBBLE1 ip_v
72 #define IP_NIBBLE2 ip_hl
73 #endif
74 PACKED(struct ip {
75         uint8_t IP_NIBBLE1: 4;
76         uint8_t IP_NIBBLE2: 4;
77         uint8_t ip_tos;
78         uint16_t ip_len;
79         uint16_t ip_id;
80         uint16_t ip_off;
81         uint8_t ip_ttl;
82         uint8_t ip_p;
83         uint16_t ip_sum;
84         struct in_addr ip_src, ip_dst;
85 });
86 #undef IP_NIBBLE1
87 #undef IP_NIBBLE2
88 #define IP_RF 0x8000
89 #define IP_DF 0x4000
90 #define IP_MF 0x2000
91 #endif
92
93 STATIC_ASSERT(sizeof(struct ip) == 20, "ip has incorrect size");
94
95 #ifndef IP_OFFMASK
96 #define IP_OFFMASK 0x1fff
97 #endif
98
99 #ifndef HAVE_STRUCT_ICMP
100 PACKED(struct icmp {
101         uint8_t icmp_type;
102         uint8_t icmp_code;
103         uint16_t icmp_cksum;
104         union {
105                 uint8_t ih_pptr;
106                 struct in_addr ih_gwaddr;
107                 struct ih_idseq {
108                         uint16_t icd_id;
109                         uint16_t icd_seq;
110                 } ih_idseq;
111                 uint32_t ih_void;
112
113
114                 struct ih_pmtu {
115                         uint16_t ipm_void;
116                         uint16_t ipm_nextmtu;
117                 } ih_pmtu;
118
119                 struct ih_rtradv {
120                         uint8_t irt_num_addrs;
121                         uint8_t irt_wpa;
122                         uint16_t irt_lifetime;
123                 } ih_rtradv;
124         } icmp_hun;
125         union {
126                 struct {
127                         uint32_t its_otime;
128                         uint32_t its_rtime;
129                         uint32_t its_ttime;
130                 } id_ts;
131                 struct {
132                         struct ip idi_ip;
133                 } id_ip;
134                 uint32_t id_mask;
135                 uint8_t id_data[1];
136         } icmp_dun;
137 });
138 #define icmp_pptr icmp_hun.ih_pptr
139 #define icmp_gwaddr icmp_hun.ih_gwaddr
140 #define icmp_id icmp_hun.ih_idseq.icd_id
141 #define icmp_seq icmp_hun.ih_idseq.icd_seq
142 #define icmp_void icmp_hun.ih_void
143 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
144 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
145 #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
146 #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
147 #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
148 #define icmp_otime icmp_dun.id_ts.its_otime
149 #define icmp_rtime icmp_dun.id_ts.its_rtime
150 #define icmp_ttime icmp_dun.id_ts.its_ttime
151 #define icmp_ip icmp_dun.id_ip.idi_ip
152 #define icmp_radv icmp_dun.id_radv
153 #define icmp_mask icmp_dun.id_mask
154 #define icmp_data icmp_dun.id_data
155 #endif
156
157 STATIC_ASSERT(sizeof(struct icmp) == 28, "icmp has incorrect size");
158
159 #endif