xref: /freebsd/sys/netlink/route/neigh.h (revision 4ac8f4067096a9d4a00e41cd53bd5c4fa295fd15)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * Neighbors-related (RTM_<NEW|DEL|GET>NEIGH) message header and attributes.
30  */
31 
32 #ifndef _NETLINK_ROUTE_NEIGH_H_
33 #define _NETLINK_ROUTE_NEIGH_H_
34 
35 /* Base header for all of the relevant messages */
36 struct ndmsg {
37 	uint8_t		ndm_family;
38 	uint8_t		ndm_pad1;
39 	uint16_t	ndm_pad2;
40 	int32_t		ndm_ifindex;
41 	uint16_t	ndm_state;
42 	uint8_t		ndm_flags;
43 	uint8_t		ndm_type;
44 };
45 
46 /* Attributes */
47 enum {
48 	NDA_UNSPEC,
49 	NDA_DST,		/* binary: neigh l3 address */
50 	NDA_LLADDR,		/* binary: neigh link-level address */
51 	NDA_CACHEINFO,		/* binary, struct nda_cacheinfo */
52 	NDA_PROBES,		/* XXX */
53 	NDA_VLAN,		/* upper 802.1Q tag */
54 	NDA_PORT,		/* not supported */
55 	NDA_VNI,		/* not supported */
56 	NDA_IFINDEX,		/* interface index */
57 	NDA_MASTER,		/* not supported */
58 	NDA_LINK_NETNSID,	/* not supported */
59 	NDA_SRC_VNI,		/* not supported */
60 	NDA_PROTOCOL,		/* XXX */
61 	NDA_NH_ID,		/* not supported */
62 	NDA_FDB_EXT_ATTRS,	/* not supported */
63 	NDA_FLAGS_EXT,		/* u32: ndm_flags */
64 	NDA_NDM_STATE_MASK,	/* XXX */
65 	NDA_NDM_FLAGS_MASK,	/* XXX */
66 	__NDA_MAX
67 };
68 
69 #define	NDA_MAX	(__NDA_MAX - 1)
70 
71 
72 /* ndm_flags / NDA_FLAGS_EXT */
73 #define	NTF_USE			0x0001	/* XXX */
74 #define	NTF_SELF		0x0002	/* local station */
75 #define	NTF_MASTER		0x0004	/* XXX */
76 #define	NTF_PROXY		0x0008	/* proxy entry */
77 #define	NTF_EXT_LEARNED		0x0010	/* not used */
78 #define	NTF_OFFLOADED		0x0020	/* not used */
79 #define	NTF_STICKY		0x0040	/* permament entry */
80 #define	NTF_ROUTER		0x0080	/* dst indicated itself as a router */
81 /* start of NDA_FLAGS_EXT */
82 #define	NTF_EXT_MANAGED		0x0100	/* not used */
83 
84 /* ndm_state */
85 #define	NUD_INCOMPLETE		0x01	/* No lladdr, address resolution in progress */
86 #define	NUD_REACHABLE		0x02	/* reachable & recently resolved */
87 #define	NUD_STALE		0x04	/* has lladdr but it's stale */
88 #define	NUD_DELAY		0x08	/* has lladdr, is stale, probes delayed */
89 #define	NUD_PROBE		0x10	/* has lladdr, is stale, probes sent */
90 #define	NUD_FAILED		0x20	/* unused */
91 
92 /* Dummy states */
93 #define	NUD_NOARP		0x40	/* not used */
94 #define	NUD_PERMANENT		0x80	/* not flushed */
95 #define	NUD_NONE		0x00
96 
97 /* NDA_CACHEINFO */
98 struct nda_cacheinfo {
99 	uint32_t	ndm_confirmed;	/* seconds since ARP/ND was received from neigh */
100 	uint32_t	ndm_used;	/* seconds since last used (not provided) */
101 	uint32_t	ndm_updated;	/* seconds since state was updated last */
102 	uint32_t	ndm_refcnt;	/* number of references held */
103 };
104 
105 #endif
106