From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, sdf@google.com,
posk@google.com, Willem de Bruijn <willemb@google.com>
Subject: [PATCH bpf-next 11/13] selftests/bpf: convert bpf tunnel test to BPF_ADJ_ROOM_MAC
Date: Wed, 20 Mar 2019 10:49:42 -0400 [thread overview]
Message-ID: <20190320144944.147862-12-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20190320144944.147862-1-willemdebruijn.kernel@gmail.com>
From: Willem de Bruijn <willemb@google.com>
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>
---
.../selftests/bpf/progs/test_tc_tunnel.c | 25 +++----------------
1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
index 900c5653105fe..f6a16fd23dbd5 100644
--- a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
+++ b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
@@ -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);
/* 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;
/* 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)
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;
}
@@ -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);
/* 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;
/* 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)
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;
}
@@ -207,14 +195,7 @@ static int decap_internal(struct __sk_buff *skb, int off, int len, char proto)
return TC_ACT_OK;
}
- if (bpf_skb_load_bytes(skb, off + olen, &buf, olen) < 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)
+ if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC, 0))
return TC_ACT_SHOT;
return TC_ACT_OK;
--
2.21.0.225.g810b269d1ac-goog
next prev parent reply other threads:[~2019-03-20 14:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 14:49 [PATCH bpf-next 00/13] bpf tc tunneling Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 01/13] bpf: in bpf_skb_adjust_room avoid copy in tx fast path Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 02/13] selftests/bpf: bpf tunnel encap test Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 03/13] selftests/bpf: expand bpf tunnel test with decap Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 04/13] selftests/bpf: expand bpf tunnel test to ipv6 Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 05/13] selftests/bpf: extend bpf tunnel test with gre Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 06/13] selftests/bpf: extend bpf tunnel test with tso Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 07/13] bpf: add bpf_skb_adjust_room mode BPF_ADJ_ROOM_MAC Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 08/13] bpf: add bpf_skb_adjust_room flag BPF_F_ADJ_ROOM_FIXED_GSO Willem de Bruijn
2019-03-21 13:42 ` Alan Maguire
2019-03-21 14:00 ` Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 09/13] bpf: add bpf_skb_adjust_room encap flags Willem de Bruijn
2019-03-20 15:51 ` Alan Maguire
2019-03-20 18:10 ` Willem de Bruijn
2019-03-21 3:13 ` Alexei Starovoitov
2019-03-21 13:25 ` Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 10/13] bpf: Sync bpf.h to tools Willem de Bruijn
2019-03-20 14:56 ` Soheil Hassas Yeganeh
2019-03-20 14:49 ` Willem de Bruijn [this message]
2019-03-20 14:49 ` [PATCH bpf-next 12/13] selftests/bpf: convert bpf tunnel test to BPF_F_ADJ_ROOM_FIXED_GSO Willem de Bruijn
2019-03-20 14:49 ` [PATCH bpf-next 13/13] selftests/bpf: convert bpf tunnel test to encap modes Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190320144944.147862-12-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=posk@google.com \
--cc=sdf@google.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).