]>
Commit | Line | Data |
---|---|---|
b97bf3fd | 1 | /* |
5b06c85c | 2 | * net/tipc/subscr.c: TIPC network topology service |
c4307285 | 3 | * |
593a5f22 | 4 | * Copyright (c) 2000-2006, Ericsson AB |
5b06c85c | 5 | * Copyright (c) 2005-2007, Wind River Systems |
b97bf3fd PL |
6 | * All rights reserved. |
7 | * | |
9ea1fd3c | 8 | * Redistribution and use in source and binary forms, with or without |
b97bf3fd PL |
9 | * modification, are permitted provided that the following conditions are met: |
10 | * | |
9ea1fd3c PL |
11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. Neither the names of the copyright holders nor the names of its | |
17 | * contributors may be used to endorse or promote products derived from | |
18 | * this software without specific prior written permission. | |
b97bf3fd | 19 | * |
9ea1fd3c PL |
20 | * Alternatively, this software may be distributed under the terms of the |
21 | * GNU General Public License ("GPL") version 2 as published by the Free | |
22 | * Software Foundation. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
b97bf3fd PL |
34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | */ | |
36 | ||
37 | #include "core.h" | |
b97bf3fd | 38 | #include "name_table.h" |
d265fef6 | 39 | #include "user_reg.h" |
5b06c85c | 40 | #include "subscr.h" |
b97bf3fd PL |
41 | |
42 | /** | |
43 | * struct subscriber - TIPC network topology subscriber | |
28353e7f AS |
44 | * @port_ref: object reference to server port connecting to subscriber |
45 | * @lock: pointer to spinlock controlling access to subscriber's server port | |
b97bf3fd PL |
46 | * @subscriber_list: adjacent subscribers in top. server's list of subscribers |
47 | * @subscription_list: list of subscription objects for this subscriber | |
b97bf3fd | 48 | */ |
c4307285 | 49 | |
b97bf3fd | 50 | struct subscriber { |
28353e7f | 51 | u32 port_ref; |
c4307285 | 52 | spinlock_t *lock; |
b97bf3fd PL |
53 | struct list_head subscriber_list; |
54 | struct list_head subscription_list; | |
b97bf3fd PL |
55 | }; |
56 | ||
57 | /** | |
58 | * struct top_srv - TIPC network topology subscription service | |
59 | * @user_ref: TIPC userid of subscription service | |
60 | * @setup_port: reference to TIPC port that handles subscription requests | |
61 | * @subscription_count: number of active subscriptions (not subscribers!) | |
62 | * @subscriber_list: list of ports subscribing to service | |
63 | * @lock: spinlock govering access to subscriber list | |
64 | */ | |
65 | ||
66 | struct top_srv { | |
67 | u32 user_ref; | |
68 | u32 setup_port; | |
69 | atomic_t subscription_count; | |
70 | struct list_head subscriber_list; | |
71 | spinlock_t lock; | |
72 | }; | |
73 | ||
74 | static struct top_srv topsrv = { 0 }; | |
75 | ||
db5a753b NH |
76 | /** |
77 | * htohl - convert value to endianness used by destination | |
78 | * @in: value to convert | |
79 | * @swap: non-zero if endianness must be reversed | |
80 | * | |
81 | * Returns converted value | |
82 | */ | |
83 | ||
84 | static u32 htohl(u32 in, int swap) | |
85 | { | |
86 | return swap ? swab32(in) : in; | |
87 | } | |
88 | ||
b97bf3fd PL |
89 | /** |
90 | * subscr_send_event - send a message containing a tipc_event to the subscriber | |
28353e7f AS |
91 | * |
92 | * Note: Must not hold subscriber's server port lock, since tipc_send() will | |
93 | * try to take the lock if the message is rejected and returned! | |
b97bf3fd PL |
94 | */ |
95 | ||
c4307285 YH |
96 | static void subscr_send_event(struct subscription *sub, |
97 | u32 found_lower, | |
b97bf3fd | 98 | u32 found_upper, |
c4307285 YH |
99 | u32 event, |
100 | u32 port_ref, | |
b97bf3fd PL |
101 | u32 node) |
102 | { | |
103 | struct iovec msg_sect; | |
104 | ||
105 | msg_sect.iov_base = (void *)&sub->evt; | |
106 | msg_sect.iov_len = sizeof(struct tipc_event); | |
107 | ||
db5a753b NH |
108 | sub->evt.event = htohl(event, sub->swap); |
109 | sub->evt.found_lower = htohl(found_lower, sub->swap); | |
110 | sub->evt.found_upper = htohl(found_upper, sub->swap); | |
111 | sub->evt.port.ref = htohl(port_ref, sub->swap); | |
112 | sub->evt.port.node = htohl(node, sub->swap); | |
28353e7f | 113 | tipc_send(sub->server_ref, 1, &msg_sect); |
b97bf3fd PL |
114 | } |
115 | ||
116 | /** | |
4323add6 | 117 | * tipc_subscr_overlap - test for subscription overlap with the given values |
b97bf3fd PL |
118 | * |
119 | * Returns 1 if there is overlap, otherwise 0. | |
120 | */ | |
121 | ||
c4307285 YH |
122 | int tipc_subscr_overlap(struct subscription *sub, |
123 | u32 found_lower, | |
4323add6 | 124 | u32 found_upper) |
b97bf3fd PL |
125 | |
126 | { | |
127 | if (found_lower < sub->seq.lower) | |
128 | found_lower = sub->seq.lower; | |
129 | if (found_upper > sub->seq.upper) | |
130 | found_upper = sub->seq.upper; | |
131 | if (found_lower > found_upper) | |
132 | return 0; | |
133 | return 1; | |
134 | } | |
135 | ||
136 | /** | |
4323add6 | 137 | * tipc_subscr_report_overlap - issue event if there is subscription overlap |
c4307285 | 138 | * |
b97bf3fd PL |
139 | * Protected by nameseq.lock in name_table.c |
140 | */ | |
141 | ||
c4307285 YH |
142 | void tipc_subscr_report_overlap(struct subscription *sub, |
143 | u32 found_lower, | |
4323add6 | 144 | u32 found_upper, |
c4307285 YH |
145 | u32 event, |
146 | u32 port_ref, | |
4323add6 PL |
147 | u32 node, |
148 | int must) | |
b97bf3fd | 149 | { |
4323add6 | 150 | if (!tipc_subscr_overlap(sub, found_lower, found_upper)) |
b97bf3fd | 151 | return; |
eb409460 | 152 | if (!must && !(sub->filter & TIPC_SUB_PORTS)) |
b97bf3fd | 153 | return; |
e15f8804 AS |
154 | |
155 | sub->event_cb(sub, found_lower, found_upper, event, port_ref, node); | |
b97bf3fd PL |
156 | } |
157 | ||
158 | /** | |
159 | * subscr_timeout - subscription timeout has occurred | |
160 | */ | |
161 | ||
162 | static void subscr_timeout(struct subscription *sub) | |
163 | { | |
28353e7f | 164 | struct port *server_port; |
b97bf3fd | 165 | |
28353e7f | 166 | /* Validate server port reference (in case subscriber is terminating) */ |
b97bf3fd | 167 | |
28353e7f AS |
168 | server_port = tipc_port_lock(sub->server_ref); |
169 | if (server_port == NULL) | |
b97bf3fd PL |
170 | return; |
171 | ||
eb409460 LC |
172 | /* Validate timeout (in case subscription is being cancelled) */ |
173 | ||
174 | if (sub->timeout == TIPC_WAIT_FOREVER) { | |
28353e7f | 175 | tipc_port_unlock(server_port); |
eb409460 LC |
176 | return; |
177 | } | |
178 | ||
b97bf3fd PL |
179 | /* Unlink subscription from name table */ |
180 | ||
4323add6 | 181 | tipc_nametbl_unsubscribe(sub); |
b97bf3fd | 182 | |
28353e7f | 183 | /* Unlink subscription from subscriber */ |
b97bf3fd | 184 | |
b97bf3fd PL |
185 | list_del(&sub->subscription_list); |
186 | ||
28353e7f AS |
187 | /* Release subscriber's server port */ |
188 | ||
189 | tipc_port_unlock(server_port); | |
190 | ||
191 | /* Notify subscriber of timeout */ | |
192 | ||
193 | subscr_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper, | |
194 | TIPC_SUBSCR_TIMEOUT, 0, 0); | |
195 | ||
b97bf3fd PL |
196 | /* Now destroy subscription */ |
197 | ||
b97bf3fd PL |
198 | k_term_timer(&sub->timer); |
199 | kfree(sub); | |
200 | atomic_dec(&topsrv.subscription_count); | |
201 | } | |
202 | ||
eb409460 LC |
203 | /** |
204 | * subscr_del - delete a subscription within a subscription list | |
205 | * | |
28353e7f | 206 | * Called with subscriber port locked. |
eb409460 LC |
207 | */ |
208 | ||
209 | static void subscr_del(struct subscription *sub) | |
210 | { | |
211 | tipc_nametbl_unsubscribe(sub); | |
212 | list_del(&sub->subscription_list); | |
213 | kfree(sub); | |
214 | atomic_dec(&topsrv.subscription_count); | |
215 | } | |
216 | ||
b97bf3fd PL |
217 | /** |
218 | * subscr_terminate - terminate communication with a subscriber | |
c4307285 | 219 | * |
28353e7f | 220 | * Called with subscriber port locked. Routine must temporarily release lock |
c4307285 | 221 | * to enable subscription timeout routine(s) to finish without deadlocking; |
b97bf3fd | 222 | * the lock is then reclaimed to allow caller to release it upon return. |
c4307285 | 223 | * (This should work even in the unlikely event some other thread creates |
b97bf3fd PL |
224 | * a new object reference in the interim that uses this lock; this routine will |
225 | * simply wait for it to be released, then claim it.) | |
226 | */ | |
227 | ||
228 | static void subscr_terminate(struct subscriber *subscriber) | |
229 | { | |
28353e7f | 230 | u32 port_ref; |
b97bf3fd PL |
231 | struct subscription *sub; |
232 | struct subscription *sub_temp; | |
233 | ||
234 | /* Invalidate subscriber reference */ | |
235 | ||
28353e7f AS |
236 | port_ref = subscriber->port_ref; |
237 | subscriber->port_ref = 0; | |
b97bf3fd PL |
238 | spin_unlock_bh(subscriber->lock); |
239 | ||
28353e7f AS |
240 | /* Sever connection to subscriber */ |
241 | ||
242 | tipc_shutdown(port_ref); | |
243 | tipc_deleteport(port_ref); | |
244 | ||
b97bf3fd | 245 | /* Destroy any existing subscriptions for subscriber */ |
c4307285 | 246 | |
b97bf3fd PL |
247 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, |
248 | subscription_list) { | |
249 | if (sub->timeout != TIPC_WAIT_FOREVER) { | |
250 | k_cancel_timer(&sub->timer); | |
251 | k_term_timer(&sub->timer); | |
252 | } | |
eb409460 | 253 | dbg("Term: Removing sub %u,%u,%u from subscriber %x list\n", |
b97bf3fd | 254 | sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber); |
eb409460 | 255 | subscr_del(sub); |
b97bf3fd PL |
256 | } |
257 | ||
b97bf3fd PL |
258 | /* Remove subscriber from topology server's subscriber list */ |
259 | ||
260 | spin_lock_bh(&topsrv.lock); | |
261 | list_del(&subscriber->subscriber_list); | |
262 | spin_unlock_bh(&topsrv.lock); | |
263 | ||
28353e7f | 264 | /* Reclaim subscriber lock */ |
b97bf3fd PL |
265 | |
266 | spin_lock_bh(subscriber->lock); | |
28353e7f AS |
267 | |
268 | /* Now destroy subscriber */ | |
269 | ||
b97bf3fd PL |
270 | kfree(subscriber); |
271 | } | |
272 | ||
eb409460 LC |
273 | /** |
274 | * subscr_cancel - handle subscription cancellation request | |
275 | * | |
28353e7f | 276 | * Called with subscriber port locked. Routine must temporarily release lock |
eb409460 LC |
277 | * to enable the subscription timeout routine to finish without deadlocking; |
278 | * the lock is then reclaimed to allow caller to release it upon return. | |
279 | * | |
280 | * Note that fields of 's' use subscriber's endianness! | |
281 | */ | |
282 | ||
283 | static void subscr_cancel(struct tipc_subscr *s, | |
284 | struct subscriber *subscriber) | |
285 | { | |
286 | struct subscription *sub; | |
287 | struct subscription *sub_temp; | |
288 | int found = 0; | |
289 | ||
290 | /* Find first matching subscription, exit if not found */ | |
291 | ||
292 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, | |
293 | subscription_list) { | |
db5a753b NH |
294 | if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) { |
295 | found = 1; | |
296 | break; | |
297 | } | |
eb409460 LC |
298 | } |
299 | if (!found) | |
300 | return; | |
301 | ||
302 | /* Cancel subscription timer (if used), then delete subscription */ | |
303 | ||
304 | if (sub->timeout != TIPC_WAIT_FOREVER) { | |
305 | sub->timeout = TIPC_WAIT_FOREVER; | |
306 | spin_unlock_bh(subscriber->lock); | |
307 | k_cancel_timer(&sub->timer); | |
308 | k_term_timer(&sub->timer); | |
309 | spin_lock_bh(subscriber->lock); | |
310 | } | |
8c974438 | 311 | dbg("Cancel: removing sub %u,%u,%u from subscriber %x list\n", |
eb409460 LC |
312 | sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber); |
313 | subscr_del(sub); | |
314 | } | |
315 | ||
b97bf3fd PL |
316 | /** |
317 | * subscr_subscribe - create subscription for subscriber | |
c4307285 | 318 | * |
28353e7f | 319 | * Called with subscriber port locked. |
b97bf3fd PL |
320 | */ |
321 | ||
28353e7f AS |
322 | static struct subscription *subscr_subscribe(struct tipc_subscr *s, |
323 | struct subscriber *subscriber) | |
b97bf3fd PL |
324 | { |
325 | struct subscription *sub; | |
db5a753b NH |
326 | int swap; |
327 | ||
328 | /* Determine subscriber's endianness */ | |
329 | ||
330 | swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE)); | |
eb409460 LC |
331 | |
332 | /* Detect & process a subscription cancellation request */ | |
333 | ||
db5a753b NH |
334 | if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { |
335 | s->filter &= ~htohl(TIPC_SUB_CANCEL, swap); | |
eb409460 | 336 | subscr_cancel(s, subscriber); |
28353e7f | 337 | return NULL; |
eb409460 LC |
338 | } |
339 | ||
b97bf3fd PL |
340 | /* Refuse subscription if global limit exceeded */ |
341 | ||
342 | if (atomic_read(&topsrv.subscription_count) >= tipc_max_subscriptions) { | |
a10bd924 AS |
343 | warn("Subscription rejected, subscription limit reached (%u)\n", |
344 | tipc_max_subscriptions); | |
b97bf3fd | 345 | subscr_terminate(subscriber); |
28353e7f | 346 | return NULL; |
b97bf3fd PL |
347 | } |
348 | ||
349 | /* Allocate subscription object */ | |
350 | ||
28353e7f | 351 | sub = kmalloc(sizeof(*sub), GFP_ATOMIC); |
a10bd924 AS |
352 | if (!sub) { |
353 | warn("Subscription rejected, no memory\n"); | |
b97bf3fd | 354 | subscr_terminate(subscriber); |
28353e7f | 355 | return NULL; |
b97bf3fd PL |
356 | } |
357 | ||
b97bf3fd PL |
358 | /* Initialize subscription object */ |
359 | ||
db5a753b NH |
360 | sub->seq.type = htohl(s->seq.type, swap); |
361 | sub->seq.lower = htohl(s->seq.lower, swap); | |
362 | sub->seq.upper = htohl(s->seq.upper, swap); | |
363 | sub->timeout = htohl(s->timeout, swap); | |
364 | sub->filter = htohl(s->filter, swap); | |
8c974438 NH |
365 | if ((!(sub->filter & TIPC_SUB_PORTS) == |
366 | !(sub->filter & TIPC_SUB_SERVICE)) || | |
f64f9e71 | 367 | (sub->seq.lower > sub->seq.upper)) { |
a10bd924 | 368 | warn("Subscription rejected, illegal request\n"); |
b97bf3fd PL |
369 | kfree(sub); |
370 | subscr_terminate(subscriber); | |
28353e7f | 371 | return NULL; |
b97bf3fd | 372 | } |
e15f8804 | 373 | sub->event_cb = subscr_send_event; |
b97bf3fd PL |
374 | INIT_LIST_HEAD(&sub->nameseq_list); |
375 | list_add(&sub->subscription_list, &subscriber->subscription_list); | |
28353e7f | 376 | sub->server_ref = subscriber->port_ref; |
db5a753b | 377 | sub->swap = swap; |
28353e7f | 378 | memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); |
b97bf3fd PL |
379 | atomic_inc(&topsrv.subscription_count); |
380 | if (sub->timeout != TIPC_WAIT_FOREVER) { | |
381 | k_init_timer(&sub->timer, | |
382 | (Handler)subscr_timeout, (unsigned long)sub); | |
383 | k_start_timer(&sub->timer, sub->timeout); | |
384 | } | |
28353e7f AS |
385 | |
386 | return sub; | |
b97bf3fd PL |
387 | } |
388 | ||
389 | /** | |
390 | * subscr_conn_shutdown_event - handle termination request from subscriber | |
28353e7f AS |
391 | * |
392 | * Called with subscriber's server port unlocked. | |
b97bf3fd PL |
393 | */ |
394 | ||
395 | static void subscr_conn_shutdown_event(void *usr_handle, | |
28353e7f | 396 | u32 port_ref, |
b97bf3fd PL |
397 | struct sk_buff **buf, |
398 | unsigned char const *data, | |
399 | unsigned int size, | |
400 | int reason) | |
401 | { | |
28353e7f | 402 | struct subscriber *subscriber = usr_handle; |
b97bf3fd PL |
403 | spinlock_t *subscriber_lock; |
404 | ||
28353e7f | 405 | if (tipc_port_lock(port_ref) == NULL) |
b97bf3fd PL |
406 | return; |
407 | ||
408 | subscriber_lock = subscriber->lock; | |
409 | subscr_terminate(subscriber); | |
410 | spin_unlock_bh(subscriber_lock); | |
411 | } | |
412 | ||
413 | /** | |
414 | * subscr_conn_msg_event - handle new subscription request from subscriber | |
28353e7f AS |
415 | * |
416 | * Called with subscriber's server port unlocked. | |
b97bf3fd PL |
417 | */ |
418 | ||
419 | static void subscr_conn_msg_event(void *usr_handle, | |
420 | u32 port_ref, | |
421 | struct sk_buff **buf, | |
422 | const unchar *data, | |
423 | u32 size) | |
424 | { | |
28353e7f | 425 | struct subscriber *subscriber = usr_handle; |
b97bf3fd | 426 | spinlock_t *subscriber_lock; |
28353e7f AS |
427 | struct subscription *sub; |
428 | ||
429 | /* | |
430 | * Lock subscriber's server port (& make a local copy of lock pointer, | |
431 | * in case subscriber is deleted while processing subscription request) | |
432 | */ | |
b97bf3fd | 433 | |
28353e7f | 434 | if (tipc_port_lock(port_ref) == NULL) |
b97bf3fd PL |
435 | return; |
436 | ||
437 | subscriber_lock = subscriber->lock; | |
c4307285 | 438 | |
28353e7f AS |
439 | if (size != sizeof(struct tipc_subscr)) { |
440 | subscr_terminate(subscriber); | |
441 | spin_unlock_bh(subscriber_lock); | |
442 | } else { | |
443 | sub = subscr_subscribe((struct tipc_subscr *)data, subscriber); | |
444 | spin_unlock_bh(subscriber_lock); | |
445 | if (sub != NULL) { | |
446 | ||
447 | /* | |
448 | * We must release the server port lock before adding a | |
449 | * subscription to the name table since TIPC needs to be | |
450 | * able to (re)acquire the port lock if an event message | |
451 | * issued by the subscription process is rejected and | |
452 | * returned. The subscription cannot be deleted while | |
453 | * it is being added to the name table because: | |
454 | * a) the single-threading of the native API port code | |
455 | * ensures the subscription cannot be cancelled and | |
456 | * the subscriber connection cannot be broken, and | |
457 | * b) the name table lock ensures the subscription | |
458 | * timeout code cannot delete the subscription, | |
459 | * so the subscription object is still protected. | |
460 | */ | |
461 | ||
462 | tipc_nametbl_subscribe(sub); | |
463 | } | |
464 | } | |
b97bf3fd PL |
465 | } |
466 | ||
467 | /** | |
468 | * subscr_named_msg_event - handle request to establish a new subscriber | |
469 | */ | |
470 | ||
471 | static void subscr_named_msg_event(void *usr_handle, | |
472 | u32 port_ref, | |
473 | struct sk_buff **buf, | |
474 | const unchar *data, | |
475 | u32 size, | |
c4307285 | 476 | u32 importance, |
b97bf3fd PL |
477 | struct tipc_portid const *orig, |
478 | struct tipc_name_seq const *dest) | |
479 | { | |
28353e7f | 480 | static struct iovec msg_sect = {NULL, 0}; |
b97bf3fd | 481 | |
28353e7f AS |
482 | struct subscriber *subscriber; |
483 | u32 server_port_ref; | |
b97bf3fd PL |
484 | |
485 | /* Create subscriber object */ | |
486 | ||
0da974f4 | 487 | subscriber = kzalloc(sizeof(struct subscriber), GFP_ATOMIC); |
b97bf3fd | 488 | if (subscriber == NULL) { |
a10bd924 | 489 | warn("Subscriber rejected, no memory\n"); |
b97bf3fd PL |
490 | return; |
491 | } | |
b97bf3fd PL |
492 | INIT_LIST_HEAD(&subscriber->subscription_list); |
493 | INIT_LIST_HEAD(&subscriber->subscriber_list); | |
b97bf3fd | 494 | |
28353e7f | 495 | /* Create server port & establish connection to subscriber */ |
b97bf3fd PL |
496 | |
497 | tipc_createport(topsrv.user_ref, | |
28353e7f | 498 | subscriber, |
b97bf3fd | 499 | importance, |
1fc54d8f SR |
500 | NULL, |
501 | NULL, | |
b97bf3fd | 502 | subscr_conn_shutdown_event, |
1fc54d8f SR |
503 | NULL, |
504 | NULL, | |
b97bf3fd | 505 | subscr_conn_msg_event, |
1fc54d8f | 506 | NULL, |
b97bf3fd PL |
507 | &subscriber->port_ref); |
508 | if (subscriber->port_ref == 0) { | |
a10bd924 | 509 | warn("Subscriber rejected, unable to create port\n"); |
b97bf3fd PL |
510 | kfree(subscriber); |
511 | return; | |
512 | } | |
513 | tipc_connect2port(subscriber->port_ref, orig); | |
514 | ||
28353e7f AS |
515 | /* Lock server port (& save lock address for future use) */ |
516 | ||
517 | subscriber->lock = tipc_port_lock(subscriber->port_ref)->publ.lock; | |
b97bf3fd PL |
518 | |
519 | /* Add subscriber to topology server's subscriber list */ | |
520 | ||
b97bf3fd PL |
521 | spin_lock_bh(&topsrv.lock); |
522 | list_add(&subscriber->subscriber_list, &topsrv.subscriber_list); | |
523 | spin_unlock_bh(&topsrv.lock); | |
524 | ||
28353e7f | 525 | /* Unlock server port */ |
b97bf3fd | 526 | |
28353e7f AS |
527 | server_port_ref = subscriber->port_ref; |
528 | spin_unlock_bh(subscriber->lock); | |
b97bf3fd | 529 | |
28353e7f AS |
530 | /* Send an ACK- to complete connection handshaking */ |
531 | ||
532 | tipc_send(server_port_ref, 1, &msg_sect); | |
533 | ||
534 | /* Handle optional subscription request */ | |
535 | ||
536 | if (size != 0) { | |
537 | subscr_conn_msg_event(subscriber, server_port_ref, | |
538 | buf, data, size); | |
539 | } | |
b97bf3fd PL |
540 | } |
541 | ||
4323add6 | 542 | int tipc_subscr_start(void) |
b97bf3fd PL |
543 | { |
544 | struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV}; | |
545 | int res = -1; | |
546 | ||
547 | memset(&topsrv, 0, sizeof (topsrv)); | |
34af946a | 548 | spin_lock_init(&topsrv.lock); |
b97bf3fd PL |
549 | INIT_LIST_HEAD(&topsrv.subscriber_list); |
550 | ||
551 | spin_lock_bh(&topsrv.lock); | |
a5c2af99 | 552 | res = tipc_attach(&topsrv.user_ref); |
b97bf3fd PL |
553 | if (res) { |
554 | spin_unlock_bh(&topsrv.lock); | |
555 | return res; | |
556 | } | |
557 | ||
c4307285 YH |
558 | res = tipc_createport(topsrv.user_ref, |
559 | NULL, | |
560 | TIPC_CRITICAL_IMPORTANCE, | |
561 | NULL, | |
562 | NULL, | |
563 | NULL, | |
564 | NULL, | |
565 | subscr_named_msg_event, | |
566 | NULL, | |
567 | NULL, | |
568 | &topsrv.setup_port); | |
569 | if (res) | |
b97bf3fd PL |
570 | goto failed; |
571 | ||
c4307285 YH |
572 | res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq); |
573 | if (res) | |
b97bf3fd PL |
574 | goto failed; |
575 | ||
576 | spin_unlock_bh(&topsrv.lock); | |
577 | return 0; | |
578 | ||
579 | failed: | |
d0a14a9d | 580 | err("Failed to create subscription service\n"); |
b97bf3fd PL |
581 | tipc_detach(topsrv.user_ref); |
582 | topsrv.user_ref = 0; | |
583 | spin_unlock_bh(&topsrv.lock); | |
584 | return res; | |
585 | } | |
586 | ||
4323add6 | 587 | void tipc_subscr_stop(void) |
b97bf3fd PL |
588 | { |
589 | struct subscriber *subscriber; | |
590 | struct subscriber *subscriber_temp; | |
591 | spinlock_t *subscriber_lock; | |
592 | ||
593 | if (topsrv.user_ref) { | |
594 | tipc_deleteport(topsrv.setup_port); | |
c4307285 | 595 | list_for_each_entry_safe(subscriber, subscriber_temp, |
b97bf3fd PL |
596 | &topsrv.subscriber_list, |
597 | subscriber_list) { | |
b97bf3fd | 598 | subscriber_lock = subscriber->lock; |
28353e7f | 599 | spin_lock_bh(subscriber_lock); |
b97bf3fd PL |
600 | subscr_terminate(subscriber); |
601 | spin_unlock_bh(subscriber_lock); | |
602 | } | |
603 | tipc_detach(topsrv.user_ref); | |
604 | topsrv.user_ref = 0; | |
605 | } | |
606 | } |