diff options
Diffstat (limited to 'net/netlink')
-rw-r--r-- | net/netlink/af_netlink.c | 11 | ||||
-rw-r--r-- | net/netlink/genetlink.c | 32 |
2 files changed, 17 insertions, 26 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 19e98007691c..a4957bf2ca60 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -428,7 +428,8 @@ static int __netlink_create(struct net *net, struct socket *sock, | |||
428 | return 0; | 428 | return 0; |
429 | } | 429 | } |
430 | 430 | ||
431 | static int netlink_create(struct net *net, struct socket *sock, int protocol) | 431 | static int netlink_create(struct net *net, struct socket *sock, int protocol, |
432 | int kern) | ||
432 | { | 433 | { |
433 | struct module *module = NULL; | 434 | struct module *module = NULL; |
434 | struct mutex *cb_mutex; | 435 | struct mutex *cb_mutex; |
@@ -497,7 +498,7 @@ static int netlink_release(struct socket *sock) | |||
497 | 498 | ||
498 | skb_queue_purge(&sk->sk_write_queue); | 499 | skb_queue_purge(&sk->sk_write_queue); |
499 | 500 | ||
500 | if (nlk->pid && !nlk->subscriptions) { | 501 | if (nlk->pid) { |
501 | struct netlink_notify n = { | 502 | struct netlink_notify n = { |
502 | .net = sock_net(sk), | 503 | .net = sock_net(sk), |
503 | .protocol = sk->sk_protocol, | 504 | .protocol = sk->sk_protocol, |
@@ -707,7 +708,7 @@ static int netlink_getname(struct socket *sock, struct sockaddr *addr, | |||
707 | { | 708 | { |
708 | struct sock *sk = sock->sk; | 709 | struct sock *sk = sock->sk; |
709 | struct netlink_sock *nlk = nlk_sk(sk); | 710 | struct netlink_sock *nlk = nlk_sk(sk); |
710 | struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; | 711 | DECLARE_SOCKADDR(struct sockaddr_nl *, nladdr, addr); |
711 | 712 | ||
712 | nladdr->nl_family = AF_NETLINK; | 713 | nladdr->nl_family = AF_NETLINK; |
713 | nladdr->nl_pad = 0; | 714 | nladdr->nl_pad = 0; |
@@ -1091,7 +1092,7 @@ static inline int do_one_set_err(struct sock *sk, | |||
1091 | if (sk == p->exclude_sk) | 1092 | if (sk == p->exclude_sk) |
1092 | goto out; | 1093 | goto out; |
1093 | 1094 | ||
1094 | if (sock_net(sk) != sock_net(p->exclude_sk)) | 1095 | if (!net_eq(sock_net(sk), sock_net(p->exclude_sk))) |
1095 | goto out; | 1096 | goto out; |
1096 | 1097 | ||
1097 | if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups || | 1098 | if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups || |
@@ -2050,7 +2051,7 @@ static const struct proto_ops netlink_ops = { | |||
2050 | .sendpage = sock_no_sendpage, | 2051 | .sendpage = sock_no_sendpage, |
2051 | }; | 2052 | }; |
2052 | 2053 | ||
2053 | static struct net_proto_family netlink_family_ops = { | 2054 | static const struct net_proto_family netlink_family_ops = { |
2054 | .family = PF_NETLINK, | 2055 | .family = PF_NETLINK, |
2055 | .create = netlink_create, | 2056 | .create = netlink_create, |
2056 | .owner = THIS_MODULE, /* for consistency 8) */ | 2057 | .owner = THIS_MODULE, /* for consistency 8) */ |
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 44ff3f3810fa..d07ecda0a92d 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -97,25 +97,17 @@ static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family) | |||
97 | */ | 97 | */ |
98 | static inline u16 genl_generate_id(void) | 98 | static inline u16 genl_generate_id(void) |
99 | { | 99 | { |
100 | static u16 id_gen_idx; | 100 | static u16 id_gen_idx = GENL_MIN_ID; |
101 | int overflowed = 0; | 101 | int i; |
102 | 102 | ||
103 | do { | 103 | for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) { |
104 | if (id_gen_idx == 0) | 104 | if (!genl_family_find_byid(id_gen_idx)) |
105 | return id_gen_idx; | ||
106 | if (++id_gen_idx > GENL_MAX_ID) | ||
105 | id_gen_idx = GENL_MIN_ID; | 107 | id_gen_idx = GENL_MIN_ID; |
108 | } | ||
106 | 109 | ||
107 | if (++id_gen_idx > GENL_MAX_ID) { | 110 | return 0; |
108 | if (!overflowed) { | ||
109 | overflowed = 1; | ||
110 | id_gen_idx = 0; | ||
111 | continue; | ||
112 | } else | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | } while (genl_family_find_byid(id_gen_idx)); | ||
117 | |||
118 | return id_gen_idx; | ||
119 | } | 111 | } |
120 | 112 | ||
121 | static struct genl_multicast_group notify_grp; | 113 | static struct genl_multicast_group notify_grp; |
@@ -374,11 +366,6 @@ int genl_register_family(struct genl_family *family) | |||
374 | goto errout_locked; | 366 | goto errout_locked; |
375 | } | 367 | } |
376 | 368 | ||
377 | if (genl_family_find_byid(family->id)) { | ||
378 | err = -EEXIST; | ||
379 | goto errout_locked; | ||
380 | } | ||
381 | |||
382 | if (family->id == GENL_ID_GENERATE) { | 369 | if (family->id == GENL_ID_GENERATE) { |
383 | u16 newid = genl_generate_id(); | 370 | u16 newid = genl_generate_id(); |
384 | 371 | ||
@@ -388,6 +375,9 @@ int genl_register_family(struct genl_family *family) | |||
388 | } | 375 | } |
389 | 376 | ||
390 | family->id = newid; | 377 | family->id = newid; |
378 | } else if (genl_family_find_byid(family->id)) { | ||
379 | err = -EEXIST; | ||
380 | goto errout_locked; | ||
391 | } | 381 | } |
392 | 382 | ||
393 | if (family->maxattr) { | 383 | if (family->maxattr) { |