home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / netinet6 / nd6.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  11.7 KB  |  351 lines

  1. /*    $KAME: nd6.h,v 1.18 2000/03/16 11:58:32 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. /* see net/route.h, or net/if_inarp.h */
  36. #ifndef RTF_ANNOUNCE
  37. #define RTF_ANNOUNCE    RTF_PROTO2
  38. #endif
  39.  
  40. #include <sys/queue.h>
  41.  
  42. struct    llinfo_nd6 {
  43.     struct    llinfo_nd6 *ln_next;
  44.     struct    llinfo_nd6 *ln_prev;
  45.     struct    rtentry *ln_rt;
  46.     struct    mbuf *ln_hold;    /* last packet until resolved/timeout */
  47.     long    ln_asked;    /* number of queries already sent for this addr */
  48.     u_long    ln_expire;    /* lifetime for NDP state transition */
  49.     short    ln_state;    /* reachability state */
  50.     short    ln_router;    /* 2^0: ND6 router bit */
  51. };
  52.  
  53. #define ND6_LLINFO_NOSTATE    -2
  54. #define ND6_LLINFO_WAITDELETE    -1
  55. #define ND6_LLINFO_INCOMPLETE    0
  56. #define ND6_LLINFO_REACHABLE    1
  57. #define ND6_LLINFO_STALE    2
  58. #define ND6_LLINFO_DELAY    3
  59. #define ND6_LLINFO_PROBE    4
  60.  
  61. #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
  62.  
  63. struct nd_ifinfo {
  64.     u_int32_t linkmtu;        /* LinkMTU */
  65.     u_int32_t maxmtu;        /* Upper bound of LinkMTU */
  66.     u_int32_t basereachable;    /* BaseReachableTime */
  67.     u_int32_t reachable;        /* Reachable Time */
  68.     u_int32_t retrans;        /* Retrans Timer */
  69.     u_int32_t flags;        /* Flags */
  70.     int recalctm;            /* BaseReacable re-calculation timer */
  71.     u_int8_t chlim;            /* CurHopLimit */
  72.     u_int8_t receivedra;
  73. };
  74.  
  75. #define ND6_IFF_PERFORMNUD    0x1
  76.  
  77. struct in6_nbrinfo {
  78.     char ifname[IFNAMSIZ];    /* if name, e.g. "en0" */
  79.     struct in6_addr addr;    /* IPv6 address of the neighbor */
  80.     long    asked;        /* number of queries already sent for this addr */
  81.     int    isrouter;    /* if it acts as a router */
  82.     int    state;        /* reachability state */
  83.     int    expire;        /* lifetime for NDP state transition */
  84. };
  85.  
  86. #define DRLSTSIZ 10
  87. #define PRLSTSIZ 10
  88. struct    in6_drlist {
  89.     char ifname[IFNAMSIZ];
  90.     struct {
  91.         struct    in6_addr rtaddr;
  92.         u_char    flags;
  93.         u_short    rtlifetime;
  94.         u_long    expire;
  95.         u_short if_index;
  96.     } defrouter[DRLSTSIZ];
  97. };
  98.  
  99. struct    in6_prlist {
  100.     char ifname[IFNAMSIZ];
  101.     struct {
  102.         struct    in6_addr prefix;
  103.         struct prf_ra raflags;
  104.         u_char    prefixlen;
  105.         u_char    origin;
  106.         u_long    vltime;
  107.         u_long    pltime;
  108.         u_long    expire;
  109.         u_short if_index;
  110.         u_short advrtrs; /* number of advertisement routers */
  111.         struct    in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */
  112.     } prefix[PRLSTSIZ];
  113. };
  114.  
  115. struct    in6_ndireq {
  116.     char ifname[IFNAMSIZ];
  117.     struct nd_ifinfo ndi;
  118. };
  119.  
  120. struct    in6_ndifreq {
  121.     char ifname[IFNAMSIZ];
  122.     u_long ifindex;
  123. };
  124.  
  125.  
  126. /* protocol constants */
  127. #define MAX_RTR_SOLICITATION_DELAY    1    /*1sec*/
  128. #define RTR_SOLICITATION_INTERVAL    4    /*4sec*/
  129. #define MAX_RTR_SOLICITATIONS        3
  130.  
  131. #define ND6_INFINITE_LIFETIME        0xffffffff
  132.  
  133. #if KERNEL
  134. /* node constants */
  135. #define MAX_REACHABLE_TIME        3600000    /* msec */
  136. #define REACHABLE_TIME            30000    /* msec */
  137. #define RETRANS_TIMER            1000    /* msec */
  138. #define MIN_RANDOM_FACTOR        512    /* 1024 * 0.5 */
  139. #define MAX_RANDOM_FACTOR        1536    /* 1024 * 1.5 */
  140. #ifndef __OpenBSD__
  141. #define ND_COMPUTE_RTIME(x) \
  142.         (((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \
  143.         ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
  144. #else
  145. #define ND_COMPUTE_RTIME(x) \
  146.         (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \
  147.         ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
  148. #endif
  149.  
  150. TAILQ_HEAD(nd_drhead, nd_defrouter);
  151. struct    nd_defrouter {
  152.     TAILQ_ENTRY(nd_defrouter) dr_entry;
  153.     struct    in6_addr rtaddr;
  154.     u_char    flags;
  155.     u_short    rtlifetime;
  156.     u_long    expire;
  157.     u_long    advint;        /* Mobile IPv6 addition (milliseconds) */
  158.     u_long    advint_expire;    /* Mobile IPv6 addition */
  159.     int    advints_lost;    /* Mobile IPv6 addition */
  160.     struct  ifnet *ifp;
  161. };
  162.  
  163. struct nd_prefix {
  164.     struct ifnet *ndpr_ifp;
  165.     LIST_ENTRY(nd_prefix) ndpr_entry;
  166.     struct sockaddr_in6 ndpr_prefix;    /* prefix */
  167.     struct in6_addr ndpr_mask; /* netmask derived from the prefix */
  168.     struct in6_addr ndpr_addr; /* address that is derived from the prefix */
  169.     u_int32_t ndpr_vltime;    /* advertised valid lifetime */
  170.     u_int32_t ndpr_pltime;    /* advertised preferred lifetime */
  171.     time_t ndpr_expire;    /* expiration time of the prefix */
  172.     time_t ndpr_preferred;    /* preferred time of the prefix */
  173.     struct prf_ra ndpr_flags;
  174.     /* list of routers that advertise the prefix: */
  175.     LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
  176.     u_char    ndpr_plen;
  177.     struct    ndpr_stateflags {
  178.         /* if this prefix can be regarded as on-link */
  179.         u_char onlink : 1;
  180.     } ndpr_stateflags;
  181. };
  182.  
  183. #define ndpr_next        ndpr_entry.le_next
  184.  
  185. #define ndpr_raf        ndpr_flags
  186. #define ndpr_raf_onlink        ndpr_flags.onlink
  187. #define ndpr_raf_auto        ndpr_flags.autonomous
  188.  
  189. #define ndpr_statef_onlink    ndpr_stateflags.onlink
  190. #define ndpr_statef_addmark    ndpr_stateflags.addmark
  191.  
  192. /*
  193.  * We keep expired prefix for certain amount of time, for validation purposes.
  194.  * 1800s = MaxRtrAdvInterval
  195.  */
  196. #define NDPR_KEEP_EXPIRED    (1800 * 2)
  197.  
  198. /*
  199.  * Message format for use in obtaining information about prefixes
  200.  * from inet6 sysctl function
  201.  */
  202. struct inet6_ndpr_msghdr {
  203.     u_short    inpm_msglen;    /* to skip over non-understood messages */
  204.     u_char    inpm_version;    /* future binary compatability */
  205.     u_char    inpm_type;    /* message type */
  206.     struct in6_addr inpm_prefix;
  207.     u_long    prm_vltim;
  208.     u_long    prm_pltime;
  209.     u_long    prm_expire;
  210.     u_long    prm_preferred;
  211.     struct in6_prflags prm_flags;
  212.     u_short    prm_index;    /* index for associated ifp */
  213.     u_char    prm_plen;    /* length of prefix in bits */
  214. };
  215.  
  216. #define prm_raf_onlink        prm_flags.prf_ra.onlink
  217. #define prm_raf_auto        prm_flags.prf_ra.autonomous
  218.  
  219. #define prm_statef_onlink    prm_flags.prf_state.onlink
  220.  
  221. #define prm_rrf_decrvalid    prm_flags.prf_rr.decrvalid
  222. #define prm_rrf_decrprefd    prm_flags.prf_rr.decrprefd
  223.  
  224. #define ifpr2ndpr(ifpr)    ((struct nd_prefix *)(ifpr))
  225. #define ndpr2ifpr(ndpr)    ((struct ifprefix *)(ndpr))
  226.  
  227. struct nd_pfxrouter {
  228.     LIST_ENTRY(nd_pfxrouter) pfr_entry;
  229. #define pfr_next pfr_entry.le_next
  230.     struct nd_defrouter *router;
  231. };
  232.  
  233. LIST_HEAD(nd_prhead, nd_prefix);
  234.  
  235. /* nd6.c */
  236. extern int nd6_prune;
  237. extern int nd6_delay;
  238. extern int nd6_umaxtries;
  239. extern int nd6_mmaxtries;
  240. extern int nd6_useloopback;
  241. extern struct llinfo_nd6 llinfo_nd6;
  242. extern struct nd_ifinfo *nd_ifinfo;
  243. extern struct nd_drhead nd_defrouter;
  244. extern struct nd_prhead nd_prefix;
  245.  
  246. /* nd6_rtr.c */
  247. extern struct ifnet *nd6_defifp;  /* XXXYYY */
  248. extern int nd6_defifindex;
  249.  
  250. union nd_opts {
  251.     struct nd_opt_hdr *nd_opt_array[9];    /*max = home agent info*/
  252.     struct {
  253.         struct nd_opt_hdr *zero;
  254.         struct nd_opt_hdr *src_lladdr;
  255.         struct nd_opt_hdr *tgt_lladdr;
  256.         struct nd_opt_prefix_info *pi_beg;/* multiple opts, start */
  257.         struct nd_opt_rd_hdr *rh;
  258.         struct nd_opt_mtu *mtu;
  259.         struct nd_opt_hdr *six;
  260.         struct nd_opt_advint *adv;
  261.         struct nd_opt_hai *hai;
  262.         struct nd_opt_hdr *search;    /* multiple opts */
  263.         struct nd_opt_hdr *last;    /* multiple opts */
  264.         int done;
  265.         struct nd_opt_prefix_info *pi_end;/* multiple opts, end */
  266.     } nd_opt_each;
  267. };
  268. #define nd_opts_src_lladdr    nd_opt_each.src_lladdr
  269. #define nd_opts_tgt_lladdr    nd_opt_each.tgt_lladdr
  270. #define nd_opts_pi        nd_opt_each.pi_beg
  271. #define nd_opts_pi_end        nd_opt_each.pi_end
  272. #define nd_opts_rh        nd_opt_each.rh
  273. #define nd_opts_mtu        nd_opt_each.mtu
  274. #define nd_opts_adv        nd_opt_each.adv
  275. #define nd_opts_hai        nd_opt_each.hai
  276. #define nd_opts_search        nd_opt_each.search
  277. #define nd_opts_last        nd_opt_each.last
  278. #define nd_opts_done        nd_opt_each.done
  279.  
  280. /* XXX: need nd6_var.h?? */
  281. /* nd6.c */
  282. void nd6_init __P((void));
  283. void nd6_ifattach __P((struct ifnet *));
  284. int nd6_is_addr_neighbor __P((struct in6_addr *, struct ifnet *));
  285. void nd6_option_init __P((void *, int, union nd_opts *));
  286. struct nd_opt_hdr *nd6_option __P((union nd_opts *));
  287. int nd6_options __P((union nd_opts *));
  288. struct    rtentry *nd6_lookup __P((struct in6_addr *, int, struct ifnet *));
  289. void nd6_setmtu __P((struct ifnet *));
  290. void nd6_timer __P((void *));
  291. void nd6_timer_funneled __P((void *));
  292. void nd6_purge __P((struct ifnet *));
  293. void nd6_free __P((struct rtentry *));
  294. void nd6_nud_hint __P((struct rtentry *, struct in6_addr *));
  295. int nd6_resolve __P((struct ifnet *, struct rtentry *,
  296.              struct mbuf *, struct sockaddr *, u_char *));
  297. #if defined(__bsdi__) && _BSDI_VERSION >= 199802
  298. void nd6_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
  299. void nd6_p2p_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
  300. #else
  301. void nd6_rtrequest __P((int, struct rtentry *, struct sockaddr *));
  302. void nd6_p2p_rtrequest __P((int, struct rtentry *, struct sockaddr *));
  303. #endif
  304. int nd6_ioctl __P((u_long, caddr_t, struct ifnet *));
  305. struct rtentry *nd6_cache_lladdr __P((struct ifnet *, struct in6_addr *,
  306.     char *, int, int, int));
  307. /* for test */
  308. int nd6_output __P((struct ifnet *, struct mbuf *, struct sockaddr_in6 *,
  309.             struct rtentry *));
  310. int nd6_storelladdr __P((struct ifnet *, struct rtentry *, struct mbuf *,
  311.              struct sockaddr *, u_char *));
  312.  
  313. /* nd6_nbr.c */
  314. void nd6_na_input __P((struct mbuf *, int, int));
  315. void nd6_na_output __P((struct ifnet *, struct in6_addr *,
  316.              struct in6_addr *, u_long, int, struct sockaddr *));
  317. void nd6_ns_input __P((struct mbuf *, int, int));
  318. void nd6_ns_output __P((struct ifnet *, struct in6_addr *,
  319.             struct in6_addr *, struct llinfo_nd6 *, int));
  320. caddr_t nd6_ifptomac __P((struct ifnet *));
  321. void nd6_dad_start __P((struct ifaddr *, int *));
  322. void nd6_dad_duplicated __P((struct ifaddr *));
  323.  
  324. /* nd6_rtr.c */
  325. void nd6_rs_input __P((struct mbuf *, int, int));
  326. void nd6_ra_input __P((struct mbuf *, int, int));
  327. void prelist_del __P((struct nd_prefix *));
  328. void defrouter_addreq __P((struct nd_defrouter *));
  329. void defrouter_delreq __P((struct nd_defrouter *, int));
  330. void defrouter_select __P((void));
  331. void defrtrlist_del __P((struct nd_defrouter *));
  332. void prelist_remove __P((struct nd_prefix *));
  333. int prelist_update __P((struct nd_prefix *, struct nd_defrouter *,
  334.     struct mbuf *));
  335. struct nd_pfxrouter *find_pfxlist_reachable_router __P((struct nd_prefix *)); /* XXXYYY */
  336. void pfxlist_onlink_check __P((void));
  337. void defrouter_addifreq __P((struct ifnet *));           /* XXXYYY */
  338. struct nd_defrouter *defrouter_lookup __P((struct in6_addr *,
  339.                        struct ifnet *));
  340. struct nd_prefix *prefix_lookup __P((struct nd_prefix *));  /* XXXYYY */
  341. int in6_ifdel __P((struct ifnet *, struct in6_addr *));
  342. struct nd_pfxrouter *pfxrtr_lookup __P((struct nd_prefix *,
  343.                                         struct nd_defrouter *));  /* XXXYYY */
  344. int in6_init_prefix_ltimes __P((struct nd_prefix *ndpr));
  345. void rt6_flush __P((struct in6_addr *, struct ifnet *));
  346. int nd6_setdefaultiface __P((int));
  347.  
  348. #endif /* KERNEL */
  349.  
  350. #endif /* _NETINET6_ND6_H_ */
  351.