@@ -121,7 +121,7 @@ struct netlink_table {
121121 struct nl_pid_hash hash ;
122122 struct hlist_head mc_list ;
123123 struct listeners __rcu * listeners ;
124- unsigned int nl_nonroot ;
124+ unsigned int flags ;
125125 unsigned int groups ;
126126 struct mutex * cb_mutex ;
127127 struct module * module ;
@@ -536,6 +536,8 @@ static int netlink_release(struct socket *sock)
536536 if (-- nl_table [sk -> sk_protocol ].registered == 0 ) {
537537 kfree (nl_table [sk -> sk_protocol ].listeners );
538538 nl_table [sk -> sk_protocol ].module = NULL ;
539+ nl_table [sk -> sk_protocol ].bind = NULL ;
540+ nl_table [sk -> sk_protocol ].flags = 0 ;
539541 nl_table [sk -> sk_protocol ].registered = 0 ;
540542 }
541543 } else if (nlk -> subscriptions ) {
@@ -596,7 +598,7 @@ static int netlink_autobind(struct socket *sock)
596598
597599static inline int netlink_capable (const struct socket * sock , unsigned int flag )
598600{
599- return (nl_table [sock -> sk -> sk_protocol ].nl_nonroot & flag ) ||
601+ return (nl_table [sock -> sk -> sk_protocol ].flags & flag ) ||
600602 capable (CAP_NET_ADMIN );
601603}
602604
@@ -659,7 +661,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
659661
660662 /* Only superuser is allowed to listen multicasts */
661663 if (nladdr -> nl_groups ) {
662- if (!netlink_capable (sock , NL_NONROOT_RECV ))
664+ if (!netlink_capable (sock , NL_CFG_F_NONROOT_RECV ))
663665 return - EPERM ;
664666 err = netlink_realloc_groups (sk );
665667 if (err )
@@ -721,7 +723,7 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
721723 return - EINVAL ;
722724
723725 /* Only superuser is allowed to send multicasts */
724- if (nladdr -> nl_groups && !netlink_capable (sock , NL_NONROOT_SEND ))
726+ if (nladdr -> nl_groups && !netlink_capable (sock , NL_CFG_F_NONROOT_SEND ))
725727 return - EPERM ;
726728
727729 if (!nlk -> pid )
@@ -1244,7 +1246,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
12441246 break ;
12451247 case NETLINK_ADD_MEMBERSHIP :
12461248 case NETLINK_DROP_MEMBERSHIP : {
1247- if (!netlink_capable (sock , NL_NONROOT_RECV ))
1249+ if (!netlink_capable (sock , NL_CFG_F_NONROOT_RECV ))
12481250 return - EPERM ;
12491251 err = netlink_realloc_groups (sk );
12501252 if (err )
@@ -1376,7 +1378,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
13761378 dst_group = ffs (addr -> nl_groups );
13771379 err = - EPERM ;
13781380 if ((dst_group || dst_pid ) &&
1379- !netlink_capable (sock , NL_NONROOT_SEND ))
1381+ !netlink_capable (sock , NL_CFG_F_NONROOT_SEND ))
13801382 goto out ;
13811383 } else {
13821384 dst_pid = nlk -> dst_pid ;
@@ -1580,7 +1582,10 @@ netlink_kernel_create(struct net *net, int unit,
15801582 rcu_assign_pointer (nl_table [unit ].listeners , listeners );
15811583 nl_table [unit ].cb_mutex = cb_mutex ;
15821584 nl_table [unit ].module = module ;
1583- nl_table [unit ].bind = cfg ? cfg -> bind : NULL ;
1585+ if (cfg ) {
1586+ nl_table [unit ].bind = cfg -> bind ;
1587+ nl_table [unit ].flags = cfg -> flags ;
1588+ }
15841589 nl_table [unit ].registered = 1 ;
15851590 } else {
15861591 kfree (listeners );
@@ -1679,13 +1684,6 @@ void netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
16791684 netlink_table_ungrab ();
16801685}
16811686
1682- void netlink_set_nonroot (int protocol , unsigned int flags )
1683- {
1684- if ((unsigned int )protocol < MAX_LINKS )
1685- nl_table [protocol ].nl_nonroot = flags ;
1686- }
1687- EXPORT_SYMBOL (netlink_set_nonroot );
1688-
16891687struct nlmsghdr *
16901688__nlmsg_put (struct sk_buff * skb , u32 pid , u32 seq , int type , int len , int flags )
16911689{
@@ -2150,7 +2148,7 @@ static void __init netlink_add_usersock_entry(void)
21502148 rcu_assign_pointer (nl_table [NETLINK_USERSOCK ].listeners , listeners );
21512149 nl_table [NETLINK_USERSOCK ].module = THIS_MODULE ;
21522150 nl_table [NETLINK_USERSOCK ].registered = 1 ;
2153- nl_table [NETLINK_USERSOCK ].nl_nonroot = NL_NONROOT_SEND ;
2151+ nl_table [NETLINK_USERSOCK ].flags = NL_CFG_F_NONROOT_SEND ;
21542152
21552153 netlink_table_ungrab ();
21562154}
0 commit comments