diff options
Diffstat (limited to 'net/tipc/discover.c')
-rw-r--r-- | net/tipc/discover.c | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index aa722a42ef8b..feef3753615d 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/discover.c | 2 | * net/tipc/discover.c |
3 | * | 3 | * |
4 | * Copyright (c) 2003-2006, 2014, Ericsson AB | 4 | * Copyright (c) 2003-2006, 2014-2015, Ericsson AB |
5 | * Copyright (c) 2005-2006, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005-2006, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -38,15 +38,19 @@ | |||
38 | #include "link.h" | 38 | #include "link.h" |
39 | #include "discover.h" | 39 | #include "discover.h" |
40 | 40 | ||
41 | #define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */ | 41 | /* min delay during bearer start up */ |
42 | #define TIPC_LINK_REQ_FAST 1000 /* max delay if bearer has no links */ | 42 | #define TIPC_LINK_REQ_INIT msecs_to_jiffies(125) |
43 | #define TIPC_LINK_REQ_SLOW 60000 /* max delay if bearer has links */ | 43 | /* max delay if bearer has no links */ |
44 | #define TIPC_LINK_REQ_INACTIVE 0xffffffff /* indicates no timer in use */ | 44 | #define TIPC_LINK_REQ_FAST msecs_to_jiffies(1000) |
45 | 45 | /* max delay if bearer has links */ | |
46 | #define TIPC_LINK_REQ_SLOW msecs_to_jiffies(60000) | ||
47 | /* indicates no timer in use */ | ||
48 | #define TIPC_LINK_REQ_INACTIVE 0xffffffff | ||
46 | 49 | ||
47 | /** | 50 | /** |
48 | * struct tipc_link_req - information about an ongoing link setup request | 51 | * struct tipc_link_req - information about an ongoing link setup request |
49 | * @bearer_id: identity of bearer issuing requests | 52 | * @bearer_id: identity of bearer issuing requests |
53 | * @net: network namespace instance | ||
50 | * @dest: destination address for request messages | 54 | * @dest: destination address for request messages |
51 | * @domain: network domain to which links can be established | 55 | * @domain: network domain to which links can be established |
52 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) | 56 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) |
@@ -58,31 +62,35 @@ | |||
58 | struct tipc_link_req { | 62 | struct tipc_link_req { |
59 | u32 bearer_id; | 63 | u32 bearer_id; |
60 | struct tipc_media_addr dest; | 64 | struct tipc_media_addr dest; |
65 | struct net *net; | ||
61 | u32 domain; | 66 | u32 domain; |
62 | int num_nodes; | 67 | int num_nodes; |
63 | spinlock_t lock; | 68 | spinlock_t lock; |
64 | struct sk_buff *buf; | 69 | struct sk_buff *buf; |
65 | struct timer_list timer; | 70 | struct timer_list timer; |
66 | unsigned int timer_intv; | 71 | unsigned long timer_intv; |
67 | }; | 72 | }; |
68 | 73 | ||
69 | /** | 74 | /** |
70 | * tipc_disc_init_msg - initialize a link setup message | 75 | * tipc_disc_init_msg - initialize a link setup message |
76 | * @net: the applicable net namespace | ||
71 | * @type: message type (request or response) | 77 | * @type: message type (request or response) |
72 | * @b_ptr: ptr to bearer issuing message | 78 | * @b_ptr: ptr to bearer issuing message |
73 | */ | 79 | */ |
74 | static void tipc_disc_init_msg(struct sk_buff *buf, u32 type, | 80 | static void tipc_disc_init_msg(struct net *net, struct sk_buff *buf, u32 type, |
75 | struct tipc_bearer *b_ptr) | 81 | struct tipc_bearer *b_ptr) |
76 | { | 82 | { |
83 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
77 | struct tipc_msg *msg; | 84 | struct tipc_msg *msg; |
78 | u32 dest_domain = b_ptr->domain; | 85 | u32 dest_domain = b_ptr->domain; |
79 | 86 | ||
80 | msg = buf_msg(buf); | 87 | msg = buf_msg(buf); |
81 | tipc_msg_init(msg, LINK_CONFIG, type, INT_H_SIZE, dest_domain); | 88 | tipc_msg_init(tn->own_addr, msg, LINK_CONFIG, type, |
89 | INT_H_SIZE, dest_domain); | ||
82 | msg_set_non_seq(msg, 1); | 90 | msg_set_non_seq(msg, 1); |
83 | msg_set_node_sig(msg, tipc_random); | 91 | msg_set_node_sig(msg, tn->random); |
84 | msg_set_dest_domain(msg, dest_domain); | 92 | msg_set_dest_domain(msg, dest_domain); |
85 | msg_set_bc_netid(msg, tipc_net_id); | 93 | msg_set_bc_netid(msg, tn->net_id); |
86 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); | 94 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); |
87 | } | 95 | } |
88 | 96 | ||
@@ -107,11 +115,14 @@ static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr, | |||
107 | 115 | ||
108 | /** | 116 | /** |
109 | * tipc_disc_rcv - handle incoming discovery message (request or response) | 117 | * tipc_disc_rcv - handle incoming discovery message (request or response) |
118 | * @net: the applicable net namespace | ||
110 | * @buf: buffer containing message | 119 | * @buf: buffer containing message |
111 | * @bearer: bearer that message arrived on | 120 | * @bearer: bearer that message arrived on |
112 | */ | 121 | */ |
113 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | 122 | void tipc_disc_rcv(struct net *net, struct sk_buff *buf, |
123 | struct tipc_bearer *bearer) | ||
114 | { | 124 | { |
125 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
115 | struct tipc_node *node; | 126 | struct tipc_node *node; |
116 | struct tipc_link *link; | 127 | struct tipc_link *link; |
117 | struct tipc_media_addr maddr; | 128 | struct tipc_media_addr maddr; |
@@ -133,7 +144,7 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
133 | kfree_skb(buf); | 144 | kfree_skb(buf); |
134 | 145 | ||
135 | /* Ensure message from node is valid and communication is permitted */ | 146 | /* Ensure message from node is valid and communication is permitted */ |
136 | if (net_id != tipc_net_id) | 147 | if (net_id != tn->net_id) |
137 | return; | 148 | return; |
138 | if (maddr.broadcast) | 149 | if (maddr.broadcast) |
139 | return; | 150 | return; |
@@ -142,23 +153,19 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
142 | if (!tipc_addr_node_valid(onode)) | 153 | if (!tipc_addr_node_valid(onode)) |
143 | return; | 154 | return; |
144 | 155 | ||
145 | if (in_own_node(onode)) { | 156 | if (in_own_node(net, onode)) { |
146 | if (memcmp(&maddr, &bearer->addr, sizeof(maddr))) | 157 | if (memcmp(&maddr, &bearer->addr, sizeof(maddr))) |
147 | disc_dupl_alert(bearer, tipc_own_addr, &maddr); | 158 | disc_dupl_alert(bearer, tn->own_addr, &maddr); |
148 | return; | 159 | return; |
149 | } | 160 | } |
150 | if (!tipc_in_scope(ddom, tipc_own_addr)) | 161 | if (!tipc_in_scope(ddom, tn->own_addr)) |
151 | return; | 162 | return; |
152 | if (!tipc_in_scope(bearer->domain, onode)) | 163 | if (!tipc_in_scope(bearer->domain, onode)) |
153 | return; | 164 | return; |
154 | 165 | ||
155 | /* Locate, or if necessary, create, node: */ | 166 | node = tipc_node_create(net, onode); |
156 | node = tipc_node_find(onode); | ||
157 | if (!node) | ||
158 | node = tipc_node_create(onode); | ||
159 | if (!node) | 167 | if (!node) |
160 | return; | 168 | return; |
161 | |||
162 | tipc_node_lock(node); | 169 | tipc_node_lock(node); |
163 | link = node->links[bearer->identity]; | 170 | link = node->links[bearer->identity]; |
164 | 171 | ||
@@ -244,8 +251,8 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
244 | if (respond && (mtyp == DSC_REQ_MSG)) { | 251 | if (respond && (mtyp == DSC_REQ_MSG)) { |
245 | rbuf = tipc_buf_acquire(INT_H_SIZE); | 252 | rbuf = tipc_buf_acquire(INT_H_SIZE); |
246 | if (rbuf) { | 253 | if (rbuf) { |
247 | tipc_disc_init_msg(rbuf, DSC_RESP_MSG, bearer); | 254 | tipc_disc_init_msg(net, rbuf, DSC_RESP_MSG, bearer); |
248 | tipc_bearer_send(bearer->identity, rbuf, &maddr); | 255 | tipc_bearer_send(net, bearer->identity, rbuf, &maddr); |
249 | kfree_skb(rbuf); | 256 | kfree_skb(rbuf); |
250 | } | 257 | } |
251 | } | 258 | } |
@@ -265,7 +272,7 @@ static void disc_update(struct tipc_link_req *req) | |||
265 | if ((req->timer_intv == TIPC_LINK_REQ_INACTIVE) || | 272 | if ((req->timer_intv == TIPC_LINK_REQ_INACTIVE) || |
266 | (req->timer_intv > TIPC_LINK_REQ_FAST)) { | 273 | (req->timer_intv > TIPC_LINK_REQ_FAST)) { |
267 | req->timer_intv = TIPC_LINK_REQ_INIT; | 274 | req->timer_intv = TIPC_LINK_REQ_INIT; |
268 | k_start_timer(&req->timer, req->timer_intv); | 275 | mod_timer(&req->timer, jiffies + req->timer_intv); |
269 | } | 276 | } |
270 | } | 277 | } |
271 | } | 278 | } |
@@ -295,12 +302,13 @@ void tipc_disc_remove_dest(struct tipc_link_req *req) | |||
295 | 302 | ||
296 | /** | 303 | /** |
297 | * disc_timeout - send a periodic link setup request | 304 | * disc_timeout - send a periodic link setup request |
298 | * @req: ptr to link request structure | 305 | * @data: ptr to link request structure |
299 | * | 306 | * |
300 | * Called whenever a link setup request timer associated with a bearer expires. | 307 | * Called whenever a link setup request timer associated with a bearer expires. |
301 | */ | 308 | */ |
302 | static void disc_timeout(struct tipc_link_req *req) | 309 | static void disc_timeout(unsigned long data) |
303 | { | 310 | { |
311 | struct tipc_link_req *req = (struct tipc_link_req *)data; | ||
304 | int max_delay; | 312 | int max_delay; |
305 | 313 | ||
306 | spin_lock_bh(&req->lock); | 314 | spin_lock_bh(&req->lock); |
@@ -318,7 +326,7 @@ static void disc_timeout(struct tipc_link_req *req) | |||
318 | * hold at fast polling rate if don't have any associated nodes, | 326 | * hold at fast polling rate if don't have any associated nodes, |
319 | * otherwise hold at slow polling rate | 327 | * otherwise hold at slow polling rate |
320 | */ | 328 | */ |
321 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 329 | tipc_bearer_send(req->net, req->bearer_id, req->buf, &req->dest); |
322 | 330 | ||
323 | 331 | ||
324 | req->timer_intv *= 2; | 332 | req->timer_intv *= 2; |
@@ -329,20 +337,22 @@ static void disc_timeout(struct tipc_link_req *req) | |||
329 | if (req->timer_intv > max_delay) | 337 | if (req->timer_intv > max_delay) |
330 | req->timer_intv = max_delay; | 338 | req->timer_intv = max_delay; |
331 | 339 | ||
332 | k_start_timer(&req->timer, req->timer_intv); | 340 | mod_timer(&req->timer, jiffies + req->timer_intv); |
333 | exit: | 341 | exit: |
334 | spin_unlock_bh(&req->lock); | 342 | spin_unlock_bh(&req->lock); |
335 | } | 343 | } |
336 | 344 | ||
337 | /** | 345 | /** |
338 | * tipc_disc_create - create object to send periodic link setup requests | 346 | * tipc_disc_create - create object to send periodic link setup requests |
347 | * @net: the applicable net namespace | ||
339 | * @b_ptr: ptr to bearer issuing requests | 348 | * @b_ptr: ptr to bearer issuing requests |
340 | * @dest: destination address for request messages | 349 | * @dest: destination address for request messages |
341 | * @dest_domain: network domain to which links can be established | 350 | * @dest_domain: network domain to which links can be established |
342 | * | 351 | * |
343 | * Returns 0 if successful, otherwise -errno. | 352 | * Returns 0 if successful, otherwise -errno. |
344 | */ | 353 | */ |
345 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | 354 | int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr, |
355 | struct tipc_media_addr *dest) | ||
346 | { | 356 | { |
347 | struct tipc_link_req *req; | 357 | struct tipc_link_req *req; |
348 | 358 | ||
@@ -356,17 +366,18 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | |||
356 | return -ENOMEM; | 366 | return -ENOMEM; |
357 | } | 367 | } |
358 | 368 | ||
359 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 369 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
360 | memcpy(&req->dest, dest, sizeof(*dest)); | 370 | memcpy(&req->dest, dest, sizeof(*dest)); |
371 | req->net = net; | ||
361 | req->bearer_id = b_ptr->identity; | 372 | req->bearer_id = b_ptr->identity; |
362 | req->domain = b_ptr->domain; | 373 | req->domain = b_ptr->domain; |
363 | req->num_nodes = 0; | 374 | req->num_nodes = 0; |
364 | req->timer_intv = TIPC_LINK_REQ_INIT; | 375 | req->timer_intv = TIPC_LINK_REQ_INIT; |
365 | spin_lock_init(&req->lock); | 376 | spin_lock_init(&req->lock); |
366 | k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); | 377 | setup_timer(&req->timer, disc_timeout, (unsigned long)req); |
367 | k_start_timer(&req->timer, req->timer_intv); | 378 | mod_timer(&req->timer, jiffies + req->timer_intv); |
368 | b_ptr->link_req = req; | 379 | b_ptr->link_req = req; |
369 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 380 | tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest); |
370 | return 0; | 381 | return 0; |
371 | } | 382 | } |
372 | 383 | ||
@@ -376,28 +387,29 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | |||
376 | */ | 387 | */ |
377 | void tipc_disc_delete(struct tipc_link_req *req) | 388 | void tipc_disc_delete(struct tipc_link_req *req) |
378 | { | 389 | { |
379 | k_cancel_timer(&req->timer); | 390 | del_timer_sync(&req->timer); |
380 | k_term_timer(&req->timer); | ||
381 | kfree_skb(req->buf); | 391 | kfree_skb(req->buf); |
382 | kfree(req); | 392 | kfree(req); |
383 | } | 393 | } |
384 | 394 | ||
385 | /** | 395 | /** |
386 | * tipc_disc_reset - reset object to send periodic link setup requests | 396 | * tipc_disc_reset - reset object to send periodic link setup requests |
397 | * @net: the applicable net namespace | ||
387 | * @b_ptr: ptr to bearer issuing requests | 398 | * @b_ptr: ptr to bearer issuing requests |
388 | * @dest_domain: network domain to which links can be established | 399 | * @dest_domain: network domain to which links can be established |
389 | */ | 400 | */ |
390 | void tipc_disc_reset(struct tipc_bearer *b_ptr) | 401 | void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr) |
391 | { | 402 | { |
392 | struct tipc_link_req *req = b_ptr->link_req; | 403 | struct tipc_link_req *req = b_ptr->link_req; |
393 | 404 | ||
394 | spin_lock_bh(&req->lock); | 405 | spin_lock_bh(&req->lock); |
395 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 406 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
407 | req->net = net; | ||
396 | req->bearer_id = b_ptr->identity; | 408 | req->bearer_id = b_ptr->identity; |
397 | req->domain = b_ptr->domain; | 409 | req->domain = b_ptr->domain; |
398 | req->num_nodes = 0; | 410 | req->num_nodes = 0; |
399 | req->timer_intv = TIPC_LINK_REQ_INIT; | 411 | req->timer_intv = TIPC_LINK_REQ_INIT; |
400 | k_start_timer(&req->timer, req->timer_intv); | 412 | mod_timer(&req->timer, jiffies + req->timer_intv); |
401 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 413 | tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest); |
402 | spin_unlock_bh(&req->lock); | 414 | spin_unlock_bh(&req->lock); |
403 | } | 415 | } |