aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/subscr.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/subscr.c')
-rw-r--r--net/tipc/subscr.c128
1 files changed, 54 insertions, 74 deletions
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index ab6eab4c45e2..6cf726863485 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -2,7 +2,7 @@
2 * net/tipc/subscr.c: TIPC network topology service 2 * net/tipc/subscr.c: TIPC network topology service
3 * 3 *
4 * Copyright (c) 2000-2006, Ericsson AB 4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005-2007, Wind River Systems 5 * Copyright (c) 2005-2007, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
@@ -35,10 +35,8 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "name_table.h" 38#include "name_table.h"
40#include "port.h" 39#include "port.h"
41#include "ref.h"
42#include "subscr.h" 40#include "subscr.h"
43 41
44/** 42/**
@@ -66,14 +64,26 @@ struct subscriber {
66 */ 64 */
67 65
68struct top_srv { 66struct top_srv {
69 u32 user_ref;
70 u32 setup_port; 67 u32 setup_port;
71 atomic_t subscription_count; 68 atomic_t subscription_count;
72 struct list_head subscriber_list; 69 struct list_head subscriber_list;
73 spinlock_t lock; 70 spinlock_t lock;
74}; 71};
75 72
76static struct top_srv topsrv = { 0 }; 73static struct top_srv topsrv;
74
75/**
76 * htohl - convert value to endianness used by destination
77 * @in: value to convert
78 * @swap: non-zero if endianness must be reversed
79 *
80 * Returns converted value
81 */
82
83static u32 htohl(u32 in, int swap)
84{
85 return swap ? swab32(in) : in;
86}
77 87
78/** 88/**
79 * subscr_send_event - send a message containing a tipc_event to the subscriber 89 * subscr_send_event - send a message containing a tipc_event to the subscriber
@@ -94,12 +104,12 @@ static void subscr_send_event(struct subscription *sub,
94 msg_sect.iov_base = (void *)&sub->evt; 104 msg_sect.iov_base = (void *)&sub->evt;
95 msg_sect.iov_len = sizeof(struct tipc_event); 105 msg_sect.iov_len = sizeof(struct tipc_event);
96 106
97 sub->evt.event = htonl(event); 107 sub->evt.event = htohl(event, sub->swap);
98 sub->evt.found_lower = htonl(found_lower); 108 sub->evt.found_lower = htohl(found_lower, sub->swap);
99 sub->evt.found_upper = htonl(found_upper); 109 sub->evt.found_upper = htohl(found_upper, sub->swap);
100 sub->evt.port.ref = htonl(port_ref); 110 sub->evt.port.ref = htohl(port_ref, sub->swap);
101 sub->evt.port.node = htonl(node); 111 sub->evt.port.node = htohl(node, sub->swap);
102 tipc_send(sub->server_ref, 1, &msg_sect); 112 tipc_send(sub->server_ref, 1, &msg_sect, msg_sect.iov_len);
103} 113}
104 114
105/** 115/**
@@ -150,7 +160,7 @@ void tipc_subscr_report_overlap(struct subscription *sub,
150 160
151static void subscr_timeout(struct subscription *sub) 161static void subscr_timeout(struct subscription *sub)
152{ 162{
153 struct port *server_port; 163 struct tipc_port *server_port;
154 164
155 /* Validate server port reference (in case subscriber is terminating) */ 165 /* Validate server port reference (in case subscriber is terminating) */
156 166
@@ -239,8 +249,6 @@ static void subscr_terminate(struct subscriber *subscriber)
239 k_cancel_timer(&sub->timer); 249 k_cancel_timer(&sub->timer);
240 k_term_timer(&sub->timer); 250 k_term_timer(&sub->timer);
241 } 251 }
242 dbg("Term: Removing sub %u,%u,%u from subscriber %x list\n",
243 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
244 subscr_del(sub); 252 subscr_del(sub);
245 } 253 }
246 254
@@ -274,29 +282,16 @@ static void subscr_cancel(struct tipc_subscr *s,
274{ 282{
275 struct subscription *sub; 283 struct subscription *sub;
276 struct subscription *sub_temp; 284 struct subscription *sub_temp;
277 __u32 type, lower, upper, timeout, filter;
278 int found = 0; 285 int found = 0;
279 286
280 /* Find first matching subscription, exit if not found */ 287 /* Find first matching subscription, exit if not found */
281 288
282 type = ntohl(s->seq.type);
283 lower = ntohl(s->seq.lower);
284 upper = ntohl(s->seq.upper);
285 timeout = ntohl(s->timeout);
286 filter = ntohl(s->filter) & ~TIPC_SUB_CANCEL;
287
288 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, 289 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
289 subscription_list) { 290 subscription_list) {
290 if ((type == sub->seq.type) && 291 if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
291 (lower == sub->seq.lower) && 292 found = 1;
292 (upper == sub->seq.upper) && 293 break;
293 (timeout == sub->timeout) && 294 }
294 (filter == sub->filter) &&
295 !memcmp(s->usr_handle,sub->evt.s.usr_handle,
296 sizeof(s->usr_handle)) ){
297 found = 1;
298 break;
299 }
300 } 295 }
301 if (!found) 296 if (!found)
302 return; 297 return;
@@ -310,8 +305,6 @@ static void subscr_cancel(struct tipc_subscr *s,
310 k_term_timer(&sub->timer); 305 k_term_timer(&sub->timer);
311 spin_lock_bh(subscriber->lock); 306 spin_lock_bh(subscriber->lock);
312 } 307 }
313 dbg("Cancel: removing sub %u,%u,%u from subscriber %p list\n",
314 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
315 subscr_del(sub); 308 subscr_del(sub);
316} 309}
317 310
@@ -325,10 +318,16 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
325 struct subscriber *subscriber) 318 struct subscriber *subscriber)
326{ 319{
327 struct subscription *sub; 320 struct subscription *sub;
321 int swap;
322
323 /* Determine subscriber's endianness */
324
325 swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE));
328 326
329 /* Detect & process a subscription cancellation request */ 327 /* Detect & process a subscription cancellation request */
330 328
331 if (ntohl(s->filter) & TIPC_SUB_CANCEL) { 329 if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
330 s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
332 subscr_cancel(s, subscriber); 331 subscr_cancel(s, subscriber);
333 return NULL; 332 return NULL;
334 } 333 }
@@ -353,12 +352,13 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
353 352
354 /* Initialize subscription object */ 353 /* Initialize subscription object */
355 354
356 sub->seq.type = ntohl(s->seq.type); 355 sub->seq.type = htohl(s->seq.type, swap);
357 sub->seq.lower = ntohl(s->seq.lower); 356 sub->seq.lower = htohl(s->seq.lower, swap);
358 sub->seq.upper = ntohl(s->seq.upper); 357 sub->seq.upper = htohl(s->seq.upper, swap);
359 sub->timeout = ntohl(s->timeout); 358 sub->timeout = htohl(s->timeout, swap);
360 sub->filter = ntohl(s->filter); 359 sub->filter = htohl(s->filter, swap);
361 if ((sub->filter && (sub->filter != TIPC_SUB_PORTS)) || 360 if ((!(sub->filter & TIPC_SUB_PORTS) ==
361 !(sub->filter & TIPC_SUB_SERVICE)) ||
362 (sub->seq.lower > sub->seq.upper)) { 362 (sub->seq.lower > sub->seq.upper)) {
363 warn("Subscription rejected, illegal request\n"); 363 warn("Subscription rejected, illegal request\n");
364 kfree(sub); 364 kfree(sub);
@@ -369,6 +369,7 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
369 INIT_LIST_HEAD(&sub->nameseq_list); 369 INIT_LIST_HEAD(&sub->nameseq_list);
370 list_add(&sub->subscription_list, &subscriber->subscription_list); 370 list_add(&sub->subscription_list, &subscriber->subscription_list);
371 sub->server_ref = subscriber->port_ref; 371 sub->server_ref = subscriber->port_ref;
372 sub->swap = swap;
372 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); 373 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
373 atomic_inc(&topsrv.subscription_count); 374 atomic_inc(&topsrv.subscription_count);
374 if (sub->timeout != TIPC_WAIT_FOREVER) { 375 if (sub->timeout != TIPC_WAIT_FOREVER) {
@@ -471,8 +472,6 @@ static void subscr_named_msg_event(void *usr_handle,
471 struct tipc_portid const *orig, 472 struct tipc_portid const *orig,
472 struct tipc_name_seq const *dest) 473 struct tipc_name_seq const *dest)
473{ 474{
474 static struct iovec msg_sect = {NULL, 0};
475
476 struct subscriber *subscriber; 475 struct subscriber *subscriber;
477 u32 server_port_ref; 476 u32 server_port_ref;
478 477
@@ -488,8 +487,7 @@ static void subscr_named_msg_event(void *usr_handle,
488 487
489 /* Create server port & establish connection to subscriber */ 488 /* Create server port & establish connection to subscriber */
490 489
491 tipc_createport(topsrv.user_ref, 490 tipc_createport(subscriber,
492 subscriber,
493 importance, 491 importance,
494 NULL, 492 NULL,
495 NULL, 493 NULL,
@@ -508,7 +506,7 @@ static void subscr_named_msg_event(void *usr_handle,
508 506
509 /* Lock server port (& save lock address for future use) */ 507 /* Lock server port (& save lock address for future use) */
510 508
511 subscriber->lock = tipc_port_lock(subscriber->port_ref)->publ.lock; 509 subscriber->lock = tipc_port_lock(subscriber->port_ref)->lock;
512 510
513 /* Add subscriber to topology server's subscriber list */ 511 /* Add subscriber to topology server's subscriber list */
514 512
@@ -523,7 +521,7 @@ static void subscr_named_msg_event(void *usr_handle,
523 521
524 /* Send an ACK- to complete connection handshaking */ 522 /* Send an ACK- to complete connection handshaking */
525 523
526 tipc_send(server_port_ref, 1, &msg_sect); 524 tipc_send(server_port_ref, 0, NULL, 0);
527 525
528 /* Handle optional subscription request */ 526 /* Handle optional subscription request */
529 527
@@ -536,21 +534,13 @@ static void subscr_named_msg_event(void *usr_handle,
536int tipc_subscr_start(void) 534int tipc_subscr_start(void)
537{ 535{
538 struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV}; 536 struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV};
539 int res = -1; 537 int res;
540 538
541 memset(&topsrv, 0, sizeof (topsrv)); 539 memset(&topsrv, 0, sizeof(topsrv));
542 spin_lock_init(&topsrv.lock); 540 spin_lock_init(&topsrv.lock);
543 INIT_LIST_HEAD(&topsrv.subscriber_list); 541 INIT_LIST_HEAD(&topsrv.subscriber_list);
544 542
545 spin_lock_bh(&topsrv.lock); 543 res = tipc_createport(NULL,
546 res = tipc_attach(&topsrv.user_ref, NULL, NULL);
547 if (res) {
548 spin_unlock_bh(&topsrv.lock);
549 return res;
550 }
551
552 res = tipc_createport(topsrv.user_ref,
553 NULL,
554 TIPC_CRITICAL_IMPORTANCE, 544 TIPC_CRITICAL_IMPORTANCE,
555 NULL, 545 NULL,
556 NULL, 546 NULL,
@@ -564,17 +554,16 @@ int tipc_subscr_start(void)
564 goto failed; 554 goto failed;
565 555
566 res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq); 556 res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq);
567 if (res) 557 if (res) {
558 tipc_deleteport(topsrv.setup_port);
559 topsrv.setup_port = 0;
568 goto failed; 560 goto failed;
561 }
569 562
570 spin_unlock_bh(&topsrv.lock);
571 return 0; 563 return 0;
572 564
573failed: 565failed:
574 err("Failed to create subscription service\n"); 566 err("Failed to create subscription service\n");
575 tipc_detach(topsrv.user_ref);
576 topsrv.user_ref = 0;
577 spin_unlock_bh(&topsrv.lock);
578 return res; 567 return res;
579} 568}
580 569
@@ -584,8 +573,10 @@ void tipc_subscr_stop(void)
584 struct subscriber *subscriber_temp; 573 struct subscriber *subscriber_temp;
585 spinlock_t *subscriber_lock; 574 spinlock_t *subscriber_lock;
586 575
587 if (topsrv.user_ref) { 576 if (topsrv.setup_port) {
588 tipc_deleteport(topsrv.setup_port); 577 tipc_deleteport(topsrv.setup_port);
578 topsrv.setup_port = 0;
579
589 list_for_each_entry_safe(subscriber, subscriber_temp, 580 list_for_each_entry_safe(subscriber, subscriber_temp,
590 &topsrv.subscriber_list, 581 &topsrv.subscriber_list,
591 subscriber_list) { 582 subscriber_list) {
@@ -594,16 +585,5 @@ void tipc_subscr_stop(void)
594 subscr_terminate(subscriber); 585 subscr_terminate(subscriber);
595 spin_unlock_bh(subscriber_lock); 586 spin_unlock_bh(subscriber_lock);
596 } 587 }
597 tipc_detach(topsrv.user_ref);
598 topsrv.user_ref = 0;
599 } 588 }
600} 589}
601
602
603int tipc_ispublished(struct tipc_name const *name)
604{
605 u32 domain = 0;
606
607 return(tipc_nametbl_translate(name->type, name->instance,&domain) != 0);
608}
609