[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191218081050.10170-4-prashantbhole.linux@gmail.com>
Date: Wed, 18 Dec 2019 17:10:39 +0900
From: Prashant Bhole <prashantbhole.linux@...il.com>
To: "David S . Miller" <davem@...emloft.net>,
"Michael S . Tsirkin" <mst@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>
Cc: Prashant Bhole <prashantbhole.linux@...il.com>,
Jason Wang <jasowang@...hat.com>,
David Ahern <dsahern@...il.com>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
John Fastabend <john.fastabend@...il.com>,
Toshiaki Makita <toshiaki.makita1@...il.com>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andriin@...com>, netdev@...r.kernel.org,
David Ahern <dahern@...italocean.com>
Subject: [RFC net-next 03/14] libbpf: API for tx path XDP support
Adds new APIs for tx path XDP:
- bpf_set_link_xdp_tx_fd
- bpf_get_link_xdp_tx_id
- bpf_get_link_xdp_tx_info
Co-developed-by: David Ahern <dahern@...italocean.com>
Signed-off-by: David Ahern <dahern@...italocean.com>
Signed-off-by: Prashant Bhole <prashantbhole.linux@...il.com>
---
tools/lib/bpf/libbpf.h | 4 +++
tools/lib/bpf/libbpf.map | 3 ++
tools/lib/bpf/netlink.c | 77 +++++++++++++++++++++++++++++++++++-----
3 files changed, 75 insertions(+), 9 deletions(-)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 0dbf4bfba0c4..741e5fee61f6 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -447,6 +447,10 @@ LIBBPF_API int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags);
LIBBPF_API int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags);
LIBBPF_API int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
size_t info_size, __u32 flags);
+LIBBPF_API int bpf_set_link_xdp_tx_fd(int ifindex, int fd, __u32 flags);
+LIBBPF_API int bpf_get_link_xdp_tx_id(int ifindex, __u32 *prog_id, __u32 flags);
+LIBBPF_API int bpf_get_link_xdp_tx_info(int ifindex, struct xdp_link_info *info,
+ size_t info_size, __u32 flags);
struct perf_buffer;
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 8ddc2c40e482..28597c2a24c4 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -207,4 +207,7 @@ LIBBPF_0.0.6 {
bpf_program__size;
btf__find_by_name_kind;
libbpf_find_vmlinux_btf_id;
+ bpf_set_link_xdp_tx_fd;
+ bpf_get_link_xdp_tx_id;
+ bpf_get_link_xdp_tx_info;
} LIBBPF_0.0.5;
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
index 5065c1aa1061..eca6e80df697 100644
--- a/tools/lib/bpf/netlink.c
+++ b/tools/lib/bpf/netlink.c
@@ -129,7 +129,7 @@ static int bpf_netlink_recv(int sock, __u32 nl_pid, int seq,
return ret;
}
-int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
+static int __bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags, bool tx)
{
int sock, seq = 0, ret;
struct nlattr *nla, *nla_xdp;
@@ -156,7 +156,11 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
/* started nested attribute for XDP */
nla = (struct nlattr *)(((char *)&req)
+ NLMSG_ALIGN(req.nh.nlmsg_len));
- nla->nla_type = NLA_F_NESTED | IFLA_XDP;
+ nla->nla_type = NLA_F_NESTED;
+ if (tx)
+ nla->nla_type |= IFLA_XDP_TX;
+ else
+ nla->nla_type |= IFLA_XDP;
nla->nla_len = NLA_HDRLEN;
/* add XDP fd */
@@ -188,6 +192,16 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
return ret;
}
+int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
+{
+ return __bpf_set_link_xdp_fd(ifindex, fd, flags, false);
+}
+
+int bpf_set_link_xdp_tx_fd(int ifindex, int fd, __u32 flags)
+{
+ return __bpf_set_link_xdp_fd(ifindex, fd, flags, true);
+}
+
static int __dump_link_nlmsg(struct nlmsghdr *nlh,
libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
{
@@ -203,20 +217,23 @@ 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 __get_xdp_info(void *cookie, void *msg, struct nlattr **tb, bool tx)
{
struct nlattr *xdp_tb[IFLA_XDP_MAX + 1];
struct xdp_id_md *xdp_id = cookie;
struct ifinfomsg *ifinfo = msg;
+ struct nlattr *attr;
int ret;
if (xdp_id->ifindex && xdp_id->ifindex != ifinfo->ifi_index)
return 0;
- if (!tb[IFLA_XDP])
- return 0;
+ if (tx)
+ attr = tb[IFLA_XDP_TX];
+ else
+ attr = tb[IFLA_XDP];
- ret = libbpf_nla_parse_nested(xdp_tb, IFLA_XDP_MAX, tb[IFLA_XDP], NULL);
+ ret = libbpf_nla_parse_nested(xdp_tb, IFLA_XDP_MAX, attr, NULL);
if (ret)
return ret;
@@ -248,8 +265,22 @@ static int get_xdp_info(void *cookie, void *msg, struct nlattr **tb)
return 0;
}
-int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
- size_t info_size, __u32 flags)
+static int get_xdp_tx_info(void *cookie, void *msg, struct nlattr **tb)
+{
+ if (!tb[IFLA_XDP_TX])
+ return 0;
+ return __get_xdp_info(cookie, msg, tb, true);
+}
+
+static int get_xdp_info(void *cookie, void *msg, struct nlattr **tb)
+{
+ if (!tb[IFLA_XDP])
+ return 0;
+ return __get_xdp_info(cookie, msg, tb, false);
+}
+
+static int __bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
+ size_t info_size, __u32 flags, bool tx)
{
struct xdp_id_md xdp_id = {};
int sock, ret;
@@ -272,7 +303,11 @@ int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
xdp_id.ifindex = ifindex;
xdp_id.flags = flags;
- ret = libbpf_nl_get_link(sock, nl_pid, get_xdp_info, &xdp_id);
+ if (tx)
+ ret = libbpf_nl_get_link(sock, nl_pid, get_xdp_tx_info,
+ &xdp_id);
+ else
+ ret = libbpf_nl_get_link(sock, nl_pid, get_xdp_info, &xdp_id);
if (!ret) {
size_t sz = min(info_size, sizeof(xdp_id.info));
@@ -284,6 +319,18 @@ int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
return ret;
}
+int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
+ size_t info_size, __u32 flags)
+{
+ return __bpf_get_link_xdp_info(ifindex, info, info_size, flags, false);
+}
+
+int bpf_get_link_xdp_tx_info(int ifindex, struct xdp_link_info *info,
+ size_t info_size, __u32 flags)
+{
+ return __bpf_get_link_xdp_info(ifindex, info, info_size, flags, true);
+}
+
static __u32 get_xdp_id(struct xdp_link_info *info, __u32 flags)
{
if (info->attach_mode != XDP_ATTACHED_MULTI)
@@ -310,6 +357,18 @@ int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags)
return ret;
}
+int bpf_get_link_xdp_tx_id(int ifindex, __u32 *prog_id, __u32 flags)
+{
+ struct xdp_link_info info;
+ int ret;
+
+ ret = bpf_get_link_xdp_tx_info(ifindex, &info, sizeof(info), flags);
+ if (!ret)
+ *prog_id = get_xdp_id(&info, flags);
+
+ return ret;
+}
+
int libbpf_nl_get_link(int sock, unsigned int nl_pid,
libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
{
--
2.21.0
Powered by blists - more mailing lists