summaryrefslogtreecommitdiffstats
path: root/net/tipc/subscr.h
diff options
context:
space:
mode:
authorJon Maloy <jon.maloy@ericsson.com>2018-02-15 04:40:46 -0500
committerDavid S. Miller <davem@davemloft.net>2018-02-16 15:26:33 -0500
commit8985ecc7c1e07c42acc1e44ac56fa224f8a5c62f (patch)
treeed564ee8b615b55e4569b38ea039e3eb89dccbe0 /net/tipc/subscr.h
parent414574a0af36d329f560f542e650cc4a81cc1d69 (diff)
tipc: simplify endianness handling in topology subscriber
Because of the requirement for total distribution transparency, users send subscriptions and receive topology events in their own host format. It is up to the topology server to determine this format and do the correct conversions to and from its own host format when needed. Until now, this has been handled in a rather non-transparent way inside the topology server and subscriber code, leading to unnecessary complexity when creating subscriptions and issuing events. We now improve this situation by adding two new macros, tipc_sub_read() and tipc_evt_write(). Both those functions calculate the need for conversion internally before performing their respective operations. Hence, all handling of such conversions become transparent to the rest of the code. Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/subscr.h')
-rw-r--r--net/tipc/subscr.h36
1 files changed, 27 insertions, 9 deletions
diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h
index 64ffd32d15e6..db80e41bba08 100644
--- a/net/tipc/subscr.h
+++ b/net/tipc/subscr.h
@@ -52,7 +52,6 @@ struct tipc_conn;
52 * @timer: timer governing subscription duration (optional) 52 * @timer: timer governing subscription duration (optional)
53 * @nameseq_list: adjacent subscriptions in name sequence's subscription list 53 * @nameseq_list: adjacent subscriptions in name sequence's subscription list
54 * @subscrp_list: adjacent subscriptions in subscriber's subscription list 54 * @subscrp_list: adjacent subscriptions in subscriber's subscription list
55 * @swap: indicates if subscriber uses opposite endianness in its messages
56 * @evt: template for events generated by subscription 55 * @evt: template for events generated by subscription
57 */ 56 */
58struct tipc_subscription { 57struct tipc_subscription {
@@ -63,28 +62,47 @@ struct tipc_subscription {
63 struct list_head subscrp_list; 62 struct list_head subscrp_list;
64 struct tipc_event evt; 63 struct tipc_event evt;
65 int conid; 64 int conid;
66 bool swap;
67 bool inactive; 65 bool inactive;
68 spinlock_t lock; /* serialize up/down and timer events */ 66 spinlock_t lock; /* serialize up/down and timer events */
69}; 67};
70 68
71struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv, 69struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
72 struct tipc_subscr *s, 70 struct tipc_subscr *s,
73 int conid, bool swap, 71 int conid);
74 bool status);
75void tipc_sub_delete(struct tipc_subscription *sub); 72void tipc_sub_delete(struct tipc_subscription *sub);
73
76int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower, 74int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
77 u32 found_upper); 75 u32 found_upper);
78void tipc_subscrp_report_overlap(struct tipc_subscription *sub, 76void tipc_subscrp_report_overlap(struct tipc_subscription *sub,
79 u32 found_lower, u32 found_upper, u32 event, 77 u32 found_lower, u32 found_upper,
80 u32 port_ref, u32 node, u32 scope, int must); 78 u32 event, u32 port, u32 node,
81void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap, 79 u32 scope, int must);
82 struct tipc_name_seq *out);
83u32 tipc_subscrp_convert_seq_type(u32 type, int swap);
84int tipc_topsrv_start(struct net *net); 80int tipc_topsrv_start(struct net *net);
85void tipc_topsrv_stop(struct net *net); 81void tipc_topsrv_stop(struct net *net);
86 82
87void tipc_subscrp_put(struct tipc_subscription *subscription); 83void tipc_subscrp_put(struct tipc_subscription *subscription);
88void tipc_subscrp_get(struct tipc_subscription *subscription); 84void tipc_subscrp_get(struct tipc_subscription *subscription);
89 85
86#define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
87
88/* tipc_sub_read - return field_ of struct sub_ in host endian format
89 */
90#define tipc_sub_read(sub_, field_) \
91 ({ \
92 struct tipc_subscr *sub__ = sub_; \
93 u32 val__ = (sub__)->field_; \
94 int swap_ = !((sub__)->filter & TIPC_FILTER_MASK); \
95 (swap_ ? swab32(val__) : val__); \
96 })
97
98/* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
99 */
100#define tipc_evt_write(evt_, field_, val_) \
101 ({ \
102 struct tipc_event *evt__ = evt_; \
103 u32 val__ = val_; \
104 int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK)); \
105 (evt__)->field_ = swap_ ? swab32(val__) : val__; \
106 })
107
90#endif 108#endif