]>
Commit | Line | Data |
---|---|---|
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> |
0a827d10 | 19 | #include <linux/if_tunnel.h> |
3a56e697 | 20 | #include <linux/l2tp.h> |
5a2dadf1 | 21 | #include <linux/veth.h> |
01234e1f | 22 | #include <linux/wireguard.h> |
d6df583c | 23 | |
d8e538ec | 24 | #include "macro.h" |
0830ba61 | 25 | #include "missing.h" |
8b43440b | 26 | #include "netlink-types.h" |
5a2dadf1 | 27 | #include "sd-netlink.h" |
8b43440b LP |
28 | #include "string-table.h" |
29 | #include "util.h" | |
d8e538ec | 30 | |
dd906398 DH |
31 | /* Maximum ARP IP target defined in kernel */ |
32 | #define BOND_MAX_ARP_TARGETS 16 | |
33 | ||
34 | typedef enum { | |
35 | BOND_ARP_TARGETS_0, | |
36 | BOND_ARP_TARGETS_1, | |
37 | BOND_ARP_TARGETS_2, | |
38 | BOND_ARP_TARGETS_3, | |
39 | BOND_ARP_TARGETS_4, | |
40 | BOND_ARP_TARGETS_5, | |
41 | BOND_ARP_TARGETS_6, | |
42 | BOND_ARP_TARGETS_7, | |
43 | BOND_ARP_TARGETS_8, | |
44 | BOND_ARP_TARGETS_9, | |
45 | BOND_ARP_TARGETS_10, | |
46 | BOND_ARP_TARGETS_11, | |
47 | BOND_ARP_TARGETS_12, | |
48 | BOND_ARP_TARGETS_13, | |
49 | BOND_ARP_TARGETS_14, | |
50 | BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS, | |
51 | } BondArpTargets; | |
52 | ||
817d1cd8 DH |
53 | struct NLType { |
54 | uint16_t type; | |
55 | size_t size; | |
56 | const NLTypeSystem *type_system; | |
57 | const NLTypeSystemUnion *type_system_union; | |
58 | }; | |
59 | ||
435bbb02 | 60 | struct NLTypeSystem { |
c1df8dee | 61 | uint16_t count; |
435bbb02 DH |
62 | const NLType *types; |
63 | }; | |
64 | ||
d8e538ec TG |
65 | static const NLTypeSystem rtnl_link_type_system; |
66 | ||
979e7eb9 DH |
67 | static const NLType empty_types[1] = { |
68 | /* fake array to avoid .types==NULL, which denotes invalid type-systems */ | |
69 | }; | |
70 | ||
71 | static const NLTypeSystem empty_type_system = { | |
72 | .count = 0, | |
73 | .types = empty_types, | |
74 | }; | |
75 | ||
8ae4b6d1 | 76 | static const NLType rtnl_link_info_data_veth_types[] = { |
cafbc790 | 77 | [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, |
d8e538ec TG |
78 | }; |
79 | ||
d6df583c SS |
80 | static const NLType rtnl_link_info_data_vxcan_types[] = { |
81 | [VXCAN_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
82 | }; | |
83 | ||
8ae4b6d1 | 84 | static const NLType rtnl_link_info_data_ipvlan_types[] = { |
cafbc790 | 85 | [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 }, |
d384826f | 86 | [IFLA_IPVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, |
c4a5ddc9 | 87 | }; |
d8e538ec | 88 | |
8ae4b6d1 | 89 | static const NLType rtnl_link_info_data_macvlan_types[] = { |
cafbc790 DH |
90 | [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, |
91 | [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
d8e538ec TG |
92 | }; |
93 | ||
8ae4b6d1 | 94 | static const NLType rtnl_link_info_data_bridge_types[] = { |
3fef7a3f SS |
95 | [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 }, |
96 | [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 }, | |
97 | [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 }, | |
98 | [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 }, | |
99 | [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 }, | |
100 | [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
101 | [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 }, | |
102 | [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, | |
103 | [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 }, | |
104 | [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 }, | |
105 | [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 }, | |
106 | [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 }, | |
107 | [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 }, | |
108 | [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
109 | [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
110 | [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
111 | [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
112 | [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 }, | |
113 | [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 }, | |
114 | [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 }, | |
115 | [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 }, | |
116 | [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 }, | |
117 | [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 }, | |
118 | [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 }, | |
119 | [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 }, | |
120 | [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 }, | |
121 | [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 }, | |
122 | [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
123 | [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
124 | [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
125 | [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
126 | [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
127 | [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
128 | [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
129 | [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 }, | |
130 | [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
131 | [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 }, | |
ced671e1 SS |
132 | }; |
133 | ||
8ae4b6d1 | 134 | static const NLType rtnl_link_info_data_vlan_types[] = { |
cafbc790 | 135 | [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
136 | /* |
137 | [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) }, | |
cafbc790 DH |
138 | [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, |
139 | [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec | 140 | */ |
cafbc790 | 141 | [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
142 | }; |
143 | ||
8ae4b6d1 | 144 | static const NLType rtnl_link_info_data_vxlan_types[] = { |
452c9569 SS |
145 | [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 }, |
146 | [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR }, | |
147 | [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 }, | |
5564545b | 148 | [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
452c9569 SS |
149 | [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 }, |
150 | [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
151 | [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 }, | |
152 | [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 }, | |
153 | [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 }, | |
154 | [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32}, | |
155 | [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 }, | |
156 | [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 }, | |
157 | [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 }, | |
158 | [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 }, | |
159 | [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 }, | |
160 | [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
161 | [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
162 | [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
163 | [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 }, | |
164 | [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 }, | |
165 | [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 }, | |
166 | [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 }, | |
167 | [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG }, | |
168 | [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG }, | |
6d21646a SS |
169 | [IFLA_VXLAN_COLLECT_METADATA] = { .type = NETLINK_TYPE_U8 }, |
170 | [IFLA_VXLAN_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
171 | [IFLA_VXLAN_GPE] = { .type = NETLINK_TYPE_FLAG }, | |
6ef81477 SS |
172 | }; |
173 | ||
8ae4b6d1 | 174 | static const NLType rtnl_bond_arp_target_types[] = { |
cafbc790 DH |
175 | [BOND_ARP_TARGETS_0] = { .type = NETLINK_TYPE_U32 }, |
176 | [BOND_ARP_TARGETS_1] = { .type = NETLINK_TYPE_U32 }, | |
177 | [BOND_ARP_TARGETS_2] = { .type = NETLINK_TYPE_U32 }, | |
178 | [BOND_ARP_TARGETS_3] = { .type = NETLINK_TYPE_U32 }, | |
179 | [BOND_ARP_TARGETS_4] = { .type = NETLINK_TYPE_U32 }, | |
180 | [BOND_ARP_TARGETS_5] = { .type = NETLINK_TYPE_U32 }, | |
181 | [BOND_ARP_TARGETS_6] = { .type = NETLINK_TYPE_U32 }, | |
182 | [BOND_ARP_TARGETS_7] = { .type = NETLINK_TYPE_U32 }, | |
183 | [BOND_ARP_TARGETS_8] = { .type = NETLINK_TYPE_U32 }, | |
184 | [BOND_ARP_TARGETS_9] = { .type = NETLINK_TYPE_U32 }, | |
185 | [BOND_ARP_TARGETS_10] = { .type = NETLINK_TYPE_U32 }, | |
186 | [BOND_ARP_TARGETS_11] = { .type = NETLINK_TYPE_U32 }, | |
187 | [BOND_ARP_TARGETS_12] = { .type = NETLINK_TYPE_U32 }, | |
188 | [BOND_ARP_TARGETS_13] = { .type = NETLINK_TYPE_U32 }, | |
189 | [BOND_ARP_TARGETS_14] = { .type = NETLINK_TYPE_U32 }, | |
190 | [BOND_ARP_TARGETS_MAX] = { .type = NETLINK_TYPE_U32 }, | |
81bd37a8 SS |
191 | }; |
192 | ||
193 | static const NLTypeSystem rtnl_bond_arp_type_system = { | |
c1df8dee | 194 | .count = ELEMENTSOF(rtnl_bond_arp_target_types), |
81bd37a8 SS |
195 | .types = rtnl_bond_arp_target_types, |
196 | }; | |
197 | ||
8ae4b6d1 | 198 | static const NLType rtnl_link_info_data_bond_types[] = { |
cafbc790 DH |
199 | [IFLA_BOND_MODE] = { .type = NETLINK_TYPE_U8 }, |
200 | [IFLA_BOND_ACTIVE_SLAVE] = { .type = NETLINK_TYPE_U32 }, | |
201 | [IFLA_BOND_MIIMON] = { .type = NETLINK_TYPE_U32 }, | |
202 | [IFLA_BOND_UPDELAY] = { .type = NETLINK_TYPE_U32 }, | |
203 | [IFLA_BOND_DOWNDELAY] = { .type = NETLINK_TYPE_U32 }, | |
204 | [IFLA_BOND_USE_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
205 | [IFLA_BOND_ARP_INTERVAL] = { .type = NETLINK_TYPE_U32 }, | |
206 | [IFLA_BOND_ARP_IP_TARGET] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_bond_arp_type_system }, | |
207 | [IFLA_BOND_ARP_VALIDATE] = { .type = NETLINK_TYPE_U32 }, | |
208 | [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NETLINK_TYPE_U32 }, | |
209 | [IFLA_BOND_PRIMARY] = { .type = NETLINK_TYPE_U32 }, | |
210 | [IFLA_BOND_PRIMARY_RESELECT] = { .type = NETLINK_TYPE_U8 }, | |
211 | [IFLA_BOND_FAIL_OVER_MAC] = { .type = NETLINK_TYPE_U8 }, | |
212 | [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NETLINK_TYPE_U8 }, | |
213 | [IFLA_BOND_RESEND_IGMP] = { .type = NETLINK_TYPE_U32 }, | |
214 | [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NETLINK_TYPE_U8 }, | |
215 | [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NETLINK_TYPE_U8 }, | |
216 | [IFLA_BOND_MIN_LINKS] = { .type = NETLINK_TYPE_U32 }, | |
217 | [IFLA_BOND_LP_INTERVAL] = { .type = NETLINK_TYPE_U32 }, | |
218 | [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NETLINK_TYPE_U32 }, | |
219 | [IFLA_BOND_AD_LACP_RATE] = { .type = NETLINK_TYPE_U8 }, | |
220 | [IFLA_BOND_AD_SELECT] = { .type = NETLINK_TYPE_U8 }, | |
221 | [IFLA_BOND_AD_INFO] = { .type = NETLINK_TYPE_NESTED }, | |
99f68ef0 TJ |
222 | [IFLA_BOND_AD_ACTOR_SYS_PRIO] = { .type = NETLINK_TYPE_U16 }, |
223 | [IFLA_BOND_AD_USER_PORT_KEY] = { .type = NETLINK_TYPE_U16 }, | |
224 | [IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
fde60a42 | 225 | [IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NETLINK_TYPE_U8 }, |
d8e538ec TG |
226 | }; |
227 | ||
8ae4b6d1 | 228 | static const NLType rtnl_link_info_data_iptun_types[] = { |
cafbc790 DH |
229 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
230 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
231 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
232 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
233 | [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
234 | [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
235 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
236 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
237 | [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR }, | |
238 | [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 }, | |
239 | [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
240 | [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
6e74cade ZJS |
241 | [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, |
242 | [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
243 | [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
244 | [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
0a827d10 SS |
245 | }; |
246 | ||
8ae4b6d1 | 247 | static const NLType rtnl_link_info_data_ipgre_types[] = { |
8aee0f1f SS |
248 | [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 }, |
249 | [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
250 | [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
251 | [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
252 | [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
253 | [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
254 | [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
255 | [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 }, | |
256 | [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 }, | |
257 | [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
258 | [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, | |
259 | [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
260 | [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, | |
261 | [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
262 | [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
263 | [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
2266864b | 264 | [IFLA_GRE_ERSPAN_INDEX] = { .type = NETLINK_TYPE_U32 }, |
8bb088c5 SS |
265 | }; |
266 | ||
8ae4b6d1 | 267 | static const NLType rtnl_link_info_data_ipvti_types[] = { |
cafbc790 DH |
268 | [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 }, |
269 | [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
270 | [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
6e74cade ZJS |
271 | [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
272 | [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
a613382b SS |
273 | }; |
274 | ||
8ae4b6d1 | 275 | static const NLType rtnl_link_info_data_ip6tnl_types[] = { |
cafbc790 DH |
276 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
277 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
278 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
279 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
280 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
281 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
282 | [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 }, | |
6e74cade | 283 | [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, |
855ee1a1 SS |
284 | }; |
285 | ||
20897a0d AR |
286 | static const NLType rtnl_link_info_data_vrf_types[] = { |
287 | [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 }, | |
288 | }; | |
289 | ||
ca5e8071 SS |
290 | static const NLType rtnl_link_info_data_geneve_types[] = { |
291 | [IFLA_GENEVE_ID] = { .type = NETLINK_TYPE_U32 }, | |
292 | [IFLA_GENEVE_TTL] = { .type = NETLINK_TYPE_U8 }, | |
293 | [IFLA_GENEVE_TOS] = { .type = NETLINK_TYPE_U8 }, | |
294 | [IFLA_GENEVE_PORT] = { .type = NETLINK_TYPE_U16 }, | |
295 | [IFLA_GENEVE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
296 | [IFLA_GENEVE_REMOTE6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
297 | [IFLA_GENEVE_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
298 | [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 }, | |
299 | [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 }, | |
300 | [IFLA_GENEVE_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
301 | }; | |
302 | ||
06828bb6 HP |
303 | static const NLType rtnl_link_info_data_can_types[] = { |
304 | [IFLA_CAN_BITTIMING] = { .size = sizeof(struct can_bittiming) }, | |
305 | [IFLA_CAN_RESTART_MS] = { .type = NETLINK_TYPE_U32 }, | |
c423be28 | 306 | [IFLA_CAN_CTRLMODE] = { .size = sizeof(struct can_ctrlmode) }, |
06828bb6 HP |
307 | }; |
308 | ||
0a827d10 | 309 | /* these strings must match the .kind entries in the kernel */ |
8ae4b6d1 | 310 | static const char* const nl_union_link_info_data_table[] = { |
d8e538ec TG |
311 | [NL_UNION_LINK_INFO_DATA_BOND] = "bond", |
312 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge", | |
313 | [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan", | |
314 | [NL_UNION_LINK_INFO_DATA_VETH] = "veth", | |
9e358851 | 315 | [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy", |
d8e538ec | 316 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan", |
d1312575 | 317 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap", |
c4a5ddc9 | 318 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan", |
6ef81477 | 319 | [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan", |
0a827d10 | 320 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip", |
8bb088c5 | 321 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre", |
2266864b | 322 | [NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan", |
1af2536a | 323 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap", |
b16492f8 SS |
324 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre", |
325 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap", | |
0a827d10 | 326 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit", |
a613382b | 327 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti", |
9011ce77 | 328 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6", |
855ee1a1 | 329 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl", |
20897a0d | 330 | [NL_UNION_LINK_INFO_DATA_VRF] = "vrf", |
92c918b0 | 331 | [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan", |
ca5e8071 | 332 | [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve", |
d6df583c | 333 | [NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan", |
e5719363 | 334 | [NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard", |
56e7fb50 | 335 | [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim", |
06828bb6 | 336 | [NL_UNION_LINK_INFO_DATA_CAN] = "can", |
d8e538ec TG |
337 | }; |
338 | ||
339 | DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData); | |
340 | ||
8ae4b6d1 | 341 | static const NLTypeSystem rtnl_link_info_data_type_systems[] = { |
92c918b0 SS |
342 | [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types), |
343 | .types = rtnl_link_info_data_bond_types }, | |
344 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types), | |
345 | .types = rtnl_link_info_data_bridge_types }, | |
346 | [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types), | |
347 | .types = rtnl_link_info_data_vlan_types }, | |
348 | [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types), | |
349 | .types = rtnl_link_info_data_veth_types }, | |
350 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), | |
351 | .types = rtnl_link_info_data_macvlan_types }, | |
352 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), | |
353 | .types = rtnl_link_info_data_macvlan_types }, | |
354 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), | |
355 | .types = rtnl_link_info_data_ipvlan_types }, | |
356 | [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types), | |
357 | .types = rtnl_link_info_data_vxlan_types }, | |
358 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), | |
359 | .types = rtnl_link_info_data_iptun_types }, | |
360 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
361 | .types = rtnl_link_info_data_ipgre_types }, | |
2266864b SS |
362 | [NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
363 | .types = rtnl_link_info_data_ipgre_types }, | |
c1df8dee | 364 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
92c918b0 SS |
365 | .types = rtnl_link_info_data_ipgre_types }, |
366 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
367 | .types = rtnl_link_info_data_ipgre_types }, | |
368 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
369 | .types = rtnl_link_info_data_ipgre_types }, | |
370 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), | |
371 | .types = rtnl_link_info_data_iptun_types }, | |
372 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), | |
373 | .types = rtnl_link_info_data_ipvti_types }, | |
374 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), | |
375 | .types = rtnl_link_info_data_ipvti_types }, | |
376 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types), | |
377 | .types = rtnl_link_info_data_ip6tnl_types }, | |
378 | [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types), | |
379 | .types = rtnl_link_info_data_vrf_types }, | |
ca5e8071 SS |
380 | [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types), |
381 | .types = rtnl_link_info_data_geneve_types }, | |
d6df583c SS |
382 | [NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types), |
383 | .types = rtnl_link_info_data_vxcan_types }, | |
06828bb6 HP |
384 | [NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types), |
385 | .types = rtnl_link_info_data_can_types }, | |
d8e538ec TG |
386 | }; |
387 | ||
388 | static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = { | |
389 | .num = _NL_UNION_LINK_INFO_DATA_MAX, | |
390 | .lookup = nl_union_link_info_data_from_string, | |
391 | .type_systems = rtnl_link_info_data_type_systems, | |
4af7b60d | 392 | .match_type = NL_MATCH_SIBLING, |
d8e538ec TG |
393 | .match = IFLA_INFO_KIND, |
394 | }; | |
395 | ||
8ae4b6d1 | 396 | static const NLType rtnl_link_info_types[] = { |
cafbc790 DH |
397 | [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING }, |
398 | [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union}, | |
d8e538ec TG |
399 | /* |
400 | [IFLA_INFO_XSTATS], | |
cafbc790 DH |
401 | [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING }, |
402 | [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec TG |
403 | */ |
404 | }; | |
405 | ||
406 | static const NLTypeSystem rtnl_link_info_type_system = { | |
c1df8dee | 407 | .count = ELEMENTSOF(rtnl_link_info_types), |
d8e538ec TG |
408 | .types = rtnl_link_info_types, |
409 | }; | |
410 | ||
8ae4b6d1 | 411 | static const struct NLType rtnl_prot_info_bridge_port_types[] = { |
d3aa8b49 SS |
412 | [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 }, |
413 | [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 }, | |
414 | [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
415 | [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 }, | |
416 | [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 }, | |
417 | [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 }, | |
418 | [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 }, | |
419 | [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 }, | |
420 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
421 | [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 }, | |
422 | [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 }, | |
423 | [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NETLINK_TYPE_U8 }, | |
424 | [IFLA_BRPORT_ROOT_ID] = { .type = NETLINK_TYPE_U8 }, | |
425 | [IFLA_BRPORT_BRIDGE_ID] = { .type = NETLINK_TYPE_U8 }, | |
426 | [IFLA_BRPORT_DESIGNATED_PORT] = { .type = NETLINK_TYPE_U16 }, | |
427 | [IFLA_BRPORT_DESIGNATED_COST] = { .type = NETLINK_TYPE_U16 }, | |
428 | [IFLA_BRPORT_ID] = { .type = NETLINK_TYPE_U16 }, | |
429 | [IFLA_BRPORT_NO] = { .type = NETLINK_TYPE_U16 }, | |
430 | [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = { .type = NETLINK_TYPE_U8 }, | |
431 | [IFLA_BRPORT_CONFIG_PENDING] = { .type = NETLINK_TYPE_U8 }, | |
432 | [IFLA_BRPORT_MESSAGE_AGE_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
433 | [IFLA_BRPORT_FORWARD_DELAY_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
434 | [IFLA_BRPORT_HOLD_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
435 | [IFLA_BRPORT_FLUSH] = { .type = NETLINK_TYPE_U8 }, | |
436 | [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NETLINK_TYPE_U8 }, | |
437 | [IFLA_BRPORT_PAD] = { .type = NETLINK_TYPE_U8 }, | |
438 | [IFLA_BRPORT_MCAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
439 | [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NETLINK_TYPE_U8 }, | |
440 | [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NETLINK_TYPE_U8 }, | |
441 | [IFLA_BRPORT_BCAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
442 | [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 }, | |
443 | [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NETLINK_TYPE_U8 }, | |
444 | [IFLA_BRPORT_ISOLATED] = { .type = NETLINK_TYPE_U8 }, | |
445 | [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 }, | |
d0159fdc SS |
446 | }; |
447 | ||
8ae4b6d1 | 448 | static const NLTypeSystem rtnl_prot_info_type_systems[] = { |
c1df8dee | 449 | [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types), |
4af7b60d TG |
450 | .types = rtnl_prot_info_bridge_port_types }, |
451 | }; | |
452 | ||
453 | static const NLTypeSystemUnion rtnl_prot_info_type_system_union = { | |
454 | .num = AF_MAX, | |
455 | .type_systems = rtnl_prot_info_type_systems, | |
456 | .match_type = NL_MATCH_PROTOCOL, | |
d0159fdc SS |
457 | }; |
458 | ||
8ae4b6d1 | 459 | static const struct NLType rtnl_af_spec_inet6_types[] = { |
cafbc790 | 460 | [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
c149ae08 TG |
461 | /* |
462 | IFLA_INET6_CONF, | |
463 | IFLA_INET6_STATS, | |
464 | IFLA_INET6_MCAST, | |
465 | IFLA_INET6_CACHEINFO, | |
466 | IFLA_INET6_ICMP6STATS, | |
467 | */ | |
cafbc790 DH |
468 | [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR }, |
469 | [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 }, | |
c149ae08 TG |
470 | }; |
471 | ||
73cb1c14 | 472 | static const NLTypeSystem rtnl_af_spec_inet6_type_system = { |
c1df8dee | 473 | .count = ELEMENTSOF(rtnl_af_spec_inet6_types), |
73cb1c14 | 474 | .types = rtnl_af_spec_inet6_types, |
c149ae08 TG |
475 | }; |
476 | ||
8ae4b6d1 | 477 | static const NLType rtnl_af_spec_types[] = { |
cafbc790 | 478 | [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system }, |
73cb1c14 TG |
479 | }; |
480 | ||
481 | static const NLTypeSystem rtnl_af_spec_type_system = { | |
c1df8dee | 482 | .count = ELEMENTSOF(rtnl_af_spec_types), |
73cb1c14 | 483 | .types = rtnl_af_spec_types, |
c149ae08 TG |
484 | }; |
485 | ||
8ae4b6d1 | 486 | static const NLType rtnl_link_types[] = { |
6e74cade ZJS |
487 | [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR }, |
488 | [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
489 | [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
cafbc790 DH |
490 | [IFLA_MTU] = { .type = NETLINK_TYPE_U32 }, |
491 | [IFLA_LINK] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
492 | /* |
493 | [IFLA_QDISC], | |
494 | [IFLA_STATS], | |
495 | [IFLA_COST], | |
496 | [IFLA_PRIORITY], | |
497 | */ | |
cafbc790 | 498 | [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
499 | /* |
500 | [IFLA_WIRELESS], | |
d8e538ec | 501 | */ |
cafbc790 DH |
502 | [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union }, |
503 | [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
504 | /* |
505 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, | |
506 | */ | |
cafbc790 DH |
507 | [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 }, |
508 | [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 }, | |
509 | [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 }, | |
510 | [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system }, | |
511 | [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 }, | |
512 | [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 }, | |
d8e538ec TG |
513 | /* |
514 | [IFLA_NUM_VF], | |
cafbc790 | 515 | [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, }, |
d8e538ec | 516 | [IFLA_STATS64], |
cafbc790 DH |
517 | [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED }, |
518 | [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED }, | |
c149ae08 | 519 | */ |
cafbc790 | 520 | [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system }, |
c149ae08 | 521 | /* |
d8e538ec TG |
522 | [IFLA_VF_PORTS], |
523 | [IFLA_PORT_SELF], | |
524 | [IFLA_AF_SPEC], | |
525 | */ | |
cafbc790 DH |
526 | [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 }, |
527 | [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 }, | |
528 | [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 }, | |
529 | [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 }, | |
530 | [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
531 | [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
532 | [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
d8e538ec | 533 | /* |
cafbc790 | 534 | [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN }, |
d8e538ec TG |
535 | */ |
536 | }; | |
537 | ||
538 | static const NLTypeSystem rtnl_link_type_system = { | |
c1df8dee | 539 | .count = ELEMENTSOF(rtnl_link_types), |
d8e538ec TG |
540 | .types = rtnl_link_types, |
541 | }; | |
542 | ||
de79f906 LP |
543 | /* IFA_FLAGS was defined in kernel 3.14, but we still support older |
544 | * kernels where IFA_MAX is lower. */ | |
8ae4b6d1 | 545 | static const NLType rtnl_address_types[] = { |
cafbc790 DH |
546 | [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR }, |
547 | [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
548 | [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
549 | [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
550 | [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) }, | |
d8e538ec TG |
551 | /* |
552 | [IFA_ANYCAST], | |
d8e538ec TG |
553 | [IFA_MULTICAST], |
554 | */ | |
cafbc790 | 555 | [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
556 | }; |
557 | ||
558 | static const NLTypeSystem rtnl_address_type_system = { | |
c1df8dee | 559 | .count = ELEMENTSOF(rtnl_address_types), |
d8e538ec TG |
560 | .types = rtnl_address_types, |
561 | }; | |
562 | ||
d6fceaf1 SS |
563 | /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */ |
564 | ||
565 | static const NLType rtnl_route_metrics_types[] = { | |
566 | [RTAX_MTU] = { .type = NETLINK_TYPE_U32 }, | |
567 | [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 }, | |
568 | [RTAX_RTT] = { .type = NETLINK_TYPE_U32 }, | |
569 | [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 }, | |
570 | [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 }, | |
571 | [RTAX_CWND] = { .type = NETLINK_TYPE_U32 }, | |
572 | [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 }, | |
573 | [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 }, | |
574 | [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 }, | |
575 | [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 }, | |
576 | [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 }, | |
577 | [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 }, | |
323d9329 | 578 | [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 }, |
09f5dfad | 579 | [RTAX_QUICKACK] = { .type = NETLINK_TYPE_U32 }, |
d6fceaf1 SS |
580 | }; |
581 | ||
582 | static const NLTypeSystem rtnl_route_metrics_type_system = { | |
583 | .count = ELEMENTSOF(rtnl_route_metrics_types), | |
584 | .types = rtnl_route_metrics_types, | |
585 | }; | |
586 | ||
8ae4b6d1 | 587 | static const NLType rtnl_route_types[] = { |
cafbc790 DH |
588 | [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ |
589 | [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
590 | [RTA_IIF] = { .type = NETLINK_TYPE_U32 }, | |
591 | [RTA_OIF] = { .type = NETLINK_TYPE_U32 }, | |
592 | [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR }, | |
593 | [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, | |
594 | [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
d6fceaf1 SS |
595 | [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system}, |
596 | /* [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, | |
d8e538ec | 597 | */ |
cafbc790 | 598 | [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */ |
d8e538ec TG |
599 | /* |
600 | RTA_CACHEINFO, | |
601 | RTA_TABLE, | |
602 | RTA_MARK, | |
603 | RTA_MFC_STATS, | |
b69015ef TG |
604 | RTA_VIA, |
605 | RTA_NEWDST, | |
d8e538ec | 606 | */ |
b69015ef | 607 | [RTA_PREF] = { .type = NETLINK_TYPE_U8 }, |
f02ba163 DD |
608 | /* |
609 | RTA_ENCAP_TYPE, | |
610 | RTA_ENCAP, | |
611 | */ | |
612 | [RTA_EXPIRES] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
613 | }; |
614 | ||
615 | static const NLTypeSystem rtnl_route_type_system = { | |
c1df8dee | 616 | .count = ELEMENTSOF(rtnl_route_types), |
d8e538ec TG |
617 | .types = rtnl_route_types, |
618 | }; | |
619 | ||
8ae4b6d1 | 620 | static const NLType rtnl_neigh_types[] = { |
cafbc790 DH |
621 | [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, |
622 | [NDA_LLADDR] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
623 | [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) }, | |
624 | [NDA_PROBES] = { .type = NETLINK_TYPE_U32 }, | |
625 | [NDA_VLAN] = { .type = NETLINK_TYPE_U16 }, | |
626 | [NDA_PORT] = { .type = NETLINK_TYPE_U16 }, | |
627 | [NDA_VNI] = { .type = NETLINK_TYPE_U32 }, | |
628 | [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 }, | |
e559b384 TG |
629 | }; |
630 | ||
631 | static const NLTypeSystem rtnl_neigh_type_system = { | |
c1df8dee | 632 | .count = ELEMENTSOF(rtnl_neigh_types), |
e559b384 TG |
633 | .types = rtnl_neigh_types, |
634 | }; | |
635 | ||
30746d60 SS |
636 | static const NLType rtnl_addrlabel_types[] = { |
637 | [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) }, | |
638 | [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
639 | }; | |
640 | ||
641 | static const NLTypeSystem rtnl_addrlabel_type_system = { | |
642 | .count = ELEMENTSOF(rtnl_addrlabel_types), | |
643 | .types = rtnl_addrlabel_types, | |
644 | }; | |
645 | ||
bce67bbe SS |
646 | static const NLType rtnl_routing_policy_rule_types[] = { |
647 | [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, | |
648 | [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, | |
649 | [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING }, | |
8abd60c1 | 650 | [FRA_GOTO] = { .type = NETLINK_TYPE_U32 }, |
bce67bbe SS |
651 | [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, |
652 | [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 }, | |
653 | [FRA_FLOW] = { .type = NETLINK_TYPE_U32 }, | |
202aa159 | 654 | [FRA_TUN_ID] = { .type = NETLINK_TYPE_U64 }, |
bce67bbe SS |
655 | [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 }, |
656 | [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 }, | |
657 | [FRA_TABLE] = { .type = NETLINK_TYPE_U32 }, | |
658 | [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 }, | |
659 | [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING }, | |
660 | [FRA_PAD] = { .type = NETLINK_TYPE_U32 }, | |
a15ff62d | 661 | [FRA_L3MDEV] = { .type = NETLINK_TYPE_U8 }, |
bce67bbe | 662 | [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) }, |
926062f0 SS |
663 | [FRA_PROTOCOL] = { .type = NETLINK_TYPE_U8 }, |
664 | [FRA_IP_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
665 | [FRA_SPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) }, | |
666 | [FRA_DPORT_RANGE] = { .size = sizeof(struct fib_rule_port_range) }, | |
bce67bbe SS |
667 | }; |
668 | ||
669 | static const NLTypeSystem rtnl_routing_policy_rule_type_system = { | |
670 | .count = ELEMENTSOF(rtnl_routing_policy_rule_types), | |
671 | .types = rtnl_routing_policy_rule_types, | |
672 | }; | |
673 | ||
8ae4b6d1 | 674 | static const NLType rtnl_types[] = { |
30746d60 SS |
675 | [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 }, |
676 | [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) }, | |
677 | [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
678 | [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
679 | [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
680 | [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
681 | [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
682 | [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
683 | [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
684 | [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
685 | [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
686 | [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
687 | [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
688 | [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
689 | [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
690 | [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
691 | [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
692 | [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
bce67bbe SS |
693 | [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, |
694 | [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, | |
695 | [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, | |
d8e538ec TG |
696 | }; |
697 | ||
05d0c2e3 | 698 | const NLTypeSystem rtnl_type_system_root = { |
c1df8dee | 699 | .count = ELEMENTSOF(rtnl_types), |
d8e538ec TG |
700 | .types = rtnl_types, |
701 | }; | |
702 | ||
e5719363 JT |
703 | static const NLType genl_wireguard_allowedip_types[] = { |
704 | [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 }, | |
705 | [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR }, | |
706 | [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 }, | |
707 | }; | |
708 | ||
709 | static const NLTypeSystem genl_wireguard_allowedip_type_system = { | |
710 | .count = ELEMENTSOF(genl_wireguard_allowedip_types), | |
711 | .types = genl_wireguard_allowedip_types, | |
712 | }; | |
713 | ||
714 | static const NLType genl_wireguard_peer_types[] = { | |
715 | [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN }, | |
716 | [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
717 | [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN }, | |
7d0b26a0 | 718 | [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 }, |
abd48ec8 | 719 | [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR }, |
e5719363 JT |
720 | [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system }, |
721 | }; | |
722 | ||
723 | static const NLTypeSystem genl_wireguard_peer_type_system = { | |
724 | .count = ELEMENTSOF(genl_wireguard_peer_types), | |
725 | .types = genl_wireguard_peer_types, | |
726 | }; | |
727 | ||
728 | static const NLType genl_wireguard_set_device_types[] = { | |
729 | [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 }, | |
33c2ea80 | 730 | [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 }, |
e5719363 JT |
731 | [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
732 | [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN }, | |
733 | [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 }, | |
734 | [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 }, | |
735 | [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system }, | |
736 | }; | |
737 | ||
738 | static const NLTypeSystem genl_wireguard_set_device_type_system = { | |
739 | .count = ELEMENTSOF(genl_wireguard_set_device_types), | |
740 | .types = genl_wireguard_set_device_types, | |
741 | }; | |
742 | ||
743 | static const NLType genl_wireguard_cmds[] = { | |
744 | [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system }, | |
745 | }; | |
746 | ||
747 | static const NLTypeSystem genl_wireguard_type_system = { | |
748 | .count = ELEMENTSOF(genl_wireguard_cmds), | |
749 | .types = genl_wireguard_cmds, | |
750 | }; | |
05d0c2e3 JT |
751 | |
752 | static const NLType genl_get_family_types[] = { | |
753 | [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING }, | |
754 | [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 }, | |
755 | }; | |
756 | ||
757 | static const NLTypeSystem genl_get_family_type_system = { | |
758 | .count = ELEMENTSOF(genl_get_family_types), | |
759 | .types = genl_get_family_types, | |
760 | }; | |
761 | ||
762 | static const NLType genl_ctrl_id_ctrl_cmds[] = { | |
763 | [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system }, | |
764 | }; | |
765 | ||
766 | static const NLTypeSystem genl_ctrl_id_ctrl_type_system = { | |
767 | .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds), | |
768 | .types = genl_ctrl_id_ctrl_cmds, | |
769 | }; | |
770 | ||
53cb501a SS |
771 | static const NLType genl_fou_types[] = { |
772 | [FOU_ATTR_PORT] = { .type = NETLINK_TYPE_U16 }, | |
773 | [FOU_ATTR_AF] = { .type = NETLINK_TYPE_U8 }, | |
774 | [FOU_ATTR_IPPROTO] = { .type = NETLINK_TYPE_U8 }, | |
775 | [FOU_ATTR_TYPE] = { .type = NETLINK_TYPE_U8 }, | |
776 | [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG }, | |
777 | }; | |
778 | ||
779 | static const NLTypeSystem genl_fou_type_system = { | |
780 | .count = ELEMENTSOF(genl_fou_types), | |
781 | .types = genl_fou_types, | |
782 | }; | |
783 | ||
784 | static const NLType genl_fou_cmds[] = { | |
785 | [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, | |
786 | [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, | |
787 | [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, | |
788 | }; | |
789 | ||
790 | static const NLTypeSystem genl_fou_cmds_type_system = { | |
791 | .count = ELEMENTSOF(genl_fou_cmds), | |
792 | .types = genl_fou_cmds, | |
793 | }; | |
794 | ||
3a56e697 SS |
795 | static const NLType genl_l2tp_types[] = { |
796 | [L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 }, | |
797 | [L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, | |
798 | [L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 }, | |
799 | [L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 }, | |
800 | [L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 }, | |
801 | [L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 }, | |
802 | [L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 }, | |
803 | [L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING }, | |
804 | [L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 }, | |
805 | [L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 }, | |
806 | [L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 }, | |
807 | [L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 }, | |
808 | [L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
809 | [L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 }, | |
810 | [L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 }, | |
811 | [L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 }, | |
812 | [L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 }, | |
813 | [L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 }, | |
814 | [L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 }, | |
815 | [L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR }, | |
816 | [L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR }, | |
817 | [L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
818 | [L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
819 | [L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR }, | |
820 | [L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR }, | |
821 | [L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG }, | |
822 | [L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG }, | |
823 | }; | |
824 | ||
825 | static const NLTypeSystem genl_l2tp_type_system = { | |
826 | .count = ELEMENTSOF(genl_l2tp_types), | |
827 | .types = genl_l2tp_types, | |
828 | }; | |
829 | ||
830 | static const NLType genl_l2tp[] = { | |
831 | [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
832 | [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
833 | [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
834 | [L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
835 | [L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
836 | [L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
837 | [L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
838 | [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, | |
839 | }; | |
840 | ||
841 | static const NLTypeSystem genl_l2tp_tunnel_session_type_system = { | |
842 | .count = ELEMENTSOF(genl_l2tp), | |
843 | .types = genl_l2tp, | |
844 | }; | |
845 | ||
05d0c2e3 | 846 | static const NLType genl_families[] = { |
53cb501a | 847 | [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system }, |
e5719363 | 848 | [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system }, |
53cb501a | 849 | [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system}, |
3a56e697 | 850 | [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system }, |
05d0c2e3 JT |
851 | }; |
852 | ||
853 | const NLTypeSystem genl_family_type_system_root = { | |
854 | .count = ELEMENTSOF(genl_families), | |
855 | .types = genl_families, | |
856 | }; | |
857 | ||
858 | static const NLType genl_types[] = { | |
0aa2fe6f | 859 | [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) }, |
05d0c2e3 JT |
860 | [GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) }, |
861 | }; | |
862 | ||
863 | const NLTypeSystem genl_type_system_root = { | |
864 | .count = ELEMENTSOF(genl_types), | |
865 | .types = genl_types, | |
866 | }; | |
867 | ||
817d1cd8 DH |
868 | uint16_t type_get_type(const NLType *type) { |
869 | assert(type); | |
870 | return type->type; | |
871 | } | |
872 | ||
873 | size_t type_get_size(const NLType *type) { | |
874 | assert(type); | |
875 | return type->size; | |
876 | } | |
877 | ||
c658008f DH |
878 | void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { |
879 | assert(nl_type); | |
880 | assert(ret); | |
881 | assert(nl_type->type == NETLINK_TYPE_NESTED); | |
882 | assert(nl_type->type_system); | |
883 | ||
884 | *ret = nl_type->type_system; | |
885 | } | |
886 | ||
887 | void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { | |
888 | assert(nl_type); | |
889 | assert(ret); | |
890 | assert(nl_type->type == NETLINK_TYPE_UNION); | |
891 | assert(nl_type->type_system_union); | |
892 | ||
893 | *ret = nl_type->type_system_union; | |
894 | } | |
895 | ||
c1df8dee | 896 | uint16_t type_system_get_count(const NLTypeSystem *type_system) { |
435bbb02 | 897 | assert(type_system); |
c1df8dee | 898 | return type_system->count; |
435bbb02 DH |
899 | } |
900 | ||
05d0c2e3 JT |
901 | const NLTypeSystem *type_system_get_root(int protocol) { |
902 | switch (protocol) { | |
903 | case NETLINK_GENERIC: | |
904 | return &genl_type_system_root; | |
905 | default: /* NETLINK_ROUTE: */ | |
906 | return &rtnl_type_system_root; | |
907 | } | |
908 | } | |
909 | ||
d8e538ec TG |
910 | int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) { |
911 | const NLType *nl_type; | |
912 | ||
913 | assert(ret); | |
846a6b3d | 914 | assert(type_system); |
d8e538ec TG |
915 | assert(type_system->types); |
916 | ||
c1df8dee | 917 | if (type >= type_system->count) |
15411c0c | 918 | return -EOPNOTSUPP; |
d8e538ec TG |
919 | |
920 | nl_type = &type_system->types[type]; | |
921 | ||
cafbc790 | 922 | if (nl_type->type == NETLINK_TYPE_UNSPEC) |
15411c0c | 923 | return -EOPNOTSUPP; |
d8e538ec TG |
924 | |
925 | *ret = nl_type; | |
926 | ||
927 | return 0; | |
928 | } | |
929 | ||
930 | int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) { | |
931 | const NLType *nl_type; | |
932 | int r; | |
933 | ||
934 | assert(ret); | |
935 | ||
936 | r = type_system_get_type(type_system, &nl_type, type); | |
937 | if (r < 0) | |
938 | return r; | |
939 | ||
c658008f | 940 | type_get_type_system(nl_type, ret); |
d8e538ec TG |
941 | return 0; |
942 | } | |
943 | ||
944 | int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) { | |
945 | const NLType *nl_type; | |
946 | int r; | |
947 | ||
948 | assert(ret); | |
949 | ||
950 | r = type_system_get_type(type_system, &nl_type, type); | |
951 | if (r < 0) | |
952 | return r; | |
953 | ||
c658008f | 954 | type_get_type_system_union(nl_type, ret); |
d8e538ec TG |
955 | return 0; |
956 | } | |
957 | ||
958 | int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) { | |
959 | int type; | |
960 | ||
961 | assert(type_system_union); | |
f8a6ca1b | 962 | assert(type_system_union->match_type == NL_MATCH_SIBLING); |
d8e538ec TG |
963 | assert(type_system_union->lookup); |
964 | assert(type_system_union->type_systems); | |
965 | assert(ret); | |
966 | assert(key); | |
967 | ||
968 | type = type_system_union->lookup(key); | |
969 | if (type < 0) | |
15411c0c | 970 | return -EOPNOTSUPP; |
d8e538ec TG |
971 | |
972 | assert(type < type_system_union->num); | |
973 | ||
974 | *ret = &type_system_union->type_systems[type]; | |
975 | ||
976 | return 0; | |
977 | } | |
4af7b60d TG |
978 | |
979 | int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) { | |
980 | const NLTypeSystem *type_system; | |
981 | ||
982 | assert(type_system_union); | |
983 | assert(type_system_union->type_systems); | |
f8a6ca1b | 984 | assert(type_system_union->match_type == NL_MATCH_PROTOCOL); |
4af7b60d | 985 | assert(ret); |
4af7b60d TG |
986 | |
987 | if (protocol >= type_system_union->num) | |
15411c0c | 988 | return -EOPNOTSUPP; |
4af7b60d TG |
989 | |
990 | type_system = &type_system_union->type_systems[protocol]; | |
e7de105c | 991 | if (!type_system->types) |
15411c0c | 992 | return -EOPNOTSUPP; |
4af7b60d TG |
993 | |
994 | *ret = type_system; | |
995 | ||
996 | return 0; | |
997 | } |