Skip to content

Commit fc906e7

Browse files
committed
Merge branch 'for-thermal-genetlink-family-bind-unbind-callbacks'
Stanislaw Gruszka says: ==================== thermal/netlink/intel_hfi: Enable HFI feature only when required The patchset introduces a new genetlink family bind/unbind callbacks and thermal/netlink notifications, which allow drivers to send netlink multicast events based on the presence of actual user-space consumers. This functionality optimizes resource usage by allowing disabling of features when not needed. v1: https://lore.kernel.org/linux-pm/[email protected]// v2: https://lore.kernel.org/linux-pm/[email protected]/ v3: https://lore.kernel.org/linux-pm/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3738d71 + 3de21a8 commit fc906e7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/net/genetlink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct genl_info;
4141
* do additional, common, filtering and return an error
4242
* @post_doit: called after an operation's doit callback, it may
4343
* undo operations done by pre_doit, for example release locks
44+
* @bind: called when family multicast group is added to a netlink socket
45+
* @unbind: called when family multicast group is removed from a netlink socket
4446
* @module: pointer to the owning module (set to THIS_MODULE)
4547
* @mcgrps: multicast groups used by this family
4648
* @n_mcgrps: number of multicast groups
@@ -84,6 +86,8 @@ struct genl_family {
8486
void (*post_doit)(const struct genl_split_ops *ops,
8587
struct sk_buff *skb,
8688
struct genl_info *info);
89+
int (*bind)(int mcgrp);
90+
void (*unbind)(int mcgrp);
8791
const struct genl_ops * ops;
8892
const struct genl_small_ops *small_ops;
8993
const struct genl_split_ops *split_ops;

net/netlink/genetlink.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,19 +1836,49 @@ static int genl_bind(struct net *net, int group)
18361836
!ns_capable(net->user_ns, CAP_SYS_ADMIN))
18371837
ret = -EPERM;
18381838

1839+
if (family->bind)
1840+
family->bind(i);
1841+
18391842
break;
18401843
}
18411844

18421845
up_read(&cb_lock);
18431846
return ret;
18441847
}
18451848

1849+
static void genl_unbind(struct net *net, int group)
1850+
{
1851+
const struct genl_family *family;
1852+
unsigned int id;
1853+
1854+
down_read(&cb_lock);
1855+
1856+
idr_for_each_entry(&genl_fam_idr, family, id) {
1857+
int i;
1858+
1859+
if (family->n_mcgrps == 0)
1860+
continue;
1861+
1862+
i = group - family->mcgrp_offset;
1863+
if (i < 0 || i >= family->n_mcgrps)
1864+
continue;
1865+
1866+
if (family->unbind)
1867+
family->unbind(i);
1868+
1869+
break;
1870+
}
1871+
1872+
up_read(&cb_lock);
1873+
}
1874+
18461875
static int __net_init genl_pernet_init(struct net *net)
18471876
{
18481877
struct netlink_kernel_cfg cfg = {
18491878
.input = genl_rcv,
18501879
.flags = NL_CFG_F_NONROOT_RECV,
18511880
.bind = genl_bind,
1881+
.unbind = genl_unbind,
18521882
.release = genl_release,
18531883
};
18541884

0 commit comments

Comments
 (0)