]>
Commit | Line | Data |
---|---|---|
60f067b4 JS |
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 | ||
60f067b4 JS |
20 | #include <stdint.h> |
21 | #include <sys/socket.h> | |
22 | #include <linux/netlink.h> | |
23 | #include <linux/rtnetlink.h> | |
24 | #include <linux/in6.h> | |
25 | #include <linux/veth.h> | |
26 | #include <linux/if_bridge.h> | |
27 | #include <linux/if_addr.h> | |
28 | #include <linux/if.h> | |
60f067b4 | 29 | #include <linux/ip.h> |
e735f4d4 | 30 | #include <linux/if_link.h> |
60f067b4 JS |
31 | #include <linux/if_tunnel.h> |
32 | ||
33 | #include "macro.h" | |
60f067b4 | 34 | #include "missing.h" |
db2df898 MP |
35 | #include "netlink-types.h" |
36 | #include "string-table.h" | |
37 | #include "util.h" | |
60f067b4 | 38 | |
fb183854 MP |
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 | ||
61 | struct NLType { | |
62 | uint16_t type; | |
63 | size_t size; | |
64 | const NLTypeSystem *type_system; | |
65 | const NLTypeSystemUnion *type_system_union; | |
66 | }; | |
67 | ||
68 | struct NLTypeSystem { | |
69 | uint16_t count; | |
70 | const NLType *types; | |
71 | }; | |
72 | ||
60f067b4 JS |
73 | static const NLTypeSystem rtnl_link_type_system; |
74 | ||
fb183854 MP |
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 | ||
db2df898 | 84 | static const NLType rtnl_link_info_data_veth_types[] = { |
fb183854 | 85 | [VETH_INFO_PEER] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, |
60f067b4 JS |
86 | }; |
87 | ||
db2df898 | 88 | static const NLType rtnl_link_info_data_ipvlan_types[] = { |
fb183854 | 89 | [IFLA_IPVLAN_MODE] = { .type = NETLINK_TYPE_U16 }, |
e735f4d4 | 90 | }; |
60f067b4 | 91 | |
db2df898 | 92 | static const NLType rtnl_link_info_data_macvlan_types[] = { |
fb183854 MP |
93 | [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, |
94 | [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, | |
60f067b4 JS |
95 | }; |
96 | ||
db2df898 | 97 | static const NLType rtnl_link_info_data_bridge_types[] = { |
aa27b158 MP |
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 }, | |
6300502b MP |
135 | }; |
136 | ||
db2df898 | 137 | static const NLType rtnl_link_info_data_vlan_types[] = { |
fb183854 | 138 | [IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 }, |
60f067b4 JS |
139 | /* |
140 | [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) }, | |
fb183854 MP |
141 | [IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, |
142 | [IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED }, | |
60f067b4 | 143 | */ |
fb183854 | 144 | [IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 }, |
60f067b4 JS |
145 | }; |
146 | ||
db2df898 | 147 | static const NLType rtnl_link_info_data_vxlan_types[] = { |
5fd56512 MP |
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 }, | |
e842803a MB |
172 | }; |
173 | ||
db2df898 | 174 | static const NLType rtnl_bond_arp_target_types[] = { |
fb183854 MP |
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 }, | |
e3bff60a MP |
191 | }; |
192 | ||
193 | static const NLTypeSystem rtnl_bond_arp_type_system = { | |
fb183854 | 194 | .count = ELEMENTSOF(rtnl_bond_arp_target_types), |
e3bff60a MP |
195 | .types = rtnl_bond_arp_target_types, |
196 | }; | |
197 | ||
db2df898 | 198 | static const NLType rtnl_link_info_data_bond_types[] = { |
fb183854 MP |
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 }, | |
60f067b4 JS |
222 | }; |
223 | ||
db2df898 | 224 | static const NLType rtnl_link_info_data_iptun_types[] = { |
fb183854 MP |
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 }, | |
7035cd9e MP |
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 }, | |
60f067b4 JS |
241 | }; |
242 | ||
db2df898 | 243 | static const NLType rtnl_link_info_data_ipgre_types[] = { |
7035cd9e MP |
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 }, | |
60f067b4 JS |
260 | }; |
261 | ||
db2df898 | 262 | static const NLType rtnl_link_info_data_ipvti_types[] = { |
fb183854 MP |
263 | [IFLA_VTI_LINK] = { .type = NETLINK_TYPE_U32 }, |
264 | [IFLA_VTI_IKEY] = { .type = NETLINK_TYPE_U32 }, | |
265 | [IFLA_VTI_OKEY] = { .type = NETLINK_TYPE_U32 }, | |
7035cd9e MP |
266 | [IFLA_VTI_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, |
267 | [IFLA_VTI_REMOTE] = { .type = NETLINK_TYPE_IN_ADDR }, | |
60f067b4 JS |
268 | }; |
269 | ||
db2df898 | 270 | static const NLType rtnl_link_info_data_ip6tnl_types[] = { |
fb183854 MP |
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 }, | |
7035cd9e | 278 | [IFLA_IPTUN_FLOWINFO] = { .type = NETLINK_TYPE_U32 }, |
e735f4d4 MP |
279 | }; |
280 | ||
5a920b42 MP |
281 | static const NLType rtnl_link_info_data_vrf_types[] = { |
282 | [IFLA_VRF_TABLE] = { .type = NETLINK_TYPE_U32 }, | |
283 | }; | |
284 | ||
60f067b4 | 285 | /* these strings must match the .kind entries in the kernel */ |
db2df898 | 286 | static const char* const nl_union_link_info_data_table[] = { |
60f067b4 JS |
287 | [NL_UNION_LINK_INFO_DATA_BOND] = "bond", |
288 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge", | |
289 | [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan", | |
290 | [NL_UNION_LINK_INFO_DATA_VETH] = "veth", | |
e842803a | 291 | [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy", |
60f067b4 | 292 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan", |
7035cd9e | 293 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap", |
e735f4d4 | 294 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan", |
e842803a | 295 | [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan", |
60f067b4 JS |
296 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip", |
297 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre", | |
e735f4d4 MP |
298 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap", |
299 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre", | |
300 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap", | |
60f067b4 JS |
301 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit", |
302 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti", | |
e3bff60a | 303 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6", |
e735f4d4 | 304 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl", |
5a920b42 | 305 | [NL_UNION_LINK_INFO_DATA_VRF] = "vrf", |
60f067b4 JS |
306 | }; |
307 | ||
308 | DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData); | |
309 | ||
db2df898 | 310 | static const NLTypeSystem rtnl_link_info_data_type_systems[] = { |
fb183854 | 311 | [NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types), |
60f067b4 | 312 | .types = rtnl_link_info_data_bond_types }, |
fb183854 | 313 | [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types), |
60f067b4 | 314 | .types = rtnl_link_info_data_bridge_types }, |
fb183854 | 315 | [NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types), |
60f067b4 | 316 | .types = rtnl_link_info_data_vlan_types }, |
fb183854 | 317 | [NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types), |
60f067b4 | 318 | .types = rtnl_link_info_data_veth_types }, |
fb183854 | 319 | [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), |
60f067b4 | 320 | .types = rtnl_link_info_data_macvlan_types }, |
7035cd9e MP |
321 | [NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), |
322 | .types = rtnl_link_info_data_macvlan_types }, | |
fb183854 | 323 | [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), |
e735f4d4 | 324 | .types = rtnl_link_info_data_ipvlan_types }, |
fb183854 | 325 | [NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types), |
e842803a | 326 | .types = rtnl_link_info_data_vxlan_types }, |
fb183854 | 327 | [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), |
60f067b4 | 328 | .types = rtnl_link_info_data_iptun_types }, |
fb183854 | 329 | [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
60f067b4 | 330 | .types = rtnl_link_info_data_ipgre_types }, |
fb183854 | 331 | [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
e735f4d4 | 332 | .types = rtnl_link_info_data_ipgre_types }, |
fb183854 | 333 | [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
e735f4d4 | 334 | .types = rtnl_link_info_data_ipgre_types }, |
fb183854 | 335 | [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), |
e735f4d4 | 336 | .types = rtnl_link_info_data_ipgre_types }, |
fb183854 | 337 | [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), |
60f067b4 | 338 | .types = rtnl_link_info_data_iptun_types }, |
fb183854 | 339 | [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), |
60f067b4 | 340 | .types = rtnl_link_info_data_ipvti_types }, |
fb183854 | 341 | [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), |
e3bff60a | 342 | .types = rtnl_link_info_data_ipvti_types }, |
fb183854 | 343 | [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types), |
e735f4d4 MP |
344 | .types = rtnl_link_info_data_ip6tnl_types }, |
345 | ||
5a920b42 MP |
346 | [NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types), |
347 | .types = rtnl_link_info_data_vrf_types }, | |
348 | ||
60f067b4 JS |
349 | }; |
350 | ||
351 | static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = { | |
352 | .num = _NL_UNION_LINK_INFO_DATA_MAX, | |
353 | .lookup = nl_union_link_info_data_from_string, | |
354 | .type_systems = rtnl_link_info_data_type_systems, | |
e735f4d4 | 355 | .match_type = NL_MATCH_SIBLING, |
60f067b4 JS |
356 | .match = IFLA_INFO_KIND, |
357 | }; | |
358 | ||
db2df898 | 359 | static const NLType rtnl_link_info_types[] = { |
fb183854 MP |
360 | [IFLA_INFO_KIND] = { .type = NETLINK_TYPE_STRING }, |
361 | [IFLA_INFO_DATA] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_link_info_data_type_system_union}, | |
60f067b4 JS |
362 | /* |
363 | [IFLA_INFO_XSTATS], | |
fb183854 MP |
364 | [IFLA_INFO_SLAVE_KIND] = { .type = NETLINK_TYPE_STRING }, |
365 | [IFLA_INFO_SLAVE_DATA] = { .type = NETLINK_TYPE_NESTED }, | |
60f067b4 JS |
366 | */ |
367 | }; | |
368 | ||
369 | static const NLTypeSystem rtnl_link_info_type_system = { | |
fb183854 | 370 | .count = ELEMENTSOF(rtnl_link_info_types), |
60f067b4 JS |
371 | .types = rtnl_link_info_types, |
372 | }; | |
373 | ||
db2df898 | 374 | static const struct NLType rtnl_prot_info_bridge_port_types[] = { |
fb183854 MP |
375 | [IFLA_BRPORT_STATE] = { .type = NETLINK_TYPE_U8 }, |
376 | [IFLA_BRPORT_COST] = { .type = NETLINK_TYPE_U32 }, | |
377 | [IFLA_BRPORT_PRIORITY] = { .type = NETLINK_TYPE_U16 }, | |
378 | [IFLA_BRPORT_MODE] = { .type = NETLINK_TYPE_U8 }, | |
379 | [IFLA_BRPORT_GUARD] = { .type = NETLINK_TYPE_U8 }, | |
380 | [IFLA_BRPORT_PROTECT] = { .type = NETLINK_TYPE_U8 }, | |
7035cd9e | 381 | [IFLA_BRPORT_FAST_LEAVE] = { .type = NETLINK_TYPE_U8 }, |
fb183854 MP |
382 | [IFLA_BRPORT_LEARNING] = { .type = NETLINK_TYPE_U8 }, |
383 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NETLINK_TYPE_U8 }, | |
7035cd9e MP |
384 | [IFLA_BRPORT_PROXYARP] = { .type = NETLINK_TYPE_U8 }, |
385 | [IFLA_BRPORT_LEARNING_SYNC] = { .type = NETLINK_TYPE_U8 }, | |
f47781d8 MP |
386 | }; |
387 | ||
db2df898 | 388 | static const NLTypeSystem rtnl_prot_info_type_systems[] = { |
fb183854 | 389 | [AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types), |
e735f4d4 MP |
390 | .types = rtnl_prot_info_bridge_port_types }, |
391 | }; | |
392 | ||
393 | static const NLTypeSystemUnion rtnl_prot_info_type_system_union = { | |
394 | .num = AF_MAX, | |
395 | .type_systems = rtnl_prot_info_type_systems, | |
396 | .match_type = NL_MATCH_PROTOCOL, | |
397 | }; | |
398 | ||
db2df898 | 399 | static const struct NLType rtnl_af_spec_inet6_types[] = { |
fb183854 | 400 | [IFLA_INET6_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
e735f4d4 MP |
401 | /* |
402 | IFLA_INET6_CONF, | |
403 | IFLA_INET6_STATS, | |
404 | IFLA_INET6_MCAST, | |
405 | IFLA_INET6_CACHEINFO, | |
406 | IFLA_INET6_ICMP6STATS, | |
407 | */ | |
fb183854 MP |
408 | [IFLA_INET6_TOKEN] = { .type = NETLINK_TYPE_IN_ADDR }, |
409 | [IFLA_INET6_ADDR_GEN_MODE] = { .type = NETLINK_TYPE_U8 }, | |
e735f4d4 MP |
410 | }; |
411 | ||
412 | static const NLTypeSystem rtnl_af_spec_inet6_type_system = { | |
fb183854 | 413 | .count = ELEMENTSOF(rtnl_af_spec_inet6_types), |
e735f4d4 MP |
414 | .types = rtnl_af_spec_inet6_types, |
415 | }; | |
416 | ||
db2df898 | 417 | static const NLType rtnl_af_spec_types[] = { |
fb183854 | 418 | [AF_INET6] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_inet6_type_system }, |
e735f4d4 MP |
419 | }; |
420 | ||
421 | static const NLTypeSystem rtnl_af_spec_type_system = { | |
fb183854 | 422 | .count = ELEMENTSOF(rtnl_af_spec_types), |
e735f4d4 | 423 | .types = rtnl_af_spec_types, |
f47781d8 MP |
424 | }; |
425 | ||
db2df898 | 426 | static const NLType rtnl_link_types[] = { |
7035cd9e MP |
427 | [IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR }, |
428 | [IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
429 | [IFLA_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
fb183854 MP |
430 | [IFLA_MTU] = { .type = NETLINK_TYPE_U32 }, |
431 | [IFLA_LINK] = { .type = NETLINK_TYPE_U32 }, | |
60f067b4 JS |
432 | /* |
433 | [IFLA_QDISC], | |
434 | [IFLA_STATS], | |
435 | [IFLA_COST], | |
436 | [IFLA_PRIORITY], | |
437 | */ | |
fb183854 | 438 | [IFLA_MASTER] = { .type = NETLINK_TYPE_U32 }, |
60f067b4 JS |
439 | /* |
440 | [IFLA_WIRELESS], | |
60f067b4 | 441 | */ |
fb183854 MP |
442 | [IFLA_PROTINFO] = { .type = NETLINK_TYPE_UNION, .type_system_union = &rtnl_prot_info_type_system_union }, |
443 | [IFLA_TXQLEN] = { .type = NETLINK_TYPE_U32 }, | |
60f067b4 JS |
444 | /* |
445 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, | |
446 | */ | |
fb183854 MP |
447 | [IFLA_WEIGHT] = { .type = NETLINK_TYPE_U32 }, |
448 | [IFLA_OPERSTATE] = { .type = NETLINK_TYPE_U8 }, | |
449 | [IFLA_LINKMODE] = { .type = NETLINK_TYPE_U8 }, | |
450 | [IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system }, | |
451 | [IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 }, | |
452 | [IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 }, | |
60f067b4 JS |
453 | /* |
454 | [IFLA_NUM_VF], | |
fb183854 | 455 | [IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, }, |
60f067b4 | 456 | [IFLA_STATS64], |
fb183854 MP |
457 | [IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED }, |
458 | [IFLA_PORT_SELF] = { .type = NETLINK_TYPE_NESTED }, | |
e735f4d4 | 459 | */ |
fb183854 | 460 | [IFLA_AF_SPEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_af_spec_type_system }, |
e735f4d4 | 461 | /* |
60f067b4 JS |
462 | [IFLA_VF_PORTS], |
463 | [IFLA_PORT_SELF], | |
464 | [IFLA_AF_SPEC], | |
465 | */ | |
fb183854 MP |
466 | [IFLA_GROUP] = { .type = NETLINK_TYPE_U32 }, |
467 | [IFLA_NET_NS_FD] = { .type = NETLINK_TYPE_U32 }, | |
468 | [IFLA_EXT_MASK] = { .type = NETLINK_TYPE_U32 }, | |
469 | [IFLA_PROMISCUITY] = { .type = NETLINK_TYPE_U32 }, | |
470 | [IFLA_NUM_TX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
471 | [IFLA_NUM_RX_QUEUES] = { .type = NETLINK_TYPE_U32 }, | |
472 | [IFLA_CARRIER] = { .type = NETLINK_TYPE_U8 }, | |
60f067b4 | 473 | /* |
fb183854 | 474 | [IFLA_PHYS_PORT_ID] = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN }, |
60f067b4 JS |
475 | */ |
476 | }; | |
477 | ||
478 | static const NLTypeSystem rtnl_link_type_system = { | |
fb183854 | 479 | .count = ELEMENTSOF(rtnl_link_types), |
60f067b4 JS |
480 | .types = rtnl_link_types, |
481 | }; | |
482 | ||
e3bff60a MP |
483 | /* IFA_FLAGS was defined in kernel 3.14, but we still support older |
484 | * kernels where IFA_MAX is lower. */ | |
db2df898 | 485 | static const NLType rtnl_address_types[] = { |
fb183854 MP |
486 | [IFA_ADDRESS] = { .type = NETLINK_TYPE_IN_ADDR }, |
487 | [IFA_LOCAL] = { .type = NETLINK_TYPE_IN_ADDR }, | |
488 | [IFA_LABEL] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ - 1 }, | |
489 | [IFA_BROADCAST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
490 | [IFA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) }, | |
60f067b4 JS |
491 | /* |
492 | [IFA_ANYCAST], | |
493 | [IFA_MULTICAST], | |
494 | */ | |
fb183854 | 495 | [IFA_FLAGS] = { .type = NETLINK_TYPE_U32 }, |
60f067b4 JS |
496 | }; |
497 | ||
498 | static const NLTypeSystem rtnl_address_type_system = { | |
fb183854 | 499 | .count = ELEMENTSOF(rtnl_address_types), |
60f067b4 JS |
500 | .types = rtnl_address_types, |
501 | }; | |
502 | ||
db2df898 | 503 | static const NLType rtnl_route_types[] = { |
fb183854 MP |
504 | [RTA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ |
505 | [RTA_SRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
506 | [RTA_IIF] = { .type = NETLINK_TYPE_U32 }, | |
507 | [RTA_OIF] = { .type = NETLINK_TYPE_U32 }, | |
508 | [RTA_GATEWAY] = { .type = NETLINK_TYPE_IN_ADDR }, | |
509 | [RTA_PRIORITY] = { .type = NETLINK_TYPE_U32 }, | |
510 | [RTA_PREFSRC] = { .type = NETLINK_TYPE_IN_ADDR }, /* 6? */ | |
60f067b4 | 511 | /* |
fb183854 | 512 | [RTA_METRICS] = { .type = NETLINK_TYPE_NESTED }, |
60f067b4 JS |
513 | [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, |
514 | */ | |
fb183854 | 515 | [RTA_FLOW] = { .type = NETLINK_TYPE_U32 }, /* 6? */ |
60f067b4 JS |
516 | /* |
517 | RTA_CACHEINFO, | |
518 | RTA_TABLE, | |
519 | RTA_MARK, | |
520 | RTA_MFC_STATS, | |
db2df898 MP |
521 | RTA_VIA, |
522 | RTA_NEWDST, | |
60f067b4 | 523 | */ |
db2df898 MP |
524 | [RTA_PREF] = { .type = NETLINK_TYPE_U8 }, |
525 | ||
60f067b4 JS |
526 | }; |
527 | ||
528 | static const NLTypeSystem rtnl_route_type_system = { | |
fb183854 | 529 | .count = ELEMENTSOF(rtnl_route_types), |
60f067b4 JS |
530 | .types = rtnl_route_types, |
531 | }; | |
532 | ||
db2df898 | 533 | static const NLType rtnl_neigh_types[] = { |
fb183854 MP |
534 | [NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR }, |
535 | [NDA_LLADDR] = { .type = NETLINK_TYPE_ETHER_ADDR }, | |
536 | [NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) }, | |
537 | [NDA_PROBES] = { .type = NETLINK_TYPE_U32 }, | |
538 | [NDA_VLAN] = { .type = NETLINK_TYPE_U16 }, | |
539 | [NDA_PORT] = { .type = NETLINK_TYPE_U16 }, | |
540 | [NDA_VNI] = { .type = NETLINK_TYPE_U32 }, | |
541 | [NDA_IFINDEX] = { .type = NETLINK_TYPE_U32 }, | |
f47781d8 MP |
542 | }; |
543 | ||
544 | static const NLTypeSystem rtnl_neigh_type_system = { | |
fb183854 | 545 | .count = ELEMENTSOF(rtnl_neigh_types), |
f47781d8 MP |
546 | .types = rtnl_neigh_types, |
547 | }; | |
548 | ||
db2df898 | 549 | static const NLType rtnl_types[] = { |
fb183854 MP |
550 | [NLMSG_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = 0 }, |
551 | [NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) }, | |
552 | [RTM_NEWLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
553 | [RTM_DELLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
554 | [RTM_GETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
555 | [RTM_SETLINK] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, | |
556 | [RTM_NEWADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
557 | [RTM_DELADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
558 | [RTM_GETADDR] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) }, | |
559 | [RTM_NEWROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
560 | [RTM_DELROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
561 | [RTM_GETROUTE] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) }, | |
562 | [RTM_NEWNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
563 | [RTM_DELNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
564 | [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) }, | |
565 | }; | |
566 | ||
567 | const NLTypeSystem type_system_root = { | |
568 | .count = ELEMENTSOF(rtnl_types), | |
60f067b4 JS |
569 | .types = rtnl_types, |
570 | }; | |
571 | ||
fb183854 MP |
572 | uint16_t type_get_type(const NLType *type) { |
573 | assert(type); | |
574 | return type->type; | |
575 | } | |
60f067b4 | 576 | |
fb183854 MP |
577 | size_t type_get_size(const NLType *type) { |
578 | assert(type); | |
579 | return type->size; | |
580 | } | |
581 | ||
582 | void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { | |
583 | assert(nl_type); | |
60f067b4 | 584 | assert(ret); |
fb183854 MP |
585 | assert(nl_type->type == NETLINK_TYPE_NESTED); |
586 | assert(nl_type->type_system); | |
60f067b4 | 587 | |
fb183854 MP |
588 | *ret = nl_type->type_system; |
589 | } | |
60f067b4 | 590 | |
fb183854 MP |
591 | void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { |
592 | assert(nl_type); | |
593 | assert(ret); | |
594 | assert(nl_type->type == NETLINK_TYPE_UNION); | |
595 | assert(nl_type->type_system_union); | |
596 | ||
597 | *ret = nl_type->type_system_union; | |
598 | } | |
599 | ||
600 | uint16_t type_system_get_count(const NLTypeSystem *type_system) { | |
601 | assert(type_system); | |
602 | return type_system->count; | |
603 | } | |
604 | ||
605 | int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) { | |
606 | const NLType *nl_type; | |
607 | ||
608 | assert(ret); | |
609 | assert(type_system); | |
60f067b4 JS |
610 | assert(type_system->types); |
611 | ||
fb183854 | 612 | if (type >= type_system->count) |
e3bff60a | 613 | return -EOPNOTSUPP; |
60f067b4 JS |
614 | |
615 | nl_type = &type_system->types[type]; | |
616 | ||
fb183854 | 617 | if (nl_type->type == NETLINK_TYPE_UNSPEC) |
e3bff60a | 618 | return -EOPNOTSUPP; |
60f067b4 JS |
619 | |
620 | *ret = nl_type; | |
621 | ||
622 | return 0; | |
623 | } | |
624 | ||
625 | int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) { | |
626 | const NLType *nl_type; | |
627 | int r; | |
628 | ||
629 | assert(ret); | |
630 | ||
631 | r = type_system_get_type(type_system, &nl_type, type); | |
632 | if (r < 0) | |
633 | return r; | |
634 | ||
fb183854 | 635 | type_get_type_system(nl_type, ret); |
60f067b4 JS |
636 | return 0; |
637 | } | |
638 | ||
639 | int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) { | |
640 | const NLType *nl_type; | |
641 | int r; | |
642 | ||
643 | assert(ret); | |
644 | ||
645 | r = type_system_get_type(type_system, &nl_type, type); | |
646 | if (r < 0) | |
647 | return r; | |
648 | ||
fb183854 | 649 | type_get_type_system_union(nl_type, ret); |
60f067b4 JS |
650 | return 0; |
651 | } | |
652 | ||
653 | int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) { | |
654 | int type; | |
655 | ||
656 | assert(type_system_union); | |
e3bff60a | 657 | assert(type_system_union->match_type == NL_MATCH_SIBLING); |
60f067b4 JS |
658 | assert(type_system_union->lookup); |
659 | assert(type_system_union->type_systems); | |
660 | assert(ret); | |
661 | assert(key); | |
662 | ||
663 | type = type_system_union->lookup(key); | |
664 | if (type < 0) | |
e3bff60a | 665 | return -EOPNOTSUPP; |
60f067b4 JS |
666 | |
667 | assert(type < type_system_union->num); | |
668 | ||
669 | *ret = &type_system_union->type_systems[type]; | |
670 | ||
671 | return 0; | |
672 | } | |
e735f4d4 MP |
673 | |
674 | int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) { | |
675 | const NLTypeSystem *type_system; | |
676 | ||
677 | assert(type_system_union); | |
678 | assert(type_system_union->type_systems); | |
e3bff60a | 679 | assert(type_system_union->match_type == NL_MATCH_PROTOCOL); |
e735f4d4 | 680 | assert(ret); |
e735f4d4 MP |
681 | |
682 | if (protocol >= type_system_union->num) | |
e3bff60a | 683 | return -EOPNOTSUPP; |
e735f4d4 MP |
684 | |
685 | type_system = &type_system_union->type_systems[protocol]; | |
fb183854 | 686 | if (!type_system->types) |
e3bff60a | 687 | return -EOPNOTSUPP; |
e735f4d4 MP |
688 | |
689 | *ret = type_system; | |
690 | ||
691 | return 0; | |
692 | } |