Skip to content

Commit

Permalink
netlink: add nlmsg_consume() and use it in devlink compat
Browse files Browse the repository at this point in the history
devlink_compat_running_version() sticks out when running
netdevsim tests and watching dropped skbs. Add nlmsg_consume()
for cases were we want to free a netlink skb but it is expected,
rather than a drop. af_netlink code uses consume_skb() directly,
which is fine, but some may prefer the symmetry of nlmsg_new() /
nlmsg_consume().

Signed-off-by: Jakub Kicinski <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
kuba-moo authored and davem330 committed Apr 6, 2024
1 parent 9f06f87 commit 8e69b34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
* nlmsg_get_pos() return current position in message
* nlmsg_trim() trim part of message
* nlmsg_cancel() cancel message construction
* nlmsg_free() free a netlink message
* nlmsg_consume() free a netlink message (expected)
* nlmsg_free() free a netlink message (drop)
*
* Message Sending:
* nlmsg_multicast() multicast message to several groups
Expand Down Expand Up @@ -1082,14 +1083,23 @@ static inline void nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh)
}

/**
* nlmsg_free - free a netlink message
* nlmsg_free - drop a netlink message
* @skb: socket buffer of netlink message
*/
static inline void nlmsg_free(struct sk_buff *skb)
{
kfree_skb(skb);
}

/**
* nlmsg_consume - free a netlink message
* @skb: socket buffer of netlink message
*/
static inline void nlmsg_consume(struct sk_buff *skb)
{
consume_skb(skb);
}

/**
* nlmsg_multicast_filtered - multicast a netlink message with filter function
* @sk: netlink socket to spread messages to
Expand Down
2 changes: 1 addition & 1 deletion net/devlink/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ static void __devlink_compat_running_version(struct devlink *devlink,
}
}
free_msg:
nlmsg_free(msg);
nlmsg_consume(msg);
}

void devlink_compat_running_version(struct devlink *devlink,
Expand Down

0 comments on commit 8e69b34

Please sign in to comment.