• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file
3  *
4  * IPv6 addresses.
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  * Structs and macros for handling IPv6 addresses.
38  *
39  * Please coordinate changes and requests with Ivan Delamer
40  * <delamer@inicotech.com>
41  */
42 #ifndef LWIP_HDR_IP6_ADDR_H
43 #define LWIP_HDR_IP6_ADDR_H
44 
45 #include "lwip/opt.h"
46 #include "def.h"
47 
48 #if LWIP_IPV6  /* don't build if not configured for use in lwipopts.h */
49 
50 #include "lwip/ip6_zone.h"
51 
52 #if defined (__cplusplus) && __cplusplus
53 extern "C" {
54 #endif
55 
56 #define IP6_ADDR_U32_ARR_SIZE  4
57 
58 /** This is the aligned version of ip6_addr_t,
59     used as local variable, on the stack, etc. */
60 struct ip6_addr {
61   u32_t addr[IP6_ADDR_U32_ARR_SIZE];
62 #if LWIP_IPV6_SCOPES
63   u8_t zone;
64 #endif /* LWIP_IPV6_SCOPES */
65 };
66 
67 /** IPv6 address */
68 typedef struct ip6_addr ip6_addr_t;
69 
70 /** Set an IPv6 partial address given by byte-parts */
71 #define IP6_ADDR_PART(ip6addr, index, a, b, c, d) \
72   (ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a, b, c, d))
73 
74 /** Set a full IPv6 address by passing the 4 u32_t indices in network byte order
75     (use PP_HTONL() for constants) */
76 #define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
77   (ip6addr)->addr[0] = idx0; \
78   (ip6addr)->addr[1] = idx1; \
79   (ip6addr)->addr[2] = idx2; \
80   (ip6addr)->addr[3] = idx3; \
81   ip6_addr_clear_zone(ip6addr); } while(0)
82 
83 /** Access address in 16-bit block */
84 #define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
85 /** Access address in 16-bit block */
86 #define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
87 /** Access address in 16-bit block */
88 #define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
89 /** Access address in 16-bit block */
90 #define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
91 /** Access address in 16-bit block */
92 #define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
93 /** Access address in 16-bit block */
94 #define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
95 /** Access address in 16-bit block */
96 #define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
97 /** Access address in 16-bit block */
98 #define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
99 
100 #if LWIP_SMALL_SIZE
101 extern const ip6_addr_t ip6_addr_none;
102 extern const ip6_addr_t ip6_addr_loopback;
103 extern const ip6_addr_t ip6_addr_allnodes_iflocal;
104 extern const ip6_addr_t ip6_addr_allnodes_linklocal;
105 extern const ip6_addr_t ip6_addr_allrpl_nodes_linklocal;
106 extern const ip6_addr_t ip6_addr_mpl_ip4_bcast;
107 extern const ip6_addr_t ip6_addr_allrouters_linklocal;
108 void ip6_addr_set_fun(ip6_addr_t *dest, ip6_addr_t* src);
109 #endif
110 
111 /** Copy IPv6 address - faster than ip6_addr_set: no NULL check */
112 #define ip6_addr_copy(dest, src) do { (dest).addr[0] = (src).addr[0]; \
113                                       (dest).addr[1] = (src).addr[1]; \
114                                       (dest).addr[2] = (src).addr[2]; \
115                                       (dest).addr[3] = (src).addr[3]; \
116                                       ip6_addr_copy_zone((dest), (src)); }while(0)
117 #define ip6_addr_copy_ptr(dest, src) do { (dest)->addr[0] = (src)->addr[0]; \
118                                           (dest)->addr[1] = (src)->addr[1]; \
119                                           (dest)->addr[2] = (src)->addr[2]; \
120                                           (dest)->addr[3] = (src)->addr[3]; } while (0)
121 
122 /** Safely copy one IPv6 address to another (src may be NULL) */
123 #if LWIP_SMALL_SIZE
124 #define ip6_addr_set(dest, src) ip6_addr_set_fun((ip6_addr_t *)dest, (ip6_addr_t *)src)
125 #else
126 #define ip6_addr_set(dest, src) do { (dest)->addr[0] = (src) == (void *)NULL ? 0 : (src)->addr[0]; \
127                                      (dest)->addr[1] = (src) == (void *)NULL ? 0 : (src)->addr[1]; \
128                                      (dest)->addr[2] = (src) == (void *)NULL ? 0 : (src)->addr[2]; \
129                                      (dest)->addr[3] = (src) == (void *)NULL ? 0 : (src)->addr[3]; \
130 									 ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src)); } while (0)
131 #endif
132 
133 #define ip6_addr_set_val(dest, src) do { (dest)->addr[0] = (src)->addr[0]; \
134                                          (dest)->addr[1] = (src)->addr[1]; \
135                                          (dest)->addr[2] = (src)->addr[2]; \
136                                          (dest)->addr[3] = (src)->addr[3]; \
137                                          ip6_addr_set_zone((dest), ip6_addr_zone(src)); } while (0)
138 
139 /** Copy packed IPv6 address to unpacked IPv6 address; zone is not set */
140 #define ip6_addr_copy_from_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \
141                                     (dest).addr[1] = (src).addr[1]; \
142                                     (dest).addr[2] = (src).addr[2]; \
143                                     (dest).addr[3] = (src).addr[3]; \
144                                     ip6_addr_clear_zone(&dest); }while(0)
145 
146 /** Copy unpacked IPv6 address to packed IPv6 address; zone is lost */
147 #define ip6_addr_copy_to_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \
148                                     (dest).addr[1] = (src).addr[1]; \
149                                     (dest).addr[2] = (src).addr[2]; \
150                                     (dest).addr[3] = (src).addr[3]; }while(0)
151 
152 /** Set complete address to zero */
153 #define ip6_addr_set_zero(ip6addr)    do { (ip6addr)->addr[0] = 0; \
154                                            (ip6addr)->addr[1] = 0; \
155                                            (ip6addr)->addr[2] = 0; \
156                                            (ip6addr)->addr[3] = 0; \
157 										   ip6_addr_clear_zone(ip6addr); } while (0)
158 
159 /** Set address to ipv6 'any' (no need for lwip_htonl()) */
160 #define ip6_addr_set_any(ip6addr)       ip6_addr_set_zero(ip6addr)
161 /** Set address to ipv6 loopback address */
162 #define ip6_addr_set_loopback(ip6addr) do { (ip6addr)->addr[0] = 0; \
163                                             (ip6addr)->addr[1] = 0; \
164                                             (ip6addr)->addr[2] = 0; \
165                                             (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
166 											ip6_addr_clear_zone(ip6addr); } while (0)
167 /** Safely copy one IPv6 address to another and change byte order
168  * from host- to network-order. */
169 #define ip6_addr_set_hton(dest, src) do { (dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
170                                           (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
171                                           (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
172                                           (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]); \
173 										  ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src)); } while (0)
174 
175 #if defined(LWIP_RA_PREFIX_DYNAMIC) && LWIP_RA_PREFIX_DYNAMIC
176 #define LWIP_RA_PREFIX_LONG 80
177 #endif
178 
179 /** Compare IPv6 networks, ignoring zone information. To be used sparingly! */
180 #define ip6_addr_netcmp_zoneless(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
181                                                ((addr1)->addr[1] == (addr2)->addr[1]))
182 
183 /**
184  * Determine if two IPv6 address are on the same network.
185  *
186  * @param addr1 IPv6 address 1
187  * @param addr2 IPv6 address 2
188  * @return 1 if the network identifiers of both address match, 0 if not
189  */
190 #define ip6_addr_netcmp(addr1, addr2) (ip6_addr_netcmp_zoneless((addr1), (addr2)) && \
191                                        ip6_addr_cmp_zone((addr1), (addr2)))
192 
193 /* Exact-host comparison *after* ip6_addr_netcmp() succeeded, for efficiency. */
194 #define ip6_addr_nethostcmp(addr1, addr2) (((addr1)->addr[2] == (addr2)->addr[2]) && \
195                                            ((addr1)->addr[3] == (addr2)->addr[3]))
196 
197 #define ip6_addr_prefix_netcmp(addr1, addr2, len) (((len) > 0) ? (memcmp((addr1), (addr2), (len)) == 0) : \
198                                                     ip6_addr_netcmp((addr1), (addr2)))
199 
200 /** Compare IPv6 addresses, ignoring zone information. To be used sparingly! */
201 #define ip6_addr_cmp_zoneless(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
202                                     ((addr1)->addr[1] == (addr2)->addr[1]) && \
203                                     ((addr1)->addr[2] == (addr2)->addr[2]) && \
204                                     ((addr1)->addr[3] == (addr2)->addr[3]))
205 
206 /**
207  * Determine if two IPv6 addresses are the same. In particular, the address
208  * part of both must be the same, and the zone must be compatible.
209  *
210  * @param addr1 IPv6 address 1
211  * @param addr2 IPv6 address 2
212  * @return 1 if the addresses are considered equal, 0 if not
213  */
214 #define ip6_addr_cmp(addr1, addr2) (ip6_addr_cmp_zoneless((addr1), (addr2)) && \
215                                     ip6_addr_cmp_zone((addr1), (addr2)))
216 
217 /** Compare IPv6 address to packed address and zone */
218 #define ip6_addr_cmp_packed(ip6addr, paddr, zone_idx) (((ip6addr)->addr[0] == (paddr)->addr[0]) && \
219                                     ((ip6addr)->addr[1] == (paddr)->addr[1]) && \
220                                     ((ip6addr)->addr[2] == (paddr)->addr[2]) && \
221                                     ((ip6addr)->addr[3] == (paddr)->addr[3]) && \
222                                     ip6_addr_equals_zone((ip6addr), (zone_idx)))
223 
224 #define ip6_get_subnet_id(ip6addr)   (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
225 
226 #if LWIP_SMALL_SIZE
227 #define ip6_addr_isany_val(ip6addr) (memcmp(&ip6addr, ip_2_ip6(&ip6_addr_any), sizeof(ip6_addr_t)) == 0)
228 #define ip6_addr_isnone_val(ip6addr) (memcmp(&ip6addr, &ip6_addr_none, sizeof(ip6_addr_t)) == 0)
229 #else
230 #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
231                                      ((ip6addr).addr[1] == 0) && \
232                                      ((ip6addr).addr[2] == 0) && \
233                                      ((ip6addr).addr[3] == 0))
234 #define ip6_addr_isnone_val(ip6addr) (((ip6addr).addr[0] == 0xffffffffUL) && \
235                                      ((ip6addr).addr[1] == 0xffffffffUL) && \
236                                      ((ip6addr).addr[2] == 0xffffffffUL) && \
237                                      ((ip6addr).addr[3] == 0xffffffffUL))
238 #endif
239 #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
240 #define ip6_addr_isnone(ip6addr) (((ip6addr) == NULL) || ip6_addr_isnone_val(*(ip6addr)))
241 #if LWIP_SMALL_SIZE
242 #define ip6_addr_isloopback(ip6addr) (memcmp(ip6addr, &ip6_addr_loopback, sizeof(ip6_addr_t)) == 0)
243 #else
244 #define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
245                                       ((ip6addr)->addr[1] == 0UL) && \
246                                       ((ip6addr)->addr[2] == 0UL) && \
247                                       ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
248 #endif
249 #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
250 
251 #define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
252 
253 #define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
254 
255 #define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
256 
257 #define ip6_addr_isipv4mappedipv6(ip6addr) \
258   (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && \
259   (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
260 #define ip6_addr_isipv4compatible(ip6addr) \
261   (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && \
262   ((ip6addr)->addr[2] == 0)  && (PP_NTOHL((ip6addr)->addr[3]) > 1))
263 
264 #define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
265 #define ip6_addr_link_local_ismulticast(ip6addr) \
266   (((ip6addr)->addr[0] & PP_HTONL(0xff020000UL)) == PP_HTONL(0xff020000UL))
267 #define ip6_addr_multicast_transient_flag(ip6addr)  ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
268 #define ip6_addr_multicast_prefix_flag(ip6addr)     ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
269 #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
270 #define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
271 #define IP6_MULTICAST_SCOPE_RESERVED            0x0
272 #define IP6_MULTICAST_SCOPE_RESERVED0           0x0
273 #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL     0x1
274 #define IP6_MULTICAST_SCOPE_LINK_LOCAL          0x2
275 #define IP6_MULTICAST_SCOPE_RESERVED3           0x3
276 #define IP6_MULTICAST_SCOPE_ADMIN_LOCAL         0x4
277 #define IP6_MULTICAST_SCOPE_SITE_LOCAL          0x5
278 #define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL  0x8
279 #define IP6_MULTICAST_SCOPE_GLOBAL              0xe
280 #define IP6_MULTICAST_SCOPE_RESERVEDF           0xf
281 
282 #define ip6_addr_ismulticast_reserved_scope(ip6addr) \
283   (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff000000UL))
284 #define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
285 #define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
286 #define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
287 #define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
288 #define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
289 #define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
290 
291 /* Scoping note: while interface-local and link-local multicast addresses do
292  * have a scope (i.e., they are meaningful only in the context of a particular
293  * interface), the following functions are not assigning or comparing zone
294  * indices. The reason for this is backward compatibility. Any call site that
295  * produces a non-global multicast address must assign a multicast address as
296  * appropriate itself. */
297 #if LWIP_SMALL_SIZE && !LWIP_IPV6_SCOPES
298 #define ip6_addr_isallnodes_iflocal(ip6addr) \
299   (memcmp(ip6addr, &ip6_addr_allnodes_iflocal, sizeof(ip6_addr_t)) == 0)
300 #define ip6_addr_isallnodes_linklocal(ip6addr) \
301   (memcmp(ip6addr, &ip6_addr_allnodes_linklocal, sizeof(ip6_addr_t)) == 0)
302 #define ip6_addr_isallrpl_nodes_linklocal(ip6addr) \
303   (memcmp(ip6addr, &ip6_addr_allrpl_nodes_linklocal, sizeof(ip6_addr_t)) == 0)
304 #define ip6_addr_is_mpl_ip4_bcast(ip6addr) \
305   (memcmp(ip6addr, &ip6_addr_mpl_ip4_bcast, sizeof(ip6_addr_t)) == 0)
306 #else
307 #define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
308     ((ip6addr)->addr[1] == 0UL) && \
309     ((ip6addr)->addr[2] == 0UL) && \
310     ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
311 
312 #define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
313     ((ip6addr)->addr[1] == 0UL) && \
314     ((ip6addr)->addr[2] == 0UL) && \
315     ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
316 
317 #define ip6_addr_isallrpl_nodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
318     ((ip6addr)->addr[1] == 0UL) && \
319     ((ip6addr)->addr[2] == 0UL) && \
320     ((ip6addr)->addr[3] == PP_HTONL(0x0000001aUL)))
321 
322 #define ip6_addr_is_mpl_ip4_bcast(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff130000UL)) && \
323     ((ip6addr)->addr[1] == 0UL) && \
324     ((ip6addr)->addr[2] == 0UL) && \
325     ((ip6addr)->addr[3] == PP_HTONL(0x000000fcUL)))
326 #endif
327 
328 #define ip6_addr_set_mpl_ip4_bcast(ip6addr) do { (ip6addr)->addr[0] = PP_HTONL(0xff130000UL); \
329                                                  (ip6addr)->addr[1] = 0UL; \
330                                                  (ip6addr)->addr[2] = 0UL; \
331                                                  (ip6addr)->addr[3] = PP_HTONL(0x000000fcUL); } while (0)
332 
333 #define ip6_addr_set_allnodes_linklocal(ip6addr) do { (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
334                 (ip6addr)->addr[1] = 0; \
335                 (ip6addr)->addr[2] = 0; \
336                 (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
337 				ip6_addr_clear_zone(ip6addr); } while (0)
338 
339 #if LWIP_SMALL_SIZE
340 #define ip6_addr_isallrouters_linklocal(ip6addr) \
341   (memcmp(ip6addr, &ip6_addr_allrouters_linklocal, sizeof(ip6_addr_t)) == 0)
342 #else
343 #define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
344     ((ip6addr)->addr[1] == 0UL) && \
345     ((ip6addr)->addr[2] == 0UL) && \
346     ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
347 #endif
348 #define ip6_addr_set_allrouters_linklocal(ip6addr) do { (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
349                 (ip6addr)->addr[1] = 0; \
350                 (ip6addr)->addr[2] = 0; \
351                 (ip6addr)->addr[3] = PP_HTONL(0x00000002UL); \
352 				ip6_addr_clear_zone(ip6addr); }while (0)
353 
354 #define ip6_addr_issolicitednode(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
355         ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
356         (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)))
357 
358 #define ip6_addr_set_solicitednode(ip6addr, if_id) do { (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
359                 (ip6addr)->addr[1] = 0; \
360                 (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
361                 (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id)); \
362 				ip6_addr_clear_zone(ip6addr); } while (0)
363 
364 #define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
365                                    ((ip6addr)->addr[1] == 0) && \
366                                    ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
367                                    ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
368 
369 #define lwip_lladdr_cmp(addr1, addr2, len) (memcmp(addr1, addr2, len) == 0)
370 
371 /* IPv6 address states. */
372 #define IP6_ADDR_INVALID      0x00
373 #define IP6_ADDR_TENTATIVE    0x08
374 #define IP6_ADDR_TENTATIVE_1  0x09 /* 1 probe sent */
375 #define IP6_ADDR_TENTATIVE_2  0x0a /* 2 probes sent */
376 #define IP6_ADDR_TENTATIVE_3  0x0b /* 3 probes sent */
377 #define IP6_ADDR_TENTATIVE_4  0x0c /* 4 probes sent */
378 #define IP6_ADDR_TENTATIVE_5  0x0d /* 5 probes sent */
379 #define IP6_ADDR_TENTATIVE_6  0x0e /* 6 probes sent */
380 #define IP6_ADDR_TENTATIVE_7  0x0f /* 7 probes sent */
381 #define IP6_ADDR_VALID        0x10 /* This bit marks an address as valid (preferred or deprecated) */
382 #define IP6_ADDR_PREFERRED    0x30
383 #define IP6_ADDR_DEPRECATED   0x10 /* Same as VALID (valid but not preferred) */
384 #define IP6_ADDR_DUPLICATED   0x40 /* Failed DAD test, not valid */
385 
386 #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
387 
388 #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
389 #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
390 #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
391 #define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
392 #define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
393 #define ip6_addr_isduplicated(addr_state) (addr_state == IP6_ADDR_DUPLICATED)
394 
395 #if LWIP_IPV6_ADDRESS_LIFETIMES
396 #define IP6_ADDR_LIFE_STATIC   (0)
397 #define IP6_ADDR_LIFE_INFINITE (0xffffffffUL)
398 #define ip6_addr_life_isstatic(addr_life) ((addr_life) == IP6_ADDR_LIFE_STATIC)
399 #define ip6_addr_life_isinfinite(addr_life) ((addr_life) == IP6_ADDR_LIFE_INFINITE)
400 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */
401 
402 #define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
403   LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
404                       a, b, c, d, e, f, g, h))
405 #define ip6_addr_debug_print(debug, ipaddr) \
406   ip6_addr_debug_print_parts(debug, \
407                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0),    \
408                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0),    \
409                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0),    \
410                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0),    \
411                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0),    \
412                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0),    \
413                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0),    \
414                       (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
415 #define ip6_addr_debug_print_val(debug, ipaddr) \
416   ip6_addr_debug_print_parts(debug, \
417                       IP6_ADDR_BLOCK1(&(ipaddr)),    \
418                       IP6_ADDR_BLOCK2(&(ipaddr)),    \
419                       IP6_ADDR_BLOCK3(&(ipaddr)),    \
420                       IP6_ADDR_BLOCK4(&(ipaddr)),    \
421                       IP6_ADDR_BLOCK5(&(ipaddr)),    \
422                       IP6_ADDR_BLOCK6(&(ipaddr)),    \
423                       IP6_ADDR_BLOCK7(&(ipaddr)),    \
424                       IP6_ADDR_BLOCK8(&(ipaddr)))
425 
426 #define IP6ADDR_STRLEN_MAX    46
427 
428 int ip6addr_aton(const char *cp, ip6_addr_t *addr);
429 /** returns ptr to static buffer; not reentrant! */
430 char *ip6addr_ntoa(const ip6_addr_t *addr);
431 char *ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen);
432 
433 #if defined (__cplusplus) && __cplusplus
434 }
435 #endif
436 
437 #endif /* LWIP_IPV6 */
438 
439 #endif /* LWIP_HDR_IP6_ADDR_H */
440