nd6.h revision 53541
153541Sshin/* 253541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 353541Sshin * All rights reserved. 453541Sshin * 553541Sshin * Redistribution and use in source and binary forms, with or without 653541Sshin * modification, are permitted provided that the following conditions 753541Sshin * are met: 853541Sshin * 1. Redistributions of source code must retain the above copyright 953541Sshin * notice, this list of conditions and the following disclaimer. 1053541Sshin * 2. Redistributions in binary form must reproduce the above copyright 1153541Sshin * notice, this list of conditions and the following disclaimer in the 1253541Sshin * documentation and/or other materials provided with the distribution. 1353541Sshin * 3. Neither the name of the project nor the names of its contributors 1453541Sshin * may be used to endorse or promote products derived from this software 1553541Sshin * without specific prior written permission. 1653541Sshin * 1753541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1853541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1953541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2053541Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2153541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2253541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2353541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2453541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2553541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2653541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2753541Sshin * SUCH DAMAGE. 2853541Sshin * 2953541Sshin * $FreeBSD: head/sys/netinet6/nd6.h 53541 1999-11-22 02:45:11Z shin $ 3053541Sshin */ 3153541Sshin 3253541Sshin#ifndef _NETINET6_ND6_H_ 3353541Sshin#define _NETINET6_ND6_H_ 3453541Sshin 3553541Sshin#include <sys/queue.h> 3653541Sshin 3753541Sshinstruct llinfo_nd6 { 3853541Sshin struct llinfo_nd6 *ln_next; 3953541Sshin struct llinfo_nd6 *ln_prev; 4053541Sshin struct rtentry *ln_rt; 4153541Sshin struct mbuf *ln_hold; /* last packet until resolved/timeout */ 4253541Sshin long ln_asked; /* number of queries already sent for this addr */ 4353541Sshin u_long ln_expire; /* lifetime for NDP state transition */ 4453541Sshin short ln_state; /* reachability state */ 4553541Sshin short ln_router; /* 2^0: ND6 router bit */ 4653541Sshin}; 4753541Sshin 4853541Sshin#define ND6_LLINFO_NOSTATE -2 4953541Sshin#define ND6_LLINFO_WAITDELETE -1 5053541Sshin#define ND6_LLINFO_INCOMPLETE 0 5153541Sshin#define ND6_LLINFO_REACHABLE 1 5253541Sshin#define ND6_LLINFO_STALE 2 5353541Sshin#define ND6_LLINFO_DELAY 3 5453541Sshin#define ND6_LLINFO_PROBE 4 5553541Sshin 5653541Sshinstruct nd_ifinfo { 5753541Sshin u_int32_t linkmtu; /* LinkMTU */ 5853541Sshin u_int32_t maxmtu; /* Upper bound of LinkMTU */ 5953541Sshin u_int32_t basereachable; /* BaseReachableTime */ 6053541Sshin u_int32_t reachable; /* Reachable Time */ 6153541Sshin u_int32_t retrans; /* Retrans Timer */ 6253541Sshin int recalctm; /* BaseReacable re-calculation timer */ 6353541Sshin u_int8_t chlim; /* CurHopLimit */ 6453541Sshin u_int8_t receivedra; 6553541Sshin}; 6653541Sshin 6753541Sshinstruct in6_nbrinfo { 6853541Sshin char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ 6953541Sshin struct in6_addr addr; /* IPv6 address of the neighbor */ 7053541Sshin long asked; /* number of queries already sent for this addr */ 7153541Sshin int isrouter; /* if it acts as a router */ 7253541Sshin int state; /* reachability state */ 7353541Sshin int expire; /* lifetime for NDP state transition */ 7453541Sshin}; 7553541Sshin 7653541Sshin#define DRLSTSIZ 10 7753541Sshin#define PRLSTSIZ 10 7853541Sshinstruct in6_drlist { 7953541Sshin char ifname[IFNAMSIZ]; 8053541Sshin struct { 8153541Sshin struct in6_addr rtaddr; 8253541Sshin u_char flags; 8353541Sshin u_short rtlifetime; 8453541Sshin u_long expire; 8553541Sshin u_short if_index; 8653541Sshin } defrouter[DRLSTSIZ]; 8753541Sshin}; 8853541Sshin 8953541Sshinstruct in6_prlist { 9053541Sshin char ifname[IFNAMSIZ]; 9153541Sshin struct { 9253541Sshin struct in6_addr prefix; 9353541Sshin struct prf_ra raflags; 9453541Sshin u_char prefixlen; 9553541Sshin u_long vltime; 9653541Sshin u_long pltime; 9753541Sshin u_long expire; 9853541Sshin u_short if_index; 9953541Sshin u_short advrtrs; /* number of advertisement routers */ 10053541Sshin struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ 10153541Sshin } prefix[PRLSTSIZ]; 10253541Sshin}; 10353541Sshin 10453541Sshinstruct in6_ndireq { 10553541Sshin char ifname[IFNAMSIZ]; 10653541Sshin struct nd_ifinfo ndi; 10753541Sshin}; 10853541Sshin 10953541Sshin/* protocol constants */ 11053541Sshin#define MAX_RTR_SOLICITATION_DELAY 1 /*1sec*/ 11153541Sshin#define RTR_SOLICITATION_INTERVAL 4 /*4sec*/ 11253541Sshin#define MAX_RTR_SOLICITATIONS 3 11353541Sshin 11453541Sshin#define ND6_INFINITE_LIFETIME 0xffffffff 11553541Sshin 11653541Sshin#ifdef _KERNEL 11753541Sshin/* node constants */ 11853541Sshin#define MAX_REACHABLE_TIME 3600000 /* msec */ 11953541Sshin#define REACHABLE_TIME 30000 /* msec */ 12053541Sshin#define RETRANS_TIMER 1000 /* msec */ 12153541Sshin#define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 12253541Sshin#define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 12353541Sshin#define ND_COMPUTE_RTIME(x) \ 12453541Sshin (((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \ 12553541Sshin ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 12653541Sshin 12753541Sshinstruct nd_defrouter { 12853541Sshin LIST_ENTRY(nd_defrouter) dr_entry; 12953541Sshin#define dr_next dr_entry.le_next 13053541Sshin struct in6_addr rtaddr; 13153541Sshin u_char flags; 13253541Sshin u_short rtlifetime; 13353541Sshin u_long expire; 13453541Sshin struct ifnet *ifp; 13553541Sshin}; 13653541Sshin 13753541Sshinstruct nd_prefix { 13853541Sshin struct ifnet *ndpr_ifp; 13953541Sshin LIST_ENTRY(nd_prefix) ndpr_entry; 14053541Sshin struct sockaddr_in6 ndpr_prefix; /* prefix */ 14153541Sshin struct in6_addr ndpr_mask; /* netmask derived from the prefix */ 14253541Sshin struct in6_addr ndpr_addr; /* address that is derived from the prefix */ 14353541Sshin u_int32_t ndpr_vltime; /* advertised valid lifetime */ 14453541Sshin u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 14553541Sshin time_t ndpr_expire; /* expiration time of the prefix */ 14653541Sshin time_t ndpr_preferred; /* preferred time of the prefix */ 14753541Sshin struct prf_ra ndpr_flags; 14853541Sshin /* list of routers that advertise the prefix: */ 14953541Sshin LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs; 15053541Sshin u_char ndpr_plen; 15153541Sshin struct ndpr_stateflags { 15253541Sshin /* if this prefix can be regarded as on-link */ 15353541Sshin u_char onlink : 1; 15453541Sshin } ndpr_stateflags; 15553541Sshin}; 15653541Sshin 15753541Sshin#define ndpr_next ndpr_entry.le_next 15853541Sshin 15953541Sshin#define ndpr_raf ndpr_flags 16053541Sshin#define ndpr_raf_onlink ndpr_flags.onlink 16153541Sshin#define ndpr_raf_auto ndpr_flags.autonomous 16253541Sshin 16353541Sshin#define ndpr_statef_onlink ndpr_stateflags.onlink 16453541Sshin#define ndpr_statef_addmark ndpr_stateflags.addmark 16553541Sshin 16653541Sshin/* 16753541Sshin * We keep expired prefix for certain amount of time, for validation purposes. 16853541Sshin * 1800s = MaxRtrAdvInterval 16953541Sshin */ 17053541Sshin#define NDPR_KEEP_EXPIRED (1800 * 2) 17153541Sshin 17253541Sshin/* 17353541Sshin * Message format for use in obtaining information about prefixes 17453541Sshin * from inet6 sysctl function 17553541Sshin */ 17653541Sshinstruct inet6_ndpr_msghdr { 17753541Sshin u_short inpm_msglen; /* to skip over non-understood messages */ 17853541Sshin u_char inpm_version; /* future binary compatability */ 17953541Sshin u_char inpm_type; /* message type */ 18053541Sshin struct in6_addr inpm_prefix; 18153541Sshin u_long prm_vltim; 18253541Sshin u_long prm_pltime; 18353541Sshin u_long prm_expire; 18453541Sshin u_long prm_preferred; 18553541Sshin struct in6_prflags prm_flags; 18653541Sshin u_short prm_index; /* index for associated ifp */ 18753541Sshin u_char prm_plen; /* length of prefix in bits */ 18853541Sshin}; 18953541Sshin 19053541Sshin#define prm_raf_onlink prm_flags.prf_ra.onlink 19153541Sshin#define prm_raf_auto prm_flags.prf_ra.autonomous 19253541Sshin 19353541Sshin#define prm_statef_onlink prm_flags.prf_state.onlink 19453541Sshin 19553541Sshin#define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid 19653541Sshin#define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd 19753541Sshin 19853541Sshin#define ifpr2ndpr(ifpr) ((struct nd_prefix *)(ifpr)) 19953541Sshin#define ndpr2ifpr(ndpr) ((struct ifprefix *)(ndpr)) 20053541Sshin 20153541Sshinstruct nd_pfxrouter { 20253541Sshin LIST_ENTRY(nd_pfxrouter) pfr_entry; 20353541Sshin#define pfr_next pfr_entry.le_next 20453541Sshin struct nd_defrouter *router; 20553541Sshin}; 20653541Sshin 20753541SshinLIST_HEAD(nd_drhead, nd_defrouter); 20853541SshinLIST_HEAD(nd_prhead, nd_prefix); 20953541Sshin 21053541Sshin/* nd6.c */ 21153541Sshinextern int nd6_prune; 21253541Sshinextern int nd6_delay; 21353541Sshinextern int nd6_umaxtries; 21453541Sshinextern int nd6_mmaxtries; 21553541Sshinextern int nd6_useloopback; 21653541Sshinextern int nd6_proxyall; 21753541Sshinextern struct llinfo_nd6 llinfo_nd6; 21853541Sshinextern struct nd_ifinfo *nd_ifinfo; 21953541Sshinextern struct nd_drhead nd_defrouter; 22053541Sshinextern struct nd_prhead nd_prefix; 22153541Sshin 22253541Sshinunion nd_opts { 22353541Sshin struct nd_opt_hdr *nd_opt_array[9]; 22453541Sshin struct { 22553541Sshin struct nd_opt_hdr *zero; 22653541Sshin struct nd_opt_hdr *src_lladdr; 22753541Sshin struct nd_opt_hdr *tgt_lladdr; 22853541Sshin struct nd_opt_prefix_info *pi_beg;/* multiple opts, start */ 22953541Sshin struct nd_opt_rd_hdr *rh; 23053541Sshin struct nd_opt_mtu *mtu; 23153541Sshin struct nd_opt_hdr *search; /* multiple opts */ 23253541Sshin struct nd_opt_hdr *last; /* multiple opts */ 23353541Sshin int done; 23453541Sshin struct nd_opt_prefix_info *pi_end;/* multiple opts, end */ 23553541Sshin } nd_opt_each; 23653541Sshin}; 23753541Sshin#define nd_opts_src_lladdr nd_opt_each.src_lladdr 23853541Sshin#define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr 23953541Sshin#define nd_opts_pi nd_opt_each.pi_beg 24053541Sshin#define nd_opts_pi_end nd_opt_each.pi_end 24153541Sshin#define nd_opts_rh nd_opt_each.rh 24253541Sshin#define nd_opts_mtu nd_opt_each.mtu 24353541Sshin#define nd_opts_search nd_opt_each.search 24453541Sshin#define nd_opts_last nd_opt_each.last 24553541Sshin#define nd_opts_done nd_opt_each.done 24653541Sshin 24753541Sshin/* XXX: need nd6_var.h?? */ 24853541Sshin/* nd6.c */ 24953541Sshinvoid nd6_init __P((void)); 25053541Sshinvoid nd6_ifattach __P((struct ifnet *)); 25153541Sshinint nd6_is_addr_neighbor __P((struct in6_addr *, struct ifnet *)); 25253541Sshinvoid nd6_option_init __P((void *, int, union nd_opts *)); 25353541Sshinstruct nd_opt_hdr *nd6_option __P((union nd_opts *)); 25453541Sshinint nd6_options __P((union nd_opts *)); 25553541Sshinstruct rtentry *nd6_lookup __P((struct in6_addr *, int, struct ifnet *)); 25653541Sshinvoid nd6_setmtu __P((struct ifnet *)); 25753541Sshinvoid nd6_timer __P((void *)); 25853541Sshinvoid nd6_free __P((struct rtentry *)); 25953541Sshinvoid nd6_nud_hint __P((struct rtentry *, struct in6_addr *)); 26053541Sshinint nd6_resolve __P((struct ifnet *, struct rtentry *, 26153541Sshin struct mbuf *, struct sockaddr *, u_char *)); 26253541Sshinvoid nd6_rtrequest __P((int, struct rtentry *, struct sockaddr *)); 26353541Sshinvoid nd6_p2p_rtrequest __P((int, struct rtentry *, struct sockaddr *)); 26453541Sshinint nd6_ioctl __P((u_long, caddr_t, struct ifnet *)); 26553541Sshinstruct rtentry *nd6_cache_lladdr __P((struct ifnet *, struct in6_addr *, 26653541Sshin char *, int, int, int)); 26753541Sshin/* for test */ 26853541Sshinint nd6_output __P((struct ifnet *, struct mbuf *, struct sockaddr_in6 *, 26953541Sshin struct rtentry *)); 27053541Sshinint nd6_storelladdr __P((struct ifnet *, struct rtentry *, struct mbuf *, 27153541Sshin struct sockaddr *, u_char *)); 27253541Sshin 27353541Sshin/* nd6_nbr.c */ 27453541Sshinvoid nd6_na_input __P((struct mbuf *, int, int)); 27553541Sshinvoid nd6_na_output __P((struct ifnet *, struct in6_addr *, 27653541Sshin struct in6_addr *, u_long, int)); 27753541Sshinvoid nd6_ns_input __P((struct mbuf *, int, int)); 27853541Sshinvoid nd6_ns_output __P((struct ifnet *, struct in6_addr *, 27953541Sshin struct in6_addr *, struct llinfo_nd6 *, int)); 28053541Sshincaddr_t nd6_ifptomac __P((struct ifnet *)); 28153541Sshinvoid nd6_dad_start __P((struct ifaddr *, int *)); 28253541Sshinvoid nd6_dad_duplicated __P((struct ifaddr *)); 28353541Sshin 28453541Sshin/* nd6_rtr.c */ 28553541Sshinvoid nd6_rs_input __P((struct mbuf *, int, int)); 28653541Sshinvoid nd6_ra_input __P((struct mbuf *, int, int)); 28753541Sshinvoid prelist_del __P((struct nd_prefix *)); 28853541Sshinvoid defrouter_addreq __P((struct nd_defrouter *)); 28953541Sshinvoid defrouter_delreq __P((struct nd_defrouter *, int)); 29053541Sshinvoid defrtrlist_del __P((struct nd_defrouter *)); 29153541Sshinvoid prelist_remove __P((struct nd_prefix *)); 29253541Sshinint prelist_update __P((struct nd_prefix *, struct nd_defrouter *, 29353541Sshin struct mbuf *)); 29453541Sshinstruct nd_defrouter *defrouter_lookup __P((struct in6_addr *, 29553541Sshin struct ifnet *)); 29653541Sshinint in6_ifdel __P((struct ifnet *, struct in6_addr *)); 29753541Sshinint in6_init_prefix_ltimes __P((struct nd_prefix *ndpr)); 29853541Sshinvoid rt6_flush __P((struct in6_addr *, struct ifnet *)); 29953541Sshin 30053541Sshin#endif /* _KERNEL */ 30153541Sshin 30253541Sshin#endif /* _NETINET6_ND6_H_ */ 303