Skip to content

Commit

Permalink
devlink: put netnsid to nested handle
Browse files Browse the repository at this point in the history
If netns of devlink instance and nested devlink instance differs,
put netnsid attr to indicate that.

Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jiri Pirko authored and davem330 committed Sep 17, 2023
1 parent 602d61e commit ad99637
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions net/devlink/linecard.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)
return devlink_linecard_get_from_attrs(devlink, info->attrs);
}

static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *devlink)
static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
struct devlink *devlink)
{
struct nlattr *nested_attr;

Expand All @@ -74,6 +75,13 @@ static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *dev
return -EMSGSIZE;
if (devlink_nl_put_handle(msg, devlink))
goto nla_put_failure;
if (!net_eq(net, devlink_net(devlink))) {
int id = peernet2id_alloc(net, devlink_net(devlink),
GFP_KERNEL);

if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
return -EMSGSIZE;
}

nla_nest_end(msg, nested_attr);
return 0;
Expand Down Expand Up @@ -131,7 +139,8 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg,
}

if (linecard->nested_devlink &&
devlink_nl_put_nested_handle(msg, linecard->nested_devlink))
devlink_nl_put_nested_handle(msg, devlink_net(devlink),
linecard->nested_devlink))
goto nla_put_failure;

genlmsg_end(msg, hdr);
Expand Down

0 comments on commit ad99637

Please sign in to comment.