1 /* $NetBSD: nd6.h,v 1.56 2011/11/19 22:51:29 tls Exp $ */ 2 /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef _NETINET6_ND6_H_ 34 #define _NETINET6_ND6_H_ 35 36 #include <sys/queue.h> 37 #include <sys/callout.h> 38 39 struct llinfo_nd6 { 40 struct llinfo_nd6 *ln_next; 41 struct llinfo_nd6 *ln_prev; 42 struct rtentry *ln_rt; 43 struct mbuf *ln_hold; /* last packet until resolved/timeout */ 44 long ln_asked; /* number of queries already sent for this addr */ 45 u_long ln_expire; /* lifetime for NDP state transition */ 46 short ln_state; /* reachability state */ 47 short ln_router; /* 2^0: ND6 router bit */ 48 int ln_byhint; /* # of times we made it reachable by UL hint */ 49 50 long ln_ntick; 51 struct callout ln_timer_ch; 52 }; 53 54 #define ND6_LLINFO_NOSTATE -2 55 /* 56 * We don't need the WAITDELETE state any more, but we keep the definition 57 * in a comment line instead of removing it. This is necessary to avoid 58 * unintentionally reusing the value for another purpose, which might 59 * affect backward compatibility with old applications. 60 * (20000711 jinmei@kame.net) 61 */ 62 /* #define ND6_LLINFO_WAITDELETE -1 */ 63 #define ND6_LLINFO_INCOMPLETE 0 64 #define ND6_LLINFO_REACHABLE 1 65 #define ND6_LLINFO_STALE 2 66 #define ND6_LLINFO_DELAY 3 67 #define ND6_LLINFO_PROBE 4 68 69 #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE) 70 #define ND6_LLINFO_PERMANENT(n) (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE)) 71 72 struct nd_ifinfo { 73 u_int32_t linkmtu; /* LinkMTU */ 74 u_int32_t maxmtu; /* Upper bound of LinkMTU */ 75 u_int32_t basereachable; /* BaseReachableTime */ 76 u_int32_t reachable; /* Reachable Time */ 77 u_int32_t retrans; /* Retrans Timer */ 78 u_int32_t flags; /* Flags */ 79 int recalctm; /* BaseReacable re-calculation timer */ 80 u_int8_t chlim; /* CurHopLimit */ 81 u_int8_t initialized; /* Flag to see the entry is initialized */ 82 /* the following 3 members are for privacy extension for addrconf */ 83 u_int8_t randomseed0[8]; /* upper 64 bits of MD5 digest */ 84 u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */ 85 u_int8_t randomid[8]; /* current random ID */ 86 }; 87 88 #define ND6_IFF_PERFORMNUD 0x01 89 #define ND6_IFF_ACCEPT_RTADV 0x02 /* See "RTADV Key", below. */ 90 #define ND6_IFF_PREFER_SOURCE 0x04 /* XXX: not related to ND. */ 91 #define ND6_IFF_IFDISABLED 0x08 /* IPv6 operation is disabled due to 92 * DAD failure. (XXX: not ND-specific) 93 */ 94 #define ND6_IFF_OVERRIDE_RTADV 0x10 /* See "RTADV Key", below. */ 95 96 /* 97 * RTADV Key 98 * 99 * The flags ND6_IFF_ACCEPT_RTADV and ND6_IFF_OVERRIDE_RTADV form a 100 * tri-state variable. (There are actually four different states, but 101 * two of the states are functionally identical.) 102 * 103 * ND6_IFF_OVERRIDE_RTADV or 0: This interface does not accept 104 * Router Advertisements. 105 * 106 * ND6_IFF_OVERRIDE_RTADV| 107 * ND6_IFF_ACCEPT_RTADV: This interface accepts Router 108 * Advertisements regardless of the 109 * global setting, ip6_accept_rtadv. 110 * 111 * ND6_IFF_ACCEPT_RTADV: This interface follows the global setting, 112 * ip6_accept_rtadv. If ip6_accept_rtadv == 0, 113 * this interface does not accept Router 114 * Advertisements. If ip6_accept_rtadv != 0, 115 * this interface does accept them. 116 */ 117 118 #ifdef _KERNEL 119 #define ND_IFINFO(ifp) \ 120 (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo) 121 #define IN6_LINKMTU(ifp) \ 122 ((ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) \ 123 ? ND_IFINFO(ifp)->linkmtu \ 124 : ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) \ 125 ? ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)) 126 #endif 127 128 struct in6_nbrinfo { 129 char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ 130 struct in6_addr addr; /* IPv6 address of the neighbor */ 131 long asked; /* number of queries already sent for this addr */ 132 int isrouter; /* if it acts as a router */ 133 int state; /* reachability state */ 134 int expire; /* lifetime for NDP state transition */ 135 }; 136 137 #define DRLSTSIZ 10 138 #define PRLSTSIZ 10 139 struct in6_drlist { 140 char ifname[IFNAMSIZ]; 141 struct { 142 struct in6_addr rtaddr; 143 u_char flags; 144 u_short rtlifetime; 145 u_long expire; 146 u_short if_index; 147 } defrouter[DRLSTSIZ]; 148 }; 149 150 struct in6_defrouter { 151 struct sockaddr_in6 rtaddr; 152 u_char flags; 153 u_short rtlifetime; 154 u_long expire; 155 u_short if_index; 156 }; 157 158 #ifdef _KERNEL 159 struct in6_oprlist { 160 char ifname[IFNAMSIZ]; 161 struct { 162 struct in6_addr prefix; 163 struct prf_ra raflags; 164 u_char prefixlen; 165 u_char origin; 166 u_long vltime; 167 u_long pltime; 168 u_long expire; 169 u_short if_index; 170 u_short advrtrs; /* number of advertisement routers */ 171 struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ 172 } prefix[PRLSTSIZ]; 173 }; 174 #endif 175 176 struct in6_prlist { 177 char ifname[IFNAMSIZ]; 178 struct { 179 struct in6_addr prefix; 180 struct prf_ra raflags; 181 u_char prefixlen; 182 u_char origin; 183 u_int32_t vltime; 184 u_int32_t pltime; 185 time_t expire; 186 u_short if_index; 187 u_short advrtrs; /* number of advertisement routers */ 188 struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ 189 } prefix[PRLSTSIZ]; 190 }; 191 192 struct in6_prefix { 193 struct sockaddr_in6 prefix; 194 struct prf_ra raflags; 195 u_char prefixlen; 196 u_char origin; 197 u_int32_t vltime; 198 u_int32_t pltime; 199 time_t expire; 200 u_int32_t flags; 201 int refcnt; 202 u_short if_index; 203 u_short advrtrs; /* number of advertisement routers */ 204 /* struct sockaddr_in6 advrtr[] */ 205 }; 206 207 #ifdef _KERNEL 208 struct in6_ondireq { 209 char ifname[IFNAMSIZ]; 210 struct { 211 u_int32_t linkmtu; /* LinkMTU */ 212 u_int32_t maxmtu; /* Upper bound of LinkMTU */ 213 u_int32_t basereachable; /* BaseReachableTime */ 214 u_int32_t reachable; /* Reachable Time */ 215 u_int32_t retrans; /* Retrans Timer */ 216 u_int32_t flags; /* Flags */ 217 int recalctm; /* BaseReacable re-calculation timer */ 218 u_int8_t chlim; /* CurHopLimit */ 219 u_int8_t receivedra; 220 } ndi; 221 }; 222 #endif 223 224 struct in6_ndireq { 225 char ifname[IFNAMSIZ]; 226 struct nd_ifinfo ndi; 227 }; 228 229 struct in6_ndifreq { 230 char ifname[IFNAMSIZ]; 231 u_long ifindex; 232 }; 233 234 /* Prefix status */ 235 #define NDPRF_ONLINK 0x1 236 #define NDPRF_DETACHED 0x2 237 #define NDPRF_HOME 0x4 238 239 /* protocol constants */ 240 #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ 241 #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */ 242 #define MAX_RTR_SOLICITATIONS 3 243 244 #define ND6_INFINITE_LIFETIME ((u_int32_t)~0) 245 246 #ifdef _KERNEL 247 /* node constants */ 248 #define MAX_REACHABLE_TIME 3600000 /* msec */ 249 #define REACHABLE_TIME 30000 /* msec */ 250 #define RETRANS_TIMER 1000 /* msec */ 251 #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 252 #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 253 #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */ 254 #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */ 255 #define TEMPADDR_REGEN_ADVANCE 5 /* sec */ 256 #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */ 257 #define ND_COMPUTE_RTIME(x) \ 258 (((MIN_RANDOM_FACTOR * (x >> 10)) + (cprng_fast32() & \ 259 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 260 261 TAILQ_HEAD(nd_drhead, nd_defrouter); 262 struct nd_defrouter { 263 TAILQ_ENTRY(nd_defrouter) dr_entry; 264 struct in6_addr rtaddr; 265 u_char flags; /* flags on RA message */ 266 u_short rtlifetime; 267 u_long expire; 268 struct ifnet *ifp; 269 int installed; /* is installed into kernel routing table */ 270 }; 271 272 struct nd_prefixctl { 273 struct ifnet *ndpr_ifp; 274 275 /* prefix */ 276 struct sockaddr_in6 ndpr_prefix; 277 u_char ndpr_plen; 278 279 u_int32_t ndpr_vltime; /* advertised valid lifetime */ 280 u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 281 282 struct prf_ra ndpr_flags; 283 }; 284 285 struct nd_prefix { 286 struct ifnet *ndpr_ifp; 287 LIST_ENTRY(nd_prefix) ndpr_entry; 288 struct sockaddr_in6 ndpr_prefix; /* prefix */ 289 struct in6_addr ndpr_mask; /* netmask derived from the prefix */ 290 291 u_int32_t ndpr_vltime; /* advertised valid lifetime */ 292 u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 293 294 time_t ndpr_expire; /* expiration time of the prefix */ 295 time_t ndpr_preferred; /* preferred time of the prefix */ 296 time_t ndpr_lastupdate; /* reception time of last advertisement */ 297 298 struct prf_ra ndpr_flags; 299 u_int32_t ndpr_stateflags; /* actual state flags */ 300 /* list of routers that advertise the prefix: */ 301 LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs; 302 u_char ndpr_plen; 303 int ndpr_refcnt; /* reference couter from addresses */ 304 }; 305 306 #define ndpr_raf ndpr_flags 307 #define ndpr_raf_onlink ndpr_flags.onlink 308 #define ndpr_raf_auto ndpr_flags.autonomous 309 #define ndpr_raf_router ndpr_flags.router 310 311 /* 312 * Message format for use in obtaining information about prefixes 313 * from inet6 sysctl function 314 */ 315 struct inet6_ndpr_msghdr { 316 u_short inpm_msglen; /* to skip over non-understood messages */ 317 u_char inpm_version; /* future binary compatibility */ 318 u_char inpm_type; /* message type */ 319 struct in6_addr inpm_prefix; 320 u_long prm_vltim; 321 u_long prm_pltime; 322 u_long prm_expire; 323 u_long prm_preferred; 324 struct in6_prflags prm_flags; 325 u_short prm_index; /* index for associated ifp */ 326 u_char prm_plen; /* length of prefix in bits */ 327 }; 328 329 #define prm_raf_onlink prm_flags.prf_ra.onlink 330 #define prm_raf_auto prm_flags.prf_ra.autonomous 331 332 #define prm_statef_onlink prm_flags.prf_state.onlink 333 334 #define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid 335 #define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd 336 337 struct nd_pfxrouter { 338 LIST_ENTRY(nd_pfxrouter) pfr_entry; 339 struct nd_defrouter *router; 340 }; 341 342 LIST_HEAD(nd_prhead, nd_prefix); 343 344 #include <sys/mallocvar.h> 345 MALLOC_DECLARE(M_IP6NDP); 346 347 /* nd6.c */ 348 extern int nd6_prune; 349 extern int nd6_delay; 350 extern int nd6_umaxtries; 351 extern int nd6_mmaxtries; 352 extern int nd6_useloopback; 353 extern int nd6_maxnudhint; 354 extern int nd6_gctimer; 355 extern struct llinfo_nd6 llinfo_nd6; 356 extern struct nd_drhead nd_defrouter; 357 extern struct nd_prhead nd_prefix; 358 extern int nd6_debug; 359 360 #define nd6log(x) do { if (nd6_debug) log x; } while (/*CONSTCOND*/ 0) 361 362 extern struct callout nd6_timer_ch; 363 364 /* nd6_rtr.c */ 365 extern int nd6_defifindex; 366 extern int ip6_desync_factor; /* seconds */ 367 extern u_int32_t ip6_temp_preferred_lifetime; /* seconds */ 368 extern u_int32_t ip6_temp_valid_lifetime; /* seconds */ 369 extern int ip6_temp_regen_advance; /* seconds */ 370 extern int nd6_numroutes; 371 372 union nd_opts { 373 struct nd_opt_hdr *nd_opt_array[8]; 374 struct { 375 struct nd_opt_hdr *zero; 376 struct nd_opt_hdr *src_lladdr; 377 struct nd_opt_hdr *tgt_lladdr; 378 struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */ 379 struct nd_opt_rd_hdr *rh; 380 struct nd_opt_mtu *mtu; 381 struct nd_opt_hdr *search; /* multiple opts */ 382 struct nd_opt_hdr *last; /* multiple opts */ 383 int done; 384 struct nd_opt_prefix_info *pi_end;/* multiple opts, end */ 385 } nd_opt_each; 386 }; 387 #define nd_opts_src_lladdr nd_opt_each.src_lladdr 388 #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr 389 #define nd_opts_pi nd_opt_each.pi_beg 390 #define nd_opts_pi_end nd_opt_each.pi_end 391 #define nd_opts_rh nd_opt_each.rh 392 #define nd_opts_mtu nd_opt_each.mtu 393 #define nd_opts_search nd_opt_each.search 394 #define nd_opts_last nd_opt_each.last 395 #define nd_opts_done nd_opt_each.done 396 397 /* XXX: need nd6_var.h?? */ 398 /* nd6.c */ 399 void nd6_init(void); 400 struct nd_ifinfo *nd6_ifattach(struct ifnet *); 401 void nd6_ifdetach(struct nd_ifinfo *); 402 int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); 403 void nd6_option_init(void *, int, union nd_opts *); 404 struct nd_opt_hdr *nd6_option(union nd_opts *); 405 int nd6_options(union nd_opts *); 406 struct rtentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *); 407 void nd6_setmtu(struct ifnet *); 408 void nd6_llinfo_settimer(struct llinfo_nd6 *, long); 409 void nd6_timer(void *); 410 void nd6_purge(struct ifnet *); 411 void nd6_nud_hint(struct rtentry *, struct in6_addr *, int); 412 int nd6_resolve(struct ifnet *, struct rtentry *, 413 struct mbuf *, struct sockaddr *, u_char *); 414 void nd6_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); 415 int nd6_ioctl(u_long, void *, struct ifnet *); 416 struct rtentry *nd6_cache_lladdr(struct ifnet *, struct in6_addr *, 417 char *, int, int, int); 418 int nd6_output(struct ifnet *, struct ifnet *, struct mbuf *, 419 const struct sockaddr_in6 *, struct rtentry *); 420 int nd6_storelladdr(const struct ifnet *, const struct rtentry *, struct mbuf *, 421 const struct sockaddr *, uint8_t *, size_t); 422 int nd6_sysctl(int, void *, size_t *, void *, size_t); 423 int nd6_need_cache(struct ifnet *); 424 void nd6_llinfo_release_pkts(struct llinfo_nd6 *, struct ifnet *, 425 struct rtentry *); 426 427 /* nd6_nbr.c */ 428 void nd6_na_input(struct mbuf *, int, int); 429 void nd6_na_output(struct ifnet *, const struct in6_addr *, 430 const struct in6_addr *, u_long, int, const struct sockaddr *); 431 void nd6_ns_input(struct mbuf *, int, int); 432 void nd6_ns_output(struct ifnet *, const struct in6_addr *, 433 const struct in6_addr *, struct llinfo_nd6 *, int); 434 const void *nd6_ifptomac(const struct ifnet *); 435 void nd6_dad_start(struct ifaddr *, int); 436 void nd6_dad_stop(struct ifaddr *); 437 void nd6_dad_duplicated(struct ifaddr *); 438 439 /* nd6_rtr.c */ 440 void nd6_rs_input(struct mbuf *, int, int); 441 void nd6_ra_input(struct mbuf *, int, int); 442 void prelist_del(struct nd_prefix *); 443 void defrouter_addreq(struct nd_defrouter *); 444 void defrouter_reset(void); 445 void defrouter_select(void); 446 void defrtrlist_del(struct nd_defrouter *); 447 void prelist_remove(struct nd_prefix *); 448 int nd6_prelist_add(struct nd_prefixctl *, struct nd_defrouter *, 449 struct nd_prefix **); 450 int nd6_prefix_onlink(struct nd_prefix *); 451 int nd6_prefix_offlink(struct nd_prefix *); 452 void pfxlist_onlink_check(void); 453 struct nd_defrouter *defrouter_lookup(const struct in6_addr *, struct ifnet *); 454 struct nd_prefix *nd6_prefix_lookup(struct nd_prefixctl *); 455 int in6_ifdel(struct ifnet *, struct in6_addr *); 456 void rt6_flush(struct in6_addr *, struct ifnet *); 457 int nd6_setdefaultiface(int); 458 int in6_tmpifadd(const struct in6_ifaddr *, int, int); 459 bool nd6_accepts_rtadv(const struct nd_ifinfo *); 460 461 #endif /* _KERNEL */ 462 463 #endif /* !_NETINET6_ND6_H_ */ 464