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