bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	Rumen Telbizov <rumen.telbizov@menlosecurity.com>
Cc: bpf@vger.kernel.org, Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: bpf_fib_lookup support for firewall mark
Date: Thu, 10 Jun 2021 19:41:21 -0600	[thread overview]
Message-ID: <64222254-eef3-f1c4-2b75-6ea1668a0ad5@gmail.com> (raw)
In-Reply-To: <7742f2a2-11a7-4d8f-d8c1-7787483a3935@iogearbox.net>

On 6/10/21 2:58 PM, Daniel Borkmann wrote:
>> But, I do not think the vlan data should be overloaded right now. We
>> still have an open design issue around supporting vlans on ingress
>> (XDP). One option is to allow the lookup to take the vlan as an input,
>> have the the bpf helper lookup the vlan device that goes with the
>> {device index, vlan} pair and use that as the input device. If we
>> overload the vlan_TCI with fwmark that prohibits this option.
> 
> I guess it's not overly pretty, but if all things break down and there's
> no other
> unused space, wouldn't it work if we opt into the vlan as input (instead
> of mark)
> in future via flag?
> 
>>> Moreover, there are 12 extra bytes used only as output for the
>>> smac/dmac.
>>> If the above works then maybe this opens up the opportunity to
>>> incorporate
>>> even more input parameters that way?
>>
>> I think that's going to be tricky since the macs are 6-byte arrays.

This should work (whitespace damaged on paste). It preserves the vlan
for potential later use, and we have 2 more 4-byte holes. Untested, not
even compiled. Can you try it out?

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 418b9b813d65..476bc81f3d04 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5954,8 +5954,20 @@ struct bpf_fib_lookup {
        /* output */
        __be16  h_vlan_proto;
        __be16  h_vlan_TCI;
-       __u8    smac[6];     /* ETH_ALEN */
-       __u8    dmac[6];     /* ETH_ALEN */
+
+       union {
+               /* input */
+               struct {
+                       __u32 fwmark;
+                       /* 2 4-byte holes for input */
+               };
+
+               /* output: source and dest mac */
+               struct {
+                       __u8    smac[6];     /* ETH_ALEN */
+                       __u8    dmac[6];     /* ETH_ALEN */
+               };
+       };
 };

 struct bpf_redir_neigh {

diff --git a/net/core/filter.c b/net/core/filter.c
index 239de1306de9..a9b4fd2a6657 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5303,6 +5303,7 @@ static int bpf_ipv4_fib_lookup(struct net *net,
struct bpf_fib_lookup *params,
        fl4.saddr = params->ipv4_src;
        fl4.fl4_sport = params->sport;
        fl4.fl4_dport = params->dport;
+       fl4.flowi4_mark = params->fwmark;
        fl4.flowi4_multipath_hash = 0;

        if (flags & BPF_FIB_LOOKUP_DIRECT) {
@@ -5315,7 +5316,6 @@ static int bpf_ipv4_fib_lookup(struct net *net,
struct bpf_fib_lookup *params,

                err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF);
        } else {
-               fl4.flowi4_mark = 0;
                fl4.flowi4_secid = 0;
                fl4.flowi4_tun_key.tun_id = 0;
                fl4.flowi4_uid = sock_net_uid(net, NULL);
@@ -5429,6 +5429,7 @@ static int bpf_ipv6_fib_lookup(struct net *net,
struct bpf_fib_lookup *params,
        fl6.saddr = *src;
        fl6.fl6_sport = params->sport;
        fl6.fl6_dport = params->dport;
+       fl6.flowi6_mark = params->fwmark;

        if (flags & BPF_FIB_LOOKUP_DIRECT) {
                u32 tbid = l3mdev_fib_table_rcu(dev) ? : RT_TABLE_MAIN;
@@ -5441,7 +5442,6 @@ static int bpf_ipv6_fib_lookup(struct net *net,
struct bpf_fib_lookup *params,
                err = ipv6_stub->fib6_table_lookup(net, tb, oif, &fl6, &res,
                                                   strict);
        } else {
-               fl6.flowi6_mark = 0;
                fl6.flowi6_secid = 0;
                fl6.flowi6_tun_key.tun_id = 0;
                fl6.flowi6_uid = sock_net_uid(net, NULL);


  reply	other threads:[~2021-06-11  1:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 22:59 bpf_fib_lookup support for firewall mark Rumen Telbizov
2021-06-09  1:21 ` David Ahern
2021-06-09 18:30   ` Rumen Telbizov
2021-06-09 21:56     ` Rumen Telbizov
2021-06-09 22:08       ` Daniel Borkmann
2021-06-10 14:37         ` David Ahern
2021-06-10 17:41           ` Rumen Telbizov
2021-06-10 18:52             ` David Ahern
2021-06-10 20:58               ` Daniel Borkmann
2021-06-11  1:41                 ` David Ahern [this message]
2021-06-11 17:32                   ` Rumen Telbizov
     [not found]                     ` <CA+FoirA-eAfux3PfxjgyO=--7duWCKuyeJfxWTdW6jiMWzShTw@mail.gmail.com>
2021-06-12  0:00                       ` Rumen Telbizov
2021-06-12  1:13                       ` David Ahern
2021-06-14 16:53                         ` Rumen Telbizov
2021-06-29 17:18                       ` Rumen Telbizov
2021-06-29 17:21                         ` Greg KH

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=64222254-eef3-f1c4-2b75-6ea1668a0ad5@gmail.com \
    --to=dsahern@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=rumen.telbizov@menlosecurity.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).