aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bearer.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r--net/tipc/bearer.c205
1 files changed, 75 insertions, 130 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 463db5b15b8b..48852c2dcc03 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -34,11 +34,12 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <net/sock.h>
37#include "core.h" 38#include "core.h"
38#include "config.h"
39#include "bearer.h" 39#include "bearer.h"
40#include "link.h" 40#include "link.h"
41#include "discover.h" 41#include "discover.h"
42#include "bcast.h"
42 43
43#define MAX_ADDR_STR 60 44#define MAX_ADDR_STR 60
44 45
@@ -67,9 +68,8 @@ static const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = {
67 [TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED } 68 [TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED }
68}; 69};
69 70
70struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; 71static void bearer_disable(struct net *net, struct tipc_bearer *b_ptr,
71 72 bool shutting_down);
72static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down);
73 73
74/** 74/**
75 * tipc_media_find - locates specified media object by name 75 * tipc_media_find - locates specified media object by name
@@ -111,38 +111,18 @@ void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a)
111 m_ptr = media_find_id(a->media_id); 111 m_ptr = media_find_id(a->media_id);
112 112
113 if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str))) 113 if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
114 ret = tipc_snprintf(buf, len, "%s(%s)", m_ptr->name, addr_str); 114 ret = scnprintf(buf, len, "%s(%s)", m_ptr->name, addr_str);
115 else { 115 else {
116 u32 i; 116 u32 i;
117 117
118 ret = tipc_snprintf(buf, len, "UNKNOWN(%u)", a->media_id); 118 ret = scnprintf(buf, len, "UNKNOWN(%u)", a->media_id);
119 for (i = 0; i < sizeof(a->value); i++) 119 for (i = 0; i < sizeof(a->value); i++)
120 ret += tipc_snprintf(buf - ret, len + ret, 120 ret += scnprintf(buf - ret, len + ret,
121 "-%02x", a->value[i]); 121 "-%02x", a->value[i]);
122 } 122 }
123} 123}
124 124
125/** 125/**
126 * tipc_media_get_names - record names of registered media in buffer
127 */
128struct sk_buff *tipc_media_get_names(void)
129{
130 struct sk_buff *buf;
131 int i;
132
133 buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
134 if (!buf)
135 return NULL;
136
137 for (i = 0; media_info_array[i] != NULL; i++) {
138 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
139 media_info_array[i]->name,
140 strlen(media_info_array[i]->name) + 1);
141 }
142 return buf;
143}
144
145/**
146 * bearer_name_validate - validate & (optionally) deconstruct bearer name 126 * bearer_name_validate - validate & (optionally) deconstruct bearer name
147 * @name: ptr to bearer name string 127 * @name: ptr to bearer name string
148 * @name_parts: ptr to area for bearer name components (or NULL if not needed) 128 * @name_parts: ptr to area for bearer name components (or NULL if not needed)
@@ -190,68 +170,43 @@ static int bearer_name_validate(const char *name,
190/** 170/**
191 * tipc_bearer_find - locates bearer object with matching bearer name 171 * tipc_bearer_find - locates bearer object with matching bearer name
192 */ 172 */
193struct tipc_bearer *tipc_bearer_find(const char *name) 173struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name)
194{ 174{
175 struct tipc_net *tn = net_generic(net, tipc_net_id);
195 struct tipc_bearer *b_ptr; 176 struct tipc_bearer *b_ptr;
196 u32 i; 177 u32 i;
197 178
198 for (i = 0; i < MAX_BEARERS; i++) { 179 for (i = 0; i < MAX_BEARERS; i++) {
199 b_ptr = rtnl_dereference(bearer_list[i]); 180 b_ptr = rtnl_dereference(tn->bearer_list[i]);
200 if (b_ptr && (!strcmp(b_ptr->name, name))) 181 if (b_ptr && (!strcmp(b_ptr->name, name)))
201 return b_ptr; 182 return b_ptr;
202 } 183 }
203 return NULL; 184 return NULL;
204} 185}
205 186
206/** 187void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest)
207 * tipc_bearer_get_names - record names of bearers in buffer
208 */
209struct sk_buff *tipc_bearer_get_names(void)
210{
211 struct sk_buff *buf;
212 struct tipc_bearer *b;
213 int i, j;
214
215 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
216 if (!buf)
217 return NULL;
218
219 for (i = 0; media_info_array[i] != NULL; i++) {
220 for (j = 0; j < MAX_BEARERS; j++) {
221 b = rtnl_dereference(bearer_list[j]);
222 if (!b)
223 continue;
224 if (b->media == media_info_array[i]) {
225 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
226 b->name,
227 strlen(b->name) + 1);
228 }
229 }
230 }
231 return buf;
232}
233
234void tipc_bearer_add_dest(u32 bearer_id, u32 dest)
235{ 188{
189 struct tipc_net *tn = net_generic(net, tipc_net_id);
236 struct tipc_bearer *b_ptr; 190 struct tipc_bearer *b_ptr;
237 191
238 rcu_read_lock(); 192 rcu_read_lock();
239 b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); 193 b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
240 if (b_ptr) { 194 if (b_ptr) {
241 tipc_bcbearer_sort(&b_ptr->nodes, dest, true); 195 tipc_bcbearer_sort(net, &b_ptr->nodes, dest, true);
242 tipc_disc_add_dest(b_ptr->link_req); 196 tipc_disc_add_dest(b_ptr->link_req);
243 } 197 }
244 rcu_read_unlock(); 198 rcu_read_unlock();
245} 199}
246 200
247void tipc_bearer_remove_dest(u32 bearer_id, u32 dest) 201void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest)
248{ 202{
203 struct tipc_net *tn = net_generic(net, tipc_net_id);
249 struct tipc_bearer *b_ptr; 204 struct tipc_bearer *b_ptr;
250 205
251 rcu_read_lock(); 206 rcu_read_lock();
252 b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); 207 b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
253 if (b_ptr) { 208 if (b_ptr) {
254 tipc_bcbearer_sort(&b_ptr->nodes, dest, false); 209 tipc_bcbearer_sort(net, &b_ptr->nodes, dest, false);
255 tipc_disc_remove_dest(b_ptr->link_req); 210 tipc_disc_remove_dest(b_ptr->link_req);
256 } 211 }
257 rcu_read_unlock(); 212 rcu_read_unlock();
@@ -260,8 +215,10 @@ void tipc_bearer_remove_dest(u32 bearer_id, u32 dest)
260/** 215/**
261 * tipc_enable_bearer - enable bearer with the given name 216 * tipc_enable_bearer - enable bearer with the given name
262 */ 217 */
263int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) 218static int tipc_enable_bearer(struct net *net, const char *name,
219 u32 disc_domain, u32 priority)
264{ 220{
221 struct tipc_net *tn = net_generic(net, tipc_net_id);
265 struct tipc_bearer *b_ptr; 222 struct tipc_bearer *b_ptr;
266 struct tipc_media *m_ptr; 223 struct tipc_media *m_ptr;
267 struct tipc_bearer_names b_names; 224 struct tipc_bearer_names b_names;
@@ -271,7 +228,7 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
271 u32 i; 228 u32 i;
272 int res = -EINVAL; 229 int res = -EINVAL;
273 230
274 if (!tipc_own_addr) { 231 if (!tn->own_addr) {
275 pr_warn("Bearer <%s> rejected, not supported in standalone mode\n", 232 pr_warn("Bearer <%s> rejected, not supported in standalone mode\n",
276 name); 233 name);
277 return -ENOPROTOOPT; 234 return -ENOPROTOOPT;
@@ -281,11 +238,11 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
281 return -EINVAL; 238 return -EINVAL;
282 } 239 }
283 if (tipc_addr_domain_valid(disc_domain) && 240 if (tipc_addr_domain_valid(disc_domain) &&
284 (disc_domain != tipc_own_addr)) { 241 (disc_domain != tn->own_addr)) {
285 if (tipc_in_scope(disc_domain, tipc_own_addr)) { 242 if (tipc_in_scope(disc_domain, tn->own_addr)) {
286 disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK; 243 disc_domain = tn->own_addr & TIPC_CLUSTER_MASK;
287 res = 0; /* accept any node in own cluster */ 244 res = 0; /* accept any node in own cluster */
288 } else if (in_own_cluster_exact(disc_domain)) 245 } else if (in_own_cluster_exact(net, disc_domain))
289 res = 0; /* accept specified node in own cluster */ 246 res = 0; /* accept specified node in own cluster */
290 } 247 }
291 if (res) { 248 if (res) {
@@ -313,7 +270,7 @@ restart:
313 bearer_id = MAX_BEARERS; 270 bearer_id = MAX_BEARERS;
314 with_this_prio = 1; 271 with_this_prio = 1;
315 for (i = MAX_BEARERS; i-- != 0; ) { 272 for (i = MAX_BEARERS; i-- != 0; ) {
316 b_ptr = rtnl_dereference(bearer_list[i]); 273 b_ptr = rtnl_dereference(tn->bearer_list[i]);
317 if (!b_ptr) { 274 if (!b_ptr) {
318 bearer_id = i; 275 bearer_id = i;
319 continue; 276 continue;
@@ -347,7 +304,7 @@ restart:
347 304
348 strcpy(b_ptr->name, name); 305 strcpy(b_ptr->name, name);
349 b_ptr->media = m_ptr; 306 b_ptr->media = m_ptr;
350 res = m_ptr->enable_media(b_ptr); 307 res = m_ptr->enable_media(net, b_ptr);
351 if (res) { 308 if (res) {
352 pr_warn("Bearer <%s> rejected, enable failure (%d)\n", 309 pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
353 name, -res); 310 name, -res);
@@ -361,15 +318,15 @@ restart:
361 b_ptr->net_plane = bearer_id + 'A'; 318 b_ptr->net_plane = bearer_id + 'A';
362 b_ptr->priority = priority; 319 b_ptr->priority = priority;
363 320
364 res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr); 321 res = tipc_disc_create(net, b_ptr, &b_ptr->bcast_addr);
365 if (res) { 322 if (res) {
366 bearer_disable(b_ptr, false); 323 bearer_disable(net, b_ptr, false);
367 pr_warn("Bearer <%s> rejected, discovery object creation failed\n", 324 pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
368 name); 325 name);
369 return -EINVAL; 326 return -EINVAL;
370 } 327 }
371 328
372 rcu_assign_pointer(bearer_list[bearer_id], b_ptr); 329 rcu_assign_pointer(tn->bearer_list[bearer_id], b_ptr);
373 330
374 pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n", 331 pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
375 name, 332 name,
@@ -380,11 +337,11 @@ restart:
380/** 337/**
381 * tipc_reset_bearer - Reset all links established over this bearer 338 * tipc_reset_bearer - Reset all links established over this bearer
382 */ 339 */
383static int tipc_reset_bearer(struct tipc_bearer *b_ptr) 340static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b_ptr)
384{ 341{
385 pr_info("Resetting bearer <%s>\n", b_ptr->name); 342 pr_info("Resetting bearer <%s>\n", b_ptr->name);
386 tipc_link_reset_list(b_ptr->identity); 343 tipc_link_reset_list(net, b_ptr->identity);
387 tipc_disc_reset(b_ptr); 344 tipc_disc_reset(net, b_ptr);
388 return 0; 345 return 0;
389} 346}
390 347
@@ -393,49 +350,35 @@ static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
393 * 350 *
394 * Note: This routine assumes caller holds RTNL lock. 351 * Note: This routine assumes caller holds RTNL lock.
395 */ 352 */
396static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down) 353static void bearer_disable(struct net *net, struct tipc_bearer *b_ptr,
354 bool shutting_down)
397{ 355{
356 struct tipc_net *tn = net_generic(net, tipc_net_id);
398 u32 i; 357 u32 i;
399 358
400 pr_info("Disabling bearer <%s>\n", b_ptr->name); 359 pr_info("Disabling bearer <%s>\n", b_ptr->name);
401 b_ptr->media->disable_media(b_ptr); 360 b_ptr->media->disable_media(b_ptr);
402 361
403 tipc_link_delete_list(b_ptr->identity, shutting_down); 362 tipc_link_delete_list(net, b_ptr->identity, shutting_down);
404 if (b_ptr->link_req) 363 if (b_ptr->link_req)
405 tipc_disc_delete(b_ptr->link_req); 364 tipc_disc_delete(b_ptr->link_req);
406 365
407 for (i = 0; i < MAX_BEARERS; i++) { 366 for (i = 0; i < MAX_BEARERS; i++) {
408 if (b_ptr == rtnl_dereference(bearer_list[i])) { 367 if (b_ptr == rtnl_dereference(tn->bearer_list[i])) {
409 RCU_INIT_POINTER(bearer_list[i], NULL); 368 RCU_INIT_POINTER(tn->bearer_list[i], NULL);
410 break; 369 break;
411 } 370 }
412 } 371 }
413 kfree_rcu(b_ptr, rcu); 372 kfree_rcu(b_ptr, rcu);
414} 373}
415 374
416int tipc_disable_bearer(const char *name) 375int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b)
417{
418 struct tipc_bearer *b_ptr;
419 int res;
420
421 b_ptr = tipc_bearer_find(name);
422 if (b_ptr == NULL) {
423 pr_warn("Attempt to disable unknown bearer <%s>\n", name);
424 res = -EINVAL;
425 } else {
426 bearer_disable(b_ptr, false);
427 res = 0;
428 }
429 return res;
430}
431
432int tipc_enable_l2_media(struct tipc_bearer *b)
433{ 376{
434 struct net_device *dev; 377 struct net_device *dev;
435 char *driver_name = strchr((const char *)b->name, ':') + 1; 378 char *driver_name = strchr((const char *)b->name, ':') + 1;
436 379
437 /* Find device with specified name */ 380 /* Find device with specified name */
438 dev = dev_get_by_name(&init_net, driver_name); 381 dev = dev_get_by_name(net, driver_name);
439 if (!dev) 382 if (!dev)
440 return -ENODEV; 383 return -ENODEV;
441 384
@@ -474,8 +417,8 @@ void tipc_disable_l2_media(struct tipc_bearer *b)
474 * @b_ptr: the bearer through which the packet is to be sent 417 * @b_ptr: the bearer through which the packet is to be sent
475 * @dest: peer destination address 418 * @dest: peer destination address
476 */ 419 */
477int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, 420int tipc_l2_send_msg(struct net *net, struct sk_buff *buf,
478 struct tipc_media_addr *dest) 421 struct tipc_bearer *b, struct tipc_media_addr *dest)
479{ 422{
480 struct sk_buff *clone; 423 struct sk_buff *clone;
481 struct net_device *dev; 424 struct net_device *dev;
@@ -511,15 +454,16 @@ int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
511 * The media send routine must not alter the buffer being passed in 454 * The media send routine must not alter the buffer being passed in
512 * as it may be needed for later retransmission! 455 * as it may be needed for later retransmission!
513 */ 456 */
514void tipc_bearer_send(u32 bearer_id, struct sk_buff *buf, 457void tipc_bearer_send(struct net *net, u32 bearer_id, struct sk_buff *buf,
515 struct tipc_media_addr *dest) 458 struct tipc_media_addr *dest)
516{ 459{
460 struct tipc_net *tn = net_generic(net, tipc_net_id);
517 struct tipc_bearer *b_ptr; 461 struct tipc_bearer *b_ptr;
518 462
519 rcu_read_lock(); 463 rcu_read_lock();
520 b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); 464 b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
521 if (likely(b_ptr)) 465 if (likely(b_ptr))
522 b_ptr->media->send_msg(buf, b_ptr, dest); 466 b_ptr->media->send_msg(net, buf, b_ptr, dest);
523 rcu_read_unlock(); 467 rcu_read_unlock();
524} 468}
525 469
@@ -539,17 +483,12 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
539{ 483{
540 struct tipc_bearer *b_ptr; 484 struct tipc_bearer *b_ptr;
541 485
542 if (!net_eq(dev_net(dev), &init_net)) {
543 kfree_skb(buf);
544 return NET_RX_DROP;
545 }
546
547 rcu_read_lock(); 486 rcu_read_lock();
548 b_ptr = rcu_dereference_rtnl(dev->tipc_ptr); 487 b_ptr = rcu_dereference_rtnl(dev->tipc_ptr);
549 if (likely(b_ptr)) { 488 if (likely(b_ptr)) {
550 if (likely(buf->pkt_type <= PACKET_BROADCAST)) { 489 if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
551 buf->next = NULL; 490 buf->next = NULL;
552 tipc_rcv(buf, b_ptr); 491 tipc_rcv(dev_net(dev), buf, b_ptr);
553 rcu_read_unlock(); 492 rcu_read_unlock();
554 return NET_RX_SUCCESS; 493 return NET_RX_SUCCESS;
555 } 494 }
@@ -572,11 +511,9 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
572static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, 511static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
573 void *ptr) 512 void *ptr)
574{ 513{
575 struct tipc_bearer *b_ptr;
576 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 514 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
577 515 struct net *net = dev_net(dev);
578 if (!net_eq(dev_net(dev), &init_net)) 516 struct tipc_bearer *b_ptr;
579 return NOTIFY_DONE;
580 517
581 b_ptr = rtnl_dereference(dev->tipc_ptr); 518 b_ptr = rtnl_dereference(dev->tipc_ptr);
582 if (!b_ptr) 519 if (!b_ptr)
@@ -590,16 +527,16 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
590 break; 527 break;
591 case NETDEV_DOWN: 528 case NETDEV_DOWN:
592 case NETDEV_CHANGEMTU: 529 case NETDEV_CHANGEMTU:
593 tipc_reset_bearer(b_ptr); 530 tipc_reset_bearer(net, b_ptr);
594 break; 531 break;
595 case NETDEV_CHANGEADDR: 532 case NETDEV_CHANGEADDR:
596 b_ptr->media->raw2addr(b_ptr, &b_ptr->addr, 533 b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
597 (char *)dev->dev_addr); 534 (char *)dev->dev_addr);
598 tipc_reset_bearer(b_ptr); 535 tipc_reset_bearer(net, b_ptr);
599 break; 536 break;
600 case NETDEV_UNREGISTER: 537 case NETDEV_UNREGISTER:
601 case NETDEV_CHANGENAME: 538 case NETDEV_CHANGENAME:
602 bearer_disable(b_ptr, false); 539 bearer_disable(dev_net(dev), b_ptr, false);
603 break; 540 break;
604 } 541 }
605 return NOTIFY_OK; 542 return NOTIFY_OK;
@@ -632,16 +569,17 @@ void tipc_bearer_cleanup(void)
632 dev_remove_pack(&tipc_packet_type); 569 dev_remove_pack(&tipc_packet_type);
633} 570}
634 571
635void tipc_bearer_stop(void) 572void tipc_bearer_stop(struct net *net)
636{ 573{
574 struct tipc_net *tn = net_generic(net, tipc_net_id);
637 struct tipc_bearer *b_ptr; 575 struct tipc_bearer *b_ptr;
638 u32 i; 576 u32 i;
639 577
640 for (i = 0; i < MAX_BEARERS; i++) { 578 for (i = 0; i < MAX_BEARERS; i++) {
641 b_ptr = rtnl_dereference(bearer_list[i]); 579 b_ptr = rtnl_dereference(tn->bearer_list[i]);
642 if (b_ptr) { 580 if (b_ptr) {
643 bearer_disable(b_ptr, true); 581 bearer_disable(net, b_ptr, true);
644 bearer_list[i] = NULL; 582 tn->bearer_list[i] = NULL;
645 } 583 }
646 } 584 }
647} 585}
@@ -654,7 +592,7 @@ static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
654 struct nlattr *attrs; 592 struct nlattr *attrs;
655 struct nlattr *prop; 593 struct nlattr *prop;
656 594
657 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, 595 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
658 NLM_F_MULTI, TIPC_NL_BEARER_GET); 596 NLM_F_MULTI, TIPC_NL_BEARER_GET);
659 if (!hdr) 597 if (!hdr)
660 return -EMSGSIZE; 598 return -EMSGSIZE;
@@ -698,6 +636,8 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
698 int i = cb->args[0]; 636 int i = cb->args[0];
699 struct tipc_bearer *bearer; 637 struct tipc_bearer *bearer;
700 struct tipc_nl_msg msg; 638 struct tipc_nl_msg msg;
639 struct net *net = sock_net(skb->sk);
640 struct tipc_net *tn = net_generic(net, tipc_net_id);
701 641
702 if (i == MAX_BEARERS) 642 if (i == MAX_BEARERS)
703 return 0; 643 return 0;
@@ -708,7 +648,7 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
708 648
709 rtnl_lock(); 649 rtnl_lock();
710 for (i = 0; i < MAX_BEARERS; i++) { 650 for (i = 0; i < MAX_BEARERS; i++) {
711 bearer = rtnl_dereference(bearer_list[i]); 651 bearer = rtnl_dereference(tn->bearer_list[i]);
712 if (!bearer) 652 if (!bearer)
713 continue; 653 continue;
714 654
@@ -730,6 +670,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
730 struct tipc_bearer *bearer; 670 struct tipc_bearer *bearer;
731 struct tipc_nl_msg msg; 671 struct tipc_nl_msg msg;
732 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 672 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
673 struct net *net = genl_info_net(info);
733 674
734 if (!info->attrs[TIPC_NLA_BEARER]) 675 if (!info->attrs[TIPC_NLA_BEARER])
735 return -EINVAL; 676 return -EINVAL;
@@ -753,7 +694,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
753 msg.seq = info->snd_seq; 694 msg.seq = info->snd_seq;
754 695
755 rtnl_lock(); 696 rtnl_lock();
756 bearer = tipc_bearer_find(name); 697 bearer = tipc_bearer_find(net, name);
757 if (!bearer) { 698 if (!bearer) {
758 err = -EINVAL; 699 err = -EINVAL;
759 goto err_out; 700 goto err_out;
@@ -778,6 +719,7 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
778 char *name; 719 char *name;
779 struct tipc_bearer *bearer; 720 struct tipc_bearer *bearer;
780 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 721 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
722 struct net *net = sock_net(skb->sk);
781 723
782 if (!info->attrs[TIPC_NLA_BEARER]) 724 if (!info->attrs[TIPC_NLA_BEARER])
783 return -EINVAL; 725 return -EINVAL;
@@ -794,13 +736,13 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
794 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); 736 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
795 737
796 rtnl_lock(); 738 rtnl_lock();
797 bearer = tipc_bearer_find(name); 739 bearer = tipc_bearer_find(net, name);
798 if (!bearer) { 740 if (!bearer) {
799 rtnl_unlock(); 741 rtnl_unlock();
800 return -EINVAL; 742 return -EINVAL;
801 } 743 }
802 744
803 bearer_disable(bearer, false); 745 bearer_disable(net, bearer, false);
804 rtnl_unlock(); 746 rtnl_unlock();
805 747
806 return 0; 748 return 0;
@@ -811,11 +753,13 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
811 int err; 753 int err;
812 char *bearer; 754 char *bearer;
813 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 755 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
756 struct net *net = sock_net(skb->sk);
757 struct tipc_net *tn = net_generic(net, tipc_net_id);
814 u32 domain; 758 u32 domain;
815 u32 prio; 759 u32 prio;
816 760
817 prio = TIPC_MEDIA_LINK_PRI; 761 prio = TIPC_MEDIA_LINK_PRI;
818 domain = tipc_own_addr & TIPC_CLUSTER_MASK; 762 domain = tn->own_addr & TIPC_CLUSTER_MASK;
819 763
820 if (!info->attrs[TIPC_NLA_BEARER]) 764 if (!info->attrs[TIPC_NLA_BEARER])
821 return -EINVAL; 765 return -EINVAL;
@@ -847,7 +791,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
847 } 791 }
848 792
849 rtnl_lock(); 793 rtnl_lock();
850 err = tipc_enable_bearer(bearer, domain, prio); 794 err = tipc_enable_bearer(net, bearer, domain, prio);
851 if (err) { 795 if (err) {
852 rtnl_unlock(); 796 rtnl_unlock();
853 return err; 797 return err;
@@ -863,6 +807,7 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
863 char *name; 807 char *name;
864 struct tipc_bearer *b; 808 struct tipc_bearer *b;
865 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 809 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
810 struct net *net = genl_info_net(info);
866 811
867 if (!info->attrs[TIPC_NLA_BEARER]) 812 if (!info->attrs[TIPC_NLA_BEARER])
868 return -EINVAL; 813 return -EINVAL;
@@ -878,7 +823,7 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
878 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); 823 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
879 824
880 rtnl_lock(); 825 rtnl_lock();
881 b = tipc_bearer_find(name); 826 b = tipc_bearer_find(net, name);
882 if (!b) { 827 if (!b) {
883 rtnl_unlock(); 828 rtnl_unlock();
884 return -EINVAL; 829 return -EINVAL;
@@ -913,7 +858,7 @@ static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
913 struct nlattr *attrs; 858 struct nlattr *attrs;
914 struct nlattr *prop; 859 struct nlattr *prop;
915 860
916 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, 861 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
917 NLM_F_MULTI, TIPC_NL_MEDIA_GET); 862 NLM_F_MULTI, TIPC_NL_MEDIA_GET);
918 if (!hdr) 863 if (!hdr)
919 return -EMSGSIZE; 864 return -EMSGSIZE;