]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/tipc/net.c
tipc: Remove prototype code for supporting multiple clusters
[mirror_ubuntu-artful-kernel.git] / net / tipc / net.c
CommitLineData
b97bf3fd
PL
1/*
2 * net/tipc/net.c: TIPC network routing code
c4307285 3 *
593a5f22 4 * Copyright (c) 1995-2006, Ericsson AB
b97bf3fd 5 * Copyright (c) 2005, Wind River Systems
b97bf3fd
PL
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 *
9ea1fd3c
PL
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.
b97bf3fd
PL
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"
b97bf3fd 38#include "net.h"
b97bf3fd
PL
39#include "name_table.h"
40#include "name_distr.h"
41#include "subscr.h"
42#include "link.h"
b97bf3fd 43#include "port.h"
b97bf3fd
PL
44#include "config.h"
45
c4307285 46/*
b97bf3fd
PL
47 * The TIPC locking policy is designed to ensure a very fine locking
48 * granularity, permitting complete parallel access to individual
c4307285 49 * port and node/link instances. The code consists of three major
b97bf3fd
PL
50 * locking domains, each protected with their own disjunct set of locks.
51 *
52 * 1: The routing hierarchy.
c4307285
YH
53 * Comprises the structures 'zone', 'cluster', 'node', 'link'
54 * and 'bearer'. The whole hierarchy is protected by a big
55 * read/write lock, tipc_net_lock, to enssure that nothing is added
56 * or removed while code is accessing any of these structures.
57 * This layer must not be called from the two others while they
b97bf3fd
PL
58 * hold any of their own locks.
59 * Neither must it itself do any upcalls to the other two before
4323add6 60 * it has released tipc_net_lock and other protective locks.
b97bf3fd 61 *
c4307285 62 * Within the tipc_net_lock domain there are two sub-domains;'node' and
b97bf3fd
PL
63 * 'bearer', where local write operations are permitted,
64 * provided that those are protected by individual spin_locks
c4307285 65 * per instance. Code holding tipc_net_lock(read) and a node spin_lock
b97bf3fd 66 * is permitted to poke around in both the node itself and its
c4307285
YH
67 * subordinate links. I.e, it can update link counters and queues,
68 * change link state, send protocol messages, and alter the
69 * "active_links" array in the node; but it can _not_ remove a link
b97bf3fd 70 * or a node from the overall structure.
c4307285
YH
71 * Correspondingly, individual bearers may change status within a
72 * tipc_net_lock(read), protected by an individual spin_lock ber bearer
4323add6 73 * instance, but it needs tipc_net_lock(write) to remove/add any bearers.
b97bf3fd 74 *
c4307285
YH
75 *
76 * 2: The transport level of the protocol.
77 * This consists of the structures port, (and its user level
78 * representations, such as user_port and tipc_sock), reference and
79 * tipc_user (port.c, reg.c, socket.c).
b97bf3fd
PL
80 *
81 * This layer has four different locks:
82 * - The tipc_port spin_lock. This is protecting each port instance
c4307285
YH
83 * from parallel data access and removal. Since we can not place
84 * this lock in the port itself, it has been placed in the
b97bf3fd 85 * corresponding reference table entry, which has the same life
c4307285
YH
86 * cycle as the module. This entry is difficult to access from
87 * outside the TIPC core, however, so a pointer to the lock has
88 * been added in the port instance, -to be used for unlocking
b97bf3fd 89 * only.
c4307285
YH
90 * - A read/write lock to protect the reference table itself (teg.c).
91 * (Nobody is using read-only access to this, so it can just as
b97bf3fd
PL
92 * well be changed to a spin_lock)
93 * - A spin lock to protect the registry of kernel/driver users (reg.c)
c4307285 94 * - A global spin_lock (tipc_port_lock), which only task is to ensure
b97bf3fd
PL
95 * consistency where more than one port is involved in an operation,
96 * i.e., whe a port is part of a linked list of ports.
97 * There are two such lists; 'port_list', which is used for management,
98 * and 'wait_list', which is used to queue ports during congestion.
c4307285 99 *
b97bf3fd 100 * 3: The name table (name_table.c, name_distr.c, subscription.c)
c4307285
YH
101 * - There is one big read/write-lock (tipc_nametbl_lock) protecting the
102 * overall name table structure. Nothing must be added/removed to
b97bf3fd
PL
103 * this structure without holding write access to it.
104 * - There is one local spin_lock per sub_sequence, which can be seen
4323add6 105 * as a sub-domain to the tipc_nametbl_lock domain. It is used only
b97bf3fd
PL
106 * for translation operations, and is needed because a translation
107 * steps the root of the 'publication' linked list between each lookup.
4323add6 108 * This is always used within the scope of a tipc_nametbl_lock(read).
b97bf3fd
PL
109 * - A local spin_lock protecting the queue of subscriber events.
110*/
111
34af946a 112DEFINE_RWLOCK(tipc_net_lock);
51f98a8d 113struct network tipc_net;
b97bf3fd 114
8f92df6a
AS
115static int net_start(void)
116{
117 tipc_net.nodes = kcalloc(tipc_max_nodes + 1,
118 sizeof(*tipc_net.nodes), GFP_ATOMIC);
119 tipc_net.highest_node = 0;
120
121 return tipc_net.nodes ? 0 : -ENOMEM;
122}
123
4323add6 124static void net_stop(void)
b97bf3fd 125{
8f92df6a 126 u32 n_num;
b97bf3fd 127
8f92df6a
AS
128 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++)
129 tipc_node_delete(tipc_net.nodes[n_num]);
130 kfree(tipc_net.nodes);
131 tipc_net.nodes = NULL;
b97bf3fd
PL
132}
133
134static void net_route_named_msg(struct sk_buff *buf)
135{
136 struct tipc_msg *msg = buf_msg(buf);
137 u32 dnode;
138 u32 dport;
139
140 if (!msg_named(msg)) {
4323add6 141 msg_dbg(msg, "tipc_net->drop_nam:");
b97bf3fd
PL
142 buf_discard(buf);
143 return;
144 }
145
146 dnode = addr_domain(msg_lookup_scope(msg));
4323add6
PL
147 dport = tipc_nametbl_translate(msg_nametype(msg), msg_nameinst(msg), &dnode);
148 dbg("tipc_net->lookup<%u,%u>-><%u,%x>\n",
b97bf3fd
PL
149 msg_nametype(msg), msg_nameinst(msg), dport, dnode);
150 if (dport) {
151 msg_set_destnode(msg, dnode);
152 msg_set_destport(msg, dport);
4323add6 153 tipc_net_route_msg(buf);
b97bf3fd
PL
154 return;
155 }
4323add6 156 msg_dbg(msg, "tipc_net->rej:NO NAME: ");
b97bf3fd
PL
157 tipc_reject_msg(buf, TIPC_ERR_NO_NAME);
158}
159
4323add6 160void tipc_net_route_msg(struct sk_buff *buf)
b97bf3fd
PL
161{
162 struct tipc_msg *msg;
163 u32 dnode;
164
165 if (!buf)
166 return;
167 msg = buf_msg(buf);
168
169 msg_incr_reroute_cnt(msg);
170 if (msg_reroute_cnt(msg) > 6) {
171 if (msg_errcode(msg)) {
172 msg_dbg(msg, "NET>DISC>:");
173 buf_discard(buf);
174 } else {
175 msg_dbg(msg, "NET>REJ>:");
c4307285 176 tipc_reject_msg(buf, msg_destport(msg) ?
b97bf3fd
PL
177 TIPC_ERR_NO_PORT : TIPC_ERR_NO_NAME);
178 }
179 return;
180 }
181
4323add6 182 msg_dbg(msg, "tipc_net->rout: ");
b97bf3fd
PL
183
184 /* Handle message for this node */
185 dnode = msg_short(msg) ? tipc_own_addr : msg_destnode(msg);
c68ca7b7 186 if (tipc_in_scope(dnode, tipc_own_addr)) {
b97bf3fd 187 if (msg_isdata(msg)) {
c4307285 188 if (msg_mcast(msg))
4323add6 189 tipc_port_recv_mcast(buf, NULL);
b97bf3fd 190 else if (msg_destport(msg))
4323add6 191 tipc_port_recv_msg(buf);
b97bf3fd
PL
192 else
193 net_route_named_msg(buf);
194 return;
195 }
196 switch (msg_user(msg)) {
b97bf3fd 197 case NAME_DISTRIBUTOR:
4323add6 198 tipc_named_recv(buf);
b97bf3fd
PL
199 break;
200 case CONN_MANAGER:
4323add6 201 tipc_port_recv_proto_msg(buf);
b97bf3fd
PL
202 break;
203 default:
204 msg_dbg(msg,"DROP/NET/<REC<");
205 buf_discard(buf);
206 }
207 return;
208 }
209
210 /* Handle message for another node */
211 msg_dbg(msg, "NET>SEND>: ");
b2abd4c0 212 skb_trim(buf, msg_size(msg));
4323add6 213 tipc_link_send(buf, dnode, msg_link_selector(msg));
b97bf3fd
PL
214}
215
03194379 216int tipc_net_start(u32 addr)
b97bf3fd
PL
217{
218 char addr_string[16];
219 int res;
220
221 if (tipc_mode != TIPC_NODE_MODE)
222 return -ENOPROTOOPT;
223
03194379
AS
224 tipc_subscr_stop();
225 tipc_cfg_stop();
226
227 tipc_own_addr = addr;
b97bf3fd 228 tipc_mode = TIPC_NET_MODE;
4323add6
PL
229 tipc_named_reinit();
230 tipc_port_reinit();
b97bf3fd 231
8f92df6a
AS
232 res = net_start();
233 if (res)
234 return res;
235 res = tipc_bclink_init();
236 if (res)
b97bf3fd 237 return res;
03194379 238
4323add6
PL
239 tipc_k_signal((Handler)tipc_subscr_start, 0);
240 tipc_k_signal((Handler)tipc_cfg_init, 0);
03194379 241
b97bf3fd
PL
242 info("Started in network mode\n");
243 info("Own node address %s, network identity %u\n",
c68ca7b7 244 tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id);
0e35fd5e 245 return 0;
b97bf3fd
PL
246}
247
4323add6 248void tipc_net_stop(void)
b97bf3fd
PL
249{
250 if (tipc_mode != TIPC_NET_MODE)
251 return;
c4307285 252 write_lock_bh(&tipc_net_lock);
4323add6 253 tipc_bearer_stop();
b97bf3fd 254 tipc_mode = TIPC_NODE_MODE;
4323add6 255 tipc_bclink_stop();
b97bf3fd 256 net_stop();
c4307285 257 write_unlock_bh(&tipc_net_lock);
a570f095 258 info("Left network mode\n");
b97bf3fd
PL
259}
260