tipc: Remove prototype code for supporting slave nodes
[deliverable/linux.git] / net / tipc / discover.c
1 /*
2 * net/tipc/discover.c
3 *
4 * Copyright (c) 2003-2006, Ericsson AB
5 * Copyright (c) 2005-2006, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include "core.h"
38 #include "link.h"
39 #include "discover.h"
40 #include "port.h"
41 #include "name_table.h"
42
43 #define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */
44 #define TIPC_LINK_REQ_FAST 2000 /* normal delay if bearer has no links */
45 #define TIPC_LINK_REQ_SLOW 600000 /* normal delay if bearer has links */
46
47 /*
48 * TODO: Most of the inter-cluster setup stuff should be
49 * rewritten, and be made conformant with specification.
50 */
51
52
53 /**
54 * struct link_req - information about an ongoing link setup request
55 * @bearer: bearer issuing requests
56 * @dest: destination address for request messages
57 * @buf: request message to be (repeatedly) sent
58 * @timer: timer governing period between requests
59 * @timer_intv: current interval between requests (in ms)
60 */
61 struct link_req {
62 struct bearer *bearer;
63 struct tipc_media_addr dest;
64 struct sk_buff *buf;
65 struct timer_list timer;
66 unsigned int timer_intv;
67 };
68
69 /**
70 * tipc_disc_init_msg - initialize a link setup message
71 * @type: message type (request or response)
72 * @req_links: number of links associated with message
73 * @dest_domain: network domain of node(s) which should respond to message
74 * @b_ptr: ptr to bearer issuing message
75 */
76
77 static struct sk_buff *tipc_disc_init_msg(u32 type,
78 u32 req_links,
79 u32 dest_domain,
80 struct bearer *b_ptr)
81 {
82 struct sk_buff *buf = tipc_buf_acquire(DSC_H_SIZE);
83 struct tipc_msg *msg;
84
85 if (buf) {
86 msg = buf_msg(buf);
87 tipc_msg_init(msg, LINK_CONFIG, type, DSC_H_SIZE, dest_domain);
88 msg_set_non_seq(msg, 1);
89 msg_set_req_links(msg, req_links);
90 msg_set_dest_domain(msg, dest_domain);
91 msg_set_bc_netid(msg, tipc_net_id);
92 msg_set_media_addr(msg, &b_ptr->publ.addr);
93 }
94 return buf;
95 }
96
97 /**
98 * disc_dupl_alert - issue node address duplication alert
99 * @b_ptr: pointer to bearer detecting duplication
100 * @node_addr: duplicated node address
101 * @media_addr: media address advertised by duplicated node
102 */
103
104 static void disc_dupl_alert(struct bearer *b_ptr, u32 node_addr,
105 struct tipc_media_addr *media_addr)
106 {
107 char node_addr_str[16];
108 char media_addr_str[64];
109 struct print_buf pb;
110
111 tipc_addr_string_fill(node_addr_str, node_addr);
112 tipc_printbuf_init(&pb, media_addr_str, sizeof(media_addr_str));
113 tipc_media_addr_printf(&pb, media_addr);
114 tipc_printbuf_validate(&pb);
115 warn("Duplicate %s using %s seen on <%s>\n",
116 node_addr_str, media_addr_str, b_ptr->publ.name);
117 }
118
119 /**
120 * tipc_disc_recv_msg - handle incoming link setup message (request or response)
121 * @buf: buffer containing message
122 * @b_ptr: bearer that message arrived on
123 */
124
125 void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
126 {
127 struct link *link;
128 struct tipc_media_addr media_addr;
129 struct tipc_msg *msg = buf_msg(buf);
130 u32 dest = msg_dest_domain(msg);
131 u32 orig = msg_prevnode(msg);
132 u32 net_id = msg_bc_netid(msg);
133 u32 type = msg_type(msg);
134
135 msg_get_media_addr(msg,&media_addr);
136 msg_dbg(msg, "RECV:");
137 buf_discard(buf);
138
139 if (net_id != tipc_net_id)
140 return;
141 if (!tipc_addr_domain_valid(dest))
142 return;
143 if (!tipc_addr_node_valid(orig))
144 return;
145 if (orig == tipc_own_addr) {
146 if (memcmp(&media_addr, &b_ptr->publ.addr, sizeof(media_addr)))
147 disc_dupl_alert(b_ptr, tipc_own_addr, &media_addr);
148 return;
149 }
150 if (!tipc_in_scope(dest, tipc_own_addr))
151 return;
152 if (in_own_cluster(orig)) {
153 /* Always accept link here */
154 struct sk_buff *rbuf;
155 struct tipc_media_addr *addr;
156 struct tipc_node *n_ptr = tipc_node_find(orig);
157 int link_fully_up;
158
159 dbg(" in own cluster\n");
160 if (n_ptr == NULL) {
161 n_ptr = tipc_node_create(orig);
162 if (!n_ptr)
163 return;
164 }
165 spin_lock_bh(&n_ptr->lock);
166
167 /* Don't talk to neighbor during cleanup after last session */
168
169 if (n_ptr->cleanup_required) {
170 spin_unlock_bh(&n_ptr->lock);
171 return;
172 }
173
174 link = n_ptr->links[b_ptr->identity];
175 if (!link) {
176 dbg("creating link\n");
177 link = tipc_link_create(b_ptr, orig, &media_addr);
178 if (!link) {
179 spin_unlock_bh(&n_ptr->lock);
180 return;
181 }
182 }
183 addr = &link->media_addr;
184 if (memcmp(addr, &media_addr, sizeof(*addr))) {
185 if (tipc_link_is_up(link) || (!link->started)) {
186 disc_dupl_alert(b_ptr, orig, &media_addr);
187 spin_unlock_bh(&n_ptr->lock);
188 return;
189 }
190 warn("Resetting link <%s>, peer interface address changed\n",
191 link->name);
192 memcpy(addr, &media_addr, sizeof(*addr));
193 tipc_link_reset(link);
194 }
195 link_fully_up = link_working_working(link);
196 spin_unlock_bh(&n_ptr->lock);
197 if ((type == DSC_RESP_MSG) || link_fully_up)
198 return;
199 rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr);
200 if (rbuf != NULL) {
201 msg_dbg(buf_msg(rbuf),"SEND:");
202 b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr);
203 buf_discard(rbuf);
204 }
205 }
206 }
207
208 /**
209 * tipc_disc_stop_link_req - stop sending periodic link setup requests
210 * @req: ptr to link request structure
211 */
212
213 void tipc_disc_stop_link_req(struct link_req *req)
214 {
215 if (!req)
216 return;
217
218 k_cancel_timer(&req->timer);
219 k_term_timer(&req->timer);
220 buf_discard(req->buf);
221 kfree(req);
222 }
223
224 /**
225 * tipc_disc_update_link_req - update frequency of periodic link setup requests
226 * @req: ptr to link request structure
227 */
228
229 void tipc_disc_update_link_req(struct link_req *req)
230 {
231 if (!req)
232 return;
233
234 if (req->timer_intv == TIPC_LINK_REQ_SLOW) {
235 if (!req->bearer->nodes.count) {
236 req->timer_intv = TIPC_LINK_REQ_FAST;
237 k_start_timer(&req->timer, req->timer_intv);
238 }
239 } else if (req->timer_intv == TIPC_LINK_REQ_FAST) {
240 if (req->bearer->nodes.count) {
241 req->timer_intv = TIPC_LINK_REQ_SLOW;
242 k_start_timer(&req->timer, req->timer_intv);
243 }
244 } else {
245 /* leave timer "as is" if haven't yet reached a "normal" rate */
246 }
247 }
248
249 /**
250 * disc_timeout - send a periodic link setup request
251 * @req: ptr to link request structure
252 *
253 * Called whenever a link setup request timer associated with a bearer expires.
254 */
255
256 static void disc_timeout(struct link_req *req)
257 {
258 spin_lock_bh(&req->bearer->publ.lock);
259
260 req->bearer->media->send_msg(req->buf, &req->bearer->publ, &req->dest);
261
262 if ((req->timer_intv == TIPC_LINK_REQ_SLOW) ||
263 (req->timer_intv == TIPC_LINK_REQ_FAST)) {
264 /* leave timer interval "as is" if already at a "normal" rate */
265 } else {
266 req->timer_intv *= 2;
267 if (req->timer_intv > TIPC_LINK_REQ_FAST)
268 req->timer_intv = TIPC_LINK_REQ_FAST;
269 if ((req->timer_intv == TIPC_LINK_REQ_FAST) &&
270 (req->bearer->nodes.count))
271 req->timer_intv = TIPC_LINK_REQ_SLOW;
272 }
273 k_start_timer(&req->timer, req->timer_intv);
274
275 spin_unlock_bh(&req->bearer->publ.lock);
276 }
277
278 /**
279 * tipc_disc_init_link_req - start sending periodic link setup requests
280 * @b_ptr: ptr to bearer issuing requests
281 * @dest: destination address for request messages
282 * @dest_domain: network domain of node(s) which should respond to message
283 * @req_links: max number of desired links
284 *
285 * Returns pointer to link request structure, or NULL if unable to create.
286 */
287
288 struct link_req *tipc_disc_init_link_req(struct bearer *b_ptr,
289 const struct tipc_media_addr *dest,
290 u32 dest_domain,
291 u32 req_links)
292 {
293 struct link_req *req;
294
295 req = kmalloc(sizeof(*req), GFP_ATOMIC);
296 if (!req)
297 return NULL;
298
299 req->buf = tipc_disc_init_msg(DSC_REQ_MSG, req_links, dest_domain, b_ptr);
300 if (!req->buf) {
301 kfree(req);
302 return NULL;
303 }
304
305 memcpy(&req->dest, dest, sizeof(*dest));
306 req->bearer = b_ptr;
307 req->timer_intv = TIPC_LINK_REQ_INIT;
308 k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req);
309 k_start_timer(&req->timer, req->timer_intv);
310 return req;
311 }
312
This page took 0.046265 seconds and 6 git commands to generate.