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 #ifndef AF_INET
25 #define AF_INET 2
26 #endif
27 
28 #ifndef IPPROTO_ICMP
29 #define IPPROTO_ICMP 1
30 #endif
31 
32 #ifndef ICMP_DEST_UNREACH
33 #define ICMP_DEST_UNREACH 3
34 #endif
35 
36 #ifndef ICMP_FRAG_NEEDED
37 #define ICMP_FRAG_NEEDED 4
38 #endif
39 
40 #ifndef ICMP_NET_UNKNOWN
41 #define ICMP_NET_UNKNOWN 6
42 #endif
43 
44 #ifndef ICMP_TIME_EXCEEDED
45 #define ICMP_TIME_EXCEEDED 11
46 #endif
47 
48 #ifndef ICMP_EXC_TTL
49 #define ICMP_EXC_TTL 0
50 #endif
51 
52 #ifndef ICMP_NET_UNREACH
53 #define ICMP_NET_UNREACH 0
54 #endif
55 
56 #ifndef ICMP_NET_ANO
57 #define ICMP_NET_ANO 9
58 #endif
59 
60 #ifndef IP_MSS
61 #define       IP_MSS          576
62 #endif
63 
64 #ifndef HAVE_STRUCT_IP
65 struct ip {
66 #if __BYTE_ORDER == __LITTLE_ENDIAN
67 	unsigned int ip_hl: 4;
68 	unsigned int ip_v: 4;
69 #else
70 	unsigned int ip_v: 4;
71 	unsigned int ip_hl: 4;
72 #endif
73 	uint8_t ip_tos;
74 	uint16_t ip_len;
75 	uint16_t ip_id;
76 	uint16_t ip_off;
77 #define IP_RF 0x8000
78 #define IP_DF 0x4000
79 #define IP_MF 0x2000
80 	uint8_t ip_ttl;
81 	uint8_t ip_p;
82 	uint16_t ip_sum;
83 	struct in_addr ip_src, ip_dst;
84 } __attribute__((__gcc_struct__)) __attribute((__packed__));
85 #endif
86 
87 #ifndef IP_OFFMASK
88 #define IP_OFFMASK 0x1fff
89 #endif
90 
91 #ifndef HAVE_STRUCT_ICMP
92 struct icmp {
93 	uint8_t icmp_type;
94 	uint8_t icmp_code;
95 	uint16_t icmp_cksum;
96 	union {
97 		uint8_t ih_pptr;
98 		struct in_addr ih_gwaddr;
99 		struct ih_idseq {
100 			uint16_t icd_id;
101 			uint16_t icd_seq;
102 		} ih_idseq;
103 		uint32_t ih_void;
104 
105 
106 		struct ih_pmtu {
107 			uint16_t ipm_void;
108 			uint16_t ipm_nextmtu;
109 		} ih_pmtu;
110 
111 		struct ih_rtradv {
112 			uint8_t irt_num_addrs;
113 			uint8_t irt_wpa;
114 			uint16_t irt_lifetime;
115 		} ih_rtradv;
116 	} icmp_hun;
117 #define icmp_pptr icmp_hun.ih_pptr
118 #define icmp_gwaddr icmp_hun.ih_gwaddr
119 #define icmp_id icmp_hun.ih_idseq.icd_id
120 #define icmp_seq icmp_hun.ih_idseq.icd_seq
121 #define icmp_void icmp_hun.ih_void
122 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
123 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
124 #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
125 #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
126 #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
127 	union {
128 		struct {
129 			uint32_t its_otime;
130 			uint32_t its_rtime;
131 			uint32_t its_ttime;
132 		} id_ts;
133 		struct {
134 			struct ip idi_ip;
135 		} id_ip;
136 		uint32_t id_mask;
137 		uint8_t id_data[1];
138 	} icmp_dun;
139 #define icmp_otime icmp_dun.id_ts.its_otime
140 #define icmp_rtime icmp_dun.id_ts.its_rtime
141 #define icmp_ttime icmp_dun.id_ts.its_ttime
142 #define icmp_ip icmp_dun.id_ip.idi_ip
143 #define icmp_radv icmp_dun.id_radv
144 #define icmp_mask icmp_dun.id_mask
145 #define icmp_data icmp_dun.id_data
146 } __attribute__((__gcc_struct__)) __attribute((__packed__));
147 #endif
148 
149 #endif
150