xref: /freebsd/sys/netlink/route/common.h (revision 0aa2700123e22c2b0a977375e087dc2759b8e980)
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  * 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_NEWNEXTHOP	NL_RTM_NEWNEXTHOP
112 #define	RTM_DELNEXTHOP	NL_RTM_DELNEXTHOP
113 #define	RTM_GETNEXTHOP	NL_RTM_GETNEXTHOP
114 #endif
115 
116 #ifndef _KERNEL
117 /* rtnetlink multicast groups - backwards compatibility for userspace */
118 #define RTMGRP_LINK		0x01
119 #define RTMGRP_NOTIFY		0x02
120 #define RTMGRP_NEIGH		0x04
121 #define RTMGRP_TC		0x08
122 
123 #define RTMGRP_IPV4_IFADDR	0x10
124 #define RTMGRP_IPV4_MROUTE	0x20
125 #define RTMGRP_IPV4_ROUTE	0x40
126 #define RTMGRP_IPV4_RULE	0x80
127 
128 #define RTMGRP_IPV6_IFADDR	0x100
129 #define RTMGRP_IPV6_MROUTE	0x200
130 #define RTMGRP_IPV6_ROUTE	0x400
131 #define RTMGRP_IPV6_IFINFO	0x800
132 
133 #define RTMGRP_DECnet_IFADDR	0x1000
134 #define RTMGRP_DECnet_ROUTE	0x4000
135 
136 #define RTMGRP_IPV6_PREFIX	0x20000
137 #endif
138 
139 /* Defined NETLINK_ROUTE multicast groups */
140 enum rtnetlink_groups {
141 	RTNLGRP_NONE,
142 #define RTNLGRP_NONE		RTNLGRP_NONE
143 	RTNLGRP_LINK,
144 #define RTNLGRP_LINK		RTNLGRP_LINK
145 	RTNLGRP_NOTIFY,
146 #define RTNLGRP_NOTIFY		RTNLGRP_NOTIFY
147 	RTNLGRP_NEIGH,
148 #define RTNLGRP_NEIGH		RTNLGRP_NEIGH
149 	RTNLGRP_TC,
150 #define RTNLGRP_TC		RTNLGRP_TC
151 	RTNLGRP_IPV4_IFADDR,
152 #define RTNLGRP_IPV4_IFADDR	RTNLGRP_IPV4_IFADDR
153 	RTNLGRP_IPV4_MROUTE,
154 #define RTNLGRP_IPV4_MROUTE	RTNLGRP_IPV4_MROUTE
155 	RTNLGRP_IPV4_ROUTE,
156 #define RTNLGRP_IPV4_ROUTE	RTNLGRP_IPV4_ROUTE
157 	RTNLGRP_IPV4_RULE,
158 #define RTNLGRP_IPV4_RULE	RTNLGRP_IPV4_RULE
159 	RTNLGRP_IPV6_IFADDR,
160 #define RTNLGRP_IPV6_IFADDR	RTNLGRP_IPV6_IFADDR
161 	RTNLGRP_IPV6_MROUTE,
162 #define RTNLGRP_IPV6_MROUTE	RTNLGRP_IPV6_MROUTE
163 	RTNLGRP_IPV6_ROUTE,
164 #define RTNLGRP_IPV6_ROUTE	RTNLGRP_IPV6_ROUTE
165 	RTNLGRP_IPV6_IFINFO,
166 #define RTNLGRP_IPV6_IFINFO	RTNLGRP_IPV6_IFINFO
167 	RTNLGRP_DECnet_IFADDR,
168 #define RTNLGRP_DECnet_IFADDR	RTNLGRP_DECnet_IFADDR
169 	RTNLGRP_NOP2,
170 	RTNLGRP_DECnet_ROUTE,
171 #define RTNLGRP_DECnet_ROUTE	RTNLGRP_DECnet_ROUTE
172 	RTNLGRP_DECnet_RULE,
173 #define RTNLGRP_DECnet_RULE	RTNLGRP_DECnet_RULE
174 	RTNLGRP_NOP4,
175 	RTNLGRP_IPV6_PREFIX,
176 #define RTNLGRP_IPV6_PREFIX	RTNLGRP_IPV6_PREFIX
177 	RTNLGRP_IPV6_RULE,
178 #define RTNLGRP_IPV6_RULE	RTNLGRP_IPV6_RULE
179 	RTNLGRP_ND_USEROPT,
180 #define RTNLGRP_ND_USEROPT	RTNLGRP_ND_USEROPT
181 	RTNLGRP_PHONET_IFADDR,
182 #define RTNLGRP_PHONET_IFADDR	RTNLGRP_PHONET_IFADDR
183 	RTNLGRP_PHONET_ROUTE,
184 #define RTNLGRP_PHONET_ROUTE	RTNLGRP_PHONET_ROUTE
185 	RTNLGRP_DCB,
186 #define RTNLGRP_DCB		RTNLGRP_DCB
187 	RTNLGRP_IPV4_NETCONF,
188 #define RTNLGRP_IPV4_NETCONF	RTNLGRP_IPV4_NETCONF
189 	RTNLGRP_IPV6_NETCONF,
190 #define RTNLGRP_IPV6_NETCONF	RTNLGRP_IPV6_NETCONF
191 	RTNLGRP_MDB,
192 #define RTNLGRP_MDB 		RTNLGRP_MDB
193 	RTNLGRP_MPLS_ROUTE,
194 #define RTNLGRP_MPLS_ROUTE	RTNLGRP_MPLS_ROUTE
195 	RTNLGRP_NSID,
196 #define RTNLGRP_NSID		RTNLGRP_NSID
197 	RTNLGRP_MPLS_NETCONF,
198 #define RTNLGRP_MPLS_NETCONF	RTNLGRP_MPLS_NETCONF
199 	RTNLGRP_IPV4_MROUTE_R,
200 #define RTNLGRP_IPV4_MROUTE_R	RTNLGRP_IPV4_MROUTE_R
201 	RTNLGRP_IPV6_MROUTE_R,
202 #define RTNLGRP_IPV6_MROUTE_R	RTNLGRP_IPV6_MROUTE_R
203 	RTNLGRP_NEXTHOP,
204 #define RTNLGRP_NEXTHOP		RTNLGRP_NEXTHOP
205 	RTNLGRP_BRVLAN,
206 #define RTNLGRP_BRVLAN		RTNLGRP_BRVLAN
207 	__RTNLGRP_MAX
208 };
209 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
210 
211 
212 #endif
213 
214