History

bpf: BPF-helper for MTU checking add length input

The FIB lookup example[1] show how the IP-header field tot_len (iph->tot_len) is used as input to perform the MTU check. This patch extend the BPF-helper bpf_check_mtu() with the same ability to provide the length as user parameter input, via mtu_len parameter. This still needs to be done before the bpf_check_mtu() helper API becomes frozen. [1] samples/bpf/xdp_fwd_kern.c

Jesper Dangaard Brouer committed 5 years ago

Commit e5e35e71 parent e7fb6462 files · +21 −7Browse files

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

Unified · Split

include/uapi/linux/bpf.h+11−5
@@ -3850,7 +3850,7 @@ union bpf_attr { · 3849 unmodified lines
3850 *3850 *
3851 * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)3851 * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
3852 * Description3852 * Description
3853 * Check ctx packet size against exceeding MTU of net device (based3853 * Check packet size against exceeding MTU of net device (based
3854 * on *ifindex*). This helper will likely be used in combination3854 * on *ifindex*). This helper will likely be used in combination
3855 * with helpers that adjust/change the packet size.3855 * with helpers that adjust/change the packet size.
3856 *3856 *
@@ -3867,6 +3867,14 @@ union bpf_attr { · 10 unmodified lines
3867 * against the current net device. This is practical if this isn't3867 * against the current net device. This is practical if this isn't
3868 * used prior to redirect.3868 * used prior to redirect.
3869 *3869 *
3870 * On input *mtu_len* must be a valid pointer, else verifier will
3871 * reject BPF program. If the value *mtu_len* is initialized to
3872 * zero then the ctx packet size is use. When value *mtu_len* is
3873 * provided as input this specify the L3 length that the MTU check
3874 * is done against. Remember XDP and TC length operate at L2, but
3875 * this value is L3 as this correlate to MTU and IP-header tot_len
3876 * values which are L3 (similar behavior as bpf_fib_lookup).
3877 *
3870 * The Linux kernel route table can configure MTUs on a more3878 * The Linux kernel route table can configure MTUs on a more
3871 * specific per route level, which is not provided by this helper.3879 * specific per route level, which is not provided by this helper.
3872 * For route level MTU checks use the **bpf_fib_lookup**\ ()3880 * For route level MTU checks use the **bpf_fib_lookup**\ ()
@@ -3891,11 +3899,9 @@ union bpf_attr { · 18 unmodified lines
3891 *3899 *
3892 * On return *mtu_len* pointer contains the MTU value of the net3900 * On return *mtu_len* pointer contains the MTU value of the net
3893 * device. Remember the net device configured MTU is the L3 size,3901 * device. Remember the net device configured MTU is the L3 size,
3894 * which is returned here and XDP and TX length operate at L2.3902 * which is returned here and XDP and TC length operate at L2.
3895 * Helper take this into account for you, but remember when using3903 * Helper take this into account for you, but remember when using
3896 * MTU value in your BPF-code. On input *mtu_len* must be a valid3904 * MTU value in your BPF-code.
3897 * pointer and be initialized (to zero), else verifier will reject
3898 * BPF program.
3899 *3905 *
3900 * Return3906 * Return
3901 * * 0 on success, and populate MTU value in *mtu_len* pointer.3907 * * 0 on success, and populate MTU value in *mtu_len* pointer.