Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp658878pxb; Wed, 18 Aug 2021 10:54:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAj4jyWQWrCK3ljIEFG6u08P0HVK97jrCRpht4pnRK29lv1P0/5zb5kx/OwJNCH8DzPNi5 X-Received: by 2002:a05:6402:50:: with SMTP id f16mr11311351edu.346.1629309277256; Wed, 18 Aug 2021 10:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629309277; cv=none; d=google.com; s=arc-20160816; b=iSe37CZMcP6UEUu2+yZ4Fh/WZViLmMZ7Gz7cpAbeUCkB56zd0kDrHpRpKy7SIUCU1Y bSfwDDRuR+XAzsLbO5TKtLhR5Qb9EwowSZtYIxqOl9whXbI1E5n1M1DT//ieYOUWpRVw jbqS8E0Pz4ik+Xtmd7OcfeIj0G0a4gHNucQ4GdMPSoL8hi211bv/GgSsDKE+ivWGwN0U J0TvfPIrUZIw7DpoXgFhZKAgnA0K9/xT5aMr8L2SjTakARCNMI9FmMwwdcgiJhYmamR8 iv5tX5zThWluhY/lru9vAohLVL7j3UHSe6f188kg8ZpkoESfgqWm/B2cAbwvcNEoQ351 0aJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/tTcMpIIf4j3+hmj/k0U9mgeIvZffbOFheGSoEEvNug=; b=PndcIpQESAvXcCDGCqdoNicMUBszqLR/ufTVHPINxBeCy/8poNsovrfRAJ/lqc0ohh 25EaOK3QGauYauP65vaO9UtXd+75xJmrta54P/Tr1D3RyVtPbY+SDeMm6i2pwPiJ2FRd 8gnrh0d8g3Mbd8XbsXqybvRfjA7NLl+3qdDr1CuNuBBXywZhCT1gOAmDQXqJhuwClYrQ y9SgZZ9IENTvVacwnn5EpL37dITsoYI4gR/voubm6a9J6NhIBe7fWbqxssJSwRVFUWeh 15krGMoK1BW1C7lzlX0nak5HPQxS7JX3nXuJ7E96wKnRgDW7u58aZYu3akNuP3ltXV/2 s2Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sJ+2FQYr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si695351ejo.47.2021.08.18.10.54.08; Wed, 18 Aug 2021 10:54:37 -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=@kernel.org header.s=k20201202 header.b=sJ+2FQYr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233360AbhHRRuW (ORCPT + 99 others); Wed, 18 Aug 2021 13:50:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:55836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbhHRRt6 (ORCPT ); Wed, 18 Aug 2021 13:49:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1079D6113E; Wed, 18 Aug 2021 17:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629308963; bh=FTA7NBlPmQ87b+/3ICG0beyJjC2nFsi1xUEgFApxbCk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=sJ+2FQYrQ2bCno+p1yrzBV22IHyy1wsBrYDN2TOX82UgfhPi/kuV4tzntrSj1zF0f /+PVBLr6pDw2jeArkD9lFCI2R9mjQJBPeiLHhA+oggIrhjHEhYCGsiXwwrJMA43U/t OSgq8qPcmVrpMN+zA80Ow0PUfGm2MV8swg8i73PmgX6NgARU+7amPi4smieqYmkxQ+ DsSMI41E1JyojsihUwtUBoo8Sfe+deE0UrDHRTMRpH3F7XYgWa0uZ9DMaW3vsYM6kj E8m12Pfqa9G7hCOHM/Fnh6QyoZi58tJfFJE5MhR7tlJC5/dPRISdwNQdRXWcauXOB/ f/sPLIByLW/ng== Received: by mail-lf1-f45.google.com with SMTP id i28so6374445lfl.2; Wed, 18 Aug 2021 10:49:22 -0700 (PDT) X-Gm-Message-State: AOAM532NR2r2QLrk7BPUJgoAlZguFH4jNeYuW2Guw/oyVskBmuA3vRJ1 86VcryyeR4xldWrQqDC0YoJPL9iHTtVekGq0xnU= X-Received: by 2002:a05:6512:169d:: with SMTP id bu29mr7216860lfb.160.1629308961316; Wed, 18 Aug 2021 10:49:21 -0700 (PDT) MIME-Version: 1.0 References: <20210818105820.91894-1-liuxu623@gmail.com> <20210818105820.91894-2-liuxu623@gmail.com> In-Reply-To: <20210818105820.91894-2-liuxu623@gmail.com> From: Song Liu Date: Wed, 18 Aug 2021 10:49:10 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 1/2] bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS To: Xu Liu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S . Miller" , Jakub Kicinski , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 18, 2021 at 4:00 AM Xu Liu wrote: > > We'd like to be able to identify netns from sockops hooks > to accelerate local process communication form different netns. > > Signed-off-by: Xu Liu Acked-by: Song Liu > --- > net/core/filter.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/net/core/filter.c b/net/core/filter.c > index d70187ce851b..34938a537931 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4664,6 +4664,18 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = { > .arg1_type = ARG_PTR_TO_CTX_OR_NULL, > }; > > +BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) > +{ > + return __bpf_get_netns_cookie(ctx ? ctx->sk : NULL); > +} > + > +static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = { > + .func = bpf_get_netns_cookie_sock_ops, > + .gpl_only = false, > + .ret_type = RET_INTEGER, > + .arg1_type = ARG_PTR_TO_CTX_OR_NULL, > +}; > + > BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb) > { > struct sock *sk = sk_to_full_sk(skb->sk); > @@ -7445,6 +7457,8 @@ sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) > return &bpf_sk_storage_get_proto; > case BPF_FUNC_sk_storage_delete: > return &bpf_sk_storage_delete_proto; > + case BPF_FUNC_get_netns_cookie: > + return &bpf_get_netns_cookie_sock_ops_proto; > #ifdef CONFIG_INET > case BPF_FUNC_load_hdr_opt: > return &bpf_sock_ops_load_hdr_opt_proto; > -- > 2.28.0 >