2 This file is part of systemd.
4 Copyright 2014 Tom Gundersen <teg@jklm.no>
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.
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.
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/>.
21 #include <sys/socket.h>
22 #include <linux/netlink.h>
23 #include <linux/rtnetlink.h>
24 #include <linux/can/netlink.h>
25 #include <linux/in6.h>
26 #include <linux/veth.h>
27 #include <linux/if_bridge.h>
28 #include <linux/if_addr.h>
29 #include <linux/if_addrlabel.h>
32 #include <linux/if_link.h>
33 #include <linux/if_tunnel.h>
37 #include "netlink-types.h"
38 #include "string-table.h"
41 /* Maximum ARP IP target defined in kernel */
42 #define BOND_MAX_ARP_TARGETS 16
60 BOND_ARP_TARGETS_MAX
= BOND_MAX_ARP_TARGETS
,
66 const NLTypeSystem
*type_system
;
67 const NLTypeSystemUnion
*type_system_union
;
75 static const NLTypeSystem rtnl_link_type_system
;
77 static const NLType empty_types
[1] = {
78 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
81 static const NLTypeSystem empty_type_system
= {
86 static const NLType rtnl_link_info_data_veth_types
[] = {
87 [VETH_INFO_PEER
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
90 static const NLType rtnl_link_info_data_ipvlan_types
[] = {
91 [IFLA_IPVLAN_MODE
] = { .type
= NETLINK_TYPE_U16
},
94 static const NLType rtnl_link_info_data_macvlan_types
[] = {
95 [IFLA_MACVLAN_MODE
] = { .type
= NETLINK_TYPE_U32
},
96 [IFLA_MACVLAN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
99 static const NLType rtnl_link_info_data_bridge_types
[] = {
100 [IFLA_BR_FORWARD_DELAY
] = { .type
= NETLINK_TYPE_U32
},
101 [IFLA_BR_HELLO_TIME
] = { .type
= NETLINK_TYPE_U32
},
102 [IFLA_BR_MAX_AGE
] = { .type
= NETLINK_TYPE_U32
},
103 [IFLA_BR_AGEING_TIME
] = { .type
= NETLINK_TYPE_U32
},
104 [IFLA_BR_STP_STATE
] = { .type
= NETLINK_TYPE_U32
},
105 [IFLA_BR_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
106 [IFLA_BR_VLAN_FILTERING
] = { .type
= NETLINK_TYPE_U8
},
107 [IFLA_BR_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
108 [IFLA_BR_GROUP_FWD_MASK
] = { .type
= NETLINK_TYPE_U16
},
109 [IFLA_BR_ROOT_PORT
] = { .type
= NETLINK_TYPE_U16
},
110 [IFLA_BR_ROOT_PATH_COST
] = { .type
= NETLINK_TYPE_U32
},
111 [IFLA_BR_TOPOLOGY_CHANGE
] = { .type
= NETLINK_TYPE_U8
},
112 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED
] = { .type
= NETLINK_TYPE_U8
},
113 [IFLA_BR_HELLO_TIMER
] = { .type
= NETLINK_TYPE_U16
},
114 [IFLA_BR_TCN_TIMER
] = { .type
= NETLINK_TYPE_U16
},
115 [IFLA_BR_TOPOLOGY_CHANGE_TIMER
] = { .type
= NETLINK_TYPE_U16
},
116 [IFLA_BR_GC_TIMER
] = { .type
= NETLINK_TYPE_U64
},
117 [IFLA_BR_GROUP_ADDR
] = { .type
= NETLINK_TYPE_U16
},
118 [IFLA_BR_FDB_FLUSH
] = { .type
= NETLINK_TYPE_U16
},
119 [IFLA_BR_MCAST_ROUTER
] = { .type
= NETLINK_TYPE_U8
},
120 [IFLA_BR_MCAST_SNOOPING
] = { .type
= NETLINK_TYPE_U8
},
121 [IFLA_BR_MCAST_QUERY_USE_IFADDR
] = { .type
= NETLINK_TYPE_U8
},
122 [IFLA_BR_MCAST_QUERIER
] = { .type
= NETLINK_TYPE_U8
},
123 [IFLA_BR_MCAST_HASH_ELASTICITY
] = { .type
= NETLINK_TYPE_U32
},
124 [IFLA_BR_MCAST_HASH_MAX
] = { .type
= NETLINK_TYPE_U16
},
125 [IFLA_BR_MCAST_LAST_MEMBER_CNT
] = { .type
= NETLINK_TYPE_U32
},
126 [IFLA_BR_MCAST_STARTUP_QUERY_CNT
] = { .type
= NETLINK_TYPE_U16
},
127 [IFLA_BR_MCAST_LAST_MEMBER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
128 [IFLA_BR_MCAST_MEMBERSHIP_INTVL
] = { .type
= NETLINK_TYPE_U64
},
129 [IFLA_BR_MCAST_QUERIER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
130 [IFLA_BR_MCAST_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
131 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
] = { .type
= NETLINK_TYPE_U64
},
132 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
133 [IFLA_BR_NF_CALL_IPTABLES
] = { .type
= NETLINK_TYPE_U8
},
134 [IFLA_BR_NF_CALL_IP6TABLES
] = { .type
= NETLINK_TYPE_U8
},
135 [IFLA_BR_NF_CALL_ARPTABLES
] = { .type
= NETLINK_TYPE_U8
},
136 [IFLA_BR_VLAN_DEFAULT_PVID
] = { .type
= NETLINK_TYPE_U16
},
139 static const NLType rtnl_link_info_data_vlan_types
[] = {
140 [IFLA_VLAN_ID
] = { .type
= NETLINK_TYPE_U16
},
142 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
143 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
144 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
146 [IFLA_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
149 static const NLType rtnl_link_info_data_vxlan_types
[] = {
150 [IFLA_VXLAN_ID
] = { .type
= NETLINK_TYPE_U32
},
151 [IFLA_VXLAN_GROUP
] = { .type
= NETLINK_TYPE_IN_ADDR
},
152 [IFLA_VXLAN_LINK
] = { .type
= NETLINK_TYPE_U32
},
153 [IFLA_VXLAN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
154 [IFLA_VXLAN_TTL
] = { .type
= NETLINK_TYPE_U8
},
155 [IFLA_VXLAN_TOS
] = { .type
= NETLINK_TYPE_U8
},
156 [IFLA_VXLAN_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
157 [IFLA_VXLAN_AGEING
] = { .type
= NETLINK_TYPE_U32
},
158 [IFLA_VXLAN_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
159 [IFLA_VXLAN_PORT_RANGE
] = { .type
= NETLINK_TYPE_U32
},
160 [IFLA_VXLAN_PROXY
] = { .type
= NETLINK_TYPE_U8
},
161 [IFLA_VXLAN_RSC
] = { .type
= NETLINK_TYPE_U8
},
162 [IFLA_VXLAN_L2MISS
] = { .type
= NETLINK_TYPE_U8
},
163 [IFLA_VXLAN_L3MISS
] = { .type
= NETLINK_TYPE_U8
},
164 [IFLA_VXLAN_PORT
] = { .type
= NETLINK_TYPE_U16
},
165 [IFLA_VXLAN_GROUP6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
166 [IFLA_VXLAN_LOCAL6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
167 [IFLA_VXLAN_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
168 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
169 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
170 [IFLA_VXLAN_REMCSUM_TX
] = { .type
= NETLINK_TYPE_U8
},
171 [IFLA_VXLAN_REMCSUM_RX
] = { .type
= NETLINK_TYPE_U8
},
172 [IFLA_VXLAN_GBP
] = { .type
= NETLINK_TYPE_FLAG
},
173 [IFLA_VXLAN_REMCSUM_NOPARTIAL
] = { .type
= NETLINK_TYPE_FLAG
},
174 [IFLA_VXLAN_COLLECT_METADATA
] = { .type
= NETLINK_TYPE_U8
},
175 [IFLA_VXLAN_LABEL
] = { .type
= NETLINK_TYPE_U32
},
176 [IFLA_VXLAN_GPE
] = { .type
= NETLINK_TYPE_FLAG
},
179 static const NLType rtnl_bond_arp_target_types
[] = {
180 [BOND_ARP_TARGETS_0
] = { .type
= NETLINK_TYPE_U32
},
181 [BOND_ARP_TARGETS_1
] = { .type
= NETLINK_TYPE_U32
},
182 [BOND_ARP_TARGETS_2
] = { .type
= NETLINK_TYPE_U32
},
183 [BOND_ARP_TARGETS_3
] = { .type
= NETLINK_TYPE_U32
},
184 [BOND_ARP_TARGETS_4
] = { .type
= NETLINK_TYPE_U32
},
185 [BOND_ARP_TARGETS_5
] = { .type
= NETLINK_TYPE_U32
},
186 [BOND_ARP_TARGETS_6
] = { .type
= NETLINK_TYPE_U32
},
187 [BOND_ARP_TARGETS_7
] = { .type
= NETLINK_TYPE_U32
},
188 [BOND_ARP_TARGETS_8
] = { .type
= NETLINK_TYPE_U32
},
189 [BOND_ARP_TARGETS_9
] = { .type
= NETLINK_TYPE_U32
},
190 [BOND_ARP_TARGETS_10
] = { .type
= NETLINK_TYPE_U32
},
191 [BOND_ARP_TARGETS_11
] = { .type
= NETLINK_TYPE_U32
},
192 [BOND_ARP_TARGETS_12
] = { .type
= NETLINK_TYPE_U32
},
193 [BOND_ARP_TARGETS_13
] = { .type
= NETLINK_TYPE_U32
},
194 [BOND_ARP_TARGETS_14
] = { .type
= NETLINK_TYPE_U32
},
195 [BOND_ARP_TARGETS_MAX
] = { .type
= NETLINK_TYPE_U32
},
198 static const NLTypeSystem rtnl_bond_arp_type_system
= {
199 .count
= ELEMENTSOF(rtnl_bond_arp_target_types
),
200 .types
= rtnl_bond_arp_target_types
,
203 static const NLType rtnl_link_info_data_bond_types
[] = {
204 [IFLA_BOND_MODE
] = { .type
= NETLINK_TYPE_U8
},
205 [IFLA_BOND_ACTIVE_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
206 [IFLA_BOND_MIIMON
] = { .type
= NETLINK_TYPE_U32
},
207 [IFLA_BOND_UPDELAY
] = { .type
= NETLINK_TYPE_U32
},
208 [IFLA_BOND_DOWNDELAY
] = { .type
= NETLINK_TYPE_U32
},
209 [IFLA_BOND_USE_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
210 [IFLA_BOND_ARP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
211 [IFLA_BOND_ARP_IP_TARGET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_bond_arp_type_system
},
212 [IFLA_BOND_ARP_VALIDATE
] = { .type
= NETLINK_TYPE_U32
},
213 [IFLA_BOND_ARP_ALL_TARGETS
] = { .type
= NETLINK_TYPE_U32
},
214 [IFLA_BOND_PRIMARY
] = { .type
= NETLINK_TYPE_U32
},
215 [IFLA_BOND_PRIMARY_RESELECT
] = { .type
= NETLINK_TYPE_U8
},
216 [IFLA_BOND_FAIL_OVER_MAC
] = { .type
= NETLINK_TYPE_U8
},
217 [IFLA_BOND_XMIT_HASH_POLICY
] = { .type
= NETLINK_TYPE_U8
},
218 [IFLA_BOND_RESEND_IGMP
] = { .type
= NETLINK_TYPE_U32
},
219 [IFLA_BOND_NUM_PEER_NOTIF
] = { .type
= NETLINK_TYPE_U8
},
220 [IFLA_BOND_ALL_SLAVES_ACTIVE
] = { .type
= NETLINK_TYPE_U8
},
221 [IFLA_BOND_MIN_LINKS
] = { .type
= NETLINK_TYPE_U32
},
222 [IFLA_BOND_LP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
223 [IFLA_BOND_PACKETS_PER_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
224 [IFLA_BOND_AD_LACP_RATE
] = { .type
= NETLINK_TYPE_U8
},
225 [IFLA_BOND_AD_SELECT
] = { .type
= NETLINK_TYPE_U8
},
226 [IFLA_BOND_AD_INFO
] = { .type
= NETLINK_TYPE_NESTED
},
229 static const NLType rtnl_link_info_data_iptun_types
[] = {
230 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
231 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
232 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
233 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
234 [IFLA_IPTUN_TOS
] = { .type
= NETLINK_TYPE_U8
},
235 [IFLA_IPTUN_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
236 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
237 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
238 [IFLA_IPTUN_6RD_PREFIX
] = { .type
= NETLINK_TYPE_IN_ADDR
},
239 [IFLA_IPTUN_6RD_RELAY_PREFIX
] = { .type
= NETLINK_TYPE_U32
},
240 [IFLA_IPTUN_6RD_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
241 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
242 [IFLA_IPTUN_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
243 [IFLA_IPTUN_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
244 [IFLA_IPTUN_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
245 [IFLA_IPTUN_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
248 static const NLType rtnl_link_info_data_ipgre_types
[] = {
249 [IFLA_GRE_LINK
] = { .type
= NETLINK_TYPE_U32
},
250 [IFLA_GRE_IFLAGS
] = { .type
= NETLINK_TYPE_U16
},
251 [IFLA_GRE_OFLAGS
] = { .type
= NETLINK_TYPE_U16
},
252 [IFLA_GRE_IKEY
] = { .type
= NETLINK_TYPE_U32
},
253 [IFLA_GRE_OKEY
] = { .type
= NETLINK_TYPE_U32
},
254 [IFLA_GRE_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
255 [IFLA_GRE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
256 [IFLA_GRE_TTL
] = { .type
= NETLINK_TYPE_U8
},
257 [IFLA_GRE_TOS
] = { .type
= NETLINK_TYPE_U8
},
258 [IFLA_GRE_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
259 [IFLA_GRE_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
260 [IFLA_GRE_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
261 [IFLA_GRE_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
262 [IFLA_GRE_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
263 [IFLA_GRE_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
264 [IFLA_GRE_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
267 static const NLType rtnl_link_info_data_ipvti_types
[] = {
268 [IFLA_VTI_LINK
] = { .type
= NETLINK_TYPE_U32
},
269 [IFLA_VTI_IKEY
] = { .type
= NETLINK_TYPE_U32
},
270 [IFLA_VTI_OKEY
] = { .type
= NETLINK_TYPE_U32
},
271 [IFLA_VTI_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
272 [IFLA_VTI_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
275 static const NLType rtnl_link_info_data_ip6tnl_types
[] = {
276 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
277 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
278 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
279 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
280 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
281 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
282 [IFLA_IPTUN_ENCAP_LIMIT
] = { .type
= NETLINK_TYPE_U8
},
283 [IFLA_IPTUN_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
286 static const NLType rtnl_link_info_data_vrf_types
[] = {
287 [IFLA_VRF_TABLE
] = { .type
= NETLINK_TYPE_U32
},
290 static const NLType rtnl_link_info_data_geneve_types
[] = {
291 [IFLA_GENEVE_ID
] = { .type
= NETLINK_TYPE_U32
},
292 [IFLA_GENEVE_TTL
] = { .type
= NETLINK_TYPE_U8
},
293 [IFLA_GENEVE_TOS
] = { .type
= NETLINK_TYPE_U8
},
294 [IFLA_GENEVE_PORT
] = { .type
= NETLINK_TYPE_U16
},
295 [IFLA_GENEVE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
296 [IFLA_GENEVE_REMOTE6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
297 [IFLA_GENEVE_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
298 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
299 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
300 [IFLA_GENEVE_LABEL
] = { .type
= NETLINK_TYPE_U32
},
303 /* these strings must match the .kind entries in the kernel */
304 static const char* const nl_union_link_info_data_table
[] = {
305 [NL_UNION_LINK_INFO_DATA_BOND
] = "bond",
306 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = "bridge",
307 [NL_UNION_LINK_INFO_DATA_VLAN
] = "vlan",
308 [NL_UNION_LINK_INFO_DATA_VETH
] = "veth",
309 [NL_UNION_LINK_INFO_DATA_DUMMY
] = "dummy",
310 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = "macvlan",
311 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = "macvtap",
312 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = "ipvlan",
313 [NL_UNION_LINK_INFO_DATA_VXLAN
] = "vxlan",
314 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = "ipip",
315 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = "gre",
316 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = "gretap",
317 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = "ip6gre",
318 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = "ip6gretap",
319 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = "sit",
320 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = "vti",
321 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = "vti6",
322 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = "ip6tnl",
323 [NL_UNION_LINK_INFO_DATA_VRF
] = "vrf",
324 [NL_UNION_LINK_INFO_DATA_VCAN
] = "vcan",
325 [NL_UNION_LINK_INFO_DATA_GENEVE
] = "geneve",
328 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data
, NLUnionLinkInfoData
);
330 static const NLTypeSystem rtnl_link_info_data_type_systems
[] = {
331 [NL_UNION_LINK_INFO_DATA_BOND
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bond_types
),
332 .types
= rtnl_link_info_data_bond_types
},
333 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bridge_types
),
334 .types
= rtnl_link_info_data_bridge_types
},
335 [NL_UNION_LINK_INFO_DATA_VLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vlan_types
),
336 .types
= rtnl_link_info_data_vlan_types
},
337 [NL_UNION_LINK_INFO_DATA_VETH
] = { .count
= ELEMENTSOF(rtnl_link_info_data_veth_types
),
338 .types
= rtnl_link_info_data_veth_types
},
339 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
340 .types
= rtnl_link_info_data_macvlan_types
},
341 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
342 .types
= rtnl_link_info_data_macvlan_types
},
343 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvlan_types
),
344 .types
= rtnl_link_info_data_ipvlan_types
},
345 [NL_UNION_LINK_INFO_DATA_VXLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vxlan_types
),
346 .types
= rtnl_link_info_data_vxlan_types
},
347 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
348 .types
= rtnl_link_info_data_iptun_types
},
349 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
350 .types
= rtnl_link_info_data_ipgre_types
},
351 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
352 .types
= rtnl_link_info_data_ipgre_types
},
353 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
354 .types
= rtnl_link_info_data_ipgre_types
},
355 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
356 .types
= rtnl_link_info_data_ipgre_types
},
357 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
358 .types
= rtnl_link_info_data_iptun_types
},
359 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
360 .types
= rtnl_link_info_data_ipvti_types
},
361 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
362 .types
= rtnl_link_info_data_ipvti_types
},
363 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ip6tnl_types
),
364 .types
= rtnl_link_info_data_ip6tnl_types
},
365 [NL_UNION_LINK_INFO_DATA_VRF
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vrf_types
),
366 .types
= rtnl_link_info_data_vrf_types
},
367 [NL_UNION_LINK_INFO_DATA_GENEVE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_geneve_types
),
368 .types
= rtnl_link_info_data_geneve_types
},
371 static const NLTypeSystemUnion rtnl_link_info_data_type_system_union
= {
372 .num
= _NL_UNION_LINK_INFO_DATA_MAX
,
373 .lookup
= nl_union_link_info_data_from_string
,
374 .type_systems
= rtnl_link_info_data_type_systems
,
375 .match_type
= NL_MATCH_SIBLING
,
376 .match
= IFLA_INFO_KIND
,
379 static const NLType rtnl_link_info_types
[] = {
380 [IFLA_INFO_KIND
] = { .type
= NETLINK_TYPE_STRING
},
381 [IFLA_INFO_DATA
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_link_info_data_type_system_union
},
384 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
385 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
389 static const NLTypeSystem rtnl_link_info_type_system
= {
390 .count
= ELEMENTSOF(rtnl_link_info_types
),
391 .types
= rtnl_link_info_types
,
394 static const struct NLType rtnl_prot_info_bridge_port_types
[] = {
395 [IFLA_BRPORT_STATE
] = { .type
= NETLINK_TYPE_U8
},
396 [IFLA_BRPORT_COST
] = { .type
= NETLINK_TYPE_U32
},
397 [IFLA_BRPORT_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
398 [IFLA_BRPORT_MODE
] = { .type
= NETLINK_TYPE_U8
},
399 [IFLA_BRPORT_GUARD
] = { .type
= NETLINK_TYPE_U8
},
400 [IFLA_BRPORT_PROTECT
] = { .type
= NETLINK_TYPE_U8
},
401 [IFLA_BRPORT_FAST_LEAVE
] = { .type
= NETLINK_TYPE_U8
},
402 [IFLA_BRPORT_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
403 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NETLINK_TYPE_U8
},
404 [IFLA_BRPORT_PROXYARP
] = { .type
= NETLINK_TYPE_U8
},
405 [IFLA_BRPORT_LEARNING_SYNC
] = { .type
= NETLINK_TYPE_U8
},
408 static const NLTypeSystem rtnl_prot_info_type_systems
[] = {
409 [AF_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_prot_info_bridge_port_types
),
410 .types
= rtnl_prot_info_bridge_port_types
},
413 static const NLTypeSystemUnion rtnl_prot_info_type_system_union
= {
415 .type_systems
= rtnl_prot_info_type_systems
,
416 .match_type
= NL_MATCH_PROTOCOL
,
419 static const struct NLType rtnl_af_spec_inet6_types
[] = {
420 [IFLA_INET6_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
425 IFLA_INET6_CACHEINFO,
426 IFLA_INET6_ICMP6STATS,
428 [IFLA_INET6_TOKEN
] = { .type
= NETLINK_TYPE_IN_ADDR
},
429 [IFLA_INET6_ADDR_GEN_MODE
] = { .type
= NETLINK_TYPE_U8
},
432 static const NLTypeSystem rtnl_af_spec_inet6_type_system
= {
433 .count
= ELEMENTSOF(rtnl_af_spec_inet6_types
),
434 .types
= rtnl_af_spec_inet6_types
,
437 static const NLType rtnl_af_spec_types
[] = {
438 [AF_INET6
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_inet6_type_system
},
441 static const NLTypeSystem rtnl_af_spec_type_system
= {
442 .count
= ELEMENTSOF(rtnl_af_spec_types
),
443 .types
= rtnl_af_spec_types
,
446 static const NLType rtnl_link_types
[] = {
447 [IFLA_ADDRESS
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
448 [IFLA_BROADCAST
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
449 [IFLA_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
450 [IFLA_MTU
] = { .type
= NETLINK_TYPE_U32
},
451 [IFLA_LINK
] = { .type
= NETLINK_TYPE_U32
},
458 [IFLA_MASTER
] = { .type
= NETLINK_TYPE_U32
},
462 [IFLA_PROTINFO
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_prot_info_type_system_union
},
463 [IFLA_TXQLEN
] = { .type
= NETLINK_TYPE_U32
},
465 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
467 [IFLA_WEIGHT
] = { .type
= NETLINK_TYPE_U32
},
468 [IFLA_OPERSTATE
] = { .type
= NETLINK_TYPE_U8
},
469 [IFLA_LINKMODE
] = { .type
= NETLINK_TYPE_U8
},
470 [IFLA_LINKINFO
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_info_type_system
},
471 [IFLA_NET_NS_PID
] = { .type
= NETLINK_TYPE_U32
},
472 [IFLA_IFALIAS
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFALIASZ
- 1 },
475 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
477 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
478 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
480 [IFLA_AF_SPEC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_type_system
},
486 [IFLA_GROUP
] = { .type
= NETLINK_TYPE_U32
},
487 [IFLA_NET_NS_FD
] = { .type
= NETLINK_TYPE_U32
},
488 [IFLA_EXT_MASK
] = { .type
= NETLINK_TYPE_U32
},
489 [IFLA_PROMISCUITY
] = { .type
= NETLINK_TYPE_U32
},
490 [IFLA_NUM_TX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
491 [IFLA_NUM_RX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
492 [IFLA_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
494 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
498 static const NLTypeSystem rtnl_link_type_system
= {
499 .count
= ELEMENTSOF(rtnl_link_types
),
500 .types
= rtnl_link_types
,
503 /* IFA_FLAGS was defined in kernel 3.14, but we still support older
504 * kernels where IFA_MAX is lower. */
505 static const NLType rtnl_address_types
[] = {
506 [IFA_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
},
507 [IFA_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
508 [IFA_LABEL
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
509 [IFA_BROADCAST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
510 [IFA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct ifa_cacheinfo
) },
515 [IFA_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
518 static const NLTypeSystem rtnl_address_type_system
= {
519 .count
= ELEMENTSOF(rtnl_address_types
),
520 .types
= rtnl_address_types
,
523 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
525 static const NLType rtnl_route_metrics_types
[] = {
526 [RTAX_MTU
] = { .type
= NETLINK_TYPE_U32
},
527 [RTAX_WINDOW
] = { .type
= NETLINK_TYPE_U32
},
528 [RTAX_RTT
] = { .type
= NETLINK_TYPE_U32
},
529 [RTAX_RTTVAR
] = { .type
= NETLINK_TYPE_U32
},
530 [RTAX_SSTHRESH
] = { .type
= NETLINK_TYPE_U32
},
531 [RTAX_CWND
] = { .type
= NETLINK_TYPE_U32
},
532 [RTAX_ADVMSS
] = { .type
= NETLINK_TYPE_U32
},
533 [RTAX_REORDERING
] = { .type
= NETLINK_TYPE_U32
},
534 [RTAX_HOPLIMIT
] = { .type
= NETLINK_TYPE_U32
},
535 [RTAX_INITCWND
] = { .type
= NETLINK_TYPE_U32
},
536 [RTAX_FEATURES
] = { .type
= NETLINK_TYPE_U32
},
537 [RTAX_RTO_MIN
] = { .type
= NETLINK_TYPE_U32
},
540 static const NLTypeSystem rtnl_route_metrics_type_system
= {
541 .count
= ELEMENTSOF(rtnl_route_metrics_types
),
542 .types
= rtnl_route_metrics_types
,
545 static const NLType rtnl_route_types
[] = {
546 [RTA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
547 [RTA_SRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
548 [RTA_IIF
] = { .type
= NETLINK_TYPE_U32
},
549 [RTA_OIF
] = { .type
= NETLINK_TYPE_U32
},
550 [RTA_GATEWAY
] = { .type
= NETLINK_TYPE_IN_ADDR
},
551 [RTA_PRIORITY
] = { .type
= NETLINK_TYPE_U32
},
552 [RTA_PREFSRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
553 [RTA_METRICS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_metrics_type_system
},
554 /* [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
556 [RTA_FLOW
] = { .type
= NETLINK_TYPE_U32
}, /* 6? */
565 [RTA_PREF
] = { .type
= NETLINK_TYPE_U8
},
569 static const NLTypeSystem rtnl_route_type_system
= {
570 .count
= ELEMENTSOF(rtnl_route_types
),
571 .types
= rtnl_route_types
,
574 static const NLType rtnl_neigh_types
[] = {
575 [NDA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
},
576 [NDA_LLADDR
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
577 [NDA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct nda_cacheinfo
) },
578 [NDA_PROBES
] = { .type
= NETLINK_TYPE_U32
},
579 [NDA_VLAN
] = { .type
= NETLINK_TYPE_U16
},
580 [NDA_PORT
] = { .type
= NETLINK_TYPE_U16
},
581 [NDA_VNI
] = { .type
= NETLINK_TYPE_U32
},
582 [NDA_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
585 static const NLTypeSystem rtnl_neigh_type_system
= {
586 .count
= ELEMENTSOF(rtnl_neigh_types
),
587 .types
= rtnl_neigh_types
,
590 static const NLType rtnl_addrlabel_types
[] = {
591 [IFAL_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
, .size
= sizeof(struct in6_addr
) },
592 [IFAL_LABEL
] = { .type
= NETLINK_TYPE_U32
},
595 static const NLTypeSystem rtnl_addrlabel_type_system
= {
596 .count
= ELEMENTSOF(rtnl_addrlabel_types
),
597 .types
= rtnl_addrlabel_types
,
600 static const NLType rtnl_types
[] = {
601 [NLMSG_DONE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
, .size
= 0 },
602 [NLMSG_ERROR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
, .size
= sizeof(struct nlmsgerr
) },
603 [RTM_NEWLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
604 [RTM_DELLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
605 [RTM_GETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
606 [RTM_SETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
607 [RTM_NEWADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
608 [RTM_DELADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
609 [RTM_GETADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
610 [RTM_NEWROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
611 [RTM_DELROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
612 [RTM_GETROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
613 [RTM_NEWNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
614 [RTM_DELNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
615 [RTM_GETNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
616 [RTM_NEWADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
617 [RTM_DELADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
618 [RTM_GETADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
621 const NLTypeSystem type_system_root
= {
622 .count
= ELEMENTSOF(rtnl_types
),
626 uint16_t type_get_type(const NLType
*type
) {
631 size_t type_get_size(const NLType
*type
) {
636 void type_get_type_system(const NLType
*nl_type
, const NLTypeSystem
**ret
) {
639 assert(nl_type
->type
== NETLINK_TYPE_NESTED
);
640 assert(nl_type
->type_system
);
642 *ret
= nl_type
->type_system
;
645 void type_get_type_system_union(const NLType
*nl_type
, const NLTypeSystemUnion
**ret
) {
648 assert(nl_type
->type
== NETLINK_TYPE_UNION
);
649 assert(nl_type
->type_system_union
);
651 *ret
= nl_type
->type_system_union
;
654 uint16_t type_system_get_count(const NLTypeSystem
*type_system
) {
656 return type_system
->count
;
659 int type_system_get_type(const NLTypeSystem
*type_system
, const NLType
**ret
, uint16_t type
) {
660 const NLType
*nl_type
;
664 assert(type_system
->types
);
666 if (type
>= type_system
->count
)
669 nl_type
= &type_system
->types
[type
];
671 if (nl_type
->type
== NETLINK_TYPE_UNSPEC
)
679 int type_system_get_type_system(const NLTypeSystem
*type_system
, const NLTypeSystem
**ret
, uint16_t type
) {
680 const NLType
*nl_type
;
685 r
= type_system_get_type(type_system
, &nl_type
, type
);
689 type_get_type_system(nl_type
, ret
);
693 int type_system_get_type_system_union(const NLTypeSystem
*type_system
, const NLTypeSystemUnion
**ret
, uint16_t type
) {
694 const NLType
*nl_type
;
699 r
= type_system_get_type(type_system
, &nl_type
, type
);
703 type_get_type_system_union(nl_type
, ret
);
707 int type_system_union_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, const char *key
) {
710 assert(type_system_union
);
711 assert(type_system_union
->match_type
== NL_MATCH_SIBLING
);
712 assert(type_system_union
->lookup
);
713 assert(type_system_union
->type_systems
);
717 type
= type_system_union
->lookup(key
);
721 assert(type
< type_system_union
->num
);
723 *ret
= &type_system_union
->type_systems
[type
];
728 int type_system_union_protocol_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, uint16_t protocol
) {
729 const NLTypeSystem
*type_system
;
731 assert(type_system_union
);
732 assert(type_system_union
->type_systems
);
733 assert(type_system_union
->match_type
== NL_MATCH_PROTOCOL
);
736 if (protocol
>= type_system_union
->num
)
739 type_system
= &type_system_union
->type_systems
[protocol
];
740 if (!type_system
->types
)