From: sdf@google.com
To: Ferenc Fejes <fejes@inf.elte.hu>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Lawrence Brakmo <brakmo@fb.com>,
"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next] Extending bpf_setsockopt with SO_BINDTODEVICE sockopt
Date: Thu, 21 May 2020 14:14:32 -0700 [thread overview]
Message-ID: <20200521211432.GC49942@google.com> (raw)
In-Reply-To: <20200521125247.30178-1-fejes@inf.elte.hu>
On 05/21, Ferenc Fejes wrote:
> This option makes possible to programatically bind sockets to netdevices.
> With the help of this option sockets of VRF unaware applications
> could be distributed between multiple VRFs with eBPF sock_ops program.
> This let the applications benefit from the multiple possible routes.
> Signed-off-by: Ferenc Fejes <fejes@inf.elte.hu>
> ---
> net/core/filter.c | 39 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 38 insertions(+), 1 deletion(-)
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 822d662f97ef..25dac75bfc5d 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4248,6 +4248,9 @@ static const struct bpf_func_proto
> bpf_get_socket_uid_proto = {
> static int _bpf_setsockopt(struct sock *sk, int level, int optname,
> char *optval, int optlen, u32 flags)
> {
> + char devname[IFNAMSIZ];
> + struct net *net;
> + int ifindex;
> int ret = 0;
> int val;
> @@ -4257,7 +4260,7 @@ static int _bpf_setsockopt(struct sock *sk, int
> level, int optname,
> sock_owned_by_me(sk);
> if (level == SOL_SOCKET) {
> - if (optlen != sizeof(int))
> + if (optlen != sizeof(int) && optname != SO_BINDTODEVICE)
> return -EINVAL;
> val = *((int *)optval);
> @@ -4298,6 +4301,40 @@ static int _bpf_setsockopt(struct sock *sk, int
> level, int optname,
> sk_dst_reset(sk);
> }
> break;
> + case SO_BINDTODEVICE:
> + ret = -ENOPROTOOPT;
> +#ifdef CONFIG_NETDEVICES
Any specific reason you're not reusing sock_setbindtodevice or at least
sock_setbindtodevice_locked here? I think, historically, we've
reimplemented some of the sockopts because they were 'easy' (i.e.
were just setting a flag in the socket), this one looks more involved.
I'd suggest, add an optional 'lock_sk' argument to sock_setbindtodevice,
call it with 'true' from real setsockopt, and call it with 'false'
here.
And, as Andrii pointed out, it would be nice to have a selftest
that exercises this new option.
next prev parent reply other threads:[~2020-05-21 21:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 12:52 [PATCH net-next] Extending bpf_setsockopt with SO_BINDTODEVICE sockopt Ferenc Fejes
2020-05-21 19:09 ` Andrii Nakryiko
2020-05-21 21:14 ` sdf [this message]
2020-05-21 21:55 ` Ferenc Fejes
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=20200521211432.GC49942@google.com \
--to=sdf@google.com \
--cc=bpf@vger.kernel.org \
--cc=brakmo@fb.com \
--cc=davem@davemloft.net \
--cc=fejes@inf.elte.hu \
--cc=kafai@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).