diff options
author | Per Liden <per.liden@nospam.ericsson.com> | 2006-01-02 13:04:38 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-01-12 17:06:31 -0500 |
commit | b97bf3fd8f6a16966d4f18983b2c40993ff937d4 (patch) | |
tree | 59959f8a0f3087455efdcb430846686f303c5991 /net/tipc/discover.c | |
parent | 58cba4650a7a414eabd2b40cc9d8e45fcdf192d9 (diff) |
[TIPC] Initial merge
TIPC (Transparent Inter Process Communication) is a protocol designed for
intra cluster communication. For more information see
http://tipc.sourceforge.net
Signed-off-by: Per Liden <per.liden@nospam.ericsson.com>
Diffstat (limited to 'net/tipc/discover.c')
-rw-r--r-- | net/tipc/discover.c | 339 |
1 files changed, 339 insertions, 0 deletions
diff --git a/net/tipc/discover.c b/net/tipc/discover.c new file mode 100644 index 000000000000..c83c1be17f85 --- /dev/null +++ b/net/tipc/discover.c | |||
@@ -0,0 +1,339 @@ | |||
1 | /* | ||
2 | * net/tipc/discover.c | ||
3 | * | ||
4 | * Copyright (c) 2003-2005, Ericsson Research Canada | ||
5 | * Copyright (c) 2005, Wind River Systems | ||
6 | * Copyright (c) 2005-2006, Ericsson AB | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions are met: | ||
11 | * | ||
12 | * Redistributions of source code must retain the above copyright notice, this | ||
13 | * list of conditions and the following disclaimer. | ||
14 | * Redistributions in binary form must reproduce the above copyright notice, | ||
15 | * this list of conditions and the following disclaimer in the documentation | ||
16 | * and/or other materials provided with the distribution. | ||
17 | * Neither the names of the copyright holders nor the names of its | ||
18 | * contributors may be used to endorse or promote products derived from this | ||
19 | * software without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | * POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #include "core.h" | ||
35 | #include "dbg.h" | ||
36 | #include "link.h" | ||
37 | #include "zone.h" | ||
38 | #include "discover.h" | ||
39 | #include "port.h" | ||
40 | #include "name_table.h" | ||
41 | |||
42 | #define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */ | ||
43 | #define TIPC_LINK_REQ_FAST 2000 /* normal delay if bearer has no links */ | ||
44 | #define TIPC_LINK_REQ_SLOW 600000 /* normal delay if bearer has links */ | ||
45 | |||
46 | #if 0 | ||
47 | #define GET_NODE_INFO 300 | ||
48 | #define GET_NODE_INFO_RESULT 301 | ||
49 | #define FORWARD_LINK_PROBE 302 | ||
50 | #define LINK_REQUEST_REJECTED 303 | ||
51 | #define LINK_REQUEST_ACCEPTED 304 | ||
52 | #define DROP_LINK_REQUEST 305 | ||
53 | #define CHECK_LINK_COUNT 306 | ||
54 | #endif | ||
55 | |||
56 | /* | ||
57 | * TODO: Most of the inter-cluster setup stuff should be | ||
58 | * rewritten, and be made conformant with specification. | ||
59 | */ | ||
60 | |||
61 | |||
62 | /** | ||
63 | * struct link_req - information about an ongoing link setup request | ||
64 | * @bearer: bearer issuing requests | ||
65 | * @dest: destination address for request messages | ||
66 | * @buf: request message to be (repeatedly) sent | ||
67 | * @timer: timer governing period between requests | ||
68 | * @timer_intv: current interval between requests (in ms) | ||
69 | */ | ||
70 | struct link_req { | ||
71 | struct bearer *bearer; | ||
72 | struct tipc_media_addr dest; | ||
73 | struct sk_buff *buf; | ||
74 | struct timer_list timer; | ||
75 | unsigned int timer_intv; | ||
76 | }; | ||
77 | |||
78 | |||
79 | #if 0 | ||
80 | int disc_create_link(const struct tipc_link_create *argv) | ||
81 | { | ||
82 | /* | ||
83 | * Code for inter cluster link setup here | ||
84 | */ | ||
85 | return TIPC_OK; | ||
86 | } | ||
87 | #endif | ||
88 | |||
89 | /* | ||
90 | * disc_lost_link(): A link has lost contact | ||
91 | */ | ||
92 | |||
93 | void disc_link_event(u32 addr, char *name, int up) | ||
94 | { | ||
95 | if (in_own_cluster(addr)) | ||
96 | return; | ||
97 | /* | ||
98 | * Code for inter cluster link setup here | ||
99 | */ | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * disc_init_msg - initialize a link setup message | ||
104 | * @type: message type (request or response) | ||
105 | * @req_links: number of links associated with message | ||
106 | * @dest_domain: network domain of node(s) which should respond to message | ||
107 | * @b_ptr: ptr to bearer issuing message | ||
108 | */ | ||
109 | |||
110 | struct sk_buff *disc_init_msg(u32 type, | ||
111 | u32 req_links, | ||
112 | u32 dest_domain, | ||
113 | struct bearer *b_ptr) | ||
114 | { | ||
115 | struct sk_buff *buf = buf_acquire(DSC_H_SIZE); | ||
116 | struct tipc_msg *msg; | ||
117 | |||
118 | if (buf) { | ||
119 | msg = buf_msg(buf); | ||
120 | msg_init(msg, LINK_CONFIG, type, TIPC_OK, DSC_H_SIZE, | ||
121 | dest_domain); | ||
122 | msg_set_non_seq(msg); | ||
123 | msg_set_req_links(msg, req_links); | ||
124 | msg_set_dest_domain(msg, dest_domain); | ||
125 | msg_set_bc_netid(msg, tipc_net_id); | ||
126 | msg_set_media_addr(msg, &b_ptr->publ.addr); | ||
127 | } | ||
128 | return buf; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * disc_recv_msg - handle incoming link setup message (request or response) | ||
133 | * @buf: buffer containing message | ||
134 | */ | ||
135 | |||
136 | void disc_recv_msg(struct sk_buff *buf) | ||
137 | { | ||
138 | struct bearer *b_ptr = (struct bearer *)TIPC_SKB_CB(buf)->handle; | ||
139 | struct link *link; | ||
140 | struct tipc_media_addr media_addr; | ||
141 | struct tipc_msg *msg = buf_msg(buf); | ||
142 | u32 dest = msg_dest_domain(msg); | ||
143 | u32 orig = msg_prevnode(msg); | ||
144 | u32 net_id = msg_bc_netid(msg); | ||
145 | u32 type = msg_type(msg); | ||
146 | |||
147 | msg_get_media_addr(msg,&media_addr); | ||
148 | msg_dbg(msg, "RECV:"); | ||
149 | buf_discard(buf); | ||
150 | |||
151 | if (net_id != tipc_net_id) | ||
152 | return; | ||
153 | if (!addr_domain_valid(dest)) | ||
154 | return; | ||
155 | if (!addr_node_valid(orig)) | ||
156 | return; | ||
157 | if (orig == tipc_own_addr) | ||
158 | return; | ||
159 | if (!in_scope(dest, tipc_own_addr)) | ||
160 | return; | ||
161 | if (is_slave(tipc_own_addr) && is_slave(orig)) | ||
162 | return; | ||
163 | if (is_slave(orig) && !in_own_cluster(orig)) | ||
164 | return; | ||
165 | if (in_own_cluster(orig)) { | ||
166 | /* Always accept link here */ | ||
167 | struct sk_buff *rbuf; | ||
168 | struct tipc_media_addr *addr; | ||
169 | struct node *n_ptr = node_find(orig); | ||
170 | int link_up; | ||
171 | dbg(" in own cluster\n"); | ||
172 | if (n_ptr == NULL) { | ||
173 | n_ptr = node_create(orig); | ||
174 | } | ||
175 | if (n_ptr == NULL) { | ||
176 | warn("Memory squeeze; Failed to create node\n"); | ||
177 | return; | ||
178 | } | ||
179 | spin_lock_bh(&n_ptr->lock); | ||
180 | link = n_ptr->links[b_ptr->identity]; | ||
181 | if (!link) { | ||
182 | dbg("creating link\n"); | ||
183 | link = link_create(b_ptr, orig, &media_addr); | ||
184 | if (!link) { | ||
185 | spin_unlock_bh(&n_ptr->lock); | ||
186 | return; | ||
187 | } | ||
188 | } | ||
189 | addr = &link->media_addr; | ||
190 | if (memcmp(addr, &media_addr, sizeof(*addr))) { | ||
191 | char addr_string[16]; | ||
192 | |||
193 | warn("New bearer address for %s\n", | ||
194 | addr_string_fill(addr_string, orig)); | ||
195 | memcpy(addr, &media_addr, sizeof(*addr)); | ||
196 | link_reset(link); | ||
197 | } | ||
198 | link_up = link_is_up(link); | ||
199 | spin_unlock_bh(&n_ptr->lock); | ||
200 | if ((type == DSC_RESP_MSG) || link_up) | ||
201 | return; | ||
202 | rbuf = disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr); | ||
203 | if (rbuf != NULL) { | ||
204 | msg_dbg(buf_msg(rbuf),"SEND:"); | ||
205 | b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr); | ||
206 | buf_discard(rbuf); | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | /** | ||
212 | * disc_stop_link_req - stop sending periodic link setup requests | ||
213 | * @req: ptr to link request structure | ||
214 | */ | ||
215 | |||
216 | void disc_stop_link_req(struct link_req *req) | ||
217 | { | ||
218 | if (!req) | ||
219 | return; | ||
220 | |||
221 | k_cancel_timer(&req->timer); | ||
222 | k_term_timer(&req->timer); | ||
223 | buf_discard(req->buf); | ||
224 | kfree(req); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * disc_update_link_req - update frequency of periodic link setup requests | ||
229 | * @req: ptr to link request structure | ||
230 | */ | ||
231 | |||
232 | void disc_update_link_req(struct link_req *req) | ||
233 | { | ||
234 | if (!req) | ||
235 | return; | ||
236 | |||
237 | if (req->timer_intv == TIPC_LINK_REQ_SLOW) { | ||
238 | if (!req->bearer->nodes.count) { | ||
239 | req->timer_intv = TIPC_LINK_REQ_FAST; | ||
240 | k_start_timer(&req->timer, req->timer_intv); | ||
241 | } | ||
242 | } else if (req->timer_intv == TIPC_LINK_REQ_FAST) { | ||
243 | if (req->bearer->nodes.count) { | ||
244 | req->timer_intv = TIPC_LINK_REQ_SLOW; | ||
245 | k_start_timer(&req->timer, req->timer_intv); | ||
246 | } | ||
247 | } else { | ||
248 | /* leave timer "as is" if haven't yet reached a "normal" rate */ | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * disc_timeout - send a periodic link setup request | ||
254 | * @req: ptr to link request structure | ||
255 | * | ||
256 | * Called whenever a link setup request timer associated with a bearer expires. | ||
257 | */ | ||
258 | |||
259 | static void disc_timeout(struct link_req *req) | ||
260 | { | ||
261 | struct tipc_msg *msg = buf_msg(req->buf); | ||
262 | |||
263 | spin_lock_bh(&req->bearer->publ.lock); | ||
264 | |||
265 | #if 0 | ||
266 | /* CURRENTLY DON'T SUPPORT INTER-ZONE LINKS */ | ||
267 | u32 dest_domain = msg_dest_domain(msg); | ||
268 | int stop = 0; | ||
269 | if (!in_scope(dest_domain, tipc_own_addr)) { | ||
270 | struct _zone *z_ptr = zone_find(dest_domain); | ||
271 | |||
272 | if (z_ptr && (z_ptr->links >= msg_req_links(msg))) | ||
273 | stop = 1; | ||
274 | if (req->timer_intv >= 32000) | ||
275 | stop = 1; | ||
276 | } | ||
277 | if (stop) { | ||
278 | k_cancel_timer(&req->timer); | ||
279 | buf_discard(req->buf); | ||
280 | kfree(req); | ||
281 | spin_unlock_bh(&req->bearer->publ.lock); | ||
282 | return; | ||
283 | } | ||
284 | #endif | ||
285 | |||
286 | msg_dbg(msg,"SEND:"); | ||
287 | req->bearer->media->send_msg(req->buf, &req->bearer->publ, &req->dest); | ||
288 | |||
289 | if ((req->timer_intv == TIPC_LINK_REQ_SLOW) || | ||
290 | (req->timer_intv == TIPC_LINK_REQ_FAST)) { | ||
291 | /* leave timer interval "as is" if already at a "normal" rate */ | ||
292 | } else { | ||
293 | req->timer_intv *= 2; | ||
294 | if (req->timer_intv > TIPC_LINK_REQ_FAST) | ||
295 | req->timer_intv = TIPC_LINK_REQ_FAST; | ||
296 | if ((req->timer_intv == TIPC_LINK_REQ_FAST) && | ||
297 | (req->bearer->nodes.count)) | ||
298 | req->timer_intv = TIPC_LINK_REQ_SLOW; | ||
299 | } | ||
300 | k_start_timer(&req->timer, req->timer_intv); | ||
301 | |||
302 | spin_unlock_bh(&req->bearer->publ.lock); | ||
303 | } | ||
304 | |||
305 | /** | ||
306 | * disc_init_link_req - start sending periodic link setup requests | ||
307 | * @b_ptr: ptr to bearer issuing requests | ||
308 | * @dest: destination address for request messages | ||
309 | * @dest_domain: network domain of node(s) which should respond to message | ||
310 | * @req_links: max number of desired links | ||
311 | * | ||
312 | * Returns pointer to link request structure, or NULL if unable to create. | ||
313 | */ | ||
314 | |||
315 | struct link_req *disc_init_link_req(struct bearer *b_ptr, | ||
316 | const struct tipc_media_addr *dest, | ||
317 | u32 dest_domain, | ||
318 | u32 req_links) | ||
319 | { | ||
320 | struct link_req *req; | ||
321 | |||
322 | req = (struct link_req *)kmalloc(sizeof(*req), GFP_ATOMIC); | ||
323 | if (!req) | ||
324 | return NULL; | ||
325 | |||
326 | req->buf = disc_init_msg(DSC_REQ_MSG, req_links, dest_domain, b_ptr); | ||
327 | if (!req->buf) { | ||
328 | kfree(req); | ||
329 | return NULL; | ||
330 | } | ||
331 | |||
332 | memcpy(&req->dest, dest, sizeof(*dest)); | ||
333 | req->bearer = b_ptr; | ||
334 | req->timer_intv = TIPC_LINK_REQ_INIT; | ||
335 | k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); | ||
336 | k_start_timer(&req->timer, req->timer_intv); | ||
337 | return req; | ||
338 | } | ||
339 | |||