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 "link.h"
39#include "name_distr.h"
40
41#define ITEM_SIZE sizeof(struct distr_item)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct distr_item {
63 __be32 type;
64 __be32 lower;
65 __be32 upper;
66 __be32 ref;
67 __be32 key;
68};
69
70
71
72
73
74
75static LIST_HEAD(publ_root);
76static u32 publ_cnt;
77
78
79
80
81
82static void publ_to_item(struct distr_item *i, struct publication *p)
83{
84 i->type = htonl(p->type);
85 i->lower = htonl(p->lower);
86 i->upper = htonl(p->upper);
87 i->ref = htonl(p->ref);
88 i->key = htonl(p->key);
89}
90
91
92
93
94
95static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest)
96{
97 struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size);
98 struct tipc_msg *msg;
99
100 if (buf != NULL) {
101 msg = buf_msg(buf);
102 tipc_msg_init(msg, NAME_DISTRIBUTOR, type, INT_H_SIZE, dest);
103 msg_set_size(msg, INT_H_SIZE + size);
104 }
105 return buf;
106}
107
108static void named_cluster_distribute(struct sk_buff *buf)
109{
110 struct sk_buff *buf_copy;
111 struct tipc_node *n_ptr;
112
113 list_for_each_entry(n_ptr, &tipc_node_list, list) {
114 if (tipc_node_active_links(n_ptr)) {
115 buf_copy = skb_copy(buf, GFP_ATOMIC);
116 if (!buf_copy)
117 break;
118 msg_set_destnode(buf_msg(buf_copy), n_ptr->addr);
119 tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr);
120 }
121 }
122
123 buf_discard(buf);
124}
125
126
127
128
129
130void tipc_named_publish(struct publication *publ)
131{
132 struct sk_buff *buf;
133 struct distr_item *item;
134
135 list_add_tail(&publ->local_list, &publ_root);
136 publ_cnt++;
137
138 buf = named_prepare_buf(PUBLICATION, ITEM_SIZE, 0);
139 if (!buf) {
140 warn("Publication distribution failure\n");
141 return;
142 }
143
144 item = (struct distr_item *)msg_data(buf_msg(buf));
145 publ_to_item(item, publ);
146 named_cluster_distribute(buf);
147}
148
149
150
151
152
153void tipc_named_withdraw(struct publication *publ)
154{
155 struct sk_buff *buf;
156 struct distr_item *item;
157
158 list_del(&publ->local_list);
159 publ_cnt--;
160
161 buf = named_prepare_buf(WITHDRAWAL, ITEM_SIZE, 0);
162 if (!buf) {
163 warn("Withdrawal distribution failure\n");
164 return;
165 }
166
167 item = (struct distr_item *)msg_data(buf_msg(buf));
168 publ_to_item(item, publ);
169 named_cluster_distribute(buf);
170}
171
172
173
174
175
176void tipc_named_node_up(unsigned long nodearg)
177{
178 struct tipc_node *n_ptr;
179 struct tipc_link *l_ptr;
180 struct publication *publ;
181 struct distr_item *item = NULL;
182 struct sk_buff *buf = NULL;
183 struct list_head message_list;
184 u32 node = (u32)nodearg;
185 u32 left = 0;
186 u32 rest;
187 u32 max_item_buf = 0;
188
189
190
191 read_lock_bh(&tipc_net_lock);
192 n_ptr = tipc_node_find(node);
193 if (n_ptr) {
194 tipc_node_lock(n_ptr);
195 l_ptr = n_ptr->active_links[0];
196 if (l_ptr)
197 max_item_buf = ((l_ptr->max_pkt - INT_H_SIZE) /
198 ITEM_SIZE) * ITEM_SIZE;
199 tipc_node_unlock(n_ptr);
200 }
201 read_unlock_bh(&tipc_net_lock);
202 if (!max_item_buf)
203 return;
204
205
206
207 INIT_LIST_HEAD(&message_list);
208
209 read_lock_bh(&tipc_nametbl_lock);
210 rest = publ_cnt * ITEM_SIZE;
211
212 list_for_each_entry(publ, &publ_root, local_list) {
213 if (!buf) {
214 left = (rest <= max_item_buf) ? rest : max_item_buf;
215 rest -= left;
216 buf = named_prepare_buf(PUBLICATION, left, node);
217 if (!buf) {
218 warn("Bulk publication distribution failure\n");
219 goto exit;
220 }
221 item = (struct distr_item *)msg_data(buf_msg(buf));
222 }
223 publ_to_item(item, publ);
224 item++;
225 left -= ITEM_SIZE;
226 if (!left) {
227 list_add_tail((struct list_head *)buf, &message_list);
228 buf = NULL;
229 }
230 }
231exit:
232 read_unlock_bh(&tipc_nametbl_lock);
233
234 tipc_link_send_names(&message_list, (u32)node);
235}
236
237
238
239
240
241
242
243
244
245
246
247static void named_purge_publ(struct publication *publ)
248{
249 struct publication *p;
250
251 write_lock_bh(&tipc_nametbl_lock);
252 publ->key += 1222345;
253 p = tipc_nametbl_remove_publ(publ->type, publ->lower,
254 publ->node, publ->ref, publ->key);
255 if (p)
256 tipc_nodesub_unsubscribe(&p->subscr);
257 write_unlock_bh(&tipc_nametbl_lock);
258
259 if (p != publ) {
260 err("Unable to remove publication from failed node\n"
261 "(type=%u, lower=%u, node=0x%x, ref=%u, key=%u)\n",
262 publ->type, publ->lower, publ->node, publ->ref, publ->key);
263 }
264
265 kfree(p);
266}
267
268
269
270
271
272void tipc_named_recv(struct sk_buff *buf)
273{
274 struct publication *publ;
275 struct tipc_msg *msg = buf_msg(buf);
276 struct distr_item *item = (struct distr_item *)msg_data(msg);
277 u32 count = msg_data_sz(msg) / ITEM_SIZE;
278
279 write_lock_bh(&tipc_nametbl_lock);
280 while (count--) {
281 if (msg_type(msg) == PUBLICATION) {
282 publ = tipc_nametbl_insert_publ(ntohl(item->type),
283 ntohl(item->lower),
284 ntohl(item->upper),
285 TIPC_CLUSTER_SCOPE,
286 msg_orignode(msg),
287 ntohl(item->ref),
288 ntohl(item->key));
289 if (publ) {
290 tipc_nodesub_subscribe(&publ->subscr,
291 msg_orignode(msg),
292 publ,
293 (net_ev_handler)
294 named_purge_publ);
295 }
296 } else if (msg_type(msg) == WITHDRAWAL) {
297 publ = tipc_nametbl_remove_publ(ntohl(item->type),
298 ntohl(item->lower),
299 msg_orignode(msg),
300 ntohl(item->ref),
301 ntohl(item->key));
302
303 if (publ) {
304 tipc_nodesub_unsubscribe(&publ->subscr);
305 kfree(publ);
306 } else {
307 err("Unable to remove publication by node 0x%x\n"
308 "(type=%u, lower=%u, ref=%u, key=%u)\n",
309 msg_orignode(msg),
310 ntohl(item->type), ntohl(item->lower),
311 ntohl(item->ref), ntohl(item->key));
312 }
313 } else {
314 warn("Unrecognized name table message received\n");
315 }
316 item++;
317 }
318 write_unlock_bh(&tipc_nametbl_lock);
319 buf_discard(buf);
320}
321
322
323
324
325
326
327
328
329
330void tipc_named_reinit(void)
331{
332 struct publication *publ;
333
334 write_lock_bh(&tipc_nametbl_lock);
335
336 list_for_each_entry(publ, &publ_root, local_list)
337 publ->node = tipc_own_addr;
338
339 write_unlock_bh(&tipc_nametbl_lock);
340}
341