tipc: Eliminate duplication of media structures
[deliverable/linux.git] / net / tipc / bearer.c
CommitLineData
b97bf3fd
PL
1/*
2 * net/tipc/bearer.c: TIPC bearer code
c4307285 3 *
593a5f22 4 * Copyright (c) 1996-2006, Ericsson AB
2d627b92 5 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
b97bf3fd
PL
6 * All rights reserved.
7 *
9ea1fd3c 8 * Redistribution and use in source and binary forms, with or without
b97bf3fd
PL
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.
b97bf3fd 19 *
9ea1fd3c
PL
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
b97bf3fd
PL
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "config.h"
b97bf3fd 39#include "bearer.h"
b97bf3fd 40#include "discover.h"
b97bf3fd
PL
41
42#define MAX_ADDR_STR 32
43
a31abe8d 44static struct media *media_list[MAX_MEDIA];
e3ec9c7d 45static u32 media_count;
b97bf3fd 46
2d627b92 47struct tipc_bearer tipc_bearers[MAX_BEARERS];
b97bf3fd 48
3a777ff8
AS
49static void bearer_disable(struct tipc_bearer *b_ptr);
50
b97bf3fd
PL
51/**
52 * media_name_valid - validate media name
c4307285 53 *
b97bf3fd
PL
54 * Returns 1 if media name is valid, otherwise 0.
55 */
56
57static int media_name_valid(const char *name)
58{
59 u32 len;
60
61 len = strlen(name);
62 if ((len + 1) > TIPC_MAX_MEDIA_NAME)
63 return 0;
a02cec21 64 return strspn(name, tipc_alphabet) == len;
b97bf3fd
PL
65}
66
67/**
68 * media_find - locates specified media object by name
69 */
70
71static struct media *media_find(const char *name)
72{
b97bf3fd
PL
73 u32 i;
74
a31abe8d
AS
75 for (i = 0; i < media_count; i++) {
76 if (!strcmp(media_list[i]->name, name))
77 return media_list[i];
b97bf3fd 78 }
1fc54d8f 79 return NULL;
b97bf3fd
PL
80}
81
c79be454
AS
82/**
83 * media_find_id - locates specified media object by type identifier
84 */
85
86static struct media *media_find_id(u8 type)
87{
88 u32 i;
89
90 for (i = 0; i < media_count; i++) {
a31abe8d
AS
91 if (media_list[i]->type_id == type)
92 return media_list[i];
c79be454
AS
93 }
94 return NULL;
95}
96
b97bf3fd
PL
97/**
98 * tipc_register_media - register a media type
c4307285 99 *
b97bf3fd
PL
100 * Bearers for this media type must be activated separately at a later stage.
101 */
102
706767da 103int tipc_register_media(struct media *m_ptr)
b97bf3fd 104{
b97bf3fd
PL
105 int res = -EINVAL;
106
4323add6 107 write_lock_bh(&tipc_net_lock);
b97bf3fd 108
d0021b25 109 if (tipc_mode != TIPC_NET_MODE) {
706767da
AS
110 warn("Media <%s> rejected, not in networked mode yet\n",
111 m_ptr->name);
d0021b25
NH
112 goto exit;
113 }
706767da
AS
114 if (!media_name_valid(m_ptr->name)) {
115 warn("Media <%s> rejected, illegal name\n", m_ptr->name);
b97bf3fd
PL
116 goto exit;
117 }
706767da
AS
118 if (m_ptr->bcast_addr.type != htonl(m_ptr->type_id)) {
119 warn("Media <%s> rejected, illegal broadcast address\n",
120 m_ptr->name);
b97bf3fd
PL
121 goto exit;
122 }
706767da
AS
123 if ((m_ptr->priority < TIPC_MIN_LINK_PRI) ||
124 (m_ptr->priority > TIPC_MAX_LINK_PRI)) {
125 warn("Media <%s> rejected, illegal priority (%u)\n",
126 m_ptr->name, m_ptr->priority);
b97bf3fd
PL
127 goto exit;
128 }
706767da
AS
129 if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
130 (m_ptr->tolerance > TIPC_MAX_LINK_TOL)) {
131 warn("Media <%s> rejected, illegal tolerance (%u)\n",
132 m_ptr->name, m_ptr->tolerance);
b97bf3fd
PL
133 goto exit;
134 }
135
c79be454 136 if (media_count >= MAX_MEDIA) {
706767da
AS
137 warn("Media <%s> rejected, media limit reached (%u)\n",
138 m_ptr->name, MAX_MEDIA);
b97bf3fd
PL
139 goto exit;
140 }
c79be454
AS
141 if (media_find(m_ptr->name) || media_find_id(m_ptr->type_id)) {
142 warn("Media <%s> rejected, already registered\n", m_ptr->name);
143 goto exit;
b97bf3fd
PL
144 }
145
a31abe8d 146 media_list[media_count] = m_ptr;
c79be454 147 media_count++;
b97bf3fd
PL
148 res = 0;
149exit:
4323add6 150 write_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
151 return res;
152}
153
154/**
4323add6 155 * tipc_media_addr_printf - record media address in print buffer
b97bf3fd
PL
156 */
157
4323add6 158void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
b97bf3fd
PL
159{
160 struct media *m_ptr;
161 u32 media_type;
162 u32 i;
163
164 media_type = ntohl(a->type);
a31abe8d 165 m_ptr = media_find_id(media_type);
b97bf3fd 166
a31abe8d 167 if (m_ptr && (m_ptr->addr2str != NULL)) {
b97bf3fd
PL
168 char addr_str[MAX_ADDR_STR];
169
e91ed0bc 170 tipc_printf(pb, "%s(%s)", m_ptr->name,
b97bf3fd
PL
171 m_ptr->addr2str(a, addr_str, sizeof(addr_str)));
172 } else {
173 unchar *addr = (unchar *)&a->dev_addr;
174
e91ed0bc 175 tipc_printf(pb, "UNKNOWN(%u)", media_type);
a016892c 176 for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
e91ed0bc 177 tipc_printf(pb, "-%02x", addr[i]);
b97bf3fd
PL
178 }
179}
180
181/**
4323add6 182 * tipc_media_get_names - record names of registered media in buffer
b97bf3fd
PL
183 */
184
4323add6 185struct sk_buff *tipc_media_get_names(void)
b97bf3fd
PL
186{
187 struct sk_buff *buf;
b97bf3fd
PL
188 int i;
189
4323add6 190 buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
b97bf3fd
PL
191 if (!buf)
192 return NULL;
193
4323add6 194 read_lock_bh(&tipc_net_lock);
a31abe8d
AS
195 for (i = 0; i < media_count; i++) {
196 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
197 media_list[i]->name,
198 strlen(media_list[i]->name) + 1);
b97bf3fd 199 }
4323add6 200 read_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
201 return buf;
202}
203
204/**
205 * bearer_name_validate - validate & (optionally) deconstruct bearer name
206 * @name - ptr to bearer name string
207 * @name_parts - ptr to area for bearer name components (or NULL if not needed)
c4307285 208 *
b97bf3fd
PL
209 * Returns 1 if bearer name is valid, otherwise 0.
210 */
211
c4307285 212static int bearer_name_validate(const char *name,
b97bf3fd
PL
213 struct bearer_name *name_parts)
214{
215 char name_copy[TIPC_MAX_BEARER_NAME];
216 char *media_name;
217 char *if_name;
218 u32 media_len;
219 u32 if_len;
220
221 /* copy bearer name & ensure length is OK */
222
223 name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
224 /* need above in case non-Posix strncpy() doesn't pad with nulls */
225 strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
226 if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
227 return 0;
228
229 /* ensure all component parts of bearer name are present */
230
231 media_name = name_copy;
2db9983a
AS
232 if_name = strchr(media_name, ':');
233 if (if_name == NULL)
b97bf3fd
PL
234 return 0;
235 *(if_name++) = 0;
236 media_len = if_name - media_name;
237 if_len = strlen(if_name) + 1;
238
239 /* validate component parts of bearer name */
240
c4307285
YH
241 if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
242 (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME) ||
b97bf3fd
PL
243 (strspn(media_name, tipc_alphabet) != (media_len - 1)) ||
244 (strspn(if_name, tipc_alphabet) != (if_len - 1)))
245 return 0;
246
247 /* return bearer name components, if necessary */
248
249 if (name_parts) {
250 strcpy(name_parts->media_name, media_name);
251 strcpy(name_parts->if_name, if_name);
252 }
253 return 1;
254}
255
256/**
257 * bearer_find - locates bearer object with matching bearer name
258 */
259
2d627b92 260static struct tipc_bearer *bearer_find(const char *name)
b97bf3fd 261{
2d627b92 262 struct tipc_bearer *b_ptr;
b97bf3fd
PL
263 u32 i;
264
4323add6 265 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
2d627b92 266 if (b_ptr->active && (!strcmp(b_ptr->name, name)))
b97bf3fd
PL
267 return b_ptr;
268 }
1fc54d8f 269 return NULL;
b97bf3fd
PL
270}
271
272/**
4323add6 273 * tipc_bearer_find_interface - locates bearer object with matching interface name
b97bf3fd
PL
274 */
275
2d627b92 276struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
b97bf3fd 277{
2d627b92 278 struct tipc_bearer *b_ptr;
b97bf3fd
PL
279 char *b_if_name;
280 u32 i;
281
4323add6 282 for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
b97bf3fd
PL
283 if (!b_ptr->active)
284 continue;
2d627b92 285 b_if_name = strchr(b_ptr->name, ':') + 1;
b97bf3fd
PL
286 if (!strcmp(b_if_name, if_name))
287 return b_ptr;
288 }
1fc54d8f 289 return NULL;
b97bf3fd
PL
290}
291
292/**
4323add6 293 * tipc_bearer_get_names - record names of bearers in buffer
b97bf3fd
PL
294 */
295
4323add6 296struct sk_buff *tipc_bearer_get_names(void)
b97bf3fd
PL
297{
298 struct sk_buff *buf;
2d627b92 299 struct tipc_bearer *b_ptr;
b97bf3fd
PL
300 int i, j;
301
4323add6 302 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
b97bf3fd
PL
303 if (!buf)
304 return NULL;
305
4323add6 306 read_lock_bh(&tipc_net_lock);
a31abe8d 307 for (i = 0; i < media_count; i++) {
b97bf3fd 308 for (j = 0; j < MAX_BEARERS; j++) {
4323add6 309 b_ptr = &tipc_bearers[j];
a31abe8d 310 if (b_ptr->active && (b_ptr->media == media_list[i])) {
c4307285 311 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
2d627b92
AS
312 b_ptr->name,
313 strlen(b_ptr->name) + 1);
b97bf3fd
PL
314 }
315 }
316 }
4323add6 317 read_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
318 return buf;
319}
320
2d627b92 321void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
b97bf3fd 322{
4323add6 323 tipc_nmap_add(&b_ptr->nodes, dest);
4323add6 324 tipc_bcbearer_sort();
1209966c 325 tipc_disc_add_dest(b_ptr->link_req);
b97bf3fd
PL
326}
327
2d627b92 328void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
b97bf3fd 329{
4323add6 330 tipc_nmap_remove(&b_ptr->nodes, dest);
4323add6 331 tipc_bcbearer_sort();
1209966c 332 tipc_disc_remove_dest(b_ptr->link_req);
b97bf3fd
PL
333}
334
335/*
336 * bearer_push(): Resolve bearer congestion. Force the waiting
337 * links to push out their unsent packets, one packet per link
338 * per iteration, until all packets are gone or congestion reoccurs.
4323add6 339 * 'tipc_net_lock' is read_locked when this function is called
b97bf3fd
PL
340 * bearer.lock must be taken before calling
341 * Returns binary true(1) ore false(0)
342 */
2d627b92 343static int bearer_push(struct tipc_bearer *b_ptr)
b97bf3fd 344{
0e35fd5e 345 u32 res = 0;
b97bf3fd
PL
346 struct link *ln, *tln;
347
2d627b92 348 if (b_ptr->blocked)
b97bf3fd
PL
349 return 0;
350
351 while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
352 list_for_each_entry_safe(ln, tln, &b_ptr->cong_links, link_list) {
4323add6 353 res = tipc_link_push_packet(ln);
b97bf3fd
PL
354 if (res == PUSH_FAILED)
355 break;
356 if (res == PUSH_FINISHED)
357 list_move_tail(&ln->link_list, &b_ptr->links);
358 }
359 }
360 return list_empty(&b_ptr->cong_links);
361}
362
2d627b92 363void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
b97bf3fd 364{
2d627b92 365 spin_lock_bh(&b_ptr->lock);
23f0ff90 366 bearer_push(b_ptr);
2d627b92 367 spin_unlock_bh(&b_ptr->lock);
b97bf3fd
PL
368}
369
370
371/*
c4307285
YH
372 * Interrupt enabling new requests after bearer congestion or blocking:
373 * See bearer_send().
b97bf3fd 374 */
2d627b92 375void tipc_continue(struct tipc_bearer *b_ptr)
b97bf3fd 376{
2d627b92 377 spin_lock_bh(&b_ptr->lock);
b97bf3fd 378 if (!list_empty(&b_ptr->cong_links))
4323add6 379 tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
2d627b92
AS
380 b_ptr->blocked = 0;
381 spin_unlock_bh(&b_ptr->lock);
b97bf3fd
PL
382}
383
384/*
c4307285
YH
385 * Schedule link for sending of messages after the bearer
386 * has been deblocked by 'continue()'. This method is called
387 * when somebody tries to send a message via this link while
4323add6 388 * the bearer is congested. 'tipc_net_lock' is in read_lock here
b97bf3fd
PL
389 * bearer.lock is busy
390 */
391
2d627b92 392static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
b97bf3fd
PL
393{
394 list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
395}
396
397/*
c4307285
YH
398 * Schedule link for sending of messages after the bearer
399 * has been deblocked by 'continue()'. This method is called
400 * when somebody tries to send a message via this link while
4323add6 401 * the bearer is congested. 'tipc_net_lock' is in read_lock here,
b97bf3fd
PL
402 * bearer.lock is free
403 */
404
2d627b92 405void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
b97bf3fd 406{
2d627b92 407 spin_lock_bh(&b_ptr->lock);
4323add6 408 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
2d627b92 409 spin_unlock_bh(&b_ptr->lock);
b97bf3fd
PL
410}
411
412
413/*
4323add6 414 * tipc_bearer_resolve_congestion(): Check if there is bearer congestion,
b97bf3fd 415 * and if there is, try to resolve it before returning.
4323add6 416 * 'tipc_net_lock' is read_locked when this function is called
b97bf3fd 417 */
2d627b92 418int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
b97bf3fd
PL
419{
420 int res = 1;
421
422 if (list_empty(&b_ptr->cong_links))
423 return 1;
2d627b92 424 spin_lock_bh(&b_ptr->lock);
b97bf3fd 425 if (!bearer_push(b_ptr)) {
4323add6 426 tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
b97bf3fd
PL
427 res = 0;
428 }
2d627b92 429 spin_unlock_bh(&b_ptr->lock);
b97bf3fd
PL
430 return res;
431}
432
b274f4ab
AS
433/**
434 * tipc_bearer_congested - determines if bearer is currently congested
435 */
436
2d627b92 437int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
b274f4ab 438{
2d627b92 439 if (unlikely(b_ptr->blocked))
b274f4ab
AS
440 return 1;
441 if (likely(list_empty(&b_ptr->cong_links)))
442 return 0;
443 return !tipc_bearer_resolve_congestion(b_ptr, l_ptr);
444}
b97bf3fd
PL
445
446/**
447 * tipc_enable_bearer - enable bearer with the given name
c4307285 448 */
b97bf3fd 449
50d3e639 450int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
b97bf3fd 451{
2d627b92 452 struct tipc_bearer *b_ptr;
b97bf3fd
PL
453 struct media *m_ptr;
454 struct bearer_name b_name;
455 char addr_string[16];
456 u32 bearer_id;
457 u32 with_this_prio;
458 u32 i;
459 int res = -EINVAL;
460
a10bd924
AS
461 if (tipc_mode != TIPC_NET_MODE) {
462 warn("Bearer <%s> rejected, not supported in standalone mode\n",
463 name);
b97bf3fd 464 return -ENOPROTOOPT;
a10bd924
AS
465 }
466 if (!bearer_name_validate(name, &b_name)) {
467 warn("Bearer <%s> rejected, illegal name\n", name);
16cb4b33 468 return -EINVAL;
a10bd924 469 }
66e019a6
AS
470 if (tipc_addr_domain_valid(disc_domain) &&
471 (disc_domain != tipc_own_addr)) {
472 if (tipc_in_scope(disc_domain, tipc_own_addr)) {
473 disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
474 res = 0; /* accept any node in own cluster */
475 } else if (in_own_cluster(disc_domain))
476 res = 0; /* accept specified node in own cluster */
477 }
478 if (res) {
50d3e639 479 warn("Bearer <%s> rejected, illegal discovery domain\n", name);
a10bd924
AS
480 return -EINVAL;
481 }
16cb4b33
PL
482 if ((priority < TIPC_MIN_LINK_PRI ||
483 priority > TIPC_MAX_LINK_PRI) &&
a10bd924
AS
484 (priority != TIPC_MEDIA_LINK_PRI)) {
485 warn("Bearer <%s> rejected, illegal priority\n", name);
b97bf3fd 486 return -EINVAL;
a10bd924 487 }
b97bf3fd 488
4323add6 489 write_lock_bh(&tipc_net_lock);
b97bf3fd
PL
490
491 m_ptr = media_find(b_name.media_name);
492 if (!m_ptr) {
a10bd924
AS
493 warn("Bearer <%s> rejected, media <%s> not registered\n", name,
494 b_name.media_name);
3a777ff8 495 goto exit;
b97bf3fd 496 }
16cb4b33
PL
497
498 if (priority == TIPC_MEDIA_LINK_PRI)
b97bf3fd
PL
499 priority = m_ptr->priority;
500
501restart:
502 bearer_id = MAX_BEARERS;
503 with_this_prio = 1;
504 for (i = MAX_BEARERS; i-- != 0; ) {
4323add6 505 if (!tipc_bearers[i].active) {
b97bf3fd
PL
506 bearer_id = i;
507 continue;
508 }
2d627b92 509 if (!strcmp(name, tipc_bearers[i].name)) {
a10bd924 510 warn("Bearer <%s> rejected, already enabled\n", name);
3a777ff8 511 goto exit;
b97bf3fd 512 }
4323add6 513 if ((tipc_bearers[i].priority == priority) &&
b97bf3fd
PL
514 (++with_this_prio > 2)) {
515 if (priority-- == 0) {
a10bd924
AS
516 warn("Bearer <%s> rejected, duplicate priority\n",
517 name);
3a777ff8 518 goto exit;
b97bf3fd 519 }
a10bd924 520 warn("Bearer <%s> priority adjustment required %u->%u\n",
b97bf3fd
PL
521 name, priority + 1, priority);
522 goto restart;
523 }
524 }
525 if (bearer_id >= MAX_BEARERS) {
c4307285 526 warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
a10bd924 527 name, MAX_BEARERS);
3a777ff8 528 goto exit;
b97bf3fd
PL
529 }
530
4323add6 531 b_ptr = &tipc_bearers[bearer_id];
2d627b92
AS
532 strcpy(b_ptr->name, name);
533 res = m_ptr->enable_bearer(b_ptr);
b97bf3fd 534 if (res) {
a10bd924 535 warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
3a777ff8 536 goto exit;
b97bf3fd
PL
537 }
538
539 b_ptr->identity = bearer_id;
540 b_ptr->media = m_ptr;
541 b_ptr->net_plane = bearer_id + 'A';
542 b_ptr->active = 1;
b97bf3fd
PL
543 b_ptr->priority = priority;
544 INIT_LIST_HEAD(&b_ptr->cong_links);
545 INIT_LIST_HEAD(&b_ptr->links);
2d627b92 546 spin_lock_init(&b_ptr->lock);
3a777ff8
AS
547
548 res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain);
549 if (res) {
550 bearer_disable(b_ptr);
551 warn("Bearer <%s> rejected, discovery object creation failed\n",
552 name);
553 goto exit;
554 }
16cb4b33 555 info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
50d3e639 556 name, tipc_addr_string_fill(addr_string, disc_domain), priority);
3a777ff8 557exit:
4323add6 558 write_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
559 return res;
560}
561
562/**
563 * tipc_block_bearer(): Block the bearer with the given name,
564 * and reset all its links
565 */
566
567int tipc_block_bearer(const char *name)
568{
2d627b92 569 struct tipc_bearer *b_ptr = NULL;
b97bf3fd
PL
570 struct link *l_ptr;
571 struct link *temp_l_ptr;
572
4323add6 573 read_lock_bh(&tipc_net_lock);
b97bf3fd
PL
574 b_ptr = bearer_find(name);
575 if (!b_ptr) {
576 warn("Attempt to block unknown bearer <%s>\n", name);
4323add6 577 read_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
578 return -EINVAL;
579 }
580
a10bd924 581 info("Blocking bearer <%s>\n", name);
2d627b92
AS
582 spin_lock_bh(&b_ptr->lock);
583 b_ptr->blocked = 1;
4b3743ef 584 list_splice_init(&b_ptr->cong_links, &b_ptr->links);
b97bf3fd 585 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
6c00055a 586 struct tipc_node *n_ptr = l_ptr->owner;
b97bf3fd
PL
587
588 spin_lock_bh(&n_ptr->lock);
4323add6 589 tipc_link_reset(l_ptr);
b97bf3fd
PL
590 spin_unlock_bh(&n_ptr->lock);
591 }
2d627b92 592 spin_unlock_bh(&b_ptr->lock);
4323add6 593 read_unlock_bh(&tipc_net_lock);
0e35fd5e 594 return 0;
b97bf3fd
PL
595}
596
597/**
598 * bearer_disable -
c4307285 599 *
4323add6 600 * Note: This routine assumes caller holds tipc_net_lock.
b97bf3fd
PL
601 */
602
2d627b92 603static void bearer_disable(struct tipc_bearer *b_ptr)
b97bf3fd 604{
b97bf3fd
PL
605 struct link *l_ptr;
606 struct link *temp_l_ptr;
607
2d627b92 608 info("Disabling bearer <%s>\n", b_ptr->name);
2d627b92 609 spin_lock_bh(&b_ptr->lock);
2d627b92
AS
610 b_ptr->blocked = 1;
611 b_ptr->media->disable_bearer(b_ptr);
4b3743ef 612 list_splice_init(&b_ptr->cong_links, &b_ptr->links);
b97bf3fd 613 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
4323add6 614 tipc_link_delete(l_ptr);
b97bf3fd 615 }
3a777ff8
AS
616 if (b_ptr->link_req)
617 tipc_disc_delete(b_ptr->link_req);
2d627b92
AS
618 spin_unlock_bh(&b_ptr->lock);
619 memset(b_ptr, 0, sizeof(struct tipc_bearer));
b97bf3fd
PL
620}
621
622int tipc_disable_bearer(const char *name)
623{
2d627b92 624 struct tipc_bearer *b_ptr;
b97bf3fd
PL
625 int res;
626
4323add6 627 write_lock_bh(&tipc_net_lock);
ccc901ee
AS
628 b_ptr = bearer_find(name);
629 if (b_ptr == NULL) {
630 warn("Attempt to disable unknown bearer <%s>\n", name);
631 res = -EINVAL;
28cc937e
AS
632 } else {
633 bearer_disable(b_ptr);
634 res = 0;
635 }
4323add6 636 write_unlock_bh(&tipc_net_lock);
b97bf3fd
PL
637 return res;
638}
639
640
641
4323add6 642void tipc_bearer_stop(void)
b97bf3fd
PL
643{
644 u32 i;
645
b97bf3fd 646 for (i = 0; i < MAX_BEARERS; i++) {
4323add6 647 if (tipc_bearers[i].active)
ccc901ee 648 bearer_disable(&tipc_bearers[i]);
b97bf3fd 649 }
b97bf3fd
PL
650 media_count = 0;
651}
This page took 0.997324 seconds and 5 git commands to generate.