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.c151
1 files changed, 79 insertions, 72 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 837b7a467885..85209eadfae6 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -2,7 +2,7 @@
2 * net/tipc/bearer.c: TIPC bearer code 2 * net/tipc/bearer.c: TIPC bearer code
3 * 3 *
4 * Copyright (c) 1996-2006, Ericsson AB 4 * Copyright (c) 1996-2006, Ericsson AB
5 * Copyright (c) 2004-2006, Wind River Systems 5 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,9 @@
44static struct media media_list[MAX_MEDIA]; 44static struct media media_list[MAX_MEDIA];
45static u32 media_count; 45static u32 media_count;
46 46
47struct bearer tipc_bearers[MAX_BEARERS]; 47struct tipc_bearer tipc_bearers[MAX_BEARERS];
48
49static void bearer_disable(struct tipc_bearer *b_ptr);
48 50
49/** 51/**
50 * media_name_valid - validate media name 52 * media_name_valid - validate media name
@@ -158,7 +160,6 @@ int tipc_register_media(u32 media_type,
158 m_ptr->disable_bearer = disable; 160 m_ptr->disable_bearer = disable;
159 m_ptr->addr2str = addr2str; 161 m_ptr->addr2str = addr2str;
160 memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr)); 162 memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
161 m_ptr->bcast = 1;
162 strcpy(m_ptr->name, name); 163 strcpy(m_ptr->name, name);
163 m_ptr->priority = bearer_priority; 164 m_ptr->priority = bearer_priority;
164 m_ptr->tolerance = link_tolerance; 165 m_ptr->tolerance = link_tolerance;
@@ -278,13 +279,13 @@ static int bearer_name_validate(const char *name,
278 * bearer_find - locates bearer object with matching bearer name 279 * bearer_find - locates bearer object with matching bearer name
279 */ 280 */
280 281
281static struct bearer *bearer_find(const char *name) 282static struct tipc_bearer *bearer_find(const char *name)
282{ 283{
283 struct bearer *b_ptr; 284 struct tipc_bearer *b_ptr;
284 u32 i; 285 u32 i;
285 286
286 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { 287 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
287 if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) 288 if (b_ptr->active && (!strcmp(b_ptr->name, name)))
288 return b_ptr; 289 return b_ptr;
289 } 290 }
290 return NULL; 291 return NULL;
@@ -294,16 +295,16 @@ static struct bearer *bearer_find(const char *name)
294 * tipc_bearer_find_interface - locates bearer object with matching interface name 295 * tipc_bearer_find_interface - locates bearer object with matching interface name
295 */ 296 */
296 297
297struct bearer *tipc_bearer_find_interface(const char *if_name) 298struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
298{ 299{
299 struct bearer *b_ptr; 300 struct tipc_bearer *b_ptr;
300 char *b_if_name; 301 char *b_if_name;
301 u32 i; 302 u32 i;
302 303
303 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { 304 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
304 if (!b_ptr->active) 305 if (!b_ptr->active)
305 continue; 306 continue;
306 b_if_name = strchr(b_ptr->publ.name, ':') + 1; 307 b_if_name = strchr(b_ptr->name, ':') + 1;
307 if (!strcmp(b_if_name, if_name)) 308 if (!strcmp(b_if_name, if_name))
308 return b_ptr; 309 return b_ptr;
309 } 310 }
@@ -318,7 +319,7 @@ struct sk_buff *tipc_bearer_get_names(void)
318{ 319{
319 struct sk_buff *buf; 320 struct sk_buff *buf;
320 struct media *m_ptr; 321 struct media *m_ptr;
321 struct bearer *b_ptr; 322 struct tipc_bearer *b_ptr;
322 int i, j; 323 int i, j;
323 324
324 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); 325 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
@@ -331,8 +332,8 @@ struct sk_buff *tipc_bearer_get_names(void)
331 b_ptr = &tipc_bearers[j]; 332 b_ptr = &tipc_bearers[j];
332 if (b_ptr->active && (b_ptr->media == m_ptr)) { 333 if (b_ptr->active && (b_ptr->media == m_ptr)) {
333 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, 334 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
334 b_ptr->publ.name, 335 b_ptr->name,
335 strlen(b_ptr->publ.name) + 1); 336 strlen(b_ptr->name) + 1);
336 } 337 }
337 } 338 }
338 } 339 }
@@ -340,18 +341,18 @@ struct sk_buff *tipc_bearer_get_names(void)
340 return buf; 341 return buf;
341} 342}
342 343
343void tipc_bearer_add_dest(struct bearer *b_ptr, u32 dest) 344void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
344{ 345{
345 tipc_nmap_add(&b_ptr->nodes, dest); 346 tipc_nmap_add(&b_ptr->nodes, dest);
346 tipc_disc_update_link_req(b_ptr->link_req);
347 tipc_bcbearer_sort(); 347 tipc_bcbearer_sort();
348 tipc_disc_add_dest(b_ptr->link_req);
348} 349}
349 350
350void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest) 351void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
351{ 352{
352 tipc_nmap_remove(&b_ptr->nodes, dest); 353 tipc_nmap_remove(&b_ptr->nodes, dest);
353 tipc_disc_update_link_req(b_ptr->link_req);
354 tipc_bcbearer_sort(); 354 tipc_bcbearer_sort();
355 tipc_disc_remove_dest(b_ptr->link_req);
355} 356}
356 357
357/* 358/*
@@ -362,12 +363,12 @@ void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
362 * bearer.lock must be taken before calling 363 * bearer.lock must be taken before calling
363 * Returns binary true(1) ore false(0) 364 * Returns binary true(1) ore false(0)
364 */ 365 */
365static int bearer_push(struct bearer *b_ptr) 366static int bearer_push(struct tipc_bearer *b_ptr)
366{ 367{
367 u32 res = 0; 368 u32 res = 0;
368 struct link *ln, *tln; 369 struct link *ln, *tln;
369 370
370 if (b_ptr->publ.blocked) 371 if (b_ptr->blocked)
371 return 0; 372 return 0;
372 373
373 while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) { 374 while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
@@ -382,13 +383,13 @@ static int bearer_push(struct bearer *b_ptr)
382 return list_empty(&b_ptr->cong_links); 383 return list_empty(&b_ptr->cong_links);
383} 384}
384 385
385void tipc_bearer_lock_push(struct bearer *b_ptr) 386void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
386{ 387{
387 int res; 388 int res;
388 389
389 spin_lock_bh(&b_ptr->publ.lock); 390 spin_lock_bh(&b_ptr->lock);
390 res = bearer_push(b_ptr); 391 res = bearer_push(b_ptr);
391 spin_unlock_bh(&b_ptr->publ.lock); 392 spin_unlock_bh(&b_ptr->lock);
392 if (res) 393 if (res)
393 tipc_bcbearer_push(); 394 tipc_bcbearer_push();
394} 395}
@@ -398,16 +399,14 @@ void tipc_bearer_lock_push(struct bearer *b_ptr)
398 * Interrupt enabling new requests after bearer congestion or blocking: 399 * Interrupt enabling new requests after bearer congestion or blocking:
399 * See bearer_send(). 400 * See bearer_send().
400 */ 401 */
401void tipc_continue(struct tipc_bearer *tb_ptr) 402void tipc_continue(struct tipc_bearer *b_ptr)
402{ 403{
403 struct bearer *b_ptr = (struct bearer *)tb_ptr; 404 spin_lock_bh(&b_ptr->lock);
404
405 spin_lock_bh(&b_ptr->publ.lock);
406 b_ptr->continue_count++; 405 b_ptr->continue_count++;
407 if (!list_empty(&b_ptr->cong_links)) 406 if (!list_empty(&b_ptr->cong_links))
408 tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr); 407 tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
409 b_ptr->publ.blocked = 0; 408 b_ptr->blocked = 0;
410 spin_unlock_bh(&b_ptr->publ.lock); 409 spin_unlock_bh(&b_ptr->lock);
411} 410}
412 411
413/* 412/*
@@ -418,7 +417,7 @@ void tipc_continue(struct tipc_bearer *tb_ptr)
418 * bearer.lock is busy 417 * bearer.lock is busy
419 */ 418 */
420 419
421static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_ptr) 420static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
422{ 421{
423 list_move_tail(&l_ptr->link_list, &b_ptr->cong_links); 422 list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
424} 423}
@@ -431,11 +430,11 @@ static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_p
431 * bearer.lock is free 430 * bearer.lock is free
432 */ 431 */
433 432
434void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr) 433void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
435{ 434{
436 spin_lock_bh(&b_ptr->publ.lock); 435 spin_lock_bh(&b_ptr->lock);
437 tipc_bearer_schedule_unlocked(b_ptr, l_ptr); 436 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
438 spin_unlock_bh(&b_ptr->publ.lock); 437 spin_unlock_bh(&b_ptr->lock);
439} 438}
440 439
441 440
@@ -444,18 +443,18 @@ void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
444 * and if there is, try to resolve it before returning. 443 * and if there is, try to resolve it before returning.
445 * 'tipc_net_lock' is read_locked when this function is called 444 * 'tipc_net_lock' is read_locked when this function is called
446 */ 445 */
447int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr) 446int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
448{ 447{
449 int res = 1; 448 int res = 1;
450 449
451 if (list_empty(&b_ptr->cong_links)) 450 if (list_empty(&b_ptr->cong_links))
452 return 1; 451 return 1;
453 spin_lock_bh(&b_ptr->publ.lock); 452 spin_lock_bh(&b_ptr->lock);
454 if (!bearer_push(b_ptr)) { 453 if (!bearer_push(b_ptr)) {
455 tipc_bearer_schedule_unlocked(b_ptr, l_ptr); 454 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
456 res = 0; 455 res = 0;
457 } 456 }
458 spin_unlock_bh(&b_ptr->publ.lock); 457 spin_unlock_bh(&b_ptr->lock);
459 return res; 458 return res;
460} 459}
461 460
@@ -463,9 +462,9 @@ int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr)
463 * tipc_bearer_congested - determines if bearer is currently congested 462 * tipc_bearer_congested - determines if bearer is currently congested
464 */ 463 */
465 464
466int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr) 465int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
467{ 466{
468 if (unlikely(b_ptr->publ.blocked)) 467 if (unlikely(b_ptr->blocked))
469 return 1; 468 return 1;
470 if (likely(list_empty(&b_ptr->cong_links))) 469 if (likely(list_empty(&b_ptr->cong_links)))
471 return 0; 470 return 0;
@@ -476,9 +475,9 @@ int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
476 * tipc_enable_bearer - enable bearer with the given name 475 * tipc_enable_bearer - enable bearer with the given name
477 */ 476 */
478 477
479int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) 478int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
480{ 479{
481 struct bearer *b_ptr; 480 struct tipc_bearer *b_ptr;
482 struct media *m_ptr; 481 struct media *m_ptr;
483 struct bearer_name b_name; 482 struct bearer_name b_name;
484 char addr_string[16]; 483 char addr_string[16];
@@ -496,9 +495,16 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
496 warn("Bearer <%s> rejected, illegal name\n", name); 495 warn("Bearer <%s> rejected, illegal name\n", name);
497 return -EINVAL; 496 return -EINVAL;
498 } 497 }
499 if (!tipc_addr_domain_valid(bcast_scope) || 498 if (tipc_addr_domain_valid(disc_domain) &&
500 !tipc_in_scope(bcast_scope, tipc_own_addr)) { 499 (disc_domain != tipc_own_addr)) {
501 warn("Bearer <%s> rejected, illegal broadcast scope\n", name); 500 if (tipc_in_scope(disc_domain, tipc_own_addr)) {
501 disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
502 res = 0; /* accept any node in own cluster */
503 } else if (in_own_cluster(disc_domain))
504 res = 0; /* accept specified node in own cluster */
505 }
506 if (res) {
507 warn("Bearer <%s> rejected, illegal discovery domain\n", name);
502 return -EINVAL; 508 return -EINVAL;
503 } 509 }
504 if ((priority < TIPC_MIN_LINK_PRI || 510 if ((priority < TIPC_MIN_LINK_PRI ||
@@ -514,7 +520,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
514 if (!m_ptr) { 520 if (!m_ptr) {
515 warn("Bearer <%s> rejected, media <%s> not registered\n", name, 521 warn("Bearer <%s> rejected, media <%s> not registered\n", name,
516 b_name.media_name); 522 b_name.media_name);
517 goto failed; 523 goto exit;
518 } 524 }
519 525
520 if (priority == TIPC_MEDIA_LINK_PRI) 526 if (priority == TIPC_MEDIA_LINK_PRI)
@@ -528,16 +534,16 @@ restart:
528 bearer_id = i; 534 bearer_id = i;
529 continue; 535 continue;
530 } 536 }
531 if (!strcmp(name, tipc_bearers[i].publ.name)) { 537 if (!strcmp(name, tipc_bearers[i].name)) {
532 warn("Bearer <%s> rejected, already enabled\n", name); 538 warn("Bearer <%s> rejected, already enabled\n", name);
533 goto failed; 539 goto exit;
534 } 540 }
535 if ((tipc_bearers[i].priority == priority) && 541 if ((tipc_bearers[i].priority == priority) &&
536 (++with_this_prio > 2)) { 542 (++with_this_prio > 2)) {
537 if (priority-- == 0) { 543 if (priority-- == 0) {
538 warn("Bearer <%s> rejected, duplicate priority\n", 544 warn("Bearer <%s> rejected, duplicate priority\n",
539 name); 545 name);
540 goto failed; 546 goto exit;
541 } 547 }
542 warn("Bearer <%s> priority adjustment required %u->%u\n", 548 warn("Bearer <%s> priority adjustment required %u->%u\n",
543 name, priority + 1, priority); 549 name, priority + 1, priority);
@@ -547,35 +553,36 @@ restart:
547 if (bearer_id >= MAX_BEARERS) { 553 if (bearer_id >= MAX_BEARERS) {
548 warn("Bearer <%s> rejected, bearer limit reached (%u)\n", 554 warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
549 name, MAX_BEARERS); 555 name, MAX_BEARERS);
550 goto failed; 556 goto exit;
551 } 557 }
552 558
553 b_ptr = &tipc_bearers[bearer_id]; 559 b_ptr = &tipc_bearers[bearer_id];
554 strcpy(b_ptr->publ.name, name); 560 strcpy(b_ptr->name, name);
555 res = m_ptr->enable_bearer(&b_ptr->publ); 561 res = m_ptr->enable_bearer(b_ptr);
556 if (res) { 562 if (res) {
557 warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res); 563 warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
558 goto failed; 564 goto exit;
559 } 565 }
560 566
561 b_ptr->identity = bearer_id; 567 b_ptr->identity = bearer_id;
562 b_ptr->media = m_ptr; 568 b_ptr->media = m_ptr;
563 b_ptr->net_plane = bearer_id + 'A'; 569 b_ptr->net_plane = bearer_id + 'A';
564 b_ptr->active = 1; 570 b_ptr->active = 1;
565 b_ptr->detect_scope = bcast_scope;
566 b_ptr->priority = priority; 571 b_ptr->priority = priority;
567 INIT_LIST_HEAD(&b_ptr->cong_links); 572 INIT_LIST_HEAD(&b_ptr->cong_links);
568 INIT_LIST_HEAD(&b_ptr->links); 573 INIT_LIST_HEAD(&b_ptr->links);
569 if (m_ptr->bcast) { 574 spin_lock_init(&b_ptr->lock);
570 b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr, 575
571 bcast_scope, 2); 576 res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain);
577 if (res) {
578 bearer_disable(b_ptr);
579 warn("Bearer <%s> rejected, discovery object creation failed\n",
580 name);
581 goto exit;
572 } 582 }
573 spin_lock_init(&b_ptr->publ.lock);
574 write_unlock_bh(&tipc_net_lock);
575 info("Enabled bearer <%s>, discovery domain %s, priority %u\n", 583 info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
576 name, tipc_addr_string_fill(addr_string, bcast_scope), priority); 584 name, tipc_addr_string_fill(addr_string, disc_domain), priority);
577 return 0; 585exit:
578failed:
579 write_unlock_bh(&tipc_net_lock); 586 write_unlock_bh(&tipc_net_lock);
580 return res; 587 return res;
581} 588}
@@ -587,7 +594,7 @@ failed:
587 594
588int tipc_block_bearer(const char *name) 595int tipc_block_bearer(const char *name)
589{ 596{
590 struct bearer *b_ptr = NULL; 597 struct tipc_bearer *b_ptr = NULL;
591 struct link *l_ptr; 598 struct link *l_ptr;
592 struct link *temp_l_ptr; 599 struct link *temp_l_ptr;
593 600
@@ -600,8 +607,8 @@ int tipc_block_bearer(const char *name)
600 } 607 }
601 608
602 info("Blocking bearer <%s>\n", name); 609 info("Blocking bearer <%s>\n", name);
603 spin_lock_bh(&b_ptr->publ.lock); 610 spin_lock_bh(&b_ptr->lock);
604 b_ptr->publ.blocked = 1; 611 b_ptr->blocked = 1;
605 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 612 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
606 struct tipc_node *n_ptr = l_ptr->owner; 613 struct tipc_node *n_ptr = l_ptr->owner;
607 614
@@ -609,7 +616,7 @@ int tipc_block_bearer(const char *name)
609 tipc_link_reset(l_ptr); 616 tipc_link_reset(l_ptr);
610 spin_unlock_bh(&n_ptr->lock); 617 spin_unlock_bh(&n_ptr->lock);
611 } 618 }
612 spin_unlock_bh(&b_ptr->publ.lock); 619 spin_unlock_bh(&b_ptr->lock);
613 read_unlock_bh(&tipc_net_lock); 620 read_unlock_bh(&tipc_net_lock);
614 return 0; 621 return 0;
615} 622}
@@ -620,27 +627,27 @@ int tipc_block_bearer(const char *name)
620 * Note: This routine assumes caller holds tipc_net_lock. 627 * Note: This routine assumes caller holds tipc_net_lock.
621 */ 628 */
622 629
623static void bearer_disable(struct bearer *b_ptr) 630static void bearer_disable(struct tipc_bearer *b_ptr)
624{ 631{
625 struct link *l_ptr; 632 struct link *l_ptr;
626 struct link *temp_l_ptr; 633 struct link *temp_l_ptr;
627 634
628 info("Disabling bearer <%s>\n", b_ptr->publ.name); 635 info("Disabling bearer <%s>\n", b_ptr->name);
629 tipc_disc_stop_link_req(b_ptr->link_req); 636 spin_lock_bh(&b_ptr->lock);
630 spin_lock_bh(&b_ptr->publ.lock); 637 b_ptr->blocked = 1;
631 b_ptr->link_req = NULL; 638 b_ptr->media->disable_bearer(b_ptr);
632 b_ptr->publ.blocked = 1;
633 b_ptr->media->disable_bearer(&b_ptr->publ);
634 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 639 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
635 tipc_link_delete(l_ptr); 640 tipc_link_delete(l_ptr);
636 } 641 }
637 spin_unlock_bh(&b_ptr->publ.lock); 642 if (b_ptr->link_req)
638 memset(b_ptr, 0, sizeof(struct bearer)); 643 tipc_disc_delete(b_ptr->link_req);
644 spin_unlock_bh(&b_ptr->lock);
645 memset(b_ptr, 0, sizeof(struct tipc_bearer));
639} 646}
640 647
641int tipc_disable_bearer(const char *name) 648int tipc_disable_bearer(const char *name)
642{ 649{
643 struct bearer *b_ptr; 650 struct tipc_bearer *b_ptr;
644 int res; 651 int res;
645 652
646 write_lock_bh(&tipc_net_lock); 653 write_lock_bh(&tipc_net_lock);