]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/ipv6/lwip/ip6.h
027a20be0c5e3b4b09bf5134af7b9bf11e6c4f15
[pes-rpp/rpp-lwip.git] / src / include / ipv6 / lwip / ip6.h
1 /**
2  * @file
3  *
4  * IPv6 layer.
5  */
6
7 /*
8  * Copyright (c) 2010 Inico Technologies Ltd.
9  * All rights reserved. 
10  * 
11  * Redistribution and use in source and binary forms, with or without modification, 
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  *    this list of conditions and the following disclaimer in the documentation
18  *    and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission. 
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  * 
35  * Author: Ivan Delamer <delamer@inicotech.com>
36  *
37  *
38  * Please coordinate changes and requests with Ivan Delamer
39  * <delamer@inicotech.com>
40  */
41 #ifndef __LWIP_IP6_H__
42 #define __LWIP_IP6_H__
43
44 #include "lwip/opt.h"
45
46 #if LWIP_IPV6  /* don't build if not configured for use in lwipopts.h */
47
48 /* #include "lwip/ip.h" */
49 #include "lwip/ip6_addr.h"
50 #include "lwip/def.h"
51 #include "lwip/pbuf.h"
52 #include "lwip/netif.h"
53
54 #include "lwip/err.h"
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 #define IP6_HLEN 40
61
62 #define IP6_NEXTH_HOPBYHOP  0
63 #define IP6_NEXTH_TCP       6
64 #define IP6_NEXTH_UDP       17
65 #define IP6_NEXTH_ENCAPS    41
66 #define IP6_NEXTH_ROUTING   43
67 #define IP6_NEXTH_FRAGMENT  44
68 #define IP6_NEXTH_ICMP6     58
69 #define IP6_NEXTH_NONE      59
70 #define IP6_NEXTH_DESTOPTS  60
71 #define IP6_NEXTH_UDPLITE   136
72
73
74 /* The IPv6 header. */
75 #ifdef PACK_STRUCT_USE_INCLUDES
76 #  include "arch/bpstruct.h"
77 #endif
78 PACK_STRUCT_BEGIN
79 struct ip6_hdr {
80   /* version / traffic class / flow label */
81   PACK_STRUCT_FIELD(u32_t _v_tc_fl);
82   /* payload length */
83   PACK_STRUCT_FIELD(u16_t _plen);
84   /* next header */
85   PACK_STRUCT_FIELD(u8_t _nexth);
86   /* hop limit */
87   PACK_STRUCT_FIELD(u8_t _hoplim);
88   /* source and destination IP addresses */
89   PACK_STRUCT_FIELD(ip6_addr_p_t src);
90   PACK_STRUCT_FIELD(ip6_addr_p_t dest);
91 } PACK_STRUCT_STRUCT;
92 PACK_STRUCT_END
93 #ifdef PACK_STRUCT_USE_INCLUDES
94 #  include "arch/epstruct.h"
95 #endif
96
97 /* Hop-by-hop router alert option. */
98 #define IP6_HBH_HLEN    8
99 #define IP6_PAD1_OPTION         0
100 #define IP6_PADN_ALERT_OPTION   1
101 #define IP6_ROUTER_ALERT_OPTION 5
102 #define IP6_ROUTER_ALERT_VALUE_MLD 0
103 #ifdef PACK_STRUCT_USE_INCLUDES
104 #  include "arch/bpstruct.h"
105 #endif
106 PACK_STRUCT_BEGIN
107 struct ip6_hbh_hdr {
108   /* next header */
109   PACK_STRUCT_FIELD(u8_t _nexth);
110   /* header length */
111   PACK_STRUCT_FIELD(u8_t _hlen);
112   /* router alert option type */
113   PACK_STRUCT_FIELD(u8_t _ra_opt_type);
114   /* router alert option data len */
115   PACK_STRUCT_FIELD(u8_t _ra_opt_dlen);
116   /* router alert option data */
117   PACK_STRUCT_FIELD(u16_t _ra_opt_data);
118   /* PadN option type */
119   PACK_STRUCT_FIELD(u8_t _padn_opt_type);
120   /* PadN option data len */
121   PACK_STRUCT_FIELD(u8_t _padn_opt_dlen);
122 } PACK_STRUCT_STRUCT;
123 PACK_STRUCT_END
124 #ifdef PACK_STRUCT_USE_INCLUDES
125 #  include "arch/epstruct.h"
126 #endif
127
128 /* Fragment header. */
129 #define IP6_FRAG_HLEN    8
130 #define IP6_FRAG_OFFSET_MASK    0xfff8
131 #define IP6_FRAG_MORE_FLAG      0x0001
132 #ifdef PACK_STRUCT_USE_INCLUDES
133 #  include "arch/bpstruct.h"
134 #endif
135 PACK_STRUCT_BEGIN
136 struct ip6_frag_hdr {
137   /* next header */
138   PACK_STRUCT_FIELD(u8_t _nexth);
139   /* reserved */
140   PACK_STRUCT_FIELD(u8_t reserved);
141   /* fragment offset */
142   PACK_STRUCT_FIELD(u16_t _fragment_offset);
143   /* fragmented packet identification */
144   PACK_STRUCT_FIELD(u32_t _identification);
145 } PACK_STRUCT_STRUCT;
146 PACK_STRUCT_END
147 #ifdef PACK_STRUCT_USE_INCLUDES
148 #  include "arch/epstruct.h"
149 #endif
150
151 #define IP6H_V(hdr)  ((ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f)
152 #define IP6H_TC(hdr) ((ntohl((hdr)->_v_tc_fl) >> 20) & 0xff)
153 #define IP6H_FL(hdr) (ntohl((hdr)->_v_tc_fl) & 0x000fffff)
154 #define IP6H_PLEN(hdr) (ntohs((hdr)->_plen))
155 #define IP6H_NEXTH(hdr) ((hdr)->_nexth)
156 #define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6)
157 #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim)
158
159 #define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (htonl(((v) << 28) | ((tc) << 20) | (fl)))
160 #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen)
161 #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth)
162 #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl)
163
164
165 #define ip6_init() /* TODO should we init current addresses and header pointer? */
166 struct netif *ip6_route(struct ip6_addr *src, struct ip6_addr *dest);
167 ip6_addr_t   *ip6_select_source_address(struct netif *netif, ip6_addr_t * dest);
168 err_t         ip6_input(struct pbuf *p, struct netif *inp);
169 err_t         ip6_output(struct pbuf *p, struct ip6_addr *src, struct ip6_addr *dest,
170                          u8_t hl, u8_t tc, u8_t nexth);
171 err_t         ip6_output_if(struct pbuf *p, struct ip6_addr *src, struct ip6_addr *dest,
172                             u8_t hl, u8_t tc, u8_t nexth, struct netif *netif);
173 #if LWIP_NETIF_HWADDRHINT
174 err_t         ip6_output_hinted(struct pbuf *p, ip6_addr_t *src, ip6_addr_t *dest,
175                                 u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint);
176 #endif /* LWIP_NETIF_HWADDRHINT */
177 #if LWIP_IPV6_MLD
178 err_t         ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value);
179 #endif /* LWIP_IPV6_MLD */
180
181 #define ip6_netif_get_local_ipX(netif, dest) (((netif) != NULL) ? \
182   ip6_2_ipX(ip6_select_source_address(netif, dest)) : NULL)
183
184 #if IP6_DEBUG
185 void ip6_debug_print(struct pbuf *p);
186 #else
187 #define ip6_debug_print(p)
188 #endif /* IP6_DEBUG */
189
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* LWIP_IPV6 */
196
197 #endif /* __LWIP_IP6_H__ */