diff options
Diffstat (limited to 'net/tipc')
| -rw-r--r-- | net/tipc/addr.h | 2 | ||||
| -rw-r--r-- | net/tipc/bcast.c | 41 | ||||
| -rw-r--r-- | net/tipc/bcast.h | 4 | ||||
| -rw-r--r-- | net/tipc/bearer.c | 103 | ||||
| -rw-r--r-- | net/tipc/bearer.h | 13 | ||||
| -rw-r--r-- | net/tipc/config.c | 114 | ||||
| -rw-r--r-- | net/tipc/config.h | 5 | ||||
| -rw-r--r-- | net/tipc/core.c | 108 | ||||
| -rw-r--r-- | net/tipc/core.h | 3 | ||||
| -rw-r--r-- | net/tipc/discover.c | 23 | ||||
| -rw-r--r-- | net/tipc/discover.h | 5 | ||||
| -rw-r--r-- | net/tipc/handler.c | 1 | ||||
| -rw-r--r-- | net/tipc/link.c | 627 | ||||
| -rw-r--r-- | net/tipc/link.h | 57 | ||||
| -rw-r--r-- | net/tipc/name_distr.c | 22 | ||||
| -rw-r--r-- | net/tipc/name_distr.h | 2 | ||||
| -rw-r--r-- | net/tipc/name_table.c | 40 | ||||
| -rw-r--r-- | net/tipc/net.c | 22 | ||||
| -rw-r--r-- | net/tipc/netlink.c | 8 | ||||
| -rw-r--r-- | net/tipc/node.c | 119 | ||||
| -rw-r--r-- | net/tipc/node.h | 6 | ||||
| -rw-r--r-- | net/tipc/port.c | 301 | ||||
| -rw-r--r-- | net/tipc/port.h | 130 | ||||
| -rw-r--r-- | net/tipc/ref.c | 30 | ||||
| -rw-r--r-- | net/tipc/ref.h | 1 | ||||
| -rw-r--r-- | net/tipc/server.c | 19 | ||||
| -rw-r--r-- | net/tipc/server.h | 2 | ||||
| -rw-r--r-- | net/tipc/socket.c | 429 | ||||
| -rw-r--r-- | net/tipc/socket.h | 72 | ||||
| -rw-r--r-- | net/tipc/subscr.c | 48 |
30 files changed, 1139 insertions, 1218 deletions
diff --git a/net/tipc/addr.h b/net/tipc/addr.h index 60b00ab93d74..a74acf9ee804 100644 --- a/net/tipc/addr.h +++ b/net/tipc/addr.h | |||
| @@ -37,6 +37,8 @@ | |||
| 37 | #ifndef _TIPC_ADDR_H | 37 | #ifndef _TIPC_ADDR_H |
| 38 | #define _TIPC_ADDR_H | 38 | #define _TIPC_ADDR_H |
| 39 | 39 | ||
| 40 | #include "core.h" | ||
| 41 | |||
| 40 | #define TIPC_ZONE_MASK 0xff000000u | 42 | #define TIPC_ZONE_MASK 0xff000000u |
| 41 | #define TIPC_CLUSTER_MASK 0xfffff000u | 43 | #define TIPC_CLUSTER_MASK 0xfffff000u |
| 42 | 44 | ||
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index bf860d9e75af..95ab5ef92920 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
| @@ -41,9 +41,9 @@ | |||
| 41 | #include "bcast.h" | 41 | #include "bcast.h" |
| 42 | #include "name_distr.h" | 42 | #include "name_distr.h" |
| 43 | 43 | ||
| 44 | #define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ | 44 | #define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ |
| 45 | 45 | #define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ | |
| 46 | #define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ | 46 | #define BCBEARER MAX_BEARERS |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link | 49 | * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link |
| @@ -356,9 +356,9 @@ static void bclink_peek_nack(struct tipc_msg *msg) | |||
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | /* | 358 | /* |
| 359 | * tipc_bclink_send_msg - broadcast a packet to all nodes in cluster | 359 | * tipc_bclink_xmit - broadcast a packet to all nodes in cluster |
| 360 | */ | 360 | */ |
| 361 | int tipc_bclink_send_msg(struct sk_buff *buf) | 361 | int tipc_bclink_xmit(struct sk_buff *buf) |
| 362 | { | 362 | { |
| 363 | int res; | 363 | int res; |
| 364 | 364 | ||
| @@ -370,7 +370,7 @@ int tipc_bclink_send_msg(struct sk_buff *buf) | |||
| 370 | goto exit; | 370 | goto exit; |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | res = tipc_link_send_buf(bcl, buf); | 373 | res = __tipc_link_xmit(bcl, buf); |
| 374 | if (likely(res >= 0)) { | 374 | if (likely(res >= 0)) { |
| 375 | bclink_set_last_sent(); | 375 | bclink_set_last_sent(); |
| 376 | bcl->stats.queue_sz_counts++; | 376 | bcl->stats.queue_sz_counts++; |
| @@ -399,19 +399,18 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) | |||
| 399 | */ | 399 | */ |
| 400 | 400 | ||
| 401 | if (((seqno - tipc_own_addr) % TIPC_MIN_LINK_WIN) == 0) { | 401 | if (((seqno - tipc_own_addr) % TIPC_MIN_LINK_WIN) == 0) { |
| 402 | tipc_link_send_proto_msg( | 402 | tipc_link_proto_xmit(node->active_links[node->addr & 1], |
| 403 | node->active_links[node->addr & 1], | 403 | STATE_MSG, 0, 0, 0, 0, 0); |
| 404 | STATE_MSG, 0, 0, 0, 0, 0); | ||
| 405 | bcl->stats.sent_acks++; | 404 | bcl->stats.sent_acks++; |
| 406 | } | 405 | } |
| 407 | } | 406 | } |
| 408 | 407 | ||
| 409 | /** | 408 | /** |
| 410 | * tipc_bclink_recv_pkt - receive a broadcast packet, and deliver upwards | 409 | * tipc_bclink_rcv - receive a broadcast packet, and deliver upwards |
| 411 | * | 410 | * |
| 412 | * tipc_net_lock is read_locked, no other locks set | 411 | * tipc_net_lock is read_locked, no other locks set |
| 413 | */ | 412 | */ |
| 414 | void tipc_bclink_recv_pkt(struct sk_buff *buf) | 413 | void tipc_bclink_rcv(struct sk_buff *buf) |
| 415 | { | 414 | { |
| 416 | struct tipc_msg *msg = buf_msg(buf); | 415 | struct tipc_msg *msg = buf_msg(buf); |
| 417 | struct tipc_node *node; | 416 | struct tipc_node *node; |
| @@ -468,7 +467,7 @@ receive: | |||
| 468 | spin_unlock_bh(&bc_lock); | 467 | spin_unlock_bh(&bc_lock); |
| 469 | tipc_node_unlock(node); | 468 | tipc_node_unlock(node); |
| 470 | if (likely(msg_mcast(msg))) | 469 | if (likely(msg_mcast(msg))) |
| 471 | tipc_port_recv_mcast(buf, NULL); | 470 | tipc_port_mcast_rcv(buf, NULL); |
| 472 | else | 471 | else |
| 473 | kfree_skb(buf); | 472 | kfree_skb(buf); |
| 474 | } else if (msg_user(msg) == MSG_BUNDLER) { | 473 | } else if (msg_user(msg) == MSG_BUNDLER) { |
| @@ -478,12 +477,12 @@ receive: | |||
| 478 | bcl->stats.recv_bundled += msg_msgcnt(msg); | 477 | bcl->stats.recv_bundled += msg_msgcnt(msg); |
| 479 | spin_unlock_bh(&bc_lock); | 478 | spin_unlock_bh(&bc_lock); |
| 480 | tipc_node_unlock(node); | 479 | tipc_node_unlock(node); |
| 481 | tipc_link_recv_bundle(buf); | 480 | tipc_link_bundle_rcv(buf); |
| 482 | } else if (msg_user(msg) == MSG_FRAGMENTER) { | 481 | } else if (msg_user(msg) == MSG_FRAGMENTER) { |
| 483 | int ret; | 482 | int ret; |
| 484 | ret = tipc_link_recv_fragment(&node->bclink.reasm_head, | 483 | ret = tipc_link_frag_rcv(&node->bclink.reasm_head, |
| 485 | &node->bclink.reasm_tail, | 484 | &node->bclink.reasm_tail, |
| 486 | &buf); | 485 | &buf); |
| 487 | if (ret == LINK_REASM_ERROR) | 486 | if (ret == LINK_REASM_ERROR) |
| 488 | goto unlock; | 487 | goto unlock; |
| 489 | spin_lock_bh(&bc_lock); | 488 | spin_lock_bh(&bc_lock); |
| @@ -503,7 +502,7 @@ receive: | |||
| 503 | bclink_accept_pkt(node, seqno); | 502 | bclink_accept_pkt(node, seqno); |
| 504 | spin_unlock_bh(&bc_lock); | 503 | spin_unlock_bh(&bc_lock); |
| 505 | tipc_node_unlock(node); | 504 | tipc_node_unlock(node); |
| 506 | tipc_named_recv(buf); | 505 | tipc_named_rcv(buf); |
| 507 | } else { | 506 | } else { |
| 508 | spin_lock_bh(&bc_lock); | 507 | spin_lock_bh(&bc_lock); |
| 509 | bclink_accept_pkt(node, seqno); | 508 | bclink_accept_pkt(node, seqno); |
| @@ -669,9 +668,8 @@ void tipc_bcbearer_sort(void) | |||
| 669 | memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp)); | 668 | memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp)); |
| 670 | 669 | ||
| 671 | for (b_index = 0; b_index < MAX_BEARERS; b_index++) { | 670 | for (b_index = 0; b_index < MAX_BEARERS; b_index++) { |
| 672 | struct tipc_bearer *b = &tipc_bearers[b_index]; | 671 | struct tipc_bearer *b = bearer_list[b_index]; |
| 673 | 672 | if (!b || !b->nodes.count) | |
| 674 | if (!b->active || !b->nodes.count) | ||
| 675 | continue; | 673 | continue; |
| 676 | 674 | ||
| 677 | if (!bp_temp[b->priority].primary) | 675 | if (!bp_temp[b->priority].primary) |
| @@ -785,8 +783,8 @@ void tipc_bclink_init(void) | |||
| 785 | bcl->owner = &bclink->node; | 783 | bcl->owner = &bclink->node; |
| 786 | bcl->max_pkt = MAX_PKT_DEFAULT_MCAST; | 784 | bcl->max_pkt = MAX_PKT_DEFAULT_MCAST; |
| 787 | tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); | 785 | tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); |
| 788 | spin_lock_init(&bcbearer->bearer.lock); | ||
| 789 | bcl->b_ptr = &bcbearer->bearer; | 786 | bcl->b_ptr = &bcbearer->bearer; |
| 787 | bearer_list[BCBEARER] = &bcbearer->bearer; | ||
| 790 | bcl->state = WORKING_WORKING; | 788 | bcl->state = WORKING_WORKING; |
| 791 | strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); | 789 | strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); |
| 792 | } | 790 | } |
| @@ -797,6 +795,7 @@ void tipc_bclink_stop(void) | |||
| 797 | tipc_link_purge_queues(bcl); | 795 | tipc_link_purge_queues(bcl); |
| 798 | spin_unlock_bh(&bc_lock); | 796 | spin_unlock_bh(&bc_lock); |
| 799 | 797 | ||
| 798 | bearer_list[BCBEARER] = NULL; | ||
| 800 | memset(bclink, 0, sizeof(*bclink)); | 799 | memset(bclink, 0, sizeof(*bclink)); |
| 801 | memset(bcbearer, 0, sizeof(*bcbearer)); | 800 | memset(bcbearer, 0, sizeof(*bcbearer)); |
| 802 | } | 801 | } |
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h index 6ee587b469fd..a80ef54b818e 100644 --- a/net/tipc/bcast.h +++ b/net/tipc/bcast.h | |||
| @@ -90,8 +90,8 @@ void tipc_bclink_add_node(u32 addr); | |||
| 90 | void tipc_bclink_remove_node(u32 addr); | 90 | void tipc_bclink_remove_node(u32 addr); |
| 91 | struct tipc_node *tipc_bclink_retransmit_to(void); | 91 | struct tipc_node *tipc_bclink_retransmit_to(void); |
| 92 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); | 92 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); |
| 93 | int tipc_bclink_send_msg(struct sk_buff *buf); | 93 | int tipc_bclink_xmit(struct sk_buff *buf); |
| 94 | void tipc_bclink_recv_pkt(struct sk_buff *buf); | 94 | void tipc_bclink_rcv(struct sk_buff *buf); |
| 95 | u32 tipc_bclink_get_last_sent(void); | 95 | u32 tipc_bclink_get_last_sent(void); |
| 96 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); | 96 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); |
| 97 | void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent); | 97 | void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent); |
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index a38c89969c68..3fef7eb776dc 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
| @@ -49,9 +49,9 @@ static struct tipc_media * const media_info_array[] = { | |||
| 49 | NULL | 49 | NULL |
| 50 | }; | 50 | }; |
| 51 | 51 | ||
| 52 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; | 52 | struct tipc_bearer *bearer_list[MAX_BEARERS + 1]; |
| 53 | 53 | ||
| 54 | static void bearer_disable(struct tipc_bearer *b_ptr); | 54 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | * tipc_media_find - locates specified media object by name | 57 | * tipc_media_find - locates specified media object by name |
| @@ -177,8 +177,9 @@ struct tipc_bearer *tipc_bearer_find(const char *name) | |||
| 177 | struct tipc_bearer *b_ptr; | 177 | struct tipc_bearer *b_ptr; |
| 178 | u32 i; | 178 | u32 i; |
| 179 | 179 | ||
| 180 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { | 180 | for (i = 0; i < MAX_BEARERS; i++) { |
| 181 | if (b_ptr->active && (!strcmp(b_ptr->name, name))) | 181 | b_ptr = bearer_list[i]; |
| 182 | if (b_ptr && (!strcmp(b_ptr->name, name))) | ||
| 182 | return b_ptr; | 183 | return b_ptr; |
| 183 | } | 184 | } |
| 184 | return NULL; | 185 | return NULL; |
| @@ -200,8 +201,10 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
| 200 | read_lock_bh(&tipc_net_lock); | 201 | read_lock_bh(&tipc_net_lock); |
| 201 | for (i = 0; media_info_array[i] != NULL; i++) { | 202 | for (i = 0; media_info_array[i] != NULL; i++) { |
| 202 | for (j = 0; j < MAX_BEARERS; j++) { | 203 | for (j = 0; j < MAX_BEARERS; j++) { |
| 203 | b = &tipc_bearers[j]; | 204 | b = bearer_list[j]; |
| 204 | if (b->active && (b->media == media_info_array[i])) { | 205 | if (!b) |
| 206 | continue; | ||
| 207 | if (b->media == media_info_array[i]) { | ||
| 205 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, | 208 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, |
| 206 | b->name, | 209 | b->name, |
| 207 | strlen(b->name) + 1); | 210 | strlen(b->name) + 1); |
| @@ -284,16 +287,17 @@ restart: | |||
| 284 | bearer_id = MAX_BEARERS; | 287 | bearer_id = MAX_BEARERS; |
| 285 | with_this_prio = 1; | 288 | with_this_prio = 1; |
| 286 | for (i = MAX_BEARERS; i-- != 0; ) { | 289 | for (i = MAX_BEARERS; i-- != 0; ) { |
| 287 | if (!tipc_bearers[i].active) { | 290 | b_ptr = bearer_list[i]; |
| 291 | if (!b_ptr) { | ||
| 288 | bearer_id = i; | 292 | bearer_id = i; |
| 289 | continue; | 293 | continue; |
| 290 | } | 294 | } |
| 291 | if (!strcmp(name, tipc_bearers[i].name)) { | 295 | if (!strcmp(name, b_ptr->name)) { |
| 292 | pr_warn("Bearer <%s> rejected, already enabled\n", | 296 | pr_warn("Bearer <%s> rejected, already enabled\n", |
| 293 | name); | 297 | name); |
| 294 | goto exit; | 298 | goto exit; |
| 295 | } | 299 | } |
| 296 | if ((tipc_bearers[i].priority == priority) && | 300 | if ((b_ptr->priority == priority) && |
| 297 | (++with_this_prio > 2)) { | 301 | (++with_this_prio > 2)) { |
| 298 | if (priority-- == 0) { | 302 | if (priority-- == 0) { |
| 299 | pr_warn("Bearer <%s> rejected, duplicate priority\n", | 303 | pr_warn("Bearer <%s> rejected, duplicate priority\n", |
| @@ -311,7 +315,11 @@ restart: | |||
| 311 | goto exit; | 315 | goto exit; |
| 312 | } | 316 | } |
| 313 | 317 | ||
| 314 | b_ptr = &tipc_bearers[bearer_id]; | 318 | b_ptr = kzalloc(sizeof(*b_ptr), GFP_ATOMIC); |
| 319 | if (!b_ptr) { | ||
| 320 | res = -ENOMEM; | ||
| 321 | goto exit; | ||
| 322 | } | ||
| 315 | strcpy(b_ptr->name, name); | 323 | strcpy(b_ptr->name, name); |
| 316 | b_ptr->media = m_ptr; | 324 | b_ptr->media = m_ptr; |
| 317 | res = m_ptr->enable_media(b_ptr); | 325 | res = m_ptr->enable_media(b_ptr); |
| @@ -324,19 +332,20 @@ restart: | |||
| 324 | b_ptr->identity = bearer_id; | 332 | b_ptr->identity = bearer_id; |
| 325 | b_ptr->tolerance = m_ptr->tolerance; | 333 | b_ptr->tolerance = m_ptr->tolerance; |
| 326 | b_ptr->window = m_ptr->window; | 334 | b_ptr->window = m_ptr->window; |
| 335 | b_ptr->domain = disc_domain; | ||
| 327 | b_ptr->net_plane = bearer_id + 'A'; | 336 | b_ptr->net_plane = bearer_id + 'A'; |
| 328 | b_ptr->active = 1; | ||
| 329 | b_ptr->priority = priority; | 337 | b_ptr->priority = priority; |
| 330 | INIT_LIST_HEAD(&b_ptr->links); | ||
| 331 | spin_lock_init(&b_ptr->lock); | ||
| 332 | 338 | ||
| 333 | res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr, disc_domain); | 339 | res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr); |
| 334 | if (res) { | 340 | if (res) { |
| 335 | bearer_disable(b_ptr); | 341 | bearer_disable(b_ptr, false); |
| 336 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", | 342 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", |
| 337 | name); | 343 | name); |
| 338 | goto exit; | 344 | goto exit; |
| 339 | } | 345 | } |
| 346 | |||
| 347 | bearer_list[bearer_id] = b_ptr; | ||
| 348 | |||
| 340 | pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n", | 349 | pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n", |
| 341 | name, | 350 | name, |
| 342 | tipc_addr_string_fill(addr_string, disc_domain), priority); | 351 | tipc_addr_string_fill(addr_string, disc_domain), priority); |
| @@ -350,20 +359,11 @@ exit: | |||
| 350 | */ | 359 | */ |
| 351 | static int tipc_reset_bearer(struct tipc_bearer *b_ptr) | 360 | static int tipc_reset_bearer(struct tipc_bearer *b_ptr) |
| 352 | { | 361 | { |
| 353 | struct tipc_link *l_ptr; | ||
| 354 | struct tipc_link *temp_l_ptr; | ||
| 355 | |||
| 356 | read_lock_bh(&tipc_net_lock); | 362 | read_lock_bh(&tipc_net_lock); |
| 357 | pr_info("Resetting bearer <%s>\n", b_ptr->name); | 363 | pr_info("Resetting bearer <%s>\n", b_ptr->name); |
| 358 | spin_lock_bh(&b_ptr->lock); | 364 | tipc_disc_delete(b_ptr->link_req); |
| 359 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 365 | tipc_link_reset_list(b_ptr->identity); |
| 360 | struct tipc_node *n_ptr = l_ptr->owner; | 366 | tipc_disc_create(b_ptr, &b_ptr->bcast_addr); |
| 361 | |||
| 362 | spin_lock_bh(&n_ptr->lock); | ||
| 363 | tipc_link_reset(l_ptr); | ||
| 364 | spin_unlock_bh(&n_ptr->lock); | ||
| 365 | } | ||
| 366 | spin_unlock_bh(&b_ptr->lock); | ||
| 367 | read_unlock_bh(&tipc_net_lock); | 367 | read_unlock_bh(&tipc_net_lock); |
| 368 | return 0; | 368 | return 0; |
| 369 | } | 369 | } |
| @@ -373,26 +373,24 @@ static int tipc_reset_bearer(struct tipc_bearer *b_ptr) | |||
| 373 | * | 373 | * |
| 374 | * Note: This routine assumes caller holds tipc_net_lock. | 374 | * Note: This routine assumes caller holds tipc_net_lock. |
| 375 | */ | 375 | */ |
| 376 | static void bearer_disable(struct tipc_bearer *b_ptr) | 376 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down) |
| 377 | { | 377 | { |
| 378 | struct tipc_link *l_ptr; | 378 | u32 i; |
| 379 | struct tipc_link *temp_l_ptr; | ||
| 380 | struct tipc_link_req *temp_req; | ||
| 381 | 379 | ||
| 382 | pr_info("Disabling bearer <%s>\n", b_ptr->name); | 380 | pr_info("Disabling bearer <%s>\n", b_ptr->name); |
| 383 | spin_lock_bh(&b_ptr->lock); | ||
| 384 | b_ptr->media->disable_media(b_ptr); | 381 | b_ptr->media->disable_media(b_ptr); |
| 385 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | ||
| 386 | tipc_link_delete(l_ptr); | ||
| 387 | } | ||
| 388 | temp_req = b_ptr->link_req; | ||
| 389 | b_ptr->link_req = NULL; | ||
| 390 | spin_unlock_bh(&b_ptr->lock); | ||
| 391 | 382 | ||
| 392 | if (temp_req) | 383 | tipc_link_delete_list(b_ptr->identity, shutting_down); |
| 393 | tipc_disc_delete(temp_req); | 384 | if (b_ptr->link_req) |
| 385 | tipc_disc_delete(b_ptr->link_req); | ||
| 394 | 386 | ||
| 395 | memset(b_ptr, 0, sizeof(struct tipc_bearer)); | 387 | for (i = 0; i < MAX_BEARERS; i++) { |
| 388 | if (b_ptr == bearer_list[i]) { | ||
| 389 | bearer_list[i] = NULL; | ||
| 390 | break; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | kfree(b_ptr); | ||
| 396 | } | 394 | } |
| 397 | 395 | ||
| 398 | int tipc_disable_bearer(const char *name) | 396 | int tipc_disable_bearer(const char *name) |
| @@ -406,7 +404,7 @@ int tipc_disable_bearer(const char *name) | |||
| 406 | pr_warn("Attempt to disable unknown bearer <%s>\n", name); | 404 | pr_warn("Attempt to disable unknown bearer <%s>\n", name); |
| 407 | res = -EINVAL; | 405 | res = -EINVAL; |
| 408 | } else { | 406 | } else { |
| 409 | bearer_disable(b_ptr); | 407 | bearer_disable(b_ptr, false); |
| 410 | res = 0; | 408 | res = 0; |
| 411 | } | 409 | } |
| 412 | write_unlock_bh(&tipc_net_lock); | 410 | write_unlock_bh(&tipc_net_lock); |
| @@ -585,7 +583,11 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
| 585 | break; | 583 | break; |
| 586 | case NETDEV_DOWN: | 584 | case NETDEV_DOWN: |
| 587 | case NETDEV_CHANGEMTU: | 585 | case NETDEV_CHANGEMTU: |
| 586 | tipc_reset_bearer(b_ptr); | ||
| 587 | break; | ||
| 588 | case NETDEV_CHANGEADDR: | 588 | case NETDEV_CHANGEADDR: |
| 589 | tipc_l2_media_addr_set(b_ptr, &b_ptr->addr, | ||
| 590 | (char *)dev->dev_addr); | ||
| 589 | tipc_reset_bearer(b_ptr); | 591 | tipc_reset_bearer(b_ptr); |
| 590 | break; | 592 | break; |
| 591 | case NETDEV_UNREGISTER: | 593 | case NETDEV_UNREGISTER: |
| @@ -599,7 +601,7 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
| 599 | } | 601 | } |
| 600 | 602 | ||
| 601 | static struct packet_type tipc_packet_type __read_mostly = { | 603 | static struct packet_type tipc_packet_type __read_mostly = { |
| 602 | .type = __constant_htons(ETH_P_TIPC), | 604 | .type = htons(ETH_P_TIPC), |
| 603 | .func = tipc_l2_rcv_msg, | 605 | .func = tipc_l2_rcv_msg, |
| 604 | }; | 606 | }; |
| 605 | 607 | ||
| @@ -610,8 +612,13 @@ static struct notifier_block notifier = { | |||
| 610 | 612 | ||
| 611 | int tipc_bearer_setup(void) | 613 | int tipc_bearer_setup(void) |
| 612 | { | 614 | { |
| 615 | int err; | ||
| 616 | |||
| 617 | err = register_netdevice_notifier(¬ifier); | ||
| 618 | if (err) | ||
| 619 | return err; | ||
| 613 | dev_add_pack(&tipc_packet_type); | 620 | dev_add_pack(&tipc_packet_type); |
| 614 | return register_netdevice_notifier(¬ifier); | 621 | return 0; |
| 615 | } | 622 | } |
| 616 | 623 | ||
| 617 | void tipc_bearer_cleanup(void) | 624 | void tipc_bearer_cleanup(void) |
| @@ -622,10 +629,14 @@ void tipc_bearer_cleanup(void) | |||
| 622 | 629 | ||
| 623 | void tipc_bearer_stop(void) | 630 | void tipc_bearer_stop(void) |
| 624 | { | 631 | { |
| 632 | struct tipc_bearer *b_ptr; | ||
| 625 | u32 i; | 633 | u32 i; |
| 626 | 634 | ||
| 627 | for (i = 0; i < MAX_BEARERS; i++) { | 635 | for (i = 0; i < MAX_BEARERS; i++) { |
| 628 | if (tipc_bearers[i].active) | 636 | b_ptr = bearer_list[i]; |
| 629 | bearer_disable(&tipc_bearers[i]); | 637 | if (b_ptr) { |
| 638 | bearer_disable(b_ptr, true); | ||
| 639 | bearer_list[i] = NULL; | ||
| 640 | } | ||
| 630 | } | 641 | } |
| 631 | } | 642 | } |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 4f5db9ad5bf6..ba48145e871d 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
| @@ -107,10 +107,8 @@ struct tipc_media { | |||
| 107 | 107 | ||
| 108 | /** | 108 | /** |
| 109 | * struct tipc_bearer - Generic TIPC bearer structure | 109 | * struct tipc_bearer - Generic TIPC bearer structure |
| 110 | * @dev: ptr to associated network device | 110 | * @media_ptr: pointer to additional media-specific information about bearer |
| 111 | * @usr_handle: pointer to additional media-specific information about bearer | ||
| 112 | * @mtu: max packet size bearer can support | 111 | * @mtu: max packet size bearer can support |
| 113 | * @lock: spinlock for controlling access to bearer | ||
| 114 | * @addr: media-specific address associated with bearer | 112 | * @addr: media-specific address associated with bearer |
| 115 | * @name: bearer name (format = media:interface) | 113 | * @name: bearer name (format = media:interface) |
| 116 | * @media: ptr to media structure associated with bearer | 114 | * @media: ptr to media structure associated with bearer |
| @@ -118,10 +116,9 @@ struct tipc_media { | |||
| 118 | * @priority: default link priority for bearer | 116 | * @priority: default link priority for bearer |
| 119 | * @window: default window size for bearer | 117 | * @window: default window size for bearer |
| 120 | * @tolerance: default link tolerance for bearer | 118 | * @tolerance: default link tolerance for bearer |
| 119 | * @domain: network domain to which links can be established | ||
| 121 | * @identity: array index of this bearer within TIPC bearer array | 120 | * @identity: array index of this bearer within TIPC bearer array |
| 122 | * @link_req: ptr to (optional) structure making periodic link setup requests | 121 | * @link_req: ptr to (optional) structure making periodic link setup requests |
| 123 | * @links: list of non-congested links associated with bearer | ||
| 124 | * @active: non-zero if bearer structure is represents a bearer | ||
| 125 | * @net_plane: network plane ('A' through 'H') currently associated with bearer | 122 | * @net_plane: network plane ('A' through 'H') currently associated with bearer |
| 126 | * @nodes: indicates which nodes in cluster can be reached through bearer | 123 | * @nodes: indicates which nodes in cluster can be reached through bearer |
| 127 | * | 124 | * |
| @@ -134,16 +131,14 @@ struct tipc_bearer { | |||
| 134 | u32 mtu; /* initalized by media */ | 131 | u32 mtu; /* initalized by media */ |
| 135 | struct tipc_media_addr addr; /* initalized by media */ | 132 | struct tipc_media_addr addr; /* initalized by media */ |
| 136 | char name[TIPC_MAX_BEARER_NAME]; | 133 | char name[TIPC_MAX_BEARER_NAME]; |
| 137 | spinlock_t lock; | ||
| 138 | struct tipc_media *media; | 134 | struct tipc_media *media; |
| 139 | struct tipc_media_addr bcast_addr; | 135 | struct tipc_media_addr bcast_addr; |
| 140 | u32 priority; | 136 | u32 priority; |
| 141 | u32 window; | 137 | u32 window; |
| 142 | u32 tolerance; | 138 | u32 tolerance; |
| 139 | u32 domain; | ||
| 143 | u32 identity; | 140 | u32 identity; |
| 144 | struct tipc_link_req *link_req; | 141 | struct tipc_link_req *link_req; |
| 145 | struct list_head links; | ||
| 146 | int active; | ||
| 147 | char net_plane; | 142 | char net_plane; |
| 148 | struct tipc_node_map nodes; | 143 | struct tipc_node_map nodes; |
| 149 | }; | 144 | }; |
| @@ -155,7 +150,7 @@ struct tipc_bearer_names { | |||
| 155 | 150 | ||
| 156 | struct tipc_link; | 151 | struct tipc_link; |
| 157 | 152 | ||
| 158 | extern struct tipc_bearer tipc_bearers[]; | 153 | extern struct tipc_bearer *bearer_list[]; |
| 159 | 154 | ||
| 160 | /* | 155 | /* |
| 161 | * TIPC routines available to supported media types | 156 | * TIPC routines available to supported media types |
diff --git a/net/tipc/config.c b/net/tipc/config.c index c301a9a592d8..4b981c053823 100644 --- a/net/tipc/config.c +++ b/net/tipc/config.c | |||
| @@ -43,13 +43,11 @@ | |||
| 43 | #define REPLY_TRUNCATED "<truncated>\n" | 43 | #define REPLY_TRUNCATED "<truncated>\n" |
| 44 | 44 | ||
| 45 | static DEFINE_MUTEX(config_mutex); | 45 | static DEFINE_MUTEX(config_mutex); |
| 46 | static struct tipc_server cfgsrv; | ||
| 47 | 46 | ||
| 48 | static const void *req_tlv_area; /* request message TLV area */ | 47 | static const void *req_tlv_area; /* request message TLV area */ |
| 49 | static int req_tlv_space; /* request message TLV area size */ | 48 | static int req_tlv_space; /* request message TLV area size */ |
| 50 | static int rep_headroom; /* reply message headroom to use */ | 49 | static int rep_headroom; /* reply message headroom to use */ |
| 51 | 50 | ||
| 52 | |||
| 53 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size) | 51 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size) |
| 54 | { | 52 | { |
| 55 | struct sk_buff *buf; | 53 | struct sk_buff *buf; |
| @@ -181,19 +179,7 @@ static struct sk_buff *cfg_set_own_addr(void) | |||
| 181 | if (tipc_own_addr) | 179 | if (tipc_own_addr) |
| 182 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 180 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 183 | " (cannot change node address once assigned)"); | 181 | " (cannot change node address once assigned)"); |
| 184 | tipc_core_start_net(addr); | 182 | tipc_net_start(addr); |
| 185 | return tipc_cfg_reply_none(); | ||
| 186 | } | ||
| 187 | |||
| 188 | static struct sk_buff *cfg_set_remote_mng(void) | ||
| 189 | { | ||
| 190 | u32 value; | ||
| 191 | |||
| 192 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | ||
| 193 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | ||
| 194 | |||
| 195 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | ||
| 196 | tipc_remote_management = (value != 0); | ||
| 197 | return tipc_cfg_reply_none(); | 183 | return tipc_cfg_reply_none(); |
| 198 | } | 184 | } |
| 199 | 185 | ||
| @@ -247,21 +233,10 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 247 | /* Check command authorization */ | 233 | /* Check command authorization */ |
| 248 | if (likely(in_own_node(orig_node))) { | 234 | if (likely(in_own_node(orig_node))) { |
| 249 | /* command is permitted */ | 235 | /* command is permitted */ |
| 250 | } else if (cmd >= 0x8000) { | 236 | } else { |
| 251 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 237 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 252 | " (cannot be done remotely)"); | 238 | " (cannot be done remotely)"); |
| 253 | goto exit; | 239 | goto exit; |
| 254 | } else if (!tipc_remote_management) { | ||
| 255 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE); | ||
| 256 | goto exit; | ||
| 257 | } else if (cmd >= 0x4000) { | ||
| 258 | u32 domain = 0; | ||
| 259 | |||
| 260 | if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) || | ||
| 261 | (domain != orig_node)) { | ||
| 262 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR); | ||
| 263 | goto exit; | ||
| 264 | } | ||
| 265 | } | 240 | } |
| 266 | 241 | ||
| 267 | /* Call appropriate processing routine */ | 242 | /* Call appropriate processing routine */ |
| @@ -310,18 +285,12 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 310 | case TIPC_CMD_SET_NODE_ADDR: | 285 | case TIPC_CMD_SET_NODE_ADDR: |
| 311 | rep_tlv_buf = cfg_set_own_addr(); | 286 | rep_tlv_buf = cfg_set_own_addr(); |
| 312 | break; | 287 | break; |
| 313 | case TIPC_CMD_SET_REMOTE_MNG: | ||
| 314 | rep_tlv_buf = cfg_set_remote_mng(); | ||
| 315 | break; | ||
| 316 | case TIPC_CMD_SET_MAX_PORTS: | 288 | case TIPC_CMD_SET_MAX_PORTS: |
| 317 | rep_tlv_buf = cfg_set_max_ports(); | 289 | rep_tlv_buf = cfg_set_max_ports(); |
| 318 | break; | 290 | break; |
| 319 | case TIPC_CMD_SET_NETID: | 291 | case TIPC_CMD_SET_NETID: |
| 320 | rep_tlv_buf = cfg_set_netid(); | 292 | rep_tlv_buf = cfg_set_netid(); |
| 321 | break; | 293 | break; |
| 322 | case TIPC_CMD_GET_REMOTE_MNG: | ||
| 323 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management); | ||
| 324 | break; | ||
| 325 | case TIPC_CMD_GET_MAX_PORTS: | 294 | case TIPC_CMD_GET_MAX_PORTS: |
| 326 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports); | 295 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports); |
| 327 | break; | 296 | break; |
| @@ -345,6 +314,8 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 345 | case TIPC_CMD_SET_MAX_PUBL: | 314 | case TIPC_CMD_SET_MAX_PUBL: |
| 346 | case TIPC_CMD_GET_MAX_PUBL: | 315 | case TIPC_CMD_GET_MAX_PUBL: |
| 347 | case TIPC_CMD_SET_LOG_SIZE: | 316 | case TIPC_CMD_SET_LOG_SIZE: |
| 317 | case TIPC_CMD_SET_REMOTE_MNG: | ||
| 318 | case TIPC_CMD_GET_REMOTE_MNG: | ||
| 348 | case TIPC_CMD_DUMP_LOG: | 319 | case TIPC_CMD_DUMP_LOG: |
| 349 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 320 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 350 | " (obsolete command)"); | 321 | " (obsolete command)"); |
| @@ -369,80 +340,3 @@ exit: | |||
| 369 | mutex_unlock(&config_mutex); | 340 | mutex_unlock(&config_mutex); |
| 370 | return rep_tlv_buf; | 341 | return rep_tlv_buf; |
| 371 | } | 342 | } |
| 372 | |||
| 373 | static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr, | ||
| 374 | void *usr_data, void *buf, size_t len) | ||
| 375 | { | ||
| 376 | struct tipc_cfg_msg_hdr *req_hdr; | ||
| 377 | struct tipc_cfg_msg_hdr *rep_hdr; | ||
| 378 | struct sk_buff *rep_buf; | ||
| 379 | int ret; | ||
| 380 | |||
| 381 | /* Validate configuration message header (ignore invalid message) */ | ||
| 382 | req_hdr = (struct tipc_cfg_msg_hdr *)buf; | ||
| 383 | if ((len < sizeof(*req_hdr)) || | ||
| 384 | (len != TCM_ALIGN(ntohl(req_hdr->tcm_len))) || | ||
| 385 | (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) { | ||
| 386 | pr_warn("Invalid configuration message discarded\n"); | ||
| 387 | return; | ||
| 388 | } | ||
| 389 | |||
| 390 | /* Generate reply for request (if can't, return request) */ | ||
| 391 | rep_buf = tipc_cfg_do_cmd(addr->addr.id.node, ntohs(req_hdr->tcm_type), | ||
| 392 | buf + sizeof(*req_hdr), | ||
| 393 | len - sizeof(*req_hdr), | ||
| 394 | BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr)); | ||
| 395 | if (rep_buf) { | ||
| 396 | skb_push(rep_buf, sizeof(*rep_hdr)); | ||
| 397 | rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data; | ||
| 398 | memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); | ||
| 399 | rep_hdr->tcm_len = htonl(rep_buf->len); | ||
| 400 | rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); | ||
| 401 | |||
| 402 | ret = tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data, | ||
| 403 | rep_buf->len); | ||
| 404 | if (ret < 0) | ||
| 405 | pr_err("Sending cfg reply message failed, no memory\n"); | ||
| 406 | |||
| 407 | kfree_skb(rep_buf); | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | static struct sockaddr_tipc cfgsrv_addr __read_mostly = { | ||
| 412 | .family = AF_TIPC, | ||
| 413 | .addrtype = TIPC_ADDR_NAMESEQ, | ||
| 414 | .addr.nameseq.type = TIPC_CFG_SRV, | ||
| 415 | .addr.nameseq.lower = 0, | ||
| 416 | .addr.nameseq.upper = 0, | ||
| 417 | .scope = TIPC_ZONE_SCOPE | ||
| 418 | }; | ||
| 419 | |||
| 420 | static struct tipc_server cfgsrv __read_mostly = { | ||
| 421 | .saddr = &cfgsrv_addr, | ||
| 422 | .imp = TIPC_CRITICAL_IMPORTANCE, | ||
| 423 | .type = SOCK_RDM, | ||
| 424 | .max_rcvbuf_size = 64 * 1024, | ||
| 425 | .name = "cfg_server", | ||
| 426 | .tipc_conn_recvmsg = cfg_conn_msg_event, | ||
| 427 | .tipc_conn_new = NULL, | ||
| 428 | .tipc_conn_shutdown = NULL | ||
| 429 | }; | ||
| 430 | |||
| 431 | int tipc_cfg_init(void) | ||
| 432 | { | ||
| 433 | return tipc_server_start(&cfgsrv); | ||
| 434 | } | ||
| 435 | |||
| 436 | void tipc_cfg_reinit(void) | ||
| 437 | { | ||
| 438 | tipc_server_stop(&cfgsrv); | ||
| 439 | |||
| 440 | cfgsrv_addr.addr.nameseq.lower = tipc_own_addr; | ||
| 441 | cfgsrv_addr.addr.nameseq.upper = tipc_own_addr; | ||
| 442 | tipc_server_start(&cfgsrv); | ||
| 443 | } | ||
| 444 | |||
| 445 | void tipc_cfg_stop(void) | ||
| 446 | { | ||
| 447 | tipc_server_stop(&cfgsrv); | ||
| 448 | } | ||
diff --git a/net/tipc/config.h b/net/tipc/config.h index 1f252f3fa058..47b1bf181612 100644 --- a/net/tipc/config.h +++ b/net/tipc/config.h | |||
| @@ -64,9 +64,4 @@ static inline struct sk_buff *tipc_cfg_reply_ultra_string(char *string) | |||
| 64 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, | 64 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, |
| 65 | const void *req_tlv_area, int req_tlv_space, | 65 | const void *req_tlv_area, int req_tlv_space, |
| 66 | int headroom); | 66 | int headroom); |
| 67 | |||
| 68 | int tipc_cfg_init(void); | ||
| 69 | void tipc_cfg_reinit(void); | ||
| 70 | void tipc_cfg_stop(void); | ||
| 71 | |||
| 72 | #endif | 67 | #endif |
diff --git a/net/tipc/core.c b/net/tipc/core.c index f9e88d8b04ca..50d57429ebca 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/core.c: TIPC module code | 2 | * net/tipc/core.c: TIPC module code |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2003-2006, Ericsson AB | 4 | * Copyright (c) 2003-2006, 2013, Ericsson AB |
| 5 | * Copyright (c) 2005-2006, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2005-2006, 2010-2013, Wind River Systems |
| 6 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| @@ -50,7 +50,6 @@ int tipc_random __read_mostly; | |||
| 50 | u32 tipc_own_addr __read_mostly; | 50 | u32 tipc_own_addr __read_mostly; |
| 51 | int tipc_max_ports __read_mostly; | 51 | int tipc_max_ports __read_mostly; |
| 52 | int tipc_net_id __read_mostly; | 52 | int tipc_net_id __read_mostly; |
| 53 | int tipc_remote_management __read_mostly; | ||
| 54 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ | 53 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ |
| 55 | 54 | ||
| 56 | /** | 55 | /** |
| @@ -77,39 +76,14 @@ struct sk_buff *tipc_buf_acquire(u32 size) | |||
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | /** | 78 | /** |
| 80 | * tipc_core_stop_net - shut down TIPC networking sub-systems | ||
| 81 | */ | ||
| 82 | static void tipc_core_stop_net(void) | ||
| 83 | { | ||
| 84 | tipc_net_stop(); | ||
| 85 | tipc_bearer_cleanup(); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * start_net - start TIPC networking sub-systems | ||
| 90 | */ | ||
| 91 | int tipc_core_start_net(unsigned long addr) | ||
| 92 | { | ||
| 93 | int res; | ||
| 94 | |||
| 95 | tipc_net_start(addr); | ||
| 96 | res = tipc_bearer_setup(); | ||
| 97 | if (res < 0) | ||
| 98 | goto err; | ||
| 99 | return res; | ||
| 100 | |||
| 101 | err: | ||
| 102 | tipc_core_stop_net(); | ||
| 103 | return res; | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode | 79 | * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode |
| 108 | */ | 80 | */ |
| 109 | static void tipc_core_stop(void) | 81 | static void tipc_core_stop(void) |
| 110 | { | 82 | { |
| 83 | tipc_handler_stop(); | ||
| 84 | tipc_net_stop(); | ||
| 85 | tipc_bearer_cleanup(); | ||
| 111 | tipc_netlink_stop(); | 86 | tipc_netlink_stop(); |
| 112 | tipc_cfg_stop(); | ||
| 113 | tipc_subscr_stop(); | 87 | tipc_subscr_stop(); |
| 114 | tipc_nametbl_stop(); | 88 | tipc_nametbl_stop(); |
| 115 | tipc_ref_table_stop(); | 89 | tipc_ref_table_stop(); |
| @@ -122,30 +96,59 @@ static void tipc_core_stop(void) | |||
| 122 | */ | 96 | */ |
| 123 | static int tipc_core_start(void) | 97 | static int tipc_core_start(void) |
| 124 | { | 98 | { |
| 125 | int res; | 99 | int err; |
| 126 | 100 | ||
| 127 | get_random_bytes(&tipc_random, sizeof(tipc_random)); | 101 | get_random_bytes(&tipc_random, sizeof(tipc_random)); |
| 128 | 102 | ||
| 129 | res = tipc_handler_start(); | 103 | err = tipc_handler_start(); |
| 130 | if (!res) | 104 | if (err) |
| 131 | res = tipc_ref_table_init(tipc_max_ports, tipc_random); | 105 | goto out_handler; |
| 132 | if (!res) | 106 | |
| 133 | res = tipc_nametbl_init(); | 107 | err = tipc_ref_table_init(tipc_max_ports, tipc_random); |
| 134 | if (!res) | 108 | if (err) |
| 135 | res = tipc_netlink_start(); | 109 | goto out_reftbl; |
| 136 | if (!res) | 110 | |
| 137 | res = tipc_socket_init(); | 111 | err = tipc_nametbl_init(); |
| 138 | if (!res) | 112 | if (err) |
| 139 | res = tipc_register_sysctl(); | 113 | goto out_nametbl; |
| 140 | if (!res) | 114 | |
| 141 | res = tipc_subscr_start(); | 115 | err = tipc_netlink_start(); |
| 142 | if (!res) | 116 | if (err) |
| 143 | res = tipc_cfg_init(); | 117 | goto out_netlink; |
| 144 | if (res) { | 118 | |
| 145 | tipc_handler_stop(); | 119 | err = tipc_socket_init(); |
| 146 | tipc_core_stop(); | 120 | if (err) |
| 147 | } | 121 | goto out_socket; |
| 148 | return res; | 122 | |
| 123 | err = tipc_register_sysctl(); | ||
| 124 | if (err) | ||
| 125 | goto out_sysctl; | ||
| 126 | |||
| 127 | err = tipc_subscr_start(); | ||
| 128 | if (err) | ||
| 129 | goto out_subscr; | ||
| 130 | |||
| 131 | err = tipc_bearer_setup(); | ||
| 132 | if (err) | ||
| 133 | goto out_bearer; | ||
| 134 | |||
| 135 | return 0; | ||
| 136 | out_bearer: | ||
| 137 | tipc_subscr_stop(); | ||
| 138 | out_subscr: | ||
| 139 | tipc_unregister_sysctl(); | ||
| 140 | out_sysctl: | ||
| 141 | tipc_socket_stop(); | ||
| 142 | out_socket: | ||
| 143 | tipc_netlink_stop(); | ||
| 144 | out_netlink: | ||
| 145 | tipc_nametbl_stop(); | ||
| 146 | out_nametbl: | ||
| 147 | tipc_ref_table_stop(); | ||
| 148 | out_reftbl: | ||
| 149 | tipc_handler_stop(); | ||
| 150 | out_handler: | ||
| 151 | return err; | ||
| 149 | } | 152 | } |
| 150 | 153 | ||
| 151 | static int __init tipc_init(void) | 154 | static int __init tipc_init(void) |
| @@ -155,7 +158,6 @@ static int __init tipc_init(void) | |||
| 155 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); | 158 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); |
| 156 | 159 | ||
| 157 | tipc_own_addr = 0; | 160 | tipc_own_addr = 0; |
| 158 | tipc_remote_management = 1; | ||
| 159 | tipc_max_ports = CONFIG_TIPC_PORTS; | 161 | tipc_max_ports = CONFIG_TIPC_PORTS; |
| 160 | tipc_net_id = 4711; | 162 | tipc_net_id = 4711; |
| 161 | 163 | ||
| @@ -174,8 +176,6 @@ static int __init tipc_init(void) | |||
| 174 | 176 | ||
| 175 | static void __exit tipc_exit(void) | 177 | static void __exit tipc_exit(void) |
| 176 | { | 178 | { |
| 177 | tipc_handler_stop(); | ||
| 178 | tipc_core_stop_net(); | ||
| 179 | tipc_core_stop(); | 179 | tipc_core_stop(); |
| 180 | pr_info("Deactivated\n"); | 180 | pr_info("Deactivated\n"); |
| 181 | } | 181 | } |
diff --git a/net/tipc/core.h b/net/tipc/core.h index 1ff477b0450d..8985bbcb942b 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
| @@ -79,7 +79,6 @@ int tipc_snprintf(char *buf, int len, const char *fmt, ...); | |||
| 79 | extern u32 tipc_own_addr __read_mostly; | 79 | extern u32 tipc_own_addr __read_mostly; |
| 80 | extern int tipc_max_ports __read_mostly; | 80 | extern int tipc_max_ports __read_mostly; |
| 81 | extern int tipc_net_id __read_mostly; | 81 | extern int tipc_net_id __read_mostly; |
| 82 | extern int tipc_remote_management __read_mostly; | ||
| 83 | extern int sysctl_tipc_rmem[3] __read_mostly; | 82 | extern int sysctl_tipc_rmem[3] __read_mostly; |
| 84 | 83 | ||
| 85 | /* | 84 | /* |
| @@ -90,7 +89,6 @@ extern int tipc_random __read_mostly; | |||
| 90 | /* | 89 | /* |
| 91 | * Routines available to privileged subsystems | 90 | * Routines available to privileged subsystems |
| 92 | */ | 91 | */ |
| 93 | int tipc_core_start_net(unsigned long); | ||
| 94 | int tipc_handler_start(void); | 92 | int tipc_handler_start(void); |
| 95 | void tipc_handler_stop(void); | 93 | void tipc_handler_stop(void); |
| 96 | int tipc_netlink_start(void); | 94 | int tipc_netlink_start(void); |
| @@ -192,6 +190,7 @@ static inline void k_term_timer(struct timer_list *timer) | |||
| 192 | 190 | ||
| 193 | struct tipc_skb_cb { | 191 | struct tipc_skb_cb { |
| 194 | void *handle; | 192 | void *handle; |
| 193 | bool deferred; | ||
| 195 | }; | 194 | }; |
| 196 | 195 | ||
| 197 | #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0])) | 196 | #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0])) |
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index 412ff41b8611..542fe3413dc4 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
| @@ -48,7 +48,6 @@ | |||
| 48 | * struct tipc_link_req - information about an ongoing link setup request | 48 | * struct tipc_link_req - information about an ongoing link setup request |
| 49 | * @bearer: bearer issuing requests | 49 | * @bearer: bearer issuing requests |
| 50 | * @dest: destination address for request messages | 50 | * @dest: destination address for request messages |
| 51 | * @domain: network domain to which links can be established | ||
| 52 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) | 51 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) |
| 53 | * @lock: spinlock for controlling access to requests | 52 | * @lock: spinlock for controlling access to requests |
| 54 | * @buf: request message to be (repeatedly) sent | 53 | * @buf: request message to be (repeatedly) sent |
| @@ -58,7 +57,6 @@ | |||
| 58 | struct tipc_link_req { | 57 | struct tipc_link_req { |
| 59 | struct tipc_bearer *bearer; | 58 | struct tipc_bearer *bearer; |
| 60 | struct tipc_media_addr dest; | 59 | struct tipc_media_addr dest; |
| 61 | u32 domain; | ||
| 62 | int num_nodes; | 60 | int num_nodes; |
| 63 | spinlock_t lock; | 61 | spinlock_t lock; |
| 64 | struct sk_buff *buf; | 62 | struct sk_buff *buf; |
| @@ -69,14 +67,13 @@ struct tipc_link_req { | |||
| 69 | /** | 67 | /** |
| 70 | * tipc_disc_init_msg - initialize a link setup message | 68 | * tipc_disc_init_msg - initialize a link setup message |
| 71 | * @type: message type (request or response) | 69 | * @type: message type (request or response) |
| 72 | * @dest_domain: network domain of node(s) which should respond to message | ||
| 73 | * @b_ptr: ptr to bearer issuing message | 70 | * @b_ptr: ptr to bearer issuing message |
| 74 | */ | 71 | */ |
| 75 | static struct sk_buff *tipc_disc_init_msg(u32 type, u32 dest_domain, | 72 | static struct sk_buff *tipc_disc_init_msg(u32 type, struct tipc_bearer *b_ptr) |
| 76 | struct tipc_bearer *b_ptr) | ||
| 77 | { | 73 | { |
| 78 | struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE); | 74 | struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE); |
| 79 | struct tipc_msg *msg; | 75 | struct tipc_msg *msg; |
| 76 | u32 dest_domain = b_ptr->domain; | ||
| 80 | 77 | ||
| 81 | if (buf) { | 78 | if (buf) { |
| 82 | msg = buf_msg(buf); | 79 | msg = buf_msg(buf); |
| @@ -110,11 +107,11 @@ static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr, | |||
| 110 | } | 107 | } |
| 111 | 108 | ||
| 112 | /** | 109 | /** |
| 113 | * tipc_disc_recv_msg - handle incoming link setup message (request or response) | 110 | * tipc_disc_rcv - handle incoming link setup message (request or response) |
| 114 | * @buf: buffer containing message | 111 | * @buf: buffer containing message |
| 115 | * @b_ptr: bearer that message arrived on | 112 | * @b_ptr: bearer that message arrived on |
| 116 | */ | 113 | */ |
| 117 | void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) | 114 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *b_ptr) |
| 118 | { | 115 | { |
| 119 | struct tipc_node *n_ptr; | 116 | struct tipc_node *n_ptr; |
| 120 | struct tipc_link *link; | 117 | struct tipc_link *link; |
| @@ -149,7 +146,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) | |||
| 149 | } | 146 | } |
| 150 | if (!tipc_in_scope(dest, tipc_own_addr)) | 147 | if (!tipc_in_scope(dest, tipc_own_addr)) |
| 151 | return; | 148 | return; |
| 152 | if (!tipc_in_scope(b_ptr->link_req->domain, orig)) | 149 | if (!tipc_in_scope(b_ptr->domain, orig)) |
| 153 | return; | 150 | return; |
| 154 | 151 | ||
| 155 | /* Locate structure corresponding to requesting node */ | 152 | /* Locate structure corresponding to requesting node */ |
| @@ -242,7 +239,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) | |||
| 242 | link_fully_up = link_working_working(link); | 239 | link_fully_up = link_working_working(link); |
| 243 | 240 | ||
| 244 | if ((type == DSC_REQ_MSG) && !link_fully_up) { | 241 | if ((type == DSC_REQ_MSG) && !link_fully_up) { |
| 245 | rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr); | 242 | rbuf = tipc_disc_init_msg(DSC_RESP_MSG, b_ptr); |
| 246 | if (rbuf) { | 243 | if (rbuf) { |
| 247 | tipc_bearer_send(b_ptr, rbuf, &media_addr); | 244 | tipc_bearer_send(b_ptr, rbuf, &media_addr); |
| 248 | kfree_skb(rbuf); | 245 | kfree_skb(rbuf); |
| @@ -306,7 +303,7 @@ static void disc_timeout(struct tipc_link_req *req) | |||
| 306 | spin_lock_bh(&req->lock); | 303 | spin_lock_bh(&req->lock); |
| 307 | 304 | ||
| 308 | /* Stop searching if only desired node has been found */ | 305 | /* Stop searching if only desired node has been found */ |
| 309 | if (tipc_node(req->domain) && req->num_nodes) { | 306 | if (tipc_node(req->bearer->domain) && req->num_nodes) { |
| 310 | req->timer_intv = TIPC_LINK_REQ_INACTIVE; | 307 | req->timer_intv = TIPC_LINK_REQ_INACTIVE; |
| 311 | goto exit; | 308 | goto exit; |
| 312 | } | 309 | } |
| @@ -342,8 +339,7 @@ exit: | |||
| 342 | * | 339 | * |
| 343 | * Returns 0 if successful, otherwise -errno. | 340 | * Returns 0 if successful, otherwise -errno. |
| 344 | */ | 341 | */ |
| 345 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, | 342 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) |
| 346 | u32 dest_domain) | ||
| 347 | { | 343 | { |
| 348 | struct tipc_link_req *req; | 344 | struct tipc_link_req *req; |
| 349 | 345 | ||
| @@ -351,7 +347,7 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, | |||
| 351 | if (!req) | 347 | if (!req) |
| 352 | return -ENOMEM; | 348 | return -ENOMEM; |
| 353 | 349 | ||
| 354 | req->buf = tipc_disc_init_msg(DSC_REQ_MSG, dest_domain, b_ptr); | 350 | req->buf = tipc_disc_init_msg(DSC_REQ_MSG, b_ptr); |
| 355 | if (!req->buf) { | 351 | if (!req->buf) { |
| 356 | kfree(req); | 352 | kfree(req); |
| 357 | return -ENOMSG; | 353 | return -ENOMSG; |
| @@ -359,7 +355,6 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, | |||
| 359 | 355 | ||
| 360 | memcpy(&req->dest, dest, sizeof(*dest)); | 356 | memcpy(&req->dest, dest, sizeof(*dest)); |
| 361 | req->bearer = b_ptr; | 357 | req->bearer = b_ptr; |
| 362 | req->domain = dest_domain; | ||
| 363 | req->num_nodes = 0; | 358 | req->num_nodes = 0; |
| 364 | req->timer_intv = TIPC_LINK_REQ_INIT; | 359 | req->timer_intv = TIPC_LINK_REQ_INIT; |
| 365 | spin_lock_init(&req->lock); | 360 | spin_lock_init(&req->lock); |
diff --git a/net/tipc/discover.h b/net/tipc/discover.h index 75b67c403aa3..07f34729459d 100644 --- a/net/tipc/discover.h +++ b/net/tipc/discover.h | |||
| @@ -39,11 +39,10 @@ | |||
| 39 | 39 | ||
| 40 | struct tipc_link_req; | 40 | struct tipc_link_req; |
| 41 | 41 | ||
| 42 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, | 42 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest); |
| 43 | u32 dest_domain); | ||
| 44 | void tipc_disc_delete(struct tipc_link_req *req); | 43 | void tipc_disc_delete(struct tipc_link_req *req); |
| 45 | void tipc_disc_add_dest(struct tipc_link_req *req); | 44 | void tipc_disc_add_dest(struct tipc_link_req *req); |
| 46 | void tipc_disc_remove_dest(struct tipc_link_req *req); | 45 | void tipc_disc_remove_dest(struct tipc_link_req *req); |
| 47 | void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr); | 46 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *b_ptr); |
| 48 | 47 | ||
| 49 | #endif | 48 | #endif |
diff --git a/net/tipc/handler.c b/net/tipc/handler.c index e4bc8a296744..1fabf160501f 100644 --- a/net/tipc/handler.c +++ b/net/tipc/handler.c | |||
| @@ -58,7 +58,6 @@ unsigned int tipc_k_signal(Handler routine, unsigned long argument) | |||
| 58 | 58 | ||
| 59 | spin_lock_bh(&qitem_lock); | 59 | spin_lock_bh(&qitem_lock); |
| 60 | if (!handler_enabled) { | 60 | if (!handler_enabled) { |
| 61 | pr_err("Signal request ignored by handler\n"); | ||
| 62 | spin_unlock_bh(&qitem_lock); | 61 | spin_unlock_bh(&qitem_lock); |
| 63 | return -ENOPROTOOPT; | 62 | return -ENOPROTOOPT; |
| 64 | } | 63 | } |
diff --git a/net/tipc/link.c b/net/tipc/link.c index d4b5de41b682..c5190ab75290 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
| @@ -77,19 +77,19 @@ static const char *link_unk_evt = "Unknown link event "; | |||
| 77 | 77 | ||
| 78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | 78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
| 79 | struct sk_buff *buf); | 79 | struct sk_buff *buf); |
| 80 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); | 80 | static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf); |
| 81 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, | 81 | static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, |
| 82 | struct sk_buff **buf); | 82 | struct sk_buff **buf); |
| 83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); | 83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); |
| 84 | static int link_send_sections_long(struct tipc_port *sender, | 84 | static int tipc_link_iovec_long_xmit(struct tipc_port *sender, |
| 85 | struct iovec const *msg_sect, | 85 | struct iovec const *msg_sect, |
| 86 | unsigned int len, u32 destnode); | 86 | unsigned int len, u32 destnode); |
| 87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); | 87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); |
| 88 | static void link_reset_statistics(struct tipc_link *l_ptr); | 88 | static void link_reset_statistics(struct tipc_link *l_ptr); |
| 89 | static void link_print(struct tipc_link *l_ptr, const char *str); | 89 | static void link_print(struct tipc_link *l_ptr, const char *str); |
| 90 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); | 90 | static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf); |
| 91 | static void tipc_link_send_sync(struct tipc_link *l); | 91 | static void tipc_link_sync_xmit(struct tipc_link *l); |
| 92 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); | 92 | static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf); |
| 93 | 93 | ||
| 94 | /* | 94 | /* |
| 95 | * Simple link routines | 95 | * Simple link routines |
| @@ -147,11 +147,6 @@ int tipc_link_is_active(struct tipc_link *l_ptr) | |||
| 147 | /** | 147 | /** |
| 148 | * link_timeout - handle expiration of link timer | 148 | * link_timeout - handle expiration of link timer |
| 149 | * @l_ptr: pointer to link | 149 | * @l_ptr: pointer to link |
| 150 | * | ||
| 151 | * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict | ||
| 152 | * with tipc_link_delete(). (There is no risk that the node will be deleted by | ||
| 153 | * another thread because tipc_link_delete() always cancels the link timer before | ||
| 154 | * tipc_node_delete() is called.) | ||
| 155 | */ | 150 | */ |
| 156 | static void link_timeout(struct tipc_link *l_ptr) | 151 | static void link_timeout(struct tipc_link *l_ptr) |
| 157 | { | 152 | { |
| @@ -213,8 +208,8 @@ static void link_set_timer(struct tipc_link *l_ptr, u32 time) | |||
| 213 | * Returns pointer to link. | 208 | * Returns pointer to link. |
| 214 | */ | 209 | */ |
| 215 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | 210 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, |
| 216 | struct tipc_bearer *b_ptr, | 211 | struct tipc_bearer *b_ptr, |
| 217 | const struct tipc_media_addr *media_addr) | 212 | const struct tipc_media_addr *media_addr) |
| 218 | { | 213 | { |
| 219 | struct tipc_link *l_ptr; | 214 | struct tipc_link *l_ptr; |
| 220 | struct tipc_msg *msg; | 215 | struct tipc_msg *msg; |
| @@ -279,41 +274,44 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
| 279 | 274 | ||
| 280 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, | 275 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, |
| 281 | (unsigned long)l_ptr); | 276 | (unsigned long)l_ptr); |
| 282 | list_add_tail(&l_ptr->link_list, &b_ptr->links); | ||
| 283 | 277 | ||
| 284 | link_state_event(l_ptr, STARTING_EVT); | 278 | link_state_event(l_ptr, STARTING_EVT); |
| 285 | 279 | ||
| 286 | return l_ptr; | 280 | return l_ptr; |
| 287 | } | 281 | } |
| 288 | 282 | ||
| 289 | /** | 283 | void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down) |
| 290 | * tipc_link_delete - delete a link | ||
| 291 | * @l_ptr: pointer to link | ||
| 292 | * | ||
| 293 | * Note: 'tipc_net_lock' is write_locked, bearer is locked. | ||
| 294 | * This routine must not grab the node lock until after link timer cancellation | ||
| 295 | * to avoid a potential deadlock situation. | ||
| 296 | */ | ||
| 297 | void tipc_link_delete(struct tipc_link *l_ptr) | ||
| 298 | { | 284 | { |
| 299 | if (!l_ptr) { | 285 | struct tipc_link *l_ptr; |
| 300 | pr_err("Attempt to delete non-existent link\n"); | 286 | struct tipc_node *n_ptr; |
| 301 | return; | ||
| 302 | } | ||
| 303 | |||
| 304 | k_cancel_timer(&l_ptr->timer); | ||
| 305 | 287 | ||
| 306 | tipc_node_lock(l_ptr->owner); | 288 | rcu_read_lock(); |
| 307 | tipc_link_reset(l_ptr); | 289 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { |
| 308 | tipc_node_detach_link(l_ptr->owner, l_ptr); | 290 | spin_lock_bh(&n_ptr->lock); |
| 309 | tipc_link_purge_queues(l_ptr); | 291 | l_ptr = n_ptr->links[bearer_id]; |
| 310 | list_del_init(&l_ptr->link_list); | 292 | if (l_ptr) { |
| 311 | tipc_node_unlock(l_ptr->owner); | 293 | tipc_link_reset(l_ptr); |
| 312 | k_term_timer(&l_ptr->timer); | 294 | if (shutting_down || !tipc_node_is_up(n_ptr)) { |
| 313 | kfree(l_ptr); | 295 | tipc_node_detach_link(l_ptr->owner, l_ptr); |
| 296 | tipc_link_reset_fragments(l_ptr); | ||
| 297 | spin_unlock_bh(&n_ptr->lock); | ||
| 298 | |||
| 299 | /* Nobody else can access this link now: */ | ||
| 300 | del_timer_sync(&l_ptr->timer); | ||
| 301 | kfree(l_ptr); | ||
| 302 | } else { | ||
| 303 | /* Detach/delete when failover is finished: */ | ||
| 304 | l_ptr->flags |= LINK_STOPPED; | ||
| 305 | spin_unlock_bh(&n_ptr->lock); | ||
| 306 | del_timer_sync(&l_ptr->timer); | ||
| 307 | } | ||
| 308 | continue; | ||
| 309 | } | ||
| 310 | spin_unlock_bh(&n_ptr->lock); | ||
| 311 | } | ||
| 312 | rcu_read_unlock(); | ||
| 314 | } | 313 | } |
| 315 | 314 | ||
| 316 | |||
| 317 | /** | 315 | /** |
| 318 | * link_schedule_port - schedule port for deferred sending | 316 | * link_schedule_port - schedule port for deferred sending |
| 319 | * @l_ptr: pointer to link | 317 | * @l_ptr: pointer to link |
| @@ -330,8 +328,6 @@ static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz) | |||
| 330 | spin_lock_bh(&tipc_port_list_lock); | 328 | spin_lock_bh(&tipc_port_list_lock); |
| 331 | p_ptr = tipc_port_lock(origport); | 329 | p_ptr = tipc_port_lock(origport); |
| 332 | if (p_ptr) { | 330 | if (p_ptr) { |
| 333 | if (!p_ptr->wakeup) | ||
| 334 | goto exit; | ||
| 335 | if (!list_empty(&p_ptr->wait_list)) | 331 | if (!list_empty(&p_ptr->wait_list)) |
| 336 | goto exit; | 332 | goto exit; |
| 337 | p_ptr->congested = 1; | 333 | p_ptr->congested = 1; |
| @@ -366,7 +362,7 @@ void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all) | |||
| 366 | list_del_init(&p_ptr->wait_list); | 362 | list_del_init(&p_ptr->wait_list); |
| 367 | spin_lock_bh(p_ptr->lock); | 363 | spin_lock_bh(p_ptr->lock); |
| 368 | p_ptr->congested = 0; | 364 | p_ptr->congested = 0; |
| 369 | p_ptr->wakeup(p_ptr); | 365 | tipc_port_wakeup(p_ptr); |
| 370 | win -= p_ptr->waiting_pkts; | 366 | win -= p_ptr->waiting_pkts; |
| 371 | spin_unlock_bh(p_ptr->lock); | 367 | spin_unlock_bh(p_ptr->lock); |
| 372 | } | 368 | } |
| @@ -461,6 +457,21 @@ void tipc_link_reset(struct tipc_link *l_ptr) | |||
| 461 | link_reset_statistics(l_ptr); | 457 | link_reset_statistics(l_ptr); |
| 462 | } | 458 | } |
| 463 | 459 | ||
| 460 | void tipc_link_reset_list(unsigned int bearer_id) | ||
| 461 | { | ||
| 462 | struct tipc_link *l_ptr; | ||
| 463 | struct tipc_node *n_ptr; | ||
| 464 | |||
| 465 | rcu_read_lock(); | ||
| 466 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
| 467 | spin_lock_bh(&n_ptr->lock); | ||
| 468 | l_ptr = n_ptr->links[bearer_id]; | ||
| 469 | if (l_ptr) | ||
| 470 | tipc_link_reset(l_ptr); | ||
| 471 | spin_unlock_bh(&n_ptr->lock); | ||
| 472 | } | ||
| 473 | rcu_read_unlock(); | ||
| 474 | } | ||
| 464 | 475 | ||
| 465 | static void link_activate(struct tipc_link *l_ptr) | 476 | static void link_activate(struct tipc_link *l_ptr) |
| 466 | { | 477 | { |
| @@ -479,7 +490,10 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 479 | struct tipc_link *other; | 490 | struct tipc_link *other; |
| 480 | u32 cont_intv = l_ptr->continuity_interval; | 491 | u32 cont_intv = l_ptr->continuity_interval; |
| 481 | 492 | ||
| 482 | if (!l_ptr->started && (event != STARTING_EVT)) | 493 | if (l_ptr->flags & LINK_STOPPED) |
| 494 | return; | ||
| 495 | |||
| 496 | if (!(l_ptr->flags & LINK_STARTED) && (event != STARTING_EVT)) | ||
| 483 | return; /* Not yet. */ | 497 | return; /* Not yet. */ |
| 484 | 498 | ||
| 485 | /* Check whether changeover is going on */ | 499 | /* Check whether changeover is going on */ |
| @@ -499,12 +513,12 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 499 | if (l_ptr->next_in_no != l_ptr->checkpoint) { | 513 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
| 500 | l_ptr->checkpoint = l_ptr->next_in_no; | 514 | l_ptr->checkpoint = l_ptr->next_in_no; |
| 501 | if (tipc_bclink_acks_missing(l_ptr->owner)) { | 515 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
| 502 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | 516 | tipc_link_proto_xmit(l_ptr, STATE_MSG, |
| 503 | 0, 0, 0, 0, 0); | 517 | 0, 0, 0, 0, 0); |
| 504 | l_ptr->fsm_msg_cnt++; | 518 | l_ptr->fsm_msg_cnt++; |
| 505 | } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) { | 519 | } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) { |
| 506 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | 520 | tipc_link_proto_xmit(l_ptr, STATE_MSG, |
| 507 | 1, 0, 0, 0, 0); | 521 | 1, 0, 0, 0, 0); |
| 508 | l_ptr->fsm_msg_cnt++; | 522 | l_ptr->fsm_msg_cnt++; |
| 509 | } | 523 | } |
| 510 | link_set_timer(l_ptr, cont_intv); | 524 | link_set_timer(l_ptr, cont_intv); |
| @@ -512,7 +526,7 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 512 | } | 526 | } |
| 513 | l_ptr->state = WORKING_UNKNOWN; | 527 | l_ptr->state = WORKING_UNKNOWN; |
| 514 | l_ptr->fsm_msg_cnt = 0; | 528 | l_ptr->fsm_msg_cnt = 0; |
| 515 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); | 529 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
| 516 | l_ptr->fsm_msg_cnt++; | 530 | l_ptr->fsm_msg_cnt++; |
| 517 | link_set_timer(l_ptr, cont_intv / 4); | 531 | link_set_timer(l_ptr, cont_intv / 4); |
| 518 | break; | 532 | break; |
| @@ -522,7 +536,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 522 | tipc_link_reset(l_ptr); | 536 | tipc_link_reset(l_ptr); |
| 523 | l_ptr->state = RESET_RESET; | 537 | l_ptr->state = RESET_RESET; |
| 524 | l_ptr->fsm_msg_cnt = 0; | 538 | l_ptr->fsm_msg_cnt = 0; |
| 525 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); | 539 | tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG, |
| 540 | 0, 0, 0, 0, 0); | ||
| 526 | l_ptr->fsm_msg_cnt++; | 541 | l_ptr->fsm_msg_cnt++; |
| 527 | link_set_timer(l_ptr, cont_intv); | 542 | link_set_timer(l_ptr, cont_intv); |
| 528 | break; | 543 | break; |
| @@ -544,7 +559,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 544 | tipc_link_reset(l_ptr); | 559 | tipc_link_reset(l_ptr); |
| 545 | l_ptr->state = RESET_RESET; | 560 | l_ptr->state = RESET_RESET; |
| 546 | l_ptr->fsm_msg_cnt = 0; | 561 | l_ptr->fsm_msg_cnt = 0; |
| 547 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); | 562 | tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG, |
| 563 | 0, 0, 0, 0, 0); | ||
| 548 | l_ptr->fsm_msg_cnt++; | 564 | l_ptr->fsm_msg_cnt++; |
| 549 | link_set_timer(l_ptr, cont_intv); | 565 | link_set_timer(l_ptr, cont_intv); |
| 550 | break; | 566 | break; |
| @@ -554,14 +570,14 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 554 | l_ptr->fsm_msg_cnt = 0; | 570 | l_ptr->fsm_msg_cnt = 0; |
| 555 | l_ptr->checkpoint = l_ptr->next_in_no; | 571 | l_ptr->checkpoint = l_ptr->next_in_no; |
| 556 | if (tipc_bclink_acks_missing(l_ptr->owner)) { | 572 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
| 557 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | 573 | tipc_link_proto_xmit(l_ptr, STATE_MSG, |
| 558 | 0, 0, 0, 0, 0); | 574 | 0, 0, 0, 0, 0); |
| 559 | l_ptr->fsm_msg_cnt++; | 575 | l_ptr->fsm_msg_cnt++; |
| 560 | } | 576 | } |
| 561 | link_set_timer(l_ptr, cont_intv); | 577 | link_set_timer(l_ptr, cont_intv); |
| 562 | } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { | 578 | } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { |
| 563 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | 579 | tipc_link_proto_xmit(l_ptr, STATE_MSG, |
| 564 | 1, 0, 0, 0, 0); | 580 | 1, 0, 0, 0, 0); |
| 565 | l_ptr->fsm_msg_cnt++; | 581 | l_ptr->fsm_msg_cnt++; |
| 566 | link_set_timer(l_ptr, cont_intv / 4); | 582 | link_set_timer(l_ptr, cont_intv / 4); |
| 567 | } else { /* Link has failed */ | 583 | } else { /* Link has failed */ |
| @@ -570,8 +586,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 570 | tipc_link_reset(l_ptr); | 586 | tipc_link_reset(l_ptr); |
| 571 | l_ptr->state = RESET_UNKNOWN; | 587 | l_ptr->state = RESET_UNKNOWN; |
| 572 | l_ptr->fsm_msg_cnt = 0; | 588 | l_ptr->fsm_msg_cnt = 0; |
| 573 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, | 589 | tipc_link_proto_xmit(l_ptr, RESET_MSG, |
| 574 | 0, 0, 0, 0, 0); | 590 | 0, 0, 0, 0, 0); |
| 575 | l_ptr->fsm_msg_cnt++; | 591 | l_ptr->fsm_msg_cnt++; |
| 576 | link_set_timer(l_ptr, cont_intv); | 592 | link_set_timer(l_ptr, cont_intv); |
| 577 | } | 593 | } |
| @@ -591,24 +607,25 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 591 | l_ptr->state = WORKING_WORKING; | 607 | l_ptr->state = WORKING_WORKING; |
| 592 | l_ptr->fsm_msg_cnt = 0; | 608 | l_ptr->fsm_msg_cnt = 0; |
| 593 | link_activate(l_ptr); | 609 | link_activate(l_ptr); |
| 594 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); | 610 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
| 595 | l_ptr->fsm_msg_cnt++; | 611 | l_ptr->fsm_msg_cnt++; |
| 596 | if (l_ptr->owner->working_links == 1) | 612 | if (l_ptr->owner->working_links == 1) |
| 597 | tipc_link_send_sync(l_ptr); | 613 | tipc_link_sync_xmit(l_ptr); |
| 598 | link_set_timer(l_ptr, cont_intv); | 614 | link_set_timer(l_ptr, cont_intv); |
| 599 | break; | 615 | break; |
| 600 | case RESET_MSG: | 616 | case RESET_MSG: |
| 601 | l_ptr->state = RESET_RESET; | 617 | l_ptr->state = RESET_RESET; |
| 602 | l_ptr->fsm_msg_cnt = 0; | 618 | l_ptr->fsm_msg_cnt = 0; |
| 603 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0); | 619 | tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG, |
| 620 | 1, 0, 0, 0, 0); | ||
| 604 | l_ptr->fsm_msg_cnt++; | 621 | l_ptr->fsm_msg_cnt++; |
| 605 | link_set_timer(l_ptr, cont_intv); | 622 | link_set_timer(l_ptr, cont_intv); |
| 606 | break; | 623 | break; |
| 607 | case STARTING_EVT: | 624 | case STARTING_EVT: |
| 608 | l_ptr->started = 1; | 625 | l_ptr->flags |= LINK_STARTED; |
| 609 | /* fall through */ | 626 | /* fall through */ |
| 610 | case TIMEOUT_EVT: | 627 | case TIMEOUT_EVT: |
| 611 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); | 628 | tipc_link_proto_xmit(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); |
| 612 | l_ptr->fsm_msg_cnt++; | 629 | l_ptr->fsm_msg_cnt++; |
| 613 | link_set_timer(l_ptr, cont_intv); | 630 | link_set_timer(l_ptr, cont_intv); |
| 614 | break; | 631 | break; |
| @@ -626,16 +643,17 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 626 | l_ptr->state = WORKING_WORKING; | 643 | l_ptr->state = WORKING_WORKING; |
| 627 | l_ptr->fsm_msg_cnt = 0; | 644 | l_ptr->fsm_msg_cnt = 0; |
| 628 | link_activate(l_ptr); | 645 | link_activate(l_ptr); |
| 629 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); | 646 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
| 630 | l_ptr->fsm_msg_cnt++; | 647 | l_ptr->fsm_msg_cnt++; |
| 631 | if (l_ptr->owner->working_links == 1) | 648 | if (l_ptr->owner->working_links == 1) |
| 632 | tipc_link_send_sync(l_ptr); | 649 | tipc_link_sync_xmit(l_ptr); |
| 633 | link_set_timer(l_ptr, cont_intv); | 650 | link_set_timer(l_ptr, cont_intv); |
| 634 | break; | 651 | break; |
| 635 | case RESET_MSG: | 652 | case RESET_MSG: |
| 636 | break; | 653 | break; |
| 637 | case TIMEOUT_EVT: | 654 | case TIMEOUT_EVT: |
| 638 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); | 655 | tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG, |
| 656 | 0, 0, 0, 0, 0); | ||
| 639 | l_ptr->fsm_msg_cnt++; | 657 | l_ptr->fsm_msg_cnt++; |
| 640 | link_set_timer(l_ptr, cont_intv); | 658 | link_set_timer(l_ptr, cont_intv); |
| 641 | break; | 659 | break; |
| @@ -721,11 +739,11 @@ static void link_add_chain_to_outqueue(struct tipc_link *l_ptr, | |||
| 721 | } | 739 | } |
| 722 | 740 | ||
| 723 | /* | 741 | /* |
| 724 | * tipc_link_send_buf() is the 'full path' for messages, called from | 742 | * tipc_link_xmit() is the 'full path' for messages, called from |
| 725 | * inside TIPC when the 'fast path' in tipc_send_buf | 743 | * inside TIPC when the 'fast path' in tipc_send_xmit |
| 726 | * has failed, and from link_send() | 744 | * has failed, and from link_send() |
| 727 | */ | 745 | */ |
| 728 | int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | 746 | int __tipc_link_xmit(struct tipc_link *l_ptr, struct sk_buff *buf) |
| 729 | { | 747 | { |
| 730 | struct tipc_msg *msg = buf_msg(buf); | 748 | struct tipc_msg *msg = buf_msg(buf); |
| 731 | u32 size = msg_size(msg); | 749 | u32 size = msg_size(msg); |
| @@ -753,7 +771,7 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 753 | 771 | ||
| 754 | /* Fragmentation needed ? */ | 772 | /* Fragmentation needed ? */ |
| 755 | if (size > max_packet) | 773 | if (size > max_packet) |
| 756 | return link_send_long_buf(l_ptr, buf); | 774 | return tipc_link_frag_xmit(l_ptr, buf); |
| 757 | 775 | ||
| 758 | /* Packet can be queued or sent. */ | 776 | /* Packet can be queued or sent. */ |
| 759 | if (likely(!link_congested(l_ptr))) { | 777 | if (likely(!link_congested(l_ptr))) { |
| @@ -797,11 +815,11 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 797 | } | 815 | } |
| 798 | 816 | ||
| 799 | /* | 817 | /* |
| 800 | * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has | 818 | * tipc_link_xmit(): same as __tipc_link_xmit(), but the link to use |
| 801 | * not been selected yet, and the the owner node is not locked | 819 | * has not been selected yet, and the the owner node is not locked |
| 802 | * Called by TIPC internal users, e.g. the name distributor | 820 | * Called by TIPC internal users, e.g. the name distributor |
| 803 | */ | 821 | */ |
| 804 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) | 822 | int tipc_link_xmit(struct sk_buff *buf, u32 dest, u32 selector) |
| 805 | { | 823 | { |
| 806 | struct tipc_link *l_ptr; | 824 | struct tipc_link *l_ptr; |
| 807 | struct tipc_node *n_ptr; | 825 | struct tipc_node *n_ptr; |
| @@ -813,7 +831,7 @@ int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) | |||
| 813 | tipc_node_lock(n_ptr); | 831 | tipc_node_lock(n_ptr); |
| 814 | l_ptr = n_ptr->active_links[selector & 1]; | 832 | l_ptr = n_ptr->active_links[selector & 1]; |
| 815 | if (l_ptr) | 833 | if (l_ptr) |
| 816 | res = tipc_link_send_buf(l_ptr, buf); | 834 | res = __tipc_link_xmit(l_ptr, buf); |
| 817 | else | 835 | else |
| 818 | kfree_skb(buf); | 836 | kfree_skb(buf); |
| 819 | tipc_node_unlock(n_ptr); | 837 | tipc_node_unlock(n_ptr); |
| @@ -825,14 +843,14 @@ int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) | |||
| 825 | } | 843 | } |
| 826 | 844 | ||
| 827 | /* | 845 | /* |
| 828 | * tipc_link_send_sync - synchronize broadcast link endpoints. | 846 | * tipc_link_sync_xmit - synchronize broadcast link endpoints. |
| 829 | * | 847 | * |
| 830 | * Give a newly added peer node the sequence number where it should | 848 | * Give a newly added peer node the sequence number where it should |
| 831 | * start receiving and acking broadcast packets. | 849 | * start receiving and acking broadcast packets. |
| 832 | * | 850 | * |
| 833 | * Called with node locked | 851 | * Called with node locked |
| 834 | */ | 852 | */ |
| 835 | static void tipc_link_send_sync(struct tipc_link *l) | 853 | static void tipc_link_sync_xmit(struct tipc_link *l) |
| 836 | { | 854 | { |
| 837 | struct sk_buff *buf; | 855 | struct sk_buff *buf; |
| 838 | struct tipc_msg *msg; | 856 | struct tipc_msg *msg; |
| @@ -849,14 +867,14 @@ static void tipc_link_send_sync(struct tipc_link *l) | |||
| 849 | } | 867 | } |
| 850 | 868 | ||
| 851 | /* | 869 | /* |
| 852 | * tipc_link_recv_sync - synchronize broadcast link endpoints. | 870 | * tipc_link_sync_rcv - synchronize broadcast link endpoints. |
| 853 | * Receive the sequence number where we should start receiving and | 871 | * Receive the sequence number where we should start receiving and |
| 854 | * acking broadcast packets from a newly added peer node, and open | 872 | * acking broadcast packets from a newly added peer node, and open |
| 855 | * up for reception of such packets. | 873 | * up for reception of such packets. |
| 856 | * | 874 | * |
| 857 | * Called with node locked | 875 | * Called with node locked |
| 858 | */ | 876 | */ |
| 859 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) | 877 | static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf) |
| 860 | { | 878 | { |
| 861 | struct tipc_msg *msg = buf_msg(buf); | 879 | struct tipc_msg *msg = buf_msg(buf); |
| 862 | 880 | ||
| @@ -866,7 +884,7 @@ static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) | |||
| 866 | } | 884 | } |
| 867 | 885 | ||
| 868 | /* | 886 | /* |
| 869 | * tipc_link_send_names - send name table entries to new neighbor | 887 | * tipc_link_names_xmit - send name table entries to new neighbor |
| 870 | * | 888 | * |
| 871 | * Send routine for bulk delivery of name table messages when contact | 889 | * Send routine for bulk delivery of name table messages when contact |
| 872 | * with a new neighbor occurs. No link congestion checking is performed | 890 | * with a new neighbor occurs. No link congestion checking is performed |
| @@ -874,7 +892,7 @@ static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) | |||
| 874 | * small enough not to require fragmentation. | 892 | * small enough not to require fragmentation. |
| 875 | * Called without any locks held. | 893 | * Called without any locks held. |
| 876 | */ | 894 | */ |
| 877 | void tipc_link_send_names(struct list_head *message_list, u32 dest) | 895 | void tipc_link_names_xmit(struct list_head *message_list, u32 dest) |
| 878 | { | 896 | { |
| 879 | struct tipc_node *n_ptr; | 897 | struct tipc_node *n_ptr; |
| 880 | struct tipc_link *l_ptr; | 898 | struct tipc_link *l_ptr; |
| @@ -909,13 +927,13 @@ void tipc_link_send_names(struct list_head *message_list, u32 dest) | |||
| 909 | } | 927 | } |
| 910 | 928 | ||
| 911 | /* | 929 | /* |
| 912 | * link_send_buf_fast: Entry for data messages where the | 930 | * tipc_link_xmit_fast: Entry for data messages where the |
| 913 | * destination link is known and the header is complete, | 931 | * destination link is known and the header is complete, |
| 914 | * inclusive total message length. Very time critical. | 932 | * inclusive total message length. Very time critical. |
| 915 | * Link is locked. Returns user data length. | 933 | * Link is locked. Returns user data length. |
| 916 | */ | 934 | */ |
| 917 | static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, | 935 | static int tipc_link_xmit_fast(struct tipc_link *l_ptr, struct sk_buff *buf, |
| 918 | u32 *used_max_pkt) | 936 | u32 *used_max_pkt) |
| 919 | { | 937 | { |
| 920 | struct tipc_msg *msg = buf_msg(buf); | 938 | struct tipc_msg *msg = buf_msg(buf); |
| 921 | int res = msg_data_sz(msg); | 939 | int res = msg_data_sz(msg); |
| @@ -931,18 +949,18 @@ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, | |||
| 931 | else | 949 | else |
| 932 | *used_max_pkt = l_ptr->max_pkt; | 950 | *used_max_pkt = l_ptr->max_pkt; |
| 933 | } | 951 | } |
| 934 | return tipc_link_send_buf(l_ptr, buf); /* All other cases */ | 952 | return __tipc_link_xmit(l_ptr, buf); /* All other cases */ |
| 935 | } | 953 | } |
| 936 | 954 | ||
| 937 | /* | 955 | /* |
| 938 | * tipc_link_send_sections_fast: Entry for messages where the | 956 | * tipc_link_iovec_xmit_fast: Entry for messages where the |
| 939 | * destination processor is known and the header is complete, | 957 | * destination processor is known and the header is complete, |
| 940 | * except for total message length. | 958 | * except for total message length. |
| 941 | * Returns user data length or errno. | 959 | * Returns user data length or errno. |
| 942 | */ | 960 | */ |
| 943 | int tipc_link_send_sections_fast(struct tipc_port *sender, | 961 | int tipc_link_iovec_xmit_fast(struct tipc_port *sender, |
| 944 | struct iovec const *msg_sect, | 962 | struct iovec const *msg_sect, |
| 945 | unsigned int len, u32 destaddr) | 963 | unsigned int len, u32 destaddr) |
| 946 | { | 964 | { |
| 947 | struct tipc_msg *hdr = &sender->phdr; | 965 | struct tipc_msg *hdr = &sender->phdr; |
| 948 | struct tipc_link *l_ptr; | 966 | struct tipc_link *l_ptr; |
| @@ -968,8 +986,8 @@ again: | |||
| 968 | l_ptr = node->active_links[selector]; | 986 | l_ptr = node->active_links[selector]; |
| 969 | if (likely(l_ptr)) { | 987 | if (likely(l_ptr)) { |
| 970 | if (likely(buf)) { | 988 | if (likely(buf)) { |
| 971 | res = link_send_buf_fast(l_ptr, buf, | 989 | res = tipc_link_xmit_fast(l_ptr, buf, |
| 972 | &sender->max_pkt); | 990 | &sender->max_pkt); |
| 973 | exit: | 991 | exit: |
| 974 | tipc_node_unlock(node); | 992 | tipc_node_unlock(node); |
| 975 | read_unlock_bh(&tipc_net_lock); | 993 | read_unlock_bh(&tipc_net_lock); |
| @@ -995,24 +1013,21 @@ exit: | |||
| 995 | if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt) | 1013 | if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt) |
| 996 | goto again; | 1014 | goto again; |
| 997 | 1015 | ||
| 998 | return link_send_sections_long(sender, msg_sect, len, | 1016 | return tipc_link_iovec_long_xmit(sender, msg_sect, |
| 999 | destaddr); | 1017 | len, destaddr); |
| 1000 | } | 1018 | } |
| 1001 | tipc_node_unlock(node); | 1019 | tipc_node_unlock(node); |
| 1002 | } | 1020 | } |
| 1003 | read_unlock_bh(&tipc_net_lock); | 1021 | read_unlock_bh(&tipc_net_lock); |
| 1004 | 1022 | ||
| 1005 | /* Couldn't find a link to the destination node */ | 1023 | /* Couldn't find a link to the destination node */ |
| 1006 | if (buf) | 1024 | kfree_skb(buf); |
| 1007 | return tipc_reject_msg(buf, TIPC_ERR_NO_NODE); | 1025 | tipc_port_iovec_reject(sender, hdr, msg_sect, len, TIPC_ERR_NO_NODE); |
| 1008 | if (res >= 0) | 1026 | return -ENETUNREACH; |
| 1009 | return tipc_port_reject_sections(sender, hdr, msg_sect, | ||
| 1010 | len, TIPC_ERR_NO_NODE); | ||
| 1011 | return res; | ||
| 1012 | } | 1027 | } |
| 1013 | 1028 | ||
| 1014 | /* | 1029 | /* |
| 1015 | * link_send_sections_long(): Entry for long messages where the | 1030 | * tipc_link_iovec_long_xmit(): Entry for long messages where the |
| 1016 | * destination node is known and the header is complete, | 1031 | * destination node is known and the header is complete, |
| 1017 | * inclusive total message length. | 1032 | * inclusive total message length. |
| 1018 | * Link and bearer congestion status have been checked to be ok, | 1033 | * Link and bearer congestion status have been checked to be ok, |
| @@ -1025,9 +1040,9 @@ exit: | |||
| 1025 | * | 1040 | * |
| 1026 | * Returns user data length or errno. | 1041 | * Returns user data length or errno. |
| 1027 | */ | 1042 | */ |
| 1028 | static int link_send_sections_long(struct tipc_port *sender, | 1043 | static int tipc_link_iovec_long_xmit(struct tipc_port *sender, |
| 1029 | struct iovec const *msg_sect, | 1044 | struct iovec const *msg_sect, |
| 1030 | unsigned int len, u32 destaddr) | 1045 | unsigned int len, u32 destaddr) |
| 1031 | { | 1046 | { |
| 1032 | struct tipc_link *l_ptr; | 1047 | struct tipc_link *l_ptr; |
| 1033 | struct tipc_node *node; | 1048 | struct tipc_node *node; |
| @@ -1146,8 +1161,9 @@ error: | |||
| 1146 | } else { | 1161 | } else { |
| 1147 | reject: | 1162 | reject: |
| 1148 | kfree_skb_list(buf_chain); | 1163 | kfree_skb_list(buf_chain); |
| 1149 | return tipc_port_reject_sections(sender, hdr, msg_sect, | 1164 | tipc_port_iovec_reject(sender, hdr, msg_sect, len, |
| 1150 | len, TIPC_ERR_NO_NODE); | 1165 | TIPC_ERR_NO_NODE); |
| 1166 | return -ENETUNREACH; | ||
| 1151 | } | 1167 | } |
| 1152 | 1168 | ||
| 1153 | /* Append chain of fragments to send queue & send them */ | 1169 | /* Append chain of fragments to send queue & send them */ |
| @@ -1391,6 +1407,12 @@ static int link_recv_buf_validate(struct sk_buff *buf) | |||
| 1391 | u32 hdr_size; | 1407 | u32 hdr_size; |
| 1392 | u32 min_hdr_size; | 1408 | u32 min_hdr_size; |
| 1393 | 1409 | ||
| 1410 | /* If this packet comes from the defer queue, the skb has already | ||
| 1411 | * been validated | ||
| 1412 | */ | ||
| 1413 | if (unlikely(TIPC_SKB_CB(buf)->deferred)) | ||
| 1414 | return 1; | ||
| 1415 | |||
| 1394 | if (unlikely(buf->len < MIN_H_SIZE)) | 1416 | if (unlikely(buf->len < MIN_H_SIZE)) |
| 1395 | return 0; | 1417 | return 0; |
| 1396 | 1418 | ||
| @@ -1435,15 +1457,10 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) | |||
| 1435 | u32 seq_no; | 1457 | u32 seq_no; |
| 1436 | u32 ackd; | 1458 | u32 ackd; |
| 1437 | u32 released = 0; | 1459 | u32 released = 0; |
| 1438 | int type; | ||
| 1439 | 1460 | ||
| 1440 | head = head->next; | 1461 | head = head->next; |
| 1441 | buf->next = NULL; | 1462 | buf->next = NULL; |
| 1442 | 1463 | ||
| 1443 | /* Ensure bearer is still enabled */ | ||
| 1444 | if (unlikely(!b_ptr->active)) | ||
| 1445 | goto discard; | ||
| 1446 | |||
| 1447 | /* Ensure message is well-formed */ | 1464 | /* Ensure message is well-formed */ |
| 1448 | if (unlikely(!link_recv_buf_validate(buf))) | 1465 | if (unlikely(!link_recv_buf_validate(buf))) |
| 1449 | goto discard; | 1466 | goto discard; |
| @@ -1457,9 +1474,9 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) | |||
| 1457 | 1474 | ||
| 1458 | if (unlikely(msg_non_seq(msg))) { | 1475 | if (unlikely(msg_non_seq(msg))) { |
| 1459 | if (msg_user(msg) == LINK_CONFIG) | 1476 | if (msg_user(msg) == LINK_CONFIG) |
| 1460 | tipc_disc_recv_msg(buf, b_ptr); | 1477 | tipc_disc_rcv(buf, b_ptr); |
| 1461 | else | 1478 | else |
| 1462 | tipc_bclink_recv_pkt(buf); | 1479 | tipc_bclink_rcv(buf); |
| 1463 | continue; | 1480 | continue; |
| 1464 | } | 1481 | } |
| 1465 | 1482 | ||
| @@ -1483,7 +1500,7 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) | |||
| 1483 | if ((n_ptr->block_setup & WAIT_PEER_DOWN) && | 1500 | if ((n_ptr->block_setup & WAIT_PEER_DOWN) && |
| 1484 | msg_user(msg) == LINK_PROTOCOL && | 1501 | msg_user(msg) == LINK_PROTOCOL && |
| 1485 | (msg_type(msg) == RESET_MSG || | 1502 | (msg_type(msg) == RESET_MSG || |
| 1486 | msg_type(msg) == ACTIVATE_MSG) && | 1503 | msg_type(msg) == ACTIVATE_MSG) && |
| 1487 | !msg_redundant_link(msg)) | 1504 | !msg_redundant_link(msg)) |
| 1488 | n_ptr->block_setup &= ~WAIT_PEER_DOWN; | 1505 | n_ptr->block_setup &= ~WAIT_PEER_DOWN; |
| 1489 | 1506 | ||
| @@ -1502,7 +1519,6 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) | |||
| 1502 | while ((crs != l_ptr->next_out) && | 1519 | while ((crs != l_ptr->next_out) && |
| 1503 | less_eq(buf_seqno(crs), ackd)) { | 1520 | less_eq(buf_seqno(crs), ackd)) { |
| 1504 | struct sk_buff *next = crs->next; | 1521 | struct sk_buff *next = crs->next; |
| 1505 | |||
| 1506 | kfree_skb(crs); | 1522 | kfree_skb(crs); |
| 1507 | crs = next; | 1523 | crs = next; |
| 1508 | released++; | 1524 | released++; |
| @@ -1515,18 +1531,19 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) | |||
| 1515 | /* Try sending any messages link endpoint has pending */ | 1531 | /* Try sending any messages link endpoint has pending */ |
| 1516 | if (unlikely(l_ptr->next_out)) | 1532 | if (unlikely(l_ptr->next_out)) |
| 1517 | tipc_link_push_queue(l_ptr); | 1533 | tipc_link_push_queue(l_ptr); |
| 1534 | |||
| 1518 | if (unlikely(!list_empty(&l_ptr->waiting_ports))) | 1535 | if (unlikely(!list_empty(&l_ptr->waiting_ports))) |
| 1519 | tipc_link_wakeup_ports(l_ptr, 0); | 1536 | tipc_link_wakeup_ports(l_ptr, 0); |
| 1537 | |||
| 1520 | if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { | 1538 | if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { |
| 1521 | l_ptr->stats.sent_acks++; | 1539 | l_ptr->stats.sent_acks++; |
| 1522 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); | 1540 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
| 1523 | } | 1541 | } |
| 1524 | 1542 | ||
| 1525 | /* Now (finally!) process the incoming message */ | 1543 | /* Process the incoming packet */ |
| 1526 | protocol_check: | ||
| 1527 | if (unlikely(!link_working_working(l_ptr))) { | 1544 | if (unlikely(!link_working_working(l_ptr))) { |
| 1528 | if (msg_user(msg) == LINK_PROTOCOL) { | 1545 | if (msg_user(msg) == LINK_PROTOCOL) { |
| 1529 | link_recv_proto_msg(l_ptr, buf); | 1546 | tipc_link_proto_rcv(l_ptr, buf); |
| 1530 | head = link_insert_deferred_queue(l_ptr, head); | 1547 | head = link_insert_deferred_queue(l_ptr, head); |
| 1531 | tipc_node_unlock(n_ptr); | 1548 | tipc_node_unlock(n_ptr); |
| 1532 | continue; | 1549 | continue; |
| @@ -1555,67 +1572,65 @@ protocol_check: | |||
| 1555 | l_ptr->next_in_no++; | 1572 | l_ptr->next_in_no++; |
| 1556 | if (unlikely(l_ptr->oldest_deferred_in)) | 1573 | if (unlikely(l_ptr->oldest_deferred_in)) |
| 1557 | head = link_insert_deferred_queue(l_ptr, head); | 1574 | head = link_insert_deferred_queue(l_ptr, head); |
| 1558 | deliver: | 1575 | |
| 1559 | if (likely(msg_isdata(msg))) { | 1576 | /* Deliver packet/message to correct user: */ |
| 1560 | tipc_node_unlock(n_ptr); | 1577 | if (unlikely(msg_user(msg) == CHANGEOVER_PROTOCOL)) { |
| 1561 | tipc_port_recv_msg(buf); | 1578 | if (!tipc_link_tunnel_rcv(n_ptr, &buf)) { |
| 1562 | continue; | 1579 | tipc_node_unlock(n_ptr); |
| 1580 | continue; | ||
| 1581 | } | ||
| 1582 | msg = buf_msg(buf); | ||
| 1583 | } else if (msg_user(msg) == MSG_FRAGMENTER) { | ||
| 1584 | int rc; | ||
| 1585 | |||
| 1586 | l_ptr->stats.recv_fragments++; | ||
| 1587 | rc = tipc_link_frag_rcv(&l_ptr->reasm_head, | ||
| 1588 | &l_ptr->reasm_tail, | ||
| 1589 | &buf); | ||
| 1590 | if (rc == LINK_REASM_COMPLETE) { | ||
| 1591 | l_ptr->stats.recv_fragmented++; | ||
| 1592 | msg = buf_msg(buf); | ||
| 1593 | } else { | ||
| 1594 | if (rc == LINK_REASM_ERROR) | ||
| 1595 | tipc_link_reset(l_ptr); | ||
| 1596 | tipc_node_unlock(n_ptr); | ||
| 1597 | continue; | ||
| 1598 | } | ||
| 1563 | } | 1599 | } |
| 1600 | |||
| 1564 | switch (msg_user(msg)) { | 1601 | switch (msg_user(msg)) { |
| 1565 | int ret; | 1602 | case TIPC_LOW_IMPORTANCE: |
| 1603 | case TIPC_MEDIUM_IMPORTANCE: | ||
| 1604 | case TIPC_HIGH_IMPORTANCE: | ||
| 1605 | case TIPC_CRITICAL_IMPORTANCE: | ||
| 1606 | tipc_node_unlock(n_ptr); | ||
| 1607 | tipc_port_rcv(buf); | ||
| 1608 | continue; | ||
| 1566 | case MSG_BUNDLER: | 1609 | case MSG_BUNDLER: |
| 1567 | l_ptr->stats.recv_bundles++; | 1610 | l_ptr->stats.recv_bundles++; |
| 1568 | l_ptr->stats.recv_bundled += msg_msgcnt(msg); | 1611 | l_ptr->stats.recv_bundled += msg_msgcnt(msg); |
| 1569 | tipc_node_unlock(n_ptr); | 1612 | tipc_node_unlock(n_ptr); |
| 1570 | tipc_link_recv_bundle(buf); | 1613 | tipc_link_bundle_rcv(buf); |
| 1571 | continue; | 1614 | continue; |
| 1572 | case NAME_DISTRIBUTOR: | 1615 | case NAME_DISTRIBUTOR: |
| 1573 | n_ptr->bclink.recv_permitted = true; | 1616 | n_ptr->bclink.recv_permitted = true; |
| 1574 | tipc_node_unlock(n_ptr); | 1617 | tipc_node_unlock(n_ptr); |
| 1575 | tipc_named_recv(buf); | 1618 | tipc_named_rcv(buf); |
| 1576 | continue; | ||
| 1577 | case BCAST_PROTOCOL: | ||
| 1578 | tipc_link_recv_sync(n_ptr, buf); | ||
| 1579 | tipc_node_unlock(n_ptr); | ||
| 1580 | continue; | 1619 | continue; |
| 1581 | case CONN_MANAGER: | 1620 | case CONN_MANAGER: |
| 1582 | tipc_node_unlock(n_ptr); | 1621 | tipc_node_unlock(n_ptr); |
| 1583 | tipc_port_recv_proto_msg(buf); | 1622 | tipc_port_proto_rcv(buf); |
| 1584 | continue; | ||
| 1585 | case MSG_FRAGMENTER: | ||
| 1586 | l_ptr->stats.recv_fragments++; | ||
| 1587 | ret = tipc_link_recv_fragment(&l_ptr->reasm_head, | ||
| 1588 | &l_ptr->reasm_tail, | ||
| 1589 | &buf); | ||
| 1590 | if (ret == LINK_REASM_COMPLETE) { | ||
| 1591 | l_ptr->stats.recv_fragmented++; | ||
| 1592 | msg = buf_msg(buf); | ||
| 1593 | goto deliver; | ||
| 1594 | } | ||
| 1595 | if (ret == LINK_REASM_ERROR) | ||
| 1596 | tipc_link_reset(l_ptr); | ||
| 1597 | tipc_node_unlock(n_ptr); | ||
| 1598 | continue; | 1623 | continue; |
| 1599 | case CHANGEOVER_PROTOCOL: | 1624 | case BCAST_PROTOCOL: |
| 1600 | type = msg_type(msg); | 1625 | tipc_link_sync_rcv(n_ptr, buf); |
| 1601 | if (tipc_link_tunnel_rcv(&l_ptr, &buf)) { | ||
| 1602 | msg = buf_msg(buf); | ||
| 1603 | seq_no = msg_seqno(msg); | ||
| 1604 | if (type == ORIGINAL_MSG) | ||
| 1605 | goto deliver; | ||
| 1606 | goto protocol_check; | ||
| 1607 | } | ||
| 1608 | break; | 1626 | break; |
| 1609 | default: | 1627 | default: |
| 1610 | kfree_skb(buf); | 1628 | kfree_skb(buf); |
| 1611 | buf = NULL; | ||
| 1612 | break; | 1629 | break; |
| 1613 | } | 1630 | } |
| 1614 | tipc_node_unlock(n_ptr); | 1631 | tipc_node_unlock(n_ptr); |
| 1615 | tipc_net_route_msg(buf); | ||
| 1616 | continue; | 1632 | continue; |
| 1617 | unlock_discard: | 1633 | unlock_discard: |
| 1618 | |||
| 1619 | tipc_node_unlock(n_ptr); | 1634 | tipc_node_unlock(n_ptr); |
| 1620 | discard: | 1635 | discard: |
| 1621 | kfree_skb(buf); | 1636 | kfree_skb(buf); |
| @@ -1682,7 +1697,7 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | |||
| 1682 | u32 seq_no = buf_seqno(buf); | 1697 | u32 seq_no = buf_seqno(buf); |
| 1683 | 1698 | ||
| 1684 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { | 1699 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { |
| 1685 | link_recv_proto_msg(l_ptr, buf); | 1700 | tipc_link_proto_rcv(l_ptr, buf); |
| 1686 | return; | 1701 | return; |
| 1687 | } | 1702 | } |
| 1688 | 1703 | ||
| @@ -1703,8 +1718,9 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | |||
| 1703 | &l_ptr->newest_deferred_in, buf)) { | 1718 | &l_ptr->newest_deferred_in, buf)) { |
| 1704 | l_ptr->deferred_inqueue_sz++; | 1719 | l_ptr->deferred_inqueue_sz++; |
| 1705 | l_ptr->stats.deferred_recv++; | 1720 | l_ptr->stats.deferred_recv++; |
| 1721 | TIPC_SKB_CB(buf)->deferred = true; | ||
| 1706 | if ((l_ptr->deferred_inqueue_sz % 16) == 1) | 1722 | if ((l_ptr->deferred_inqueue_sz % 16) == 1) |
| 1707 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); | 1723 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
| 1708 | } else | 1724 | } else |
| 1709 | l_ptr->stats.duplicates++; | 1725 | l_ptr->stats.duplicates++; |
| 1710 | } | 1726 | } |
| @@ -1712,9 +1728,8 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | |||
| 1712 | /* | 1728 | /* |
| 1713 | * Send protocol message to the other endpoint. | 1729 | * Send protocol message to the other endpoint. |
| 1714 | */ | 1730 | */ |
| 1715 | void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, | 1731 | void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg, |
| 1716 | int probe_msg, u32 gap, u32 tolerance, | 1732 | u32 gap, u32 tolerance, u32 priority, u32 ack_mtu) |
| 1717 | u32 priority, u32 ack_mtu) | ||
| 1718 | { | 1733 | { |
| 1719 | struct sk_buff *buf = NULL; | 1734 | struct sk_buff *buf = NULL; |
| 1720 | struct tipc_msg *msg = l_ptr->pmsg; | 1735 | struct tipc_msg *msg = l_ptr->pmsg; |
| @@ -1813,7 +1828,7 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, | |||
| 1813 | * Note that network plane id propagates through the network, and may | 1828 | * Note that network plane id propagates through the network, and may |
| 1814 | * change at any time. The node with lowest address rules | 1829 | * change at any time. The node with lowest address rules |
| 1815 | */ | 1830 | */ |
| 1816 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) | 1831 | static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) |
| 1817 | { | 1832 | { |
| 1818 | u32 rec_gap = 0; | 1833 | u32 rec_gap = 0; |
| 1819 | u32 max_pkt_info; | 1834 | u32 max_pkt_info; |
| @@ -1932,8 +1947,8 @@ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 1932 | msg_last_bcast(msg)); | 1947 | msg_last_bcast(msg)); |
| 1933 | 1948 | ||
| 1934 | if (rec_gap || (msg_probe(msg))) { | 1949 | if (rec_gap || (msg_probe(msg))) { |
| 1935 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | 1950 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, rec_gap, 0, |
| 1936 | 0, rec_gap, 0, 0, max_pkt_ack); | 1951 | 0, max_pkt_ack); |
| 1937 | } | 1952 | } |
| 1938 | if (msg_seq_gap(msg)) { | 1953 | if (msg_seq_gap(msg)) { |
| 1939 | l_ptr->stats.recv_nacks++; | 1954 | l_ptr->stats.recv_nacks++; |
| @@ -1972,7 +1987,7 @@ static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr, | |||
| 1972 | } | 1987 | } |
| 1973 | skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); | 1988 | skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); |
| 1974 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); | 1989 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); |
| 1975 | tipc_link_send_buf(tunnel, buf); | 1990 | __tipc_link_xmit(tunnel, buf); |
| 1976 | } | 1991 | } |
| 1977 | 1992 | ||
| 1978 | 1993 | ||
| @@ -2005,7 +2020,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr) | |||
| 2005 | if (buf) { | 2020 | if (buf) { |
| 2006 | skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); | 2021 | skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); |
| 2007 | msg_set_size(&tunnel_hdr, INT_H_SIZE); | 2022 | msg_set_size(&tunnel_hdr, INT_H_SIZE); |
| 2008 | tipc_link_send_buf(tunnel, buf); | 2023 | __tipc_link_xmit(tunnel, buf); |
| 2009 | } else { | 2024 | } else { |
| 2010 | pr_warn("%sunable to send changeover msg\n", | 2025 | pr_warn("%sunable to send changeover msg\n", |
| 2011 | link_co_err); | 2026 | link_co_err); |
| @@ -2039,7 +2054,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr) | |||
| 2039 | } | 2054 | } |
| 2040 | } | 2055 | } |
| 2041 | 2056 | ||
| 2042 | /* tipc_link_dup_send_queue(): A second link has become active. Tunnel a | 2057 | /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a |
| 2043 | * duplicate of the first link's send queue via the new link. This way, we | 2058 | * duplicate of the first link's send queue via the new link. This way, we |
| 2044 | * are guaranteed that currently queued packets from a socket are delivered | 2059 | * are guaranteed that currently queued packets from a socket are delivered |
| 2045 | * before future traffic from the same socket, even if this is using the | 2060 | * before future traffic from the same socket, even if this is using the |
| @@ -2048,7 +2063,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr) | |||
| 2048 | * and sequence order is preserved per sender/receiver socket pair. | 2063 | * and sequence order is preserved per sender/receiver socket pair. |
| 2049 | * Owner node is locked. | 2064 | * Owner node is locked. |
| 2050 | */ | 2065 | */ |
| 2051 | void tipc_link_dup_send_queue(struct tipc_link *l_ptr, | 2066 | void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, |
| 2052 | struct tipc_link *tunnel) | 2067 | struct tipc_link *tunnel) |
| 2053 | { | 2068 | { |
| 2054 | struct sk_buff *iter; | 2069 | struct sk_buff *iter; |
| @@ -2078,7 +2093,7 @@ void tipc_link_dup_send_queue(struct tipc_link *l_ptr, | |||
| 2078 | skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); | 2093 | skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); |
| 2079 | skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, | 2094 | skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, |
| 2080 | length); | 2095 | length); |
| 2081 | tipc_link_send_buf(tunnel, outbuf); | 2096 | __tipc_link_xmit(tunnel, outbuf); |
| 2082 | if (!tipc_link_is_up(l_ptr)) | 2097 | if (!tipc_link_is_up(l_ptr)) |
| 2083 | return; | 2098 | return; |
| 2084 | iter = iter->next; | 2099 | iter = iter->next; |
| @@ -2105,89 +2120,114 @@ static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) | |||
| 2105 | return eb; | 2120 | return eb; |
| 2106 | } | 2121 | } |
| 2107 | 2122 | ||
| 2108 | /* tipc_link_tunnel_rcv(): Receive a tunneled packet, sent | 2123 | |
| 2109 | * via other link as result of a failover (ORIGINAL_MSG) or | 2124 | |
| 2110 | * a new active link (DUPLICATE_MSG). Failover packets are | 2125 | /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet. |
| 2111 | * returned to the active link for delivery upwards. | 2126 | * Owner node is locked. |
| 2127 | */ | ||
| 2128 | static void tipc_link_dup_rcv(struct tipc_link *l_ptr, | ||
| 2129 | struct sk_buff *t_buf) | ||
| 2130 | { | ||
| 2131 | struct sk_buff *buf; | ||
| 2132 | |||
| 2133 | if (!tipc_link_is_up(l_ptr)) | ||
| 2134 | return; | ||
| 2135 | |||
| 2136 | buf = buf_extract(t_buf, INT_H_SIZE); | ||
| 2137 | if (buf == NULL) { | ||
| 2138 | pr_warn("%sfailed to extract inner dup pkt\n", link_co_err); | ||
| 2139 | return; | ||
| 2140 | } | ||
| 2141 | |||
| 2142 | /* Add buffer to deferred queue, if applicable: */ | ||
| 2143 | link_handle_out_of_seq_msg(l_ptr, buf); | ||
| 2144 | } | ||
| 2145 | |||
| 2146 | /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet | ||
| 2112 | * Owner node is locked. | 2147 | * Owner node is locked. |
| 2113 | */ | 2148 | */ |
| 2114 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, | 2149 | static struct sk_buff *tipc_link_failover_rcv(struct tipc_link *l_ptr, |
| 2115 | struct sk_buff **buf) | 2150 | struct sk_buff *t_buf) |
| 2116 | { | 2151 | { |
| 2117 | struct sk_buff *tunnel_buf = *buf; | 2152 | struct tipc_msg *t_msg = buf_msg(t_buf); |
| 2118 | struct tipc_link *dest_link; | 2153 | struct sk_buff *buf = NULL; |
| 2119 | struct tipc_msg *msg; | 2154 | struct tipc_msg *msg; |
| 2120 | struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf); | ||
| 2121 | u32 msg_typ = msg_type(tunnel_msg); | ||
| 2122 | u32 msg_count = msg_msgcnt(tunnel_msg); | ||
| 2123 | u32 bearer_id = msg_bearer_id(tunnel_msg); | ||
| 2124 | 2155 | ||
| 2125 | if (bearer_id >= MAX_BEARERS) | 2156 | if (tipc_link_is_up(l_ptr)) |
| 2126 | goto exit; | 2157 | tipc_link_reset(l_ptr); |
| 2127 | dest_link = (*l_ptr)->owner->links[bearer_id]; | ||
| 2128 | if (!dest_link) | ||
| 2129 | goto exit; | ||
| 2130 | if (dest_link == *l_ptr) { | ||
| 2131 | pr_err("Unexpected changeover message on link <%s>\n", | ||
| 2132 | (*l_ptr)->name); | ||
| 2133 | goto exit; | ||
| 2134 | } | ||
| 2135 | *l_ptr = dest_link; | ||
| 2136 | msg = msg_get_wrapped(tunnel_msg); | ||
| 2137 | 2158 | ||
| 2138 | if (msg_typ == DUPLICATE_MSG) { | 2159 | /* First failover packet? */ |
| 2139 | if (less(msg_seqno(msg), mod(dest_link->next_in_no))) | 2160 | if (l_ptr->exp_msg_count == START_CHANGEOVER) |
| 2140 | goto exit; | 2161 | l_ptr->exp_msg_count = msg_msgcnt(t_msg); |
| 2141 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); | 2162 | |
| 2142 | if (*buf == NULL) { | 2163 | /* Should there be an inner packet? */ |
| 2143 | pr_warn("%sduplicate msg dropped\n", link_co_err); | 2164 | if (l_ptr->exp_msg_count) { |
| 2165 | l_ptr->exp_msg_count--; | ||
| 2166 | buf = buf_extract(t_buf, INT_H_SIZE); | ||
| 2167 | if (buf == NULL) { | ||
| 2168 | pr_warn("%sno inner failover pkt\n", link_co_err); | ||
| 2144 | goto exit; | 2169 | goto exit; |
| 2145 | } | 2170 | } |
| 2146 | kfree_skb(tunnel_buf); | 2171 | msg = buf_msg(buf); |
| 2147 | return 1; | ||
| 2148 | } | ||
| 2149 | 2172 | ||
| 2150 | /* First original message ?: */ | 2173 | if (less(msg_seqno(msg), l_ptr->reset_checkpoint)) { |
| 2151 | if (tipc_link_is_up(dest_link)) { | 2174 | kfree_skb(buf); |
| 2152 | pr_info("%s<%s>, changeover initiated by peer\n", link_rst_msg, | 2175 | buf = NULL; |
| 2153 | dest_link->name); | ||
| 2154 | tipc_link_reset(dest_link); | ||
| 2155 | dest_link->exp_msg_count = msg_count; | ||
| 2156 | if (!msg_count) | ||
| 2157 | goto exit; | ||
| 2158 | } else if (dest_link->exp_msg_count == START_CHANGEOVER) { | ||
| 2159 | dest_link->exp_msg_count = msg_count; | ||
| 2160 | if (!msg_count) | ||
| 2161 | goto exit; | 2176 | goto exit; |
| 2177 | } | ||
| 2178 | if (msg_user(msg) == MSG_FRAGMENTER) { | ||
| 2179 | l_ptr->stats.recv_fragments++; | ||
| 2180 | tipc_link_frag_rcv(&l_ptr->reasm_head, | ||
| 2181 | &l_ptr->reasm_tail, | ||
| 2182 | &buf); | ||
| 2183 | } | ||
| 2162 | } | 2184 | } |
| 2185 | exit: | ||
| 2186 | if ((l_ptr->exp_msg_count == 0) && (l_ptr->flags & LINK_STOPPED)) { | ||
| 2187 | tipc_node_detach_link(l_ptr->owner, l_ptr); | ||
| 2188 | kfree(l_ptr); | ||
| 2189 | } | ||
| 2190 | return buf; | ||
| 2191 | } | ||
| 2192 | |||
| 2193 | /* tipc_link_tunnel_rcv(): Receive a tunnelled packet, sent | ||
| 2194 | * via other link as result of a failover (ORIGINAL_MSG) or | ||
| 2195 | * a new active link (DUPLICATE_MSG). Failover packets are | ||
| 2196 | * returned to the active link for delivery upwards. | ||
| 2197 | * Owner node is locked. | ||
| 2198 | */ | ||
| 2199 | static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | ||
| 2200 | struct sk_buff **buf) | ||
| 2201 | { | ||
| 2202 | struct sk_buff *t_buf = *buf; | ||
| 2203 | struct tipc_link *l_ptr; | ||
| 2204 | struct tipc_msg *t_msg = buf_msg(t_buf); | ||
| 2205 | u32 bearer_id = msg_bearer_id(t_msg); | ||
| 2206 | |||
| 2207 | *buf = NULL; | ||
| 2163 | 2208 | ||
| 2164 | /* Receive original message */ | 2209 | if (bearer_id >= MAX_BEARERS) |
| 2165 | if (dest_link->exp_msg_count == 0) { | ||
| 2166 | pr_warn("%sgot too many tunnelled messages\n", link_co_err); | ||
| 2167 | goto exit; | 2210 | goto exit; |
| 2168 | } | 2211 | |
| 2169 | dest_link->exp_msg_count--; | 2212 | l_ptr = n_ptr->links[bearer_id]; |
| 2170 | if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { | 2213 | if (!l_ptr) |
| 2171 | goto exit; | 2214 | goto exit; |
| 2172 | } else { | 2215 | |
| 2173 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); | 2216 | if (msg_type(t_msg) == DUPLICATE_MSG) |
| 2174 | if (*buf != NULL) { | 2217 | tipc_link_dup_rcv(l_ptr, t_buf); |
| 2175 | kfree_skb(tunnel_buf); | 2218 | else if (msg_type(t_msg) == ORIGINAL_MSG) |
| 2176 | return 1; | 2219 | *buf = tipc_link_failover_rcv(l_ptr, t_buf); |
| 2177 | } else { | 2220 | else |
| 2178 | pr_warn("%soriginal msg dropped\n", link_co_err); | 2221 | pr_warn("%sunknown tunnel pkt received\n", link_co_err); |
| 2179 | } | ||
| 2180 | } | ||
| 2181 | exit: | 2222 | exit: |
| 2182 | *buf = NULL; | 2223 | kfree_skb(t_buf); |
| 2183 | kfree_skb(tunnel_buf); | 2224 | return *buf != NULL; |
| 2184 | return 0; | ||
| 2185 | } | 2225 | } |
| 2186 | 2226 | ||
| 2187 | /* | 2227 | /* |
| 2188 | * Bundler functionality: | 2228 | * Bundler functionality: |
| 2189 | */ | 2229 | */ |
| 2190 | void tipc_link_recv_bundle(struct sk_buff *buf) | 2230 | void tipc_link_bundle_rcv(struct sk_buff *buf) |
| 2191 | { | 2231 | { |
| 2192 | u32 msgcount = msg_msgcnt(buf_msg(buf)); | 2232 | u32 msgcount = msg_msgcnt(buf_msg(buf)); |
| 2193 | u32 pos = INT_H_SIZE; | 2233 | u32 pos = INT_H_SIZE; |
| @@ -2210,11 +2250,11 @@ void tipc_link_recv_bundle(struct sk_buff *buf) | |||
| 2210 | */ | 2250 | */ |
| 2211 | 2251 | ||
| 2212 | /* | 2252 | /* |
| 2213 | * link_send_long_buf: Entry for buffers needing fragmentation. | 2253 | * tipc_link_frag_xmit: Entry for buffers needing fragmentation. |
| 2214 | * The buffer is complete, inclusive total message length. | 2254 | * The buffer is complete, inclusive total message length. |
| 2215 | * Returns user data length. | 2255 | * Returns user data length. |
| 2216 | */ | 2256 | */ |
| 2217 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | 2257 | static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf) |
| 2218 | { | 2258 | { |
| 2219 | struct sk_buff *buf_chain = NULL; | 2259 | struct sk_buff *buf_chain = NULL; |
| 2220 | struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; | 2260 | struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; |
| @@ -2277,12 +2317,11 @@ static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 2277 | return dsz; | 2317 | return dsz; |
| 2278 | } | 2318 | } |
| 2279 | 2319 | ||
| 2280 | /* | 2320 | /* tipc_link_frag_rcv(): Called with node lock on. Returns |
| 2281 | * tipc_link_recv_fragment(): Called with node lock on. Returns | ||
| 2282 | * the reassembled buffer if message is complete. | 2321 | * the reassembled buffer if message is complete. |
| 2283 | */ | 2322 | */ |
| 2284 | int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail, | 2323 | int tipc_link_frag_rcv(struct sk_buff **head, struct sk_buff **tail, |
| 2285 | struct sk_buff **fbuf) | 2324 | struct sk_buff **fbuf) |
| 2286 | { | 2325 | { |
| 2287 | struct sk_buff *frag = *fbuf; | 2326 | struct sk_buff *frag = *fbuf; |
| 2288 | struct tipc_msg *msg = buf_msg(frag); | 2327 | struct tipc_msg *msg = buf_msg(frag); |
| @@ -2296,6 +2335,7 @@ int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail, | |||
| 2296 | goto out_free; | 2335 | goto out_free; |
| 2297 | *head = frag; | 2336 | *head = frag; |
| 2298 | skb_frag_list_init(*head); | 2337 | skb_frag_list_init(*head); |
| 2338 | *fbuf = NULL; | ||
| 2299 | return 0; | 2339 | return 0; |
| 2300 | } else if (*head && | 2340 | } else if (*head && |
| 2301 | skb_try_coalesce(*head, frag, &headstolen, &delta)) { | 2341 | skb_try_coalesce(*head, frag, &headstolen, &delta)) { |
| @@ -2315,10 +2355,12 @@ int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail, | |||
| 2315 | *tail = *head = NULL; | 2355 | *tail = *head = NULL; |
| 2316 | return LINK_REASM_COMPLETE; | 2356 | return LINK_REASM_COMPLETE; |
| 2317 | } | 2357 | } |
| 2358 | *fbuf = NULL; | ||
| 2318 | return 0; | 2359 | return 0; |
| 2319 | out_free: | 2360 | out_free: |
| 2320 | pr_warn_ratelimited("Link unable to reassemble fragmented message\n"); | 2361 | pr_warn_ratelimited("Link unable to reassemble fragmented message\n"); |
| 2321 | kfree_skb(*fbuf); | 2362 | kfree_skb(*fbuf); |
| 2363 | *fbuf = NULL; | ||
| 2322 | return LINK_REASM_ERROR; | 2364 | return LINK_REASM_ERROR; |
| 2323 | } | 2365 | } |
| 2324 | 2366 | ||
| @@ -2352,35 +2394,41 @@ void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) | |||
| 2352 | l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; | 2394 | l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; |
| 2353 | } | 2395 | } |
| 2354 | 2396 | ||
| 2355 | /** | 2397 | /* tipc_link_find_owner - locate owner node of link by link's name |
| 2356 | * link_find_link - locate link by name | 2398 | * @name: pointer to link name string |
| 2357 | * @name: ptr to link name string | 2399 | * @bearer_id: pointer to index in 'node->links' array where the link was found. |
| 2358 | * @node: ptr to area to be filled with ptr to associated node | ||
| 2359 | * | ||
| 2360 | * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted; | 2400 | * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted; |
| 2361 | * this also prevents link deletion. | 2401 | * this also prevents link deletion. |
| 2362 | * | 2402 | * |
| 2363 | * Returns pointer to link (or 0 if invalid link name). | 2403 | * Returns pointer to node owning the link, or 0 if no matching link is found. |
| 2364 | */ | 2404 | */ |
| 2365 | static struct tipc_link *link_find_link(const char *name, | 2405 | static struct tipc_node *tipc_link_find_owner(const char *link_name, |
| 2366 | struct tipc_node **node) | 2406 | unsigned int *bearer_id) |
| 2367 | { | 2407 | { |
| 2368 | struct tipc_link *l_ptr; | 2408 | struct tipc_link *l_ptr; |
| 2369 | struct tipc_node *n_ptr; | 2409 | struct tipc_node *n_ptr; |
| 2410 | struct tipc_node *found_node = 0; | ||
| 2370 | int i; | 2411 | int i; |
| 2371 | 2412 | ||
| 2372 | list_for_each_entry(n_ptr, &tipc_node_list, list) { | 2413 | *bearer_id = 0; |
| 2414 | rcu_read_lock(); | ||
| 2415 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
| 2416 | tipc_node_lock(n_ptr); | ||
| 2373 | for (i = 0; i < MAX_BEARERS; i++) { | 2417 | for (i = 0; i < MAX_BEARERS; i++) { |
| 2374 | l_ptr = n_ptr->links[i]; | 2418 | l_ptr = n_ptr->links[i]; |
| 2375 | if (l_ptr && !strcmp(l_ptr->name, name)) | 2419 | if (l_ptr && !strcmp(l_ptr->name, link_name)) { |
| 2376 | goto found; | 2420 | *bearer_id = i; |
| 2421 | found_node = n_ptr; | ||
| 2422 | break; | ||
| 2423 | } | ||
| 2377 | } | 2424 | } |
| 2425 | tipc_node_unlock(n_ptr); | ||
| 2426 | if (found_node) | ||
| 2427 | break; | ||
| 2378 | } | 2428 | } |
| 2379 | l_ptr = NULL; | 2429 | rcu_read_unlock(); |
| 2380 | n_ptr = NULL; | 2430 | |
| 2381 | found: | 2431 | return found_node; |
| 2382 | *node = n_ptr; | ||
| 2383 | return l_ptr; | ||
| 2384 | } | 2432 | } |
| 2385 | 2433 | ||
| 2386 | /** | 2434 | /** |
| @@ -2422,32 +2470,33 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) | |||
| 2422 | struct tipc_link *l_ptr; | 2470 | struct tipc_link *l_ptr; |
| 2423 | struct tipc_bearer *b_ptr; | 2471 | struct tipc_bearer *b_ptr; |
| 2424 | struct tipc_media *m_ptr; | 2472 | struct tipc_media *m_ptr; |
| 2473 | int bearer_id; | ||
| 2425 | int res = 0; | 2474 | int res = 0; |
| 2426 | 2475 | ||
| 2427 | l_ptr = link_find_link(name, &node); | 2476 | node = tipc_link_find_owner(name, &bearer_id); |
| 2428 | if (l_ptr) { | 2477 | if (node) { |
| 2429 | /* | ||
| 2430 | * acquire node lock for tipc_link_send_proto_msg(). | ||
| 2431 | * see "TIPC locking policy" in net.c. | ||
| 2432 | */ | ||
| 2433 | tipc_node_lock(node); | 2478 | tipc_node_lock(node); |
| 2434 | switch (cmd) { | 2479 | l_ptr = node->links[bearer_id]; |
| 2435 | case TIPC_CMD_SET_LINK_TOL: | 2480 | |
| 2436 | link_set_supervision_props(l_ptr, new_value); | 2481 | if (l_ptr) { |
| 2437 | tipc_link_send_proto_msg(l_ptr, | 2482 | switch (cmd) { |
| 2438 | STATE_MSG, 0, 0, new_value, 0, 0); | 2483 | case TIPC_CMD_SET_LINK_TOL: |
| 2439 | break; | 2484 | link_set_supervision_props(l_ptr, new_value); |
| 2440 | case TIPC_CMD_SET_LINK_PRI: | 2485 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, |
| 2441 | l_ptr->priority = new_value; | 2486 | new_value, 0, 0); |
| 2442 | tipc_link_send_proto_msg(l_ptr, | 2487 | break; |
| 2443 | STATE_MSG, 0, 0, 0, new_value, 0); | 2488 | case TIPC_CMD_SET_LINK_PRI: |
| 2444 | break; | 2489 | l_ptr->priority = new_value; |
| 2445 | case TIPC_CMD_SET_LINK_WINDOW: | 2490 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, |
| 2446 | tipc_link_set_queue_limits(l_ptr, new_value); | 2491 | 0, new_value, 0); |
| 2447 | break; | 2492 | break; |
| 2448 | default: | 2493 | case TIPC_CMD_SET_LINK_WINDOW: |
| 2449 | res = -EINVAL; | 2494 | tipc_link_set_queue_limits(l_ptr, new_value); |
| 2450 | break; | 2495 | break; |
| 2496 | default: | ||
| 2497 | res = -EINVAL; | ||
| 2498 | break; | ||
| 2499 | } | ||
| 2451 | } | 2500 | } |
| 2452 | tipc_node_unlock(node); | 2501 | tipc_node_unlock(node); |
| 2453 | return res; | 2502 | return res; |
| @@ -2542,6 +2591,7 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_ | |||
| 2542 | char *link_name; | 2591 | char *link_name; |
| 2543 | struct tipc_link *l_ptr; | 2592 | struct tipc_link *l_ptr; |
| 2544 | struct tipc_node *node; | 2593 | struct tipc_node *node; |
| 2594 | unsigned int bearer_id; | ||
| 2545 | 2595 | ||
| 2546 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) | 2596 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) |
| 2547 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 2597 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| @@ -2552,15 +2602,19 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_ | |||
| 2552 | return tipc_cfg_reply_error_string("link not found"); | 2602 | return tipc_cfg_reply_error_string("link not found"); |
| 2553 | return tipc_cfg_reply_none(); | 2603 | return tipc_cfg_reply_none(); |
| 2554 | } | 2604 | } |
| 2555 | |||
| 2556 | read_lock_bh(&tipc_net_lock); | 2605 | read_lock_bh(&tipc_net_lock); |
| 2557 | l_ptr = link_find_link(link_name, &node); | 2606 | node = tipc_link_find_owner(link_name, &bearer_id); |
| 2558 | if (!l_ptr) { | 2607 | if (!node) { |
| 2559 | read_unlock_bh(&tipc_net_lock); | 2608 | read_unlock_bh(&tipc_net_lock); |
| 2560 | return tipc_cfg_reply_error_string("link not found"); | 2609 | return tipc_cfg_reply_error_string("link not found"); |
| 2561 | } | 2610 | } |
| 2562 | |||
| 2563 | tipc_node_lock(node); | 2611 | tipc_node_lock(node); |
| 2612 | l_ptr = node->links[bearer_id]; | ||
| 2613 | if (!l_ptr) { | ||
| 2614 | tipc_node_unlock(node); | ||
| 2615 | read_unlock_bh(&tipc_net_lock); | ||
| 2616 | return tipc_cfg_reply_error_string("link not found"); | ||
| 2617 | } | ||
| 2564 | link_reset_statistics(l_ptr); | 2618 | link_reset_statistics(l_ptr); |
| 2565 | tipc_node_unlock(node); | 2619 | tipc_node_unlock(node); |
| 2566 | read_unlock_bh(&tipc_net_lock); | 2620 | read_unlock_bh(&tipc_net_lock); |
| @@ -2590,18 +2644,27 @@ static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) | |||
| 2590 | struct tipc_node *node; | 2644 | struct tipc_node *node; |
| 2591 | char *status; | 2645 | char *status; |
| 2592 | u32 profile_total = 0; | 2646 | u32 profile_total = 0; |
| 2647 | unsigned int bearer_id; | ||
| 2593 | int ret; | 2648 | int ret; |
| 2594 | 2649 | ||
| 2595 | if (!strcmp(name, tipc_bclink_name)) | 2650 | if (!strcmp(name, tipc_bclink_name)) |
| 2596 | return tipc_bclink_stats(buf, buf_size); | 2651 | return tipc_bclink_stats(buf, buf_size); |
| 2597 | 2652 | ||
| 2598 | read_lock_bh(&tipc_net_lock); | 2653 | read_lock_bh(&tipc_net_lock); |
| 2599 | l = link_find_link(name, &node); | 2654 | node = tipc_link_find_owner(name, &bearer_id); |
| 2600 | if (!l) { | 2655 | if (!node) { |
| 2601 | read_unlock_bh(&tipc_net_lock); | 2656 | read_unlock_bh(&tipc_net_lock); |
| 2602 | return 0; | 2657 | return 0; |
| 2603 | } | 2658 | } |
| 2604 | tipc_node_lock(node); | 2659 | tipc_node_lock(node); |
| 2660 | |||
| 2661 | l = node->links[bearer_id]; | ||
| 2662 | if (!l) { | ||
| 2663 | tipc_node_unlock(node); | ||
| 2664 | read_unlock_bh(&tipc_net_lock); | ||
| 2665 | return 0; | ||
| 2666 | } | ||
| 2667 | |||
| 2605 | s = &l->stats; | 2668 | s = &l->stats; |
| 2606 | 2669 | ||
| 2607 | if (tipc_link_is_active(l)) | 2670 | if (tipc_link_is_active(l)) |
diff --git a/net/tipc/link.h b/net/tipc/link.h index 3b6aa65b608c..8c0b49b5b2ee 100644 --- a/net/tipc/link.h +++ b/net/tipc/link.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/link.h: Include file for TIPC link code | 2 | * net/tipc/link.h: Include file for TIPC link code |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 1995-2006, Ericsson AB | 4 | * Copyright (c) 1995-2006, 2013, Ericsson AB |
| 5 | * Copyright (c) 2004-2005, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2004-2005, 2010-2011, Wind River Systems |
| 6 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| @@ -40,27 +40,28 @@ | |||
| 40 | #include "msg.h" | 40 | #include "msg.h" |
| 41 | #include "node.h" | 41 | #include "node.h" |
| 42 | 42 | ||
| 43 | /* | 43 | /* Link reassembly status codes |
| 44 | * Link reassembly status codes | ||
| 45 | */ | 44 | */ |
| 46 | #define LINK_REASM_ERROR -1 | 45 | #define LINK_REASM_ERROR -1 |
| 47 | #define LINK_REASM_COMPLETE 1 | 46 | #define LINK_REASM_COMPLETE 1 |
| 48 | 47 | ||
| 49 | /* | 48 | /* Out-of-range value for link sequence numbers |
| 50 | * Out-of-range value for link sequence numbers | ||
| 51 | */ | 49 | */ |
| 52 | #define INVALID_LINK_SEQ 0x10000 | 50 | #define INVALID_LINK_SEQ 0x10000 |
| 53 | 51 | ||
| 54 | /* | 52 | /* Link working states |
| 55 | * Link states | ||
| 56 | */ | 53 | */ |
| 57 | #define WORKING_WORKING 560810u | 54 | #define WORKING_WORKING 560810u |
| 58 | #define WORKING_UNKNOWN 560811u | 55 | #define WORKING_UNKNOWN 560811u |
| 59 | #define RESET_UNKNOWN 560812u | 56 | #define RESET_UNKNOWN 560812u |
| 60 | #define RESET_RESET 560813u | 57 | #define RESET_RESET 560813u |
| 61 | 58 | ||
| 62 | /* | 59 | /* Link endpoint execution states |
| 63 | * Starting value for maximum packet size negotiation on unicast links | 60 | */ |
| 61 | #define LINK_STARTED 0x0001 | ||
| 62 | #define LINK_STOPPED 0x0002 | ||
| 63 | |||
| 64 | /* Starting value for maximum packet size negotiation on unicast links | ||
| 64 | * (unless bearer MTU is less) | 65 | * (unless bearer MTU is less) |
| 65 | */ | 66 | */ |
| 66 | #define MAX_PKT_DEFAULT 1500 | 67 | #define MAX_PKT_DEFAULT 1500 |
| @@ -102,8 +103,7 @@ struct tipc_stats { | |||
| 102 | * @media_addr: media address to use when sending messages over link | 103 | * @media_addr: media address to use when sending messages over link |
| 103 | * @timer: link timer | 104 | * @timer: link timer |
| 104 | * @owner: pointer to peer node | 105 | * @owner: pointer to peer node |
| 105 | * @link_list: adjacent links in bearer's list of links | 106 | * @flags: execution state flags for link endpoint instance |
| 106 | * @started: indicates if link has been started | ||
| 107 | * @checkpoint: reference point for triggering link continuity checking | 107 | * @checkpoint: reference point for triggering link continuity checking |
| 108 | * @peer_session: link session # being used by peer end of link | 108 | * @peer_session: link session # being used by peer end of link |
| 109 | * @peer_bearer_id: bearer id used by link's peer endpoint | 109 | * @peer_bearer_id: bearer id used by link's peer endpoint |
| @@ -149,10 +149,9 @@ struct tipc_link { | |||
| 149 | struct tipc_media_addr media_addr; | 149 | struct tipc_media_addr media_addr; |
| 150 | struct timer_list timer; | 150 | struct timer_list timer; |
| 151 | struct tipc_node *owner; | 151 | struct tipc_node *owner; |
| 152 | struct list_head link_list; | ||
| 153 | 152 | ||
| 154 | /* Management and link supervision data */ | 153 | /* Management and link supervision data */ |
| 155 | int started; | 154 | unsigned int flags; |
| 156 | u32 checkpoint; | 155 | u32 checkpoint; |
| 157 | u32 peer_session; | 156 | u32 peer_session; |
| 158 | u32 peer_bearer_id; | 157 | u32 peer_bearer_id; |
| @@ -215,10 +214,9 @@ struct tipc_port; | |||
| 215 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | 214 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, |
| 216 | struct tipc_bearer *b_ptr, | 215 | struct tipc_bearer *b_ptr, |
| 217 | const struct tipc_media_addr *media_addr); | 216 | const struct tipc_media_addr *media_addr); |
| 218 | void tipc_link_delete(struct tipc_link *l_ptr); | 217 | void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down); |
| 219 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr); | 218 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr); |
| 220 | void tipc_link_dup_send_queue(struct tipc_link *l_ptr, | 219 | void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, struct tipc_link *dest); |
| 221 | struct tipc_link *dest); | ||
| 222 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); | 220 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); |
| 223 | int tipc_link_is_up(struct tipc_link *l_ptr); | 221 | int tipc_link_is_up(struct tipc_link *l_ptr); |
| 224 | int tipc_link_is_active(struct tipc_link *l_ptr); | 222 | int tipc_link_is_active(struct tipc_link *l_ptr); |
| @@ -231,23 +229,24 @@ struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, | |||
| 231 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, | 229 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, |
| 232 | int req_tlv_space); | 230 | int req_tlv_space); |
| 233 | void tipc_link_reset(struct tipc_link *l_ptr); | 231 | void tipc_link_reset(struct tipc_link *l_ptr); |
| 234 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector); | 232 | void tipc_link_reset_list(unsigned int bearer_id); |
| 235 | void tipc_link_send_names(struct list_head *message_list, u32 dest); | 233 | int tipc_link_xmit(struct sk_buff *buf, u32 dest, u32 selector); |
| 234 | void tipc_link_names_xmit(struct list_head *message_list, u32 dest); | ||
| 235 | int __tipc_link_xmit(struct tipc_link *l_ptr, struct sk_buff *buf); | ||
| 236 | int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf); | 236 | int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf); |
| 237 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector); | 237 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector); |
| 238 | int tipc_link_send_sections_fast(struct tipc_port *sender, | 238 | int tipc_link_iovec_xmit_fast(struct tipc_port *sender, |
| 239 | struct iovec const *msg_sect, | 239 | struct iovec const *msg_sect, |
| 240 | unsigned int len, u32 destnode); | 240 | unsigned int len, u32 destnode); |
| 241 | void tipc_link_recv_bundle(struct sk_buff *buf); | 241 | void tipc_link_bundle_rcv(struct sk_buff *buf); |
| 242 | int tipc_link_recv_fragment(struct sk_buff **reasm_head, | 242 | int tipc_link_frag_rcv(struct sk_buff **reasm_head, |
| 243 | struct sk_buff **reasm_tail, | 243 | struct sk_buff **reasm_tail, |
| 244 | struct sk_buff **fbuf); | 244 | struct sk_buff **fbuf); |
| 245 | void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, int prob, | 245 | void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int prob, |
| 246 | u32 gap, u32 tolerance, u32 priority, | 246 | u32 gap, u32 tolerance, u32 priority, u32 acked_mtu); |
| 247 | u32 acked_mtu); | ||
| 248 | void tipc_link_push_queue(struct tipc_link *l_ptr); | 247 | void tipc_link_push_queue(struct tipc_link *l_ptr); |
| 249 | u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, | 248 | u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, |
| 250 | struct sk_buff *buf); | 249 | struct sk_buff *buf); |
| 251 | void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all); | 250 | void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all); |
| 252 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window); | 251 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window); |
| 253 | void tipc_link_retransmit(struct tipc_link *l_ptr, | 252 | void tipc_link_retransmit(struct tipc_link *l_ptr, |
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index e0d08055754e..aff8041dc157 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c | |||
| @@ -131,16 +131,24 @@ static void named_cluster_distribute(struct sk_buff *buf) | |||
| 131 | { | 131 | { |
| 132 | struct sk_buff *buf_copy; | 132 | struct sk_buff *buf_copy; |
| 133 | struct tipc_node *n_ptr; | 133 | struct tipc_node *n_ptr; |
| 134 | struct tipc_link *l_ptr; | ||
| 134 | 135 | ||
| 135 | list_for_each_entry(n_ptr, &tipc_node_list, list) { | 136 | rcu_read_lock(); |
| 136 | if (tipc_node_active_links(n_ptr)) { | 137 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { |
| 138 | spin_lock_bh(&n_ptr->lock); | ||
| 139 | l_ptr = n_ptr->active_links[n_ptr->addr & 1]; | ||
| 140 | if (l_ptr) { | ||
| 137 | buf_copy = skb_copy(buf, GFP_ATOMIC); | 141 | buf_copy = skb_copy(buf, GFP_ATOMIC); |
| 138 | if (!buf_copy) | 142 | if (!buf_copy) { |
| 143 | spin_unlock_bh(&n_ptr->lock); | ||
| 139 | break; | 144 | break; |
| 145 | } | ||
| 140 | msg_set_destnode(buf_msg(buf_copy), n_ptr->addr); | 146 | msg_set_destnode(buf_msg(buf_copy), n_ptr->addr); |
| 141 | tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr); | 147 | __tipc_link_xmit(l_ptr, buf_copy); |
| 142 | } | 148 | } |
| 149 | spin_unlock_bh(&n_ptr->lock); | ||
| 143 | } | 150 | } |
| 151 | rcu_read_unlock(); | ||
| 144 | 152 | ||
| 145 | kfree_skb(buf); | 153 | kfree_skb(buf); |
| 146 | } | 154 | } |
| @@ -262,7 +270,7 @@ void tipc_named_node_up(unsigned long nodearg) | |||
| 262 | named_distribute(&message_list, node, &publ_zone, max_item_buf); | 270 | named_distribute(&message_list, node, &publ_zone, max_item_buf); |
| 263 | read_unlock_bh(&tipc_nametbl_lock); | 271 | read_unlock_bh(&tipc_nametbl_lock); |
| 264 | 272 | ||
| 265 | tipc_link_send_names(&message_list, node); | 273 | tipc_link_names_xmit(&message_list, node); |
| 266 | } | 274 | } |
| 267 | 275 | ||
| 268 | /** | 276 | /** |
| @@ -293,9 +301,9 @@ static void named_purge_publ(struct publication *publ) | |||
| 293 | } | 301 | } |
| 294 | 302 | ||
| 295 | /** | 303 | /** |
| 296 | * tipc_named_recv - process name table update message sent by another node | 304 | * tipc_named_rcv - process name table update message sent by another node |
| 297 | */ | 305 | */ |
| 298 | void tipc_named_recv(struct sk_buff *buf) | 306 | void tipc_named_rcv(struct sk_buff *buf) |
| 299 | { | 307 | { |
| 300 | struct publication *publ; | 308 | struct publication *publ; |
| 301 | struct tipc_msg *msg = buf_msg(buf); | 309 | struct tipc_msg *msg = buf_msg(buf); |
diff --git a/net/tipc/name_distr.h b/net/tipc/name_distr.h index 1e41bdd4f255..9b312ccfd43e 100644 --- a/net/tipc/name_distr.h +++ b/net/tipc/name_distr.h | |||
| @@ -42,7 +42,7 @@ | |||
| 42 | void tipc_named_publish(struct publication *publ); | 42 | void tipc_named_publish(struct publication *publ); |
| 43 | void tipc_named_withdraw(struct publication *publ); | 43 | void tipc_named_withdraw(struct publication *publ); |
| 44 | void tipc_named_node_up(unsigned long node); | 44 | void tipc_named_node_up(unsigned long node); |
| 45 | void tipc_named_recv(struct sk_buff *buf); | 45 | void tipc_named_rcv(struct sk_buff *buf); |
| 46 | void tipc_named_reinit(void); | 46 | void tipc_named_reinit(void); |
| 47 | 47 | ||
| 48 | #endif | 48 | #endif |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 92a1533af4e0..042e8e3cabc0 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
| @@ -941,20 +941,48 @@ int tipc_nametbl_init(void) | |||
| 941 | return 0; | 941 | return 0; |
| 942 | } | 942 | } |
| 943 | 943 | ||
| 944 | void tipc_nametbl_stop(void) | 944 | /** |
| 945 | * tipc_purge_publications - remove all publications for a given type | ||
| 946 | * | ||
| 947 | * tipc_nametbl_lock must be held when calling this function | ||
| 948 | */ | ||
| 949 | static void tipc_purge_publications(struct name_seq *seq) | ||
| 945 | { | 950 | { |
| 946 | u32 i; | 951 | struct publication *publ, *safe; |
| 952 | struct sub_seq *sseq; | ||
| 953 | struct name_info *info; | ||
| 947 | 954 | ||
| 948 | if (!table.types) | 955 | if (!seq->sseqs) { |
| 956 | nameseq_delete_empty(seq); | ||
| 949 | return; | 957 | return; |
| 958 | } | ||
| 959 | sseq = seq->sseqs; | ||
| 960 | info = sseq->info; | ||
| 961 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { | ||
| 962 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, | ||
| 963 | publ->ref, publ->key); | ||
| 964 | } | ||
| 965 | } | ||
| 966 | |||
| 967 | void tipc_nametbl_stop(void) | ||
| 968 | { | ||
| 969 | u32 i; | ||
| 970 | struct name_seq *seq; | ||
| 971 | struct hlist_head *seq_head; | ||
| 972 | struct hlist_node *safe; | ||
| 950 | 973 | ||
| 951 | /* Verify name table is empty, then release it */ | 974 | /* Verify name table is empty and purge any lingering |
| 975 | * publications, then release the name table | ||
| 976 | */ | ||
| 952 | write_lock_bh(&tipc_nametbl_lock); | 977 | write_lock_bh(&tipc_nametbl_lock); |
| 953 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 978 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 954 | if (hlist_empty(&table.types[i])) | 979 | if (hlist_empty(&table.types[i])) |
| 955 | continue; | 980 | continue; |
| 956 | pr_err("nametbl_stop(): orphaned hash chain detected\n"); | 981 | seq_head = &table.types[i]; |
| 957 | break; | 982 | hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) { |
| 983 | tipc_purge_publications(seq); | ||
| 984 | } | ||
| 985 | continue; | ||
| 958 | } | 986 | } |
| 959 | kfree(table.types); | 987 | kfree(table.types); |
| 960 | table.types = NULL; | 988 | table.types = NULL; |
diff --git a/net/tipc/net.c b/net/tipc/net.c index 7d305ecc09c2..4c564eb69e1a 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
| @@ -146,19 +146,19 @@ void tipc_net_route_msg(struct sk_buff *buf) | |||
| 146 | if (tipc_in_scope(dnode, tipc_own_addr)) { | 146 | if (tipc_in_scope(dnode, tipc_own_addr)) { |
| 147 | if (msg_isdata(msg)) { | 147 | if (msg_isdata(msg)) { |
| 148 | if (msg_mcast(msg)) | 148 | if (msg_mcast(msg)) |
| 149 | tipc_port_recv_mcast(buf, NULL); | 149 | tipc_port_mcast_rcv(buf, NULL); |
| 150 | else if (msg_destport(msg)) | 150 | else if (msg_destport(msg)) |
| 151 | tipc_port_recv_msg(buf); | 151 | tipc_port_rcv(buf); |
| 152 | else | 152 | else |
| 153 | net_route_named_msg(buf); | 153 | net_route_named_msg(buf); |
| 154 | return; | 154 | return; |
| 155 | } | 155 | } |
| 156 | switch (msg_user(msg)) { | 156 | switch (msg_user(msg)) { |
| 157 | case NAME_DISTRIBUTOR: | 157 | case NAME_DISTRIBUTOR: |
| 158 | tipc_named_recv(buf); | 158 | tipc_named_rcv(buf); |
| 159 | break; | 159 | break; |
| 160 | case CONN_MANAGER: | 160 | case CONN_MANAGER: |
| 161 | tipc_port_recv_proto_msg(buf); | 161 | tipc_port_proto_rcv(buf); |
| 162 | break; | 162 | break; |
| 163 | default: | 163 | default: |
| 164 | kfree_skb(buf); | 164 | kfree_skb(buf); |
| @@ -168,7 +168,7 @@ void tipc_net_route_msg(struct sk_buff *buf) | |||
| 168 | 168 | ||
| 169 | /* Handle message for another node */ | 169 | /* Handle message for another node */ |
| 170 | skb_trim(buf, msg_size(msg)); | 170 | skb_trim(buf, msg_size(msg)); |
| 171 | tipc_link_send(buf, dnode, msg_link_selector(msg)); | 171 | tipc_link_xmit(buf, dnode, msg_link_selector(msg)); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | void tipc_net_start(u32 addr) | 174 | void tipc_net_start(u32 addr) |
| @@ -182,8 +182,8 @@ void tipc_net_start(u32 addr) | |||
| 182 | tipc_bclink_init(); | 182 | tipc_bclink_init(); |
| 183 | write_unlock_bh(&tipc_net_lock); | 183 | write_unlock_bh(&tipc_net_lock); |
| 184 | 184 | ||
| 185 | tipc_cfg_reinit(); | 185 | tipc_nametbl_publish(TIPC_CFG_SRV, tipc_own_addr, tipc_own_addr, |
| 186 | 186 | TIPC_ZONE_SCOPE, 0, tipc_own_addr); | |
| 187 | pr_info("Started in network mode\n"); | 187 | pr_info("Started in network mode\n"); |
| 188 | pr_info("Own node address %s, network identity %u\n", | 188 | pr_info("Own node address %s, network identity %u\n", |
| 189 | tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); | 189 | tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); |
| @@ -191,15 +191,15 @@ void tipc_net_start(u32 addr) | |||
| 191 | 191 | ||
| 192 | void tipc_net_stop(void) | 192 | void tipc_net_stop(void) |
| 193 | { | 193 | { |
| 194 | struct tipc_node *node, *t_node; | ||
| 195 | |||
| 196 | if (!tipc_own_addr) | 194 | if (!tipc_own_addr) |
| 197 | return; | 195 | return; |
| 196 | |||
| 197 | tipc_nametbl_withdraw(TIPC_CFG_SRV, tipc_own_addr, 0, tipc_own_addr); | ||
| 198 | write_lock_bh(&tipc_net_lock); | 198 | write_lock_bh(&tipc_net_lock); |
| 199 | tipc_bearer_stop(); | 199 | tipc_bearer_stop(); |
| 200 | tipc_bclink_stop(); | 200 | tipc_bclink_stop(); |
| 201 | list_for_each_entry_safe(node, t_node, &tipc_node_list, list) | 201 | tipc_node_stop(); |
| 202 | tipc_node_delete(node); | ||
| 203 | write_unlock_bh(&tipc_net_lock); | 202 | write_unlock_bh(&tipc_net_lock); |
| 203 | |||
| 204 | pr_info("Left network mode\n"); | 204 | pr_info("Left network mode\n"); |
| 205 | } | 205 | } |
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index 9f72a6376362..3aaf73de9e2d 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
| @@ -83,8 +83,6 @@ static struct genl_ops tipc_genl_ops[] = { | |||
| 83 | }, | 83 | }, |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | static int tipc_genl_family_registered; | ||
| 87 | |||
| 88 | int tipc_netlink_start(void) | 86 | int tipc_netlink_start(void) |
| 89 | { | 87 | { |
| 90 | int res; | 88 | int res; |
| @@ -94,16 +92,10 @@ int tipc_netlink_start(void) | |||
| 94 | pr_err("Failed to register netlink interface\n"); | 92 | pr_err("Failed to register netlink interface\n"); |
| 95 | return res; | 93 | return res; |
| 96 | } | 94 | } |
| 97 | |||
| 98 | tipc_genl_family_registered = 1; | ||
| 99 | return 0; | 95 | return 0; |
| 100 | } | 96 | } |
| 101 | 97 | ||
| 102 | void tipc_netlink_stop(void) | 98 | void tipc_netlink_stop(void) |
| 103 | { | 99 | { |
| 104 | if (!tipc_genl_family_registered) | ||
| 105 | return; | ||
| 106 | |||
| 107 | genl_unregister_family(&tipc_genl_family); | 100 | genl_unregister_family(&tipc_genl_family); |
| 108 | tipc_genl_family_registered = 0; | ||
| 109 | } | 101 | } |
diff --git a/net/tipc/node.c b/net/tipc/node.c index efe4d41bf11b..1d3a4999a70f 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, 2012 Ericsson AB | 4 | * Copyright (c) 2000-2006, 2012 Ericsson AB |
| 5 | * Copyright (c) 2005-2006, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005-2006, 2010-2014, 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 |
| @@ -44,13 +44,11 @@ | |||
| 44 | static void node_lost_contact(struct tipc_node *n_ptr); | 44 | static void node_lost_contact(struct tipc_node *n_ptr); |
| 45 | static void node_established_contact(struct tipc_node *n_ptr); | 45 | static void node_established_contact(struct tipc_node *n_ptr); |
| 46 | 46 | ||
| 47 | static DEFINE_SPINLOCK(node_create_lock); | ||
| 48 | |||
| 49 | static struct hlist_head node_htable[NODE_HTABLE_SIZE]; | 47 | static struct hlist_head node_htable[NODE_HTABLE_SIZE]; |
| 50 | LIST_HEAD(tipc_node_list); | 48 | LIST_HEAD(tipc_node_list); |
| 51 | static u32 tipc_num_nodes; | 49 | static u32 tipc_num_nodes; |
| 52 | 50 | static u32 tipc_num_links; | |
| 53 | static atomic_t tipc_num_links = ATOMIC_INIT(0); | 51 | static DEFINE_SPINLOCK(node_list_lock); |
| 54 | 52 | ||
| 55 | /* | 53 | /* |
| 56 | * A trivial power-of-two bitmask technique is used for speed, since this | 54 | * A trivial power-of-two bitmask technique is used for speed, since this |
| @@ -73,37 +71,26 @@ struct tipc_node *tipc_node_find(u32 addr) | |||
| 73 | if (unlikely(!in_own_cluster_exact(addr))) | 71 | if (unlikely(!in_own_cluster_exact(addr))) |
| 74 | return NULL; | 72 | return NULL; |
| 75 | 73 | ||
| 76 | hlist_for_each_entry(node, &node_htable[tipc_hashfn(addr)], hash) { | 74 | rcu_read_lock(); |
| 77 | if (node->addr == addr) | 75 | hlist_for_each_entry_rcu(node, &node_htable[tipc_hashfn(addr)], hash) { |
| 76 | if (node->addr == addr) { | ||
| 77 | rcu_read_unlock(); | ||
| 78 | return node; | 78 | return node; |
| 79 | } | ||
| 79 | } | 80 | } |
| 81 | rcu_read_unlock(); | ||
| 80 | return NULL; | 82 | return NULL; |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | /** | ||
| 84 | * tipc_node_create - create neighboring node | ||
| 85 | * | ||
| 86 | * Currently, this routine is called by neighbor discovery code, which holds | ||
| 87 | * net_lock for reading only. We must take node_create_lock to ensure a node | ||
| 88 | * isn't created twice if two different bearers discover the node at the same | ||
| 89 | * time. (It would be preferable to switch to holding net_lock in write mode, | ||
| 90 | * but this is a non-trivial change.) | ||
| 91 | */ | ||
| 92 | struct tipc_node *tipc_node_create(u32 addr) | 85 | struct tipc_node *tipc_node_create(u32 addr) |
| 93 | { | 86 | { |
| 94 | struct tipc_node *n_ptr, *temp_node; | 87 | struct tipc_node *n_ptr, *temp_node; |
| 95 | 88 | ||
| 96 | spin_lock_bh(&node_create_lock); | 89 | spin_lock_bh(&node_list_lock); |
| 97 | |||
| 98 | n_ptr = tipc_node_find(addr); | ||
| 99 | if (n_ptr) { | ||
| 100 | spin_unlock_bh(&node_create_lock); | ||
| 101 | return n_ptr; | ||
| 102 | } | ||
| 103 | 90 | ||
| 104 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); | 91 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); |
| 105 | if (!n_ptr) { | 92 | if (!n_ptr) { |
| 106 | spin_unlock_bh(&node_create_lock); | 93 | spin_unlock_bh(&node_list_lock); |
| 107 | pr_warn("Node creation failed, no memory\n"); | 94 | pr_warn("Node creation failed, no memory\n"); |
| 108 | return NULL; | 95 | return NULL; |
| 109 | } | 96 | } |
| @@ -114,31 +101,41 @@ struct tipc_node *tipc_node_create(u32 addr) | |||
| 114 | INIT_LIST_HEAD(&n_ptr->list); | 101 | INIT_LIST_HEAD(&n_ptr->list); |
| 115 | INIT_LIST_HEAD(&n_ptr->nsub); | 102 | INIT_LIST_HEAD(&n_ptr->nsub); |
| 116 | 103 | ||
| 117 | hlist_add_head(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); | 104 | hlist_add_head_rcu(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); |
| 118 | 105 | ||
| 119 | list_for_each_entry(temp_node, &tipc_node_list, list) { | 106 | list_for_each_entry_rcu(temp_node, &tipc_node_list, list) { |
| 120 | if (n_ptr->addr < temp_node->addr) | 107 | if (n_ptr->addr < temp_node->addr) |
| 121 | break; | 108 | break; |
| 122 | } | 109 | } |
| 123 | list_add_tail(&n_ptr->list, &temp_node->list); | 110 | list_add_tail_rcu(&n_ptr->list, &temp_node->list); |
| 124 | n_ptr->block_setup = WAIT_PEER_DOWN; | 111 | n_ptr->block_setup = WAIT_PEER_DOWN; |
| 125 | n_ptr->signature = INVALID_NODE_SIG; | 112 | n_ptr->signature = INVALID_NODE_SIG; |
| 126 | 113 | ||
| 127 | tipc_num_nodes++; | 114 | tipc_num_nodes++; |
| 128 | 115 | ||
| 129 | spin_unlock_bh(&node_create_lock); | 116 | spin_unlock_bh(&node_list_lock); |
| 130 | return n_ptr; | 117 | return n_ptr; |
| 131 | } | 118 | } |
| 132 | 119 | ||
| 133 | void tipc_node_delete(struct tipc_node *n_ptr) | 120 | static void tipc_node_delete(struct tipc_node *n_ptr) |
| 134 | { | 121 | { |
| 135 | list_del(&n_ptr->list); | 122 | list_del_rcu(&n_ptr->list); |
| 136 | hlist_del(&n_ptr->hash); | 123 | hlist_del_rcu(&n_ptr->hash); |
| 137 | kfree(n_ptr); | 124 | kfree_rcu(n_ptr, rcu); |
| 138 | 125 | ||
| 139 | tipc_num_nodes--; | 126 | tipc_num_nodes--; |
| 140 | } | 127 | } |
| 141 | 128 | ||
| 129 | void tipc_node_stop(void) | ||
| 130 | { | ||
| 131 | struct tipc_node *node, *t_node; | ||
| 132 | |||
| 133 | spin_lock_bh(&node_list_lock); | ||
| 134 | list_for_each_entry_safe(node, t_node, &tipc_node_list, list) | ||
| 135 | tipc_node_delete(node); | ||
| 136 | spin_unlock_bh(&node_list_lock); | ||
| 137 | } | ||
| 138 | |||
| 142 | /** | 139 | /** |
| 143 | * tipc_node_link_up - handle addition of link | 140 | * tipc_node_link_up - handle addition of link |
| 144 | * | 141 | * |
| @@ -162,7 +159,7 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 162 | pr_info("New link <%s> becomes standby\n", l_ptr->name); | 159 | pr_info("New link <%s> becomes standby\n", l_ptr->name); |
| 163 | return; | 160 | return; |
| 164 | } | 161 | } |
| 165 | tipc_link_dup_send_queue(active[0], l_ptr); | 162 | tipc_link_dup_queue_xmit(active[0], l_ptr); |
| 166 | if (l_ptr->priority == active[0]->priority) { | 163 | if (l_ptr->priority == active[0]->priority) { |
| 167 | active[0] = l_ptr; | 164 | active[0] = l_ptr; |
| 168 | return; | 165 | return; |
| @@ -243,15 +240,25 @@ int tipc_node_is_up(struct tipc_node *n_ptr) | |||
| 243 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 240 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 244 | { | 241 | { |
| 245 | n_ptr->links[l_ptr->b_ptr->identity] = l_ptr; | 242 | n_ptr->links[l_ptr->b_ptr->identity] = l_ptr; |
| 246 | atomic_inc(&tipc_num_links); | 243 | spin_lock_bh(&node_list_lock); |
| 244 | tipc_num_links++; | ||
| 245 | spin_unlock_bh(&node_list_lock); | ||
| 247 | n_ptr->link_cnt++; | 246 | n_ptr->link_cnt++; |
| 248 | } | 247 | } |
| 249 | 248 | ||
| 250 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 249 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 251 | { | 250 | { |
| 252 | n_ptr->links[l_ptr->b_ptr->identity] = NULL; | 251 | int i; |
| 253 | atomic_dec(&tipc_num_links); | 252 | |
| 254 | n_ptr->link_cnt--; | 253 | for (i = 0; i < MAX_BEARERS; i++) { |
| 254 | if (l_ptr != n_ptr->links[i]) | ||
| 255 | continue; | ||
| 256 | n_ptr->links[i] = NULL; | ||
| 257 | spin_lock_bh(&node_list_lock); | ||
| 258 | tipc_num_links--; | ||
| 259 | spin_unlock_bh(&node_list_lock); | ||
| 260 | n_ptr->link_cnt--; | ||
| 261 | } | ||
| 255 | } | 262 | } |
| 256 | 263 | ||
| 257 | static void node_established_contact(struct tipc_node *n_ptr) | 264 | static void node_established_contact(struct tipc_node *n_ptr) |
| @@ -335,27 +342,28 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 335 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 342 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 336 | " (network address)"); | 343 | " (network address)"); |
| 337 | 344 | ||
| 338 | read_lock_bh(&tipc_net_lock); | 345 | spin_lock_bh(&node_list_lock); |
| 339 | if (!tipc_num_nodes) { | 346 | if (!tipc_num_nodes) { |
| 340 | read_unlock_bh(&tipc_net_lock); | 347 | spin_unlock_bh(&node_list_lock); |
| 341 | return tipc_cfg_reply_none(); | 348 | return tipc_cfg_reply_none(); |
| 342 | } | 349 | } |
| 343 | 350 | ||
| 344 | /* For now, get space for all other nodes */ | 351 | /* For now, get space for all other nodes */ |
| 345 | payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes; | 352 | payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes; |
| 346 | if (payload_size > 32768u) { | 353 | if (payload_size > 32768u) { |
| 347 | read_unlock_bh(&tipc_net_lock); | 354 | spin_unlock_bh(&node_list_lock); |
| 348 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 355 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 349 | " (too many nodes)"); | 356 | " (too many nodes)"); |
| 350 | } | 357 | } |
| 358 | spin_unlock_bh(&node_list_lock); | ||
| 359 | |||
| 351 | buf = tipc_cfg_reply_alloc(payload_size); | 360 | buf = tipc_cfg_reply_alloc(payload_size); |
| 352 | if (!buf) { | 361 | if (!buf) |
| 353 | read_unlock_bh(&tipc_net_lock); | ||
| 354 | return NULL; | 362 | return NULL; |
| 355 | } | ||
| 356 | 363 | ||
| 357 | /* Add TLVs for all nodes in scope */ | 364 | /* Add TLVs for all nodes in scope */ |
| 358 | list_for_each_entry(n_ptr, &tipc_node_list, list) { | 365 | rcu_read_lock(); |
| 366 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
| 359 | if (!tipc_in_scope(domain, n_ptr->addr)) | 367 | if (!tipc_in_scope(domain, n_ptr->addr)) |
| 360 | continue; | 368 | continue; |
| 361 | node_info.addr = htonl(n_ptr->addr); | 369 | node_info.addr = htonl(n_ptr->addr); |
| @@ -363,8 +371,7 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 363 | tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO, | 371 | tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO, |
| 364 | &node_info, sizeof(node_info)); | 372 | &node_info, sizeof(node_info)); |
| 365 | } | 373 | } |
| 366 | 374 | rcu_read_unlock(); | |
| 367 | read_unlock_bh(&tipc_net_lock); | ||
| 368 | return buf; | 375 | return buf; |
| 369 | } | 376 | } |
| 370 | 377 | ||
| @@ -387,21 +394,19 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 387 | if (!tipc_own_addr) | 394 | if (!tipc_own_addr) |
| 388 | return tipc_cfg_reply_none(); | 395 | return tipc_cfg_reply_none(); |
| 389 | 396 | ||
| 390 | read_lock_bh(&tipc_net_lock); | 397 | spin_lock_bh(&node_list_lock); |
| 391 | |||
| 392 | /* Get space for all unicast links + broadcast link */ | 398 | /* Get space for all unicast links + broadcast link */ |
| 393 | payload_size = TLV_SPACE(sizeof(link_info)) * | 399 | payload_size = TLV_SPACE((sizeof(link_info)) * (tipc_num_links + 1)); |
| 394 | (atomic_read(&tipc_num_links) + 1); | ||
| 395 | if (payload_size > 32768u) { | 400 | if (payload_size > 32768u) { |
| 396 | read_unlock_bh(&tipc_net_lock); | 401 | spin_unlock_bh(&node_list_lock); |
| 397 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 402 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 398 | " (too many links)"); | 403 | " (too many links)"); |
| 399 | } | 404 | } |
| 405 | spin_unlock_bh(&node_list_lock); | ||
| 406 | |||
| 400 | buf = tipc_cfg_reply_alloc(payload_size); | 407 | buf = tipc_cfg_reply_alloc(payload_size); |
| 401 | if (!buf) { | 408 | if (!buf) |
| 402 | read_unlock_bh(&tipc_net_lock); | ||
| 403 | return NULL; | 409 | return NULL; |
| 404 | } | ||
| 405 | 410 | ||
| 406 | /* Add TLV for broadcast link */ | 411 | /* Add TLV for broadcast link */ |
| 407 | link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr)); | 412 | link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr)); |
| @@ -410,7 +415,8 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 410 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); | 415 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); |
| 411 | 416 | ||
| 412 | /* Add TLVs for any other links in scope */ | 417 | /* Add TLVs for any other links in scope */ |
| 413 | list_for_each_entry(n_ptr, &tipc_node_list, list) { | 418 | rcu_read_lock(); |
| 419 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
| 414 | u32 i; | 420 | u32 i; |
| 415 | 421 | ||
| 416 | if (!tipc_in_scope(domain, n_ptr->addr)) | 422 | if (!tipc_in_scope(domain, n_ptr->addr)) |
| @@ -427,7 +433,6 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 427 | } | 433 | } |
| 428 | tipc_node_unlock(n_ptr); | 434 | tipc_node_unlock(n_ptr); |
| 429 | } | 435 | } |
| 430 | 436 | rcu_read_unlock(); | |
| 431 | read_unlock_bh(&tipc_net_lock); | ||
| 432 | return buf; | 437 | return buf; |
| 433 | } | 438 | } |
diff --git a/net/tipc/node.h b/net/tipc/node.h index 63e2e8ead2fe..7cbb8cec1a93 100644 --- a/net/tipc/node.h +++ b/net/tipc/node.h | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | * net/tipc/node.h: Include file for TIPC node management routines | 2 | * net/tipc/node.h: Include file for TIPC node management routines |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2000-2006, Ericsson AB | 4 | * Copyright (c) 2000-2006, Ericsson AB |
| 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005, 2010-2014, 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 |
| @@ -66,6 +66,7 @@ | |||
| 66 | * @link_cnt: number of links to node | 66 | * @link_cnt: number of links to node |
| 67 | * @signature: node instance identifier | 67 | * @signature: node instance identifier |
| 68 | * @bclink: broadcast-related info | 68 | * @bclink: broadcast-related info |
| 69 | * @rcu: rcu struct for tipc_node | ||
| 69 | * @acked: sequence # of last outbound b'cast message acknowledged by node | 70 | * @acked: sequence # of last outbound b'cast message acknowledged by node |
| 70 | * @last_in: sequence # of last in-sequence b'cast message received from node | 71 | * @last_in: sequence # of last in-sequence b'cast message received from node |
| 71 | * @last_sent: sequence # of last b'cast message sent by node | 72 | * @last_sent: sequence # of last b'cast message sent by node |
| @@ -89,6 +90,7 @@ struct tipc_node { | |||
| 89 | int working_links; | 90 | int working_links; |
| 90 | int block_setup; | 91 | int block_setup; |
| 91 | u32 signature; | 92 | u32 signature; |
| 93 | struct rcu_head rcu; | ||
| 92 | struct { | 94 | struct { |
| 93 | u32 acked; | 95 | u32 acked; |
| 94 | u32 last_in; | 96 | u32 last_in; |
| @@ -107,7 +109,7 @@ extern struct list_head tipc_node_list; | |||
| 107 | 109 | ||
| 108 | struct tipc_node *tipc_node_find(u32 addr); | 110 | struct tipc_node *tipc_node_find(u32 addr); |
| 109 | struct tipc_node *tipc_node_create(u32 addr); | 111 | struct tipc_node *tipc_node_create(u32 addr); |
| 110 | void tipc_node_delete(struct tipc_node *n_ptr); | 112 | void tipc_node_stop(void); |
| 111 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 113 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 112 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 114 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 113 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 115 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
diff --git a/net/tipc/port.c b/net/tipc/port.c index b742b2654525..5c14c7801ee6 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/port.c: TIPC port code | 2 | * net/tipc/port.c: TIPC port code |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 1992-2007, Ericsson AB | 4 | * Copyright (c) 1992-2007, 2014, Ericsson AB |
| 5 | * Copyright (c) 2004-2008, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2004-2008, 2010-2013, Wind River Systems |
| 6 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| @@ -38,6 +38,7 @@ | |||
| 38 | #include "config.h" | 38 | #include "config.h" |
| 39 | #include "port.h" | 39 | #include "port.h" |
| 40 | #include "name_table.h" | 40 | #include "name_table.h" |
| 41 | #include "socket.h" | ||
| 41 | 42 | ||
| 42 | /* Connection management: */ | 43 | /* Connection management: */ |
| 43 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ | 44 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ |
| @@ -54,17 +55,6 @@ static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err); | |||
| 54 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err); | 55 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err); |
| 55 | static void port_timeout(unsigned long ref); | 56 | static void port_timeout(unsigned long ref); |
| 56 | 57 | ||
| 57 | |||
| 58 | static u32 port_peernode(struct tipc_port *p_ptr) | ||
| 59 | { | ||
| 60 | return msg_destnode(&p_ptr->phdr); | ||
| 61 | } | ||
| 62 | |||
| 63 | static u32 port_peerport(struct tipc_port *p_ptr) | ||
| 64 | { | ||
| 65 | return msg_destport(&p_ptr->phdr); | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | 58 | /** |
| 69 | * tipc_port_peer_msg - verify message was sent by connected port's peer | 59 | * tipc_port_peer_msg - verify message was sent by connected port's peer |
| 70 | * | 60 | * |
| @@ -76,33 +66,32 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg) | |||
| 76 | u32 peernode; | 66 | u32 peernode; |
| 77 | u32 orignode; | 67 | u32 orignode; |
| 78 | 68 | ||
| 79 | if (msg_origport(msg) != port_peerport(p_ptr)) | 69 | if (msg_origport(msg) != tipc_port_peerport(p_ptr)) |
| 80 | return 0; | 70 | return 0; |
| 81 | 71 | ||
| 82 | orignode = msg_orignode(msg); | 72 | orignode = msg_orignode(msg); |
| 83 | peernode = port_peernode(p_ptr); | 73 | peernode = tipc_port_peernode(p_ptr); |
| 84 | return (orignode == peernode) || | 74 | return (orignode == peernode) || |
| 85 | (!orignode && (peernode == tipc_own_addr)) || | 75 | (!orignode && (peernode == tipc_own_addr)) || |
| 86 | (!peernode && (orignode == tipc_own_addr)); | 76 | (!peernode && (orignode == tipc_own_addr)); |
| 87 | } | 77 | } |
| 88 | 78 | ||
| 89 | /** | 79 | /** |
| 90 | * tipc_multicast - send a multicast message to local and remote destinations | 80 | * tipc_port_mcast_xmit - send a multicast message to local and remote |
| 81 | * destinations | ||
| 91 | */ | 82 | */ |
| 92 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, | 83 | int tipc_port_mcast_xmit(struct tipc_port *oport, |
| 93 | struct iovec const *msg_sect, unsigned int len) | 84 | struct tipc_name_seq const *seq, |
| 85 | struct iovec const *msg_sect, | ||
| 86 | unsigned int len) | ||
| 94 | { | 87 | { |
| 95 | struct tipc_msg *hdr; | 88 | struct tipc_msg *hdr; |
| 96 | struct sk_buff *buf; | 89 | struct sk_buff *buf; |
| 97 | struct sk_buff *ibuf = NULL; | 90 | struct sk_buff *ibuf = NULL; |
| 98 | struct tipc_port_list dports = {0, NULL, }; | 91 | struct tipc_port_list dports = {0, NULL, }; |
| 99 | struct tipc_port *oport = tipc_port_deref(ref); | ||
| 100 | int ext_targets; | 92 | int ext_targets; |
| 101 | int res; | 93 | int res; |
| 102 | 94 | ||
| 103 | if (unlikely(!oport)) | ||
| 104 | return -EINVAL; | ||
| 105 | |||
| 106 | /* Create multicast message */ | 95 | /* Create multicast message */ |
| 107 | hdr = &oport->phdr; | 96 | hdr = &oport->phdr; |
| 108 | msg_set_type(hdr, TIPC_MCAST_MSG); | 97 | msg_set_type(hdr, TIPC_MCAST_MSG); |
| @@ -131,7 +120,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, | |||
| 131 | return -ENOMEM; | 120 | return -ENOMEM; |
| 132 | } | 121 | } |
| 133 | } | 122 | } |
| 134 | res = tipc_bclink_send_msg(buf); | 123 | res = tipc_bclink_xmit(buf); |
| 135 | if ((res < 0) && (dports.count != 0)) | 124 | if ((res < 0) && (dports.count != 0)) |
| 136 | kfree_skb(ibuf); | 125 | kfree_skb(ibuf); |
| 137 | } else { | 126 | } else { |
| @@ -140,7 +129,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, | |||
| 140 | 129 | ||
| 141 | if (res >= 0) { | 130 | if (res >= 0) { |
| 142 | if (ibuf) | 131 | if (ibuf) |
| 143 | tipc_port_recv_mcast(ibuf, &dports); | 132 | tipc_port_mcast_rcv(ibuf, &dports); |
| 144 | } else { | 133 | } else { |
| 145 | tipc_port_list_free(&dports); | 134 | tipc_port_list_free(&dports); |
| 146 | } | 135 | } |
| @@ -148,11 +137,11 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, | |||
| 148 | } | 137 | } |
| 149 | 138 | ||
| 150 | /** | 139 | /** |
| 151 | * tipc_port_recv_mcast - deliver multicast message to all destination ports | 140 | * tipc_port_mcast_rcv - deliver multicast message to all destination ports |
| 152 | * | 141 | * |
| 153 | * If there is no port list, perform a lookup to create one | 142 | * If there is no port list, perform a lookup to create one |
| 154 | */ | 143 | */ |
| 155 | void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp) | 144 | void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp) |
| 156 | { | 145 | { |
| 157 | struct tipc_msg *msg; | 146 | struct tipc_msg *msg; |
| 158 | struct tipc_port_list dports = {0, NULL, }; | 147 | struct tipc_port_list dports = {0, NULL, }; |
| @@ -176,7 +165,7 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp) | |||
| 176 | msg_set_destnode(msg, tipc_own_addr); | 165 | msg_set_destnode(msg, tipc_own_addr); |
| 177 | if (dp->count == 1) { | 166 | if (dp->count == 1) { |
| 178 | msg_set_destport(msg, dp->ports[0]); | 167 | msg_set_destport(msg, dp->ports[0]); |
| 179 | tipc_port_recv_msg(buf); | 168 | tipc_port_rcv(buf); |
| 180 | tipc_port_list_free(dp); | 169 | tipc_port_list_free(dp); |
| 181 | return; | 170 | return; |
| 182 | } | 171 | } |
| @@ -191,7 +180,7 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp) | |||
| 191 | if ((index == 0) && (cnt != 0)) | 180 | if ((index == 0) && (cnt != 0)) |
| 192 | item = item->next; | 181 | item = item->next; |
| 193 | msg_set_destport(buf_msg(b), item->ports[index]); | 182 | msg_set_destport(buf_msg(b), item->ports[index]); |
| 194 | tipc_port_recv_msg(b); | 183 | tipc_port_rcv(b); |
| 195 | } | 184 | } |
| 196 | } | 185 | } |
| 197 | exit: | 186 | exit: |
| @@ -199,40 +188,32 @@ exit: | |||
| 199 | tipc_port_list_free(dp); | 188 | tipc_port_list_free(dp); |
| 200 | } | 189 | } |
| 201 | 190 | ||
| 202 | /** | 191 | |
| 203 | * tipc_createport - create a generic TIPC port | 192 | void tipc_port_wakeup(struct tipc_port *port) |
| 193 | { | ||
| 194 | tipc_sock_wakeup(tipc_port_to_sock(port)); | ||
| 195 | } | ||
| 196 | |||
| 197 | /* tipc_port_init - intiate TIPC port and lock it | ||
| 204 | * | 198 | * |
| 205 | * Returns pointer to (locked) TIPC port, or NULL if unable to create it | 199 | * Returns obtained reference if initialization is successful, zero otherwise |
| 206 | */ | 200 | */ |
| 207 | struct tipc_port *tipc_createport(struct sock *sk, | 201 | u32 tipc_port_init(struct tipc_port *p_ptr, |
| 208 | u32 (*dispatcher)(struct tipc_port *, | 202 | const unsigned int importance) |
| 209 | struct sk_buff *), | ||
| 210 | void (*wakeup)(struct tipc_port *), | ||
| 211 | const u32 importance) | ||
| 212 | { | 203 | { |
| 213 | struct tipc_port *p_ptr; | ||
| 214 | struct tipc_msg *msg; | 204 | struct tipc_msg *msg; |
| 215 | u32 ref; | 205 | u32 ref; |
| 216 | 206 | ||
| 217 | p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC); | ||
| 218 | if (!p_ptr) { | ||
| 219 | pr_warn("Port creation failed, no memory\n"); | ||
| 220 | return NULL; | ||
| 221 | } | ||
| 222 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); | 207 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); |
| 223 | if (!ref) { | 208 | if (!ref) { |
| 224 | pr_warn("Port creation failed, ref. table exhausted\n"); | 209 | pr_warn("Port registration failed, ref. table exhausted\n"); |
| 225 | kfree(p_ptr); | 210 | return 0; |
| 226 | return NULL; | ||
| 227 | } | 211 | } |
| 228 | 212 | ||
| 229 | p_ptr->sk = sk; | ||
| 230 | p_ptr->max_pkt = MAX_PKT_DEFAULT; | 213 | p_ptr->max_pkt = MAX_PKT_DEFAULT; |
| 231 | p_ptr->ref = ref; | 214 | p_ptr->ref = ref; |
| 232 | INIT_LIST_HEAD(&p_ptr->wait_list); | 215 | INIT_LIST_HEAD(&p_ptr->wait_list); |
| 233 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); | 216 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
| 234 | p_ptr->dispatcher = dispatcher; | ||
| 235 | p_ptr->wakeup = wakeup; | ||
| 236 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); | 217 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
| 237 | INIT_LIST_HEAD(&p_ptr->publications); | 218 | INIT_LIST_HEAD(&p_ptr->publications); |
| 238 | INIT_LIST_HEAD(&p_ptr->port_list); | 219 | INIT_LIST_HEAD(&p_ptr->port_list); |
| @@ -248,10 +229,10 @@ struct tipc_port *tipc_createport(struct sock *sk, | |||
| 248 | msg_set_origport(msg, ref); | 229 | msg_set_origport(msg, ref); |
| 249 | list_add_tail(&p_ptr->port_list, &ports); | 230 | list_add_tail(&p_ptr->port_list, &ports); |
| 250 | spin_unlock_bh(&tipc_port_list_lock); | 231 | spin_unlock_bh(&tipc_port_list_lock); |
| 251 | return p_ptr; | 232 | return ref; |
| 252 | } | 233 | } |
| 253 | 234 | ||
| 254 | int tipc_deleteport(struct tipc_port *p_ptr) | 235 | void tipc_port_destroy(struct tipc_port *p_ptr) |
| 255 | { | 236 | { |
| 256 | struct sk_buff *buf = NULL; | 237 | struct sk_buff *buf = NULL; |
| 257 | 238 | ||
| @@ -272,67 +253,7 @@ int tipc_deleteport(struct tipc_port *p_ptr) | |||
| 272 | list_del(&p_ptr->wait_list); | 253 | list_del(&p_ptr->wait_list); |
| 273 | spin_unlock_bh(&tipc_port_list_lock); | 254 | spin_unlock_bh(&tipc_port_list_lock); |
| 274 | k_term_timer(&p_ptr->timer); | 255 | k_term_timer(&p_ptr->timer); |
| 275 | kfree(p_ptr); | ||
| 276 | tipc_net_route_msg(buf); | 256 | tipc_net_route_msg(buf); |
| 277 | return 0; | ||
| 278 | } | ||
| 279 | |||
| 280 | static int port_unreliable(struct tipc_port *p_ptr) | ||
| 281 | { | ||
| 282 | return msg_src_droppable(&p_ptr->phdr); | ||
| 283 | } | ||
| 284 | |||
| 285 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) | ||
| 286 | { | ||
| 287 | struct tipc_port *p_ptr; | ||
| 288 | |||
| 289 | p_ptr = tipc_port_lock(ref); | ||
| 290 | if (!p_ptr) | ||
| 291 | return -EINVAL; | ||
| 292 | *isunreliable = port_unreliable(p_ptr); | ||
| 293 | tipc_port_unlock(p_ptr); | ||
| 294 | return 0; | ||
| 295 | } | ||
| 296 | |||
| 297 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) | ||
| 298 | { | ||
| 299 | struct tipc_port *p_ptr; | ||
| 300 | |||
| 301 | p_ptr = tipc_port_lock(ref); | ||
| 302 | if (!p_ptr) | ||
| 303 | return -EINVAL; | ||
| 304 | msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0)); | ||
| 305 | tipc_port_unlock(p_ptr); | ||
| 306 | return 0; | ||
| 307 | } | ||
| 308 | |||
| 309 | static int port_unreturnable(struct tipc_port *p_ptr) | ||
| 310 | { | ||
| 311 | return msg_dest_droppable(&p_ptr->phdr); | ||
| 312 | } | ||
| 313 | |||
| 314 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) | ||
| 315 | { | ||
| 316 | struct tipc_port *p_ptr; | ||
| 317 | |||
| 318 | p_ptr = tipc_port_lock(ref); | ||
| 319 | if (!p_ptr) | ||
| 320 | return -EINVAL; | ||
| 321 | *isunrejectable = port_unreturnable(p_ptr); | ||
| 322 | tipc_port_unlock(p_ptr); | ||
| 323 | return 0; | ||
| 324 | } | ||
| 325 | |||
| 326 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) | ||
| 327 | { | ||
| 328 | struct tipc_port *p_ptr; | ||
| 329 | |||
| 330 | p_ptr = tipc_port_lock(ref); | ||
| 331 | if (!p_ptr) | ||
| 332 | return -EINVAL; | ||
| 333 | msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0)); | ||
| 334 | tipc_port_unlock(p_ptr); | ||
| 335 | return 0; | ||
| 336 | } | 257 | } |
| 337 | 258 | ||
| 338 | /* | 259 | /* |
| @@ -350,8 +271,8 @@ static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr, | |||
| 350 | if (buf) { | 271 | if (buf) { |
| 351 | msg = buf_msg(buf); | 272 | msg = buf_msg(buf); |
| 352 | tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE, | 273 | tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE, |
| 353 | port_peernode(p_ptr)); | 274 | tipc_port_peernode(p_ptr)); |
| 354 | msg_set_destport(msg, port_peerport(p_ptr)); | 275 | msg_set_destport(msg, tipc_port_peerport(p_ptr)); |
| 355 | msg_set_origport(msg, p_ptr->ref); | 276 | msg_set_origport(msg, p_ptr->ref); |
| 356 | msg_set_msgcnt(msg, ack); | 277 | msg_set_msgcnt(msg, ack); |
| 357 | } | 278 | } |
| @@ -422,17 +343,17 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) | |||
| 422 | /* send returned message & dispose of rejected message */ | 343 | /* send returned message & dispose of rejected message */ |
| 423 | src_node = msg_prevnode(msg); | 344 | src_node = msg_prevnode(msg); |
| 424 | if (in_own_node(src_node)) | 345 | if (in_own_node(src_node)) |
| 425 | tipc_port_recv_msg(rbuf); | 346 | tipc_port_rcv(rbuf); |
| 426 | else | 347 | else |
| 427 | tipc_link_send(rbuf, src_node, msg_link_selector(rmsg)); | 348 | tipc_link_xmit(rbuf, src_node, msg_link_selector(rmsg)); |
| 428 | exit: | 349 | exit: |
| 429 | kfree_skb(buf); | 350 | kfree_skb(buf); |
| 430 | return data_sz; | 351 | return data_sz; |
| 431 | } | 352 | } |
| 432 | 353 | ||
| 433 | int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, | 354 | int tipc_port_iovec_reject(struct tipc_port *p_ptr, struct tipc_msg *hdr, |
| 434 | struct iovec const *msg_sect, unsigned int len, | 355 | struct iovec const *msg_sect, unsigned int len, |
| 435 | int err) | 356 | int err) |
| 436 | { | 357 | { |
| 437 | struct sk_buff *buf; | 358 | struct sk_buff *buf; |
| 438 | int res; | 359 | int res; |
| @@ -519,7 +440,7 @@ static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 er | |||
| 519 | return buf; | 440 | return buf; |
| 520 | } | 441 | } |
| 521 | 442 | ||
| 522 | void tipc_port_recv_proto_msg(struct sk_buff *buf) | 443 | void tipc_port_proto_rcv(struct sk_buff *buf) |
| 523 | { | 444 | { |
| 524 | struct tipc_msg *msg = buf_msg(buf); | 445 | struct tipc_msg *msg = buf_msg(buf); |
| 525 | struct tipc_port *p_ptr; | 446 | struct tipc_port *p_ptr; |
| @@ -547,13 +468,12 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf) | |||
| 547 | /* Process protocol message sent by peer */ | 468 | /* Process protocol message sent by peer */ |
| 548 | switch (msg_type(msg)) { | 469 | switch (msg_type(msg)) { |
| 549 | case CONN_ACK: | 470 | case CONN_ACK: |
| 550 | wakeable = tipc_port_congested(p_ptr) && p_ptr->congested && | 471 | wakeable = tipc_port_congested(p_ptr) && p_ptr->congested; |
| 551 | p_ptr->wakeup; | ||
| 552 | p_ptr->acked += msg_msgcnt(msg); | 472 | p_ptr->acked += msg_msgcnt(msg); |
| 553 | if (!tipc_port_congested(p_ptr)) { | 473 | if (!tipc_port_congested(p_ptr)) { |
| 554 | p_ptr->congested = 0; | 474 | p_ptr->congested = 0; |
| 555 | if (wakeable) | 475 | if (wakeable) |
| 556 | p_ptr->wakeup(p_ptr); | 476 | tipc_port_wakeup(p_ptr); |
| 557 | } | 477 | } |
| 558 | break; | 478 | break; |
| 559 | case CONN_PROBE: | 479 | case CONN_PROBE: |
| @@ -584,8 +504,8 @@ static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id) | |||
| 584 | ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref); | 504 | ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref); |
| 585 | 505 | ||
| 586 | if (p_ptr->connected) { | 506 | if (p_ptr->connected) { |
| 587 | u32 dport = port_peerport(p_ptr); | 507 | u32 dport = tipc_port_peerport(p_ptr); |
| 588 | u32 destnode = port_peernode(p_ptr); | 508 | u32 destnode = tipc_port_peernode(p_ptr); |
| 589 | 509 | ||
| 590 | ret += tipc_snprintf(buf + ret, len - ret, | 510 | ret += tipc_snprintf(buf + ret, len - ret, |
| 591 | " connected to <%u.%u.%u:%u>", | 511 | " connected to <%u.%u.%u:%u>", |
| @@ -673,34 +593,6 @@ void tipc_acknowledge(u32 ref, u32 ack) | |||
| 673 | tipc_net_route_msg(buf); | 593 | tipc_net_route_msg(buf); |
| 674 | } | 594 | } |
| 675 | 595 | ||
| 676 | int tipc_portimportance(u32 ref, unsigned int *importance) | ||
| 677 | { | ||
| 678 | struct tipc_port *p_ptr; | ||
| 679 | |||
| 680 | p_ptr = tipc_port_lock(ref); | ||
| 681 | if (!p_ptr) | ||
| 682 | return -EINVAL; | ||
| 683 | *importance = (unsigned int)msg_importance(&p_ptr->phdr); | ||
| 684 | tipc_port_unlock(p_ptr); | ||
| 685 | return 0; | ||
| 686 | } | ||
| 687 | |||
| 688 | int tipc_set_portimportance(u32 ref, unsigned int imp) | ||
| 689 | { | ||
| 690 | struct tipc_port *p_ptr; | ||
| 691 | |||
| 692 | if (imp > TIPC_CRITICAL_IMPORTANCE) | ||
| 693 | return -EINVAL; | ||
| 694 | |||
| 695 | p_ptr = tipc_port_lock(ref); | ||
| 696 | if (!p_ptr) | ||
| 697 | return -EINVAL; | ||
| 698 | msg_set_importance(&p_ptr->phdr, (u32)imp); | ||
| 699 | tipc_port_unlock(p_ptr); | ||
| 700 | return 0; | ||
| 701 | } | ||
| 702 | |||
| 703 | |||
| 704 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, | 596 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, |
| 705 | struct tipc_name_seq const *seq) | 597 | struct tipc_name_seq const *seq) |
| 706 | { | 598 | { |
| @@ -760,7 +652,7 @@ int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, | |||
| 760 | return res; | 652 | return res; |
| 761 | } | 653 | } |
| 762 | 654 | ||
| 763 | int tipc_connect(u32 ref, struct tipc_portid const *peer) | 655 | int tipc_port_connect(u32 ref, struct tipc_portid const *peer) |
| 764 | { | 656 | { |
| 765 | struct tipc_port *p_ptr; | 657 | struct tipc_port *p_ptr; |
| 766 | int res; | 658 | int res; |
| @@ -768,17 +660,17 @@ int tipc_connect(u32 ref, struct tipc_portid const *peer) | |||
| 768 | p_ptr = tipc_port_lock(ref); | 660 | p_ptr = tipc_port_lock(ref); |
| 769 | if (!p_ptr) | 661 | if (!p_ptr) |
| 770 | return -EINVAL; | 662 | return -EINVAL; |
| 771 | res = __tipc_connect(ref, p_ptr, peer); | 663 | res = __tipc_port_connect(ref, p_ptr, peer); |
| 772 | tipc_port_unlock(p_ptr); | 664 | tipc_port_unlock(p_ptr); |
| 773 | return res; | 665 | return res; |
| 774 | } | 666 | } |
| 775 | 667 | ||
| 776 | /* | 668 | /* |
| 777 | * __tipc_connect - connect to a remote peer | 669 | * __tipc_port_connect - connect to a remote peer |
| 778 | * | 670 | * |
| 779 | * Port must be locked. | 671 | * Port must be locked. |
| 780 | */ | 672 | */ |
| 781 | int __tipc_connect(u32 ref, struct tipc_port *p_ptr, | 673 | int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr, |
| 782 | struct tipc_portid const *peer) | 674 | struct tipc_portid const *peer) |
| 783 | { | 675 | { |
| 784 | struct tipc_msg *msg; | 676 | struct tipc_msg *msg; |
| @@ -815,7 +707,7 @@ exit: | |||
| 815 | * | 707 | * |
| 816 | * Port must be locked. | 708 | * Port must be locked. |
| 817 | */ | 709 | */ |
| 818 | int __tipc_disconnect(struct tipc_port *tp_ptr) | 710 | int __tipc_port_disconnect(struct tipc_port *tp_ptr) |
| 819 | { | 711 | { |
| 820 | if (tp_ptr->connected) { | 712 | if (tp_ptr->connected) { |
| 821 | tp_ptr->connected = 0; | 713 | tp_ptr->connected = 0; |
| @@ -828,10 +720,10 @@ int __tipc_disconnect(struct tipc_port *tp_ptr) | |||
| 828 | } | 720 | } |
| 829 | 721 | ||
| 830 | /* | 722 | /* |
| 831 | * tipc_disconnect(): Disconnect port form peer. | 723 | * tipc_port_disconnect(): Disconnect port form peer. |
| 832 | * This is a node local operation. | 724 | * This is a node local operation. |
| 833 | */ | 725 | */ |
| 834 | int tipc_disconnect(u32 ref) | 726 | int tipc_port_disconnect(u32 ref) |
| 835 | { | 727 | { |
| 836 | struct tipc_port *p_ptr; | 728 | struct tipc_port *p_ptr; |
| 837 | int res; | 729 | int res; |
| @@ -839,15 +731,15 @@ int tipc_disconnect(u32 ref) | |||
| 839 | p_ptr = tipc_port_lock(ref); | 731 | p_ptr = tipc_port_lock(ref); |
| 840 | if (!p_ptr) | 732 | if (!p_ptr) |
| 841 | return -EINVAL; | 733 | return -EINVAL; |
| 842 | res = __tipc_disconnect(p_ptr); | 734 | res = __tipc_port_disconnect(p_ptr); |
| 843 | tipc_port_unlock(p_ptr); | 735 | tipc_port_unlock(p_ptr); |
| 844 | return res; | 736 | return res; |
| 845 | } | 737 | } |
| 846 | 738 | ||
| 847 | /* | 739 | /* |
| 848 | * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect | 740 | * tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect |
| 849 | */ | 741 | */ |
| 850 | int tipc_shutdown(u32 ref) | 742 | int tipc_port_shutdown(u32 ref) |
| 851 | { | 743 | { |
| 852 | struct tipc_port *p_ptr; | 744 | struct tipc_port *p_ptr; |
| 853 | struct sk_buff *buf = NULL; | 745 | struct sk_buff *buf = NULL; |
| @@ -859,13 +751,13 @@ int tipc_shutdown(u32 ref) | |||
| 859 | buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); | 751 | buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); |
| 860 | tipc_port_unlock(p_ptr); | 752 | tipc_port_unlock(p_ptr); |
| 861 | tipc_net_route_msg(buf); | 753 | tipc_net_route_msg(buf); |
| 862 | return tipc_disconnect(ref); | 754 | return tipc_port_disconnect(ref); |
| 863 | } | 755 | } |
| 864 | 756 | ||
| 865 | /** | 757 | /** |
| 866 | * tipc_port_recv_msg - receive message from lower layer and deliver to port user | 758 | * tipc_port_rcv - receive message from lower layer and deliver to port user |
| 867 | */ | 759 | */ |
| 868 | int tipc_port_recv_msg(struct sk_buff *buf) | 760 | int tipc_port_rcv(struct sk_buff *buf) |
| 869 | { | 761 | { |
| 870 | struct tipc_port *p_ptr; | 762 | struct tipc_port *p_ptr; |
| 871 | struct tipc_msg *msg = buf_msg(buf); | 763 | struct tipc_msg *msg = buf_msg(buf); |
| @@ -882,7 +774,7 @@ int tipc_port_recv_msg(struct sk_buff *buf) | |||
| 882 | /* validate destination & pass to port, otherwise reject message */ | 774 | /* validate destination & pass to port, otherwise reject message */ |
| 883 | p_ptr = tipc_port_lock(destport); | 775 | p_ptr = tipc_port_lock(destport); |
| 884 | if (likely(p_ptr)) { | 776 | if (likely(p_ptr)) { |
| 885 | err = p_ptr->dispatcher(p_ptr, buf); | 777 | err = tipc_sk_rcv(&tipc_port_to_sock(p_ptr)->sk, buf); |
| 886 | tipc_port_unlock(p_ptr); | 778 | tipc_port_unlock(p_ptr); |
| 887 | if (likely(!err)) | 779 | if (likely(!err)) |
| 888 | return dsz; | 780 | return dsz; |
| @@ -894,43 +786,43 @@ int tipc_port_recv_msg(struct sk_buff *buf) | |||
| 894 | } | 786 | } |
| 895 | 787 | ||
| 896 | /* | 788 | /* |
| 897 | * tipc_port_recv_sections(): Concatenate and deliver sectioned | 789 | * tipc_port_iovec_rcv: Concatenate and deliver sectioned |
| 898 | * message for this node. | 790 | * message for this node. |
| 899 | */ | 791 | */ |
| 900 | static int tipc_port_recv_sections(struct tipc_port *sender, | 792 | static int tipc_port_iovec_rcv(struct tipc_port *sender, |
| 901 | struct iovec const *msg_sect, | 793 | struct iovec const *msg_sect, |
| 902 | unsigned int len) | 794 | unsigned int len) |
| 903 | { | 795 | { |
| 904 | struct sk_buff *buf; | 796 | struct sk_buff *buf; |
| 905 | int res; | 797 | int res; |
| 906 | 798 | ||
| 907 | res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf); | 799 | res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf); |
| 908 | if (likely(buf)) | 800 | if (likely(buf)) |
| 909 | tipc_port_recv_msg(buf); | 801 | tipc_port_rcv(buf); |
| 910 | return res; | 802 | return res; |
| 911 | } | 803 | } |
| 912 | 804 | ||
| 913 | /** | 805 | /** |
| 914 | * tipc_send - send message sections on connection | 806 | * tipc_send - send message sections on connection |
| 915 | */ | 807 | */ |
| 916 | int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) | 808 | int tipc_send(struct tipc_port *p_ptr, |
| 809 | struct iovec const *msg_sect, | ||
| 810 | unsigned int len) | ||
| 917 | { | 811 | { |
| 918 | struct tipc_port *p_ptr; | ||
| 919 | u32 destnode; | 812 | u32 destnode; |
| 920 | int res; | 813 | int res; |
| 921 | 814 | ||
| 922 | p_ptr = tipc_port_deref(ref); | 815 | if (!p_ptr->connected) |
| 923 | if (!p_ptr || !p_ptr->connected) | ||
| 924 | return -EINVAL; | 816 | return -EINVAL; |
| 925 | 817 | ||
| 926 | p_ptr->congested = 1; | 818 | p_ptr->congested = 1; |
| 927 | if (!tipc_port_congested(p_ptr)) { | 819 | if (!tipc_port_congested(p_ptr)) { |
| 928 | destnode = port_peernode(p_ptr); | 820 | destnode = tipc_port_peernode(p_ptr); |
| 929 | if (likely(!in_own_node(destnode))) | 821 | if (likely(!in_own_node(destnode))) |
| 930 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, | 822 | res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len, |
| 931 | len, destnode); | 823 | destnode); |
| 932 | else | 824 | else |
| 933 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); | 825 | res = tipc_port_iovec_rcv(p_ptr, msg_sect, len); |
| 934 | 826 | ||
| 935 | if (likely(res != -ELINKCONG)) { | 827 | if (likely(res != -ELINKCONG)) { |
| 936 | p_ptr->congested = 0; | 828 | p_ptr->congested = 0; |
| @@ -939,7 +831,7 @@ int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) | |||
| 939 | return res; | 831 | return res; |
| 940 | } | 832 | } |
| 941 | } | 833 | } |
| 942 | if (port_unreliable(p_ptr)) { | 834 | if (tipc_port_unreliable(p_ptr)) { |
| 943 | p_ptr->congested = 0; | 835 | p_ptr->congested = 0; |
| 944 | return len; | 836 | return len; |
| 945 | } | 837 | } |
| @@ -949,17 +841,18 @@ int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) | |||
| 949 | /** | 841 | /** |
| 950 | * tipc_send2name - send message sections to port name | 842 | * tipc_send2name - send message sections to port name |
| 951 | */ | 843 | */ |
| 952 | int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, | 844 | int tipc_send2name(struct tipc_port *p_ptr, |
| 953 | struct iovec const *msg_sect, unsigned int len) | 845 | struct tipc_name const *name, |
| 846 | unsigned int domain, | ||
| 847 | struct iovec const *msg_sect, | ||
| 848 | unsigned int len) | ||
| 954 | { | 849 | { |
| 955 | struct tipc_port *p_ptr; | ||
| 956 | struct tipc_msg *msg; | 850 | struct tipc_msg *msg; |
| 957 | u32 destnode = domain; | 851 | u32 destnode = domain; |
| 958 | u32 destport; | 852 | u32 destport; |
| 959 | int res; | 853 | int res; |
| 960 | 854 | ||
| 961 | p_ptr = tipc_port_deref(ref); | 855 | if (p_ptr->connected) |
| 962 | if (!p_ptr || p_ptr->connected) | ||
| 963 | return -EINVAL; | 856 | return -EINVAL; |
| 964 | 857 | ||
| 965 | msg = &p_ptr->phdr; | 858 | msg = &p_ptr->phdr; |
| @@ -974,39 +867,39 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, | |||
| 974 | 867 | ||
| 975 | if (likely(destport || destnode)) { | 868 | if (likely(destport || destnode)) { |
| 976 | if (likely(in_own_node(destnode))) | 869 | if (likely(in_own_node(destnode))) |
| 977 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); | 870 | res = tipc_port_iovec_rcv(p_ptr, msg_sect, len); |
| 978 | else if (tipc_own_addr) | 871 | else if (tipc_own_addr) |
| 979 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, | 872 | res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len, |
| 980 | len, destnode); | 873 | destnode); |
| 981 | else | 874 | else |
| 982 | res = tipc_port_reject_sections(p_ptr, msg, msg_sect, | 875 | res = tipc_port_iovec_reject(p_ptr, msg, msg_sect, |
| 983 | len, TIPC_ERR_NO_NODE); | 876 | len, TIPC_ERR_NO_NODE); |
| 984 | if (likely(res != -ELINKCONG)) { | 877 | if (likely(res != -ELINKCONG)) { |
| 985 | if (res > 0) | 878 | if (res > 0) |
| 986 | p_ptr->sent++; | 879 | p_ptr->sent++; |
| 987 | return res; | 880 | return res; |
| 988 | } | 881 | } |
| 989 | if (port_unreliable(p_ptr)) { | 882 | if (tipc_port_unreliable(p_ptr)) |
| 990 | return len; | 883 | return len; |
| 991 | } | 884 | |
| 992 | return -ELINKCONG; | 885 | return -ELINKCONG; |
| 993 | } | 886 | } |
| 994 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, len, | 887 | return tipc_port_iovec_reject(p_ptr, msg, msg_sect, len, |
| 995 | TIPC_ERR_NO_NAME); | 888 | TIPC_ERR_NO_NAME); |
| 996 | } | 889 | } |
| 997 | 890 | ||
| 998 | /** | 891 | /** |
| 999 | * tipc_send2port - send message sections to port identity | 892 | * tipc_send2port - send message sections to port identity |
| 1000 | */ | 893 | */ |
| 1001 | int tipc_send2port(u32 ref, struct tipc_portid const *dest, | 894 | int tipc_send2port(struct tipc_port *p_ptr, |
| 1002 | struct iovec const *msg_sect, unsigned int len) | 895 | struct tipc_portid const *dest, |
| 896 | struct iovec const *msg_sect, | ||
| 897 | unsigned int len) | ||
| 1003 | { | 898 | { |
| 1004 | struct tipc_port *p_ptr; | ||
| 1005 | struct tipc_msg *msg; | 899 | struct tipc_msg *msg; |
| 1006 | int res; | 900 | int res; |
| 1007 | 901 | ||
| 1008 | p_ptr = tipc_port_deref(ref); | 902 | if (p_ptr->connected) |
| 1009 | if (!p_ptr || p_ptr->connected) | ||
| 1010 | return -EINVAL; | 903 | return -EINVAL; |
| 1011 | 904 | ||
| 1012 | msg = &p_ptr->phdr; | 905 | msg = &p_ptr->phdr; |
| @@ -1017,20 +910,20 @@ int tipc_send2port(u32 ref, struct tipc_portid const *dest, | |||
| 1017 | msg_set_hdr_sz(msg, BASIC_H_SIZE); | 910 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
| 1018 | 911 | ||
| 1019 | if (in_own_node(dest->node)) | 912 | if (in_own_node(dest->node)) |
| 1020 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); | 913 | res = tipc_port_iovec_rcv(p_ptr, msg_sect, len); |
| 1021 | else if (tipc_own_addr) | 914 | else if (tipc_own_addr) |
| 1022 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, len, | 915 | res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len, |
| 1023 | dest->node); | 916 | dest->node); |
| 1024 | else | 917 | else |
| 1025 | res = tipc_port_reject_sections(p_ptr, msg, msg_sect, len, | 918 | res = tipc_port_iovec_reject(p_ptr, msg, msg_sect, len, |
| 1026 | TIPC_ERR_NO_NODE); | 919 | TIPC_ERR_NO_NODE); |
| 1027 | if (likely(res != -ELINKCONG)) { | 920 | if (likely(res != -ELINKCONG)) { |
| 1028 | if (res > 0) | 921 | if (res > 0) |
| 1029 | p_ptr->sent++; | 922 | p_ptr->sent++; |
| 1030 | return res; | 923 | return res; |
| 1031 | } | 924 | } |
| 1032 | if (port_unreliable(p_ptr)) { | 925 | if (tipc_port_unreliable(p_ptr)) |
| 1033 | return len; | 926 | return len; |
| 1034 | } | 927 | |
| 1035 | return -ELINKCONG; | 928 | return -ELINKCONG; |
| 1036 | } | 929 | } |
diff --git a/net/tipc/port.h b/net/tipc/port.h index 34f12bd4074e..a00397393bd1 100644 --- a/net/tipc/port.h +++ b/net/tipc/port.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/port.h: Include file for TIPC port code | 2 | * net/tipc/port.h: Include file for TIPC port code |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 1994-2007, Ericsson AB | 4 | * Copyright (c) 1994-2007, 2014, Ericsson AB |
| 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
| 6 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| @@ -48,7 +48,6 @@ | |||
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * struct tipc_port - TIPC port structure | 50 | * struct tipc_port - TIPC port structure |
| 51 | * @sk: pointer to socket handle | ||
| 52 | * @lock: pointer to spinlock for controlling access to port | 51 | * @lock: pointer to spinlock for controlling access to port |
| 53 | * @connected: non-zero if port is currently connected to a peer port | 52 | * @connected: non-zero if port is currently connected to a peer port |
| 54 | * @conn_type: TIPC type used when connection was established | 53 | * @conn_type: TIPC type used when connection was established |
| @@ -60,8 +59,6 @@ | |||
| 60 | * @ref: unique reference to port in TIPC object registry | 59 | * @ref: unique reference to port in TIPC object registry |
| 61 | * @phdr: preformatted message header used when sending messages | 60 | * @phdr: preformatted message header used when sending messages |
| 62 | * @port_list: adjacent ports in TIPC's global list of ports | 61 | * @port_list: adjacent ports in TIPC's global list of ports |
| 63 | * @dispatcher: ptr to routine which handles received messages | ||
| 64 | * @wakeup: ptr to routine to call when port is no longer congested | ||
| 65 | * @wait_list: adjacent ports in list of ports waiting on link congestion | 62 | * @wait_list: adjacent ports in list of ports waiting on link congestion |
| 66 | * @waiting_pkts: | 63 | * @waiting_pkts: |
| 67 | * @sent: # of non-empty messages sent by port | 64 | * @sent: # of non-empty messages sent by port |
| @@ -74,7 +71,6 @@ | |||
| 74 | * @subscription: "node down" subscription used to terminate failed connections | 71 | * @subscription: "node down" subscription used to terminate failed connections |
| 75 | */ | 72 | */ |
| 76 | struct tipc_port { | 73 | struct tipc_port { |
| 77 | struct sock *sk; | ||
| 78 | spinlock_t *lock; | 74 | spinlock_t *lock; |
| 79 | int connected; | 75 | int connected; |
| 80 | u32 conn_type; | 76 | u32 conn_type; |
| @@ -86,8 +82,6 @@ struct tipc_port { | |||
| 86 | u32 ref; | 82 | u32 ref; |
| 87 | struct tipc_msg phdr; | 83 | struct tipc_msg phdr; |
| 88 | struct list_head port_list; | 84 | struct list_head port_list; |
| 89 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *); | ||
| 90 | void (*wakeup)(struct tipc_port *); | ||
| 91 | struct list_head wait_list; | 85 | struct list_head wait_list; |
| 92 | u32 waiting_pkts; | 86 | u32 waiting_pkts; |
| 93 | u32 sent; | 87 | u32 sent; |
| @@ -106,68 +100,71 @@ struct tipc_port_list; | |||
| 106 | /* | 100 | /* |
| 107 | * TIPC port manipulation routines | 101 | * TIPC port manipulation routines |
| 108 | */ | 102 | */ |
| 109 | struct tipc_port *tipc_createport(struct sock *sk, | 103 | u32 tipc_port_init(struct tipc_port *p_ptr, |
| 110 | u32 (*dispatcher)(struct tipc_port *, | 104 | const unsigned int importance); |
| 111 | struct sk_buff *), | ||
| 112 | void (*wakeup)(struct tipc_port *), | ||
| 113 | const u32 importance); | ||
| 114 | 105 | ||
| 115 | int tipc_reject_msg(struct sk_buff *buf, u32 err); | 106 | int tipc_reject_msg(struct sk_buff *buf, u32 err); |
| 116 | 107 | ||
| 117 | void tipc_acknowledge(u32 port_ref, u32 ack); | 108 | void tipc_acknowledge(u32 port_ref, u32 ack); |
| 118 | 109 | ||
| 119 | int tipc_deleteport(struct tipc_port *p_ptr); | 110 | void tipc_port_destroy(struct tipc_port *p_ptr); |
| 120 | |||
| 121 | int tipc_portimportance(u32 portref, unsigned int *importance); | ||
| 122 | int tipc_set_portimportance(u32 portref, unsigned int importance); | ||
| 123 | |||
| 124 | int tipc_portunreliable(u32 portref, unsigned int *isunreliable); | ||
| 125 | int tipc_set_portunreliable(u32 portref, unsigned int isunreliable); | ||
| 126 | |||
| 127 | int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable); | ||
| 128 | int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable); | ||
| 129 | 111 | ||
| 130 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, | 112 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, |
| 131 | struct tipc_name_seq const *name_seq); | 113 | struct tipc_name_seq const *name_seq); |
| 114 | |||
| 132 | int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, | 115 | int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, |
| 133 | struct tipc_name_seq const *name_seq); | 116 | struct tipc_name_seq const *name_seq); |
| 134 | 117 | ||
| 135 | int tipc_connect(u32 portref, struct tipc_portid const *port); | 118 | int tipc_port_connect(u32 portref, struct tipc_portid const *port); |
| 136 | 119 | ||
| 137 | int tipc_disconnect(u32 portref); | 120 | int tipc_port_disconnect(u32 portref); |
| 138 | 121 | ||
| 139 | int tipc_shutdown(u32 ref); | 122 | int tipc_port_shutdown(u32 ref); |
| 140 | 123 | ||
| 124 | void tipc_port_wakeup(struct tipc_port *port); | ||
| 141 | 125 | ||
| 142 | /* | 126 | /* |
| 143 | * The following routines require that the port be locked on entry | 127 | * The following routines require that the port be locked on entry |
| 144 | */ | 128 | */ |
| 145 | int __tipc_disconnect(struct tipc_port *tp_ptr); | 129 | int __tipc_port_disconnect(struct tipc_port *tp_ptr); |
| 146 | int __tipc_connect(u32 ref, struct tipc_port *p_ptr, | 130 | int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr, |
| 147 | struct tipc_portid const *peer); | 131 | struct tipc_portid const *peer); |
| 148 | int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg); | 132 | int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg); |
| 149 | 133 | ||
| 150 | /* | 134 | /* |
| 151 | * TIPC messaging routines | 135 | * TIPC messaging routines |
| 152 | */ | 136 | */ |
| 153 | int tipc_port_recv_msg(struct sk_buff *buf); | 137 | int tipc_port_rcv(struct sk_buff *buf); |
| 154 | int tipc_send(u32 portref, struct iovec const *msg_sect, unsigned int len); | 138 | |
| 155 | 139 | int tipc_send(struct tipc_port *port, | |
| 156 | int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain, | 140 | struct iovec const *msg_sect, |
| 157 | struct iovec const *msg_sect, unsigned int len); | 141 | unsigned int len); |
| 142 | |||
| 143 | int tipc_send2name(struct tipc_port *port, | ||
| 144 | struct tipc_name const *name, | ||
| 145 | u32 domain, | ||
| 146 | struct iovec const *msg_sect, | ||
| 147 | unsigned int len); | ||
| 148 | |||
| 149 | int tipc_send2port(struct tipc_port *port, | ||
| 150 | struct tipc_portid const *dest, | ||
| 151 | struct iovec const *msg_sect, | ||
| 152 | unsigned int len); | ||
| 153 | |||
| 154 | int tipc_port_mcast_xmit(struct tipc_port *port, | ||
| 155 | struct tipc_name_seq const *seq, | ||
| 156 | struct iovec const *msg, | ||
| 157 | unsigned int len); | ||
| 158 | |||
| 159 | int tipc_port_iovec_reject(struct tipc_port *p_ptr, | ||
| 160 | struct tipc_msg *hdr, | ||
| 161 | struct iovec const *msg_sect, | ||
| 162 | unsigned int len, | ||
| 163 | int err); | ||
| 158 | 164 | ||
| 159 | int tipc_send2port(u32 portref, struct tipc_portid const *dest, | ||
| 160 | struct iovec const *msg_sect, unsigned int len); | ||
| 161 | |||
| 162 | int tipc_multicast(u32 portref, struct tipc_name_seq const *seq, | ||
| 163 | struct iovec const *msg, unsigned int len); | ||
| 164 | |||
| 165 | int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, | ||
| 166 | struct iovec const *msg_sect, unsigned int len, | ||
| 167 | int err); | ||
| 168 | struct sk_buff *tipc_port_get_ports(void); | 165 | struct sk_buff *tipc_port_get_ports(void); |
| 169 | void tipc_port_recv_proto_msg(struct sk_buff *buf); | 166 | void tipc_port_proto_rcv(struct sk_buff *buf); |
| 170 | void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp); | 167 | void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp); |
| 171 | void tipc_port_reinit(void); | 168 | void tipc_port_reinit(void); |
| 172 | 169 | ||
| 173 | /** | 170 | /** |
| @@ -188,14 +185,53 @@ static inline void tipc_port_unlock(struct tipc_port *p_ptr) | |||
| 188 | spin_unlock_bh(p_ptr->lock); | 185 | spin_unlock_bh(p_ptr->lock); |
| 189 | } | 186 | } |
| 190 | 187 | ||
| 191 | static inline struct tipc_port *tipc_port_deref(u32 ref) | 188 | static inline int tipc_port_congested(struct tipc_port *p_ptr) |
| 192 | { | 189 | { |
| 193 | return (struct tipc_port *)tipc_ref_deref(ref); | 190 | return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2); |
| 194 | } | 191 | } |
| 195 | 192 | ||
| 196 | static inline int tipc_port_congested(struct tipc_port *p_ptr) | 193 | |
| 194 | static inline u32 tipc_port_peernode(struct tipc_port *p_ptr) | ||
| 197 | { | 195 | { |
| 198 | return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2); | 196 | return msg_destnode(&p_ptr->phdr); |
| 197 | } | ||
| 198 | |||
| 199 | static inline u32 tipc_port_peerport(struct tipc_port *p_ptr) | ||
| 200 | { | ||
| 201 | return msg_destport(&p_ptr->phdr); | ||
| 202 | } | ||
| 203 | |||
| 204 | static inline bool tipc_port_unreliable(struct tipc_port *port) | ||
| 205 | { | ||
| 206 | return msg_src_droppable(&port->phdr) != 0; | ||
| 207 | } | ||
| 208 | |||
| 209 | static inline void tipc_port_set_unreliable(struct tipc_port *port, | ||
| 210 | bool unreliable) | ||
| 211 | { | ||
| 212 | msg_set_src_droppable(&port->phdr, unreliable ? 1 : 0); | ||
| 213 | } | ||
| 214 | |||
| 215 | static inline bool tipc_port_unreturnable(struct tipc_port *port) | ||
| 216 | { | ||
| 217 | return msg_dest_droppable(&port->phdr) != 0; | ||
| 218 | } | ||
| 219 | |||
| 220 | static inline void tipc_port_set_unreturnable(struct tipc_port *port, | ||
| 221 | bool unreturnable) | ||
| 222 | { | ||
| 223 | msg_set_dest_droppable(&port->phdr, unreturnable ? 1 : 0); | ||
| 224 | } | ||
| 225 | |||
| 226 | |||
| 227 | static inline int tipc_port_importance(struct tipc_port *port) | ||
| 228 | { | ||
| 229 | return msg_importance(&port->phdr); | ||
| 230 | } | ||
| 231 | |||
| 232 | static inline void tipc_port_set_importance(struct tipc_port *port, int imp) | ||
| 233 | { | ||
| 234 | msg_set_importance(&port->phdr, (u32)imp); | ||
| 199 | } | 235 | } |
| 200 | 236 | ||
| 201 | #endif | 237 | #endif |
diff --git a/net/tipc/ref.c b/net/tipc/ref.c index 2a2a938dc22c..3d4ecd754eee 100644 --- a/net/tipc/ref.c +++ b/net/tipc/ref.c | |||
| @@ -89,7 +89,7 @@ struct ref_table { | |||
| 89 | 89 | ||
| 90 | static struct ref_table tipc_ref_table; | 90 | static struct ref_table tipc_ref_table; |
| 91 | 91 | ||
| 92 | static DEFINE_RWLOCK(ref_table_lock); | 92 | static DEFINE_SPINLOCK(ref_table_lock); |
| 93 | 93 | ||
| 94 | /** | 94 | /** |
| 95 | * tipc_ref_table_init - create reference table for objects | 95 | * tipc_ref_table_init - create reference table for objects |
| @@ -126,9 +126,6 @@ int tipc_ref_table_init(u32 requested_size, u32 start) | |||
| 126 | */ | 126 | */ |
| 127 | void tipc_ref_table_stop(void) | 127 | void tipc_ref_table_stop(void) |
| 128 | { | 128 | { |
| 129 | if (!tipc_ref_table.entries) | ||
| 130 | return; | ||
| 131 | |||
| 132 | vfree(tipc_ref_table.entries); | 129 | vfree(tipc_ref_table.entries); |
| 133 | tipc_ref_table.entries = NULL; | 130 | tipc_ref_table.entries = NULL; |
| 134 | } | 131 | } |
| @@ -162,7 +159,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) | |||
| 162 | } | 159 | } |
| 163 | 160 | ||
| 164 | /* take a free entry, if available; otherwise initialize a new entry */ | 161 | /* take a free entry, if available; otherwise initialize a new entry */ |
| 165 | write_lock_bh(&ref_table_lock); | 162 | spin_lock_bh(&ref_table_lock); |
| 166 | if (tipc_ref_table.first_free) { | 163 | if (tipc_ref_table.first_free) { |
| 167 | index = tipc_ref_table.first_free; | 164 | index = tipc_ref_table.first_free; |
| 168 | entry = &(tipc_ref_table.entries[index]); | 165 | entry = &(tipc_ref_table.entries[index]); |
| @@ -178,7 +175,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) | |||
| 178 | } else { | 175 | } else { |
| 179 | ref = 0; | 176 | ref = 0; |
| 180 | } | 177 | } |
| 181 | write_unlock_bh(&ref_table_lock); | 178 | spin_unlock_bh(&ref_table_lock); |
| 182 | 179 | ||
| 183 | /* | 180 | /* |
| 184 | * Grab the lock so no one else can modify this entry | 181 | * Grab the lock so no one else can modify this entry |
| @@ -219,7 +216,7 @@ void tipc_ref_discard(u32 ref) | |||
| 219 | index = ref & index_mask; | 216 | index = ref & index_mask; |
| 220 | entry = &(tipc_ref_table.entries[index]); | 217 | entry = &(tipc_ref_table.entries[index]); |
| 221 | 218 | ||
| 222 | write_lock_bh(&ref_table_lock); | 219 | spin_lock_bh(&ref_table_lock); |
| 223 | 220 | ||
| 224 | if (!entry->object) { | 221 | if (!entry->object) { |
| 225 | pr_err("Attempt to discard ref. to non-existent obj\n"); | 222 | pr_err("Attempt to discard ref. to non-existent obj\n"); |
| @@ -245,7 +242,7 @@ void tipc_ref_discard(u32 ref) | |||
| 245 | tipc_ref_table.last_free = index; | 242 | tipc_ref_table.last_free = index; |
| 246 | 243 | ||
| 247 | exit: | 244 | exit: |
| 248 | write_unlock_bh(&ref_table_lock); | 245 | spin_unlock_bh(&ref_table_lock); |
| 249 | } | 246 | } |
| 250 | 247 | ||
| 251 | /** | 248 | /** |
| @@ -267,20 +264,3 @@ void *tipc_ref_lock(u32 ref) | |||
| 267 | } | 264 | } |
| 268 | return NULL; | 265 | return NULL; |
| 269 | } | 266 | } |
| 270 | |||
| 271 | |||
| 272 | /** | ||
| 273 | * tipc_ref_deref - return pointer referenced object (without locking it) | ||
| 274 | */ | ||
| 275 | void *tipc_ref_deref(u32 ref) | ||
| 276 | { | ||
| 277 | if (likely(tipc_ref_table.entries)) { | ||
| 278 | struct reference *entry; | ||
| 279 | |||
| 280 | entry = &tipc_ref_table.entries[ref & | ||
| 281 | tipc_ref_table.index_mask]; | ||
| 282 | if (likely(entry->ref == ref)) | ||
| 283 | return entry->object; | ||
| 284 | } | ||
| 285 | return NULL; | ||
| 286 | } | ||
diff --git a/net/tipc/ref.h b/net/tipc/ref.h index 5bc8e7ab84de..d01aa1df63b8 100644 --- a/net/tipc/ref.h +++ b/net/tipc/ref.h | |||
| @@ -44,6 +44,5 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock); | |||
| 44 | void tipc_ref_discard(u32 ref); | 44 | void tipc_ref_discard(u32 ref); |
| 45 | 45 | ||
| 46 | void *tipc_ref_lock(u32 ref); | 46 | void *tipc_ref_lock(u32 ref); |
| 47 | void *tipc_ref_deref(u32 ref); | ||
| 48 | 47 | ||
| 49 | #endif | 48 | #endif |
diff --git a/net/tipc/server.c b/net/tipc/server.c index b635ca347a87..646a930eefbf 100644 --- a/net/tipc/server.c +++ b/net/tipc/server.c | |||
| @@ -87,7 +87,6 @@ static void tipc_clean_outqueues(struct tipc_conn *con); | |||
| 87 | static void tipc_conn_kref_release(struct kref *kref) | 87 | static void tipc_conn_kref_release(struct kref *kref) |
| 88 | { | 88 | { |
| 89 | struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); | 89 | struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); |
| 90 | struct tipc_server *s = con->server; | ||
| 91 | 90 | ||
| 92 | if (con->sock) { | 91 | if (con->sock) { |
| 93 | tipc_sock_release_local(con->sock); | 92 | tipc_sock_release_local(con->sock); |
| @@ -95,10 +94,6 @@ static void tipc_conn_kref_release(struct kref *kref) | |||
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | tipc_clean_outqueues(con); | 96 | tipc_clean_outqueues(con); |
| 98 | |||
| 99 | if (con->conid) | ||
| 100 | s->tipc_conn_shutdown(con->conid, con->usr_data); | ||
| 101 | |||
| 102 | kfree(con); | 97 | kfree(con); |
| 103 | } | 98 | } |
| 104 | 99 | ||
| @@ -181,6 +176,9 @@ static void tipc_close_conn(struct tipc_conn *con) | |||
| 181 | struct tipc_server *s = con->server; | 176 | struct tipc_server *s = con->server; |
| 182 | 177 | ||
| 183 | if (test_and_clear_bit(CF_CONNECTED, &con->flags)) { | 178 | if (test_and_clear_bit(CF_CONNECTED, &con->flags)) { |
| 179 | if (con->conid) | ||
| 180 | s->tipc_conn_shutdown(con->conid, con->usr_data); | ||
| 181 | |||
| 184 | spin_lock_bh(&s->idr_lock); | 182 | spin_lock_bh(&s->idr_lock); |
| 185 | idr_remove(&s->conn_idr, con->conid); | 183 | idr_remove(&s->conn_idr, con->conid); |
| 186 | s->idr_in_use--; | 184 | s->idr_in_use--; |
| @@ -429,10 +427,12 @@ int tipc_conn_sendmsg(struct tipc_server *s, int conid, | |||
| 429 | list_add_tail(&e->list, &con->outqueue); | 427 | list_add_tail(&e->list, &con->outqueue); |
| 430 | spin_unlock_bh(&con->outqueue_lock); | 428 | spin_unlock_bh(&con->outqueue_lock); |
| 431 | 429 | ||
| 432 | if (test_bit(CF_CONNECTED, &con->flags)) | 430 | if (test_bit(CF_CONNECTED, &con->flags)) { |
| 433 | if (!queue_work(s->send_wq, &con->swork)) | 431 | if (!queue_work(s->send_wq, &con->swork)) |
| 434 | conn_put(con); | 432 | conn_put(con); |
| 435 | 433 | } else { | |
| 434 | conn_put(con); | ||
| 435 | } | ||
| 436 | return 0; | 436 | return 0; |
| 437 | } | 437 | } |
| 438 | 438 | ||
| @@ -573,7 +573,6 @@ int tipc_server_start(struct tipc_server *s) | |||
| 573 | kmem_cache_destroy(s->rcvbuf_cache); | 573 | kmem_cache_destroy(s->rcvbuf_cache); |
| 574 | return ret; | 574 | return ret; |
| 575 | } | 575 | } |
| 576 | s->enabled = 1; | ||
| 577 | return ret; | 576 | return ret; |
| 578 | } | 577 | } |
| 579 | 578 | ||
| @@ -583,10 +582,6 @@ void tipc_server_stop(struct tipc_server *s) | |||
| 583 | int total = 0; | 582 | int total = 0; |
| 584 | int id; | 583 | int id; |
| 585 | 584 | ||
| 586 | if (!s->enabled) | ||
| 587 | return; | ||
| 588 | |||
| 589 | s->enabled = 0; | ||
| 590 | spin_lock_bh(&s->idr_lock); | 585 | spin_lock_bh(&s->idr_lock); |
| 591 | for (id = 0; total < s->idr_in_use; id++) { | 586 | for (id = 0; total < s->idr_in_use; id++) { |
| 592 | con = idr_find(&s->conn_idr, id); | 587 | con = idr_find(&s->conn_idr, id); |
diff --git a/net/tipc/server.h b/net/tipc/server.h index 98b23f20bc0f..be817b0b547e 100644 --- a/net/tipc/server.h +++ b/net/tipc/server.h | |||
| @@ -56,7 +56,6 @@ | |||
| 56 | * @name: server name | 56 | * @name: server name |
| 57 | * @imp: message importance | 57 | * @imp: message importance |
| 58 | * @type: socket type | 58 | * @type: socket type |
| 59 | * @enabled: identify whether server is launched or not | ||
| 60 | */ | 59 | */ |
| 61 | struct tipc_server { | 60 | struct tipc_server { |
| 62 | struct idr conn_idr; | 61 | struct idr conn_idr; |
| @@ -74,7 +73,6 @@ struct tipc_server { | |||
| 74 | const char name[TIPC_SERVER_NAME_LEN]; | 73 | const char name[TIPC_SERVER_NAME_LEN]; |
| 75 | int imp; | 74 | int imp; |
| 76 | int type; | 75 | int type; |
| 77 | int enabled; | ||
| 78 | }; | 76 | }; |
| 79 | 77 | ||
| 80 | int tipc_conn_sendmsg(struct tipc_server *s, int conid, | 78 | int tipc_conn_sendmsg(struct tipc_server *s, int conid, |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index aab4948f0aff..adc12e227303 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/socket.c: TIPC socket API | 2 | * net/tipc/socket.c: TIPC socket API |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2001-2007, 2012 Ericsson AB | 4 | * Copyright (c) 2001-2007, 2012-2014, Ericsson AB |
| 5 | * Copyright (c) 2004-2008, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2004-2008, 2010-2013, Wind River Systems |
| 6 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| @@ -38,30 +38,17 @@ | |||
| 38 | #include "port.h" | 38 | #include "port.h" |
| 39 | 39 | ||
| 40 | #include <linux/export.h> | 40 | #include <linux/export.h> |
| 41 | #include <net/sock.h> | ||
| 42 | 41 | ||
| 43 | #define SS_LISTENING -1 /* socket is listening */ | 42 | #define SS_LISTENING -1 /* socket is listening */ |
| 44 | #define SS_READY -2 /* socket is connectionless */ | 43 | #define SS_READY -2 /* socket is connectionless */ |
| 45 | 44 | ||
| 46 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ | 45 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
| 47 | 46 | ||
| 48 | struct tipc_sock { | ||
| 49 | struct sock sk; | ||
| 50 | struct tipc_port *p; | ||
| 51 | struct tipc_portid peer_name; | ||
| 52 | unsigned int conn_timeout; | ||
| 53 | }; | ||
| 54 | |||
| 55 | #define tipc_sk(sk) ((struct tipc_sock *)(sk)) | ||
| 56 | #define tipc_sk_port(sk) (tipc_sk(sk)->p) | ||
| 57 | |||
| 58 | static int backlog_rcv(struct sock *sk, struct sk_buff *skb); | 47 | static int backlog_rcv(struct sock *sk, struct sk_buff *skb); |
| 59 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf); | ||
| 60 | static void wakeupdispatch(struct tipc_port *tport); | ||
| 61 | static void tipc_data_ready(struct sock *sk, int len); | 48 | static void tipc_data_ready(struct sock *sk, int len); |
| 62 | static void tipc_write_space(struct sock *sk); | 49 | static void tipc_write_space(struct sock *sk); |
| 63 | static int release(struct socket *sock); | 50 | static int tipc_release(struct socket *sock); |
| 64 | static int accept(struct socket *sock, struct socket *new_sock, int flags); | 51 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); |
| 65 | 52 | ||
| 66 | static const struct proto_ops packet_ops; | 53 | static const struct proto_ops packet_ops; |
| 67 | static const struct proto_ops stream_ops; | 54 | static const struct proto_ops stream_ops; |
| @@ -70,8 +57,6 @@ static const struct proto_ops msg_ops; | |||
| 70 | static struct proto tipc_proto; | 57 | static struct proto tipc_proto; |
| 71 | static struct proto tipc_proto_kern; | 58 | static struct proto tipc_proto_kern; |
| 72 | 59 | ||
| 73 | static int sockets_enabled; | ||
| 74 | |||
| 75 | /* | 60 | /* |
| 76 | * Revised TIPC socket locking policy: | 61 | * Revised TIPC socket locking policy: |
| 77 | * | 62 | * |
| @@ -117,6 +102,8 @@ static int sockets_enabled; | |||
| 117 | * - port reference | 102 | * - port reference |
| 118 | */ | 103 | */ |
| 119 | 104 | ||
| 105 | #include "socket.h" | ||
| 106 | |||
| 120 | /** | 107 | /** |
| 121 | * advance_rx_queue - discard first buffer in socket receive queue | 108 | * advance_rx_queue - discard first buffer in socket receive queue |
| 122 | * | 109 | * |
| @@ -152,13 +139,15 @@ static void reject_rx_queue(struct sock *sk) | |||
| 152 | * | 139 | * |
| 153 | * Returns 0 on success, errno otherwise | 140 | * Returns 0 on success, errno otherwise |
| 154 | */ | 141 | */ |
| 155 | static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, | 142 | static int tipc_sk_create(struct net *net, struct socket *sock, |
| 156 | int kern) | 143 | int protocol, int kern) |
| 157 | { | 144 | { |
| 158 | const struct proto_ops *ops; | 145 | const struct proto_ops *ops; |
| 159 | socket_state state; | 146 | socket_state state; |
| 160 | struct sock *sk; | 147 | struct sock *sk; |
| 161 | struct tipc_port *tp_ptr; | 148 | struct tipc_sock *tsk; |
| 149 | struct tipc_port *port; | ||
| 150 | u32 ref; | ||
| 162 | 151 | ||
| 163 | /* Validate arguments */ | 152 | /* Validate arguments */ |
| 164 | if (unlikely(protocol != 0)) | 153 | if (unlikely(protocol != 0)) |
| @@ -191,10 +180,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, | |||
| 191 | if (sk == NULL) | 180 | if (sk == NULL) |
| 192 | return -ENOMEM; | 181 | return -ENOMEM; |
| 193 | 182 | ||
| 194 | /* Allocate TIPC port for socket to use */ | 183 | tsk = tipc_sk(sk); |
| 195 | tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch, | 184 | port = &tsk->port; |
| 196 | TIPC_LOW_IMPORTANCE); | 185 | |
| 197 | if (unlikely(!tp_ptr)) { | 186 | ref = tipc_port_init(port, TIPC_LOW_IMPORTANCE); |
| 187 | if (!ref) { | ||
| 188 | pr_warn("Socket registration failed, ref. table exhausted\n"); | ||
| 198 | sk_free(sk); | 189 | sk_free(sk); |
| 199 | return -ENOMEM; | 190 | return -ENOMEM; |
| 200 | } | 191 | } |
| @@ -208,17 +199,14 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, | |||
| 208 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; | 199 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; |
| 209 | sk->sk_data_ready = tipc_data_ready; | 200 | sk->sk_data_ready = tipc_data_ready; |
| 210 | sk->sk_write_space = tipc_write_space; | 201 | sk->sk_write_space = tipc_write_space; |
| 211 | tipc_sk(sk)->p = tp_ptr; | ||
| 212 | tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; | 202 | tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; |
| 213 | 203 | tipc_port_unlock(port); | |
| 214 | spin_unlock_bh(tp_ptr->lock); | ||
| 215 | 204 | ||
| 216 | if (sock->state == SS_READY) { | 205 | if (sock->state == SS_READY) { |
| 217 | tipc_set_portunreturnable(tp_ptr->ref, 1); | 206 | tipc_port_set_unreturnable(port, true); |
| 218 | if (sock->type == SOCK_DGRAM) | 207 | if (sock->type == SOCK_DGRAM) |
| 219 | tipc_set_portunreliable(tp_ptr->ref, 1); | 208 | tipc_port_set_unreliable(port, true); |
| 220 | } | 209 | } |
| 221 | |||
| 222 | return 0; | 210 | return 0; |
| 223 | } | 211 | } |
| 224 | 212 | ||
| @@ -256,7 +244,7 @@ int tipc_sock_create_local(int type, struct socket **res) | |||
| 256 | */ | 244 | */ |
| 257 | void tipc_sock_release_local(struct socket *sock) | 245 | void tipc_sock_release_local(struct socket *sock) |
| 258 | { | 246 | { |
| 259 | release(sock); | 247 | tipc_release(sock); |
| 260 | sock->ops = NULL; | 248 | sock->ops = NULL; |
| 261 | sock_release(sock); | 249 | sock_release(sock); |
| 262 | } | 250 | } |
| @@ -282,7 +270,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | |||
| 282 | if (ret < 0) | 270 | if (ret < 0) |
| 283 | return ret; | 271 | return ret; |
| 284 | 272 | ||
| 285 | ret = accept(sock, *newsock, flags); | 273 | ret = tipc_accept(sock, *newsock, flags); |
| 286 | if (ret < 0) { | 274 | if (ret < 0) { |
| 287 | sock_release(*newsock); | 275 | sock_release(*newsock); |
| 288 | return ret; | 276 | return ret; |
| @@ -292,7 +280,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | |||
| 292 | } | 280 | } |
| 293 | 281 | ||
| 294 | /** | 282 | /** |
| 295 | * release - destroy a TIPC socket | 283 | * tipc_release - destroy a TIPC socket |
| 296 | * @sock: socket to destroy | 284 | * @sock: socket to destroy |
| 297 | * | 285 | * |
| 298 | * This routine cleans up any messages that are still queued on the socket. | 286 | * This routine cleans up any messages that are still queued on the socket. |
| @@ -307,12 +295,12 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | |||
| 307 | * | 295 | * |
| 308 | * Returns 0 on success, errno otherwise | 296 | * Returns 0 on success, errno otherwise |
| 309 | */ | 297 | */ |
| 310 | static int release(struct socket *sock) | 298 | static int tipc_release(struct socket *sock) |
| 311 | { | 299 | { |
| 312 | struct sock *sk = sock->sk; | 300 | struct sock *sk = sock->sk; |
| 313 | struct tipc_port *tport; | 301 | struct tipc_sock *tsk; |
| 302 | struct tipc_port *port; | ||
| 314 | struct sk_buff *buf; | 303 | struct sk_buff *buf; |
| 315 | int res; | ||
| 316 | 304 | ||
| 317 | /* | 305 | /* |
| 318 | * Exit if socket isn't fully initialized (occurs when a failed accept() | 306 | * Exit if socket isn't fully initialized (occurs when a failed accept() |
| @@ -321,7 +309,8 @@ static int release(struct socket *sock) | |||
| 321 | if (sk == NULL) | 309 | if (sk == NULL) |
| 322 | return 0; | 310 | return 0; |
| 323 | 311 | ||
| 324 | tport = tipc_sk_port(sk); | 312 | tsk = tipc_sk(sk); |
| 313 | port = &tsk->port; | ||
| 325 | lock_sock(sk); | 314 | lock_sock(sk); |
| 326 | 315 | ||
| 327 | /* | 316 | /* |
| @@ -338,17 +327,16 @@ static int release(struct socket *sock) | |||
| 338 | if ((sock->state == SS_CONNECTING) || | 327 | if ((sock->state == SS_CONNECTING) || |
| 339 | (sock->state == SS_CONNECTED)) { | 328 | (sock->state == SS_CONNECTED)) { |
| 340 | sock->state = SS_DISCONNECTING; | 329 | sock->state = SS_DISCONNECTING; |
| 341 | tipc_disconnect(tport->ref); | 330 | tipc_port_disconnect(port->ref); |
| 342 | } | 331 | } |
| 343 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); | 332 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); |
| 344 | } | 333 | } |
| 345 | } | 334 | } |
| 346 | 335 | ||
| 347 | /* | 336 | /* Destroy TIPC port; also disconnects an active connection and |
| 348 | * Delete TIPC port; this ensures no more messages are queued | 337 | * sends a 'FIN-' to peer. |
| 349 | * (also disconnects an active connection & sends a 'FIN-' to peer) | ||
| 350 | */ | 338 | */ |
| 351 | res = tipc_deleteport(tport); | 339 | tipc_port_destroy(port); |
| 352 | 340 | ||
| 353 | /* Discard any remaining (connection-based) messages in receive queue */ | 341 | /* Discard any remaining (connection-based) messages in receive queue */ |
| 354 | __skb_queue_purge(&sk->sk_receive_queue); | 342 | __skb_queue_purge(&sk->sk_receive_queue); |
| @@ -360,11 +348,11 @@ static int release(struct socket *sock) | |||
| 360 | sock_put(sk); | 348 | sock_put(sk); |
| 361 | sock->sk = NULL; | 349 | sock->sk = NULL; |
| 362 | 350 | ||
| 363 | return res; | 351 | return 0; |
| 364 | } | 352 | } |
| 365 | 353 | ||
| 366 | /** | 354 | /** |
| 367 | * bind - associate or disassocate TIPC name(s) with a socket | 355 | * tipc_bind - associate or disassocate TIPC name(s) with a socket |
| 368 | * @sock: socket structure | 356 | * @sock: socket structure |
| 369 | * @uaddr: socket address describing name(s) and desired operation | 357 | * @uaddr: socket address describing name(s) and desired operation |
| 370 | * @uaddr_len: size of socket address data structure | 358 | * @uaddr_len: size of socket address data structure |
| @@ -378,16 +366,17 @@ static int release(struct socket *sock) | |||
| 378 | * NOTE: This routine doesn't need to take the socket lock since it doesn't | 366 | * NOTE: This routine doesn't need to take the socket lock since it doesn't |
| 379 | * access any non-constant socket information. | 367 | * access any non-constant socket information. |
| 380 | */ | 368 | */ |
| 381 | static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | 369 | static int tipc_bind(struct socket *sock, struct sockaddr *uaddr, |
| 370 | int uaddr_len) | ||
| 382 | { | 371 | { |
| 383 | struct sock *sk = sock->sk; | 372 | struct sock *sk = sock->sk; |
| 384 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; | 373 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
| 385 | struct tipc_port *tport = tipc_sk_port(sock->sk); | 374 | struct tipc_sock *tsk = tipc_sk(sk); |
| 386 | int res = -EINVAL; | 375 | int res = -EINVAL; |
| 387 | 376 | ||
| 388 | lock_sock(sk); | 377 | lock_sock(sk); |
| 389 | if (unlikely(!uaddr_len)) { | 378 | if (unlikely(!uaddr_len)) { |
| 390 | res = tipc_withdraw(tport, 0, NULL); | 379 | res = tipc_withdraw(&tsk->port, 0, NULL); |
| 391 | goto exit; | 380 | goto exit; |
| 392 | } | 381 | } |
| 393 | 382 | ||
| @@ -415,15 +404,15 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | |||
| 415 | } | 404 | } |
| 416 | 405 | ||
| 417 | res = (addr->scope > 0) ? | 406 | res = (addr->scope > 0) ? |
| 418 | tipc_publish(tport, addr->scope, &addr->addr.nameseq) : | 407 | tipc_publish(&tsk->port, addr->scope, &addr->addr.nameseq) : |
| 419 | tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq); | 408 | tipc_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq); |
| 420 | exit: | 409 | exit: |
| 421 | release_sock(sk); | 410 | release_sock(sk); |
| 422 | return res; | 411 | return res; |
| 423 | } | 412 | } |
| 424 | 413 | ||
| 425 | /** | 414 | /** |
| 426 | * get_name - get port ID of socket or peer socket | 415 | * tipc_getname - get port ID of socket or peer socket |
| 427 | * @sock: socket structure | 416 | * @sock: socket structure |
| 428 | * @uaddr: area for returned socket address | 417 | * @uaddr: area for returned socket address |
| 429 | * @uaddr_len: area for returned length of socket address | 418 | * @uaddr_len: area for returned length of socket address |
| @@ -435,21 +424,21 @@ exit: | |||
| 435 | * accesses socket information that is unchanging (or which changes in | 424 | * accesses socket information that is unchanging (or which changes in |
| 436 | * a completely predictable manner). | 425 | * a completely predictable manner). |
| 437 | */ | 426 | */ |
| 438 | static int get_name(struct socket *sock, struct sockaddr *uaddr, | 427 | static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, |
| 439 | int *uaddr_len, int peer) | 428 | int *uaddr_len, int peer) |
| 440 | { | 429 | { |
| 441 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; | 430 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
| 442 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 431 | struct tipc_sock *tsk = tipc_sk(sock->sk); |
| 443 | 432 | ||
| 444 | memset(addr, 0, sizeof(*addr)); | 433 | memset(addr, 0, sizeof(*addr)); |
| 445 | if (peer) { | 434 | if (peer) { |
| 446 | if ((sock->state != SS_CONNECTED) && | 435 | if ((sock->state != SS_CONNECTED) && |
| 447 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) | 436 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) |
| 448 | return -ENOTCONN; | 437 | return -ENOTCONN; |
| 449 | addr->addr.id.ref = tsock->peer_name.ref; | 438 | addr->addr.id.ref = tipc_port_peerport(&tsk->port); |
| 450 | addr->addr.id.node = tsock->peer_name.node; | 439 | addr->addr.id.node = tipc_port_peernode(&tsk->port); |
| 451 | } else { | 440 | } else { |
| 452 | addr->addr.id.ref = tsock->p->ref; | 441 | addr->addr.id.ref = tsk->port.ref; |
| 453 | addr->addr.id.node = tipc_own_addr; | 442 | addr->addr.id.node = tipc_own_addr; |
| 454 | } | 443 | } |
| 455 | 444 | ||
| @@ -463,7 +452,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr, | |||
| 463 | } | 452 | } |
| 464 | 453 | ||
| 465 | /** | 454 | /** |
| 466 | * poll - read and possibly block on pollmask | 455 | * tipc_poll - read and possibly block on pollmask |
| 467 | * @file: file structure associated with the socket | 456 | * @file: file structure associated with the socket |
| 468 | * @sock: socket for which to calculate the poll bits | 457 | * @sock: socket for which to calculate the poll bits |
| 469 | * @wait: ??? | 458 | * @wait: ??? |
| @@ -502,22 +491,23 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr, | |||
| 502 | * imply that the operation will succeed, merely that it should be performed | 491 | * imply that the operation will succeed, merely that it should be performed |
| 503 | * and will not block. | 492 | * and will not block. |
| 504 | */ | 493 | */ |
| 505 | static unsigned int poll(struct file *file, struct socket *sock, | 494 | static unsigned int tipc_poll(struct file *file, struct socket *sock, |
| 506 | poll_table *wait) | 495 | poll_table *wait) |
| 507 | { | 496 | { |
| 508 | struct sock *sk = sock->sk; | 497 | struct sock *sk = sock->sk; |
| 498 | struct tipc_sock *tsk = tipc_sk(sk); | ||
| 509 | u32 mask = 0; | 499 | u32 mask = 0; |
| 510 | 500 | ||
| 511 | sock_poll_wait(file, sk_sleep(sk), wait); | 501 | sock_poll_wait(file, sk_sleep(sk), wait); |
| 512 | 502 | ||
| 513 | switch ((int)sock->state) { | 503 | switch ((int)sock->state) { |
| 514 | case SS_UNCONNECTED: | 504 | case SS_UNCONNECTED: |
| 515 | if (!tipc_sk_port(sk)->congested) | 505 | if (!tsk->port.congested) |
| 516 | mask |= POLLOUT; | 506 | mask |= POLLOUT; |
| 517 | break; | 507 | break; |
| 518 | case SS_READY: | 508 | case SS_READY: |
| 519 | case SS_CONNECTED: | 509 | case SS_CONNECTED: |
| 520 | if (!tipc_sk_port(sk)->congested) | 510 | if (!tsk->port.congested) |
| 521 | mask |= POLLOUT; | 511 | mask |= POLLOUT; |
| 522 | /* fall thru' */ | 512 | /* fall thru' */ |
| 523 | case SS_CONNECTING: | 513 | case SS_CONNECTING: |
| @@ -567,7 +557,7 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | |||
| 567 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) | 557 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) |
| 568 | { | 558 | { |
| 569 | struct sock *sk = sock->sk; | 559 | struct sock *sk = sock->sk; |
| 570 | struct tipc_port *tport = tipc_sk_port(sk); | 560 | struct tipc_sock *tsk = tipc_sk(sk); |
| 571 | DEFINE_WAIT(wait); | 561 | DEFINE_WAIT(wait); |
| 572 | int done; | 562 | int done; |
| 573 | 563 | ||
| @@ -583,14 +573,15 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) | |||
| 583 | return sock_intr_errno(*timeo_p); | 573 | return sock_intr_errno(*timeo_p); |
| 584 | 574 | ||
| 585 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | 575 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 586 | done = sk_wait_event(sk, timeo_p, !tport->congested); | 576 | done = sk_wait_event(sk, timeo_p, !tsk->port.congested); |
| 587 | finish_wait(sk_sleep(sk), &wait); | 577 | finish_wait(sk_sleep(sk), &wait); |
| 588 | } while (!done); | 578 | } while (!done); |
| 589 | return 0; | 579 | return 0; |
| 590 | } | 580 | } |
| 591 | 581 | ||
| 582 | |||
| 592 | /** | 583 | /** |
| 593 | * send_msg - send message in connectionless manner | 584 | * tipc_sendmsg - send message in connectionless manner |
| 594 | * @iocb: if NULL, indicates that socket lock is already held | 585 | * @iocb: if NULL, indicates that socket lock is already held |
| 595 | * @sock: socket structure | 586 | * @sock: socket structure |
| 596 | * @m: message to send | 587 | * @m: message to send |
| @@ -603,11 +594,12 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) | |||
| 603 | * | 594 | * |
| 604 | * Returns the number of bytes sent on success, or errno otherwise | 595 | * Returns the number of bytes sent on success, or errno otherwise |
| 605 | */ | 596 | */ |
| 606 | static int send_msg(struct kiocb *iocb, struct socket *sock, | 597 | static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, |
| 607 | struct msghdr *m, size_t total_len) | 598 | struct msghdr *m, size_t total_len) |
| 608 | { | 599 | { |
| 609 | struct sock *sk = sock->sk; | 600 | struct sock *sk = sock->sk; |
| 610 | struct tipc_port *tport = tipc_sk_port(sk); | 601 | struct tipc_sock *tsk = tipc_sk(sk); |
| 602 | struct tipc_port *port = &tsk->port; | ||
| 611 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); | 603 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
| 612 | int needs_conn; | 604 | int needs_conn; |
| 613 | long timeo; | 605 | long timeo; |
| @@ -634,13 +626,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
| 634 | res = -EISCONN; | 626 | res = -EISCONN; |
| 635 | goto exit; | 627 | goto exit; |
| 636 | } | 628 | } |
| 637 | if (tport->published) { | 629 | if (tsk->port.published) { |
| 638 | res = -EOPNOTSUPP; | 630 | res = -EOPNOTSUPP; |
| 639 | goto exit; | 631 | goto exit; |
| 640 | } | 632 | } |
| 641 | if (dest->addrtype == TIPC_ADDR_NAME) { | 633 | if (dest->addrtype == TIPC_ADDR_NAME) { |
| 642 | tport->conn_type = dest->addr.name.name.type; | 634 | tsk->port.conn_type = dest->addr.name.name.type; |
| 643 | tport->conn_instance = dest->addr.name.name.instance; | 635 | tsk->port.conn_instance = dest->addr.name.name.instance; |
| 644 | } | 636 | } |
| 645 | 637 | ||
| 646 | /* Abort any pending connection attempts (very unlikely) */ | 638 | /* Abort any pending connection attempts (very unlikely) */ |
| @@ -653,13 +645,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
| 653 | res = dest_name_check(dest, m); | 645 | res = dest_name_check(dest, m); |
| 654 | if (res) | 646 | if (res) |
| 655 | break; | 647 | break; |
| 656 | res = tipc_send2name(tport->ref, | 648 | res = tipc_send2name(port, |
| 657 | &dest->addr.name.name, | 649 | &dest->addr.name.name, |
| 658 | dest->addr.name.domain, | 650 | dest->addr.name.domain, |
| 659 | m->msg_iov, | 651 | m->msg_iov, |
| 660 | total_len); | 652 | total_len); |
| 661 | } else if (dest->addrtype == TIPC_ADDR_ID) { | 653 | } else if (dest->addrtype == TIPC_ADDR_ID) { |
| 662 | res = tipc_send2port(tport->ref, | 654 | res = tipc_send2port(port, |
| 663 | &dest->addr.id, | 655 | &dest->addr.id, |
| 664 | m->msg_iov, | 656 | m->msg_iov, |
| 665 | total_len); | 657 | total_len); |
| @@ -671,10 +663,10 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
| 671 | res = dest_name_check(dest, m); | 663 | res = dest_name_check(dest, m); |
| 672 | if (res) | 664 | if (res) |
| 673 | break; | 665 | break; |
| 674 | res = tipc_multicast(tport->ref, | 666 | res = tipc_port_mcast_xmit(port, |
| 675 | &dest->addr.nameseq, | 667 | &dest->addr.nameseq, |
| 676 | m->msg_iov, | 668 | m->msg_iov, |
| 677 | total_len); | 669 | total_len); |
| 678 | } | 670 | } |
| 679 | if (likely(res != -ELINKCONG)) { | 671 | if (likely(res != -ELINKCONG)) { |
| 680 | if (needs_conn && (res >= 0)) | 672 | if (needs_conn && (res >= 0)) |
| @@ -695,7 +687,8 @@ exit: | |||
| 695 | static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) | 687 | static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) |
| 696 | { | 688 | { |
| 697 | struct sock *sk = sock->sk; | 689 | struct sock *sk = sock->sk; |
| 698 | struct tipc_port *tport = tipc_sk_port(sk); | 690 | struct tipc_sock *tsk = tipc_sk(sk); |
| 691 | struct tipc_port *port = &tsk->port; | ||
| 699 | DEFINE_WAIT(wait); | 692 | DEFINE_WAIT(wait); |
| 700 | int done; | 693 | int done; |
| 701 | 694 | ||
| @@ -714,14 +707,14 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) | |||
| 714 | 707 | ||
| 715 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | 708 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 716 | done = sk_wait_event(sk, timeo_p, | 709 | done = sk_wait_event(sk, timeo_p, |
| 717 | (!tport->congested || !tport->connected)); | 710 | (!port->congested || !port->connected)); |
| 718 | finish_wait(sk_sleep(sk), &wait); | 711 | finish_wait(sk_sleep(sk), &wait); |
| 719 | } while (!done); | 712 | } while (!done); |
| 720 | return 0; | 713 | return 0; |
| 721 | } | 714 | } |
| 722 | 715 | ||
| 723 | /** | 716 | /** |
| 724 | * send_packet - send a connection-oriented message | 717 | * tipc_send_packet - send a connection-oriented message |
| 725 | * @iocb: if NULL, indicates that socket lock is already held | 718 | * @iocb: if NULL, indicates that socket lock is already held |
| 726 | * @sock: socket structure | 719 | * @sock: socket structure |
| 727 | * @m: message to send | 720 | * @m: message to send |
| @@ -731,18 +724,18 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) | |||
| 731 | * | 724 | * |
| 732 | * Returns the number of bytes sent on success, or errno otherwise | 725 | * Returns the number of bytes sent on success, or errno otherwise |
| 733 | */ | 726 | */ |
| 734 | static int send_packet(struct kiocb *iocb, struct socket *sock, | 727 | static int tipc_send_packet(struct kiocb *iocb, struct socket *sock, |
| 735 | struct msghdr *m, size_t total_len) | 728 | struct msghdr *m, size_t total_len) |
| 736 | { | 729 | { |
| 737 | struct sock *sk = sock->sk; | 730 | struct sock *sk = sock->sk; |
| 738 | struct tipc_port *tport = tipc_sk_port(sk); | 731 | struct tipc_sock *tsk = tipc_sk(sk); |
| 739 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); | 732 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
| 740 | int res = -EINVAL; | 733 | int res = -EINVAL; |
| 741 | long timeo; | 734 | long timeo; |
| 742 | 735 | ||
| 743 | /* Handle implied connection establishment */ | 736 | /* Handle implied connection establishment */ |
| 744 | if (unlikely(dest)) | 737 | if (unlikely(dest)) |
| 745 | return send_msg(iocb, sock, m, total_len); | 738 | return tipc_sendmsg(iocb, sock, m, total_len); |
| 746 | 739 | ||
| 747 | if (total_len > TIPC_MAX_USER_MSG_SIZE) | 740 | if (total_len > TIPC_MAX_USER_MSG_SIZE) |
| 748 | return -EMSGSIZE; | 741 | return -EMSGSIZE; |
| @@ -760,7 +753,7 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
| 760 | 753 | ||
| 761 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); | 754 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
| 762 | do { | 755 | do { |
| 763 | res = tipc_send(tport->ref, m->msg_iov, total_len); | 756 | res = tipc_send(&tsk->port, m->msg_iov, total_len); |
| 764 | if (likely(res != -ELINKCONG)) | 757 | if (likely(res != -ELINKCONG)) |
| 765 | break; | 758 | break; |
| 766 | res = tipc_wait_for_sndpkt(sock, &timeo); | 759 | res = tipc_wait_for_sndpkt(sock, &timeo); |
| @@ -774,7 +767,7 @@ exit: | |||
| 774 | } | 767 | } |
| 775 | 768 | ||
| 776 | /** | 769 | /** |
| 777 | * send_stream - send stream-oriented data | 770 | * tipc_send_stream - send stream-oriented data |
| 778 | * @iocb: (unused) | 771 | * @iocb: (unused) |
| 779 | * @sock: socket structure | 772 | * @sock: socket structure |
| 780 | * @m: data to send | 773 | * @m: data to send |
| @@ -785,11 +778,11 @@ exit: | |||
| 785 | * Returns the number of bytes sent on success (or partial success), | 778 | * Returns the number of bytes sent on success (or partial success), |
| 786 | * or errno if no data sent | 779 | * or errno if no data sent |
| 787 | */ | 780 | */ |
| 788 | static int send_stream(struct kiocb *iocb, struct socket *sock, | 781 | static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, |
| 789 | struct msghdr *m, size_t total_len) | 782 | struct msghdr *m, size_t total_len) |
| 790 | { | 783 | { |
| 791 | struct sock *sk = sock->sk; | 784 | struct sock *sk = sock->sk; |
| 792 | struct tipc_port *tport = tipc_sk_port(sk); | 785 | struct tipc_sock *tsk = tipc_sk(sk); |
| 793 | struct msghdr my_msg; | 786 | struct msghdr my_msg; |
| 794 | struct iovec my_iov; | 787 | struct iovec my_iov; |
| 795 | struct iovec *curr_iov; | 788 | struct iovec *curr_iov; |
| @@ -806,7 +799,7 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
| 806 | /* Handle special cases where there is no connection */ | 799 | /* Handle special cases where there is no connection */ |
| 807 | if (unlikely(sock->state != SS_CONNECTED)) { | 800 | if (unlikely(sock->state != SS_CONNECTED)) { |
| 808 | if (sock->state == SS_UNCONNECTED) | 801 | if (sock->state == SS_UNCONNECTED) |
| 809 | res = send_packet(NULL, sock, m, total_len); | 802 | res = tipc_send_packet(NULL, sock, m, total_len); |
| 810 | else | 803 | else |
| 811 | res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; | 804 | res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; |
| 812 | goto exit; | 805 | goto exit; |
| @@ -837,21 +830,22 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
| 837 | my_msg.msg_name = NULL; | 830 | my_msg.msg_name = NULL; |
| 838 | bytes_sent = 0; | 831 | bytes_sent = 0; |
| 839 | 832 | ||
| 840 | hdr_size = msg_hdr_sz(&tport->phdr); | 833 | hdr_size = msg_hdr_sz(&tsk->port.phdr); |
| 841 | 834 | ||
| 842 | while (curr_iovlen--) { | 835 | while (curr_iovlen--) { |
| 843 | curr_start = curr_iov->iov_base; | 836 | curr_start = curr_iov->iov_base; |
| 844 | curr_left = curr_iov->iov_len; | 837 | curr_left = curr_iov->iov_len; |
| 845 | 838 | ||
| 846 | while (curr_left) { | 839 | while (curr_left) { |
| 847 | bytes_to_send = tport->max_pkt - hdr_size; | 840 | bytes_to_send = tsk->port.max_pkt - hdr_size; |
| 848 | if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) | 841 | if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) |
| 849 | bytes_to_send = TIPC_MAX_USER_MSG_SIZE; | 842 | bytes_to_send = TIPC_MAX_USER_MSG_SIZE; |
| 850 | if (curr_left < bytes_to_send) | 843 | if (curr_left < bytes_to_send) |
| 851 | bytes_to_send = curr_left; | 844 | bytes_to_send = curr_left; |
| 852 | my_iov.iov_base = curr_start; | 845 | my_iov.iov_base = curr_start; |
| 853 | my_iov.iov_len = bytes_to_send; | 846 | my_iov.iov_len = bytes_to_send; |
| 854 | res = send_packet(NULL, sock, &my_msg, bytes_to_send); | 847 | res = tipc_send_packet(NULL, sock, &my_msg, |
| 848 | bytes_to_send); | ||
| 855 | if (res < 0) { | 849 | if (res < 0) { |
| 856 | if (bytes_sent) | 850 | if (bytes_sent) |
| 857 | res = bytes_sent; | 851 | res = bytes_sent; |
| @@ -872,27 +866,25 @@ exit: | |||
| 872 | 866 | ||
| 873 | /** | 867 | /** |
| 874 | * auto_connect - complete connection setup to a remote port | 868 | * auto_connect - complete connection setup to a remote port |
| 875 | * @sock: socket structure | 869 | * @tsk: tipc socket structure |
| 876 | * @msg: peer's response message | 870 | * @msg: peer's response message |
| 877 | * | 871 | * |
| 878 | * Returns 0 on success, errno otherwise | 872 | * Returns 0 on success, errno otherwise |
| 879 | */ | 873 | */ |
| 880 | static int auto_connect(struct socket *sock, struct tipc_msg *msg) | 874 | static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg) |
| 881 | { | 875 | { |
| 882 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 876 | struct tipc_port *port = &tsk->port; |
| 883 | struct tipc_port *p_ptr; | 877 | struct socket *sock = tsk->sk.sk_socket; |
| 878 | struct tipc_portid peer; | ||
| 884 | 879 | ||
| 885 | tsock->peer_name.ref = msg_origport(msg); | 880 | peer.ref = msg_origport(msg); |
| 886 | tsock->peer_name.node = msg_orignode(msg); | 881 | peer.node = msg_orignode(msg); |
| 887 | p_ptr = tipc_port_deref(tsock->p->ref); | ||
| 888 | if (!p_ptr) | ||
| 889 | return -EINVAL; | ||
| 890 | 882 | ||
| 891 | __tipc_connect(tsock->p->ref, p_ptr, &tsock->peer_name); | 883 | __tipc_port_connect(port->ref, port, &peer); |
| 892 | 884 | ||
| 893 | if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) | 885 | if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) |
| 894 | return -EINVAL; | 886 | return -EINVAL; |
| 895 | msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg)); | 887 | msg_set_importance(&port->phdr, (u32)msg_importance(msg)); |
| 896 | sock->state = SS_CONNECTED; | 888 | sock->state = SS_CONNECTED; |
| 897 | return 0; | 889 | return 0; |
| 898 | } | 890 | } |
| @@ -999,7 +991,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo) | |||
| 999 | 991 | ||
| 1000 | for (;;) { | 992 | for (;;) { |
| 1001 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | 993 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 1002 | if (skb_queue_empty(&sk->sk_receive_queue)) { | 994 | if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { |
| 1003 | if (sock->state == SS_DISCONNECTING) { | 995 | if (sock->state == SS_DISCONNECTING) { |
| 1004 | err = -ENOTCONN; | 996 | err = -ENOTCONN; |
| 1005 | break; | 997 | break; |
| @@ -1023,7 +1015,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo) | |||
| 1023 | } | 1015 | } |
| 1024 | 1016 | ||
| 1025 | /** | 1017 | /** |
| 1026 | * recv_msg - receive packet-oriented message | 1018 | * tipc_recvmsg - receive packet-oriented message |
| 1027 | * @iocb: (unused) | 1019 | * @iocb: (unused) |
| 1028 | * @m: descriptor for message info | 1020 | * @m: descriptor for message info |
| 1029 | * @buf_len: total size of user buffer area | 1021 | * @buf_len: total size of user buffer area |
| @@ -1034,11 +1026,12 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo) | |||
| 1034 | * | 1026 | * |
| 1035 | * Returns size of returned message data, errno otherwise | 1027 | * Returns size of returned message data, errno otherwise |
| 1036 | */ | 1028 | */ |
| 1037 | static int recv_msg(struct kiocb *iocb, struct socket *sock, | 1029 | static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 1038 | struct msghdr *m, size_t buf_len, int flags) | 1030 | struct msghdr *m, size_t buf_len, int flags) |
| 1039 | { | 1031 | { |
| 1040 | struct sock *sk = sock->sk; | 1032 | struct sock *sk = sock->sk; |
| 1041 | struct tipc_port *tport = tipc_sk_port(sk); | 1033 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1034 | struct tipc_port *port = &tsk->port; | ||
| 1042 | struct sk_buff *buf; | 1035 | struct sk_buff *buf; |
| 1043 | struct tipc_msg *msg; | 1036 | struct tipc_msg *msg; |
| 1044 | long timeo; | 1037 | long timeo; |
| @@ -1081,7 +1074,7 @@ restart: | |||
| 1081 | set_orig_addr(m, msg); | 1074 | set_orig_addr(m, msg); |
| 1082 | 1075 | ||
| 1083 | /* Capture ancillary data (optional) */ | 1076 | /* Capture ancillary data (optional) */ |
| 1084 | res = anc_data_recv(m, msg, tport); | 1077 | res = anc_data_recv(m, msg, port); |
| 1085 | if (res) | 1078 | if (res) |
| 1086 | goto exit; | 1079 | goto exit; |
| 1087 | 1080 | ||
| @@ -1107,8 +1100,8 @@ restart: | |||
| 1107 | /* Consume received message (optional) */ | 1100 | /* Consume received message (optional) */ |
| 1108 | if (likely(!(flags & MSG_PEEK))) { | 1101 | if (likely(!(flags & MSG_PEEK))) { |
| 1109 | if ((sock->state != SS_READY) && | 1102 | if ((sock->state != SS_READY) && |
| 1110 | (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 1103 | (++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
| 1111 | tipc_acknowledge(tport->ref, tport->conn_unacked); | 1104 | tipc_acknowledge(port->ref, port->conn_unacked); |
| 1112 | advance_rx_queue(sk); | 1105 | advance_rx_queue(sk); |
| 1113 | } | 1106 | } |
| 1114 | exit: | 1107 | exit: |
| @@ -1117,7 +1110,7 @@ exit: | |||
| 1117 | } | 1110 | } |
| 1118 | 1111 | ||
| 1119 | /** | 1112 | /** |
| 1120 | * recv_stream - receive stream-oriented data | 1113 | * tipc_recv_stream - receive stream-oriented data |
| 1121 | * @iocb: (unused) | 1114 | * @iocb: (unused) |
| 1122 | * @m: descriptor for message info | 1115 | * @m: descriptor for message info |
| 1123 | * @buf_len: total size of user buffer area | 1116 | * @buf_len: total size of user buffer area |
| @@ -1128,11 +1121,12 @@ exit: | |||
| 1128 | * | 1121 | * |
| 1129 | * Returns size of returned message data, errno otherwise | 1122 | * Returns size of returned message data, errno otherwise |
| 1130 | */ | 1123 | */ |
| 1131 | static int recv_stream(struct kiocb *iocb, struct socket *sock, | 1124 | static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock, |
| 1132 | struct msghdr *m, size_t buf_len, int flags) | 1125 | struct msghdr *m, size_t buf_len, int flags) |
| 1133 | { | 1126 | { |
| 1134 | struct sock *sk = sock->sk; | 1127 | struct sock *sk = sock->sk; |
| 1135 | struct tipc_port *tport = tipc_sk_port(sk); | 1128 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1129 | struct tipc_port *port = &tsk->port; | ||
| 1136 | struct sk_buff *buf; | 1130 | struct sk_buff *buf; |
| 1137 | struct tipc_msg *msg; | 1131 | struct tipc_msg *msg; |
| 1138 | long timeo; | 1132 | long timeo; |
| @@ -1177,7 +1171,7 @@ restart: | |||
| 1177 | /* Optionally capture sender's address & ancillary data of first msg */ | 1171 | /* Optionally capture sender's address & ancillary data of first msg */ |
| 1178 | if (sz_copied == 0) { | 1172 | if (sz_copied == 0) { |
| 1179 | set_orig_addr(m, msg); | 1173 | set_orig_addr(m, msg); |
| 1180 | res = anc_data_recv(m, msg, tport); | 1174 | res = anc_data_recv(m, msg, port); |
| 1181 | if (res) | 1175 | if (res) |
| 1182 | goto exit; | 1176 | goto exit; |
| 1183 | } | 1177 | } |
| @@ -1215,8 +1209,8 @@ restart: | |||
| 1215 | 1209 | ||
| 1216 | /* Consume received message (optional) */ | 1210 | /* Consume received message (optional) */ |
| 1217 | if (likely(!(flags & MSG_PEEK))) { | 1211 | if (likely(!(flags & MSG_PEEK))) { |
| 1218 | if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 1212 | if (unlikely(++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
| 1219 | tipc_acknowledge(tport->ref, tport->conn_unacked); | 1213 | tipc_acknowledge(port->ref, port->conn_unacked); |
| 1220 | advance_rx_queue(sk); | 1214 | advance_rx_queue(sk); |
| 1221 | } | 1215 | } |
| 1222 | 1216 | ||
| @@ -1268,17 +1262,19 @@ static void tipc_data_ready(struct sock *sk, int len) | |||
| 1268 | 1262 | ||
| 1269 | /** | 1263 | /** |
| 1270 | * filter_connect - Handle all incoming messages for a connection-based socket | 1264 | * filter_connect - Handle all incoming messages for a connection-based socket |
| 1271 | * @tsock: TIPC socket | 1265 | * @tsk: TIPC socket |
| 1272 | * @msg: message | 1266 | * @msg: message |
| 1273 | * | 1267 | * |
| 1274 | * Returns TIPC error status code and socket error status code | 1268 | * Returns TIPC error status code and socket error status code |
| 1275 | * once it encounters some errors | 1269 | * once it encounters some errors |
| 1276 | */ | 1270 | */ |
| 1277 | static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) | 1271 | static u32 filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) |
| 1278 | { | 1272 | { |
| 1279 | struct socket *sock = tsock->sk.sk_socket; | 1273 | struct sock *sk = &tsk->sk; |
| 1274 | struct tipc_port *port = &tsk->port; | ||
| 1275 | struct socket *sock = sk->sk_socket; | ||
| 1280 | struct tipc_msg *msg = buf_msg(*buf); | 1276 | struct tipc_msg *msg = buf_msg(*buf); |
| 1281 | struct sock *sk = &tsock->sk; | 1277 | |
| 1282 | u32 retval = TIPC_ERR_NO_PORT; | 1278 | u32 retval = TIPC_ERR_NO_PORT; |
| 1283 | int res; | 1279 | int res; |
| 1284 | 1280 | ||
| @@ -1288,10 +1284,10 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) | |||
| 1288 | switch ((int)sock->state) { | 1284 | switch ((int)sock->state) { |
| 1289 | case SS_CONNECTED: | 1285 | case SS_CONNECTED: |
| 1290 | /* Accept only connection-based messages sent by peer */ | 1286 | /* Accept only connection-based messages sent by peer */ |
| 1291 | if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) { | 1287 | if (msg_connected(msg) && tipc_port_peer_msg(port, msg)) { |
| 1292 | if (unlikely(msg_errcode(msg))) { | 1288 | if (unlikely(msg_errcode(msg))) { |
| 1293 | sock->state = SS_DISCONNECTING; | 1289 | sock->state = SS_DISCONNECTING; |
| 1294 | __tipc_disconnect(tsock->p); | 1290 | __tipc_port_disconnect(port); |
| 1295 | } | 1291 | } |
| 1296 | retval = TIPC_OK; | 1292 | retval = TIPC_OK; |
| 1297 | } | 1293 | } |
| @@ -1308,7 +1304,7 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) | |||
| 1308 | if (unlikely(!msg_connected(msg))) | 1304 | if (unlikely(!msg_connected(msg))) |
| 1309 | break; | 1305 | break; |
| 1310 | 1306 | ||
| 1311 | res = auto_connect(sock, msg); | 1307 | res = auto_connect(tsk, msg); |
| 1312 | if (res) { | 1308 | if (res) { |
| 1313 | sock->state = SS_DISCONNECTING; | 1309 | sock->state = SS_DISCONNECTING; |
| 1314 | sk->sk_err = -res; | 1310 | sk->sk_err = -res; |
| @@ -1387,6 +1383,7 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) | |||
| 1387 | static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | 1383 | static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) |
| 1388 | { | 1384 | { |
| 1389 | struct socket *sock = sk->sk_socket; | 1385 | struct socket *sock = sk->sk_socket; |
| 1386 | struct tipc_sock *tsk = tipc_sk(sk); | ||
| 1390 | struct tipc_msg *msg = buf_msg(buf); | 1387 | struct tipc_msg *msg = buf_msg(buf); |
| 1391 | unsigned int limit = rcvbuf_limit(sk, buf); | 1388 | unsigned int limit = rcvbuf_limit(sk, buf); |
| 1392 | u32 res = TIPC_OK; | 1389 | u32 res = TIPC_OK; |
| @@ -1399,7 +1396,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | |||
| 1399 | if (msg_connected(msg)) | 1396 | if (msg_connected(msg)) |
| 1400 | return TIPC_ERR_NO_PORT; | 1397 | return TIPC_ERR_NO_PORT; |
| 1401 | } else { | 1398 | } else { |
| 1402 | res = filter_connect(tipc_sk(sk), &buf); | 1399 | res = filter_connect(tsk, &buf); |
| 1403 | if (res != TIPC_OK || buf == NULL) | 1400 | if (res != TIPC_OK || buf == NULL) |
| 1404 | return res; | 1401 | return res; |
| 1405 | } | 1402 | } |
| @@ -1437,17 +1434,16 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf) | |||
| 1437 | } | 1434 | } |
| 1438 | 1435 | ||
| 1439 | /** | 1436 | /** |
| 1440 | * dispatch - handle incoming message | 1437 | * tipc_sk_rcv - handle incoming message |
| 1441 | * @tport: TIPC port that received message | 1438 | * @sk: socket receiving message |
| 1442 | * @buf: message | 1439 | * @buf: message |
| 1443 | * | 1440 | * |
| 1444 | * Called with port lock already taken. | 1441 | * Called with port lock already taken. |
| 1445 | * | 1442 | * |
| 1446 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) | 1443 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) |
| 1447 | */ | 1444 | */ |
| 1448 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | 1445 | u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf) |
| 1449 | { | 1446 | { |
| 1450 | struct sock *sk = tport->sk; | ||
| 1451 | u32 res; | 1447 | u32 res; |
| 1452 | 1448 | ||
| 1453 | /* | 1449 | /* |
| @@ -1470,19 +1466,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
| 1470 | return res; | 1466 | return res; |
| 1471 | } | 1467 | } |
| 1472 | 1468 | ||
| 1473 | /** | ||
| 1474 | * wakeupdispatch - wake up port after congestion | ||
| 1475 | * @tport: port to wakeup | ||
| 1476 | * | ||
| 1477 | * Called with port lock already taken. | ||
| 1478 | */ | ||
| 1479 | static void wakeupdispatch(struct tipc_port *tport) | ||
| 1480 | { | ||
| 1481 | struct sock *sk = tport->sk; | ||
| 1482 | |||
| 1483 | sk->sk_write_space(sk); | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) | 1469 | static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) |
| 1487 | { | 1470 | { |
| 1488 | struct sock *sk = sock->sk; | 1471 | struct sock *sk = sock->sk; |
| @@ -1506,7 +1489,7 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) | |||
| 1506 | } | 1489 | } |
| 1507 | 1490 | ||
| 1508 | /** | 1491 | /** |
| 1509 | * connect - establish a connection to another TIPC port | 1492 | * tipc_connect - establish a connection to another TIPC port |
| 1510 | * @sock: socket structure | 1493 | * @sock: socket structure |
| 1511 | * @dest: socket address for destination port | 1494 | * @dest: socket address for destination port |
| 1512 | * @destlen: size of socket address data structure | 1495 | * @destlen: size of socket address data structure |
| @@ -1514,8 +1497,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) | |||
| 1514 | * | 1497 | * |
| 1515 | * Returns 0 on success, errno otherwise | 1498 | * Returns 0 on success, errno otherwise |
| 1516 | */ | 1499 | */ |
| 1517 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | 1500 | static int tipc_connect(struct socket *sock, struct sockaddr *dest, |
| 1518 | int flags) | 1501 | int destlen, int flags) |
| 1519 | { | 1502 | { |
| 1520 | struct sock *sk = sock->sk; | 1503 | struct sock *sk = sock->sk; |
| 1521 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; | 1504 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; |
| @@ -1556,7 +1539,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
| 1556 | if (!timeout) | 1539 | if (!timeout) |
| 1557 | m.msg_flags = MSG_DONTWAIT; | 1540 | m.msg_flags = MSG_DONTWAIT; |
| 1558 | 1541 | ||
| 1559 | res = send_msg(NULL, sock, &m, 0); | 1542 | res = tipc_sendmsg(NULL, sock, &m, 0); |
| 1560 | if ((res < 0) && (res != -EWOULDBLOCK)) | 1543 | if ((res < 0) && (res != -EWOULDBLOCK)) |
| 1561 | goto exit; | 1544 | goto exit; |
| 1562 | 1545 | ||
| @@ -1587,13 +1570,13 @@ exit: | |||
| 1587 | } | 1570 | } |
| 1588 | 1571 | ||
| 1589 | /** | 1572 | /** |
| 1590 | * listen - allow socket to listen for incoming connections | 1573 | * tipc_listen - allow socket to listen for incoming connections |
| 1591 | * @sock: socket structure | 1574 | * @sock: socket structure |
| 1592 | * @len: (unused) | 1575 | * @len: (unused) |
| 1593 | * | 1576 | * |
| 1594 | * Returns 0 on success, errno otherwise | 1577 | * Returns 0 on success, errno otherwise |
| 1595 | */ | 1578 | */ |
| 1596 | static int listen(struct socket *sock, int len) | 1579 | static int tipc_listen(struct socket *sock, int len) |
| 1597 | { | 1580 | { |
| 1598 | struct sock *sk = sock->sk; | 1581 | struct sock *sk = sock->sk; |
| 1599 | int res; | 1582 | int res; |
| @@ -1625,7 +1608,7 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) | |||
| 1625 | for (;;) { | 1608 | for (;;) { |
| 1626 | prepare_to_wait_exclusive(sk_sleep(sk), &wait, | 1609 | prepare_to_wait_exclusive(sk_sleep(sk), &wait, |
| 1627 | TASK_INTERRUPTIBLE); | 1610 | TASK_INTERRUPTIBLE); |
| 1628 | if (skb_queue_empty(&sk->sk_receive_queue)) { | 1611 | if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { |
| 1629 | release_sock(sk); | 1612 | release_sock(sk); |
| 1630 | timeo = schedule_timeout(timeo); | 1613 | timeo = schedule_timeout(timeo); |
| 1631 | lock_sock(sk); | 1614 | lock_sock(sk); |
| @@ -1648,20 +1631,20 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) | |||
| 1648 | } | 1631 | } |
| 1649 | 1632 | ||
| 1650 | /** | 1633 | /** |
| 1651 | * accept - wait for connection request | 1634 | * tipc_accept - wait for connection request |
| 1652 | * @sock: listening socket | 1635 | * @sock: listening socket |
| 1653 | * @newsock: new socket that is to be connected | 1636 | * @newsock: new socket that is to be connected |
| 1654 | * @flags: file-related flags associated with socket | 1637 | * @flags: file-related flags associated with socket |
| 1655 | * | 1638 | * |
| 1656 | * Returns 0 on success, errno otherwise | 1639 | * Returns 0 on success, errno otherwise |
| 1657 | */ | 1640 | */ |
| 1658 | static int accept(struct socket *sock, struct socket *new_sock, int flags) | 1641 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) |
| 1659 | { | 1642 | { |
| 1660 | struct sock *new_sk, *sk = sock->sk; | 1643 | struct sock *new_sk, *sk = sock->sk; |
| 1661 | struct sk_buff *buf; | 1644 | struct sk_buff *buf; |
| 1662 | struct tipc_sock *new_tsock; | 1645 | struct tipc_port *new_port; |
| 1663 | struct tipc_port *new_tport; | ||
| 1664 | struct tipc_msg *msg; | 1646 | struct tipc_msg *msg; |
| 1647 | struct tipc_portid peer; | ||
| 1665 | u32 new_ref; | 1648 | u32 new_ref; |
| 1666 | long timeo; | 1649 | long timeo; |
| 1667 | int res; | 1650 | int res; |
| @@ -1672,7 +1655,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
| 1672 | res = -EINVAL; | 1655 | res = -EINVAL; |
| 1673 | goto exit; | 1656 | goto exit; |
| 1674 | } | 1657 | } |
| 1675 | |||
| 1676 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); | 1658 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 1677 | res = tipc_wait_for_accept(sock, timeo); | 1659 | res = tipc_wait_for_accept(sock, timeo); |
| 1678 | if (res) | 1660 | if (res) |
| @@ -1685,9 +1667,8 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
| 1685 | goto exit; | 1667 | goto exit; |
| 1686 | 1668 | ||
| 1687 | new_sk = new_sock->sk; | 1669 | new_sk = new_sock->sk; |
| 1688 | new_tsock = tipc_sk(new_sk); | 1670 | new_port = &tipc_sk(new_sk)->port; |
| 1689 | new_tport = new_tsock->p; | 1671 | new_ref = new_port->ref; |
| 1690 | new_ref = new_tport->ref; | ||
| 1691 | msg = buf_msg(buf); | 1672 | msg = buf_msg(buf); |
| 1692 | 1673 | ||
| 1693 | /* we lock on new_sk; but lockdep sees the lock on sk */ | 1674 | /* we lock on new_sk; but lockdep sees the lock on sk */ |
| @@ -1700,15 +1681,15 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
| 1700 | reject_rx_queue(new_sk); | 1681 | reject_rx_queue(new_sk); |
| 1701 | 1682 | ||
| 1702 | /* Connect new socket to it's peer */ | 1683 | /* Connect new socket to it's peer */ |
| 1703 | new_tsock->peer_name.ref = msg_origport(msg); | 1684 | peer.ref = msg_origport(msg); |
| 1704 | new_tsock->peer_name.node = msg_orignode(msg); | 1685 | peer.node = msg_orignode(msg); |
| 1705 | tipc_connect(new_ref, &new_tsock->peer_name); | 1686 | tipc_port_connect(new_ref, &peer); |
| 1706 | new_sock->state = SS_CONNECTED; | 1687 | new_sock->state = SS_CONNECTED; |
| 1707 | 1688 | ||
| 1708 | tipc_set_portimportance(new_ref, msg_importance(msg)); | 1689 | tipc_port_set_importance(new_port, msg_importance(msg)); |
| 1709 | if (msg_named(msg)) { | 1690 | if (msg_named(msg)) { |
| 1710 | new_tport->conn_type = msg_nametype(msg); | 1691 | new_port->conn_type = msg_nametype(msg); |
| 1711 | new_tport->conn_instance = msg_nameinst(msg); | 1692 | new_port->conn_instance = msg_nameinst(msg); |
| 1712 | } | 1693 | } |
| 1713 | 1694 | ||
| 1714 | /* | 1695 | /* |
| @@ -1719,21 +1700,20 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
| 1719 | struct msghdr m = {NULL,}; | 1700 | struct msghdr m = {NULL,}; |
| 1720 | 1701 | ||
| 1721 | advance_rx_queue(sk); | 1702 | advance_rx_queue(sk); |
| 1722 | send_packet(NULL, new_sock, &m, 0); | 1703 | tipc_send_packet(NULL, new_sock, &m, 0); |
| 1723 | } else { | 1704 | } else { |
| 1724 | __skb_dequeue(&sk->sk_receive_queue); | 1705 | __skb_dequeue(&sk->sk_receive_queue); |
| 1725 | __skb_queue_head(&new_sk->sk_receive_queue, buf); | 1706 | __skb_queue_head(&new_sk->sk_receive_queue, buf); |
| 1726 | skb_set_owner_r(buf, new_sk); | 1707 | skb_set_owner_r(buf, new_sk); |
| 1727 | } | 1708 | } |
| 1728 | release_sock(new_sk); | 1709 | release_sock(new_sk); |
| 1729 | |||
| 1730 | exit: | 1710 | exit: |
| 1731 | release_sock(sk); | 1711 | release_sock(sk); |
| 1732 | return res; | 1712 | return res; |
| 1733 | } | 1713 | } |
| 1734 | 1714 | ||
| 1735 | /** | 1715 | /** |
| 1736 | * shutdown - shutdown socket connection | 1716 | * tipc_shutdown - shutdown socket connection |
| 1737 | * @sock: socket structure | 1717 | * @sock: socket structure |
| 1738 | * @how: direction to close (must be SHUT_RDWR) | 1718 | * @how: direction to close (must be SHUT_RDWR) |
| 1739 | * | 1719 | * |
| @@ -1741,10 +1721,11 @@ exit: | |||
| 1741 | * | 1721 | * |
| 1742 | * Returns 0 on success, errno otherwise | 1722 | * Returns 0 on success, errno otherwise |
| 1743 | */ | 1723 | */ |
| 1744 | static int shutdown(struct socket *sock, int how) | 1724 | static int tipc_shutdown(struct socket *sock, int how) |
| 1745 | { | 1725 | { |
| 1746 | struct sock *sk = sock->sk; | 1726 | struct sock *sk = sock->sk; |
| 1747 | struct tipc_port *tport = tipc_sk_port(sk); | 1727 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1728 | struct tipc_port *port = &tsk->port; | ||
| 1748 | struct sk_buff *buf; | 1729 | struct sk_buff *buf; |
| 1749 | int res; | 1730 | int res; |
| 1750 | 1731 | ||
| @@ -1765,10 +1746,10 @@ restart: | |||
| 1765 | kfree_skb(buf); | 1746 | kfree_skb(buf); |
| 1766 | goto restart; | 1747 | goto restart; |
| 1767 | } | 1748 | } |
| 1768 | tipc_disconnect(tport->ref); | 1749 | tipc_port_disconnect(port->ref); |
| 1769 | tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); | 1750 | tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); |
| 1770 | } else { | 1751 | } else { |
| 1771 | tipc_shutdown(tport->ref); | 1752 | tipc_port_shutdown(port->ref); |
| 1772 | } | 1753 | } |
| 1773 | 1754 | ||
| 1774 | sock->state = SS_DISCONNECTING; | 1755 | sock->state = SS_DISCONNECTING; |
| @@ -1794,7 +1775,7 @@ restart: | |||
| 1794 | } | 1775 | } |
| 1795 | 1776 | ||
| 1796 | /** | 1777 | /** |
| 1797 | * setsockopt - set socket option | 1778 | * tipc_setsockopt - set socket option |
| 1798 | * @sock: socket structure | 1779 | * @sock: socket structure |
| 1799 | * @lvl: option level | 1780 | * @lvl: option level |
| 1800 | * @opt: option identifier | 1781 | * @opt: option identifier |
| @@ -1806,11 +1787,12 @@ restart: | |||
| 1806 | * | 1787 | * |
| 1807 | * Returns 0 on success, errno otherwise | 1788 | * Returns 0 on success, errno otherwise |
| 1808 | */ | 1789 | */ |
| 1809 | static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | 1790 | static int tipc_setsockopt(struct socket *sock, int lvl, int opt, |
| 1810 | unsigned int ol) | 1791 | char __user *ov, unsigned int ol) |
| 1811 | { | 1792 | { |
| 1812 | struct sock *sk = sock->sk; | 1793 | struct sock *sk = sock->sk; |
| 1813 | struct tipc_port *tport = tipc_sk_port(sk); | 1794 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1795 | struct tipc_port *port = &tsk->port; | ||
| 1814 | u32 value; | 1796 | u32 value; |
| 1815 | int res; | 1797 | int res; |
| 1816 | 1798 | ||
| @@ -1828,16 +1810,16 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | |||
| 1828 | 1810 | ||
| 1829 | switch (opt) { | 1811 | switch (opt) { |
| 1830 | case TIPC_IMPORTANCE: | 1812 | case TIPC_IMPORTANCE: |
| 1831 | res = tipc_set_portimportance(tport->ref, value); | 1813 | tipc_port_set_importance(port, value); |
| 1832 | break; | 1814 | break; |
| 1833 | case TIPC_SRC_DROPPABLE: | 1815 | case TIPC_SRC_DROPPABLE: |
| 1834 | if (sock->type != SOCK_STREAM) | 1816 | if (sock->type != SOCK_STREAM) |
| 1835 | res = tipc_set_portunreliable(tport->ref, value); | 1817 | tipc_port_set_unreliable(port, value); |
| 1836 | else | 1818 | else |
| 1837 | res = -ENOPROTOOPT; | 1819 | res = -ENOPROTOOPT; |
| 1838 | break; | 1820 | break; |
| 1839 | case TIPC_DEST_DROPPABLE: | 1821 | case TIPC_DEST_DROPPABLE: |
| 1840 | res = tipc_set_portunreturnable(tport->ref, value); | 1822 | tipc_port_set_unreturnable(port, value); |
| 1841 | break; | 1823 | break; |
| 1842 | case TIPC_CONN_TIMEOUT: | 1824 | case TIPC_CONN_TIMEOUT: |
| 1843 | tipc_sk(sk)->conn_timeout = value; | 1825 | tipc_sk(sk)->conn_timeout = value; |
| @@ -1853,7 +1835,7 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | |||
| 1853 | } | 1835 | } |
| 1854 | 1836 | ||
| 1855 | /** | 1837 | /** |
| 1856 | * getsockopt - get socket option | 1838 | * tipc_getsockopt - get socket option |
| 1857 | * @sock: socket structure | 1839 | * @sock: socket structure |
| 1858 | * @lvl: option level | 1840 | * @lvl: option level |
| 1859 | * @opt: option identifier | 1841 | * @opt: option identifier |
| @@ -1865,11 +1847,12 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | |||
| 1865 | * | 1847 | * |
| 1866 | * Returns 0 on success, errno otherwise | 1848 | * Returns 0 on success, errno otherwise |
| 1867 | */ | 1849 | */ |
| 1868 | static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | 1850 | static int tipc_getsockopt(struct socket *sock, int lvl, int opt, |
| 1869 | int __user *ol) | 1851 | char __user *ov, int __user *ol) |
| 1870 | { | 1852 | { |
| 1871 | struct sock *sk = sock->sk; | 1853 | struct sock *sk = sock->sk; |
| 1872 | struct tipc_port *tport = tipc_sk_port(sk); | 1854 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1855 | struct tipc_port *port = &tsk->port; | ||
| 1873 | int len; | 1856 | int len; |
| 1874 | u32 value; | 1857 | u32 value; |
| 1875 | int res; | 1858 | int res; |
| @@ -1886,13 +1869,13 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | |||
| 1886 | 1869 | ||
| 1887 | switch (opt) { | 1870 | switch (opt) { |
| 1888 | case TIPC_IMPORTANCE: | 1871 | case TIPC_IMPORTANCE: |
| 1889 | res = tipc_portimportance(tport->ref, &value); | 1872 | value = tipc_port_importance(port); |
| 1890 | break; | 1873 | break; |
| 1891 | case TIPC_SRC_DROPPABLE: | 1874 | case TIPC_SRC_DROPPABLE: |
| 1892 | res = tipc_portunreliable(tport->ref, &value); | 1875 | value = tipc_port_unreliable(port); |
| 1893 | break; | 1876 | break; |
| 1894 | case TIPC_DEST_DROPPABLE: | 1877 | case TIPC_DEST_DROPPABLE: |
| 1895 | res = tipc_portunreturnable(tport->ref, &value); | 1878 | value = tipc_port_unreturnable(port); |
| 1896 | break; | 1879 | break; |
| 1897 | case TIPC_CONN_TIMEOUT: | 1880 | case TIPC_CONN_TIMEOUT: |
| 1898 | value = tipc_sk(sk)->conn_timeout; | 1881 | value = tipc_sk(sk)->conn_timeout; |
| @@ -1927,20 +1910,20 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, | |||
| 1927 | static const struct proto_ops msg_ops = { | 1910 | static const struct proto_ops msg_ops = { |
| 1928 | .owner = THIS_MODULE, | 1911 | .owner = THIS_MODULE, |
| 1929 | .family = AF_TIPC, | 1912 | .family = AF_TIPC, |
| 1930 | .release = release, | 1913 | .release = tipc_release, |
| 1931 | .bind = bind, | 1914 | .bind = tipc_bind, |
| 1932 | .connect = connect, | 1915 | .connect = tipc_connect, |
| 1933 | .socketpair = sock_no_socketpair, | 1916 | .socketpair = sock_no_socketpair, |
| 1934 | .accept = sock_no_accept, | 1917 | .accept = sock_no_accept, |
| 1935 | .getname = get_name, | 1918 | .getname = tipc_getname, |
| 1936 | .poll = poll, | 1919 | .poll = tipc_poll, |
| 1937 | .ioctl = sock_no_ioctl, | 1920 | .ioctl = sock_no_ioctl, |
| 1938 | .listen = sock_no_listen, | 1921 | .listen = sock_no_listen, |
| 1939 | .shutdown = shutdown, | 1922 | .shutdown = tipc_shutdown, |
| 1940 | .setsockopt = setsockopt, | 1923 | .setsockopt = tipc_setsockopt, |
| 1941 | .getsockopt = getsockopt, | 1924 | .getsockopt = tipc_getsockopt, |
| 1942 | .sendmsg = send_msg, | 1925 | .sendmsg = tipc_sendmsg, |
| 1943 | .recvmsg = recv_msg, | 1926 | .recvmsg = tipc_recvmsg, |
| 1944 | .mmap = sock_no_mmap, | 1927 | .mmap = sock_no_mmap, |
| 1945 | .sendpage = sock_no_sendpage | 1928 | .sendpage = sock_no_sendpage |
| 1946 | }; | 1929 | }; |
| @@ -1948,20 +1931,20 @@ static const struct proto_ops msg_ops = { | |||
| 1948 | static const struct proto_ops packet_ops = { | 1931 | static const struct proto_ops packet_ops = { |
| 1949 | .owner = THIS_MODULE, | 1932 | .owner = THIS_MODULE, |
| 1950 | .family = AF_TIPC, | 1933 | .family = AF_TIPC, |
| 1951 | .release = release, | 1934 | .release = tipc_release, |
| 1952 | .bind = bind, | 1935 | .bind = tipc_bind, |
| 1953 | .connect = connect, | 1936 | .connect = tipc_connect, |
| 1954 | .socketpair = sock_no_socketpair, | 1937 | .socketpair = sock_no_socketpair, |
| 1955 | .accept = accept, | 1938 | .accept = tipc_accept, |
| 1956 | .getname = get_name, | 1939 | .getname = tipc_getname, |
| 1957 | .poll = poll, | 1940 | .poll = tipc_poll, |
| 1958 | .ioctl = sock_no_ioctl, | 1941 | .ioctl = sock_no_ioctl, |
| 1959 | .listen = listen, | 1942 | .listen = tipc_listen, |
| 1960 | .shutdown = shutdown, | 1943 | .shutdown = tipc_shutdown, |
| 1961 | .setsockopt = setsockopt, | 1944 | .setsockopt = tipc_setsockopt, |
| 1962 | .getsockopt = getsockopt, | 1945 | .getsockopt = tipc_getsockopt, |
| 1963 | .sendmsg = send_packet, | 1946 | .sendmsg = tipc_send_packet, |
| 1964 | .recvmsg = recv_msg, | 1947 | .recvmsg = tipc_recvmsg, |
| 1965 | .mmap = sock_no_mmap, | 1948 | .mmap = sock_no_mmap, |
| 1966 | .sendpage = sock_no_sendpage | 1949 | .sendpage = sock_no_sendpage |
| 1967 | }; | 1950 | }; |
| @@ -1969,20 +1952,20 @@ static const struct proto_ops packet_ops = { | |||
| 1969 | static const struct proto_ops stream_ops = { | 1952 | static const struct proto_ops stream_ops = { |
| 1970 | .owner = THIS_MODULE, | 1953 | .owner = THIS_MODULE, |
| 1971 | .family = AF_TIPC, | 1954 | .family = AF_TIPC, |
| 1972 | .release = release, | 1955 | .release = tipc_release, |
| 1973 | .bind = bind, | 1956 | .bind = tipc_bind, |
| 1974 | .connect = connect, | 1957 | .connect = tipc_connect, |
| 1975 | .socketpair = sock_no_socketpair, | 1958 | .socketpair = sock_no_socketpair, |
| 1976 | .accept = accept, | 1959 | .accept = tipc_accept, |
| 1977 | .getname = get_name, | 1960 | .getname = tipc_getname, |
| 1978 | .poll = poll, | 1961 | .poll = tipc_poll, |
| 1979 | .ioctl = sock_no_ioctl, | 1962 | .ioctl = sock_no_ioctl, |
| 1980 | .listen = listen, | 1963 | .listen = tipc_listen, |
| 1981 | .shutdown = shutdown, | 1964 | .shutdown = tipc_shutdown, |
| 1982 | .setsockopt = setsockopt, | 1965 | .setsockopt = tipc_setsockopt, |
| 1983 | .getsockopt = getsockopt, | 1966 | .getsockopt = tipc_getsockopt, |
| 1984 | .sendmsg = send_stream, | 1967 | .sendmsg = tipc_send_stream, |
| 1985 | .recvmsg = recv_stream, | 1968 | .recvmsg = tipc_recv_stream, |
| 1986 | .mmap = sock_no_mmap, | 1969 | .mmap = sock_no_mmap, |
| 1987 | .sendpage = sock_no_sendpage | 1970 | .sendpage = sock_no_sendpage |
| 1988 | }; | 1971 | }; |
| @@ -2027,8 +2010,6 @@ int tipc_socket_init(void) | |||
| 2027 | proto_unregister(&tipc_proto); | 2010 | proto_unregister(&tipc_proto); |
| 2028 | goto out; | 2011 | goto out; |
| 2029 | } | 2012 | } |
| 2030 | |||
| 2031 | sockets_enabled = 1; | ||
| 2032 | out: | 2013 | out: |
| 2033 | return res; | 2014 | return res; |
| 2034 | } | 2015 | } |
| @@ -2038,10 +2019,6 @@ int tipc_socket_init(void) | |||
| 2038 | */ | 2019 | */ |
| 2039 | void tipc_socket_stop(void) | 2020 | void tipc_socket_stop(void) |
| 2040 | { | 2021 | { |
| 2041 | if (!sockets_enabled) | ||
| 2042 | return; | ||
| 2043 | |||
| 2044 | sockets_enabled = 0; | ||
| 2045 | sock_unregister(tipc_family_ops.family); | 2022 | sock_unregister(tipc_family_ops.family); |
| 2046 | proto_unregister(&tipc_proto); | 2023 | proto_unregister(&tipc_proto); |
| 2047 | } | 2024 | } |
diff --git a/net/tipc/socket.h b/net/tipc/socket.h new file mode 100644 index 000000000000..74e5c7f195a6 --- /dev/null +++ b/net/tipc/socket.h | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | /* net/tipc/socket.h: Include file for TIPC socket code | ||
| 2 | * | ||
| 3 | * Copyright (c) 2014, Ericsson AB | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * 3. Neither the names of the copyright holders nor the names of its | ||
| 15 | * contributors may be used to endorse or promote products derived from | ||
| 16 | * this software without specific prior written permission. | ||
| 17 | * | ||
| 18 | * Alternatively, this software may be distributed under the terms of the | ||
| 19 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
| 20 | * Software Foundation. | ||
| 21 | * | ||
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 32 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #ifndef _TIPC_SOCK_H | ||
| 36 | #define _TIPC_SOCK_H | ||
| 37 | |||
| 38 | #include "port.h" | ||
| 39 | #include <net/sock.h> | ||
| 40 | |||
| 41 | /** | ||
| 42 | * struct tipc_sock - TIPC socket structure | ||
| 43 | * @sk: socket - interacts with 'port' and with user via the socket API | ||
| 44 | * @port: port - interacts with 'sk' and with the rest of the TIPC stack | ||
| 45 | * @peer_name: the peer of the connection, if any | ||
| 46 | * @conn_timeout: the time we can wait for an unresponded setup request | ||
| 47 | */ | ||
| 48 | |||
| 49 | struct tipc_sock { | ||
| 50 | struct sock sk; | ||
| 51 | struct tipc_port port; | ||
| 52 | unsigned int conn_timeout; | ||
| 53 | }; | ||
| 54 | |||
| 55 | static inline struct tipc_sock *tipc_sk(const struct sock *sk) | ||
| 56 | { | ||
| 57 | return container_of(sk, struct tipc_sock, sk); | ||
| 58 | } | ||
| 59 | |||
| 60 | static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port) | ||
| 61 | { | ||
| 62 | return container_of(port, struct tipc_sock, port); | ||
| 63 | } | ||
| 64 | |||
| 65 | static inline void tipc_sock_wakeup(struct tipc_sock *tsk) | ||
| 66 | { | ||
| 67 | tsk->sk.sk_write_space(&tsk->sk); | ||
| 68 | } | ||
| 69 | |||
| 70 | u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf); | ||
| 71 | |||
| 72 | #endif | ||
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index 7cb0bd5b1176..642437231ad5 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
| @@ -96,20 +96,16 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower, | |||
| 96 | { | 96 | { |
| 97 | struct tipc_subscriber *subscriber = sub->subscriber; | 97 | struct tipc_subscriber *subscriber = sub->subscriber; |
| 98 | struct kvec msg_sect; | 98 | struct kvec msg_sect; |
| 99 | int ret; | ||
| 100 | 99 | ||
| 101 | msg_sect.iov_base = (void *)&sub->evt; | 100 | msg_sect.iov_base = (void *)&sub->evt; |
| 102 | msg_sect.iov_len = sizeof(struct tipc_event); | 101 | msg_sect.iov_len = sizeof(struct tipc_event); |
| 103 | |||
| 104 | sub->evt.event = htohl(event, sub->swap); | 102 | sub->evt.event = htohl(event, sub->swap); |
| 105 | sub->evt.found_lower = htohl(found_lower, sub->swap); | 103 | sub->evt.found_lower = htohl(found_lower, sub->swap); |
| 106 | sub->evt.found_upper = htohl(found_upper, sub->swap); | 104 | sub->evt.found_upper = htohl(found_upper, sub->swap); |
| 107 | sub->evt.port.ref = htohl(port_ref, sub->swap); | 105 | sub->evt.port.ref = htohl(port_ref, sub->swap); |
| 108 | sub->evt.port.node = htohl(node, sub->swap); | 106 | sub->evt.port.node = htohl(node, sub->swap); |
| 109 | ret = tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, | 107 | tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base, |
| 110 | msg_sect.iov_base, msg_sect.iov_len); | 108 | msg_sect.iov_len); |
| 111 | if (ret < 0) | ||
| 112 | pr_err("Sending subscription event failed, no memory\n"); | ||
| 113 | } | 109 | } |
| 114 | 110 | ||
| 115 | /** | 111 | /** |
| @@ -153,14 +149,6 @@ static void subscr_timeout(struct tipc_subscription *sub) | |||
| 153 | /* The spin lock per subscriber is used to protect its members */ | 149 | /* The spin lock per subscriber is used to protect its members */ |
| 154 | spin_lock_bh(&subscriber->lock); | 150 | spin_lock_bh(&subscriber->lock); |
| 155 | 151 | ||
| 156 | /* Validate if the connection related to the subscriber is | ||
| 157 | * closed (in case subscriber is terminating) | ||
| 158 | */ | ||
| 159 | if (subscriber->conid == 0) { | ||
| 160 | spin_unlock_bh(&subscriber->lock); | ||
| 161 | return; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* Validate timeout (in case subscription is being cancelled) */ | 152 | /* Validate timeout (in case subscription is being cancelled) */ |
| 165 | if (sub->timeout == TIPC_WAIT_FOREVER) { | 153 | if (sub->timeout == TIPC_WAIT_FOREVER) { |
| 166 | spin_unlock_bh(&subscriber->lock); | 154 | spin_unlock_bh(&subscriber->lock); |
| @@ -215,9 +203,6 @@ static void subscr_release(struct tipc_subscriber *subscriber) | |||
| 215 | 203 | ||
| 216 | spin_lock_bh(&subscriber->lock); | 204 | spin_lock_bh(&subscriber->lock); |
| 217 | 205 | ||
| 218 | /* Invalidate subscriber reference */ | ||
| 219 | subscriber->conid = 0; | ||
| 220 | |||
| 221 | /* Destroy any existing subscriptions for subscriber */ | 206 | /* Destroy any existing subscriptions for subscriber */ |
| 222 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, | 207 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, |
| 223 | subscription_list) { | 208 | subscription_list) { |
| @@ -278,9 +263,9 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
| 278 | * | 263 | * |
| 279 | * Called with subscriber lock held. | 264 | * Called with subscriber lock held. |
| 280 | */ | 265 | */ |
| 281 | static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s, | 266 | static int subscr_subscribe(struct tipc_subscr *s, |
| 282 | struct tipc_subscriber *subscriber) | 267 | struct tipc_subscriber *subscriber, |
| 283 | { | 268 | struct tipc_subscription **sub_p) { |
| 284 | struct tipc_subscription *sub; | 269 | struct tipc_subscription *sub; |
| 285 | int swap; | 270 | int swap; |
| 286 | 271 | ||
| @@ -291,23 +276,21 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s, | |||
| 291 | if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { | 276 | if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { |
| 292 | s->filter &= ~htohl(TIPC_SUB_CANCEL, swap); | 277 | s->filter &= ~htohl(TIPC_SUB_CANCEL, swap); |
| 293 | subscr_cancel(s, subscriber); | 278 | subscr_cancel(s, subscriber); |
| 294 | return NULL; | 279 | return 0; |
| 295 | } | 280 | } |
| 296 | 281 | ||
| 297 | /* Refuse subscription if global limit exceeded */ | 282 | /* Refuse subscription if global limit exceeded */ |
| 298 | if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { | 283 | if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { |
| 299 | pr_warn("Subscription rejected, limit reached (%u)\n", | 284 | pr_warn("Subscription rejected, limit reached (%u)\n", |
| 300 | TIPC_MAX_SUBSCRIPTIONS); | 285 | TIPC_MAX_SUBSCRIPTIONS); |
| 301 | subscr_terminate(subscriber); | 286 | return -EINVAL; |
| 302 | return NULL; | ||
| 303 | } | 287 | } |
| 304 | 288 | ||
| 305 | /* Allocate subscription object */ | 289 | /* Allocate subscription object */ |
| 306 | sub = kmalloc(sizeof(*sub), GFP_ATOMIC); | 290 | sub = kmalloc(sizeof(*sub), GFP_ATOMIC); |
| 307 | if (!sub) { | 291 | if (!sub) { |
| 308 | pr_warn("Subscription rejected, no memory\n"); | 292 | pr_warn("Subscription rejected, no memory\n"); |
| 309 | subscr_terminate(subscriber); | 293 | return -ENOMEM; |
| 310 | return NULL; | ||
| 311 | } | 294 | } |
| 312 | 295 | ||
| 313 | /* Initialize subscription object */ | 296 | /* Initialize subscription object */ |
| @@ -321,8 +304,7 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s, | |||
| 321 | (sub->seq.lower > sub->seq.upper)) { | 304 | (sub->seq.lower > sub->seq.upper)) { |
| 322 | pr_warn("Subscription rejected, illegal request\n"); | 305 | pr_warn("Subscription rejected, illegal request\n"); |
| 323 | kfree(sub); | 306 | kfree(sub); |
| 324 | subscr_terminate(subscriber); | 307 | return -EINVAL; |
| 325 | return NULL; | ||
| 326 | } | 308 | } |
| 327 | INIT_LIST_HEAD(&sub->nameseq_list); | 309 | INIT_LIST_HEAD(&sub->nameseq_list); |
| 328 | list_add(&sub->subscription_list, &subscriber->subscription_list); | 310 | list_add(&sub->subscription_list, &subscriber->subscription_list); |
| @@ -335,8 +317,8 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s, | |||
| 335 | (Handler)subscr_timeout, (unsigned long)sub); | 317 | (Handler)subscr_timeout, (unsigned long)sub); |
| 336 | k_start_timer(&sub->timer, sub->timeout); | 318 | k_start_timer(&sub->timer, sub->timeout); |
| 337 | } | 319 | } |
| 338 | 320 | *sub_p = sub; | |
| 339 | return sub; | 321 | return 0; |
| 340 | } | 322 | } |
| 341 | 323 | ||
| 342 | /* Handle one termination request for the subscriber */ | 324 | /* Handle one termination request for the subscriber */ |
| @@ -350,10 +332,14 @@ static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr, | |||
| 350 | void *usr_data, void *buf, size_t len) | 332 | void *usr_data, void *buf, size_t len) |
| 351 | { | 333 | { |
| 352 | struct tipc_subscriber *subscriber = usr_data; | 334 | struct tipc_subscriber *subscriber = usr_data; |
| 353 | struct tipc_subscription *sub; | 335 | struct tipc_subscription *sub = NULL; |
| 354 | 336 | ||
| 355 | spin_lock_bh(&subscriber->lock); | 337 | spin_lock_bh(&subscriber->lock); |
| 356 | sub = subscr_subscribe((struct tipc_subscr *)buf, subscriber); | 338 | if (subscr_subscribe((struct tipc_subscr *)buf, subscriber, &sub) < 0) { |
| 339 | spin_unlock_bh(&subscriber->lock); | ||
| 340 | subscr_terminate(subscriber); | ||
| 341 | return; | ||
| 342 | } | ||
| 357 | if (sub) | 343 | if (sub) |
| 358 | tipc_nametbl_subscribe(sub); | 344 | tipc_nametbl_subscribe(sub); |
| 359 | spin_unlock_bh(&subscriber->lock); | 345 | spin_unlock_bh(&subscriber->lock); |
