diff options
Diffstat (limited to 'net/tipc/node.c')
| -rw-r--r-- | net/tipc/node.c | 104 |
1 files changed, 59 insertions, 45 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c index 0d5db06e203f..fc6d09630ccd 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | * net/tipc/node.c: TIPC node management routines | 2 | * net/tipc/node.c: TIPC node management routines |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2000-2006, Ericsson AB | 4 | * Copyright (c) 2000-2006, Ericsson AB |
| 5 | * Copyright (c) 2005, Wind River Systems | 5 | * Copyright (c) 2005-2006, 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 |
| @@ -61,34 +61,37 @@ struct node *tipc_node_create(u32 addr) | |||
| 61 | struct node **curr_node; | 61 | struct node **curr_node; |
| 62 | 62 | ||
| 63 | n_ptr = kmalloc(sizeof(*n_ptr),GFP_ATOMIC); | 63 | n_ptr = kmalloc(sizeof(*n_ptr),GFP_ATOMIC); |
| 64 | if (n_ptr != NULL) { | 64 | if (!n_ptr) { |
| 65 | memset(n_ptr, 0, sizeof(*n_ptr)); | 65 | warn("Node creation failed, no memory\n"); |
| 66 | n_ptr->addr = addr; | 66 | return NULL; |
| 67 | n_ptr->lock = SPIN_LOCK_UNLOCKED; | 67 | } |
| 68 | INIT_LIST_HEAD(&n_ptr->nsub); | 68 | |
| 69 | 69 | c_ptr = tipc_cltr_find(addr); | |
| 70 | c_ptr = tipc_cltr_find(addr); | 70 | if (!c_ptr) { |
| 71 | if (c_ptr == NULL) | 71 | c_ptr = tipc_cltr_create(addr); |
| 72 | c_ptr = tipc_cltr_create(addr); | 72 | } |
| 73 | if (c_ptr != NULL) { | 73 | if (!c_ptr) { |
| 74 | n_ptr->owner = c_ptr; | 74 | kfree(n_ptr); |
| 75 | tipc_cltr_attach_node(c_ptr, n_ptr); | 75 | return NULL; |
| 76 | n_ptr->last_router = -1; | 76 | } |
| 77 | 77 | ||
| 78 | /* Insert node into ordered list */ | 78 | memset(n_ptr, 0, sizeof(*n_ptr)); |
| 79 | for (curr_node = &tipc_nodes; *curr_node; | 79 | n_ptr->addr = addr; |
| 80 | curr_node = &(*curr_node)->next) { | 80 | spin_lock_init(&n_ptr->lock); |
| 81 | if (addr < (*curr_node)->addr) { | 81 | INIT_LIST_HEAD(&n_ptr->nsub); |
| 82 | n_ptr->next = *curr_node; | 82 | n_ptr->owner = c_ptr; |
| 83 | break; | 83 | tipc_cltr_attach_node(c_ptr, n_ptr); |
| 84 | } | 84 | n_ptr->last_router = -1; |
| 85 | } | 85 | |
| 86 | (*curr_node) = n_ptr; | 86 | /* Insert node into ordered list */ |
| 87 | } else { | 87 | for (curr_node = &tipc_nodes; *curr_node; |
| 88 | kfree(n_ptr); | 88 | curr_node = &(*curr_node)->next) { |
| 89 | n_ptr = NULL; | 89 | if (addr < (*curr_node)->addr) { |
| 90 | } | 90 | n_ptr->next = *curr_node; |
| 91 | } | 91 | break; |
| 92 | } | ||
| 93 | } | ||
| 94 | (*curr_node) = n_ptr; | ||
| 92 | return n_ptr; | 95 | return n_ptr; |
| 93 | } | 96 | } |
| 94 | 97 | ||
| @@ -122,6 +125,8 @@ void tipc_node_link_up(struct node *n_ptr, struct link *l_ptr) | |||
| 122 | { | 125 | { |
| 123 | struct link **active = &n_ptr->active_links[0]; | 126 | struct link **active = &n_ptr->active_links[0]; |
| 124 | 127 | ||
| 128 | n_ptr->working_links++; | ||
| 129 | |||
| 125 | info("Established link <%s> on network plane %c\n", | 130 | info("Established link <%s> on network plane %c\n", |
| 126 | l_ptr->name, l_ptr->b_ptr->net_plane); | 131 | l_ptr->name, l_ptr->b_ptr->net_plane); |
| 127 | 132 | ||
| @@ -132,7 +137,7 @@ void tipc_node_link_up(struct node *n_ptr, struct link *l_ptr) | |||
| 132 | return; | 137 | return; |
| 133 | } | 138 | } |
| 134 | if (l_ptr->priority < active[0]->priority) { | 139 | if (l_ptr->priority < active[0]->priority) { |
| 135 | info("Link is standby\n"); | 140 | info("New link <%s> becomes standby\n", l_ptr->name); |
| 136 | return; | 141 | return; |
| 137 | } | 142 | } |
| 138 | tipc_link_send_duplicate(active[0], l_ptr); | 143 | tipc_link_send_duplicate(active[0], l_ptr); |
| @@ -140,8 +145,9 @@ void tipc_node_link_up(struct node *n_ptr, struct link *l_ptr) | |||
| 140 | active[0] = l_ptr; | 145 | active[0] = l_ptr; |
| 141 | return; | 146 | return; |
| 142 | } | 147 | } |
| 143 | info("Link <%s> on network plane %c becomes standby\n", | 148 | info("Old link <%s> becomes standby\n", active[0]->name); |
| 144 | active[0]->name, active[0]->b_ptr->net_plane); | 149 | if (active[1] != active[0]) |
| 150 | info("Old link <%s> becomes standby\n", active[1]->name); | ||
| 145 | active[0] = active[1] = l_ptr; | 151 | active[0] = active[1] = l_ptr; |
| 146 | } | 152 | } |
| 147 | 153 | ||
| @@ -181,6 +187,8 @@ void tipc_node_link_down(struct node *n_ptr, struct link *l_ptr) | |||
| 181 | { | 187 | { |
| 182 | struct link **active; | 188 | struct link **active; |
| 183 | 189 | ||
| 190 | n_ptr->working_links--; | ||
| 191 | |||
| 184 | if (!tipc_link_is_active(l_ptr)) { | 192 | if (!tipc_link_is_active(l_ptr)) { |
| 185 | info("Lost standby link <%s> on network plane %c\n", | 193 | info("Lost standby link <%s> on network plane %c\n", |
| 186 | l_ptr->name, l_ptr->b_ptr->net_plane); | 194 | l_ptr->name, l_ptr->b_ptr->net_plane); |
| @@ -210,8 +218,7 @@ int tipc_node_has_active_links(struct node *n_ptr) | |||
| 210 | 218 | ||
| 211 | int tipc_node_has_redundant_links(struct node *n_ptr) | 219 | int tipc_node_has_redundant_links(struct node *n_ptr) |
| 212 | { | 220 | { |
| 213 | return (tipc_node_has_active_links(n_ptr) && | 221 | return (n_ptr->working_links > 1); |
| 214 | (n_ptr->active_links[0] != n_ptr->active_links[1])); | ||
| 215 | } | 222 | } |
| 216 | 223 | ||
| 217 | static int tipc_node_has_active_routes(struct node *n_ptr) | 224 | static int tipc_node_has_active_routes(struct node *n_ptr) |
| @@ -234,7 +241,6 @@ struct node *tipc_node_attach_link(struct link *l_ptr) | |||
| 234 | u32 bearer_id = l_ptr->b_ptr->identity; | 241 | u32 bearer_id = l_ptr->b_ptr->identity; |
| 235 | char addr_string[16]; | 242 | char addr_string[16]; |
| 236 | 243 | ||
| 237 | assert(bearer_id < MAX_BEARERS); | ||
| 238 | if (n_ptr->link_cnt >= 2) { | 244 | if (n_ptr->link_cnt >= 2) { |
| 239 | char addr_string[16]; | 245 | char addr_string[16]; |
| 240 | 246 | ||
| @@ -249,7 +255,7 @@ struct node *tipc_node_attach_link(struct link *l_ptr) | |||
| 249 | n_ptr->link_cnt++; | 255 | n_ptr->link_cnt++; |
| 250 | return n_ptr; | 256 | return n_ptr; |
| 251 | } | 257 | } |
| 252 | err("Attempt to establish second link on <%s> to <%s> \n", | 258 | err("Attempt to establish second link on <%s> to %s \n", |
| 253 | l_ptr->b_ptr->publ.name, | 259 | l_ptr->b_ptr->publ.name, |
| 254 | addr_string_fill(addr_string, l_ptr->addr)); | 260 | addr_string_fill(addr_string, l_ptr->addr)); |
| 255 | } | 261 | } |
| @@ -314,7 +320,7 @@ static void node_established_contact(struct node *n_ptr) | |||
| 314 | struct cluster *c_ptr; | 320 | struct cluster *c_ptr; |
| 315 | 321 | ||
| 316 | dbg("node_established_contact:-> %x\n", n_ptr->addr); | 322 | dbg("node_established_contact:-> %x\n", n_ptr->addr); |
| 317 | if (!tipc_node_has_active_routes(n_ptr)) { | 323 | if (!tipc_node_has_active_routes(n_ptr) && in_own_cluster(n_ptr->addr)) { |
| 318 | tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr); | 324 | tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr); |
| 319 | } | 325 | } |
| 320 | 326 | ||
| @@ -586,6 +592,7 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 586 | struct sk_buff *buf; | 592 | struct sk_buff *buf; |
| 587 | struct node *n_ptr; | 593 | struct node *n_ptr; |
| 588 | struct tipc_node_info node_info; | 594 | struct tipc_node_info node_info; |
| 595 | u32 payload_size; | ||
| 589 | 596 | ||
| 590 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | 597 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) |
| 591 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 598 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| @@ -602,8 +609,11 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 602 | /* For now, get space for all other nodes | 609 | /* For now, get space for all other nodes |
| 603 | (will need to modify this when slave nodes are supported */ | 610 | (will need to modify this when slave nodes are supported */ |
| 604 | 611 | ||
| 605 | buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(node_info)) * | 612 | payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1); |
| 606 | (tipc_max_nodes - 1)); | 613 | if (payload_size > 32768u) |
| 614 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | ||
| 615 | " (too many nodes)"); | ||
| 616 | buf = tipc_cfg_reply_alloc(payload_size); | ||
| 607 | if (!buf) | 617 | if (!buf) |
| 608 | return NULL; | 618 | return NULL; |
| 609 | 619 | ||
| @@ -627,6 +637,7 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 627 | struct sk_buff *buf; | 637 | struct sk_buff *buf; |
| 628 | struct node *n_ptr; | 638 | struct node *n_ptr; |
| 629 | struct tipc_link_info link_info; | 639 | struct tipc_link_info link_info; |
| 640 | u32 payload_size; | ||
| 630 | 641 | ||
| 631 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | 642 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) |
| 632 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 643 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| @@ -639,12 +650,15 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 639 | 650 | ||
| 640 | if (!tipc_nodes) | 651 | if (!tipc_nodes) |
| 641 | return tipc_cfg_reply_none(); | 652 | return tipc_cfg_reply_none(); |
| 642 | 653 | ||
| 643 | /* For now, get space for 2 links to all other nodes + bcast link | 654 | /* Get space for all unicast links + multicast link */ |
| 644 | (will need to modify this when slave nodes are supported */ | 655 | |
| 645 | 656 | payload_size = TLV_SPACE(sizeof(link_info)) * | |
| 646 | buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(link_info)) * | 657 | (tipc_net.zones[tipc_zone(tipc_own_addr)]->links + 1); |
| 647 | (2 * (tipc_max_nodes - 1) + 1)); | 658 | if (payload_size > 32768u) |
| 659 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | ||
| 660 | " (too many links)"); | ||
| 661 | buf = tipc_cfg_reply_alloc(payload_size); | ||
| 648 | if (!buf) | 662 | if (!buf) |
| 649 | return NULL; | 663 | return NULL; |
| 650 | 664 | ||
