From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org,
prashantbhole.linux@gmail.com, jasowang@redhat.com,
brouer@redhat.com, toke@redhat.com, toshiaki.makita1@gmail.com,
daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org,
kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andriin@fb.com,
dsahern@gmail.com, David Ahern <dahern@digitalocean.com>
Subject: [PATCH v2 bpf-next 12/17] libbpf: Refactor get_xdp_info
Date: Thu, 23 Apr 2020 20:11:43 -0600 [thread overview]
Message-ID: <20200424021148.83015-13-dsahern@kernel.org> (raw)
In-Reply-To: <20200424021148.83015-1-dsahern@kernel.org>
From: David Ahern <dahern@digitalocean.com>
Move parsing of IFLA_XDP attribute to a helper that can be reused
for the new IFLA_XDP_EGRESS attribute.
Signed-off-by: David Ahern <dahern@digitalocean.com>
---
tools/lib/bpf/netlink.c | 43 +++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
index 0b709fd10bba..90ced689e53b 100644
--- a/tools/lib/bpf/netlink.c
+++ b/tools/lib/bpf/netlink.c
@@ -238,51 +238,60 @@ static int __dump_link_nlmsg(struct nlmsghdr *nlh,
return dump_link_nlmsg(cookie, ifi, tb);
}
-static int get_xdp_info(void *cookie, void *msg, struct nlattr **tb)
+static int process_xdp_attr(struct nlattr *tb, struct xdp_link_info *info)
{
struct nlattr *xdp_tb[IFLA_XDP_MAX + 1];
- struct xdp_id_md *xdp_id = cookie;
- struct ifinfomsg *ifinfo = msg;
int ret;
- if (xdp_id->ifindex && xdp_id->ifindex != ifinfo->ifi_index)
- return 0;
-
- if (!tb[IFLA_XDP])
- return 0;
-
- ret = libbpf_nla_parse_nested(xdp_tb, IFLA_XDP_MAX, tb[IFLA_XDP], NULL);
+ ret = libbpf_nla_parse_nested(xdp_tb, IFLA_XDP_MAX, tb, NULL);
if (ret)
return ret;
if (!xdp_tb[IFLA_XDP_ATTACHED])
return 0;
- xdp_id->info.attach_mode = libbpf_nla_getattr_u8(
- xdp_tb[IFLA_XDP_ATTACHED]);
+ info->attach_mode = libbpf_nla_getattr_u8(xdp_tb[IFLA_XDP_ATTACHED]);
- if (xdp_id->info.attach_mode == XDP_ATTACHED_NONE)
+ if (info->attach_mode == XDP_ATTACHED_NONE)
return 0;
if (xdp_tb[IFLA_XDP_PROG_ID])
- xdp_id->info.prog_id = libbpf_nla_getattr_u32(
+ info->prog_id = libbpf_nla_getattr_u32(
xdp_tb[IFLA_XDP_PROG_ID]);
if (xdp_tb[IFLA_XDP_SKB_PROG_ID])
- xdp_id->info.skb_prog_id = libbpf_nla_getattr_u32(
+ info->skb_prog_id = libbpf_nla_getattr_u32(
xdp_tb[IFLA_XDP_SKB_PROG_ID]);
if (xdp_tb[IFLA_XDP_DRV_PROG_ID])
- xdp_id->info.drv_prog_id = libbpf_nla_getattr_u32(
+ info->drv_prog_id = libbpf_nla_getattr_u32(
xdp_tb[IFLA_XDP_DRV_PROG_ID]);
if (xdp_tb[IFLA_XDP_HW_PROG_ID])
- xdp_id->info.hw_prog_id = libbpf_nla_getattr_u32(
+ info->hw_prog_id = libbpf_nla_getattr_u32(
xdp_tb[IFLA_XDP_HW_PROG_ID]);
return 0;
}
+static int get_xdp_info(void *cookie, void *msg, struct nlattr **tb)
+{
+ struct xdp_id_md *xdp_id = cookie;
+ struct ifinfomsg *ifinfo = msg;
+ int ret;
+
+ if (xdp_id->ifindex && xdp_id->ifindex != ifinfo->ifi_index)
+ return 0;
+
+ if (tb[IFLA_XDP]) {
+ ret = process_xdp_attr(tb[IFLA_XDP], &xdp_id->info);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
size_t info_size, __u32 flags)
{
--
2.21.1 (Apple Git-122.3)
next prev parent reply other threads:[~2020-04-24 2:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 2:11 [PATCH v2 bpf-next 00/17] net: Add support for XDP in egress path David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 01/17] net: Refactor convert_to_xdp_frame David Ahern
2020-04-24 7:27 ` Jesper Dangaard Brouer
2020-04-24 2:11 ` [PATCH v2 bpf-next 02/17] net: Move handling of IFLA_XDP attribute out of do_setlink David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 03/17] net: Add XDP setup and query commands for Tx programs David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 04/17] net: Add BPF_XDP_EGRESS as a bpf_attach_type David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 05/17] xdp: Add xdp_txq_info to xdp_buff David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 06/17] net: Add IFLA_XDP_EGRESS for XDP programs in the egress path David Ahern
2020-04-24 8:57 ` Toke Høiland-Jørgensen
2020-04-24 20:23 ` David Ahern
2020-04-24 9:56 ` Jesper Dangaard Brouer
2020-04-24 2:11 ` [PATCH v2 bpf-next 07/17] net: Rename do_xdp_generic to do_xdp_generic_rx David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 08/17] net: rename netif_receive_generic_xdp to do_generic_xdp_core David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 09/17] net: set XDP egress program on netdevice David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 10/17] net: Support xdp in the Tx path for packets as an skb David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 11/17] net: Support xdp in the Tx path for xdp_frames David Ahern
2020-04-24 2:11 ` David Ahern [this message]
2020-04-24 2:11 ` [PATCH v2 bpf-next 13/17] libbpf: Add egress XDP support David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 14/17] bpftool: Add support for XDP egress David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 15/17] selftest: Add test for xdp_egress David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 16/17] selftest: Add xdp_egress attach tests David Ahern
2020-04-24 2:11 ` [PATCH v2 bpf-next 17/17] samples/bpf: add XDP egress support to xdp1 David Ahern
2020-04-24 4:25 ` [PATCH v2 bpf-next 00/17] net: Add support for XDP in egress path David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200424021148.83015-13-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=brouer@redhat.com \
--cc=dahern@digitalocean.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=prashantbhole.linux@gmail.com \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=toshiaki.makita1@gmail.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).