aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink/af_netlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/netlink/af_netlink.c')
-rw-r--r--net/netlink/af_netlink.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index d0ff382c40ca..c5aab6a368ce 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -177,9 +177,11 @@ static void netlink_sock_destruct(struct sock *sk)
177 * this, _but_ remember, it adds useless work on UP machines. 177 * this, _but_ remember, it adds useless work on UP machines.
178 */ 178 */
179 179
180static void netlink_table_grab(void) 180void netlink_table_grab(void)
181 __acquires(nl_table_lock) 181 __acquires(nl_table_lock)
182{ 182{
183 might_sleep();
184
183 write_lock_irq(&nl_table_lock); 185 write_lock_irq(&nl_table_lock);
184 186
185 if (atomic_read(&nl_table_users)) { 187 if (atomic_read(&nl_table_users)) {
@@ -200,7 +202,7 @@ static void netlink_table_grab(void)
200 } 202 }
201} 203}
202 204
203static void netlink_table_ungrab(void) 205void netlink_table_ungrab(void)
204 __releases(nl_table_lock) 206 __releases(nl_table_lock)
205{ 207{
206 write_unlock_irq(&nl_table_lock); 208 write_unlock_irq(&nl_table_lock);
@@ -1549,37 +1551,21 @@ static void netlink_free_old_listeners(struct rcu_head *rcu_head)
1549 kfree(lrh->ptr); 1551 kfree(lrh->ptr);
1550} 1552}
1551 1553
1552/** 1554int __netlink_change_ngroups(struct sock *sk, unsigned int groups)
1553 * netlink_change_ngroups - change number of multicast groups
1554 *
1555 * This changes the number of multicast groups that are available
1556 * on a certain netlink family. Note that it is not possible to
1557 * change the number of groups to below 32. Also note that it does
1558 * not implicitly call netlink_clear_multicast_users() when the
1559 * number of groups is reduced.
1560 *
1561 * @sk: The kernel netlink socket, as returned by netlink_kernel_create().
1562 * @groups: The new number of groups.
1563 */
1564int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1565{ 1555{
1566 unsigned long *listeners, *old = NULL; 1556 unsigned long *listeners, *old = NULL;
1567 struct listeners_rcu_head *old_rcu_head; 1557 struct listeners_rcu_head *old_rcu_head;
1568 struct netlink_table *tbl = &nl_table[sk->sk_protocol]; 1558 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
1569 int err = 0;
1570 1559
1571 if (groups < 32) 1560 if (groups < 32)
1572 groups = 32; 1561 groups = 32;
1573 1562
1574 netlink_table_grab();
1575 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) { 1563 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) {
1576 listeners = kzalloc(NLGRPSZ(groups) + 1564 listeners = kzalloc(NLGRPSZ(groups) +
1577 sizeof(struct listeners_rcu_head), 1565 sizeof(struct listeners_rcu_head),
1578 GFP_ATOMIC); 1566 GFP_ATOMIC);
1579 if (!listeners) { 1567 if (!listeners)
1580 err = -ENOMEM; 1568 return -ENOMEM;
1581 goto out_ungrab;
1582 }
1583 old = tbl->listeners; 1569 old = tbl->listeners;
1584 memcpy(listeners, old, NLGRPSZ(tbl->groups)); 1570 memcpy(listeners, old, NLGRPSZ(tbl->groups));
1585 rcu_assign_pointer(tbl->listeners, listeners); 1571 rcu_assign_pointer(tbl->listeners, listeners);
@@ -1597,8 +1583,29 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1597 } 1583 }
1598 tbl->groups = groups; 1584 tbl->groups = groups;
1599 1585
1600 out_ungrab: 1586 return 0;
1587}
1588
1589/**
1590 * netlink_change_ngroups - change number of multicast groups
1591 *
1592 * This changes the number of multicast groups that are available
1593 * on a certain netlink family. Note that it is not possible to
1594 * change the number of groups to below 32. Also note that it does
1595 * not implicitly call netlink_clear_multicast_users() when the
1596 * number of groups is reduced.
1597 *
1598 * @sk: The kernel netlink socket, as returned by netlink_kernel_create().
1599 * @groups: The new number of groups.
1600 */
1601int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1602{
1603 int err;
1604
1605 netlink_table_grab();
1606 err = __netlink_change_ngroups(sk, groups);
1601 netlink_table_ungrab(); 1607 netlink_table_ungrab();
1608
1602 return err; 1609 return err;
1603} 1610}
1604 1611