]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-netlink/netlink-types.c
networkd: Add support for ipvlan L3s and flags (#7726)
[thirdparty/systemd.git] / src / libsystemd / sd-netlink / netlink-types.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2014 Tom Gundersen <teg@jklm.no>
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <stdint.h>
22 #include <sys/socket.h>
23 #include <linux/netlink.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/can/netlink.h>
26 #include <linux/fib_rules.h>
27 #include <linux/in6.h>
28 #include <linux/veth.h>
29 #include <linux/if_bridge.h>
30 #include <linux/if_addr.h>
31 #include <linux/if_addrlabel.h>
32 #include <linux/if.h>
33 #include <linux/ip.h>
34 #include <linux/if_addr.h>
35 #include <linux/if_bridge.h>
36 #include <linux/if_link.h>
37 #include <linux/if_tunnel.h>
38 #include <linux/fib_rules.h>
39
40 #if HAVE_VXCAN_INFO_PEER
41 #include <linux/can/vxcan.h>
42 #endif
43
44 #include "macro.h"
45 #include "missing.h"
46 #include "netlink-types.h"
47 #include "string-table.h"
48 #include "util.h"
49
50 /* Maximum ARP IP target defined in kernel */
51 #define BOND_MAX_ARP_TARGETS 16
52
53 typedef enum {
54 BOND_ARP_TARGETS_0,
55 BOND_ARP_TARGETS_1,
56 BOND_ARP_TARGETS_2,
57 BOND_ARP_TARGETS_3,
58 BOND_ARP_TARGETS_4,
59 BOND_ARP_TARGETS_5,
60 BOND_ARP_TARGETS_6,
61 BOND_ARP_TARGETS_7,
62 BOND_ARP_TARGETS_8,
63 BOND_ARP_TARGETS_9,
64 BOND_ARP_TARGETS_10,
65 BOND_ARP_TARGETS_11,
66 BOND_ARP_TARGETS_12,
67 BOND_ARP_TARGETS_13,
68 BOND_ARP_TARGETS_14,
69 BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
70 } BondArpTargets;
71
72 struct NLType {
73 uint16_t type;
74 size_t size;
75 const NLTypeSystem *type_system;
76 const NLTypeSystemUnion *type_system_union;
77 };
78
79 struct NLTypeSystem {
80 uint16_t count;
81 const NLType *types;
82 };
83
84 static const NLTypeSystem rtnl_link_type_system;
85
86 static const NLType empty_types[1] = {
87 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
88 };
89
90 static const NLTypeSystem empty_type_system = {
91 .count = 0,
92 .types = empty_types,
93 };
94
95 static const NLType rtnl_link_info_data_veth_types[] = {
96 [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
97 };
98
99 static const NLType rtnl_link_info_data_vxcan_types[] = {
100 [VXCAN_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
101 };
102
103 static const NLType rtnl_link_info_data_ipvlan_types[] = {
104 [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 },
105 [IFLA_IPVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
106 };
107
108 static const NLType rtnl_link_info_data_macvlan_types[] = {
109 [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 },
110 [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
111 };
112
113 static const NLType rtnl_link_info_data_bridge_types[] = {
114 [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 },
115 [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 },
116 [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 },
117 [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 },
118 [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 },
119 [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 },
120 [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 },
121 [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
122 [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
123 [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 },
124 [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 },
125 [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 },
126 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 },
127 [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 },
128 [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 },
129 [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 },
130 [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 },
131 [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 },
132 [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 },
133 [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
134 [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 },
135 [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 },
136 [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 },
137 [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 },
138 [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 },
139 [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 },
140 [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 },
141 [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 },
142 [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 },
143 [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 },
144 [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
145 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 },
146 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
147 [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 },
148 [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 },
149 [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 },
150 [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 },
151 };
152
153 static const NLType rtnl_link_info_data_vlan_types[] = {
154 [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
155 /*
156 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
157 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
158 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
159 */
160 [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
161 };
162
163 static const NLType rtnl_link_info_data_vxlan_types[] = {
164 [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 },
165 [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR },
166 [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 },
167 [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
168 [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 },
169 [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 },
170 [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 },
171 [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 },
172 [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 },
173 [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32},
174 [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 },
175 [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 },
176 [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 },
177 [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 },
178 [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 },
179 [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR },
180 [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR },
181 [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
182 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
183 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
184 [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 },
185 [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 },
186 [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG },
187 [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
188 [IFLA_VXLAN_COLLECT_METADATA] = { .type = NETLINK_TYPE_U8 },
189 [IFLA_VXLAN_LABEL] = { .type = NETLINK_TYPE_U32 },
190 [IFLA_VXLAN_GPE] = { .type = NETLINK_TYPE_FLAG },
191 };
192
193 static const NLType rtnl_bond_arp_target_types[] = {
194 [BOND_ARP_TARGETS_0] = { .type = NETLINK_TYPE_U32 },
195 [BOND_ARP_TARGETS_1] = { .type = NETLINK_TYPE_U32 },
196 [BOND_ARP_TARGETS_2] = { .type = NETLINK_TYPE_U32 },
197 [BOND_ARP_TARGETS_3] = { .type = NETLINK_TYPE_U32 },
198 [BOND_ARP_TARGETS_4] = { .type = NETLINK_TYPE_U32 },
199 [BOND_ARP_TARGETS_5] = { .type = NETLINK_TYPE_U32 },
200 [BOND_ARP_TARGETS_6] = { .type = NETLINK_TYPE_U32 },
201 [BOND_ARP_TARGETS_7] = { .type = NETLINK_TYPE_U32 },
202 [BOND_ARP_TARGETS_8] = { .type = NETLINK_TYPE_U32 },
203 [BOND_ARP_TARGETS_9] = { .type = NETLINK_TYPE_U32 },
204 [BOND_ARP_TARGETS_10] = { .type = NETLINK_TYPE_U32 },
205 [BOND_ARP_TARGETS_11] = { .type = NETLINK_TYPE_U32 },
206 [BOND_ARP_TARGETS_12] = { .type = NETLINK_TYPE_U32 },
207 [BOND_ARP_TARGETS_13] = { .type = NETLINK_TYPE_U32 },
208 [BOND_ARP_TARGETS_14] = { .type = NETLINK_TYPE_U32 },
209 [BOND_ARP_TARGETS_MAX] = { .type = NETLINK_TYPE_U32 },
210 };
211
212 static const NLTypeSystem rtnl_bond_arp_type_system = {
213 .count = ELEMENTSOF(rtnl_bond_arp_target_types),
214 .types = rtnl_bond_arp_target_types,
215 };
216
217 static const NLType rtnl_link_info_data_bond_types[] = {
218 [IFLA_BOND_MODE] = { .type = NETLINK_TYPE_U8 },
219 [IFLA_BOND_ACTIVE_SLAVE] = { .type = NETLINK_TYPE_U32 },
220 [IFLA_BOND_MIIMON] = { .type = NETLINK_TYPE_U32 },
221 [IFLA_BOND_UPDELAY] = { .type = NETLINK_TYPE_U32 },
222 [IFLA_BOND_DOWNDELAY] = { .type = NETLINK_TYPE_U32 },
223 [IFLA_BOND_USE_CARRIER] = { .type = NETLINK_TYPE_U8 },
224 [IFLA_BOND_ARP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
225 [IFLA_BOND_ARP_IP_TARGET] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_bond_arp_type_system },
226 [IFLA_BOND_ARP_VALIDATE] = { .type = NETLINK_TYPE_U32 },
227 [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NETLINK_TYPE_U32 },
228 [IFLA_BOND_PRIMARY] = { .type = NETLINK_TYPE_U32 },
229 [IFLA_BOND_PRIMARY_RESELECT] = { .type = NETLINK_TYPE_U8 },
230 [IFLA_BOND_FAIL_OVER_MAC] = { .type = NETLINK_TYPE_U8 },
231 [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NETLINK_TYPE_U8 },
232 [IFLA_BOND_RESEND_IGMP] = { .type = NETLINK_TYPE_U32 },
233 [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NETLINK_TYPE_U8 },
234 [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NETLINK_TYPE_U8 },
235 [IFLA_BOND_MIN_LINKS] = { .type = NETLINK_TYPE_U32 },
236 [IFLA_BOND_LP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
237 [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NETLINK_TYPE_U32 },
238 [IFLA_BOND_AD_LACP_RATE] = { .type = NETLINK_TYPE_U8 },
239 [IFLA_BOND_AD_SELECT] = { .type = NETLINK_TYPE_U8 },
240 [IFLA_BOND_AD_INFO] = { .type = NETLINK_TYPE_NESTED },
241 };
242
243 static const NLType rtnl_link_info_data_iptun_types[] = {
244 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
245 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
246 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
247 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
248 [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 },
249 [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
250 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 },
251 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
252 [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR },
253 [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 },
254 [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
255 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
256 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
257 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
258 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
259 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
260 };
261
262 static const NLType rtnl_link_info_data_ipgre_types[] = {
263 [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 },
264 [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 },
265 [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 },
266 [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 },
267 [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 },
268 [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
269 [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
270 [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 },
271 [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 },
272 [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
273 [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
274 [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 },
275 [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
276 [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
277 [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
278 [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
279 };
280
281 static const NLType rtnl_link_info_data_ipvti_types[] = {
282 [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 },
283 [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 },
284 [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 },
285 [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
286 [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
287 };
288
289 static const NLType rtnl_link_info_data_ip6tnl_types[] = {
290 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
291 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
292 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
293 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
294 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 },
295 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
296 [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 },
297 [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
298 };
299
300 static const NLType rtnl_link_info_data_vrf_types[] = {
301 [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 },
302 };
303
304 static const NLType rtnl_link_info_data_geneve_types[] = {
305 [IFLA_GENEVE_ID] = { .type = NETLINK_TYPE_U32 },
306 [IFLA_GENEVE_TTL] = { .type = NETLINK_TYPE_U8 },
307 [IFLA_GENEVE_TOS] = { .type = NETLINK_TYPE_U8 },
308 [IFLA_GENEVE_PORT] = { .type = NETLINK_TYPE_U16 },
309 [IFLA_GENEVE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
310 [IFLA_GENEVE_REMOTE6] = { .type = NETLINK_TYPE_IN_ADDR },
311 [IFLA_GENEVE_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
312 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
313 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
314 [IFLA_GENEVE_LABEL] = { .type = NETLINK_TYPE_U32 },
315 };
316
317 /* these strings must match the .kind entries in the kernel */
318 static const char* const nl_union_link_info_data_table[] = {
319 [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
320 [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
321 [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
322 [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
323 [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
324 [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
325 [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap",
326 [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
327 [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
328 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
329 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
330 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
331 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
332 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
333 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
334 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
335 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
336 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
337 [NL_UNION_LINK_INFO_DATA_VRF] = "vrf",
338 [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan",
339 [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve",
340 [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan",
341
342 };
343
344 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
345
346 static const NLTypeSystem rtnl_link_info_data_type_systems[] = {
347 [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
348 .types = rtnl_link_info_data_bond_types },
349 [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
350 .types = rtnl_link_info_data_bridge_types },
351 [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
352 .types = rtnl_link_info_data_vlan_types },
353 [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
354 .types = rtnl_link_info_data_veth_types },
355 [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
356 .types = rtnl_link_info_data_macvlan_types },
357 [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
358 .types = rtnl_link_info_data_macvlan_types },
359 [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
360 .types = rtnl_link_info_data_ipvlan_types },
361 [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
362 .types = rtnl_link_info_data_vxlan_types },
363 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
364 .types = rtnl_link_info_data_iptun_types },
365 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
366 .types = rtnl_link_info_data_ipgre_types },
367 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
368 .types = rtnl_link_info_data_ipgre_types },
369 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
370 .types = rtnl_link_info_data_ipgre_types },
371 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
372 .types = rtnl_link_info_data_ipgre_types },
373 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
374 .types = rtnl_link_info_data_iptun_types },
375 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
376 .types = rtnl_link_info_data_ipvti_types },
377 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
378 .types = rtnl_link_info_data_ipvti_types },
379 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
380 .types = rtnl_link_info_data_ip6tnl_types },
381 [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
382 .types = rtnl_link_info_data_vrf_types },
383 [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
384 .types = rtnl_link_info_data_geneve_types },
385 [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
386 .types = rtnl_link_info_data_vxcan_types },
387 };
388
389 static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
390 .num = _NL_UNION_LINK_INFO_DATA_MAX,
391 .lookup = nl_union_link_info_data_from_string,
392 .type_systems = rtnl_link_info_data_type_systems,
393 .match_type = NL_MATCH_SIBLING,
394 .match = IFLA_INFO_KIND,
395 };
396
397 static const NLType rtnl_link_info_types[] = {
398 [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING },
399 [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union},
400 /*
401 [IFLA_INFO_XSTATS],
402 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
403 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
404 */
405 };
406
407 static const NLTypeSystem rtnl_link_info_type_system = {
408 .count = ELEMENTSOF(rtnl_link_info_types),
409 .types = rtnl_link_info_types,
410 };
411
412 static const struct NLType rtnl_prot_info_bridge_port_types[] = {
413 [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 },
414 [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 },
415 [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 },
416 [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 },
417 [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 },
418 [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 },
419 [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 },
420 [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 },
421 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
422 [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 },
423 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 },
424 };
425
426 static const NLTypeSystem rtnl_prot_info_type_systems[] = {
427 [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
428 .types = rtnl_prot_info_bridge_port_types },
429 };
430
431 static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
432 .num = AF_MAX,
433 .type_systems = rtnl_prot_info_type_systems,
434 .match_type = NL_MATCH_PROTOCOL,
435 };
436
437 static const struct NLType rtnl_af_spec_inet6_types[] = {
438 [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 },
439 /*
440 IFLA_INET6_CONF,
441 IFLA_INET6_STATS,
442 IFLA_INET6_MCAST,
443 IFLA_INET6_CACHEINFO,
444 IFLA_INET6_ICMP6STATS,
445 */
446 [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR },
447 [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 },
448 };
449
450 static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
451 .count = ELEMENTSOF(rtnl_af_spec_inet6_types),
452 .types = rtnl_af_spec_inet6_types,
453 };
454
455 static const NLType rtnl_af_spec_types[] = {
456 [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
457 };
458
459 static const NLTypeSystem rtnl_af_spec_type_system = {
460 .count = ELEMENTSOF(rtnl_af_spec_types),
461 .types = rtnl_af_spec_types,
462 };
463
464 static const NLType rtnl_link_types[] = {
465 [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
466 [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
467 [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
468 [IFLA_MTU] = { .type = NETLINK_TYPE_U32 },
469 [IFLA_LINK] = { .type = NETLINK_TYPE_U32 },
470 /*
471 [IFLA_QDISC],
472 [IFLA_STATS],
473 [IFLA_COST],
474 [IFLA_PRIORITY],
475 */
476 [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 },
477 /*
478 [IFLA_WIRELESS],
479 */
480 [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
481 [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 },
482 /*
483 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
484 */
485 [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 },
486 [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 },
487 [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 },
488 [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
489 [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
490 [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
491 /*
492 [IFLA_NUM_VF],
493 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
494 [IFLA_STATS64],
495 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
496 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
497 */
498 [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system },
499 /*
500 [IFLA_VF_PORTS],
501 [IFLA_PORT_SELF],
502 [IFLA_AF_SPEC],
503 */
504 [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 },
505 [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 },
506 [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 },
507 [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 },
508 [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 },
509 [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 },
510 [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 },
511 /*
512 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
513 */
514 };
515
516 static const NLTypeSystem rtnl_link_type_system = {
517 .count = ELEMENTSOF(rtnl_link_types),
518 .types = rtnl_link_types,
519 };
520
521 /* IFA_FLAGS was defined in kernel 3.14, but we still support older
522 * kernels where IFA_MAX is lower. */
523 static const NLType rtnl_address_types[] = {
524 [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR },
525 [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
526 [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
527 [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
528 [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
529 /*
530 [IFA_ANYCAST],
531 [IFA_MULTICAST],
532 */
533 [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 },
534 };
535
536 static const NLTypeSystem rtnl_address_type_system = {
537 .count = ELEMENTSOF(rtnl_address_types),
538 .types = rtnl_address_types,
539 };
540
541 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
542
543 static const NLType rtnl_route_metrics_types[] = {
544 [RTAX_MTU] = { .type = NETLINK_TYPE_U32 },
545 [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 },
546 [RTAX_RTT] = { .type = NETLINK_TYPE_U32 },
547 [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 },
548 [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 },
549 [RTAX_CWND] = { .type = NETLINK_TYPE_U32 },
550 [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 },
551 [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 },
552 [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 },
553 [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 },
554 [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 },
555 [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 },
556 };
557
558 static const NLTypeSystem rtnl_route_metrics_type_system = {
559 .count = ELEMENTSOF(rtnl_route_metrics_types),
560 .types = rtnl_route_metrics_types,
561 };
562
563 static const NLType rtnl_route_types[] = {
564 [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
565 [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
566 [RTA_IIF] = { .type = NETLINK_TYPE_U32 },
567 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
568 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
569 [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
570 [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
571 [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system},
572 /* [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
573 */
574 [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */
575 /*
576 RTA_CACHEINFO,
577 RTA_TABLE,
578 RTA_MARK,
579 RTA_MFC_STATS,
580 RTA_VIA,
581 RTA_NEWDST,
582 */
583 [RTA_PREF] = { .type = NETLINK_TYPE_U8 },
584
585 };
586
587 static const NLTypeSystem rtnl_route_type_system = {
588 .count = ELEMENTSOF(rtnl_route_types),
589 .types = rtnl_route_types,
590 };
591
592 static const NLType rtnl_neigh_types[] = {
593 [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
594 [NDA_LLADDR] = { .type = NETLINK_TYPE_ETHER_ADDR },
595 [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
596 [NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
597 [NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
598 [NDA_PORT] = { .type = NETLINK_TYPE_U16 },
599 [NDA_VNI] = { .type = NETLINK_TYPE_U32 },
600 [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 },
601 };
602
603 static const NLTypeSystem rtnl_neigh_type_system = {
604 .count = ELEMENTSOF(rtnl_neigh_types),
605 .types = rtnl_neigh_types,
606 };
607
608 static const NLType rtnl_addrlabel_types[] = {
609 [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) },
610 [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 },
611 };
612
613 static const NLTypeSystem rtnl_addrlabel_type_system = {
614 .count = ELEMENTSOF(rtnl_addrlabel_types),
615 .types = rtnl_addrlabel_types,
616 };
617
618 static const NLType rtnl_routing_policy_rule_types[] = {
619 [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
620 [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR },
621 [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING },
622 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
623 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
624 [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
625 [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 },
626 [FRA_FLOW] = { .type = NETLINK_TYPE_U32 },
627 [FRA_TUN_ID] = { .type = NETLINK_TYPE_U32 },
628 [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 },
629 [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 },
630 [FRA_TABLE] = { .type = NETLINK_TYPE_U32 },
631 [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 },
632 [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING },
633 [FRA_PAD] = { .type = NETLINK_TYPE_U32 },
634 [FRA_L3MDEV] = { .type = NETLINK_TYPE_U64 },
635 [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) },
636 };
637
638 static const NLTypeSystem rtnl_routing_policy_rule_type_system = {
639 .count = ELEMENTSOF(rtnl_routing_policy_rule_types),
640 .types = rtnl_routing_policy_rule_types,
641 };
642
643 static const NLType rtnl_types[] = {
644 [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 },
645 [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) },
646 [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
647 [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
648 [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
649 [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
650 [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
651 [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
652 [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
653 [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
654 [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
655 [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
656 [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
657 [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
658 [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
659 [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
660 [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
661 [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
662 [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
663 [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
664 [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
665 };
666
667 const NLTypeSystem type_system_root = {
668 .count = ELEMENTSOF(rtnl_types),
669 .types = rtnl_types,
670 };
671
672 uint16_t type_get_type(const NLType *type) {
673 assert(type);
674 return type->type;
675 }
676
677 size_t type_get_size(const NLType *type) {
678 assert(type);
679 return type->size;
680 }
681
682 void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) {
683 assert(nl_type);
684 assert(ret);
685 assert(nl_type->type == NETLINK_TYPE_NESTED);
686 assert(nl_type->type_system);
687
688 *ret = nl_type->type_system;
689 }
690
691 void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) {
692 assert(nl_type);
693 assert(ret);
694 assert(nl_type->type == NETLINK_TYPE_UNION);
695 assert(nl_type->type_system_union);
696
697 *ret = nl_type->type_system_union;
698 }
699
700 uint16_t type_system_get_count(const NLTypeSystem *type_system) {
701 assert(type_system);
702 return type_system->count;
703 }
704
705 int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
706 const NLType *nl_type;
707
708 assert(ret);
709 assert(type_system);
710 assert(type_system->types);
711
712 if (type >= type_system->count)
713 return -EOPNOTSUPP;
714
715 nl_type = &type_system->types[type];
716
717 if (nl_type->type == NETLINK_TYPE_UNSPEC)
718 return -EOPNOTSUPP;
719
720 *ret = nl_type;
721
722 return 0;
723 }
724
725 int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
726 const NLType *nl_type;
727 int r;
728
729 assert(ret);
730
731 r = type_system_get_type(type_system, &nl_type, type);
732 if (r < 0)
733 return r;
734
735 type_get_type_system(nl_type, ret);
736 return 0;
737 }
738
739 int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
740 const NLType *nl_type;
741 int r;
742
743 assert(ret);
744
745 r = type_system_get_type(type_system, &nl_type, type);
746 if (r < 0)
747 return r;
748
749 type_get_type_system_union(nl_type, ret);
750 return 0;
751 }
752
753 int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
754 int type;
755
756 assert(type_system_union);
757 assert(type_system_union->match_type == NL_MATCH_SIBLING);
758 assert(type_system_union->lookup);
759 assert(type_system_union->type_systems);
760 assert(ret);
761 assert(key);
762
763 type = type_system_union->lookup(key);
764 if (type < 0)
765 return -EOPNOTSUPP;
766
767 assert(type < type_system_union->num);
768
769 *ret = &type_system_union->type_systems[type];
770
771 return 0;
772 }
773
774 int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
775 const NLTypeSystem *type_system;
776
777 assert(type_system_union);
778 assert(type_system_union->type_systems);
779 assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
780 assert(ret);
781
782 if (protocol >= type_system_union->num)
783 return -EOPNOTSUPP;
784
785 type_system = &type_system_union->type_systems[protocol];
786 if (!type_system->types)
787 return -EOPNOTSUPP;
788
789 *ret = type_system;
790
791 return 0;
792 }