diff options
author | David S. Miller <davem@davemloft.net> | 2018-02-04 16:46:58 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-02-04 16:46:58 -0500 |
commit | a6b88814ab541d386d793f6df260a3e4d5cccb11 (patch) | |
tree | a7c633be819bb450edab3beebd1a9a0cfba8bb72 /tools | |
parent | 35277995e17919ab838beae765f440674e8576eb (diff) | |
parent | 09c0656dfabd0b15e410eca67dc45cb14ec9c13a (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Alexei Starovoitov says:
====================
pull-request: bpf 2018-02-02
The following pull-request contains BPF updates for your *net* tree.
The main changes are:
1) support XDP attach in libbpf, from Eric.
2) minor fixes, from Daniel, Jakub, Yonghong, Alexei.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/include/uapi/linux/if_link.h | 943 | ||||
-rw-r--r-- | tools/include/uapi/linux/netlink.h | 251 | ||||
-rw-r--r-- | tools/lib/bpf/Build | 2 | ||||
-rw-r--r-- | tools/lib/bpf/Makefile | 6 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.c | 135 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 2 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.c | 4 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 6 | ||||
-rw-r--r-- | tools/lib/bpf/nlattr.c | 187 | ||||
-rw-r--r-- | tools/lib/bpf/nlattr.h | 72 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/.gitignore | 1 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/Makefile | 4 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 14 |
13 files changed, 1624 insertions, 3 deletions
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h new file mode 100644 index 000000000000..8616131e2c61 --- /dev/null +++ b/tools/include/uapi/linux/if_link.h | |||
@@ -0,0 +1,943 @@ | |||
1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
2 | #ifndef _UAPI_LINUX_IF_LINK_H | ||
3 | #define _UAPI_LINUX_IF_LINK_H | ||
4 | |||
5 | #include <linux/types.h> | ||
6 | #include <linux/netlink.h> | ||
7 | |||
8 | /* This struct should be in sync with struct rtnl_link_stats64 */ | ||
9 | struct rtnl_link_stats { | ||
10 | __u32 rx_packets; /* total packets received */ | ||
11 | __u32 tx_packets; /* total packets transmitted */ | ||
12 | __u32 rx_bytes; /* total bytes received */ | ||
13 | __u32 tx_bytes; /* total bytes transmitted */ | ||
14 | __u32 rx_errors; /* bad packets received */ | ||
15 | __u32 tx_errors; /* packet transmit problems */ | ||
16 | __u32 rx_dropped; /* no space in linux buffers */ | ||
17 | __u32 tx_dropped; /* no space available in linux */ | ||
18 | __u32 multicast; /* multicast packets received */ | ||
19 | __u32 collisions; | ||
20 | |||
21 | /* detailed rx_errors: */ | ||
22 | __u32 rx_length_errors; | ||
23 | __u32 rx_over_errors; /* receiver ring buff overflow */ | ||
24 | __u32 rx_crc_errors; /* recved pkt with crc error */ | ||
25 | __u32 rx_frame_errors; /* recv'd frame alignment error */ | ||
26 | __u32 rx_fifo_errors; /* recv'r fifo overrun */ | ||
27 | __u32 rx_missed_errors; /* receiver missed packet */ | ||
28 | |||
29 | /* detailed tx_errors */ | ||
30 | __u32 tx_aborted_errors; | ||
31 | __u32 tx_carrier_errors; | ||
32 | __u32 tx_fifo_errors; | ||
33 | __u32 tx_heartbeat_errors; | ||
34 | __u32 tx_window_errors; | ||
35 | |||
36 | /* for cslip etc */ | ||
37 | __u32 rx_compressed; | ||
38 | __u32 tx_compressed; | ||
39 | |||
40 | __u32 rx_nohandler; /* dropped, no handler found */ | ||
41 | }; | ||
42 | |||
43 | /* The main device statistics structure */ | ||
44 | struct rtnl_link_stats64 { | ||
45 | __u64 rx_packets; /* total packets received */ | ||
46 | __u64 tx_packets; /* total packets transmitted */ | ||
47 | __u64 rx_bytes; /* total bytes received */ | ||
48 | __u64 tx_bytes; /* total bytes transmitted */ | ||
49 | __u64 rx_errors; /* bad packets received */ | ||
50 | __u64 tx_errors; /* packet transmit problems */ | ||
51 | __u64 rx_dropped; /* no space in linux buffers */ | ||
52 | __u64 tx_dropped; /* no space available in linux */ | ||
53 | __u64 multicast; /* multicast packets received */ | ||
54 | __u64 collisions; | ||
55 | |||
56 | /* detailed rx_errors: */ | ||
57 | __u64 rx_length_errors; | ||
58 | __u64 rx_over_errors; /* receiver ring buff overflow */ | ||
59 | __u64 rx_crc_errors; /* recved pkt with crc error */ | ||
60 | __u64 rx_frame_errors; /* recv'd frame alignment error */ | ||
61 | __u64 rx_fifo_errors; /* recv'r fifo overrun */ | ||
62 | __u64 rx_missed_errors; /* receiver missed packet */ | ||
63 | |||
64 | /* detailed tx_errors */ | ||
65 | __u64 tx_aborted_errors; | ||
66 | __u64 tx_carrier_errors; | ||
67 | __u64 tx_fifo_errors; | ||
68 | __u64 tx_heartbeat_errors; | ||
69 | __u64 tx_window_errors; | ||
70 | |||
71 | /* for cslip etc */ | ||
72 | __u64 rx_compressed; | ||
73 | __u64 tx_compressed; | ||
74 | |||
75 | __u64 rx_nohandler; /* dropped, no handler found */ | ||
76 | }; | ||
77 | |||
78 | /* The struct should be in sync with struct ifmap */ | ||
79 | struct rtnl_link_ifmap { | ||
80 | __u64 mem_start; | ||
81 | __u64 mem_end; | ||
82 | __u64 base_addr; | ||
83 | __u16 irq; | ||
84 | __u8 dma; | ||
85 | __u8 port; | ||
86 | }; | ||
87 | |||
88 | /* | ||
89 | * IFLA_AF_SPEC | ||
90 | * Contains nested attributes for address family specific attributes. | ||
91 | * Each address family may create a attribute with the address family | ||
92 | * number as type and create its own attribute structure in it. | ||
93 | * | ||
94 | * Example: | ||
95 | * [IFLA_AF_SPEC] = { | ||
96 | * [AF_INET] = { | ||
97 | * [IFLA_INET_CONF] = ..., | ||
98 | * }, | ||
99 | * [AF_INET6] = { | ||
100 | * [IFLA_INET6_FLAGS] = ..., | ||
101 | * [IFLA_INET6_CONF] = ..., | ||
102 | * } | ||
103 | * } | ||
104 | */ | ||
105 | |||
106 | enum { | ||
107 | IFLA_UNSPEC, | ||
108 | IFLA_ADDRESS, | ||
109 | IFLA_BROADCAST, | ||
110 | IFLA_IFNAME, | ||
111 | IFLA_MTU, | ||
112 | IFLA_LINK, | ||
113 | IFLA_QDISC, | ||
114 | IFLA_STATS, | ||
115 | IFLA_COST, | ||
116 | #define IFLA_COST IFLA_COST | ||
117 | IFLA_PRIORITY, | ||
118 | #define IFLA_PRIORITY IFLA_PRIORITY | ||
119 | IFLA_MASTER, | ||
120 | #define IFLA_MASTER IFLA_MASTER | ||
121 | IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */ | ||
122 | #define IFLA_WIRELESS IFLA_WIRELESS | ||
123 | IFLA_PROTINFO, /* Protocol specific information for a link */ | ||
124 | #define IFLA_PROTINFO IFLA_PROTINFO | ||
125 | IFLA_TXQLEN, | ||
126 | #define IFLA_TXQLEN IFLA_TXQLEN | ||
127 | IFLA_MAP, | ||
128 | #define IFLA_MAP IFLA_MAP | ||
129 | IFLA_WEIGHT, | ||
130 | #define IFLA_WEIGHT IFLA_WEIGHT | ||
131 | IFLA_OPERSTATE, | ||
132 | IFLA_LINKMODE, | ||
133 | IFLA_LINKINFO, | ||
134 | #define IFLA_LINKINFO IFLA_LINKINFO | ||
135 | IFLA_NET_NS_PID, | ||
136 | IFLA_IFALIAS, | ||
137 | IFLA_NUM_VF, /* Number of VFs if device is SR-IOV PF */ | ||
138 | IFLA_VFINFO_LIST, | ||
139 | IFLA_STATS64, | ||
140 | IFLA_VF_PORTS, | ||
141 | IFLA_PORT_SELF, | ||
142 | IFLA_AF_SPEC, | ||
143 | IFLA_GROUP, /* Group the device belongs to */ | ||
144 | IFLA_NET_NS_FD, | ||
145 | IFLA_EXT_MASK, /* Extended info mask, VFs, etc */ | ||
146 | IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */ | ||
147 | #define IFLA_PROMISCUITY IFLA_PROMISCUITY | ||
148 | IFLA_NUM_TX_QUEUES, | ||
149 | IFLA_NUM_RX_QUEUES, | ||
150 | IFLA_CARRIER, | ||
151 | IFLA_PHYS_PORT_ID, | ||
152 | IFLA_CARRIER_CHANGES, | ||
153 | IFLA_PHYS_SWITCH_ID, | ||
154 | IFLA_LINK_NETNSID, | ||
155 | IFLA_PHYS_PORT_NAME, | ||
156 | IFLA_PROTO_DOWN, | ||
157 | IFLA_GSO_MAX_SEGS, | ||
158 | IFLA_GSO_MAX_SIZE, | ||
159 | IFLA_PAD, | ||
160 | IFLA_XDP, | ||
161 | IFLA_EVENT, | ||
162 | IFLA_NEW_NETNSID, | ||
163 | IFLA_IF_NETNSID, | ||
164 | IFLA_CARRIER_UP_COUNT, | ||
165 | IFLA_CARRIER_DOWN_COUNT, | ||
166 | __IFLA_MAX | ||
167 | }; | ||
168 | |||
169 | |||
170 | #define IFLA_MAX (__IFLA_MAX - 1) | ||
171 | |||
172 | /* backwards compatibility for userspace */ | ||
173 | #ifndef __KERNEL__ | ||
174 | #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg)))) | ||
175 | #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg)) | ||
176 | #endif | ||
177 | |||
178 | enum { | ||
179 | IFLA_INET_UNSPEC, | ||
180 | IFLA_INET_CONF, | ||
181 | __IFLA_INET_MAX, | ||
182 | }; | ||
183 | |||
184 | #define IFLA_INET_MAX (__IFLA_INET_MAX - 1) | ||
185 | |||
186 | /* ifi_flags. | ||
187 | |||
188 | IFF_* flags. | ||
189 | |||
190 | The only change is: | ||
191 | IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are | ||
192 | more not changeable by user. They describe link media | ||
193 | characteristics and set by device driver. | ||
194 | |||
195 | Comments: | ||
196 | - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid | ||
197 | - If neither of these three flags are set; | ||
198 | the interface is NBMA. | ||
199 | |||
200 | - IFF_MULTICAST does not mean anything special: | ||
201 | multicasts can be used on all not-NBMA links. | ||
202 | IFF_MULTICAST means that this media uses special encapsulation | ||
203 | for multicast frames. Apparently, all IFF_POINTOPOINT and | ||
204 | IFF_BROADCAST devices are able to use multicasts too. | ||
205 | */ | ||
206 | |||
207 | /* IFLA_LINK. | ||
208 | For usual devices it is equal ifi_index. | ||
209 | If it is a "virtual interface" (f.e. tunnel), ifi_link | ||
210 | can point to real physical interface (f.e. for bandwidth calculations), | ||
211 | or maybe 0, what means, that real media is unknown (usual | ||
212 | for IPIP tunnels, when route to endpoint is allowed to change) | ||
213 | */ | ||
214 | |||
215 | /* Subtype attributes for IFLA_PROTINFO */ | ||
216 | enum { | ||
217 | IFLA_INET6_UNSPEC, | ||
218 | IFLA_INET6_FLAGS, /* link flags */ | ||
219 | IFLA_INET6_CONF, /* sysctl parameters */ | ||
220 | IFLA_INET6_STATS, /* statistics */ | ||
221 | IFLA_INET6_MCAST, /* MC things. What of them? */ | ||
222 | IFLA_INET6_CACHEINFO, /* time values and max reasm size */ | ||
223 | IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */ | ||
224 | IFLA_INET6_TOKEN, /* device token */ | ||
225 | IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */ | ||
226 | __IFLA_INET6_MAX | ||
227 | }; | ||
228 | |||
229 | #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1) | ||
230 | |||
231 | enum in6_addr_gen_mode { | ||
232 | IN6_ADDR_GEN_MODE_EUI64, | ||
233 | IN6_ADDR_GEN_MODE_NONE, | ||
234 | IN6_ADDR_GEN_MODE_STABLE_PRIVACY, | ||
235 | IN6_ADDR_GEN_MODE_RANDOM, | ||
236 | }; | ||
237 | |||
238 | /* Bridge section */ | ||
239 | |||
240 | enum { | ||
241 | IFLA_BR_UNSPEC, | ||
242 | IFLA_BR_FORWARD_DELAY, | ||
243 | IFLA_BR_HELLO_TIME, | ||
244 | IFLA_BR_MAX_AGE, | ||
245 | IFLA_BR_AGEING_TIME, | ||
246 | IFLA_BR_STP_STATE, | ||
247 | IFLA_BR_PRIORITY, | ||
248 | IFLA_BR_VLAN_FILTERING, | ||
249 | IFLA_BR_VLAN_PROTOCOL, | ||
250 | IFLA_BR_GROUP_FWD_MASK, | ||
251 | IFLA_BR_ROOT_ID, | ||
252 | IFLA_BR_BRIDGE_ID, | ||
253 | IFLA_BR_ROOT_PORT, | ||
254 | IFLA_BR_ROOT_PATH_COST, | ||
255 | IFLA_BR_TOPOLOGY_CHANGE, | ||
256 | IFLA_BR_TOPOLOGY_CHANGE_DETECTED, | ||
257 | IFLA_BR_HELLO_TIMER, | ||
258 | IFLA_BR_TCN_TIMER, | ||
259 | IFLA_BR_TOPOLOGY_CHANGE_TIMER, | ||
260 | IFLA_BR_GC_TIMER, | ||
261 | IFLA_BR_GROUP_ADDR, | ||
262 | IFLA_BR_FDB_FLUSH, | ||
263 | IFLA_BR_MCAST_ROUTER, | ||
264 | IFLA_BR_MCAST_SNOOPING, | ||
265 | IFLA_BR_MCAST_QUERY_USE_IFADDR, | ||
266 | IFLA_BR_MCAST_QUERIER, | ||
267 | IFLA_BR_MCAST_HASH_ELASTICITY, | ||
268 | IFLA_BR_MCAST_HASH_MAX, | ||
269 | IFLA_BR_MCAST_LAST_MEMBER_CNT, | ||
270 | IFLA_BR_MCAST_STARTUP_QUERY_CNT, | ||
271 | IFLA_BR_MCAST_LAST_MEMBER_INTVL, | ||
272 | IFLA_BR_MCAST_MEMBERSHIP_INTVL, | ||
273 | IFLA_BR_MCAST_QUERIER_INTVL, | ||
274 | IFLA_BR_MCAST_QUERY_INTVL, | ||
275 | IFLA_BR_MCAST_QUERY_RESPONSE_INTVL, | ||
276 | IFLA_BR_MCAST_STARTUP_QUERY_INTVL, | ||
277 | IFLA_BR_NF_CALL_IPTABLES, | ||
278 | IFLA_BR_NF_CALL_IP6TABLES, | ||
279 | IFLA_BR_NF_CALL_ARPTABLES, | ||
280 | IFLA_BR_VLAN_DEFAULT_PVID, | ||
281 | IFLA_BR_PAD, | ||
282 | IFLA_BR_VLAN_STATS_ENABLED, | ||
283 | IFLA_BR_MCAST_STATS_ENABLED, | ||
284 | IFLA_BR_MCAST_IGMP_VERSION, | ||
285 | IFLA_BR_MCAST_MLD_VERSION, | ||
286 | __IFLA_BR_MAX, | ||
287 | }; | ||
288 | |||
289 | #define IFLA_BR_MAX (__IFLA_BR_MAX - 1) | ||
290 | |||
291 | struct ifla_bridge_id { | ||
292 | __u8 prio[2]; | ||
293 | __u8 addr[6]; /* ETH_ALEN */ | ||
294 | }; | ||
295 | |||
296 | enum { | ||
297 | BRIDGE_MODE_UNSPEC, | ||
298 | BRIDGE_MODE_HAIRPIN, | ||
299 | }; | ||
300 | |||
301 | enum { | ||
302 | IFLA_BRPORT_UNSPEC, | ||
303 | IFLA_BRPORT_STATE, /* Spanning tree state */ | ||
304 | IFLA_BRPORT_PRIORITY, /* " priority */ | ||
305 | IFLA_BRPORT_COST, /* " cost */ | ||
306 | IFLA_BRPORT_MODE, /* mode (hairpin) */ | ||
307 | IFLA_BRPORT_GUARD, /* bpdu guard */ | ||
308 | IFLA_BRPORT_PROTECT, /* root port protection */ | ||
309 | IFLA_BRPORT_FAST_LEAVE, /* multicast fast leave */ | ||
310 | IFLA_BRPORT_LEARNING, /* mac learning */ | ||
311 | IFLA_BRPORT_UNICAST_FLOOD, /* flood unicast traffic */ | ||
312 | IFLA_BRPORT_PROXYARP, /* proxy ARP */ | ||
313 | IFLA_BRPORT_LEARNING_SYNC, /* mac learning sync from device */ | ||
314 | IFLA_BRPORT_PROXYARP_WIFI, /* proxy ARP for Wi-Fi */ | ||
315 | IFLA_BRPORT_ROOT_ID, /* designated root */ | ||
316 | IFLA_BRPORT_BRIDGE_ID, /* designated bridge */ | ||
317 | IFLA_BRPORT_DESIGNATED_PORT, | ||
318 | IFLA_BRPORT_DESIGNATED_COST, | ||
319 | IFLA_BRPORT_ID, | ||
320 | IFLA_BRPORT_NO, | ||
321 | IFLA_BRPORT_TOPOLOGY_CHANGE_ACK, | ||
322 | IFLA_BRPORT_CONFIG_PENDING, | ||
323 | IFLA_BRPORT_MESSAGE_AGE_TIMER, | ||
324 | IFLA_BRPORT_FORWARD_DELAY_TIMER, | ||
325 | IFLA_BRPORT_HOLD_TIMER, | ||
326 | IFLA_BRPORT_FLUSH, | ||
327 | IFLA_BRPORT_MULTICAST_ROUTER, | ||
328 | IFLA_BRPORT_PAD, | ||
329 | IFLA_BRPORT_MCAST_FLOOD, | ||
330 | IFLA_BRPORT_MCAST_TO_UCAST, | ||
331 | IFLA_BRPORT_VLAN_TUNNEL, | ||
332 | IFLA_BRPORT_BCAST_FLOOD, | ||
333 | IFLA_BRPORT_GROUP_FWD_MASK, | ||
334 | IFLA_BRPORT_NEIGH_SUPPRESS, | ||
335 | __IFLA_BRPORT_MAX | ||
336 | }; | ||
337 | #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) | ||
338 | |||
339 | struct ifla_cacheinfo { | ||
340 | __u32 max_reasm_len; | ||
341 | __u32 tstamp; /* ipv6InterfaceTable updated timestamp */ | ||
342 | __u32 reachable_time; | ||
343 | __u32 retrans_time; | ||
344 | }; | ||
345 | |||
346 | enum { | ||
347 | IFLA_INFO_UNSPEC, | ||
348 | IFLA_INFO_KIND, | ||
349 | IFLA_INFO_DATA, | ||
350 | IFLA_INFO_XSTATS, | ||
351 | IFLA_INFO_SLAVE_KIND, | ||
352 | IFLA_INFO_SLAVE_DATA, | ||
353 | __IFLA_INFO_MAX, | ||
354 | }; | ||
355 | |||
356 | #define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1) | ||
357 | |||
358 | /* VLAN section */ | ||
359 | |||
360 | enum { | ||
361 | IFLA_VLAN_UNSPEC, | ||
362 | IFLA_VLAN_ID, | ||
363 | IFLA_VLAN_FLAGS, | ||
364 | IFLA_VLAN_EGRESS_QOS, | ||
365 | IFLA_VLAN_INGRESS_QOS, | ||
366 | IFLA_VLAN_PROTOCOL, | ||
367 | __IFLA_VLAN_MAX, | ||
368 | }; | ||
369 | |||
370 | #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1) | ||
371 | |||
372 | struct ifla_vlan_flags { | ||
373 | __u32 flags; | ||
374 | __u32 mask; | ||
375 | }; | ||
376 | |||
377 | enum { | ||
378 | IFLA_VLAN_QOS_UNSPEC, | ||
379 | IFLA_VLAN_QOS_MAPPING, | ||
380 | __IFLA_VLAN_QOS_MAX | ||
381 | }; | ||
382 | |||
383 | #define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1) | ||
384 | |||
385 | struct ifla_vlan_qos_mapping { | ||
386 | __u32 from; | ||
387 | __u32 to; | ||
388 | }; | ||
389 | |||
390 | /* MACVLAN section */ | ||
391 | enum { | ||
392 | IFLA_MACVLAN_UNSPEC, | ||
393 | IFLA_MACVLAN_MODE, | ||
394 | IFLA_MACVLAN_FLAGS, | ||
395 | IFLA_MACVLAN_MACADDR_MODE, | ||
396 | IFLA_MACVLAN_MACADDR, | ||
397 | IFLA_MACVLAN_MACADDR_DATA, | ||
398 | IFLA_MACVLAN_MACADDR_COUNT, | ||
399 | __IFLA_MACVLAN_MAX, | ||
400 | }; | ||
401 | |||
402 | #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1) | ||
403 | |||
404 | enum macvlan_mode { | ||
405 | MACVLAN_MODE_PRIVATE = 1, /* don't talk to other macvlans */ | ||
406 | MACVLAN_MODE_VEPA = 2, /* talk to other ports through ext bridge */ | ||
407 | MACVLAN_MODE_BRIDGE = 4, /* talk to bridge ports directly */ | ||
408 | MACVLAN_MODE_PASSTHRU = 8,/* take over the underlying device */ | ||
409 | MACVLAN_MODE_SOURCE = 16,/* use source MAC address list to assign */ | ||
410 | }; | ||
411 | |||
412 | enum macvlan_macaddr_mode { | ||
413 | MACVLAN_MACADDR_ADD, | ||
414 | MACVLAN_MACADDR_DEL, | ||
415 | MACVLAN_MACADDR_FLUSH, | ||
416 | MACVLAN_MACADDR_SET, | ||
417 | }; | ||
418 | |||
419 | #define MACVLAN_FLAG_NOPROMISC 1 | ||
420 | |||
421 | /* VRF section */ | ||
422 | enum { | ||
423 | IFLA_VRF_UNSPEC, | ||
424 | IFLA_VRF_TABLE, | ||
425 | __IFLA_VRF_MAX | ||
426 | }; | ||
427 | |||
428 | #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1) | ||
429 | |||
430 | enum { | ||
431 | IFLA_VRF_PORT_UNSPEC, | ||
432 | IFLA_VRF_PORT_TABLE, | ||
433 | __IFLA_VRF_PORT_MAX | ||
434 | }; | ||
435 | |||
436 | #define IFLA_VRF_PORT_MAX (__IFLA_VRF_PORT_MAX - 1) | ||
437 | |||
438 | /* MACSEC section */ | ||
439 | enum { | ||
440 | IFLA_MACSEC_UNSPEC, | ||
441 | IFLA_MACSEC_SCI, | ||
442 | IFLA_MACSEC_PORT, | ||
443 | IFLA_MACSEC_ICV_LEN, | ||
444 | IFLA_MACSEC_CIPHER_SUITE, | ||
445 | IFLA_MACSEC_WINDOW, | ||
446 | IFLA_MACSEC_ENCODING_SA, | ||
447 | IFLA_MACSEC_ENCRYPT, | ||
448 | IFLA_MACSEC_PROTECT, | ||
449 | IFLA_MACSEC_INC_SCI, | ||
450 | IFLA_MACSEC_ES, | ||
451 | IFLA_MACSEC_SCB, | ||
452 | IFLA_MACSEC_REPLAY_PROTECT, | ||
453 | IFLA_MACSEC_VALIDATION, | ||
454 | IFLA_MACSEC_PAD, | ||
455 | __IFLA_MACSEC_MAX, | ||
456 | }; | ||
457 | |||
458 | #define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1) | ||
459 | |||
460 | enum macsec_validation_type { | ||
461 | MACSEC_VALIDATE_DISABLED = 0, | ||
462 | MACSEC_VALIDATE_CHECK = 1, | ||
463 | MACSEC_VALIDATE_STRICT = 2, | ||
464 | __MACSEC_VALIDATE_END, | ||
465 | MACSEC_VALIDATE_MAX = __MACSEC_VALIDATE_END - 1, | ||
466 | }; | ||
467 | |||
468 | /* IPVLAN section */ | ||
469 | enum { | ||
470 | IFLA_IPVLAN_UNSPEC, | ||
471 | IFLA_IPVLAN_MODE, | ||
472 | IFLA_IPVLAN_FLAGS, | ||
473 | __IFLA_IPVLAN_MAX | ||
474 | }; | ||
475 | |||
476 | #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1) | ||
477 | |||
478 | enum ipvlan_mode { | ||
479 | IPVLAN_MODE_L2 = 0, | ||
480 | IPVLAN_MODE_L3, | ||
481 | IPVLAN_MODE_L3S, | ||
482 | IPVLAN_MODE_MAX | ||
483 | }; | ||
484 | |||
485 | #define IPVLAN_F_PRIVATE 0x01 | ||
486 | #define IPVLAN_F_VEPA 0x02 | ||
487 | |||
488 | /* VXLAN section */ | ||
489 | enum { | ||
490 | IFLA_VXLAN_UNSPEC, | ||
491 | IFLA_VXLAN_ID, | ||
492 | IFLA_VXLAN_GROUP, /* group or remote address */ | ||
493 | IFLA_VXLAN_LINK, | ||
494 | IFLA_VXLAN_LOCAL, | ||
495 | IFLA_VXLAN_TTL, | ||
496 | IFLA_VXLAN_TOS, | ||
497 | IFLA_VXLAN_LEARNING, | ||
498 | IFLA_VXLAN_AGEING, | ||
499 | IFLA_VXLAN_LIMIT, | ||
500 | IFLA_VXLAN_PORT_RANGE, /* source port */ | ||
501 | IFLA_VXLAN_PROXY, | ||
502 | IFLA_VXLAN_RSC, | ||
503 | IFLA_VXLAN_L2MISS, | ||
504 | IFLA_VXLAN_L3MISS, | ||
505 | IFLA_VXLAN_PORT, /* destination port */ | ||
506 | IFLA_VXLAN_GROUP6, | ||
507 | IFLA_VXLAN_LOCAL6, | ||
508 | IFLA_VXLAN_UDP_CSUM, | ||
509 | IFLA_VXLAN_UDP_ZERO_CSUM6_TX, | ||
510 | IFLA_VXLAN_UDP_ZERO_CSUM6_RX, | ||
511 | IFLA_VXLAN_REMCSUM_TX, | ||
512 | IFLA_VXLAN_REMCSUM_RX, | ||
513 | IFLA_VXLAN_GBP, | ||
514 | IFLA_VXLAN_REMCSUM_NOPARTIAL, | ||
515 | IFLA_VXLAN_COLLECT_METADATA, | ||
516 | IFLA_VXLAN_LABEL, | ||
517 | IFLA_VXLAN_GPE, | ||
518 | __IFLA_VXLAN_MAX | ||
519 | }; | ||
520 | #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) | ||
521 | |||
522 | struct ifla_vxlan_port_range { | ||
523 | __be16 low; | ||
524 | __be16 high; | ||
525 | }; | ||
526 | |||
527 | /* GENEVE section */ | ||
528 | enum { | ||
529 | IFLA_GENEVE_UNSPEC, | ||
530 | IFLA_GENEVE_ID, | ||
531 | IFLA_GENEVE_REMOTE, | ||
532 | IFLA_GENEVE_TTL, | ||
533 | IFLA_GENEVE_TOS, | ||
534 | IFLA_GENEVE_PORT, /* destination port */ | ||
535 | IFLA_GENEVE_COLLECT_METADATA, | ||
536 | IFLA_GENEVE_REMOTE6, | ||
537 | IFLA_GENEVE_UDP_CSUM, | ||
538 | IFLA_GENEVE_UDP_ZERO_CSUM6_TX, | ||
539 | IFLA_GENEVE_UDP_ZERO_CSUM6_RX, | ||
540 | IFLA_GENEVE_LABEL, | ||
541 | __IFLA_GENEVE_MAX | ||
542 | }; | ||
543 | #define IFLA_GENEVE_MAX (__IFLA_GENEVE_MAX - 1) | ||
544 | |||
545 | /* PPP section */ | ||
546 | enum { | ||
547 | IFLA_PPP_UNSPEC, | ||
548 | IFLA_PPP_DEV_FD, | ||
549 | __IFLA_PPP_MAX | ||
550 | }; | ||
551 | #define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1) | ||
552 | |||
553 | /* GTP section */ | ||
554 | |||
555 | enum ifla_gtp_role { | ||
556 | GTP_ROLE_GGSN = 0, | ||
557 | GTP_ROLE_SGSN, | ||
558 | }; | ||
559 | |||
560 | enum { | ||
561 | IFLA_GTP_UNSPEC, | ||
562 | IFLA_GTP_FD0, | ||
563 | IFLA_GTP_FD1, | ||
564 | IFLA_GTP_PDP_HASHSIZE, | ||
565 | IFLA_GTP_ROLE, | ||
566 | __IFLA_GTP_MAX, | ||
567 | }; | ||
568 | #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) | ||
569 | |||
570 | /* Bonding section */ | ||
571 | |||
572 | enum { | ||
573 | IFLA_BOND_UNSPEC, | ||
574 | IFLA_BOND_MODE, | ||
575 | IFLA_BOND_ACTIVE_SLAVE, | ||
576 | IFLA_BOND_MIIMON, | ||
577 | IFLA_BOND_UPDELAY, | ||
578 | IFLA_BOND_DOWNDELAY, | ||
579 | IFLA_BOND_USE_CARRIER, | ||
580 | IFLA_BOND_ARP_INTERVAL, | ||
581 | IFLA_BOND_ARP_IP_TARGET, | ||
582 | IFLA_BOND_ARP_VALIDATE, | ||
583 | IFLA_BOND_ARP_ALL_TARGETS, | ||
584 | IFLA_BOND_PRIMARY, | ||
585 | IFLA_BOND_PRIMARY_RESELECT, | ||
586 | IFLA_BOND_FAIL_OVER_MAC, | ||
587 | IFLA_BOND_XMIT_HASH_POLICY, | ||
588 | IFLA_BOND_RESEND_IGMP, | ||
589 | IFLA_BOND_NUM_PEER_NOTIF, | ||
590 | IFLA_BOND_ALL_SLAVES_ACTIVE, | ||
591 | IFLA_BOND_MIN_LINKS, | ||
592 | IFLA_BOND_LP_INTERVAL, | ||
593 | IFLA_BOND_PACKETS_PER_SLAVE, | ||
594 | IFLA_BOND_AD_LACP_RATE, | ||
595 | IFLA_BOND_AD_SELECT, | ||
596 | IFLA_BOND_AD_INFO, | ||
597 | IFLA_BOND_AD_ACTOR_SYS_PRIO, | ||
598 | IFLA_BOND_AD_USER_PORT_KEY, | ||
599 | IFLA_BOND_AD_ACTOR_SYSTEM, | ||
600 | IFLA_BOND_TLB_DYNAMIC_LB, | ||
601 | __IFLA_BOND_MAX, | ||
602 | }; | ||
603 | |||
604 | #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1) | ||
605 | |||
606 | enum { | ||
607 | IFLA_BOND_AD_INFO_UNSPEC, | ||
608 | IFLA_BOND_AD_INFO_AGGREGATOR, | ||
609 | IFLA_BOND_AD_INFO_NUM_PORTS, | ||
610 | IFLA_BOND_AD_INFO_ACTOR_KEY, | ||
611 | IFLA_BOND_AD_INFO_PARTNER_KEY, | ||
612 | IFLA_BOND_AD_INFO_PARTNER_MAC, | ||
613 | __IFLA_BOND_AD_INFO_MAX, | ||
614 | }; | ||
615 | |||
616 | #define IFLA_BOND_AD_INFO_MAX (__IFLA_BOND_AD_INFO_MAX - 1) | ||
617 | |||
618 | enum { | ||
619 | IFLA_BOND_SLAVE_UNSPEC, | ||
620 | IFLA_BOND_SLAVE_STATE, | ||
621 | IFLA_BOND_SLAVE_MII_STATUS, | ||
622 | IFLA_BOND_SLAVE_LINK_FAILURE_COUNT, | ||
623 | IFLA_BOND_SLAVE_PERM_HWADDR, | ||
624 | IFLA_BOND_SLAVE_QUEUE_ID, | ||
625 | IFLA_BOND_SLAVE_AD_AGGREGATOR_ID, | ||
626 | IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE, | ||
627 | IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE, | ||
628 | __IFLA_BOND_SLAVE_MAX, | ||
629 | }; | ||
630 | |||
631 | #define IFLA_BOND_SLAVE_MAX (__IFLA_BOND_SLAVE_MAX - 1) | ||
632 | |||
633 | /* SR-IOV virtual function management section */ | ||
634 | |||
635 | enum { | ||
636 | IFLA_VF_INFO_UNSPEC, | ||
637 | IFLA_VF_INFO, | ||
638 | __IFLA_VF_INFO_MAX, | ||
639 | }; | ||
640 | |||
641 | #define IFLA_VF_INFO_MAX (__IFLA_VF_INFO_MAX - 1) | ||
642 | |||
643 | enum { | ||
644 | IFLA_VF_UNSPEC, | ||
645 | IFLA_VF_MAC, /* Hardware queue specific attributes */ | ||
646 | IFLA_VF_VLAN, /* VLAN ID and QoS */ | ||
647 | IFLA_VF_TX_RATE, /* Max TX Bandwidth Allocation */ | ||
648 | IFLA_VF_SPOOFCHK, /* Spoof Checking on/off switch */ | ||
649 | IFLA_VF_LINK_STATE, /* link state enable/disable/auto switch */ | ||
650 | IFLA_VF_RATE, /* Min and Max TX Bandwidth Allocation */ | ||
651 | IFLA_VF_RSS_QUERY_EN, /* RSS Redirection Table and Hash Key query | ||
652 | * on/off switch | ||
653 | */ | ||
654 | IFLA_VF_STATS, /* network device statistics */ | ||
655 | IFLA_VF_TRUST, /* Trust VF */ | ||
656 | IFLA_VF_IB_NODE_GUID, /* VF Infiniband node GUID */ | ||
657 | IFLA_VF_IB_PORT_GUID, /* VF Infiniband port GUID */ | ||
658 | IFLA_VF_VLAN_LIST, /* nested list of vlans, option for QinQ */ | ||
659 | __IFLA_VF_MAX, | ||
660 | }; | ||
661 | |||
662 | #define IFLA_VF_MAX (__IFLA_VF_MAX - 1) | ||
663 | |||
664 | struct ifla_vf_mac { | ||
665 | __u32 vf; | ||
666 | __u8 mac[32]; /* MAX_ADDR_LEN */ | ||
667 | }; | ||
668 | |||
669 | struct ifla_vf_vlan { | ||
670 | __u32 vf; | ||
671 | __u32 vlan; /* 0 - 4095, 0 disables VLAN filter */ | ||
672 | __u32 qos; | ||
673 | }; | ||
674 | |||
675 | enum { | ||
676 | IFLA_VF_VLAN_INFO_UNSPEC, | ||
677 | IFLA_VF_VLAN_INFO, /* VLAN ID, QoS and VLAN protocol */ | ||
678 | __IFLA_VF_VLAN_INFO_MAX, | ||
679 | }; | ||
680 | |||
681 | #define IFLA_VF_VLAN_INFO_MAX (__IFLA_VF_VLAN_INFO_MAX - 1) | ||
682 | #define MAX_VLAN_LIST_LEN 1 | ||
683 | |||
684 | struct ifla_vf_vlan_info { | ||
685 | __u32 vf; | ||
686 | __u32 vlan; /* 0 - 4095, 0 disables VLAN filter */ | ||
687 | __u32 qos; | ||
688 | __be16 vlan_proto; /* VLAN protocol either 802.1Q or 802.1ad */ | ||
689 | }; | ||
690 | |||
691 | struct ifla_vf_tx_rate { | ||
692 | __u32 vf; | ||
693 | __u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */ | ||
694 | }; | ||
695 | |||
696 | struct ifla_vf_rate { | ||
697 | __u32 vf; | ||
698 | __u32 min_tx_rate; /* Min Bandwidth in Mbps */ | ||
699 | __u32 max_tx_rate; /* Max Bandwidth in Mbps */ | ||
700 | }; | ||
701 | |||
702 | struct ifla_vf_spoofchk { | ||
703 | __u32 vf; | ||
704 | __u32 setting; | ||
705 | }; | ||
706 | |||
707 | struct ifla_vf_guid { | ||
708 | __u32 vf; | ||
709 | __u64 guid; | ||
710 | }; | ||
711 | |||
712 | enum { | ||
713 | IFLA_VF_LINK_STATE_AUTO, /* link state of the uplink */ | ||
714 | IFLA_VF_LINK_STATE_ENABLE, /* link always up */ | ||
715 | IFLA_VF_LINK_STATE_DISABLE, /* link always down */ | ||
716 | __IFLA_VF_LINK_STATE_MAX, | ||
717 | }; | ||
718 | |||
719 | struct ifla_vf_link_state { | ||
720 | __u32 vf; | ||
721 | __u32 link_state; | ||
722 | }; | ||
723 | |||
724 | struct ifla_vf_rss_query_en { | ||
725 | __u32 vf; | ||
726 | __u32 setting; | ||
727 | }; | ||
728 | |||
729 | enum { | ||
730 | IFLA_VF_STATS_RX_PACKETS, | ||
731 | IFLA_VF_STATS_TX_PACKETS, | ||
732 | IFLA_VF_STATS_RX_BYTES, | ||
733 | IFLA_VF_STATS_TX_BYTES, | ||
734 | IFLA_VF_STATS_BROADCAST, | ||
735 | IFLA_VF_STATS_MULTICAST, | ||
736 | IFLA_VF_STATS_PAD, | ||
737 | IFLA_VF_STATS_RX_DROPPED, | ||
738 | IFLA_VF_STATS_TX_DROPPED, | ||
739 | __IFLA_VF_STATS_MAX, | ||
740 | }; | ||
741 | |||
742 | #define IFLA_VF_STATS_MAX (__IFLA_VF_STATS_MAX - 1) | ||
743 | |||
744 | struct ifla_vf_trust { | ||
745 | __u32 vf; | ||
746 | __u32 setting; | ||
747 | }; | ||
748 | |||
749 | /* VF ports management section | ||
750 | * | ||
751 | * Nested layout of set/get msg is: | ||
752 | * | ||
753 | * [IFLA_NUM_VF] | ||
754 | * [IFLA_VF_PORTS] | ||
755 | * [IFLA_VF_PORT] | ||
756 | * [IFLA_PORT_*], ... | ||
757 | * [IFLA_VF_PORT] | ||
758 | * [IFLA_PORT_*], ... | ||
759 | * ... | ||
760 | * [IFLA_PORT_SELF] | ||
761 | * [IFLA_PORT_*], ... | ||
762 | */ | ||
763 | |||
764 | enum { | ||
765 | IFLA_VF_PORT_UNSPEC, | ||
766 | IFLA_VF_PORT, /* nest */ | ||
767 | __IFLA_VF_PORT_MAX, | ||
768 | }; | ||
769 | |||
770 | #define IFLA_VF_PORT_MAX (__IFLA_VF_PORT_MAX - 1) | ||
771 | |||
772 | enum { | ||
773 | IFLA_PORT_UNSPEC, | ||
774 | IFLA_PORT_VF, /* __u32 */ | ||
775 | IFLA_PORT_PROFILE, /* string */ | ||
776 | IFLA_PORT_VSI_TYPE, /* 802.1Qbg (pre-)standard VDP */ | ||
777 | IFLA_PORT_INSTANCE_UUID, /* binary UUID */ | ||
778 | IFLA_PORT_HOST_UUID, /* binary UUID */ | ||
779 | IFLA_PORT_REQUEST, /* __u8 */ | ||
780 | IFLA_PORT_RESPONSE, /* __u16, output only */ | ||
781 | __IFLA_PORT_MAX, | ||
782 | }; | ||
783 | |||
784 | #define IFLA_PORT_MAX (__IFLA_PORT_MAX - 1) | ||
785 | |||
786 | #define PORT_PROFILE_MAX 40 | ||
787 | #define PORT_UUID_MAX 16 | ||
788 | #define PORT_SELF_VF -1 | ||
789 | |||
790 | enum { | ||
791 | PORT_REQUEST_PREASSOCIATE = 0, | ||
792 | PORT_REQUEST_PREASSOCIATE_RR, | ||
793 | PORT_REQUEST_ASSOCIATE, | ||
794 | PORT_REQUEST_DISASSOCIATE, | ||
795 | }; | ||
796 | |||
797 | enum { | ||
798 | PORT_VDP_RESPONSE_SUCCESS = 0, | ||
799 | PORT_VDP_RESPONSE_INVALID_FORMAT, | ||
800 | PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES, | ||
801 | PORT_VDP_RESPONSE_UNUSED_VTID, | ||
802 | PORT_VDP_RESPONSE_VTID_VIOLATION, | ||
803 | PORT_VDP_RESPONSE_VTID_VERSION_VIOALTION, | ||
804 | PORT_VDP_RESPONSE_OUT_OF_SYNC, | ||
805 | /* 0x08-0xFF reserved for future VDP use */ | ||
806 | PORT_PROFILE_RESPONSE_SUCCESS = 0x100, | ||
807 | PORT_PROFILE_RESPONSE_INPROGRESS, | ||
808 | PORT_PROFILE_RESPONSE_INVALID, | ||
809 | PORT_PROFILE_RESPONSE_BADSTATE, | ||
810 | PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES, | ||
811 | PORT_PROFILE_RESPONSE_ERROR, | ||
812 | }; | ||
813 | |||
814 | struct ifla_port_vsi { | ||
815 | __u8 vsi_mgr_id; | ||
816 | __u8 vsi_type_id[3]; | ||
817 | __u8 vsi_type_version; | ||
818 | __u8 pad[3]; | ||
819 | }; | ||
820 | |||
821 | |||
822 | /* IPoIB section */ | ||
823 | |||
824 | enum { | ||
825 | IFLA_IPOIB_UNSPEC, | ||
826 | IFLA_IPOIB_PKEY, | ||
827 | IFLA_IPOIB_MODE, | ||
828 | IFLA_IPOIB_UMCAST, | ||
829 | __IFLA_IPOIB_MAX | ||
830 | }; | ||
831 | |||
832 | enum { | ||
833 | IPOIB_MODE_DATAGRAM = 0, /* using unreliable datagram QPs */ | ||
834 | IPOIB_MODE_CONNECTED = 1, /* using connected QPs */ | ||
835 | }; | ||
836 | |||
837 | #define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1) | ||
838 | |||
839 | |||
840 | /* HSR section */ | ||
841 | |||
842 | enum { | ||
843 | IFLA_HSR_UNSPEC, | ||
844 | IFLA_HSR_SLAVE1, | ||
845 | IFLA_HSR_SLAVE2, | ||
846 | IFLA_HSR_MULTICAST_SPEC, /* Last byte of supervision addr */ | ||
847 | IFLA_HSR_SUPERVISION_ADDR, /* Supervision frame multicast addr */ | ||
848 | IFLA_HSR_SEQ_NR, | ||
849 | IFLA_HSR_VERSION, /* HSR version */ | ||
850 | __IFLA_HSR_MAX, | ||
851 | }; | ||
852 | |||
853 | #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1) | ||
854 | |||
855 | /* STATS section */ | ||
856 | |||
857 | struct if_stats_msg { | ||
858 | __u8 family; | ||
859 | __u8 pad1; | ||
860 | __u16 pad2; | ||
861 | __u32 ifindex; | ||
862 | __u32 filter_mask; | ||
863 | }; | ||
864 | |||
865 | /* A stats attribute can be netdev specific or a global stat. | ||
866 | * For netdev stats, lets use the prefix IFLA_STATS_LINK_* | ||
867 | */ | ||
868 | enum { | ||
869 | IFLA_STATS_UNSPEC, /* also used as 64bit pad attribute */ | ||
870 | IFLA_STATS_LINK_64, | ||
871 | IFLA_STATS_LINK_XSTATS, | ||
872 | IFLA_STATS_LINK_XSTATS_SLAVE, | ||
873 | IFLA_STATS_LINK_OFFLOAD_XSTATS, | ||
874 | IFLA_STATS_AF_SPEC, | ||
875 | __IFLA_STATS_MAX, | ||
876 | }; | ||
877 | |||
878 | #define IFLA_STATS_MAX (__IFLA_STATS_MAX - 1) | ||
879 | |||
880 | #define IFLA_STATS_FILTER_BIT(ATTR) (1 << (ATTR - 1)) | ||
881 | |||
882 | /* These are embedded into IFLA_STATS_LINK_XSTATS: | ||
883 | * [IFLA_STATS_LINK_XSTATS] | ||
884 | * -> [LINK_XSTATS_TYPE_xxx] | ||
885 | * -> [rtnl link type specific attributes] | ||
886 | */ | ||
887 | enum { | ||
888 | LINK_XSTATS_TYPE_UNSPEC, | ||
889 | LINK_XSTATS_TYPE_BRIDGE, | ||
890 | __LINK_XSTATS_TYPE_MAX | ||
891 | }; | ||
892 | #define LINK_XSTATS_TYPE_MAX (__LINK_XSTATS_TYPE_MAX - 1) | ||
893 | |||
894 | /* These are stats embedded into IFLA_STATS_LINK_OFFLOAD_XSTATS */ | ||
895 | enum { | ||
896 | IFLA_OFFLOAD_XSTATS_UNSPEC, | ||
897 | IFLA_OFFLOAD_XSTATS_CPU_HIT, /* struct rtnl_link_stats64 */ | ||
898 | __IFLA_OFFLOAD_XSTATS_MAX | ||
899 | }; | ||
900 | #define IFLA_OFFLOAD_XSTATS_MAX (__IFLA_OFFLOAD_XSTATS_MAX - 1) | ||
901 | |||
902 | /* XDP section */ | ||
903 | |||
904 | #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0) | ||
905 | #define XDP_FLAGS_SKB_MODE (1U << 1) | ||
906 | #define XDP_FLAGS_DRV_MODE (1U << 2) | ||
907 | #define XDP_FLAGS_HW_MODE (1U << 3) | ||
908 | #define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \ | ||
909 | XDP_FLAGS_DRV_MODE | \ | ||
910 | XDP_FLAGS_HW_MODE) | ||
911 | #define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \ | ||
912 | XDP_FLAGS_MODES) | ||
913 | |||
914 | /* These are stored into IFLA_XDP_ATTACHED on dump. */ | ||
915 | enum { | ||
916 | XDP_ATTACHED_NONE = 0, | ||
917 | XDP_ATTACHED_DRV, | ||
918 | XDP_ATTACHED_SKB, | ||
919 | XDP_ATTACHED_HW, | ||
920 | }; | ||
921 | |||
922 | enum { | ||
923 | IFLA_XDP_UNSPEC, | ||
924 | IFLA_XDP_FD, | ||
925 | IFLA_XDP_ATTACHED, | ||
926 | IFLA_XDP_FLAGS, | ||
927 | IFLA_XDP_PROG_ID, | ||
928 | __IFLA_XDP_MAX, | ||
929 | }; | ||
930 | |||
931 | #define IFLA_XDP_MAX (__IFLA_XDP_MAX - 1) | ||
932 | |||
933 | enum { | ||
934 | IFLA_EVENT_NONE, | ||
935 | IFLA_EVENT_REBOOT, /* internal reset / reboot */ | ||
936 | IFLA_EVENT_FEATURES, /* change in offload features */ | ||
937 | IFLA_EVENT_BONDING_FAILOVER, /* change in active slave */ | ||
938 | IFLA_EVENT_NOTIFY_PEERS, /* re-sent grat. arp/ndisc */ | ||
939 | IFLA_EVENT_IGMP_RESEND, /* re-sent IGMP JOIN */ | ||
940 | IFLA_EVENT_BONDING_OPTIONS, /* change in bonding options */ | ||
941 | }; | ||
942 | |||
943 | #endif /* _UAPI_LINUX_IF_LINK_H */ | ||
diff --git a/tools/include/uapi/linux/netlink.h b/tools/include/uapi/linux/netlink.h new file mode 100644 index 000000000000..776bc92e9118 --- /dev/null +++ b/tools/include/uapi/linux/netlink.h | |||
@@ -0,0 +1,251 @@ | |||
1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
2 | #ifndef _UAPI__LINUX_NETLINK_H | ||
3 | #define _UAPI__LINUX_NETLINK_H | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/socket.h> /* for __kernel_sa_family_t */ | ||
7 | #include <linux/types.h> | ||
8 | |||
9 | #define NETLINK_ROUTE 0 /* Routing/device hook */ | ||
10 | #define NETLINK_UNUSED 1 /* Unused number */ | ||
11 | #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ | ||
12 | #define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue */ | ||
13 | #define NETLINK_SOCK_DIAG 4 /* socket monitoring */ | ||
14 | #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */ | ||
15 | #define NETLINK_XFRM 6 /* ipsec */ | ||
16 | #define NETLINK_SELINUX 7 /* SELinux event notifications */ | ||
17 | #define NETLINK_ISCSI 8 /* Open-iSCSI */ | ||
18 | #define NETLINK_AUDIT 9 /* auditing */ | ||
19 | #define NETLINK_FIB_LOOKUP 10 | ||
20 | #define NETLINK_CONNECTOR 11 | ||
21 | #define NETLINK_NETFILTER 12 /* netfilter subsystem */ | ||
22 | #define NETLINK_IP6_FW 13 | ||
23 | #define NETLINK_DNRTMSG 14 /* DECnet routing messages */ | ||
24 | #define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ | ||
25 | #define NETLINK_GENERIC 16 | ||
26 | /* leave room for NETLINK_DM (DM Events) */ | ||
27 | #define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */ | ||
28 | #define NETLINK_ECRYPTFS 19 | ||
29 | #define NETLINK_RDMA 20 | ||
30 | #define NETLINK_CRYPTO 21 /* Crypto layer */ | ||
31 | #define NETLINK_SMC 22 /* SMC monitoring */ | ||
32 | |||
33 | #define NETLINK_INET_DIAG NETLINK_SOCK_DIAG | ||
34 | |||
35 | #define MAX_LINKS 32 | ||
36 | |||
37 | struct sockaddr_nl { | ||
38 | __kernel_sa_family_t nl_family; /* AF_NETLINK */ | ||
39 | unsigned short nl_pad; /* zero */ | ||
40 | __u32 nl_pid; /* port ID */ | ||
41 | __u32 nl_groups; /* multicast groups mask */ | ||
42 | }; | ||
43 | |||
44 | struct nlmsghdr { | ||
45 | __u32 nlmsg_len; /* Length of message including header */ | ||
46 | __u16 nlmsg_type; /* Message content */ | ||
47 | __u16 nlmsg_flags; /* Additional flags */ | ||
48 | __u32 nlmsg_seq; /* Sequence number */ | ||
49 | __u32 nlmsg_pid; /* Sending process port ID */ | ||
50 | }; | ||
51 | |||
52 | /* Flags values */ | ||
53 | |||
54 | #define NLM_F_REQUEST 0x01 /* It is request message. */ | ||
55 | #define NLM_F_MULTI 0x02 /* Multipart message, terminated by NLMSG_DONE */ | ||
56 | #define NLM_F_ACK 0x04 /* Reply with ack, with zero or error code */ | ||
57 | #define NLM_F_ECHO 0x08 /* Echo this request */ | ||
58 | #define NLM_F_DUMP_INTR 0x10 /* Dump was inconsistent due to sequence change */ | ||
59 | #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */ | ||
60 | |||
61 | /* Modifiers to GET request */ | ||
62 | #define NLM_F_ROOT 0x100 /* specify tree root */ | ||
63 | #define NLM_F_MATCH 0x200 /* return all matching */ | ||
64 | #define NLM_F_ATOMIC 0x400 /* atomic GET */ | ||
65 | #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) | ||
66 | |||
67 | /* Modifiers to NEW request */ | ||
68 | #define NLM_F_REPLACE 0x100 /* Override existing */ | ||
69 | #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */ | ||
70 | #define NLM_F_CREATE 0x400 /* Create, if it does not exist */ | ||
71 | #define NLM_F_APPEND 0x800 /* Add to end of list */ | ||
72 | |||
73 | /* Modifiers to DELETE request */ | ||
74 | #define NLM_F_NONREC 0x100 /* Do not delete recursively */ | ||
75 | |||
76 | /* Flags for ACK message */ | ||
77 | #define NLM_F_CAPPED 0x100 /* request was capped */ | ||
78 | #define NLM_F_ACK_TLVS 0x200 /* extended ACK TVLs were included */ | ||
79 | |||
80 | /* | ||
81 | 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL | ||
82 | 4.4BSD CHANGE NLM_F_REPLACE | ||
83 | |||
84 | True CHANGE NLM_F_CREATE|NLM_F_REPLACE | ||
85 | Append NLM_F_CREATE | ||
86 | Check NLM_F_EXCL | ||
87 | */ | ||
88 | |||
89 | #define NLMSG_ALIGNTO 4U | ||
90 | #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) | ||
91 | #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr))) | ||
92 | #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN) | ||
93 | #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) | ||
94 | #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0))) | ||
95 | #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ | ||
96 | (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len))) | ||
97 | #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \ | ||
98 | (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ | ||
99 | (nlh)->nlmsg_len <= (len)) | ||
100 | #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len))) | ||
101 | |||
102 | #define NLMSG_NOOP 0x1 /* Nothing. */ | ||
103 | #define NLMSG_ERROR 0x2 /* Error */ | ||
104 | #define NLMSG_DONE 0x3 /* End of a dump */ | ||
105 | #define NLMSG_OVERRUN 0x4 /* Data lost */ | ||
106 | |||
107 | #define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */ | ||
108 | |||
109 | struct nlmsgerr { | ||
110 | int error; | ||
111 | struct nlmsghdr msg; | ||
112 | /* | ||
113 | * followed by the message contents unless NETLINK_CAP_ACK was set | ||
114 | * or the ACK indicates success (error == 0) | ||
115 | * message length is aligned with NLMSG_ALIGN() | ||
116 | */ | ||
117 | /* | ||
118 | * followed by TLVs defined in enum nlmsgerr_attrs | ||
119 | * if NETLINK_EXT_ACK was set | ||
120 | */ | ||
121 | }; | ||
122 | |||
123 | /** | ||
124 | * enum nlmsgerr_attrs - nlmsgerr attributes | ||
125 | * @NLMSGERR_ATTR_UNUSED: unused | ||
126 | * @NLMSGERR_ATTR_MSG: error message string (string) | ||
127 | * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original | ||
128 | * message, counting from the beginning of the header (u32) | ||
129 | * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to | ||
130 | * be used - in the success case - to identify a created | ||
131 | * object or operation or similar (binary) | ||
132 | * @__NLMSGERR_ATTR_MAX: number of attributes | ||
133 | * @NLMSGERR_ATTR_MAX: highest attribute number | ||
134 | */ | ||
135 | enum nlmsgerr_attrs { | ||
136 | NLMSGERR_ATTR_UNUSED, | ||
137 | NLMSGERR_ATTR_MSG, | ||
138 | NLMSGERR_ATTR_OFFS, | ||
139 | NLMSGERR_ATTR_COOKIE, | ||
140 | |||
141 | __NLMSGERR_ATTR_MAX, | ||
142 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 | ||
143 | }; | ||
144 | |||
145 | #define NETLINK_ADD_MEMBERSHIP 1 | ||
146 | #define NETLINK_DROP_MEMBERSHIP 2 | ||
147 | #define NETLINK_PKTINFO 3 | ||
148 | #define NETLINK_BROADCAST_ERROR 4 | ||
149 | #define NETLINK_NO_ENOBUFS 5 | ||
150 | #ifndef __KERNEL__ | ||
151 | #define NETLINK_RX_RING 6 | ||
152 | #define NETLINK_TX_RING 7 | ||
153 | #endif | ||
154 | #define NETLINK_LISTEN_ALL_NSID 8 | ||
155 | #define NETLINK_LIST_MEMBERSHIPS 9 | ||
156 | #define NETLINK_CAP_ACK 10 | ||
157 | #define NETLINK_EXT_ACK 11 | ||
158 | |||
159 | struct nl_pktinfo { | ||
160 | __u32 group; | ||
161 | }; | ||
162 | |||
163 | struct nl_mmap_req { | ||
164 | unsigned int nm_block_size; | ||
165 | unsigned int nm_block_nr; | ||
166 | unsigned int nm_frame_size; | ||
167 | unsigned int nm_frame_nr; | ||
168 | }; | ||
169 | |||
170 | struct nl_mmap_hdr { | ||
171 | unsigned int nm_status; | ||
172 | unsigned int nm_len; | ||
173 | __u32 nm_group; | ||
174 | /* credentials */ | ||
175 | __u32 nm_pid; | ||
176 | __u32 nm_uid; | ||
177 | __u32 nm_gid; | ||
178 | }; | ||
179 | |||
180 | #ifndef __KERNEL__ | ||
181 | enum nl_mmap_status { | ||
182 | NL_MMAP_STATUS_UNUSED, | ||
183 | NL_MMAP_STATUS_RESERVED, | ||
184 | NL_MMAP_STATUS_VALID, | ||
185 | NL_MMAP_STATUS_COPY, | ||
186 | NL_MMAP_STATUS_SKIP, | ||
187 | }; | ||
188 | |||
189 | #define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO | ||
190 | #define NL_MMAP_MSG_ALIGN(sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT) | ||
191 | #define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr)) | ||
192 | #endif | ||
193 | |||
194 | #define NET_MAJOR 36 /* Major 36 is reserved for networking */ | ||
195 | |||
196 | enum { | ||
197 | NETLINK_UNCONNECTED = 0, | ||
198 | NETLINK_CONNECTED, | ||
199 | }; | ||
200 | |||
201 | /* | ||
202 | * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)--> | ||
203 | * +---------------------+- - -+- - - - - - - - - -+- - -+ | ||
204 | * | Header | Pad | Payload | Pad | | ||
205 | * | (struct nlattr) | ing | | ing | | ||
206 | * +---------------------+- - -+- - - - - - - - - -+- - -+ | ||
207 | * <-------------- nlattr->nla_len --------------> | ||
208 | */ | ||
209 | |||
210 | struct nlattr { | ||
211 | __u16 nla_len; | ||
212 | __u16 nla_type; | ||
213 | }; | ||
214 | |||
215 | /* | ||
216 | * nla_type (16 bits) | ||
217 | * +---+---+-------------------------------+ | ||
218 | * | N | O | Attribute Type | | ||
219 | * +---+---+-------------------------------+ | ||
220 | * N := Carries nested attributes | ||
221 | * O := Payload stored in network byte order | ||
222 | * | ||
223 | * Note: The N and O flag are mutually exclusive. | ||
224 | */ | ||
225 | #define NLA_F_NESTED (1 << 15) | ||
226 | #define NLA_F_NET_BYTEORDER (1 << 14) | ||
227 | #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER) | ||
228 | |||
229 | #define NLA_ALIGNTO 4 | ||
230 | #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) | ||
231 | #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) | ||
232 | |||
233 | /* Generic 32 bitflags attribute content sent to the kernel. | ||
234 | * | ||
235 | * The value is a bitmap that defines the values being set | ||
236 | * The selector is a bitmask that defines which value is legit | ||
237 | * | ||
238 | * Examples: | ||
239 | * value = 0x0, and selector = 0x1 | ||
240 | * implies we are selecting bit 1 and we want to set its value to 0. | ||
241 | * | ||
242 | * value = 0x2, and selector = 0x2 | ||
243 | * implies we are selecting bit 2 and we want to set its value to 1. | ||
244 | * | ||
245 | */ | ||
246 | struct nla_bitfield32 { | ||
247 | __u32 value; | ||
248 | __u32 selector; | ||
249 | }; | ||
250 | |||
251 | #endif /* _UAPI__LINUX_NETLINK_H */ | ||
diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build index d8749756352d..64c679d67109 100644 --- a/tools/lib/bpf/Build +++ b/tools/lib/bpf/Build | |||
@@ -1 +1 @@ | |||
libbpf-y := libbpf.o bpf.o | libbpf-y := libbpf.o bpf.o nlattr.o | ||
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 83714ca1f22b..e6d5f8d1477f 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile | |||
@@ -160,6 +160,12 @@ $(BPF_IN): force elfdep bpfdep | |||
160 | @(test -f ../../include/uapi/linux/bpf_common.h -a -f ../../../include/uapi/linux/bpf_common.h && ( \ | 160 | @(test -f ../../include/uapi/linux/bpf_common.h -a -f ../../../include/uapi/linux/bpf_common.h && ( \ |
161 | (diff -B ../../include/uapi/linux/bpf_common.h ../../../include/uapi/linux/bpf_common.h >/dev/null) || \ | 161 | (diff -B ../../include/uapi/linux/bpf_common.h ../../../include/uapi/linux/bpf_common.h >/dev/null) || \ |
162 | echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf_common.h' differs from latest version at 'include/uapi/linux/bpf_common.h'" >&2 )) || true | 162 | echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf_common.h' differs from latest version at 'include/uapi/linux/bpf_common.h'" >&2 )) || true |
163 | @(test -f ../../include/uapi/linux/netlink.h -a -f ../../../include/uapi/linux/netlink.h && ( \ | ||
164 | (diff -B ../../include/uapi/linux/netlink.h ../../../include/uapi/linux/netlink.h >/dev/null) || \ | ||
165 | echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/netlink.h' differs from latest version at 'include/uapi/linux/netlink.h'" >&2 )) || true | ||
166 | @(test -f ../../include/uapi/linux/if_link.h -a -f ../../../include/uapi/linux/if_link.h && ( \ | ||
167 | (diff -B ../../include/uapi/linux/if_link.h ../../../include/uapi/linux/if_link.h >/dev/null) || \ | ||
168 | echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'" >&2 )) || true | ||
163 | $(Q)$(MAKE) $(build)=libbpf | 169 | $(Q)$(MAKE) $(build)=libbpf |
164 | 170 | ||
165 | $(OUTPUT)libbpf.so: $(BPF_IN) | 171 | $(OUTPUT)libbpf.so: $(BPF_IN) |
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 5128677e4117..592a58a2b681 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -1,3 +1,5 @@ | |||
1 | // SPDX-License-Identifier: LGPL-2.1 | ||
2 | |||
1 | /* | 3 | /* |
2 | * common eBPF ELF operations. | 4 | * common eBPF ELF operations. |
3 | * | 5 | * |
@@ -25,6 +27,16 @@ | |||
25 | #include <asm/unistd.h> | 27 | #include <asm/unistd.h> |
26 | #include <linux/bpf.h> | 28 | #include <linux/bpf.h> |
27 | #include "bpf.h" | 29 | #include "bpf.h" |
30 | #include "libbpf.h" | ||
31 | #include "nlattr.h" | ||
32 | #include <linux/rtnetlink.h> | ||
33 | #include <linux/if_link.h> | ||
34 | #include <sys/socket.h> | ||
35 | #include <errno.h> | ||
36 | |||
37 | #ifndef SOL_NETLINK | ||
38 | #define SOL_NETLINK 270 | ||
39 | #endif | ||
28 | 40 | ||
29 | /* | 41 | /* |
30 | * When building perf, unistd.h is overridden. __NR_bpf is | 42 | * When building perf, unistd.h is overridden. __NR_bpf is |
@@ -46,7 +58,9 @@ | |||
46 | # endif | 58 | # endif |
47 | #endif | 59 | #endif |
48 | 60 | ||
61 | #ifndef min | ||
49 | #define min(x, y) ((x) < (y) ? (x) : (y)) | 62 | #define min(x, y) ((x) < (y) ? (x) : (y)) |
63 | #endif | ||
50 | 64 | ||
51 | static inline __u64 ptr_to_u64(const void *ptr) | 65 | static inline __u64 ptr_to_u64(const void *ptr) |
52 | { | 66 | { |
@@ -413,3 +427,124 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) | |||
413 | 427 | ||
414 | return err; | 428 | return err; |
415 | } | 429 | } |
430 | |||
431 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) | ||
432 | { | ||
433 | struct sockaddr_nl sa; | ||
434 | int sock, seq = 0, len, ret = -1; | ||
435 | char buf[4096]; | ||
436 | struct nlattr *nla, *nla_xdp; | ||
437 | struct { | ||
438 | struct nlmsghdr nh; | ||
439 | struct ifinfomsg ifinfo; | ||
440 | char attrbuf[64]; | ||
441 | } req; | ||
442 | struct nlmsghdr *nh; | ||
443 | struct nlmsgerr *err; | ||
444 | socklen_t addrlen; | ||
445 | int one = 1; | ||
446 | |||
447 | memset(&sa, 0, sizeof(sa)); | ||
448 | sa.nl_family = AF_NETLINK; | ||
449 | |||
450 | sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); | ||
451 | if (sock < 0) { | ||
452 | return -errno; | ||
453 | } | ||
454 | |||
455 | if (setsockopt(sock, SOL_NETLINK, NETLINK_EXT_ACK, | ||
456 | &one, sizeof(one)) < 0) { | ||
457 | fprintf(stderr, "Netlink error reporting not supported\n"); | ||
458 | } | ||
459 | |||
460 | if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) { | ||
461 | ret = -errno; | ||
462 | goto cleanup; | ||
463 | } | ||
464 | |||
465 | addrlen = sizeof(sa); | ||
466 | if (getsockname(sock, (struct sockaddr *)&sa, &addrlen) < 0) { | ||
467 | ret = -errno; | ||
468 | goto cleanup; | ||
469 | } | ||
470 | |||
471 | if (addrlen != sizeof(sa)) { | ||
472 | ret = -LIBBPF_ERRNO__INTERNAL; | ||
473 | goto cleanup; | ||
474 | } | ||
475 | |||
476 | memset(&req, 0, sizeof(req)); | ||
477 | req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); | ||
478 | req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; | ||
479 | req.nh.nlmsg_type = RTM_SETLINK; | ||
480 | req.nh.nlmsg_pid = 0; | ||
481 | req.nh.nlmsg_seq = ++seq; | ||
482 | req.ifinfo.ifi_family = AF_UNSPEC; | ||
483 | req.ifinfo.ifi_index = ifindex; | ||
484 | |||
485 | /* started nested attribute for XDP */ | ||
486 | nla = (struct nlattr *)(((char *)&req) | ||
487 | + NLMSG_ALIGN(req.nh.nlmsg_len)); | ||
488 | nla->nla_type = NLA_F_NESTED | IFLA_XDP; | ||
489 | nla->nla_len = NLA_HDRLEN; | ||
490 | |||
491 | /* add XDP fd */ | ||
492 | nla_xdp = (struct nlattr *)((char *)nla + nla->nla_len); | ||
493 | nla_xdp->nla_type = IFLA_XDP_FD; | ||
494 | nla_xdp->nla_len = NLA_HDRLEN + sizeof(int); | ||
495 | memcpy((char *)nla_xdp + NLA_HDRLEN, &fd, sizeof(fd)); | ||
496 | nla->nla_len += nla_xdp->nla_len; | ||
497 | |||
498 | /* if user passed in any flags, add those too */ | ||
499 | if (flags) { | ||
500 | nla_xdp = (struct nlattr *)((char *)nla + nla->nla_len); | ||
501 | nla_xdp->nla_type = IFLA_XDP_FLAGS; | ||
502 | nla_xdp->nla_len = NLA_HDRLEN + sizeof(flags); | ||
503 | memcpy((char *)nla_xdp + NLA_HDRLEN, &flags, sizeof(flags)); | ||
504 | nla->nla_len += nla_xdp->nla_len; | ||
505 | } | ||
506 | |||
507 | req.nh.nlmsg_len += NLA_ALIGN(nla->nla_len); | ||
508 | |||
509 | if (send(sock, &req, req.nh.nlmsg_len, 0) < 0) { | ||
510 | ret = -errno; | ||
511 | goto cleanup; | ||
512 | } | ||
513 | |||
514 | len = recv(sock, buf, sizeof(buf), 0); | ||
515 | if (len < 0) { | ||
516 | ret = -errno; | ||
517 | goto cleanup; | ||
518 | } | ||
519 | |||
520 | for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); | ||
521 | nh = NLMSG_NEXT(nh, len)) { | ||
522 | if (nh->nlmsg_pid != sa.nl_pid) { | ||
523 | ret = -LIBBPF_ERRNO__WRNGPID; | ||
524 | goto cleanup; | ||
525 | } | ||
526 | if (nh->nlmsg_seq != seq) { | ||
527 | ret = -LIBBPF_ERRNO__INVSEQ; | ||
528 | goto cleanup; | ||
529 | } | ||
530 | switch (nh->nlmsg_type) { | ||
531 | case NLMSG_ERROR: | ||
532 | err = (struct nlmsgerr *)NLMSG_DATA(nh); | ||
533 | if (!err->error) | ||
534 | continue; | ||
535 | ret = err->error; | ||
536 | nla_dump_errormsg(nh); | ||
537 | goto cleanup; | ||
538 | case NLMSG_DONE: | ||
539 | break; | ||
540 | default: | ||
541 | break; | ||
542 | } | ||
543 | } | ||
544 | |||
545 | ret = 0; | ||
546 | |||
547 | cleanup: | ||
548 | close(sock); | ||
549 | return ret; | ||
550 | } | ||
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 9f44c196931e..8d18fb73d7fb 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -1,3 +1,5 @@ | |||
1 | /* SPDX-License-Identifier: LGPL-2.1 */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * common eBPF ELF operations. | 4 | * common eBPF ELF operations. |
3 | * | 5 | * |
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 30c776375118..71ddc481f349 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1,3 +1,5 @@ | |||
1 | // SPDX-License-Identifier: LGPL-2.1 | ||
2 | |||
1 | /* | 3 | /* |
2 | * Common eBPF ELF object loading operations. | 4 | * Common eBPF ELF object loading operations. |
3 | * | 5 | * |
@@ -106,6 +108,8 @@ static const char *libbpf_strerror_table[NR_ERRNO] = { | |||
106 | [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", | 108 | [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", |
107 | [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", | 109 | [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", |
108 | [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type", | 110 | [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type", |
111 | [ERRCODE_OFFSET(WRNGPID)] = "Wrong pid in netlink message", | ||
112 | [ERRCODE_OFFSET(INVSEQ)] = "Invalid netlink sequence", | ||
109 | }; | 113 | }; |
110 | 114 | ||
111 | int libbpf_strerror(int err, char *buf, size_t size) | 115 | int libbpf_strerror(int err, char *buf, size_t size) |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 6e20003109e0..f85906533cdd 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -1,3 +1,5 @@ | |||
1 | /* SPDX-License-Identifier: LGPL-2.1 */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Common eBPF ELF object loading operations. | 4 | * Common eBPF ELF object loading operations. |
3 | * | 5 | * |
@@ -42,6 +44,8 @@ enum libbpf_errno { | |||
42 | LIBBPF_ERRNO__PROG2BIG, /* Program too big */ | 44 | LIBBPF_ERRNO__PROG2BIG, /* Program too big */ |
43 | LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ | 45 | LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ |
44 | LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ | 46 | LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ |
47 | LIBBPF_ERRNO__WRNGPID, /* Wrong pid in netlink message */ | ||
48 | LIBBPF_ERRNO__INVSEQ, /* Invalid netlink sequence */ | ||
45 | __LIBBPF_ERRNO__END, | 49 | __LIBBPF_ERRNO__END, |
46 | }; | 50 | }; |
47 | 51 | ||
@@ -246,4 +250,6 @@ long libbpf_get_error(const void *ptr); | |||
246 | 250 | ||
247 | int bpf_prog_load(const char *file, enum bpf_prog_type type, | 251 | int bpf_prog_load(const char *file, enum bpf_prog_type type, |
248 | struct bpf_object **pobj, int *prog_fd); | 252 | struct bpf_object **pobj, int *prog_fd); |
253 | |||
254 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); | ||
249 | #endif | 255 | #endif |
diff --git a/tools/lib/bpf/nlattr.c b/tools/lib/bpf/nlattr.c new file mode 100644 index 000000000000..4719434278b2 --- /dev/null +++ b/tools/lib/bpf/nlattr.c | |||
@@ -0,0 +1,187 @@ | |||
1 | // SPDX-License-Identifier: LGPL-2.1 | ||
2 | |||
3 | /* | ||
4 | * NETLINK Netlink attributes | ||
5 | * | ||
6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation version 2.1 | ||
9 | * of the License. | ||
10 | * | ||
11 | * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch> | ||
12 | */ | ||
13 | |||
14 | #include <errno.h> | ||
15 | #include "nlattr.h" | ||
16 | #include <linux/rtnetlink.h> | ||
17 | #include <string.h> | ||
18 | #include <stdio.h> | ||
19 | |||
20 | static uint16_t nla_attr_minlen[NLA_TYPE_MAX+1] = { | ||
21 | [NLA_U8] = sizeof(uint8_t), | ||
22 | [NLA_U16] = sizeof(uint16_t), | ||
23 | [NLA_U32] = sizeof(uint32_t), | ||
24 | [NLA_U64] = sizeof(uint64_t), | ||
25 | [NLA_STRING] = 1, | ||
26 | [NLA_FLAG] = 0, | ||
27 | }; | ||
28 | |||
29 | static int nla_len(const struct nlattr *nla) | ||
30 | { | ||
31 | return nla->nla_len - NLA_HDRLEN; | ||
32 | } | ||
33 | |||
34 | static struct nlattr *nla_next(const struct nlattr *nla, int *remaining) | ||
35 | { | ||
36 | int totlen = NLA_ALIGN(nla->nla_len); | ||
37 | |||
38 | *remaining -= totlen; | ||
39 | return (struct nlattr *) ((char *) nla + totlen); | ||
40 | } | ||
41 | |||
42 | static int nla_ok(const struct nlattr *nla, int remaining) | ||
43 | { | ||
44 | return remaining >= sizeof(*nla) && | ||
45 | nla->nla_len >= sizeof(*nla) && | ||
46 | nla->nla_len <= remaining; | ||
47 | } | ||
48 | |||
49 | static void *nla_data(const struct nlattr *nla) | ||
50 | { | ||
51 | return (char *) nla + NLA_HDRLEN; | ||
52 | } | ||
53 | |||
54 | static int nla_type(const struct nlattr *nla) | ||
55 | { | ||
56 | return nla->nla_type & NLA_TYPE_MASK; | ||
57 | } | ||
58 | |||
59 | static int validate_nla(struct nlattr *nla, int maxtype, | ||
60 | struct nla_policy *policy) | ||
61 | { | ||
62 | struct nla_policy *pt; | ||
63 | unsigned int minlen = 0; | ||
64 | int type = nla_type(nla); | ||
65 | |||
66 | if (type < 0 || type > maxtype) | ||
67 | return 0; | ||
68 | |||
69 | pt = &policy[type]; | ||
70 | |||
71 | if (pt->type > NLA_TYPE_MAX) | ||
72 | return 0; | ||
73 | |||
74 | if (pt->minlen) | ||
75 | minlen = pt->minlen; | ||
76 | else if (pt->type != NLA_UNSPEC) | ||
77 | minlen = nla_attr_minlen[pt->type]; | ||
78 | |||
79 | if (nla_len(nla) < minlen) | ||
80 | return -1; | ||
81 | |||
82 | if (pt->maxlen && nla_len(nla) > pt->maxlen) | ||
83 | return -1; | ||
84 | |||
85 | if (pt->type == NLA_STRING) { | ||
86 | char *data = nla_data(nla); | ||
87 | if (data[nla_len(nla) - 1] != '\0') | ||
88 | return -1; | ||
89 | } | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | static inline int nlmsg_len(const struct nlmsghdr *nlh) | ||
95 | { | ||
96 | return nlh->nlmsg_len - NLMSG_HDRLEN; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * Create attribute index based on a stream of attributes. | ||
101 | * @arg tb Index array to be filled (maxtype+1 elements). | ||
102 | * @arg maxtype Maximum attribute type expected and accepted. | ||
103 | * @arg head Head of attribute stream. | ||
104 | * @arg len Length of attribute stream. | ||
105 | * @arg policy Attribute validation policy. | ||
106 | * | ||
107 | * Iterates over the stream of attributes and stores a pointer to each | ||
108 | * attribute in the index array using the attribute type as index to | ||
109 | * the array. Attribute with a type greater than the maximum type | ||
110 | * specified will be silently ignored in order to maintain backwards | ||
111 | * compatibility. If \a policy is not NULL, the attribute will be | ||
112 | * validated using the specified policy. | ||
113 | * | ||
114 | * @see nla_validate | ||
115 | * @return 0 on success or a negative error code. | ||
116 | */ | ||
117 | static int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, | ||
118 | struct nla_policy *policy) | ||
119 | { | ||
120 | struct nlattr *nla; | ||
121 | int rem, err; | ||
122 | |||
123 | memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); | ||
124 | |||
125 | nla_for_each_attr(nla, head, len, rem) { | ||
126 | int type = nla_type(nla); | ||
127 | |||
128 | if (type > maxtype) | ||
129 | continue; | ||
130 | |||
131 | if (policy) { | ||
132 | err = validate_nla(nla, maxtype, policy); | ||
133 | if (err < 0) | ||
134 | goto errout; | ||
135 | } | ||
136 | |||
137 | if (tb[type]) | ||
138 | fprintf(stderr, "Attribute of type %#x found multiple times in message, " | ||
139 | "previous attribute is being ignored.\n", type); | ||
140 | |||
141 | tb[type] = nla; | ||
142 | } | ||
143 | |||
144 | err = 0; | ||
145 | errout: | ||
146 | return err; | ||
147 | } | ||
148 | |||
149 | /* dump netlink extended ack error message */ | ||
150 | int nla_dump_errormsg(struct nlmsghdr *nlh) | ||
151 | { | ||
152 | struct nla_policy extack_policy[NLMSGERR_ATTR_MAX + 1] = { | ||
153 | [NLMSGERR_ATTR_MSG] = { .type = NLA_STRING }, | ||
154 | [NLMSGERR_ATTR_OFFS] = { .type = NLA_U32 }, | ||
155 | }; | ||
156 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1], *attr; | ||
157 | struct nlmsgerr *err; | ||
158 | char *errmsg = NULL; | ||
159 | int hlen, alen; | ||
160 | |||
161 | /* no TLVs, nothing to do here */ | ||
162 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) | ||
163 | return 0; | ||
164 | |||
165 | err = (struct nlmsgerr *)NLMSG_DATA(nlh); | ||
166 | hlen = sizeof(*err); | ||
167 | |||
168 | /* if NLM_F_CAPPED is set then the inner err msg was capped */ | ||
169 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) | ||
170 | hlen += nlmsg_len(&err->msg); | ||
171 | |||
172 | attr = (struct nlattr *) ((void *) err + hlen); | ||
173 | alen = nlh->nlmsg_len - hlen; | ||
174 | |||
175 | if (nla_parse(tb, NLMSGERR_ATTR_MAX, attr, alen, extack_policy) != 0) { | ||
176 | fprintf(stderr, | ||
177 | "Failed to parse extended error attributes\n"); | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | if (tb[NLMSGERR_ATTR_MSG]) | ||
182 | errmsg = (char *) nla_data(tb[NLMSGERR_ATTR_MSG]); | ||
183 | |||
184 | fprintf(stderr, "Kernel error message: %s\n", errmsg); | ||
185 | |||
186 | return 0; | ||
187 | } | ||
diff --git a/tools/lib/bpf/nlattr.h b/tools/lib/bpf/nlattr.h new file mode 100644 index 000000000000..931a71f68f93 --- /dev/null +++ b/tools/lib/bpf/nlattr.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* SPDX-License-Identifier: LGPL-2.1 */ | ||
2 | |||
3 | /* | ||
4 | * NETLINK Netlink attributes | ||
5 | * | ||
6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation version 2.1 | ||
9 | * of the License. | ||
10 | * | ||
11 | * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch> | ||
12 | */ | ||
13 | |||
14 | #ifndef __NLATTR_H | ||
15 | #define __NLATTR_H | ||
16 | |||
17 | #include <stdint.h> | ||
18 | #include <linux/netlink.h> | ||
19 | /* avoid multiple definition of netlink features */ | ||
20 | #define __LINUX_NETLINK_H | ||
21 | |||
22 | /** | ||
23 | * Standard attribute types to specify validation policy | ||
24 | */ | ||
25 | enum { | ||
26 | NLA_UNSPEC, /**< Unspecified type, binary data chunk */ | ||
27 | NLA_U8, /**< 8 bit integer */ | ||
28 | NLA_U16, /**< 16 bit integer */ | ||
29 | NLA_U32, /**< 32 bit integer */ | ||
30 | NLA_U64, /**< 64 bit integer */ | ||
31 | NLA_STRING, /**< NUL terminated character string */ | ||
32 | NLA_FLAG, /**< Flag */ | ||
33 | NLA_MSECS, /**< Micro seconds (64bit) */ | ||
34 | NLA_NESTED, /**< Nested attributes */ | ||
35 | __NLA_TYPE_MAX, | ||
36 | }; | ||
37 | |||
38 | #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1) | ||
39 | |||
40 | /** | ||
41 | * @ingroup attr | ||
42 | * Attribute validation policy. | ||
43 | * | ||
44 | * See section @core_doc{core_attr_parse,Attribute Parsing} for more details. | ||
45 | */ | ||
46 | struct nla_policy { | ||
47 | /** Type of attribute or NLA_UNSPEC */ | ||
48 | uint16_t type; | ||
49 | |||
50 | /** Minimal length of payload required */ | ||
51 | uint16_t minlen; | ||
52 | |||
53 | /** Maximal length of payload allowed */ | ||
54 | uint16_t maxlen; | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * @ingroup attr | ||
59 | * Iterate over a stream of attributes | ||
60 | * @arg pos loop counter, set to current attribute | ||
61 | * @arg head head of attribute stream | ||
62 | * @arg len length of attribute stream | ||
63 | * @arg rem initialized to len, holds bytes currently remaining in stream | ||
64 | */ | ||
65 | #define nla_for_each_attr(pos, head, len, rem) \ | ||
66 | for (pos = head, rem = len; \ | ||
67 | nla_ok(pos, rem); \ | ||
68 | pos = nla_next(pos, &(rem))) | ||
69 | |||
70 | int nla_dump_errormsg(struct nlmsghdr *nlh); | ||
71 | |||
72 | #endif /* __NLATTR_H */ | ||
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore index 1e09d77f1948..cc15af2e54fe 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore | |||
@@ -8,5 +8,6 @@ fixdep | |||
8 | test_align | 8 | test_align |
9 | test_dev_cgroup | 9 | test_dev_cgroup |
10 | test_progs | 10 | test_progs |
11 | test_tcpbpf_user | ||
11 | test_verifier_log | 12 | test_verifier_log |
12 | feature | 13 | feature |
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index bf05bc5e36e5..566d6adc172a 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile | |||
@@ -27,7 +27,7 @@ TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh \ | |||
27 | 27 | ||
28 | include ../lib.mk | 28 | include ../lib.mk |
29 | 29 | ||
30 | BPFOBJ := $(OUTPUT)/libbpf.a $(OUTPUT)/cgroup_helpers.c | 30 | BPFOBJ := $(OUTPUT)/libbpf.a cgroup_helpers.c |
31 | 31 | ||
32 | $(TEST_GEN_PROGS): $(BPFOBJ) | 32 | $(TEST_GEN_PROGS): $(BPFOBJ) |
33 | 33 | ||
@@ -58,7 +58,7 @@ CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \ | |||
58 | $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline | 58 | $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline |
59 | $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline | 59 | $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline |
60 | 60 | ||
61 | %.o: %.c | 61 | $(OUTPUT)/%.o: %.c |
62 | $(CLANG) $(CLANG_FLAGS) \ | 62 | $(CLANG) $(CLANG_FLAGS) \ |
63 | -O2 -target bpf -emit-llvm -c $< -o - | \ | 63 | -O2 -target bpf -emit-llvm -c $< -o - | \ |
64 | $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@ | 64 | $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@ |
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 697bd83de295..c0f16e93f9bd 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
@@ -7780,6 +7780,20 @@ static struct bpf_test tests[] = { | |||
7780 | .result = REJECT, | 7780 | .result = REJECT, |
7781 | }, | 7781 | }, |
7782 | { | 7782 | { |
7783 | "XDP, using ifindex from netdev", | ||
7784 | .insns = { | ||
7785 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
7786 | BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, | ||
7787 | offsetof(struct xdp_md, ingress_ifindex)), | ||
7788 | BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 1, 1), | ||
7789 | BPF_MOV64_IMM(BPF_REG_0, 1), | ||
7790 | BPF_EXIT_INSN(), | ||
7791 | }, | ||
7792 | .result = ACCEPT, | ||
7793 | .prog_type = BPF_PROG_TYPE_XDP, | ||
7794 | .retval = 1, | ||
7795 | }, | ||
7796 | { | ||
7783 | "meta access, test1", | 7797 | "meta access, test1", |
7784 | .insns = { | 7798 | .insns = { |
7785 | BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, | 7799 | BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, |