708e5c1f6b0a69d192106aefca33d9c130b679cd
[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 struct ip {
68 #if __BYTE_ORDER == __LITTLE_ENDIAN
69         unsigned int ip_hl: 4;
70         unsigned int ip_v: 4;
71 #else
72         unsigned int ip_v: 4;
73         unsigned int ip_hl: 4;
74 #endif
75         uint8_t ip_tos;
76         uint16_t ip_len;
77         uint16_t ip_id;
78         uint16_t ip_off;
79 #define IP_RF 0x8000
80 #define IP_DF 0x4000
81 #define IP_MF 0x2000
82         uint8_t ip_ttl;
83         uint8_t ip_p;
84         uint16_t ip_sum;
85         struct in_addr ip_src, ip_dst;
86 } __attribute__((__gcc_struct__)) __attribute((__packed__));
87 #endif
88
89 #ifndef IP_OFFMASK
90 #define IP_OFFMASK 0x1fff
91 #endif
92
93 #ifndef HAVE_STRUCT_ICMP
94 struct icmp {
95         uint8_t icmp_type;
96         uint8_t icmp_code;
97         uint16_t icmp_cksum;
98         union {
99                 uint8_t ih_pptr;
100                 struct in_addr ih_gwaddr;
101                 struct ih_idseq {
102                         uint16_t icd_id;
103                         uint16_t icd_seq;
104                 } ih_idseq;
105                 uint32_t ih_void;
106
107
108                 struct ih_pmtu {
109                         uint16_t ipm_void;
110                         uint16_t ipm_nextmtu;
111                 } ih_pmtu;
112
113                 struct ih_rtradv {
114                         uint8_t irt_num_addrs;
115                         uint8_t irt_wpa;
116                         uint16_t irt_lifetime;
117                 } ih_rtradv;
118         } icmp_hun;
119 #define icmp_pptr icmp_hun.ih_pptr
120 #define icmp_gwaddr icmp_hun.ih_gwaddr
121 #define icmp_id icmp_hun.ih_idseq.icd_id
122 #define icmp_seq icmp_hun.ih_idseq.icd_seq
123 #define icmp_void icmp_hun.ih_void
124 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
125 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
126 #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
127 #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
128 #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
129         union {
130                 struct {
131                         uint32_t its_otime;
132                         uint32_t its_rtime;
133                         uint32_t its_ttime;
134                 } id_ts;
135                 struct {
136                         struct ip idi_ip;
137                 } id_ip;
138                 uint32_t id_mask;
139                 uint8_t id_data[1];
140         } icmp_dun;
141 #define icmp_otime icmp_dun.id_ts.its_otime
142 #define icmp_rtime icmp_dun.id_ts.its_rtime
143 #define icmp_ttime icmp_dun.id_ts.its_ttime
144 #define icmp_ip icmp_dun.id_ip.idi_ip
145 #define icmp_radv icmp_dun.id_radv
146 #define icmp_mask icmp_dun.id_mask
147 #define icmp_data icmp_dun.id_data
148 } __attribute__((__gcc_struct__)) __attribute((__packed__));
149 #endif
150
151 #endif