diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2006-06-26 02:52:17 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-06-26 02:52:17 -0400 |
commit | a10bd924a421e0e5d5bb9640735b9317b8e473b5 (patch) | |
tree | d86ac98e60292c3197a8f6ef9af86549dd051102 /net/tipc/bearer.c | |
parent | f131072c3da84e70a0f65d71b3a3f6611c6a22bc (diff) |
[TIPC]: Enhanced & cleaned up system messages; fixed 2 obscure memory leaks.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Per Liden <per.liden@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r-- | net/tipc/bearer.c | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index e213a8e54855..4fa24b5e8914 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 | ||
@@ -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 | } |