]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-netlink/netlink-types.c
Merge pull request #14151 from mk-fg/fix-timer-dump-syntax-bug
[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) },
06828bb6
HP
319};
320
81962db7
SS
321static const NLType rtnl_link_info_data_macsec_types[] = {
322 [IFLA_MACSEC_SCI] = { .type = NETLINK_TYPE_U64 },
323 [IFLA_MACSEC_PORT] = { .type = NETLINK_TYPE_U16 },
324 [IFLA_MACSEC_ICV_LEN] = { .type = NETLINK_TYPE_U8 },
325 [IFLA_MACSEC_CIPHER_SUITE] = { .type = NETLINK_TYPE_U64 },
326 [IFLA_MACSEC_WINDOW] = { .type = NETLINK_TYPE_U32 },
327 [IFLA_MACSEC_ENCODING_SA] = { .type = NETLINK_TYPE_U8 },
328 [IFLA_MACSEC_ENCRYPT] = { .type = NETLINK_TYPE_U8 },
329 [IFLA_MACSEC_PROTECT] = { .type = NETLINK_TYPE_U8 },
330 [IFLA_MACSEC_INC_SCI] = { .type = NETLINK_TYPE_U8 },
331 [IFLA_MACSEC_ES] = { .type = NETLINK_TYPE_U8 },
332 [IFLA_MACSEC_SCB] = { .type = NETLINK_TYPE_U8 },
333 [IFLA_MACSEC_REPLAY_PROTECT] = { .type = NETLINK_TYPE_U8 },
334 [IFLA_MACSEC_VALIDATION] = { .type = NETLINK_TYPE_U8 },
335};
336
98d20a17 337static const NLType rtnl_link_info_data_xfrm_types[] = {
338 [IFLA_XFRM_LINK] = { .type = NETLINK_TYPE_U32 },
339 [IFLA_XFRM_IF_ID] = { .type = NETLINK_TYPE_U32 }
340};
341
0a827d10 342/* these strings must match the .kind entries in the kernel */
8ae4b6d1 343static const char* const nl_union_link_info_data_table[] = {
d8e538ec
TG
344 [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
345 [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
346 [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
347 [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
9e358851 348 [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
d8e538ec 349 [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
d1312575 350 [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap",
c4a5ddc9 351 [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
69c317a0 352 [NL_UNION_LINK_INFO_DATA_IPVTAP] = "ipvtap",
6ef81477 353 [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
0a827d10 354 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
8bb088c5 355 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
2266864b 356 [NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan",
1af2536a 357 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
b16492f8
SS
358 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
359 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
0a827d10 360 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
a613382b 361 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
9011ce77 362 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
855ee1a1 363 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
20897a0d 364 [NL_UNION_LINK_INFO_DATA_VRF] = "vrf",
92c918b0 365 [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan",
ca5e8071 366 [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve",
d6df583c 367 [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan",
e5719363 368 [NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard",
56e7fb50 369 [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim",
06828bb6 370 [NL_UNION_LINK_INFO_DATA_CAN] = "can",
81962db7 371 [NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec",
d61e4c5b 372 [NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon",
98d20a17 373 [NL_UNION_LINK_INFO_DATA_XFRM] = "xfrm",
d8e538ec
TG
374};
375
376DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
377
8ae4b6d1 378static const NLTypeSystem rtnl_link_info_data_type_systems[] = {
92c918b0
SS
379 [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
380 .types = rtnl_link_info_data_bond_types },
381 [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
382 .types = rtnl_link_info_data_bridge_types },
383 [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
384 .types = rtnl_link_info_data_vlan_types },
385 [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
386 .types = rtnl_link_info_data_veth_types },
387 [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
388 .types = rtnl_link_info_data_macvlan_types },
389 [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
390 .types = rtnl_link_info_data_macvlan_types },
391 [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
392 .types = rtnl_link_info_data_ipvlan_types },
69c317a0
SS
393 [NL_UNION_LINK_INFO_DATA_IPVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
394 .types = rtnl_link_info_data_ipvlan_types },
92c918b0
SS
395 [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
396 .types = rtnl_link_info_data_vxlan_types },
397 [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
398 .types = rtnl_link_info_data_iptun_types },
399 [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
400 .types = rtnl_link_info_data_ipgre_types },
2266864b
SS
401 [NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
402 .types = rtnl_link_info_data_ipgre_types },
c1df8dee 403 [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
92c918b0
SS
404 .types = rtnl_link_info_data_ipgre_types },
405 [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
406 .types = rtnl_link_info_data_ipgre_types },
407 [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
408 .types = rtnl_link_info_data_ipgre_types },
409 [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
410 .types = rtnl_link_info_data_iptun_types },
411 [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
412 .types = rtnl_link_info_data_ipvti_types },
413 [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
414 .types = rtnl_link_info_data_ipvti_types },
415 [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
416 .types = rtnl_link_info_data_ip6tnl_types },
417 [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
418 .types = rtnl_link_info_data_vrf_types },
ca5e8071
SS
419 [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
420 .types = rtnl_link_info_data_geneve_types },
d6df583c
SS
421 [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
422 .types = rtnl_link_info_data_vxcan_types },
06828bb6
HP
423 [NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types),
424 .types = rtnl_link_info_data_can_types },
81962db7
SS
425 [NL_UNION_LINK_INFO_DATA_MACSEC] = { .count = ELEMENTSOF(rtnl_link_info_data_macsec_types),
426 .types = rtnl_link_info_data_macsec_types },
98d20a17 427 [NL_UNION_LINK_INFO_DATA_XFRM] = { .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
428 .types = rtnl_link_info_data_xfrm_types },
d8e538ec
TG
429};
430
431static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
432 .num = _NL_UNION_LINK_INFO_DATA_MAX,
433 .lookup = nl_union_link_info_data_from_string,
434 .type_systems = rtnl_link_info_data_type_systems,
4af7b60d 435 .match_type = NL_MATCH_SIBLING,
d8e538ec
TG
436 .match = IFLA_INFO_KIND,
437};
438
8ae4b6d1 439static const NLType rtnl_link_info_types[] = {
cafbc790
DH
440 [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING },
441 [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union},
d8e538ec
TG
442/*
443 [IFLA_INFO_XSTATS],
cafbc790
DH
444 [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING },
445 [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED },
d8e538ec
TG
446*/
447};
448
449static const NLTypeSystem rtnl_link_info_type_system = {
c1df8dee 450 .count = ELEMENTSOF(rtnl_link_info_types),
d8e538ec
TG
451 .types = rtnl_link_info_types,
452};
453
8ae4b6d1 454static const struct NLType rtnl_prot_info_bridge_port_types[] = {
d3aa8b49
SS
455 [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 },
456 [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 },
457 [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 },
458 [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 },
459 [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 },
460 [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 },
461 [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 },
462 [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 },
463 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
464 [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 },
465 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 },
466 [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NETLINK_TYPE_U8 },
467 [IFLA_BRPORT_ROOT_ID] = { .type = NETLINK_TYPE_U8 },
468 [IFLA_BRPORT_BRIDGE_ID] = { .type = NETLINK_TYPE_U8 },
469 [IFLA_BRPORT_DESIGNATED_PORT] = { .type = NETLINK_TYPE_U16 },
470 [IFLA_BRPORT_DESIGNATED_COST] = { .type = NETLINK_TYPE_U16 },
471 [IFLA_BRPORT_ID] = { .type = NETLINK_TYPE_U16 },
472 [IFLA_BRPORT_NO] = { .type = NETLINK_TYPE_U16 },
473 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = { .type = NETLINK_TYPE_U8 },
474 [IFLA_BRPORT_CONFIG_PENDING] = { .type = NETLINK_TYPE_U8 },
475 [IFLA_BRPORT_MESSAGE_AGE_TIMER] = { .type = NETLINK_TYPE_U64 },
476 [IFLA_BRPORT_FORWARD_DELAY_TIMER] = { .type = NETLINK_TYPE_U64 },
477 [IFLA_BRPORT_HOLD_TIMER] = { .type = NETLINK_TYPE_U64 },
478 [IFLA_BRPORT_FLUSH] = { .type = NETLINK_TYPE_U8 },
479 [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NETLINK_TYPE_U8 },
480 [IFLA_BRPORT_PAD] = { .type = NETLINK_TYPE_U8 },
481 [IFLA_BRPORT_MCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
482 [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NETLINK_TYPE_U8 },
483 [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NETLINK_TYPE_U8 },
484 [IFLA_BRPORT_BCAST_FLOOD] = { .type = NETLINK_TYPE_U8 },
485 [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 },
486 [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NETLINK_TYPE_U8 },
487 [IFLA_BRPORT_ISOLATED] = { .type = NETLINK_TYPE_U8 },
488 [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 },
d0159fdc
SS
489};
490
8ae4b6d1 491static const NLTypeSystem rtnl_prot_info_type_systems[] = {
c1df8dee 492 [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
4af7b60d
TG
493 .types = rtnl_prot_info_bridge_port_types },
494};
495
496static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
497 .num = AF_MAX,
498 .type_systems = rtnl_prot_info_type_systems,
499 .match_type = NL_MATCH_PROTOCOL,
d0159fdc
SS
500};
501
8ae4b6d1 502static const struct NLType rtnl_af_spec_inet6_types[] = {
cafbc790 503 [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 },
c149ae08
TG
504/*
505 IFLA_INET6_CONF,
506 IFLA_INET6_STATS,
507 IFLA_INET6_MCAST,
508 IFLA_INET6_CACHEINFO,
509 IFLA_INET6_ICMP6STATS,
510*/
cafbc790
DH
511 [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR },
512 [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 },
c149ae08
TG
513};
514
73cb1c14 515static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
c1df8dee 516 .count = ELEMENTSOF(rtnl_af_spec_inet6_types),
73cb1c14 517 .types = rtnl_af_spec_inet6_types,
c149ae08
TG
518};
519
8ae4b6d1 520static const NLType rtnl_af_spec_types[] = {
cafbc790 521 [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
73cb1c14
TG
522};
523
524static const NLTypeSystem rtnl_af_spec_type_system = {
c1df8dee 525 .count = ELEMENTSOF(rtnl_af_spec_types),
73cb1c14 526 .types = rtnl_af_spec_types,
c149ae08
TG
527};
528
8ae4b6d1 529static const NLType rtnl_link_types[] = {
6e74cade
ZJS
530 [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
531 [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
532 [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
cafbc790
DH
533 [IFLA_MTU] = { .type = NETLINK_TYPE_U32 },
534 [IFLA_LINK] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
535/*
536 [IFLA_QDISC],
c095e5b0
YW
537*/
538 [IFLA_STATS] = { .size = sizeof(struct rtnl_link_stats) },
539/*
d8e538ec
TG
540 [IFLA_COST],
541 [IFLA_PRIORITY],
542*/
cafbc790 543 [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
544/*
545 [IFLA_WIRELESS],
d8e538ec 546*/
cafbc790
DH
547 [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
548 [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
549/*
550 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
551*/
cafbc790
DH
552 [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 },
553 [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 },
554 [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 },
555 [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
556 [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
557 [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
d8e538ec
TG
558/*
559 [IFLA_NUM_VF],
cafbc790 560 [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
c095e5b0
YW
561*/
562 [IFLA_STATS64] = { .size = sizeof(struct rtnl_link_stats64) },
563/*
cafbc790
DH
564 [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
565 [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED },
c149ae08 566*/
cafbc790 567 [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system },
c149ae08 568/*
d8e538ec
TG
569 [IFLA_VF_PORTS],
570 [IFLA_PORT_SELF],
571 [IFLA_AF_SPEC],
572*/
cafbc790
DH
573 [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 },
574 [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 },
575 [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 },
576 [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 },
577 [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 },
578 [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 },
579 [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 },
d8e538ec 580/*
cafbc790 581 [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
d8e538ec 582*/
61de0c42
SS
583 [IFLA_MIN_MTU] = { .type = NETLINK_TYPE_U32 },
584 [IFLA_MAX_MTU] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
585};
586
587static const NLTypeSystem rtnl_link_type_system = {
c1df8dee 588 .count = ELEMENTSOF(rtnl_link_types),
d8e538ec
TG
589 .types = rtnl_link_types,
590};
591
de79f906
LP
592/* IFA_FLAGS was defined in kernel 3.14, but we still support older
593 * kernels where IFA_MAX is lower. */
8ae4b6d1 594static const NLType rtnl_address_types[] = {
cafbc790
DH
595 [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR },
596 [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR },
597 [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 },
598 [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
599 [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
d8e538ec
TG
600/*
601 [IFA_ANYCAST],
d8e538ec
TG
602 [IFA_MULTICAST],
603*/
cafbc790 604 [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 },
d8e538ec
TG
605};
606
607static const NLTypeSystem rtnl_address_type_system = {
c1df8dee 608 .count = ELEMENTSOF(rtnl_address_types),
d8e538ec
TG
609 .types = rtnl_address_types,
610};
611
d6fceaf1
SS
612/* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
613
614static const NLType rtnl_route_metrics_types[] = {
f4679bcb
SS
615 [RTAX_MTU] = { .type = NETLINK_TYPE_U32 },
616 [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 },
617 [RTAX_RTT] = { .type = NETLINK_TYPE_U32 },
618 [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 },
619 [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 },
620 [RTAX_CWND] = { .type = NETLINK_TYPE_U32 },
621 [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 },
622 [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 },
623 [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 },
624 [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 },
625 [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 },
626 [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 },
627 [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 },
628 [RTAX_QUICKACK] = { .type = NETLINK_TYPE_U32 },
629 [RTAX_CC_ALGO] = { .type = NETLINK_TYPE_U32 },
630 [RTAX_FASTOPEN_NO_COOKIE] = { .type = NETLINK_TYPE_U32 },
d6fceaf1
SS
631};
632
633static const NLTypeSystem rtnl_route_metrics_type_system = {
634 .count = ELEMENTSOF(rtnl_route_metrics_types),
635 .types = rtnl_route_metrics_types,
636};
637
8ae4b6d1 638static const NLType rtnl_route_types[] = {
cafbc790
DH
639 [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
640 [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
641 [RTA_IIF] = { .type = NETLINK_TYPE_U32 },
642 [RTA_OIF] = { .type = NETLINK_TYPE_U32 },
643 [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
644 [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
645 [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */
d6fceaf1 646 [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system},
cb7e98ab 647 [RTA_MULTIPATH] = { .size = sizeof(struct rtnexthop) },
cafbc790 648 [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */
cb7e98ab
SS
649 [RTA_CACHEINFO] = { .size = sizeof(struct rta_cacheinfo) },
650 [RTA_TABLE] = { .type = NETLINK_TYPE_U32 },
651 [RTA_MARK] = { .type = NETLINK_TYPE_U32 },
652 [RTA_MFC_STATS] = { .type = NETLINK_TYPE_U64 },
653 [RTA_VIA] = { .type = NETLINK_TYPE_U32 },
654 [RTA_NEWDST] = { .type = NETLINK_TYPE_U32 },
b69015ef 655 [RTA_PREF] = { .type = NETLINK_TYPE_U8 },
f02ba163 656 [RTA_EXPIRES] = { .type = NETLINK_TYPE_U32 },
cb7e98ab
SS
657 [RTA_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
658 [RTA_ENCAP] = { .type = NETLINK_TYPE_NESTED }, /* Multiple type systems i.e. LWTUNNEL_ENCAP_MPLS/LWTUNNEL_ENCAP_IP/LWTUNNEL_ENCAP_ILA etc... */
659 [RTA_UID] = { .type = NETLINK_TYPE_U32 },
660 [RTA_TTL_PROPAGATE] = { .type = NETLINK_TYPE_U8 },
661 [RTA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
662 [RTA_SPORT] = { .type = NETLINK_TYPE_U16 },
663 [RTA_DPORT] = { .type = NETLINK_TYPE_U16 },
d8e538ec
TG
664};
665
666static const NLTypeSystem rtnl_route_type_system = {
c1df8dee 667 .count = ELEMENTSOF(rtnl_route_types),
d8e538ec
TG
668 .types = rtnl_route_types,
669};
670
8ae4b6d1 671static const NLType rtnl_neigh_types[] = {
cafbc790 672 [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
1647f241 673 [NDA_LLADDR] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
cafbc790
DH
674 [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
675 [NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
676 [NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
677 [NDA_PORT] = { .type = NETLINK_TYPE_U16 },
678 [NDA_VNI] = { .type = NETLINK_TYPE_U32 },
679 [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 },
e559b384
TG
680};
681
682static const NLTypeSystem rtnl_neigh_type_system = {
c1df8dee 683 .count = ELEMENTSOF(rtnl_neigh_types),
e559b384
TG
684 .types = rtnl_neigh_types,
685};
686
30746d60
SS
687static const NLType rtnl_addrlabel_types[] = {
688 [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) },
689 [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 },
690};
691
692static const NLTypeSystem rtnl_addrlabel_type_system = {
693 .count = ELEMENTSOF(rtnl_addrlabel_types),
694 .types = rtnl_addrlabel_types,
695};
696
bce67bbe
SS
697static const NLType rtnl_routing_policy_rule_types[] = {
698 [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
699 [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR },
700 [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING },
8abd60c1 701 [FRA_GOTO] = { .type = NETLINK_TYPE_U32 },
bce67bbe
SS
702 [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 },
703 [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 },
704 [FRA_FLOW] = { .type = NETLINK_TYPE_U32 },
202aa159 705 [FRA_TUN_ID] = { .type = NETLINK_TYPE_U64 },
bce67bbe
SS
706 [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 },
707 [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 },
708 [FRA_TABLE] = { .type = NETLINK_TYPE_U32 },
709 [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 },
710 [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING },
711 [FRA_PAD] = { .type = NETLINK_TYPE_U32 },
a15ff62d 712 [FRA_L3MDEV] = { .type = NETLINK_TYPE_U8 },
bce67bbe 713 [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) },
926062f0
SS
714 [FRA_PROTOCOL] = { .type = NETLINK_TYPE_U8 },
715 [FRA_IP_PROTO] = { .type = NETLINK_TYPE_U8 },
716 [FRA_SPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
717 [FRA_DPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) },
bce67bbe
SS
718};
719
720static const NLTypeSystem rtnl_routing_policy_rule_type_system = {
721 .count = ELEMENTSOF(rtnl_routing_policy_rule_types),
722 .types = rtnl_routing_policy_rule_types,
723};
724
c16c7808
SS
725static const NLType rtnl_nexthop_types[] = {
726 [NHA_ID] = { .type = NETLINK_TYPE_U32 },
727 [NHA_OIF] = { .type = NETLINK_TYPE_U32 },
728 [NHA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR },
729};
730
731static const NLTypeSystem rtnl_nexthop_type_system = {
732 .count = ELEMENTSOF(rtnl_nexthop_types),
733 .types = rtnl_nexthop_types,
734};
735
0f5bd7fe
SS
736static const NLType rtnl_qdisc_types[] = {
737 [TCA_KIND] = { .type = NETLINK_TYPE_STRING },
738 [TCA_OPTIONS] = { .size = sizeof(struct tc_netem_qopt) },
739 [TCA_INGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
740 [TCA_EGRESS_BLOCK] = { .type = NETLINK_TYPE_U32 },
741};
742
743static const NLTypeSystem rtnl_qdisc_type_system = {
744 .count = ELEMENTSOF(rtnl_qdisc_types),
745 .types = rtnl_qdisc_types,
746};
747
8ae4b6d1 748static const NLType rtnl_types[] = {
30746d60
SS
749 [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 },
750 [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) },
751 [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
752 [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
753 [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
754 [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
755 [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
756 [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
757 [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
758 [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
759 [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
760 [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
761 [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
762 [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
763 [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
764 [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
765 [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
766 [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) },
bce67bbe
SS
767 [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
768 [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
769 [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) },
c16c7808
SS
770 [RTM_NEWNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
771 [RTM_DELNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
772 [RTM_GETNEXTHOP] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_nexthop_type_system, .size = sizeof(struct nhmsg) },
0f5bd7fe
SS
773 [RTM_NEWQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
774 [RTM_DELQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
775 [RTM_GETQDISC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_qdisc_type_system, .size = sizeof(struct tcmsg) },
d8e538ec
TG
776};
777
05d0c2e3 778const NLTypeSystem rtnl_type_system_root = {
c1df8dee 779 .count = ELEMENTSOF(rtnl_types),
d8e538ec
TG
780 .types = rtnl_types,
781};
782
e5719363
JT
783static const NLType genl_wireguard_allowedip_types[] = {
784 [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 },
785 [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR },
786 [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 },
787};
788
789static const NLTypeSystem genl_wireguard_allowedip_type_system = {
790 .count = ELEMENTSOF(genl_wireguard_allowedip_types),
791 .types = genl_wireguard_allowedip_types,
792};
793
794static const NLType genl_wireguard_peer_types[] = {
795 [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN },
796 [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
797 [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN },
7d0b26a0 798 [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 },
abd48ec8 799 [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR },
e5719363
JT
800 [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system },
801};
802
803static const NLTypeSystem genl_wireguard_peer_type_system = {
804 .count = ELEMENTSOF(genl_wireguard_peer_types),
805 .types = genl_wireguard_peer_types,
806};
807
808static const NLType genl_wireguard_set_device_types[] = {
809 [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 },
33c2ea80 810 [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 },
e5719363
JT
811 [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
812 [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN },
813 [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 },
814 [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 },
815 [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system },
816};
817
818static const NLTypeSystem genl_wireguard_set_device_type_system = {
819 .count = ELEMENTSOF(genl_wireguard_set_device_types),
820 .types = genl_wireguard_set_device_types,
821};
822
823static const NLType genl_wireguard_cmds[] = {
824 [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system },
825};
826
827static const NLTypeSystem genl_wireguard_type_system = {
828 .count = ELEMENTSOF(genl_wireguard_cmds),
829 .types = genl_wireguard_cmds,
830};
05d0c2e3 831
8fab2747
YW
832static const NLType genl_mcast_group_types[] = {
833 [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NETLINK_TYPE_STRING },
834 [CTRL_ATTR_MCAST_GRP_ID] = { .type = NETLINK_TYPE_U32 },
835};
836
837static const NLTypeSystem genl_mcast_group_type_system = {
838 .count = ELEMENTSOF(genl_mcast_group_types),
839 .types = genl_mcast_group_types,
840};
841
05d0c2e3 842static const NLType genl_get_family_types[] = {
8fab2747
YW
843 [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING },
844 [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 },
845 [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_mcast_group_type_system },
05d0c2e3
JT
846};
847
848static const NLTypeSystem genl_get_family_type_system = {
849 .count = ELEMENTSOF(genl_get_family_types),
850 .types = genl_get_family_types,
851};
852
853static const NLType genl_ctrl_id_ctrl_cmds[] = {
854 [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system },
855};
856
857static const NLTypeSystem genl_ctrl_id_ctrl_type_system = {
858 .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds),
859 .types = genl_ctrl_id_ctrl_cmds,
860};
861
53cb501a
SS
862static const NLType genl_fou_types[] = {
863 [FOU_ATTR_PORT] = { .type = NETLINK_TYPE_U16 },
864 [FOU_ATTR_AF] = { .type = NETLINK_TYPE_U8 },
865 [FOU_ATTR_IPPROTO] = { .type = NETLINK_TYPE_U8 },
866 [FOU_ATTR_TYPE] = { .type = NETLINK_TYPE_U8 },
867 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
397a74dd
SS
868 [FOU_ATTR_LOCAL_V4] = { .type = NETLINK_TYPE_IN_ADDR },
869 [FOU_ATTR_PEER_V4] = { .type = NETLINK_TYPE_IN_ADDR },
870 [FOU_ATTR_LOCAL_V6] = { .type = NETLINK_TYPE_IN_ADDR },
871 [FOU_ATTR_PEER_V6] = { .type = NETLINK_TYPE_IN_ADDR},
872 [FOU_ATTR_PEER_PORT] = { .type = NETLINK_TYPE_U16},
873 [FOU_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32},
53cb501a
SS
874};
875
876static const NLTypeSystem genl_fou_type_system = {
877 .count = ELEMENTSOF(genl_fou_types),
878 .types = genl_fou_types,
879};
880
881static const NLType genl_fou_cmds[] = {
882 [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
883 [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
884 [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system },
885};
886
887static const NLTypeSystem genl_fou_cmds_type_system = {
888 .count = ELEMENTSOF(genl_fou_cmds),
889 .types = genl_fou_cmds,
890};
891
3a56e697
SS
892static const NLType genl_l2tp_types[] = {
893 [L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 },
894 [L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
895 [L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 },
896 [L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 },
897 [L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 },
898 [L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 },
899 [L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 },
900 [L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING },
901 [L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 },
902 [L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 },
903 [L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
904 [L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
905 [L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
906 [L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
907 [L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 },
908 [L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 },
909 [L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 },
910 [L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 },
911 [L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 },
912 [L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
913 [L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
914 [L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 },
915 [L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 },
916 [L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
917 [L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
918 [L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG },
919 [L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG },
920};
921
922static const NLTypeSystem genl_l2tp_type_system = {
923 .count = ELEMENTSOF(genl_l2tp_types),
924 .types = genl_l2tp_types,
925};
926
927static const NLType genl_l2tp[] = {
928 [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
929 [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
930 [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
931 [L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
932 [L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
933 [L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
934 [L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
935 [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
936};
937
938static const NLTypeSystem genl_l2tp_tunnel_session_type_system = {
939 .count = ELEMENTSOF(genl_l2tp),
940 .types = genl_l2tp,
941};
942
81962db7
SS
943static const NLType genl_rxsc_types[] = {
944 [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 },
945};
946
947static const NLTypeSystem genl_rxsc_config_type_system = {
948 .count = ELEMENTSOF(genl_rxsc_types),
949 .types = genl_rxsc_types,
950};
951
952static const NLType genl_macsec_rxsc_types[] = {
953 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
954 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
955};
956
957static const NLTypeSystem genl_macsec_rxsc_type_system = {
958 .count = ELEMENTSOF(genl_macsec_rxsc_types),
959 .types = genl_macsec_rxsc_types,
960};
961
962static const NLType genl_macsec_sa_config_types[] = {
963 [MACSEC_SA_ATTR_AN] = { .type = NETLINK_TYPE_U8 },
964 [MACSEC_SA_ATTR_ACTIVE] = { .type = NETLINK_TYPE_U8 },
965 [MACSEC_SA_ATTR_PN] = { .type = NETLINK_TYPE_U32 },
966 [MACSEC_SA_ATTR_KEYID] = { .size = MACSEC_KEYID_LEN },
967 [MACSEC_SA_ATTR_KEY] = { .size = MACSEC_MAX_KEY_LEN },
968};
969
970static const NLTypeSystem genl_macsec_sa_config_type_system = {
971 .count = ELEMENTSOF(genl_macsec_sa_config_types),
972 .types = genl_macsec_sa_config_types,
973};
974
975static const NLType genl_macsec_rxsa_types[] = {
976 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
977 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
978};
979
980static const NLTypeSystem genl_macsec_rxsa_type_system = {
981 .count = ELEMENTSOF(genl_macsec_rxsa_types),
982 .types = genl_macsec_rxsa_types,
983};
984
985static const NLType genl_macsec_sa_types[] = {
986 [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
987 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system },
988 [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system },
989};
990
991static const NLTypeSystem genl_macsec_sa_type_system = {
992 .count = ELEMENTSOF(genl_macsec_sa_types),
993 .types = genl_macsec_sa_types,
994};
995
996static const NLType genl_macsec[] = {
997 [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system },
998 [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsa_type_system},
999 [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system },
1000};
1001
1002static const NLTypeSystem genl_macsec_device_type_system = {
1003 .count = ELEMENTSOF(genl_macsec),
1004 .types = genl_macsec,
1005};
1006
a1d736e2
YW
1007static const NLType genl_nl80211_types[] = {
1008 [NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
1009 [NL80211_ATTR_MAC] = { .type = NETLINK_TYPE_ETHER_ADDR },
1010 [NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_STRING },
78404d22 1011 [NL80211_ATTR_IFTYPE] = { .type = NETLINK_TYPE_U32 },
a1d736e2
YW
1012};
1013
1014static const NLTypeSystem genl_nl80211_type_system = {
1015 .count = ELEMENTSOF(genl_nl80211_types),
1016 .types = genl_nl80211_types,
1017};
1018
1019static const NLType genl_nl80211_cmds[] = {
1020 [NL80211_CMD_GET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1021 [NL80211_CMD_SET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1022 [NL80211_CMD_NEW_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1023 [NL80211_CMD_DEL_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1024 [NL80211_CMD_GET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1025 [NL80211_CMD_SET_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1026 [NL80211_CMD_NEW_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1027 [NL80211_CMD_DEL_INTERFACE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1028 [NL80211_CMD_GET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1029 [NL80211_CMD_SET_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1030 [NL80211_CMD_NEW_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1031 [NL80211_CMD_DEL_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system },
1032};
1033
1034static const NLTypeSystem genl_nl80211_cmds_type_system = {
1035 .count = ELEMENTSOF(genl_nl80211_cmds),
1036 .types = genl_nl80211_cmds,
1037};
1038
05d0c2e3 1039static const NLType genl_families[] = {
53cb501a 1040 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system },
e5719363 1041 [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system },
2be081ff 1042 [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system },
3a56e697 1043 [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system },
81962db7 1044 [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_device_type_system },
a1d736e2 1045 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmds_type_system },
05d0c2e3
JT
1046};
1047
4e8f0ef9 1048/* Mainly used when sending message */
05d0c2e3
JT
1049const NLTypeSystem genl_family_type_system_root = {
1050 .count = ELEMENTSOF(genl_families),
1051 .types = genl_families,
1052};
1053
1054static const NLType genl_types[] = {
4e8f0ef9 1055 [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) },
2be081ff 1056 [SD_GENL_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system },
4e8f0ef9 1057 [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) },
a1d736e2 1058 [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system, .size = sizeof(struct genlmsghdr) },
05d0c2e3
JT
1059};
1060
4e8f0ef9 1061/* Mainly used when message received */
05d0c2e3
JT
1062const NLTypeSystem genl_type_system_root = {
1063 .count = ELEMENTSOF(genl_types),
1064 .types = genl_types,
1065};
1066
817d1cd8
DH
1067uint16_t type_get_type(const NLType *type) {
1068 assert(type);
1069 return type->type;
1070}
1071
1072size_t type_get_size(const NLType *type) {
1073 assert(type);
1074 return type->size;
1075}
1076
c658008f
DH
1077void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) {
1078 assert(nl_type);
1079 assert(ret);
1080 assert(nl_type->type == NETLINK_TYPE_NESTED);
1081 assert(nl_type->type_system);
1082
1083 *ret = nl_type->type_system;
1084}
1085
1086void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) {
1087 assert(nl_type);
1088 assert(ret);
1089 assert(nl_type->type == NETLINK_TYPE_UNION);
1090 assert(nl_type->type_system_union);
1091
1092 *ret = nl_type->type_system_union;
1093}
1094
c1df8dee 1095uint16_t type_system_get_count(const NLTypeSystem *type_system) {
435bbb02 1096 assert(type_system);
c1df8dee 1097 return type_system->count;
435bbb02
DH
1098}
1099
05d0c2e3
JT
1100const NLTypeSystem *type_system_get_root(int protocol) {
1101 switch (protocol) {
1102 case NETLINK_GENERIC:
1103 return &genl_type_system_root;
1104 default: /* NETLINK_ROUTE: */
1105 return &rtnl_type_system_root;
1106 }
1107}
1108
4e8f0ef9
YW
1109int type_system_root_get_type(sd_netlink *nl, const NLType **ret, uint16_t type) {
1110 sd_genl_family family;
1111 const NLType *nl_type;
1112 int r;
1113
1114 if (!nl || nl->protocol != NETLINK_GENERIC)
1115 return type_system_get_type(&rtnl_type_system_root, ret, type);
1116
1117 r = nlmsg_type_to_genl_family(nl, type, &family);
1118 if (r < 0)
1119 return r;
1120
1121 if (family >= genl_type_system_root.count)
1122 return -EOPNOTSUPP;
1123
1124 nl_type = &genl_type_system_root.types[family];
1125
1126 if (nl_type->type == NETLINK_TYPE_UNSPEC)
1127 return -EOPNOTSUPP;
1128
1129 *ret = nl_type;
1130
1131 return 0;
1132}
1133
d8e538ec
TG
1134int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
1135 const NLType *nl_type;
1136
1137 assert(ret);
846a6b3d 1138 assert(type_system);
d8e538ec
TG
1139 assert(type_system->types);
1140
c1df8dee 1141 if (type >= type_system->count)
15411c0c 1142 return -EOPNOTSUPP;
d8e538ec
TG
1143
1144 nl_type = &type_system->types[type];
1145
cafbc790 1146 if (nl_type->type == NETLINK_TYPE_UNSPEC)
15411c0c 1147 return -EOPNOTSUPP;
d8e538ec
TG
1148
1149 *ret = nl_type;
1150
1151 return 0;
1152}
1153
1154int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
1155 const NLType *nl_type;
1156 int r;
1157
1158 assert(ret);
1159
1160 r = type_system_get_type(type_system, &nl_type, type);
1161 if (r < 0)
1162 return r;
1163
c658008f 1164 type_get_type_system(nl_type, ret);
d8e538ec
TG
1165 return 0;
1166}
1167
1168int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
1169 const NLType *nl_type;
1170 int r;
1171
1172 assert(ret);
1173
1174 r = type_system_get_type(type_system, &nl_type, type);
1175 if (r < 0)
1176 return r;
1177
c658008f 1178 type_get_type_system_union(nl_type, ret);
d8e538ec
TG
1179 return 0;
1180}
1181
1182int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
1183 int type;
1184
1185 assert(type_system_union);
f8a6ca1b 1186 assert(type_system_union->match_type == NL_MATCH_SIBLING);
d8e538ec
TG
1187 assert(type_system_union->lookup);
1188 assert(type_system_union->type_systems);
1189 assert(ret);
1190 assert(key);
1191
1192 type = type_system_union->lookup(key);
1193 if (type < 0)
15411c0c 1194 return -EOPNOTSUPP;
d8e538ec
TG
1195
1196 assert(type < type_system_union->num);
1197
1198 *ret = &type_system_union->type_systems[type];
1199
1200 return 0;
1201}
4af7b60d
TG
1202
1203int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
1204 const NLTypeSystem *type_system;
1205
1206 assert(type_system_union);
1207 assert(type_system_union->type_systems);
f8a6ca1b 1208 assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
4af7b60d 1209 assert(ret);
4af7b60d
TG
1210
1211 if (protocol >= type_system_union->num)
15411c0c 1212 return -EOPNOTSUPP;
4af7b60d
TG
1213
1214 type_system = &type_system_union->type_systems[protocol];
e7de105c 1215 if (!type_system->types)
15411c0c 1216 return -EOPNOTSUPP;
4af7b60d
TG
1217
1218 *ret = type_system;
1219
1220 return 0;
1221}