From: sdf@google.com
To: Ziyang Xuan <william.xuanziyang@huawei.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com,
jolsa@kernel.org, willemb@google.com
Subject: Re: [PATCH bpf-next 1/2] bpf: Add ipip6 and ip6ip decap support for bpf_skb_adjust_room()
Date: Fri, 6 Jan 2023 11:55:54 -0800 [thread overview]
Message-ID: <Y7h8yrOEkPuHkNpJ@google.com> (raw)
In-Reply-To: <7e9ca6837b20bea661248957dbbd1db198e3d1f8.1672976410.git.william.xuanziyang@huawei.com>
On 01/06, Ziyang Xuan wrote:
> Add ipip6 and ip6ip decap support for bpf_skb_adjust_room().
> Main use case is for using cls_bpf on ingress hook to decapsulate
> IPv4 over IPv6 and IPv6 over IPv4 tunnel packets.
CC'd Willem since he has done bpf_skb_adjust_room changes in the past.
There might be a lot of GRO/GSO context I'm missing.
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
> ---
> net/core/filter.c | 34 ++++++++++++++++++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 929358677183..73982fb4fe2e 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3495,6 +3495,12 @@ static int bpf_skb_net_grow(struct sk_buff *skb,
> u32 off, u32 len_diff,
> static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
> u64 flags)
> {
> + union {
> + struct iphdr *v4;
> + struct ipv6hdr *v6;
> + unsigned char *hdr;
> + } ip;
> + __be16 proto;
> int ret;
> if (unlikely(flags & ~(BPF_F_ADJ_ROOM_FIXED_GSO |
> @@ -3512,10 +3518,19 @@ static int bpf_skb_net_shrink(struct sk_buff
> *skb, u32 off, u32 len_diff,
> if (unlikely(ret < 0))
> return ret;
> + ip.hdr = skb_inner_network_header(skb);
> + if (ip.v4->version == 4)
> + proto = htons(ETH_P_IP);
> + else
> + proto = htons(ETH_P_IPV6);
> +
> ret = bpf_skb_net_hdr_pop(skb, off, len_diff);
> if (unlikely(ret < 0))
> return ret;
> + /* Match skb->protocol to new outer l3 protocol */
> + skb->protocol = proto;
> +
> if (skb_is_gso(skb)) {
> struct skb_shared_info *shinfo = skb_shinfo(skb);
> @@ -3578,10 +3593,14 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *,
> skb, s32, len_diff,
> u32, mode, u64, flags)
> {
> u32 len_cur, len_diff_abs = abs(len_diff);
> - u32 len_min = bpf_skb_net_base_len(skb);
> - u32 len_max = BPF_SKB_MAX_LEN;
> + u32 len_min, len_max = BPF_SKB_MAX_LEN;
> __be16 proto = skb->protocol;
> bool shrink = len_diff < 0;
> + union {
> + struct iphdr *v4;
> + struct ipv6hdr *v6;
> + unsigned char *hdr;
> + } ip;
> u32 off;
> int ret;
> @@ -3594,6 +3613,9 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *,
> skb, s32, len_diff,
> proto != htons(ETH_P_IPV6)))
> return -ENOTSUPP;
> + if (unlikely(shrink && !skb->encapsulation))
> + return -ENOTSUPP;
> +
> off = skb_mac_header_len(skb);
> switch (mode) {
> case BPF_ADJ_ROOM_NET:
> @@ -3605,6 +3627,14 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *,
> skb, s32, len_diff,
> return -ENOTSUPP;
> }
> + if (shrink) {
> + ip.hdr = skb_inner_network_header(skb);
> + if (ip.v4->version == 4)
> + len_min = sizeof(struct iphdr);
> + else
> + len_min = sizeof(struct ipv6hdr);
> + }
> +
> len_cur = skb->len - skb_network_offset(skb);
> if ((shrink && (len_diff_abs >= len_cur ||
> len_cur - len_diff_abs < len_min)) ||
> --
> 2.25.1
next prev parent reply other threads:[~2023-01-06 19:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 3:55 [PATCH bpf-next 0/2] bpf: Add ipip6 and ip6ip decap support for bpf_skb_adjust_room() Ziyang Xuan
2023-01-06 3:55 ` [PATCH bpf-next 1/2] " Ziyang Xuan
2023-01-06 19:55 ` sdf [this message]
2023-01-08 19:16 ` Willem de Bruijn
2023-01-09 9:19 ` Ziyang Xuan (William)
2023-01-09 13:32 ` Willem de Bruijn
2023-01-10 13:07 ` Ziyang Xuan (William)
2023-01-10 14:09 ` Willem de Bruijn
2023-01-11 2:37 ` Ziyang Xuan (William)
2023-01-06 3:55 ` [PATCH bpf-next 2/2] selftests/bpf: add ipip6 and ip6ip decap to test_tc_tunnel Ziyang Xuan
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=Y7h8yrOEkPuHkNpJ@google.com \
--to=sdf@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=song@kernel.org \
--cc=willemb@google.com \
--cc=william.xuanziyang@huawei.com \
--cc=yhs@fb.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).