mirror of https://gitee.com/openkylin/linux.git
selftests/bpf: Use bpf_check_mtu in selftest test_cls_redirect
This demonstrate how bpf_check_mtu() helper can easily be used together with bpf_skb_adjust_room() helper, prior to doing size adjustment, as delta argument is already setup. Hint: This specific test can be selected like this: ./test_progs -t cls_redirect Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/161287791481.790810.4444271170546646080.stgit@firesoul
This commit is contained in:
parent
5f7d57280c
commit
6b8838be7e
|
@ -70,6 +70,7 @@ typedef struct {
|
|||
uint64_t errors_total_encap_adjust_failed;
|
||||
uint64_t errors_total_encap_buffer_too_small;
|
||||
uint64_t errors_total_redirect_loop;
|
||||
uint64_t errors_total_encap_mtu_violate;
|
||||
} metrics_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -407,6 +408,7 @@ static INLINING ret_t forward_with_gre(struct __sk_buff *skb, encap_headers_t *e
|
|||
payload_off - sizeof(struct ethhdr) - sizeof(struct iphdr);
|
||||
int32_t delta = sizeof(struct gre_base_hdr) - encap_overhead;
|
||||
uint16_t proto = ETH_P_IP;
|
||||
uint32_t mtu_len = 0;
|
||||
|
||||
/* Loop protection: the inner packet's TTL is decremented as a safeguard
|
||||
* against any forwarding loop. As the only interesting field is the TTL
|
||||
|
@ -479,6 +481,11 @@ static INLINING ret_t forward_with_gre(struct __sk_buff *skb, encap_headers_t *e
|
|||
}
|
||||
}
|
||||
|
||||
if (bpf_check_mtu(skb, skb->ifindex, &mtu_len, delta, 0)) {
|
||||
metrics->errors_total_encap_mtu_violate++;
|
||||
return TC_ACT_SHOT;
|
||||
}
|
||||
|
||||
if (bpf_skb_adjust_room(skb, delta, BPF_ADJ_ROOM_NET,
|
||||
BPF_F_ADJ_ROOM_FIXED_GSO |
|
||||
BPF_F_ADJ_ROOM_NO_CSUM_RESET) ||
|
||||
|
|
Loading…
Reference in New Issue