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 * 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.
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.
40 #include "name_table.h"
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 */
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
57 * TODO: Most of the inter-cluster setup stuff should be
58 * rewritten, and be made conformant with specification.
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)
71 struct bearer *bearer;
72 struct tipc_media_addr dest;
74 struct timer_list timer;
75 unsigned int timer_intv;
80 int disc_create_link(const struct tipc_link_create *argv)
83 * Code for inter cluster link setup here
90 * disc_lost_link(): A link has lost contact
93 void disc_link_event(u32 addr, char *name, int up)
95 if (in_own_cluster(addr))
98 * Code for inter cluster link setup here
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
110 struct sk_buff *disc_init_msg(u32 type,
113 struct bearer *b_ptr)
115 struct sk_buff *buf = buf_acquire(DSC_H_SIZE);
116 struct tipc_msg *msg;
120 msg_init(msg, LINK_CONFIG, type, TIPC_OK, DSC_H_SIZE,
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);
132 * disc_recv_msg - handle incoming link setup message (request or response)
133 * @buf: buffer containing message
136 void disc_recv_msg(struct sk_buff *buf)
138 struct bearer *b_ptr = (struct bearer *)TIPC_SKB_CB(buf)->handle;
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);
147 msg_get_media_addr(msg,&media_addr);
148 msg_dbg(msg, "RECV:");
151 if (net_id != tipc_net_id)
153 if (!addr_domain_valid(dest))
155 if (!addr_node_valid(orig))
157 if (orig == tipc_own_addr)
159 if (!in_scope(dest, tipc_own_addr))
161 if (is_slave(tipc_own_addr) && is_slave(orig))
163 if (is_slave(orig) && !in_own_cluster(orig))
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);
171 dbg(" in own cluster\n");
173 n_ptr = node_create(orig);
176 warn("Memory squeeze; Failed to create node\n");
179 spin_lock_bh(&n_ptr->lock);
180 link = n_ptr->links[b_ptr->identity];
182 dbg("creating link\n");
183 link = link_create(b_ptr, orig, &media_addr);
185 spin_unlock_bh(&n_ptr->lock);
189 addr = &link->media_addr;
190 if (memcmp(addr, &media_addr, sizeof(*addr))) {
191 char addr_string[16];
193 warn("New bearer address for %s\n",
194 addr_string_fill(addr_string, orig));
195 memcpy(addr, &media_addr, sizeof(*addr));
198 link_up = link_is_up(link);
199 spin_unlock_bh(&n_ptr->lock);
200 if ((type == DSC_RESP_MSG) || link_up)
202 rbuf = disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr);
204 msg_dbg(buf_msg(rbuf),"SEND:");
205 b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr);
212 * disc_stop_link_req - stop sending periodic link setup requests
213 * @req: ptr to link request structure
216 void disc_stop_link_req(struct link_req *req)
221 k_cancel_timer(&req->timer);
222 k_term_timer(&req->timer);
223 buf_discard(req->buf);
228 * disc_update_link_req - update frequency of periodic link setup requests
229 * @req: ptr to link request structure
232 void disc_update_link_req(struct link_req *req)
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);
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);
248 /* leave timer "as is" if haven't yet reached a "normal" rate */
253 * disc_timeout - send a periodic link setup request
254 * @req: ptr to link request structure
256 * Called whenever a link setup request timer associated with a bearer expires.
259 static void disc_timeout(struct link_req *req)
261 struct tipc_msg *msg = buf_msg(req->buf);
263 spin_lock_bh(&req->bearer->publ.lock);
266 /* CURRENTLY DON'T SUPPORT INTER-ZONE LINKS */
267 u32 dest_domain = msg_dest_domain(msg);
269 if (!in_scope(dest_domain, tipc_own_addr)) {
270 struct _zone *z_ptr = zone_find(dest_domain);
272 if (z_ptr && (z_ptr->links >= msg_req_links(msg)))
274 if (req->timer_intv >= 32000)
278 k_cancel_timer(&req->timer);
279 buf_discard(req->buf);
281 spin_unlock_bh(&req->bearer->publ.lock);
286 msg_dbg(msg,"SEND:");
287 req->bearer->media->send_msg(req->buf, &req->bearer->publ, &req->dest);
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 */
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;
300 k_start_timer(&req->timer, req->timer_intv);
302 spin_unlock_bh(&req->bearer->publ.lock);
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
312 * Returns pointer to link request structure, or NULL if unable to create.
315 struct link_req *disc_init_link_req(struct bearer *b_ptr,
316 const struct tipc_media_addr *dest,
320 struct link_req *req;
322 req = (struct link_req *)kmalloc(sizeof(*req), GFP_ATOMIC);
326 req->buf = disc_init_msg(DSC_REQ_MSG, req_links, dest_domain, b_ptr);
332 memcpy(&req->dest, dest, sizeof(*dest));
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);