#ifndef _NETINET6_ND6_H_
#define _NETINET6_ND6_H_
#include <sys/appleapiopts.h>
#ifndef RTF_ANNOUNCE
#define RTF_ANNOUNCE RTF_PROTO2
#endif
#include <sys/queue.h>
#ifdef KERNEL_PRIVATE
struct llinfo_nd6 {
struct llinfo_nd6 *ln_next;
struct llinfo_nd6 *ln_prev;
struct rtentry *ln_rt;
struct mbuf *ln_hold;
long ln_asked;
u_long ln_expire;
short ln_state;
short ln_router;
int ln_byhint;
};
#endif
#define ND6_LLINFO_NOSTATE -2
#define ND6_LLINFO_INCOMPLETE 0
#define ND6_LLINFO_REACHABLE 1
#define ND6_LLINFO_STALE 2
#define ND6_LLINFO_DELAY 3
#define ND6_LLINFO_PROBE 4
#define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
struct nd_ifinfo {
u_int32_t linkmtu;
u_int32_t maxmtu;
u_int32_t basereachable;
u_int32_t reachable;
u_int32_t retrans;
u_int32_t flags;
int recalctm;
u_int8_t chlim;
u_int8_t receivedra;
u_int8_t randomseed0[8];
u_int8_t randomseed1[8];
u_int8_t randomid[8];
};
#define ND6_IFF_PERFORMNUD 0x1
struct in6_nbrinfo {
char ifname[IFNAMSIZ];
struct in6_addr addr;
long asked;
int isrouter;
int state;
int expire;
};
#define DRLSTSIZ 10
#define PRLSTSIZ 10
struct in6_drlist {
char ifname[IFNAMSIZ];
struct {
struct in6_addr rtaddr;
u_char flags;
u_short rtlifetime;
u_long expire;
u_short if_index;
} defrouter[DRLSTSIZ];
};
struct in6_defrouter {
struct sockaddr_in6 rtaddr;
u_char flags;
u_short rtlifetime;
u_long expire;
u_short if_index;
};
struct in6_prlist {
char ifname[IFNAMSIZ];
struct {
struct in6_addr prefix;
struct prf_ra raflags;
u_char prefixlen;
u_char origin;
u_long vltime;
u_long pltime;
u_long expire;
u_short if_index;
u_short advrtrs;
struct in6_addr advrtr[DRLSTSIZ];
} prefix[PRLSTSIZ];
};
struct in6_prefix {
struct sockaddr_in6 prefix;
struct prf_ra raflags;
u_char prefixlen;
u_char origin;
u_long vltime;
u_long pltime;
u_long expire;
u_int32_t flags;
int refcnt;
u_short if_index;
u_short advrtrs;
};
struct in6_ondireq {
char ifname[IFNAMSIZ];
struct {
u_int32_t linkmtu;
u_int32_t maxmtu;
u_int32_t basereachable;
u_int32_t reachable;
u_int32_t retrans;
u_int32_t flags;
int recalctm;
u_int8_t chlim;
u_int8_t receivedra;
} ndi;
};
struct in6_ndireq {
char ifname[IFNAMSIZ];
struct nd_ifinfo ndi;
};
struct in6_ndifreq {
char ifname[IFNAMSIZ];
u_long ifindex;
};
#define NDPRF_ONLINK 0x1
#define NDPRF_DETACHED 0x2
#define MAX_RTR_SOLICITATION_DELAY 1
#define RTR_SOLICITATION_INTERVAL 4
#define MAX_RTR_SOLICITATIONS 3
#define ND6_INFINITE_LIFETIME 0xffffffff
#ifdef KERNEL_PRIVATE
#define MAX_REACHABLE_TIME 3600000
#define REACHABLE_TIME 30000
#define RETRANS_TIMER 1000
#define MIN_RANDOM_FACTOR 512
#define MAX_RANDOM_FACTOR 1536
#define DEF_TEMP_VALID_LIFETIME 604800
#define DEF_TEMP_PREFERRED_LIFETIME 86400
#define TEMPADDR_REGEN_ADVANCE 5
#define MAX_TEMP_DESYNC_FACTOR 600
#define ND_COMPUTE_RTIME(x) \
(((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \
((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
TAILQ_HEAD(nd_drhead, nd_defrouter);
struct nd_defrouter {
TAILQ_ENTRY(nd_defrouter) dr_entry;
struct in6_addr rtaddr;
u_char flags;
u_short rtlifetime;
u_long expire;
u_long advint;
u_long advint_expire;
int advints_lost;
struct ifnet *ifp;
};
struct nd_prefix {
struct ifnet *ndpr_ifp;
LIST_ENTRY(nd_prefix) ndpr_entry;
struct sockaddr_in6 ndpr_prefix;
struct in6_addr ndpr_mask;
struct in6_addr ndpr_addr;
u_int32_t ndpr_vltime;
u_int32_t ndpr_pltime;
time_t ndpr_expire;
time_t ndpr_preferred;
struct prf_ra ndpr_flags;
u_int32_t ndpr_stateflags;
LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
u_char ndpr_plen;
int ndpr_refcnt;
};
#define ndpr_next ndpr_entry.le_next
#define ndpr_raf ndpr_flags
#define ndpr_raf_onlink ndpr_flags.onlink
#define ndpr_raf_auto ndpr_flags.autonomous
#define NDPR_KEEP_EXPIRED (1800 * 2)
struct inet6_ndpr_msghdr {
u_short inpm_msglen;
u_char inpm_version;
u_char inpm_type;
struct in6_addr inpm_prefix;
u_long prm_vltim;
u_long prm_pltime;
u_long prm_expire;
u_long prm_preferred;
struct in6_prflags prm_flags;
u_short prm_index;
u_char prm_plen;
};
#define prm_raf_onlink prm_flags.prf_ra.onlink
#define prm_raf_auto prm_flags.prf_ra.autonomous
#define prm_statef_onlink prm_flags.prf_state.onlink
#define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid
#define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd
#define ifpr2ndpr(ifpr) ((struct nd_prefix *)(ifpr))
#define ndpr2ifpr(ndpr) ((struct ifprefix *)(ndpr))
struct nd_pfxrouter {
LIST_ENTRY(nd_pfxrouter) pfr_entry;
#define pfr_next pfr_entry.le_next
struct nd_defrouter *router;
};
LIST_HEAD(nd_prhead, nd_prefix);
extern int nd6_prune;
extern int nd6_delay;
extern int nd6_umaxtries;
extern int nd6_mmaxtries;
extern int nd6_useloopback;
extern int nd6_maxnudhint;
extern int nd6_gctimer;
extern struct llinfo_nd6 llinfo_nd6;
extern struct nd_ifinfo *nd_ifinfo;
extern struct nd_drhead nd_defrouter;
extern struct nd_prhead nd_prefix;
extern int nd6_debug;
#define nd6log(x) do { if (nd6_debug) log x; } while (0)
extern struct callout nd6_timer_ch;
extern int nd6_defifindex;
extern int ip6_desync_factor;
extern u_int32_t ip6_temp_preferred_lifetime;
extern u_int32_t ip6_temp_valid_lifetime;
extern int ip6_temp_regen_advance;
union nd_opts {
struct nd_opt_hdr *nd_opt_array[9];
struct {
struct nd_opt_hdr *zero;
struct nd_opt_hdr *src_lladdr;
struct nd_opt_hdr *tgt_lladdr;
struct nd_opt_prefix_info *pi_beg;
struct nd_opt_rd_hdr *rh;
struct nd_opt_mtu *mtu;
struct nd_opt_hdr *six;
struct nd_opt_advint *adv;
struct nd_opt_hai *hai;
struct nd_opt_hdr *search;
struct nd_opt_hdr *last;
int done;
struct nd_opt_prefix_info *pi_end;
} nd_opt_each;
};
#define nd_opts_src_lladdr nd_opt_each.src_lladdr
#define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr
#define nd_opts_pi nd_opt_each.pi_beg
#define nd_opts_pi_end nd_opt_each.pi_end
#define nd_opts_rh nd_opt_each.rh
#define nd_opts_mtu nd_opt_each.mtu
#define nd_opts_adv nd_opt_each.adv
#define nd_opts_hai nd_opt_each.hai
#define nd_opts_search nd_opt_each.search
#define nd_opts_last nd_opt_each.last
#define nd_opts_done nd_opt_each.done
void nd6_init(void);
void nd6_ifattach(struct ifnet *);
int nd6_is_addr_neighbor(struct sockaddr_in6 *, struct ifnet *, int);
void nd6_option_init(void *, int, union nd_opts *);
struct nd_opt_hdr *nd6_option(union nd_opts *);
int nd6_options(union nd_opts *);
struct rtentry *nd6_lookup(struct in6_addr *, int, struct ifnet *, int);
void nd6_setmtu(struct ifnet *);
void nd6_timer(void *);
void nd6_purge(struct ifnet *);
struct llinfo_nd6 *nd6_free(struct rtentry *);
void nd6_nud_hint(struct rtentry *, struct in6_addr *, int);
int nd6_resolve(struct ifnet *, struct rtentry *,
struct mbuf *, struct sockaddr *, u_char *);
void nd6_rtrequest(int, struct rtentry *, struct sockaddr *);
int nd6_ioctl(u_long, caddr_t, struct ifnet *);
struct rtentry *nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
char *, int, int, int);
int nd6_output(struct ifnet *, struct ifnet *, struct mbuf *,
struct sockaddr_in6 *, struct rtentry *, int);
int nd6_storelladdr(struct ifnet *, struct rtentry *, struct mbuf *,
struct sockaddr *, u_char *);
int nd6_need_cache(struct ifnet *);
void nd6_na_input(struct mbuf *, int, int);
void nd6_na_output(struct ifnet *, const struct in6_addr *,
const struct in6_addr *, u_long, int, struct sockaddr *);
void nd6_ns_input(struct mbuf *, int, int);
void nd6_ns_output(struct ifnet *, const struct in6_addr *,
const struct in6_addr *, struct llinfo_nd6 *, int, int);
caddr_t nd6_ifptomac(struct ifnet *);
void nd6_dad_start(struct ifaddr *, int *);
void nd6_dad_stop(struct ifaddr *);
void nd6_dad_duplicated(struct ifaddr *);
void nd6_rs_input(struct mbuf *, int, int);
void nd6_ra_input(struct mbuf *, int, int);
void prelist_del(struct nd_prefix *);
void defrouter_addreq(struct nd_defrouter *);
void defrouter_delreq(struct nd_defrouter *, int);
void defrouter_select(void);
void defrtrlist_del(struct nd_defrouter *, int);
void prelist_remove(struct nd_prefix *, int);
int prelist_update(struct nd_prefix *, struct nd_defrouter *,
struct mbuf *);
int nd6_prelist_add(struct nd_prefix *, struct nd_defrouter *,
struct nd_prefix **);
int nd6_prefix_onlink(struct nd_prefix *, int, int);
int nd6_prefix_offlink(struct nd_prefix *);
void pfxlist_onlink_check(int);
struct nd_defrouter *defrouter_lookup(struct in6_addr *,
struct ifnet *);
struct nd_prefix *nd6_prefix_lookup(struct nd_prefix *);
int in6_init_prefix_ltimes(struct nd_prefix *ndpr);
void rt6_flush(struct in6_addr *, struct ifnet *);
int nd6_setdefaultiface(int);
int in6_tmpifadd(const struct in6_ifaddr *, int);
#endif
#ifdef KERNEL
errno_t nd6_lookup_ipv6(ifnet_t interface, const struct sockaddr_in6 *ip6_dest,
struct sockaddr_dl *ll_dest, size_t ll_dest_len, route_t hint,
mbuf_t packet);
#endif KERNEL
#endif