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 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 1E49BC282D8 for ; Fri, 1 Feb 2019 23:00:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E48272086C for ; Fri, 1 Feb 2019 23:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726421AbfBAXAi (ORCPT ); Fri, 1 Feb 2019 18:00:38 -0500 Received: from www62.your-server.de ([213.133.104.62]:56600 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfBAXAi (ORCPT ); Fri, 1 Feb 2019 18:00:38 -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 1gphnZ-0005MF-71; Sat, 02 Feb 2019 00:00:37 +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 1gphnZ-000RCB-0Y; Sat, 02 Feb 2019 00:00:37 +0100 Subject: Re: [PATCH bpf-next v5 7/8] libbpf: Add a support for getting xdp prog id on ifindex To: Jakub Kicinski Cc: Maciej Fijalkowski , ast@kernel.org, netdev@vger.kernel.org, brouer@redhat.com, john.fastabend@gmail.com References: <20190201001954.4130-1-maciej.fijalkowski@intel.com> <20190201001954.4130-8-maciej.fijalkowski@intel.com> <5d963a81-6a22-b1c6-e2f6-b6734c6d78ff@iogearbox.net> <20190201134746.59386942@cakuba.hsd1.ca.comcast.net> From: Daniel Borkmann Message-ID: <28f7885f-1084-d790-fff2-96d4c4bf54a6@iogearbox.net> Date: Sat, 2 Feb 2019 00:00:36 +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: <20190201134746.59386942@cakuba.hsd1.ca.comcast.net> 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 10:47 PM, Jakub Kicinski wrote: > On Fri, 1 Feb 2019 22:43:39 +0100, Daniel Borkmann wrote: >> 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? > > I haven't tested to be honest, but I think Maciek got that right - > get_xdp_id_attr() should return IFLA_XDP_PROG_ID or a mode-specific > attr based on flags. And there is a check that only flag is set. > > Or do you mean retrieving all program ids with one dump? Yeah was thinking about the latter, but agree it's fine and probably cleaner this way here.