Blame view
net/tipc/node.c
13.8 KB
b97bf3fd8 [TIPC] Initial merge |
1 2 |
/* * net/tipc/node.c: TIPC node management routines |
c43072852 [NET] TIPC: Fix w... |
3 |
* |
593a5f22d [TIPC] More updat... |
4 |
* Copyright (c) 2000-2006, Ericsson AB |
2d627b92f tipc: Combine bea... |
5 |
* Copyright (c) 2005-2006, 2010-2011, Wind River Systems |
b97bf3fd8 [TIPC] Initial merge |
6 7 |
* All rights reserved. * |
9ea1fd3c1 [TIPC] License he... |
8 |
* Redistribution and use in source and binary forms, with or without |
b97bf3fd8 [TIPC] Initial merge |
9 10 |
* modification, are permitted provided that the following conditions are met: * |
9ea1fd3c1 [TIPC] License he... |
11 12 13 14 15 16 17 18 |
* 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the names of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. |
b97bf3fd8 [TIPC] Initial merge |
19 |
* |
9ea1fd3c1 [TIPC] License he... |
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
* Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
b97bf3fd8 [TIPC] Initial merge |
34 35 36 37 38 39 |
* POSSIBILITY OF SUCH DAMAGE. */ #include "core.h" #include "config.h" #include "node.h" |
b97bf3fd8 [TIPC] Initial merge |
40 |
#include "name_distr.h" |
b97bf3fd8 [TIPC] Initial merge |
41 |
|
6c00055a8 tipc: Don't use s... |
42 43 |
static void node_lost_contact(struct tipc_node *n_ptr); static void node_established_contact(struct tipc_node *n_ptr); |
b97bf3fd8 [TIPC] Initial merge |
44 |
|
2ecb0924d tipc: Prevent nod... |
45 |
static DEFINE_SPINLOCK(node_create_lock); |
672d99e19 tipc: Convert nod... |
46 47 48 |
static struct hlist_head node_htable[NODE_HTABLE_SIZE]; LIST_HEAD(tipc_node_list); static u32 tipc_num_nodes; |
34e46258c tipc: manually in... |
49 50 |
static atomic_t tipc_num_links = ATOMIC_INIT(0); |
e3ec9c7d5 tipc: remove zero... |
51 |
u32 tipc_own_tag; |
b97bf3fd8 [TIPC] Initial merge |
52 |
|
2ecb0924d tipc: Prevent nod... |
53 |
/** |
672d99e19 tipc: Convert nod... |
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
* tipc_node_find - locate specified node object, if it exists */ struct tipc_node *tipc_node_find(u32 addr) { struct tipc_node *node; struct hlist_node *pos; if (unlikely(!in_own_cluster(addr))) return NULL; hlist_for_each_entry(node, pos, &node_htable[tipc_hashfn(addr)], hash) { if (node->addr == addr) return node; } return NULL; } /** |
2ecb0924d tipc: Prevent nod... |
73 74 75 76 77 78 79 80 |
* tipc_node_create - create neighboring node * * Currently, this routine is called by neighbor discovery code, which holds * net_lock for reading only. We must take node_create_lock to ensure a node * isn't created twice if two different bearers discover the node at the same * time. (It would be preferable to switch to holding net_lock in write mode, * but this is a non-trivial change.) */ |
6c00055a8 tipc: Don't use s... |
81 |
struct tipc_node *tipc_node_create(u32 addr) |
b97bf3fd8 [TIPC] Initial merge |
82 |
{ |
672d99e19 tipc: Convert nod... |
83 |
struct tipc_node *n_ptr, *temp_node; |
b97bf3fd8 [TIPC] Initial merge |
84 |
|
2ecb0924d tipc: Prevent nod... |
85 |
spin_lock_bh(&node_create_lock); |
5af547929 tipc: Remove inte... |
86 87 88 89 |
n_ptr = tipc_node_find(addr); if (n_ptr) { spin_unlock_bh(&node_create_lock); return n_ptr; |
2ecb0924d tipc: Prevent nod... |
90 |
} |
5af547929 tipc: Remove inte... |
91 |
n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); |
a10bd924a [TIPC]: Enhanced ... |
92 |
if (!n_ptr) { |
2ecb0924d tipc: Prevent nod... |
93 |
spin_unlock_bh(&node_create_lock); |
a10bd924a [TIPC]: Enhanced ... |
94 95 96 97 |
warn("Node creation failed, no memory "); return NULL; } |
a10bd924a [TIPC]: Enhanced ... |
98 |
n_ptr->addr = addr; |
51a8e4dee tipc: Remove prot... |
99 |
spin_lock_init(&n_ptr->lock); |
672d99e19 tipc: Convert nod... |
100 101 |
INIT_HLIST_NODE(&n_ptr->hash); INIT_LIST_HEAD(&n_ptr->list); |
a10bd924a [TIPC]: Enhanced ... |
102 |
INIT_LIST_HEAD(&n_ptr->nsub); |
8f92df6ad tipc: Remove prot... |
103 |
|
672d99e19 tipc: Convert nod... |
104 105 106 107 108 109 110 |
hlist_add_head(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); list_for_each_entry(temp_node, &tipc_node_list, list) { if (n_ptr->addr < temp_node->addr) break; } list_add_tail(&n_ptr->list, &temp_node->list); |
b4b561022 tipc: Ensure both... |
111 |
n_ptr->block_setup = WAIT_PEER_DOWN; |
672d99e19 tipc: Convert nod... |
112 113 |
tipc_num_nodes++; |
a10bd924a [TIPC]: Enhanced ... |
114 |
|
2ecb0924d tipc: Prevent nod... |
115 |
spin_unlock_bh(&node_create_lock); |
b97bf3fd8 [TIPC] Initial merge |
116 117 |
return n_ptr; } |
6c00055a8 tipc: Don't use s... |
118 |
void tipc_node_delete(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
119 |
{ |
672d99e19 tipc: Convert nod... |
120 121 |
list_del(&n_ptr->list); hlist_del(&n_ptr->hash); |
b97bf3fd8 [TIPC] Initial merge |
122 |
kfree(n_ptr); |
8f92df6ad tipc: Remove prot... |
123 |
|
672d99e19 tipc: Convert nod... |
124 |
tipc_num_nodes--; |
b97bf3fd8 [TIPC] Initial merge |
125 126 127 128 |
} /** |
4323add67 [TIPC] Avoid poll... |
129 |
* tipc_node_link_up - handle addition of link |
c43072852 [NET] TIPC: Fix w... |
130 |
* |
b97bf3fd8 [TIPC] Initial merge |
131 132 |
* Link becomes active (alone or shared) or standby, depending on its priority. */ |
a18c4bc3e tipc: rename stru... |
133 |
void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
b97bf3fd8 [TIPC] Initial merge |
134 |
{ |
a18c4bc3e tipc: rename stru... |
135 |
struct tipc_link **active = &n_ptr->active_links[0]; |
b97bf3fd8 [TIPC] Initial merge |
136 |
|
5392d6468 [TIPC]: Fixed lin... |
137 |
n_ptr->working_links++; |
b97bf3fd8 [TIPC] Initial merge |
138 139 140 |
info("Established link <%s> on network plane %c ", l_ptr->name, l_ptr->b_ptr->net_plane); |
c43072852 [NET] TIPC: Fix w... |
141 |
|
b97bf3fd8 [TIPC] Initial merge |
142 |
if (!active[0]) { |
b97bf3fd8 [TIPC] Initial merge |
143 144 145 146 |
active[0] = active[1] = l_ptr; node_established_contact(n_ptr); return; } |
c43072852 [NET] TIPC: Fix w... |
147 |
if (l_ptr->priority < active[0]->priority) { |
a10bd924a [TIPC]: Enhanced ... |
148 149 |
info("New link <%s> becomes standby ", l_ptr->name); |
b97bf3fd8 [TIPC] Initial merge |
150 151 |
return; } |
4323add67 [TIPC] Avoid poll... |
152 |
tipc_link_send_duplicate(active[0], l_ptr); |
c43072852 [NET] TIPC: Fix w... |
153 |
if (l_ptr->priority == active[0]->priority) { |
b97bf3fd8 [TIPC] Initial merge |
154 155 156 |
active[0] = l_ptr; return; } |
a10bd924a [TIPC]: Enhanced ... |
157 158 159 160 161 |
info("Old link <%s> becomes standby ", active[0]->name); if (active[1] != active[0]) info("Old link <%s> becomes standby ", active[1]->name); |
b97bf3fd8 [TIPC] Initial merge |
162 163 164 165 166 167 |
active[0] = active[1] = l_ptr; } /** * node_select_active_links - select active link */ |
6c00055a8 tipc: Don't use s... |
168 |
static void node_select_active_links(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
169 |
{ |
a18c4bc3e tipc: rename stru... |
170 |
struct tipc_link **active = &n_ptr->active_links[0]; |
b97bf3fd8 [TIPC] Initial merge |
171 172 |
u32 i; u32 highest_prio = 0; |
c43072852 [NET] TIPC: Fix w... |
173 |
active[0] = active[1] = NULL; |
b97bf3fd8 [TIPC] Initial merge |
174 175 |
for (i = 0; i < MAX_BEARERS; i++) { |
a18c4bc3e tipc: rename stru... |
176 |
struct tipc_link *l_ptr = n_ptr->links[i]; |
b97bf3fd8 [TIPC] Initial merge |
177 |
|
4323add67 [TIPC] Avoid poll... |
178 |
if (!l_ptr || !tipc_link_is_up(l_ptr) || |
b97bf3fd8 [TIPC] Initial merge |
179 180 181 182 |
(l_ptr->priority < highest_prio)) continue; if (l_ptr->priority > highest_prio) { |
c43072852 [NET] TIPC: Fix w... |
183 |
highest_prio = l_ptr->priority; |
b97bf3fd8 [TIPC] Initial merge |
184 185 186 187 188 189 190 191 |
active[0] = active[1] = l_ptr; } else { active[1] = l_ptr; } } } /** |
4323add67 [TIPC] Avoid poll... |
192 |
* tipc_node_link_down - handle loss of link |
b97bf3fd8 [TIPC] Initial merge |
193 |
*/ |
a18c4bc3e tipc: rename stru... |
194 |
void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
b97bf3fd8 [TIPC] Initial merge |
195 |
{ |
a18c4bc3e tipc: rename stru... |
196 |
struct tipc_link **active; |
b97bf3fd8 [TIPC] Initial merge |
197 |
|
5392d6468 [TIPC]: Fixed lin... |
198 |
n_ptr->working_links--; |
4323add67 [TIPC] Avoid poll... |
199 |
if (!tipc_link_is_active(l_ptr)) { |
b97bf3fd8 [TIPC] Initial merge |
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
info("Lost standby link <%s> on network plane %c ", l_ptr->name, l_ptr->b_ptr->net_plane); return; } info("Lost link <%s> on network plane %c ", l_ptr->name, l_ptr->b_ptr->net_plane); active = &n_ptr->active_links[0]; if (active[0] == l_ptr) active[0] = active[1]; if (active[1] == l_ptr) active[1] = active[0]; if (active[0] == l_ptr) node_select_active_links(n_ptr); |
c43072852 [NET] TIPC: Fix w... |
216 |
if (tipc_node_is_up(n_ptr)) |
4323add67 [TIPC] Avoid poll... |
217 |
tipc_link_changeover(l_ptr); |
c43072852 [NET] TIPC: Fix w... |
218 |
else |
b97bf3fd8 [TIPC] Initial merge |
219 220 |
node_lost_contact(n_ptr); } |
8f19afb2d tipc: cosmetic - ... |
221 |
int tipc_node_active_links(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
222 |
{ |
76ae0d71d tipc: Optimize ti... |
223 |
return n_ptr->active_links[0] != NULL; |
b97bf3fd8 [TIPC] Initial merge |
224 |
} |
8f19afb2d tipc: cosmetic - ... |
225 |
int tipc_node_redundant_links(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
226 |
{ |
a02cec215 net: return opera... |
227 |
return n_ptr->working_links > 1; |
b97bf3fd8 [TIPC] Initial merge |
228 |
} |
6c00055a8 tipc: Don't use s... |
229 |
int tipc_node_is_up(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
230 |
{ |
8f19afb2d tipc: cosmetic - ... |
231 |
return tipc_node_active_links(n_ptr); |
b97bf3fd8 [TIPC] Initial merge |
232 |
} |
a18c4bc3e tipc: rename stru... |
233 |
void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
b97bf3fd8 [TIPC] Initial merge |
234 |
{ |
37b9c08a8 tipc: Optimizatio... |
235 236 237 |
n_ptr->links[l_ptr->b_ptr->identity] = l_ptr; atomic_inc(&tipc_num_links); n_ptr->link_cnt++; |
b97bf3fd8 [TIPC] Initial merge |
238 |
} |
a18c4bc3e tipc: rename stru... |
239 |
void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
b97bf3fd8 [TIPC] Initial merge |
240 |
{ |
1fc54d8f4 [TIPC]: Fix simpl... |
241 |
n_ptr->links[l_ptr->b_ptr->identity] = NULL; |
d1bcb1154 tipc: Split up un... |
242 |
atomic_dec(&tipc_num_links); |
b97bf3fd8 [TIPC] Initial merge |
243 244 245 246 247 248 249 |
n_ptr->link_cnt--; } /* * Routing table management - five cases to handle: * * 1: A link towards a zone/cluster external node comes up. |
c43072852 [NET] TIPC: Fix w... |
250 251 252 |
* => Send a multicast message updating routing tables of all * system nodes within own cluster that the new destination * can be reached via this node. |
b97bf3fd8 [TIPC] Initial merge |
253 254 255 |
* (node.establishedContact()=>cluster.multicastNewRoute()) * * 2: A link towards a slave node comes up. |
c43072852 [NET] TIPC: Fix w... |
256 257 258 |
* => Send a multicast message updating routing tables of all * system nodes within own cluster that the new destination * can be reached via this node. |
b97bf3fd8 [TIPC] Initial merge |
259 |
* (node.establishedContact()=>cluster.multicastNewRoute()) |
c43072852 [NET] TIPC: Fix w... |
260 |
* => Send a message to the slave node about existence |
b97bf3fd8 [TIPC] Initial merge |
261 262 263 264 265 266 267 268 269 |
* of all system nodes within cluster: * (node.establishedContact()=>cluster.sendLocalRoutes()) * * 3: A new cluster local system node becomes available. * => Send message(s) to this particular node containing * information about all cluster external and slave * nodes which can be reached via this node. * (node.establishedContact()==>network.sendExternalRoutes()) * (node.establishedContact()==>network.sendSlaveRoutes()) |
c43072852 [NET] TIPC: Fix w... |
270 |
* => Send messages to all directly connected slave nodes |
b97bf3fd8 [TIPC] Initial merge |
271 272 |
* containing information about the existence of the new node * (node.establishedContact()=>cluster.multicastNewRoute()) |
c43072852 [NET] TIPC: Fix w... |
273 |
* |
b97bf3fd8 [TIPC] Initial merge |
274 275 |
* 4: The link towards a zone/cluster external node or slave * node goes down. |
c43072852 [NET] TIPC: Fix w... |
276 |
* => Send a multcast message updating routing tables of all |
b97bf3fd8 [TIPC] Initial merge |
277 278 279 280 281 282 283 284 285 |
* nodes within cluster that the new destination can not any * longer be reached via this node. * (node.lostAllLinks()=>cluster.bcastLostRoute()) * * 5: A cluster local system node becomes unavailable. * => Remove all references to this node from the local * routing tables. Note: This is a completely node * local operation. * (node.lostAllLinks()=>network.removeAsRouter()) |
c43072852 [NET] TIPC: Fix w... |
286 |
* => Send messages to all directly connected slave nodes |
b97bf3fd8 [TIPC] Initial merge |
287 288 289 290 |
* containing information about loss of the node * (node.establishedContact()=>cluster.multicastLostRoute()) * */ |
6c00055a8 tipc: Don't use s... |
291 |
static void node_established_contact(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
292 |
{ |
51a8e4dee tipc: Remove prot... |
293 |
tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr); |
b97bf3fd8 [TIPC] Initial merge |
294 |
|
c43072852 [NET] TIPC: Fix w... |
295 296 |
/* Syncronize broadcast acks */ n_ptr->bclink.acked = tipc_bclink_get_last_sent(); |
b97bf3fd8 [TIPC] Initial merge |
297 |
|
b97bf3fd8 [TIPC] Initial merge |
298 |
if (n_ptr->bclink.supported) { |
cd3decdfd tipc: Ensure broa... |
299 |
tipc_bclink_add_node(n_ptr->addr); |
b97bf3fd8 [TIPC] Initial merge |
300 301 302 |
if (n_ptr->addr < tipc_own_addr) tipc_own_tag++; } |
b97bf3fd8 [TIPC] Initial merge |
303 |
} |
b4b561022 tipc: Ensure both... |
304 |
static void node_name_purge_complete(unsigned long node_addr) |
5a68d5ee0 tipc: Prevent mis... |
305 306 307 308 309 310 311 |
{ struct tipc_node *n_ptr; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(node_addr); if (n_ptr) { tipc_node_lock(n_ptr); |
b4b561022 tipc: Ensure both... |
312 |
n_ptr->block_setup &= ~WAIT_NAMES_GONE; |
5a68d5ee0 tipc: Prevent mis... |
313 314 315 316 |
tipc_node_unlock(n_ptr); } read_unlock_bh(&tipc_net_lock); } |
6c00055a8 tipc: Don't use s... |
317 |
static void node_lost_contact(struct tipc_node *n_ptr) |
b97bf3fd8 [TIPC] Initial merge |
318 |
{ |
b97bf3fd8 [TIPC] Initial merge |
319 320 |
char addr_string[16]; u32 i; |
c5bd4d85d tipc: Enhance cle... |
321 322 323 324 325 |
info("Lost contact with %s ", tipc_addr_string_fill(addr_string, n_ptr->addr)); /* Flush broadcast link info associated with lost node */ |
c43072852 [NET] TIPC: Fix w... |
326 |
|
51a8e4dee tipc: Remove prot... |
327 |
if (n_ptr->bclink.supported) { |
c5bd4d85d tipc: Enhance cle... |
328 329 330 331 332 333 334 335 336 337 338 |
n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0; while (n_ptr->bclink.deferred_head) { struct sk_buff *buf = n_ptr->bclink.deferred_head; n_ptr->bclink.deferred_head = buf->next; buf_discard(buf); } if (n_ptr->bclink.defragm) { buf_discard(n_ptr->bclink.defragm); n_ptr->bclink.defragm = NULL; } |
cd3decdfd tipc: Ensure broa... |
339 |
tipc_bclink_remove_node(n_ptr->addr); |
365595914 tipc: Ignore broa... |
340 |
tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ); |
51a8e4dee tipc: Remove prot... |
341 342 |
if (n_ptr->addr < tipc_own_addr) tipc_own_tag--; |
b97bf3fd8 [TIPC] Initial merge |
343 |
|
c5bd4d85d tipc: Enhance cle... |
344 345 |
n_ptr->bclink.supported = 0; } |
b97bf3fd8 [TIPC] Initial merge |
346 347 348 |
/* Abort link changeover */ for (i = 0; i < MAX_BEARERS; i++) { |
a18c4bc3e tipc: rename stru... |
349 |
struct tipc_link *l_ptr = n_ptr->links[i]; |
c43072852 [NET] TIPC: Fix w... |
350 |
if (!l_ptr) |
b97bf3fd8 [TIPC] Initial merge |
351 352 353 |
continue; l_ptr->reset_checkpoint = l_ptr->next_in_no; l_ptr->exp_msg_count = 0; |
4323add67 [TIPC] Avoid poll... |
354 |
tipc_link_reset_fragments(l_ptr); |
b97bf3fd8 [TIPC] Initial merge |
355 356 357 |
} /* Notify subscribers */ |
f13791733 tipc: Cosmetic ch... |
358 |
tipc_nodesub_notify(n_ptr); |
5a68d5ee0 tipc: Prevent mis... |
359 |
|
b4b561022 tipc: Ensure both... |
360 |
/* Prevent re-contact with node until cleanup is done */ |
5a68d5ee0 tipc: Prevent mis... |
361 |
|
b4b561022 tipc: Ensure both... |
362 363 |
n_ptr->block_setup = WAIT_PEER_DOWN | WAIT_NAMES_GONE; tipc_k_signal((Handler)node_name_purge_complete, n_ptr->addr); |
b97bf3fd8 [TIPC] Initial merge |
364 |
} |
4323add67 [TIPC] Avoid poll... |
365 |
struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd8 [TIPC] Initial merge |
366 367 368 |
{ u32 domain; struct sk_buff *buf; |
6c00055a8 tipc: Don't use s... |
369 |
struct tipc_node *n_ptr; |
c43072852 [NET] TIPC: Fix w... |
370 |
struct tipc_node_info node_info; |
ea13847b2 [TIPC]: Improve r... |
371 |
u32 payload_size; |
b97bf3fd8 [TIPC] Initial merge |
372 373 |
if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) |
4323add67 [TIPC] Avoid poll... |
374 |
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd8 [TIPC] Initial merge |
375 |
|
3e6c8cd56 [TIPC]: endiannes... |
376 |
domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
4323add67 [TIPC] Avoid poll... |
377 378 379 |
if (!tipc_addr_domain_valid(domain)) return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE " (network address)"); |
b97bf3fd8 [TIPC] Initial merge |
380 |
|
1aad72d6c tipc: Add missing... |
381 |
read_lock_bh(&tipc_net_lock); |
672d99e19 tipc: Convert nod... |
382 |
if (!tipc_num_nodes) { |
1aad72d6c tipc: Add missing... |
383 |
read_unlock_bh(&tipc_net_lock); |
c43072852 [NET] TIPC: Fix w... |
384 |
return tipc_cfg_reply_none(); |
1aad72d6c tipc: Add missing... |
385 |
} |
b97bf3fd8 [TIPC] Initial merge |
386 |
|
08c80e9a0 tipc: Remove prot... |
387 |
/* For now, get space for all other nodes */ |
b97bf3fd8 [TIPC] Initial merge |
388 |
|
672d99e19 tipc: Convert nod... |
389 |
payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes; |
1aad72d6c tipc: Add missing... |
390 391 |
if (payload_size > 32768u) { read_unlock_bh(&tipc_net_lock); |
ea13847b2 [TIPC]: Improve r... |
392 393 |
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED " (too many nodes)"); |
1aad72d6c tipc: Add missing... |
394 |
} |
ea13847b2 [TIPC]: Improve r... |
395 |
buf = tipc_cfg_reply_alloc(payload_size); |
1aad72d6c tipc: Add missing... |
396 397 |
if (!buf) { read_unlock_bh(&tipc_net_lock); |
b97bf3fd8 [TIPC] Initial merge |
398 |
return NULL; |
1aad72d6c tipc: Add missing... |
399 |
} |
b97bf3fd8 [TIPC] Initial merge |
400 401 |
/* Add TLVs for all nodes in scope */ |
672d99e19 tipc: Convert nod... |
402 403 |
list_for_each_entry(n_ptr, &tipc_node_list, list) { if (!tipc_in_scope(domain, n_ptr->addr)) |
b97bf3fd8 [TIPC] Initial merge |
404 |
continue; |
c43072852 [NET] TIPC: Fix w... |
405 406 407 |
node_info.addr = htonl(n_ptr->addr); node_info.up = htonl(tipc_node_is_up(n_ptr)); tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO, |
4323add67 [TIPC] Avoid poll... |
408 |
&node_info, sizeof(node_info)); |
b97bf3fd8 [TIPC] Initial merge |
409 |
} |
1aad72d6c tipc: Add missing... |
410 |
read_unlock_bh(&tipc_net_lock); |
b97bf3fd8 [TIPC] Initial merge |
411 412 |
return buf; } |
4323add67 [TIPC] Avoid poll... |
413 |
struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd8 [TIPC] Initial merge |
414 415 416 |
{ u32 domain; struct sk_buff *buf; |
6c00055a8 tipc: Don't use s... |
417 |
struct tipc_node *n_ptr; |
c43072852 [NET] TIPC: Fix w... |
418 |
struct tipc_link_info link_info; |
ea13847b2 [TIPC]: Improve r... |
419 |
u32 payload_size; |
b97bf3fd8 [TIPC] Initial merge |
420 421 |
if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) |
4323add67 [TIPC] Avoid poll... |
422 |
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd8 [TIPC] Initial merge |
423 |
|
3e6c8cd56 [TIPC]: endiannes... |
424 |
domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
4323add67 [TIPC] Avoid poll... |
425 426 427 |
if (!tipc_addr_domain_valid(domain)) return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE " (network address)"); |
b97bf3fd8 [TIPC] Initial merge |
428 |
|
c43072852 [NET] TIPC: Fix w... |
429 430 |
if (tipc_mode != TIPC_NET_MODE) return tipc_cfg_reply_none(); |
1aad72d6c tipc: Add missing... |
431 |
read_lock_bh(&tipc_net_lock); |
ea13847b2 [TIPC]: Improve r... |
432 |
/* Get space for all unicast links + multicast link */ |
9df3b7eb6 tipc: Fix problem... |
433 |
payload_size = TLV_SPACE(sizeof(link_info)) * |
d1bcb1154 tipc: Split up un... |
434 |
(atomic_read(&tipc_num_links) + 1); |
1aad72d6c tipc: Add missing... |
435 436 |
if (payload_size > 32768u) { read_unlock_bh(&tipc_net_lock); |
ea13847b2 [TIPC]: Improve r... |
437 438 |
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED " (too many links)"); |
1aad72d6c tipc: Add missing... |
439 |
} |
ea13847b2 [TIPC]: Improve r... |
440 |
buf = tipc_cfg_reply_alloc(payload_size); |
1aad72d6c tipc: Add missing... |
441 442 |
if (!buf) { read_unlock_bh(&tipc_net_lock); |
b97bf3fd8 [TIPC] Initial merge |
443 |
return NULL; |
1aad72d6c tipc: Add missing... |
444 |
} |
b97bf3fd8 [TIPC] Initial merge |
445 446 |
/* Add TLV for broadcast link */ |
a3796f895 tipc: Add network... |
447 |
link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr)); |
c43072852 [NET] TIPC: Fix w... |
448 |
link_info.up = htonl(1); |
4b704d59d tipc: fix non-con... |
449 |
strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME); |
4323add67 [TIPC] Avoid poll... |
450 |
tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); |
b97bf3fd8 [TIPC] Initial merge |
451 452 |
/* Add TLVs for any other links in scope */ |
672d99e19 tipc: Convert nod... |
453 |
list_for_each_entry(n_ptr, &tipc_node_list, list) { |
c43072852 [NET] TIPC: Fix w... |
454 |
u32 i; |
b97bf3fd8 [TIPC] Initial merge |
455 |
|
672d99e19 tipc: Convert nod... |
456 |
if (!tipc_in_scope(domain, n_ptr->addr)) |
b97bf3fd8 [TIPC] Initial merge |
457 |
continue; |
1aad72d6c tipc: Add missing... |
458 |
tipc_node_lock(n_ptr); |
c43072852 [NET] TIPC: Fix w... |
459 460 461 462 463 464 465 |
for (i = 0; i < MAX_BEARERS; i++) { if (!n_ptr->links[i]) continue; link_info.dest = htonl(n_ptr->addr); link_info.up = htonl(tipc_link_is_up(n_ptr->links[i])); strcpy(link_info.str, n_ptr->links[i]->name); tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, |
4323add67 [TIPC] Avoid poll... |
466 |
&link_info, sizeof(link_info)); |
c43072852 [NET] TIPC: Fix w... |
467 |
} |
1aad72d6c tipc: Add missing... |
468 |
tipc_node_unlock(n_ptr); |
b97bf3fd8 [TIPC] Initial merge |
469 |
} |
1aad72d6c tipc: Add missing... |
470 |
read_unlock_bh(&tipc_net_lock); |
b97bf3fd8 [TIPC] Initial merge |
471 472 |
return buf; } |