1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <netinet/in.h>
5 #include <sys/socket.h>
6 #include <linux/can/vxcan.h>
7 #include <linux/netlink.h>
8 #include <linux/rtnetlink.h>
9 #include <linux/genetlink.h>
12 #include <linux/can/netlink.h>
13 #include <linux/fib_rules.h>
14 #include <linux/fou.h>
15 #include <linux/if_addr.h>
16 #include <linux/if_addrlabel.h>
17 #include <linux/if_bridge.h>
18 #include <linux/if_link.h>
19 #include <linux/if_macsec.h>
20 #include <linux/if_tunnel.h>
21 #include <linux/l2tp.h>
22 #include <linux/nexthop.h>
23 #include <linux/nl80211.h>
24 #include <linux/pkt_sched.h>
25 #include <linux/veth.h>
26 #include <linux/wireguard.h>
28 #include "sd-netlink.h"
30 #include "generic-netlink.h"
33 #include "netlink-internal.h"
34 #include "netlink-types.h"
35 #include "string-table.h"
38 /* Maximum ARP IP target defined in kernel */
39 #define BOND_MAX_ARP_TARGETS 16
57 BOND_ARP_TARGETS_MAX
= BOND_MAX_ARP_TARGETS
,
63 const NLTypeSystem
*type_system
;
64 const NLTypeSystemUnion
*type_system_union
;
72 static const NLTypeSystem rtnl_link_type_system
;
74 static const NLType empty_types
[1] = {
75 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
78 static const NLTypeSystem empty_type_system
= {
83 static const NLType rtnl_link_info_data_veth_types
[] = {
84 [VETH_INFO_PEER
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
87 static const NLType rtnl_link_info_data_vxcan_types
[] = {
88 [VXCAN_INFO_PEER
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
91 static const NLType rtnl_link_info_data_ipvlan_types
[] = {
92 [IFLA_IPVLAN_MODE
] = { .type
= NETLINK_TYPE_U16
},
93 [IFLA_IPVLAN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
96 static const NLType rtnl_link_info_data_macvlan_types
[] = {
97 [IFLA_MACVLAN_MODE
] = { .type
= NETLINK_TYPE_U32
},
98 [IFLA_MACVLAN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
101 static const NLType rtnl_link_info_data_bridge_types
[] = {
102 [IFLA_BR_FORWARD_DELAY
] = { .type
= NETLINK_TYPE_U32
},
103 [IFLA_BR_HELLO_TIME
] = { .type
= NETLINK_TYPE_U32
},
104 [IFLA_BR_MAX_AGE
] = { .type
= NETLINK_TYPE_U32
},
105 [IFLA_BR_AGEING_TIME
] = { .type
= NETLINK_TYPE_U32
},
106 [IFLA_BR_STP_STATE
] = { .type
= NETLINK_TYPE_U32
},
107 [IFLA_BR_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
108 [IFLA_BR_VLAN_FILTERING
] = { .type
= NETLINK_TYPE_U8
},
109 [IFLA_BR_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
110 [IFLA_BR_GROUP_FWD_MASK
] = { .type
= NETLINK_TYPE_U16
},
111 [IFLA_BR_ROOT_PORT
] = { .type
= NETLINK_TYPE_U16
},
112 [IFLA_BR_ROOT_PATH_COST
] = { .type
= NETLINK_TYPE_U32
},
113 [IFLA_BR_TOPOLOGY_CHANGE
] = { .type
= NETLINK_TYPE_U8
},
114 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED
] = { .type
= NETLINK_TYPE_U8
},
115 [IFLA_BR_HELLO_TIMER
] = { .type
= NETLINK_TYPE_U16
},
116 [IFLA_BR_TCN_TIMER
] = { .type
= NETLINK_TYPE_U16
},
117 [IFLA_BR_TOPOLOGY_CHANGE_TIMER
] = { .type
= NETLINK_TYPE_U16
},
118 [IFLA_BR_GC_TIMER
] = { .type
= NETLINK_TYPE_U64
},
119 [IFLA_BR_GROUP_ADDR
] = { .type
= NETLINK_TYPE_U16
},
120 [IFLA_BR_FDB_FLUSH
] = { .type
= NETLINK_TYPE_U16
},
121 [IFLA_BR_MCAST_ROUTER
] = { .type
= NETLINK_TYPE_U8
},
122 [IFLA_BR_MCAST_SNOOPING
] = { .type
= NETLINK_TYPE_U8
},
123 [IFLA_BR_MCAST_QUERY_USE_IFADDR
] = { .type
= NETLINK_TYPE_U8
},
124 [IFLA_BR_MCAST_QUERIER
] = { .type
= NETLINK_TYPE_U8
},
125 [IFLA_BR_MCAST_HASH_ELASTICITY
] = { .type
= NETLINK_TYPE_U32
},
126 [IFLA_BR_MCAST_HASH_MAX
] = { .type
= NETLINK_TYPE_U16
},
127 [IFLA_BR_MCAST_LAST_MEMBER_CNT
] = { .type
= NETLINK_TYPE_U32
},
128 [IFLA_BR_MCAST_STARTUP_QUERY_CNT
] = { .type
= NETLINK_TYPE_U16
},
129 [IFLA_BR_MCAST_LAST_MEMBER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
130 [IFLA_BR_MCAST_MEMBERSHIP_INTVL
] = { .type
= NETLINK_TYPE_U64
},
131 [IFLA_BR_MCAST_QUERIER_INTVL
] = { .type
= NETLINK_TYPE_U64
},
132 [IFLA_BR_MCAST_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
133 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
] = { .type
= NETLINK_TYPE_U64
},
134 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL
] = { .type
= NETLINK_TYPE_U64
},
135 [IFLA_BR_NF_CALL_IPTABLES
] = { .type
= NETLINK_TYPE_U8
},
136 [IFLA_BR_NF_CALL_IP6TABLES
] = { .type
= NETLINK_TYPE_U8
},
137 [IFLA_BR_NF_CALL_ARPTABLES
] = { .type
= NETLINK_TYPE_U8
},
138 [IFLA_BR_VLAN_DEFAULT_PVID
] = { .type
= NETLINK_TYPE_U16
},
139 [IFLA_BR_MCAST_IGMP_VERSION
] = { .type
= NETLINK_TYPE_U8
},
142 static const NLType rtnl_link_info_data_vlan_types
[] = {
143 [IFLA_VLAN_ID
] = { .type
= NETLINK_TYPE_U16
},
145 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
146 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
147 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
149 [IFLA_VLAN_PROTOCOL
] = { .type
= NETLINK_TYPE_U16
},
152 static const NLType rtnl_link_info_data_vxlan_types
[] = {
153 [IFLA_VXLAN_ID
] = { .type
= NETLINK_TYPE_U32
},
154 [IFLA_VXLAN_GROUP
] = { .type
= NETLINK_TYPE_IN_ADDR
},
155 [IFLA_VXLAN_LINK
] = { .type
= NETLINK_TYPE_U32
},
156 [IFLA_VXLAN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
157 [IFLA_VXLAN_TTL
] = { .type
= NETLINK_TYPE_U8
},
158 [IFLA_VXLAN_TOS
] = { .type
= NETLINK_TYPE_U8
},
159 [IFLA_VXLAN_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
160 [IFLA_VXLAN_AGEING
] = { .type
= NETLINK_TYPE_U32
},
161 [IFLA_VXLAN_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
162 [IFLA_VXLAN_PORT_RANGE
] = { .type
= NETLINK_TYPE_U32
},
163 [IFLA_VXLAN_PROXY
] = { .type
= NETLINK_TYPE_U8
},
164 [IFLA_VXLAN_RSC
] = { .type
= NETLINK_TYPE_U8
},
165 [IFLA_VXLAN_L2MISS
] = { .type
= NETLINK_TYPE_U8
},
166 [IFLA_VXLAN_L3MISS
] = { .type
= NETLINK_TYPE_U8
},
167 [IFLA_VXLAN_PORT
] = { .type
= NETLINK_TYPE_U16
},
168 [IFLA_VXLAN_GROUP6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
169 [IFLA_VXLAN_LOCAL6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
170 [IFLA_VXLAN_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
171 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
172 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
173 [IFLA_VXLAN_REMCSUM_TX
] = { .type
= NETLINK_TYPE_U8
},
174 [IFLA_VXLAN_REMCSUM_RX
] = { .type
= NETLINK_TYPE_U8
},
175 [IFLA_VXLAN_GBP
] = { .type
= NETLINK_TYPE_FLAG
},
176 [IFLA_VXLAN_REMCSUM_NOPARTIAL
] = { .type
= NETLINK_TYPE_FLAG
},
177 [IFLA_VXLAN_COLLECT_METADATA
] = { .type
= NETLINK_TYPE_U8
},
178 [IFLA_VXLAN_LABEL
] = { .type
= NETLINK_TYPE_U32
},
179 [IFLA_VXLAN_GPE
] = { .type
= NETLINK_TYPE_FLAG
},
180 [IFLA_VXLAN_TTL_INHERIT
] = { .type
= NETLINK_TYPE_FLAG
},
181 [IFLA_VXLAN_DF
] = { .type
= NETLINK_TYPE_U8
},
184 static const NLType rtnl_bond_arp_target_types
[] = {
185 [BOND_ARP_TARGETS_0
] = { .type
= NETLINK_TYPE_U32
},
186 [BOND_ARP_TARGETS_1
] = { .type
= NETLINK_TYPE_U32
},
187 [BOND_ARP_TARGETS_2
] = { .type
= NETLINK_TYPE_U32
},
188 [BOND_ARP_TARGETS_3
] = { .type
= NETLINK_TYPE_U32
},
189 [BOND_ARP_TARGETS_4
] = { .type
= NETLINK_TYPE_U32
},
190 [BOND_ARP_TARGETS_5
] = { .type
= NETLINK_TYPE_U32
},
191 [BOND_ARP_TARGETS_6
] = { .type
= NETLINK_TYPE_U32
},
192 [BOND_ARP_TARGETS_7
] = { .type
= NETLINK_TYPE_U32
},
193 [BOND_ARP_TARGETS_8
] = { .type
= NETLINK_TYPE_U32
},
194 [BOND_ARP_TARGETS_9
] = { .type
= NETLINK_TYPE_U32
},
195 [BOND_ARP_TARGETS_10
] = { .type
= NETLINK_TYPE_U32
},
196 [BOND_ARP_TARGETS_11
] = { .type
= NETLINK_TYPE_U32
},
197 [BOND_ARP_TARGETS_12
] = { .type
= NETLINK_TYPE_U32
},
198 [BOND_ARP_TARGETS_13
] = { .type
= NETLINK_TYPE_U32
},
199 [BOND_ARP_TARGETS_14
] = { .type
= NETLINK_TYPE_U32
},
200 [BOND_ARP_TARGETS_MAX
] = { .type
= NETLINK_TYPE_U32
},
203 static const NLTypeSystem rtnl_bond_arp_type_system
= {
204 .count
= ELEMENTSOF(rtnl_bond_arp_target_types
),
205 .types
= rtnl_bond_arp_target_types
,
208 static const NLType rtnl_link_info_data_bond_types
[] = {
209 [IFLA_BOND_MODE
] = { .type
= NETLINK_TYPE_U8
},
210 [IFLA_BOND_ACTIVE_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
211 [IFLA_BOND_MIIMON
] = { .type
= NETLINK_TYPE_U32
},
212 [IFLA_BOND_UPDELAY
] = { .type
= NETLINK_TYPE_U32
},
213 [IFLA_BOND_DOWNDELAY
] = { .type
= NETLINK_TYPE_U32
},
214 [IFLA_BOND_USE_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
215 [IFLA_BOND_ARP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
216 [IFLA_BOND_ARP_IP_TARGET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_bond_arp_type_system
},
217 [IFLA_BOND_ARP_VALIDATE
] = { .type
= NETLINK_TYPE_U32
},
218 [IFLA_BOND_ARP_ALL_TARGETS
] = { .type
= NETLINK_TYPE_U32
},
219 [IFLA_BOND_PRIMARY
] = { .type
= NETLINK_TYPE_U32
},
220 [IFLA_BOND_PRIMARY_RESELECT
] = { .type
= NETLINK_TYPE_U8
},
221 [IFLA_BOND_FAIL_OVER_MAC
] = { .type
= NETLINK_TYPE_U8
},
222 [IFLA_BOND_XMIT_HASH_POLICY
] = { .type
= NETLINK_TYPE_U8
},
223 [IFLA_BOND_RESEND_IGMP
] = { .type
= NETLINK_TYPE_U32
},
224 [IFLA_BOND_NUM_PEER_NOTIF
] = { .type
= NETLINK_TYPE_U8
},
225 [IFLA_BOND_ALL_SLAVES_ACTIVE
] = { .type
= NETLINK_TYPE_U8
},
226 [IFLA_BOND_MIN_LINKS
] = { .type
= NETLINK_TYPE_U32
},
227 [IFLA_BOND_LP_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
228 [IFLA_BOND_PACKETS_PER_SLAVE
] = { .type
= NETLINK_TYPE_U32
},
229 [IFLA_BOND_AD_LACP_RATE
] = { .type
= NETLINK_TYPE_U8
},
230 [IFLA_BOND_AD_SELECT
] = { .type
= NETLINK_TYPE_U8
},
231 [IFLA_BOND_AD_INFO
] = { .type
= NETLINK_TYPE_NESTED
},
232 [IFLA_BOND_AD_ACTOR_SYS_PRIO
] = { .type
= NETLINK_TYPE_U16
},
233 [IFLA_BOND_AD_USER_PORT_KEY
] = { .type
= NETLINK_TYPE_U16
},
234 [IFLA_BOND_AD_ACTOR_SYSTEM
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
235 [IFLA_BOND_TLB_DYNAMIC_LB
] = { .type
= NETLINK_TYPE_U8
},
238 static const NLType rtnl_link_info_data_iptun_types
[] = {
239 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
240 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
241 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
242 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
243 [IFLA_IPTUN_TOS
] = { .type
= NETLINK_TYPE_U8
},
244 [IFLA_IPTUN_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
245 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
246 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
247 [IFLA_IPTUN_6RD_PREFIX
] = { .type
= NETLINK_TYPE_IN_ADDR
},
248 [IFLA_IPTUN_6RD_RELAY_PREFIX
] = { .type
= NETLINK_TYPE_U32
},
249 [IFLA_IPTUN_6RD_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
250 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN
] = { .type
= NETLINK_TYPE_U16
},
251 [IFLA_IPTUN_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
252 [IFLA_IPTUN_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
253 [IFLA_IPTUN_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
254 [IFLA_IPTUN_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
257 static const NLType rtnl_link_info_data_ipgre_types
[] = {
258 [IFLA_GRE_LINK
] = { .type
= NETLINK_TYPE_U32
},
259 [IFLA_GRE_IFLAGS
] = { .type
= NETLINK_TYPE_U16
},
260 [IFLA_GRE_OFLAGS
] = { .type
= NETLINK_TYPE_U16
},
261 [IFLA_GRE_IKEY
] = { .type
= NETLINK_TYPE_U32
},
262 [IFLA_GRE_OKEY
] = { .type
= NETLINK_TYPE_U32
},
263 [IFLA_GRE_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
264 [IFLA_GRE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
265 [IFLA_GRE_TTL
] = { .type
= NETLINK_TYPE_U8
},
266 [IFLA_GRE_TOS
] = { .type
= NETLINK_TYPE_U8
},
267 [IFLA_GRE_PMTUDISC
] = { .type
= NETLINK_TYPE_U8
},
268 [IFLA_GRE_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
269 [IFLA_GRE_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
270 [IFLA_GRE_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
271 [IFLA_GRE_ENCAP_FLAGS
] = { .type
= NETLINK_TYPE_U16
},
272 [IFLA_GRE_ENCAP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
273 [IFLA_GRE_ENCAP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
274 [IFLA_GRE_ERSPAN_INDEX
] = { .type
= NETLINK_TYPE_U32
},
277 static const NLType rtnl_link_info_data_ipvti_types
[] = {
278 [IFLA_VTI_LINK
] = { .type
= NETLINK_TYPE_U32
},
279 [IFLA_VTI_IKEY
] = { .type
= NETLINK_TYPE_U32
},
280 [IFLA_VTI_OKEY
] = { .type
= NETLINK_TYPE_U32
},
281 [IFLA_VTI_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
282 [IFLA_VTI_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
285 static const NLType rtnl_link_info_data_ip6tnl_types
[] = {
286 [IFLA_IPTUN_LINK
] = { .type
= NETLINK_TYPE_U32
},
287 [IFLA_IPTUN_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
288 [IFLA_IPTUN_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
289 [IFLA_IPTUN_TTL
] = { .type
= NETLINK_TYPE_U8
},
290 [IFLA_IPTUN_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
291 [IFLA_IPTUN_PROTO
] = { .type
= NETLINK_TYPE_U8
},
292 [IFLA_IPTUN_ENCAP_LIMIT
] = { .type
= NETLINK_TYPE_U8
},
293 [IFLA_IPTUN_FLOWINFO
] = { .type
= NETLINK_TYPE_U32
},
296 static const NLType rtnl_link_info_data_vrf_types
[] = {
297 [IFLA_VRF_TABLE
] = { .type
= NETLINK_TYPE_U32
},
300 static const NLType rtnl_link_info_data_geneve_types
[] = {
301 [IFLA_GENEVE_ID
] = { .type
= NETLINK_TYPE_U32
},
302 [IFLA_GENEVE_TTL
] = { .type
= NETLINK_TYPE_U8
},
303 [IFLA_GENEVE_TOS
] = { .type
= NETLINK_TYPE_U8
},
304 [IFLA_GENEVE_PORT
] = { .type
= NETLINK_TYPE_U16
},
305 [IFLA_GENEVE_REMOTE
] = { .type
= NETLINK_TYPE_IN_ADDR
},
306 [IFLA_GENEVE_REMOTE6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
307 [IFLA_GENEVE_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
308 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_U8
},
309 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_U8
},
310 [IFLA_GENEVE_LABEL
] = { .type
= NETLINK_TYPE_U32
},
311 [IFLA_GENEVE_TTL_INHERIT
] = { .type
= NETLINK_TYPE_U8
},
312 [IFLA_GENEVE_DF
] = { .type
= NETLINK_TYPE_U8
},
315 static const NLType rtnl_link_info_data_can_types
[] = {
316 [IFLA_CAN_BITTIMING
] = { .size
= sizeof(struct can_bittiming
) },
317 [IFLA_CAN_RESTART_MS
] = { .type
= NETLINK_TYPE_U32
},
318 [IFLA_CAN_CTRLMODE
] = { .size
= sizeof(struct can_ctrlmode
) },
319 [IFLA_CAN_TERMINATION
] = { .type
= NETLINK_TYPE_U16
},
322 static const NLType rtnl_link_info_data_macsec_types
[] = {
323 [IFLA_MACSEC_SCI
] = { .type
= NETLINK_TYPE_U64
},
324 [IFLA_MACSEC_PORT
] = { .type
= NETLINK_TYPE_U16
},
325 [IFLA_MACSEC_ICV_LEN
] = { .type
= NETLINK_TYPE_U8
},
326 [IFLA_MACSEC_CIPHER_SUITE
] = { .type
= NETLINK_TYPE_U64
},
327 [IFLA_MACSEC_WINDOW
] = { .type
= NETLINK_TYPE_U32
},
328 [IFLA_MACSEC_ENCODING_SA
] = { .type
= NETLINK_TYPE_U8
},
329 [IFLA_MACSEC_ENCRYPT
] = { .type
= NETLINK_TYPE_U8
},
330 [IFLA_MACSEC_PROTECT
] = { .type
= NETLINK_TYPE_U8
},
331 [IFLA_MACSEC_INC_SCI
] = { .type
= NETLINK_TYPE_U8
},
332 [IFLA_MACSEC_ES
] = { .type
= NETLINK_TYPE_U8
},
333 [IFLA_MACSEC_SCB
] = { .type
= NETLINK_TYPE_U8
},
334 [IFLA_MACSEC_REPLAY_PROTECT
] = { .type
= NETLINK_TYPE_U8
},
335 [IFLA_MACSEC_VALIDATION
] = { .type
= NETLINK_TYPE_U8
},
338 static const NLType rtnl_link_info_data_xfrm_types
[] = {
339 [IFLA_XFRM_LINK
] = { .type
= NETLINK_TYPE_U32
},
340 [IFLA_XFRM_IF_ID
] = { .type
= NETLINK_TYPE_U32
}
343 /* these strings must match the .kind entries in the kernel */
344 static const char* const nl_union_link_info_data_table
[] = {
345 [NL_UNION_LINK_INFO_DATA_BOND
] = "bond",
346 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = "bridge",
347 [NL_UNION_LINK_INFO_DATA_VLAN
] = "vlan",
348 [NL_UNION_LINK_INFO_DATA_VETH
] = "veth",
349 [NL_UNION_LINK_INFO_DATA_DUMMY
] = "dummy",
350 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = "macvlan",
351 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = "macvtap",
352 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = "ipvlan",
353 [NL_UNION_LINK_INFO_DATA_IPVTAP
] = "ipvtap",
354 [NL_UNION_LINK_INFO_DATA_VXLAN
] = "vxlan",
355 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = "ipip",
356 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = "gre",
357 [NL_UNION_LINK_INFO_DATA_ERSPAN
] = "erspan",
358 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = "gretap",
359 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = "ip6gre",
360 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = "ip6gretap",
361 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = "sit",
362 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = "vti",
363 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = "vti6",
364 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = "ip6tnl",
365 [NL_UNION_LINK_INFO_DATA_VRF
] = "vrf",
366 [NL_UNION_LINK_INFO_DATA_VCAN
] = "vcan",
367 [NL_UNION_LINK_INFO_DATA_GENEVE
] = "geneve",
368 [NL_UNION_LINK_INFO_DATA_VXCAN
] = "vxcan",
369 [NL_UNION_LINK_INFO_DATA_WIREGUARD
] = "wireguard",
370 [NL_UNION_LINK_INFO_DATA_NETDEVSIM
] = "netdevsim",
371 [NL_UNION_LINK_INFO_DATA_CAN
] = "can",
372 [NL_UNION_LINK_INFO_DATA_MACSEC
] = "macsec",
373 [NL_UNION_LINK_INFO_DATA_NLMON
] = "nlmon",
374 [NL_UNION_LINK_INFO_DATA_XFRM
] = "xfrm",
375 [NL_UNION_LINK_INFO_DATA_IFB
] = "ifb",
378 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data
, NLUnionLinkInfoData
);
380 static const NLTypeSystem rtnl_link_info_data_type_systems
[] = {
381 [NL_UNION_LINK_INFO_DATA_BOND
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bond_types
),
382 .types
= rtnl_link_info_data_bond_types
},
383 [NL_UNION_LINK_INFO_DATA_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_bridge_types
),
384 .types
= rtnl_link_info_data_bridge_types
},
385 [NL_UNION_LINK_INFO_DATA_VLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vlan_types
),
386 .types
= rtnl_link_info_data_vlan_types
},
387 [NL_UNION_LINK_INFO_DATA_VETH
] = { .count
= ELEMENTSOF(rtnl_link_info_data_veth_types
),
388 .types
= rtnl_link_info_data_veth_types
},
389 [NL_UNION_LINK_INFO_DATA_MACVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
390 .types
= rtnl_link_info_data_macvlan_types
},
391 [NL_UNION_LINK_INFO_DATA_MACVTAP
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macvlan_types
),
392 .types
= rtnl_link_info_data_macvlan_types
},
393 [NL_UNION_LINK_INFO_DATA_IPVLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvlan_types
),
394 .types
= rtnl_link_info_data_ipvlan_types
},
395 [NL_UNION_LINK_INFO_DATA_IPVTAP
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvlan_types
),
396 .types
= rtnl_link_info_data_ipvlan_types
},
397 [NL_UNION_LINK_INFO_DATA_VXLAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vxlan_types
),
398 .types
= rtnl_link_info_data_vxlan_types
},
399 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
400 .types
= rtnl_link_info_data_iptun_types
},
401 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
402 .types
= rtnl_link_info_data_ipgre_types
},
403 [NL_UNION_LINK_INFO_DATA_ERSPAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
404 .types
= rtnl_link_info_data_ipgre_types
},
405 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
406 .types
= rtnl_link_info_data_ipgre_types
},
407 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
408 .types
= rtnl_link_info_data_ipgre_types
},
409 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipgre_types
),
410 .types
= rtnl_link_info_data_ipgre_types
},
411 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_iptun_types
),
412 .types
= rtnl_link_info_data_iptun_types
},
413 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
414 .types
= rtnl_link_info_data_ipvti_types
},
415 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ipvti_types
),
416 .types
= rtnl_link_info_data_ipvti_types
},
417 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL
] = { .count
= ELEMENTSOF(rtnl_link_info_data_ip6tnl_types
),
418 .types
= rtnl_link_info_data_ip6tnl_types
},
419 [NL_UNION_LINK_INFO_DATA_VRF
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vrf_types
),
420 .types
= rtnl_link_info_data_vrf_types
},
421 [NL_UNION_LINK_INFO_DATA_GENEVE
] = { .count
= ELEMENTSOF(rtnl_link_info_data_geneve_types
),
422 .types
= rtnl_link_info_data_geneve_types
},
423 [NL_UNION_LINK_INFO_DATA_VXCAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_vxcan_types
),
424 .types
= rtnl_link_info_data_vxcan_types
},
425 [NL_UNION_LINK_INFO_DATA_CAN
] = { .count
= ELEMENTSOF(rtnl_link_info_data_can_types
),
426 .types
= rtnl_link_info_data_can_types
},
427 [NL_UNION_LINK_INFO_DATA_MACSEC
] = { .count
= ELEMENTSOF(rtnl_link_info_data_macsec_types
),
428 .types
= rtnl_link_info_data_macsec_types
},
429 [NL_UNION_LINK_INFO_DATA_XFRM
] = { .count
= ELEMENTSOF(rtnl_link_info_data_xfrm_types
),
430 .types
= rtnl_link_info_data_xfrm_types
},
433 static const NLTypeSystemUnion rtnl_link_info_data_type_system_union
= {
434 .num
= _NL_UNION_LINK_INFO_DATA_MAX
,
435 .lookup
= nl_union_link_info_data_from_string
,
436 .type_systems
= rtnl_link_info_data_type_systems
,
437 .match_type
= NL_MATCH_SIBLING
,
438 .match
= IFLA_INFO_KIND
,
441 static const NLType rtnl_link_info_types
[] = {
442 [IFLA_INFO_KIND
] = { .type
= NETLINK_TYPE_STRING
},
443 [IFLA_INFO_DATA
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_link_info_data_type_system_union
},
446 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
447 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
451 static const NLTypeSystem rtnl_link_info_type_system
= {
452 .count
= ELEMENTSOF(rtnl_link_info_types
),
453 .types
= rtnl_link_info_types
,
456 static const struct NLType rtnl_prot_info_bridge_port_types
[] = {
457 [IFLA_BRPORT_STATE
] = { .type
= NETLINK_TYPE_U8
},
458 [IFLA_BRPORT_COST
] = { .type
= NETLINK_TYPE_U32
},
459 [IFLA_BRPORT_PRIORITY
] = { .type
= NETLINK_TYPE_U16
},
460 [IFLA_BRPORT_MODE
] = { .type
= NETLINK_TYPE_U8
},
461 [IFLA_BRPORT_GUARD
] = { .type
= NETLINK_TYPE_U8
},
462 [IFLA_BRPORT_PROTECT
] = { .type
= NETLINK_TYPE_U8
},
463 [IFLA_BRPORT_FAST_LEAVE
] = { .type
= NETLINK_TYPE_U8
},
464 [IFLA_BRPORT_LEARNING
] = { .type
= NETLINK_TYPE_U8
},
465 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NETLINK_TYPE_U8
},
466 [IFLA_BRPORT_PROXYARP
] = { .type
= NETLINK_TYPE_U8
},
467 [IFLA_BRPORT_LEARNING_SYNC
] = { .type
= NETLINK_TYPE_U8
},
468 [IFLA_BRPORT_PROXYARP_WIFI
] = { .type
= NETLINK_TYPE_U8
},
469 [IFLA_BRPORT_ROOT_ID
] = { .type
= NETLINK_TYPE_U8
},
470 [IFLA_BRPORT_BRIDGE_ID
] = { .type
= NETLINK_TYPE_U8
},
471 [IFLA_BRPORT_DESIGNATED_PORT
] = { .type
= NETLINK_TYPE_U16
},
472 [IFLA_BRPORT_DESIGNATED_COST
] = { .type
= NETLINK_TYPE_U16
},
473 [IFLA_BRPORT_ID
] = { .type
= NETLINK_TYPE_U16
},
474 [IFLA_BRPORT_NO
] = { .type
= NETLINK_TYPE_U16
},
475 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
] = { .type
= NETLINK_TYPE_U8
},
476 [IFLA_BRPORT_CONFIG_PENDING
] = { .type
= NETLINK_TYPE_U8
},
477 [IFLA_BRPORT_MESSAGE_AGE_TIMER
] = { .type
= NETLINK_TYPE_U64
},
478 [IFLA_BRPORT_FORWARD_DELAY_TIMER
] = { .type
= NETLINK_TYPE_U64
},
479 [IFLA_BRPORT_HOLD_TIMER
] = { .type
= NETLINK_TYPE_U64
},
480 [IFLA_BRPORT_FLUSH
] = { .type
= NETLINK_TYPE_U8
},
481 [IFLA_BRPORT_MULTICAST_ROUTER
] = { .type
= NETLINK_TYPE_U8
},
482 [IFLA_BRPORT_PAD
] = { .type
= NETLINK_TYPE_U8
},
483 [IFLA_BRPORT_MCAST_FLOOD
] = { .type
= NETLINK_TYPE_U8
},
484 [IFLA_BRPORT_MCAST_TO_UCAST
] = { .type
= NETLINK_TYPE_U8
},
485 [IFLA_BRPORT_VLAN_TUNNEL
] = { .type
= NETLINK_TYPE_U8
},
486 [IFLA_BRPORT_BCAST_FLOOD
] = { .type
= NETLINK_TYPE_U8
},
487 [IFLA_BRPORT_GROUP_FWD_MASK
] = { .type
= NETLINK_TYPE_U16
},
488 [IFLA_BRPORT_NEIGH_SUPPRESS
] = { .type
= NETLINK_TYPE_U8
},
489 [IFLA_BRPORT_ISOLATED
] = { .type
= NETLINK_TYPE_U8
},
490 [IFLA_BRPORT_BACKUP_PORT
] = { .type
= NETLINK_TYPE_U32
},
493 static const NLTypeSystem rtnl_prot_info_type_systems
[] = {
494 [AF_BRIDGE
] = { .count
= ELEMENTSOF(rtnl_prot_info_bridge_port_types
),
495 .types
= rtnl_prot_info_bridge_port_types
},
498 static const NLTypeSystemUnion rtnl_prot_info_type_system_union
= {
500 .type_systems
= rtnl_prot_info_type_systems
,
501 .match_type
= NL_MATCH_PROTOCOL
,
504 static const struct NLType rtnl_af_spec_inet6_types
[] = {
505 [IFLA_INET6_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
510 IFLA_INET6_CACHEINFO,
511 IFLA_INET6_ICMP6STATS,
513 [IFLA_INET6_TOKEN
] = { .type
= NETLINK_TYPE_IN_ADDR
},
514 [IFLA_INET6_ADDR_GEN_MODE
] = { .type
= NETLINK_TYPE_U8
},
517 static const NLTypeSystem rtnl_af_spec_inet6_type_system
= {
518 .count
= ELEMENTSOF(rtnl_af_spec_inet6_types
),
519 .types
= rtnl_af_spec_inet6_types
,
522 static const NLType rtnl_af_spec_types
[] = {
523 [AF_INET6
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_inet6_type_system
},
526 static const NLTypeSystem rtnl_af_spec_type_system
= {
527 .count
= ELEMENTSOF(rtnl_af_spec_types
),
528 .types
= rtnl_af_spec_types
,
531 static const NLType rtnl_prop_list_types
[] = {
532 [IFLA_ALT_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= ALTIFNAMSIZ
- 1 },
535 static const NLTypeSystem rtnl_prop_list_type_system
= {
536 .count
= ELEMENTSOF(rtnl_prop_list_types
),
537 .types
= rtnl_prop_list_types
,
540 static const NLType rtnl_link_types
[] = {
541 [IFLA_ADDRESS
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
542 [IFLA_BROADCAST
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
543 [IFLA_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
544 [IFLA_MTU
] = { .type
= NETLINK_TYPE_U32
},
545 [IFLA_LINK
] = { .type
= NETLINK_TYPE_U32
},
546 [IFLA_QDISC
] = { .type
= NETLINK_TYPE_STRING
},
547 [IFLA_STATS
] = { .size
= sizeof(struct rtnl_link_stats
) },
552 [IFLA_MASTER
] = { .type
= NETLINK_TYPE_U32
},
556 [IFLA_PROTINFO
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_prot_info_type_system_union
},
557 [IFLA_TXQLEN
] = { .type
= NETLINK_TYPE_U32
},
559 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
561 [IFLA_WEIGHT
] = { .type
= NETLINK_TYPE_U32
},
562 [IFLA_OPERSTATE
] = { .type
= NETLINK_TYPE_U8
},
563 [IFLA_LINKMODE
] = { .type
= NETLINK_TYPE_U8
},
564 [IFLA_LINKINFO
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_info_type_system
},
565 [IFLA_NET_NS_PID
] = { .type
= NETLINK_TYPE_U32
},
566 [IFLA_IFALIAS
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFALIASZ
- 1 },
569 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
571 [IFLA_STATS64
] = { .size
= sizeof(struct rtnl_link_stats64
) },
573 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
574 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
576 [IFLA_AF_SPEC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_af_spec_type_system
},
582 [IFLA_GROUP
] = { .type
= NETLINK_TYPE_U32
},
583 [IFLA_NET_NS_FD
] = { .type
= NETLINK_TYPE_U32
},
584 [IFLA_EXT_MASK
] = { .type
= NETLINK_TYPE_U32
},
585 [IFLA_PROMISCUITY
] = { .type
= NETLINK_TYPE_U32
},
586 [IFLA_NUM_TX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
587 [IFLA_NUM_RX_QUEUES
] = { .type
= NETLINK_TYPE_U32
},
588 [IFLA_CARRIER
] = { .type
= NETLINK_TYPE_U8
},
590 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
592 [IFLA_MIN_MTU
] = { .type
= NETLINK_TYPE_U32
},
593 [IFLA_MAX_MTU
] = { .type
= NETLINK_TYPE_U32
},
594 [IFLA_PROP_LIST
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_prop_list_type_system
},
595 [IFLA_ALT_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= ALTIFNAMSIZ
- 1 },
598 static const NLTypeSystem rtnl_link_type_system
= {
599 .count
= ELEMENTSOF(rtnl_link_types
),
600 .types
= rtnl_link_types
,
603 /* IFA_FLAGS was defined in kernel 3.14, but we still support older
604 * kernels where IFA_MAX is lower. */
605 static const NLType rtnl_address_types
[] = {
606 [IFA_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
},
607 [IFA_LOCAL
] = { .type
= NETLINK_TYPE_IN_ADDR
},
608 [IFA_LABEL
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
- 1 },
609 [IFA_BROADCAST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
610 [IFA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct ifa_cacheinfo
) },
615 [IFA_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
618 static const NLTypeSystem rtnl_address_type_system
= {
619 .count
= ELEMENTSOF(rtnl_address_types
),
620 .types
= rtnl_address_types
,
623 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
625 static const NLType rtnl_route_metrics_types
[] = {
626 [RTAX_MTU
] = { .type
= NETLINK_TYPE_U32
},
627 [RTAX_WINDOW
] = { .type
= NETLINK_TYPE_U32
},
628 [RTAX_RTT
] = { .type
= NETLINK_TYPE_U32
},
629 [RTAX_RTTVAR
] = { .type
= NETLINK_TYPE_U32
},
630 [RTAX_SSTHRESH
] = { .type
= NETLINK_TYPE_U32
},
631 [RTAX_CWND
] = { .type
= NETLINK_TYPE_U32
},
632 [RTAX_ADVMSS
] = { .type
= NETLINK_TYPE_U32
},
633 [RTAX_REORDERING
] = { .type
= NETLINK_TYPE_U32
},
634 [RTAX_HOPLIMIT
] = { .type
= NETLINK_TYPE_U32
},
635 [RTAX_INITCWND
] = { .type
= NETLINK_TYPE_U32
},
636 [RTAX_FEATURES
] = { .type
= NETLINK_TYPE_U32
},
637 [RTAX_RTO_MIN
] = { .type
= NETLINK_TYPE_U32
},
638 [RTAX_INITRWND
] = { .type
= NETLINK_TYPE_U32
},
639 [RTAX_QUICKACK
] = { .type
= NETLINK_TYPE_U32
},
640 [RTAX_CC_ALGO
] = { .type
= NETLINK_TYPE_U32
},
641 [RTAX_FASTOPEN_NO_COOKIE
] = { .type
= NETLINK_TYPE_U32
},
644 static const NLTypeSystem rtnl_route_metrics_type_system
= {
645 .count
= ELEMENTSOF(rtnl_route_metrics_types
),
646 .types
= rtnl_route_metrics_types
,
649 static const NLType rtnl_route_types
[] = {
650 [RTA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
651 [RTA_SRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
652 [RTA_IIF
] = { .type
= NETLINK_TYPE_U32
},
653 [RTA_OIF
] = { .type
= NETLINK_TYPE_U32
},
654 [RTA_GATEWAY
] = { .type
= NETLINK_TYPE_IN_ADDR
},
655 [RTA_PRIORITY
] = { .type
= NETLINK_TYPE_U32
},
656 [RTA_PREFSRC
] = { .type
= NETLINK_TYPE_IN_ADDR
}, /* 6? */
657 [RTA_METRICS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_metrics_type_system
},
658 [RTA_MULTIPATH
] = { .size
= sizeof(struct rtnexthop
) },
659 [RTA_FLOW
] = { .type
= NETLINK_TYPE_U32
}, /* 6? */
660 [RTA_CACHEINFO
] = { .size
= sizeof(struct rta_cacheinfo
) },
661 [RTA_TABLE
] = { .type
= NETLINK_TYPE_U32
},
662 [RTA_MARK
] = { .type
= NETLINK_TYPE_U32
},
663 [RTA_MFC_STATS
] = { .type
= NETLINK_TYPE_U64
},
664 [RTA_VIA
] = { .type
= NETLINK_TYPE_U32
},
665 [RTA_NEWDST
] = { .type
= NETLINK_TYPE_U32
},
666 [RTA_PREF
] = { .type
= NETLINK_TYPE_U8
},
667 [RTA_EXPIRES
] = { .type
= NETLINK_TYPE_U32
},
668 [RTA_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
669 [RTA_ENCAP
] = { .type
= NETLINK_TYPE_NESTED
}, /* Multiple type systems i.e. LWTUNNEL_ENCAP_MPLS/LWTUNNEL_ENCAP_IP/LWTUNNEL_ENCAP_ILA etc... */
670 [RTA_UID
] = { .type
= NETLINK_TYPE_U32
},
671 [RTA_TTL_PROPAGATE
] = { .type
= NETLINK_TYPE_U8
},
672 [RTA_IP_PROTO
] = { .type
= NETLINK_TYPE_U8
},
673 [RTA_SPORT
] = { .type
= NETLINK_TYPE_U16
},
674 [RTA_DPORT
] = { .type
= NETLINK_TYPE_U16
},
677 static const NLTypeSystem rtnl_route_type_system
= {
678 .count
= ELEMENTSOF(rtnl_route_types
),
679 .types
= rtnl_route_types
,
682 static const NLType rtnl_neigh_types
[] = {
683 [NDA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
},
684 [NDA_LLADDR
] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
685 [NDA_CACHEINFO
] = { .type
= NETLINK_TYPE_CACHE_INFO
, .size
= sizeof(struct nda_cacheinfo
) },
686 [NDA_PROBES
] = { .type
= NETLINK_TYPE_U32
},
687 [NDA_VLAN
] = { .type
= NETLINK_TYPE_U16
},
688 [NDA_PORT
] = { .type
= NETLINK_TYPE_U16
},
689 [NDA_VNI
] = { .type
= NETLINK_TYPE_U32
},
690 [NDA_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
693 static const NLTypeSystem rtnl_neigh_type_system
= {
694 .count
= ELEMENTSOF(rtnl_neigh_types
),
695 .types
= rtnl_neigh_types
,
698 static const NLType rtnl_addrlabel_types
[] = {
699 [IFAL_ADDRESS
] = { .type
= NETLINK_TYPE_IN_ADDR
, .size
= sizeof(struct in6_addr
) },
700 [IFAL_LABEL
] = { .type
= NETLINK_TYPE_U32
},
703 static const NLTypeSystem rtnl_addrlabel_type_system
= {
704 .count
= ELEMENTSOF(rtnl_addrlabel_types
),
705 .types
= rtnl_addrlabel_types
,
708 static const NLType rtnl_routing_policy_rule_types
[] = {
709 [FRA_DST
] = { .type
= NETLINK_TYPE_IN_ADDR
},
710 [FRA_SRC
] = { .type
= NETLINK_TYPE_IN_ADDR
},
711 [FRA_IIFNAME
] = { .type
= NETLINK_TYPE_STRING
},
712 [FRA_GOTO
] = { .type
= NETLINK_TYPE_U32
},
713 [FRA_PRIORITY
] = { .type
= NETLINK_TYPE_U32
},
714 [FRA_FWMARK
] = { .type
= NETLINK_TYPE_U32
},
715 [FRA_FLOW
] = { .type
= NETLINK_TYPE_U32
},
716 [FRA_TUN_ID
] = { .type
= NETLINK_TYPE_U64
},
717 [FRA_SUPPRESS_IFGROUP
] = { .type
= NETLINK_TYPE_U32
},
718 [FRA_SUPPRESS_PREFIXLEN
] = { .type
= NETLINK_TYPE_U32
},
719 [FRA_TABLE
] = { .type
= NETLINK_TYPE_U32
},
720 [FRA_FWMASK
] = { .type
= NETLINK_TYPE_U32
},
721 [FRA_OIFNAME
] = { .type
= NETLINK_TYPE_STRING
},
722 [FRA_PAD
] = { .type
= NETLINK_TYPE_U32
},
723 [FRA_L3MDEV
] = { .type
= NETLINK_TYPE_U8
},
724 [FRA_UID_RANGE
] = { .size
= sizeof(struct fib_rule_uid_range
) },
725 [FRA_PROTOCOL
] = { .type
= NETLINK_TYPE_U8
},
726 [FRA_IP_PROTO
] = { .type
= NETLINK_TYPE_U8
},
727 [FRA_SPORT_RANGE
] = { .size
= sizeof(struct fib_rule_port_range
) },
728 [FRA_DPORT_RANGE
] = { .size
= sizeof(struct fib_rule_port_range
) },
731 static const NLTypeSystem rtnl_routing_policy_rule_type_system
= {
732 .count
= ELEMENTSOF(rtnl_routing_policy_rule_types
),
733 .types
= rtnl_routing_policy_rule_types
,
736 static const NLType rtnl_nexthop_types
[] = {
737 [NHA_ID
] = { .type
= NETLINK_TYPE_U32
},
738 [NHA_OIF
] = { .type
= NETLINK_TYPE_U32
},
739 [NHA_GATEWAY
] = { .type
= NETLINK_TYPE_IN_ADDR
},
742 static const NLTypeSystem rtnl_nexthop_type_system
= {
743 .count
= ELEMENTSOF(rtnl_nexthop_types
),
744 .types
= rtnl_nexthop_types
,
747 static const NLType rtnl_tca_option_data_cake_types
[] = {
748 [TCA_CAKE_BASE_RATE64
] = { .type
= NETLINK_TYPE_U64
},
749 [TCA_CAKE_OVERHEAD
] = { .type
= NETLINK_TYPE_S32
},
750 [TCA_CAKE_MPU
] = { .type
= NETLINK_TYPE_U32
},
753 static const NLType rtnl_tca_option_data_codel_types
[] = {
754 [TCA_CODEL_TARGET
] = { .type
= NETLINK_TYPE_U32
},
755 [TCA_CODEL_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
756 [TCA_CODEL_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
757 [TCA_CODEL_ECN
] = { .type
= NETLINK_TYPE_U32
},
758 [TCA_CODEL_CE_THRESHOLD
] = { .type
= NETLINK_TYPE_U32
},
761 static const NLType rtnl_tca_option_data_drr_types
[] = {
762 [TCA_DRR_QUANTUM
] = { .type
= NETLINK_TYPE_U32
},
765 static const NLType rtnl_tca_option_data_fq_types
[] = {
766 [TCA_FQ_PLIMIT
] = { .type
= NETLINK_TYPE_U32
},
767 [TCA_FQ_FLOW_PLIMIT
] = { .type
= NETLINK_TYPE_U32
},
768 [TCA_FQ_QUANTUM
] = { .type
= NETLINK_TYPE_U32
},
769 [TCA_FQ_INITIAL_QUANTUM
] = { .type
= NETLINK_TYPE_U32
},
770 [TCA_FQ_RATE_ENABLE
] = { .type
= NETLINK_TYPE_U32
},
771 [TCA_FQ_FLOW_DEFAULT_RATE
] = { .type
= NETLINK_TYPE_U32
},
772 [TCA_FQ_FLOW_MAX_RATE
] = { .type
= NETLINK_TYPE_U32
},
773 [TCA_FQ_BUCKETS_LOG
] = { .type
= NETLINK_TYPE_U32
},
774 [TCA_FQ_FLOW_REFILL_DELAY
] = { .type
= NETLINK_TYPE_U32
},
775 [TCA_FQ_LOW_RATE_THRESHOLD
] = { .type
= NETLINK_TYPE_U32
},
776 [TCA_FQ_CE_THRESHOLD
] = { .type
= NETLINK_TYPE_U32
},
777 [TCA_FQ_ORPHAN_MASK
] = { .type
= NETLINK_TYPE_U32
},
780 static const NLType rtnl_tca_option_data_fq_codel_types
[] = {
781 [TCA_FQ_CODEL_TARGET
] = { .type
= NETLINK_TYPE_U32
},
782 [TCA_FQ_CODEL_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
783 [TCA_FQ_CODEL_INTERVAL
] = { .type
= NETLINK_TYPE_U32
},
784 [TCA_FQ_CODEL_ECN
] = { .type
= NETLINK_TYPE_U32
},
785 [TCA_FQ_CODEL_FLOWS
] = { .type
= NETLINK_TYPE_U32
},
786 [TCA_FQ_CODEL_QUANTUM
] = { .type
= NETLINK_TYPE_U32
},
787 [TCA_FQ_CODEL_CE_THRESHOLD
] = { .type
= NETLINK_TYPE_U32
},
788 [TCA_FQ_CODEL_DROP_BATCH_SIZE
] = { .type
= NETLINK_TYPE_U32
},
789 [TCA_FQ_CODEL_MEMORY_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
792 static const NLType rtnl_tca_option_data_gred_types
[] = {
793 [TCA_GRED_DPS
] = { .size
= sizeof(struct tc_gred_sopt
) },
796 static const NLType rtnl_tca_option_data_hhf_types
[] = {
797 [TCA_HHF_BACKLOG_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
800 static const NLType rtnl_tca_option_data_htb_types
[] = {
801 [TCA_HTB_PARMS
] = { .size
= sizeof(struct tc_htb_opt
) },
802 [TCA_HTB_INIT
] = { .size
= sizeof(struct tc_htb_glob
) },
803 [TCA_HTB_CTAB
] = { .size
= TC_RTAB_SIZE
},
804 [TCA_HTB_RTAB
] = { .size
= TC_RTAB_SIZE
},
805 [TCA_HTB_RATE64
] = { .type
= NETLINK_TYPE_U64
},
806 [TCA_HTB_CEIL64
] = { .type
= NETLINK_TYPE_U64
},
809 static const NLType rtnl_tca_option_data_pie_types
[] = {
810 [TCA_PIE_LIMIT
] = { .type
= NETLINK_TYPE_U32
},
813 static const NLType rtnl_tca_option_data_qfq_types
[] = {
814 [TCA_QFQ_WEIGHT
] = { .type
= NETLINK_TYPE_U32
},
815 [TCA_QFQ_LMAX
] = { .type
= NETLINK_TYPE_U32
},
818 static const NLType rtnl_tca_option_data_sfb_types
[] = {
819 [TCA_SFB_PARMS
] = { .size
= sizeof(struct tc_sfb_qopt
) },
822 static const NLType rtnl_tca_option_data_tbf_types
[] = {
823 [TCA_TBF_PARMS
] = { .size
= sizeof(struct tc_tbf_qopt
) },
824 [TCA_TBF_RTAB
] = { .size
= TC_RTAB_SIZE
},
825 [TCA_TBF_PTAB
] = { .size
= TC_RTAB_SIZE
},
826 [TCA_TBF_RATE64
] = { .type
= NETLINK_TYPE_U64
},
827 [TCA_TBF_PRATE64
] = { .type
= NETLINK_TYPE_U64
},
828 [TCA_TBF_BURST
] = { .type
= NETLINK_TYPE_U32
},
829 [TCA_TBF_PBURST
] = { .type
= NETLINK_TYPE_U32
},
832 static const char* const nl_union_tca_option_data_table
[] = {
833 [NL_UNION_TCA_OPTION_DATA_CAKE
] = "cake",
834 [NL_UNION_TCA_OPTION_DATA_CODEL
] = "codel",
835 [NL_UNION_TCA_OPTION_DATA_DRR
] = "drr",
836 [NL_UNION_TCA_OPTION_DATA_FQ
] = "fq",
837 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL
] = "fq_codel",
838 [NL_UNION_TCA_OPTION_DATA_GRED
] = "gred",
839 [NL_UNION_TCA_OPTION_DATA_HHF
] = "hhf",
840 [NL_UNION_TCA_OPTION_DATA_HTB
] = "htb",
841 [NL_UNION_TCA_OPTION_DATA_PIE
] = "pie",
842 [NL_UNION_TCA_OPTION_DATA_QFQ
] = "qfq",
843 [NL_UNION_TCA_OPTION_DATA_SFB
] = "sfb",
844 [NL_UNION_TCA_OPTION_DATA_TBF
] = "tbf",
847 DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data
, NLUnionTCAOptionData
);
849 static const NLTypeSystem rtnl_tca_option_data_type_systems
[] = {
850 [NL_UNION_TCA_OPTION_DATA_CAKE
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_cake_types
),
851 .types
= rtnl_tca_option_data_cake_types
},
852 [NL_UNION_TCA_OPTION_DATA_CODEL
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_codel_types
),
853 .types
= rtnl_tca_option_data_codel_types
},
854 [NL_UNION_TCA_OPTION_DATA_DRR
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_drr_types
),
855 .types
= rtnl_tca_option_data_drr_types
},
856 [NL_UNION_TCA_OPTION_DATA_FQ
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_fq_types
),
857 .types
= rtnl_tca_option_data_fq_types
},
858 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_fq_codel_types
),
859 .types
= rtnl_tca_option_data_fq_codel_types
},
860 [NL_UNION_TCA_OPTION_DATA_GRED
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_gred_types
),
861 .types
= rtnl_tca_option_data_gred_types
},
862 [NL_UNION_TCA_OPTION_DATA_HHF
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_hhf_types
),
863 .types
= rtnl_tca_option_data_hhf_types
},
864 [NL_UNION_TCA_OPTION_DATA_HTB
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_htb_types
),
865 .types
= rtnl_tca_option_data_htb_types
},
866 [NL_UNION_TCA_OPTION_DATA_PIE
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_pie_types
),
867 .types
= rtnl_tca_option_data_pie_types
},
868 [NL_UNION_TCA_OPTION_DATA_QFQ
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_qfq_types
),
869 .types
= rtnl_tca_option_data_qfq_types
},
870 [NL_UNION_TCA_OPTION_DATA_SFB
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_sfb_types
),
871 .types
= rtnl_tca_option_data_sfb_types
},
872 [NL_UNION_TCA_OPTION_DATA_TBF
] = { .count
= ELEMENTSOF(rtnl_tca_option_data_tbf_types
),
873 .types
= rtnl_tca_option_data_tbf_types
},
876 static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union
= {
877 .num
= _NL_UNION_TCA_OPTION_DATA_MAX
,
878 .lookup
= nl_union_tca_option_data_from_string
,
879 .type_systems
= rtnl_tca_option_data_type_systems
,
880 .match_type
= NL_MATCH_SIBLING
,
884 static const NLType rtnl_tca_types
[] = {
885 [TCA_KIND
] = { .type
= NETLINK_TYPE_STRING
},
886 [TCA_OPTIONS
] = { .type
= NETLINK_TYPE_UNION
, .type_system_union
= &rtnl_tca_option_data_type_system_union
},
887 [TCA_INGRESS_BLOCK
] = { .type
= NETLINK_TYPE_U32
},
888 [TCA_EGRESS_BLOCK
] = { .type
= NETLINK_TYPE_U32
},
891 static const NLTypeSystem rtnl_tca_type_system
= {
892 .count
= ELEMENTSOF(rtnl_tca_types
),
893 .types
= rtnl_tca_types
,
896 static const NLType error_types
[] = {
897 [NLMSGERR_ATTR_MSG
] = { .type
= NETLINK_TYPE_STRING
},
898 [NLMSGERR_ATTR_OFFS
] = { .type
= NETLINK_TYPE_U32
},
901 static const NLTypeSystem error_type_system
= {
902 .count
= ELEMENTSOF(error_types
),
903 .types
= error_types
,
906 static const NLType rtnl_types
[] = {
907 [NLMSG_DONE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
, .size
= 0 },
908 [NLMSG_ERROR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &error_type_system
, .size
= sizeof(struct nlmsgerr
) },
909 [RTM_NEWLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
910 [RTM_DELLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
911 [RTM_GETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
912 [RTM_SETLINK
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
913 [RTM_NEWLINKPROP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
914 [RTM_DELLINKPROP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
915 [RTM_GETLINKPROP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_link_type_system
, .size
= sizeof(struct ifinfomsg
) },
916 [RTM_NEWADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
917 [RTM_DELADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
918 [RTM_GETADDR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_address_type_system
, .size
= sizeof(struct ifaddrmsg
) },
919 [RTM_NEWROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
920 [RTM_DELROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
921 [RTM_GETROUTE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_route_type_system
, .size
= sizeof(struct rtmsg
) },
922 [RTM_NEWNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
923 [RTM_DELNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
924 [RTM_GETNEIGH
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_neigh_type_system
, .size
= sizeof(struct ndmsg
) },
925 [RTM_NEWADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
926 [RTM_DELADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
927 [RTM_GETADDRLABEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_addrlabel_type_system
, .size
= sizeof(struct ifaddrlblmsg
) },
928 [RTM_NEWRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
929 [RTM_DELRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
930 [RTM_GETRULE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_routing_policy_rule_type_system
, .size
= sizeof(struct rtmsg
) },
931 [RTM_NEWNEXTHOP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_nexthop_type_system
, .size
= sizeof(struct nhmsg
) },
932 [RTM_DELNEXTHOP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_nexthop_type_system
, .size
= sizeof(struct nhmsg
) },
933 [RTM_GETNEXTHOP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_nexthop_type_system
, .size
= sizeof(struct nhmsg
) },
934 [RTM_NEWQDISC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
935 [RTM_DELQDISC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
936 [RTM_GETQDISC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
937 [RTM_NEWTCLASS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
938 [RTM_DELTCLASS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
939 [RTM_GETTCLASS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &rtnl_tca_type_system
, .size
= sizeof(struct tcmsg
) },
942 const NLTypeSystem rtnl_type_system_root
= {
943 .count
= ELEMENTSOF(rtnl_types
),
947 static const NLType genl_wireguard_allowedip_types
[] = {
948 [WGALLOWEDIP_A_FAMILY
] = { .type
= NETLINK_TYPE_U16
},
949 [WGALLOWEDIP_A_IPADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
950 [WGALLOWEDIP_A_CIDR_MASK
] = { .type
= NETLINK_TYPE_U8
},
953 static const NLTypeSystem genl_wireguard_allowedip_type_system
= {
954 .count
= ELEMENTSOF(genl_wireguard_allowedip_types
),
955 .types
= genl_wireguard_allowedip_types
,
958 static const NLType genl_wireguard_peer_types
[] = {
959 [WGPEER_A_PUBLIC_KEY
] = { .size
= WG_KEY_LEN
},
960 [WGPEER_A_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
961 [WGPEER_A_PRESHARED_KEY
] = { .size
= WG_KEY_LEN
},
962 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL
] = { .type
= NETLINK_TYPE_U16
},
963 [WGPEER_A_ENDPOINT
] = { .type
= NETLINK_TYPE_SOCKADDR
},
964 [WGPEER_A_ALLOWEDIPS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_allowedip_type_system
},
967 static const NLTypeSystem genl_wireguard_peer_type_system
= {
968 .count
= ELEMENTSOF(genl_wireguard_peer_types
),
969 .types
= genl_wireguard_peer_types
,
972 static const NLType genl_wireguard_set_device_types
[] = {
973 [WGDEVICE_A_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
974 [WGDEVICE_A_IFNAME
] = { .type
= NETLINK_TYPE_STRING
, .size
= IFNAMSIZ
-1 },
975 [WGDEVICE_A_FLAGS
] = { .type
= NETLINK_TYPE_U32
},
976 [WGDEVICE_A_PRIVATE_KEY
] = { .size
= WG_KEY_LEN
},
977 [WGDEVICE_A_LISTEN_PORT
] = { .type
= NETLINK_TYPE_U16
},
978 [WGDEVICE_A_FWMARK
] = { .type
= NETLINK_TYPE_U32
},
979 [WGDEVICE_A_PEERS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_peer_type_system
},
982 static const NLTypeSystem genl_wireguard_set_device_type_system
= {
983 .count
= ELEMENTSOF(genl_wireguard_set_device_types
),
984 .types
= genl_wireguard_set_device_types
,
987 static const NLType genl_wireguard_cmds
[] = {
988 [WG_CMD_SET_DEVICE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_set_device_type_system
},
991 static const NLTypeSystem genl_wireguard_type_system
= {
992 .count
= ELEMENTSOF(genl_wireguard_cmds
),
993 .types
= genl_wireguard_cmds
,
996 static const NLType genl_mcast_group_types
[] = {
997 [CTRL_ATTR_MCAST_GRP_NAME
] = { .type
= NETLINK_TYPE_STRING
},
998 [CTRL_ATTR_MCAST_GRP_ID
] = { .type
= NETLINK_TYPE_U32
},
1001 static const NLTypeSystem genl_mcast_group_type_system
= {
1002 .count
= ELEMENTSOF(genl_mcast_group_types
),
1003 .types
= genl_mcast_group_types
,
1006 static const NLType genl_get_family_types
[] = {
1007 [CTRL_ATTR_FAMILY_NAME
] = { .type
= NETLINK_TYPE_STRING
},
1008 [CTRL_ATTR_FAMILY_ID
] = { .type
= NETLINK_TYPE_U16
},
1009 [CTRL_ATTR_MCAST_GROUPS
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_mcast_group_type_system
},
1012 static const NLTypeSystem genl_get_family_type_system
= {
1013 .count
= ELEMENTSOF(genl_get_family_types
),
1014 .types
= genl_get_family_types
,
1017 static const NLType genl_ctrl_id_ctrl_cmds
[] = {
1018 [CTRL_CMD_GETFAMILY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_get_family_type_system
},
1021 static const NLTypeSystem genl_ctrl_id_ctrl_type_system
= {
1022 .count
= ELEMENTSOF(genl_ctrl_id_ctrl_cmds
),
1023 .types
= genl_ctrl_id_ctrl_cmds
,
1026 static const NLType genl_fou_types
[] = {
1027 [FOU_ATTR_PORT
] = { .type
= NETLINK_TYPE_U16
},
1028 [FOU_ATTR_AF
] = { .type
= NETLINK_TYPE_U8
},
1029 [FOU_ATTR_IPPROTO
] = { .type
= NETLINK_TYPE_U8
},
1030 [FOU_ATTR_TYPE
] = { .type
= NETLINK_TYPE_U8
},
1031 [FOU_ATTR_REMCSUM_NOPARTIAL
] = { .type
= NETLINK_TYPE_FLAG
},
1032 [FOU_ATTR_LOCAL_V4
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1033 [FOU_ATTR_PEER_V4
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1034 [FOU_ATTR_LOCAL_V6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1035 [FOU_ATTR_PEER_V6
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1036 [FOU_ATTR_PEER_PORT
] = { .type
= NETLINK_TYPE_U16
},
1037 [FOU_ATTR_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
1040 static const NLTypeSystem genl_fou_type_system
= {
1041 .count
= ELEMENTSOF(genl_fou_types
),
1042 .types
= genl_fou_types
,
1045 static const NLType genl_fou_cmds
[] = {
1046 [FOU_CMD_ADD
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_fou_type_system
},
1047 [FOU_CMD_DEL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_fou_type_system
},
1048 [FOU_CMD_GET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_fou_type_system
},
1051 static const NLTypeSystem genl_fou_cmds_type_system
= {
1052 .count
= ELEMENTSOF(genl_fou_cmds
),
1053 .types
= genl_fou_cmds
,
1056 static const NLType genl_l2tp_types
[] = {
1057 [L2TP_ATTR_PW_TYPE
] = { .type
= NETLINK_TYPE_U16
},
1058 [L2TP_ATTR_ENCAP_TYPE
] = { .type
= NETLINK_TYPE_U16
},
1059 [L2TP_ATTR_OFFSET
] = { .type
= NETLINK_TYPE_U16
},
1060 [L2TP_ATTR_DATA_SEQ
] = { .type
= NETLINK_TYPE_U16
},
1061 [L2TP_ATTR_L2SPEC_TYPE
] = { .type
= NETLINK_TYPE_U8
},
1062 [L2TP_ATTR_L2SPEC_LEN
] = { .type
= NETLINK_TYPE_U8
},
1063 [L2TP_ATTR_PROTO_VERSION
] = { .type
= NETLINK_TYPE_U8
},
1064 [L2TP_ATTR_IFNAME
] = { .type
= NETLINK_TYPE_STRING
},
1065 [L2TP_ATTR_CONN_ID
] = { .type
= NETLINK_TYPE_U32
},
1066 [L2TP_ATTR_PEER_CONN_ID
] = { .type
= NETLINK_TYPE_U32
},
1067 [L2TP_ATTR_SESSION_ID
] = { .type
= NETLINK_TYPE_U32
},
1068 [L2TP_ATTR_PEER_SESSION_ID
] = { .type
= NETLINK_TYPE_U32
},
1069 [L2TP_ATTR_UDP_CSUM
] = { .type
= NETLINK_TYPE_U8
},
1070 [L2TP_ATTR_VLAN_ID
] = { .type
= NETLINK_TYPE_U16
},
1071 [L2TP_ATTR_RECV_SEQ
] = { .type
= NETLINK_TYPE_U8
},
1072 [L2TP_ATTR_SEND_SEQ
] = { .type
= NETLINK_TYPE_U8
},
1073 [L2TP_ATTR_LNS_MODE
] = { .type
= NETLINK_TYPE_U8
},
1074 [L2TP_ATTR_USING_IPSEC
] = { .type
= NETLINK_TYPE_U8
},
1075 [L2TP_ATTR_FD
] = { .type
= NETLINK_TYPE_U32
},
1076 [L2TP_ATTR_IP_SADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1077 [L2TP_ATTR_IP_DADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1078 [L2TP_ATTR_UDP_SPORT
] = { .type
= NETLINK_TYPE_U16
},
1079 [L2TP_ATTR_UDP_DPORT
] = { .type
= NETLINK_TYPE_U16
},
1080 [L2TP_ATTR_IP6_SADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1081 [L2TP_ATTR_IP6_DADDR
] = { .type
= NETLINK_TYPE_IN_ADDR
},
1082 [L2TP_ATTR_UDP_ZERO_CSUM6_TX
] = { .type
= NETLINK_TYPE_FLAG
},
1083 [L2TP_ATTR_UDP_ZERO_CSUM6_RX
] = { .type
= NETLINK_TYPE_FLAG
},
1086 static const NLTypeSystem genl_l2tp_type_system
= {
1087 .count
= ELEMENTSOF(genl_l2tp_types
),
1088 .types
= genl_l2tp_types
,
1091 static const NLType genl_l2tp
[] = {
1092 [L2TP_CMD_TUNNEL_CREATE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1093 [L2TP_CMD_TUNNEL_DELETE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1094 [L2TP_CMD_TUNNEL_MODIFY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1095 [L2TP_CMD_TUNNEL_GET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1096 [L2TP_CMD_SESSION_CREATE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1097 [L2TP_CMD_SESSION_DELETE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1098 [L2TP_CMD_SESSION_MODIFY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1099 [L2TP_CMD_SESSION_GET
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_type_system
},
1102 static const NLTypeSystem genl_l2tp_tunnel_session_type_system
= {
1103 .count
= ELEMENTSOF(genl_l2tp
),
1107 static const NLType genl_rxsc_types
[] = {
1108 [MACSEC_RXSC_ATTR_SCI
] = { .type
= NETLINK_TYPE_U64
},
1111 static const NLTypeSystem genl_rxsc_config_type_system
= {
1112 .count
= ELEMENTSOF(genl_rxsc_types
),
1113 .types
= genl_rxsc_types
,
1116 static const NLType genl_macsec_rxsc_types
[] = {
1117 [MACSEC_ATTR_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
1118 [MACSEC_ATTR_RXSC_CONFIG
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_rxsc_config_type_system
},
1121 static const NLTypeSystem genl_macsec_rxsc_type_system
= {
1122 .count
= ELEMENTSOF(genl_macsec_rxsc_types
),
1123 .types
= genl_macsec_rxsc_types
,
1126 static const NLType genl_macsec_sa_config_types
[] = {
1127 [MACSEC_SA_ATTR_AN
] = { .type
= NETLINK_TYPE_U8
},
1128 [MACSEC_SA_ATTR_ACTIVE
] = { .type
= NETLINK_TYPE_U8
},
1129 [MACSEC_SA_ATTR_PN
] = { .type
= NETLINK_TYPE_U32
},
1130 [MACSEC_SA_ATTR_KEYID
] = { .size
= MACSEC_KEYID_LEN
},
1131 [MACSEC_SA_ATTR_KEY
] = { .size
= MACSEC_MAX_KEY_LEN
},
1134 static const NLTypeSystem genl_macsec_sa_config_type_system
= {
1135 .count
= ELEMENTSOF(genl_macsec_sa_config_types
),
1136 .types
= genl_macsec_sa_config_types
,
1139 static const NLType genl_macsec_rxsa_types
[] = {
1140 [MACSEC_ATTR_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
1141 [MACSEC_ATTR_SA_CONFIG
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_sa_config_type_system
},
1144 static const NLTypeSystem genl_macsec_rxsa_type_system
= {
1145 .count
= ELEMENTSOF(genl_macsec_rxsa_types
),
1146 .types
= genl_macsec_rxsa_types
,
1149 static const NLType genl_macsec_sa_types
[] = {
1150 [MACSEC_ATTR_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
1151 [MACSEC_ATTR_RXSC_CONFIG
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_rxsc_config_type_system
},
1152 [MACSEC_ATTR_SA_CONFIG
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_sa_config_type_system
},
1155 static const NLTypeSystem genl_macsec_sa_type_system
= {
1156 .count
= ELEMENTSOF(genl_macsec_sa_types
),
1157 .types
= genl_macsec_sa_types
,
1160 static const NLType genl_macsec
[] = {
1161 [MACSEC_CMD_ADD_RXSC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_rxsc_type_system
},
1162 [MACSEC_CMD_ADD_TXSA
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_rxsa_type_system
},
1163 [MACSEC_CMD_ADD_RXSA
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_sa_type_system
},
1166 static const NLTypeSystem genl_macsec_device_type_system
= {
1167 .count
= ELEMENTSOF(genl_macsec
),
1168 .types
= genl_macsec
,
1171 static const NLType genl_nl80211_types
[] = {
1172 [NL80211_ATTR_IFINDEX
] = { .type
= NETLINK_TYPE_U32
},
1173 [NL80211_ATTR_MAC
] = { .type
= NETLINK_TYPE_ETHER_ADDR
},
1174 [NL80211_ATTR_SSID
] = { .type
= NETLINK_TYPE_STRING
},
1175 [NL80211_ATTR_IFTYPE
] = { .type
= NETLINK_TYPE_U32
},
1178 static const NLTypeSystem genl_nl80211_type_system
= {
1179 .count
= ELEMENTSOF(genl_nl80211_types
),
1180 .types
= genl_nl80211_types
,
1183 static const NLType genl_nl80211_cmds
[] = {
1184 [NL80211_CMD_GET_WIPHY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1185 [NL80211_CMD_SET_WIPHY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1186 [NL80211_CMD_NEW_WIPHY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1187 [NL80211_CMD_DEL_WIPHY
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1188 [NL80211_CMD_GET_INTERFACE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1189 [NL80211_CMD_SET_INTERFACE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1190 [NL80211_CMD_NEW_INTERFACE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1191 [NL80211_CMD_DEL_INTERFACE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1192 [NL80211_CMD_GET_STATION
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1193 [NL80211_CMD_SET_STATION
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1194 [NL80211_CMD_NEW_STATION
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1195 [NL80211_CMD_DEL_STATION
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
},
1198 static const NLTypeSystem genl_nl80211_cmds_type_system
= {
1199 .count
= ELEMENTSOF(genl_nl80211_cmds
),
1200 .types
= genl_nl80211_cmds
,
1203 static const NLType genl_families
[] = {
1204 [SD_GENL_ID_CTRL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_ctrl_id_ctrl_type_system
},
1205 [SD_GENL_WIREGUARD
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_wireguard_type_system
},
1206 [SD_GENL_FOU
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_fou_cmds_type_system
},
1207 [SD_GENL_L2TP
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_l2tp_tunnel_session_type_system
},
1208 [SD_GENL_MACSEC
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_macsec_device_type_system
},
1209 [SD_GENL_NL80211
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_cmds_type_system
},
1212 /* Mainly used when sending message */
1213 const NLTypeSystem genl_family_type_system_root
= {
1214 .count
= ELEMENTSOF(genl_families
),
1215 .types
= genl_families
,
1218 static const NLType genl_types
[] = {
1219 [SD_GENL_ERROR
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &error_type_system
, .size
= sizeof(struct nlmsgerr
) },
1220 [SD_GENL_DONE
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &empty_type_system
},
1221 [SD_GENL_ID_CTRL
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_get_family_type_system
, .size
= sizeof(struct genlmsghdr
) },
1222 [SD_GENL_NL80211
] = { .type
= NETLINK_TYPE_NESTED
, .type_system
= &genl_nl80211_type_system
, .size
= sizeof(struct genlmsghdr
) },
1225 /* Mainly used when message received */
1226 const NLTypeSystem genl_type_system_root
= {
1227 .count
= ELEMENTSOF(genl_types
),
1228 .types
= genl_types
,
1231 uint16_t type_get_type(const NLType
*type
) {
1236 size_t type_get_size(const NLType
*type
) {
1241 void type_get_type_system(const NLType
*nl_type
, const NLTypeSystem
**ret
) {
1244 assert(nl_type
->type
== NETLINK_TYPE_NESTED
);
1245 assert(nl_type
->type_system
);
1247 *ret
= nl_type
->type_system
;
1250 void type_get_type_system_union(const NLType
*nl_type
, const NLTypeSystemUnion
**ret
) {
1253 assert(nl_type
->type
== NETLINK_TYPE_UNION
);
1254 assert(nl_type
->type_system_union
);
1256 *ret
= nl_type
->type_system_union
;
1259 uint16_t type_system_get_count(const NLTypeSystem
*type_system
) {
1260 assert(type_system
);
1261 return type_system
->count
;
1264 const NLTypeSystem
*type_system_get_root(int protocol
) {
1266 case NETLINK_GENERIC
:
1267 return &genl_type_system_root
;
1268 default: /* NETLINK_ROUTE: */
1269 return &rtnl_type_system_root
;
1273 int type_system_root_get_type(sd_netlink
*nl
, const NLType
**ret
, uint16_t type
) {
1274 sd_genl_family family
;
1275 const NLType
*nl_type
;
1278 if (!nl
|| nl
->protocol
!= NETLINK_GENERIC
)
1279 return type_system_get_type(&rtnl_type_system_root
, ret
, type
);
1281 r
= nlmsg_type_to_genl_family(nl
, type
, &family
);
1285 if (family
>= genl_type_system_root
.count
)
1288 nl_type
= &genl_type_system_root
.types
[family
];
1290 if (nl_type
->type
== NETLINK_TYPE_UNSPEC
)
1298 int type_system_get_type(const NLTypeSystem
*type_system
, const NLType
**ret
, uint16_t type
) {
1299 const NLType
*nl_type
;
1302 assert(type_system
);
1303 assert(type_system
->types
);
1305 if (type
>= type_system
->count
)
1308 nl_type
= &type_system
->types
[type
];
1310 if (nl_type
->type
== NETLINK_TYPE_UNSPEC
)
1318 int type_system_get_type_system(const NLTypeSystem
*type_system
, const NLTypeSystem
**ret
, uint16_t type
) {
1319 const NLType
*nl_type
;
1324 r
= type_system_get_type(type_system
, &nl_type
, type
);
1328 type_get_type_system(nl_type
, ret
);
1332 int type_system_get_type_system_union(const NLTypeSystem
*type_system
, const NLTypeSystemUnion
**ret
, uint16_t type
) {
1333 const NLType
*nl_type
;
1338 r
= type_system_get_type(type_system
, &nl_type
, type
);
1342 type_get_type_system_union(nl_type
, ret
);
1346 int type_system_union_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, const char *key
) {
1349 assert(type_system_union
);
1350 assert(type_system_union
->match_type
== NL_MATCH_SIBLING
);
1351 assert(type_system_union
->lookup
);
1352 assert(type_system_union
->type_systems
);
1356 type
= type_system_union
->lookup(key
);
1360 assert(type
< type_system_union
->num
);
1362 *ret
= &type_system_union
->type_systems
[type
];
1367 int type_system_union_protocol_get_type_system(const NLTypeSystemUnion
*type_system_union
, const NLTypeSystem
**ret
, uint16_t protocol
) {
1368 const NLTypeSystem
*type_system
;
1370 assert(type_system_union
);
1371 assert(type_system_union
->type_systems
);
1372 assert(type_system_union
->match_type
== NL_MATCH_PROTOCOL
);
1375 if (protocol
>= type_system_union
->num
)
1378 type_system
= &type_system_union
->type_systems
[protocol
];
1379 if (!type_system
->types
)