Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
nd6.h
00001 /** 00002 * @file 00003 * 00004 * Neighbor discovery and stateless address autoconfiguration for IPv6. 00005 * Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 00006 * (Address autoconfiguration). 00007 */ 00008 00009 /* 00010 * Copyright (c) 2010 Inico Technologies Ltd. 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. The name of the author may not be used to endorse or promote products 00022 * derived from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00025 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00027 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00029 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00030 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00031 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00032 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00033 * OF SUCH DAMAGE. 00034 * 00035 * This file is part of the lwIP TCP/IP stack. 00036 * 00037 * Author: Ivan Delamer <delamer@inicotech.com> 00038 * 00039 * 00040 * Please coordinate changes and requests with Ivan Delamer 00041 * <delamer@inicotech.com> 00042 */ 00043 00044 #ifndef LWIP_HDR_ND6_H 00045 #define LWIP_HDR_ND6_H 00046 00047 #include "lwip/opt.h" 00048 00049 #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ 00050 00051 #include "lwip/pbuf.h" 00052 #include "lwip/ip6.h" 00053 #include "lwip/ip6_addr.h" 00054 #include "lwip/netif.h" 00055 00056 00057 #ifdef __cplusplus 00058 extern "C" { 00059 #endif 00060 00061 /** Struct for tables. */ 00062 struct nd6_neighbor_cache_entry { 00063 ip6_addr_t next_hop_address; 00064 struct netif * netif; 00065 u8_t lladdr[NETIF_MAX_HWADDR_LEN]; 00066 /*u32_t pmtu;*/ 00067 #if LWIP_ND6_QUEUEING 00068 /** Pointer to queue of pending outgoing packets on this entry. */ 00069 struct nd6_q_entry *q; 00070 #else /* LWIP_ND6_QUEUEING */ 00071 /** Pointer to a single pending outgoing packet on this entry. */ 00072 struct pbuf *q; 00073 #endif /* LWIP_ND6_QUEUEING */ 00074 u8_t state; 00075 u8_t isrouter; 00076 union { 00077 u32_t reachable_time; 00078 u32_t delay_time; 00079 u32_t probes_sent; 00080 u32_t stale_time; 00081 } counter; 00082 }; 00083 00084 struct nd6_destination_cache_entry { 00085 ip6_addr_t destination_addr; 00086 ip6_addr_t next_hop_addr; 00087 u16_t pmtu; 00088 u32_t age; 00089 }; 00090 00091 struct nd6_prefix_list_entry { 00092 ip6_addr_t prefix; 00093 struct netif * netif; 00094 u32_t invalidation_timer; 00095 #if LWIP_IPV6_AUTOCONFIG 00096 u8_t flags; 00097 #define ND6_PREFIX_AUTOCONFIG_AUTONOMOUS 0x01 00098 #define ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED 0x02 00099 #define ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE 0x04 00100 #endif /* LWIP_IPV6_AUTOCONFIG */ 00101 }; 00102 00103 struct nd6_router_list_entry { 00104 struct nd6_neighbor_cache_entry * neighbor_entry; 00105 u32_t invalidation_timer; 00106 u8_t flags; 00107 }; 00108 00109 00110 enum nd6_neighbor_cache_entry_state { 00111 ND6_NO_ENTRY = 0, 00112 ND6_INCOMPLETE, 00113 ND6_REACHABLE, 00114 ND6_STALE, 00115 ND6_DELAY, 00116 ND6_PROBE 00117 }; 00118 00119 #if LWIP_ND6_QUEUEING 00120 /** struct for queueing outgoing packets for unknown address 00121 * defined here to be accessed by memp.h 00122 */ 00123 struct nd6_q_entry { 00124 struct nd6_q_entry *next; 00125 struct pbuf *p; 00126 }; 00127 #endif /* LWIP_ND6_QUEUEING */ 00128 00129 /** Neighbor solicitation message header. */ 00130 #ifdef PACK_STRUCT_USE_INCLUDES 00131 # include "arch/bpstruct.h" 00132 #endif 00133 PACK_STRUCT_BEGIN 00134 struct ns_header { 00135 PACK_STRUCT_FLD_8(u8_t type); 00136 PACK_STRUCT_FLD_8(u8_t code); 00137 PACK_STRUCT_FIELD(u16_t chksum); 00138 PACK_STRUCT_FIELD(u32_t reserved); 00139 PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); 00140 /* Options follow. */ 00141 } PACK_STRUCT_STRUCT; 00142 PACK_STRUCT_END 00143 #ifdef PACK_STRUCT_USE_INCLUDES 00144 # include "arch/epstruct.h" 00145 #endif 00146 00147 /** Neighbor advertisement message header. */ 00148 #ifdef PACK_STRUCT_USE_INCLUDES 00149 # include "arch/bpstruct.h" 00150 #endif 00151 PACK_STRUCT_BEGIN 00152 struct na_header { 00153 PACK_STRUCT_FLD_8(u8_t type); 00154 PACK_STRUCT_FLD_8(u8_t code); 00155 PACK_STRUCT_FIELD(u16_t chksum); 00156 PACK_STRUCT_FLD_8(u8_t flags); 00157 PACK_STRUCT_FLD_8(u8_t reserved[3]); 00158 PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); 00159 /* Options follow. */ 00160 } PACK_STRUCT_STRUCT; 00161 PACK_STRUCT_END 00162 #ifdef PACK_STRUCT_USE_INCLUDES 00163 # include "arch/epstruct.h" 00164 #endif 00165 #define ND6_FLAG_ROUTER (0x80) 00166 #define ND6_FLAG_SOLICITED (0x40) 00167 #define ND6_FLAG_OVERRIDE (0x20) 00168 00169 /** Router solicitation message header. */ 00170 #ifdef PACK_STRUCT_USE_INCLUDES 00171 # include "arch/bpstruct.h" 00172 #endif 00173 PACK_STRUCT_BEGIN 00174 struct rs_header { 00175 PACK_STRUCT_FLD_8(u8_t type); 00176 PACK_STRUCT_FLD_8(u8_t code); 00177 PACK_STRUCT_FIELD(u16_t chksum); 00178 PACK_STRUCT_FIELD(u32_t reserved); 00179 /* Options follow. */ 00180 } PACK_STRUCT_STRUCT; 00181 PACK_STRUCT_END 00182 #ifdef PACK_STRUCT_USE_INCLUDES 00183 # include "arch/epstruct.h" 00184 #endif 00185 00186 /** Router advertisement message header. */ 00187 #define ND6_RA_FLAG_MANAGED_ADDR_CONFIG (0x80) 00188 #define ND6_RA_FLAG_OTHER_CONFIG (0x40) 00189 #define ND6_RA_FLAG_HOME_AGENT (0x20) 00190 #define ND6_RA_PREFERENCE_MASK (0x18) 00191 #define ND6_RA_PREFERENCE_HIGH (0x08) 00192 #define ND6_RA_PREFERENCE_MEDIUM (0x00) 00193 #define ND6_RA_PREFERENCE_LOW (0x18) 00194 #define ND6_RA_PREFERENCE_DISABLED (0x10) 00195 #ifdef PACK_STRUCT_USE_INCLUDES 00196 # include "arch/bpstruct.h" 00197 #endif 00198 PACK_STRUCT_BEGIN 00199 struct ra_header { 00200 PACK_STRUCT_FLD_8(u8_t type); 00201 PACK_STRUCT_FLD_8(u8_t code); 00202 PACK_STRUCT_FIELD(u16_t chksum); 00203 PACK_STRUCT_FLD_8(u8_t current_hop_limit); 00204 PACK_STRUCT_FLD_8(u8_t flags); 00205 PACK_STRUCT_FIELD(u16_t router_lifetime); 00206 PACK_STRUCT_FIELD(u32_t reachable_time); 00207 PACK_STRUCT_FIELD(u32_t retrans_timer); 00208 /* Options follow. */ 00209 } PACK_STRUCT_STRUCT; 00210 PACK_STRUCT_END 00211 #ifdef PACK_STRUCT_USE_INCLUDES 00212 # include "arch/epstruct.h" 00213 #endif 00214 00215 /** Redirect message header. */ 00216 #ifdef PACK_STRUCT_USE_INCLUDES 00217 # include "arch/bpstruct.h" 00218 #endif 00219 PACK_STRUCT_BEGIN 00220 struct redirect_header { 00221 PACK_STRUCT_FLD_8(u8_t type); 00222 PACK_STRUCT_FLD_8(u8_t code); 00223 PACK_STRUCT_FIELD(u16_t chksum); 00224 PACK_STRUCT_FIELD(u32_t reserved); 00225 PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); 00226 PACK_STRUCT_FLD_S(ip6_addr_p_t destination_address); 00227 /* Options follow. */ 00228 } PACK_STRUCT_STRUCT; 00229 PACK_STRUCT_END 00230 #ifdef PACK_STRUCT_USE_INCLUDES 00231 # include "arch/epstruct.h" 00232 #endif 00233 00234 /** Link-layer address option. */ 00235 #define ND6_OPTION_TYPE_SOURCE_LLADDR (0x01) 00236 #define ND6_OPTION_TYPE_TARGET_LLADDR (0x02) 00237 #ifdef PACK_STRUCT_USE_INCLUDES 00238 # include "arch/bpstruct.h" 00239 #endif 00240 PACK_STRUCT_BEGIN 00241 struct lladdr_option { 00242 PACK_STRUCT_FLD_8(u8_t type); 00243 PACK_STRUCT_FLD_8(u8_t length); 00244 PACK_STRUCT_FLD_8(u8_t addr[NETIF_MAX_HWADDR_LEN]); 00245 } PACK_STRUCT_STRUCT; 00246 PACK_STRUCT_END 00247 #ifdef PACK_STRUCT_USE_INCLUDES 00248 # include "arch/epstruct.h" 00249 #endif 00250 00251 /** Prefix information option. */ 00252 #define ND6_OPTION_TYPE_PREFIX_INFO (0x03) 00253 #define ND6_PREFIX_FLAG_ON_LINK (0x80) 00254 #define ND6_PREFIX_FLAG_AUTONOMOUS (0x40) 00255 #define ND6_PREFIX_FLAG_ROUTER_ADDRESS (0x20) 00256 #define ND6_PREFIX_FLAG_SITE_PREFIX (0x10) 00257 #ifdef PACK_STRUCT_USE_INCLUDES 00258 # include "arch/bpstruct.h" 00259 #endif 00260 PACK_STRUCT_BEGIN 00261 struct prefix_option { 00262 PACK_STRUCT_FLD_8(u8_t type); 00263 PACK_STRUCT_FLD_8(u8_t length); 00264 PACK_STRUCT_FLD_8(u8_t prefix_length); 00265 PACK_STRUCT_FLD_8(u8_t flags); 00266 PACK_STRUCT_FIELD(u32_t valid_lifetime); 00267 PACK_STRUCT_FIELD(u32_t preferred_lifetime); 00268 PACK_STRUCT_FLD_8(u8_t reserved2[3]); 00269 PACK_STRUCT_FLD_8(u8_t site_prefix_length); 00270 PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); 00271 } PACK_STRUCT_STRUCT; 00272 PACK_STRUCT_END 00273 #ifdef PACK_STRUCT_USE_INCLUDES 00274 # include "arch/epstruct.h" 00275 #endif 00276 00277 /** Redirected header option. */ 00278 #define ND6_OPTION_TYPE_REDIR_HDR (0x04) 00279 #ifdef PACK_STRUCT_USE_INCLUDES 00280 # include "arch/bpstruct.h" 00281 #endif 00282 PACK_STRUCT_BEGIN 00283 struct redirected_header_option { 00284 PACK_STRUCT_FLD_8(u8_t type); 00285 PACK_STRUCT_FLD_8(u8_t length); 00286 PACK_STRUCT_FLD_8(u8_t reserved[6]); 00287 /* Portion of redirected packet follows. */ 00288 /* PACK_STRUCT_FLD_8(u8_t redirected[8]); */ 00289 } PACK_STRUCT_STRUCT; 00290 PACK_STRUCT_END 00291 #ifdef PACK_STRUCT_USE_INCLUDES 00292 # include "arch/epstruct.h" 00293 #endif 00294 00295 /** MTU option. */ 00296 #define ND6_OPTION_TYPE_MTU (0x05) 00297 #ifdef PACK_STRUCT_USE_INCLUDES 00298 # include "arch/bpstruct.h" 00299 #endif 00300 PACK_STRUCT_BEGIN 00301 struct mtu_option { 00302 PACK_STRUCT_FLD_8(u8_t type); 00303 PACK_STRUCT_FLD_8(u8_t length); 00304 PACK_STRUCT_FIELD(u16_t reserved); 00305 PACK_STRUCT_FIELD(u32_t mtu); 00306 } PACK_STRUCT_STRUCT; 00307 PACK_STRUCT_END 00308 #ifdef PACK_STRUCT_USE_INCLUDES 00309 # include "arch/epstruct.h" 00310 #endif 00311 00312 /** Route information option. */ 00313 #define ND6_OPTION_TYPE_ROUTE_INFO (24) 00314 #ifdef PACK_STRUCT_USE_INCLUDES 00315 # include "arch/bpstruct.h" 00316 #endif 00317 PACK_STRUCT_BEGIN 00318 struct route_option { 00319 PACK_STRUCT_FLD_8(u8_t type); 00320 PACK_STRUCT_FLD_8(u8_t length); 00321 PACK_STRUCT_FLD_8(u8_t prefix_length); 00322 PACK_STRUCT_FLD_8(u8_t preference); 00323 PACK_STRUCT_FIELD(u32_t route_lifetime); 00324 PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); 00325 } PACK_STRUCT_STRUCT; 00326 PACK_STRUCT_END 00327 #ifdef PACK_STRUCT_USE_INCLUDES 00328 # include "arch/epstruct.h" 00329 #endif 00330 00331 /** 1 second period */ 00332 #define ND6_TMR_INTERVAL 1000 00333 00334 /* Router tables. */ 00335 /* @todo make these static? and entries accessible through API? */ 00336 extern struct nd6_neighbor_cache_entry neighbor_cache[]; 00337 extern struct nd6_destination_cache_entry destination_cache[]; 00338 extern struct nd6_prefix_list_entry prefix_list[]; 00339 extern struct nd6_router_list_entry default_router_list[]; 00340 00341 /* Default values, can be updated by a RA message. */ 00342 extern u32_t reachable_time; 00343 extern u32_t retrans_timer; 00344 00345 void nd6_tmr(void); 00346 void nd6_input(struct pbuf *p, struct netif *inp); 00347 s8_t nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif); 00348 s8_t nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif); 00349 u16_t nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif); 00350 err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf * p); 00351 #if LWIP_ND6_TCP_REACHABILITY_HINTS 00352 void nd6_reachability_hint(const ip6_addr_t * ip6addr); 00353 #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ 00354 void nd6_cleanup_netif(struct netif * netif); 00355 00356 #ifdef __cplusplus 00357 } 00358 #endif 00359 00360 #endif /* LWIP_IPV6 */ 00361 00362 #endif /* LWIP_HDR_ND6_H */
Generated on Tue Jul 12 2022 17:34:49 by
