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