Skip to content

Commit 005edd1

Browse files
wdebruijAlexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6c408de commit 005edd1

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

tools/testing/selftests/bpf/progs/test_tc_tunnel.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
7272
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
7373

7474
/* add room between mac and network header */
75-
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_NET, 0))
75+
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
7676
return TC_ACT_SHOT;
7777

7878
/* prepare new outer network header */
@@ -94,12 +94,6 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
9494
BPF_F_INVALIDATE_HASH) < 0)
9595
return TC_ACT_SHOT;
9696

97-
/* bpf_skb_adjust_room has moved header to start of room: restore */
98-
if (bpf_skb_store_bytes(skb, ETH_HLEN + olen,
99-
&iph_inner, sizeof(iph_inner),
100-
BPF_F_INVALIDATE_HASH) < 0)
101-
return TC_ACT_SHOT;
102-
10397
return TC_ACT_OK;
10498
}
10599

@@ -125,7 +119,7 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
125119
olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
126120

127121
/* add room between mac and network header */
128-
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_NET, 0))
122+
if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
129123
return TC_ACT_SHOT;
130124

131125
/* prepare new outer network header */
@@ -145,12 +139,6 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
145139
BPF_F_INVALIDATE_HASH) < 0)
146140
return TC_ACT_SHOT;
147141

148-
/* bpf_skb_adjust_room has moved header to start of room: restore */
149-
if (bpf_skb_store_bytes(skb, ETH_HLEN + olen,
150-
&iph_inner, sizeof(iph_inner),
151-
BPF_F_INVALIDATE_HASH) < 0)
152-
return TC_ACT_SHOT;
153-
154142
return TC_ACT_OK;
155143
}
156144

@@ -207,14 +195,7 @@ static int decap_internal(struct __sk_buff *skb, int off, int len, char proto)
207195
return TC_ACT_OK;
208196
}
209197

210-
if (bpf_skb_load_bytes(skb, off + olen, &buf, olen) < 0)
211-
return TC_ACT_OK;
212-
213-
if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_NET, 0))
214-
return TC_ACT_SHOT;
215-
216-
/* bpf_skb_adjust_room has moved outer over inner header: restore */
217-
if (bpf_skb_store_bytes(skb, off, buf, len, BPF_F_INVALIDATE_HASH) < 0)
198+
if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC, 0))
218199
return TC_ACT_SHOT;
219200

220201
return TC_ACT_OK;

0 commit comments

Comments
 (0)