Skip to content

Commit

Permalink
genetlink: factor skb preparation out of ctrl_dumppolicy()
Browse files Browse the repository at this point in the history
We'll need this later for the per-op policy index dump.

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Johannes Berg authored and David S. Miller committed Oct 3, 2020
1 parent 04a351a commit aa85ee5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,24 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
rt->maxattr);
}

static void *ctrl_dumppolicy_prep(struct sk_buff *skb,
struct netlink_callback *cb)
{
struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
void *hdr;

hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, &genl_ctrl,
NLM_F_MULTI, CTRL_CMD_GETPOLICY);
if (!hdr)
return NULL;

if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
return NULL;

return hdr;
}

static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
{
struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
Expand All @@ -1162,15 +1180,10 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
void *hdr;
struct nlattr *nest;

hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, &genl_ctrl,
NLM_F_MULTI, CTRL_CMD_GETPOLICY);
hdr = ctrl_dumppolicy_prep(skb, cb);
if (!hdr)
goto nla_put_failure;

if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
goto nla_put_failure;

nest = nla_nest_start(skb, CTRL_ATTR_POLICY);
if (!nest)
goto nla_put_failure;
Expand Down

0 comments on commit aa85ee5

Please sign in to comment.