1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2014 Tom Gundersen <teg@jklm.no>
6 #include <netinet/in.h>
8 #include <sys/socket.h>
9 #include <linux/netlink.h>
10 #include <linux/rtnetlink.h>
11 #include <linux/genetlink.h>
14 #include <linux/can/netlink.h>
15 #include <linux/fib_rules.h>
16 #include <linux/if_addr.h>
17 #include <linux/if_addrlabel.h>
18 #include <linux/if_bridge.h>
19 #include <linux/if_link.h>
20 #include <linux/if_tunnel.h>
21 #include <linux/veth.h>
22 #if HAVE_VXCAN_INFO_PEER
23 #include <linux/can/vxcan.h>
28 #include "netlink-types.h"
29 #include "sd-netlink.h"
30 #include "string-table.h"
32 #include "wireguard-netlink.h"
34 /* Maximum ARP IP target defined in kernel */
35 #define BOND_MAX_ARP_TARGETS 16
53 BOND_ARP_TARGETS_MAX
= BOND_MAX_ARP_TARGETS
,
59 const NLTypeSystem
*type_system
;
60 const NLTypeSystemUnion
*type_system_union
;
68 static const NLTypeSystem rtnl_link_type_system
;
70 static const NLType empty_types
[1] = {
71 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
74 static const NLTypeSystem empty_type_system
= {
79 static const NLType rtnl_link_info_data_veth_types
[] = {
80 [VETH_INFO_PEER
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
83 static const NLType rtnl_link_info_data_vxcan_types
[] = {
84 [VXCAN_INFO_PEER
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
87 static const NLType rtnl_link_info_data_ipvlan_types
[] = {
88 [IFLA_IPVLAN_MODE
] = { .type
= NETLINK_TYPE_U16
},
89 [IFLA_IPVLAN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
92 static const NLType rtnl_link_info_data_macvlan_types
[] = {
93 [IFLA_MACVLAN_MODE
] = { .type
= NETLINK_TYPE_U32
},
94 [IFLA_MACVLAN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
97 static const NLType rtnl_link_info_data_bridge_types
[] = {
98 [IFLA_BR_FORWARD_DELAY
] = { .type
= NETLINK_TYPE_U32
},
99 [IFLA_BR_HELLO_TIME
] = { .type
= NETLINK_TYPE_U32
},
100 [IFLA_BR_MAX_AGE
] = { .type
= NETLINK_TYPE_U32
},
101 [IFLA_BR_AGEING_TIME
] = { .type
= NETLINK_TYPE_U32
},
102 [IFLA_BR_STP_STATE
] = { .type
= NETLINK_TYPE_U32
},
103 [IFLA_BR_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
104 [IFLA_BR_VLAN_FILTERING
] = { .type
= NETLINK_TYPE_U8
},
105 [IFLA_BR_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
106 [IFLA_BR_GROUP_FWD_MASK
] = { .type
= NETLINK_TYPE_U16
},
107 [IFLA_BR_ROOT_PORT
] = { .type
= NETLINK_TYPE_U16
},
108 [IFLA_BR_ROOT_PATH_COST
] = { .type
= NETLINK_TYPE_U32
},
109 [IFLA_BR_TOPOLOGY_CHANGE
] = { .type
= NETLINK_TYPE_U8
},
110 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED
] = { .type
= NETLINK_TYPE_U8
},
111 [IFLA_BR_HELLO_TIMER
] = { .type
= NETLINK_TYPE_U16
},
112 [IFLA_BR_TCN_TIMER
] = { .type
= NETLINK_TYPE_U16
},
113 [IFLA_BR_TOPOLOGY_CHANGE_TIMER
] = { .type
= NETLINK_TYPE_U16
},
114 [IFLA_BR_GC_TIMER
] = { .type
= NETLINK_TYPE_U64
},
115 [IFLA_BR_GROUP_ADDR
] = { .type
= NETLINK_TYPE_U16
},
116 [IFLA_BR_FDB_FLUSH
] = { .type
= NETLINK_TYPE_U16
},
117 [IFLA_BR_MCAST_ROUTER
] = { .type
= NETLINK_TYPE_U8
},
118 [IFLA_BR_MCAST_SNOOPING
] = { .type
= NETLINK_TYPE_U8
},
119 [IFLA_BR_MCAST_QUERY_USE_IFADDR
] = { .type
= NETLINK_TYPE_U8
},
120 [IFLA_BR_MCAST_QUERIER
] = { .type
= NETLINK_TYPE_U8
},
121 [IFLA_BR_MCAST_HASH_ELASTICITY
] = { .type
= NETLINK_TYPE_U32
},
122 [IFLA_BR_MCAST_HASH_MAX
] = { .type
= NETLINK_TYPE_U16
},
123 [IFLA_BR_MCAST_LAST_MEMBER_CNT
] = { .type
= NETLINK_TYPE_U32
},
124 [IFLA_BR_MCAST_STARTUP_QUERY_CNT
] = { .type
= NETLINK_TYPE_U16
},
125 [IFLA_BR_MCAST_LAST_MEMBER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
126 [IFLA_BR_MCAST_MEMBERSHIP_INTVL
] = { .type
= NETLINK_TYPE_U64
},
127 [IFLA_BR_MCAST_QUERIER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
128 [IFLA_BR_MCAST_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
129 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
] = { .type
= NETLINK_TYPE_U64
},
130 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
131 [IFLA_BR_NF_CALL_IPTABLES
] = { .type
= NETLINK_TYPE_U8
},
132 [IFLA_BR_NF_CALL_IP6TABLES
] = { .type
= NETLINK_TYPE_U8
},
133 [IFLA_BR_NF_CALL_ARPTABLES
] = { .type
= NETLINK_TYPE_U8
},
134 [IFLA_BR_VLAN_DEFAULT_PVID
] = { .type
= NETLINK_TYPE_U16
},
137 static const NLType rtnl_link_info_data_vlan_types
[] = {
138 [IFLA_VLAN_ID
] = { .type
= NETLINK_TYPE_U16
},
140 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
141 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
142 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
144 [IFLA_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
147 static const NLType rtnl_link_info_data_vxlan_types
[] = {
148 [IFLA_VXLAN_ID
] = { .type
= NETLINK_TYPE_U32
},
149 [IFLA_VXLAN_GROUP
] = { .type
= NETLINK_TYPE_IN_ADDR
},
150 [IFLA_VXLAN_LINK
] = { .type
= NETLINK_TYPE_U32
},
151 [IFLA_VXLAN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
152 [IFLA_VXLAN_TTL
] = { .type
= NETLINK_TYPE_U8
},
153 [IFLA_VXLAN_TOS
] = { .type
= NETLINK_TYPE_U8
},
154 [IFLA_VXLAN_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
155 [IFLA_VXLAN_AGEING
] = { .type
= NETLINK_TYPE_U32
},
156 [IFLA_VXLAN_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
157 [IFLA_VXLAN_PORT_RANGE
] = { .type
= NETLINK_TYPE_U32
},
158 [IFLA_VXLAN_PROXY
] = { .type
= NETLINK_TYPE_U8
},
159 [IFLA_VXLAN_RSC
] = { .type
= NETLINK_TYPE_U8
},
160 [IFLA_VXLAN_L2MISS
] = { .type
= NETLINK_TYPE_U8
},
161 [IFLA_VXLAN_L3MISS
] = { .type
= NETLINK_TYPE_U8
},
162 [IFLA_VXLAN_PORT
] = { .type
= NETLINK_TYPE_U16
},
163 [IFLA_VXLAN_GROUP6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
164 [IFLA_VXLAN_LOCAL6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
165 [IFLA_VXLAN_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
166 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
167 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
168 [IFLA_VXLAN_REMCSUM_TX
] = { .type
= NETLINK_TYPE_U8
},
169 [IFLA_VXLAN_REMCSUM_RX
] = { .type
= NETLINK_TYPE_U8
},
170 [IFLA_VXLAN_GBP
] = { .type
= NETLINK_TYPE_FLAG
},
171 [IFLA_VXLAN_REMCSUM_NOPARTIAL
] = { .type
= NETLINK_TYPE_FLAG
},
172 [IFLA_VXLAN_COLLECT_METADATA
] = { .type
= NETLINK_TYPE_U8
},
173 [IFLA_VXLAN_LABEL
] = { .type
= NETLINK_TYPE_U32
},
174 [IFLA_VXLAN_GPE
] = { .type
= NETLINK_TYPE_FLAG
},
177 static const NLType rtnl_bond_arp_target_types
[] = {
178 [BOND_ARP_TARGETS_0
] = { .type
= NETLINK_TYPE_U32
},
179 [BOND_ARP_TARGETS_1
] = { .type
= NETLINK_TYPE_U32
},
180 [BOND_ARP_TARGETS_2
] = { .type
= NETLINK_TYPE_U32
},
181 [BOND_ARP_TARGETS_3
] = { .type
= NETLINK_TYPE_U32
},
182 [BOND_ARP_TARGETS_4
] = { .type
= NETLINK_TYPE_U32
},
183 [BOND_ARP_TARGETS_5
] = { .type
= NETLINK_TYPE_U32
},
184 [BOND_ARP_TARGETS_6
] = { .type
= NETLINK_TYPE_U32
},
185 [BOND_ARP_TARGETS_7
] = { .type
= NETLINK_TYPE_U32
},
186 [BOND_ARP_TARGETS_8
] = { .type
= NETLINK_TYPE_U32
},
187 [BOND_ARP_TARGETS_9
] = { .type
= NETLINK_TYPE_U32
},
188 [BOND_ARP_TARGETS_10
] = { .type
= NETLINK_TYPE_U32
},
189 [BOND_ARP_TARGETS_11
] = { .type
= NETLINK_TYPE_U32
},
190 [BOND_ARP_TARGETS_12
] = { .type
= NETLINK_TYPE_U32
},
191 [BOND_ARP_TARGETS_13
] = { .type
= NETLINK_TYPE_U32
},
192 [BOND_ARP_TARGETS_14
] = { .type
= NETLINK_TYPE_U32
},
193 [BOND_ARP_TARGETS_MAX
] = { .type
= NETLINK_TYPE_U32
},
196 static const NLTypeSystem rtnl_bond_arp_type_system
= {
197 .count
= ELEMENTSOF(rtnl_bond_arp_target_types
),
198 .types
= rtnl_bond_arp_target_types
,
201 static const NLType rtnl_link_info_data_bond_types
[] = {
202 [IFLA_BOND_MODE
] = { .type
= NETLINK_TYPE_U8
},
203 [IFLA_BOND_ACTIVE_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
204 [IFLA_BOND_MIIMON
] = { .type
= NETLINK_TYPE_U32
},
205 [IFLA_BOND_UPDELAY
] = { .type
= NETLINK_TYPE_U32
},
206 [IFLA_BOND_DOWNDELAY
] = { .type
= NETLINK_TYPE_U32
},
207 [IFLA_BOND_USE_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
208 [IFLA_BOND_ARP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
209 [IFLA_BOND_ARP_IP_TARGET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_bond_arp_type_system
},
210 [IFLA_BOND_ARP_VALIDATE
] = { .type
= NETLINK_TYPE_U32
},
211 [IFLA_BOND_ARP_ALL_TARGETS
] = { .type
= NETLINK_TYPE_U32
},
212 [IFLA_BOND_PRIMARY
] = { .type
= NETLINK_TYPE_U32
},
213 [IFLA_BOND_PRIMARY_RESELECT
] = { .type
= NETLINK_TYPE_U8
},
214 [IFLA_BOND_FAIL_OVER_MAC
] = { .type
= NETLINK_TYPE_U8
},
215 [IFLA_BOND_XMIT_HASH_POLICY
] = { .type
= NETLINK_TYPE_U8
},
216 [IFLA_BOND_RESEND_IGMP
] = { .type
= NETLINK_TYPE_U32
},
217 [IFLA_BOND_NUM_PEER_NOTIF
] = { .type
= NETLINK_TYPE_U8
},
218 [IFLA_BOND_ALL_SLAVES_ACTIVE
] = { .type
= NETLINK_TYPE_U8
},
219 [IFLA_BOND_MIN_LINKS
] = { .type
= NETLINK_TYPE_U32
},
220 [IFLA_BOND_LP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
221 [IFLA_BOND_PACKETS_PER_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
222 [IFLA_BOND_AD_LACP_RATE
] = { .type
= NETLINK_TYPE_U8
},
223 [IFLA_BOND_AD_SELECT
] = { .type
= NETLINK_TYPE_U8
},
224 [IFLA_BOND_AD_INFO
] = { .type
= NETLINK_TYPE_NESTED
},
227 static const NLType rtnl_link_info_data_iptun_types
[] = {
228 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
229 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
230 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
231 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
232 [IFLA_IPTUN_TOS
] = { .type
= NETLINK_TYPE_U8
},
233 [IFLA_IPTUN_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
234 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
235 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
236 [IFLA_IPTUN_6RD_PREFIX
] = { .type
= NETLINK_TYPE_IN_ADDR
},
237 [IFLA_IPTUN_6RD_RELAY_PREFIX
] = { .type
= NETLINK_TYPE_U32
},
238 [IFLA_IPTUN_6RD_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
239 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
240 [IFLA_IPTUN_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
241 [IFLA_IPTUN_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
242 [IFLA_IPTUN_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
243 [IFLA_IPTUN_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
246 static const NLType rtnl_link_info_data_ipgre_types
[] = {
247 [IFLA_GRE_LINK
] = { .type
= NETLINK_TYPE_U32
},
248 [IFLA_GRE_IFLAGS
] = { .type
= NETLINK_TYPE_U16
},
249 [IFLA_GRE_OFLAGS
] = { .type
= NETLINK_TYPE_U16
},
250 [IFLA_GRE_IKEY
] = { .type
= NETLINK_TYPE_U32
},
251 [IFLA_GRE_OKEY
] = { .type
= NETLINK_TYPE_U32
},
252 [IFLA_GRE_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
253 [IFLA_GRE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
254 [IFLA_GRE_TTL
] = { .type
= NETLINK_TYPE_U8
},
255 [IFLA_GRE_TOS
] = { .type
= NETLINK_TYPE_U8
},
256 [IFLA_GRE_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
257 [IFLA_GRE_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
258 [IFLA_GRE_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
259 [IFLA_GRE_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
260 [IFLA_GRE_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
261 [IFLA_GRE_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
262 [IFLA_GRE_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
265 static const NLType rtnl_link_info_data_ipvti_types
[] = {
266 [IFLA_VTI_LINK
] = { .type
= NETLINK_TYPE_U32
},
267 [IFLA_VTI_IKEY
] = { .type
= NETLINK_TYPE_U32
},
268 [IFLA_VTI_OKEY
] = { .type
= NETLINK_TYPE_U32
},
269 [IFLA_VTI_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
270 [IFLA_VTI_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
273 static const NLType rtnl_link_info_data_ip6tnl_types
[] = {
274 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
275 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
276 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
277 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
278 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
279 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
280 [IFLA_IPTUN_ENCAP_LIMIT
] = { .type
= NETLINK_TYPE_U8
},
281 [IFLA_IPTUN_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
284 static const NLType rtnl_link_info_data_vrf_types
[] = {
285 [IFLA_VRF_TABLE
] = { .type
= NETLINK_TYPE_U32
},
288 static const NLType rtnl_link_info_data_geneve_types
[] = {
289 [IFLA_GENEVE_ID
] = { .type
= NETLINK_TYPE_U32
},
290 [IFLA_GENEVE_TTL
] = { .type
= NETLINK_TYPE_U8
},
291 [IFLA_GENEVE_TOS
] = { .type
= NETLINK_TYPE_U8
},
292 [IFLA_GENEVE_PORT
] = { .type
= NETLINK_TYPE_U16
},
293 [IFLA_GENEVE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
294 [IFLA_GENEVE_REMOTE6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
295 [IFLA_GENEVE_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
296 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
297 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
298 [IFLA_GENEVE_LABEL
] = { .type
= NETLINK_TYPE_U32
},
301 static const NLType rtnl_link_info_data_can_types
[] = {
302 [IFLA_CAN_BITTIMING
] = { .size
= sizeof(struct can_bittiming
) },
303 [IFLA_CAN_RESTART_MS
] = { .type
= NETLINK_TYPE_U32
},
306 /* these strings must match the .kind entries in the kernel */
307 static const char* const nl_union_link_info_data_table
[] = {
308 [NL_UNION_LINK_INFO_DATA_BOND
] = "bond",
309 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = "bridge",
310 [NL_UNION_LINK_INFO_DATA_VLAN
] = "vlan",
311 [NL_UNION_LINK_INFO_DATA_VETH
] = "veth",
312 [NL_UNION_LINK_INFO_DATA_DUMMY
] = "dummy",
313 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = "macvlan",
314 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = "macvtap",
315 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = "ipvlan",
316 [NL_UNION_LINK_INFO_DATA_VXLAN
] = "vxlan",
317 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = "ipip",
318 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = "gre",
319 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = "gretap",
320 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = "ip6gre",
321 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = "ip6gretap",
322 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = "sit",
323 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = "vti",
324 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = "vti6",
325 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = "ip6tnl",
326 [NL_UNION_LINK_INFO_DATA_VRF
] = "vrf",
327 [NL_UNION_LINK_INFO_DATA_VCAN
] = "vcan",
328 [NL_UNION_LINK_INFO_DATA_GENEVE
] = "geneve",
329 [NL_UNION_LINK_INFO_DATA_VXCAN
] = "vxcan",
330 [NL_UNION_LINK_INFO_DATA_WIREGUARD
] = "wireguard",
331 [NL_UNION_LINK_INFO_DATA_NETDEVSIM
] = "netdevsim",
332 [NL_UNION_LINK_INFO_DATA_CAN
] = "can",
335 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data
, NLUnionLinkInfoData
);
337 static const NLTypeSystem rtnl_link_info_data_type_systems
[] = {
338 [NL_UNION_LINK_INFO_DATA_BOND
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bond_types
),
339 .types
= rtnl_link_info_data_bond_types
},
340 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bridge_types
),
341 .types
= rtnl_link_info_data_bridge_types
},
342 [NL_UNION_LINK_INFO_DATA_VLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vlan_types
),
343 .types
= rtnl_link_info_data_vlan_types
},
344 [NL_UNION_LINK_INFO_DATA_VETH
] = { .count
= ELEMENTSOF(rtnl_link_info_data_veth_types
),
345 .types
= rtnl_link_info_data_veth_types
},
346 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
347 .types
= rtnl_link_info_data_macvlan_types
},
348 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
349 .types
= rtnl_link_info_data_macvlan_types
},
350 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvlan_types
),
351 .types
= rtnl_link_info_data_ipvlan_types
},
352 [NL_UNION_LINK_INFO_DATA_VXLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vxlan_types
),
353 .types
= rtnl_link_info_data_vxlan_types
},
354 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
355 .types
= rtnl_link_info_data_iptun_types
},
356 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
357 .types
= rtnl_link_info_data_ipgre_types
},
358 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
359 .types
= rtnl_link_info_data_ipgre_types
},
360 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
361 .types
= rtnl_link_info_data_ipgre_types
},
362 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
363 .types
= rtnl_link_info_data_ipgre_types
},
364 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
365 .types
= rtnl_link_info_data_iptun_types
},
366 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
367 .types
= rtnl_link_info_data_ipvti_types
},
368 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
369 .types
= rtnl_link_info_data_ipvti_types
},
370 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ip6tnl_types
),
371 .types
= rtnl_link_info_data_ip6tnl_types
},
372 [NL_UNION_LINK_INFO_DATA_VRF
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vrf_types
),
373 .types
= rtnl_link_info_data_vrf_types
},
374 [NL_UNION_LINK_INFO_DATA_GENEVE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_geneve_types
),
375 .types
= rtnl_link_info_data_geneve_types
},
376 [NL_UNION_LINK_INFO_DATA_VXCAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vxcan_types
),
377 .types
= rtnl_link_info_data_vxcan_types
},
378 [NL_UNION_LINK_INFO_DATA_CAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_can_types
),
379 .types
= rtnl_link_info_data_can_types
},
382 static const NLTypeSystemUnion rtnl_link_info_data_type_system_union
= {
383 .num
= _NL_UNION_LINK_INFO_DATA_MAX
,
384 .lookup
= nl_union_link_info_data_from_string
,
385 .type_systems
= rtnl_link_info_data_type_systems
,
386 .match_type
= NL_MATCH_SIBLING
,
387 .match
= IFLA_INFO_KIND
,
390 static const NLType rtnl_link_info_types
[] = {
391 [IFLA_INFO_KIND
] = { .type
= NETLINK_TYPE_STRING
},
392 [IFLA_INFO_DATA
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_link_info_data_type_system_union
},
395 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
396 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
400 static const NLTypeSystem rtnl_link_info_type_system
= {
401 .count
= ELEMENTSOF(rtnl_link_info_types
),
402 .types
= rtnl_link_info_types
,
405 static const struct NLType rtnl_prot_info_bridge_port_types
[] = {
406 [IFLA_BRPORT_STATE
] = { .type
= NETLINK_TYPE_U8
},
407 [IFLA_BRPORT_COST
] = { .type
= NETLINK_TYPE_U32
},
408 [IFLA_BRPORT_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
409 [IFLA_BRPORT_MODE
] = { .type
= NETLINK_TYPE_U8
},
410 [IFLA_BRPORT_GUARD
] = { .type
= NETLINK_TYPE_U8
},
411 [IFLA_BRPORT_PROTECT
] = { .type
= NETLINK_TYPE_U8
},
412 [IFLA_BRPORT_FAST_LEAVE
] = { .type
= NETLINK_TYPE_U8
},
413 [IFLA_BRPORT_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
414 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NETLINK_TYPE_U8
},
415 [IFLA_BRPORT_PROXYARP
] = { .type
= NETLINK_TYPE_U8
},
416 [IFLA_BRPORT_LEARNING_SYNC
] = { .type
= NETLINK_TYPE_U8
},
419 static const NLTypeSystem rtnl_prot_info_type_systems
[] = {
420 [AF_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_prot_info_bridge_port_types
),
421 .types
= rtnl_prot_info_bridge_port_types
},
424 static const NLTypeSystemUnion rtnl_prot_info_type_system_union
= {
426 .type_systems
= rtnl_prot_info_type_systems
,
427 .match_type
= NL_MATCH_PROTOCOL
,
430 static const struct NLType rtnl_af_spec_inet6_types
[] = {
431 [IFLA_INET6_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
436 IFLA_INET6_CACHEINFO,
437 IFLA_INET6_ICMP6STATS,
439 [IFLA_INET6_TOKEN
] = { .type
= NETLINK_TYPE_IN_ADDR
},
440 [IFLA_INET6_ADDR_GEN_MODE
] = { .type
= NETLINK_TYPE_U8
},
443 static const NLTypeSystem rtnl_af_spec_inet6_type_system
= {
444 .count
= ELEMENTSOF(rtnl_af_spec_inet6_types
),
445 .types
= rtnl_af_spec_inet6_types
,
448 static const NLType rtnl_af_spec_types
[] = {
449 [AF_INET6
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_inet6_type_system
},
452 static const NLTypeSystem rtnl_af_spec_type_system
= {
453 .count
= ELEMENTSOF(rtnl_af_spec_types
),
454 .types
= rtnl_af_spec_types
,
457 static const NLType rtnl_link_types
[] = {
458 [IFLA_ADDRESS
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
459 [IFLA_BROADCAST
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
460 [IFLA_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
461 [IFLA_MTU
] = { .type
= NETLINK_TYPE_U32
},
462 [IFLA_LINK
] = { .type
= NETLINK_TYPE_U32
},
469 [IFLA_MASTER
] = { .type
= NETLINK_TYPE_U32
},
473 [IFLA_PROTINFO
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_prot_info_type_system_union
},
474 [IFLA_TXQLEN
] = { .type
= NETLINK_TYPE_U32
},
476 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
478 [IFLA_WEIGHT
] = { .type
= NETLINK_TYPE_U32
},
479 [IFLA_OPERSTATE
] = { .type
= NETLINK_TYPE_U8
},
480 [IFLA_LINKMODE
] = { .type
= NETLINK_TYPE_U8
},
481 [IFLA_LINKINFO
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_info_type_system
},
482 [IFLA_NET_NS_PID
] = { .type
= NETLINK_TYPE_U32
},
483 [IFLA_IFALIAS
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFALIASZ
- 1 },
486 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
488 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
489 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
491 [IFLA_AF_SPEC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_type_system
},
497 [IFLA_GROUP
] = { .type
= NETLINK_TYPE_U32
},
498 [IFLA_NET_NS_FD
] = { .type
= NETLINK_TYPE_U32
},
499 [IFLA_EXT_MASK
] = { .type
= NETLINK_TYPE_U32
},
500 [IFLA_PROMISCUITY
] = { .type
= NETLINK_TYPE_U32
},
501 [IFLA_NUM_TX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
502 [IFLA_NUM_RX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
503 [IFLA_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
505 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
509 static const NLTypeSystem rtnl_link_type_system
= {
510 .count
= ELEMENTSOF(rtnl_link_types
),
511 .types
= rtnl_link_types
,
514 /* IFA_FLAGS was defined in kernel 3.14, but we still support older
515 * kernels where IFA_MAX is lower. */
516 static const NLType rtnl_address_types
[] = {
517 [IFA_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
},
518 [IFA_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
519 [IFA_LABEL
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
520 [IFA_BROADCAST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
521 [IFA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct ifa_cacheinfo
) },
526 [IFA_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
529 static const NLTypeSystem rtnl_address_type_system
= {
530 .count
= ELEMENTSOF(rtnl_address_types
),
531 .types
= rtnl_address_types
,
534 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
536 static const NLType rtnl_route_metrics_types
[] = {
537 [RTAX_MTU
] = { .type
= NETLINK_TYPE_U32
},
538 [RTAX_WINDOW
] = { .type
= NETLINK_TYPE_U32
},
539 [RTAX_RTT
] = { .type
= NETLINK_TYPE_U32
},
540 [RTAX_RTTVAR
] = { .type
= NETLINK_TYPE_U32
},
541 [RTAX_SSTHRESH
] = { .type
= NETLINK_TYPE_U32
},
542 [RTAX_CWND
] = { .type
= NETLINK_TYPE_U32
},
543 [RTAX_ADVMSS
] = { .type
= NETLINK_TYPE_U32
},
544 [RTAX_REORDERING
] = { .type
= NETLINK_TYPE_U32
},
545 [RTAX_HOPLIMIT
] = { .type
= NETLINK_TYPE_U32
},
546 [RTAX_INITCWND
] = { .type
= NETLINK_TYPE_U32
},
547 [RTAX_FEATURES
] = { .type
= NETLINK_TYPE_U32
},
548 [RTAX_RTO_MIN
] = { .type
= NETLINK_TYPE_U32
},
549 [RTAX_INITRWND
] = { .type
= NETLINK_TYPE_U32
},
550 [RTAX_QUICKACK
] = { .type
= NETLINK_TYPE_U32
},
553 static const NLTypeSystem rtnl_route_metrics_type_system
= {
554 .count
= ELEMENTSOF(rtnl_route_metrics_types
),
555 .types
= rtnl_route_metrics_types
,
558 static const NLType rtnl_route_types
[] = {
559 [RTA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
560 [RTA_SRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
561 [RTA_IIF
] = { .type
= NETLINK_TYPE_U32
},
562 [RTA_OIF
] = { .type
= NETLINK_TYPE_U32
},
563 [RTA_GATEWAY
] = { .type
= NETLINK_TYPE_IN_ADDR
},
564 [RTA_PRIORITY
] = { .type
= NETLINK_TYPE_U32
},
565 [RTA_PREFSRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
566 [RTA_METRICS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_metrics_type_system
},
567 /* [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
569 [RTA_FLOW
] = { .type
= NETLINK_TYPE_U32
}, /* 6? */
578 [RTA_PREF
] = { .type
= NETLINK_TYPE_U8
},
583 [RTA_EXPIRES
] = { .type
= NETLINK_TYPE_U32
},
586 static const NLTypeSystem rtnl_route_type_system
= {
587 .count
= ELEMENTSOF(rtnl_route_types
),
588 .types
= rtnl_route_types
,
591 static const NLType rtnl_neigh_types
[] = {
592 [NDA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
},
593 [NDA_LLADDR
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
594 [NDA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct nda_cacheinfo
) },
595 [NDA_PROBES
] = { .type
= NETLINK_TYPE_U32
},
596 [NDA_VLAN
] = { .type
= NETLINK_TYPE_U16
},
597 [NDA_PORT
] = { .type
= NETLINK_TYPE_U16
},
598 [NDA_VNI
] = { .type
= NETLINK_TYPE_U32
},
599 [NDA_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
602 static const NLTypeSystem rtnl_neigh_type_system
= {
603 .count
= ELEMENTSOF(rtnl_neigh_types
),
604 .types
= rtnl_neigh_types
,
607 static const NLType rtnl_addrlabel_types
[] = {
608 [IFAL_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
, .size
= sizeof(struct in6_addr
) },
609 [IFAL_LABEL
] = { .type
= NETLINK_TYPE_U32
},
612 static const NLTypeSystem rtnl_addrlabel_type_system
= {
613 .count
= ELEMENTSOF(rtnl_addrlabel_types
),
614 .types
= rtnl_addrlabel_types
,
617 static const NLType rtnl_routing_policy_rule_types
[] = {
618 [FRA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
},
619 [FRA_SRC
] = { .type
= NETLINK_TYPE_IN_ADDR
},
620 [FRA_IIFNAME
] = { .type
= NETLINK_TYPE_STRING
},
621 [RTA_OIF
] = { .type
= NETLINK_TYPE_U32
},
622 [RTA_GATEWAY
] = { .type
= NETLINK_TYPE_IN_ADDR
},
623 [FRA_PRIORITY
] = { .type
= NETLINK_TYPE_U32
},
624 [FRA_FWMARK
] = { .type
= NETLINK_TYPE_U32
},
625 [FRA_FLOW
] = { .type
= NETLINK_TYPE_U32
},
626 [FRA_TUN_ID
] = { .type
= NETLINK_TYPE_U32
},
627 [FRA_SUPPRESS_IFGROUP
] = { .type
= NETLINK_TYPE_U32
},
628 [FRA_SUPPRESS_PREFIXLEN
] = { .type
= NETLINK_TYPE_U32
},
629 [FRA_TABLE
] = { .type
= NETLINK_TYPE_U32
},
630 [FRA_FWMASK
] = { .type
= NETLINK_TYPE_U32
},
631 [FRA_OIFNAME
] = { .type
= NETLINK_TYPE_STRING
},
632 [FRA_PAD
] = { .type
= NETLINK_TYPE_U32
},
633 [FRA_L3MDEV
] = { .type
= NETLINK_TYPE_U64
},
634 [FRA_UID_RANGE
] = { .size
= sizeof(struct fib_rule_uid_range
) },
637 static const NLTypeSystem rtnl_routing_policy_rule_type_system
= {
638 .count
= ELEMENTSOF(rtnl_routing_policy_rule_types
),
639 .types
= rtnl_routing_policy_rule_types
,
642 static const NLType rtnl_types
[] = {
643 [NLMSG_DONE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
, .size
= 0 },
644 [NLMSG_ERROR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
, .size
= sizeof(struct nlmsgerr
) },
645 [RTM_NEWLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
646 [RTM_DELLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
647 [RTM_GETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
648 [RTM_SETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
649 [RTM_NEWADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
650 [RTM_DELADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
651 [RTM_GETADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
652 [RTM_NEWROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
653 [RTM_DELROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
654 [RTM_GETROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
655 [RTM_NEWNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
656 [RTM_DELNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
657 [RTM_GETNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
658 [RTM_NEWADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
659 [RTM_DELADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
660 [RTM_GETADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
661 [RTM_NEWRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
662 [RTM_DELRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
663 [RTM_GETRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
666 const NLTypeSystem rtnl_type_system_root
= {
667 .count
= ELEMENTSOF(rtnl_types
),
671 static const NLType genl_wireguard_allowedip_types
[] = {
672 [WGALLOWEDIP_A_FAMILY
] = { .type
= NETLINK_TYPE_U16
},
673 [WGALLOWEDIP_A_IPADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
674 [WGALLOWEDIP_A_CIDR_MASK
] = { .type
= NETLINK_TYPE_U8
},
677 static const NLTypeSystem genl_wireguard_allowedip_type_system
= {
678 .count
= ELEMENTSOF(genl_wireguard_allowedip_types
),
679 .types
= genl_wireguard_allowedip_types
,
682 static const NLType genl_wireguard_peer_types
[] = {
683 [WGPEER_A_PUBLIC_KEY
] = { .size
= WG_KEY_LEN
},
684 [WGPEER_A_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
685 [WGPEER_A_PRESHARED_KEY
] = { .size
= WG_KEY_LEN
},
686 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
687 [WGPEER_A_ENDPOINT
] = { /* either size of sockaddr_in or sockaddr_in6 depending on address family */ },
688 [WGPEER_A_ALLOWEDIPS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_allowedip_type_system
},
691 static const NLTypeSystem genl_wireguard_peer_type_system
= {
692 .count
= ELEMENTSOF(genl_wireguard_peer_types
),
693 .types
= genl_wireguard_peer_types
,
696 static const NLType genl_wireguard_set_device_types
[] = {
697 [WGDEVICE_A_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
698 [WGDEVICE_A_IFNAME
] = { .type
= NETLINK_TYPE_STRING
},
699 [WGDEVICE_A_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
700 [WGDEVICE_A_PRIVATE_KEY
] = { .size
= WG_KEY_LEN
},
701 [WGDEVICE_A_LISTEN_PORT
] = { .type
= NETLINK_TYPE_U16
},
702 [WGDEVICE_A_FWMARK
] = { .type
= NETLINK_TYPE_U32
},
703 [WGDEVICE_A_PEERS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_peer_type_system
},
706 static const NLTypeSystem genl_wireguard_set_device_type_system
= {
707 .count
= ELEMENTSOF(genl_wireguard_set_device_types
),
708 .types
= genl_wireguard_set_device_types
,
711 static const NLType genl_wireguard_cmds
[] = {
712 [WG_CMD_SET_DEVICE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_set_device_type_system
},
715 static const NLTypeSystem genl_wireguard_type_system
= {
716 .count
= ELEMENTSOF(genl_wireguard_cmds
),
717 .types
= genl_wireguard_cmds
,
720 static const NLType genl_get_family_types
[] = {
721 [CTRL_ATTR_FAMILY_NAME
] = { .type
= NETLINK_TYPE_STRING
},
722 [CTRL_ATTR_FAMILY_ID
] = { .type
= NETLINK_TYPE_U16
},
725 static const NLTypeSystem genl_get_family_type_system
= {
726 .count
= ELEMENTSOF(genl_get_family_types
),
727 .types
= genl_get_family_types
,
730 static const NLType genl_ctrl_id_ctrl_cmds
[] = {
731 [CTRL_CMD_GETFAMILY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_get_family_type_system
},
734 static const NLTypeSystem genl_ctrl_id_ctrl_type_system
= {
735 .count
= ELEMENTSOF(genl_ctrl_id_ctrl_cmds
),
736 .types
= genl_ctrl_id_ctrl_cmds
,
739 static const NLType genl_families
[] = {
740 [SD_GENL_ID_CTRL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_ctrl_id_ctrl_type_system
},
741 [SD_GENL_WIREGUARD
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_type_system
},
744 const NLTypeSystem genl_family_type_system_root
= {
745 .count
= ELEMENTSOF(genl_families
),
746 .types
= genl_families
,
749 static const NLType genl_types
[] = {
750 [GENL_ID_CTRL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_get_family_type_system
, .size
= sizeof(struct genlmsghdr
) },
753 const NLTypeSystem genl_type_system_root
= {
754 .count
= ELEMENTSOF(genl_types
),
758 uint16_t type_get_type(const NLType
*type
) {
763 size_t type_get_size(const NLType
*type
) {
768 void type_get_type_system(const NLType
*nl_type
, const NLTypeSystem
**ret
) {
771 assert(nl_type
->type
== NETLINK_TYPE_NESTED
);
772 assert(nl_type
->type_system
);
774 *ret
= nl_type
->type_system
;
777 void type_get_type_system_union(const NLType
*nl_type
, const NLTypeSystemUnion
**ret
) {
780 assert(nl_type
->type
== NETLINK_TYPE_UNION
);
781 assert(nl_type
->type_system_union
);
783 *ret
= nl_type
->type_system_union
;
786 uint16_t type_system_get_count(const NLTypeSystem
*type_system
) {
788 return type_system
->count
;
791 const NLTypeSystem
*type_system_get_root(int protocol
) {
793 case NETLINK_GENERIC
:
794 return &genl_type_system_root
;
795 default: /* NETLINK_ROUTE: */
796 return &rtnl_type_system_root
;
800 int type_system_get_type(const NLTypeSystem
*type_system
, const NLType
**ret
, uint16_t type
) {
801 const NLType
*nl_type
;
805 assert(type_system
->types
);
807 if (type
>= type_system
->count
)
810 nl_type
= &type_system
->types
[type
];
812 if (nl_type
->type
== NETLINK_TYPE_UNSPEC
)
820 int type_system_get_type_system(const NLTypeSystem
*type_system
, const NLTypeSystem
**ret
, uint16_t type
) {
821 const NLType
*nl_type
;
826 r
= type_system_get_type(type_system
, &nl_type
, type
);
830 type_get_type_system(nl_type
, ret
);
834 int type_system_get_type_system_union(const NLTypeSystem
*type_system
, const NLTypeSystemUnion
**ret
, uint16_t type
) {
835 const NLType
*nl_type
;
840 r
= type_system_get_type(type_system
, &nl_type
, type
);
844 type_get_type_system_union(nl_type
, ret
);
848 int type_system_union_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, const char *key
) {
851 assert(type_system_union
);
852 assert(type_system_union
->match_type
== NL_MATCH_SIBLING
);
853 assert(type_system_union
->lookup
);
854 assert(type_system_union
->type_systems
);
858 type
= type_system_union
->lookup(key
);
862 assert(type
< type_system_union
->num
);
864 *ret
= &type_system_union
->type_systems
[type
];
869 int type_system_union_protocol_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, uint16_t protocol
) {
870 const NLTypeSystem
*type_system
;
872 assert(type_system_union
);
873 assert(type_system_union
->type_systems
);
874 assert(type_system_union
->match_type
== NL_MATCH_PROTOCOL
);
877 if (protocol
>= type_system_union
->num
)
880 type_system
= &type_system_union
->type_systems
[protocol
];
881 if (!type_system
->types
)