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