8 * Copyright (c) 2010 Inico Technologies Ltd.
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
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.
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
33 * This file is part of the lwIP TCP/IP stack.
35 * Author: Ivan Delamer <delamer@inicotech.com>
38 * Please coordinate changes and requests with Ivan Delamer
39 * <delamer@inicotech.com>
41 #ifndef __LWIP_IP6_H__
42 #define __LWIP_IP6_H__
46 #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
48 /* #include "lwip/ip.h" */
49 #include "lwip/ip6_addr.h"
51 #include "lwip/pbuf.h"
52 #include "lwip/netif.h"
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
74 /* The IPv6 header. */
75 #ifdef PACK_STRUCT_USE_INCLUDES
76 # include "arch/bpstruct.h"
80 /* version / traffic class / flow label */
81 PACK_STRUCT_FIELD(u32_t _v_tc_fl);
83 PACK_STRUCT_FIELD(u16_t _plen);
85 PACK_STRUCT_FIELD(u8_t _nexth);
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);
93 #ifdef PACK_STRUCT_USE_INCLUDES
94 # include "arch/epstruct.h"
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"
109 PACK_STRUCT_FIELD(u8_t _nexth);
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;
124 #ifdef PACK_STRUCT_USE_INCLUDES
125 # include "arch/epstruct.h"
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"
136 struct ip6_frag_hdr {
138 PACK_STRUCT_FIELD(u8_t _nexth);
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;
147 #ifdef PACK_STRUCT_USE_INCLUDES
148 # include "arch/epstruct.h"
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)
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)
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 */
178 err_t ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value);
179 #endif /* LWIP_IPV6_MLD */
181 #define ip6_netif_get_local_ipX(netif, dest) (((netif) != NULL) ? \
182 ip6_2_ipX(ip6_select_source_address(netif, dest)) : NULL)
185 void ip6_debug_print(struct pbuf *p);
187 #define ip6_debug_print(p)
188 #endif /* IP6_DEBUG */
195 #endif /* LWIP_IPV6 */
197 #endif /* __LWIP_IP6_H__ */