]>
Commit | Line | Data |
---|---|---|
d8e538ec TG |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2014 Tom Gundersen <teg@jklm.no> | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
d8e538ec TG |
20 | #include <stdint.h> |
21 | #include <sys/socket.h> | |
22 | #include <linux/netlink.h> | |
23 | #include <linux/rtnetlink.h> | |
92c918b0 | 24 | #include <linux/can/netlink.h> |
bce67bbe | 25 | #include <linux/fib_rules.h> |
e410b07d | 26 | #include <linux/in6.h> |
d8e538ec TG |
27 | #include <linux/veth.h> |
28 | #include <linux/if_bridge.h> | |
29 | #include <linux/if_addr.h> | |
30746d60 | 30 | #include <linux/if_addrlabel.h> |
d8e538ec | 31 | #include <linux/if.h> |
0a827d10 | 32 | #include <linux/ip.h> |
bce67bbe SS |
33 | #include <linux/if_addr.h> |
34 | #include <linux/if_bridge.h> | |
c4a5ddc9 | 35 | #include <linux/if_link.h> |
0a827d10 | 36 | #include <linux/if_tunnel.h> |
bce67bbe | 37 | #include <linux/fib_rules.h> |
0a827d10 | 38 | |
d8e538ec | 39 | #include "macro.h" |
0830ba61 | 40 | #include "missing.h" |
8b43440b LP |
41 | #include "netlink-types.h" |
42 | #include "string-table.h" | |
43 | #include "util.h" | |
d8e538ec | 44 | |
dd906398 DH |
45 | /* Maximum ARP IP target defined in kernel */ |
46 | #define BOND_MAX_ARP_TARGETS 16 | |
47 | ||
48 | typedef enum { | |
49 | BOND_ARP_TARGETS_0, | |
50 | BOND_ARP_TARGETS_1, | |
51 | BOND_ARP_TARGETS_2, | |
52 | BOND_ARP_TARGETS_3, | |
53 | BOND_ARP_TARGETS_4, | |
54 | BOND_ARP_TARGETS_5, | |
55 | BOND_ARP_TARGETS_6, | |
56 | BOND_ARP_TARGETS_7, | |
57 | BOND_ARP_TARGETS_8, | |
58 | BOND_ARP_TARGETS_9, | |
59 | BOND_ARP_TARGETS_10, | |
60 | BOND_ARP_TARGETS_11, | |
61 | BOND_ARP_TARGETS_12, | |
62 | BOND_ARP_TARGETS_13, | |
63 | BOND_ARP_TARGETS_14, | |
64 | BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS, | |
65 | } BondArpTargets; | |
66 | ||
817d1cd8 DH |
67 | struct NLType { |
68 | uint16_t type; | |
69 | size_t size; | |
70 | const NLTypeSystem *type_system; | |
71 | const NLTypeSystemUnion *type_system_union; | |
72 | }; | |
73 | ||
435bbb02 | 74 | struct NLTypeSystem { |
c1df8dee | 75 | uint16_t count; |
435bbb02 DH |
76 | const NLType *types; |
77 | }; | |
78 | ||
d8e538ec TG |
79 | static const NLTypeSystem rtnl_link_type_system; |
80 | ||
979e7eb9 DH |
81 | static const NLType empty_types[1] = { |
82 | /* fake array to avoid .types==NULL, which denotes invalid type-systems */ | |
83 | }; | |
84 | ||
85 | static const NLTypeSystem empty_type_system = { | |
86 | .count = 0, | |
87 | .types = empty_types, | |
88 | }; | |
89 | ||
8ae4b6d1 | 90 | static const NLType rtnl_link_info_data_veth_types[] = { |
cafbc790 | 91 | [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, |
d8e538ec TG |
92 | }; |
93 | ||
8ae4b6d1 | 94 | static const NLType rtnl_link_info_data_ipvlan_types[] = { |
cafbc790 | 95 | [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 }, |
c4a5ddc9 | 96 | }; |
d8e538ec | 97 | |
8ae4b6d1 | 98 | static const NLType rtnl_link_info_data_macvlan_types[] = { |
cafbc790 DH |
99 | [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, |
100 | [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
d8e538ec TG |
101 | }; |
102 | ||
8ae4b6d1 | 103 | static const NLType rtnl_link_info_data_bridge_types[] = { |
3fef7a3f SS |
104 | [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 }, |
105 | [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 }, | |
106 | [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 }, | |
107 | [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 }, | |
108 | [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 }, | |
109 | [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
110 | [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 }, | |
111 | [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, | |
112 | [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 }, | |
113 | [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 }, | |
114 | [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 }, | |
115 | [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 }, | |
116 | [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 }, | |
117 | [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
118 | [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
119 | [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
120 | [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
121 | [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 }, | |
122 | [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 }, | |
123 | [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 }, | |
124 | [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 }, | |
125 | [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 }, | |
126 | [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 }, | |
127 | [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 }, | |
128 | [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 }, | |
129 | [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 }, | |
130 | [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 }, | |
131 | [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
132 | [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
133 | [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
134 | [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
135 | [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
136 | [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
137 | [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
138 | [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 }, | |
139 | [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
140 | [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 }, | |
ced671e1 SS |
141 | }; |
142 | ||
8ae4b6d1 | 143 | static const NLType rtnl_link_info_data_vlan_types[] = { |
cafbc790 | 144 | [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
145 | /* |
146 | [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) }, | |
cafbc790 DH |
147 | [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, |
148 | [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec | 149 | */ |
cafbc790 | 150 | [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
151 | }; |
152 | ||
8ae4b6d1 | 153 | static const NLType rtnl_link_info_data_vxlan_types[] = { |
452c9569 SS |
154 | [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 }, |
155 | [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR }, | |
156 | [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 }, | |
5564545b | 157 | [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
452c9569 SS |
158 | [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 }, |
159 | [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
160 | [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 }, | |
161 | [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 }, | |
162 | [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 }, | |
163 | [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32}, | |
164 | [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 }, | |
165 | [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 }, | |
166 | [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 }, | |
167 | [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 }, | |
168 | [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 }, | |
169 | [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
170 | [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
171 | [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
172 | [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 }, | |
173 | [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 }, | |
174 | [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 }, | |
175 | [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 }, | |
176 | [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG }, | |
177 | [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG }, | |
6d21646a SS |
178 | [IFLA_VXLAN_COLLECT_METADATA] = { .type = NETLINK_TYPE_U8 }, |
179 | [IFLA_VXLAN_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
180 | [IFLA_VXLAN_GPE] = { .type = NETLINK_TYPE_FLAG }, | |
6ef81477 SS |
181 | }; |
182 | ||
8ae4b6d1 | 183 | static const NLType rtnl_bond_arp_target_types[] = { |
cafbc790 DH |
184 | [BOND_ARP_TARGETS_0] = { .type = NETLINK_TYPE_U32 }, |
185 | [BOND_ARP_TARGETS_1] = { .type = NETLINK_TYPE_U32 }, | |
186 | [BOND_ARP_TARGETS_2] = { .type = NETLINK_TYPE_U32 }, | |
187 | [BOND_ARP_TARGETS_3] = { .type = NETLINK_TYPE_U32 }, | |
188 | [BOND_ARP_TARGETS_4] = { .type = NETLINK_TYPE_U32 }, | |
189 | [BOND_ARP_TARGETS_5] = { .type = NETLINK_TYPE_U32 }, | |
190 | [BOND_ARP_TARGETS_6] = { .type = NETLINK_TYPE_U32 }, | |
191 | [BOND_ARP_TARGETS_7] = { .type = NETLINK_TYPE_U32 }, | |
192 | [BOND_ARP_TARGETS_8] = { .type = NETLINK_TYPE_U32 }, | |
193 | [BOND_ARP_TARGETS_9] = { .type = NETLINK_TYPE_U32 }, | |
194 | [BOND_ARP_TARGETS_10] = { .type = NETLINK_TYPE_U32 }, | |
195 | [BOND_ARP_TARGETS_11] = { .type = NETLINK_TYPE_U32 }, | |
196 | [BOND_ARP_TARGETS_12] = { .type = NETLINK_TYPE_U32 }, | |
197 | [BOND_ARP_TARGETS_13] = { .type = NETLINK_TYPE_U32 }, | |
198 | [BOND_ARP_TARGETS_14] = { .type = NETLINK_TYPE_U32 }, | |
199 | [BOND_ARP_TARGETS_MAX] = { .type = NETLINK_TYPE_U32 }, | |
81bd37a8 SS |
200 | }; |
201 | ||
202 | static const NLTypeSystem rtnl_bond_arp_type_system = { | |
c1df8dee | 203 | .count = ELEMENTSOF(rtnl_bond_arp_target_types), |
81bd37a8 SS |
204 | .types = rtnl_bond_arp_target_types, |
205 | }; | |
206 | ||
8ae4b6d1 | 207 | static const NLType rtnl_link_info_data_bond_types[] = { |
cafbc790 DH |
208 | [IFLA_BOND_MODE] = { .type = NETLINK_TYPE_U8 }, |
209 | [IFLA_BOND_ACTIVE_SLAVE] = { .type = NETLINK_TYPE_U32 }, | |
210 | [IFLA_BOND_MIIMON] = { .type = NETLINK_TYPE_U32 }, | |
211 | [IFLA_BOND_UPDELAY] = { .type = NETLINK_TYPE_U32 }, | |
212 | [IFLA_BOND_DOWNDELAY] = { .type = NETLINK_TYPE_U32 }, | |
213 | [IFLA_BOND_USE_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
214 | [IFLA_BOND_ARP_INTERVAL] = { .type = NETLINK_TYPE_U32 }, | |
215 | [IFLA_BOND_ARP_IP_TARGET] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_bond_arp_type_system }, | |
216 | [IFLA_BOND_ARP_VALIDATE] = { .type = NETLINK_TYPE_U32 }, | |
217 | [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NETLINK_TYPE_U32 }, | |
218 | [IFLA_BOND_PRIMARY] = { .type = NETLINK_TYPE_U32 }, | |
219 | [IFLA_BOND_PRIMARY_RESELECT] = { .type = NETLINK_TYPE_U8 }, | |
220 | [IFLA_BOND_FAIL_OVER_MAC] = { .type = NETLINK_TYPE_U8 }, | |
221 | [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NETLINK_TYPE_U8 }, | |
222 | [IFLA_BOND_RESEND_IGMP] = { .type = NETLINK_TYPE_U32 }, | |
223 | [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NETLINK_TYPE_U8 }, | |
224 | [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NETLINK_TYPE_U8 }, | |
225 | [IFLA_BOND_MIN_LINKS] = { .type = NETLINK_TYPE_U32 }, | |
226 | [IFLA_BOND_LP_INTERVAL] = { .type = NETLINK_TYPE_U32 }, | |
227 | [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NETLINK_TYPE_U32 }, | |
228 | [IFLA_BOND_AD_LACP_RATE] = { .type = NETLINK_TYPE_U8 }, | |
229 | [IFLA_BOND_AD_SELECT] = { .type = NETLINK_TYPE_U8 }, | |
230 | [IFLA_BOND_AD_INFO] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec TG |
231 | }; |
232 | ||
8ae4b6d1 | 233 | static const NLType rtnl_link_info_data_iptun_types[] = { |
cafbc790 DH |
234 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
235 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
236 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
237 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
238 | [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
239 | [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
240 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
241 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
242 | [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR }, | |
243 | [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 }, | |
244 | [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
245 | [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
6e74cade ZJS |
246 | [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, |
247 | [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
248 | [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
249 | [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
0a827d10 SS |
250 | }; |
251 | ||
8ae4b6d1 | 252 | static const NLType rtnl_link_info_data_ipgre_types[] = { |
8aee0f1f SS |
253 | [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 }, |
254 | [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
255 | [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
256 | [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
257 | [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
258 | [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
259 | [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
260 | [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 }, | |
261 | [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 }, | |
262 | [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
263 | [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, | |
264 | [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
265 | [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, | |
266 | [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
267 | [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
268 | [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
8bb088c5 SS |
269 | }; |
270 | ||
8ae4b6d1 | 271 | static const NLType rtnl_link_info_data_ipvti_types[] = { |
cafbc790 DH |
272 | [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 }, |
273 | [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
274 | [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
6e74cade ZJS |
275 | [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
276 | [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
a613382b SS |
277 | }; |
278 | ||
8ae4b6d1 | 279 | static const NLType rtnl_link_info_data_ip6tnl_types[] = { |
cafbc790 DH |
280 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
281 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
282 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
283 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
284 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
285 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
286 | [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 }, | |
6e74cade | 287 | [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, |
855ee1a1 SS |
288 | }; |
289 | ||
20897a0d AR |
290 | static const NLType rtnl_link_info_data_vrf_types[] = { |
291 | [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 }, | |
292 | }; | |
293 | ||
ca5e8071 SS |
294 | static const NLType rtnl_link_info_data_geneve_types[] = { |
295 | [IFLA_GENEVE_ID] = { .type = NETLINK_TYPE_U32 }, | |
296 | [IFLA_GENEVE_TTL] = { .type = NETLINK_TYPE_U8 }, | |
297 | [IFLA_GENEVE_TOS] = { .type = NETLINK_TYPE_U8 }, | |
298 | [IFLA_GENEVE_PORT] = { .type = NETLINK_TYPE_U16 }, | |
299 | [IFLA_GENEVE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
300 | [IFLA_GENEVE_REMOTE6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
301 | [IFLA_GENEVE_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
302 | [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 }, | |
303 | [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 }, | |
304 | [IFLA_GENEVE_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
305 | }; | |
306 | ||
0a827d10 | 307 | /* these strings must match the .kind entries in the kernel */ |
8ae4b6d1 | 308 | static const char* const nl_union_link_info_data_table[] = { |
d8e538ec TG |
309 | [NL_UNION_LINK_INFO_DATA_BOND] = "bond", |
310 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge", | |
311 | [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan", | |
312 | [NL_UNION_LINK_INFO_DATA_VETH] = "veth", | |
9e358851 | 313 | [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy", |
d8e538ec | 314 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan", |
d1312575 | 315 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap", |
c4a5ddc9 | 316 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan", |
6ef81477 | 317 | [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan", |
0a827d10 | 318 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip", |
8bb088c5 | 319 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre", |
1af2536a | 320 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap", |
b16492f8 SS |
321 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre", |
322 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap", | |
0a827d10 | 323 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit", |
a613382b | 324 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti", |
9011ce77 | 325 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6", |
855ee1a1 | 326 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl", |
20897a0d | 327 | [NL_UNION_LINK_INFO_DATA_VRF] = "vrf", |
92c918b0 | 328 | [NL_UNION_LINK_INFO_DATA_VCAN] = "vcan", |
ca5e8071 | 329 | [NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve", |
d8e538ec TG |
330 | }; |
331 | ||
332 | DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData); | |
333 | ||
8ae4b6d1 | 334 | static const NLTypeSystem rtnl_link_info_data_type_systems[] = { |
92c918b0 SS |
335 | [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types), |
336 | .types = rtnl_link_info_data_bond_types }, | |
337 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types), | |
338 | .types = rtnl_link_info_data_bridge_types }, | |
339 | [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types), | |
340 | .types = rtnl_link_info_data_vlan_types }, | |
341 | [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types), | |
342 | .types = rtnl_link_info_data_veth_types }, | |
343 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), | |
344 | .types = rtnl_link_info_data_macvlan_types }, | |
345 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), | |
346 | .types = rtnl_link_info_data_macvlan_types }, | |
347 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), | |
348 | .types = rtnl_link_info_data_ipvlan_types }, | |
349 | [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types), | |
350 | .types = rtnl_link_info_data_vxlan_types }, | |
351 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), | |
352 | .types = rtnl_link_info_data_iptun_types }, | |
353 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
354 | .types = rtnl_link_info_data_ipgre_types }, | |
c1df8dee | 355 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
92c918b0 SS |
356 | .types = rtnl_link_info_data_ipgre_types }, |
357 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
358 | .types = rtnl_link_info_data_ipgre_types }, | |
359 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), | |
360 | .types = rtnl_link_info_data_ipgre_types }, | |
361 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), | |
362 | .types = rtnl_link_info_data_iptun_types }, | |
363 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), | |
364 | .types = rtnl_link_info_data_ipvti_types }, | |
365 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), | |
366 | .types = rtnl_link_info_data_ipvti_types }, | |
367 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types), | |
368 | .types = rtnl_link_info_data_ip6tnl_types }, | |
369 | [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types), | |
370 | .types = rtnl_link_info_data_vrf_types }, | |
ca5e8071 SS |
371 | [NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types), |
372 | .types = rtnl_link_info_data_geneve_types }, | |
d8e538ec TG |
373 | }; |
374 | ||
375 | static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = { | |
376 | .num = _NL_UNION_LINK_INFO_DATA_MAX, | |
377 | .lookup = nl_union_link_info_data_from_string, | |
378 | .type_systems = rtnl_link_info_data_type_systems, | |
4af7b60d | 379 | .match_type = NL_MATCH_SIBLING, |
d8e538ec TG |
380 | .match = IFLA_INFO_KIND, |
381 | }; | |
382 | ||
8ae4b6d1 | 383 | static const NLType rtnl_link_info_types[] = { |
cafbc790 DH |
384 | [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING }, |
385 | [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union}, | |
d8e538ec TG |
386 | /* |
387 | [IFLA_INFO_XSTATS], | |
cafbc790 DH |
388 | [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING }, |
389 | [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec TG |
390 | */ |
391 | }; | |
392 | ||
393 | static const NLTypeSystem rtnl_link_info_type_system = { | |
c1df8dee | 394 | .count = ELEMENTSOF(rtnl_link_info_types), |
d8e538ec TG |
395 | .types = rtnl_link_info_types, |
396 | }; | |
397 | ||
8ae4b6d1 | 398 | static const struct NLType rtnl_prot_info_bridge_port_types[] = { |
cafbc790 DH |
399 | [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 }, |
400 | [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 }, | |
401 | [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
402 | [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 }, | |
403 | [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 }, | |
404 | [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 }, | |
0c1f248e | 405 | [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 }, |
cafbc790 DH |
406 | [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 }, |
407 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
0c1f248e SS |
408 | [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 }, |
409 | [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 }, | |
d0159fdc SS |
410 | }; |
411 | ||
8ae4b6d1 | 412 | static const NLTypeSystem rtnl_prot_info_type_systems[] = { |
c1df8dee | 413 | [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types), |
4af7b60d TG |
414 | .types = rtnl_prot_info_bridge_port_types }, |
415 | }; | |
416 | ||
417 | static const NLTypeSystemUnion rtnl_prot_info_type_system_union = { | |
418 | .num = AF_MAX, | |
419 | .type_systems = rtnl_prot_info_type_systems, | |
420 | .match_type = NL_MATCH_PROTOCOL, | |
d0159fdc SS |
421 | }; |
422 | ||
8ae4b6d1 | 423 | static const struct NLType rtnl_af_spec_inet6_types[] = { |
cafbc790 | 424 | [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
c149ae08 TG |
425 | /* |
426 | IFLA_INET6_CONF, | |
427 | IFLA_INET6_STATS, | |
428 | IFLA_INET6_MCAST, | |
429 | IFLA_INET6_CACHEINFO, | |
430 | IFLA_INET6_ICMP6STATS, | |
431 | */ | |
cafbc790 DH |
432 | [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR }, |
433 | [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 }, | |
c149ae08 TG |
434 | }; |
435 | ||
73cb1c14 | 436 | static const NLTypeSystem rtnl_af_spec_inet6_type_system = { |
c1df8dee | 437 | .count = ELEMENTSOF(rtnl_af_spec_inet6_types), |
73cb1c14 | 438 | .types = rtnl_af_spec_inet6_types, |
c149ae08 TG |
439 | }; |
440 | ||
8ae4b6d1 | 441 | static const NLType rtnl_af_spec_types[] = { |
cafbc790 | 442 | [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system }, |
73cb1c14 TG |
443 | }; |
444 | ||
445 | static const NLTypeSystem rtnl_af_spec_type_system = { | |
c1df8dee | 446 | .count = ELEMENTSOF(rtnl_af_spec_types), |
73cb1c14 | 447 | .types = rtnl_af_spec_types, |
c149ae08 TG |
448 | }; |
449 | ||
8ae4b6d1 | 450 | static const NLType rtnl_link_types[] = { |
6e74cade ZJS |
451 | [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR }, |
452 | [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
453 | [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
cafbc790 DH |
454 | [IFLA_MTU] = { .type = NETLINK_TYPE_U32 }, |
455 | [IFLA_LINK] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
456 | /* |
457 | [IFLA_QDISC], | |
458 | [IFLA_STATS], | |
459 | [IFLA_COST], | |
460 | [IFLA_PRIORITY], | |
461 | */ | |
cafbc790 | 462 | [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
463 | /* |
464 | [IFLA_WIRELESS], | |
d8e538ec | 465 | */ |
cafbc790 DH |
466 | [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union }, |
467 | [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
468 | /* |
469 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, | |
470 | */ | |
cafbc790 DH |
471 | [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 }, |
472 | [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 }, | |
473 | [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 }, | |
474 | [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system }, | |
475 | [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 }, | |
476 | [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 }, | |
d8e538ec TG |
477 | /* |
478 | [IFLA_NUM_VF], | |
cafbc790 | 479 | [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, }, |
d8e538ec | 480 | [IFLA_STATS64], |
cafbc790 DH |
481 | [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED }, |
482 | [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED }, | |
c149ae08 | 483 | */ |
cafbc790 | 484 | [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system }, |
c149ae08 | 485 | /* |
d8e538ec TG |
486 | [IFLA_VF_PORTS], |
487 | [IFLA_PORT_SELF], | |
488 | [IFLA_AF_SPEC], | |
489 | */ | |
cafbc790 DH |
490 | [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 }, |
491 | [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 }, | |
492 | [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 }, | |
493 | [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 }, | |
494 | [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
495 | [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
496 | [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
d8e538ec | 497 | /* |
cafbc790 | 498 | [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN }, |
d8e538ec TG |
499 | */ |
500 | }; | |
501 | ||
502 | static const NLTypeSystem rtnl_link_type_system = { | |
c1df8dee | 503 | .count = ELEMENTSOF(rtnl_link_types), |
d8e538ec TG |
504 | .types = rtnl_link_types, |
505 | }; | |
506 | ||
de79f906 LP |
507 | /* IFA_FLAGS was defined in kernel 3.14, but we still support older |
508 | * kernels where IFA_MAX is lower. */ | |
8ae4b6d1 | 509 | static const NLType rtnl_address_types[] = { |
cafbc790 DH |
510 | [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR }, |
511 | [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
512 | [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
513 | [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
514 | [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) }, | |
d8e538ec TG |
515 | /* |
516 | [IFA_ANYCAST], | |
d8e538ec TG |
517 | [IFA_MULTICAST], |
518 | */ | |
cafbc790 | 519 | [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
520 | }; |
521 | ||
522 | static const NLTypeSystem rtnl_address_type_system = { | |
c1df8dee | 523 | .count = ELEMENTSOF(rtnl_address_types), |
d8e538ec TG |
524 | .types = rtnl_address_types, |
525 | }; | |
526 | ||
d6fceaf1 SS |
527 | /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */ |
528 | ||
529 | static const NLType rtnl_route_metrics_types[] = { | |
530 | [RTAX_MTU] = { .type = NETLINK_TYPE_U32 }, | |
531 | [RTAX_WINDOW] = { .type = NETLINK_TYPE_U32 }, | |
532 | [RTAX_RTT] = { .type = NETLINK_TYPE_U32 }, | |
533 | [RTAX_RTTVAR] = { .type = NETLINK_TYPE_U32 }, | |
534 | [RTAX_SSTHRESH] = { .type = NETLINK_TYPE_U32 }, | |
535 | [RTAX_CWND] = { .type = NETLINK_TYPE_U32 }, | |
536 | [RTAX_ADVMSS] = { .type = NETLINK_TYPE_U32 }, | |
537 | [RTAX_REORDERING] = { .type = NETLINK_TYPE_U32 }, | |
538 | [RTAX_HOPLIMIT] = { .type = NETLINK_TYPE_U32 }, | |
539 | [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 }, | |
540 | [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 }, | |
541 | [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 }, | |
542 | }; | |
543 | ||
544 | static const NLTypeSystem rtnl_route_metrics_type_system = { | |
545 | .count = ELEMENTSOF(rtnl_route_metrics_types), | |
546 | .types = rtnl_route_metrics_types, | |
547 | }; | |
548 | ||
8ae4b6d1 | 549 | static const NLType rtnl_route_types[] = { |
cafbc790 DH |
550 | [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ |
551 | [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
552 | [RTA_IIF] = { .type = NETLINK_TYPE_U32 }, | |
553 | [RTA_OIF] = { .type = NETLINK_TYPE_U32 }, | |
554 | [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR }, | |
555 | [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, | |
556 | [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
d6fceaf1 SS |
557 | [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_metrics_type_system}, |
558 | /* [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, | |
d8e538ec | 559 | */ |
cafbc790 | 560 | [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */ |
d8e538ec TG |
561 | /* |
562 | RTA_CACHEINFO, | |
563 | RTA_TABLE, | |
564 | RTA_MARK, | |
565 | RTA_MFC_STATS, | |
b69015ef TG |
566 | RTA_VIA, |
567 | RTA_NEWDST, | |
d8e538ec | 568 | */ |
b69015ef TG |
569 | [RTA_PREF] = { .type = NETLINK_TYPE_U8 }, |
570 | ||
d8e538ec TG |
571 | }; |
572 | ||
573 | static const NLTypeSystem rtnl_route_type_system = { | |
c1df8dee | 574 | .count = ELEMENTSOF(rtnl_route_types), |
d8e538ec TG |
575 | .types = rtnl_route_types, |
576 | }; | |
577 | ||
8ae4b6d1 | 578 | static const NLType rtnl_neigh_types[] = { |
cafbc790 DH |
579 | [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, |
580 | [NDA_LLADDR] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
581 | [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) }, | |
582 | [NDA_PROBES] = { .type = NETLINK_TYPE_U32 }, | |
583 | [NDA_VLAN] = { .type = NETLINK_TYPE_U16 }, | |
584 | [NDA_PORT] = { .type = NETLINK_TYPE_U16 }, | |
585 | [NDA_VNI] = { .type = NETLINK_TYPE_U32 }, | |
586 | [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 }, | |
e559b384 TG |
587 | }; |
588 | ||
589 | static const NLTypeSystem rtnl_neigh_type_system = { | |
c1df8dee | 590 | .count = ELEMENTSOF(rtnl_neigh_types), |
e559b384 TG |
591 | .types = rtnl_neigh_types, |
592 | }; | |
593 | ||
30746d60 SS |
594 | static const NLType rtnl_addrlabel_types[] = { |
595 | [IFAL_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR, .size = sizeof(struct in6_addr) }, | |
596 | [IFAL_LABEL] = { .type = NETLINK_TYPE_U32 }, | |
597 | }; | |
598 | ||
599 | static const NLTypeSystem rtnl_addrlabel_type_system = { | |
600 | .count = ELEMENTSOF(rtnl_addrlabel_types), | |
601 | .types = rtnl_addrlabel_types, | |
602 | }; | |
603 | ||
bce67bbe SS |
604 | static const NLType rtnl_routing_policy_rule_types[] = { |
605 | [FRA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, | |
606 | [FRA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, | |
607 | [FRA_IIFNAME] = { .type = NETLINK_TYPE_STRING }, | |
608 | [RTA_OIF] = { .type = NETLINK_TYPE_U32 }, | |
609 | [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR }, | |
610 | [FRA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, | |
611 | [FRA_FWMARK] = { .type = NETLINK_TYPE_U32 }, | |
612 | [FRA_FLOW] = { .type = NETLINK_TYPE_U32 }, | |
613 | [FRA_TUN_ID] = { .type = NETLINK_TYPE_U32 }, | |
614 | [FRA_SUPPRESS_IFGROUP] = { .type = NETLINK_TYPE_U32 }, | |
615 | [FRA_SUPPRESS_PREFIXLEN] = { .type = NETLINK_TYPE_U32 }, | |
616 | [FRA_TABLE] = { .type = NETLINK_TYPE_U32 }, | |
617 | [FRA_FWMASK] = { .type = NETLINK_TYPE_U32 }, | |
618 | [FRA_OIFNAME] = { .type = NETLINK_TYPE_STRING }, | |
619 | [FRA_PAD] = { .type = NETLINK_TYPE_U32 }, | |
620 | [FRA_L3MDEV] = { .type = NETLINK_TYPE_U64 }, | |
621 | [FRA_UID_RANGE] = { .size = sizeof(struct fib_rule_uid_range) }, | |
622 | }; | |
623 | ||
624 | static const NLTypeSystem rtnl_routing_policy_rule_type_system = { | |
625 | .count = ELEMENTSOF(rtnl_routing_policy_rule_types), | |
626 | .types = rtnl_routing_policy_rule_types, | |
627 | }; | |
628 | ||
8ae4b6d1 | 629 | static const NLType rtnl_types[] = { |
30746d60 SS |
630 | [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 }, |
631 | [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) }, | |
632 | [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
633 | [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
634 | [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
635 | [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
636 | [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
637 | [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
638 | [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
639 | [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
640 | [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
641 | [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
642 | [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
643 | [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
644 | [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
645 | [RTM_NEWADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
646 | [RTM_DELADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
647 | [RTM_GETADDRLABEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_addrlabel_type_system, .size = sizeof(struct ifaddrlblmsg) }, | |
bce67bbe SS |
648 | [RTM_NEWRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, |
649 | [RTM_DELRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, | |
650 | [RTM_GETRULE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_routing_policy_rule_type_system, .size = sizeof(struct rtmsg) }, | |
d8e538ec TG |
651 | }; |
652 | ||
846a6b3d | 653 | const NLTypeSystem type_system_root = { |
c1df8dee | 654 | .count = ELEMENTSOF(rtnl_types), |
d8e538ec TG |
655 | .types = rtnl_types, |
656 | }; | |
657 | ||
817d1cd8 DH |
658 | uint16_t type_get_type(const NLType *type) { |
659 | assert(type); | |
660 | return type->type; | |
661 | } | |
662 | ||
663 | size_t type_get_size(const NLType *type) { | |
664 | assert(type); | |
665 | return type->size; | |
666 | } | |
667 | ||
c658008f DH |
668 | void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { |
669 | assert(nl_type); | |
670 | assert(ret); | |
671 | assert(nl_type->type == NETLINK_TYPE_NESTED); | |
672 | assert(nl_type->type_system); | |
673 | ||
674 | *ret = nl_type->type_system; | |
675 | } | |
676 | ||
677 | void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { | |
678 | assert(nl_type); | |
679 | assert(ret); | |
680 | assert(nl_type->type == NETLINK_TYPE_UNION); | |
681 | assert(nl_type->type_system_union); | |
682 | ||
683 | *ret = nl_type->type_system_union; | |
684 | } | |
685 | ||
c1df8dee | 686 | uint16_t type_system_get_count(const NLTypeSystem *type_system) { |
435bbb02 | 687 | assert(type_system); |
c1df8dee | 688 | return type_system->count; |
435bbb02 DH |
689 | } |
690 | ||
d8e538ec TG |
691 | int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) { |
692 | const NLType *nl_type; | |
693 | ||
694 | assert(ret); | |
846a6b3d | 695 | assert(type_system); |
d8e538ec TG |
696 | assert(type_system->types); |
697 | ||
c1df8dee | 698 | if (type >= type_system->count) |
15411c0c | 699 | return -EOPNOTSUPP; |
d8e538ec TG |
700 | |
701 | nl_type = &type_system->types[type]; | |
702 | ||
cafbc790 | 703 | if (nl_type->type == NETLINK_TYPE_UNSPEC) |
15411c0c | 704 | return -EOPNOTSUPP; |
d8e538ec TG |
705 | |
706 | *ret = nl_type; | |
707 | ||
708 | return 0; | |
709 | } | |
710 | ||
711 | int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) { | |
712 | const NLType *nl_type; | |
713 | int r; | |
714 | ||
715 | assert(ret); | |
716 | ||
717 | r = type_system_get_type(type_system, &nl_type, type); | |
718 | if (r < 0) | |
719 | return r; | |
720 | ||
c658008f | 721 | type_get_type_system(nl_type, ret); |
d8e538ec TG |
722 | return 0; |
723 | } | |
724 | ||
725 | int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) { | |
726 | const NLType *nl_type; | |
727 | int r; | |
728 | ||
729 | assert(ret); | |
730 | ||
731 | r = type_system_get_type(type_system, &nl_type, type); | |
732 | if (r < 0) | |
733 | return r; | |
734 | ||
c658008f | 735 | type_get_type_system_union(nl_type, ret); |
d8e538ec TG |
736 | return 0; |
737 | } | |
738 | ||
739 | int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) { | |
740 | int type; | |
741 | ||
742 | assert(type_system_union); | |
f8a6ca1b | 743 | assert(type_system_union->match_type == NL_MATCH_SIBLING); |
d8e538ec TG |
744 | assert(type_system_union->lookup); |
745 | assert(type_system_union->type_systems); | |
746 | assert(ret); | |
747 | assert(key); | |
748 | ||
749 | type = type_system_union->lookup(key); | |
750 | if (type < 0) | |
15411c0c | 751 | return -EOPNOTSUPP; |
d8e538ec TG |
752 | |
753 | assert(type < type_system_union->num); | |
754 | ||
755 | *ret = &type_system_union->type_systems[type]; | |
756 | ||
757 | return 0; | |
758 | } | |
4af7b60d TG |
759 | |
760 | int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) { | |
761 | const NLTypeSystem *type_system; | |
762 | ||
763 | assert(type_system_union); | |
764 | assert(type_system_union->type_systems); | |
f8a6ca1b | 765 | assert(type_system_union->match_type == NL_MATCH_PROTOCOL); |
4af7b60d | 766 | assert(ret); |
4af7b60d TG |
767 | |
768 | if (protocol >= type_system_union->num) | |
15411c0c | 769 | return -EOPNOTSUPP; |
4af7b60d TG |
770 | |
771 | type_system = &type_system_union->type_systems[protocol]; | |
e7de105c | 772 | if (!type_system->types) |
15411c0c | 773 | return -EOPNOTSUPP; |
4af7b60d TG |
774 | |
775 | *ret = type_system; | |
776 | ||
777 | return 0; | |
778 | } |