History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2018-06-05 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add a new BPF hook for sendmsg similar to existing hooks for bind and connect: "This allows to override source IP (including the case when it's set via cmsg(3)) and destination IP:port for unconnected UDP (slow path). TCP and connected UDP (fast path) are not affected. This makes UDP support complete, that is, connected UDP is handled by connect hooks, unconnected by sendmsg ones.", from Andrey. 2) Rework of the AF_XDP API to allow extending it in future for type writer model if necessary. In this mode a memory window is passed to hardware and multiple frames might be filled into that window instead of just one that is the case in the current fixed frame-size model. With the new changes made this can be supported without having to add a new descriptor format. Also, core bits for the zero-copy support for AF_XDP have been merged as agreed upon, where i40e bits will be routed via Jeff later on. Various improvements to documentation and sample programs included as well, all from Björn and Magnus. 3) Given BPF's flexibility, a new program type has been added to implement infrared decoders. Quote: "The kernel IR decoders support the most widely used IR protocols, but there are many protocols which are not supported. [...] There is a 'long tail' of unsupported IR protocols, for which lircd is need to decode the IR. IR encoding is done in such a way that some simple circuit can decode it; therefore, BPF is ideal. [...] user-space can define a decoder in BPF, attach it to the rc device through the lirc chardev.", from Sean. 4) Several improvements and fixes to BPF core, among others, dumping map and prog IDs into fdinfo which is a straight forward way to correlate BPF objects used by applications, removing an indirect call and therefore retpoline in all map lookup/update/delete calls by invoking the callback directly for 64 bit archs, adding a new bpf_skb_cgroup_id() BPF helper for tc BPF programs to have an efficient way of looking up cgroup v2 id for policy or other use cases. Fixes to make sure we zero tunnel/xfrm state that hasn't been filled, to allow context access wrt pt_regs in 32 bit archs for tracing, and last but not least various test cases for fixes that landed in bpf earlier, from Daniel. 5) Get rid of the ndo_xdp_flush API and extend the ndo_xdp_xmit with a XDP_XMIT_FLUSH flag instead which allows to avoid one indirect call as flushing is now merged directly into ndo_xdp_xmit(), from Jesper. 6) Add a new bpf_get_current_cgroup_id() helper that can be used in tracing to retrieve the cgroup id from the current process in order to allow for e.g. aggregation of container-level events, from Yonghong. 7) Two follow-up fixes for BTF to reject invalid input values and related to that also two test cases for BPF kselftests, from Martin. 8) Various API improvements to the bpf_fib_lookup() helper, that is, dropping MPLS bits which are not fully hashed out yet, rejecting invalid helper flags, returning error for unsupported address families as well as renaming flowlabel to flowinfo, from David. 9) Various fixes and improvements to sockmap BPF kselftests in particular in proper error detection and data verification, from Prashant. 10) Two arm32 BPF JIT improvements. One is to fix imm range check with regards to whether immediate fits into 24 bits, and a naming cleanup to get functions related to rsh handling consistent to those handling lsh, from Wang. 11) Two compile warning fixes in BPF, one for BTF and a false positive to silent gcc in stack_map_get_build_id_offset(), from Arnd. 12) Add missing seg6.h header into tools include infrastructure in order to fix compilation of BPF kselftests, from Mathieu. 13) Several formatting cleanups in the BPF UAPI helper description that also fix an error during rst2man compilation, from Quentin. 14) Hide an unused variable in sk_msg_convert_ctx_access() when IPv6 is not built into the kernel, from Yue. 15) Remove a useless double assignment in dev_map_enqueue(), from Colin. ====================

David S. Miller committed 8 years ago

Commit fd129f82 parents a6fa908 9fa061076 files · +3841 −730Browse files

Showing the changes to include/uapi/linux (2 of 76 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +109 −27
  2. include/uapi/linux/if_xdp.h +8 −8
include/uapi/linux/bpf.h+109−27
@@ -143,6 +143,7 @@ enum bpf_prog_type { · 142 unmodified lines
143143 BPF_PROG_TYPE_RAW_TRACEPOINT,
144144 BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
145145 BPF_PROG_TYPE_LWT_SEG6LOCAL,
146+ BPF_PROG_TYPE_LIRC_MODE2,
146147 };
147148
148149 enum bpf_attach_type {
@@ -160,6 +161,9 @@ enum bpf_attach_type { · 11 unmodified lines
160161 BPF_CGROUP_INET6_CONNECT,
161162 BPF_CGROUP_INET4_POST_BIND,
162163 BPF_CGROUP_INET6_POST_BIND,
164+ BPF_CGROUP_UDP4_SENDMSG,
165+ BPF_CGROUP_UDP6_SENDMSG,
166+ BPF_LIRC_MODE2,
163167 __MAX_BPF_ATTACH_TYPE
164168 };
165169
@@ -1008,7 +1012,6 @@ union bpf_attr { · 842 unmodified lines
10081012 * ::
10091013 *
10101014 * # sysctl kernel.perf_event_max_stack=<new value>
1011− *
10121015 * Return
10131016 * The positive or null stack id on success, or a negative error
10141017 * in case of failure.
@@ -1819,10 +1822,9 @@ union bpf_attr { · 804 unmodified lines
18191822 * ::
18201823 *
18211824 * # sysctl kernel.perf_event_max_stack=<new value>
1822− *
18231825 * Return
1824− * a non-negative value equal to or less than size on success, or
1825− * a negative error in case of failure.
1826+ * A non-negative value equal to or less than *size* on success,
1827+ * or a negative error in case of failure.
18261828 *
18271829 * int skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
18281830 * Description
@@ -1843,7 +1845,6 @@ union bpf_attr { · 14 unmodified lines
18431845 * in socket filters where *skb*\ **->data** does not always point
18441846 * to the start of the mac header and where "direct packet access"
18451847 * is not available.
1846− *
18471848 * Return
18481849 * 0 on success, or a negative error in case of failure.
18491850 *
@@ -1853,22 +1854,24 @@ union bpf_attr { · 3 unmodified lines
18531854 * If lookup is successful and result shows packet is to be
18541855 * forwarded, the neighbor tables are searched for the nexthop.
18551856 * If successful (ie., FIB lookup shows forwarding and nexthop
1856− * is resolved), the nexthop address is returned in ipv4_dst,
1857− * ipv6_dst or mpls_out based on family, smac is set to mac
1858− * address of egress device, dmac is set to nexthop mac address,
1859− * rt_metric is set to metric from route.
1857+ * is resolved), the nexthop address is returned in ipv4_dst
1858+ * or ipv6_dst based on family, smac is set to mac address of
1859+ * egress device, dmac is set to nexthop mac address, rt_metric
1860+ * is set to metric from route (IPv4/IPv6 only).
18601861 *
18611862 * *plen* argument is the size of the passed in struct.
1862− * *flags* argument can be one or more BPF_FIB_LOOKUP_ flags:
1863+ * *flags* argument can be a combination of one or more of the
1864+ * following values:
18631865 *
1864− * **BPF_FIB_LOOKUP_DIRECT** means do a direct table lookup vs
1865− * full lookup using FIB rules
1866− * **BPF_FIB_LOOKUP_OUTPUT** means do lookup from an egress
1867− * perspective (default is ingress)
1866+ * **BPF_FIB_LOOKUP_DIRECT**
1867+ * Do a direct table lookup vs full lookup using FIB
1868+ * rules.
1869+ * **BPF_FIB_LOOKUP_OUTPUT**
1870+ * Perform lookup from an egress perspective (default is
1871+ * ingress).
18681872 *
18691873 * *ctx* is either **struct xdp_md** for XDP programs or
18701874 * **struct sk_buff** tc cls_act programs.
1871− *
18721875 * Return
18731876 * Egress device index on success, 0 if packet needs to continue
18741877 * up the stack for further processing or a negative error in case
@@ -2004,6 +2007,74 @@ union bpf_attr { · 129 unmodified lines
20042007 * direct packet access.
20052008 * Return
20062009 * 0 on success, or a negative error in case of failure.
2010+ *
2011+ * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
2012+ * Description
2013+ * This helper is used in programs implementing IR decoding, to
2014+ * report a successfully decoded key press with *scancode*,
2015+ * *toggle* value in the given *protocol*. The scancode will be
2016+ * translated to a keycode using the rc keymap, and reported as
2017+ * an input key down event. After a period a key up event is
2018+ * generated. This period can be extended by calling either
2019+ * **bpf_rc_keydown** () again with the same values, or calling
2020+ * **bpf_rc_repeat** ().
2021+ *
2022+ * Some protocols include a toggle bit, in case the button was
2023+ * released and pressed again between consecutive scancodes.
2024+ *
2025+ * The *ctx* should point to the lirc sample as passed into
2026+ * the program.
2027+ *
2028+ * The *protocol* is the decoded protocol number (see
2029+ * **enum rc_proto** for some predefined values).
2030+ *
2031+ * This helper is only available is the kernel was compiled with
2032+ * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2033+ * "**y**".
2034+ *
2035+ * Return
2036+ * 0
2037+ *
2038+ * int bpf_rc_repeat(void *ctx)
2039+ * Description
2040+ * This helper is used in programs implementing IR decoding, to
2041+ * report a successfully decoded repeat key message. This delays
2042+ * the generation of a key up event for previously generated
2043+ * key down event.
2044+ *
2045+ * Some IR protocols like NEC have a special IR message for
2046+ * repeating last button, for when a button is held down.
2047+ *
2048+ * The *ctx* should point to the lirc sample as passed into
2049+ * the program.
2050+ *
2051+ * This helper is only available is the kernel was compiled with
2052+ * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2053+ * "**y**".
2054+ *
2055+ * Return
2056+ * 0
2057+ *
2058+ * uint64_t bpf_skb_cgroup_id(struct sk_buff *skb)
2059+ * Description
2060+ * Return the cgroup v2 id of the socket associated with the *skb*.
2061+ * This is roughly similar to the **bpf_get_cgroup_classid**\ ()
2062+ * helper for cgroup v1 by providing a tag resp. identifier that
2063+ * can be matched on or used for map lookups e.g. to implement
2064+ * policy. The cgroup v2 id of a given path in the hierarchy is
2065+ * exposed in user space through the f_handle API in order to get
2066+ * to the same 64-bit id.
2067+ *
2068+ * This helper can be used on TC egress path, but not on ingress,
2069+ * and is available only if the kernel was compiled with the
2070+ * **CONFIG_SOCK_CGROUP_DATA** configuration option.
2071+ * Return
2072+ * The id is returned or 0 in case the id could not be retrieved.
2073+ *
2074+ * u64 bpf_get_current_cgroup_id(void)
2075+ * Return
2076+ * A 64-bit integer containing the current cgroup id based
2077+ * on the cgroup within which the current task is running.
20072078 */
20082079 #define __BPF_FUNC_MAPPER(FN) \
20092080 FN(unspec), \
@@ -2082,7 +2153,11 @@ union bpf_attr { · 72 unmodified lines
20822153 FN(lwt_push_encap), \
20832154 FN(lwt_seg6_store_bytes), \
20842155 FN(lwt_seg6_adjust_srh), \
2085− FN(lwt_seg6_action),
2156+ FN(lwt_seg6_action), \
2157+ FN(rc_repeat), \
2158+ FN(rc_keydown), \
2159+ FN(skb_cgroup_id), \
2160+ FN(get_current_cgroup_id),
20862161
20872162 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
20882163 * function eBPF program intends to call
@@ -2199,7 +2274,7 @@ struct bpf_tunnel_key { · 110 unmodified lines
21992274 };
22002275 __u8 tunnel_tos;
22012276 __u8 tunnel_ttl;
2202− __u16 tunnel_ext;
2277+ __u16 tunnel_ext; /* Padding, future use. */
22032278 __u32 tunnel_label;
22042279 };
22052280
@@ -2210,6 +2285,7 @@ struct bpf_xfrm_state { · 4 unmodified lines
22102285 __u32 reqid;
22112286 __u32 spi; /* Stored in network byte order */
22122287 __u16 family;
2288+ __u16 ext; /* Padding, future use. */
22132289 union {
22142290 __u32 remote_ipv4; /* Stored in network byte order */
22152291 __u32 remote_ipv6[4]; /* Stored in network byte order */
@@ -2364,6 +2440,12 @@ struct bpf_sock_addr { · 148 unmodified lines
23642440 __u32 family; /* Allows 4-byte read, but no write */
23652441 __u32 type; /* Allows 4-byte read, but no write */
23662442 __u32 protocol; /* Allows 4-byte read, but no write */
2443+ __u32 msg_src_ip4; /* Allows 1,2,4-byte read an 4-byte write.
2444+ * Stored in network byte order.
2445+ */
2446+ __u32 msg_src_ip6[4]; /* Allows 1,2,4-byte read an 4-byte write.
2447+ * Stored in network byte order.
2448+ */
23672449 };
23682450
23692451 /* User bpf_sock_ops struct to access socket values and specify request ops
@@ -2531,8 +2613,10 @@ struct bpf_raw_tracepoint_args { · 161 unmodified lines
25312613 #define BPF_FIB_LOOKUP_OUTPUT BIT(1)
25322614
25332615 struct bpf_fib_lookup {
2534− /* input */
2535− __u8 family; /* network family, AF_INET, AF_INET6, AF_MPLS */
2616+ /* input: network family for lookup (AF_INET, AF_INET6)
2617+ * output: network family of egress nexthop
2618+ */
2619+ __u8 family;
25362620
25372621 /* set if lookup is to consider L4 data - e.g., FIB rules */
25382622 __u8 l4_protocol;
@@ -2546,24 +2630,22 @@ struct bpf_fib_lookup { · 7 unmodified lines
25462630 union {
25472631 /* inputs to lookup */
25482632 __u8 tos; /* AF_INET */
2549− __be32 flowlabel; /* AF_INET6 */
2633+ __be32 flowinfo; /* AF_INET6, flow_label + priority */
25502634
2551− /* output: metric of fib result */
2552− __u32 rt_metric;
2635+ /* output: metric of fib result (IPv4/IPv6 only) */
2636+ __u32 rt_metric;
25532637 };
25542638
25552639 union {
2556− __be32 mpls_in;
25572640 __be32 ipv4_src;
25582641 __u32 ipv6_src[4]; /* in6_addr; network order */
25592642 };
25602643
2561− /* input to bpf_fib_lookup, *dst is destination address.
2562− * output: bpf_fib_lookup sets to gateway address
2644+ /* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
2645+ * network header. output: bpf_fib_lookup sets to gateway address
2646+ * if FIB lookup returns gateway route
25632647 */
25642648 union {
2565− /* return for MPLS lookups */
2566− __be32 mpls_out[4]; /* support up to 4 labels */
25672649 __be32 ipv4_dst;
25682650 __u32 ipv6_dst[4]; /* in6_addr; network order */
25692651 };
include/uapi/linux/if_xdp.h+8−8
@@ -13,7 +13,9 @@ · 12 unmodified lines
1313 #include <linux/types.h>
1414
1515 /* Options for the sxdp_flags field */
16−#define XDP_SHARED_UMEM 1
16+#define XDP_SHARED_UMEM (1 << 0)
17+#define XDP_COPY (1 << 1) /* Force copy-mode */
18+#define XDP_ZEROCOPY (1 << 2) /* Force zero-copy mode */
1719
1820 struct sockaddr_xdp {
1921 __u16 sxdp_family;
@@ -48,8 +50,8 @@ struct xdp_mmap_offsets { · 28 unmodified lines
4850 struct xdp_umem_reg {
4951 __u64 addr; /* Start of packet data area */
5052 __u64 len; /* Length of packet data area */
51− __u32 frame_size; /* Frame size */
52− __u32 frame_headroom; /* Frame head room */
53+ __u32 chunk_size;
54+ __u32 headroom;
5355 };
5456
5557 struct xdp_statistics {
@@ -66,13 +68,11 @@ struct xdp_statistics { · 10 unmodified lines
6668
6769 /* Rx/Tx descriptor */
6870 struct xdp_desc {
69− __u32 idx;
71+ __u64 addr;
7072 __u32 len;
71− __u16 offset;
72− __u8 flags;
73− __u8 padding[5];
73+ __u32 options;
7474 };
7575
76−/* UMEM descriptor is __u32 */
76+/* UMEM descriptor is __u64 */
7777
7878 #endif /* _LINUX_IF_XDP_H */