xref: /freebsd/sys/netlink/route/nexthop.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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  * NEXTHOP-related (RTM_<NEW|DEL|GET>NEXTHOP) message header and attributes.
30  */
31 
32 #ifndef _NETLINK_ROUTE_NEXTHOP_H_
33 #define _NETLINK_ROUTE_NEXTHOP_H_
34 
35 /* Base header for all of the relevant messages */
36 struct nhmsg {
37         unsigned char	nh_family;	/* transport family */
38 	unsigned char	nh_scope;	/* ignored on RX, filled by kernel */
39 	unsigned char	nh_protocol;	/* Routing protocol that installed nh */
40 	unsigned char	resvd;
41 	unsigned int	nh_flags;	/* RTNH_F_* flags from route.h */
42 };
43 
44 enum {
45 	NHA_UNSPEC,
46 	NHA_ID,		/* u32: nexthop userland index, auto-assigned if 0 */
47 	NHA_GROUP,	/* binary: array of struct nexthop_grp */
48 	NHA_GROUP_TYPE,	/* u16: set to NEXTHOP_GRP_TYPE */
49 	NHA_BLACKHOLE,	/* flag: nexthop used to blackhole packets */
50 	NHA_OIF,	/* u32: transmit ifindex */
51 	NHA_GATEWAY,	/* network: IPv4/IPv6 gateway addr */
52 	NHA_ENCAP_TYPE, /* not supported */
53 	NHA_ENCAP,	/* not supported */
54 	NHA_GROUPS,	/* flag: match nexthop groups */
55 	NHA_MASTER,	/* not supported */
56 	NHA_FDB,	/* not supported */
57 	NHA_RES_GROUP,	/* not supported */
58 	NHA_RES_BUCKET,	/* not supported */
59 	NHA_FREEBSD,	/* nested: FreeBSD-specific attributes */
60 	__NHA_MAX,
61 };
62 #define NHA_MAX	(__NHA_MAX - 1)
63 
64 enum {
65 	NHAF_UNSPEC,
66 	NHAF_KNHOPS,	/* flag: dump kernel nexthops */
67 	NHAF_KGOUPS,	/* flag: dump kernel nexthop groups */
68 	NHAF_TABLE,	/* u32: rtable id */
69 	NHAF_FAMILY,	/* u32: upper family */
70 	NHAF_KID,	/* u32: kernel nexthop index */
71 	NHAF_AIF,	/* u32: source interface address */
72 };
73 
74 /*
75  * Attributes that can be used as filters:
76  * NHA_ID (nexhop or group), NHA_OIF, NHA_GROUPS,
77  */
78 
79 /*
80  * NHA_GROUP: array of the following structures.
81  * If attribute is set, the only other valid attributes are
82  *  NHA_ID and NHA_GROUP_TYPE.
83  *  NHA_RES_GROUP and NHA_RES_BUCKET are not supported yet
84  */
85 struct nexthop_grp {
86 	uint32_t	id;		/* nexhop userland index */
87 	uint8_t		weight;         /* weight of this nexthop */
88 	uint8_t		resvd1;
89 	uint16_t	resvd2;
90 };
91 
92 /* NHA_GROUP_TYPE: u16 */
93 enum {
94 	NEXTHOP_GRP_TYPE_MPATH,		/* default nexthop group */
95 	NEXTHOP_GRP_TYPE_RES,		/* resilient nexthop group */
96 	__NEXTHOP_GRP_TYPE_MAX,
97 };
98 #define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
99 
100 
101 /* NHA_RES_GROUP */
102 enum {
103 	NHA_RES_GROUP_UNSPEC,
104 	NHA_RES_GROUP_PAD = NHA_RES_GROUP_UNSPEC,
105 	NHA_RES_GROUP_BUCKETS,
106 	NHA_RES_GROUP_IDLE_TIMER,
107 	NHA_RES_GROUP_UNBALANCED_TIMER,
108 	NHA_RES_GROUP_UNBALANCED_TIME,
109 	__NHA_RES_GROUP_MAX,
110 };
111 #define NHA_RES_GROUP_MAX	(__NHA_RES_GROUP_MAX - 1)
112 
113 #endif
114