diff options
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r-- | net/tipc/bearer.c | 201 |
1 files changed, 93 insertions, 108 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 52ae17b2583e..85209eadfae6 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/bearer.c: TIPC bearer code | 2 | * net/tipc/bearer.c: TIPC bearer code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, Ericsson AB | 4 | * Copyright (c) 1996-2006, Ericsson AB |
5 | * Copyright (c) 2004-2006, Wind River Systems | 5 | * Copyright (c) 2004-2006, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -36,19 +36,17 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "dbg.h" | ||
40 | #include "bearer.h" | 39 | #include "bearer.h" |
41 | #include "link.h" | ||
42 | #include "port.h" | ||
43 | #include "discover.h" | 40 | #include "discover.h" |
44 | #include "bcast.h" | ||
45 | 41 | ||
46 | #define MAX_ADDR_STR 32 | 42 | #define MAX_ADDR_STR 32 |
47 | 43 | ||
48 | static struct media media_list[MAX_MEDIA]; | 44 | static struct media media_list[MAX_MEDIA]; |
49 | static u32 media_count = 0; | 45 | static u32 media_count; |
50 | 46 | ||
51 | struct bearer tipc_bearers[MAX_BEARERS]; | 47 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; |
48 | |||
49 | static void bearer_disable(struct tipc_bearer *b_ptr); | ||
52 | 50 | ||
53 | /** | 51 | /** |
54 | * media_name_valid - validate media name | 52 | * media_name_valid - validate media name |
@@ -63,7 +61,7 @@ static int media_name_valid(const char *name) | |||
63 | len = strlen(name); | 61 | len = strlen(name); |
64 | if ((len + 1) > TIPC_MAX_MEDIA_NAME) | 62 | if ((len + 1) > TIPC_MAX_MEDIA_NAME) |
65 | return 0; | 63 | return 0; |
66 | return (strspn(name, tipc_alphabet) == len); | 64 | return strspn(name, tipc_alphabet) == len; |
67 | } | 65 | } |
68 | 66 | ||
69 | /** | 67 | /** |
@@ -162,12 +160,10 @@ int tipc_register_media(u32 media_type, | |||
162 | m_ptr->disable_bearer = disable; | 160 | m_ptr->disable_bearer = disable; |
163 | m_ptr->addr2str = addr2str; | 161 | m_ptr->addr2str = addr2str; |
164 | memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr)); | 162 | memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr)); |
165 | m_ptr->bcast = 1; | ||
166 | strcpy(m_ptr->name, name); | 163 | strcpy(m_ptr->name, name); |
167 | m_ptr->priority = bearer_priority; | 164 | m_ptr->priority = bearer_priority; |
168 | m_ptr->tolerance = link_tolerance; | 165 | m_ptr->tolerance = link_tolerance; |
169 | m_ptr->window = send_window_limit; | 166 | m_ptr->window = send_window_limit; |
170 | dbg("Media <%s> registered\n", name); | ||
171 | res = 0; | 167 | res = 0; |
172 | exit: | 168 | exit: |
173 | write_unlock_bh(&tipc_net_lock); | 169 | write_unlock_bh(&tipc_net_lock); |
@@ -199,9 +195,8 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a) | |||
199 | unchar *addr = (unchar *)&a->dev_addr; | 195 | unchar *addr = (unchar *)&a->dev_addr; |
200 | 196 | ||
201 | tipc_printf(pb, "UNKNOWN(%u)", media_type); | 197 | tipc_printf(pb, "UNKNOWN(%u)", media_type); |
202 | for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++) { | 198 | for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++) |
203 | tipc_printf(pb, "-%02x", addr[i]); | 199 | tipc_printf(pb, "-%02x", addr[i]); |
204 | } | ||
205 | } | 200 | } |
206 | } | 201 | } |
207 | 202 | ||
@@ -256,7 +251,8 @@ static int bearer_name_validate(const char *name, | |||
256 | /* ensure all component parts of bearer name are present */ | 251 | /* ensure all component parts of bearer name are present */ |
257 | 252 | ||
258 | media_name = name_copy; | 253 | media_name = name_copy; |
259 | if ((if_name = strchr(media_name, ':')) == NULL) | 254 | if_name = strchr(media_name, ':'); |
255 | if (if_name == NULL) | ||
260 | return 0; | 256 | return 0; |
261 | *(if_name++) = 0; | 257 | *(if_name++) = 0; |
262 | media_len = if_name - media_name; | 258 | media_len = if_name - media_name; |
@@ -283,16 +279,13 @@ static int bearer_name_validate(const char *name, | |||
283 | * bearer_find - locates bearer object with matching bearer name | 279 | * bearer_find - locates bearer object with matching bearer name |
284 | */ | 280 | */ |
285 | 281 | ||
286 | static struct bearer *bearer_find(const char *name) | 282 | static struct tipc_bearer *bearer_find(const char *name) |
287 | { | 283 | { |
288 | struct bearer *b_ptr; | 284 | struct tipc_bearer *b_ptr; |
289 | u32 i; | 285 | u32 i; |
290 | 286 | ||
291 | if (tipc_mode != TIPC_NET_MODE) | ||
292 | return NULL; | ||
293 | |||
294 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { | 287 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { |
295 | if (b_ptr->active && (!strcmp(b_ptr->publ.name, name))) | 288 | if (b_ptr->active && (!strcmp(b_ptr->name, name))) |
296 | return b_ptr; | 289 | return b_ptr; |
297 | } | 290 | } |
298 | return NULL; | 291 | return NULL; |
@@ -302,16 +295,16 @@ static struct bearer *bearer_find(const char *name) | |||
302 | * tipc_bearer_find_interface - locates bearer object with matching interface name | 295 | * tipc_bearer_find_interface - locates bearer object with matching interface name |
303 | */ | 296 | */ |
304 | 297 | ||
305 | struct bearer *tipc_bearer_find_interface(const char *if_name) | 298 | struct tipc_bearer *tipc_bearer_find_interface(const char *if_name) |
306 | { | 299 | { |
307 | struct bearer *b_ptr; | 300 | struct tipc_bearer *b_ptr; |
308 | char *b_if_name; | 301 | char *b_if_name; |
309 | u32 i; | 302 | u32 i; |
310 | 303 | ||
311 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { | 304 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { |
312 | if (!b_ptr->active) | 305 | if (!b_ptr->active) |
313 | continue; | 306 | continue; |
314 | b_if_name = strchr(b_ptr->publ.name, ':') + 1; | 307 | b_if_name = strchr(b_ptr->name, ':') + 1; |
315 | if (!strcmp(b_if_name, if_name)) | 308 | if (!strcmp(b_if_name, if_name)) |
316 | return b_ptr; | 309 | return b_ptr; |
317 | } | 310 | } |
@@ -326,7 +319,7 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
326 | { | 319 | { |
327 | struct sk_buff *buf; | 320 | struct sk_buff *buf; |
328 | struct media *m_ptr; | 321 | struct media *m_ptr; |
329 | struct bearer *b_ptr; | 322 | struct tipc_bearer *b_ptr; |
330 | int i, j; | 323 | int i, j; |
331 | 324 | ||
332 | buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); | 325 | buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); |
@@ -339,8 +332,8 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
339 | b_ptr = &tipc_bearers[j]; | 332 | b_ptr = &tipc_bearers[j]; |
340 | if (b_ptr->active && (b_ptr->media == m_ptr)) { | 333 | if (b_ptr->active && (b_ptr->media == m_ptr)) { |
341 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, | 334 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, |
342 | b_ptr->publ.name, | 335 | b_ptr->name, |
343 | strlen(b_ptr->publ.name) + 1); | 336 | strlen(b_ptr->name) + 1); |
344 | } | 337 | } |
345 | } | 338 | } |
346 | } | 339 | } |
@@ -348,18 +341,18 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
348 | return buf; | 341 | return buf; |
349 | } | 342 | } |
350 | 343 | ||
351 | void tipc_bearer_add_dest(struct bearer *b_ptr, u32 dest) | 344 | void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest) |
352 | { | 345 | { |
353 | tipc_nmap_add(&b_ptr->nodes, dest); | 346 | tipc_nmap_add(&b_ptr->nodes, dest); |
354 | tipc_disc_update_link_req(b_ptr->link_req); | ||
355 | tipc_bcbearer_sort(); | 347 | tipc_bcbearer_sort(); |
348 | tipc_disc_add_dest(b_ptr->link_req); | ||
356 | } | 349 | } |
357 | 350 | ||
358 | void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest) | 351 | void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest) |
359 | { | 352 | { |
360 | tipc_nmap_remove(&b_ptr->nodes, dest); | 353 | tipc_nmap_remove(&b_ptr->nodes, dest); |
361 | tipc_disc_update_link_req(b_ptr->link_req); | ||
362 | tipc_bcbearer_sort(); | 354 | tipc_bcbearer_sort(); |
355 | tipc_disc_remove_dest(b_ptr->link_req); | ||
363 | } | 356 | } |
364 | 357 | ||
365 | /* | 358 | /* |
@@ -370,12 +363,12 @@ void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest) | |||
370 | * bearer.lock must be taken before calling | 363 | * bearer.lock must be taken before calling |
371 | * Returns binary true(1) ore false(0) | 364 | * Returns binary true(1) ore false(0) |
372 | */ | 365 | */ |
373 | static int bearer_push(struct bearer *b_ptr) | 366 | static int bearer_push(struct tipc_bearer *b_ptr) |
374 | { | 367 | { |
375 | u32 res = 0; | 368 | u32 res = 0; |
376 | struct link *ln, *tln; | 369 | struct link *ln, *tln; |
377 | 370 | ||
378 | if (b_ptr->publ.blocked) | 371 | if (b_ptr->blocked) |
379 | return 0; | 372 | return 0; |
380 | 373 | ||
381 | while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) { | 374 | while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) { |
@@ -390,13 +383,13 @@ static int bearer_push(struct bearer *b_ptr) | |||
390 | return list_empty(&b_ptr->cong_links); | 383 | return list_empty(&b_ptr->cong_links); |
391 | } | 384 | } |
392 | 385 | ||
393 | void tipc_bearer_lock_push(struct bearer *b_ptr) | 386 | void tipc_bearer_lock_push(struct tipc_bearer *b_ptr) |
394 | { | 387 | { |
395 | int res; | 388 | int res; |
396 | 389 | ||
397 | spin_lock_bh(&b_ptr->publ.lock); | 390 | spin_lock_bh(&b_ptr->lock); |
398 | res = bearer_push(b_ptr); | 391 | res = bearer_push(b_ptr); |
399 | spin_unlock_bh(&b_ptr->publ.lock); | 392 | spin_unlock_bh(&b_ptr->lock); |
400 | if (res) | 393 | if (res) |
401 | tipc_bcbearer_push(); | 394 | tipc_bcbearer_push(); |
402 | } | 395 | } |
@@ -406,16 +399,14 @@ void tipc_bearer_lock_push(struct bearer *b_ptr) | |||
406 | * Interrupt enabling new requests after bearer congestion or blocking: | 399 | * Interrupt enabling new requests after bearer congestion or blocking: |
407 | * See bearer_send(). | 400 | * See bearer_send(). |
408 | */ | 401 | */ |
409 | void tipc_continue(struct tipc_bearer *tb_ptr) | 402 | void tipc_continue(struct tipc_bearer *b_ptr) |
410 | { | 403 | { |
411 | struct bearer *b_ptr = (struct bearer *)tb_ptr; | 404 | spin_lock_bh(&b_ptr->lock); |
412 | |||
413 | spin_lock_bh(&b_ptr->publ.lock); | ||
414 | b_ptr->continue_count++; | 405 | b_ptr->continue_count++; |
415 | if (!list_empty(&b_ptr->cong_links)) | 406 | if (!list_empty(&b_ptr->cong_links)) |
416 | tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr); | 407 | tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr); |
417 | b_ptr->publ.blocked = 0; | 408 | b_ptr->blocked = 0; |
418 | spin_unlock_bh(&b_ptr->publ.lock); | 409 | spin_unlock_bh(&b_ptr->lock); |
419 | } | 410 | } |
420 | 411 | ||
421 | /* | 412 | /* |
@@ -426,7 +417,7 @@ void tipc_continue(struct tipc_bearer *tb_ptr) | |||
426 | * bearer.lock is busy | 417 | * bearer.lock is busy |
427 | */ | 418 | */ |
428 | 419 | ||
429 | static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_ptr) | 420 | static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr) |
430 | { | 421 | { |
431 | list_move_tail(&l_ptr->link_list, &b_ptr->cong_links); | 422 | list_move_tail(&l_ptr->link_list, &b_ptr->cong_links); |
432 | } | 423 | } |
@@ -439,11 +430,11 @@ static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_p | |||
439 | * bearer.lock is free | 430 | * bearer.lock is free |
440 | */ | 431 | */ |
441 | 432 | ||
442 | void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr) | 433 | void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr) |
443 | { | 434 | { |
444 | spin_lock_bh(&b_ptr->publ.lock); | 435 | spin_lock_bh(&b_ptr->lock); |
445 | tipc_bearer_schedule_unlocked(b_ptr, l_ptr); | 436 | tipc_bearer_schedule_unlocked(b_ptr, l_ptr); |
446 | spin_unlock_bh(&b_ptr->publ.lock); | 437 | spin_unlock_bh(&b_ptr->lock); |
447 | } | 438 | } |
448 | 439 | ||
449 | 440 | ||
@@ -452,18 +443,18 @@ void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr) | |||
452 | * and if there is, try to resolve it before returning. | 443 | * and if there is, try to resolve it before returning. |
453 | * 'tipc_net_lock' is read_locked when this function is called | 444 | * 'tipc_net_lock' is read_locked when this function is called |
454 | */ | 445 | */ |
455 | int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr) | 446 | int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr) |
456 | { | 447 | { |
457 | int res = 1; | 448 | int res = 1; |
458 | 449 | ||
459 | if (list_empty(&b_ptr->cong_links)) | 450 | if (list_empty(&b_ptr->cong_links)) |
460 | return 1; | 451 | return 1; |
461 | spin_lock_bh(&b_ptr->publ.lock); | 452 | spin_lock_bh(&b_ptr->lock); |
462 | if (!bearer_push(b_ptr)) { | 453 | if (!bearer_push(b_ptr)) { |
463 | tipc_bearer_schedule_unlocked(b_ptr, l_ptr); | 454 | tipc_bearer_schedule_unlocked(b_ptr, l_ptr); |
464 | res = 0; | 455 | res = 0; |
465 | } | 456 | } |
466 | spin_unlock_bh(&b_ptr->publ.lock); | 457 | spin_unlock_bh(&b_ptr->lock); |
467 | return res; | 458 | return res; |
468 | } | 459 | } |
469 | 460 | ||
@@ -471,9 +462,9 @@ int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr) | |||
471 | * tipc_bearer_congested - determines if bearer is currently congested | 462 | * tipc_bearer_congested - determines if bearer is currently congested |
472 | */ | 463 | */ |
473 | 464 | ||
474 | int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr) | 465 | int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr) |
475 | { | 466 | { |
476 | if (unlikely(b_ptr->publ.blocked)) | 467 | if (unlikely(b_ptr->blocked)) |
477 | return 1; | 468 | return 1; |
478 | if (likely(list_empty(&b_ptr->cong_links))) | 469 | if (likely(list_empty(&b_ptr->cong_links))) |
479 | return 0; | 470 | return 0; |
@@ -484,9 +475,9 @@ int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr) | |||
484 | * tipc_enable_bearer - enable bearer with the given name | 475 | * tipc_enable_bearer - enable bearer with the given name |
485 | */ | 476 | */ |
486 | 477 | ||
487 | int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) | 478 | int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) |
488 | { | 479 | { |
489 | struct bearer *b_ptr; | 480 | struct tipc_bearer *b_ptr; |
490 | struct media *m_ptr; | 481 | struct media *m_ptr; |
491 | struct bearer_name b_name; | 482 | struct bearer_name b_name; |
492 | char addr_string[16]; | 483 | char addr_string[16]; |
@@ -504,9 +495,16 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) | |||
504 | warn("Bearer <%s> rejected, illegal name\n", name); | 495 | warn("Bearer <%s> rejected, illegal name\n", name); |
505 | return -EINVAL; | 496 | return -EINVAL; |
506 | } | 497 | } |
507 | if (!tipc_addr_domain_valid(bcast_scope) || | 498 | if (tipc_addr_domain_valid(disc_domain) && |
508 | !tipc_in_scope(bcast_scope, tipc_own_addr)) { | 499 | (disc_domain != tipc_own_addr)) { |
509 | warn("Bearer <%s> rejected, illegal broadcast scope\n", name); | 500 | if (tipc_in_scope(disc_domain, tipc_own_addr)) { |
501 | disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK; | ||
502 | res = 0; /* accept any node in own cluster */ | ||
503 | } else if (in_own_cluster(disc_domain)) | ||
504 | res = 0; /* accept specified node in own cluster */ | ||
505 | } | ||
506 | if (res) { | ||
507 | warn("Bearer <%s> rejected, illegal discovery domain\n", name); | ||
510 | return -EINVAL; | 508 | return -EINVAL; |
511 | } | 509 | } |
512 | if ((priority < TIPC_MIN_LINK_PRI || | 510 | if ((priority < TIPC_MIN_LINK_PRI || |
@@ -522,7 +520,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority) | |||
522 | if (!m_ptr) { | 520 | if (!m_ptr) { |
523 | warn("Bearer <%s> rejected, media <%s> not registered\n", name, | 521 | warn("Bearer <%s> rejected, media <%s> not registered\n", name, |
524 | b_name.media_name); | 522 | b_name.media_name); |
525 | goto failed; | 523 | goto exit; |
526 | } | 524 | } |
527 | 525 | ||
528 | if (priority == TIPC_MEDIA_LINK_PRI) | 526 | if (priority == TIPC_MEDIA_LINK_PRI) |
@@ -536,16 +534,16 @@ restart: | |||
536 | bearer_id = i; | 534 | bearer_id = i; |
537 | continue; | 535 | continue; |
538 | } | 536 | } |
539 | if (!strcmp(name, tipc_bearers[i].publ.name)) { | 537 | if (!strcmp(name, tipc_bearers[i].name)) { |
540 | warn("Bearer <%s> rejected, already enabled\n", name); | 538 | warn("Bearer <%s> rejected, already enabled\n", name); |
541 | goto failed; | 539 | goto exit; |
542 | } | 540 | } |
543 | if ((tipc_bearers[i].priority == priority) && | 541 | if ((tipc_bearers[i].priority == priority) && |
544 | (++with_this_prio > 2)) { | 542 | (++with_this_prio > 2)) { |
545 | if (priority-- == 0) { | 543 | if (priority-- == 0) { |
546 | warn("Bearer <%s> rejected, duplicate priority\n", | 544 | warn("Bearer <%s> rejected, duplicate priority\n", |
547 | name); | 545 | name); |
548 | goto failed; | 546 | goto exit; |
549 | } | 547 | } |
550 | warn("Bearer <%s> priority adjustment required %u->%u\n", | 548 | warn("Bearer <%s> priority adjustment required %u->%u\n", |
551 | name, priority + 1, priority); | 549 | name, priority + 1, priority); |
@@ -555,37 +553,36 @@ restart: | |||
555 | if (bearer_id >= MAX_BEARERS) { | 553 | if (bearer_id >= MAX_BEARERS) { |
556 | warn("Bearer <%s> rejected, bearer limit reached (%u)\n", | 554 | warn("Bearer <%s> rejected, bearer limit reached (%u)\n", |
557 | name, MAX_BEARERS); | 555 | name, MAX_BEARERS); |
558 | goto failed; | 556 | goto exit; |
559 | } | 557 | } |
560 | 558 | ||
561 | b_ptr = &tipc_bearers[bearer_id]; | 559 | b_ptr = &tipc_bearers[bearer_id]; |
562 | memset(b_ptr, 0, sizeof(struct bearer)); | 560 | strcpy(b_ptr->name, name); |
563 | 561 | res = m_ptr->enable_bearer(b_ptr); | |
564 | strcpy(b_ptr->publ.name, name); | ||
565 | res = m_ptr->enable_bearer(&b_ptr->publ); | ||
566 | if (res) { | 562 | if (res) { |
567 | warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res); | 563 | warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res); |
568 | goto failed; | 564 | goto exit; |
569 | } | 565 | } |
570 | 566 | ||
571 | b_ptr->identity = bearer_id; | 567 | b_ptr->identity = bearer_id; |
572 | b_ptr->media = m_ptr; | 568 | b_ptr->media = m_ptr; |
573 | b_ptr->net_plane = bearer_id + 'A'; | 569 | b_ptr->net_plane = bearer_id + 'A'; |
574 | b_ptr->active = 1; | 570 | b_ptr->active = 1; |
575 | b_ptr->detect_scope = bcast_scope; | ||
576 | b_ptr->priority = priority; | 571 | b_ptr->priority = priority; |
577 | INIT_LIST_HEAD(&b_ptr->cong_links); | 572 | INIT_LIST_HEAD(&b_ptr->cong_links); |
578 | INIT_LIST_HEAD(&b_ptr->links); | 573 | INIT_LIST_HEAD(&b_ptr->links); |
579 | if (m_ptr->bcast) { | 574 | spin_lock_init(&b_ptr->lock); |
580 | b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr, | 575 | |
581 | bcast_scope, 2); | 576 | res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain); |
577 | if (res) { | ||
578 | bearer_disable(b_ptr); | ||
579 | warn("Bearer <%s> rejected, discovery object creation failed\n", | ||
580 | name); | ||
581 | goto exit; | ||
582 | } | 582 | } |
583 | spin_lock_init(&b_ptr->publ.lock); | ||
584 | write_unlock_bh(&tipc_net_lock); | ||
585 | info("Enabled bearer <%s>, discovery domain %s, priority %u\n", | 583 | info("Enabled bearer <%s>, discovery domain %s, priority %u\n", |
586 | name, tipc_addr_string_fill(addr_string, bcast_scope), priority); | 584 | name, tipc_addr_string_fill(addr_string, disc_domain), priority); |
587 | return 0; | 585 | exit: |
588 | failed: | ||
589 | write_unlock_bh(&tipc_net_lock); | 586 | write_unlock_bh(&tipc_net_lock); |
590 | return res; | 587 | return res; |
591 | } | 588 | } |
@@ -597,7 +594,7 @@ failed: | |||
597 | 594 | ||
598 | int tipc_block_bearer(const char *name) | 595 | int tipc_block_bearer(const char *name) |
599 | { | 596 | { |
600 | struct bearer *b_ptr = NULL; | 597 | struct tipc_bearer *b_ptr = NULL; |
601 | struct link *l_ptr; | 598 | struct link *l_ptr; |
602 | struct link *temp_l_ptr; | 599 | struct link *temp_l_ptr; |
603 | 600 | ||
@@ -610,8 +607,8 @@ int tipc_block_bearer(const char *name) | |||
610 | } | 607 | } |
611 | 608 | ||
612 | info("Blocking bearer <%s>\n", name); | 609 | info("Blocking bearer <%s>\n", name); |
613 | spin_lock_bh(&b_ptr->publ.lock); | 610 | spin_lock_bh(&b_ptr->lock); |
614 | b_ptr->publ.blocked = 1; | 611 | b_ptr->blocked = 1; |
615 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 612 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
616 | struct tipc_node *n_ptr = l_ptr->owner; | 613 | struct tipc_node *n_ptr = l_ptr->owner; |
617 | 614 | ||
@@ -619,7 +616,7 @@ int tipc_block_bearer(const char *name) | |||
619 | tipc_link_reset(l_ptr); | 616 | tipc_link_reset(l_ptr); |
620 | spin_unlock_bh(&n_ptr->lock); | 617 | spin_unlock_bh(&n_ptr->lock); |
621 | } | 618 | } |
622 | spin_unlock_bh(&b_ptr->publ.lock); | 619 | spin_unlock_bh(&b_ptr->lock); |
623 | read_unlock_bh(&tipc_net_lock); | 620 | read_unlock_bh(&tipc_net_lock); |
624 | return 0; | 621 | return 0; |
625 | } | 622 | } |
@@ -630,44 +627,38 @@ int tipc_block_bearer(const char *name) | |||
630 | * Note: This routine assumes caller holds tipc_net_lock. | 627 | * Note: This routine assumes caller holds tipc_net_lock. |
631 | */ | 628 | */ |
632 | 629 | ||
633 | static int bearer_disable(const char *name) | 630 | static void bearer_disable(struct tipc_bearer *b_ptr) |
634 | { | 631 | { |
635 | struct bearer *b_ptr; | ||
636 | struct link *l_ptr; | 632 | struct link *l_ptr; |
637 | struct link *temp_l_ptr; | 633 | struct link *temp_l_ptr; |
638 | 634 | ||
639 | b_ptr = bearer_find(name); | 635 | info("Disabling bearer <%s>\n", b_ptr->name); |
640 | if (!b_ptr) { | 636 | spin_lock_bh(&b_ptr->lock); |
641 | warn("Attempt to disable unknown bearer <%s>\n", name); | 637 | b_ptr->blocked = 1; |
642 | return -EINVAL; | 638 | b_ptr->media->disable_bearer(b_ptr); |
643 | } | ||
644 | |||
645 | info("Disabling bearer <%s>\n", name); | ||
646 | tipc_disc_stop_link_req(b_ptr->link_req); | ||
647 | spin_lock_bh(&b_ptr->publ.lock); | ||
648 | b_ptr->link_req = NULL; | ||
649 | b_ptr->publ.blocked = 1; | ||
650 | if (b_ptr->media->disable_bearer) { | ||
651 | spin_unlock_bh(&b_ptr->publ.lock); | ||
652 | write_unlock_bh(&tipc_net_lock); | ||
653 | b_ptr->media->disable_bearer(&b_ptr->publ); | ||
654 | write_lock_bh(&tipc_net_lock); | ||
655 | spin_lock_bh(&b_ptr->publ.lock); | ||
656 | } | ||
657 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 639 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
658 | tipc_link_delete(l_ptr); | 640 | tipc_link_delete(l_ptr); |
659 | } | 641 | } |
660 | spin_unlock_bh(&b_ptr->publ.lock); | 642 | if (b_ptr->link_req) |
661 | memset(b_ptr, 0, sizeof(struct bearer)); | 643 | tipc_disc_delete(b_ptr->link_req); |
662 | return 0; | 644 | spin_unlock_bh(&b_ptr->lock); |
645 | memset(b_ptr, 0, sizeof(struct tipc_bearer)); | ||
663 | } | 646 | } |
664 | 647 | ||
665 | int tipc_disable_bearer(const char *name) | 648 | int tipc_disable_bearer(const char *name) |
666 | { | 649 | { |
650 | struct tipc_bearer *b_ptr; | ||
667 | int res; | 651 | int res; |
668 | 652 | ||
669 | write_lock_bh(&tipc_net_lock); | 653 | write_lock_bh(&tipc_net_lock); |
670 | res = bearer_disable(name); | 654 | b_ptr = bearer_find(name); |
655 | if (b_ptr == NULL) { | ||
656 | warn("Attempt to disable unknown bearer <%s>\n", name); | ||
657 | res = -EINVAL; | ||
658 | } else { | ||
659 | bearer_disable(b_ptr); | ||
660 | res = 0; | ||
661 | } | ||
671 | write_unlock_bh(&tipc_net_lock); | 662 | write_unlock_bh(&tipc_net_lock); |
672 | return res; | 663 | return res; |
673 | } | 664 | } |
@@ -680,13 +671,7 @@ void tipc_bearer_stop(void) | |||
680 | 671 | ||
681 | for (i = 0; i < MAX_BEARERS; i++) { | 672 | for (i = 0; i < MAX_BEARERS; i++) { |
682 | if (tipc_bearers[i].active) | 673 | if (tipc_bearers[i].active) |
683 | tipc_bearers[i].publ.blocked = 1; | 674 | bearer_disable(&tipc_bearers[i]); |
684 | } | ||
685 | for (i = 0; i < MAX_BEARERS; i++) { | ||
686 | if (tipc_bearers[i].active) | ||
687 | bearer_disable(tipc_bearers[i].publ.name); | ||
688 | } | 675 | } |
689 | media_count = 0; | 676 | media_count = 0; |
690 | } | 677 | } |
691 | |||
692 | |||