aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/subscr.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-10-21 11:43:05 -0400
committerDavid S. Miller <davem@davemloft.net>2010-10-21 11:43:05 -0400
commit2198a10b501fd4443430cb17e065a9e859cc58c9 (patch)
tree87f3781d293da0f8f8f61615905eb7bf62b7c128 /net/tipc/subscr.c
parent9941fb62762253774cc6177d0b9172ece5133fe1 (diff)
parentdb5a753bf198ef7a50e17d2ff358adf37efe8648 (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Conflicts: net/core/dev.c
Diffstat (limited to 'net/tipc/subscr.c')
-rw-r--r--net/tipc/subscr.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 18813acc6bef..33313961d010 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -76,6 +76,19 @@ struct top_srv {
76static struct top_srv topsrv = { 0 }; 76static struct top_srv topsrv = { 0 };
77 77
78/** 78/**
79 * htohl - convert value to endianness used by destination
80 * @in: value to convert
81 * @swap: non-zero if endianness must be reversed
82 *
83 * Returns converted value
84 */
85
86static u32 htohl(u32 in, int swap)
87{
88 return swap ? swab32(in) : in;
89}
90
91/**
79 * subscr_send_event - send a message containing a tipc_event to the subscriber 92 * subscr_send_event - send a message containing a tipc_event to the subscriber
80 * 93 *
81 * Note: Must not hold subscriber's server port lock, since tipc_send() will 94 * Note: Must not hold subscriber's server port lock, since tipc_send() will
@@ -94,11 +107,11 @@ static void subscr_send_event(struct subscription *sub,
94 msg_sect.iov_base = (void *)&sub->evt; 107 msg_sect.iov_base = (void *)&sub->evt;
95 msg_sect.iov_len = sizeof(struct tipc_event); 108 msg_sect.iov_len = sizeof(struct tipc_event);
96 109
97 sub->evt.event = htonl(event); 110 sub->evt.event = htohl(event, sub->swap);
98 sub->evt.found_lower = htonl(found_lower); 111 sub->evt.found_lower = htohl(found_lower, sub->swap);
99 sub->evt.found_upper = htonl(found_upper); 112 sub->evt.found_upper = htohl(found_upper, sub->swap);
100 sub->evt.port.ref = htonl(port_ref); 113 sub->evt.port.ref = htohl(port_ref, sub->swap);
101 sub->evt.port.node = htonl(node); 114 sub->evt.port.node = htohl(node, sub->swap);
102 tipc_send(sub->server_ref, 1, &msg_sect); 115 tipc_send(sub->server_ref, 1, &msg_sect);
103} 116}
104 117
@@ -274,29 +287,16 @@ static void subscr_cancel(struct tipc_subscr *s,
274{ 287{
275 struct subscription *sub; 288 struct subscription *sub;
276 struct subscription *sub_temp; 289 struct subscription *sub_temp;
277 __u32 type, lower, upper, timeout, filter;
278 int found = 0; 290 int found = 0;
279 291
280 /* Find first matching subscription, exit if not found */ 292 /* Find first matching subscription, exit if not found */
281 293
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, 294 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
289 subscription_list) { 295 subscription_list) {
290 if ((type == sub->seq.type) && 296 if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
291 (lower == sub->seq.lower) && 297 found = 1;
292 (upper == sub->seq.upper) && 298 break;
293 (timeout == sub->timeout) && 299 }
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 } 300 }
301 if (!found) 301 if (!found)
302 return; 302 return;
@@ -310,7 +310,7 @@ static void subscr_cancel(struct tipc_subscr *s,
310 k_term_timer(&sub->timer); 310 k_term_timer(&sub->timer);
311 spin_lock_bh(subscriber->lock); 311 spin_lock_bh(subscriber->lock);
312 } 312 }
313 dbg("Cancel: removing sub %u,%u,%u from subscriber %p list\n", 313 dbg("Cancel: removing sub %u,%u,%u from subscriber %x list\n",
314 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber); 314 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
315 subscr_del(sub); 315 subscr_del(sub);
316} 316}
@@ -325,10 +325,16 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
325 struct subscriber *subscriber) 325 struct subscriber *subscriber)
326{ 326{
327 struct subscription *sub; 327 struct subscription *sub;
328 int swap;
329
330 /* Determine subscriber's endianness */
331
332 swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE));
328 333
329 /* Detect & process a subscription cancellation request */ 334 /* Detect & process a subscription cancellation request */
330 335
331 if (ntohl(s->filter) & TIPC_SUB_CANCEL) { 336 if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
337 s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
332 subscr_cancel(s, subscriber); 338 subscr_cancel(s, subscriber);
333 return NULL; 339 return NULL;
334 } 340 }
@@ -353,12 +359,13 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
353 359
354 /* Initialize subscription object */ 360 /* Initialize subscription object */
355 361
356 sub->seq.type = ntohl(s->seq.type); 362 sub->seq.type = htohl(s->seq.type, swap);
357 sub->seq.lower = ntohl(s->seq.lower); 363 sub->seq.lower = htohl(s->seq.lower, swap);
358 sub->seq.upper = ntohl(s->seq.upper); 364 sub->seq.upper = htohl(s->seq.upper, swap);
359 sub->timeout = ntohl(s->timeout); 365 sub->timeout = htohl(s->timeout, swap);
360 sub->filter = ntohl(s->filter); 366 sub->filter = htohl(s->filter, swap);
361 if ((sub->filter && (sub->filter != TIPC_SUB_PORTS)) || 367 if ((!(sub->filter & TIPC_SUB_PORTS) ==
368 !(sub->filter & TIPC_SUB_SERVICE)) ||
362 (sub->seq.lower > sub->seq.upper)) { 369 (sub->seq.lower > sub->seq.upper)) {
363 warn("Subscription rejected, illegal request\n"); 370 warn("Subscription rejected, illegal request\n");
364 kfree(sub); 371 kfree(sub);
@@ -369,6 +376,7 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
369 INIT_LIST_HEAD(&sub->nameseq_list); 376 INIT_LIST_HEAD(&sub->nameseq_list);
370 list_add(&sub->subscription_list, &subscriber->subscription_list); 377 list_add(&sub->subscription_list, &subscriber->subscription_list);
371 sub->server_ref = subscriber->port_ref; 378 sub->server_ref = subscriber->port_ref;
379 sub->swap = swap;
372 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); 380 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
373 atomic_inc(&topsrv.subscription_count); 381 atomic_inc(&topsrv.subscription_count);
374 if (sub->timeout != TIPC_WAIT_FOREVER) { 382 if (sub->timeout != TIPC_WAIT_FOREVER) {