1 From 8dc94a59cfad70ec3a808add56718255eee39ab2 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sat, 29 Mar 2025 12:50:55 +0100
4 Subject: [PATCH] backports: handle genlmsg_multicast_allns upstream backport
7 Better handle genlmsg_multicast_allns upstream backport changes that
8 dropped a flag to the function middle version. Use a backport function
9 if backports project is tried to be built on older kernel version.
11 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
13 backport-include/net/genetlink.h | 11 +++++
14 compat/Makefile | 3 +-
15 compat/backport-genetlink.c | 60 +++++++++++++++++++++++
16 3 files changed, 73 insertions(+), 1 deletion(-)
18 --- a/backport-include/net/genetlink.h
19 +++ b/backport-include/net/genetlink.h
20 @@ -172,4 +172,15 @@ static inline int genlmsg_parse(const st
22 #endif /* LINUX_VERSION_IS_LESS(5,2,0) */
24 +#if LINUX_VERSION_IN_RANGE(5,15,0,5,15,169) || \
25 + LINUX_VERSION_IN_RANGE(6,1,0,6,1,115) || \
26 + LINUX_VERSION_IN_RANGE(6,6,0,6,6,58)
27 +#define genlmsg_multicast_allns LINUX_BACKPORT(genlmsg_multicast_allns)
28 +int backport_genlmsg_multicast_allns(const struct genl_family *family,
29 + struct sk_buff *skb, u32 portid,
30 + unsigned int group);
31 +#endif /* LINUX_VERSION_IN_RANGE(5,15,0,5,15,169) ||
32 + LINUX_VERSION_IN_RANGE(6,1,0,6,1,115) ||
33 + LINUX_VERSION_IN_RANGE(6,6,0,6,6,58) */
35 #endif /* __BACKPORT_NET_GENETLINK_H */
38 @@ -16,7 +16,8 @@ compat-$(CPTCFG_KERNEL_5_9) += backport-
39 compat-$(CPTCFG_KERNEL_5_10) += backport-5.10.o
40 compat-$(CPTCFG_KERNEL_5_11) += backport-5.11.o
41 compat-$(CPTCFG_KERNEL_5_13) += backport-5.13.o
42 -compat-$(CPTCFG_KERNEL_5_15) += backport-5.15.o
43 +compat-$(CPTCFG_KERNEL_5_15) += backport-5.15.o backport-genetlink.o
44 +compat-$(CPTCFG_KERNEL_6_1) += backport-genetlink.o
45 compat-$(CPTCFG_KERNEL_6_4) += backport-6.4.o
47 compat-$(CPTCFG_BPAUTO_BUILD_CRYPTO_LIB_ARC4) += lib-crypto-arc4.o
48 --- a/compat/backport-genetlink.c
49 +++ b/compat/backport-genetlink.c
51 #include <net/netlink.h>
54 +#if LINUX_VERSION_IS_LESS(5,2,0)
55 static const struct genl_family *find_family_real_ops(const struct genl_ops **ops)
57 const struct genl_family *family;
58 @@ -249,3 +250,63 @@ int backport_genlmsg_multicast_allns(con
59 return genlmsg_mcast(skb, portid, group);
61 EXPORT_SYMBOL_GPL(backport_genlmsg_multicast_allns);
62 +#endif /* LINUX_VERSION_IS_LESS(5,2,0) */
64 +#if LINUX_VERSION_IN_RANGE(5,15,0,5,15,169) || \
65 + LINUX_VERSION_IN_RANGE(6,1,0,6,1,115) || \
66 + LINUX_VERSION_IN_RANGE(6,6,0,6,6,58)
67 +static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group)
69 + struct sk_buff *tmp;
70 + struct net *net, *prev = NULL;
71 + bool delivered = false;
75 + for_each_net_rcu(net) {
77 + tmp = skb_clone(skb, GFP_ATOMIC);
82 + err = nlmsg_multicast(prev->genl_sock, tmp,
83 + portid, group, GFP_ATOMIC);
86 + else if (err != -ESRCH)
92 + err = nlmsg_multicast(prev->genl_sock, skb, portid, group, GFP_ATOMIC);
98 + else if (err != -ESRCH)
100 + return delivered ? 0 : -ESRCH;
108 +int backport_genlmsg_multicast_allns(const struct genl_family *family,
109 + struct sk_buff *skb, u32 portid,
110 + unsigned int group)
112 + if (WARN_ON_ONCE(group >= family->n_mcgrps))
115 + group = family->mcgrp_offset + group;
116 + return genlmsg_mcast(skb, portid, group);
118 +EXPORT_SYMBOL_GPL(backport_genlmsg_multicast_allns);
119 +#endif /* LINUX_VERSION_IN_RANGE(5,15,0,5,15,169) ||
120 + LINUX_VERSION_IN_RANGE(6,1,0,6,1,115) ||
121 + LINUX_VERSION_IN_RANGE(6,6,0,6,6,58) */