File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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+
18461875static 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
You can’t perform that action at this time.
0 commit comments