aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/link.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-07-16 16:54:19 -0400
committerDavid S. Miller <davem@davemloft.net>2015-07-20 23:41:14 -0400
commit9d13ec65ede775f896c3da1cfa35283afe2f796c (patch)
tree34ac0c21607481a2377b3201c3fe58c3f6ac7947 /net/tipc/link.c
parent6acc23266054a9969737b435fa012f87465dbc50 (diff)
tipc: introduce link entry structure to struct tipc_node
struct 'tipc_node' currently contains two arrays for link attributes, one for the link pointers, and one for the usable link MTUs. We now group those into a new struct 'tipc_link_entry', and intoduce one single array consisting of such enties. Apart from being a cosmetic improvement, this is a starting point for the strict master-slave relation between node and link that we will introduce in the following commits. Reviewed-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/link.c')
-rw-r--r--net/tipc/link.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index eaa9fe54b4ae..03372a7e98df 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -132,9 +132,11 @@ static void tipc_link_put(struct tipc_link *l_ptr)
132 132
133static struct tipc_link *tipc_parallel_link(struct tipc_link *l) 133static struct tipc_link *tipc_parallel_link(struct tipc_link *l)
134{ 134{
135 if (l->owner->active_links[0] != l) 135 struct tipc_node *n = l->owner;
136 return l->owner->active_links[0]; 136
137 return l->owner->active_links[1]; 137 if (node_active_link(n, 0) != l)
138 return node_active_link(n, 0);
139 return node_active_link(n, 1);
138} 140}
139 141
140/* 142/*
@@ -147,10 +149,11 @@ int tipc_link_is_up(struct tipc_link *l_ptr)
147 return link_working_working(l_ptr) || link_working_unknown(l_ptr); 149 return link_working_working(l_ptr) || link_working_unknown(l_ptr);
148} 150}
149 151
150int tipc_link_is_active(struct tipc_link *l_ptr) 152int tipc_link_is_active(struct tipc_link *l)
151{ 153{
152 return (l_ptr->owner->active_links[0] == l_ptr) || 154 struct tipc_node *n = l->owner;
153 (l_ptr->owner->active_links[1] == l_ptr); 155
156 return (node_active_link(n, 0) == l) || (node_active_link(n, 1) == l);
154} 157}
155 158
156/** 159/**
@@ -240,7 +243,7 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
240 return NULL; 243 return NULL;
241 } 244 }
242 245
243 if (n_ptr->links[b_ptr->identity]) { 246 if (n_ptr->links[b_ptr->identity].link) {
244 tipc_addr_string_fill(addr_string, n_ptr->addr); 247 tipc_addr_string_fill(addr_string, n_ptr->addr);
245 pr_err("Attempt to establish second link on <%s> to %s\n", 248 pr_err("Attempt to establish second link on <%s> to %s\n",
246 b_ptr->name, addr_string); 249 b_ptr->name, addr_string);
@@ -321,7 +324,7 @@ void tipc_link_delete_list(struct net *net, unsigned int bearer_id)
321 rcu_read_lock(); 324 rcu_read_lock();
322 list_for_each_entry_rcu(node, &tn->node_list, list) { 325 list_for_each_entry_rcu(node, &tn->node_list, list) {
323 tipc_node_lock(node); 326 tipc_node_lock(node);
324 link = node->links[bearer_id]; 327 link = node->links[bearer_id].link;
325 if (link) 328 if (link)
326 tipc_link_delete(link); 329 tipc_link_delete(link);
327 tipc_node_unlock(node); 330 tipc_node_unlock(node);
@@ -446,7 +449,7 @@ void tipc_link_reset(struct tipc_link *l_ptr)
446 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET)) 449 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
447 return; 450 return;
448 451
449 tipc_node_link_down(l_ptr->owner, l_ptr); 452 tipc_node_link_down(l_ptr->owner, l_ptr->bearer_id);
450 tipc_bearer_remove_dest(owner->net, l_ptr->bearer_id, l_ptr->addr); 453 tipc_bearer_remove_dest(owner->net, l_ptr->bearer_id, l_ptr->addr);
451 454
452 if (was_active_link && tipc_node_is_up(l_ptr->owner) && (pl != l_ptr)) { 455 if (was_active_link && tipc_node_is_up(l_ptr->owner) && (pl != l_ptr)) {
@@ -482,7 +485,7 @@ static void link_activate(struct tipc_link *link)
482 link->rcv_nxt = 1; 485 link->rcv_nxt = 1;
483 link->stats.recv_info = 1; 486 link->stats.recv_info = 1;
484 link->silent_intv_cnt = 0; 487 link->silent_intv_cnt = 0;
485 tipc_node_link_up(node, link); 488 tipc_node_link_up(node, link->bearer_id);
486 tipc_bearer_add_dest(node->net, link->bearer_id, link->addr); 489 tipc_bearer_add_dest(node->net, link->bearer_id, link->addr);
487} 490}
488 491
@@ -577,7 +580,7 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
577 case TRAFFIC_MSG_EVT: 580 case TRAFFIC_MSG_EVT:
578 break; 581 break;
579 case ACTIVATE_MSG: 582 case ACTIVATE_MSG:
580 other = l_ptr->owner->active_links[0]; 583 other = node_active_link(l_ptr->owner, 0);
581 if (other && link_working_unknown(other)) 584 if (other && link_working_unknown(other))
582 break; 585 break;
583 l_ptr->state = WORKING_WORKING; 586 l_ptr->state = WORKING_WORKING;
@@ -606,7 +609,7 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
606 switch (event) { 609 switch (event) {
607 case TRAFFIC_MSG_EVT: 610 case TRAFFIC_MSG_EVT:
608 case ACTIVATE_MSG: 611 case ACTIVATE_MSG:
609 other = l_ptr->owner->active_links[0]; 612 other = node_active_link(l_ptr->owner, 0);
610 if (other && link_working_unknown(other)) 613 if (other && link_working_unknown(other))
611 break; 614 break;
612 l_ptr->state = WORKING_WORKING; 615 l_ptr->state = WORKING_WORKING;
@@ -755,7 +758,7 @@ int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dnode,
755 node = tipc_node_find(net, dnode); 758 node = tipc_node_find(net, dnode);
756 if (node) { 759 if (node) {
757 tipc_node_lock(node); 760 tipc_node_lock(node);
758 link = node->active_links[selector & 1]; 761 link = node_active_link(node, selector & 1);
759 if (link) 762 if (link)
760 rc = __tipc_link_xmit(net, link, list); 763 rc = __tipc_link_xmit(net, link, list);
761 tipc_node_unlock(node); 764 tipc_node_unlock(node);
@@ -858,9 +861,9 @@ void tipc_link_reset_all(struct tipc_node *node)
858 tipc_addr_string_fill(addr_string, node->addr)); 861 tipc_addr_string_fill(addr_string, node->addr));
859 862
860 for (i = 0; i < MAX_BEARERS; i++) { 863 for (i = 0; i < MAX_BEARERS; i++) {
861 if (node->links[i]) { 864 if (node->links[i].link) {
862 link_print(node->links[i], "Resetting link\n"); 865 link_print(node->links[i].link, "Resetting link\n");
863 tipc_link_reset(node->links[i]); 866 tipc_link_reset(node->links[i].link);
864 } 867 }
865 } 868 }
866 869
@@ -1029,7 +1032,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
1029 1032
1030 tipc_node_lock(n_ptr); 1033 tipc_node_lock(n_ptr);
1031 /* Locate unicast link endpoint that should handle message */ 1034 /* Locate unicast link endpoint that should handle message */
1032 l_ptr = n_ptr->links[b_ptr->identity]; 1035 l_ptr = n_ptr->links[b_ptr->identity].link;
1033 if (unlikely(!l_ptr)) 1036 if (unlikely(!l_ptr))
1034 goto unlock; 1037 goto unlock;
1035 1038
@@ -1496,7 +1499,7 @@ static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
1496 struct sk_buff *skb; 1499 struct sk_buff *skb;
1497 u32 length = msg_size(msg); 1500 u32 length = msg_size(msg);
1498 1501
1499 tunnel = l_ptr->owner->active_links[selector & 1]; 1502 tunnel = node_active_link(l_ptr->owner, selector & 1);
1500 if (!tipc_link_is_up(tunnel)) { 1503 if (!tipc_link_is_up(tunnel)) {
1501 pr_warn("%stunnel link no longer available\n", link_co_err); 1504 pr_warn("%stunnel link no longer available\n", link_co_err);
1502 return; 1505 return;
@@ -1522,7 +1525,7 @@ static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
1522void tipc_link_failover_send_queue(struct tipc_link *l_ptr) 1525void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
1523{ 1526{
1524 int msgcount; 1527 int msgcount;
1525 struct tipc_link *tunnel = l_ptr->owner->active_links[0]; 1528 struct tipc_link *tunnel = node_active_link(l_ptr->owner, 0);
1526 struct tipc_msg tunnel_hdr; 1529 struct tipc_msg tunnel_hdr;
1527 struct sk_buff *skb; 1530 struct sk_buff *skb;
1528 int split_bundles; 1531 int split_bundles;
@@ -1556,8 +1559,8 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
1556 return; 1559 return;
1557 } 1560 }
1558 1561
1559 split_bundles = (l_ptr->owner->active_links[0] != 1562 split_bundles = (node_active_link(l_ptr->owner, 0) !=
1560 l_ptr->owner->active_links[1]); 1563 node_active_link(l_ptr->owner, 0));
1561 1564
1562 skb_queue_walk(&l_ptr->transmq, skb) { 1565 skb_queue_walk(&l_ptr->transmq, skb) {
1563 struct tipc_msg *msg = buf_msg(skb); 1566 struct tipc_msg *msg = buf_msg(skb);
@@ -1660,7 +1663,7 @@ static bool tipc_link_failover_rcv(struct tipc_link *link,
1660 if (bearer_id == link->bearer_id) 1663 if (bearer_id == link->bearer_id)
1661 goto exit; 1664 goto exit;
1662 1665
1663 pl = link->owner->links[bearer_id]; 1666 pl = link->owner->links[bearer_id].link;
1664 if (pl && tipc_link_is_up(pl)) 1667 if (pl && tipc_link_is_up(pl))
1665 tipc_link_reset(pl); 1668 tipc_link_reset(pl);
1666 1669
@@ -1743,7 +1746,7 @@ static struct tipc_node *tipc_link_find_owner(struct net *net,
1743 list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { 1746 list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
1744 tipc_node_lock(n_ptr); 1747 tipc_node_lock(n_ptr);
1745 for (i = 0; i < MAX_BEARERS; i++) { 1748 for (i = 0; i < MAX_BEARERS; i++) {
1746 l_ptr = n_ptr->links[i]; 1749 l_ptr = n_ptr->links[i].link;
1747 if (l_ptr && !strcmp(l_ptr->name, link_name)) { 1750 if (l_ptr && !strcmp(l_ptr->name, link_name)) {
1748 *bearer_id = i; 1751 *bearer_id = i;
1749 found_node = n_ptr; 1752 found_node = n_ptr;
@@ -1865,7 +1868,7 @@ int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info)
1865 1868
1866 tipc_node_lock(node); 1869 tipc_node_lock(node);
1867 1870
1868 link = node->links[bearer_id]; 1871 link = node->links[bearer_id].link;
1869 if (!link) { 1872 if (!link) {
1870 res = -EINVAL; 1873 res = -EINVAL;
1871 goto out; 1874 goto out;
@@ -2055,10 +2058,11 @@ static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2055 for (i = *prev_link; i < MAX_BEARERS; i++) { 2058 for (i = *prev_link; i < MAX_BEARERS; i++) {
2056 *prev_link = i; 2059 *prev_link = i;
2057 2060
2058 if (!node->links[i]) 2061 if (!node->links[i].link)
2059 continue; 2062 continue;
2060 2063
2061 err = __tipc_nl_add_link(net, msg, node->links[i], NLM_F_MULTI); 2064 err = __tipc_nl_add_link(net, msg,
2065 node->links[i].link, NLM_F_MULTI);
2062 if (err) 2066 if (err)
2063 return err; 2067 return err;
2064 } 2068 }
@@ -2172,7 +2176,7 @@ int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
2172 return -EINVAL; 2176 return -EINVAL;
2173 2177
2174 tipc_node_lock(node); 2178 tipc_node_lock(node);
2175 link = node->links[bearer_id]; 2179 link = node->links[bearer_id].link;
2176 if (!link) { 2180 if (!link) {
2177 tipc_node_unlock(node); 2181 tipc_node_unlock(node);
2178 nlmsg_free(msg.skb); 2182 nlmsg_free(msg.skb);
@@ -2227,7 +2231,7 @@ int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info)
2227 2231
2228 tipc_node_lock(node); 2232 tipc_node_lock(node);
2229 2233
2230 link = node->links[bearer_id]; 2234 link = node->links[bearer_id].link;
2231 if (!link) { 2235 if (!link) {
2232 tipc_node_unlock(node); 2236 tipc_node_unlock(node);
2233 return -EINVAL; 2237 return -EINVAL;