aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/node.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-07-30 18:24:26 -0400
committerDavid S. Miller <davem@davemloft.net>2015-07-30 20:25:15 -0400
commit440d8963cd590ec9387d76a36e60c02da9ed944d (patch)
tree7d1135b020321fd3bd06f9bd6dbc1837380858f8 /net/tipc/node.c
parent9073fb8be3ee6f89492b8ea8f6d3902913a9fc91 (diff)
tipc: clean up link creation
We simplify the link creation function tipc_link_create() and the way the link struct it is connected to the node struct. In particular, we remove the duplicate initialization of some fields which are anyway set in tipc_link_reset(). Tested-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/node.c')
-rw-r--r--net/tipc/node.c48
1 files changed, 16 insertions, 32 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 9e9b0938bd17..7c191641b44f 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -320,10 +320,6 @@ static void __tipc_node_link_up(struct tipc_node *n, int bearer_id,
320 if (!nl || !tipc_link_is_up(nl)) 320 if (!nl || !tipc_link_is_up(nl))
321 return; 321 return;
322 322
323 if (n->working_links > 1) {
324 pr_warn("Attempt to establish 3rd link to %x\n", n->addr);
325 return;
326 }
327 n->working_links++; 323 n->working_links++;
328 n->action_flags |= TIPC_NOTIFY_LINK_UP; 324 n->action_flags |= TIPC_NOTIFY_LINK_UP;
329 n->link_id = nl->peer_bearer_id << 16 | bearer_id; 325 n->link_id = nl->peer_bearer_id << 16 | bearer_id;
@@ -470,13 +466,13 @@ void tipc_node_check_dest(struct net *net, u32 onode,
470{ 466{
471 struct tipc_node *n; 467 struct tipc_node *n;
472 struct tipc_link *l; 468 struct tipc_link *l;
473 struct tipc_media_addr *curr_maddr; 469 struct tipc_link_entry *le;
474 struct sk_buff_head *inputq;
475 bool addr_match = false; 470 bool addr_match = false;
476 bool sign_match = false; 471 bool sign_match = false;
477 bool link_up = false; 472 bool link_up = false;
478 bool accept_addr = false; 473 bool accept_addr = false;
479 bool reset = true; 474 bool reset = true;
475
480 *dupl_addr = false; 476 *dupl_addr = false;
481 *respond = false; 477 *respond = false;
482 478
@@ -486,13 +482,12 @@ void tipc_node_check_dest(struct net *net, u32 onode,
486 482
487 tipc_node_lock(n); 483 tipc_node_lock(n);
488 484
489 curr_maddr = &n->links[b->identity].maddr; 485 le = &n->links[b->identity];
490 inputq = &n->links[b->identity].inputq;
491 486
492 /* Prepare to validate requesting node's signature and media address */ 487 /* Prepare to validate requesting node's signature and media address */
493 l = n->links[b->identity].link; 488 l = le->link;
494 link_up = l && tipc_link_is_up(l); 489 link_up = l && tipc_link_is_up(l);
495 addr_match = l && !memcmp(curr_maddr, maddr, sizeof(*maddr)); 490 addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
496 sign_match = (signature == n->signature); 491 sign_match = (signature == n->signature);
497 492
498 /* These three flags give us eight permutations: */ 493 /* These three flags give us eight permutations: */
@@ -559,18 +554,25 @@ void tipc_node_check_dest(struct net *net, u32 onode,
559 554
560 /* Now create new link if not already existing */ 555 /* Now create new link if not already existing */
561 if (!l) { 556 if (!l) {
562 l = tipc_link_create(n, b, maddr, inputq, &n->bclink.namedq); 557 if (n->link_cnt == 2) {
563 if (!l) { 558 pr_warn("Cannot establish 3rd link to %x\n", n->addr);
559 goto exit;
560 }
561 if (!tipc_link_create(n, b, mod(tipc_net(net)->random),
562 tipc_own_addr(net), onode, &le->maddr,
563 &le->inputq, &n->bclink.namedq, &l)) {
564 *respond = false; 564 *respond = false;
565 goto exit; 565 goto exit;
566 } 566 }
567 tipc_link_reset(l);
568 le->link = l;
569 n->link_cnt++;
567 tipc_node_calculate_timer(n, l); 570 tipc_node_calculate_timer(n, l);
568 if (n->link_cnt == 1) 571 if (n->link_cnt == 1)
569 if (!mod_timer(&n->timer, jiffies + n->keepalive_intv)) 572 if (!mod_timer(&n->timer, jiffies + n->keepalive_intv))
570 tipc_node_get(n); 573 tipc_node_get(n);
571 } 574 }
572 memcpy(&l->media_addr, maddr, sizeof(*maddr)); 575 memcpy(&le->maddr, maddr, sizeof(*maddr));
573 memcpy(curr_maddr, maddr, sizeof(*maddr));
574exit: 576exit:
575 tipc_node_unlock(n); 577 tipc_node_unlock(n);
576 if (reset) 578 if (reset)
@@ -603,24 +605,6 @@ static void tipc_node_reset_links(struct tipc_node *n)
603 } 605 }
604} 606}
605 607
606void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
607{
608 n_ptr->links[l_ptr->bearer_id].link = l_ptr;
609 n_ptr->link_cnt++;
610}
611
612void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
613{
614 int i;
615
616 for (i = 0; i < MAX_BEARERS; i++) {
617 if (l_ptr != n_ptr->links[i].link)
618 continue;
619 n_ptr->links[i].link = NULL;
620 n_ptr->link_cnt--;
621 }
622}
623
624/* tipc_node_fsm_evt - node finite state machine 608/* tipc_node_fsm_evt - node finite state machine
625 * Determines when contact is allowed with peer node 609 * Determines when contact is allowed with peer node
626 */ 610 */