This source file includes following definitions.
- tipc_sub_send_event
- tipc_sub_check_overlap
- tipc_sub_report_overlap
- tipc_sub_timeout
- tipc_sub_kref_release
- tipc_sub_put
- tipc_sub_get
- tipc_sub_subscribe
- tipc_sub_unsubscribe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include "core.h"
38 #include "name_table.h"
39 #include "subscr.h"
40
41 static void tipc_sub_send_event(struct tipc_subscription *sub,
42 u32 found_lower, u32 found_upper,
43 u32 event, u32 port, u32 node)
44 {
45 struct tipc_event *evt = &sub->evt;
46
47 if (sub->inactive)
48 return;
49 tipc_evt_write(evt, event, event);
50 tipc_evt_write(evt, found_lower, found_lower);
51 tipc_evt_write(evt, found_upper, found_upper);
52 tipc_evt_write(evt, port.ref, port);
53 tipc_evt_write(evt, port.node, node);
54 tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt);
55 }
56
57
58
59
60
61
62
63 int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
64 u32 found_upper)
65 {
66 if (found_lower < seq->lower)
67 found_lower = seq->lower;
68 if (found_upper > seq->upper)
69 found_upper = seq->upper;
70 if (found_lower > found_upper)
71 return 0;
72 return 1;
73 }
74
75 void tipc_sub_report_overlap(struct tipc_subscription *sub,
76 u32 found_lower, u32 found_upper,
77 u32 event, u32 port, u32 node,
78 u32 scope, int must)
79 {
80 struct tipc_subscr *s = &sub->evt.s;
81 u32 filter = tipc_sub_read(s, filter);
82 struct tipc_name_seq seq;
83
84 seq.type = tipc_sub_read(s, seq.type);
85 seq.lower = tipc_sub_read(s, seq.lower);
86 seq.upper = tipc_sub_read(s, seq.upper);
87
88 if (!tipc_sub_check_overlap(&seq, found_lower, found_upper))
89 return;
90
91 if (!must && !(filter & TIPC_SUB_PORTS))
92 return;
93 if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE)
94 return;
95 if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE)
96 return;
97 spin_lock(&sub->lock);
98 tipc_sub_send_event(sub, found_lower, found_upper,
99 event, port, node);
100 spin_unlock(&sub->lock);
101 }
102
103 static void tipc_sub_timeout(struct timer_list *t)
104 {
105 struct tipc_subscription *sub = from_timer(sub, t, timer);
106 struct tipc_subscr *s = &sub->evt.s;
107
108 spin_lock(&sub->lock);
109 tipc_sub_send_event(sub, s->seq.lower, s->seq.upper,
110 TIPC_SUBSCR_TIMEOUT, 0, 0);
111 sub->inactive = true;
112 spin_unlock(&sub->lock);
113 }
114
115 static void tipc_sub_kref_release(struct kref *kref)
116 {
117 kfree(container_of(kref, struct tipc_subscription, kref));
118 }
119
120 void tipc_sub_put(struct tipc_subscription *subscription)
121 {
122 kref_put(&subscription->kref, tipc_sub_kref_release);
123 }
124
125 void tipc_sub_get(struct tipc_subscription *subscription)
126 {
127 kref_get(&subscription->kref);
128 }
129
130 struct tipc_subscription *tipc_sub_subscribe(struct net *net,
131 struct tipc_subscr *s,
132 int conid)
133 {
134 u32 filter = tipc_sub_read(s, filter);
135 struct tipc_subscription *sub;
136 u32 timeout;
137
138 if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
139 (tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) {
140 pr_warn("Subscription rejected, illegal request\n");
141 return NULL;
142 }
143 sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
144 if (!sub) {
145 pr_warn("Subscription rejected, no memory\n");
146 return NULL;
147 }
148 INIT_LIST_HEAD(&sub->service_list);
149 INIT_LIST_HEAD(&sub->sub_list);
150 sub->net = net;
151 sub->conid = conid;
152 sub->inactive = false;
153 memcpy(&sub->evt.s, s, sizeof(*s));
154 spin_lock_init(&sub->lock);
155 kref_init(&sub->kref);
156 if (!tipc_nametbl_subscribe(sub)) {
157 kfree(sub);
158 return NULL;
159 }
160 timer_setup(&sub->timer, tipc_sub_timeout, 0);
161 timeout = tipc_sub_read(&sub->evt.s, timeout);
162 if (timeout != TIPC_WAIT_FOREVER)
163 mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
164 return sub;
165 }
166
167 void tipc_sub_unsubscribe(struct tipc_subscription *sub)
168 {
169 tipc_nametbl_unsubscribe(sub);
170 if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)
171 del_timer_sync(&sub->timer);
172 list_del(&sub->sub_list);
173 tipc_sub_put(sub);
174 }