]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - net/tipc/name_distr.c
2 * net/tipc/name_distr.c: TIPC name distribution code
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * Alternatively, this software may be distributed under the terms of the
22 * GNU General Public License ("GPL") version 2 as published by the Free
23 * Software Foundation.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
43 #include "name_distr.h"
46 #define DBG_OUTPUT NULL
48 #define ITEM_SIZE sizeof(struct distr_item)
51 * struct distr_item - publication info distributed to other nodes
52 * @type: name sequence type
53 * @lower: name sequence lower bound
54 * @upper: name sequence upper bound
55 * @ref: publishing port reference
56 * @key: publication key
58 * ===> All fields are stored in network byte order. <===
60 * First 3 fields identify (name or) name sequence being published.
61 * Reference field uniquely identifies port that published name sequence.
62 * Key field uniquely identifies publication, in the event a port has
63 * multiple publications of the same name sequence.
65 * Note: There is no field that identifies the publishing node because it is
66 * the same for all items contained within a publication message.
78 * List of externally visible publications by this node --
79 * that is, all publications having scope > TIPC_NODE_SCOPE.
82 static LIST_HEAD(publ_root
);
83 static u32 publ_cnt
= 0;
86 * publ_to_item - add publication info to a publication message
89 static void publ_to_item(struct distr_item
*i
, struct publication
*p
)
91 i
->type
= htonl(p
->type
);
92 i
->lower
= htonl(p
->lower
);
93 i
->upper
= htonl(p
->upper
);
94 i
->ref
= htonl(p
->ref
);
95 i
->key
= htonl(p
->key
);
96 dbg("publ_to_item: %u, %u, %u\n", p
->type
, p
->lower
, p
->upper
);
100 * named_prepare_buf - allocate & initialize a publication message
103 static struct sk_buff
*named_prepare_buf(u32 type
, u32 size
, u32 dest
)
105 struct sk_buff
*buf
= buf_acquire(LONG_H_SIZE
+ size
);
106 struct tipc_msg
*msg
;
110 msg_init(msg
, NAME_DISTRIBUTOR
, type
, TIPC_OK
,
112 msg_set_size(msg
, LONG_H_SIZE
+ size
);
118 * named_publish - tell other nodes about a new publication by this node
121 void named_publish(struct publication
*publ
)
124 struct distr_item
*item
;
126 list_add(&publ
->local_list
, &publ_root
);
129 buf
= named_prepare_buf(PUBLICATION
, ITEM_SIZE
, 0);
131 warn("Memory squeeze; failed to distribute publication\n");
135 item
= (struct distr_item
*)msg_data(buf_msg(buf
));
136 publ_to_item(item
, publ
);
137 dbg("named_withdraw: broadcasting publish msg\n");
138 cluster_broadcast(buf
);
142 * named_withdraw - tell other nodes about a withdrawn publication by this node
145 void named_withdraw(struct publication
*publ
)
148 struct distr_item
*item
;
150 list_del(&publ
->local_list
);
153 buf
= named_prepare_buf(WITHDRAWAL
, ITEM_SIZE
, 0);
155 warn("Memory squeeze; failed to distribute withdrawal\n");
159 item
= (struct distr_item
*)msg_data(buf_msg(buf
));
160 publ_to_item(item
, publ
);
161 dbg("named_withdraw: broadcasting withdraw msg\n");
162 cluster_broadcast(buf
);
166 * named_node_up - tell specified node about all publications by this node
169 void named_node_up(unsigned long node
)
171 struct publication
*publ
;
172 struct distr_item
*item
= 0;
173 struct sk_buff
*buf
= 0;
178 assert(in_own_cluster(node
));
179 read_lock_bh(&nametbl_lock
);
180 max_item_buf
= TIPC_MAX_USER_MSG_SIZE
/ ITEM_SIZE
;
181 max_item_buf
*= ITEM_SIZE
;
182 rest
= publ_cnt
* ITEM_SIZE
;
184 list_for_each_entry(publ
, &publ_root
, local_list
) {
186 left
= (rest
<= max_item_buf
) ? rest
: max_item_buf
;
188 buf
= named_prepare_buf(PUBLICATION
, left
, node
);
190 warn("Memory Squeeze; could not send publication\n");
193 item
= (struct distr_item
*)msg_data(buf_msg(buf
));
195 publ_to_item(item
, publ
);
199 msg_set_link_selector(buf_msg(buf
), node
);
200 dbg("named_node_up: sending publish msg to "
201 "<%u.%u.%u>\n", tipc_zone(node
),
202 tipc_cluster(node
), tipc_node(node
));
203 link_send(buf
, node
, node
);
208 read_unlock_bh(&nametbl_lock
);
212 * node_is_down - remove publication associated with a failed node
214 * Invoked for each publication issued by a newly failed node.
215 * Removes publication structure from name table & deletes it.
216 * In rare cases the link may have come back up again when this
217 * function is called, and we have two items representing the same
218 * publication. Nudge this item's key to distinguish it from the other.
219 * (Note: Publication's node subscription is already unsubscribed.)
222 static void node_is_down(struct publication
*publ
)
224 struct publication
*p
;
225 write_lock_bh(&nametbl_lock
);
226 dbg("node_is_down: withdrawing %u, %u, %u\n",
227 publ
->type
, publ
->lower
, publ
->upper
);
228 publ
->key
+= 1222345;
229 p
= nametbl_remove_publ(publ
->type
, publ
->lower
,
230 publ
->node
, publ
->ref
, publ
->key
);
232 write_unlock_bh(&nametbl_lock
);
238 * named_recv - process name table update message sent by another node
241 void named_recv(struct sk_buff
*buf
)
243 struct publication
*publ
;
244 struct tipc_msg
*msg
= buf_msg(buf
);
245 struct distr_item
*item
= (struct distr_item
*)msg_data(msg
);
246 u32 count
= msg_data_sz(msg
) / ITEM_SIZE
;
248 write_lock_bh(&nametbl_lock
);
250 if (msg_type(msg
) == PUBLICATION
) {
251 dbg("named_recv: got publication for %u, %u, %u\n",
252 ntohl(item
->type
), ntohl(item
->lower
),
254 publ
= nametbl_insert_publ(ntohl(item
->type
),
262 nodesub_subscribe(&publ
->subscr
,
265 (net_ev_handler
)node_is_down
);
267 } else if (msg_type(msg
) == WITHDRAWAL
) {
268 dbg("named_recv: got withdrawl for %u, %u, %u\n",
269 ntohl(item
->type
), ntohl(item
->lower
),
271 publ
= nametbl_remove_publ(ntohl(item
->type
),
278 nodesub_unsubscribe(&publ
->subscr
);
282 warn("named_recv: unknown msg\n");
286 write_unlock_bh(&nametbl_lock
);
291 * named_reinit - re-initialize local publication list
293 * This routine is called whenever TIPC networking is (re)enabled.
294 * All existing publications by this node that have "cluster" or "zone" scope
295 * are updated to reflect the node's current network address.
296 * (If the node's address is unchanged, the update loop terminates immediately.)
299 void named_reinit(void)
301 struct publication
*publ
;
303 write_lock_bh(&nametbl_lock
);
304 list_for_each_entry(publ
, &publ_root
, local_list
) {
305 if (publ
->node
== tipc_own_addr
)
307 publ
->node
= tipc_own_addr
;
309 write_unlock_bh(&nametbl_lock
);