Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: add the capability to specify netlink proto in libbpf_netlink_send_recv

This is a preliminary patch in order to introduce netlink_generic
protocol support to libbpf.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/7878a54667e74afeec3ee519999c044bd514b44c.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Lorenzo Bianconi and committed by
Alexei Starovoitov
8f166931 0ae0cb2b

+12 -10
+12 -10
tools/lib/bpf/netlink.c
··· 41 41 struct xdp_link_info info; 42 42 }; 43 43 44 - static int libbpf_netlink_open(__u32 *nl_pid) 44 + static int libbpf_netlink_open(__u32 *nl_pid, int proto) 45 45 { 46 46 struct sockaddr_nl sa; 47 47 socklen_t addrlen; ··· 51 51 memset(&sa, 0, sizeof(sa)); 52 52 sa.nl_family = AF_NETLINK; 53 53 54 - sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); 54 + sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, proto); 55 55 if (sock < 0) 56 56 return -errno; 57 57 ··· 212 212 } 213 213 214 214 static int libbpf_netlink_send_recv(struct libbpf_nla_req *req, 215 - __dump_nlmsg_t parse_msg, 215 + int proto, __dump_nlmsg_t parse_msg, 216 216 libbpf_dump_nlmsg_t parse_attr, 217 217 void *cookie) 218 218 { 219 219 __u32 nl_pid = 0; 220 220 int sock, ret; 221 221 222 - sock = libbpf_netlink_open(&nl_pid); 222 + sock = libbpf_netlink_open(&nl_pid, proto); 223 223 if (sock < 0) 224 224 return sock; 225 225 ··· 271 271 } 272 272 nlattr_end_nested(&req, nla); 273 273 274 - return libbpf_netlink_send_recv(&req, NULL, NULL, NULL); 274 + return libbpf_netlink_send_recv(&req, NETLINK_ROUTE, NULL, NULL, NULL); 275 275 } 276 276 277 277 int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts *opts) ··· 382 382 xdp_id.ifindex = ifindex; 383 383 xdp_id.flags = xdp_flags; 384 384 385 - err = libbpf_netlink_send_recv(&req, __dump_link_nlmsg, 385 + err = libbpf_netlink_send_recv(&req, NETLINK_ROUTE, __dump_link_nlmsg, 386 386 get_xdp_info, &xdp_id); 387 387 if (err) 388 388 return libbpf_err(err); ··· 493 493 if (ret < 0) 494 494 return ret; 495 495 496 - return libbpf_netlink_send_recv(&req, NULL, NULL, NULL); 496 + return libbpf_netlink_send_recv(&req, NETLINK_ROUTE, NULL, NULL, NULL); 497 497 } 498 498 499 499 static int tc_qdisc_create_excl(struct bpf_tc_hook *hook) ··· 673 673 674 674 info.opts = opts; 675 675 676 - ret = libbpf_netlink_send_recv(&req, get_tc_info, NULL, &info); 676 + ret = libbpf_netlink_send_recv(&req, NETLINK_ROUTE, get_tc_info, NULL, 677 + &info); 677 678 if (ret < 0) 678 679 return libbpf_err(ret); 679 680 if (!info.processed) ··· 740 739 return ret; 741 740 } 742 741 743 - return libbpf_netlink_send_recv(&req, NULL, NULL, NULL); 742 + return libbpf_netlink_send_recv(&req, NETLINK_ROUTE, NULL, NULL, NULL); 744 743 } 745 744 746 745 int bpf_tc_detach(const struct bpf_tc_hook *hook, ··· 805 804 806 805 info.opts = opts; 807 806 808 - ret = libbpf_netlink_send_recv(&req, get_tc_info, NULL, &info); 807 + ret = libbpf_netlink_send_recv(&req, NETLINK_ROUTE, get_tc_info, NULL, 808 + &info); 809 809 if (ret < 0) 810 810 return libbpf_err(ret); 811 811 if (!info.processed)