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