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.c116
1 files changed, 55 insertions, 61 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 837b7a467885..411719feb803 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,7 @@
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 48
49/** 49/**
50 * media_name_valid - validate media name 50 * media_name_valid - validate media name
@@ -158,7 +158,6 @@ int tipc_register_media(u32 media_type,
158 m_ptr->disable_bearer = disable; 158 m_ptr->disable_bearer = disable;
159 m_ptr->addr2str = addr2str; 159 m_ptr->addr2str = addr2str;
160 memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr)); 160 memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
161 m_ptr->bcast = 1;
162 strcpy(m_ptr->name, name); 161 strcpy(m_ptr->name, name);
163 m_ptr->priority = bearer_priority; 162 m_ptr->priority = bearer_priority;
164 m_ptr->tolerance = link_tolerance; 163 m_ptr->tolerance = link_tolerance;
@@ -278,13 +277,13 @@ static int bearer_name_validate(const char *name,
278 * bearer_find - locates bearer object with matching bearer name 277 * bearer_find - locates bearer object with matching bearer name
279 */ 278 */
280 279
281static struct bearer *bearer_find(const char *name) 280static struct tipc_bearer *bearer_find(const char *name)
282{ 281{
283 struct bearer *b_ptr; 282 struct tipc_bearer *b_ptr;
284 u32 i; 283 u32 i;
285 284
286 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { 285 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
287 if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) 286 if (b_ptr->active && (!strcmp(b_ptr->name, name)))
288 return b_ptr; 287 return b_ptr;
289 } 288 }
290 return NULL; 289 return NULL;
@@ -294,16 +293,16 @@ static struct bearer *bearer_find(const char *name)
294 * tipc_bearer_find_interface - locates bearer object with matching interface name 293 * tipc_bearer_find_interface - locates bearer object with matching interface name
295 */ 294 */
296 295
297struct bearer *tipc_bearer_find_interface(const char *if_name) 296struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
298{ 297{
299 struct bearer *b_ptr; 298 struct tipc_bearer *b_ptr;
300 char *b_if_name; 299 char *b_if_name;
301 u32 i; 300 u32 i;
302 301
303 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { 302 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
304 if (!b_ptr->active) 303 if (!b_ptr->active)
305 continue; 304 continue;
306 b_if_name = strchr(b_ptr->publ.name, ':') + 1; 305 b_if_name = strchr(b_ptr->name, ':') + 1;
307 if (!strcmp(b_if_name, if_name)) 306 if (!strcmp(b_if_name, if_name))
308 return b_ptr; 307 return b_ptr;
309 } 308 }
@@ -318,7 +317,7 @@ struct sk_buff *tipc_bearer_get_names(void)
318{ 317{
319 struct sk_buff *buf; 318 struct sk_buff *buf;
320 struct media *m_ptr; 319 struct media *m_ptr;
321 struct bearer *b_ptr; 320 struct tipc_bearer *b_ptr;
322 int i, j; 321 int i, j;
323 322
324 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); 323 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
@@ -331,8 +330,8 @@ struct sk_buff *tipc_bearer_get_names(void)
331 b_ptr = &tipc_bearers[j]; 330 b_ptr = &tipc_bearers[j];
332 if (b_ptr->active && (b_ptr->media == m_ptr)) { 331 if (b_ptr->active && (b_ptr->media == m_ptr)) {
333 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, 332 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
334 b_ptr->publ.name, 333 b_ptr->name,
335 strlen(b_ptr->publ.name) + 1); 334 strlen(b_ptr->name) + 1);
336 } 335 }
337 } 336 }
338 } 337 }
@@ -340,14 +339,14 @@ struct sk_buff *tipc_bearer_get_names(void)
340 return buf; 339 return buf;
341} 340}
342 341
343void tipc_bearer_add_dest(struct bearer *b_ptr, u32 dest) 342void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
344{ 343{
345 tipc_nmap_add(&b_ptr->nodes, dest); 344 tipc_nmap_add(&b_ptr->nodes, dest);
346 tipc_disc_update_link_req(b_ptr->link_req); 345 tipc_disc_update_link_req(b_ptr->link_req);
347 tipc_bcbearer_sort(); 346 tipc_bcbearer_sort();
348} 347}
349 348
350void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest) 349void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
351{ 350{
352 tipc_nmap_remove(&b_ptr->nodes, dest); 351 tipc_nmap_remove(&b_ptr->nodes, dest);
353 tipc_disc_update_link_req(b_ptr->link_req); 352 tipc_disc_update_link_req(b_ptr->link_req);
@@ -362,12 +361,12 @@ void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
362 * bearer.lock must be taken before calling 361 * bearer.lock must be taken before calling
363 * Returns binary true(1) ore false(0) 362 * Returns binary true(1) ore false(0)
364 */ 363 */
365static int bearer_push(struct bearer *b_ptr) 364static int bearer_push(struct tipc_bearer *b_ptr)
366{ 365{
367 u32 res = 0; 366 u32 res = 0;
368 struct link *ln, *tln; 367 struct link *ln, *tln;
369 368
370 if (b_ptr->publ.blocked) 369 if (b_ptr->blocked)
371 return 0; 370 return 0;
372 371
373 while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) { 372 while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
@@ -382,13 +381,13 @@ static int bearer_push(struct bearer *b_ptr)
382 return list_empty(&b_ptr->cong_links); 381 return list_empty(&b_ptr->cong_links);
383} 382}
384 383
385void tipc_bearer_lock_push(struct bearer *b_ptr) 384void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
386{ 385{
387 int res; 386 int res;
388 387
389 spin_lock_bh(&b_ptr->publ.lock); 388 spin_lock_bh(&b_ptr->lock);
390 res = bearer_push(b_ptr); 389 res = bearer_push(b_ptr);
391 spin_unlock_bh(&b_ptr->publ.lock); 390 spin_unlock_bh(&b_ptr->lock);
392 if (res) 391 if (res)
393 tipc_bcbearer_push(); 392 tipc_bcbearer_push();
394} 393}
@@ -398,16 +397,14 @@ void tipc_bearer_lock_push(struct bearer *b_ptr)
398 * Interrupt enabling new requests after bearer congestion or blocking: 397 * Interrupt enabling new requests after bearer congestion or blocking:
399 * See bearer_send(). 398 * See bearer_send().
400 */ 399 */
401void tipc_continue(struct tipc_bearer *tb_ptr) 400void tipc_continue(struct tipc_bearer *b_ptr)
402{ 401{
403 struct bearer *b_ptr = (struct bearer *)tb_ptr; 402 spin_lock_bh(&b_ptr->lock);
404
405 spin_lock_bh(&b_ptr->publ.lock);
406 b_ptr->continue_count++; 403 b_ptr->continue_count++;
407 if (!list_empty(&b_ptr->cong_links)) 404 if (!list_empty(&b_ptr->cong_links))
408 tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr); 405 tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
409 b_ptr->publ.blocked = 0; 406 b_ptr->blocked = 0;
410 spin_unlock_bh(&b_ptr->publ.lock); 407 spin_unlock_bh(&b_ptr->lock);
411} 408}
412 409
413/* 410/*
@@ -418,7 +415,7 @@ void tipc_continue(struct tipc_bearer *tb_ptr)
418 * bearer.lock is busy 415 * bearer.lock is busy
419 */ 416 */
420 417
421static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_ptr) 418static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
422{ 419{
423 list_move_tail(&l_ptr->link_list, &b_ptr->cong_links); 420 list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
424} 421}
@@ -431,11 +428,11 @@ static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_p
431 * bearer.lock is free 428 * bearer.lock is free
432 */ 429 */
433 430
434void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr) 431void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
435{ 432{
436 spin_lock_bh(&b_ptr->publ.lock); 433 spin_lock_bh(&b_ptr->lock);
437 tipc_bearer_schedule_unlocked(b_ptr, l_ptr); 434 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
438 spin_unlock_bh(&b_ptr->publ.lock); 435 spin_unlock_bh(&b_ptr->lock);
439} 436}
440 437
441 438
@@ -444,18 +441,18 @@ void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
444 * and if there is, try to resolve it before returning. 441 * and if there is, try to resolve it before returning.
445 * 'tipc_net_lock' is read_locked when this function is called 442 * 'tipc_net_lock' is read_locked when this function is called
446 */ 443 */
447int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr) 444int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
448{ 445{
449 int res = 1; 446 int res = 1;
450 447
451 if (list_empty(&b_ptr->cong_links)) 448 if (list_empty(&b_ptr->cong_links))
452 return 1; 449 return 1;
453 spin_lock_bh(&b_ptr->publ.lock); 450 spin_lock_bh(&b_ptr->lock);
454 if (!bearer_push(b_ptr)) { 451 if (!bearer_push(b_ptr)) {
455 tipc_bearer_schedule_unlocked(b_ptr, l_ptr); 452 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
456 res = 0; 453 res = 0;
457 } 454 }
458 spin_unlock_bh(&b_ptr->publ.lock); 455 spin_unlock_bh(&b_ptr->lock);
459 return res; 456 return res;
460} 457}
461 458
@@ -463,9 +460,9 @@ int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr)
463 * tipc_bearer_congested - determines if bearer is currently congested 460 * tipc_bearer_congested - determines if bearer is currently congested
464 */ 461 */
465 462
466int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr) 463int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
467{ 464{
468 if (unlikely(b_ptr->publ.blocked)) 465 if (unlikely(b_ptr->blocked))
469 return 1; 466 return 1;
470 if (likely(list_empty(&b_ptr->cong_links))) 467 if (likely(list_empty(&b_ptr->cong_links)))
471 return 0; 468 return 0;
@@ -476,9 +473,9 @@ int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
476 * tipc_enable_bearer - enable bearer with the given name 473 * tipc_enable_bearer - enable bearer with the given name
477 */ 474 */
478 475
479int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) 476int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
480{ 477{
481 struct bearer *b_ptr; 478 struct tipc_bearer *b_ptr;
482 struct media *m_ptr; 479 struct media *m_ptr;
483 struct bearer_name b_name; 480 struct bearer_name b_name;
484 char addr_string[16]; 481 char addr_string[16];
@@ -496,9 +493,9 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
496 warn("Bearer <%s> rejected, illegal name\n", name); 493 warn("Bearer <%s> rejected, illegal name\n", name);
497 return -EINVAL; 494 return -EINVAL;
498 } 495 }
499 if (!tipc_addr_domain_valid(bcast_scope) || 496 if (!tipc_addr_domain_valid(disc_domain) ||
500 !tipc_in_scope(bcast_scope, tipc_own_addr)) { 497 !tipc_in_scope(disc_domain, tipc_own_addr)) {
501 warn("Bearer <%s> rejected, illegal broadcast scope\n", name); 498 warn("Bearer <%s> rejected, illegal discovery domain\n", name);
502 return -EINVAL; 499 return -EINVAL;
503 } 500 }
504 if ((priority < TIPC_MIN_LINK_PRI || 501 if ((priority < TIPC_MIN_LINK_PRI ||
@@ -528,7 +525,7 @@ restart:
528 bearer_id = i; 525 bearer_id = i;
529 continue; 526 continue;
530 } 527 }
531 if (!strcmp(name, tipc_bearers[i].publ.name)) { 528 if (!strcmp(name, tipc_bearers[i].name)) {
532 warn("Bearer <%s> rejected, already enabled\n", name); 529 warn("Bearer <%s> rejected, already enabled\n", name);
533 goto failed; 530 goto failed;
534 } 531 }
@@ -551,8 +548,8 @@ restart:
551 } 548 }
552 549
553 b_ptr = &tipc_bearers[bearer_id]; 550 b_ptr = &tipc_bearers[bearer_id];
554 strcpy(b_ptr->publ.name, name); 551 strcpy(b_ptr->name, name);
555 res = m_ptr->enable_bearer(&b_ptr->publ); 552 res = m_ptr->enable_bearer(b_ptr);
556 if (res) { 553 if (res) {
557 warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res); 554 warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
558 goto failed; 555 goto failed;
@@ -562,18 +559,15 @@ restart:
562 b_ptr->media = m_ptr; 559 b_ptr->media = m_ptr;
563 b_ptr->net_plane = bearer_id + 'A'; 560 b_ptr->net_plane = bearer_id + 'A';
564 b_ptr->active = 1; 561 b_ptr->active = 1;
565 b_ptr->detect_scope = bcast_scope;
566 b_ptr->priority = priority; 562 b_ptr->priority = priority;
567 INIT_LIST_HEAD(&b_ptr->cong_links); 563 INIT_LIST_HEAD(&b_ptr->cong_links);
568 INIT_LIST_HEAD(&b_ptr->links); 564 INIT_LIST_HEAD(&b_ptr->links);
569 if (m_ptr->bcast) { 565 b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
570 b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr, 566 disc_domain);
571 bcast_scope, 2); 567 spin_lock_init(&b_ptr->lock);
572 }
573 spin_lock_init(&b_ptr->publ.lock);
574 write_unlock_bh(&tipc_net_lock); 568 write_unlock_bh(&tipc_net_lock);
575 info("Enabled bearer <%s>, discovery domain %s, priority %u\n", 569 info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
576 name, tipc_addr_string_fill(addr_string, bcast_scope), priority); 570 name, tipc_addr_string_fill(addr_string, disc_domain), priority);
577 return 0; 571 return 0;
578failed: 572failed:
579 write_unlock_bh(&tipc_net_lock); 573 write_unlock_bh(&tipc_net_lock);
@@ -587,7 +581,7 @@ failed:
587 581
588int tipc_block_bearer(const char *name) 582int tipc_block_bearer(const char *name)
589{ 583{
590 struct bearer *b_ptr = NULL; 584 struct tipc_bearer *b_ptr = NULL;
591 struct link *l_ptr; 585 struct link *l_ptr;
592 struct link *temp_l_ptr; 586 struct link *temp_l_ptr;
593 587
@@ -600,8 +594,8 @@ int tipc_block_bearer(const char *name)
600 } 594 }
601 595
602 info("Blocking bearer <%s>\n", name); 596 info("Blocking bearer <%s>\n", name);
603 spin_lock_bh(&b_ptr->publ.lock); 597 spin_lock_bh(&b_ptr->lock);
604 b_ptr->publ.blocked = 1; 598 b_ptr->blocked = 1;
605 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 599 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
606 struct tipc_node *n_ptr = l_ptr->owner; 600 struct tipc_node *n_ptr = l_ptr->owner;
607 601
@@ -609,7 +603,7 @@ int tipc_block_bearer(const char *name)
609 tipc_link_reset(l_ptr); 603 tipc_link_reset(l_ptr);
610 spin_unlock_bh(&n_ptr->lock); 604 spin_unlock_bh(&n_ptr->lock);
611 } 605 }
612 spin_unlock_bh(&b_ptr->publ.lock); 606 spin_unlock_bh(&b_ptr->lock);
613 read_unlock_bh(&tipc_net_lock); 607 read_unlock_bh(&tipc_net_lock);
614 return 0; 608 return 0;
615} 609}
@@ -620,27 +614,27 @@ int tipc_block_bearer(const char *name)
620 * Note: This routine assumes caller holds tipc_net_lock. 614 * Note: This routine assumes caller holds tipc_net_lock.
621 */ 615 */
622 616
623static void bearer_disable(struct bearer *b_ptr) 617static void bearer_disable(struct tipc_bearer *b_ptr)
624{ 618{
625 struct link *l_ptr; 619 struct link *l_ptr;
626 struct link *temp_l_ptr; 620 struct link *temp_l_ptr;
627 621
628 info("Disabling bearer <%s>\n", b_ptr->publ.name); 622 info("Disabling bearer <%s>\n", b_ptr->name);
629 tipc_disc_stop_link_req(b_ptr->link_req); 623 tipc_disc_stop_link_req(b_ptr->link_req);
630 spin_lock_bh(&b_ptr->publ.lock); 624 spin_lock_bh(&b_ptr->lock);
631 b_ptr->link_req = NULL; 625 b_ptr->link_req = NULL;
632 b_ptr->publ.blocked = 1; 626 b_ptr->blocked = 1;
633 b_ptr->media->disable_bearer(&b_ptr->publ); 627 b_ptr->media->disable_bearer(b_ptr);
634 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 628 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
635 tipc_link_delete(l_ptr); 629 tipc_link_delete(l_ptr);
636 } 630 }
637 spin_unlock_bh(&b_ptr->publ.lock); 631 spin_unlock_bh(&b_ptr->lock);
638 memset(b_ptr, 0, sizeof(struct bearer)); 632 memset(b_ptr, 0, sizeof(struct tipc_bearer));
639} 633}
640 634
641int tipc_disable_bearer(const char *name) 635int tipc_disable_bearer(const char *name)
642{ 636{
643 struct bearer *b_ptr; 637 struct tipc_bearer *b_ptr;
644 int res; 638 int res;
645 639
646 write_lock_bh(&tipc_net_lock); 640 write_lock_bh(&tipc_net_lock);