diff options
| -rw-r--r-- | net/tipc/subscr.c | 57 | ||||
| -rw-r--r-- | net/tipc/subscr.h | 2 |
2 files changed, 37 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) { |
diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h index c20f496d95b2..45d89bf4d202 100644 --- a/net/tipc/subscr.h +++ b/net/tipc/subscr.h | |||
| @@ -53,6 +53,7 @@ typedef void (*tipc_subscr_event) (struct subscription *sub, | |||
| 53 | * @nameseq_list: adjacent subscriptions in name sequence's subscription list | 53 | * @nameseq_list: adjacent subscriptions in name sequence's subscription list |
| 54 | * @subscription_list: adjacent subscriptions in subscriber's subscription list | 54 | * @subscription_list: adjacent subscriptions in subscriber's subscription list |
| 55 | * @server_ref: object reference of server port associated with subscription | 55 | * @server_ref: object reference of server port associated with subscription |
| 56 | * @swap: indicates if subscriber uses opposite endianness in its messages | ||
| 56 | * @evt: template for events generated by subscription | 57 | * @evt: template for events generated by subscription |
| 57 | */ | 58 | */ |
| 58 | 59 | ||
| @@ -65,6 +66,7 @@ struct subscription { | |||
| 65 | struct list_head nameseq_list; | 66 | struct list_head nameseq_list; |
| 66 | struct list_head subscription_list; | 67 | struct list_head subscription_list; |
| 67 | u32 server_ref; | 68 | u32 server_ref; |
| 69 | int swap; | ||
| 68 | struct tipc_event evt; | 70 | struct tipc_event evt; |
| 69 | }; | 71 | }; |
| 70 | 72 | ||
