]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-netlink/netlink-types.c
Merge pull request #14444 from yuwata/network-codel-more
[thirdparty/systemd.git] / src / libsystemd / sd-netlink / netlink-types.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <netinet/in.h>
4 #include <stdint.h>
5 #include <sys/socket.h>
6 #include <linux/can/vxcan.h>
7 #include <linux/netlink.h>
8 #include <linux/rtnetlink.h>
9 #include <linux/genetlink.h>
10 #include <linux/ip.h>
11 #include <linux/if.h>
12 #include <linux/can/netlink.h>
13 #include <linux/fib_rules.h>
14 #include <linux/fou.h>
15 #include <linux/if_addr.h>
16 #include <linux/if_addrlabel.h>
17 #include <linux/if_bridge.h>
18 #include <linux/if_link.h>
19 #include <linux/if_macsec.h>
20 #include <linux/if_tunnel.h>
21 #include <linux/l2tp.h>
22 #include <linux/nexthop.h>
23 #include <linux/nl80211.h>
24 #include <linux/pkt_sched.h>
25 #include <linux/veth.h>
26 #include <linux/wireguard.h>
27
28 #include "sd-netlink.h"
29
30 #include "generic-netlink.h"
31 #include "hashmap.h"
32 #include "macro.h"
33 #include "netlink-internal.h"
34 #include "netlink-types.h"
35 #include "string-table.h"
36 #include "util.h"
37
38 /* Maximum ARP IP target defined in kernel */
39 #define BOND_MAX_ARP_TARGETS 16
40
41 typedef enum {
42 BOND_ARP_TARGETS_0,
43 BOND_ARP_TARGETS_1,
44 BOND_ARP_TARGETS_2,
45 BOND_ARP_TARGETS_3,
46 BOND_ARP_TARGETS_4,
47 BOND_ARP_TARGETS_5,
48 BOND_ARP_TARGETS_6,
49 BOND_ARP_TARGETS_7,
50 BOND_ARP_TARGETS_8,
51 BOND_ARP_TARGETS_9,
52 BOND_ARP_TARGETS_10,
53 BOND_ARP_TARGETS_11,
54 BOND_ARP_TARGETS_12,
55 BOND_ARP_TARGETS_13,
56 BOND_ARP_TARGETS_14,
57 BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
58 } BondArpTargets;
59
60 struct NLType {
61 uint16_t type;
62 size_t size;
63 const NLTypeSystem *type_system;
64 const NLTypeSystemUnion *type_system_union;
65 };
66
67 struct NLTypeSystem {
68 uint16_t count;
69 const NLType *types;
70 };
71
72 static const NLTypeSystem rtnl_link_type_system;
73
74 static const NLType empty_types[1] = {
75 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
76 };
77
78 static const NLTypeSystem empty_type_system = {
79 .count = 0,
80 .types = empty_types,
81 };
82
83 static const NLType rtnl_link_info_data_veth_types[] = {
84 [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
85 };
86
87 static const NLType rtnl_link_info_data_vxcan_types[] = {
88 [VXCAN_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
89 };
90
91 static const NLType rtnl_link_info_data_ipvlan_types[] = {
92 [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 },
93 [IFLA_IPVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
94 };
95
96 static const NLType rtnl_link_info_data_macvlan_types[] = {
97 [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 },
98 [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
99 };
100
101 static const NLType rtnl_link_info_data_bridge_types[] = {
102 [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 },
103 [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 },
104 [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 },
105 [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 },
106 [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 },
107 [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 },
108 [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 },
109 [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
110 [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
111 [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 },
112 [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 },
113 [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 },
114 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 },
115 [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 },
116 [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 },
117 [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 },
118 [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 },
119 [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 },
120 [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 },
121 [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
122 [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 },
123 [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 },
124 [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 },
125 [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 },
126 [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 },
127 [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 },
128 [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 },
129 [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 },
130 [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 },
131 [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 },
132 [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
133 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 },
134 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
135 [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 },
136 [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 },
137 [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 },
138 [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 },
139 [IFLA_BR_MCAST_IGMP_VERSION] = { .type = NETLINK_TYPE_U8 },
140 };
141
142 static const NLType rtnl_link_info_data_vlan_types[] = {
143 [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
144 /*
145 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
146 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
147 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
148 */
149 [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
150 };
151
152 static const NLType rtnl_link_info_data_vxlan_types[] = {
153 [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 },
154 [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR },
155 [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 },
156 [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
157 [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 },
158 [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 },
159 [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 },
160 [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 },
161 [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 },
162 [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32},
163 [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 },
164 [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 },
165 [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 },
166 [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 },
167 [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 },
168 [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR },
169 [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR },
170 [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
171 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
172 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
173 [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 },
174 [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 },
175 [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG },
176 [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
177 [IFLA_VXLAN_COLLECT_METADATA] = { .type = NETLINK_TYPE_U8 },
178 [IFLA_VXLAN_LABEL] = { .type = NETLINK_TYPE_U32 },
179 [IFLA_VXLAN_GPE] = { .type = NETLINK_TYPE_FLAG },
180 [IFLA_VXLAN_TTL_INHERIT] = { .type = NETLINK_TYPE_FLAG },
181 [IFLA_VXLAN_DF] = { .type = NETLINK_TYPE_U8 },
182 };
183
184 static const NLType rtnl_bond_arp_target_types[] = {
185 [BOND_ARP_TARGETS_0] = { .type = NETLINK_TYPE_U32 },
186 [BOND_ARP_TARGETS_1] = { .type = NETLINK_TYPE_U32 },
187 [BOND_ARP_TARGETS_2] = { .type = NETLINK_TYPE_U32 },
188 [BOND_ARP_TARGETS_3] = { .type = NETLINK_TYPE_U32 },
189 [BOND_ARP_TARGETS_4] = { .type = NETLINK_TYPE_U32 },
190 [BOND_ARP_TARGETS_5] = { .type = NETLINK_TYPE_U32 },
191 [BOND_ARP_TARGETS_6] = { .type = NETLINK_TYPE_U32 },
192 [BOND_ARP_TARGETS_7] = { .type = NETLINK_TYPE_U32 },
193 [BOND_ARP_TARGETS_8] = { .type = NETLINK_TYPE_U32 },
194 [BOND_ARP_TARGETS_9] = { .type = NETLINK_TYPE_U32 },
195 [BOND_ARP_TARGETS_10] = { .type = NETLINK_TYPE_U32 },
196 [BOND_ARP_TARGETS_11] = { .type = NETLINK_TYPE_U32 },
197 [BOND_ARP_TARGETS_12] = { .type = NETLINK_TYPE_U32 },
198 [BOND_ARP_TARGETS_13] = { .type = NETLINK_TYPE_U32 },
199 [BOND_ARP_TARGETS_14] = { .type = NETLINK_TYPE_U32 },
200 [BOND_ARP_TARGETS_MAX] = { .type = NETLINK_TYPE_U32 },
201 };
202
203 static const NLTypeSystem rtnl_bond_arp_type_system = {
204 .count = ELEMENTSOF(rtnl_bond_arp_target_types),
205 .types = rtnl_bond_arp_target_types,
206 };
207
208 static const NLType rtnl_link_info_data_bond_types[] = {
209 [IFLA_BOND_MODE] = { .type = NETLINK_TYPE_U8 },
210 [IFLA_BOND_ACTIVE_SLAVE] = { .type = NETLINK_TYPE_U32 },
211 [IFLA_BOND_MIIMON] = { .type = NETLINK_TYPE_U32 },
212 [IFLA_BOND_UPDELAY] = { .type = NETLINK_TYPE_U32 },
213 [IFLA_BOND_DOWNDELAY] = { .type = NETLINK_TYPE_U32 },
214 [IFLA_BOND_USE_CARRIER] = { .type = NETLINK_TYPE_U8 },
215 [IFLA_BOND_ARP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
216 [IFLA_BOND_ARP_IP_TARGET] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_bond_arp_type_system },
217 [IFLA_BOND_ARP_VALIDATE] = { .type = NETLINK_TYPE_U32 },
218 [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NETLINK_TYPE_U32 },
219 [IFLA_BOND_PRIMARY] = { .type = NETLINK_TYPE_U32 },
220 [IFLA_BOND_PRIMARY_RESELECT] = { .type = NETLINK_TYPE_U8 },
221 [IFLA_BOND_FAIL_OVER_MAC] = { .type = NETLINK_TYPE_U8 },
222 [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NETLINK_TYPE_U8 },
223 [IFLA_BOND_RESEND_IGMP] = { .type = NETLINK_TYPE_U32 },
224 [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NETLINK_TYPE_U8 },
225 [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NETLINK_TYPE_U8 },
226 [IFLA_BOND_MIN_LINKS] = { .type = NETLINK_TYPE_U32 },
227 [IFLA_BOND_LP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
228 [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NETLINK_TYPE_U32 },
229 [IFLA_BOND_AD_LACP_RATE] = { .type = NETLINK_TYPE_U8 },
230 [IFLA_BOND_AD_SELECT] = { .type = NETLINK_TYPE_U8 },
231 [IFLA_BOND_AD_INFO] = { .type = NETLINK_TYPE_NESTED },
232 [IFLA_BOND_AD_ACTOR_SYS_PRIO] = { .type = NETLINK_TYPE_U16 },
233 [IFLA_BOND_AD_USER_PORT_KEY] = { .type = NETLINK_TYPE_U16 },
234 [IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NETLINK_TYPE_ETHER_ADDR },
235 [IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NETLINK_TYPE_U8 },
236 };
237
238 static const NLType rtnl_link_info_data_iptun_types[] = {
239 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
240 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
241 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
242 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
243 [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 },
244 [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
245 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 },
246 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
247 [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR },
248 [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 },
249 [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
250 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
251 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
252 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
253 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
254 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
255 };
256
257 static const NLType rtnl_link_info_data_ipgre_types[] = {
258 [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 },
259 [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 },
260 [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 },
261 [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 },
262 [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 },
263 [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
264 [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
265 [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 },
266 [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 },
267 [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
268 [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
269 [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 },
270 [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
271 [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
272 [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
273 [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
274 [IFLA_GRE_ERSPAN_INDEX] = { .type = NETLINK_TYPE_U32 },
275 };
276
277 static const NLType rtnl_link_info_data_ipvti_types[] = {
278 [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 },
279 [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 },
280 [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 },
281 [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
282 [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
283 };
284
285 static const NLType rtnl_link_info_data_ip6tnl_types[] = {
286 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
287 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
288 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
289 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
290 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 },
291 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
292 [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 },
293 [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
294 };
295
296 static const NLType rtnl_link_info_data_vrf_types[] = {
297 [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 },
298 };
299
300 static const NLType rtnl_link_info_data_geneve_types[] = {
301 [IFLA_GENEVE_ID] = { .type = NETLINK_TYPE_U32 },
302 [IFLA_GENEVE_TTL] = { .type = NETLINK_TYPE_U8 },
303 [IFLA_GENEVE_TOS] = { .type = NETLINK_TYPE_U8 },
304 [IFLA_GENEVE_PORT] = { .type = NETLINK_TYPE_U16 },
305 [IFLA_GENEVE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
306 [IFLA_GENEVE_REMOTE6] = { .type = NETLINK_TYPE_IN_ADDR },
307 [IFLA_GENEVE_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
308 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
309 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
310 [IFLA_GENEVE_LABEL] = { .type = NETLINK_TYPE_U32 },
311 [IFLA_GENEVE_TTL_INHERIT] = { .type = NETLINK_TYPE_U8 },
312 [IFLA_GENEVE_DF] = { .type = NETLINK_TYPE_U8 },
313 };
314
315 static const NLType rtnl_link_info_data_can_types[] = {
316 [IFLA_CAN_BITTIMING] = { .size = sizeof(struct can_bittiming) },
317 [IFLA_CAN_RESTART_MS] = { .type = NETLINK_TYPE_U32 },
318 [IFLA_CAN_CTRLMODE] = { .size = sizeof(struct can_ctrlmode) },
319 };
320
321 static const NLType rtnl_link_info_data_macsec_types[] = {
322 [IFLA_MACSEC_SCI] = { .type = NETLINK_TYPE_U64 },
323 [IFLA_MACSEC_PORT] = { .type = NETLINK_TYPE_U16 },
324 [IFLA_MACSEC_ICV_LEN] = { .type = NETLINK_TYPE_U8 },
325 [IFLA_MACSEC_CIPHER_SUITE] = { .type = NETLINK_TYPE_U64 },
326 [IFLA_MACSEC_WINDOW] = { .type = NETLINK_TYPE_U32 },
327 [IFLA_MACSEC_ENCODING_SA] = { .type = NETLINK_TYPE_U8 },
328 [IFLA_MACSEC_ENCRYPT] = { .type = NETLINK_TYPE_U8 },
329 [IFLA_MACSEC_PROTECT] = { .type = NETLINK_TYPE_U8 },
330 [IFLA_MACSEC_INC_SCI] = { .type = NETLINK_TYPE_U8 },
331 [IFLA_MACSEC_ES] = { .type = NETLINK_TYPE_U8 },
332 [IFLA_MACSEC_SCB] = { .type = NETLINK_TYPE_U8 },
333 [IFLA_MACSEC_REPLAY_PROTECT] = { .type = NETLINK_TYPE_U8 },
334 [IFLA_MACSEC_VALIDATION] = { .type = NETLINK_TYPE_U8 },
335 };
336
337 static const NLType rtnl_link_info_data_xfrm_types[] = {
338 [IFLA_XFRM_LINK] = { .type = NETLINK_TYPE_U32 },
339 [IFLA_XFRM_IF_ID] = { .type = NETLINK_TYPE_U32 }
340 };
341
342 /* these strings must match the .kind entries in the kernel */
343 static const char* const nl_union_link_info_data_table[] = {
344 [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
345 [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
346 [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
347 [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
348 [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
349 [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
350 [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap",
351 [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
352 [NL_UNION_LINK_INFO_DATA_IPVTAP] = "ipvtap",
353 [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
354 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
355 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
356 [NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan",
357 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
358 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
359 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
360 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
361 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
362 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
363 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
364 [NL_UNION_LINK_INFO_DATA_VRF] = "vrf",
365 [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan",
366 [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve",
367 [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan",
368 [NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard",
369 [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim",
370 [NL_UNION_LINK_INFO_DATA_CAN] = "can",
371 [NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec",
372 [NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon",
373 [NL_UNION_LINK_INFO_DATA_XFRM] = "xfrm",
374 [NL_UNION_LINK_INFO_DATA_IFB] = "ifb",
375 };
376
377 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
378
379 static const NLTypeSystem rtnl_link_info_data_type_systems[] = {
380 [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
381 .types = rtnl_link_info_data_bond_types },
382 [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
383 .types = rtnl_link_info_data_bridge_types },
384 [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
385 .types = rtnl_link_info_data_vlan_types },
386 [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
387 .types = rtnl_link_info_data_veth_types },
388 [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
389 .types = rtnl_link_info_data_macvlan_types },
390 [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
391 .types = rtnl_link_info_data_macvlan_types },
392 [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
393 .types = rtnl_link_info_data_ipvlan_types },
394 [NL_UNION_LINK_INFO_DATA_IPVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
395 .types = rtnl_link_info_data_ipvlan_types },
396 [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
397 .types = rtnl_link_info_data_vxlan_types },
398 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
399 .types = rtnl_link_info_data_iptun_types },
400 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
401 .types = rtnl_link_info_data_ipgre_types },
402 [NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
403 .types = rtnl_link_info_data_ipgre_types },
404 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
405 .types = rtnl_link_info_data_ipgre_types },
406 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
407 .types = rtnl_link_info_data_ipgre_types },
408 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
409 .types = rtnl_link_info_data_ipgre_types },
410 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
411 .types = rtnl_link_info_data_iptun_types },
412 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
413 .types = rtnl_link_info_data_ipvti_types },
414 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
415 .types = rtnl_link_info_data_ipvti_types },
416 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
417 .types = rtnl_link_info_data_ip6tnl_types },
418 [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
419 .types = rtnl_link_info_data_vrf_types },
420 [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
421 .types = rtnl_link_info_data_geneve_types },
422 [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
423 .types = rtnl_link_info_data_vxcan_types },
424 [NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types),
425 .types = rtnl_link_info_data_can_types },
426 [NL_UNION_LINK_INFO_DATA_MACSEC] = { .count = ELEMENTSOF(rtnl_link_info_data_macsec_types),
427 .types = rtnl_link_info_data_macsec_types },
428 [NL_UNION_LINK_INFO_DATA_XFRM] = { .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
429 .types = rtnl_link_info_data_xfrm_types },
430 };
431
432 static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
433 .num = _NL_UNION_LINK_INFO_DATA_MAX,
434 .lookup = nl_union_link_info_data_from_string,
435 .type_systems = rtnl_link_info_data_type_systems,
436 .match_type = NL_MATCH_SIBLING,
437 .match = IFLA_INFO_KIND,
438 };
439
440 static const NLType rtnl_link_info_types[] = {
441 [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING },
442 [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union },
443 /*
444 [IFLA_INFO_XSTATS],
445 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
446 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
447 */
448 };
449
450 static const NLTypeSystem rtnl_link_info_type_system = {
451 .count = ELEMENTSOF(rtnl_link_info_types),
452 .types = rtnl_link_info_types,
453 };
454
455 static const struct NLType rtnl_prot_info_bridge_port_types[] = {
456 [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 },
457 [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 },
458 [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 },
459 [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 },
460 [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 },
461 [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 },
462 [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 },
463 [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 },
464 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
465 [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 },
466 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 },
467 [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NETLINK_TYPE_U8 },
468 [IFLA_BRPORT_ROOT_ID] = { .type = NETLINK_TYPE_U8 },
469 [IFLA_BRPORT_BRIDGE_ID] = { .type = NETLINK_TYPE_U8 },
470 [IFLA_BRPORT_DESIGNATED_PORT] = { .type = NETLINK_TYPE_U16 },
471 [IFLA_BRPORT_DESIGNATED_COST] = { .type = NETLINK_TYPE_U16 },
472 [IFLA_BRPORT_ID] = { .type = NETLINK_TYPE_U16 },
473 [IFLA_BRPORT_NO] = { .type = NETLINK_TYPE_U16 },
474 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = { .type = NETLINK_TYPE_U8 },
475 [IFLA_BRPORT_CONFIG_PENDING] = { .type = NETLINK_TYPE_U8 },
476 [IFLA_BRPORT_MESSAGE_AGE_TIMER] = { .type = NETLINK_TYPE_U64 },
477 [IFLA_BRPORT_FORWARD_DELAY_TIMER] = { .type = NETLINK_TYPE_U64 },
478 [IFLA_BRPORT_HOLD_TIMER] = { .type = NETLINK_TYPE_U64 },
479 [IFLA_BRPORT_FLUSH] = { .type = NETLINK_TYPE_U8 },
480 [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
481 [IFLA_BRPORT_PAD] = { .type = NETLINK_TYPE_U8 },
482 [IFLA_BRPORT_MCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
483 [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NETLINK_TYPE_U8 },
484 [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NETLINK_TYPE_U8 },
485 [IFLA_BRPORT_BCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
486 [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
487 [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NETLINK_TYPE_U8 },
488 [IFLA_BRPORT_ISOLATED] = { .type = NETLINK_TYPE_U8 },
489 [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 },
490 };
491
492 static const NLTypeSystem rtnl_prot_info_type_systems[] = {
493 [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
494 .types = rtnl_prot_info_bridge_port_types },
495 };
496
497 static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
498 .num = AF_MAX,
499 .type_systems = rtnl_prot_info_type_systems,
500 .match_type = NL_MATCH_PROTOCOL,
501 };
502
503 static const struct NLType rtnl_af_spec_inet6_types[] = {
504 [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 },
505 /*
506 IFLA_INET6_CONF,
507 IFLA_INET6_STATS,
508 IFLA_INET6_MCAST,
509 IFLA_INET6_CACHEINFO,
510 IFLA_INET6_ICMP6STATS,
511 */
512 [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR },
513 [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 },
514 };
515
516 static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
517 .count = ELEMENTSOF(rtnl_af_spec_inet6_types),
518 .types = rtnl_af_spec_inet6_types,
519 };
520
521 static const NLType rtnl_af_spec_types[] = {
522 [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
523 };
524
525 static const NLTypeSystem rtnl_af_spec_type_system = {
526 .count = ELEMENTSOF(rtnl_af_spec_types),
527 .types = rtnl_af_spec_types,
528 };
529
530 static const NLType rtnl_prop_list_types[] = {
531 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
532 };
533
534 static const NLTypeSystem rtnl_prop_list_type_system = {
535 .count = ELEMENTSOF(rtnl_prop_list_types),
536 .types = rtnl_prop_list_types,
537 };
538
539 static const NLType rtnl_link_types[] = {
540 [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
541 [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
542 [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
543 [IFLA_MTU] = { .type = NETLINK_TYPE_U32 },
544 [IFLA_LINK] = { .type = NETLINK_TYPE_U32 },
545 /*
546 [IFLA_QDISC],
547 */
548 [IFLA_STATS] = { .size = sizeof(struct rtnl_link_stats) },
549 /*
550 [IFLA_COST],
551 [IFLA_PRIORITY],
552 */
553 [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 },
554 /*
555 [IFLA_WIRELESS],
556 */
557 [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
558 [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 },
559 /*
560 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
561 */
562 [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 },
563 [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 },
564 [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 },
565 [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
566 [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
567 [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
568 /*
569 [IFLA_NUM_VF],
570 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
571 */
572 [IFLA_STATS64] = { .size = sizeof(struct rtnl_link_stats64) },
573 /*
574 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
575 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
576 */
577 [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system },
578 /*
579 [IFLA_VF_PORTS],
580 [IFLA_PORT_SELF],
581 [IFLA_AF_SPEC],
582 */
583 [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 },
584 [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 },
585 [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 },
586 [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 },
587 [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 },
588 [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 },
589 [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 },
590 /*
591 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
592 */
593 [IFLA_MIN_MTU] = { .type = NETLINK_TYPE_U32 },
594 [IFLA_MAX_MTU] = { .type = NETLINK_TYPE_U32 },
595 [IFLA_PROP_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_prop_list_type_system },
596 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
597 };
598
599 static const NLTypeSystem rtnl_link_type_system = {
600 .count = ELEMENTSOF(rtnl_link_types),
601 .types = rtnl_link_types,
602 };
603
604 /* IFA_FLAGS was defined in kernel 3.14, but we still support older
605 * kernels where IFA_MAX is lower. */
606 static const NLType rtnl_address_types[] = {
607 [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR },
608 [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
609 [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
610 [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
611 [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
612 /*
613 [IFA_ANYCAST],
614 [IFA_MULTICAST],
615 */
616 [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 },
617 };
618
619 static const NLTypeSystem rtnl_address_type_system = {
620 .count = ELEMENTSOF(rtnl_address_types),
621 .types = rtnl_address_types,
622 };
623
624 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
625
626 static const NLType rtnl_route_metrics_types[] = {
627 [RTAX_MTU] = { .type = NETLINK_TYPE_U32 },
628 [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 },
629 [RTAX_RTT] = { .type = NETLINK_TYPE_U32 },
630 [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 },
631 [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 },
632 [RTAX_CWND] = { .type = NETLINK_TYPE_U32 },
633 [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 },
634 [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 },
635 [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 },
636 [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 },
637 [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 },
638 [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 },
639 [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 },
640 [RTAX_QUICKACK] = { .type = NETLINK_TYPE_U32 },
641 [RTAX_CC_ALGO] = { .type = NETLINK_TYPE_U32 },
642 [RTAX_FASTOPEN_NO_COOKIE] = { .type = NETLINK_TYPE_U32 },
643 };
644
645 static const NLTypeSystem rtnl_route_metrics_type_system = {
646 .count = ELEMENTSOF(rtnl_route_metrics_types),
647 .types = rtnl_route_metrics_types,
648 };
649
650 static const NLType rtnl_route_types[] = {
651 [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
652 [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
653 [RTA_IIF] = { .type = NETLINK_TYPE_U32 },
654 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
655 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
656 [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
657 [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
658 [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system},
659 [RTA_MULTIPATH] = { .size = sizeof(struct rtnexthop) },
660 [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */
661 [RTA_CACHEINFO] = { .size = sizeof(struct rta_cacheinfo) },
662 [RTA_TABLE] = { .type = NETLINK_TYPE_U32 },
663 [RTA_MARK] = { .type = NETLINK_TYPE_U32 },
664 [RTA_MFC_STATS] = { .type = NETLINK_TYPE_U64 },
665 [RTA_VIA] = { .type = NETLINK_TYPE_U32 },
666 [RTA_NEWDST] = { .type = NETLINK_TYPE_U32 },
667 [RTA_PREF] = { .type = NETLINK_TYPE_U8 },
668 [RTA_EXPIRES] = { .type = NETLINK_TYPE_U32 },
669 [RTA_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
670 [RTA_ENCAP] = { .type = NETLINK_TYPE_NESTED }, /* Multiple type systems i.e. LWTUNNEL_ENCAP_MPLS/LWTUNNEL_ENCAP_IP/LWTUNNEL_ENCAP_ILA etc... */
671 [RTA_UID] = { .type = NETLINK_TYPE_U32 },
672 [RTA_TTL_PROPAGATE] = { .type = NETLINK_TYPE_U8 },
673 [RTA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
674 [RTA_SPORT] = { .type = NETLINK_TYPE_U16 },
675 [RTA_DPORT] = { .type = NETLINK_TYPE_U16 },
676 };
677
678 static const NLTypeSystem rtnl_route_type_system = {
679 .count = ELEMENTSOF(rtnl_route_types),
680 .types = rtnl_route_types,
681 };
682
683 static const NLType rtnl_neigh_types[] = {
684 [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
685 [NDA_LLADDR] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
686 [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
687 [NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
688 [NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
689 [NDA_PORT] = { .type = NETLINK_TYPE_U16 },
690 [NDA_VNI] = { .type = NETLINK_TYPE_U32 },
691 [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 },
692 };
693
694 static const NLTypeSystem rtnl_neigh_type_system = {
695 .count = ELEMENTSOF(rtnl_neigh_types),
696 .types = rtnl_neigh_types,
697 };
698
699 static const NLType rtnl_addrlabel_types[] = {
700 [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) },
701 [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 },
702 };
703
704 static const NLTypeSystem rtnl_addrlabel_type_system = {
705 .count = ELEMENTSOF(rtnl_addrlabel_types),
706 .types = rtnl_addrlabel_types,
707 };
708
709 static const NLType rtnl_routing_policy_rule_types[] = {
710 [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
711 [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR },
712 [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING },
713 [FRA_GOTO] = { .type = NETLINK_TYPE_U32 },
714 [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
715 [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 },
716 [FRA_FLOW] = { .type = NETLINK_TYPE_U32 },
717 [FRA_TUN_ID] = { .type = NETLINK_TYPE_U64 },
718 [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 },
719 [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 },
720 [FRA_TABLE] = { .type = NETLINK_TYPE_U32 },
721 [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 },
722 [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING },
723 [FRA_PAD] = { .type = NETLINK_TYPE_U32 },
724 [FRA_L3MDEV] = { .type = NETLINK_TYPE_U8 },
725 [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) },
726 [FRA_PROTOCOL] = { .type = NETLINK_TYPE_U8 },
727 [FRA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
728 [FRA_SPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
729 [FRA_DPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
730 };
731
732 static const NLTypeSystem rtnl_routing_policy_rule_type_system = {
733 .count = ELEMENTSOF(rtnl_routing_policy_rule_types),
734 .types = rtnl_routing_policy_rule_types,
735 };
736
737 static const NLType rtnl_nexthop_types[] = {
738 [NHA_ID] = { .type = NETLINK_TYPE_U32 },
739 [NHA_OIF] = { .type = NETLINK_TYPE_U32 },
740 [NHA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
741 };
742
743 static const NLTypeSystem rtnl_nexthop_type_system = {
744 .count = ELEMENTSOF(rtnl_nexthop_types),
745 .types = rtnl_nexthop_types,
746 };
747
748 static const NLType rtnl_tca_option_data_codel_types[] = {
749 [TCA_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
750 [TCA_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
751 [TCA_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
752 [TCA_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
753 [TCA_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
754 };
755
756 static const NLType rtnl_tca_option_data_fq_types[] = {
757 [TCA_FQ_PLIMIT] = { .type = NETLINK_TYPE_U32 },
758 [TCA_FQ_FLOW_PLIMIT] = { .type = NETLINK_TYPE_U32 },
759 [TCA_FQ_QUANTUM] = { .type = NETLINK_TYPE_U32 },
760 [TCA_FQ_INITIAL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
761 [TCA_FQ_RATE_ENABLE] = { .type = NETLINK_TYPE_U32 },
762 [TCA_FQ_FLOW_DEFAULT_RATE] = { .type = NETLINK_TYPE_U32 },
763 [TCA_FQ_FLOW_MAX_RATE] = { .type = NETLINK_TYPE_U32 },
764 [TCA_FQ_BUCKETS_LOG] = { .type = NETLINK_TYPE_U32 },
765 [TCA_FQ_FLOW_REFILL_DELAY] = { .type = NETLINK_TYPE_U32 },
766 [TCA_FQ_LOW_RATE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
767 [TCA_FQ_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
768 [TCA_FQ_ORPHAN_MASK] = { .type = NETLINK_TYPE_U32 },
769 };
770
771 static const NLType rtnl_tca_option_data_fq_codel_types[] = {
772 [TCA_FQ_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
773 [TCA_FQ_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
774 [TCA_FQ_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
775 [TCA_FQ_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
776 [TCA_FQ_CODEL_FLOWS] = { .type = NETLINK_TYPE_U32 },
777 [TCA_FQ_CODEL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
778 [TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
779 [TCA_FQ_CODEL_DROP_BATCH_SIZE] = { .type = NETLINK_TYPE_U32 },
780 [TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NETLINK_TYPE_U32 },
781 };
782
783 static const NLType rtnl_tca_option_data_tbf_types[] = {
784 [TCA_TBF_PARMS] = { .size = sizeof(struct tc_tbf_qopt) },
785 [TCA_TBF_RTAB] = { .size = TC_RTAB_SIZE },
786 [TCA_TBF_PTAB] = { .size = TC_RTAB_SIZE },
787 [TCA_TBF_RATE64] = { .type = NETLINK_TYPE_U64 },
788 [TCA_TBF_PRATE64] = { .type = NETLINK_TYPE_U64 },
789 [TCA_TBF_BURST] = { .type = NETLINK_TYPE_U32 },
790 [TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 },
791 };
792
793 static const char* const nl_union_tca_option_data_table[] = {
794 [NL_UNION_TCA_OPTION_DATA_CODEL] = "codel",
795 [NL_UNION_TCA_OPTION_DATA_FQ] = "fq",
796 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel",
797 [NL_UNION_TCA_OPTION_DATA_TBF] = "tbf",
798 };
799
800 DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData);
801
802 static const NLTypeSystem rtnl_tca_option_data_type_systems[] = {
803 [NL_UNION_TCA_OPTION_DATA_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_codel_types),
804 .types = rtnl_tca_option_data_codel_types },
805 [NL_UNION_TCA_OPTION_DATA_FQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_types),
806 .types = rtnl_tca_option_data_fq_types },
807 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types),
808 .types = rtnl_tca_option_data_fq_codel_types },
809 [NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
810 .types = rtnl_tca_option_data_tbf_types },
811 };
812
813 static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = {
814 .num = _NL_UNION_TCA_OPTION_DATA_MAX,
815 .lookup = nl_union_tca_option_data_from_string,
816 .type_systems = rtnl_tca_option_data_type_systems,
817 .match_type = NL_MATCH_SIBLING,
818 .match = TCA_KIND,
819 };
820
821 static const NLType rtnl_qdisc_types[] = {
822 [TCA_KIND] = { .type = NETLINK_TYPE_STRING },
823 [TCA_OPTIONS] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_tca_option_data_type_system_union },
824 [TCA_INGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
825 [TCA_EGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
826 };
827
828 static const NLTypeSystem rtnl_qdisc_type_system = {
829 .count = ELEMENTSOF(rtnl_qdisc_types),
830 .types = rtnl_qdisc_types,
831 };
832
833 static const NLType error_types[] = {
834 [NLMSGERR_ATTR_MSG] = { .type = NETLINK_TYPE_STRING },
835 [NLMSGERR_ATTR_OFFS] = { .type = NETLINK_TYPE_U32 },
836 };
837
838 static const NLTypeSystem error_type_system = {
839 .count = ELEMENTSOF(error_types),
840 .types = error_types,
841 };
842
843 static const NLType rtnl_types[] = {
844 [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 },
845 [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
846 [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
847 [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
848 [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
849 [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
850 [RTM_NEWLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
851 [RTM_DELLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
852 [RTM_GETLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
853 [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
854 [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
855 [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
856 [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
857 [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
858 [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
859 [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
860 [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
861 [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
862 [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
863 [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
864 [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
865 [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
866 [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
867 [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
868 [RTM_NEWNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
869 [RTM_DELNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
870 [RTM_GETNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
871 [RTM_NEWQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
872 [RTM_DELQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
873 [RTM_GETQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
874 };
875
876 const NLTypeSystem rtnl_type_system_root = {
877 .count = ELEMENTSOF(rtnl_types),
878 .types = rtnl_types,
879 };
880
881 static const NLType genl_wireguard_allowedip_types[] = {
882 [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 },
883 [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR },
884 [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 },
885 };
886
887 static const NLTypeSystem genl_wireguard_allowedip_type_system = {
888 .count = ELEMENTSOF(genl_wireguard_allowedip_types),
889 .types = genl_wireguard_allowedip_types,
890 };
891
892 static const NLType genl_wireguard_peer_types[] = {
893 [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN },
894 [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
895 [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN },
896 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 },
897 [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR },
898 [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system },
899 };
900
901 static const NLTypeSystem genl_wireguard_peer_type_system = {
902 .count = ELEMENTSOF(genl_wireguard_peer_types),
903 .types = genl_wireguard_peer_types,
904 };
905
906 static const NLType genl_wireguard_set_device_types[] = {
907 [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 },
908 [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 },
909 [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
910 [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN },
911 [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 },
912 [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 },
913 [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system },
914 };
915
916 static const NLTypeSystem genl_wireguard_set_device_type_system = {
917 .count = ELEMENTSOF(genl_wireguard_set_device_types),
918 .types = genl_wireguard_set_device_types,
919 };
920
921 static const NLType genl_wireguard_cmds[] = {
922 [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system },
923 };
924
925 static const NLTypeSystem genl_wireguard_type_system = {
926 .count = ELEMENTSOF(genl_wireguard_cmds),
927 .types = genl_wireguard_cmds,
928 };
929
930 static const NLType genl_mcast_group_types[] = {
931 [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NETLINK_TYPE_STRING },
932 [CTRL_ATTR_MCAST_GRP_ID] = { .type = NETLINK_TYPE_U32 },
933 };
934
935 static const NLTypeSystem genl_mcast_group_type_system = {
936 .count = ELEMENTSOF(genl_mcast_group_types),
937 .types = genl_mcast_group_types,
938 };
939
940 static const NLType genl_get_family_types[] = {
941 [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING },
942 [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 },
943 [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_mcast_group_type_system },
944 };
945
946 static const NLTypeSystem genl_get_family_type_system = {
947 .count = ELEMENTSOF(genl_get_family_types),
948 .types = genl_get_family_types,
949 };
950
951 static const NLType genl_ctrl_id_ctrl_cmds[] = {
952 [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system },
953 };
954
955 static const NLTypeSystem genl_ctrl_id_ctrl_type_system = {
956 .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds),
957 .types = genl_ctrl_id_ctrl_cmds,
958 };
959
960 static const NLType genl_fou_types[] = {
961 [FOU_ATTR_PORT] = { .type = NETLINK_TYPE_U16 },
962 [FOU_ATTR_AF] = { .type = NETLINK_TYPE_U8 },
963 [FOU_ATTR_IPPROTO] = { .type = NETLINK_TYPE_U8 },
964 [FOU_ATTR_TYPE] = { .type = NETLINK_TYPE_U8 },
965 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
966 [FOU_ATTR_LOCAL_V4] = { .type = NETLINK_TYPE_IN_ADDR },
967 [FOU_ATTR_PEER_V4] = { .type = NETLINK_TYPE_IN_ADDR },
968 [FOU_ATTR_LOCAL_V6] = { .type = NETLINK_TYPE_IN_ADDR },
969 [FOU_ATTR_PEER_V6] = { .type = NETLINK_TYPE_IN_ADDR},
970 [FOU_ATTR_PEER_PORT] = { .type = NETLINK_TYPE_U16},
971 [FOU_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32},
972 };
973
974 static const NLTypeSystem genl_fou_type_system = {
975 .count = ELEMENTSOF(genl_fou_types),
976 .types = genl_fou_types,
977 };
978
979 static const NLType genl_fou_cmds[] = {
980 [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
981 [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
982 [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
983 };
984
985 static const NLTypeSystem genl_fou_cmds_type_system = {
986 .count = ELEMENTSOF(genl_fou_cmds),
987 .types = genl_fou_cmds,
988 };
989
990 static const NLType genl_l2tp_types[] = {
991 [L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 },
992 [L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
993 [L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 },
994 [L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 },
995 [L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 },
996 [L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 },
997 [L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 },
998 [L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING },
999 [L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1000 [L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1001 [L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1002 [L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1003 [L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
1004 [L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
1005 [L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 },
1006 [L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 },
1007 [L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 },
1008 [L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 },
1009 [L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 },
1010 [L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1011 [L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1012 [L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 },
1013 [L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 },
1014 [L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1015 [L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1016 [L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG },
1017 [L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG },
1018 };
1019
1020 static const NLTypeSystem genl_l2tp_type_system = {
1021 .count = ELEMENTSOF(genl_l2tp_types),
1022 .types = genl_l2tp_types,
1023 };
1024
1025 static const NLType genl_l2tp[] = {
1026 [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1027 [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1028 [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1029 [L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1030 [L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1031 [L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1032 [L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1033 [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1034 };
1035
1036 static const NLTypeSystem genl_l2tp_tunnel_session_type_system = {
1037 .count = ELEMENTSOF(genl_l2tp),
1038 .types = genl_l2tp,
1039 };
1040
1041 static const NLType genl_rxsc_types[] = {
1042 [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 },
1043 };
1044
1045 static const NLTypeSystem genl_rxsc_config_type_system = {
1046 .count = ELEMENTSOF(genl_rxsc_types),
1047 .types = genl_rxsc_types,
1048 };
1049
1050 static const NLType genl_macsec_rxsc_types[] = {
1051 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1052 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1053 };
1054
1055 static const NLTypeSystem genl_macsec_rxsc_type_system = {
1056 .count = ELEMENTSOF(genl_macsec_rxsc_types),
1057 .types = genl_macsec_rxsc_types,
1058 };
1059
1060 static const NLType genl_macsec_sa_config_types[] = {
1061 [MACSEC_SA_ATTR_AN] = { .type = NETLINK_TYPE_U8 },
1062 [MACSEC_SA_ATTR_ACTIVE] = { .type = NETLINK_TYPE_U8 },
1063 [MACSEC_SA_ATTR_PN] = { .type = NETLINK_TYPE_U32 },
1064 [MACSEC_SA_ATTR_KEYID] = { .size = MACSEC_KEYID_LEN },
1065 [MACSEC_SA_ATTR_KEY] = { .size = MACSEC_MAX_KEY_LEN },
1066 };
1067
1068 static const NLTypeSystem genl_macsec_sa_config_type_system = {
1069 .count = ELEMENTSOF(genl_macsec_sa_config_types),
1070 .types = genl_macsec_sa_config_types,
1071 };
1072
1073 static const NLType genl_macsec_rxsa_types[] = {
1074 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1075 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1076 };
1077
1078 static const NLTypeSystem genl_macsec_rxsa_type_system = {
1079 .count = ELEMENTSOF(genl_macsec_rxsa_types),
1080 .types = genl_macsec_rxsa_types,
1081 };
1082
1083 static const NLType genl_macsec_sa_types[] = {
1084 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1085 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1086 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1087 };
1088
1089 static const NLTypeSystem genl_macsec_sa_type_system = {
1090 .count = ELEMENTSOF(genl_macsec_sa_types),
1091 .types = genl_macsec_sa_types,
1092 };
1093
1094 static const NLType genl_macsec[] = {
1095 [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system },
1096 [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsa_type_system},
1097 [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system },
1098 };
1099
1100 static const NLTypeSystem genl_macsec_device_type_system = {
1101 .count = ELEMENTSOF(genl_macsec),
1102 .types = genl_macsec,
1103 };
1104
1105 static const NLType genl_nl80211_types[] = {
1106 [NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1107 [NL80211_ATTR_MAC] = { .type = NETLINK_TYPE_ETHER_ADDR },
1108 [NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_STRING },
1109 [NL80211_ATTR_IFTYPE] = { .type = NETLINK_TYPE_U32 },
1110 };
1111
1112 static const NLTypeSystem genl_nl80211_type_system = {
1113 .count = ELEMENTSOF(genl_nl80211_types),
1114 .types = genl_nl80211_types,
1115 };
1116
1117 static const NLType genl_nl80211_cmds[] = {
1118 [NL80211_CMD_GET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1119 [NL80211_CMD_SET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1120 [NL80211_CMD_NEW_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1121 [NL80211_CMD_DEL_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1122 [NL80211_CMD_GET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1123 [NL80211_CMD_SET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1124 [NL80211_CMD_NEW_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1125 [NL80211_CMD_DEL_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1126 [NL80211_CMD_GET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1127 [NL80211_CMD_SET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1128 [NL80211_CMD_NEW_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1129 [NL80211_CMD_DEL_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1130 };
1131
1132 static const NLTypeSystem genl_nl80211_cmds_type_system = {
1133 .count = ELEMENTSOF(genl_nl80211_cmds),
1134 .types = genl_nl80211_cmds,
1135 };
1136
1137 static const NLType genl_families[] = {
1138 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system },
1139 [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system },
1140 [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system },
1141 [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system },
1142 [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_device_type_system },
1143 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmds_type_system },
1144 };
1145
1146 /* Mainly used when sending message */
1147 const NLTypeSystem genl_family_type_system_root = {
1148 .count = ELEMENTSOF(genl_families),
1149 .types = genl_families,
1150 };
1151
1152 static const NLType genl_types[] = {
1153 [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
1154 [SD_GENL_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system },
1155 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) },
1156 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system, .size = sizeof(struct genlmsghdr) },
1157 };
1158
1159 /* Mainly used when message received */
1160 const NLTypeSystem genl_type_system_root = {
1161 .count = ELEMENTSOF(genl_types),
1162 .types = genl_types,
1163 };
1164
1165 uint16_t type_get_type(const NLType *type) {
1166 assert(type);
1167 return type->type;
1168 }
1169
1170 size_t type_get_size(const NLType *type) {
1171 assert(type);
1172 return type->size;
1173 }
1174
1175 void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) {
1176 assert(nl_type);
1177 assert(ret);
1178 assert(nl_type->type == NETLINK_TYPE_NESTED);
1179 assert(nl_type->type_system);
1180
1181 *ret = nl_type->type_system;
1182 }
1183
1184 void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) {
1185 assert(nl_type);
1186 assert(ret);
1187 assert(nl_type->type == NETLINK_TYPE_UNION);
1188 assert(nl_type->type_system_union);
1189
1190 *ret = nl_type->type_system_union;
1191 }
1192
1193 uint16_t type_system_get_count(const NLTypeSystem *type_system) {
1194 assert(type_system);
1195 return type_system->count;
1196 }
1197
1198 const NLTypeSystem *type_system_get_root(int protocol) {
1199 switch (protocol) {
1200 case NETLINK_GENERIC:
1201 return &genl_type_system_root;
1202 default: /* NETLINK_ROUTE: */
1203 return &rtnl_type_system_root;
1204 }
1205 }
1206
1207 int type_system_root_get_type(sd_netlink *nl, const NLType **ret, uint16_t type) {
1208 sd_genl_family family;
1209 const NLType *nl_type;
1210 int r;
1211
1212 if (!nl || nl->protocol != NETLINK_GENERIC)
1213 return type_system_get_type(&rtnl_type_system_root, ret, type);
1214
1215 r = nlmsg_type_to_genl_family(nl, type, &family);
1216 if (r < 0)
1217 return r;
1218
1219 if (family >= genl_type_system_root.count)
1220 return -EOPNOTSUPP;
1221
1222 nl_type = &genl_type_system_root.types[family];
1223
1224 if (nl_type->type == NETLINK_TYPE_UNSPEC)
1225 return -EOPNOTSUPP;
1226
1227 *ret = nl_type;
1228
1229 return 0;
1230 }
1231
1232 int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
1233 const NLType *nl_type;
1234
1235 assert(ret);
1236 assert(type_system);
1237 assert(type_system->types);
1238
1239 if (type >= type_system->count)
1240 return -EOPNOTSUPP;
1241
1242 nl_type = &type_system->types[type];
1243
1244 if (nl_type->type == NETLINK_TYPE_UNSPEC)
1245 return -EOPNOTSUPP;
1246
1247 *ret = nl_type;
1248
1249 return 0;
1250 }
1251
1252 int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
1253 const NLType *nl_type;
1254 int r;
1255
1256 assert(ret);
1257
1258 r = type_system_get_type(type_system, &nl_type, type);
1259 if (r < 0)
1260 return r;
1261
1262 type_get_type_system(nl_type, ret);
1263 return 0;
1264 }
1265
1266 int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
1267 const NLType *nl_type;
1268 int r;
1269
1270 assert(ret);
1271
1272 r = type_system_get_type(type_system, &nl_type, type);
1273 if (r < 0)
1274 return r;
1275
1276 type_get_type_system_union(nl_type, ret);
1277 return 0;
1278 }
1279
1280 int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
1281 int type;
1282
1283 assert(type_system_union);
1284 assert(type_system_union->match_type == NL_MATCH_SIBLING);
1285 assert(type_system_union->lookup);
1286 assert(type_system_union->type_systems);
1287 assert(ret);
1288 assert(key);
1289
1290 type = type_system_union->lookup(key);
1291 if (type < 0)
1292 return -EOPNOTSUPP;
1293
1294 assert(type < type_system_union->num);
1295
1296 *ret = &type_system_union->type_systems[type];
1297
1298 return 0;
1299 }
1300
1301 int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
1302 const NLTypeSystem *type_system;
1303
1304 assert(type_system_union);
1305 assert(type_system_union->type_systems);
1306 assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
1307 assert(ret);
1308
1309 if (protocol >= type_system_union->num)
1310 return -EOPNOTSUPP;
1311
1312 type_system = &type_system_union->type_systems[protocol];
1313 if (!type_system->types)
1314 return -EOPNOTSUPP;
1315
1316 *ret = type_system;
1317
1318 return 0;
1319 }