diff options
Diffstat (limited to 'net/tipc/subscr.c')
-rw-r--r-- | net/tipc/subscr.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index ff123e56114a..ac91f0dfa144 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
@@ -76,6 +76,19 @@ struct top_srv { | |||
76 | static struct top_srv topsrv = { 0 }; | 76 | static 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 | |||
86 | static 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,23 +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; | ||
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 | |||
286 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, | 294 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, |
287 | subscription_list) { | 295 | subscription_list) { |
288 | if ((type == sub->seq.type) && | 296 | if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) { |
289 | (lower == sub->seq.lower) && | 297 | found = 1; |
290 | (upper == sub->seq.upper)) { | 298 | break; |
291 | found = 1; | 299 | } |
292 | break; | ||
293 | } | ||
294 | } | 300 | } |
295 | if (!found) | 301 | if (!found) |
296 | return; | 302 | return; |
@@ -319,10 +325,16 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s, | |||
319 | struct subscriber *subscriber) | 325 | struct subscriber *subscriber) |
320 | { | 326 | { |
321 | 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)); | ||
322 | 333 | ||
323 | /* Detect & process a subscription cancellation request */ | 334 | /* Detect & process a subscription cancellation request */ |
324 | 335 | ||
325 | if (ntohl(s->filter) & TIPC_SUB_CANCEL) { | 336 | if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { |
337 | s->filter &= ~htohl(TIPC_SUB_CANCEL, swap); | ||
326 | subscr_cancel(s, subscriber); | 338 | subscr_cancel(s, subscriber); |
327 | return NULL; | 339 | return NULL; |
328 | } | 340 | } |
@@ -347,11 +359,11 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s, | |||
347 | 359 | ||
348 | /* Initialize subscription object */ | 360 | /* Initialize subscription object */ |
349 | 361 | ||
350 | sub->seq.type = ntohl(s->seq.type); | 362 | sub->seq.type = htohl(s->seq.type, swap); |
351 | sub->seq.lower = ntohl(s->seq.lower); | 363 | sub->seq.lower = htohl(s->seq.lower, swap); |
352 | sub->seq.upper = ntohl(s->seq.upper); | 364 | sub->seq.upper = htohl(s->seq.upper, swap); |
353 | sub->timeout = ntohl(s->timeout); | 365 | sub->timeout = htohl(s->timeout, swap); |
354 | sub->filter = ntohl(s->filter); | 366 | sub->filter = htohl(s->filter, swap); |
355 | if ((!(sub->filter & TIPC_SUB_PORTS) == | 367 | if ((!(sub->filter & TIPC_SUB_PORTS) == |
356 | !(sub->filter & TIPC_SUB_SERVICE)) || | 368 | !(sub->filter & TIPC_SUB_SERVICE)) || |
357 | (sub->seq.lower > sub->seq.upper)) { | 369 | (sub->seq.lower > sub->seq.upper)) { |
@@ -364,6 +376,7 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s, | |||
364 | INIT_LIST_HEAD(&sub->nameseq_list); | 376 | INIT_LIST_HEAD(&sub->nameseq_list); |
365 | list_add(&sub->subscription_list, &subscriber->subscription_list); | 377 | list_add(&sub->subscription_list, &subscriber->subscription_list); |
366 | sub->server_ref = subscriber->port_ref; | 378 | sub->server_ref = subscriber->port_ref; |
379 | sub->swap = swap; | ||
367 | memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); | 380 | memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); |
368 | atomic_inc(&topsrv.subscription_count); | 381 | atomic_inc(&topsrv.subscription_count); |
369 | if (sub->timeout != TIPC_WAIT_FOREVER) { | 382 | if (sub->timeout != TIPC_WAIT_FOREVER) { |