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=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 647A6C282D7 for ; Wed, 30 Jan 2019 17:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37FD12087F for ; Wed, 30 Jan 2019 17:53:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mKzmj1s8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732609AbfA3Rxi (ORCPT ); Wed, 30 Jan 2019 12:53:38 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46720 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfA3Rxh (ORCPT ); Wed, 30 Jan 2019 12:53:37 -0500 Received: by mail-pl1-f195.google.com with SMTP id t13so137316ply.13 for ; Wed, 30 Jan 2019 09:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+7lBsxCwvXE3xH3QrJYKJHi5eyy18a25V0IybztOs+k=; b=mKzmj1s85AwfVctT1tWVyt4HoVjBgikAX4vUHDZljukeVfriVFwSf9DMgh3Am2bo7n z1yT50+Kq8LKZpvi6z3VqktrbZeHzwf6GPZhSPjOTEG+xUHTX5juSqbsx3Dg2XFeZUyD tjHLFztnUqSHefUKrypxhz4fHMVFDFu58dKIonV/CVvA6yX1TAlGpM3aK5//xoFgQ8hu vkq9YiOZRPyz07HoXDd+tzQVHpcDqTuFPtKsf3IoPuNAltlky86ZNq1ked4LwfLge8W+ muOHOv5zCeafaUzTdt3HFoB2MDAG7YluJMq8lWaKouXx+BoBwTRLHzbRUkQtXJ6zeBcy WBSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+7lBsxCwvXE3xH3QrJYKJHi5eyy18a25V0IybztOs+k=; b=FdzzTf/j+dg6TGySZ0BtC6jWSIkK2pdwy7uAag/2e3jFMVIvKJ9pnp7aLimicTtST4 sD7FWx0WvZeHkyH8Xs3JNzatYs+tZb2gkUAsT8aZzLzXc1SeAVUEddV1yl9yj4cUUM+T slDSxKsQTx/OkrU18gAIPBaNkM03QizTXQkq6ZJtk75Wyd310oDcoY00NW/zPsLsuLzq ko5IpkG9eMe/EMl9R0HAukPsi45yaxOHK6XB7+Q8S4vhwW73NN3EvwHzpGV6yYpMswLP OoWbFJhzKc/ntGdPPVDkMFpCXAvqu7L9SB4IFeCvgZWe+Jyf0QCPPzkaAbuCBr3mHP0x Z+Jw== X-Gm-Message-State: AJcUukdsxXw7B9w3esovMk3quo+SRz4wHDChSNxi89dj3dIv4u46+5P5 ZuFOl6SGMCXGZQ7e/8ri9x/zAFwQl3A= X-Google-Smtp-Source: ALg8bN5AWCaHomnGnBDWUA8QB/66cLHbCr5scYufSKnjvcdfhaehMttdoHFqbfIxaEr+S/rLt0lRIQ== X-Received: by 2002:a17:902:6b83:: with SMTP id p3mr30961654plk.118.1548870817003; Wed, 30 Jan 2019 09:53:37 -0800 (PST) Received: from localhost (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by smtp.gmail.com with ESMTPSA id h19sm2949274pfn.114.2019.01.30.09.53.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 09:53:36 -0800 (PST) Date: Wed, 30 Jan 2019 18:53:18 +0100 From: Maciej Fijalkowski To: John Fastabend Cc: daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org, jakub.kicinski@netronome.com, brouer@redhat.com Subject: Re: [PATCH bpf-next v4 6/7] libbpf: Add a support for getting xdp prog id on ifindex Message-ID: <20190130185318.000012f0@gmail.com> In-Reply-To: References: <20190128191613.11705-1-maciejromanfijalkowski@gmail.com> <20190128191613.11705-7-maciejromanfijalkowski@gmail.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, 28 Jan 2019 13:07:49 -0800 John Fastabend wrote: > On 1/28/19 11:16 AM, Maciej Fijalkowski wrote: > > From: Maciej Fijalkowski > > > > 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 > > --- > > small nit. > > > + > > +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_MODES; > > + 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); > > + *prog_id = xdp_id.id; > > just a nit but should we really set prog_id from user if there is > an error. Probably friendlier not to set caller data in error > case. > Agree, besides checking the return value from libbpf_nl_get_link() we should also check that we have assigned a value to xdp_id.id so that would mean we have gone through whole get_xdp_id(). I'll post a v5 within several hours with following check: if (!ret && xdp_id.id) *prog_id = xdp_id; Hope that makes sense. > > + > > + close(sock); > > + return ret; > > +} > > + > > int libbpf_nl_get_link(int sock, unsigned int nl_pid, > > libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie) > > { > > >