master
1/* $NetBSD: nd.h,v 1.3 2020/09/15 10:05:36 roy Exp $ */
2
3/*
4 * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Roy Marples.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef _NET_ND_H_
31#define _NET_ND_H_
32
33/* ND LLINFO states */
34#define ND_LLINFO_PURGE -3
35#define ND_LLINFO_NOSTATE -2
36#define ND_LLINFO_WAITDELETE -1
37#define ND_LLINFO_INCOMPLETE 0
38#define ND_LLINFO_REACHABLE 1
39#define ND_LLINFO_STALE 2
40#define ND_LLINFO_DELAY 3
41#define ND_LLINFO_PROBE 4
42#define ND_LLINFO_UNREACHABLE 5
43
44#ifdef _KERNEL
45#define ND_IS_LLINFO_PROBREACH(ln) \
46 ((ln)->ln_state > ND_LLINFO_INCOMPLETE)
47#define ND_IS_LLINFO_PERMANENT(ln) \
48 (((ln)->ln_expire == 0) && ((ln)->ln_state > ND_LLINFO_INCOMPLETE))
49
50/* ND timer types */
51#define ND_TIMER_IMMEDIATE 0
52#define ND_TIMER_TICK 1
53#define ND_TIMER_REACHABLE 2
54#define ND_TIMER_RETRANS 3
55#define ND_TIMER_RETRANS_BACKOFF 4
56#define ND_TIMER_EXPIRE 5
57#define ND_TIMER_DELAY 6
58#define ND_TIMER_GC 7
59
60/* node constants */
61#define MAX_REACHABLE_TIME 3600000 /* msec */
62#define REACHABLE_TIME 30000 /* msec */
63#define RETRANS_TIMER 1000 /* msec */
64#define MAX_RETRANS_TIMER 60000 /* msec */
65#define BACKOFF_MULTIPLE 3
66#define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */
67#define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */
68#define ND_COMPUTE_RTIME(x) \
69 ((MIN_RANDOM_FACTOR * (x >> 10)) + (cprng_fast32() & \
70 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10))))
71
72struct nd_domain {
73 int nd_family;
74 int nd_delay; /* delay first probe time in seconds */
75 int nd_mmaxtries; /* maximum multicast query */
76 int nd_umaxtries; /* maximum unicast query */
77 int nd_retransmultiple; /* retransmission multiplier for backoff */
78 int nd_maxretrans; /* maximum retransmission time in msec */
79 int nd_maxnudhint; /* max # of subsequent upper layer hints */
80 int nd_maxqueuelen; /* max # of packets in unresolved ND entries */
81 bool (*nd_nud_enabled)(struct ifnet *);
82 unsigned int (*nd_reachable)(struct ifnet *); /* msec */
83 unsigned int (*nd_retrans)(struct ifnet *); /* msec */
84 union l3addr *(*nd_holdsrc)(struct llentry *, union l3addr *);
85 void (*nd_output)(struct ifnet *, const union l3addr *,
86 const union l3addr *, const uint8_t *, const union l3addr *);
87 void (*nd_missed)(struct ifnet *, const union l3addr *,
88 int16_t, struct mbuf *);
89 void (*nd_free)(struct llentry *, int);
90};
91
92int nd_resolve(struct llentry *, const struct rtentry *, struct mbuf *,
93 uint8_t *, size_t);
94void nd_set_timer(struct llentry *, int);
95void nd_nud_hint(struct llentry *);
96
97void nd_attach_domain(struct nd_domain *);
98#endif /* !_KERNEL */
99#endif /* !_NET_ND_H_ */