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