]>
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> | |
e410b07d | 24 | #include <linux/in6.h> |
d8e538ec TG |
25 | #include <linux/veth.h> |
26 | #include <linux/if_bridge.h> | |
27 | #include <linux/if_addr.h> | |
28 | #include <linux/if.h> | |
0a827d10 | 29 | #include <linux/ip.h> |
c4a5ddc9 | 30 | #include <linux/if_link.h> |
0a827d10 SS |
31 | #include <linux/if_tunnel.h> |
32 | ||
d8e538ec | 33 | #include "macro.h" |
0830ba61 | 34 | #include "missing.h" |
8b43440b LP |
35 | #include "netlink-types.h" |
36 | #include "string-table.h" | |
37 | #include "util.h" | |
d8e538ec | 38 | |
dd906398 DH |
39 | /* Maximum ARP IP target defined in kernel */ |
40 | #define BOND_MAX_ARP_TARGETS 16 | |
41 | ||
42 | typedef enum { | |
43 | BOND_ARP_TARGETS_0, | |
44 | BOND_ARP_TARGETS_1, | |
45 | BOND_ARP_TARGETS_2, | |
46 | BOND_ARP_TARGETS_3, | |
47 | BOND_ARP_TARGETS_4, | |
48 | BOND_ARP_TARGETS_5, | |
49 | BOND_ARP_TARGETS_6, | |
50 | BOND_ARP_TARGETS_7, | |
51 | BOND_ARP_TARGETS_8, | |
52 | BOND_ARP_TARGETS_9, | |
53 | BOND_ARP_TARGETS_10, | |
54 | BOND_ARP_TARGETS_11, | |
55 | BOND_ARP_TARGETS_12, | |
56 | BOND_ARP_TARGETS_13, | |
57 | BOND_ARP_TARGETS_14, | |
58 | BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS, | |
59 | } BondArpTargets; | |
60 | ||
817d1cd8 DH |
61 | struct NLType { |
62 | uint16_t type; | |
63 | size_t size; | |
64 | const NLTypeSystem *type_system; | |
65 | const NLTypeSystemUnion *type_system_union; | |
66 | }; | |
67 | ||
435bbb02 | 68 | struct NLTypeSystem { |
c1df8dee | 69 | uint16_t count; |
435bbb02 DH |
70 | const NLType *types; |
71 | }; | |
72 | ||
d8e538ec TG |
73 | static const NLTypeSystem rtnl_link_type_system; |
74 | ||
979e7eb9 DH |
75 | static const NLType empty_types[1] = { |
76 | /* fake array to avoid .types==NULL, which denotes invalid type-systems */ | |
77 | }; | |
78 | ||
79 | static const NLTypeSystem empty_type_system = { | |
80 | .count = 0, | |
81 | .types = empty_types, | |
82 | }; | |
83 | ||
8ae4b6d1 | 84 | static const NLType rtnl_link_info_data_veth_types[] = { |
cafbc790 | 85 | [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, |
d8e538ec TG |
86 | }; |
87 | ||
8ae4b6d1 | 88 | static const NLType rtnl_link_info_data_ipvlan_types[] = { |
cafbc790 | 89 | [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 }, |
c4a5ddc9 | 90 | }; |
d8e538ec | 91 | |
8ae4b6d1 | 92 | static const NLType rtnl_link_info_data_macvlan_types[] = { |
cafbc790 DH |
93 | [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, |
94 | [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
d8e538ec TG |
95 | }; |
96 | ||
8ae4b6d1 | 97 | static const NLType rtnl_link_info_data_bridge_types[] = { |
3fef7a3f SS |
98 | [IFLA_BR_FORWARD_DELAY] = { .type = NETLINK_TYPE_U32 }, |
99 | [IFLA_BR_HELLO_TIME] = { .type = NETLINK_TYPE_U32 }, | |
100 | [IFLA_BR_MAX_AGE] = { .type = NETLINK_TYPE_U32 }, | |
101 | [IFLA_BR_AGEING_TIME] = { .type = NETLINK_TYPE_U32 }, | |
102 | [IFLA_BR_STP_STATE] = { .type = NETLINK_TYPE_U32 }, | |
103 | [IFLA_BR_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
104 | [IFLA_BR_VLAN_FILTERING] = { .type = NETLINK_TYPE_U8 }, | |
105 | [IFLA_BR_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, | |
106 | [IFLA_BR_GROUP_FWD_MASK] = { .type = NETLINK_TYPE_U16 }, | |
107 | [IFLA_BR_ROOT_PORT] = { .type = NETLINK_TYPE_U16 }, | |
108 | [IFLA_BR_ROOT_PATH_COST] = { .type = NETLINK_TYPE_U32 }, | |
109 | [IFLA_BR_TOPOLOGY_CHANGE] = { .type = NETLINK_TYPE_U8 }, | |
110 | [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = { .type = NETLINK_TYPE_U8 }, | |
111 | [IFLA_BR_HELLO_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
112 | [IFLA_BR_TCN_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
113 | [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = { .type = NETLINK_TYPE_U16 }, | |
114 | [IFLA_BR_GC_TIMER] = { .type = NETLINK_TYPE_U64 }, | |
115 | [IFLA_BR_GROUP_ADDR] = { .type = NETLINK_TYPE_U16 }, | |
116 | [IFLA_BR_FDB_FLUSH] = { .type = NETLINK_TYPE_U16 }, | |
117 | [IFLA_BR_MCAST_ROUTER] = { .type = NETLINK_TYPE_U8 }, | |
118 | [IFLA_BR_MCAST_SNOOPING] = { .type = NETLINK_TYPE_U8 }, | |
119 | [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NETLINK_TYPE_U8 }, | |
120 | [IFLA_BR_MCAST_QUERIER] = { .type = NETLINK_TYPE_U8 }, | |
121 | [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NETLINK_TYPE_U32 }, | |
122 | [IFLA_BR_MCAST_HASH_MAX] = { .type = NETLINK_TYPE_U16 }, | |
123 | [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NETLINK_TYPE_U32 }, | |
124 | [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NETLINK_TYPE_U16 }, | |
125 | [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
126 | [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
127 | [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
128 | [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
129 | [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
130 | [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NETLINK_TYPE_U64 }, | |
131 | [IFLA_BR_NF_CALL_IPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
132 | [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NETLINK_TYPE_U8 }, | |
133 | [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NETLINK_TYPE_U8 }, | |
134 | [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NETLINK_TYPE_U16 }, | |
ced671e1 SS |
135 | }; |
136 | ||
8ae4b6d1 | 137 | static const NLType rtnl_link_info_data_vlan_types[] = { |
cafbc790 | 138 | [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
139 | /* |
140 | [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) }, | |
cafbc790 DH |
141 | [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, |
142 | [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec | 143 | */ |
cafbc790 | 144 | [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, |
d8e538ec TG |
145 | }; |
146 | ||
8ae4b6d1 | 147 | static const NLType rtnl_link_info_data_vxlan_types[] = { |
452c9569 SS |
148 | [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 }, |
149 | [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR }, | |
150 | [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 }, | |
151 | [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_U32}, | |
152 | [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
153 | [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
154 | [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 }, | |
155 | [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 }, | |
156 | [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 }, | |
157 | [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32}, | |
158 | [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 }, | |
159 | [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 }, | |
160 | [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 }, | |
161 | [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 }, | |
162 | [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 }, | |
163 | [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
164 | [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR }, | |
165 | [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 }, | |
166 | [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 }, | |
167 | [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 }, | |
168 | [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 }, | |
169 | [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 }, | |
170 | [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG }, | |
171 | [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .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 }, | |
d8e538ec TG |
222 | }; |
223 | ||
8ae4b6d1 | 224 | static const NLType rtnl_link_info_data_iptun_types[] = { |
cafbc790 DH |
225 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
226 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
227 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
228 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
229 | [IFLA_IPTUN_TOS] = { .type = NETLINK_TYPE_U8 }, | |
230 | [IFLA_IPTUN_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
231 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
232 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
233 | [IFLA_IPTUN_6RD_PREFIX] = { .type = NETLINK_TYPE_IN_ADDR }, | |
234 | [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NETLINK_TYPE_U32 }, | |
235 | [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
236 | [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NETLINK_TYPE_U16 }, | |
6e74cade ZJS |
237 | [IFLA_IPTUN_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, |
238 | [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
239 | [IFLA_IPTUN_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
240 | [IFLA_IPTUN_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
0a827d10 SS |
241 | }; |
242 | ||
8ae4b6d1 | 243 | static const NLType rtnl_link_info_data_ipgre_types[] = { |
8aee0f1f SS |
244 | [IFLA_GRE_LINK] = { .type = NETLINK_TYPE_U32 }, |
245 | [IFLA_GRE_IFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
246 | [IFLA_GRE_OFLAGS] = { .type = NETLINK_TYPE_U16 }, | |
247 | [IFLA_GRE_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
248 | [IFLA_GRE_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
249 | [IFLA_GRE_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
250 | [IFLA_GRE_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
251 | [IFLA_GRE_TTL] = { .type = NETLINK_TYPE_U8 }, | |
252 | [IFLA_GRE_TOS] = { .type = NETLINK_TYPE_U8 }, | |
253 | [IFLA_GRE_PMTUDISC] = { .type = NETLINK_TYPE_U8 }, | |
254 | [IFLA_GRE_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, | |
255 | [IFLA_GRE_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
256 | [IFLA_GRE_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 }, | |
257 | [IFLA_GRE_ENCAP_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
258 | [IFLA_GRE_ENCAP_SPORT] = { .type = NETLINK_TYPE_U16 }, | |
259 | [IFLA_GRE_ENCAP_DPORT] = { .type = NETLINK_TYPE_U16 }, | |
8bb088c5 SS |
260 | }; |
261 | ||
8ae4b6d1 | 262 | static const NLType rtnl_link_info_data_ipvti_types[] = { |
cafbc790 DH |
263 | [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 }, |
264 | [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
265 | [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
6e74cade ZJS |
266 | [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
267 | [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
a613382b SS |
268 | }; |
269 | ||
8ae4b6d1 | 270 | static const NLType rtnl_link_info_data_ip6tnl_types[] = { |
cafbc790 DH |
271 | [IFLA_IPTUN_LINK] = { .type = NETLINK_TYPE_U32 }, |
272 | [IFLA_IPTUN_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
273 | [IFLA_IPTUN_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
274 | [IFLA_IPTUN_TTL] = { .type = NETLINK_TYPE_U8 }, | |
275 | [IFLA_IPTUN_FLAGS] = { .type = NETLINK_TYPE_U32 }, | |
276 | [IFLA_IPTUN_PROTO] = { .type = NETLINK_TYPE_U8 }, | |
277 | [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NETLINK_TYPE_U8 }, | |
6e74cade | 278 | [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, |
855ee1a1 SS |
279 | }; |
280 | ||
0a827d10 | 281 | /* these strings must match the .kind entries in the kernel */ |
8ae4b6d1 | 282 | static const char* const nl_union_link_info_data_table[] = { |
d8e538ec TG |
283 | [NL_UNION_LINK_INFO_DATA_BOND] = "bond", |
284 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge", | |
285 | [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan", | |
286 | [NL_UNION_LINK_INFO_DATA_VETH] = "veth", | |
9e358851 | 287 | [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy", |
d8e538ec | 288 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan", |
d1312575 | 289 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap", |
c4a5ddc9 | 290 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan", |
6ef81477 | 291 | [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan", |
0a827d10 | 292 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip", |
8bb088c5 | 293 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre", |
1af2536a | 294 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap", |
b16492f8 SS |
295 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre", |
296 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap", | |
0a827d10 | 297 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit", |
a613382b | 298 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti", |
9011ce77 | 299 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6", |
855ee1a1 | 300 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl", |
d8e538ec TG |
301 | }; |
302 | ||
303 | DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData); | |
304 | ||
8ae4b6d1 | 305 | static const NLTypeSystem rtnl_link_info_data_type_systems[] = { |
c1df8dee | 306 | [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types), |
0a827d10 | 307 | .types = rtnl_link_info_data_bond_types }, |
c1df8dee | 308 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types), |
0a827d10 | 309 | .types = rtnl_link_info_data_bridge_types }, |
c1df8dee | 310 | [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types), |
0a827d10 | 311 | .types = rtnl_link_info_data_vlan_types }, |
c1df8dee | 312 | [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types), |
0a827d10 | 313 | .types = rtnl_link_info_data_veth_types }, |
c1df8dee | 314 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), |
0a827d10 | 315 | .types = rtnl_link_info_data_macvlan_types }, |
d1312575 SS |
316 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), |
317 | .types = rtnl_link_info_data_macvlan_types }, | |
c1df8dee | 318 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), |
c4a5ddc9 | 319 | .types = rtnl_link_info_data_ipvlan_types }, |
c1df8dee | 320 | [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types), |
6ef81477 | 321 | .types = rtnl_link_info_data_vxlan_types }, |
c1df8dee | 322 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), |
0a827d10 | 323 | .types = rtnl_link_info_data_iptun_types }, |
c1df8dee | 324 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
8bb088c5 | 325 | .types = rtnl_link_info_data_ipgre_types }, |
c1df8dee | 326 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
1af2536a | 327 | .types = rtnl_link_info_data_ipgre_types }, |
c1df8dee | 328 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
b16492f8 | 329 | .types = rtnl_link_info_data_ipgre_types }, |
c1df8dee | 330 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
b16492f8 | 331 | .types = rtnl_link_info_data_ipgre_types }, |
c1df8dee | 332 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), |
0a827d10 | 333 | .types = rtnl_link_info_data_iptun_types }, |
c1df8dee | 334 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), |
a613382b | 335 | .types = rtnl_link_info_data_ipvti_types }, |
c1df8dee | 336 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), |
9011ce77 | 337 | .types = rtnl_link_info_data_ipvti_types }, |
c1df8dee | 338 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types), |
855ee1a1 SS |
339 | .types = rtnl_link_info_data_ip6tnl_types }, |
340 | ||
d8e538ec TG |
341 | }; |
342 | ||
343 | static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = { | |
344 | .num = _NL_UNION_LINK_INFO_DATA_MAX, | |
345 | .lookup = nl_union_link_info_data_from_string, | |
346 | .type_systems = rtnl_link_info_data_type_systems, | |
4af7b60d | 347 | .match_type = NL_MATCH_SIBLING, |
d8e538ec TG |
348 | .match = IFLA_INFO_KIND, |
349 | }; | |
350 | ||
8ae4b6d1 | 351 | static const NLType rtnl_link_info_types[] = { |
cafbc790 DH |
352 | [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING }, |
353 | [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union}, | |
d8e538ec TG |
354 | /* |
355 | [IFLA_INFO_XSTATS], | |
cafbc790 DH |
356 | [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING }, |
357 | [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED }, | |
d8e538ec TG |
358 | */ |
359 | }; | |
360 | ||
361 | static const NLTypeSystem rtnl_link_info_type_system = { | |
c1df8dee | 362 | .count = ELEMENTSOF(rtnl_link_info_types), |
d8e538ec TG |
363 | .types = rtnl_link_info_types, |
364 | }; | |
365 | ||
8ae4b6d1 | 366 | static const struct NLType rtnl_prot_info_bridge_port_types[] = { |
cafbc790 DH |
367 | [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 }, |
368 | [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 }, | |
369 | [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
370 | [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 }, | |
371 | [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 }, | |
372 | [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 }, | |
0c1f248e | 373 | [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 }, |
cafbc790 DH |
374 | [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 }, |
375 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
0c1f248e SS |
376 | [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 }, |
377 | [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 }, | |
d0159fdc SS |
378 | }; |
379 | ||
8ae4b6d1 | 380 | static const NLTypeSystem rtnl_prot_info_type_systems[] = { |
c1df8dee | 381 | [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types), |
4af7b60d TG |
382 | .types = rtnl_prot_info_bridge_port_types }, |
383 | }; | |
384 | ||
385 | static const NLTypeSystemUnion rtnl_prot_info_type_system_union = { | |
386 | .num = AF_MAX, | |
387 | .type_systems = rtnl_prot_info_type_systems, | |
388 | .match_type = NL_MATCH_PROTOCOL, | |
d0159fdc SS |
389 | }; |
390 | ||
8ae4b6d1 | 391 | static const struct NLType rtnl_af_spec_inet6_types[] = { |
cafbc790 | 392 | [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
c149ae08 TG |
393 | /* |
394 | IFLA_INET6_CONF, | |
395 | IFLA_INET6_STATS, | |
396 | IFLA_INET6_MCAST, | |
397 | IFLA_INET6_CACHEINFO, | |
398 | IFLA_INET6_ICMP6STATS, | |
399 | */ | |
cafbc790 DH |
400 | [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR }, |
401 | [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 }, | |
c149ae08 TG |
402 | }; |
403 | ||
73cb1c14 | 404 | static const NLTypeSystem rtnl_af_spec_inet6_type_system = { |
c1df8dee | 405 | .count = ELEMENTSOF(rtnl_af_spec_inet6_types), |
73cb1c14 | 406 | .types = rtnl_af_spec_inet6_types, |
c149ae08 TG |
407 | }; |
408 | ||
8ae4b6d1 | 409 | static const NLType rtnl_af_spec_types[] = { |
cafbc790 | 410 | [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system }, |
73cb1c14 TG |
411 | }; |
412 | ||
413 | static const NLTypeSystem rtnl_af_spec_type_system = { | |
c1df8dee | 414 | .count = ELEMENTSOF(rtnl_af_spec_types), |
73cb1c14 | 415 | .types = rtnl_af_spec_types, |
c149ae08 TG |
416 | }; |
417 | ||
8ae4b6d1 | 418 | static const NLType rtnl_link_types[] = { |
6e74cade ZJS |
419 | [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR }, |
420 | [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
421 | [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
cafbc790 DH |
422 | [IFLA_MTU] = { .type = NETLINK_TYPE_U32 }, |
423 | [IFLA_LINK] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
424 | /* |
425 | [IFLA_QDISC], | |
426 | [IFLA_STATS], | |
427 | [IFLA_COST], | |
428 | [IFLA_PRIORITY], | |
429 | */ | |
cafbc790 | 430 | [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
431 | /* |
432 | [IFLA_WIRELESS], | |
d8e538ec | 433 | */ |
cafbc790 DH |
434 | [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union }, |
435 | [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 }, | |
d8e538ec TG |
436 | /* |
437 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, | |
438 | */ | |
cafbc790 DH |
439 | [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 }, |
440 | [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 }, | |
441 | [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 }, | |
442 | [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system }, | |
443 | [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 }, | |
444 | [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 }, | |
d8e538ec TG |
445 | /* |
446 | [IFLA_NUM_VF], | |
cafbc790 | 447 | [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, }, |
d8e538ec | 448 | [IFLA_STATS64], |
cafbc790 DH |
449 | [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED }, |
450 | [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED }, | |
c149ae08 | 451 | */ |
cafbc790 | 452 | [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system }, |
c149ae08 | 453 | /* |
d8e538ec TG |
454 | [IFLA_VF_PORTS], |
455 | [IFLA_PORT_SELF], | |
456 | [IFLA_AF_SPEC], | |
457 | */ | |
cafbc790 DH |
458 | [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 }, |
459 | [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 }, | |
460 | [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 }, | |
461 | [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 }, | |
462 | [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
463 | [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
464 | [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
d8e538ec | 465 | /* |
cafbc790 | 466 | [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN }, |
d8e538ec TG |
467 | */ |
468 | }; | |
469 | ||
470 | static const NLTypeSystem rtnl_link_type_system = { | |
c1df8dee | 471 | .count = ELEMENTSOF(rtnl_link_types), |
d8e538ec TG |
472 | .types = rtnl_link_types, |
473 | }; | |
474 | ||
de79f906 LP |
475 | /* IFA_FLAGS was defined in kernel 3.14, but we still support older |
476 | * kernels where IFA_MAX is lower. */ | |
8ae4b6d1 | 477 | static const NLType rtnl_address_types[] = { |
cafbc790 DH |
478 | [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR }, |
479 | [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
480 | [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
481 | [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
482 | [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) }, | |
d8e538ec TG |
483 | /* |
484 | [IFA_ANYCAST], | |
d8e538ec TG |
485 | [IFA_MULTICAST], |
486 | */ | |
cafbc790 | 487 | [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
d8e538ec TG |
488 | }; |
489 | ||
490 | static const NLTypeSystem rtnl_address_type_system = { | |
c1df8dee | 491 | .count = ELEMENTSOF(rtnl_address_types), |
d8e538ec TG |
492 | .types = rtnl_address_types, |
493 | }; | |
494 | ||
8ae4b6d1 | 495 | static const NLType rtnl_route_types[] = { |
cafbc790 DH |
496 | [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ |
497 | [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
498 | [RTA_IIF] = { .type = NETLINK_TYPE_U32 }, | |
499 | [RTA_OIF] = { .type = NETLINK_TYPE_U32 }, | |
500 | [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR }, | |
501 | [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, | |
502 | [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
d8e538ec | 503 | /* |
cafbc790 | 504 | [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED }, |
d8e538ec TG |
505 | [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, |
506 | */ | |
cafbc790 | 507 | [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */ |
d8e538ec TG |
508 | /* |
509 | RTA_CACHEINFO, | |
510 | RTA_TABLE, | |
511 | RTA_MARK, | |
512 | RTA_MFC_STATS, | |
b69015ef TG |
513 | RTA_VIA, |
514 | RTA_NEWDST, | |
d8e538ec | 515 | */ |
b69015ef TG |
516 | [RTA_PREF] = { .type = NETLINK_TYPE_U8 }, |
517 | ||
d8e538ec TG |
518 | }; |
519 | ||
520 | static const NLTypeSystem rtnl_route_type_system = { | |
c1df8dee | 521 | .count = ELEMENTSOF(rtnl_route_types), |
d8e538ec TG |
522 | .types = rtnl_route_types, |
523 | }; | |
524 | ||
8ae4b6d1 | 525 | static const NLType rtnl_neigh_types[] = { |
cafbc790 DH |
526 | [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, |
527 | [NDA_LLADDR] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
528 | [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) }, | |
529 | [NDA_PROBES] = { .type = NETLINK_TYPE_U32 }, | |
530 | [NDA_VLAN] = { .type = NETLINK_TYPE_U16 }, | |
531 | [NDA_PORT] = { .type = NETLINK_TYPE_U16 }, | |
532 | [NDA_VNI] = { .type = NETLINK_TYPE_U32 }, | |
533 | [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 }, | |
e559b384 TG |
534 | }; |
535 | ||
536 | static const NLTypeSystem rtnl_neigh_type_system = { | |
c1df8dee | 537 | .count = ELEMENTSOF(rtnl_neigh_types), |
e559b384 TG |
538 | .types = rtnl_neigh_types, |
539 | }; | |
540 | ||
8ae4b6d1 | 541 | static const NLType rtnl_types[] = { |
979e7eb9 DH |
542 | [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 }, |
543 | [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) }, | |
cafbc790 DH |
544 | [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, |
545 | [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
546 | [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
547 | [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
548 | [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
549 | [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
550 | [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
551 | [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
552 | [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
553 | [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
554 | [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
555 | [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
556 | [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
d8e538ec TG |
557 | }; |
558 | ||
846a6b3d | 559 | const NLTypeSystem type_system_root = { |
c1df8dee | 560 | .count = ELEMENTSOF(rtnl_types), |
d8e538ec TG |
561 | .types = rtnl_types, |
562 | }; | |
563 | ||
817d1cd8 DH |
564 | uint16_t type_get_type(const NLType *type) { |
565 | assert(type); | |
566 | return type->type; | |
567 | } | |
568 | ||
569 | size_t type_get_size(const NLType *type) { | |
570 | assert(type); | |
571 | return type->size; | |
572 | } | |
573 | ||
c658008f DH |
574 | void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { |
575 | assert(nl_type); | |
576 | assert(ret); | |
577 | assert(nl_type->type == NETLINK_TYPE_NESTED); | |
578 | assert(nl_type->type_system); | |
579 | ||
580 | *ret = nl_type->type_system; | |
581 | } | |
582 | ||
583 | void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { | |
584 | assert(nl_type); | |
585 | assert(ret); | |
586 | assert(nl_type->type == NETLINK_TYPE_UNION); | |
587 | assert(nl_type->type_system_union); | |
588 | ||
589 | *ret = nl_type->type_system_union; | |
590 | } | |
591 | ||
c1df8dee | 592 | uint16_t type_system_get_count(const NLTypeSystem *type_system) { |
435bbb02 | 593 | assert(type_system); |
c1df8dee | 594 | return type_system->count; |
435bbb02 DH |
595 | } |
596 | ||
d8e538ec TG |
597 | int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) { |
598 | const NLType *nl_type; | |
599 | ||
600 | assert(ret); | |
846a6b3d | 601 | assert(type_system); |
d8e538ec TG |
602 | assert(type_system->types); |
603 | ||
c1df8dee | 604 | if (type >= type_system->count) |
15411c0c | 605 | return -EOPNOTSUPP; |
d8e538ec TG |
606 | |
607 | nl_type = &type_system->types[type]; | |
608 | ||
cafbc790 | 609 | if (nl_type->type == NETLINK_TYPE_UNSPEC) |
15411c0c | 610 | return -EOPNOTSUPP; |
d8e538ec TG |
611 | |
612 | *ret = nl_type; | |
613 | ||
614 | return 0; | |
615 | } | |
616 | ||
617 | int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) { | |
618 | const NLType *nl_type; | |
619 | int r; | |
620 | ||
621 | assert(ret); | |
622 | ||
623 | r = type_system_get_type(type_system, &nl_type, type); | |
624 | if (r < 0) | |
625 | return r; | |
626 | ||
c658008f | 627 | type_get_type_system(nl_type, ret); |
d8e538ec TG |
628 | return 0; |
629 | } | |
630 | ||
631 | int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) { | |
632 | const NLType *nl_type; | |
633 | int r; | |
634 | ||
635 | assert(ret); | |
636 | ||
637 | r = type_system_get_type(type_system, &nl_type, type); | |
638 | if (r < 0) | |
639 | return r; | |
640 | ||
c658008f | 641 | type_get_type_system_union(nl_type, ret); |
d8e538ec TG |
642 | return 0; |
643 | } | |
644 | ||
645 | int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) { | |
646 | int type; | |
647 | ||
648 | assert(type_system_union); | |
f8a6ca1b | 649 | assert(type_system_union->match_type == NL_MATCH_SIBLING); |
d8e538ec TG |
650 | assert(type_system_union->lookup); |
651 | assert(type_system_union->type_systems); | |
652 | assert(ret); | |
653 | assert(key); | |
654 | ||
655 | type = type_system_union->lookup(key); | |
656 | if (type < 0) | |
15411c0c | 657 | return -EOPNOTSUPP; |
d8e538ec TG |
658 | |
659 | assert(type < type_system_union->num); | |
660 | ||
661 | *ret = &type_system_union->type_systems[type]; | |
662 | ||
663 | return 0; | |
664 | } | |
4af7b60d TG |
665 | |
666 | int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) { | |
667 | const NLTypeSystem *type_system; | |
668 | ||
669 | assert(type_system_union); | |
670 | assert(type_system_union->type_systems); | |
f8a6ca1b | 671 | assert(type_system_union->match_type == NL_MATCH_PROTOCOL); |
4af7b60d | 672 | assert(ret); |
4af7b60d TG |
673 | |
674 | if (protocol >= type_system_union->num) | |
15411c0c | 675 | return -EOPNOTSUPP; |
4af7b60d TG |
676 | |
677 | type_system = &type_system_union->type_systems[protocol]; | |
e7de105c | 678 | if (!type_system->types) |
15411c0c | 679 | return -EOPNOTSUPP; |
4af7b60d TG |
680 | |
681 | *ret = type_system; | |
682 | ||
683 | return 0; | |
684 | } |