Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1744224ybk; Thu, 21 May 2020 14:16:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2i//NFaZzaros21eO02L1d+7XU4I1PF52cF9nSP0OwdIIpGieDHZwjgy2fZ1X6XaSaGlY X-Received: by 2002:aa7:db4c:: with SMTP id n12mr555244edt.99.1590095803397; Thu, 21 May 2020 14:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590095803; cv=none; d=google.com; s=arc-20160816; b=PrUv/OcTPHycvD/ci14PYpV6GTQvtUre3G7cKepeWCFlvdoL58f4pepNCU7Cc/fZiZ mgrA7uG4Mzm4FCPxs+pR6Ehf8sSVtUT8NBepqvR0R38f1AgDBu2oXdaIz+xaFUk0klzQ a9VwKfCpLWuneMNd7m9ZcOJXhadOw98H/VsixiW5D1F9AePd1iaTGwYwJ/s8Mbjx+YbU UFb408aqrFf1nw15bF+2nj0IJdo9ZSfCdksL54pjtb/R94/T2CaK61ebOI0MR/5OHekw VeLv8Spzkil+RG99kExhTRtIhsMOiKfQVnNcYq3+DsEPhH049Y7msi11MlcnYD4od1hy Umbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=semgcmJd0ZZ9q+OBcE/cjzRQcM4RABCN/d9XODlBjRA=; b=Exo00RXY9G1tFxR8WCSZqtdjaN/GOOUiR//2WSFVTeijJN520SBL55Ohz+DB47VO4r SdCaz03ihVfd6fgNgtjbxHDW6k4k32whpJcAKA6zXjZoP3Otj7+y/wsBG/MCiIA3wXjL Of2Kjx3xinnk5rqWXC1xJ5q6qAHutQ+q2OeLvtqk8EHD1Y610CIn/PXfy9F1HptLKr56 8ltdnuPcXSpvTJseTkbnjtjsoX6fHlUM/QIx2ui3ODmhRy8c8heb9M44v+AFsS3NQsr+ mELPeKJ05nQwElTwHOAJ+pEAWsVdLpUmop91XhIb24KTh79OTVe4SKrOQSgj2IkeqB0e H0DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="TlYSTVO/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si3591441edq.435.2020.05.21.14.16.20; Thu, 21 May 2020 14:16:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="TlYSTVO/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730581AbgEUVOf (ORCPT + 99 others); Thu, 21 May 2020 17:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgEUVOf (ORCPT ); Thu, 21 May 2020 17:14:35 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D542C05BD43 for ; Thu, 21 May 2020 14:14:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d69so2641745ybc.22 for ; Thu, 21 May 2020 14:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=semgcmJd0ZZ9q+OBcE/cjzRQcM4RABCN/d9XODlBjRA=; b=TlYSTVO/Y8u4XRBQIPQXsEu5jGML3Ds00FRBHt//Mxa9a2AaScCsqVRxFRWHdU2drB Oc3DmuiIsF0NWvZfGexbksIlGcw3bTNLnB7Dm2vDAvLHR0EzpVD44ZglXDaidxyyv29c imLD0eJU1+IZelhBUQDzp6FhQKefWoXPsjeRjoVeWZMYpuTceYBZXqwe1usyba7Mo5fd lxPYQMiD5umdUV8hOrVNEke3LLE++/LulrbW2iidAoyzCqUm37kUbnc4WgFvpmV98zoy lJZHfQ5EpPOmS9n4KMjq3spWJA07pHcS/UJ6p83Krdx6oi+LWBGpfxXoxwUURqVeV0T5 SBKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=semgcmJd0ZZ9q+OBcE/cjzRQcM4RABCN/d9XODlBjRA=; b=Du3WQmXTzCaRJBRsECN+wvcP1vUAAoAYmIU7RpQetLUSxDEvcG9oMauOVZnruRkXF5 msWwxirbePCQfwFYCTKOVDSCbMbZs3VGz8UauV2BkGtiykeRnWtuQvk78Vj/N5adNmBr O+s+yIrtyI5VoNP7YXVUMLG5aTWevWxVDmZFkgIO/S/hD6Wn6u0QPdJEq78S6FPBdLbD f2DB8i/Akbxxo5MHKCtvjwM7pceXeydhHNI7VrBeeUHOBZ54AzG9JdE2i8oXsJoTG+o2 wag1p8wBAlQhOSHGrLh611/N1pUvCVANIfNRK3BsN66kj3uKR4rqQPPJcTp/4642vOZ1 qVmA== X-Gm-Message-State: AOAM531vGP7JPAt0oorqUUwQtBWYjhgSFaJsGSyux5GjP4kalKvDscor riJJhNsMqoHle+qKAjQH3CDgMyU= X-Received: by 2002:a25:cbc9:: with SMTP id b192mr18457440ybg.132.1590095674239; Thu, 21 May 2020 14:14:34 -0700 (PDT) Date: Thu, 21 May 2020 14:14:32 -0700 In-Reply-To: <20200521125247.30178-1-fejes@inf.elte.hu> Message-Id: <20200521211432.GC49942@google.com> Mime-Version: 1.0 References: <20200521125247.30178-1-fejes@inf.elte.hu> Subject: Re: [PATCH net-next] Extending bpf_setsockopt with SO_BINDTODEVICE sockopt From: sdf@google.com To: Ferenc Fejes Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Martin KaFai Lau , Lawrence Brakmo , "David S . Miller" Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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.