selftests/bpf: convert bpf tunnel test to BPF_ADJ_ROOM_MAC
Avoid moving the network layer header when prefixing tunnel headers. This avoids an explicit call to bpf_skb_store_bytes and an implicit move of the network header bytes in bpf_skb_adjust_room. Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
6c408decbd
commit
005edd1656
1 changed files with 3 additions and 22 deletions
|
@ -72,7 +72,7 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
|
||||||
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
|
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
|
||||||
|
|
||||||
/* add room between mac and network header */
|
/* add room between mac and network header */
|
||||||
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_NET, 0))
|
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
/* prepare new outer network header */
|
/* prepare new outer network header */
|
||||||
|
@ -94,12 +94,6 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
|
||||||
BPF_F_INVALIDATE_HASH) < 0)
|
BPF_F_INVALIDATE_HASH) < 0)
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
/* bpf_skb_adjust_room has moved header to start of room: restore */
|
|
||||||
if (bpf_skb_store_bytes(skb, ETH_HLEN + olen,
|
|
||||||
&iph_inner, sizeof(iph_inner),
|
|
||||||
BPF_F_INVALIDATE_HASH) < 0)
|
|
||||||
return TC_ACT_SHOT;
|
|
||||||
|
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +119,7 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
|
||||||
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
|
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
|
||||||
|
|
||||||
/* add room between mac and network header */
|
/* add room between mac and network header */
|
||||||
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_NET, 0))
|
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
/* prepare new outer network header */
|
/* prepare new outer network header */
|
||||||
|
@ -145,12 +139,6 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
|
||||||
BPF_F_INVALIDATE_HASH) < 0)
|
BPF_F_INVALIDATE_HASH) < 0)
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
/* bpf_skb_adjust_room has moved header to start of room: restore */
|
|
||||||
if (bpf_skb_store_bytes(skb, ETH_HLEN + olen,
|
|
||||||
&iph_inner, sizeof(iph_inner),
|
|
||||||
BPF_F_INVALIDATE_HASH) < 0)
|
|
||||||
return TC_ACT_SHOT;
|
|
||||||
|
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,14 +195,7 @@ static int decap_internal(struct __sk_buff *skb, int off, int len, char proto)
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bpf_skb_load_bytes(skb, off + olen, &buf, olen) < 0)
|
if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC, 0))
|
||||||
return TC_ACT_OK;
|
|
||||||
|
|
||||||
if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_NET, 0))
|
|
||||||
return TC_ACT_SHOT;
|
|
||||||
|
|
||||||
/* bpf_skb_adjust_room has moved outer over inner header: restore */
|
|
||||||
if (bpf_skb_store_bytes(skb, off, buf, len, BPF_F_INVALIDATE_HASH) < 0)
|
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
|
|
Loading…
Add table
Reference in a new issue