]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-netlink/netlink-types.c
Merge pull request #17185 from yuwata/ethtool-update
[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
af818d03
SS
354static const NLType rtnl_link_info_data_bareudp_types[] = {
355 [IFLA_BAREUDP_PORT] = { .type = NETLINK_TYPE_U16 },
356 [IFLA_BAREUDP_ETHERTYPE] = { .type = NETLINK_TYPE_U16 },
357 [IFLA_BAREUDP_SRCPORT_MIN] = { .type = NETLINK_TYPE_U16 },
358 [IFLA_BAREUDP_MULTIPROTO_MODE] = { .type = NETLINK_TYPE_FLAG },
359};
0a827d10 360/* these strings must match the .kind entries in the kernel */
8ae4b6d1 361static const char* const nl_union_link_info_data_table[] = {
d8e538ec
TG
362 [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
363 [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
364 [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
365 [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
9e358851 366 [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
d8e538ec 367 [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
d1312575 368 [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap",
c4a5ddc9 369 [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
69c317a0 370 [NL_UNION_LINK_INFO_DATA_IPVTAP] = "ipvtap",
6ef81477 371 [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
0a827d10 372 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
8bb088c5 373 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
2266864b 374 [NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan",
1af2536a 375 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
b16492f8
SS
376 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
377 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
0a827d10 378 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
a613382b 379 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
9011ce77 380 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
855ee1a1 381 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
20897a0d 382 [NL_UNION_LINK_INFO_DATA_VRF] = "vrf",
92c918b0 383 [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan",
ca5e8071 384 [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve",
d6df583c 385 [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan",
e5719363 386 [NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard",
56e7fb50 387 [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim",
06828bb6 388 [NL_UNION_LINK_INFO_DATA_CAN] = "can",
81962db7 389 [NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec",
d61e4c5b 390 [NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon",
98d20a17 391 [NL_UNION_LINK_INFO_DATA_XFRM] = "xfrm",
cec1552a 392 [NL_UNION_LINK_INFO_DATA_IFB] = "ifb",
af818d03 393 [NL_UNION_LINK_INFO_DATA_BAREUDP] = "bareudp",
d8e538ec
TG
394};
395
396DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
397
8ae4b6d1 398static const NLTypeSystem rtnl_link_info_data_type_systems[] = {
92c918b0
SS
399 [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
400 .types = rtnl_link_info_data_bond_types },
401 [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
402 .types = rtnl_link_info_data_bridge_types },
403 [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
404 .types = rtnl_link_info_data_vlan_types },
405 [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
406 .types = rtnl_link_info_data_veth_types },
407 [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
408 .types = rtnl_link_info_data_macvlan_types },
409 [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
410 .types = rtnl_link_info_data_macvlan_types },
411 [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
412 .types = rtnl_link_info_data_ipvlan_types },
69c317a0
SS
413 [NL_UNION_LINK_INFO_DATA_IPVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
414 .types = rtnl_link_info_data_ipvlan_types },
92c918b0
SS
415 [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
416 .types = rtnl_link_info_data_vxlan_types },
417 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
418 .types = rtnl_link_info_data_iptun_types },
419 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
420 .types = rtnl_link_info_data_ipgre_types },
2266864b
SS
421 [NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
422 .types = rtnl_link_info_data_ipgre_types },
c1df8dee 423 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
92c918b0
SS
424 .types = rtnl_link_info_data_ipgre_types },
425 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
426 .types = rtnl_link_info_data_ipgre_types },
427 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
428 .types = rtnl_link_info_data_ipgre_types },
429 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
430 .types = rtnl_link_info_data_iptun_types },
431 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
432 .types = rtnl_link_info_data_ipvti_types },
433 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
434 .types = rtnl_link_info_data_ipvti_types },
435 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
436 .types = rtnl_link_info_data_ip6tnl_types },
437 [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
438 .types = rtnl_link_info_data_vrf_types },
ca5e8071
SS
439 [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
440 .types = rtnl_link_info_data_geneve_types },
d6df583c
SS
441 [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
442 .types = rtnl_link_info_data_vxcan_types },
06828bb6
HP
443 [NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types),
444 .types = rtnl_link_info_data_can_types },
81962db7
SS
445 [NL_UNION_LINK_INFO_DATA_MACSEC] = { .count = ELEMENTSOF(rtnl_link_info_data_macsec_types),
446 .types = rtnl_link_info_data_macsec_types },
98d20a17 447 [NL_UNION_LINK_INFO_DATA_XFRM] = { .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
448 .types = rtnl_link_info_data_xfrm_types },
af818d03
SS
449 [NL_UNION_LINK_INFO_DATA_BAREUDP] = { .count = ELEMENTSOF(rtnl_link_info_data_bareudp_types),
450 .types = rtnl_link_info_data_bareudp_types },
d8e538ec
TG
451};
452
453static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
454 .num = _NL_UNION_LINK_INFO_DATA_MAX,
455 .lookup = nl_union_link_info_data_from_string,
456 .type_systems = rtnl_link_info_data_type_systems,
4af7b60d 457 .match_type = NL_MATCH_SIBLING,
d8e538ec
TG
458 .match = IFLA_INFO_KIND,
459};
460
8ae4b6d1 461static const NLType rtnl_link_info_types[] = {
cafbc790 462 [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING },
42b5f7dd 463 [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union },
d8e538ec
TG
464/*
465 [IFLA_INFO_XSTATS],
cafbc790
DH
466 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
467 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
d8e538ec
TG
468*/
469};
470
471static const NLTypeSystem rtnl_link_info_type_system = {
c1df8dee 472 .count = ELEMENTSOF(rtnl_link_info_types),
d8e538ec
TG
473 .types = rtnl_link_info_types,
474};
475
8ae4b6d1 476static const struct NLType rtnl_prot_info_bridge_port_types[] = {
d3aa8b49
SS
477 [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 },
478 [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 },
479 [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 },
480 [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 },
481 [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 },
482 [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 },
483 [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 },
484 [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 },
485 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
486 [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 },
487 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 },
488 [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NETLINK_TYPE_U8 },
489 [IFLA_BRPORT_ROOT_ID] = { .type = NETLINK_TYPE_U8 },
490 [IFLA_BRPORT_BRIDGE_ID] = { .type = NETLINK_TYPE_U8 },
491 [IFLA_BRPORT_DESIGNATED_PORT] = { .type = NETLINK_TYPE_U16 },
492 [IFLA_BRPORT_DESIGNATED_COST] = { .type = NETLINK_TYPE_U16 },
493 [IFLA_BRPORT_ID] = { .type = NETLINK_TYPE_U16 },
494 [IFLA_BRPORT_NO] = { .type = NETLINK_TYPE_U16 },
495 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = { .type = NETLINK_TYPE_U8 },
496 [IFLA_BRPORT_CONFIG_PENDING] = { .type = NETLINK_TYPE_U8 },
497 [IFLA_BRPORT_MESSAGE_AGE_TIMER] = { .type = NETLINK_TYPE_U64 },
498 [IFLA_BRPORT_FORWARD_DELAY_TIMER] = { .type = NETLINK_TYPE_U64 },
499 [IFLA_BRPORT_HOLD_TIMER] = { .type = NETLINK_TYPE_U64 },
500 [IFLA_BRPORT_FLUSH] = { .type = NETLINK_TYPE_U8 },
501 [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
502 [IFLA_BRPORT_PAD] = { .type = NETLINK_TYPE_U8 },
503 [IFLA_BRPORT_MCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
504 [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NETLINK_TYPE_U8 },
505 [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NETLINK_TYPE_U8 },
506 [IFLA_BRPORT_BCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
507 [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
508 [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NETLINK_TYPE_U8 },
509 [IFLA_BRPORT_ISOLATED] = { .type = NETLINK_TYPE_U8 },
510 [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 },
d0159fdc
SS
511};
512
8ae4b6d1 513static const NLTypeSystem rtnl_prot_info_type_systems[] = {
c1df8dee 514 [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
4af7b60d
TG
515 .types = rtnl_prot_info_bridge_port_types },
516};
517
518static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
519 .num = AF_MAX,
520 .type_systems = rtnl_prot_info_type_systems,
521 .match_type = NL_MATCH_PROTOCOL,
d0159fdc
SS
522};
523
8ae4b6d1 524static const struct NLType rtnl_af_spec_inet6_types[] = {
cafbc790 525 [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 },
c149ae08
TG
526/*
527 IFLA_INET6_CONF,
528 IFLA_INET6_STATS,
529 IFLA_INET6_MCAST,
530 IFLA_INET6_CACHEINFO,
531 IFLA_INET6_ICMP6STATS,
532*/
cafbc790
DH
533 [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR },
534 [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 },
c149ae08
TG
535};
536
73cb1c14 537static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
c1df8dee 538 .count = ELEMENTSOF(rtnl_af_spec_inet6_types),
73cb1c14 539 .types = rtnl_af_spec_inet6_types,
c149ae08
TG
540};
541
8ae4b6d1 542static const NLType rtnl_af_spec_types[] = {
cafbc790 543 [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
73cb1c14
TG
544};
545
546static const NLTypeSystem rtnl_af_spec_type_system = {
c1df8dee 547 .count = ELEMENTSOF(rtnl_af_spec_types),
73cb1c14 548 .types = rtnl_af_spec_types,
c149ae08
TG
549};
550
ffeb16f5
YW
551static const NLType rtnl_prop_list_types[] = {
552 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
553};
554
555static const NLTypeSystem rtnl_prop_list_type_system = {
556 .count = ELEMENTSOF(rtnl_prop_list_types),
557 .types = rtnl_prop_list_types,
558};
559
5908ddd7
SS
560static const NLType rtnl_vf_vlan_list_types[] = {
561 [IFLA_VF_VLAN_INFO] = { .size = sizeof(struct ifla_vf_vlan_info) },
562};
563
564static const NLTypeSystem rtnl_vf_vlan_type_system = {
565 .count = ELEMENTSOF(rtnl_vf_vlan_list_types),
566 .types = rtnl_vf_vlan_list_types,
567};
568
569static const NLType rtnl_vf_vlan_info_types[] = {
570 [IFLA_VF_MAC] = { .size = sizeof(struct ifla_vf_mac) },
571 [IFLA_VF_VLAN] = { .size = sizeof(struct ifla_vf_vlan) },
572 [IFLA_VF_VLAN_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_type_system},
573 [IFLA_VF_TX_RATE] = { .size = sizeof(struct ifla_vf_tx_rate) },
574 [IFLA_VF_SPOOFCHK] = { .size = sizeof(struct ifla_vf_spoofchk) },
575 [IFLA_VF_RATE] = { .size = sizeof(struct ifla_vf_rate) },
576 [IFLA_VF_LINK_STATE] = { .size = sizeof(struct ifla_vf_link_state) },
577 [IFLA_VF_RSS_QUERY_EN] = { .size = sizeof(struct ifla_vf_rss_query_en) },
578 [IFLA_VF_TRUST] = { .size = sizeof(struct ifla_vf_trust) },
579 [IFLA_VF_IB_NODE_GUID] = { .size = sizeof(struct ifla_vf_guid) },
580 [IFLA_VF_IB_PORT_GUID] = { .size = sizeof(struct ifla_vf_guid) },
581};
582
583static const NLTypeSystem rtnl_vf_vlan_info_type_system = {
584 .count = ELEMENTSOF(rtnl_vf_vlan_info_types),
585 .types = rtnl_vf_vlan_info_types,
586};
587
588static const NLType rtnl_link_io_srv_types[] = {
589 [IFLA_VF_INFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_info_type_system },
590};
591
592static const NLTypeSystem rtnl_io_srv_type_system = {
593 .count = ELEMENTSOF(rtnl_link_io_srv_types),
594 .types = rtnl_link_io_srv_types,
595};
596
8ae4b6d1 597static const NLType rtnl_link_types[] = {
6e74cade
ZJS
598 [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
599 [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
600 [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
cafbc790
DH
601 [IFLA_MTU] = { .type = NETLINK_TYPE_U32 },
602 [IFLA_LINK] = { .type = NETLINK_TYPE_U32 },
83949527 603 [IFLA_QDISC] = { .type = NETLINK_TYPE_STRING },
c095e5b0
YW
604 [IFLA_STATS] = { .size = sizeof(struct rtnl_link_stats) },
605/*
d8e538ec
TG
606 [IFLA_COST],
607 [IFLA_PRIORITY],
608*/
cafbc790 609 [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
610/*
611 [IFLA_WIRELESS],
d8e538ec 612*/
cafbc790
DH
613 [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
614 [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
615/*
616 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
617*/
cafbc790
DH
618 [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 },
619 [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 },
620 [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 },
621 [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
622 [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
623 [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
5908ddd7
SS
624 [IFLA_NUM_VF] = { .type = NETLINK_TYPE_U32 },
625 [IFLA_VFINFO_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_io_srv_type_system },
c095e5b0
YW
626 [IFLA_STATS64] = { .size = sizeof(struct rtnl_link_stats64) },
627/*
cafbc790
DH
628 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
629 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
c149ae08 630*/
cafbc790 631 [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system },
c149ae08 632/*
d8e538ec
TG
633 [IFLA_VF_PORTS],
634 [IFLA_PORT_SELF],
635 [IFLA_AF_SPEC],
636*/
cafbc790
DH
637 [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 },
638 [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 },
639 [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 },
640 [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 },
641 [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 },
642 [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 },
643 [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 },
d8e538ec 644/*
cafbc790 645 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
d8e538ec 646*/
ffeb16f5
YW
647 [IFLA_MIN_MTU] = { .type = NETLINK_TYPE_U32 },
648 [IFLA_MAX_MTU] = { .type = NETLINK_TYPE_U32 },
649 [IFLA_PROP_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_prop_list_type_system },
b04c5e51 650 [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
d8e538ec
TG
651};
652
653static const NLTypeSystem rtnl_link_type_system = {
c1df8dee 654 .count = ELEMENTSOF(rtnl_link_types),
d8e538ec
TG
655 .types = rtnl_link_types,
656};
657
de79f906
LP
658/* IFA_FLAGS was defined in kernel 3.14, but we still support older
659 * kernels where IFA_MAX is lower. */
8ae4b6d1 660static const NLType rtnl_address_types[] = {
cafbc790
DH
661 [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR },
662 [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
663 [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
664 [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
665 [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
d8e538ec
TG
666/*
667 [IFA_ANYCAST],
d8e538ec
TG
668 [IFA_MULTICAST],
669*/
cafbc790 670 [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
671};
672
673static const NLTypeSystem rtnl_address_type_system = {
c1df8dee 674 .count = ELEMENTSOF(rtnl_address_types),
d8e538ec
TG
675 .types = rtnl_address_types,
676};
677
d6fceaf1
SS
678/* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
679
680static const NLType rtnl_route_metrics_types[] = {
f4679bcb
SS
681 [RTAX_MTU] = { .type = NETLINK_TYPE_U32 },
682 [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 },
683 [RTAX_RTT] = { .type = NETLINK_TYPE_U32 },
684 [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 },
685 [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 },
686 [RTAX_CWND] = { .type = NETLINK_TYPE_U32 },
687 [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 },
688 [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 },
689 [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 },
690 [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 },
691 [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 },
692 [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 },
693 [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 },
694 [RTAX_QUICKACK] = { .type = NETLINK_TYPE_U32 },
695 [RTAX_CC_ALGO] = { .type = NETLINK_TYPE_U32 },
696 [RTAX_FASTOPEN_NO_COOKIE] = { .type = NETLINK_TYPE_U32 },
d6fceaf1
SS
697};
698
699static const NLTypeSystem rtnl_route_metrics_type_system = {
700 .count = ELEMENTSOF(rtnl_route_metrics_types),
701 .types = rtnl_route_metrics_types,
702};
703
8ae4b6d1 704static const NLType rtnl_route_types[] = {
cafbc790
DH
705 [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
706 [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
707 [RTA_IIF] = { .type = NETLINK_TYPE_U32 },
708 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
709 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
710 [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
711 [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
d6fceaf1 712 [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system},
cb7e98ab 713 [RTA_MULTIPATH] = { .size = sizeof(struct rtnexthop) },
cafbc790 714 [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */
cb7e98ab
SS
715 [RTA_CACHEINFO] = { .size = sizeof(struct rta_cacheinfo) },
716 [RTA_TABLE] = { .type = NETLINK_TYPE_U32 },
717 [RTA_MARK] = { .type = NETLINK_TYPE_U32 },
718 [RTA_MFC_STATS] = { .type = NETLINK_TYPE_U64 },
2c59a8a6 719 [RTA_VIA] = { /* See struct rtvia */ },
cb7e98ab 720 [RTA_NEWDST] = { .type = NETLINK_TYPE_U32 },
b69015ef 721 [RTA_PREF] = { .type = NETLINK_TYPE_U8 },
f02ba163 722 [RTA_EXPIRES] = { .type = NETLINK_TYPE_U32 },
cb7e98ab
SS
723 [RTA_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
724 [RTA_ENCAP] = { .type = NETLINK_TYPE_NESTED }, /* Multiple type systems i.e. LWTUNNEL_ENCAP_MPLS/LWTUNNEL_ENCAP_IP/LWTUNNEL_ENCAP_ILA etc... */
725 [RTA_UID] = { .type = NETLINK_TYPE_U32 },
726 [RTA_TTL_PROPAGATE] = { .type = NETLINK_TYPE_U8 },
727 [RTA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
728 [RTA_SPORT] = { .type = NETLINK_TYPE_U16 },
729 [RTA_DPORT] = { .type = NETLINK_TYPE_U16 },
d8e538ec
TG
730};
731
732static const NLTypeSystem rtnl_route_type_system = {
c1df8dee 733 .count = ELEMENTSOF(rtnl_route_types),
d8e538ec
TG
734 .types = rtnl_route_types,
735};
736
8ae4b6d1 737static const NLType rtnl_neigh_types[] = {
cafbc790 738 [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
1647f241 739 [NDA_LLADDR] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
cafbc790
DH
740 [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
741 [NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
742 [NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
743 [NDA_PORT] = { .type = NETLINK_TYPE_U16 },
744 [NDA_VNI] = { .type = NETLINK_TYPE_U32 },
745 [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 },
e559b384
TG
746};
747
748static const NLTypeSystem rtnl_neigh_type_system = {
c1df8dee 749 .count = ELEMENTSOF(rtnl_neigh_types),
e559b384
TG
750 .types = rtnl_neigh_types,
751};
752
30746d60
SS
753static const NLType rtnl_addrlabel_types[] = {
754 [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) },
755 [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 },
756};
757
758static const NLTypeSystem rtnl_addrlabel_type_system = {
759 .count = ELEMENTSOF(rtnl_addrlabel_types),
760 .types = rtnl_addrlabel_types,
761};
762
bce67bbe
SS
763static const NLType rtnl_routing_policy_rule_types[] = {
764 [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
765 [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR },
766 [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING },
8abd60c1 767 [FRA_GOTO] = { .type = NETLINK_TYPE_U32 },
bce67bbe
SS
768 [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
769 [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 },
770 [FRA_FLOW] = { .type = NETLINK_TYPE_U32 },
202aa159 771 [FRA_TUN_ID] = { .type = NETLINK_TYPE_U64 },
bce67bbe
SS
772 [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 },
773 [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 },
774 [FRA_TABLE] = { .type = NETLINK_TYPE_U32 },
775 [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 },
776 [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING },
777 [FRA_PAD] = { .type = NETLINK_TYPE_U32 },
a15ff62d 778 [FRA_L3MDEV] = { .type = NETLINK_TYPE_U8 },
bce67bbe 779 [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) },
926062f0
SS
780 [FRA_PROTOCOL] = { .type = NETLINK_TYPE_U8 },
781 [FRA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
782 [FRA_SPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
783 [FRA_DPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
bce67bbe
SS
784};
785
786static const NLTypeSystem rtnl_routing_policy_rule_type_system = {
787 .count = ELEMENTSOF(rtnl_routing_policy_rule_types),
788 .types = rtnl_routing_policy_rule_types,
789};
790
c16c7808
SS
791static const NLType rtnl_nexthop_types[] = {
792 [NHA_ID] = { .type = NETLINK_TYPE_U32 },
793 [NHA_OIF] = { .type = NETLINK_TYPE_U32 },
794 [NHA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
795};
796
797static const NLTypeSystem rtnl_nexthop_type_system = {
798 .count = ELEMENTSOF(rtnl_nexthop_types),
799 .types = rtnl_nexthop_types,
800};
801
ad8352f4
SS
802static const NLType rtnl_tca_option_data_cake_types[] = {
803 [TCA_CAKE_BASE_RATE64] = { .type = NETLINK_TYPE_U64 },
804 [TCA_CAKE_OVERHEAD] = { .type = NETLINK_TYPE_S32 },
805 [TCA_CAKE_MPU] = { .type = NETLINK_TYPE_U32 },
806};
807
a9a5d632 808static const NLType rtnl_tca_option_data_codel_types[] = {
b078e528
YW
809 [TCA_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
810 [TCA_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
811 [TCA_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
812 [TCA_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
813 [TCA_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
a9a5d632
SS
814};
815
5c21b46e
SS
816static const NLType rtnl_tca_option_data_drr_types[] = {
817 [TCA_DRR_QUANTUM] = { .type = NETLINK_TYPE_U32 },
818};
819
4dec9218
YW
820static const NLType rtnl_tca_option_data_ets_quanta_types[] = {
821 [TCA_ETS_QUANTA_BAND] = { .type = NETLINK_TYPE_U32, },
822};
823
824static const NLTypeSystem rtnl_tca_option_data_ets_quanta_type_system = {
825 .count = ELEMENTSOF(rtnl_tca_option_data_ets_quanta_types),
826 .types = rtnl_tca_option_data_ets_quanta_types,
827};
828
829static const NLType rtnl_tca_option_data_ets_prio_types[] = {
830 [TCA_ETS_PRIOMAP_BAND] = { .type = NETLINK_TYPE_U8, },
831};
832
833static const NLTypeSystem rtnl_tca_option_data_ets_prio_type_system = {
834 .count = ELEMENTSOF(rtnl_tca_option_data_ets_prio_types),
835 .types = rtnl_tca_option_data_ets_prio_types,
836};
837
838static const NLType rtnl_tca_option_data_ets_types[] = {
839 [TCA_ETS_NBANDS] = { .type = NETLINK_TYPE_U8 },
840 [TCA_ETS_NSTRICT] = { .type = NETLINK_TYPE_U8 },
841 [TCA_ETS_QUANTA] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_option_data_ets_quanta_type_system },
842 [TCA_ETS_PRIOMAP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_option_data_ets_prio_type_system },
843 [TCA_ETS_QUANTA_BAND] = { .type = NETLINK_TYPE_U32 },
844};
845
eb34f4b3
YW
846static const NLType rtnl_tca_option_data_fq_types[] = {
847 [TCA_FQ_PLIMIT] = { .type = NETLINK_TYPE_U32 },
848 [TCA_FQ_FLOW_PLIMIT] = { .type = NETLINK_TYPE_U32 },
849 [TCA_FQ_QUANTUM] = { .type = NETLINK_TYPE_U32 },
850 [TCA_FQ_INITIAL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
851 [TCA_FQ_RATE_ENABLE] = { .type = NETLINK_TYPE_U32 },
852 [TCA_FQ_FLOW_DEFAULT_RATE] = { .type = NETLINK_TYPE_U32 },
853 [TCA_FQ_FLOW_MAX_RATE] = { .type = NETLINK_TYPE_U32 },
854 [TCA_FQ_BUCKETS_LOG] = { .type = NETLINK_TYPE_U32 },
855 [TCA_FQ_FLOW_REFILL_DELAY] = { .type = NETLINK_TYPE_U32 },
856 [TCA_FQ_LOW_RATE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
857 [TCA_FQ_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
e83562e5 858 [TCA_FQ_ORPHAN_MASK] = { .type = NETLINK_TYPE_U32 },
42b5f7dd
YW
859};
860
861static const NLType rtnl_tca_option_data_fq_codel_types[] = {
862 [TCA_FQ_CODEL_TARGET] = { .type = NETLINK_TYPE_U32 },
863 [TCA_FQ_CODEL_LIMIT] = { .type = NETLINK_TYPE_U32 },
864 [TCA_FQ_CODEL_INTERVAL] = { .type = NETLINK_TYPE_U32 },
865 [TCA_FQ_CODEL_ECN] = { .type = NETLINK_TYPE_U32 },
866 [TCA_FQ_CODEL_FLOWS] = { .type = NETLINK_TYPE_U32 },
867 [TCA_FQ_CODEL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
868 [TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
869 [TCA_FQ_CODEL_DROP_BATCH_SIZE] = { .type = NETLINK_TYPE_U32 },
870 [TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NETLINK_TYPE_U32 },
871};
872
3428b32a
SS
873static const NLType rtnl_tca_option_data_fq_pie_types[] = {
874 [TCA_FQ_PIE_LIMIT] = { .type = NETLINK_TYPE_U32 },
875};
876
609e8340
SS
877static const NLType rtnl_tca_option_data_gred_types[] = {
878 [TCA_GRED_DPS] = { .size = sizeof(struct tc_gred_sopt) },
879};
880
7e16f84e
SS
881static const NLType rtnl_tca_option_data_hhf_types[] = {
882 [TCA_HHF_BACKLOG_LIMIT] = { .type = NETLINK_TYPE_U32 },
883};
884
b934ac3d 885static const NLType rtnl_tca_option_data_htb_types[] = {
19f86a63
YW
886 [TCA_HTB_PARMS] = { .size = sizeof(struct tc_htb_opt) },
887 [TCA_HTB_INIT] = { .size = sizeof(struct tc_htb_glob) },
888 [TCA_HTB_CTAB] = { .size = TC_RTAB_SIZE },
889 [TCA_HTB_RTAB] = { .size = TC_RTAB_SIZE },
890 [TCA_HTB_RATE64] = { .type = NETLINK_TYPE_U64 },
891 [TCA_HTB_CEIL64] = { .type = NETLINK_TYPE_U64 },
b934ac3d
YW
892};
893
55d22831
SS
894static const NLType rtnl_tca_option_data_pie_types[] = {
895 [TCA_PIE_LIMIT] = { .type = NETLINK_TYPE_U32 },
896};
897
c33f1e5a
SS
898static const NLType rtnl_tca_option_data_qfq_types[] = {
899 [TCA_QFQ_WEIGHT] = { .type = NETLINK_TYPE_U32 },
900 [TCA_QFQ_LMAX] = { .type = NETLINK_TYPE_U32 },
901};
902
982998b0
SS
903static const NLType rtnl_tca_option_data_sfb_types[] = {
904 [TCA_SFB_PARMS] = { .size = sizeof(struct tc_sfb_qopt) },
905};
906
eb34f4b3
YW
907static const NLType rtnl_tca_option_data_tbf_types[] = {
908 [TCA_TBF_PARMS] = { .size = sizeof(struct tc_tbf_qopt) },
909 [TCA_TBF_RTAB] = { .size = TC_RTAB_SIZE },
910 [TCA_TBF_PTAB] = { .size = TC_RTAB_SIZE },
911 [TCA_TBF_RATE64] = { .type = NETLINK_TYPE_U64 },
912 [TCA_TBF_PRATE64] = { .type = NETLINK_TYPE_U64 },
913 [TCA_TBF_BURST] = { .type = NETLINK_TYPE_U32 },
914 [TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 },
915};
916
42b5f7dd 917static const char* const nl_union_tca_option_data_table[] = {
ad8352f4 918 [NL_UNION_TCA_OPTION_DATA_CAKE] = "cake",
a9a5d632 919 [NL_UNION_TCA_OPTION_DATA_CODEL] = "codel",
5c21b46e 920 [NL_UNION_TCA_OPTION_DATA_DRR] = "drr",
4dec9218 921 [NL_UNION_TCA_OPTION_DATA_ETS] = "ets",
eb34f4b3 922 [NL_UNION_TCA_OPTION_DATA_FQ] = "fq",
42b5f7dd 923 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel",
3428b32a 924 [NL_UNION_TCA_OPTION_DATA_FQ_PIE] = "fq_pie",
609e8340 925 [NL_UNION_TCA_OPTION_DATA_GRED] = "gred",
7e16f84e 926 [NL_UNION_TCA_OPTION_DATA_HHF] = "hhf",
b934ac3d 927 [NL_UNION_TCA_OPTION_DATA_HTB] = "htb",
55d22831 928 [NL_UNION_TCA_OPTION_DATA_PIE] = "pie",
c33f1e5a 929 [NL_UNION_TCA_OPTION_DATA_QFQ] = "qfq",
982998b0 930 [NL_UNION_TCA_OPTION_DATA_SFB] = "sfb",
eb34f4b3 931 [NL_UNION_TCA_OPTION_DATA_TBF] = "tbf",
42b5f7dd
YW
932};
933
934DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData);
935
936static const NLTypeSystem rtnl_tca_option_data_type_systems[] = {
ad8352f4
SS
937 [NL_UNION_TCA_OPTION_DATA_CAKE] = { .count = ELEMENTSOF(rtnl_tca_option_data_cake_types),
938 .types = rtnl_tca_option_data_cake_types },
a9a5d632
SS
939 [NL_UNION_TCA_OPTION_DATA_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_codel_types),
940 .types = rtnl_tca_option_data_codel_types },
5c21b46e
SS
941 [NL_UNION_TCA_OPTION_DATA_DRR] = { .count = ELEMENTSOF(rtnl_tca_option_data_drr_types),
942 .types = rtnl_tca_option_data_drr_types },
4dec9218
YW
943 [NL_UNION_TCA_OPTION_DATA_ETS] = { .count = ELEMENTSOF(rtnl_tca_option_data_ets_types),
944 .types = rtnl_tca_option_data_ets_types },
eb34f4b3
YW
945 [NL_UNION_TCA_OPTION_DATA_FQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_types),
946 .types = rtnl_tca_option_data_fq_types },
42b5f7dd
YW
947 [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types),
948 .types = rtnl_tca_option_data_fq_codel_types },
3428b32a
SS
949 [NL_UNION_TCA_OPTION_DATA_FQ_PIE] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_pie_types),
950 .types = rtnl_tca_option_data_fq_pie_types },
609e8340
SS
951 [NL_UNION_TCA_OPTION_DATA_GRED] = { .count = ELEMENTSOF(rtnl_tca_option_data_gred_types),
952 .types = rtnl_tca_option_data_gred_types },
7e16f84e
SS
953 [NL_UNION_TCA_OPTION_DATA_HHF] = { .count = ELEMENTSOF(rtnl_tca_option_data_hhf_types),
954 .types = rtnl_tca_option_data_hhf_types },
b934ac3d
YW
955 [NL_UNION_TCA_OPTION_DATA_HTB] = { .count = ELEMENTSOF(rtnl_tca_option_data_htb_types),
956 .types = rtnl_tca_option_data_htb_types },
55d22831
SS
957 [NL_UNION_TCA_OPTION_DATA_PIE] = { .count = ELEMENTSOF(rtnl_tca_option_data_pie_types),
958 .types = rtnl_tca_option_data_pie_types },
c33f1e5a
SS
959 [NL_UNION_TCA_OPTION_DATA_QFQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_qfq_types),
960 .types = rtnl_tca_option_data_qfq_types },
982998b0
SS
961 [NL_UNION_TCA_OPTION_DATA_SFB] = { .count = ELEMENTSOF(rtnl_tca_option_data_sfb_types),
962 .types = rtnl_tca_option_data_sfb_types },
eb34f4b3
YW
963 [NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
964 .types = rtnl_tca_option_data_tbf_types },
42b5f7dd
YW
965};
966
967static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = {
968 .num = _NL_UNION_TCA_OPTION_DATA_MAX,
969 .lookup = nl_union_tca_option_data_from_string,
970 .type_systems = rtnl_tca_option_data_type_systems,
971 .match_type = NL_MATCH_SIBLING,
972 .match = TCA_KIND,
973};
974
0ebb76de 975static const NLType rtnl_tca_types[] = {
0f5bd7fe 976 [TCA_KIND] = { .type = NETLINK_TYPE_STRING },
42b5f7dd 977 [TCA_OPTIONS] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_tca_option_data_type_system_union },
0f5bd7fe
SS
978 [TCA_INGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
979 [TCA_EGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
980};
981
0ebb76de
YW
982static const NLTypeSystem rtnl_tca_type_system = {
983 .count = ELEMENTSOF(rtnl_tca_types),
984 .types = rtnl_tca_types,
0f5bd7fe
SS
985};
986
1903c9bb
DM
987static const NLType mdb_types[] = {
988 [MDBA_SET_ENTRY] = { .size = sizeof(struct br_port_msg) },
989};
990
991static const NLTypeSystem rtnl_mdb_type_system = {
992 .count = ELEMENTSOF(mdb_types),
993 .types = mdb_types,
994};
995
e4a1e68d
YW
996static const NLType error_types[] = {
997 [NLMSGERR_ATTR_MSG] = { .type = NETLINK_TYPE_STRING },
998 [NLMSGERR_ATTR_OFFS] = { .type = NETLINK_TYPE_U32 },
999};
1000
1001static const NLTypeSystem error_type_system = {
1002 .count = ELEMENTSOF(error_types),
1003 .types = error_types,
1004};
1005
8ae4b6d1 1006static const NLType rtnl_types[] = {
30746d60 1007 [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 },
e4a1e68d 1008 [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
30746d60
SS
1009 [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
1010 [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
1011 [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
1012 [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
ffeb16f5
YW
1013 [RTM_NEWLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
1014 [RTM_DELLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
1015 [RTM_GETLINKPROP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
30746d60
SS
1016 [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1017 [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1018 [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
1019 [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1020 [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1021 [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
1022 [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1023 [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1024 [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
1025 [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
1026 [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
1027 [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
bce67bbe
SS
1028 [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
1029 [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
1030 [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
c16c7808
SS
1031 [RTM_NEWNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
1032 [RTM_DELNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
1033 [RTM_GETNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
0ebb76de
YW
1034 [RTM_NEWQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1035 [RTM_DELQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1036 [RTM_GETQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1037 [RTM_NEWTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1038 [RTM_DELTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1039 [RTM_GETTCLASS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_tca_type_system, .size = sizeof(struct tcmsg) },
1903c9bb
DM
1040 [RTM_NEWMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
1041 [RTM_DELMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
1042 [RTM_GETMDB] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_mdb_type_system, .size = sizeof(struct br_port_msg) },
d8e538ec
TG
1043};
1044
05d0c2e3 1045const NLTypeSystem rtnl_type_system_root = {
c1df8dee 1046 .count = ELEMENTSOF(rtnl_types),
d8e538ec
TG
1047 .types = rtnl_types,
1048};
1049
e5719363
JT
1050static const NLType genl_wireguard_allowedip_types[] = {
1051 [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 },
1052 [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1053 [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 },
1054};
1055
1056static const NLTypeSystem genl_wireguard_allowedip_type_system = {
1057 .count = ELEMENTSOF(genl_wireguard_allowedip_types),
1058 .types = genl_wireguard_allowedip_types,
1059};
1060
1061static const NLType genl_wireguard_peer_types[] = {
1062 [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN },
1063 [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
1064 [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN },
7d0b26a0 1065 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 },
abd48ec8 1066 [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR },
e5719363
JT
1067 [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system },
1068};
1069
1070static const NLTypeSystem genl_wireguard_peer_type_system = {
1071 .count = ELEMENTSOF(genl_wireguard_peer_types),
1072 .types = genl_wireguard_peer_types,
1073};
1074
1075static const NLType genl_wireguard_set_device_types[] = {
1076 [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 },
33c2ea80 1077 [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 },
e5719363
JT
1078 [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
1079 [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN },
1080 [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 },
1081 [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 },
1082 [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system },
1083};
1084
1085static const NLTypeSystem genl_wireguard_set_device_type_system = {
1086 .count = ELEMENTSOF(genl_wireguard_set_device_types),
1087 .types = genl_wireguard_set_device_types,
1088};
1089
1090static const NLType genl_wireguard_cmds[] = {
1091 [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system },
1092};
1093
1094static const NLTypeSystem genl_wireguard_type_system = {
1095 .count = ELEMENTSOF(genl_wireguard_cmds),
1096 .types = genl_wireguard_cmds,
1097};
05d0c2e3 1098
8fab2747
YW
1099static const NLType genl_mcast_group_types[] = {
1100 [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NETLINK_TYPE_STRING },
1101 [CTRL_ATTR_MCAST_GRP_ID] = { .type = NETLINK_TYPE_U32 },
1102};
1103
1104static const NLTypeSystem genl_mcast_group_type_system = {
1105 .count = ELEMENTSOF(genl_mcast_group_types),
1106 .types = genl_mcast_group_types,
1107};
1108
05d0c2e3 1109static const NLType genl_get_family_types[] = {
8fab2747
YW
1110 [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING },
1111 [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 },
1112 [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_mcast_group_type_system },
05d0c2e3
JT
1113};
1114
1115static const NLTypeSystem genl_get_family_type_system = {
1116 .count = ELEMENTSOF(genl_get_family_types),
1117 .types = genl_get_family_types,
1118};
1119
1120static const NLType genl_ctrl_id_ctrl_cmds[] = {
1121 [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system },
1122};
1123
1124static const NLTypeSystem genl_ctrl_id_ctrl_type_system = {
1125 .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds),
1126 .types = genl_ctrl_id_ctrl_cmds,
1127};
1128
53cb501a
SS
1129static const NLType genl_fou_types[] = {
1130 [FOU_ATTR_PORT] = { .type = NETLINK_TYPE_U16 },
1131 [FOU_ATTR_AF] = { .type = NETLINK_TYPE_U8 },
1132 [FOU_ATTR_IPPROTO] = { .type = NETLINK_TYPE_U8 },
1133 [FOU_ATTR_TYPE] = { .type = NETLINK_TYPE_U8 },
1134 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
397a74dd
SS
1135 [FOU_ATTR_LOCAL_V4] = { .type = NETLINK_TYPE_IN_ADDR },
1136 [FOU_ATTR_PEER_V4] = { .type = NETLINK_TYPE_IN_ADDR },
1137 [FOU_ATTR_LOCAL_V6] = { .type = NETLINK_TYPE_IN_ADDR },
1138 [FOU_ATTR_PEER_V6] = { .type = NETLINK_TYPE_IN_ADDR},
1139 [FOU_ATTR_PEER_PORT] = { .type = NETLINK_TYPE_U16},
1140 [FOU_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32},
53cb501a
SS
1141};
1142
1143static const NLTypeSystem genl_fou_type_system = {
1144 .count = ELEMENTSOF(genl_fou_types),
1145 .types = genl_fou_types,
1146};
1147
1148static const NLType genl_fou_cmds[] = {
1149 [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1150 [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1151 [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
1152};
1153
1154static const NLTypeSystem genl_fou_cmds_type_system = {
1155 .count = ELEMENTSOF(genl_fou_cmds),
1156 .types = genl_fou_cmds,
1157};
1158
3a56e697
SS
1159static const NLType genl_l2tp_types[] = {
1160 [L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 },
1161 [L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
1162 [L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 },
1163 [L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 },
1164 [L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 },
1165 [L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 },
1166 [L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 },
1167 [L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING },
1168 [L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1169 [L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 },
1170 [L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1171 [L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
1172 [L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
1173 [L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
1174 [L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 },
1175 [L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 },
1176 [L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 },
1177 [L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 },
1178 [L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 },
1179 [L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1180 [L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1181 [L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 },
1182 [L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 },
1183 [L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1184 [L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
1185 [L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG },
1186 [L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG },
1187};
1188
1189static const NLTypeSystem genl_l2tp_type_system = {
1190 .count = ELEMENTSOF(genl_l2tp_types),
1191 .types = genl_l2tp_types,
1192};
1193
1194static const NLType genl_l2tp[] = {
1195 [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1196 [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1197 [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1198 [L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1199 [L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1200 [L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1201 [L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1202 [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
1203};
1204
1205static const NLTypeSystem genl_l2tp_tunnel_session_type_system = {
1206 .count = ELEMENTSOF(genl_l2tp),
1207 .types = genl_l2tp,
1208};
1209
81962db7
SS
1210static const NLType genl_rxsc_types[] = {
1211 [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 },
1212};
1213
1214static const NLTypeSystem genl_rxsc_config_type_system = {
1215 .count = ELEMENTSOF(genl_rxsc_types),
1216 .types = genl_rxsc_types,
1217};
1218
1219static const NLType genl_macsec_rxsc_types[] = {
1220 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1221 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1222};
1223
1224static const NLTypeSystem genl_macsec_rxsc_type_system = {
1225 .count = ELEMENTSOF(genl_macsec_rxsc_types),
1226 .types = genl_macsec_rxsc_types,
1227};
1228
1229static const NLType genl_macsec_sa_config_types[] = {
1230 [MACSEC_SA_ATTR_AN] = { .type = NETLINK_TYPE_U8 },
1231 [MACSEC_SA_ATTR_ACTIVE] = { .type = NETLINK_TYPE_U8 },
1232 [MACSEC_SA_ATTR_PN] = { .type = NETLINK_TYPE_U32 },
1233 [MACSEC_SA_ATTR_KEYID] = { .size = MACSEC_KEYID_LEN },
1234 [MACSEC_SA_ATTR_KEY] = { .size = MACSEC_MAX_KEY_LEN },
1235};
1236
1237static const NLTypeSystem genl_macsec_sa_config_type_system = {
1238 .count = ELEMENTSOF(genl_macsec_sa_config_types),
1239 .types = genl_macsec_sa_config_types,
1240};
1241
1242static const NLType genl_macsec_rxsa_types[] = {
1243 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1244 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1245};
1246
1247static const NLTypeSystem genl_macsec_rxsa_type_system = {
1248 .count = ELEMENTSOF(genl_macsec_rxsa_types),
1249 .types = genl_macsec_rxsa_types,
1250};
1251
1252static const NLType genl_macsec_sa_types[] = {
1253 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1254 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
1255 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
1256};
1257
1258static const NLTypeSystem genl_macsec_sa_type_system = {
1259 .count = ELEMENTSOF(genl_macsec_sa_types),
1260 .types = genl_macsec_sa_types,
1261};
1262
1263static const NLType genl_macsec[] = {
1264 [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system },
1265 [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsa_type_system},
1266 [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system },
1267};
1268
1269static const NLTypeSystem genl_macsec_device_type_system = {
1270 .count = ELEMENTSOF(genl_macsec),
1271 .types = genl_macsec,
1272};
1273
a1d736e2
YW
1274static const NLType genl_nl80211_types[] = {
1275 [NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1276 [NL80211_ATTR_MAC] = { .type = NETLINK_TYPE_ETHER_ADDR },
1277 [NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_STRING },
78404d22 1278 [NL80211_ATTR_IFTYPE] = { .type = NETLINK_TYPE_U32 },
a1d736e2
YW
1279};
1280
1281static const NLTypeSystem genl_nl80211_type_system = {
1282 .count = ELEMENTSOF(genl_nl80211_types),
1283 .types = genl_nl80211_types,
1284};
1285
1286static const NLType genl_nl80211_cmds[] = {
1287 [NL80211_CMD_GET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1288 [NL80211_CMD_SET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1289 [NL80211_CMD_NEW_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1290 [NL80211_CMD_DEL_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1291 [NL80211_CMD_GET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1292 [NL80211_CMD_SET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1293 [NL80211_CMD_NEW_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1294 [NL80211_CMD_DEL_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1295 [NL80211_CMD_GET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1296 [NL80211_CMD_SET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1297 [NL80211_CMD_NEW_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1298 [NL80211_CMD_DEL_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1299};
1300
1301static const NLTypeSystem genl_nl80211_cmds_type_system = {
1302 .count = ELEMENTSOF(genl_nl80211_cmds),
1303 .types = genl_nl80211_cmds,
1304};
1305
05d0c2e3 1306static const NLType genl_families[] = {
53cb501a 1307 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system },
e5719363 1308 [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system },
2be081ff 1309 [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system },
3a56e697 1310 [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system },
81962db7 1311 [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_device_type_system },
a1d736e2 1312 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmds_type_system },
05d0c2e3
JT
1313};
1314
4e8f0ef9 1315/* Mainly used when sending message */
05d0c2e3
JT
1316const NLTypeSystem genl_family_type_system_root = {
1317 .count = ELEMENTSOF(genl_families),
1318 .types = genl_families,
1319};
1320
1321static const NLType genl_types[] = {
e4a1e68d 1322 [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) },
2be081ff 1323 [SD_GENL_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system },
4e8f0ef9 1324 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) },
a1d736e2 1325 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system, .size = sizeof(struct genlmsghdr) },
05d0c2e3
JT
1326};
1327
4e8f0ef9 1328/* Mainly used when message received */
05d0c2e3
JT
1329const NLTypeSystem genl_type_system_root = {
1330 .count = ELEMENTSOF(genl_types),
1331 .types = genl_types,
1332};
1333
817d1cd8
DH
1334uint16_t type_get_type(const NLType *type) {
1335 assert(type);
1336 return type->type;
1337}
1338
1339size_t type_get_size(const NLType *type) {
1340 assert(type);
1341 return type->size;
1342}
1343
c658008f
DH
1344void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) {
1345 assert(nl_type);
1346 assert(ret);
1347 assert(nl_type->type == NETLINK_TYPE_NESTED);
1348 assert(nl_type->type_system);
1349
1350 *ret = nl_type->type_system;
1351}
1352
1353void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) {
1354 assert(nl_type);
1355 assert(ret);
1356 assert(nl_type->type == NETLINK_TYPE_UNION);
1357 assert(nl_type->type_system_union);
1358
1359 *ret = nl_type->type_system_union;
1360}
1361
c1df8dee 1362uint16_t type_system_get_count(const NLTypeSystem *type_system) {
435bbb02 1363 assert(type_system);
c1df8dee 1364 return type_system->count;
435bbb02
DH
1365}
1366
05d0c2e3
JT
1367const NLTypeSystem *type_system_get_root(int protocol) {
1368 switch (protocol) {
1369 case NETLINK_GENERIC:
1370 return &genl_type_system_root;
1371 default: /* NETLINK_ROUTE: */
1372 return &rtnl_type_system_root;
1373 }
1374}
1375
4e8f0ef9
YW
1376int type_system_root_get_type(sd_netlink *nl, const NLType **ret, uint16_t type) {
1377 sd_genl_family family;
1378 const NLType *nl_type;
1379 int r;
1380
1381 if (!nl || nl->protocol != NETLINK_GENERIC)
1382 return type_system_get_type(&rtnl_type_system_root, ret, type);
1383
1384 r = nlmsg_type_to_genl_family(nl, type, &family);
1385 if (r < 0)
1386 return r;
1387
1388 if (family >= genl_type_system_root.count)
1389 return -EOPNOTSUPP;
1390
1391 nl_type = &genl_type_system_root.types[family];
1392
1393 if (nl_type->type == NETLINK_TYPE_UNSPEC)
1394 return -EOPNOTSUPP;
1395
1396 *ret = nl_type;
1397
1398 return 0;
1399}
1400
d8e538ec
TG
1401int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
1402 const NLType *nl_type;
1403
1404 assert(ret);
846a6b3d 1405 assert(type_system);
d8e538ec
TG
1406 assert(type_system->types);
1407
c1df8dee 1408 if (type >= type_system->count)
15411c0c 1409 return -EOPNOTSUPP;
d8e538ec
TG
1410
1411 nl_type = &type_system->types[type];
1412
cafbc790 1413 if (nl_type->type == NETLINK_TYPE_UNSPEC)
15411c0c 1414 return -EOPNOTSUPP;
d8e538ec
TG
1415
1416 *ret = nl_type;
1417
1418 return 0;
1419}
1420
1421int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
1422 const NLType *nl_type;
1423 int r;
1424
1425 assert(ret);
1426
1427 r = type_system_get_type(type_system, &nl_type, type);
1428 if (r < 0)
1429 return r;
1430
c658008f 1431 type_get_type_system(nl_type, ret);
d8e538ec
TG
1432 return 0;
1433}
1434
1435int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
1436 const NLType *nl_type;
1437 int r;
1438
1439 assert(ret);
1440
1441 r = type_system_get_type(type_system, &nl_type, type);
1442 if (r < 0)
1443 return r;
1444
c658008f 1445 type_get_type_system_union(nl_type, ret);
d8e538ec
TG
1446 return 0;
1447}
1448
1449int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
1450 int type;
1451
1452 assert(type_system_union);
f8a6ca1b 1453 assert(type_system_union->match_type == NL_MATCH_SIBLING);
d8e538ec
TG
1454 assert(type_system_union->lookup);
1455 assert(type_system_union->type_systems);
1456 assert(ret);
1457 assert(key);
1458
1459 type = type_system_union->lookup(key);
1460 if (type < 0)
15411c0c 1461 return -EOPNOTSUPP;
d8e538ec
TG
1462
1463 assert(type < type_system_union->num);
1464
1465 *ret = &type_system_union->type_systems[type];
1466
1467 return 0;
1468}
4af7b60d
TG
1469
1470int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
1471 const NLTypeSystem *type_system;
1472
1473 assert(type_system_union);
1474 assert(type_system_union->type_systems);
f8a6ca1b 1475 assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
4af7b60d 1476 assert(ret);
4af7b60d
TG
1477
1478 if (protocol >= type_system_union->num)
15411c0c 1479 return -EOPNOTSUPP;
4af7b60d
TG
1480
1481 type_system = &type_system_union->type_systems[protocol];
e7de105c 1482 if (!type_system->types)
15411c0c 1483 return -EOPNOTSUPP;
4af7b60d
TG
1484
1485 *ret = type_system;
1486
1487 return 0;
1488}