Generic device driver for *BSD and MacOS/X
[tinc] / lib / ipv6.h
1 /*
2     ipv6.h -- missing IPv6 related definitions
3     Copyright (C) 2004 Ivo Timmermans <ivo@tinc-vpn.org>
4                   2004 Guus Sliepen <guus@tinc-vpn.org>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id$
21 */
22
23 #ifndef __TINC_IPV6_H__
24 #define __TINC_IPV6_H__
25
26 #ifndef AF_INET6
27 #define AF_INET6 10
28 #endif
29
30 #ifndef IPPROTO_ICMPV6
31 #define IPPROTO_ICMPV6 58
32 #endif
33
34 #ifndef HAVE_STRUCT_IN6_ADDR
35 struct in6_addr {
36         union {
37                 uint8_t u6_addr8[16];
38                 uint16_t u6_addr16[8];
39                 uint32_t u6_addr32[4];
40         } in6_u;
41 } __attribute__ ((__packed__));
42 #define s6_addr in6_u.u6_addr8
43 #define s6_addr16 in6_u.u6_addr16
44 #define s6_addr32 in6_u.u6_addr32
45 #endif
46
47 #ifndef HAVE_STRUCT_SOCKADDR_IN6
48 struct sockaddr_in6 {
49         uint16_t sin6_family;
50         uint16_t sin6_port;
51         uint32_t sin6_flowinfo;
52         struct in6_addr sin6_addr;
53         uint32_t sin6_scope_id;
54 } __attribute__ ((__packed__));
55 #endif
56
57 #ifndef IN6_IS_ADDR_V4MAPPED
58 #define IN6_IS_ADDR_V4MAPPED(a) \
59         ((((__const uint32_t *) (a))[0] == 0) \
60         && (((__const uint32_t *) (a))[1] == 0) \
61         && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
62 #endif
63
64 #ifndef HAVE_STRUCT_IP6_HDR
65 struct ip6_hdr {
66         union {
67                 struct ip6_hdrctl {
68                         uint32_t ip6_un1_flow;
69                         uint16_t ip6_un1_plen;
70                         uint8_t ip6_un1_nxt;
71                         uint8_t ip6_un1_hlim;
72                 } ip6_un1;
73                 uint8_t ip6_un2_vfc;
74         } ip6_ctlun;
75         struct in6_addr ip6_src;
76         struct in6_addr ip6_dst;
77 } __attribute__ ((__packed__));
78 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
79 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
80 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
81 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
82 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
83 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
84 #endif
85
86 #ifndef HAVE_STRUCT_ICMP6_HDR
87 struct icmp6_hdr {
88         uint8_t icmp6_type;
89         uint8_t icmp6_code;
90         uint16_t icmp6_cksum;
91         union {
92                 uint32_t icmp6_un_data32[1];
93                 uint16_t icmp6_un_data16[2];
94                 uint8_t icmp6_un_data8[4];
95         } icmp6_dataun;
96 } __attribute__ ((__packed__));
97 #define ICMP6_DST_UNREACH_NOROUTE 0
98 #define ICMP6_DST_UNREACH 1
99 #define ICMP6_PACKET_TOO_BIG 2
100 #define ICMP6_DST_UNREACH_ADDR 3
101 #define ND_NEIGHBOR_SOLICIT 135
102 #define ND_NEIGHBOR_ADVERT 136
103 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
104 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
105 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
106 #define icmp6_mtu icmp6_data32[0]
107 #endif
108
109 #ifndef HAVE_STRUCT_ND_NEIGHBOR_SOLICIT
110 struct nd_neighbor_solicit {
111         struct icmp6_hdr nd_ns_hdr;
112         struct in6_addr nd_ns_target;
113 } __attribute__ ((__packed__));
114 #define ND_OPT_SOURCE_LINKADDR 1
115 #define ND_OPT_TARGET_LINKADDR 2
116 #define nd_ns_type nd_ns_hdr.icmp6_type
117 #define nd_ns_code nd_ns_hdr.icmp6_code
118 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
119 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
120 #endif
121
122 #ifndef HAVE_STRUCT_ND_OPT_HDR
123 struct nd_opt_hdr {
124         uint8_t nd_opt_type;
125         uint8_t nd_opt_len;
126 } __attribute__ ((__packed__));
127 #endif
128
129 #endif /* __TINC_IPV6_H__ */