aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/link.c
diff options
context:
space:
mode:
authorYing Xue <ying.xue@windriver.com>2015-01-09 02:27:10 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-12 16:24:33 -0500
commit347475395434abb2b61bf59c2952470f37072567 (patch)
tree71a5f63547edecee31f557d0bacbf993b953a099 /net/tipc/link.c
parent4ac1c8d0ee9faf3a4be185cc4db1381fa0d81280 (diff)
tipc: make tipc node address support net namespace
If net namespace is supported in tipc, each namespace will be treated as a separate tipc node. Therefore, every namespace must own its private tipc node address. This means the "tipc_own_addr" global variable of node address must be moved to tipc_net structure to satisfy the requirement. It's turned out that users also can assign node address for every namespace. Signed-off-by: Ying Xue <ying.xue@windriver.com> Tested-by: Tero Aho <Tero.Aho@coriant.com> Reviewed-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.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index a84d5c67997e..997256769065 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -241,6 +241,7 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
241 struct tipc_bearer *b_ptr, 241 struct tipc_bearer *b_ptr,
242 const struct tipc_media_addr *media_addr) 242 const struct tipc_media_addr *media_addr)
243{ 243{
244 struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
244 struct tipc_link *l_ptr; 245 struct tipc_link *l_ptr;
245 struct tipc_msg *msg; 246 struct tipc_msg *msg;
246 char *if_name; 247 char *if_name;
@@ -270,8 +271,8 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
270 l_ptr->addr = peer; 271 l_ptr->addr = peer;
271 if_name = strchr(b_ptr->name, ':') + 1; 272 if_name = strchr(b_ptr->name, ':') + 1;
272 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", 273 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
273 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), 274 tipc_zone(tn->own_addr), tipc_cluster(tn->own_addr),
274 tipc_node(tipc_own_addr), 275 tipc_node(tn->own_addr),
275 if_name, 276 if_name,
276 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); 277 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
277 /* note: peer i/f name is updated by reset/activate message */ 278 /* note: peer i/f name is updated by reset/activate message */
@@ -285,7 +286,8 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
285 286
286 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; 287 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
287 msg = l_ptr->pmsg; 288 msg = l_ptr->pmsg;
288 tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr); 289 tipc_msg_init(n_ptr->net, msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE,
290 l_ptr->addr);
289 msg_set_size(msg, sizeof(l_ptr->proto_msg)); 291 msg_set_size(msg, sizeof(l_ptr->proto_msg));
290 msg_set_session(msg, (tipc_random & 0xffff)); 292 msg_set_session(msg, (tipc_random & 0xffff));
291 msg_set_bearer_id(msg, b_ptr->identity); 293 msg_set_bearer_id(msg, b_ptr->identity);
@@ -358,10 +360,12 @@ void tipc_link_delete_list(struct net *net, unsigned int bearer_id,
358static bool link_schedule_user(struct tipc_link *link, u32 oport, 360static bool link_schedule_user(struct tipc_link *link, u32 oport,
359 uint chain_sz, uint imp) 361 uint chain_sz, uint imp)
360{ 362{
363 struct net *net = link->owner->net;
364 struct tipc_net *tn = net_generic(net, tipc_net_id);
361 struct sk_buff *buf; 365 struct sk_buff *buf;
362 366
363 buf = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, tipc_own_addr, 367 buf = tipc_msg_create(net, SOCK_WAKEUP, 0, INT_H_SIZE, 0, tn->own_addr,
364 tipc_own_addr, oport, 0, 0); 368 tn->own_addr, oport, 0, 0);
365 if (!buf) 369 if (!buf)
366 return false; 370 return false;
367 TIPC_SKB_CB(buf)->chain_sz = chain_sz; 371 TIPC_SKB_CB(buf)->chain_sz = chain_sz;
@@ -753,7 +757,7 @@ int __tipc_link_xmit(struct net *net, struct tipc_link *link,
753 } else if (tipc_msg_bundle(outqueue, skb, mtu)) { 757 } else if (tipc_msg_bundle(outqueue, skb, mtu)) {
754 link->stats.sent_bundled++; 758 link->stats.sent_bundled++;
755 continue; 759 continue;
756 } else if (tipc_msg_make_bundle(outqueue, skb, mtu, 760 } else if (tipc_msg_make_bundle(net, outqueue, skb, mtu,
757 link->addr)) { 761 link->addr)) {
758 link->stats.sent_bundled++; 762 link->stats.sent_bundled++;
759 link->stats.sent_bundles++; 763 link->stats.sent_bundles++;
@@ -822,7 +826,7 @@ int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dnode,
822 if (link) 826 if (link)
823 return rc; 827 return rc;
824 828
825 if (likely(in_own_node(dnode))) { 829 if (likely(in_own_node(net, dnode))) {
826 /* As a node local message chain never contains more than one 830 /* As a node local message chain never contains more than one
827 * buffer, we just need to dequeue one SKB buffer from the 831 * buffer, we just need to dequeue one SKB buffer from the
828 * head list. 832 * head list.
@@ -852,7 +856,8 @@ static void tipc_link_sync_xmit(struct tipc_link *link)
852 return; 856 return;
853 857
854 msg = buf_msg(skb); 858 msg = buf_msg(skb);
855 tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, link->addr); 859 tipc_msg_init(link->owner->net, msg, BCAST_PROTOCOL, STATE_MSG,
860 INT_H_SIZE, link->addr);
856 msg_set_last_bcast(msg, link->owner->bclink.acked); 861 msg_set_last_bcast(msg, link->owner->bclink.acked);
857 __tipc_link_xmit_skb(link, skb); 862 __tipc_link_xmit_skb(link, skb);
858} 863}
@@ -1092,6 +1097,7 @@ static int link_recv_buf_validate(struct sk_buff *buf)
1092 */ 1097 */
1093void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr) 1098void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
1094{ 1099{
1100 struct tipc_net *tn = net_generic(net, tipc_net_id);
1095 struct sk_buff_head head; 1101 struct sk_buff_head head;
1096 struct tipc_node *n_ptr; 1102 struct tipc_node *n_ptr;
1097 struct tipc_link *l_ptr; 1103 struct tipc_link *l_ptr;
@@ -1125,7 +1131,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
1125 1131
1126 /* Discard unicast link messages destined for another node */ 1132 /* Discard unicast link messages destined for another node */
1127 if (unlikely(!msg_short(msg) && 1133 if (unlikely(!msg_short(msg) &&
1128 (msg_destnode(msg) != tipc_own_addr))) 1134 (msg_destnode(msg) != tn->own_addr)))
1129 goto discard; 1135 goto discard;
1130 1136
1131 /* Locate neighboring node that sent message */ 1137 /* Locate neighboring node that sent message */
@@ -1483,6 +1489,7 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
1483static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr, 1489static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr,
1484 struct sk_buff *buf) 1490 struct sk_buff *buf)
1485{ 1491{
1492 struct tipc_net *tn = net_generic(net, tipc_net_id);
1486 u32 rec_gap = 0; 1493 u32 rec_gap = 0;
1487 u32 max_pkt_info; 1494 u32 max_pkt_info;
1488 u32 max_pkt_ack; 1495 u32 max_pkt_ack;
@@ -1494,7 +1501,7 @@ static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr,
1494 goto exit; 1501 goto exit;
1495 1502
1496 if (l_ptr->net_plane != msg_net_plane(msg)) 1503 if (l_ptr->net_plane != msg_net_plane(msg))
1497 if (tipc_own_addr > msg_prevnode(msg)) 1504 if (tn->own_addr > msg_prevnode(msg))
1498 l_ptr->net_plane = msg_net_plane(msg); 1505 l_ptr->net_plane = msg_net_plane(msg);
1499 1506
1500 switch (msg_type(msg)) { 1507 switch (msg_type(msg)) {
@@ -1662,8 +1669,8 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
1662 if (!tunnel) 1669 if (!tunnel)
1663 return; 1670 return;
1664 1671
1665 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, 1672 tipc_msg_init(l_ptr->owner->net, &tunnel_hdr, CHANGEOVER_PROTOCOL,
1666 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); 1673 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
1667 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); 1674 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
1668 msg_set_msgcnt(&tunnel_hdr, msgcount); 1675 msg_set_msgcnt(&tunnel_hdr, msgcount);
1669 1676
@@ -1720,8 +1727,8 @@ void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr,
1720 struct sk_buff *skb; 1727 struct sk_buff *skb;
1721 struct tipc_msg tunnel_hdr; 1728 struct tipc_msg tunnel_hdr;
1722 1729
1723 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, 1730 tipc_msg_init(l_ptr->owner->net, &tunnel_hdr, CHANGEOVER_PROTOCOL,
1724 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); 1731 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
1725 msg_set_msgcnt(&tunnel_hdr, skb_queue_len(&l_ptr->outqueue)); 1732 msg_set_msgcnt(&tunnel_hdr, skb_queue_len(&l_ptr->outqueue));
1726 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); 1733 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
1727 skb_queue_walk(&l_ptr->outqueue, skb) { 1734 skb_queue_walk(&l_ptr->outqueue, skb) {
@@ -2506,12 +2513,14 @@ msg_full:
2506} 2513}
2507 2514
2508/* Caller should hold appropriate locks to protect the link */ 2515/* Caller should hold appropriate locks to protect the link */
2509static int __tipc_nl_add_link(struct tipc_nl_msg *msg, struct tipc_link *link) 2516static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2517 struct tipc_link *link)
2510{ 2518{
2511 int err; 2519 int err;
2512 void *hdr; 2520 void *hdr;
2513 struct nlattr *attrs; 2521 struct nlattr *attrs;
2514 struct nlattr *prop; 2522 struct nlattr *prop;
2523 struct tipc_net *tn = net_generic(net, tipc_net_id);
2515 2524
2516 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, 2525 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
2517 NLM_F_MULTI, TIPC_NL_LINK_GET); 2526 NLM_F_MULTI, TIPC_NL_LINK_GET);
@@ -2525,7 +2534,7 @@ static int __tipc_nl_add_link(struct tipc_nl_msg *msg, struct tipc_link *link)
2525 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) 2534 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
2526 goto attr_msg_full; 2535 goto attr_msg_full;
2527 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, 2536 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST,
2528 tipc_cluster_mask(tipc_own_addr))) 2537 tipc_cluster_mask(tn->own_addr)))
2529 goto attr_msg_full; 2538 goto attr_msg_full;
2530 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->max_pkt)) 2539 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->max_pkt))
2531 goto attr_msg_full; 2540 goto attr_msg_full;
@@ -2575,9 +2584,8 @@ msg_full:
2575} 2584}
2576 2585
2577/* Caller should hold node lock */ 2586/* Caller should hold node lock */
2578static int __tipc_nl_add_node_links(struct tipc_nl_msg *msg, 2587static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2579 struct tipc_node *node, 2588 struct tipc_node *node, u32 *prev_link)
2580 u32 *prev_link)
2581{ 2589{
2582 u32 i; 2590 u32 i;
2583 int err; 2591 int err;
@@ -2588,7 +2596,7 @@ static int __tipc_nl_add_node_links(struct tipc_nl_msg *msg,
2588 if (!node->links[i]) 2596 if (!node->links[i])
2589 continue; 2597 continue;
2590 2598
2591 err = __tipc_nl_add_link(msg, node->links[i]); 2599 err = __tipc_nl_add_link(net, msg, node->links[i]);
2592 if (err) 2600 if (err)
2593 return err; 2601 return err;
2594 } 2602 }
@@ -2633,7 +2641,8 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
2633 list_for_each_entry_continue_rcu(node, &tn->node_list, 2641 list_for_each_entry_continue_rcu(node, &tn->node_list,
2634 list) { 2642 list) {
2635 tipc_node_lock(node); 2643 tipc_node_lock(node);
2636 err = __tipc_nl_add_node_links(&msg, node, &prev_link); 2644 err = __tipc_nl_add_node_links(net, &msg, node,
2645 &prev_link);
2637 tipc_node_unlock(node); 2646 tipc_node_unlock(node);
2638 if (err) 2647 if (err)
2639 goto out; 2648 goto out;
@@ -2647,7 +2656,8 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
2647 2656
2648 list_for_each_entry_rcu(node, &tn->node_list, list) { 2657 list_for_each_entry_rcu(node, &tn->node_list, list) {
2649 tipc_node_lock(node); 2658 tipc_node_lock(node);
2650 err = __tipc_nl_add_node_links(&msg, node, &prev_link); 2659 err = __tipc_nl_add_node_links(net, &msg, node,
2660 &prev_link);
2651 tipc_node_unlock(node); 2661 tipc_node_unlock(node);
2652 if (err) 2662 if (err)
2653 goto out; 2663 goto out;
@@ -2700,7 +2710,7 @@ int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
2700 goto err_out; 2710 goto err_out;
2701 } 2711 }
2702 2712
2703 err = __tipc_nl_add_link(&msg, link); 2713 err = __tipc_nl_add_link(net, &msg, link);
2704 if (err) 2714 if (err)
2705 goto err_out; 2715 goto err_out;
2706 2716