2020-08-20 14:01:02 +03:00
|
|
|
/* $NetBSD: nd6.h,v 1.90 2020/08/20 11:01:02 roy Exp $ */
|
2002-06-09 01:22:29 +04:00
|
|
|
/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */
|
1999-07-04 01:24:45 +04:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2000-04-16 19:00:56 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2000-04-16 19:00:56 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETINET6_ND6_H_
|
|
|
|
#define _NETINET6_ND6_H_
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2012-06-23 07:13:41 +04:00
|
|
|
#define ND6_LLINFO_PURGE -3
|
1999-06-28 10:36:47 +04:00
|
|
|
#define ND6_LLINFO_NOSTATE -2
|
2019-09-01 22:26:21 +03:00
|
|
|
#define ND6_LLINFO_WAITDELETE -1
|
1999-06-28 10:36:47 +04:00
|
|
|
#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
|
|
|
|
|
1999-12-13 18:17:17 +03:00
|
|
|
#define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
|
2006-03-06 02:47:08 +03:00
|
|
|
#define ND6_LLINFO_PERMANENT(n) (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE))
|
2002-05-29 11:53:39 +04:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
struct nd_ifinfo {
|
2020-06-12 14:04:44 +03:00
|
|
|
uint8_t chlim; /* CurHopLimit */
|
|
|
|
uint32_t basereachable; /* BaseReachableTime */
|
|
|
|
uint32_t retrans; /* Retrans Timer */
|
|
|
|
uint32_t flags; /* Flags */
|
|
|
|
};
|
|
|
|
#ifdef _KERNEL
|
|
|
|
struct nd_kifinfo {
|
|
|
|
uint8_t chlim; /* CurHopLimit */
|
|
|
|
uint32_t basereachable; /* BaseReachableTime */
|
|
|
|
uint32_t retrans; /* Retrans Timer */
|
|
|
|
uint32_t flags; /* Flags */
|
1999-12-13 18:17:17 +03:00
|
|
|
int recalctm; /* BaseReacable re-calculation timer */
|
2020-06-12 14:04:44 +03:00
|
|
|
uint32_t reachable; /* Reachable Time */
|
1999-06-28 10:36:47 +04:00
|
|
|
};
|
2020-06-12 14:04:44 +03:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2009-11-06 23:41:22 +03:00
|
|
|
#define ND6_IFF_PERFORMNUD 0x01
|
2020-06-12 14:04:44 +03:00
|
|
|
/* 0x02 was ND6_IFF_ACCEPT_RTADV */
|
2009-11-06 23:41:22 +03:00
|
|
|
#define ND6_IFF_PREFER_SOURCE 0x04 /* XXX: not related to ND. */
|
|
|
|
#define ND6_IFF_IFDISABLED 0x08 /* IPv6 operation is disabled due to
|
|
|
|
* DAD failure. (XXX: not ND-specific)
|
|
|
|
*/
|
2020-06-12 14:04:44 +03:00
|
|
|
/* 0x10 was ND6_IFF_OVERRIDE_RTADV */
|
2014-06-05 20:06:49 +04:00
|
|
|
#define ND6_IFF_AUTO_LINKLOCAL 0x20
|
2009-11-06 23:41:22 +03:00
|
|
|
|
2002-05-29 11:53:39 +04:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#define ND_IFINFO(ifp) \
|
|
|
|
(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo)
|
|
|
|
#endif
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
struct in6_nbrinfo {
|
|
|
|
char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */
|
|
|
|
struct in6_addr addr; /* IPv6 address of the neighbor */
|
|
|
|
long asked; /* number of queries already sent for this addr */
|
|
|
|
int isrouter; /* if it acts as a router */
|
|
|
|
int state; /* reachability state */
|
|
|
|
int expire; /* lifetime for NDP state transition */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct in6_ndireq {
|
|
|
|
char ifname[IFNAMSIZ];
|
|
|
|
struct nd_ifinfo ndi;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* protocol constants */
|
2001-12-18 06:04:02 +03:00
|
|
|
#define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */
|
2009-01-15 21:20:48 +03:00
|
|
|
#define ND6_INFINITE_LIFETIME ((u_int32_t)~0)
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/* node constants */
|
|
|
|
#define MAX_REACHABLE_TIME 3600000 /* msec */
|
|
|
|
#define REACHABLE_TIME 30000 /* msec */
|
|
|
|
#define RETRANS_TIMER 1000 /* msec */
|
|
|
|
#define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */
|
|
|
|
#define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */
|
|
|
|
#define ND_COMPUTE_RTIME(x) \
|
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:
An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.
A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.
The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.
An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.
A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.
An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.
In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.
The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.
The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.
A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.
The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.
Manual pages for the new kernel interfaces are forthcoming.
2011-11-20 02:51:18 +04:00
|
|
|
(((MIN_RANDOM_FACTOR * (x >> 10)) + (cprng_fast32() & \
|
1999-06-28 10:36:47 +04:00
|
|
|
((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
|
|
|
|
|
2003-02-01 09:23:35 +03:00
|
|
|
#include <sys/mallocvar.h>
|
|
|
|
MALLOC_DECLARE(M_IP6NDP);
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/* nd6.c */
|
|
|
|
extern int nd6_prune;
|
|
|
|
extern int nd6_delay;
|
|
|
|
extern int nd6_umaxtries;
|
|
|
|
extern int nd6_mmaxtries;
|
|
|
|
extern int nd6_useloopback;
|
2000-07-06 16:36:18 +04:00
|
|
|
extern int nd6_maxnudhint;
|
2001-02-23 11:02:41 +03:00
|
|
|
extern int nd6_gctimer;
|
2001-02-07 11:59:47 +03:00
|
|
|
extern int nd6_debug;
|
|
|
|
|
2016-04-01 11:12:00 +03:00
|
|
|
#define nd6log(level, fmt, args...) \
|
|
|
|
do { if (nd6_debug) log(level, "%s: " fmt, __func__, ##args);} while (0)
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2016-12-19 10:51:34 +03:00
|
|
|
extern krwlock_t nd6_lock;
|
|
|
|
|
|
|
|
#define ND6_RLOCK() rw_enter(&nd6_lock, RW_READER)
|
|
|
|
#define ND6_WLOCK() rw_enter(&nd6_lock, RW_WRITER)
|
|
|
|
#define ND6_UNLOCK() rw_exit(&nd6_lock)
|
|
|
|
#define ND6_ASSERT_WLOCK() KASSERT(rw_write_held(&nd6_lock))
|
|
|
|
#define ND6_ASSERT_LOCK() KASSERT(rw_lock_held(&nd6_lock))
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
union nd_opts {
|
2018-03-06 13:57:00 +03:00
|
|
|
struct nd_opt_hdr *nd_opt_array[16]; /* max = ND_OPT_NONCE */
|
1999-06-28 10:36:47 +04:00
|
|
|
struct {
|
|
|
|
struct nd_opt_hdr *zero;
|
|
|
|
struct nd_opt_hdr *src_lladdr;
|
|
|
|
struct nd_opt_hdr *tgt_lladdr;
|
2002-05-29 11:53:39 +04:00
|
|
|
struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */
|
1999-06-28 10:36:47 +04:00
|
|
|
struct nd_opt_rd_hdr *rh;
|
|
|
|
struct nd_opt_mtu *mtu;
|
2018-03-06 13:57:00 +03:00
|
|
|
struct nd_opt_hdr *__res6;
|
|
|
|
struct nd_opt_hdr *__res7;
|
|
|
|
struct nd_opt_hdr *__res8;
|
|
|
|
struct nd_opt_hdr *__res9;
|
|
|
|
struct nd_opt_hdr *__res10;
|
|
|
|
struct nd_opt_hdr *__res11;
|
|
|
|
struct nd_opt_hdr *__res12;
|
|
|
|
struct nd_opt_hdr *__res13;
|
|
|
|
struct nd_opt_nonce *nonce;
|
|
|
|
struct nd_opt_hdr *__res15;
|
1999-06-28 10:36:47 +04:00
|
|
|
struct nd_opt_hdr *search; /* multiple opts */
|
|
|
|
struct nd_opt_hdr *last; /* multiple opts */
|
|
|
|
int done;
|
|
|
|
struct nd_opt_prefix_info *pi_end;/* multiple opts, 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
|
2018-03-06 13:57:00 +03:00
|
|
|
#define nd_opts_nonce nd_opt_each.nonce
|
1999-06-28 10:36:47 +04:00
|
|
|
#define nd_opts_search nd_opt_each.search
|
|
|
|
#define nd_opts_last nd_opt_each.last
|
|
|
|
#define nd_opts_done nd_opt_each.done
|
|
|
|
|
2015-11-25 09:21:26 +03:00
|
|
|
#include <net/if_llatbl.h>
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/* XXX: need nd6_var.h?? */
|
|
|
|
/* nd6.c */
|
2007-03-16 02:35:25 +03:00
|
|
|
void nd6_init(void);
|
2019-09-25 12:52:32 +03:00
|
|
|
void nd6_nbr_init(void);
|
2020-06-12 14:04:44 +03:00
|
|
|
struct nd_kifinfo *nd6_ifattach(struct ifnet *);
|
2015-02-23 22:15:59 +03:00
|
|
|
void nd6_ifdetach(struct ifnet *, struct in6_ifextra *);
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *);
|
2007-03-16 02:35:25 +03:00
|
|
|
void nd6_option_init(void *, int, union nd_opts *);
|
|
|
|
int nd6_options(union nd_opts *);
|
2016-04-04 10:37:07 +03:00
|
|
|
struct llentry *nd6_lookup(const struct in6_addr *, const struct ifnet *, bool);
|
|
|
|
struct llentry *nd6_create(const struct in6_addr *, const struct ifnet *);
|
2015-12-07 09:19:13 +03:00
|
|
|
void nd6_llinfo_settimer(struct llentry *, time_t);
|
2015-02-23 22:15:59 +03:00
|
|
|
void nd6_purge(struct ifnet *, struct in6_ifextra *);
|
2015-07-15 12:20:18 +03:00
|
|
|
void nd6_nud_hint(struct rtentry *);
|
2017-02-14 06:05:06 +03:00
|
|
|
int nd6_resolve(struct ifnet *, const struct rtentry *, struct mbuf *,
|
|
|
|
const struct sockaddr *, uint8_t *, size_t);
|
2008-10-24 21:07:33 +04:00
|
|
|
void nd6_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
|
2007-03-16 02:35:25 +03:00
|
|
|
int nd6_ioctl(u_long, void *, struct ifnet *);
|
2015-07-17 05:21:08 +03:00
|
|
|
void nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
|
2007-03-16 02:35:25 +03:00
|
|
|
char *, int, int, int);
|
|
|
|
int nd6_sysctl(int, void *, size_t *, void *, size_t);
|
|
|
|
int nd6_need_cache(struct ifnet *);
|
2016-04-04 10:37:07 +03:00
|
|
|
void nd6_llinfo_release_pkts(struct llentry *, struct ifnet *);
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/* nd6_nbr.c */
|
2007-03-16 02:35:25 +03:00
|
|
|
void nd6_na_input(struct mbuf *, int, int);
|
|
|
|
void nd6_na_output(struct ifnet *, const struct in6_addr *,
|
2007-08-07 08:35:42 +04:00
|
|
|
const struct in6_addr *, u_long, int, const struct sockaddr *);
|
2007-03-16 02:35:25 +03:00
|
|
|
void nd6_ns_input(struct mbuf *, int, int);
|
|
|
|
void nd6_ns_output(struct ifnet *, const struct in6_addr *,
|
2020-08-20 14:01:02 +03:00
|
|
|
const struct in6_addr *, const struct in6_addr *, const uint8_t *);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
const void *nd6_ifptomac(const struct ifnet *);
|
2007-03-16 02:35:25 +03:00
|
|
|
void nd6_dad_start(struct ifaddr *, int);
|
|
|
|
void nd6_dad_stop(struct ifaddr *);
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/* nd6_rtr.c */
|
2020-06-12 14:04:44 +03:00
|
|
|
void nd6_rtr_cache(struct mbuf *, int, int, int);
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
2005-12-11 02:31:41 +03:00
|
|
|
#endif /* !_NETINET6_ND6_H_ */
|