Home | History | Annotate | Line # | Download | only in netinet6
nd6.h revision 1.6
      1 /*	$NetBSD: nd6.h,v 1.6 1999/12/13 15:17:23 itojun Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the project nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _NETINET6_ND6_H_
     33 #define _NETINET6_ND6_H_
     34 
     35 #include <sys/queue.h>
     36 
     37 struct	llinfo_nd6 {
     38 	struct	llinfo_nd6 *ln_next;
     39 	struct	llinfo_nd6 *ln_prev;
     40 	struct	rtentry *ln_rt;
     41 	struct	mbuf *ln_hold;	/* last packet until resolved/timeout */
     42 	long	ln_asked;	/* number of queries already sent for this addr */
     43 	u_long	ln_expire;	/* lifetime for NDP state transition */
     44 	short	ln_state;	/* reachability state */
     45 	short	ln_router;	/* 2^0: ND6 router bit */
     46 };
     47 
     48 #define ND6_LLINFO_NOSTATE	-2
     49 #define ND6_LLINFO_WAITDELETE	-1
     50 #define ND6_LLINFO_INCOMPLETE	0
     51 #define ND6_LLINFO_REACHABLE	1
     52 #define ND6_LLINFO_STALE	2
     53 #define ND6_LLINFO_DELAY	3
     54 #define ND6_LLINFO_PROBE	4
     55 
     56 #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
     57 
     58 struct nd_ifinfo {
     59 	u_int32_t linkmtu;		/* LinkMTU */
     60 	u_int32_t maxmtu;		/* Upper bound of LinkMTU */
     61 	u_int32_t basereachable;	/* BaseReachableTime */
     62 	u_int32_t reachable;		/* Reachable Time */
     63 	u_int32_t retrans;		/* Retrans Timer */
     64 	int recalctm;			/* BaseReacable re-calculation timer */
     65 	u_int8_t chlim;			/* CurHopLimit */
     66 	u_int8_t receivedra;
     67 };
     68 
     69 struct in6_nbrinfo {
     70 	char ifname[IFNAMSIZ];	/* if name, e.g. "en0" */
     71 	struct in6_addr addr;	/* IPv6 address of the neighbor */
     72 	long	asked;		/* number of queries already sent for this addr */
     73 	int	isrouter;	/* if it acts as a router */
     74 	int	state;		/* reachability state */
     75 	int	expire;		/* lifetime for NDP state transition */
     76 };
     77 
     78 #define DRLSTSIZ 10
     79 #define PRLSTSIZ 10
     80 struct	in6_drlist {
     81 	char ifname[IFNAMSIZ];
     82 	struct {
     83 		struct	in6_addr rtaddr;
     84 		u_char	flags;
     85 		u_short	rtlifetime;
     86 		u_long	expire;
     87 		u_short if_index;
     88 	} defrouter[DRLSTSIZ];
     89 };
     90 
     91 struct	in6_prlist {
     92 	char ifname[IFNAMSIZ];
     93 	struct {
     94 		struct	in6_addr prefix;
     95 		struct prf_ra raflags;
     96 		u_char	prefixlen;
     97 		u_long	vltime;
     98 		u_long	pltime;
     99 		u_long	expire;
    100 		u_short if_index;
    101 		u_short advrtrs; /* number of advertisement routers */
    102 		struct	in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */
    103 	} prefix[PRLSTSIZ];
    104 };
    105 
    106 struct	in6_ndireq {
    107 	char ifname[IFNAMSIZ];
    108 	struct nd_ifinfo ndi;
    109 };
    110 
    111 struct	in6_ndifreq {
    112 	char ifname[IFNAMSIZ];
    113 	u_long ifindex;
    114 };
    115 
    116 
    117 /* protocol constants */
    118 #define MAX_RTR_SOLICITATION_DELAY	1	/*1sec*/
    119 #define RTR_SOLICITATION_INTERVAL	4	/*4sec*/
    120 #define MAX_RTR_SOLICITATIONS		3
    121 
    122 #define ND6_INFINITE_LIFETIME		0xffffffff
    123 
    124 #ifdef _KERNEL
    125 /* node constants */
    126 #define MAX_REACHABLE_TIME		3600000	/* msec */
    127 #define REACHABLE_TIME			30000	/* msec */
    128 #define RETRANS_TIMER			1000	/* msec */
    129 #define MIN_RANDOM_FACTOR		512	/* 1024 * 0.5 */
    130 #define MAX_RANDOM_FACTOR		1536	/* 1024 * 1.5 */
    131 #define ND_COMPUTE_RTIME(x) \
    132 		(((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \
    133 		((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
    134 
    135 TAILQ_HEAD(nd_drhead, nd_defrouter);
    136 struct	nd_defrouter {
    137 	TAILQ_ENTRY(nd_defrouter) dr_entry;
    138 	struct	in6_addr rtaddr;
    139 	u_char	flags;
    140 	u_short	rtlifetime;
    141 	u_long	expire;
    142 	struct  ifnet *ifp;
    143 };
    144 
    145 struct nd_prefix {
    146 	struct ifnet *ndpr_ifp;
    147 	LIST_ENTRY(nd_prefix) ndpr_entry;
    148 	struct sockaddr_in6 ndpr_prefix;	/* prefix */
    149 	struct in6_addr ndpr_mask; /* netmask derived from the prefix */
    150 	struct in6_addr ndpr_addr; /* address that is derived from the prefix */
    151 	u_int32_t ndpr_vltime;	/* advertised valid lifetime */
    152 	u_int32_t ndpr_pltime;	/* advertised preferred lifetime */
    153 	time_t ndpr_expire;	/* expiration time of the prefix */
    154 	time_t ndpr_preferred;	/* preferred time of the prefix */
    155 	struct prf_ra ndpr_flags;
    156 	/* list of routers that advertise the prefix: */
    157 	LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
    158 	u_char	ndpr_plen;
    159 	struct	ndpr_stateflags {
    160 		/* if this prefix can be regarded as on-link */
    161 		u_char onlink : 1;
    162 	} ndpr_stateflags;
    163 };
    164 
    165 #define ndpr_next		ndpr_entry.le_next
    166 
    167 #define ndpr_raf		ndpr_flags
    168 #define ndpr_raf_onlink		ndpr_flags.onlink
    169 #define ndpr_raf_auto		ndpr_flags.autonomous
    170 
    171 #define ndpr_statef_onlink	ndpr_stateflags.onlink
    172 #define ndpr_statef_addmark	ndpr_stateflags.addmark
    173 
    174 /*
    175  * We keep expired prefix for certain amount of time, for validation purposes.
    176  * 1800s = MaxRtrAdvInterval
    177  */
    178 #define NDPR_KEEP_EXPIRED	(1800 * 2)
    179 
    180 /*
    181  * Message format for use in obtaining information about prefixes
    182  * from inet6 sysctl function
    183  */
    184 struct inet6_ndpr_msghdr {
    185 	u_short	inpm_msglen;	/* to skip over non-understood messages */
    186 	u_char	inpm_version;	/* future binary compatability */
    187 	u_char	inpm_type;	/* message type */
    188 	struct in6_addr inpm_prefix;
    189 	u_long	prm_vltim;
    190 	u_long	prm_pltime;
    191 	u_long	prm_expire;
    192 	u_long	prm_preferred;
    193 	struct in6_prflags prm_flags;
    194 	u_short	prm_index;	/* index for associated ifp */
    195 	u_char	prm_plen;	/* length of prefix in bits */
    196 };
    197 
    198 #define prm_raf_onlink		prm_flags.prf_ra.onlink
    199 #define prm_raf_auto		prm_flags.prf_ra.autonomous
    200 
    201 #define prm_statef_onlink	prm_flags.prf_state.onlink
    202 
    203 #define prm_rrf_decrvalid	prm_flags.prf_rr.decrvalid
    204 #define prm_rrf_decrprefd	prm_flags.prf_rr.decrprefd
    205 
    206 #define ifpr2ndpr(ifpr)	((struct nd_prefix *)(ifpr))
    207 #define ndpr2ifpr(ndpr)	((struct ifprefix *)(ndpr))
    208 
    209 struct nd_pfxrouter {
    210 	LIST_ENTRY(nd_pfxrouter) pfr_entry;
    211 #define pfr_next pfr_entry.le_next
    212 	struct nd_defrouter *router;
    213 };
    214 
    215 LIST_HEAD(nd_prhead, nd_prefix);
    216 
    217 /* nd6.c */
    218 extern int nd6_prune;
    219 extern int nd6_delay;
    220 extern int nd6_umaxtries;
    221 extern int nd6_mmaxtries;
    222 extern int nd6_useloopback;
    223 extern int nd6_proxyall;
    224 extern struct llinfo_nd6 llinfo_nd6;
    225 extern struct nd_ifinfo *nd_ifinfo;
    226 extern struct nd_drhead nd_defrouter;
    227 extern struct nd_prhead nd_prefix;
    228 
    229 /* nd6_rtr.c */
    230 extern int nd6_defifindex;
    231 
    232 union nd_opts {
    233 	struct nd_opt_hdr *nd_opt_array[9];
    234 	struct {
    235 		struct nd_opt_hdr *zero;
    236 		struct nd_opt_hdr *src_lladdr;
    237 		struct nd_opt_hdr *tgt_lladdr;
    238 		struct nd_opt_prefix_info *pi_beg;/* multiple opts, start */
    239 		struct nd_opt_rd_hdr *rh;
    240 		struct nd_opt_mtu *mtu;
    241 		struct nd_opt_hdr *search;	/* multiple opts */
    242 		struct nd_opt_hdr *last;	/* multiple opts */
    243 		int done;
    244 		struct nd_opt_prefix_info *pi_end;/* multiple opts, end */
    245 	} nd_opt_each;
    246 };
    247 #define nd_opts_src_lladdr	nd_opt_each.src_lladdr
    248 #define nd_opts_tgt_lladdr	nd_opt_each.tgt_lladdr
    249 #define nd_opts_pi		nd_opt_each.pi_beg
    250 #define nd_opts_pi_end		nd_opt_each.pi_end
    251 #define nd_opts_rh		nd_opt_each.rh
    252 #define nd_opts_mtu		nd_opt_each.mtu
    253 #define nd_opts_search		nd_opt_each.search
    254 #define nd_opts_last		nd_opt_each.last
    255 #define nd_opts_done		nd_opt_each.done
    256 
    257 /* XXX: need nd6_var.h?? */
    258 /* nd6.c */
    259 void nd6_init __P((void));
    260 void nd6_ifattach __P((struct ifnet *));
    261 int nd6_is_addr_neighbor __P((struct in6_addr *, struct ifnet *));
    262 void nd6_option_init __P((void *, int, union nd_opts *));
    263 struct nd_opt_hdr *nd6_option __P((union nd_opts *));
    264 int nd6_options __P((union nd_opts *));
    265 struct	rtentry *nd6_lookup __P((struct in6_addr *, int, struct ifnet *));
    266 void nd6_setmtu __P((struct ifnet *));
    267 void nd6_timer __P((void *));
    268 void nd6_free __P((struct rtentry *));
    269 void nd6_nud_hint __P((struct rtentry *, struct in6_addr *));
    270 int nd6_resolve __P((struct ifnet *, struct rtentry *,
    271 		     struct mbuf *, struct sockaddr *, u_char *));
    272 #if defined(__bsdi__) && _BSDI_VERSION >= 199802
    273 void nd6_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
    274 void nd6_p2p_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
    275 #else
    276 void nd6_rtrequest __P((int, struct rtentry *, struct sockaddr *));
    277 void nd6_p2p_rtrequest __P((int, struct rtentry *, struct sockaddr *));
    278 #endif
    279 int nd6_ioctl __P((u_long, caddr_t, struct ifnet *));
    280 struct rtentry *nd6_cache_lladdr __P((struct ifnet *, struct in6_addr *,
    281 	char *, int, int, int));
    282 /* for test */
    283 int nd6_output __P((struct ifnet *, struct mbuf *, struct sockaddr_in6 *,
    284 		    struct rtentry *));
    285 int nd6_storelladdr __P((struct ifnet *, struct rtentry *, struct mbuf *,
    286 			 struct sockaddr *, u_char *));
    287 
    288 /* nd6_nbr.c */
    289 void nd6_na_input __P((struct mbuf *, int, int));
    290 void nd6_na_output __P((struct ifnet *, struct in6_addr *,
    291  			struct in6_addr *, u_long, int));
    292 void nd6_ns_input __P((struct mbuf *, int, int));
    293 void nd6_ns_output __P((struct ifnet *, struct in6_addr *,
    294 			struct in6_addr *, struct llinfo_nd6 *, int));
    295 caddr_t nd6_ifptomac __P((struct ifnet *));
    296 void nd6_dad_start __P((struct ifaddr *, int *));
    297 void nd6_dad_duplicated __P((struct ifaddr *));
    298 
    299 /* nd6_rtr.c */
    300 void nd6_rs_input __P((struct mbuf *, int, int));
    301 void nd6_ra_input __P((struct mbuf *, int, int));
    302 void prelist_del __P((struct nd_prefix *));
    303 void defrouter_addreq __P((struct nd_defrouter *));
    304 void defrouter_delreq __P((struct nd_defrouter *, int));
    305 void defrouter_select __P((void));
    306 void defrtrlist_del __P((struct nd_defrouter *));
    307 void prelist_remove __P((struct nd_prefix *));
    308 int prelist_update __P((struct nd_prefix *, struct nd_defrouter *,
    309 	struct mbuf *));
    310 void pfxlist_onlink_check __P((void));
    311 struct nd_defrouter *defrouter_lookup __P((struct in6_addr *,
    312 					   struct ifnet *));
    313 int in6_ifdel __P((struct ifnet *, struct in6_addr *));
    314 int in6_init_prefix_ltimes __P((struct nd_prefix *ndpr));
    315 void rt6_flush __P((struct in6_addr *, struct ifnet *));
    316 int nd6_setdefaultiface __P((int));
    317 
    318 #endif /* _KERNEL */
    319 
    320 #endif /* _NETINET6_ND6_H_ */
    321