]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-netlink/netlink-types.c
Fix compilation without libcryptsetup (#17071)
[thirdparty/systemd.git] / src / libsystemd / sd-netlink / netlink-types.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
d8e538ec 2
5a2dadf1 3#include <netinet/in.h>
d8e538ec
TG
4#include <stdint.h>
5#include <sys/socket.h>
01234e1f 6#include <linux/can/vxcan.h>
d8e538ec
TG
7#include <linux/netlink.h>
8#include <linux/rtnetlink.h>
5a2dadf1
LP
9#include <linux/genetlink.h>
10#include <linux/ip.h>
11#include <linux/if.h>
92c918b0 12#include <linux/can/netlink.h>
bce67bbe 13#include <linux/fib_rules.h>
01234e1f 14#include <linux/fou.h>
d8e538ec 15#include <linux/if_addr.h>
30746d60 16#include <linux/if_addrlabel.h>
bce67bbe 17#include <linux/if_bridge.h>
c4a5ddc9 18#include <linux/if_link.h>
81962db7 19#include <linux/if_macsec.h>
0a827d10 20#include <linux/if_tunnel.h>
3a56e697 21#include <linux/l2tp.h>
0f5bd7fe 22#include <linux/nexthop.h>
a1d736e2 23#include <linux/nl80211.h>
0f5bd7fe 24#include <linux/pkt_sched.h>
5a2dadf1 25#include <linux/veth.h>
01234e1f 26#include <linux/wireguard.h>
d6df583c 27
4e8f0ef9
YW
28#include "sd-netlink.h"
29
30#include "generic-netlink.h"
31#include "hashmap.h"
d8e538ec 32#include "macro.h"
4e8f0ef9 33#include "netlink-internal.h"
8b43440b
LP
34#include "netlink-types.h"
35#include "string-table.h"
36#include "util.h"
d8e538ec 37
dd906398
DH
38/* Maximum ARP IP target defined in kernel */
39#define BOND_MAX_ARP_TARGETS 16
40
41typedef enum {
42 BOND_ARP_TARGETS_0,
43 BOND_ARP_TARGETS_1,
44 BOND_ARP_TARGETS_2,
45 BOND_ARP_TARGETS_3,
46 BOND_ARP_TARGETS_4,
47 BOND_ARP_TARGETS_5,
48 BOND_ARP_TARGETS_6,
49 BOND_ARP_TARGETS_7,
50 BOND_ARP_TARGETS_8,
51 BOND_ARP_TARGETS_9,
52 BOND_ARP_TARGETS_10,
53 BOND_ARP_TARGETS_11,
54 BOND_ARP_TARGETS_12,
55 BOND_ARP_TARGETS_13,
56 BOND_ARP_TARGETS_14,
57 BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
58} BondArpTargets;
59
817d1cd8
DH
60struct NLType {
61 uint16_t type;
62 size_t size;
63 const NLTypeSystem *type_system;
64 const NLTypeSystemUnion *type_system_union;
65};
66
435bbb02 67struct NLTypeSystem {
c1df8dee 68 uint16_t count;
435bbb02
DH
69 const NLType *types;
70};
71
d8e538ec
TG
72static const NLTypeSystem rtnl_link_type_system;
73
979e7eb9
DH
74static const NLType empty_types[1] = {
75 /* fake array to avoid .types==NULL, which denotes invalid type-systems */
76};
77
78static const NLTypeSystem empty_type_system = {
79 .count = 0,
80 .types = empty_types,
81};
82
8ae4b6d1 83static const NLType rtnl_link_info_data_veth_types[] = {
cafbc790 84 [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
d8e538ec
TG
85};
86
d6df583c
SS
87static 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) },
89};
90
8ae4b6d1 91static const NLType rtnl_link_info_data_ipvlan_types[] = {
cafbc790 92 [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 },
d384826f 93 [IFLA_IPVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
c4a5ddc9 94};
d8e538ec 95
0d0de133
96static const NLType rtnl_macvlan_macaddr_types[] = {
97 [IFLA_MACVLAN_MACADDR] = { .type = NETLINK_TYPE_ETHER_ADDR },
98};
99
100static const NLTypeSystem rtnl_macvlan_macaddr_type_system = {
101 .count = ELEMENTSOF(rtnl_macvlan_macaddr_types),
102 .types = rtnl_macvlan_macaddr_types,
103};
104
8ae4b6d1 105static const NLType rtnl_link_info_data_macvlan_types[] = {
cafbc790
DH
106 [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 },
107 [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 },
0d0de133
108 [IFLA_MACVLAN_MACADDR_MODE] = { .type = NETLINK_TYPE_U32 },
109 [IFLA_MACVLAN_MACADDR_DATA] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_macvlan_macaddr_type_system },
d8e538ec
TG
110};
111
8ae4b6d1 112static const NLType rtnl_link_info_data_bridge_types[] = {
3fef7a3f
SS
113 [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 },
114 [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 },
115 [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 },
116 [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 },
117 [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 },
118 [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 },
119 [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 },
120 [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
121 [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
122 [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 },
123 [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 },
124 [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 },
125 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 },
126 [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 },
127 [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 },
128 [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 },
129 [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 },
130 [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 },
131 [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 },
132 [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
133 [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 },
134 [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 },
135 [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 },
136 [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 },
137 [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 },
138 [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 },
139 [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 },
140 [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 },
141 [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 },
142 [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 },
143 [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
144 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 },
145 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 },
146 [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 },
147 [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 },
148 [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 },
149 [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 },
037dbb80 150 [IFLA_BR_MCAST_IGMP_VERSION] = { .type = NETLINK_TYPE_U8 },
ced671e1
SS
151};
152
8ae4b6d1 153static const NLType rtnl_link_info_data_vlan_types[] = {
cafbc790 154 [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
d8e538ec
TG
155/*
156 [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
cafbc790
DH
157 [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
158 [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
d8e538ec 159*/
cafbc790 160 [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
d8e538ec
TG
161};
162
8ae4b6d1 163static const NLType rtnl_link_info_data_vxlan_types[] = {
452c9569
SS
164 [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 },
165 [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR },
166 [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 },
5564545b 167 [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
452c9569
SS
168 [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 },
169 [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 },
170 [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 },
171 [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 },
172 [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 },
173 [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32},
174 [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 },
175 [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 },
176 [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 },
177 [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 },
178 [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 },
179 [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR },
180 [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR },
181 [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
182 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
183 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
184 [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 },
185 [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 },
186 [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG },
187 [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
6d21646a
SS
188 [IFLA_VXLAN_COLLECT_METADATA] = { .type = NETLINK_TYPE_U8 },
189 [IFLA_VXLAN_LABEL] = { .type = NETLINK_TYPE_U32 },
190 [IFLA_VXLAN_GPE] = { .type = NETLINK_TYPE_FLAG },
2a36d400
SS
191 [IFLA_VXLAN_TTL_INHERIT] = { .type = NETLINK_TYPE_FLAG },
192 [IFLA_VXLAN_DF] = { .type = NETLINK_TYPE_U8 },
6ef81477
SS
193};
194
8ae4b6d1 195static const NLType rtnl_bond_arp_target_types[] = {
cafbc790
DH
196 [BOND_ARP_TARGETS_0] = { .type = NETLINK_TYPE_U32 },
197 [BOND_ARP_TARGETS_1] = { .type = NETLINK_TYPE_U32 },
198 [BOND_ARP_TARGETS_2] = { .type = NETLINK_TYPE_U32 },
199 [BOND_ARP_TARGETS_3] = { .type = NETLINK_TYPE_U32 },
200 [BOND_ARP_TARGETS_4] = { .type = NETLINK_TYPE_U32 },
201 [BOND_ARP_TARGETS_5] = { .type = NETLINK_TYPE_U32 },
202 [BOND_ARP_TARGETS_6] = { .type = NETLINK_TYPE_U32 },
203 [BOND_ARP_TARGETS_7] = { .type = NETLINK_TYPE_U32 },
204 [BOND_ARP_TARGETS_8] = { .type = NETLINK_TYPE_U32 },
205 [BOND_ARP_TARGETS_9] = { .type = NETLINK_TYPE_U32 },
206 [BOND_ARP_TARGETS_10] = { .type = NETLINK_TYPE_U32 },
207 [BOND_ARP_TARGETS_11] = { .type = NETLINK_TYPE_U32 },
208 [BOND_ARP_TARGETS_12] = { .type = NETLINK_TYPE_U32 },
209 [BOND_ARP_TARGETS_13] = { .type = NETLINK_TYPE_U32 },
210 [BOND_ARP_TARGETS_14] = { .type = NETLINK_TYPE_U32 },
211 [BOND_ARP_TARGETS_MAX] = { .type = NETLINK_TYPE_U32 },
81bd37a8
SS
212};
213
214static const NLTypeSystem rtnl_bond_arp_type_system = {
c1df8dee 215 .count = ELEMENTSOF(rtnl_bond_arp_target_types),
81bd37a8
SS
216 .types = rtnl_bond_arp_target_types,
217};
218
8ae4b6d1 219static const NLType rtnl_link_info_data_bond_types[] = {
cafbc790
DH
220 [IFLA_BOND_MODE] = { .type = NETLINK_TYPE_U8 },
221 [IFLA_BOND_ACTIVE_SLAVE] = { .type = NETLINK_TYPE_U32 },
222 [IFLA_BOND_MIIMON] = { .type = NETLINK_TYPE_U32 },
223 [IFLA_BOND_UPDELAY] = { .type = NETLINK_TYPE_U32 },
224 [IFLA_BOND_DOWNDELAY] = { .type = NETLINK_TYPE_U32 },
225 [IFLA_BOND_USE_CARRIER] = { .type = NETLINK_TYPE_U8 },
226 [IFLA_BOND_ARP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
227 [IFLA_BOND_ARP_IP_TARGET] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_bond_arp_type_system },
228 [IFLA_BOND_ARP_VALIDATE] = { .type = NETLINK_TYPE_U32 },
229 [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NETLINK_TYPE_U32 },
230 [IFLA_BOND_PRIMARY] = { .type = NETLINK_TYPE_U32 },
231 [IFLA_BOND_PRIMARY_RESELECT] = { .type = NETLINK_TYPE_U8 },
232 [IFLA_BOND_FAIL_OVER_MAC] = { .type = NETLINK_TYPE_U8 },
233 [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NETLINK_TYPE_U8 },
234 [IFLA_BOND_RESEND_IGMP] = { .type = NETLINK_TYPE_U32 },
235 [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NETLINK_TYPE_U8 },
236 [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NETLINK_TYPE_U8 },
237 [IFLA_BOND_MIN_LINKS] = { .type = NETLINK_TYPE_U32 },
238 [IFLA_BOND_LP_INTERVAL] = { .type = NETLINK_TYPE_U32 },
239 [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NETLINK_TYPE_U32 },
240 [IFLA_BOND_AD_LACP_RATE] = { .type = NETLINK_TYPE_U8 },
241 [IFLA_BOND_AD_SELECT] = { .type = NETLINK_TYPE_U8 },
242 [IFLA_BOND_AD_INFO] = { .type = NETLINK_TYPE_NESTED },
99f68ef0
TJ
243 [IFLA_BOND_AD_ACTOR_SYS_PRIO] = { .type = NETLINK_TYPE_U16 },
244 [IFLA_BOND_AD_USER_PORT_KEY] = { .type = NETLINK_TYPE_U16 },
245 [IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NETLINK_TYPE_ETHER_ADDR },
fde60a42 246 [IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NETLINK_TYPE_U8 },
d8e538ec
TG
247};
248
8ae4b6d1 249static const NLType rtnl_link_info_data_iptun_types[] = {
cafbc790
DH
250 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
251 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
252 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
253 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
254 [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 },
255 [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
256 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 },
257 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
258 [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR },
259 [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 },
260 [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
261 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 },
6e74cade
ZJS
262 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
263 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
264 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
265 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
0a827d10
SS
266};
267
8ae4b6d1 268static const NLType rtnl_link_info_data_ipgre_types[] = {
8aee0f1f
SS
269 [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 },
270 [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 },
271 [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 },
272 [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 },
273 [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 },
274 [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
275 [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
276 [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 },
277 [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 },
278 [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 },
279 [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
280 [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 },
281 [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
282 [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 },
283 [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 },
284 [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 },
2266864b 285 [IFLA_GRE_ERSPAN_INDEX] = { .type = NETLINK_TYPE_U32 },
8bb088c5
SS
286};
287
8ae4b6d1 288static const NLType rtnl_link_info_data_ipvti_types[] = {
cafbc790
DH
289 [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 },
290 [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 },
291 [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 },
6e74cade
ZJS
292 [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
293 [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
a613382b
SS
294};
295
8ae4b6d1 296static const NLType rtnl_link_info_data_ip6tnl_types[] = {
cafbc790
DH
297 [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 },
298 [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
299 [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
300 [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 },
301 [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 },
302 [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 },
303 [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 },
6e74cade 304 [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 },
855ee1a1
SS
305};
306
20897a0d
AR
307static const NLType rtnl_link_info_data_vrf_types[] = {
308 [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 },
309};
310
ca5e8071
SS
311static const NLType rtnl_link_info_data_geneve_types[] = {
312 [IFLA_GENEVE_ID] = { .type = NETLINK_TYPE_U32 },
313 [IFLA_GENEVE_TTL] = { .type = NETLINK_TYPE_U8 },
314 [IFLA_GENEVE_TOS] = { .type = NETLINK_TYPE_U8 },
315 [IFLA_GENEVE_PORT] = { .type = NETLINK_TYPE_U16 },
316 [IFLA_GENEVE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR },
317 [IFLA_GENEVE_REMOTE6] = { .type = NETLINK_TYPE_IN_ADDR },
318 [IFLA_GENEVE_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
319 [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
320 [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
321 [IFLA_GENEVE_LABEL] = { .type = NETLINK_TYPE_U32 },
469fd848
SS
322 [IFLA_GENEVE_TTL_INHERIT] = { .type = NETLINK_TYPE_U8 },
323 [IFLA_GENEVE_DF] = { .type = NETLINK_TYPE_U8 },
ca5e8071
SS
324};
325
06828bb6
HP
326static const NLType rtnl_link_info_data_can_types[] = {
327 [IFLA_CAN_BITTIMING] = { .size = sizeof(struct can_bittiming) },
328 [IFLA_CAN_RESTART_MS] = { .type = NETLINK_TYPE_U32 },
c423be28 329 [IFLA_CAN_CTRLMODE] = { .size = sizeof(struct can_ctrlmode) },
52aa38f1 330 [IFLA_CAN_TERMINATION] = { .type = NETLINK_TYPE_U16 },
06828bb6
HP
331};
332
81962db7
SS
333static const NLType rtnl_link_info_data_macsec_types[] = {
334 [IFLA_MACSEC_SCI] = { .type = NETLINK_TYPE_U64 },
335 [IFLA_MACSEC_PORT] = { .type = NETLINK_TYPE_U16 },
336 [IFLA_MACSEC_ICV_LEN] = { .type = NETLINK_TYPE_U8 },
337 [IFLA_MACSEC_CIPHER_SUITE] = { .type = NETLINK_TYPE_U64 },
338 [IFLA_MACSEC_WINDOW] = { .type = NETLINK_TYPE_U32 },
339 [IFLA_MACSEC_ENCODING_SA] = { .type = NETLINK_TYPE_U8 },
340 [IFLA_MACSEC_ENCRYPT] = { .type = NETLINK_TYPE_U8 },
341 [IFLA_MACSEC_PROTECT] = { .type = NETLINK_TYPE_U8 },
342 [IFLA_MACSEC_INC_SCI] = { .type = NETLINK_TYPE_U8 },
343 [IFLA_MACSEC_ES] = { .type = NETLINK_TYPE_U8 },
344 [IFLA_MACSEC_SCB] = { .type = NETLINK_TYPE_U8 },
345 [IFLA_MACSEC_REPLAY_PROTECT] = { .type = NETLINK_TYPE_U8 },
346 [IFLA_MACSEC_VALIDATION] = { .type = NETLINK_TYPE_U8 },
347};
348
98d20a17 349static const NLType rtnl_link_info_data_xfrm_types[] = {
350 [IFLA_XFRM_LINK] = { .type = NETLINK_TYPE_U32 },
351 [IFLA_XFRM_IF_ID] = { .type = NETLINK_TYPE_U32 }
352};
353
0a827d10 354/* these strings must match the .kind entries in the kernel */
8ae4b6d1 355static const char* const nl_union_link_info_data_table[] = {
d8e538ec
TG
356 [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
357 [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
358 [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
359 [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
9e358851 360 [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
d8e538ec 361 [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
d1312575 362 [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap",
c4a5ddc9 363 [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
69c317a0 364 [NL_UNION_LINK_INFO_DATA_IPVTAP] = "ipvtap",
6ef81477 365 [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
0a827d10 366 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
8bb088c5 367 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
2266864b 368 [NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan",
1af2536a 369 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
b16492f8
SS
370 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
371 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
0a827d10 372 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
a613382b 373 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
9011ce77 374 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
855ee1a1 375 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
20897a0d 376 [NL_UNION_LINK_INFO_DATA_VRF] = "vrf",
92c918b0 377 [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan",
ca5e8071 378 [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve",
d6df583c 379 [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan",
e5719363 380 [NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard",
56e7fb50 381 [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim",
06828bb6 382 [NL_UNION_LINK_INFO_DATA_CAN] = "can",
81962db7 383 [NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec",
d61e4c5b 384 [NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon",
98d20a17 385 [NL_UNION_LINK_INFO_DATA_XFRM] = "xfrm",
cec1552a 386 [NL_UNION_LINK_INFO_DATA_IFB] = "ifb",
d8e538ec
TG
387};
388
389DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
390
8ae4b6d1 391static const NLTypeSystem rtnl_link_info_data_type_systems[] = {
92c918b0
SS
392 [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
393 .types = rtnl_link_info_data_bond_types },
394 [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
395 .types = rtnl_link_info_data_bridge_types },
396 [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
397 .types = rtnl_link_info_data_vlan_types },
398 [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
399 .types = rtnl_link_info_data_veth_types },
400 [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
401 .types = rtnl_link_info_data_macvlan_types },
402 [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
403 .types = rtnl_link_info_data_macvlan_types },
404 [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
405 .types = rtnl_link_info_data_ipvlan_types },
69c317a0
SS
406 [NL_UNION_LINK_INFO_DATA_IPVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
407 .types = rtnl_link_info_data_ipvlan_types },
92c918b0
SS
408 [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
409 .types = rtnl_link_info_data_vxlan_types },
410 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
411 .types = rtnl_link_info_data_iptun_types },
412 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
413 .types = rtnl_link_info_data_ipgre_types },
2266864b
SS
414 [NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
415 .types = rtnl_link_info_data_ipgre_types },
c1df8dee 416 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
92c918b0
SS
417 .types = rtnl_link_info_data_ipgre_types },
418 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
419 .types = rtnl_link_info_data_ipgre_types },
420 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
421 .types = rtnl_link_info_data_ipgre_types },
422 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
423 .types = rtnl_link_info_data_iptun_types },
424 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
425 .types = rtnl_link_info_data_ipvti_types },
426 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
427 .types = rtnl_link_info_data_ipvti_types },
428 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
429 .types = rtnl_link_info_data_ip6tnl_types },
430 [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
431 .types = rtnl_link_info_data_vrf_types },
ca5e8071
SS
432 [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
433 .types = rtnl_link_info_data_geneve_types },
d6df583c
SS
434 [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
435 .types = rtnl_link_info_data_vxcan_types },
06828bb6
HP
436 [NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types),
437 .types = rtnl_link_info_data_can_types },
81962db7
SS
438 [NL_UNION_LINK_INFO_DATA_MACSEC] = { .count = ELEMENTSOF(rtnl_link_info_data_macsec_types),
439 .types = rtnl_link_info_data_macsec_types },
98d20a17 440 [NL_UNION_LINK_INFO_DATA_XFRM] = { .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
441 .types = rtnl_link_info_data_xfrm_types },
d8e538ec
TG
442};
443
444static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
445 .num = _NL_UNION_LINK_INFO_DATA_MAX,
446 .lookup = nl_union_link_info_data_from_string,
447 .type_systems = rtnl_link_info_data_type_systems,
4af7b60d 448 .match_type = NL_MATCH_SIBLING,
d8e538ec
TG
449 .match = IFLA_INFO_KIND,
450};
451
8ae4b6d1 452static const NLType rtnl_link_info_types[] = {
cafbc790 453 [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING },
42b5f7dd 454 [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union },
d8e538ec
TG
455/*
456 [IFLA_INFO_XSTATS],
cafbc790
DH
457 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
458 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
d8e538ec
TG
459*/
460};
461
462static const NLTypeSystem rtnl_link_info_type_system = {
c1df8dee 463 .count = ELEMENTSOF(rtnl_link_info_types),
d8e538ec
TG
464 .types = rtnl_link_info_types,
465};
466
8ae4b6d1 467static const struct NLType rtnl_prot_info_bridge_port_types[] = {
d3aa8b49
SS
468 [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 },
469 [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 },
470 [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 },
471 [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 },
472 [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 },
473 [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 },
474 [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 },
475 [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 },
476 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
477 [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 },
478 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 },
479 [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NETLINK_TYPE_U8 },
480 [IFLA_BRPORT_ROOT_ID] = { .type = NETLINK_TYPE_U8 },
481 [IFLA_BRPORT_BRIDGE_ID] = { .type = NETLINK_TYPE_U8 },
482 [IFLA_BRPORT_DESIGNATED_PORT] = { .type = NETLINK_TYPE_U16 },
483 [IFLA_BRPORT_DESIGNATED_COST] = { .type = NETLINK_TYPE_U16 },
484 [IFLA_BRPORT_ID] = { .type = NETLINK_TYPE_U16 },
485 [IFLA_BRPORT_NO] = { .type = NETLINK_TYPE_U16 },
486 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = { .type = NETLINK_TYPE_U8 },
487 [IFLA_BRPORT_CONFIG_PENDING] = { .type = NETLINK_TYPE_U8 },
488 [IFLA_BRPORT_MESSAGE_AGE_TIMER] = { .type = NETLINK_TYPE_U64 },
489 [IFLA_BRPORT_FORWARD_DELAY_TIMER] = { .type = NETLINK_TYPE_U64 },
490 [IFLA_BRPORT_HOLD_TIMER] = { .type = NETLINK_TYPE_U64 },
491 [IFLA_BRPORT_FLUSH] = { .type = NETLINK_TYPE_U8 },
492 [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
493 [IFLA_BRPORT_PAD] = { .type = NETLINK_TYPE_U8 },
494 [IFLA_BRPORT_MCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
495 [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NETLINK_TYPE_U8 },
496 [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NETLINK_TYPE_U8 },
497 [IFLA_BRPORT_BCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
498 [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
499 [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NETLINK_TYPE_U8 },
500 [IFLA_BRPORT_ISOLATED] = { .type = NETLINK_TYPE_U8 },
501 [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 },
d0159fdc
SS
502};
503
8ae4b6d1 504static const NLTypeSystem rtnl_prot_info_type_systems[] = {
c1df8dee 505 [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
4af7b60d
TG
506 .types = rtnl_prot_info_bridge_port_types },
507};
508
509static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
510 .num = AF_MAX,
511 .type_systems = rtnl_prot_info_type_systems,
512 .match_type = NL_MATCH_PROTOCOL,
d0159fdc
SS
513};
514
8ae4b6d1 515static const struct NLType rtnl_af_spec_inet6_types[] = {
cafbc790 516 [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 },
c149ae08
TG
517/*
518 IFLA_INET6_CONF,
519 IFLA_INET6_STATS,
520 IFLA_INET6_MCAST,
521 IFLA_INET6_CACHEINFO,
522 IFLA_INET6_ICMP6STATS,
523*/
cafbc790
DH
524 [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR },
525 [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 },
c149ae08
TG
526};
527
73cb1c14 528static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
c1df8dee 529 .count = ELEMENTSOF(rtnl_af_spec_inet6_types),
73cb1c14 530 .types = rtnl_af_spec_inet6_types,
c149ae08
TG
531};
532
8ae4b6d1 533static const NLType rtnl_af_spec_types[] = {
cafbc790 534 [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
73cb1c14
TG
535};
536
537static const NLTypeSystem rtnl_af_spec_type_system = {
c1df8dee 538 .count = ELEMENTSOF(rtnl_af_spec_types),
73cb1c14 539 .types = rtnl_af_spec_types,
c149ae08
TG
540};
541
ffeb16f5
YW
542static const NLType rtnl_prop_list_types[] = {
543 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
544};
545
546static const NLTypeSystem rtnl_prop_list_type_system = {
547 .count = ELEMENTSOF(rtnl_prop_list_types),
548 .types = rtnl_prop_list_types,
549};
550
5908ddd7
SS
551static const NLType rtnl_vf_vlan_list_types[] = {
552 [IFLA_VF_VLAN_INFO] = { .size = sizeof(struct ifla_vf_vlan_info) },
553};
554
555static const NLTypeSystem rtnl_vf_vlan_type_system = {
556 .count = ELEMENTSOF(rtnl_vf_vlan_list_types),
557 .types = rtnl_vf_vlan_list_types,
558};
559
560static const NLType rtnl_vf_vlan_info_types[] = {
561 [IFLA_VF_MAC] = { .size = sizeof(struct ifla_vf_mac) },
562 [IFLA_VF_VLAN] = { .size = sizeof(struct ifla_vf_vlan) },
563 [IFLA_VF_VLAN_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_type_system},
564 [IFLA_VF_TX_RATE] = { .size = sizeof(struct ifla_vf_tx_rate) },
565 [IFLA_VF_SPOOFCHK] = { .size = sizeof(struct ifla_vf_spoofchk) },
566 [IFLA_VF_RATE] = { .size = sizeof(struct ifla_vf_rate) },
567 [IFLA_VF_LINK_STATE] = { .size = sizeof(struct ifla_vf_link_state) },
568 [IFLA_VF_RSS_QUERY_EN] = { .size = sizeof(struct ifla_vf_rss_query_en) },
569 [IFLA_VF_TRUST] = { .size = sizeof(struct ifla_vf_trust) },
570 [IFLA_VF_IB_NODE_GUID] = { .size = sizeof(struct ifla_vf_guid) },
571 [IFLA_VF_IB_PORT_GUID] = { .size = sizeof(struct ifla_vf_guid) },
572};
573
574static const NLTypeSystem rtnl_vf_vlan_info_type_system = {
575 .count = ELEMENTSOF(rtnl_vf_vlan_info_types),
576 .types = rtnl_vf_vlan_info_types,
577};
578
579static const NLType rtnl_link_io_srv_types[] = {
580 [IFLA_VF_INFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_info_type_system },
581};
582
583static const NLTypeSystem rtnl_io_srv_type_system = {
584 .count = ELEMENTSOF(rtnl_link_io_srv_types),
585 .types = rtnl_link_io_srv_types,
586};
587
8ae4b6d1 588static const NLType rtnl_link_types[] = {
6e74cade
ZJS
589 [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
590 [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
591 [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
cafbc790
DH
592 [IFLA_MTU] = { .type = NETLINK_TYPE_U32 },
593 [IFLA_LINK] = { .type = NETLINK_TYPE_U32 },
83949527 594 [IFLA_QDISC] = { .type = NETLINK_TYPE_STRING },
c095e5b0
YW
595 [IFLA_STATS] = { .size = sizeof(struct rtnl_link_stats) },
596/*
d8e538ec
TG
597 [IFLA_COST],
598 [IFLA_PRIORITY],
599*/
cafbc790 600 [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
601/*
602 [IFLA_WIRELESS],
d8e538ec 603*/
cafbc790
DH
604 [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
605 [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
606/*
607 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
608*/
cafbc790
DH
609 [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 },
610 [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 },
611 [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 },
612 [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
613 [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
614 [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
5908ddd7
SS
615 [IFLA_NUM_VF] = { .type = NETLINK_TYPE_U32 },
616 [IFLA_VFINFO_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_io_srv_type_system },
c095e5b0
YW
617 [IFLA_STATS64] = { .size = sizeof(struct rtnl_link_stats64) },
618/*
cafbc790
DH
619 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
620 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
c149ae08 621*/
cafbc790 622 [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system },
c149ae08 623/*
d8e538ec
TG
624 [IFLA_VF_PORTS],
625 [IFLA_PORT_SELF],
626 [IFLA_AF_SPEC],
627*/
cafbc790
DH
628 [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 },
629 [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 },
630 [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 },
631 [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 },
632 [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 },
633 [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 },
634 [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 },
d8e538ec 635/*
cafbc790 636 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
d8e538ec 637*/
ffeb16f5
YW
638 [IFLA_MIN_MTU] = { .type = NETLINK_TYPE_U32 },
639 [IFLA_MAX_MTU] = { .type = NETLINK_TYPE_U32 },
640 [IFLA_PROP_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_prop_list_type_system },
b04c5e51 641 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
d8e538ec
TG
642};
643
644static const NLTypeSystem rtnl_link_type_system = {
c1df8dee 645 .count = ELEMENTSOF(rtnl_link_types),
d8e538ec
TG
646 .types = rtnl_link_types,
647};
648
de79f906
LP
649/* IFA_FLAGS was defined in kernel 3.14, but we still support older
650 * kernels where IFA_MAX is lower. */
8ae4b6d1 651static const NLType rtnl_address_types[] = {
cafbc790
DH
652 [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR },
653 [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
654 [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
655 [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
656 [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
d8e538ec
TG
657/*
658 [IFA_ANYCAST],
d8e538ec
TG
659 [IFA_MULTICAST],
660*/
cafbc790 661 [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
662};
663
664static const NLTypeSystem rtnl_address_type_system = {
c1df8dee 665 .count = ELEMENTSOF(rtnl_address_types),
d8e538ec
TG
666 .types = rtnl_address_types,
667};
668
d6fceaf1
SS
669/* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
670
671static const NLType rtnl_route_metrics_types[] = {
f4679bcb
SS
672 [RTAX_MTU] = { .type = NETLINK_TYPE_U32 },
673 [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 },
674 [RTAX_RTT] = { .type = NETLINK_TYPE_U32 },
675 [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 },
676 [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 },
677 [RTAX_CWND] = { .type = NETLINK_TYPE_U32 },
678 [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 },
679 [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 },
680 [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 },
681 [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 },
682 [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 },
683 [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 },
684 [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 },
685 [RTAX_QUICKACK] = { .type = NETLINK_TYPE_U32 },
686 [RTAX_CC_ALGO] = { .type = NETLINK_TYPE_U32 },
687 [RTAX_FASTOPEN_NO_COOKIE] = { .type = NETLINK_TYPE_U32 },
d6fceaf1
SS
688};
689
690static const NLTypeSystem rtnl_route_metrics_type_system = {
691 .count = ELEMENTSOF(rtnl_route_metrics_types),
692 .types = rtnl_route_metrics_types,
693};
694
8ae4b6d1 695static const NLType rtnl_route_types[] = {
cafbc790
DH
696 [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
697 [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
698 [RTA_IIF] = { .type = NETLINK_TYPE_U32 },
699 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
700 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
701 [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
702 [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
d6fceaf1 703 [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system},
cb7e98ab 704 [RTA_MULTIPATH] = { .size = sizeof(struct rtnexthop) },
cafbc790 705 [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */
cb7e98ab
SS
706 [RTA_CACHEINFO] = { .size = sizeof(struct rta_cacheinfo) },
707 [RTA_TABLE] = { .type = NETLINK_TYPE_U32 },
708 [RTA_MARK] = { .type = NETLINK_TYPE_U32 },
709 [RTA_MFC_STATS] = { .type = NETLINK_TYPE_U64 },
710 [RTA_VIA] = { .type = NETLINK_TYPE_U32 },
711 [RTA_NEWDST] = { .type = NETLINK_TYPE_U32 },
b69015ef 712 [RTA_PREF] = { .type = NETLINK_TYPE_U8 },
f02ba163 713 [RTA_EXPIRES] = { .type = NETLINK_TYPE_U32 },
cb7e98ab
SS
714 [RTA_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
715 [RTA_ENCAP] = { .type = NETLINK_TYPE_NESTED }, /* Multiple type systems i.e. LWTUNNEL_ENCAP_MPLS/LWTUNNEL_ENCAP_IP/LWTUNNEL_ENCAP_ILA etc... */
716 [RTA_UID] = { .type = NETLINK_TYPE_U32 },
717 [RTA_TTL_PROPAGATE] = { .type = NETLINK_TYPE_U8 },
718 [RTA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
719 [RTA_SPORT] = { .type = NETLINK_TYPE_U16 },
720 [RTA_DPORT] = { .type = NETLINK_TYPE_U16 },
d8e538ec
TG
721};
722
723static const NLTypeSystem rtnl_route_type_system = {
c1df8dee 724 .count = ELEMENTSOF(rtnl_route_types),
d8e538ec
TG
725 .types = rtnl_route_types,
726};
727
8ae4b6d1 728static const NLType rtnl_neigh_types[] = {
cafbc790 729 [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
1647f241 730 [NDA_LLADDR] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
cafbc790
DH
731 [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
732 [NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
733 [NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
734 [NDA_PORT] = { .type = NETLINK_TYPE_U16 },
735 [NDA_VNI] = { .type = NETLINK_TYPE_U32 },
736 [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 },
e559b384
TG
737};
738
739static const NLTypeSystem rtnl_neigh_type_system = {
c1df8dee 740 .count = ELEMENTSOF(rtnl_neigh_types),
e559b384
TG
741 .types = rtnl_neigh_types,
742};
743
30746d60
SS
744static const NLType rtnl_addrlabel_types[] = {
745 [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) },
746 [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 },
747};
748
749static const NLTypeSystem rtnl_addrlabel_type_system = {
750 .count = ELEMENTSOF(rtnl_addrlabel_types),
751 .types = rtnl_addrlabel_types,
752};
753
bce67bbe
SS
754static const NLType rtnl_routing_policy_rule_types[] = {
755 [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
756 [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR },
757 [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING },
8abd60c1 758 [FRA_GOTO] = { .type = NETLINK_TYPE_U32 },
bce67bbe
SS
759 [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
760 [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 },
761 [FRA_FLOW] = { .type = NETLINK_TYPE_U32 },
202aa159 762 [FRA_TUN_ID] = { .type = NETLINK_TYPE_U64 },
bce67bbe
SS
763 [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 },
764 [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 },
765 [FRA_TABLE] = { .type = NETLINK_TYPE_U32 },
766 [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 },
767 [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING },
768 [FRA_PAD] = { .type = NETLINK_TYPE_U32 },
a15ff62d 769 [FRA_L3MDEV] = { .type = NETLINK_TYPE_U8 },
bce67bbe 770 [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) },
926062f0
SS
771 [FRA_PROTOCOL] = { .type = NETLINK_TYPE_U8 },
772 [FRA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
773 [FRA_SPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
774 [FRA_DPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
bce67bbe
SS
775};
776
777static const NLTypeSystem rtnl_routing_policy_rule_type_system = {
778 .count = ELEMENTSOF(rtnl_routing_policy_rule_types),
779 .types = rtnl_routing_policy_rule_types,
780};
781
c16c7808
SS
782static const NLType rtnl_nexthop_types[] = {
783 [NHA_ID] = { .type = NETLINK_TYPE_U32 },
784 [NHA_OIF] = { .type = NETLINK_TYPE_U32 },
785 [NHA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
786};
787
788static const NLTypeSystem rtnl_nexthop_type_system = {
789 .count = ELEMENTSOF(rtnl_nexthop_types),
790 .types = rtnl_nexthop_types,
791};
792
ad8352f4
SS
793static const NLType rtnl_tca_option_data_cake_types[] = {
794 [TCA_CAKE_BASE_RATE64] = { .type = NETLINK_TYPE_U64 },
795 [TCA_CAKE_OVERHEAD] = { .type = NETLINK_TYPE_S32 },
796 [TCA_CAKE_MPU] = { .type = NETLINK_TYPE_U32 },
797};
798
a9a5d632 799static const NLType rtnl_tca_option_data_codel_types[] = {
b078e528
YW
800 [TCA_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
801 [TCA_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
802 [TCA_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
803 [TCA_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
804 [TCA_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
a9a5d632
SS
805};
806
5c21b46e
SS
807static const NLType rtnl_tca_option_data_drr_types[] = {
808 [TCA_DRR_QUANTUM] = { .type = NETLINK_TYPE_U32 },
809};
810
4dec9218
YW
811static const NLType rtnl_tca_option_data_ets_quanta_types[] = {
812 [TCA_ETS_QUANTA_BAND] = { .type = NETLINK_TYPE_U32, },
813};
814
815static const NLTypeSystem rtnl_tca_option_data_ets_quanta_type_system = {
816 .count = ELEMENTSOF(rtnl_tca_option_data_ets_quanta_types),
817 .types = rtnl_tca_option_data_ets_quanta_types,
818};
819
820static const NLType rtnl_tca_option_data_ets_prio_types[] = {
821 [TCA_ETS_PRIOMAP_BAND] = { .type = NETLINK_TYPE_U8, },
822};
823
824static const NLTypeSystem rtnl_tca_option_data_ets_prio_type_system = {
825 .count = ELEMENTSOF(rtnl_tca_option_data_ets_prio_types),
826 .types = rtnl_tca_option_data_ets_prio_types,
827};
828
829static const NLType rtnl_tca_option_data_ets_types[] = {
830 [TCA_ETS_NBANDS] = { .type = NETLINK_TYPE_U8 },
831 [TCA_ETS_NSTRICT] = { .type = NETLINK_TYPE_U8 },
832 [TCA_ETS_QUANTA] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_option_data_ets_quanta_type_system },
833 [TCA_ETS_PRIOMAP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_option_data_ets_prio_type_system },
834 [TCA_ETS_QUANTA_BAND] = { .type = NETLINK_TYPE_U32 },
835};
836
eb34f4b3
YW
837static const NLType rtnl_tca_option_data_fq_types[] = {
838 [TCA_FQ_PLIMIT] = { .type = NETLINK_TYPE_U32 },
839 [TCA_FQ_FLOW_PLIMIT] = { .type = NETLINK_TYPE_U32 },
840 [TCA_FQ_QUANTUM] = { .type = NETLINK_TYPE_U32 },
841 [TCA_FQ_INITIAL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
842 [TCA_FQ_RATE_ENABLE] = { .type = NETLINK_TYPE_U32 },
843 [TCA_FQ_FLOW_DEFAULT_RATE] = { .type = NETLINK_TYPE_U32 },
844 [TCA_FQ_FLOW_MAX_RATE] = { .type = NETLINK_TYPE_U32 },
845 [TCA_FQ_BUCKETS_LOG] = { .type = NETLINK_TYPE_U32 },
846 [TCA_FQ_FLOW_REFILL_DELAY] = { .type = NETLINK_TYPE_U32 },
847 [TCA_FQ_LOW_RATE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
848 [TCA_FQ_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
e83562e5 849 [TCA_FQ_ORPHAN_MASK] = { .type = NETLINK_TYPE_U32 },
42b5f7dd
YW
850};
851
852static const NLType rtnl_tca_option_data_fq_codel_types[] = {
853 [TCA_FQ_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
854 [TCA_FQ_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
855 [TCA_FQ_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
856 [TCA_FQ_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
857 [TCA_FQ_CODEL_FLOWS] = { .type = NETLINK_TYPE_U32 },
858 [TCA_FQ_CODEL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
859 [TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
860 [TCA_FQ_CODEL_DROP_BATCH_SIZE] = { .type = NETLINK_TYPE_U32 },
861 [TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NETLINK_TYPE_U32 },
862};
863
609e8340
SS
864static const NLType rtnl_tca_option_data_gred_types[] = {
865 [TCA_GRED_DPS] = { .size = sizeof(struct tc_gred_sopt) },
866};
867
7e16f84e
SS
868static const NLType rtnl_tca_option_data_hhf_types[] = {
869 [TCA_HHF_BACKLOG_LIMIT] = { .type = NETLINK_TYPE_U32 },
870};
871
b934ac3d 872static const NLType rtnl_tca_option_data_htb_types[] = {
19f86a63
YW
873 [TCA_HTB_PARMS] = { .size = sizeof(struct tc_htb_opt) },
874 [TCA_HTB_INIT] = { .size = sizeof(struct tc_htb_glob) },
875 [TCA_HTB_CTAB] = { .size = TC_RTAB_SIZE },
876 [TCA_HTB_RTAB] = { .size = TC_RTAB_SIZE },
877 [TCA_HTB_RATE64] = { .type = NETLINK_TYPE_U64 },
878 [TCA_HTB_CEIL64] = { .type = NETLINK_TYPE_U64 },
b934ac3d
YW
879};
880
55d22831
SS
881static const NLType rtnl_tca_option_data_pie_types[] = {
882 [TCA_PIE_LIMIT] = { .type = NETLINK_TYPE_U32 },
883};
884
c33f1e5a
SS
885static const NLType rtnl_tca_option_data_qfq_types[] = {
886 [TCA_QFQ_WEIGHT] = { .type = NETLINK_TYPE_U32 },
887 [TCA_QFQ_LMAX] = { .type = NETLINK_TYPE_U32 },
888};
889
982998b0
SS
890static const NLType rtnl_tca_option_data_sfb_types[] = {
891 [TCA_SFB_PARMS] = { .size = sizeof(struct tc_sfb_qopt) },
892};
893
eb34f4b3
YW
894static const NLType rtnl_tca_option_data_tbf_types[] = {
895 [TCA_TBF_PARMS] = { .size = sizeof(struct tc_tbf_qopt) },
896 [TCA_TBF_RTAB] = { .size = TC_RTAB_SIZE },
897 [TCA_TBF_PTAB] = { .size = TC_RTAB_SIZE },
898 [TCA_TBF_RATE64] = { .type = NETLINK_TYPE_U64 },
899 [TCA_TBF_PRATE64] = { .type = NETLINK_TYPE_U64 },
900 [TCA_TBF_BURST] = { .type = NETLINK_TYPE_U32 },
901 [TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 },
902};
903
42b5f7dd 904static const char* const nl_union_tca_option_data_table[] = {
ad8352f4 905 [NL_UNION_TCA_OPTION_DATA_CAKE] = "cake",
a9a5d632 906 [NL_UNION_TCA_OPTION_DATA_CODEL] = "codel",
5c21b46e 907 [NL_UNION_TCA_OPTION_DATA_DRR] = "drr",
4dec9218 908 [NL_UNION_TCA_OPTION_DATA_ETS] = "ets",
eb34f4b3 909 [NL_UNION_TCA_OPTION_DATA_FQ] = "fq",
42b5f7dd 910 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel",
609e8340 911 [NL_UNION_TCA_OPTION_DATA_GRED] = "gred",
7e16f84e 912 [NL_UNION_TCA_OPTION_DATA_HHF] = "hhf",
b934ac3d 913 [NL_UNION_TCA_OPTION_DATA_HTB] = "htb",
55d22831 914 [NL_UNION_TCA_OPTION_DATA_PIE] = "pie",
c33f1e5a 915 [NL_UNION_TCA_OPTION_DATA_QFQ] = "qfq",
982998b0 916 [NL_UNION_TCA_OPTION_DATA_SFB] = "sfb",
eb34f4b3 917 [NL_UNION_TCA_OPTION_DATA_TBF] = "tbf",
42b5f7dd
YW
918};
919
920DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData);
921
922static const NLTypeSystem rtnl_tca_option_data_type_systems[] = {
ad8352f4
SS
923 [NL_UNION_TCA_OPTION_DATA_CAKE] = { .count = ELEMENTSOF(rtnl_tca_option_data_cake_types),
924 .types = rtnl_tca_option_data_cake_types },
a9a5d632
SS
925 [NL_UNION_TCA_OPTION_DATA_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_codel_types),
926 .types = rtnl_tca_option_data_codel_types },
5c21b46e
SS
927 [NL_UNION_TCA_OPTION_DATA_DRR] = { .count = ELEMENTSOF(rtnl_tca_option_data_drr_types),
928 .types = rtnl_tca_option_data_drr_types },
4dec9218
YW
929 [NL_UNION_TCA_OPTION_DATA_ETS] = { .count = ELEMENTSOF(rtnl_tca_option_data_ets_types),
930 .types = rtnl_tca_option_data_ets_types },
eb34f4b3
YW
931 [NL_UNION_TCA_OPTION_DATA_FQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_types),
932 .types = rtnl_tca_option_data_fq_types },
42b5f7dd
YW
933 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types),
934 .types = rtnl_tca_option_data_fq_codel_types },
609e8340
SS
935 [NL_UNION_TCA_OPTION_DATA_GRED] = { .count = ELEMENTSOF(rtnl_tca_option_data_gred_types),
936 .types = rtnl_tca_option_data_gred_types },
7e16f84e
SS
937 [NL_UNION_TCA_OPTION_DATA_HHF] = { .count = ELEMENTSOF(rtnl_tca_option_data_hhf_types),
938 .types = rtnl_tca_option_data_hhf_types },
b934ac3d
YW
939 [NL_UNION_TCA_OPTION_DATA_HTB] = { .count = ELEMENTSOF(rtnl_tca_option_data_htb_types),
940 .types = rtnl_tca_option_data_htb_types },
55d22831
SS
941 [NL_UNION_TCA_OPTION_DATA_PIE] = { .count = ELEMENTSOF(rtnl_tca_option_data_pie_types),
942 .types = rtnl_tca_option_data_pie_types },
c33f1e5a
SS
943 [NL_UNION_TCA_OPTION_DATA_QFQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_qfq_types),
944 .types = rtnl_tca_option_data_qfq_types },
982998b0
SS
945 [NL_UNION_TCA_OPTION_DATA_SFB] = { .count = ELEMENTSOF(rtnl_tca_option_data_sfb_types),
946 .types = rtnl_tca_option_data_sfb_types },
eb34f4b3
YW
947 [NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
948 .types = rtnl_tca_option_data_tbf_types },
42b5f7dd
YW
949};
950
951static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = {
952 .num = _NL_UNION_TCA_OPTION_DATA_MAX,
953 .lookup = nl_union_tca_option_data_from_string,
954 .type_systems = rtnl_tca_option_data_type_systems,
955 .match_type = NL_MATCH_SIBLING,
956 .match = TCA_KIND,
957};
958
0ebb76de 959static const NLType rtnl_tca_types[] = {
0f5bd7fe 960 [TCA_KIND] = { .type = NETLINK_TYPE_STRING },
42b5f7dd 961 [TCA_OPTIONS] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_tca_option_data_type_system_union },
0f5bd7fe
SS
962 [TCA_INGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
963 [TCA_EGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
964};
965
0ebb76de
YW
966static const NLTypeSystem rtnl_tca_type_system = {
967 .count = ELEMENTSOF(rtnl_tca_types),
968 .types = rtnl_tca_types,
0f5bd7fe
SS
969};
970
1903c9bb
DM
971static const NLType mdb_types[] = {
972 [MDBA_SET_ENTRY] = { .size = sizeof(struct br_port_msg) },
973};
974
975static const NLTypeSystem rtnl_mdb_type_system = {
976 .count = ELEMENTSOF(mdb_types),
977 .types = mdb_types,
978};
979
e4a1e68d
YW
980static const NLType error_types[] = {
981 [NLMSGERR_ATTR_MSG] = { .type = NETLINK_TYPE_STRING },
982 [NLMSGERR_ATTR_OFFS] = { .type = NETLINK_TYPE_U32 },
983};
984
985static const NLTypeSystem error_type_system = {
986 .count = ELEMENTSOF(error_types),
987 .types = error_types,
988};
989
8ae4b6d1 990static const NLType rtnl_types[] = {
30746d60 991 [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 },
e4a1e68d 992 [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
30746d60
SS
993 [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
994 [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
995 [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
996 [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
ffeb16f5
YW
997 [RTM_NEWLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
998 [RTM_DELLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
999 [RTM_GETLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
30746d60
SS
1000 [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1001 [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1002 [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1003 [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1004 [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1005 [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1006 [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1007 [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1008 [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1009 [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
1010 [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
1011 [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
bce67bbe
SS
1012 [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
1013 [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
1014 [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
c16c7808
SS
1015 [RTM_NEWNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
1016 [RTM_DELNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
1017 [RTM_GETNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
0ebb76de
YW
1018 [RTM_NEWQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1019 [RTM_DELQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1020 [RTM_GETQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1021 [RTM_NEWTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1022 [RTM_DELTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1023 [RTM_GETTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1903c9bb
DM
1024 [RTM_NEWMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
1025 [RTM_DELMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
1026 [RTM_GETMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
d8e538ec
TG
1027};
1028
05d0c2e3 1029const NLTypeSystem rtnl_type_system_root = {
c1df8dee 1030 .count = ELEMENTSOF(rtnl_types),
d8e538ec
TG
1031 .types = rtnl_types,
1032};
1033
e5719363
JT
1034static const NLType genl_wireguard_allowedip_types[] = {
1035 [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 },
1036 [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1037 [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 },
1038};
1039
1040static const NLTypeSystem genl_wireguard_allowedip_type_system = {
1041 .count = ELEMENTSOF(genl_wireguard_allowedip_types),
1042 .types = genl_wireguard_allowedip_types,
1043};
1044
1045static const NLType genl_wireguard_peer_types[] = {
1046 [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN },
1047 [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
1048 [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN },
7d0b26a0 1049 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 },
abd48ec8 1050 [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR },
e5719363
JT
1051 [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system },
1052};
1053
1054static const NLTypeSystem genl_wireguard_peer_type_system = {
1055 .count = ELEMENTSOF(genl_wireguard_peer_types),
1056 .types = genl_wireguard_peer_types,
1057};
1058
1059static const NLType genl_wireguard_set_device_types[] = {
1060 [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 },
33c2ea80 1061 [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 },
e5719363
JT
1062 [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
1063 [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN },
1064 [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 },
1065 [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 },
1066 [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system },
1067};
1068
1069static const NLTypeSystem genl_wireguard_set_device_type_system = {
1070 .count = ELEMENTSOF(genl_wireguard_set_device_types),
1071 .types = genl_wireguard_set_device_types,
1072};
1073
1074static const NLType genl_wireguard_cmds[] = {
1075 [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system },
1076};
1077
1078static const NLTypeSystem genl_wireguard_type_system = {
1079 .count = ELEMENTSOF(genl_wireguard_cmds),
1080 .types = genl_wireguard_cmds,
1081};
05d0c2e3 1082
8fab2747
YW
1083static const NLType genl_mcast_group_types[] = {
1084 [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NETLINK_TYPE_STRING },
1085 [CTRL_ATTR_MCAST_GRP_ID] = { .type = NETLINK_TYPE_U32 },
1086};
1087
1088static const NLTypeSystem genl_mcast_group_type_system = {
1089 .count = ELEMENTSOF(genl_mcast_group_types),
1090 .types = genl_mcast_group_types,
1091};
1092
05d0c2e3 1093static const NLType genl_get_family_types[] = {
8fab2747
YW
1094 [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING },
1095 [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 },
1096 [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_mcast_group_type_system },
05d0c2e3
JT
1097};
1098
1099static const NLTypeSystem genl_get_family_type_system = {
1100 .count = ELEMENTSOF(genl_get_family_types),
1101 .types = genl_get_family_types,
1102};
1103
1104static const NLType genl_ctrl_id_ctrl_cmds[] = {
1105 [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system },
1106};
1107
1108static const NLTypeSystem genl_ctrl_id_ctrl_type_system = {
1109 .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds),
1110 .types = genl_ctrl_id_ctrl_cmds,
1111};
1112
53cb501a
SS
1113static const NLType genl_fou_types[] = {
1114 [FOU_ATTR_PORT] = { .type = NETLINK_TYPE_U16 },
1115 [FOU_ATTR_AF] = { .type = NETLINK_TYPE_U8 },
1116 [FOU_ATTR_IPPROTO] = { .type = NETLINK_TYPE_U8 },
1117 [FOU_ATTR_TYPE] = { .type = NETLINK_TYPE_U8 },
1118 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
397a74dd
SS
1119 [FOU_ATTR_LOCAL_V4] = { .type = NETLINK_TYPE_IN_ADDR },
1120 [FOU_ATTR_PEER_V4] = { .type = NETLINK_TYPE_IN_ADDR },
1121 [FOU_ATTR_LOCAL_V6] = { .type = NETLINK_TYPE_IN_ADDR },
1122 [FOU_ATTR_PEER_V6] = { .type = NETLINK_TYPE_IN_ADDR},
1123 [FOU_ATTR_PEER_PORT] = { .type = NETLINK_TYPE_U16},
1124 [FOU_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32},
53cb501a
SS
1125};
1126
1127static const NLTypeSystem genl_fou_type_system = {
1128 .count = ELEMENTSOF(genl_fou_types),
1129 .types = genl_fou_types,
1130};
1131
1132static const NLType genl_fou_cmds[] = {
1133 [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1134 [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1135 [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1136};
1137
1138static const NLTypeSystem genl_fou_cmds_type_system = {
1139 .count = ELEMENTSOF(genl_fou_cmds),
1140 .types = genl_fou_cmds,
1141};
1142
3a56e697
SS
1143static const NLType genl_l2tp_types[] = {
1144 [L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 },
1145 [L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
1146 [L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 },
1147 [L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 },
1148 [L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 },
1149 [L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 },
1150 [L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 },
1151 [L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING },
1152 [L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1153 [L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1154 [L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1155 [L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1156 [L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
1157 [L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
1158 [L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 },
1159 [L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 },
1160 [L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 },
1161 [L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 },
1162 [L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 },
1163 [L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1164 [L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1165 [L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 },
1166 [L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 },
1167 [L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1168 [L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1169 [L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG },
1170 [L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG },
1171};
1172
1173static const NLTypeSystem genl_l2tp_type_system = {
1174 .count = ELEMENTSOF(genl_l2tp_types),
1175 .types = genl_l2tp_types,
1176};
1177
1178static const NLType genl_l2tp[] = {
1179 [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1180 [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1181 [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1182 [L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1183 [L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1184 [L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1185 [L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1186 [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1187};
1188
1189static const NLTypeSystem genl_l2tp_tunnel_session_type_system = {
1190 .count = ELEMENTSOF(genl_l2tp),
1191 .types = genl_l2tp,
1192};
1193
81962db7
SS
1194static const NLType genl_rxsc_types[] = {
1195 [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 },
1196};
1197
1198static const NLTypeSystem genl_rxsc_config_type_system = {
1199 .count = ELEMENTSOF(genl_rxsc_types),
1200 .types = genl_rxsc_types,
1201};
1202
1203static const NLType genl_macsec_rxsc_types[] = {
1204 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1205 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1206};
1207
1208static const NLTypeSystem genl_macsec_rxsc_type_system = {
1209 .count = ELEMENTSOF(genl_macsec_rxsc_types),
1210 .types = genl_macsec_rxsc_types,
1211};
1212
1213static const NLType genl_macsec_sa_config_types[] = {
1214 [MACSEC_SA_ATTR_AN] = { .type = NETLINK_TYPE_U8 },
1215 [MACSEC_SA_ATTR_ACTIVE] = { .type = NETLINK_TYPE_U8 },
1216 [MACSEC_SA_ATTR_PN] = { .type = NETLINK_TYPE_U32 },
1217 [MACSEC_SA_ATTR_KEYID] = { .size = MACSEC_KEYID_LEN },
1218 [MACSEC_SA_ATTR_KEY] = { .size = MACSEC_MAX_KEY_LEN },
1219};
1220
1221static const NLTypeSystem genl_macsec_sa_config_type_system = {
1222 .count = ELEMENTSOF(genl_macsec_sa_config_types),
1223 .types = genl_macsec_sa_config_types,
1224};
1225
1226static const NLType genl_macsec_rxsa_types[] = {
1227 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1228 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1229};
1230
1231static const NLTypeSystem genl_macsec_rxsa_type_system = {
1232 .count = ELEMENTSOF(genl_macsec_rxsa_types),
1233 .types = genl_macsec_rxsa_types,
1234};
1235
1236static const NLType genl_macsec_sa_types[] = {
1237 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1238 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1239 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1240};
1241
1242static const NLTypeSystem genl_macsec_sa_type_system = {
1243 .count = ELEMENTSOF(genl_macsec_sa_types),
1244 .types = genl_macsec_sa_types,
1245};
1246
1247static const NLType genl_macsec[] = {
1248 [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system },
1249 [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsa_type_system},
1250 [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system },
1251};
1252
1253static const NLTypeSystem genl_macsec_device_type_system = {
1254 .count = ELEMENTSOF(genl_macsec),
1255 .types = genl_macsec,
1256};
1257
a1d736e2
YW
1258static const NLType genl_nl80211_types[] = {
1259 [NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1260 [NL80211_ATTR_MAC] = { .type = NETLINK_TYPE_ETHER_ADDR },
1261 [NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_STRING },
78404d22 1262 [NL80211_ATTR_IFTYPE] = { .type = NETLINK_TYPE_U32 },
a1d736e2
YW
1263};
1264
1265static const NLTypeSystem genl_nl80211_type_system = {
1266 .count = ELEMENTSOF(genl_nl80211_types),
1267 .types = genl_nl80211_types,
1268};
1269
1270static const NLType genl_nl80211_cmds[] = {
1271 [NL80211_CMD_GET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1272 [NL80211_CMD_SET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1273 [NL80211_CMD_NEW_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1274 [NL80211_CMD_DEL_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1275 [NL80211_CMD_GET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1276 [NL80211_CMD_SET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1277 [NL80211_CMD_NEW_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1278 [NL80211_CMD_DEL_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1279 [NL80211_CMD_GET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1280 [NL80211_CMD_SET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1281 [NL80211_CMD_NEW_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1282 [NL80211_CMD_DEL_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1283};
1284
1285static const NLTypeSystem genl_nl80211_cmds_type_system = {
1286 .count = ELEMENTSOF(genl_nl80211_cmds),
1287 .types = genl_nl80211_cmds,
1288};
1289
05d0c2e3 1290static const NLType genl_families[] = {
53cb501a 1291 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system },
e5719363 1292 [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system },
2be081ff 1293 [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system },
3a56e697 1294 [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system },
81962db7 1295 [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_device_type_system },
a1d736e2 1296 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmds_type_system },
05d0c2e3
JT
1297};
1298
4e8f0ef9 1299/* Mainly used when sending message */
05d0c2e3
JT
1300const NLTypeSystem genl_family_type_system_root = {
1301 .count = ELEMENTSOF(genl_families),
1302 .types = genl_families,
1303};
1304
1305static const NLType genl_types[] = {
e4a1e68d 1306 [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
2be081ff 1307 [SD_GENL_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system },
4e8f0ef9 1308 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) },
a1d736e2 1309 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system, .size = sizeof(struct genlmsghdr) },
05d0c2e3
JT
1310};
1311
4e8f0ef9 1312/* Mainly used when message received */
05d0c2e3
JT
1313const NLTypeSystem genl_type_system_root = {
1314 .count = ELEMENTSOF(genl_types),
1315 .types = genl_types,
1316};
1317
817d1cd8
DH
1318uint16_t type_get_type(const NLType *type) {
1319 assert(type);
1320 return type->type;
1321}
1322
1323size_t type_get_size(const NLType *type) {
1324 assert(type);
1325 return type->size;
1326}
1327
c658008f
DH
1328void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) {
1329 assert(nl_type);
1330 assert(ret);
1331 assert(nl_type->type == NETLINK_TYPE_NESTED);
1332 assert(nl_type->type_system);
1333
1334 *ret = nl_type->type_system;
1335}
1336
1337void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) {
1338 assert(nl_type);
1339 assert(ret);
1340 assert(nl_type->type == NETLINK_TYPE_UNION);
1341 assert(nl_type->type_system_union);
1342
1343 *ret = nl_type->type_system_union;
1344}
1345
c1df8dee 1346uint16_t type_system_get_count(const NLTypeSystem *type_system) {
435bbb02 1347 assert(type_system);
c1df8dee 1348 return type_system->count;
435bbb02
DH
1349}
1350
05d0c2e3
JT
1351const NLTypeSystem *type_system_get_root(int protocol) {
1352 switch (protocol) {
1353 case NETLINK_GENERIC:
1354 return &genl_type_system_root;
1355 default: /* NETLINK_ROUTE: */
1356 return &rtnl_type_system_root;
1357 }
1358}
1359
4e8f0ef9
YW
1360int type_system_root_get_type(sd_netlink *nl, const NLType **ret, uint16_t type) {
1361 sd_genl_family family;
1362 const NLType *nl_type;
1363 int r;
1364
1365 if (!nl || nl->protocol != NETLINK_GENERIC)
1366 return type_system_get_type(&rtnl_type_system_root, ret, type);
1367
1368 r = nlmsg_type_to_genl_family(nl, type, &family);
1369 if (r < 0)
1370 return r;
1371
1372 if (family >= genl_type_system_root.count)
1373 return -EOPNOTSUPP;
1374
1375 nl_type = &genl_type_system_root.types[family];
1376
1377 if (nl_type->type == NETLINK_TYPE_UNSPEC)
1378 return -EOPNOTSUPP;
1379
1380 *ret = nl_type;
1381
1382 return 0;
1383}
1384
d8e538ec
TG
1385int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
1386 const NLType *nl_type;
1387
1388 assert(ret);
846a6b3d 1389 assert(type_system);
d8e538ec
TG
1390 assert(type_system->types);
1391
c1df8dee 1392 if (type >= type_system->count)
15411c0c 1393 return -EOPNOTSUPP;
d8e538ec
TG
1394
1395 nl_type = &type_system->types[type];
1396
cafbc790 1397 if (nl_type->type == NETLINK_TYPE_UNSPEC)
15411c0c 1398 return -EOPNOTSUPP;
d8e538ec
TG
1399
1400 *ret = nl_type;
1401
1402 return 0;
1403}
1404
1405int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
1406 const NLType *nl_type;
1407 int r;
1408
1409 assert(ret);
1410
1411 r = type_system_get_type(type_system, &nl_type, type);
1412 if (r < 0)
1413 return r;
1414
c658008f 1415 type_get_type_system(nl_type, ret);
d8e538ec
TG
1416 return 0;
1417}
1418
1419int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
1420 const NLType *nl_type;
1421 int r;
1422
1423 assert(ret);
1424
1425 r = type_system_get_type(type_system, &nl_type, type);
1426 if (r < 0)
1427 return r;
1428
c658008f 1429 type_get_type_system_union(nl_type, ret);
d8e538ec
TG
1430 return 0;
1431}
1432
1433int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
1434 int type;
1435
1436 assert(type_system_union);
f8a6ca1b 1437 assert(type_system_union->match_type == NL_MATCH_SIBLING);
d8e538ec
TG
1438 assert(type_system_union->lookup);
1439 assert(type_system_union->type_systems);
1440 assert(ret);
1441 assert(key);
1442
1443 type = type_system_union->lookup(key);
1444 if (type < 0)
15411c0c 1445 return -EOPNOTSUPP;
d8e538ec
TG
1446
1447 assert(type < type_system_union->num);
1448
1449 *ret = &type_system_union->type_systems[type];
1450
1451 return 0;
1452}
4af7b60d
TG
1453
1454int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
1455 const NLTypeSystem *type_system;
1456
1457 assert(type_system_union);
1458 assert(type_system_union->type_systems);
f8a6ca1b 1459 assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
4af7b60d 1460 assert(ret);
4af7b60d
TG
1461
1462 if (protocol >= type_system_union->num)
15411c0c 1463 return -EOPNOTSUPP;
4af7b60d
TG
1464
1465 type_system = &type_system_union->type_systems[protocol];
e7de105c 1466 if (!type_system->types)
15411c0c 1467 return -EOPNOTSUPP;
4af7b60d
TG
1468
1469 *ret = type_system;
1470
1471 return 0;
1472}