On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:
> -     case XDP_QUERY_PROG:
> -             xdp->prog_attached = !!nn->dp.xdp_prog;
> +     case XDP_QUERY_PROG: {
> +             const struct bpf_prog *xdp_prog;
> +
> +             xdp_prog = nn->dp.xdp_prog;
> +             if (xdp_prog) {
> +                     xdp->prog_id = xdp_prog->aux->id;
> +                     xdp->prog_attached = true;
> +             } else {
> +                     xdp->prog_id = 0;
> +                     xdp->prog_attached = false;
> +             }
>               return 0;
> +     }

I'm sorry to nit pick but it could be done on a single line:

        case XDP_QUERY_PROG:
                xdp->prog_attached = !!nn->dp.xdp_prog;
+               xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
                return 0;
        default:
                return -EINVAL;


What would be even cooler is a helper like this:

static inline u32 bpf_prog_id(struct bpf_prog *prog)
{
        if (!prog)
                return 0;
        return prog->aux->id;
}

in linux/bpf.h.  

In patch 1 I would be tempted to add a new command for getting the prog
id, instead of muxing through query to avoid the output parameter?  But
I'm OK with the code as is, its just a preference rather than an objection :)

Reply via email to