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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 2A11CC282D8 for ; Fri, 1 Feb 2019 21:43:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEE6920863 for ; Fri, 1 Feb 2019 21:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726284AbfBAVno (ORCPT ); Fri, 1 Feb 2019 16:43:44 -0500 Received: from www62.your-server.de ([213.133.104.62]:41804 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725797AbfBAVno (ORCPT ); Fri, 1 Feb 2019 16:43:44 -0500 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gpgb8-0000f6-Ei; Fri, 01 Feb 2019 22:43:42 +0100 Received: from [178.197.249.18] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1gpgb8-0000Ua-7M; Fri, 01 Feb 2019 22:43:42 +0100 Subject: Re: [PATCH bpf-next v5 7/8] libbpf: Add a support for getting xdp prog id on ifindex To: Maciej Fijalkowski , ast@kernel.org Cc: netdev@vger.kernel.org, jakub.kicinski@netronome.com, brouer@redhat.com, john.fastabend@gmail.com References: <20190201001954.4130-1-maciej.fijalkowski@intel.com> <20190201001954.4130-8-maciej.fijalkowski@intel.com> From: Daniel Borkmann Message-ID: <5d963a81-6a22-b1c6-e2f6-b6734c6d78ff@iogearbox.net> Date: Fri, 1 Feb 2019 22:43:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190201001954.4130-8-maciej.fijalkowski@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25347/Fri Feb 1 12:05:35 2019) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/01/2019 01:19 AM, Maciej Fijalkowski wrote: > Since we have a dedicated netlink attributes for xdp setup on a > particular interface, it is now possible to retrieve the program id that > is currently attached to the interface. The use case is targeted for > sample xdp programs, which will store the program id just after loading > bpf program onto iface. On shutdown, the sample will make sure that it > can unload the program by querying again the iface and verifying that > both program id's matches. > > Signed-off-by: Maciej Fijalkowski > Reviewed-by: Jakub Kicinski [...] > +int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags) > +{ > + struct xdp_id_md xdp_id = {}; > + int sock, ret; > + __u32 nl_pid; > + __u32 mask; > + > + if (flags & ~XDP_FLAGS_MASK) > + return -EINVAL; > + > + /* Check whether the single {HW,DRV,SKB} mode is set */ > + flags &= (XDP_FLAGS_SKB_MODE | XDP_FLAGS_DRV_MODE | XDP_FLAGS_HW_MODE); > + mask = flags - 1; > + if (flags && flags & mask) > + return -EINVAL; > + > + sock = libbpf_netlink_open(&nl_pid); > + if (sock < 0) > + return sock; > + > + xdp_id.ifindex = ifindex; > + xdp_id.flags = flags; > + > + ret = libbpf_nl_get_link(sock, nl_pid, get_xdp_id, &xdp_id); > + if (!ret) > + *prog_id = xdp_id.id; > + > + close(sock); > + return ret; > +} Btw, is anyone going to follow-up on XDP_ATTACHED_MULTI support as well later on? Thanks, Daniel