Skip to content

Commit

Permalink
genetlink: refactor the cmd <> policy mapping dump
Browse files Browse the repository at this point in the history
The code at the top of ctrl_dumppolicy() dumps mappings between
ops and policies. It supports dumping both the entire family and
single op if dump is filtered. But both of those cases are handled
inside a loop, which makes the logic harder to follow and change.
Refactor to split the two cases more clearly.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Nov 7, 2022
1 parent e2dbda0 commit ff14adb
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,21 +1319,24 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
void *hdr;

if (!ctx->policies) {
while (ctx->opidx < genl_get_cmd_cnt(ctx->rt)) {
struct genl_ops op;
struct genl_ops op;

if (ctx->single_op) {
int err;
if (ctx->single_op) {
int err;

err = genl_get_cmd(ctx->op, ctx->rt, &op);
if (WARN_ON(err))
return skb->len;
err = genl_get_cmd(ctx->op, ctx->rt, &op);
if (WARN_ON(err))
return err;

/* break out of the loop after this one */
ctx->opidx = genl_get_cmd_cnt(ctx->rt);
} else {
genl_get_cmd_by_index(ctx->opidx, ctx->rt, &op);
}
if (ctrl_dumppolicy_put_op(skb, cb, &op))
return skb->len;

/* don't enter the loop below */
ctx->opidx = genl_get_cmd_cnt(ctx->rt);
}

while (ctx->opidx < genl_get_cmd_cnt(ctx->rt)) {
genl_get_cmd_by_index(ctx->opidx, ctx->rt, &op);

if (ctrl_dumppolicy_put_op(skb, cb, &op))
return skb->len;
Expand Down

0 comments on commit ff14adb

Please sign in to comment.