lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Sat, 28 Jan 2023 13:48:43 +0100
From:   Lorenzo Bianconi <lorenzo@...nel.org>
To:     Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc:     bpf@...r.kernel.org, netdev@...r.kernel.org, ast@...nel.org,
        daniel@...earbox.net, andrii@...nel.org, davem@...emloft.net,
        kuba@...nel.org, hawk@...nel.org, pabeni@...hat.com,
        edumazet@...gle.com, toke@...hat.com, memxor@...il.com,
        alardam@...il.com, saeedm@...dia.com, anthony.l.nguyen@...el.com,
        gospo@...adcom.com, vladimir.oltean@....com, nbd@....name,
        john@...ozen.org, leon@...nel.org, simon.horman@...igine.com,
        aelior@...vell.com, christophe.jaillet@...adoo.fr,
        ecree.xilinx@...il.com, mst@...hat.com, bjorn@...nel.org,
        magnus.karlsson@...el.com, maciej.fijalkowski@...el.com,
        intel-wired-lan@...ts.osuosl.org, lorenzo.bianconi@...hat.com,
        martin.lau@...ux.dev
Subject: Re: [PATCH v3 bpf-next 5/8] libbpf: add API to get XDP/XSK supported
 features

> On Thu, Jan 26, 2023 at 4:59 AM Lorenzo Bianconi <lorenzo@...nel.org> wrote:
> >
> > Extend bpf_xdp_query routine in order to get XDP/XSK supported features
> > of netdev over route netlink interface.
> > Extend libbpf netlink implementation in order to support netlink_generic
> > protocol.
> >
> > Co-developed-by: Kumar Kartikeya Dwivedi <memxor@...il.com>
> > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@...il.com>
> > Co-developed-by: Marek Majtyka <alardam@...il.com>
> > Signed-off-by: Marek Majtyka <alardam@...il.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@...nel.org>
> > ---
> >  tools/lib/bpf/libbpf.h  |  3 +-
> >  tools/lib/bpf/netlink.c | 99 +++++++++++++++++++++++++++++++++++++++++
> >  tools/lib/bpf/nlattr.h  | 12 +++++
> >  3 files changed, 113 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index 898db26e42e9..29cb7040fa77 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -982,9 +982,10 @@ struct bpf_xdp_query_opts {
> >         __u32 hw_prog_id;       /* output */
> >         __u32 skb_prog_id;      /* output */
> >         __u8 attach_mode;       /* output */
> > +       __u64 fflags;           /* output */
> >         size_t :0;
> >  };
> > -#define bpf_xdp_query_opts__last_field attach_mode
> > +#define bpf_xdp_query_opts__last_field fflags
> 
> is "fflags" an obvious name in this context? I'd expect
> "feature_flags", especially that there are already "flags". Is saving
> a few characters worth the confusion?

ack, I will fix it.

> 
> 
> >
> >  LIBBPF_API int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags,
> >                               const struct bpf_xdp_attach_opts *opts);
> > diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
> > index d2468a04a6c3..674e4d61e67e 100644
> > --- a/tools/lib/bpf/netlink.c
> > +++ b/tools/lib/bpf/netlink.c
> > @@ -9,6 +9,7 @@
> >  #include <linux/if_ether.h>
> >  #include <linux/pkt_cls.h>
> >  #include <linux/rtnetlink.h>
> > +#include <linux/netdev.h>
> >  #include <sys/socket.h>
> >  #include <errno.h>
> >  #include <time.h>
> > @@ -39,6 +40,12 @@ struct xdp_id_md {
> >         int ifindex;
> >         __u32 flags;
> >         struct xdp_link_info info;
> > +       __u64 fflags;
> > +};
> > +
> > +struct xdp_features_md {
> > +       int ifindex;
> > +       __u64 flags;
> >  };
> >
> >  static int libbpf_netlink_open(__u32 *nl_pid, int proto)
> 
> [...]
> 
> >  int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
> >  {
> >         struct libbpf_nla_req req = {
> > @@ -393,6 +460,38 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
> >         OPTS_SET(opts, skb_prog_id, xdp_id.info.skb_prog_id);
> >         OPTS_SET(opts, attach_mode, xdp_id.info.attach_mode);
> >
> > +       if (OPTS_HAS(opts, fflags)) {
> 
> maybe invert condition, return early, reduce nesting of the following code?

ack, fine, I will fix it.

> 
> > +               struct xdp_features_md md = {
> > +                       .ifindex = ifindex,
> > +               };
> > +               __u16 id;
> > +
> > +               err = libbpf_netlink_resolve_genl_family_id("netdev",
> > +                                                           sizeof("netdev"),
> > +                                                           &id);
> 
> nit: if it fits under 100 characters, let's leave it on a single line

ack, fine, I will fix it (I am still used to 79 char limits :))

Regards,
Lorenzo

> 
> > +               if (err < 0)
> > +                       return libbpf_err(err);
> > +
> > +               memset(&req, 0, sizeof(req));
> > +               req.nh.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
> > +               req.nh.nlmsg_flags = NLM_F_REQUEST;
> > +               req.nh.nlmsg_type = id;
> > +               req.gnl.cmd = NETDEV_CMD_DEV_GET;
> > +               req.gnl.version = 2;
> > +
> > +               err = nlattr_add(&req, NETDEV_A_DEV_IFINDEX, &ifindex,
> > +                                sizeof(ifindex));
> > +               if (err < 0)
> > +                       return err;
> > +
> > +               err = libbpf_netlink_send_recv(&req, NETLINK_GENERIC,
> > +                                              parse_xdp_features, NULL, &md);
> > +               if (err)
> > +                       return libbpf_err(err);
> > +
> > +               opts->fflags = md.flags;
> > +       }
> > +
> >         return 0;
> >  }
> >
> 
> [...]

Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ