diff options
Diffstat (limited to 'net/tipc/bearer.c')
| -rw-r--r-- | net/tipc/bearer.c | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index e213a8e54855..75a5968c2139 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
| @@ -112,39 +112,42 @@ int tipc_register_media(u32 media_type, | |||
| 112 | goto exit; | 112 | goto exit; |
| 113 | 113 | ||
| 114 | if (!media_name_valid(name)) { | 114 | if (!media_name_valid(name)) { |
| 115 | warn("Media registration error: illegal name <%s>\n", name); | 115 | warn("Media <%s> rejected, illegal name\n", name); |
| 116 | goto exit; | 116 | goto exit; |
| 117 | } | 117 | } |
| 118 | if (!bcast_addr) { | 118 | if (!bcast_addr) { |
| 119 | warn("Media registration error: no broadcast address supplied\n"); | 119 | warn("Media <%s> rejected, no broadcast address\n", name); |
| 120 | goto exit; | 120 | goto exit; |
| 121 | } | 121 | } |
| 122 | if ((bearer_priority < TIPC_MIN_LINK_PRI) && | 122 | if ((bearer_priority < TIPC_MIN_LINK_PRI) && |
| 123 | (bearer_priority > TIPC_MAX_LINK_PRI)) { | 123 | (bearer_priority > TIPC_MAX_LINK_PRI)) { |
| 124 | warn("Media registration error: priority %u\n", bearer_priority); | 124 | warn("Media <%s> rejected, illegal priority (%u)\n", name, |
| 125 | bearer_priority); | ||
| 125 | goto exit; | 126 | goto exit; |
| 126 | } | 127 | } |
| 127 | if ((link_tolerance < TIPC_MIN_LINK_TOL) || | 128 | if ((link_tolerance < TIPC_MIN_LINK_TOL) || |
| 128 | (link_tolerance > TIPC_MAX_LINK_TOL)) { | 129 | (link_tolerance > TIPC_MAX_LINK_TOL)) { |
| 129 | warn("Media registration error: tolerance %u\n", link_tolerance); | 130 | warn("Media <%s> rejected, illegal tolerance (%u)\n", name, |
| 131 | link_tolerance); | ||
| 130 | goto exit; | 132 | goto exit; |
| 131 | } | 133 | } |
| 132 | 134 | ||
| 133 | media_id = media_count++; | 135 | media_id = media_count++; |
| 134 | if (media_id >= MAX_MEDIA) { | 136 | if (media_id >= MAX_MEDIA) { |
| 135 | warn("Attempt to register more than %u media\n", MAX_MEDIA); | 137 | warn("Media <%s> rejected, media limit reached (%u)\n", name, |
| 138 | MAX_MEDIA); | ||
| 136 | media_count--; | 139 | media_count--; |
| 137 | goto exit; | 140 | goto exit; |
| 138 | } | 141 | } |
| 139 | for (i = 0; i < media_id; i++) { | 142 | for (i = 0; i < media_id; i++) { |
| 140 | if (media_list[i].type_id == media_type) { | 143 | if (media_list[i].type_id == media_type) { |
| 141 | warn("Attempt to register second media with type %u\n", | 144 | warn("Media <%s> rejected, duplicate type (%u)\n", name, |
| 142 | media_type); | 145 | media_type); |
| 143 | media_count--; | 146 | media_count--; |
| 144 | goto exit; | 147 | goto exit; |
| 145 | } | 148 | } |
| 146 | if (!strcmp(name, media_list[i].name)) { | 149 | if (!strcmp(name, media_list[i].name)) { |
| 147 | warn("Attempt to re-register media name <%s>\n", name); | 150 | warn("Media <%s> rejected, duplicate name\n", name); |
| 148 | media_count--; | 151 | media_count--; |
| 149 | goto exit; | 152 | goto exit; |
| 150 | } | 153 | } |
| @@ -283,6 +286,9 @@ static struct bearer *bearer_find(const char *name) | |||
| 283 | struct bearer *b_ptr; | 286 | struct bearer *b_ptr; |
| 284 | u32 i; | 287 | u32 i; |
| 285 | 288 | ||
| 289 | if (tipc_mode != TIPC_NET_MODE) | ||
| 290 | return NULL; | ||
| 291 | |||
| 286 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { | 292 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { |
| 287 | if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) | 293 | if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) |
| 288 | return b_ptr; | 294 | return b_ptr; |
| @@ -475,26 +481,33 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) | |||
| 475 | u32 i; | 481 | u32 i; |
| 476 | int res = -EINVAL; | 482 | int res = -EINVAL; |
| 477 | 483 | ||
| 478 | if (tipc_mode != TIPC_NET_MODE) | 484 | if (tipc_mode != TIPC_NET_MODE) { |
| 485 | warn("Bearer <%s> rejected, not supported in standalone mode\n", | ||
| 486 | name); | ||
| 479 | return -ENOPROTOOPT; | 487 | return -ENOPROTOOPT; |
| 480 | 488 | } | |
| 481 | if (!bearer_name_validate(name, &b_name) || | 489 | if (!bearer_name_validate(name, &b_name)) { |
| 482 | !tipc_addr_domain_valid(bcast_scope) || | 490 | warn("Bearer <%s> rejected, illegal name\n", name); |
| 483 | !in_scope(bcast_scope, tipc_own_addr)) | ||
| 484 | return -EINVAL; | 491 | return -EINVAL; |
| 485 | 492 | } | |
| 493 | if (!tipc_addr_domain_valid(bcast_scope) || | ||
| 494 | !in_scope(bcast_scope, tipc_own_addr)) { | ||
| 495 | warn("Bearer <%s> rejected, illegal broadcast scope\n", name); | ||
| 496 | return -EINVAL; | ||
| 497 | } | ||
| 486 | if ((priority < TIPC_MIN_LINK_PRI || | 498 | if ((priority < TIPC_MIN_LINK_PRI || |
| 487 | priority > TIPC_MAX_LINK_PRI) && | 499 | priority > TIPC_MAX_LINK_PRI) && |
| 488 | (priority != TIPC_MEDIA_LINK_PRI)) | 500 | (priority != TIPC_MEDIA_LINK_PRI)) { |
| 501 | warn("Bearer <%s> rejected, illegal priority\n", name); | ||
| 489 | return -EINVAL; | 502 | return -EINVAL; |
| 503 | } | ||
| 490 | 504 | ||
| 491 | write_lock_bh(&tipc_net_lock); | 505 | write_lock_bh(&tipc_net_lock); |
| 492 | if (!tipc_bearers) | ||
| 493 | goto failed; | ||
| 494 | 506 | ||
| 495 | m_ptr = media_find(b_name.media_name); | 507 | m_ptr = media_find(b_name.media_name); |
| 496 | if (!m_ptr) { | 508 | if (!m_ptr) { |
| 497 | warn("No media <%s>\n", b_name.media_name); | 509 | warn("Bearer <%s> rejected, media <%s> not registered\n", name, |
| 510 | b_name.media_name); | ||
| 498 | goto failed; | 511 | goto failed; |
| 499 | } | 512 | } |
| 500 | 513 | ||
| @@ -510,23 +523,24 @@ restart: | |||
| 510 | continue; | 523 | continue; |
| 511 | } | 524 | } |
| 512 | if (!strcmp(name, tipc_bearers[i].publ.name)) { | 525 | if (!strcmp(name, tipc_bearers[i].publ.name)) { |
| 513 | warn("Bearer <%s> already enabled\n", name); | 526 | warn("Bearer <%s> rejected, already enabled\n", name); |
| 514 | goto failed; | 527 | goto failed; |
| 515 | } | 528 | } |
| 516 | if ((tipc_bearers[i].priority == priority) && | 529 | if ((tipc_bearers[i].priority == priority) && |
| 517 | (++with_this_prio > 2)) { | 530 | (++with_this_prio > 2)) { |
| 518 | if (priority-- == 0) { | 531 | if (priority-- == 0) { |
| 519 | warn("Third bearer <%s> with priority %u, unable to lower to %u\n", | 532 | warn("Bearer <%s> rejected, duplicate priority\n", |
| 520 | name, priority + 1, priority); | 533 | name); |
| 521 | goto failed; | 534 | goto failed; |
| 522 | } | 535 | } |
| 523 | warn("Third bearer <%s> with priority %u, lowering to %u\n", | 536 | warn("Bearer <%s> priority adjustment required %u->%u\n", |
| 524 | name, priority + 1, priority); | 537 | name, priority + 1, priority); |
| 525 | goto restart; | 538 | goto restart; |
| 526 | } | 539 | } |
| 527 | } | 540 | } |
| 528 | if (bearer_id >= MAX_BEARERS) { | 541 | if (bearer_id >= MAX_BEARERS) { |
| 529 | warn("Attempt to enable more than %d bearers\n", MAX_BEARERS); | 542 | warn("Bearer <%s> rejected, bearer limit reached (%u)\n", |
| 543 | name, MAX_BEARERS); | ||
| 530 | goto failed; | 544 | goto failed; |
| 531 | } | 545 | } |
| 532 | 546 | ||
| @@ -536,7 +550,7 @@ restart: | |||
| 536 | strcpy(b_ptr->publ.name, name); | 550 | strcpy(b_ptr->publ.name, name); |
| 537 | res = m_ptr->enable_bearer(&b_ptr->publ); | 551 | res = m_ptr->enable_bearer(&b_ptr->publ); |
| 538 | if (res) { | 552 | if (res) { |
| 539 | warn("Failed to enable bearer <%s>\n", name); | 553 | warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res); |
| 540 | goto failed; | 554 | goto failed; |
| 541 | } | 555 | } |
| 542 | 556 | ||
| @@ -552,7 +566,7 @@ restart: | |||
| 552 | b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr, | 566 | b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr, |
| 553 | bcast_scope, 2); | 567 | bcast_scope, 2); |
| 554 | } | 568 | } |
| 555 | b_ptr->publ.lock = SPIN_LOCK_UNLOCKED; | 569 | spin_lock_init(&b_ptr->publ.lock); |
| 556 | write_unlock_bh(&tipc_net_lock); | 570 | write_unlock_bh(&tipc_net_lock); |
| 557 | info("Enabled bearer <%s>, discovery domain %s, priority %u\n", | 571 | info("Enabled bearer <%s>, discovery domain %s, priority %u\n", |
| 558 | name, addr_string_fill(addr_string, bcast_scope), priority); | 572 | name, addr_string_fill(addr_string, bcast_scope), priority); |
| @@ -573,9 +587,6 @@ int tipc_block_bearer(const char *name) | |||
| 573 | struct link *l_ptr; | 587 | struct link *l_ptr; |
| 574 | struct link *temp_l_ptr; | 588 | struct link *temp_l_ptr; |
| 575 | 589 | ||
| 576 | if (tipc_mode != TIPC_NET_MODE) | ||
| 577 | return -ENOPROTOOPT; | ||
| 578 | |||
| 579 | read_lock_bh(&tipc_net_lock); | 590 | read_lock_bh(&tipc_net_lock); |
| 580 | b_ptr = bearer_find(name); | 591 | b_ptr = bearer_find(name); |
| 581 | if (!b_ptr) { | 592 | if (!b_ptr) { |
| @@ -584,6 +595,7 @@ int tipc_block_bearer(const char *name) | |||
| 584 | return -EINVAL; | 595 | return -EINVAL; |
| 585 | } | 596 | } |
| 586 | 597 | ||
| 598 | info("Blocking bearer <%s>\n", name); | ||
| 587 | spin_lock_bh(&b_ptr->publ.lock); | 599 | spin_lock_bh(&b_ptr->publ.lock); |
| 588 | b_ptr->publ.blocked = 1; | 600 | b_ptr->publ.blocked = 1; |
| 589 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 601 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
| @@ -595,7 +607,6 @@ int tipc_block_bearer(const char *name) | |||
| 595 | } | 607 | } |
| 596 | spin_unlock_bh(&b_ptr->publ.lock); | 608 | spin_unlock_bh(&b_ptr->publ.lock); |
| 597 | read_unlock_bh(&tipc_net_lock); | 609 | read_unlock_bh(&tipc_net_lock); |
| 598 | info("Blocked bearer <%s>\n", name); | ||
| 599 | return TIPC_OK; | 610 | return TIPC_OK; |
| 600 | } | 611 | } |
| 601 | 612 | ||
| @@ -611,15 +622,13 @@ static int bearer_disable(const char *name) | |||
| 611 | struct link *l_ptr; | 622 | struct link *l_ptr; |
| 612 | struct link *temp_l_ptr; | 623 | struct link *temp_l_ptr; |
| 613 | 624 | ||
| 614 | if (tipc_mode != TIPC_NET_MODE) | ||
| 615 | return -ENOPROTOOPT; | ||
| 616 | |||
| 617 | b_ptr = bearer_find(name); | 625 | b_ptr = bearer_find(name); |
| 618 | if (!b_ptr) { | 626 | if (!b_ptr) { |
| 619 | warn("Attempt to disable unknown bearer <%s>\n", name); | 627 | warn("Attempt to disable unknown bearer <%s>\n", name); |
| 620 | return -EINVAL; | 628 | return -EINVAL; |
| 621 | } | 629 | } |
| 622 | 630 | ||
| 631 | info("Disabling bearer <%s>\n", name); | ||
| 623 | tipc_disc_stop_link_req(b_ptr->link_req); | 632 | tipc_disc_stop_link_req(b_ptr->link_req); |
| 624 | spin_lock_bh(&b_ptr->publ.lock); | 633 | spin_lock_bh(&b_ptr->publ.lock); |
| 625 | b_ptr->link_req = NULL; | 634 | b_ptr->link_req = NULL; |
| @@ -635,7 +644,6 @@ static int bearer_disable(const char *name) | |||
| 635 | tipc_link_delete(l_ptr); | 644 | tipc_link_delete(l_ptr); |
| 636 | } | 645 | } |
| 637 | spin_unlock_bh(&b_ptr->publ.lock); | 646 | spin_unlock_bh(&b_ptr->publ.lock); |
| 638 | info("Disabled bearer <%s>\n", name); | ||
| 639 | memset(b_ptr, 0, sizeof(struct bearer)); | 647 | memset(b_ptr, 0, sizeof(struct bearer)); |
| 640 | return TIPC_OK; | 648 | return TIPC_OK; |
| 641 | } | 649 | } |
| @@ -657,11 +665,9 @@ int tipc_bearer_init(void) | |||
| 657 | int res; | 665 | int res; |
| 658 | 666 | ||
| 659 | write_lock_bh(&tipc_net_lock); | 667 | write_lock_bh(&tipc_net_lock); |
| 660 | tipc_bearers = kmalloc(MAX_BEARERS * sizeof(struct bearer), GFP_ATOMIC); | 668 | tipc_bearers = kcalloc(MAX_BEARERS, sizeof(struct bearer), GFP_ATOMIC); |
| 661 | media_list = kmalloc(MAX_MEDIA * sizeof(struct media), GFP_ATOMIC); | 669 | media_list = kcalloc(MAX_MEDIA, sizeof(struct media), GFP_ATOMIC); |
| 662 | if (tipc_bearers && media_list) { | 670 | if (tipc_bearers && media_list) { |
| 663 | memset(tipc_bearers, 0, MAX_BEARERS * sizeof(struct bearer)); | ||
| 664 | memset(media_list, 0, MAX_MEDIA * sizeof(struct media)); | ||
| 665 | res = TIPC_OK; | 671 | res = TIPC_OK; |
| 666 | } else { | 672 | } else { |
| 667 | kfree(tipc_bearers); | 673 | kfree(tipc_bearers); |
