diff mbox series

netlink: add nl_set_extack_cookie_u64()

Message ID 20180823084813.5727-1-johannes@sipsolutions.net (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series netlink: add nl_set_extack_cookie_u64() | expand

Commit Message

Johannes Berg Aug. 23, 2018, 8:48 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Add a helper function nl_set_extack_cookie_u64() to use a u64 as
the netlink extended ACK cookie, to avoid having to open-code it
in any users of the cookie.

A u64 should be sufficient for most subsystems though we allow
for up to 20 bytes right now. This also matches the cookies in
nl80211 where I intend to use this.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/netlink.h | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

David Miller Aug. 23, 2018, 3:45 p.m. UTC | #1
From: Johannes Berg <johannes@sipsolutions.net>
Date: Thu, 23 Aug 2018 10:48:13 +0200

> From: Johannes Berg <johannes.berg@intel.com>
> 
> Add a helper function nl_set_extack_cookie_u64() to use a u64 as
> the netlink extended ACK cookie, to avoid having to open-code it
> in any users of the cookie.
> 
> A u64 should be sufficient for most subsystems though we allow
> for up to 20 bytes right now. This also matches the cookies in
> nl80211 where I intend to use this.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>

Feel free to merge this in your wireless tree since the first
user will be there.

Acked-by: David S. Miller <davem@davemloft.net>
Johannes Berg Aug. 23, 2018, 4:39 p.m. UTC | #2
On Thu, 2018-08-23 at 08:45 -0700, David Miller wrote:
> From: Johannes Berg <johannes@sipsolutions.net>
> Date: Thu, 23 Aug 2018 10:48:13 +0200
> 
> > From: Johannes Berg <johannes.berg@intel.com>
> > 
> > Add a helper function nl_set_extack_cookie_u64() to use a u64 as
> > the netlink extended ACK cookie, to avoid having to open-code it
> > in any users of the cookie.
> > 
> > A u64 should be sufficient for most subsystems though we allow
> > for up to 20 bytes right now. This also matches the cookies in
> > nl80211 where I intend to use this.
> > 
> > Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> 
> Feel free to merge this in your wireless tree since the first
> user will be there.
> 
> Acked-by: David S. Miller <davem@davemloft.net>

Will do, thanks.

johannes
diff mbox series

Patch

diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 71f121b66ca8..dc3c21dc4ba2 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -110,6 +110,15 @@  struct netlink_ext_ack {
 	}						\
 } while (0)
 
+static inline void nl_set_extack_cookie_u64(struct netlink_ext_ack *extack,
+					    u64 cookie)
+{
+	u64 __cookie = cookie;
+
+	memcpy(extack->cookie, &__cookie, sizeof(__cookie));
+	extack->cookie_len = sizeof(__cookie);
+}
+
 extern void netlink_kernel_release(struct sock *sk);
 extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
 extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);