From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mail.toke.dk (Postfix) with ESMTPS id 9672C982C95 for ; Tue, 28 Jun 2022 21:49:26 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=WN5FZGdj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445766; x=1687981766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KP8+M2ZNDj+bGLuKjD0DKVm/0e+VNysNArAnGfFt/hk=; b=WN5FZGdjekodivWCOgYqTuCn6SsnrCLbnhn7UJ4FPETHzE6yA6OLSTdz sfbe8Glua901t5+80kpHufCSr5VE9w52Ucwodss3t6VlAOKNWpffNyVyT bN1Ot1N3p8z0Pth53r8RzZd/GEKTixNvWSB5KU1WWsFUfg2yTRec/RF6D 8KsnibrzR00UCkj8Ihd+z5bGYDY31hIHQUD7wGxEEbZn5LhNhbUddCvnv YedpZnirCM17HVZkUS8YaO+Z9z/HK2jR80oHpz1xBeN2Dq57itJHHvY9W oUoBQexanyWETdHRf0fYPjh+9cjoC7xz+mJrMtnM5xzPO3GRUTZw/A17j g==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262242827" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="262242827" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="680182439" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jun 2022 12:49:10 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9B022013; Tue, 28 Jun 2022 20:49:08 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:31 +0200 Message-Id: <20220628194812.1453059-12-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: XIJH3JCKSW7UEHGGSIFV26LT6OXAYHUO X-Message-ID-Hash: XIJH3JCKSW7UEHGGSIFV26LT6OXAYHUO X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 11/52] libbpf: factor out __bpf_set_link_xdp_fd_replace() args into a struct List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Its argument list already consists of 4 entries, and there are more to be added. It's convenient to add new opts as they are already being passed using structs, but at the end the mentioned function take all the opts one by one. Place them into a local struct which will satisfy every initial call site, so it will be now a matter of adding a new field and a corresponding nlattr_add() to handle a new opt. Signed-off-by: Alexander Lobakin --- tools/lib/bpf/netlink.c | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index cbc8967d5402..3a25178d0d12 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -230,8 +230,15 @@ static int libbpf_netlink_send_recv(struct libbpf_nla_req *req, return ret; } -static int __bpf_set_link_xdp_fd_replace(int ifindex, int fd, int old_fd, - __u32 flags) +struct __bpf_set_link_xdp_fd_opts { + int ifindex; + int fd; + int old_fd; + __u32 flags; +}; + +static int +__bpf_set_link_xdp_fd_replace(const struct __bpf_set_link_xdp_fd_opts *opts) { struct nlattr *nla; int ret; @@ -242,22 +249,23 @@ static int __bpf_set_link_xdp_fd_replace(int ifindex, int fd, int old_fd, req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; req.nh.nlmsg_type = RTM_SETLINK; req.ifinfo.ifi_family = AF_UNSPEC; - req.ifinfo.ifi_index = ifindex; + req.ifinfo.ifi_index = opts->ifindex; nla = nlattr_begin_nested(&req, IFLA_XDP); if (!nla) return -EMSGSIZE; - ret = nlattr_add(&req, IFLA_XDP_FD, &fd, sizeof(fd)); + ret = nlattr_add(&req, IFLA_XDP_FD, &opts->fd, sizeof(opts->fd)); if (ret < 0) return ret; - if (flags) { - ret = nlattr_add(&req, IFLA_XDP_FLAGS, &flags, sizeof(flags)); + if (opts->flags) { + ret = nlattr_add(&req, IFLA_XDP_FLAGS, &opts->flags, + sizeof(opts->flags)); if (ret < 0) return ret; } - if (flags & XDP_FLAGS_REPLACE) { - ret = nlattr_add(&req, IFLA_XDP_EXPECTED_FD, &old_fd, - sizeof(old_fd)); + if (opts->flags & XDP_FLAGS_REPLACE) { + ret = nlattr_add(&req, IFLA_XDP_EXPECTED_FD, &opts->old_fd, + sizeof(opts->old_fd)); if (ret < 0) return ret; } @@ -268,18 +276,23 @@ static int __bpf_set_link_xdp_fd_replace(int ifindex, int fd, int old_fd, int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts *opts) { - int old_prog_fd, err; + struct __bpf_set_link_xdp_fd_opts sl_opts = { + .ifindex = ifindex, + .flags = flags, + .fd = prog_fd, + }; + int err; if (!OPTS_VALID(opts, bpf_xdp_attach_opts)) return libbpf_err(-EINVAL); - old_prog_fd = OPTS_GET(opts, old_prog_fd, 0); - if (old_prog_fd) + sl_opts.old_fd = OPTS_GET(opts, old_prog_fd, 0); + if (sl_opts.old_fd) flags |= XDP_FLAGS_REPLACE; else - old_prog_fd = -1; + sl_opts.old_fd = -1; - err = __bpf_set_link_xdp_fd_replace(ifindex, prog_fd, old_prog_fd, flags); + err = __bpf_set_link_xdp_fd_replace(&sl_opts); return libbpf_err(err); } @@ -291,25 +304,36 @@ int bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts *o int bpf_set_link_xdp_fd_opts(int ifindex, int fd, __u32 flags, const struct bpf_xdp_set_link_opts *opts) { - int old_fd = -1, ret; + struct __bpf_set_link_xdp_fd_opts sl_opts = { + .ifindex = ifindex, + .flags = flags, + .old_fd = -1, + .fd = fd, + }; + int ret; if (!OPTS_VALID(opts, bpf_xdp_set_link_opts)) return libbpf_err(-EINVAL); if (OPTS_HAS(opts, old_fd)) { - old_fd = OPTS_GET(opts, old_fd, -1); + sl_opts.old_fd = OPTS_GET(opts, old_fd, -1); flags |= XDP_FLAGS_REPLACE; } - ret = __bpf_set_link_xdp_fd_replace(ifindex, fd, old_fd, flags); + ret = __bpf_set_link_xdp_fd_replace(&sl_opts); return libbpf_err(ret); } int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) { + struct __bpf_set_link_xdp_fd_opts sl_opts = { + .ifindex = ifindex, + .flags = flags, + .fd = fd, + }; int ret; - ret = __bpf_set_link_xdp_fd_replace(ifindex, fd, 0, flags); + ret = __bpf_set_link_xdp_fd_replace(&sl_opts); return libbpf_err(ret); } -- 2.36.1