diff options
author | Jon Paul Maloy <jon.maloy@ericsson.com> | 2015-10-22 08:51:37 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-10-24 09:56:30 -0400 |
commit | 323019069e8d96d87e9dba51f897060f94999821 (patch) | |
tree | 02d0426143d9a89548a1e6f5a0d0e2ef8448db49 /net/tipc | |
parent | 0e05498e9eae16a6d8c86543e77930ec152e655e (diff) |
tipc: use explicit allocation of broadcast send link
The broadcast link instance (struct tipc_link) used for sending is
currently aggregated into struct tipc_bclink. This means that we cannot
use the regular tipc_link_create() function for initiating the link, but
do instead have to initiate numerous fields directly from the
bcast_init() function.
We want to reduce dependencies between the broadcast functionality
and the inner workings of tipc_link. In this commit, we introduce
a new function tipc_bclink_create() to link.c, and allocate the
instance of the link separately using this function.
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')
-rw-r--r-- | net/tipc/bcast.c | 89 | ||||
-rw-r--r-- | net/tipc/bcast.h | 2 | ||||
-rw-r--r-- | net/tipc/link.c | 29 | ||||
-rw-r--r-- | net/tipc/link.h | 4 |
4 files changed, 79 insertions, 45 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index c6f0d1dbfc3c..3b7bd2174330 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
@@ -98,10 +98,11 @@ struct tipc_bcbearer { | |||
98 | * Handles sequence numbering, fragmentation, bundling, etc. | 98 | * Handles sequence numbering, fragmentation, bundling, etc. |
99 | */ | 99 | */ |
100 | struct tipc_bc_base { | 100 | struct tipc_bc_base { |
101 | struct tipc_link link; | 101 | struct tipc_link *link; |
102 | struct tipc_node node; | 102 | struct tipc_node node; |
103 | struct sk_buff_head arrvq; | 103 | struct sk_buff_head arrvq; |
104 | struct sk_buff_head inputq; | 104 | struct sk_buff_head inputq; |
105 | struct sk_buff_head namedq; | ||
105 | struct tipc_node_map bcast_nodes; | 106 | struct tipc_node_map bcast_nodes; |
106 | struct tipc_node *retransmit_to; | 107 | struct tipc_node *retransmit_to; |
107 | }; | 108 | }; |
@@ -180,7 +181,7 @@ void tipc_bclink_remove_node(struct net *net, u32 addr) | |||
180 | 181 | ||
181 | /* Last node? => reset backlog queue */ | 182 | /* Last node? => reset backlog queue */ |
182 | if (!tn->bcbase->bcast_nodes.count) | 183 | if (!tn->bcbase->bcast_nodes.count) |
183 | tipc_link_purge_backlog(&tn->bcbase->link); | 184 | tipc_link_purge_backlog(tn->bcbase->link); |
184 | 185 | ||
185 | tipc_bclink_unlock(net); | 186 | tipc_bclink_unlock(net); |
186 | } | 187 | } |
@@ -1010,55 +1011,56 @@ int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[]) | |||
1010 | 1011 | ||
1011 | int tipc_bcast_init(struct net *net) | 1012 | int tipc_bcast_init(struct net *net) |
1012 | { | 1013 | { |
1013 | struct tipc_net *tn = net_generic(net, tipc_net_id); | 1014 | struct tipc_net *tn = tipc_net(net); |
1014 | struct tipc_bcbearer *bcbearer; | 1015 | struct tipc_bcbearer *bcb = NULL; |
1015 | struct tipc_bc_base *bclink; | 1016 | struct tipc_bc_base *bb = NULL; |
1016 | struct tipc_link *bcl; | 1017 | struct tipc_link *l = NULL; |
1017 | 1018 | ||
1018 | bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); | 1019 | bcb = kzalloc(sizeof(*bcb), GFP_ATOMIC); |
1019 | if (!bcbearer) | 1020 | if (!bcb) |
1020 | return -ENOMEM; | 1021 | goto enomem; |
1021 | 1022 | tn->bcbearer = bcb; | |
1022 | bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC); | 1023 | |
1023 | if (!bclink) { | 1024 | bcb->bearer.window = BCLINK_WIN_DEFAULT; |
1024 | kfree(bcbearer); | 1025 | bcb->bearer.mtu = MAX_PKT_DEFAULT_MCAST; |
1025 | return -ENOMEM; | 1026 | bcb->bearer.identity = MAX_BEARERS; |
1026 | } | 1027 | |
1027 | 1028 | bcb->bearer.media = &bcb->media; | |
1028 | bcl = &bclink->link; | 1029 | bcb->media.send_msg = tipc_bcbearer_send; |
1029 | bcbearer->bearer.media = &bcbearer->media; | 1030 | sprintf(bcb->media.name, "tipc-broadcast"); |
1030 | bcbearer->media.send_msg = tipc_bcbearer_send; | 1031 | strcpy(bcb->bearer.name, bcb->media.name); |
1031 | sprintf(bcbearer->media.name, "tipc-broadcast"); | 1032 | |
1032 | 1033 | bb = kzalloc(sizeof(*bb), GFP_ATOMIC); | |
1034 | if (!bb) | ||
1035 | goto enomem; | ||
1036 | tn->bcbase = bb; | ||
1037 | __skb_queue_head_init(&bb->arrvq); | ||
1033 | spin_lock_init(&tipc_net(net)->bclock); | 1038 | spin_lock_init(&tipc_net(net)->bclock); |
1034 | __skb_queue_head_init(&bcl->transmq); | 1039 | bb->node.net = net; |
1035 | __skb_queue_head_init(&bcl->backlogq); | 1040 | |
1036 | __skb_queue_head_init(&bcl->deferdq); | 1041 | if (!tipc_link_bc_create(&bb->node, |
1037 | skb_queue_head_init(&bcl->wakeupq); | 1042 | MAX_PKT_DEFAULT_MCAST, |
1038 | bcl->snd_nxt = 1; | 1043 | BCLINK_WIN_DEFAULT, |
1039 | spin_lock_init(&bclink->node.lock); | 1044 | &bb->inputq, |
1040 | __skb_queue_head_init(&bclink->arrvq); | 1045 | &bb->namedq, |
1041 | skb_queue_head_init(&bclink->inputq); | 1046 | &l)) |
1042 | bcl->owner = &bclink->node; | 1047 | goto enomem; |
1043 | bcl->owner->net = net; | 1048 | bb->link = l; |
1044 | bcl->mtu = MAX_PKT_DEFAULT_MCAST; | 1049 | tn->bcl = l; |
1045 | tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); | 1050 | rcu_assign_pointer(tn->bearer_list[MAX_BEARERS], &bcb->bearer); |
1046 | bcl->bearer_id = MAX_BEARERS; | ||
1047 | rcu_assign_pointer(tn->bearer_list[MAX_BEARERS], &bcbearer->bearer); | ||
1048 | bcl->pmsg = (struct tipc_msg *)&bcl->proto_msg; | ||
1049 | |||
1050 | strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); | ||
1051 | tn->bcbearer = bcbearer; | ||
1052 | tn->bcbase = bclink; | ||
1053 | tn->bcl = bcl; | ||
1054 | return 0; | 1051 | return 0; |
1052 | enomem: | ||
1053 | kfree(bcb); | ||
1054 | kfree(bb); | ||
1055 | kfree(l); | ||
1056 | return -ENOMEM; | ||
1055 | } | 1057 | } |
1056 | 1058 | ||
1057 | void tipc_bcast_reinit(struct net *net) | 1059 | void tipc_bcast_reinit(struct net *net) |
1058 | { | 1060 | { |
1059 | struct tipc_bc_base *b = tipc_bc_base(net); | 1061 | struct tipc_bc_base *b = tipc_bc_base(net); |
1060 | 1062 | ||
1061 | msg_set_prevnode(b->link.pmsg, tipc_own_addr(net)); | 1063 | msg_set_prevnode(b->link->pmsg, tipc_own_addr(net)); |
1062 | } | 1064 | } |
1063 | 1065 | ||
1064 | void tipc_bcast_stop(struct net *net) | 1066 | void tipc_bcast_stop(struct net *net) |
@@ -1072,6 +1074,7 @@ void tipc_bcast_stop(struct net *net) | |||
1072 | synchronize_net(); | 1074 | synchronize_net(); |
1073 | kfree(tn->bcbearer); | 1075 | kfree(tn->bcbearer); |
1074 | kfree(tn->bcbase); | 1076 | kfree(tn->bcbase); |
1077 | kfree(tn->bcl); | ||
1075 | } | 1078 | } |
1076 | 1079 | ||
1077 | /** | 1080 | /** |
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h index 041935d4ad6d..a378fdde9b7a 100644 --- a/net/tipc/bcast.h +++ b/net/tipc/bcast.h | |||
@@ -44,8 +44,6 @@ struct tipc_msg; | |||
44 | struct tipc_nl_msg; | 44 | struct tipc_nl_msg; |
45 | struct tipc_node_map; | 45 | struct tipc_node_map; |
46 | 46 | ||
47 | extern const char tipc_bclink_name[]; | ||
48 | |||
49 | int tipc_bcast_init(struct net *net); | 47 | int tipc_bcast_init(struct net *net); |
50 | void tipc_bcast_reinit(struct net *net); | 48 | void tipc_bcast_reinit(struct net *net); |
51 | void tipc_bcast_stop(struct net *net); | 49 | void tipc_bcast_stop(struct net *net); |
diff --git a/net/tipc/link.c b/net/tipc/link.c index 0d8fdc8fe6d4..f0cf768a59f3 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -50,6 +50,7 @@ | |||
50 | */ | 50 | */ |
51 | static const char *link_co_err = "Link tunneling error, "; | 51 | static const char *link_co_err = "Link tunneling error, "; |
52 | static const char *link_rst_msg = "Resetting link "; | 52 | static const char *link_rst_msg = "Resetting link "; |
53 | static const char tipc_bclink_name[] = "broadcast-link"; | ||
53 | 54 | ||
54 | static const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = { | 55 | static const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = { |
55 | [TIPC_NLA_LINK_UNSPEC] = { .type = NLA_UNSPEC }, | 56 | [TIPC_NLA_LINK_UNSPEC] = { .type = NLA_UNSPEC }, |
@@ -231,6 +232,34 @@ bool tipc_link_create(struct tipc_node *n, char *if_name, int bearer_id, | |||
231 | return true; | 232 | return true; |
232 | } | 233 | } |
233 | 234 | ||
235 | /** | ||
236 | * tipc_link_bc_create - create new link to be used for broadcast | ||
237 | * @n: pointer to associated node | ||
238 | * @mtu: mtu to be used | ||
239 | * @window: send window to be used | ||
240 | * @inputq: queue to put messages ready for delivery | ||
241 | * @namedq: queue to put binding table update messages ready for delivery | ||
242 | * @link: return value, pointer to put the created link | ||
243 | * | ||
244 | * Returns true if link was created, otherwise false | ||
245 | */ | ||
246 | bool tipc_link_bc_create(struct tipc_node *n, int mtu, int window, | ||
247 | struct sk_buff_head *inputq, | ||
248 | struct sk_buff_head *namedq, | ||
249 | struct tipc_link **link) | ||
250 | { | ||
251 | struct tipc_link *l; | ||
252 | |||
253 | if (!tipc_link_create(n, "", MAX_BEARERS, 0, 'Z', mtu, 0, window, | ||
254 | 0, 0, 0, NULL, inputq, namedq, link)) | ||
255 | return false; | ||
256 | |||
257 | l = *link; | ||
258 | strcpy(l->name, tipc_bclink_name); | ||
259 | tipc_link_reset(l); | ||
260 | return true; | ||
261 | } | ||
262 | |||
234 | /* tipc_link_build_bcast_sync_msg() - synchronize broadcast link endpoints. | 263 | /* tipc_link_build_bcast_sync_msg() - synchronize broadcast link endpoints. |
235 | * | 264 | * |
236 | * Give a newly added peer node the sequence number where it should | 265 | * Give a newly added peer node the sequence number where it should |
diff --git a/net/tipc/link.h b/net/tipc/link.h index 06bf66df9469..9e4e3673da76 100644 --- a/net/tipc/link.h +++ b/net/tipc/link.h | |||
@@ -211,6 +211,10 @@ bool tipc_link_create(struct tipc_node *n, char *if_name, int bearer_id, | |||
211 | struct tipc_media_addr *maddr, | 211 | struct tipc_media_addr *maddr, |
212 | struct sk_buff_head *inputq, struct sk_buff_head *namedq, | 212 | struct sk_buff_head *inputq, struct sk_buff_head *namedq, |
213 | struct tipc_link **link); | 213 | struct tipc_link **link); |
214 | bool tipc_link_bc_create(struct tipc_node *n, int mtu, int window, | ||
215 | struct sk_buff_head *inputq, | ||
216 | struct sk_buff_head *namedq, | ||
217 | struct tipc_link **link); | ||
214 | void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl, | 218 | void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl, |
215 | int mtyp, struct sk_buff_head *xmitq); | 219 | int mtyp, struct sk_buff_head *xmitq); |
216 | void tipc_link_build_bcast_sync_msg(struct tipc_link *l, | 220 | void tipc_link_build_bcast_sync_msg(struct tipc_link *l, |