From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0534AC47255 for ; Mon, 11 May 2020 19:06:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9180920736 for ; Mon, 11 May 2020 19:06:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="F7M6GHvD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731112AbgEKTGZ (ORCPT ); Mon, 11 May 2020 15:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729215AbgEKTGY (ORCPT ); Mon, 11 May 2020 15:06:24 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11D0AC061A0E for ; Mon, 11 May 2020 12:06:24 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id j5so12376947wrq.2 for ; Mon, 11 May 2020 12:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=QZEthipVzVjMeKxHpjAKSEM3ksmG1aLvz13r/CgdtzI=; b=F7M6GHvDBD0Dy9yb/TCTMOgThiMwv6EnAazuIF0KlP9eJwTau1TvINq+9FmwmyuTg1 oZO7srSSVj7j0BgfqtXitVJYQ/jPrE1/ekYAi4d8ZZrf2upsoM/YS1uKsy1LGLudQdx3 Ehwmv4wOEat5kIDbFshog0X4EQ9denYri3IRQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=QZEthipVzVjMeKxHpjAKSEM3ksmG1aLvz13r/CgdtzI=; b=tADAKaHbKrvzHA4ChZTG4edjPn8cs8/iDUnv7p1Hb3igJjL/VVA15RhcuJlt2+7rJJ sWUGGYCMxvkhXysqrC088Bw2/MI8h7OpQ10xouUeM7eW+Jt9Q1sRlBtQC4UjBzlJlYf4 KgqDxSM/020A6Kvv2r8OU2l1pX1jeeeHDuJgbld2lQHGLMWMOBj8saMycV5AcAJyrFcj pu/y5Yb8l0gqL63t1uvI7ZKHPNho2vCqcqGYZVLfASKA/DBPN6O6w2/doeRG73A48nAJ DGvtF4rDysFZbhCSTz/rmscGvasnUTOzKb3Xz9GySyTVecNryU6nJ6+fEVj2jWj/aijO R8Sw== X-Gm-Message-State: AGi0Pub4F2augYybXMWZ8BlZflXvJ16cO1Dsi/6di+SuwetYsj/hs28v lkEX8f50QlcWYNjkoMZyyCWreg== X-Google-Smtp-Source: APiQypKsnYNoRfI9lWAIqqCYoV5QKs3dC1DDBLJgfyMTQyzwdNKfzX/6hX3HHmJftuZl0sR5SM50aA== X-Received: by 2002:a5d:6283:: with SMTP id k3mr20192276wru.62.1589223982638; Mon, 11 May 2020 12:06:22 -0700 (PDT) Received: from cloudflare.com ([2a02:a310:c262:aa00:b35e:8938:2c2a:ba8b]) by smtp.gmail.com with ESMTPSA id i1sm18799199wrx.22.2020.05.11.12.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 12:06:22 -0700 (PDT) References: <20200511185218.1422406-1-jakub@cloudflare.com> <20200511185218.1422406-3-jakub@cloudflare.com> User-agent: mu4e 1.1.0; emacs 26.3 From: Jakub Sitnicki To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: dccp@vger.kernel.org, kernel-team@cloudflare.com, Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Eric Dumazet , Gerrit Renker , Jakub Kicinski , Andrii Nakryiko , Martin KaFai Lau , Marek Majkowski , Lorenz Bauer Subject: Re: [PATCH bpf-next v2 02/17] bpf: Introduce SK_LOOKUP program type with a dedicated attach point In-reply-to: <20200511185218.1422406-3-jakub@cloudflare.com> Date: Mon, 11 May 2020 21:06:21 +0200 Message-ID: <875zd2uw9e.fsf@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Mon, May 11, 2020 at 08:52 PM CEST, Jakub Sitnicki wrote: > Add a new program type BPF_PROG_TYPE_SK_LOOKUP and a dedicated attach type > called BPF_SK_LOOKUP. The new program kind is to be invoked by the > transport layer when looking up a socket for a received packet. > > When called, SK_LOOKUP program can select a socket that will receive the > packet. This serves as a mechanism to overcome the limits of what bind() > API allows to express. Two use-cases driving this work are: > > (1) steer packets destined to an IP range, fixed port to a socket > > 192.0.2.0/24, port 80 -> NGINX socket > > (2) steer packets destined to an IP address, any port to a socket > > 198.51.100.1, any port -> L7 proxy socket > > In its run-time context, program receives information about the packet that > triggered the socket lookup. Namely IP version, L4 protocol identifier, and > address 4-tuple. Context can be further extended to include ingress > interface identifier. > > To select a socket BPF program fetches it from a map holding socket > references, like SOCKMAP or SOCKHASH, and calls bpf_sk_assign(ctx, sk, ...) > helper to record the selection. Transport layer then uses the selected > socket as a result of socket lookup. > > This patch only enables the user to attach an SK_LOOKUP program to a > network namespace. Subsequent patches hook it up to run on local delivery > path in ipv4 and ipv6 stacks. > > Suggested-by: Marek Majkowski > Reviewed-by: Lorenz Bauer > Signed-off-by: Jakub Sitnicki > --- > > Notes: > v2: > - Make bpf_sk_assign reject sockets that don't use RCU freeing. > Update bpf_sk_assign docs accordingly. (Martin) > - Change bpf_sk_assign proto to take PTR_TO_SOCKET as argument. (Martin) > - Fix broken build when CONFIG_INET is not selected. (Martin) > - Rename bpf_sk_lookup{} src_/dst_* fields remote_/local_*. (Martin) I forgot to call out one more change in v2 to this patch: - Enforce BPF_SK_LOOKUP attach point on load & attach. (Martin) [...] From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Sitnicki Date: Mon, 11 May 2020 19:06:21 +0000 Subject: Re: [PATCH bpf-next v2 02/17] bpf: Introduce SK_LOOKUP program type with a dedicated attach point Message-Id: <875zd2uw9e.fsf@cloudflare.com> List-Id: References: <20200511185218.1422406-3-jakub@cloudflare.com> In-Reply-To: <20200511185218.1422406-3-jakub@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: dccp@vger.kernel.org On Mon, May 11, 2020 at 08:52 PM CEST, Jakub Sitnicki wrote: > Add a new program type BPF_PROG_TYPE_SK_LOOKUP and a dedicated attach type > called BPF_SK_LOOKUP. The new program kind is to be invoked by the > transport layer when looking up a socket for a received packet. > > When called, SK_LOOKUP program can select a socket that will receive the > packet. This serves as a mechanism to overcome the limits of what bind() > API allows to express. Two use-cases driving this work are: > > (1) steer packets destined to an IP range, fixed port to a socket > > 192.0.2.0/24, port 80 -> NGINX socket > > (2) steer packets destined to an IP address, any port to a socket > > 198.51.100.1, any port -> L7 proxy socket > > In its run-time context, program receives information about the packet that > triggered the socket lookup. Namely IP version, L4 protocol identifier, and > address 4-tuple. Context can be further extended to include ingress > interface identifier. > > To select a socket BPF program fetches it from a map holding socket > references, like SOCKMAP or SOCKHASH, and calls bpf_sk_assign(ctx, sk, ...) > helper to record the selection. Transport layer then uses the selected > socket as a result of socket lookup. > > This patch only enables the user to attach an SK_LOOKUP program to a > network namespace. Subsequent patches hook it up to run on local delivery > path in ipv4 and ipv6 stacks. > > Suggested-by: Marek Majkowski > Reviewed-by: Lorenz Bauer > Signed-off-by: Jakub Sitnicki > --- > > Notes: > v2: > - Make bpf_sk_assign reject sockets that don't use RCU freeing. > Update bpf_sk_assign docs accordingly. (Martin) > - Change bpf_sk_assign proto to take PTR_TO_SOCKET as argument. (Martin) > - Fix broken build when CONFIG_INET is not selected. (Martin) > - Rename bpf_sk_lookup{} src_/dst_* fields remote_/local_*. (Martin) I forgot to call out one more change in v2 to this patch: - Enforce BPF_SK_LOOKUP attach point on load & attach. (Martin) [...]