1caf43b02SWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 482cd038dSYoshinobu Inoue * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 582cd038dSYoshinobu Inoue * All rights reserved. 682cd038dSYoshinobu Inoue * 782cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 882cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 982cd038dSYoshinobu Inoue * are met: 1082cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1182cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1282cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1382cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1482cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1582cd038dSYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 1682cd038dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 1782cd038dSYoshinobu Inoue * without specific prior written permission. 1882cd038dSYoshinobu Inoue * 1982cd038dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2082cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2182cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2282cd038dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2382cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2482cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2582cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2682cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2782cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2882cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2982cd038dSYoshinobu Inoue * SUCH DAMAGE. 30b48287a3SDavid E. O'Brien * 31b48287a3SDavid E. O'Brien * $KAME: nd6.h,v 1.76 2001/12/18 02:10:31 itojun Exp $ 32b48287a3SDavid E. O'Brien * $FreeBSD$ 3382cd038dSYoshinobu Inoue */ 3482cd038dSYoshinobu Inoue 3582cd038dSYoshinobu Inoue #ifndef _NETINET6_ND6_H_ 3682cd038dSYoshinobu Inoue #define _NETINET6_ND6_H_ 3782cd038dSYoshinobu Inoue 38686cdd19SJun-ichiro itojun Hagino /* see net/route.h, or net/if_inarp.h */ 39686cdd19SJun-ichiro itojun Hagino #ifndef RTF_ANNOUNCE 40686cdd19SJun-ichiro itojun Hagino #define RTF_ANNOUNCE RTF_PROTO2 41686cdd19SJun-ichiro itojun Hagino #endif 42686cdd19SJun-ichiro itojun Hagino 4382cd038dSYoshinobu Inoue #include <sys/queue.h> 4433841545SHajimu UMEMOTO #include <sys/callout.h> 4582cd038dSYoshinobu Inoue 466e6b3f7cSQing Li struct llentry; 4782cd038dSYoshinobu Inoue 4882cd038dSYoshinobu Inoue #define ND6_LLINFO_NOSTATE -2 4933841545SHajimu UMEMOTO /* 5033841545SHajimu UMEMOTO * We don't need the WAITDELETE state any more, but we keep the definition 5133841545SHajimu UMEMOTO * in a comment line instead of removing it. This is necessary to avoid 5233841545SHajimu UMEMOTO * unintentionally reusing the value for another purpose, which might 5333841545SHajimu UMEMOTO * affect backward compatibility with old applications. 5433841545SHajimu UMEMOTO * (20000711 jinmei@kame.net) 5533841545SHajimu UMEMOTO */ 5633841545SHajimu UMEMOTO /* #define ND6_LLINFO_WAITDELETE -1 */ 5782cd038dSYoshinobu Inoue #define ND6_LLINFO_INCOMPLETE 0 5882cd038dSYoshinobu Inoue #define ND6_LLINFO_REACHABLE 1 5982cd038dSYoshinobu Inoue #define ND6_LLINFO_STALE 2 6082cd038dSYoshinobu Inoue #define ND6_LLINFO_DELAY 3 6182cd038dSYoshinobu Inoue #define ND6_LLINFO_PROBE 4 6282cd038dSYoshinobu Inoue 63686cdd19SJun-ichiro itojun Hagino #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE) 646e6b3f7cSQing Li #define ND6_LLINFO_PERMANENT(n) (((n)->la_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE)) 65686cdd19SJun-ichiro itojun Hagino 6682cd038dSYoshinobu Inoue struct nd_ifinfo { 6782cd038dSYoshinobu Inoue u_int32_t linkmtu; /* LinkMTU */ 6882cd038dSYoshinobu Inoue u_int32_t maxmtu; /* Upper bound of LinkMTU */ 6982cd038dSYoshinobu Inoue u_int32_t basereachable; /* BaseReachableTime */ 7082cd038dSYoshinobu Inoue u_int32_t reachable; /* Reachable Time */ 7182cd038dSYoshinobu Inoue u_int32_t retrans; /* Retrans Timer */ 72686cdd19SJun-ichiro itojun Hagino u_int32_t flags; /* Flags */ 7382cd038dSYoshinobu Inoue int recalctm; /* BaseReacable re-calculation timer */ 7482cd038dSYoshinobu Inoue u_int8_t chlim; /* CurHopLimit */ 7531b1bfe1SHajimu UMEMOTO u_int8_t initialized; /* Flag to see the entry is initialized */ 7688ff5695SSUZUKI Shinsuke /* the following 3 members are for privacy extension for addrconf */ 7733841545SHajimu UMEMOTO u_int8_t randomseed0[8]; /* upper 64 bits of MD5 digest */ 7833841545SHajimu UMEMOTO u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */ 7933841545SHajimu UMEMOTO u_int8_t randomid[8]; /* current random ID */ 8082cd038dSYoshinobu Inoue }; 8182cd038dSYoshinobu Inoue 82686cdd19SJun-ichiro itojun Hagino #define ND6_IFF_PERFORMNUD 0x1 8307cf047dSHajimu UMEMOTO #define ND6_IFF_ACCEPT_RTADV 0x2 84f6c336feSHiroki Sato #define ND6_IFF_PREFER_SOURCE 0x4 /* Not used in FreeBSD. */ 855b27b045SSUZUKI Shinsuke #define ND6_IFF_IFDISABLED 0x8 /* IPv6 operation is disabled due to 865b27b045SSUZUKI Shinsuke * DAD failure. (XXX: not ND-specific) 875b27b045SSUZUKI Shinsuke */ 88743eee66SSUZUKI Shinsuke #define ND6_IFF_DONT_SET_IFROUTE 0x10 89a283298cSHiroki Sato #define ND6_IFF_AUTO_LINKLOCAL 0x20 90e7fa8d0aSHiroki Sato #define ND6_IFF_NO_RADR 0x40 91164051ceSHajimu UMEMOTO #define ND6_IFF_NO_PREFER_IFACE 0x80 /* XXX: not related to ND. */ 9259333867SHiroki Sato #define ND6_IFF_NO_DAD 0x100 93201100c5SBjoern A. Zeeb #ifdef EXPERIMENTAL 94*21231a7aSBjoern A. Zeeb /* XXX: not related to ND. */ 95201100c5SBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY 0x200 /* draft-ietf-6man-ipv6only-flag */ 96*21231a7aSBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY_MANUAL 0x400 97*21231a7aSBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY_MASK (ND6_IFF_IPV6_ONLY|ND6_IFF_IPV6_ONLY_MANUAL) 98201100c5SBjoern A. Zeeb #endif 99686cdd19SJun-ichiro itojun Hagino 10031b1bfe1SHajimu UMEMOTO #ifdef _KERNEL 10131b1bfe1SHajimu UMEMOTO #define ND_IFINFO(ifp) \ 10231b1bfe1SHajimu UMEMOTO (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo) 10331b1bfe1SHajimu UMEMOTO #define IN6_LINKMTU(ifp) \ 10431b1bfe1SHajimu UMEMOTO ((ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) \ 10531b1bfe1SHajimu UMEMOTO ? ND_IFINFO(ifp)->linkmtu \ 10631b1bfe1SHajimu UMEMOTO : ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) \ 10731b1bfe1SHajimu UMEMOTO ? ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)) 10831b1bfe1SHajimu UMEMOTO #endif 10931b1bfe1SHajimu UMEMOTO 11082cd038dSYoshinobu Inoue struct in6_nbrinfo { 11182cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ 11282cd038dSYoshinobu Inoue struct in6_addr addr; /* IPv6 address of the neighbor */ 11382cd038dSYoshinobu Inoue long asked; /* number of queries already sent for this addr */ 11482cd038dSYoshinobu Inoue int isrouter; /* if it acts as a router */ 11582cd038dSYoshinobu Inoue int state; /* reachability state */ 11682cd038dSYoshinobu Inoue int expire; /* lifetime for NDP state transition */ 11782cd038dSYoshinobu Inoue }; 11882cd038dSYoshinobu Inoue 11982cd038dSYoshinobu Inoue #define DRLSTSIZ 10 12082cd038dSYoshinobu Inoue #define PRLSTSIZ 10 12182cd038dSYoshinobu Inoue struct in6_drlist { 12282cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; 12382cd038dSYoshinobu Inoue struct { 12482cd038dSYoshinobu Inoue struct in6_addr rtaddr; 12582cd038dSYoshinobu Inoue u_char flags; 12682cd038dSYoshinobu Inoue u_short rtlifetime; 12782cd038dSYoshinobu Inoue u_long expire; 12882cd038dSYoshinobu Inoue u_short if_index; 12982cd038dSYoshinobu Inoue } defrouter[DRLSTSIZ]; 13082cd038dSYoshinobu Inoue }; 13182cd038dSYoshinobu Inoue 13233841545SHajimu UMEMOTO struct in6_defrouter { 13333841545SHajimu UMEMOTO struct sockaddr_in6 rtaddr; 13433841545SHajimu UMEMOTO u_char flags; 13533841545SHajimu UMEMOTO u_short rtlifetime; 13633841545SHajimu UMEMOTO u_long expire; 13733841545SHajimu UMEMOTO u_short if_index; 13823cd8d58SHidetoshi Shimokawa }; 13933841545SHajimu UMEMOTO 140f95d4633SHajimu UMEMOTO #ifdef _KERNEL 141f95d4633SHajimu UMEMOTO struct in6_oprlist { 142f95d4633SHajimu UMEMOTO char ifname[IFNAMSIZ]; 143f95d4633SHajimu UMEMOTO struct { 144f95d4633SHajimu UMEMOTO struct in6_addr prefix; 145f95d4633SHajimu UMEMOTO struct prf_ra raflags; 146f95d4633SHajimu UMEMOTO u_char prefixlen; 147f95d4633SHajimu UMEMOTO u_char origin; 148f95d4633SHajimu UMEMOTO u_long vltime; 149f95d4633SHajimu UMEMOTO u_long pltime; 150f95d4633SHajimu UMEMOTO u_long expire; 151f95d4633SHajimu UMEMOTO u_short if_index; 152f95d4633SHajimu UMEMOTO u_short advrtrs; /* number of advertisement routers */ 153f95d4633SHajimu UMEMOTO struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ 154f95d4633SHajimu UMEMOTO } prefix[PRLSTSIZ]; 155f95d4633SHajimu UMEMOTO }; 156f95d4633SHajimu UMEMOTO #endif 157f95d4633SHajimu UMEMOTO 15882cd038dSYoshinobu Inoue struct in6_prlist { 15982cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; 16082cd038dSYoshinobu Inoue struct { 16182cd038dSYoshinobu Inoue struct in6_addr prefix; 16282cd038dSYoshinobu Inoue struct prf_ra raflags; 16382cd038dSYoshinobu Inoue u_char prefixlen; 164686cdd19SJun-ichiro itojun Hagino u_char origin; 16588ff5695SSUZUKI Shinsuke u_int32_t vltime; 16688ff5695SSUZUKI Shinsuke u_int32_t pltime; 16788ff5695SSUZUKI Shinsuke time_t expire; 16882cd038dSYoshinobu Inoue u_short if_index; 16982cd038dSYoshinobu Inoue u_short advrtrs; /* number of advertisement routers */ 17082cd038dSYoshinobu Inoue struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ 17182cd038dSYoshinobu Inoue } prefix[PRLSTSIZ]; 17282cd038dSYoshinobu Inoue }; 17382cd038dSYoshinobu Inoue 17433841545SHajimu UMEMOTO struct in6_prefix { 17533841545SHajimu UMEMOTO struct sockaddr_in6 prefix; 17633841545SHajimu UMEMOTO struct prf_ra raflags; 17733841545SHajimu UMEMOTO u_char prefixlen; 17833841545SHajimu UMEMOTO u_char origin; 179f95d4633SHajimu UMEMOTO u_int32_t vltime; 180f95d4633SHajimu UMEMOTO u_int32_t pltime; 181f95d4633SHajimu UMEMOTO time_t expire; 18233841545SHajimu UMEMOTO u_int32_t flags; 18333841545SHajimu UMEMOTO int refcnt; 18433841545SHajimu UMEMOTO u_short if_index; 18533841545SHajimu UMEMOTO u_short advrtrs; /* number of advertisement routers */ 18633841545SHajimu UMEMOTO /* struct sockaddr_in6 advrtr[] */ 18723cd8d58SHidetoshi Shimokawa }; 18833841545SHajimu UMEMOTO 18933841545SHajimu UMEMOTO #ifdef _KERNEL 19033841545SHajimu UMEMOTO struct in6_ondireq { 19133841545SHajimu UMEMOTO char ifname[IFNAMSIZ]; 19233841545SHajimu UMEMOTO struct { 19333841545SHajimu UMEMOTO u_int32_t linkmtu; /* LinkMTU */ 19433841545SHajimu UMEMOTO u_int32_t maxmtu; /* Upper bound of LinkMTU */ 19533841545SHajimu UMEMOTO u_int32_t basereachable; /* BaseReachableTime */ 19633841545SHajimu UMEMOTO u_int32_t reachable; /* Reachable Time */ 19733841545SHajimu UMEMOTO u_int32_t retrans; /* Retrans Timer */ 19833841545SHajimu UMEMOTO u_int32_t flags; /* Flags */ 19933841545SHajimu UMEMOTO int recalctm; /* BaseReacable re-calculation timer */ 20033841545SHajimu UMEMOTO u_int8_t chlim; /* CurHopLimit */ 20133841545SHajimu UMEMOTO u_int8_t receivedra; 20233841545SHajimu UMEMOTO } ndi; 20333841545SHajimu UMEMOTO }; 20433841545SHajimu UMEMOTO #endif 20533841545SHajimu UMEMOTO 20682cd038dSYoshinobu Inoue struct in6_ndireq { 20782cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; 20882cd038dSYoshinobu Inoue struct nd_ifinfo ndi; 20982cd038dSYoshinobu Inoue }; 21082cd038dSYoshinobu Inoue 211686cdd19SJun-ichiro itojun Hagino struct in6_ndifreq { 212686cdd19SJun-ichiro itojun Hagino char ifname[IFNAMSIZ]; 213686cdd19SJun-ichiro itojun Hagino u_long ifindex; 214686cdd19SJun-ichiro itojun Hagino }; 215686cdd19SJun-ichiro itojun Hagino 21633841545SHajimu UMEMOTO /* Prefix status */ 21733841545SHajimu UMEMOTO #define NDPRF_ONLINK 0x1 21833841545SHajimu UMEMOTO #define NDPRF_DETACHED 0x2 219686cdd19SJun-ichiro itojun Hagino 22082cd038dSYoshinobu Inoue /* protocol constants */ 22182cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ 22282cd038dSYoshinobu Inoue #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */ 22382cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATIONS 3 22482cd038dSYoshinobu Inoue 22582cd038dSYoshinobu Inoue #define ND6_INFINITE_LIFETIME 0xffffffff 22682cd038dSYoshinobu Inoue 22782cd038dSYoshinobu Inoue #ifdef _KERNEL 22882cd038dSYoshinobu Inoue /* node constants */ 22982cd038dSYoshinobu Inoue #define MAX_REACHABLE_TIME 3600000 /* msec */ 23082cd038dSYoshinobu Inoue #define REACHABLE_TIME 30000 /* msec */ 23182cd038dSYoshinobu Inoue #define RETRANS_TIMER 1000 /* msec */ 23282cd038dSYoshinobu Inoue #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 23382cd038dSYoshinobu Inoue #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 23433841545SHajimu UMEMOTO #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */ 23533841545SHajimu UMEMOTO #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */ 23633841545SHajimu UMEMOTO #define TEMPADDR_REGEN_ADVANCE 5 /* sec */ 23733841545SHajimu UMEMOTO #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */ 23882cd038dSYoshinobu Inoue #define ND_COMPUTE_RTIME(x) \ 239a02e1e2bSHajimu UMEMOTO (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \ 24082cd038dSYoshinobu Inoue ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 24182cd038dSYoshinobu Inoue 242686cdd19SJun-ichiro itojun Hagino TAILQ_HEAD(nd_drhead, nd_defrouter); 24382cd038dSYoshinobu Inoue struct nd_defrouter { 244686cdd19SJun-ichiro itojun Hagino TAILQ_ENTRY(nd_defrouter) dr_entry; 24582cd038dSYoshinobu Inoue struct in6_addr rtaddr; 24601869be5SMark Johnston u_char raflags; /* flags on RA message */ 24782cd038dSYoshinobu Inoue u_short rtlifetime; 24882cd038dSYoshinobu Inoue u_long expire; 24982cd038dSYoshinobu Inoue struct ifnet *ifp; 250743eee66SSUZUKI Shinsuke int installed; /* is installed into kernel routing table */ 2514de485feSMark Johnston u_int refcnt; 25282cd038dSYoshinobu Inoue }; 25382cd038dSYoshinobu Inoue 254743eee66SSUZUKI Shinsuke struct nd_prefixctl { 255743eee66SSUZUKI Shinsuke struct ifnet *ndpr_ifp; 256743eee66SSUZUKI Shinsuke 257743eee66SSUZUKI Shinsuke /* prefix */ 258743eee66SSUZUKI Shinsuke struct sockaddr_in6 ndpr_prefix; 259743eee66SSUZUKI Shinsuke u_char ndpr_plen; 260743eee66SSUZUKI Shinsuke 261743eee66SSUZUKI Shinsuke u_int32_t ndpr_vltime; /* advertised valid lifetime */ 262743eee66SSUZUKI Shinsuke u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 263743eee66SSUZUKI Shinsuke 264743eee66SSUZUKI Shinsuke struct prf_ra ndpr_flags; 265743eee66SSUZUKI Shinsuke }; 266743eee66SSUZUKI Shinsuke 267d748f7efSMark Johnston LIST_HEAD(nd_prhead, nd_prefix); 26882cd038dSYoshinobu Inoue struct nd_prefix { 26982cd038dSYoshinobu Inoue struct ifnet *ndpr_ifp; 270e3975643SJake Burkholder LIST_ENTRY(nd_prefix) ndpr_entry; 27182cd038dSYoshinobu Inoue struct sockaddr_in6 ndpr_prefix; /* prefix */ 27282cd038dSYoshinobu Inoue struct in6_addr ndpr_mask; /* netmask derived from the prefix */ 273743eee66SSUZUKI Shinsuke 27482cd038dSYoshinobu Inoue u_int32_t ndpr_vltime; /* advertised valid lifetime */ 27582cd038dSYoshinobu Inoue u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 276743eee66SSUZUKI Shinsuke 27782cd038dSYoshinobu Inoue time_t ndpr_expire; /* expiration time of the prefix */ 27882cd038dSYoshinobu Inoue time_t ndpr_preferred; /* preferred time of the prefix */ 279743eee66SSUZUKI Shinsuke time_t ndpr_lastupdate; /* reception time of last advertisement */ 280743eee66SSUZUKI Shinsuke 28182cd038dSYoshinobu Inoue struct prf_ra ndpr_flags; 28233841545SHajimu UMEMOTO u_int32_t ndpr_stateflags; /* actual state flags */ 28382cd038dSYoshinobu Inoue /* list of routers that advertise the prefix: */ 284e3975643SJake Burkholder LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs; 28582cd038dSYoshinobu Inoue u_char ndpr_plen; 2860bbf244eSMark Johnston int ndpr_addrcnt; /* count of derived addresses */ 287d748f7efSMark Johnston volatile u_int ndpr_refcnt; 28882cd038dSYoshinobu Inoue }; 28982cd038dSYoshinobu Inoue 29082cd038dSYoshinobu Inoue #define ndpr_raf ndpr_flags 29182cd038dSYoshinobu Inoue #define ndpr_raf_onlink ndpr_flags.onlink 29282cd038dSYoshinobu Inoue #define ndpr_raf_auto ndpr_flags.autonomous 293743eee66SSUZUKI Shinsuke #define ndpr_raf_router ndpr_flags.router 29482cd038dSYoshinobu Inoue 29582cd038dSYoshinobu Inoue /* 29682cd038dSYoshinobu Inoue * Message format for use in obtaining information about prefixes 29782cd038dSYoshinobu Inoue * from inet6 sysctl function 29882cd038dSYoshinobu Inoue */ 29982cd038dSYoshinobu Inoue struct inet6_ndpr_msghdr { 30082cd038dSYoshinobu Inoue u_short inpm_msglen; /* to skip over non-understood messages */ 3012fa72ea7SJeroen Ruigrok van der Werven u_char inpm_version; /* future binary compatibility */ 30282cd038dSYoshinobu Inoue u_char inpm_type; /* message type */ 30382cd038dSYoshinobu Inoue struct in6_addr inpm_prefix; 30482cd038dSYoshinobu Inoue u_long prm_vltim; 30582cd038dSYoshinobu Inoue u_long prm_pltime; 30682cd038dSYoshinobu Inoue u_long prm_expire; 30782cd038dSYoshinobu Inoue u_long prm_preferred; 30882cd038dSYoshinobu Inoue struct in6_prflags prm_flags; 30982cd038dSYoshinobu Inoue u_short prm_index; /* index for associated ifp */ 31082cd038dSYoshinobu Inoue u_char prm_plen; /* length of prefix in bits */ 31182cd038dSYoshinobu Inoue }; 31282cd038dSYoshinobu Inoue 31382cd038dSYoshinobu Inoue #define prm_raf_onlink prm_flags.prf_ra.onlink 31482cd038dSYoshinobu Inoue #define prm_raf_auto prm_flags.prf_ra.autonomous 31582cd038dSYoshinobu Inoue 31682cd038dSYoshinobu Inoue #define prm_statef_onlink prm_flags.prf_state.onlink 31782cd038dSYoshinobu Inoue 31882cd038dSYoshinobu Inoue #define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid 31982cd038dSYoshinobu Inoue #define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd 32082cd038dSYoshinobu Inoue 32182cd038dSYoshinobu Inoue struct nd_pfxrouter { 322e3975643SJake Burkholder LIST_ENTRY(nd_pfxrouter) pfr_entry; 32382cd038dSYoshinobu Inoue struct nd_defrouter *router; 32482cd038dSYoshinobu Inoue }; 32582cd038dSYoshinobu Inoue 3265e0a6f31SMark Johnston #ifdef MALLOC_DECLARE 3275e0a6f31SMark Johnston MALLOC_DECLARE(M_IP6NDP); 3285e0a6f31SMark Johnston #endif 3295e0a6f31SMark Johnston 33082cd038dSYoshinobu Inoue /* nd6.c */ 331eddfbb76SRobert Watson VNET_DECLARE(int, nd6_prune); 332eddfbb76SRobert Watson VNET_DECLARE(int, nd6_delay); 333eddfbb76SRobert Watson VNET_DECLARE(int, nd6_umaxtries); 334eddfbb76SRobert Watson VNET_DECLARE(int, nd6_mmaxtries); 335eddfbb76SRobert Watson VNET_DECLARE(int, nd6_useloopback); 336eddfbb76SRobert Watson VNET_DECLARE(int, nd6_maxnudhint); 337eddfbb76SRobert Watson VNET_DECLARE(int, nd6_gctimer); 338eddfbb76SRobert Watson VNET_DECLARE(struct nd_drhead, nd_defrouter); 339eddfbb76SRobert Watson VNET_DECLARE(struct nd_prhead, nd_prefix); 340eddfbb76SRobert Watson VNET_DECLARE(int, nd6_debug); 341eddfbb76SRobert Watson VNET_DECLARE(int, nd6_onlink_ns_rfc4861); 3421e77c105SRobert Watson #define V_nd6_prune VNET(nd6_prune) 3431e77c105SRobert Watson #define V_nd6_delay VNET(nd6_delay) 3441e77c105SRobert Watson #define V_nd6_umaxtries VNET(nd6_umaxtries) 3451e77c105SRobert Watson #define V_nd6_mmaxtries VNET(nd6_mmaxtries) 3461e77c105SRobert Watson #define V_nd6_useloopback VNET(nd6_useloopback) 3471e77c105SRobert Watson #define V_nd6_maxnudhint VNET(nd6_maxnudhint) 3481e77c105SRobert Watson #define V_nd6_gctimer VNET(nd6_gctimer) 3491e77c105SRobert Watson #define V_nd_defrouter VNET(nd_defrouter) 3501e77c105SRobert Watson #define V_nd_prefix VNET(nd_prefix) 3511e77c105SRobert Watson #define V_nd6_debug VNET(nd6_debug) 3521e77c105SRobert Watson #define V_nd6_onlink_ns_rfc4861 VNET(nd6_onlink_ns_rfc4861) 35382cea7e6SBjoern A. Zeeb 3544de485feSMark Johnston /* Lock for the prefix and default router lists. */ 3554de485feSMark Johnston VNET_DECLARE(struct rwlock, nd6_lock); 356d748f7efSMark Johnston VNET_DECLARE(uint64_t, nd6_list_genid); 3574de485feSMark Johnston #define V_nd6_lock VNET(nd6_lock) 358d748f7efSMark Johnston #define V_nd6_list_genid VNET(nd6_list_genid) 3594de485feSMark Johnston 3604de485feSMark Johnston #define ND6_RLOCK() rw_rlock(&V_nd6_lock) 3614de485feSMark Johnston #define ND6_RUNLOCK() rw_runlock(&V_nd6_lock) 3624de485feSMark Johnston #define ND6_WLOCK() rw_wlock(&V_nd6_lock) 3634de485feSMark Johnston #define ND6_WUNLOCK() rw_wunlock(&V_nd6_lock) 364d748f7efSMark Johnston #define ND6_TRY_UPGRADE() rw_try_upgrade(&V_nd6_lock) 3654de485feSMark Johnston #define ND6_WLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_WLOCKED) 3664de485feSMark Johnston #define ND6_RLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_RLOCKED) 3674de485feSMark Johnston #define ND6_LOCK_ASSERT() rw_assert(&V_nd6_lock, RA_LOCKED) 3684de485feSMark Johnston #define ND6_UNLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_UNLOCKED) 3694de485feSMark Johnston 370d748f7efSMark Johnston /* Mutex for prefix onlink/offlink transitions. */ 371d748f7efSMark Johnston VNET_DECLARE(struct mtx, nd6_onlink_mtx); 372d748f7efSMark Johnston #define V_nd6_onlink_mtx VNET(nd6_onlink_mtx) 373d748f7efSMark Johnston 374d748f7efSMark Johnston #define ND6_ONLINK_LOCK() mtx_lock(&V_nd6_onlink_mtx) 375d748f7efSMark Johnston #define ND6_ONLINK_TRYLOCK() mtx_trylock(&V_nd6_onlink_mtx) 376d748f7efSMark Johnston #define ND6_ONLINK_UNLOCK() mtx_unlock(&V_nd6_onlink_mtx) 377d748f7efSMark Johnston #define ND6_ONLINK_LOCK_ASSERT() mtx_assert(&V_nd6_onlink_mtx, MA_OWNED) 378d748f7efSMark Johnston #define ND6_ONLINK_UNLOCK_ASSERT() mtx_assert(&V_nd6_onlink_mtx, MA_NOTOWNED) 379d748f7efSMark Johnston 38082cea7e6SBjoern A. Zeeb #define nd6log(x) do { if (V_nd6_debug) log x; } while (/*CONSTCOND*/ 0) 38182cea7e6SBjoern A. Zeeb 382686cdd19SJun-ichiro itojun Hagino /* nd6_rtr.c */ 383eddfbb76SRobert Watson VNET_DECLARE(int, nd6_defifindex); 384eddfbb76SRobert Watson VNET_DECLARE(int, ip6_desync_factor); /* seconds */ 385eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_preferred_lifetime); /* seconds */ 386eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_valid_lifetime); /* seconds */ 387eddfbb76SRobert Watson VNET_DECLARE(int, ip6_temp_regen_advance); /* seconds */ 3881e77c105SRobert Watson #define V_nd6_defifindex VNET(nd6_defifindex) 3891e77c105SRobert Watson #define V_ip6_desync_factor VNET(ip6_desync_factor) 3901e77c105SRobert Watson #define V_ip6_temp_preferred_lifetime VNET(ip6_temp_preferred_lifetime) 3911e77c105SRobert Watson #define V_ip6_temp_valid_lifetime VNET(ip6_temp_valid_lifetime) 3921e77c105SRobert Watson #define V_ip6_temp_regen_advance VNET(ip6_temp_regen_advance) 39386413abfSBjoern A. Zeeb 39482cd038dSYoshinobu Inoue union nd_opts { 39511d8451dSHiroki Sato struct nd_opt_hdr *nd_opt_array[16]; /* max = ND_OPT_NONCE */ 39682cd038dSYoshinobu Inoue struct { 39782cd038dSYoshinobu Inoue struct nd_opt_hdr *zero; 39882cd038dSYoshinobu Inoue struct nd_opt_hdr *src_lladdr; 39982cd038dSYoshinobu Inoue struct nd_opt_hdr *tgt_lladdr; 40082cd038dSYoshinobu Inoue struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */ 40182cd038dSYoshinobu Inoue struct nd_opt_rd_hdr *rh; 40282cd038dSYoshinobu Inoue struct nd_opt_mtu *mtu; 40311d8451dSHiroki Sato struct nd_opt_hdr *__res6; 40411d8451dSHiroki Sato struct nd_opt_hdr *__res7; 40511d8451dSHiroki Sato struct nd_opt_hdr *__res8; 40611d8451dSHiroki Sato struct nd_opt_hdr *__res9; 40711d8451dSHiroki Sato struct nd_opt_hdr *__res10; 40811d8451dSHiroki Sato struct nd_opt_hdr *__res11; 40911d8451dSHiroki Sato struct nd_opt_hdr *__res12; 41011d8451dSHiroki Sato struct nd_opt_hdr *__res13; 41111d8451dSHiroki Sato struct nd_opt_nonce *nonce; 41211d8451dSHiroki Sato struct nd_opt_hdr *__res15; 41382cd038dSYoshinobu Inoue struct nd_opt_hdr *search; /* multiple opts */ 41482cd038dSYoshinobu Inoue struct nd_opt_hdr *last; /* multiple opts */ 41582cd038dSYoshinobu Inoue int done; 41682cd038dSYoshinobu Inoue struct nd_opt_prefix_info *pi_end;/* multiple opts, end */ 41782cd038dSYoshinobu Inoue } nd_opt_each; 41882cd038dSYoshinobu Inoue }; 41982cd038dSYoshinobu Inoue #define nd_opts_src_lladdr nd_opt_each.src_lladdr 42082cd038dSYoshinobu Inoue #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr 42182cd038dSYoshinobu Inoue #define nd_opts_pi nd_opt_each.pi_beg 42282cd038dSYoshinobu Inoue #define nd_opts_pi_end nd_opt_each.pi_end 42382cd038dSYoshinobu Inoue #define nd_opts_rh nd_opt_each.rh 42482cd038dSYoshinobu Inoue #define nd_opts_mtu nd_opt_each.mtu 42511d8451dSHiroki Sato #define nd_opts_nonce nd_opt_each.nonce 42682cd038dSYoshinobu Inoue #define nd_opts_search nd_opt_each.search 42782cd038dSYoshinobu Inoue #define nd_opts_last nd_opt_each.last 42882cd038dSYoshinobu Inoue #define nd_opts_done nd_opt_each.done 42982cd038dSYoshinobu Inoue 43082cd038dSYoshinobu Inoue /* XXX: need nd6_var.h?? */ 43182cd038dSYoshinobu Inoue /* nd6.c */ 4326f56329aSXin LI void nd6_init(void); 433bc29160dSMarko Zec #ifdef VIMAGE 4346f56329aSXin LI void nd6_destroy(void); 435bc29160dSMarko Zec #endif 4366f56329aSXin LI struct nd_ifinfo *nd6_ifattach(struct ifnet *); 43789856f7eSBjoern A. Zeeb void nd6_ifdetach(struct ifnet *, struct nd_ifinfo *); 438f0316e1aSAlexander V. Chernikov int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); 4396f56329aSXin LI void nd6_option_init(void *, int, union nd_opts *); 4406f56329aSXin LI struct nd_opt_hdr *nd6_option(union nd_opts *); 4416f56329aSXin LI int nd6_options(union nd_opts *); 442f0316e1aSAlexander V. Chernikov struct llentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *); 443f0316e1aSAlexander V. Chernikov struct llentry *nd6_alloc(const struct in6_addr *, int, struct ifnet *); 4446f56329aSXin LI void nd6_setmtu(struct ifnet *); 445aa5f023eSAlexander V. Chernikov void nd6_llinfo_setstate(struct llentry *lle, int newstate); 4466f56329aSXin LI void nd6_timer(void *); 4476f56329aSXin LI void nd6_purge(struct ifnet *); 4484fb3a820SAlexander V. Chernikov int nd6_resolve_addr(struct ifnet *ifp, int flags, const struct sockaddr *dst, 4494fb3a820SAlexander V. Chernikov char *desten, uint32_t *pflags); 4501fe201c3SAlexander V. Chernikov int nd6_resolve(struct ifnet *, int, struct mbuf *, 4516d768226SGeorge V. Neville-Neil const struct sockaddr *, u_char *, uint32_t *, struct llentry **); 4526f56329aSXin LI int nd6_ioctl(u_long, caddr_t, struct ifnet *); 4530e2dcee6SAlexander V. Chernikov void nd6_cache_lladdr(struct ifnet *, struct in6_addr *, 4546f56329aSXin LI char *, int, int, int); 455d7968c29SAlexander V. Chernikov void nd6_grab_holdchain(struct llentry *, struct mbuf **, 456d7968c29SAlexander V. Chernikov struct sockaddr_in6 *); 457151ba793SAlexander Kabaev int nd6_flush_holdchain(struct ifnet *, struct mbuf *, 4589c9bde01SAlexander V. Chernikov struct sockaddr_in6 *); 459f6b84910SAlexander V. Chernikov int nd6_add_ifa_lle(struct in6_ifaddr *); 4603e7a2321SAlexander V. Chernikov void nd6_rem_ifa_lle(struct in6_ifaddr *, int); 4611fe201c3SAlexander V. Chernikov int nd6_output_ifp(struct ifnet *, struct ifnet *, struct mbuf *, 462637670e7SAlexander V. Chernikov struct sockaddr_in6 *, struct route *); 46382cd038dSYoshinobu Inoue 46482cd038dSYoshinobu Inoue /* nd6_nbr.c */ 4656f56329aSXin LI void nd6_na_input(struct mbuf *, int, int); 4666f56329aSXin LI void nd6_na_output(struct ifnet *, const struct in6_addr *, 4676f56329aSXin LI const struct in6_addr *, u_long, int, struct sockaddr *); 4686f56329aSXin LI void nd6_ns_input(struct mbuf *, int, int); 4696f56329aSXin LI void nd6_ns_output(struct ifnet *, const struct in6_addr *, 47026deb882SAlexander V. Chernikov const struct in6_addr *, const struct in6_addr *, uint8_t *); 4716f56329aSXin LI caddr_t nd6_ifptomac(struct ifnet *); 472d6ad6a86SMark Johnston void nd6_dad_init(void); 4736f56329aSXin LI void nd6_dad_start(struct ifaddr *, int); 4746f56329aSXin LI void nd6_dad_stop(struct ifaddr *); 47582cd038dSYoshinobu Inoue 47682cd038dSYoshinobu Inoue /* nd6_rtr.c */ 4776f56329aSXin LI void nd6_rs_input(struct mbuf *, int, int); 4786f56329aSXin LI void nd6_ra_input(struct mbuf *, int, int); 4796f56329aSXin LI void defrouter_reset(void); 480559b4296SAlan Somers void defrouter_select_fib(int fibnum); 4816f56329aSXin LI void defrouter_select(void); 4824de485feSMark Johnston void defrouter_ref(struct nd_defrouter *); 4834de485feSMark Johnston void defrouter_rele(struct nd_defrouter *); 484ff63037dSMark Johnston bool defrouter_remove(struct in6_addr *, struct ifnet *); 4854de485feSMark Johnston void defrouter_unlink(struct nd_defrouter *, struct nd_drhead *); 4864de485feSMark Johnston void defrouter_del(struct nd_defrouter *); 4876f56329aSXin LI int nd6_prelist_add(struct nd_prefixctl *, struct nd_defrouter *, 4886f56329aSXin LI struct nd_prefix **); 489d748f7efSMark Johnston void nd6_prefix_unlink(struct nd_prefix *, struct nd_prhead *); 490d748f7efSMark Johnston void nd6_prefix_del(struct nd_prefix *); 491d748f7efSMark Johnston void nd6_prefix_ref(struct nd_prefix *); 492d748f7efSMark Johnston void nd6_prefix_rele(struct nd_prefix *); 493d748f7efSMark Johnston int nd6_prefix_onlink(struct nd_prefix *); 494d748f7efSMark Johnston int nd6_prefix_offlink(struct nd_prefix *); 4956f56329aSXin LI void pfxlist_onlink_check(void); 4966f56329aSXin LI struct nd_defrouter *defrouter_lookup(struct in6_addr *, struct ifnet *); 4974de485feSMark Johnston struct nd_defrouter *defrouter_lookup_locked(struct in6_addr *, struct ifnet *); 4986f56329aSXin LI struct nd_prefix *nd6_prefix_lookup(struct nd_prefixctl *); 4996f56329aSXin LI void rt6_flush(struct in6_addr *, struct ifnet *); 5006f56329aSXin LI int nd6_setdefaultiface(int); 5016f56329aSXin LI int in6_tmpifadd(const struct in6_ifaddr *, int, int); 50282cd038dSYoshinobu Inoue 50382cd038dSYoshinobu Inoue #endif /* _KERNEL */ 50482cd038dSYoshinobu Inoue 50582cd038dSYoshinobu Inoue #endif /* _NETINET6_ND6_H_ */ 506