aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bcast.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-10-22 08:51:33 -0400
committerDavid S. Miller <davem@davemloft.net>2015-10-24 09:56:24 -0400
commit6beb19a62a87ef6f7107fcd43c2cc1ebad3edfb5 (patch)
tree9183a5007a4d95f451eef1848486a498e9831b46 /net/tipc/bcast.c
parentba3e2084f268bdfed7627046e58a2218037e15af (diff)
tipc: move bcast definitions to bcast.c
Currently, a number of structure and function definitions related to the broadcast functionality are unnecessarily exposed in the file bcast.h. This obscures the fact that the external interface towards the broadcast link in fact is very narrow, and causes unnecessary recompilations of other files when anything changes in those definitions. In this commit, we move as many of those definitions as is currently possible to the file bcast.c. We also rename the structure 'tipc_bclink' to 'tipc_bc_base', both since the name does not correctly describe the contents of this struct, and will do so even less in the future, and because we want to use the term 'link' more appropriately in the functionality introduced later in this series. Finally, we rename a couple of functions, such as tipc_bclink_xmit() and others that will be kept in the future, to include the term 'bcast' instead. There are no functional changes in this commit. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/bcast.c')
-rw-r--r--net/tipc/bcast.c117
1 files changed, 93 insertions, 24 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index eadba62afa85..2c5f5443354a 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -35,11 +35,13 @@
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <linux/tipc_config.h>
38#include "socket.h" 39#include "socket.h"
39#include "msg.h" 40#include "msg.h"
40#include "bcast.h" 41#include "bcast.h"
41#include "name_distr.h" 42#include "name_distr.h"
42#include "core.h" 43#include "link.h"
44#include "node.h"
43 45
44#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ 46#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
45#define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */ 47#define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */
@@ -47,34 +49,101 @@
47 49
48const char tipc_bclink_name[] = "broadcast-link"; 50const char tipc_bclink_name[] = "broadcast-link";
49 51
52/**
53 * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link
54 * @primary: pointer to primary bearer
55 * @secondary: pointer to secondary bearer
56 *
57 * Bearers must have same priority and same set of reachable destinations
58 * to be paired.
59 */
60
61struct tipc_bcbearer_pair {
62 struct tipc_bearer *primary;
63 struct tipc_bearer *secondary;
64};
65
66#define BCBEARER MAX_BEARERS
67
68/**
69 * struct tipc_bcbearer - bearer used by broadcast link
70 * @bearer: (non-standard) broadcast bearer structure
71 * @media: (non-standard) broadcast media structure
72 * @bpairs: array of bearer pairs
73 * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort()
74 * @remains: temporary node map used by tipc_bcbearer_send()
75 * @remains_new: temporary node map used tipc_bcbearer_send()
76 *
77 * Note: The fields labelled "temporary" are incorporated into the bearer
78 * to avoid consuming potentially limited stack space through the use of
79 * large local variables within multicast routines. Concurrent access is
80 * prevented through use of the spinlock "bcast_lock".
81 */
82struct tipc_bcbearer {
83 struct tipc_bearer bearer;
84 struct tipc_media media;
85 struct tipc_bcbearer_pair bpairs[MAX_BEARERS];
86 struct tipc_bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];
87 struct tipc_node_map remains;
88 struct tipc_node_map remains_new;
89};
90
91/**
92 * struct tipc_bc_base - link used for broadcast messages
93 * @lock: spinlock governing access to structure
94 * @link: (non-standard) broadcast link structure
95 * @node: (non-standard) node structure representing b'cast link's peer node
96 * @bcast_nodes: map of broadcast-capable nodes
97 * @retransmit_to: node that most recently requested a retransmit
98 *
99 * Handles sequence numbering, fragmentation, bundling, etc.
100 */
101struct tipc_bc_base {
102 spinlock_t lock; /* spinlock protecting broadcast structs */
103 struct tipc_link link;
104 struct tipc_node node;
105 struct sk_buff_head arrvq;
106 struct sk_buff_head inputq;
107 struct tipc_node_map bcast_nodes;
108 struct tipc_node *retransmit_to;
109};
110
111/**
112 * tipc_nmap_equal - test for equality of node maps
113 */
114static int tipc_nmap_equal(struct tipc_node_map *nm_a,
115 struct tipc_node_map *nm_b)
116{
117 return !memcmp(nm_a, nm_b, sizeof(*nm_a));
118}
119
50static void tipc_nmap_diff(struct tipc_node_map *nm_a, 120static void tipc_nmap_diff(struct tipc_node_map *nm_a,
51 struct tipc_node_map *nm_b, 121 struct tipc_node_map *nm_b,
52 struct tipc_node_map *nm_diff); 122 struct tipc_node_map *nm_diff);
53static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node); 123static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node);
54static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node); 124static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node);
55
56static void tipc_bclink_lock(struct net *net) 125static void tipc_bclink_lock(struct net *net)
57{ 126{
58 struct tipc_net *tn = net_generic(net, tipc_net_id); 127 struct tipc_net *tn = net_generic(net, tipc_net_id);
59 128
60 spin_lock_bh(&tn->bclink->lock); 129 spin_lock_bh(&tn->bcbase->lock);
61} 130}
62 131
63static void tipc_bclink_unlock(struct net *net) 132static void tipc_bclink_unlock(struct net *net)
64{ 133{
65 struct tipc_net *tn = net_generic(net, tipc_net_id); 134 struct tipc_net *tn = net_generic(net, tipc_net_id);
66 135
67 spin_unlock_bh(&tn->bclink->lock); 136 spin_unlock_bh(&tn->bcbase->lock);
68} 137}
69 138
70void tipc_bclink_input(struct net *net) 139void tipc_bclink_input(struct net *net)
71{ 140{
72 struct tipc_net *tn = net_generic(net, tipc_net_id); 141 struct tipc_net *tn = net_generic(net, tipc_net_id);
73 142
74 tipc_sk_mcast_rcv(net, &tn->bclink->arrvq, &tn->bclink->inputq); 143 tipc_sk_mcast_rcv(net, &tn->bcbase->arrvq, &tn->bcbase->inputq);
75} 144}
76 145
77uint tipc_bclink_get_mtu(void) 146uint tipc_bcast_get_mtu(void)
78{ 147{
79 return MAX_PKT_DEFAULT_MCAST; 148 return MAX_PKT_DEFAULT_MCAST;
80} 149}
@@ -99,7 +168,7 @@ void tipc_bclink_add_node(struct net *net, u32 addr)
99 struct tipc_net *tn = net_generic(net, tipc_net_id); 168 struct tipc_net *tn = net_generic(net, tipc_net_id);
100 169
101 tipc_bclink_lock(net); 170 tipc_bclink_lock(net);
102 tipc_nmap_add(&tn->bclink->bcast_nodes, addr); 171 tipc_nmap_add(&tn->bcbase->bcast_nodes, addr);
103 tipc_bclink_unlock(net); 172 tipc_bclink_unlock(net);
104} 173}
105 174
@@ -108,11 +177,11 @@ void tipc_bclink_remove_node(struct net *net, u32 addr)
108 struct tipc_net *tn = net_generic(net, tipc_net_id); 177 struct tipc_net *tn = net_generic(net, tipc_net_id);
109 178
110 tipc_bclink_lock(net); 179 tipc_bclink_lock(net);
111 tipc_nmap_remove(&tn->bclink->bcast_nodes, addr); 180 tipc_nmap_remove(&tn->bcbase->bcast_nodes, addr);
112 181
113 /* Last node? => reset backlog queue */ 182 /* Last node? => reset backlog queue */
114 if (!tn->bclink->bcast_nodes.count) 183 if (!tn->bcbase->bcast_nodes.count)
115 tipc_link_purge_backlog(&tn->bclink->link); 184 tipc_link_purge_backlog(&tn->bcbase->link);
116 185
117 tipc_bclink_unlock(net); 186 tipc_bclink_unlock(net);
118} 187}
@@ -147,7 +216,7 @@ struct tipc_node *tipc_bclink_retransmit_to(struct net *net)
147{ 216{
148 struct tipc_net *tn = net_generic(net, tipc_net_id); 217 struct tipc_net *tn = net_generic(net, tipc_net_id);
149 218
150 return tn->bclink->retransmit_to; 219 return tn->bcbase->retransmit_to;
151} 220}
152 221
153/** 222/**
@@ -241,7 +310,7 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
241 * acknowledge sent messages only (if other nodes still exist) 310 * acknowledge sent messages only (if other nodes still exist)
242 * or both sent and unsent messages (otherwise) 311 * or both sent and unsent messages (otherwise)
243 */ 312 */
244 if (tn->bclink->bcast_nodes.count) 313 if (tn->bcbase->bcast_nodes.count)
245 acked = tn->bcl->silent_intv_cnt; 314 acked = tn->bcl->silent_intv_cnt;
246 else 315 else
247 acked = tn->bcl->snd_nxt; 316 acked = tn->bcl->snd_nxt;
@@ -390,18 +459,18 @@ static void bclink_peek_nack(struct net *net, struct tipc_msg *msg)
390 tipc_node_put(n_ptr); 459 tipc_node_put(n_ptr);
391} 460}
392 461
393/* tipc_bclink_xmit - deliver buffer chain to all nodes in cluster 462/* tipc_bcast_xmit - deliver buffer chain to all nodes in cluster
394 * and to identified node local sockets 463 * and to identified node local sockets
395 * @net: the applicable net namespace 464 * @net: the applicable net namespace
396 * @list: chain of buffers containing message 465 * @list: chain of buffers containing message
397 * Consumes the buffer chain, except when returning -ELINKCONG 466 * Consumes the buffer chain, except when returning -ELINKCONG
398 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE 467 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
399 */ 468 */
400int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list) 469int tipc_bcast_xmit(struct net *net, struct sk_buff_head *list)
401{ 470{
402 struct tipc_net *tn = net_generic(net, tipc_net_id); 471 struct tipc_net *tn = net_generic(net, tipc_net_id);
403 struct tipc_link *bcl = tn->bcl; 472 struct tipc_link *bcl = tn->bcl;
404 struct tipc_bclink *bclink = tn->bclink; 473 struct tipc_bc_base *bclink = tn->bcbase;
405 int rc = 0; 474 int rc = 0;
406 int bc = 0; 475 int bc = 0;
407 struct sk_buff *skb; 476 struct sk_buff *skb;
@@ -508,7 +577,7 @@ void tipc_bclink_rcv(struct net *net, struct sk_buff *buf)
508 tipc_bclink_acknowledge(node, msg_bcast_ack(msg)); 577 tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
509 tipc_bclink_lock(net); 578 tipc_bclink_lock(net);
510 bcl->stats.recv_nacks++; 579 bcl->stats.recv_nacks++;
511 tn->bclink->retransmit_to = node; 580 tn->bcbase->retransmit_to = node;
512 bclink_retransmit_pkt(tn, msg_bcgap_after(msg), 581 bclink_retransmit_pkt(tn, msg_bcgap_after(msg),
513 msg_bcgap_to(msg)); 582 msg_bcgap_to(msg));
514 tipc_bclink_unlock(net); 583 tipc_bclink_unlock(net);
@@ -524,8 +593,8 @@ void tipc_bclink_rcv(struct net *net, struct sk_buff *buf)
524 /* Handle in-sequence broadcast message */ 593 /* Handle in-sequence broadcast message */
525 seqno = msg_seqno(msg); 594 seqno = msg_seqno(msg);
526 next_in = mod(node->bclink.last_in + 1); 595 next_in = mod(node->bclink.last_in + 1);
527 arrvq = &tn->bclink->arrvq; 596 arrvq = &tn->bcbase->arrvq;
528 inputq = &tn->bclink->inputq; 597 inputq = &tn->bcbase->inputq;
529 598
530 if (likely(seqno == next_in)) { 599 if (likely(seqno == next_in)) {
531receive: 600receive:
@@ -651,7 +720,7 @@ static int tipc_bcbearer_send(struct net *net, struct sk_buff *buf,
651 struct tipc_msg *msg = buf_msg(buf); 720 struct tipc_msg *msg = buf_msg(buf);
652 struct tipc_net *tn = net_generic(net, tipc_net_id); 721 struct tipc_net *tn = net_generic(net, tipc_net_id);
653 struct tipc_bcbearer *bcbearer = tn->bcbearer; 722 struct tipc_bcbearer *bcbearer = tn->bcbearer;
654 struct tipc_bclink *bclink = tn->bclink; 723 struct tipc_bc_base *bclink = tn->bcbase;
655 724
656 /* Prepare broadcast link message for reliable transmission, 725 /* Prepare broadcast link message for reliable transmission,
657 * if first time trying to send it; 726 * if first time trying to send it;
@@ -940,11 +1009,11 @@ int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[])
940 return tipc_bclink_set_queue_limits(net, win); 1009 return tipc_bclink_set_queue_limits(net, win);
941} 1010}
942 1011
943int tipc_bclink_init(struct net *net) 1012int tipc_bcast_init(struct net *net)
944{ 1013{
945 struct tipc_net *tn = net_generic(net, tipc_net_id); 1014 struct tipc_net *tn = net_generic(net, tipc_net_id);
946 struct tipc_bcbearer *bcbearer; 1015 struct tipc_bcbearer *bcbearer;
947 struct tipc_bclink *bclink; 1016 struct tipc_bc_base *bclink;
948 struct tipc_link *bcl; 1017 struct tipc_link *bcl;
949 1018
950 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); 1019 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
@@ -981,12 +1050,12 @@ int tipc_bclink_init(struct net *net)
981 msg_set_prevnode(bcl->pmsg, tn->own_addr); 1050 msg_set_prevnode(bcl->pmsg, tn->own_addr);
982 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); 1051 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME);
983 tn->bcbearer = bcbearer; 1052 tn->bcbearer = bcbearer;
984 tn->bclink = bclink; 1053 tn->bcbase = bclink;
985 tn->bcl = bcl; 1054 tn->bcl = bcl;
986 return 0; 1055 return 0;
987} 1056}
988 1057
989void tipc_bclink_stop(struct net *net) 1058void tipc_bcast_stop(struct net *net)
990{ 1059{
991 struct tipc_net *tn = net_generic(net, tipc_net_id); 1060 struct tipc_net *tn = net_generic(net, tipc_net_id);
992 1061
@@ -997,7 +1066,7 @@ void tipc_bclink_stop(struct net *net)
997 RCU_INIT_POINTER(tn->bearer_list[BCBEARER], NULL); 1066 RCU_INIT_POINTER(tn->bearer_list[BCBEARER], NULL);
998 synchronize_net(); 1067 synchronize_net();
999 kfree(tn->bcbearer); 1068 kfree(tn->bcbearer);
1000 kfree(tn->bclink); 1069 kfree(tn->bcbase);
1001} 1070}
1002 1071
1003/** 1072/**