Skip to content

Commit

Permalink
TIPC: Updated topology subscription protocol according to latest spec
Browse files Browse the repository at this point in the history
This patch makes it explicit in the API that all fields in subscriptions and events exchanged with the Topology Server must be in
network byte order.
It also ensures that all fields of a subscription are compared when cancelling a subscription, in order to avoid inadvertent
cancelling of the wrong subscription.
Finally, the tipc module version is updated to 2.0.0, to reflect the API change.

Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jon Paul Maloy authored and David S. Miller committed Apr 7, 2010
1 parent 4595691 commit c6537d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
30 changes: 12 additions & 18 deletions include/linux/tipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,29 @@ static inline unsigned int tipc_node(__u32 addr)
* TIPC topology subscription service definitions
*/

#define TIPC_SUB_PORTS 0x01 /* filter for port availability */
#define TIPC_SUB_SERVICE 0x02 /* filter for service availability */
#define TIPC_SUB_CANCEL 0x04 /* cancel a subscription */
#if 0
/* The following filter options are not currently implemented */
#define TIPC_SUB_NO_BIND_EVTS 0x04 /* filter out "publish" events */
#define TIPC_SUB_NO_UNBIND_EVTS 0x08 /* filter out "withdraw" events */
#define TIPC_SUB_SINGLE_EVT 0x10 /* expire after first event */
#endif
#define TIPC_SUB_SERVICE 0x00 /* Filter for service availability */
#define TIPC_SUB_PORTS 0x01 /* Filter for port availability */
#define TIPC_SUB_CANCEL 0x04 /* Cancel a subscription */

#define TIPC_WAIT_FOREVER ~0 /* timeout for permanent subscription */

struct tipc_subscr {
struct tipc_name_seq seq; /* name sequence of interest */
__u32 timeout; /* subscription duration (in ms) */
__u32 filter; /* bitmask of filter options */
char usr_handle[8]; /* available for subscriber use */
struct tipc_name_seq seq; /* NBO. Name sequence of interest */
__u32 timeout; /* NBO. Subscription duration (in ms) */
__u32 filter; /* NBO. Bitmask of filter options */
char usr_handle[8]; /* Opaque. Available for subscriber use */
};

#define TIPC_PUBLISHED 1 /* publication event */
#define TIPC_WITHDRAWN 2 /* withdraw event */
#define TIPC_SUBSCR_TIMEOUT 3 /* subscription timeout event */

struct tipc_event {
__u32 event; /* event type */
__u32 found_lower; /* matching name seq instances */
__u32 found_upper; /* " " " " */
struct tipc_portid port; /* associated port */
struct tipc_subscr s; /* associated subscription */
__u32 event; /* NBO. Event type, as defined above */
__u32 found_lower; /* NBO. Matching name seq instances */
__u32 found_upper; /* " " " " " */
struct tipc_portid port; /* NBO. Associated port */
struct tipc_subscr s; /* Original, associated subscription */
};

/*
Expand Down
2 changes: 1 addition & 1 deletion net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "config.h"


#define TIPC_MOD_VER "1.6.4"
#define TIPC_MOD_VER "2.0.0"

#ifndef CONFIG_TIPC_ZONES
#define CONFIG_TIPC_ZONES 3
Expand Down
15 changes: 10 additions & 5 deletions net/tipc/subscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,26 @@ static void subscr_cancel(struct tipc_subscr *s,
{
struct subscription *sub;
struct subscription *sub_temp;
__u32 type, lower, upper;
__u32 type, lower, upper, timeout, filter;
int found = 0;

/* Find first matching subscription, exit if not found */

type = ntohl(s->seq.type);
lower = ntohl(s->seq.lower);
upper = ntohl(s->seq.upper);
timeout = ntohl(s->timeout);
filter = ntohl(s->filter) & ~TIPC_SUB_CANCEL;

list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
subscription_list) {
if ((type == sub->seq.type) &&
(lower == sub->seq.lower) &&
(upper == sub->seq.upper)) {
(upper == sub->seq.upper) &&
(timeout == sub->timeout) &&
(filter == sub->filter) &&
!memcmp(s->usr_handle,sub->evt.s.usr_handle,
sizeof(s->usr_handle)) ){
found = 1;
break;
}
Expand All @@ -304,7 +310,7 @@ static void subscr_cancel(struct tipc_subscr *s,
k_term_timer(&sub->timer);
spin_lock_bh(subscriber->lock);
}
dbg("Cancel: removing sub %u,%u,%u from subscriber %x list\n",
dbg("Cancel: removing sub %u,%u,%u from subscriber %p list\n",
sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
subscr_del(sub);
}
Expand Down Expand Up @@ -352,8 +358,7 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
sub->seq.upper = ntohl(s->seq.upper);
sub->timeout = ntohl(s->timeout);
sub->filter = ntohl(s->filter);
if ((!(sub->filter & TIPC_SUB_PORTS) ==
!(sub->filter & TIPC_SUB_SERVICE)) ||
if ((sub->filter && (sub->filter != TIPC_SUB_PORTS)) ||
(sub->seq.lower > sub->seq.upper)) {
warn("Subscription rejected, illegal request\n");
kfree(sub);
Expand Down

0 comments on commit c6537d6

Please sign in to comment.