xref: /freebsd/sys/netlink/route/common.h (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
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  * Common defines for all parts of the NETLINK_ROUTE family
30  */
31 #ifndef _NETLINK_ROUTE_COMMON_H_
32 #define _NETLINK_ROUTE_COMMON_H_
33 
34 /* Defined NETLINK_ROUTE messages */
35 enum {
36 	NL_RTM_BASE		= 16,
37 	NL_RTM_NEWLINK		= 16, /* creates new interface */
38 	NL_RTM_DELLINK		= 17, /* deletes matching interface */
39 	NL_RTM_GETLINK		= 18, /* lists matching interfaces */
40 	NL_RTM_SETLINK		= 19, /* not supported */
41 	NL_RTM_NEWADDR		= 20, /* not supported */
42 	NL_RTM_DELADDR		= 21, /* not supported */
43 	NL_RTM_GETADDR		= 22, /* lists matching ifaddrs */
44 	NL_RTM_NEWROUTE		= 24, /* adds or changes a route */
45 	NL_RTM_DELROUTE		= 25, /* deletes matching route */
46 	NL_RTM_GETROUTE		= 26, /* lists matching routes */
47 	NL_RTM_NEWNEIGH		= 28, /* creates new arp/ndp entry */
48 	NL_RTM_DELNEIGH		= 29, /* deletes matching arp/ndp entry */
49 	NL_RTM_GETNEIGH		= 30, /* lists matching arp/ndp entry */
50 	NL_RTM_NEWRULE		= 32, /* not supported */
51 	NL_RTM_DELRULE		= 33, /* not supported */
52 	NL_RTM_GETRULE		= 34, /* not supported */
53 	NL_RTM_NEWQDISC		= 36, /* not supported */
54 	NL_RTM_DELQDISC		= 37, /* not supported */
55 	NL_RTM_GETQDISC		= 38, /* not supported */
56 	NL_RTM_NEWTCLASS	= 40, /* not supported */
57 	NL_RTM_DELTCLASS	= 41, /* not supported */
58 	NL_RTM_GETTCLASS	= 42, /* not supported */
59 	NL_RTM_NEWTFILTER	= 44, /* not supported */
60 	NL_RTM_DELTFILTER	= 45, /* not supported */
61 	NL_RTM_GETTFILTER	= 46, /* not supported */
62 	NL_RTM_NEWACTION	= 48, /* not supported */
63 	NL_RTM_DELACTION	= 49, /* not supported */
64 	NL_RTM_GETACTION	= 50, /* not supported */
65 	NL_RTM_NEWPREFIX	= 52, /* not supported */
66 	NL_RTM_GETMULTICAST	= 58, /* not supported */
67 	NL_RTM_GETANYCAST	= 62, /* not supported */
68 	NL_RTM_NEWNEIGHTBL	= 64, /* not supported */
69 	NL_RTM_GETNEIGHTBL	= 66, /* not supported */
70 	NL_RTM_SETNEIGHTBL	= 67, /* not supported */
71 	NL_RTM_NEWNDUSEROPT	= 68, /* not supported */
72 	NL_RTM_NEWADDRLABEL	= 72, /* not supported */
73 	NL_RTM_DELADDRLABEL	= 73, /* not supported */
74 	NL_RTM_GETADDRLABEL	= 74, /* not supported */
75 	NL_RTM_GETDCB		= 78, /* not supported */
76 	NL_RTM_SETDCB		= 79, /* not supported */
77 	NL_RTM_NEWNETCONF	= 80, /* not supported */
78 	NL_RTM_GETNETCONF	= 82, /* not supported */
79 	NL_RTM_NEWMDB		= 84, /* not supported */
80 	NL_RTM_DELMDB		= 85, /* not supported */
81 	NL_RTM_GETMDB		= 86, /* not supported */
82 	NL_RTM_NEWNSID		= 88, /* not supported */
83 	NL_RTM_DELNSID		= 89, /* not supported */
84 	NL_RTM_GETNSID		= 90, /* not supported */
85 	NL_RTM_NEWSTATS		= 92, /* not supported */
86 	NL_RTM_GETSTATS		= 94, /* not supported */
87 	NL_RTM_NEWNEXTHOP	= 104, /* creates new user nexhtop */
88 	NL_RTM_DELNEXTHOP	= 105, /* deletes matching nexthop */
89 	NL_RTM_GETNEXTHOP	= 106, /* lists created user nexthops */
90 	__NL_RTM_MAX,
91 };
92 #define NL_RTM_MAX (((__NL_RTM_MAX + 3) & ~3) - 1)
93 
94 #ifndef _KERNEL
95 /*
96  * RTM_* namespace clashes with BSD rtsock namespace.
97  * Use NL_RTM_ prefix in the kernel and map it to RTM_
98  * for userland.
99  */
100 #define RTM_BASE		NL_RTM_BASE
101 #define RTM_NEWLINK		NL_RTM_NEWLINK
102 #define RTM_DELLINK		NL_RTM_DELLINK
103 #define RTM_GETLINK		NL_RTM_GETLINK
104 #define RTM_SETLINK		NL_RTM_SETLINK
105 #define RTM_NEWADDR		NL_RTM_NEWADDR
106 #define RTM_DELADDR		NL_RTM_DELADDR
107 #define RTM_GETADDR		NL_RTM_GETADDR
108 #define RTM_NEWROUTE		NL_RTM_NEWROUTE
109 #define RTM_DELROUTE		NL_RTM_DELROUTE
110 #define RTM_GETROUTE		NL_RTM_GETROUTE
111 #define RTM_NEWNEIGH		NL_RTM_NEWNEIGH
112 #define RTM_DELNEIGH		NL_RTM_DELNEIGH
113 #define RTM_GETNEIGH		NL_RTM_GETNEIGH
114 #define RTM_NEWRULE		NL_RTM_NEWRULE
115 #define RTM_DELRULE		NL_RTM_DELRULE
116 #define RTM_GETRULE		NL_RTM_GETRULE
117 #define RTM_NEWQDISC		NL_RTM_NEWQDISC
118 #define RTM_DELQDISC		NL_RTM_DELQDISC
119 #define RTM_GETQDISC		NL_RTM_GETQDISC
120 #define RTM_NEWTCLASS		NL_RTM_NEWTCLASS
121 #define RTM_DELTCLASS		NL_RTM_DELTCLASS
122 #define RTM_GETTCLASS		NL_RTM_GETTCLASS
123 #define RTM_NEWTFILTER		NL_RTM_NEWTFILTER
124 #define RTM_DELTFILTER		NL_RTM_DELTFILTER
125 #define RTM_GETTFILTER		NL_RTM_GETTFILTER
126 #define RTM_NEWACTION		NL_RTM_NEWACTION
127 #define RTM_DELACTION		NL_RTM_DELACTION
128 #define RTM_GETACTION		NL_RTM_GETACTION
129 #define RTM_NEWPREFIX		NL_RTM_NEWPREFIX
130 #define RTM_GETMULTICAST	NL_RTM_GETMULTICAST
131 #define RTM_GETANYCAST		NL_RTM_GETANYCAST
132 #define RTM_NEWNEIGHTBL		NL_RTM_NEWNEIGHTBL
133 #define RTM_GETNEIGHTBL		NL_RTM_GETNEIGHTBL
134 #define RTM_SETNEIGHTBL		NL_RTM_SETNEIGHTBL
135 #define RTM_NEWNDUSEROPT	NL_RTM_NEWNDUSEROPT
136 #define RTM_NEWADDRLABEL	NL_RTM_NEWADDRLABEL
137 #define RTM_DELADDRLABEL	NL_RTM_DELADDRLABEL
138 #define RTM_GETADDRLABEL	NL_RTM_GETADDRLABEL
139 #define RTM_GETDCB		NL_RTM_GETDCB
140 #define RTM_SETDCB		NL_RTM_SETDCB
141 #define RTM_NEWNETCONF		NL_RTM_NEWNETCONF
142 #define RTM_GETNETCONF		NL_RTM_GETNETCONF
143 #define RTM_NEWMDB		NL_RTM_NEWMDB
144 #define RTM_DELMDB		NL_RTM_DELMDB
145 #define RTM_GETMDB		NL_RTM_GETMDB
146 #define RTM_NEWNSID		NL_RTM_NEWNSID
147 #define RTM_DELNSID		NL_RTM_DELNSID
148 #define RTM_GETNSID		NL_RTM_GETNSID
149 #define RTM_NEWSTATS		NL_RTM_NEWSTATS
150 #define RTM_GETSTATS		NL_RTM_GETSTATS
151 #define RTM_NEWNEXTHOP		NL_RTM_NEWNEXTHOP
152 #define RTM_DELNEXTHOP		NL_RTM_DELNEXTHOP
153 #define RTM_GETNEXTHOP		NL_RTM_GETNEXTHOP
154 #define __RTM_MAX		__NL_RTM_MAX
155 
156 #define RTM_MAX			(roundup2(__RTM_MAX, 4))
157 
158 /* rtnetlink multicast groups - backwards compatibility for userspace */
159 #define RTMGRP_LINK		0x01
160 #define RTMGRP_NOTIFY		0x02
161 #define RTMGRP_NEIGH		0x04
162 #define RTMGRP_TC		0x08
163 
164 #define RTMGRP_IPV4_IFADDR	0x10
165 #define RTMGRP_IPV4_MROUTE	0x20
166 #define RTMGRP_IPV4_ROUTE	0x40
167 #define RTMGRP_IPV4_RULE	0x80
168 
169 #define RTMGRP_IPV6_IFADDR	0x100
170 #define RTMGRP_IPV6_MROUTE	0x200
171 #define RTMGRP_IPV6_ROUTE	0x400
172 #define RTMGRP_IPV6_IFINFO	0x800
173 
174 #define RTMGRP_DECnet_IFADDR	0x1000
175 #define RTMGRP_DECnet_ROUTE	0x4000
176 
177 #define RTMGRP_IPV6_PREFIX	0x20000
178 #endif
179 
180 /* Defined NETLINK_ROUTE multicast groups */
181 enum rtnetlink_groups {
182 	RTNLGRP_NONE,
183 #define RTNLGRP_NONE		RTNLGRP_NONE
184 	RTNLGRP_LINK,
185 #define RTNLGRP_LINK		RTNLGRP_LINK
186 	RTNLGRP_NOTIFY,
187 #define RTNLGRP_NOTIFY		RTNLGRP_NOTIFY
188 	RTNLGRP_NEIGH,
189 #define RTNLGRP_NEIGH		RTNLGRP_NEIGH
190 	RTNLGRP_TC,
191 #define RTNLGRP_TC		RTNLGRP_TC
192 	RTNLGRP_IPV4_IFADDR,
193 #define RTNLGRP_IPV4_IFADDR	RTNLGRP_IPV4_IFADDR
194 	RTNLGRP_IPV4_MROUTE,
195 #define RTNLGRP_IPV4_MROUTE	RTNLGRP_IPV4_MROUTE
196 	RTNLGRP_IPV4_ROUTE,
197 #define RTNLGRP_IPV4_ROUTE	RTNLGRP_IPV4_ROUTE
198 	RTNLGRP_IPV4_RULE,
199 #define RTNLGRP_IPV4_RULE	RTNLGRP_IPV4_RULE
200 	RTNLGRP_IPV6_IFADDR,
201 #define RTNLGRP_IPV6_IFADDR	RTNLGRP_IPV6_IFADDR
202 	RTNLGRP_IPV6_MROUTE,
203 #define RTNLGRP_IPV6_MROUTE	RTNLGRP_IPV6_MROUTE
204 	RTNLGRP_IPV6_ROUTE,
205 #define RTNLGRP_IPV6_ROUTE	RTNLGRP_IPV6_ROUTE
206 	RTNLGRP_IPV6_IFINFO,
207 #define RTNLGRP_IPV6_IFINFO	RTNLGRP_IPV6_IFINFO
208 	RTNLGRP_DECnet_IFADDR,
209 #define RTNLGRP_DECnet_IFADDR	RTNLGRP_DECnet_IFADDR
210 	RTNLGRP_NOP2,
211 	RTNLGRP_DECnet_ROUTE,
212 #define RTNLGRP_DECnet_ROUTE	RTNLGRP_DECnet_ROUTE
213 	RTNLGRP_DECnet_RULE,
214 #define RTNLGRP_DECnet_RULE	RTNLGRP_DECnet_RULE
215 	RTNLGRP_NOP4,
216 	RTNLGRP_IPV6_PREFIX,
217 #define RTNLGRP_IPV6_PREFIX	RTNLGRP_IPV6_PREFIX
218 	RTNLGRP_IPV6_RULE,
219 #define RTNLGRP_IPV6_RULE	RTNLGRP_IPV6_RULE
220 	RTNLGRP_ND_USEROPT,
221 #define RTNLGRP_ND_USEROPT	RTNLGRP_ND_USEROPT
222 	RTNLGRP_PHONET_IFADDR,
223 #define RTNLGRP_PHONET_IFADDR	RTNLGRP_PHONET_IFADDR
224 	RTNLGRP_PHONET_ROUTE,
225 #define RTNLGRP_PHONET_ROUTE	RTNLGRP_PHONET_ROUTE
226 	RTNLGRP_DCB,
227 #define RTNLGRP_DCB		RTNLGRP_DCB
228 	RTNLGRP_IPV4_NETCONF,
229 #define RTNLGRP_IPV4_NETCONF	RTNLGRP_IPV4_NETCONF
230 	RTNLGRP_IPV6_NETCONF,
231 #define RTNLGRP_IPV6_NETCONF	RTNLGRP_IPV6_NETCONF
232 	RTNLGRP_MDB,
233 #define RTNLGRP_MDB 		RTNLGRP_MDB
234 	RTNLGRP_MPLS_ROUTE,
235 #define RTNLGRP_MPLS_ROUTE	RTNLGRP_MPLS_ROUTE
236 	RTNLGRP_NSID,
237 #define RTNLGRP_NSID		RTNLGRP_NSID
238 	RTNLGRP_MPLS_NETCONF,
239 #define RTNLGRP_MPLS_NETCONF	RTNLGRP_MPLS_NETCONF
240 	RTNLGRP_IPV4_MROUTE_R,
241 #define RTNLGRP_IPV4_MROUTE_R	RTNLGRP_IPV4_MROUTE_R
242 	RTNLGRP_IPV6_MROUTE_R,
243 #define RTNLGRP_IPV6_MROUTE_R	RTNLGRP_IPV6_MROUTE_R
244 	RTNLGRP_NEXTHOP,
245 #define RTNLGRP_NEXTHOP		RTNLGRP_NEXTHOP
246 	RTNLGRP_BRVLAN,
247 #define RTNLGRP_BRVLAN		RTNLGRP_BRVLAN
248 	__RTNLGRP_MAX
249 };
250 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
251 
252 
253 /* Defined NETLINK_ROUTE virtual multicast address families */
254 #define RTNL_FAMILY_IPMR		128 /* Not supported */
255 #define RTNL_FAMILY_IP6MR		129 /* Not supported */
256 #define RTNL_FAMILY_MAX			129
257 
258 #endif
259 
260