aboutsummaryrefslogtreecommitdiffstats
path: root/include/uapi/linux
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-05-03 19:08:15 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-05-03 19:49:19 -0400
commit4e1ec56cdc59746943b2acfab3c171b930187bbe (patch)
treec7bc363b064ec1d5a3917de49d90696c8794e361 /include/uapi/linux
parente0cea7ce988cf48cc4052235d2ad2550b3bc4fa0 (diff)
bpf: add skb_load_bytes_relative helper
This adds a small BPF helper similar to bpf_skb_load_bytes() that is able to load relative to mac/net header offset from the skb's linear data. Compared to bpf_skb_load_bytes(), it takes a fifth argument namely start_header, which is either BPF_HDR_START_MAC or BPF_HDR_START_NET. This allows for a more flexible alternative compared to LD_ABS/LD_IND with negative offset. It's enabled for tc BPF programs as well as sock filter program types where it's mainly useful in reuseport programs to ease access to lower header data. Reference: https://lists.iovisor.org/pipermail/iovisor-dev/2017-March/000698.html Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/uapi/linux')
-rw-r--r--include/uapi/linux/bpf.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index a3a495052511..93d5a4eeec2a 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1802,6 +1802,30 @@ union bpf_attr {
1802 * Return 1802 * Return
1803 * a non-negative value equal to or less than size on success, or 1803 * a non-negative value equal to or less than size on success, or
1804 * a negative error in case of failure. 1804 * a negative error in case of failure.
1805 *
1806 * int skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
1807 * Description
1808 * This helper is similar to **bpf_skb_load_bytes**\ () in that
1809 * it provides an easy way to load *len* bytes from *offset*
1810 * from the packet associated to *skb*, into the buffer pointed
1811 * by *to*. The difference to **bpf_skb_load_bytes**\ () is that
1812 * a fifth argument *start_header* exists in order to select a
1813 * base offset to start from. *start_header* can be one of:
1814 *
1815 * **BPF_HDR_START_MAC**
1816 * Base offset to load data from is *skb*'s mac header.
1817 * **BPF_HDR_START_NET**
1818 * Base offset to load data from is *skb*'s network header.
1819 *
1820 * In general, "direct packet access" is the preferred method to
1821 * access packet data, however, this helper is in particular useful
1822 * in socket filters where *skb*\ **->data** does not always point
1823 * to the start of the mac header and where "direct packet access"
1824 * is not available.
1825 *
1826 * Return
1827 * 0 on success, or a negative error in case of failure.
1828 *
1805 */ 1829 */
1806#define __BPF_FUNC_MAPPER(FN) \ 1830#define __BPF_FUNC_MAPPER(FN) \
1807 FN(unspec), \ 1831 FN(unspec), \
@@ -1871,7 +1895,8 @@ union bpf_attr {
1871 FN(bind), \ 1895 FN(bind), \
1872 FN(xdp_adjust_tail), \ 1896 FN(xdp_adjust_tail), \
1873 FN(skb_get_xfrm_state), \ 1897 FN(skb_get_xfrm_state), \
1874 FN(get_stack), 1898 FN(get_stack), \
1899 FN(skb_load_bytes_relative),
1875 1900
1876/* integer value in 'imm' field of BPF_CALL instruction selects which helper 1901/* integer value in 'imm' field of BPF_CALL instruction selects which helper
1877 * function eBPF program intends to call 1902 * function eBPF program intends to call
@@ -1932,6 +1957,12 @@ enum bpf_adj_room_mode {
1932 BPF_ADJ_ROOM_NET, 1957 BPF_ADJ_ROOM_NET,
1933}; 1958};
1934 1959
1960/* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
1961enum bpf_hdr_start_off {
1962 BPF_HDR_START_MAC,
1963 BPF_HDR_START_NET,
1964};
1965
1935/* user accessible mirror of in-kernel sk_buff. 1966/* user accessible mirror of in-kernel sk_buff.
1936 * new fields can only be added to the end of this structure 1967 * new fields can only be added to the end of this structure
1937 */ 1968 */