aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-04-02 23:53:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-02 23:53:45 -0400
commitcd6362befe4cc7bf589a5236d2a780af2d47bcc9 (patch)
tree3bd4e13ec3f92a00dc4f6c3d65e820b54dbfe46e /net/tipc
parent0f1b1e6d73cb989ce2c071edc57deade3b084dfe (diff)
parentb1586f099ba897542ece36e8a23c1a62907261ef (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking updates from David Miller: "Here is my initial pull request for the networking subsystem during this merge window: 1) Support for ESN in AH (RFC 4302) from Fan Du. 2) Add full kernel doc for ethtool command structures, from Ben Hutchings. 3) Add BCM7xxx PHY driver, from Florian Fainelli. 4) Export computed TCP rate information in netlink socket dumps, from Eric Dumazet. 5) Allow IPSEC SA to be dumped partially using a filter, from Nicolas Dichtel. 6) Convert many drivers to pci_enable_msix_range(), from Alexander Gordeev. 7) Record SKB timestamps more efficiently, from Eric Dumazet. 8) Switch to microsecond resolution for TCP round trip times, also from Eric Dumazet. 9) Clean up and fix 6lowpan fragmentation handling by making use of the existing inet_frag api for it's implementation. 10) Add TX grant mapping to xen-netback driver, from Zoltan Kiss. 11) Auto size SKB lengths when composing netlink messages based upon past message sizes used, from Eric Dumazet. 12) qdisc dumps can take a long time, add a cond_resched(), From Eric Dumazet. 13) Sanitize netpoll core and drivers wrt. SKB handling semantics. Get rid of never-used-in-tree netpoll RX handling. From Eric W Biederman. 14) Support inter-address-family and namespace changing in VTI tunnel driver(s). From Steffen Klassert. 15) Add Altera TSE driver, from Vince Bridgers. 16) Optimizing csum_replace2() so that it doesn't adjust the checksum by checksumming the entire header, from Eric Dumazet. 17) Expand BPF internal implementation for faster interpreting, more direct translations into JIT'd code, and much cleaner uses of BPF filtering in non-socket ocntexts. From Daniel Borkmann and Alexei Starovoitov" * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1976 commits) netpoll: Use skb_irq_freeable to make zap_completion_queue safe. net: Add a test to see if a skb is freeable in irq context qlcnic: Fix build failure due to undefined reference to `vxlan_get_rx_port' net: ptp: move PTP classifier in its own file net: sxgbe: make "core_ops" static net: sxgbe: fix logical vs bitwise operation net: sxgbe: sxgbe_mdio_register() frees the bus Call efx_set_channels() before efx->type->dimension_resources() xen-netback: disable rogue vif in kthread context net/mlx4: Set proper build dependancy with vxlan be2net: fix build dependency on VxLAN mac802154: make csma/cca parameters per-wpan mac802154: allow only one WPAN to be up at any given time net: filter: minor: fix kdoc in __sk_run_filter netlink: don't compare the nul-termination in nla_strcmp can: c_can: Avoid led toggling for every packet. can: c_can: Simplify TX interrupt cleanup can: c_can: Store dlc private can: c_can: Reduce register access can: c_can: Make the code readable ...
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/addr.h2
-rw-r--r--net/tipc/bcast.c41
-rw-r--r--net/tipc/bcast.h4
-rw-r--r--net/tipc/bearer.c96
-rw-r--r--net/tipc/bearer.h13
-rw-r--r--net/tipc/config.c107
-rw-r--r--net/tipc/config.h5
-rw-r--r--net/tipc/core.c11
-rw-r--r--net/tipc/core.h1
-rw-r--r--net/tipc/discover.c23
-rw-r--r--net/tipc/discover.h5
-rw-r--r--net/tipc/link.c620
-rw-r--r--net/tipc/link.h57
-rw-r--r--net/tipc/name_distr.c22
-rw-r--r--net/tipc/name_distr.h2
-rw-r--r--net/tipc/net.c19
-rw-r--r--net/tipc/node.c119
-rw-r--r--net/tipc/node.h6
-rw-r--r--net/tipc/port.c301
-rw-r--r--net/tipc/port.h130
-rw-r--r--net/tipc/ref.c27
-rw-r--r--net/tipc/ref.h1
-rw-r--r--net/tipc/socket.c414
-rw-r--r--net/tipc/socket.h72
24 files changed, 1007 insertions, 1091 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 */
361int tipc_bclink_send_msg(struct sk_buff *buf) 361int 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 */
414void tipc_bclink_recv_pkt(struct sk_buff *buf) 413void 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);
90void tipc_bclink_remove_node(u32 addr); 90void tipc_bclink_remove_node(u32 addr);
91struct tipc_node *tipc_bclink_retransmit_to(void); 91struct tipc_node *tipc_bclink_retransmit_to(void);
92void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); 92void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked);
93int tipc_bclink_send_msg(struct sk_buff *buf); 93int tipc_bclink_xmit(struct sk_buff *buf);
94void tipc_bclink_recv_pkt(struct sk_buff *buf); 94void tipc_bclink_rcv(struct sk_buff *buf);
95u32 tipc_bclink_get_last_sent(void); 95u32 tipc_bclink_get_last_sent(void);
96u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); 96u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr);
97void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent); 97void 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 574b86193b15..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
52struct tipc_bearer tipc_bearers[MAX_BEARERS]; 52struct tipc_bearer *bearer_list[MAX_BEARERS + 1];
53 53
54static void bearer_disable(struct tipc_bearer *b_ptr); 54static 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 */
351static int tipc_reset_bearer(struct tipc_bearer *b_ptr) 360static 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 */
376static void bearer_disable(struct tipc_bearer *b_ptr) 376static 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
398int tipc_disable_bearer(const char *name) 396int 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
601static struct packet_type tipc_packet_type __read_mostly = { 603static 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
@@ -627,10 +629,14 @@ void tipc_bearer_cleanup(void)
627 629
628void tipc_bearer_stop(void) 630void tipc_bearer_stop(void)
629{ 631{
632 struct tipc_bearer *b_ptr;
630 u32 i; 633 u32 i;
631 634
632 for (i = 0; i < MAX_BEARERS; i++) { 635 for (i = 0; i < MAX_BEARERS; i++) {
633 if (tipc_bearers[i].active) 636 b_ptr = bearer_list[i];
634 bearer_disable(&tipc_bearers[i]); 637 if (b_ptr) {
638 bearer_disable(b_ptr, true);
639 bearer_list[i] = NULL;
640 }
635 } 641 }
636} 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
156struct tipc_link; 151struct tipc_link;
157 152
158extern struct tipc_bearer tipc_bearers[]; 153extern 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 e6d721692ae0..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
45static DEFINE_MUTEX(config_mutex); 45static DEFINE_MUTEX(config_mutex);
46static struct tipc_server cfgsrv;
47 46
48static const void *req_tlv_area; /* request message TLV area */ 47static const void *req_tlv_area; /* request message TLV area */
49static int req_tlv_space; /* request message TLV area size */ 48static int req_tlv_space; /* request message TLV area size */
50static int rep_headroom; /* reply message headroom to use */ 49static int rep_headroom; /* reply message headroom to use */
51 50
52
53struct sk_buff *tipc_cfg_reply_alloc(int payload_size) 51struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
54{ 52{
55 struct sk_buff *buf; 53 struct sk_buff *buf;
@@ -185,18 +183,6 @@ static struct sk_buff *cfg_set_own_addr(void)
185 return tipc_cfg_reply_none(); 183 return tipc_cfg_reply_none();
186} 184}
187 185
188static 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();
198}
199
200static struct sk_buff *cfg_set_max_ports(void) 186static struct sk_buff *cfg_set_max_ports(void)
201{ 187{
202 u32 value; 188 u32 value;
@@ -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,75 +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
373static 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
380 /* Validate configuration message header (ignore invalid message) */
381 req_hdr = (struct tipc_cfg_msg_hdr *)buf;
382 if ((len < sizeof(*req_hdr)) ||
383 (len != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
384 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
385 pr_warn("Invalid configuration message discarded\n");
386 return;
387 }
388
389 /* Generate reply for request (if can't, return request) */
390 rep_buf = tipc_cfg_do_cmd(addr->addr.id.node, ntohs(req_hdr->tcm_type),
391 buf + sizeof(*req_hdr),
392 len - sizeof(*req_hdr),
393 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
394 if (rep_buf) {
395 skb_push(rep_buf, sizeof(*rep_hdr));
396 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
397 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
398 rep_hdr->tcm_len = htonl(rep_buf->len);
399 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
400 tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data,
401 rep_buf->len);
402 kfree_skb(rep_buf);
403 }
404}
405
406static struct sockaddr_tipc cfgsrv_addr __read_mostly = {
407 .family = AF_TIPC,
408 .addrtype = TIPC_ADDR_NAMESEQ,
409 .addr.nameseq.type = TIPC_CFG_SRV,
410 .addr.nameseq.lower = 0,
411 .addr.nameseq.upper = 0,
412 .scope = TIPC_ZONE_SCOPE
413};
414
415static struct tipc_server cfgsrv __read_mostly = {
416 .saddr = &cfgsrv_addr,
417 .imp = TIPC_CRITICAL_IMPORTANCE,
418 .type = SOCK_RDM,
419 .max_rcvbuf_size = 64 * 1024,
420 .name = "cfg_server",
421 .tipc_conn_recvmsg = cfg_conn_msg_event,
422 .tipc_conn_new = NULL,
423 .tipc_conn_shutdown = NULL
424};
425
426int tipc_cfg_init(void)
427{
428 return tipc_server_start(&cfgsrv);
429}
430
431void tipc_cfg_reinit(void)
432{
433 tipc_server_stop(&cfgsrv);
434
435 cfgsrv_addr.addr.nameseq.lower = tipc_own_addr;
436 cfgsrv_addr.addr.nameseq.upper = tipc_own_addr;
437 tipc_server_start(&cfgsrv);
438}
439
440void tipc_cfg_stop(void)
441{
442 tipc_server_stop(&cfgsrv);
443}
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)
64struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, 64struct 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
68int tipc_cfg_init(void);
69void tipc_cfg_reinit(void);
70void tipc_cfg_stop(void);
71
72#endif 67#endif
diff --git a/net/tipc/core.c b/net/tipc/core.c
index 80c20647b3d2..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;
50u32 tipc_own_addr __read_mostly; 50u32 tipc_own_addr __read_mostly;
51int tipc_max_ports __read_mostly; 51int tipc_max_ports __read_mostly;
52int tipc_net_id __read_mostly; 52int tipc_net_id __read_mostly;
53int tipc_remote_management __read_mostly;
54int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ 53int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */
55 54
56/** 55/**
@@ -85,7 +84,6 @@ static void tipc_core_stop(void)
85 tipc_net_stop(); 84 tipc_net_stop();
86 tipc_bearer_cleanup(); 85 tipc_bearer_cleanup();
87 tipc_netlink_stop(); 86 tipc_netlink_stop();
88 tipc_cfg_stop();
89 tipc_subscr_stop(); 87 tipc_subscr_stop();
90 tipc_nametbl_stop(); 88 tipc_nametbl_stop();
91 tipc_ref_table_stop(); 89 tipc_ref_table_stop();
@@ -130,18 +128,12 @@ static int tipc_core_start(void)
130 if (err) 128 if (err)
131 goto out_subscr; 129 goto out_subscr;
132 130
133 err = tipc_cfg_init();
134 if (err)
135 goto out_cfg;
136
137 err = tipc_bearer_setup(); 131 err = tipc_bearer_setup();
138 if (err) 132 if (err)
139 goto out_bearer; 133 goto out_bearer;
140 134
141 return 0; 135 return 0;
142out_bearer: 136out_bearer:
143 tipc_cfg_stop();
144out_cfg:
145 tipc_subscr_stop(); 137 tipc_subscr_stop();
146out_subscr: 138out_subscr:
147 tipc_unregister_sysctl(); 139 tipc_unregister_sysctl();
@@ -166,7 +158,6 @@ static int __init tipc_init(void)
166 pr_info("Activated (version " TIPC_MOD_VER ")\n"); 158 pr_info("Activated (version " TIPC_MOD_VER ")\n");
167 159
168 tipc_own_addr = 0; 160 tipc_own_addr = 0;
169 tipc_remote_management = 1;
170 tipc_max_ports = CONFIG_TIPC_PORTS; 161 tipc_max_ports = CONFIG_TIPC_PORTS;
171 tipc_net_id = 4711; 162 tipc_net_id = 4711;
172 163
diff --git a/net/tipc/core.h b/net/tipc/core.h
index 4dfe137587bb..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, ...);
79extern u32 tipc_own_addr __read_mostly; 79extern u32 tipc_own_addr __read_mostly;
80extern int tipc_max_ports __read_mostly; 80extern int tipc_max_ports __read_mostly;
81extern int tipc_net_id __read_mostly; 81extern int tipc_net_id __read_mostly;
82extern int tipc_remote_management __read_mostly;
83extern int sysctl_tipc_rmem[3] __read_mostly; 82extern int sysctl_tipc_rmem[3] __read_mostly;
84 83
85/* 84/*
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 @@
58struct tipc_link_req { 57struct 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 */
75static struct sk_buff *tipc_disc_init_msg(u32 type, u32 dest_domain, 72static 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 */
117void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) 114void 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 */
345int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, 342int 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
40struct tipc_link_req; 40struct tipc_link_req;
41 41
42int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, 42int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest);
43 u32 dest_domain);
44void tipc_disc_delete(struct tipc_link_req *req); 43void tipc_disc_delete(struct tipc_link_req *req);
45void tipc_disc_add_dest(struct tipc_link_req *req); 44void tipc_disc_add_dest(struct tipc_link_req *req);
46void tipc_disc_remove_dest(struct tipc_link_req *req); 45void tipc_disc_remove_dest(struct tipc_link_req *req);
47void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr); 46void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *b_ptr);
48 47
49#endif 48#endif
diff --git a/net/tipc/link.c b/net/tipc/link.c
index da6018beb6eb..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
78static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, 78static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
79 struct sk_buff *buf); 79 struct sk_buff *buf);
80static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); 80static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf);
81static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, 81static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr,
82 struct sk_buff **buf); 82 struct sk_buff **buf);
83static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); 83static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance);
84static int link_send_sections_long(struct tipc_port *sender, 84static 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);
87static void link_state_event(struct tipc_link *l_ptr, u32 event); 87static void link_state_event(struct tipc_link *l_ptr, u32 event);
88static void link_reset_statistics(struct tipc_link *l_ptr); 88static void link_reset_statistics(struct tipc_link *l_ptr);
89static void link_print(struct tipc_link *l_ptr, const char *str); 89static void link_print(struct tipc_link *l_ptr, const char *str);
90static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); 90static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf);
91static void tipc_link_send_sync(struct tipc_link *l); 91static void tipc_link_sync_xmit(struct tipc_link *l);
92static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); 92static 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 */
156static void link_timeout(struct tipc_link *l_ptr) 151static 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 */
215struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, 210struct 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/** 283void 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 */
297void 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
460void 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
465static void link_activate(struct tipc_link *l_ptr) 476static 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 */
728int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) 746int __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 */
804int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) 822int 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 */
835static void tipc_link_send_sync(struct tipc_link *l) 853static 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 */
859static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) 877static 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 */
877void tipc_link_send_names(struct list_head *message_list, u32 dest) 895void 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 */
917static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, 935static 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 */
943int tipc_link_send_sections_fast(struct tipc_port *sender, 961int 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);
973exit: 991exit:
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 */
1028static int link_send_sections_long(struct tipc_port *sender, 1043static 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 {
1147reject: 1162reject:
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 */
@@ -1441,15 +1457,10 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1441 u32 seq_no; 1457 u32 seq_no;
1442 u32 ackd; 1458 u32 ackd;
1443 u32 released = 0; 1459 u32 released = 0;
1444 int type;
1445 1460
1446 head = head->next; 1461 head = head->next;
1447 buf->next = NULL; 1462 buf->next = NULL;
1448 1463
1449 /* Ensure bearer is still enabled */
1450 if (unlikely(!b_ptr->active))
1451 goto discard;
1452
1453 /* Ensure message is well-formed */ 1464 /* Ensure message is well-formed */
1454 if (unlikely(!link_recv_buf_validate(buf))) 1465 if (unlikely(!link_recv_buf_validate(buf)))
1455 goto discard; 1466 goto discard;
@@ -1463,9 +1474,9 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1463 1474
1464 if (unlikely(msg_non_seq(msg))) { 1475 if (unlikely(msg_non_seq(msg))) {
1465 if (msg_user(msg) == LINK_CONFIG) 1476 if (msg_user(msg) == LINK_CONFIG)
1466 tipc_disc_recv_msg(buf, b_ptr); 1477 tipc_disc_rcv(buf, b_ptr);
1467 else 1478 else
1468 tipc_bclink_recv_pkt(buf); 1479 tipc_bclink_rcv(buf);
1469 continue; 1480 continue;
1470 } 1481 }
1471 1482
@@ -1489,7 +1500,7 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1489 if ((n_ptr->block_setup & WAIT_PEER_DOWN) && 1500 if ((n_ptr->block_setup & WAIT_PEER_DOWN) &&
1490 msg_user(msg) == LINK_PROTOCOL && 1501 msg_user(msg) == LINK_PROTOCOL &&
1491 (msg_type(msg) == RESET_MSG || 1502 (msg_type(msg) == RESET_MSG ||
1492 msg_type(msg) == ACTIVATE_MSG) && 1503 msg_type(msg) == ACTIVATE_MSG) &&
1493 !msg_redundant_link(msg)) 1504 !msg_redundant_link(msg))
1494 n_ptr->block_setup &= ~WAIT_PEER_DOWN; 1505 n_ptr->block_setup &= ~WAIT_PEER_DOWN;
1495 1506
@@ -1508,7 +1519,6 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1508 while ((crs != l_ptr->next_out) && 1519 while ((crs != l_ptr->next_out) &&
1509 less_eq(buf_seqno(crs), ackd)) { 1520 less_eq(buf_seqno(crs), ackd)) {
1510 struct sk_buff *next = crs->next; 1521 struct sk_buff *next = crs->next;
1511
1512 kfree_skb(crs); 1522 kfree_skb(crs);
1513 crs = next; 1523 crs = next;
1514 released++; 1524 released++;
@@ -1521,18 +1531,19 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1521 /* Try sending any messages link endpoint has pending */ 1531 /* Try sending any messages link endpoint has pending */
1522 if (unlikely(l_ptr->next_out)) 1532 if (unlikely(l_ptr->next_out))
1523 tipc_link_push_queue(l_ptr); 1533 tipc_link_push_queue(l_ptr);
1534
1524 if (unlikely(!list_empty(&l_ptr->waiting_ports))) 1535 if (unlikely(!list_empty(&l_ptr->waiting_ports)))
1525 tipc_link_wakeup_ports(l_ptr, 0); 1536 tipc_link_wakeup_ports(l_ptr, 0);
1537
1526 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { 1538 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1527 l_ptr->stats.sent_acks++; 1539 l_ptr->stats.sent_acks++;
1528 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);
1529 } 1541 }
1530 1542
1531 /* Now (finally!) process the incoming message */ 1543 /* Process the incoming packet */
1532protocol_check:
1533 if (unlikely(!link_working_working(l_ptr))) { 1544 if (unlikely(!link_working_working(l_ptr))) {
1534 if (msg_user(msg) == LINK_PROTOCOL) { 1545 if (msg_user(msg) == LINK_PROTOCOL) {
1535 link_recv_proto_msg(l_ptr, buf); 1546 tipc_link_proto_rcv(l_ptr, buf);
1536 head = link_insert_deferred_queue(l_ptr, head); 1547 head = link_insert_deferred_queue(l_ptr, head);
1537 tipc_node_unlock(n_ptr); 1548 tipc_node_unlock(n_ptr);
1538 continue; 1549 continue;
@@ -1561,67 +1572,65 @@ protocol_check:
1561 l_ptr->next_in_no++; 1572 l_ptr->next_in_no++;
1562 if (unlikely(l_ptr->oldest_deferred_in)) 1573 if (unlikely(l_ptr->oldest_deferred_in))
1563 head = link_insert_deferred_queue(l_ptr, head); 1574 head = link_insert_deferred_queue(l_ptr, head);
1564deliver: 1575
1565 if (likely(msg_isdata(msg))) { 1576 /* Deliver packet/message to correct user: */
1566 tipc_node_unlock(n_ptr); 1577 if (unlikely(msg_user(msg) == CHANGEOVER_PROTOCOL)) {
1567 tipc_port_recv_msg(buf); 1578 if (!tipc_link_tunnel_rcv(n_ptr, &buf)) {
1568 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 }
1569 } 1599 }
1600
1570 switch (msg_user(msg)) { 1601 switch (msg_user(msg)) {
1571 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;
1572 case MSG_BUNDLER: 1609 case MSG_BUNDLER:
1573 l_ptr->stats.recv_bundles++; 1610 l_ptr->stats.recv_bundles++;
1574 l_ptr->stats.recv_bundled += msg_msgcnt(msg); 1611 l_ptr->stats.recv_bundled += msg_msgcnt(msg);
1575 tipc_node_unlock(n_ptr); 1612 tipc_node_unlock(n_ptr);
1576 tipc_link_recv_bundle(buf); 1613 tipc_link_bundle_rcv(buf);
1577 continue; 1614 continue;
1578 case NAME_DISTRIBUTOR: 1615 case NAME_DISTRIBUTOR:
1579 n_ptr->bclink.recv_permitted = true; 1616 n_ptr->bclink.recv_permitted = true;
1580 tipc_node_unlock(n_ptr); 1617 tipc_node_unlock(n_ptr);
1581 tipc_named_recv(buf); 1618 tipc_named_rcv(buf);
1582 continue;
1583 case BCAST_PROTOCOL:
1584 tipc_link_recv_sync(n_ptr, buf);
1585 tipc_node_unlock(n_ptr);
1586 continue; 1619 continue;
1587 case CONN_MANAGER: 1620 case CONN_MANAGER:
1588 tipc_node_unlock(n_ptr); 1621 tipc_node_unlock(n_ptr);
1589 tipc_port_recv_proto_msg(buf); 1622 tipc_port_proto_rcv(buf);
1590 continue; 1623 continue;
1591 case MSG_FRAGMENTER: 1624 case BCAST_PROTOCOL:
1592 l_ptr->stats.recv_fragments++; 1625 tipc_link_sync_rcv(n_ptr, buf);
1593 ret = tipc_link_recv_fragment(&l_ptr->reasm_head,
1594 &l_ptr->reasm_tail,
1595 &buf);
1596 if (ret == LINK_REASM_COMPLETE) {
1597 l_ptr->stats.recv_fragmented++;
1598 msg = buf_msg(buf);
1599 goto deliver;
1600 }
1601 if (ret == LINK_REASM_ERROR)
1602 tipc_link_reset(l_ptr);
1603 tipc_node_unlock(n_ptr);
1604 continue;
1605 case CHANGEOVER_PROTOCOL:
1606 type = msg_type(msg);
1607 if (tipc_link_tunnel_rcv(&l_ptr, &buf)) {
1608 msg = buf_msg(buf);
1609 seq_no = msg_seqno(msg);
1610 if (type == ORIGINAL_MSG)
1611 goto deliver;
1612 goto protocol_check;
1613 }
1614 break; 1626 break;
1615 default: 1627 default:
1616 kfree_skb(buf); 1628 kfree_skb(buf);
1617 buf = NULL;
1618 break; 1629 break;
1619 } 1630 }
1620 tipc_node_unlock(n_ptr); 1631 tipc_node_unlock(n_ptr);
1621 tipc_net_route_msg(buf);
1622 continue; 1632 continue;
1623unlock_discard: 1633unlock_discard:
1624
1625 tipc_node_unlock(n_ptr); 1634 tipc_node_unlock(n_ptr);
1626discard: 1635discard:
1627 kfree_skb(buf); 1636 kfree_skb(buf);
@@ -1688,7 +1697,7 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1688 u32 seq_no = buf_seqno(buf); 1697 u32 seq_no = buf_seqno(buf);
1689 1698
1690 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { 1699 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
1691 link_recv_proto_msg(l_ptr, buf); 1700 tipc_link_proto_rcv(l_ptr, buf);
1692 return; 1701 return;
1693 } 1702 }
1694 1703
@@ -1711,7 +1720,7 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1711 l_ptr->stats.deferred_recv++; 1720 l_ptr->stats.deferred_recv++;
1712 TIPC_SKB_CB(buf)->deferred = true; 1721 TIPC_SKB_CB(buf)->deferred = true;
1713 if ((l_ptr->deferred_inqueue_sz % 16) == 1) 1722 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
1714 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);
1715 } else 1724 } else
1716 l_ptr->stats.duplicates++; 1725 l_ptr->stats.duplicates++;
1717} 1726}
@@ -1719,9 +1728,8 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1719/* 1728/*
1720 * Send protocol message to the other endpoint. 1729 * Send protocol message to the other endpoint.
1721 */ 1730 */
1722void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, 1731void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
1723 int probe_msg, u32 gap, u32 tolerance, 1732 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
1724 u32 priority, u32 ack_mtu)
1725{ 1733{
1726 struct sk_buff *buf = NULL; 1734 struct sk_buff *buf = NULL;
1727 struct tipc_msg *msg = l_ptr->pmsg; 1735 struct tipc_msg *msg = l_ptr->pmsg;
@@ -1820,7 +1828,7 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ,
1820 * Note that network plane id propagates through the network, and may 1828 * Note that network plane id propagates through the network, and may
1821 * change at any time. The node with lowest address rules 1829 * change at any time. The node with lowest address rules
1822 */ 1830 */
1823static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) 1831static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf)
1824{ 1832{
1825 u32 rec_gap = 0; 1833 u32 rec_gap = 0;
1826 u32 max_pkt_info; 1834 u32 max_pkt_info;
@@ -1939,8 +1947,8 @@ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf)
1939 msg_last_bcast(msg)); 1947 msg_last_bcast(msg));
1940 1948
1941 if (rec_gap || (msg_probe(msg))) { 1949 if (rec_gap || (msg_probe(msg))) {
1942 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1950 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, rec_gap, 0,
1943 0, rec_gap, 0, 0, max_pkt_ack); 1951 0, max_pkt_ack);
1944 } 1952 }
1945 if (msg_seq_gap(msg)) { 1953 if (msg_seq_gap(msg)) {
1946 l_ptr->stats.recv_nacks++; 1954 l_ptr->stats.recv_nacks++;
@@ -1979,7 +1987,7 @@ static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
1979 } 1987 }
1980 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); 1988 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
1981 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);
1982 tipc_link_send_buf(tunnel, buf); 1990 __tipc_link_xmit(tunnel, buf);
1983} 1991}
1984 1992
1985 1993
@@ -2012,7 +2020,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
2012 if (buf) { 2020 if (buf) {
2013 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); 2021 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
2014 msg_set_size(&tunnel_hdr, INT_H_SIZE); 2022 msg_set_size(&tunnel_hdr, INT_H_SIZE);
2015 tipc_link_send_buf(tunnel, buf); 2023 __tipc_link_xmit(tunnel, buf);
2016 } else { 2024 } else {
2017 pr_warn("%sunable to send changeover msg\n", 2025 pr_warn("%sunable to send changeover msg\n",
2018 link_co_err); 2026 link_co_err);
@@ -2046,7 +2054,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
2046 } 2054 }
2047} 2055}
2048 2056
2049/* 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
2050 * 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
2051 * are guaranteed that currently queued packets from a socket are delivered 2059 * are guaranteed that currently queued packets from a socket are delivered
2052 * 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
@@ -2055,7 +2063,7 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
2055 * and sequence order is preserved per sender/receiver socket pair. 2063 * and sequence order is preserved per sender/receiver socket pair.
2056 * Owner node is locked. 2064 * Owner node is locked.
2057 */ 2065 */
2058void tipc_link_dup_send_queue(struct tipc_link *l_ptr, 2066void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr,
2059 struct tipc_link *tunnel) 2067 struct tipc_link *tunnel)
2060{ 2068{
2061 struct sk_buff *iter; 2069 struct sk_buff *iter;
@@ -2085,7 +2093,7 @@ void tipc_link_dup_send_queue(struct tipc_link *l_ptr,
2085 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); 2093 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2086 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,
2087 length); 2095 length);
2088 tipc_link_send_buf(tunnel, outbuf); 2096 __tipc_link_xmit(tunnel, outbuf);
2089 if (!tipc_link_is_up(l_ptr)) 2097 if (!tipc_link_is_up(l_ptr))
2090 return; 2098 return;
2091 iter = iter->next; 2099 iter = iter->next;
@@ -2112,89 +2120,114 @@ static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
2112 return eb; 2120 return eb;
2113} 2121}
2114 2122
2115/* tipc_link_tunnel_rcv(): Receive a tunneled packet, sent 2123
2116 * via other link as result of a failover (ORIGINAL_MSG) or 2124
2117 * a new active link (DUPLICATE_MSG). Failover packets are 2125/* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet.
2118 * returned to the active link for delivery upwards. 2126 * Owner node is locked.
2127 */
2128static 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
2119 * Owner node is locked. 2147 * Owner node is locked.
2120 */ 2148 */
2121static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, 2149static struct sk_buff *tipc_link_failover_rcv(struct tipc_link *l_ptr,
2122 struct sk_buff **buf) 2150 struct sk_buff *t_buf)
2123{ 2151{
2124 struct sk_buff *tunnel_buf = *buf; 2152 struct tipc_msg *t_msg = buf_msg(t_buf);
2125 struct tipc_link *dest_link; 2153 struct sk_buff *buf = NULL;
2126 struct tipc_msg *msg; 2154 struct tipc_msg *msg;
2127 struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf);
2128 u32 msg_typ = msg_type(tunnel_msg);
2129 u32 msg_count = msg_msgcnt(tunnel_msg);
2130 u32 bearer_id = msg_bearer_id(tunnel_msg);
2131 2155
2132 if (bearer_id >= MAX_BEARERS) 2156 if (tipc_link_is_up(l_ptr))
2133 goto exit; 2157 tipc_link_reset(l_ptr);
2134 dest_link = (*l_ptr)->owner->links[bearer_id];
2135 if (!dest_link)
2136 goto exit;
2137 if (dest_link == *l_ptr) {
2138 pr_err("Unexpected changeover message on link <%s>\n",
2139 (*l_ptr)->name);
2140 goto exit;
2141 }
2142 *l_ptr = dest_link;
2143 msg = msg_get_wrapped(tunnel_msg);
2144 2158
2145 if (msg_typ == DUPLICATE_MSG) { 2159 /* First failover packet? */
2146 if (less(msg_seqno(msg), mod(dest_link->next_in_no))) 2160 if (l_ptr->exp_msg_count == START_CHANGEOVER)
2147 goto exit; 2161 l_ptr->exp_msg_count = msg_msgcnt(t_msg);
2148 *buf = buf_extract(tunnel_buf, INT_H_SIZE); 2162
2149 if (*buf == NULL) { 2163 /* Should there be an inner packet? */
2150 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);
2151 goto exit; 2169 goto exit;
2152 } 2170 }
2153 kfree_skb(tunnel_buf); 2171 msg = buf_msg(buf);
2154 return 1;
2155 }
2156 2172
2157 /* First original message ?: */ 2173 if (less(msg_seqno(msg), l_ptr->reset_checkpoint)) {
2158 if (tipc_link_is_up(dest_link)) { 2174 kfree_skb(buf);
2159 pr_info("%s<%s>, changeover initiated by peer\n", link_rst_msg, 2175 buf = NULL;
2160 dest_link->name);
2161 tipc_link_reset(dest_link);
2162 dest_link->exp_msg_count = msg_count;
2163 if (!msg_count)
2164 goto exit;
2165 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
2166 dest_link->exp_msg_count = msg_count;
2167 if (!msg_count)
2168 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 }
2184 }
2185exit:
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);
2169 } 2189 }
2190 return buf;
2191}
2170 2192
2171 /* Receive original message */ 2193/* tipc_link_tunnel_rcv(): Receive a tunnelled packet, sent
2172 if (dest_link->exp_msg_count == 0) { 2194 * via other link as result of a failover (ORIGINAL_MSG) or
2173 pr_warn("%sgot too many tunnelled messages\n", link_co_err); 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 */
2199static 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;
2208
2209 if (bearer_id >= MAX_BEARERS)
2174 goto exit; 2210 goto exit;
2175 } 2211
2176 dest_link->exp_msg_count--; 2212 l_ptr = n_ptr->links[bearer_id];
2177 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { 2213 if (!l_ptr)
2178 goto exit; 2214 goto exit;
2179 } else { 2215
2180 *buf = buf_extract(tunnel_buf, INT_H_SIZE); 2216 if (msg_type(t_msg) == DUPLICATE_MSG)
2181 if (*buf != NULL) { 2217 tipc_link_dup_rcv(l_ptr, t_buf);
2182 kfree_skb(tunnel_buf); 2218 else if (msg_type(t_msg) == ORIGINAL_MSG)
2183 return 1; 2219 *buf = tipc_link_failover_rcv(l_ptr, t_buf);
2184 } else { 2220 else
2185 pr_warn("%soriginal msg dropped\n", link_co_err); 2221 pr_warn("%sunknown tunnel pkt received\n", link_co_err);
2186 }
2187 }
2188exit: 2222exit:
2189 *buf = NULL; 2223 kfree_skb(t_buf);
2190 kfree_skb(tunnel_buf); 2224 return *buf != NULL;
2191 return 0;
2192} 2225}
2193 2226
2194/* 2227/*
2195 * Bundler functionality: 2228 * Bundler functionality:
2196 */ 2229 */
2197void tipc_link_recv_bundle(struct sk_buff *buf) 2230void tipc_link_bundle_rcv(struct sk_buff *buf)
2198{ 2231{
2199 u32 msgcount = msg_msgcnt(buf_msg(buf)); 2232 u32 msgcount = msg_msgcnt(buf_msg(buf));
2200 u32 pos = INT_H_SIZE; 2233 u32 pos = INT_H_SIZE;
@@ -2217,11 +2250,11 @@ void tipc_link_recv_bundle(struct sk_buff *buf)
2217 */ 2250 */
2218 2251
2219/* 2252/*
2220 * link_send_long_buf: Entry for buffers needing fragmentation. 2253 * tipc_link_frag_xmit: Entry for buffers needing fragmentation.
2221 * The buffer is complete, inclusive total message length. 2254 * The buffer is complete, inclusive total message length.
2222 * Returns user data length. 2255 * Returns user data length.
2223 */ 2256 */
2224static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) 2257static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf)
2225{ 2258{
2226 struct sk_buff *buf_chain = NULL; 2259 struct sk_buff *buf_chain = NULL;
2227 struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; 2260 struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain;
@@ -2284,12 +2317,11 @@ static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
2284 return dsz; 2317 return dsz;
2285} 2318}
2286 2319
2287/* 2320/* tipc_link_frag_rcv(): Called with node lock on. Returns
2288 * tipc_link_recv_fragment(): Called with node lock on. Returns
2289 * the reassembled buffer if message is complete. 2321 * the reassembled buffer if message is complete.
2290 */ 2322 */
2291int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail, 2323int tipc_link_frag_rcv(struct sk_buff **head, struct sk_buff **tail,
2292 struct sk_buff **fbuf) 2324 struct sk_buff **fbuf)
2293{ 2325{
2294 struct sk_buff *frag = *fbuf; 2326 struct sk_buff *frag = *fbuf;
2295 struct tipc_msg *msg = buf_msg(frag); 2327 struct tipc_msg *msg = buf_msg(frag);
@@ -2303,6 +2335,7 @@ int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail,
2303 goto out_free; 2335 goto out_free;
2304 *head = frag; 2336 *head = frag;
2305 skb_frag_list_init(*head); 2337 skb_frag_list_init(*head);
2338 *fbuf = NULL;
2306 return 0; 2339 return 0;
2307 } else if (*head && 2340 } else if (*head &&
2308 skb_try_coalesce(*head, frag, &headstolen, &delta)) { 2341 skb_try_coalesce(*head, frag, &headstolen, &delta)) {
@@ -2322,10 +2355,12 @@ int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail,
2322 *tail = *head = NULL; 2355 *tail = *head = NULL;
2323 return LINK_REASM_COMPLETE; 2356 return LINK_REASM_COMPLETE;
2324 } 2357 }
2358 *fbuf = NULL;
2325 return 0; 2359 return 0;
2326out_free: 2360out_free:
2327 pr_warn_ratelimited("Link unable to reassemble fragmented message\n"); 2361 pr_warn_ratelimited("Link unable to reassemble fragmented message\n");
2328 kfree_skb(*fbuf); 2362 kfree_skb(*fbuf);
2363 *fbuf = NULL;
2329 return LINK_REASM_ERROR; 2364 return LINK_REASM_ERROR;
2330} 2365}
2331 2366
@@ -2359,35 +2394,41 @@ void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)
2359 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; 2394 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
2360} 2395}
2361 2396
2362/** 2397/* tipc_link_find_owner - locate owner node of link by link's name
2363 * link_find_link - locate link by name 2398 * @name: pointer to link name string
2364 * @name: ptr to link name string 2399 * @bearer_id: pointer to index in 'node->links' array where the link was found.
2365 * @node: ptr to area to be filled with ptr to associated node
2366 *
2367 * 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;
2368 * this also prevents link deletion. 2401 * this also prevents link deletion.
2369 * 2402 *
2370 * 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.
2371 */ 2404 */
2372static struct tipc_link *link_find_link(const char *name, 2405static struct tipc_node *tipc_link_find_owner(const char *link_name,
2373 struct tipc_node **node) 2406 unsigned int *bearer_id)
2374{ 2407{
2375 struct tipc_link *l_ptr; 2408 struct tipc_link *l_ptr;
2376 struct tipc_node *n_ptr; 2409 struct tipc_node *n_ptr;
2410 struct tipc_node *found_node = 0;
2377 int i; 2411 int i;
2378 2412
2379 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);
2380 for (i = 0; i < MAX_BEARERS; i++) { 2417 for (i = 0; i < MAX_BEARERS; i++) {
2381 l_ptr = n_ptr->links[i]; 2418 l_ptr = n_ptr->links[i];
2382 if (l_ptr && !strcmp(l_ptr->name, name)) 2419 if (l_ptr && !strcmp(l_ptr->name, link_name)) {
2383 goto found; 2420 *bearer_id = i;
2421 found_node = n_ptr;
2422 break;
2423 }
2384 } 2424 }
2425 tipc_node_unlock(n_ptr);
2426 if (found_node)
2427 break;
2385 } 2428 }
2386 l_ptr = NULL; 2429 rcu_read_unlock();
2387 n_ptr = NULL; 2430
2388found: 2431 return found_node;
2389 *node = n_ptr;
2390 return l_ptr;
2391} 2432}
2392 2433
2393/** 2434/**
@@ -2429,32 +2470,33 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)
2429 struct tipc_link *l_ptr; 2470 struct tipc_link *l_ptr;
2430 struct tipc_bearer *b_ptr; 2471 struct tipc_bearer *b_ptr;
2431 struct tipc_media *m_ptr; 2472 struct tipc_media *m_ptr;
2473 int bearer_id;
2432 int res = 0; 2474 int res = 0;
2433 2475
2434 l_ptr = link_find_link(name, &node); 2476 node = tipc_link_find_owner(name, &bearer_id);
2435 if (l_ptr) { 2477 if (node) {
2436 /*
2437 * acquire node lock for tipc_link_send_proto_msg().
2438 * see "TIPC locking policy" in net.c.
2439 */
2440 tipc_node_lock(node); 2478 tipc_node_lock(node);
2441 switch (cmd) { 2479 l_ptr = node->links[bearer_id];
2442 case TIPC_CMD_SET_LINK_TOL: 2480
2443 link_set_supervision_props(l_ptr, new_value); 2481 if (l_ptr) {
2444 tipc_link_send_proto_msg(l_ptr, 2482 switch (cmd) {
2445 STATE_MSG, 0, 0, new_value, 0, 0); 2483 case TIPC_CMD_SET_LINK_TOL:
2446 break; 2484 link_set_supervision_props(l_ptr, new_value);
2447 case TIPC_CMD_SET_LINK_PRI: 2485 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2448 l_ptr->priority = new_value; 2486 new_value, 0, 0);
2449 tipc_link_send_proto_msg(l_ptr, 2487 break;
2450 STATE_MSG, 0, 0, 0, new_value, 0); 2488 case TIPC_CMD_SET_LINK_PRI:
2451 break; 2489 l_ptr->priority = new_value;
2452 case TIPC_CMD_SET_LINK_WINDOW: 2490 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2453 tipc_link_set_queue_limits(l_ptr, new_value); 2491 0, new_value, 0);
2454 break; 2492 break;
2455 default: 2493 case TIPC_CMD_SET_LINK_WINDOW:
2456 res = -EINVAL; 2494 tipc_link_set_queue_limits(l_ptr, new_value);
2457 break; 2495 break;
2496 default:
2497 res = -EINVAL;
2498 break;
2499 }
2458 } 2500 }
2459 tipc_node_unlock(node); 2501 tipc_node_unlock(node);
2460 return res; 2502 return res;
@@ -2549,6 +2591,7 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_
2549 char *link_name; 2591 char *link_name;
2550 struct tipc_link *l_ptr; 2592 struct tipc_link *l_ptr;
2551 struct tipc_node *node; 2593 struct tipc_node *node;
2594 unsigned int bearer_id;
2552 2595
2553 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))
2554 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); 2597 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
@@ -2559,15 +2602,19 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_
2559 return tipc_cfg_reply_error_string("link not found"); 2602 return tipc_cfg_reply_error_string("link not found");
2560 return tipc_cfg_reply_none(); 2603 return tipc_cfg_reply_none();
2561 } 2604 }
2562
2563 read_lock_bh(&tipc_net_lock); 2605 read_lock_bh(&tipc_net_lock);
2564 l_ptr = link_find_link(link_name, &node); 2606 node = tipc_link_find_owner(link_name, &bearer_id);
2565 if (!l_ptr) { 2607 if (!node) {
2566 read_unlock_bh(&tipc_net_lock); 2608 read_unlock_bh(&tipc_net_lock);
2567 return tipc_cfg_reply_error_string("link not found"); 2609 return tipc_cfg_reply_error_string("link not found");
2568 } 2610 }
2569
2570 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 }
2571 link_reset_statistics(l_ptr); 2618 link_reset_statistics(l_ptr);
2572 tipc_node_unlock(node); 2619 tipc_node_unlock(node);
2573 read_unlock_bh(&tipc_net_lock); 2620 read_unlock_bh(&tipc_net_lock);
@@ -2597,18 +2644,27 @@ static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
2597 struct tipc_node *node; 2644 struct tipc_node *node;
2598 char *status; 2645 char *status;
2599 u32 profile_total = 0; 2646 u32 profile_total = 0;
2647 unsigned int bearer_id;
2600 int ret; 2648 int ret;
2601 2649
2602 if (!strcmp(name, tipc_bclink_name)) 2650 if (!strcmp(name, tipc_bclink_name))
2603 return tipc_bclink_stats(buf, buf_size); 2651 return tipc_bclink_stats(buf, buf_size);
2604 2652
2605 read_lock_bh(&tipc_net_lock); 2653 read_lock_bh(&tipc_net_lock);
2606 l = link_find_link(name, &node); 2654 node = tipc_link_find_owner(name, &bearer_id);
2607 if (!l) { 2655 if (!node) {
2608 read_unlock_bh(&tipc_net_lock); 2656 read_unlock_bh(&tipc_net_lock);
2609 return 0; 2657 return 0;
2610 } 2658 }
2611 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
2612 s = &l->stats; 2668 s = &l->stats;
2613 2669
2614 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;
215struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, 214struct 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);
218void tipc_link_delete(struct tipc_link *l_ptr); 217void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down);
219void tipc_link_failover_send_queue(struct tipc_link *l_ptr); 218void tipc_link_failover_send_queue(struct tipc_link *l_ptr);
220void tipc_link_dup_send_queue(struct tipc_link *l_ptr, 219void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, struct tipc_link *dest);
221 struct tipc_link *dest);
222void tipc_link_reset_fragments(struct tipc_link *l_ptr); 220void tipc_link_reset_fragments(struct tipc_link *l_ptr);
223int tipc_link_is_up(struct tipc_link *l_ptr); 221int tipc_link_is_up(struct tipc_link *l_ptr);
224int tipc_link_is_active(struct tipc_link *l_ptr); 222int 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,
231struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, 229struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area,
232 int req_tlv_space); 230 int req_tlv_space);
233void tipc_link_reset(struct tipc_link *l_ptr); 231void tipc_link_reset(struct tipc_link *l_ptr);
234int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector); 232void tipc_link_reset_list(unsigned int bearer_id);
235void tipc_link_send_names(struct list_head *message_list, u32 dest); 233int tipc_link_xmit(struct sk_buff *buf, u32 dest, u32 selector);
234void tipc_link_names_xmit(struct list_head *message_list, u32 dest);
235int __tipc_link_xmit(struct tipc_link *l_ptr, struct sk_buff *buf);
236int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf); 236int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf);
237u32 tipc_link_get_max_pkt(u32 dest, u32 selector); 237u32 tipc_link_get_max_pkt(u32 dest, u32 selector);
238int tipc_link_send_sections_fast(struct tipc_port *sender, 238int 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);
241void tipc_link_recv_bundle(struct sk_buff *buf); 241void tipc_link_bundle_rcv(struct sk_buff *buf);
242int tipc_link_recv_fragment(struct sk_buff **reasm_head, 242int 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);
245void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, int prob, 245void 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);
248void tipc_link_push_queue(struct tipc_link *l_ptr); 247void tipc_link_push_queue(struct tipc_link *l_ptr);
249u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, 248u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail,
250 struct sk_buff *buf); 249 struct sk_buff *buf);
251void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all); 250void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all);
252void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window); 251void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window);
253void tipc_link_retransmit(struct tipc_link *l_ptr, 252void 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 */
298void tipc_named_recv(struct sk_buff *buf) 306void 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 @@
42void tipc_named_publish(struct publication *publ); 42void tipc_named_publish(struct publication *publ);
43void tipc_named_withdraw(struct publication *publ); 43void tipc_named_withdraw(struct publication *publ);
44void tipc_named_node_up(unsigned long node); 44void tipc_named_node_up(unsigned long node);
45void tipc_named_recv(struct sk_buff *buf); 45void tipc_named_rcv(struct sk_buff *buf);
46void tipc_named_reinit(void); 46void tipc_named_reinit(void);
47 47
48#endif 48#endif
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 7d305ecc09c2..0374a817631e 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
174void tipc_net_start(u32 addr) 174void tipc_net_start(u32 addr)
@@ -182,8 +182,6 @@ 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();
186
187 pr_info("Started in network mode\n"); 185 pr_info("Started in network mode\n");
188 pr_info("Own node address %s, network identity %u\n", 186 pr_info("Own node address %s, network identity %u\n",
189 tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); 187 tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id);
@@ -191,15 +189,14 @@ void tipc_net_start(u32 addr)
191 189
192void tipc_net_stop(void) 190void tipc_net_stop(void)
193{ 191{
194 struct tipc_node *node, *t_node;
195
196 if (!tipc_own_addr) 192 if (!tipc_own_addr)
197 return; 193 return;
194
198 write_lock_bh(&tipc_net_lock); 195 write_lock_bh(&tipc_net_lock);
199 tipc_bearer_stop(); 196 tipc_bearer_stop();
200 tipc_bclink_stop(); 197 tipc_bclink_stop();
201 list_for_each_entry_safe(node, t_node, &tipc_node_list, list) 198 tipc_node_stop();
202 tipc_node_delete(node);
203 write_unlock_bh(&tipc_net_lock); 199 write_unlock_bh(&tipc_net_lock);
200
204 pr_info("Left network mode\n"); 201 pr_info("Left network mode\n");
205} 202}
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 @@
44static void node_lost_contact(struct tipc_node *n_ptr); 44static void node_lost_contact(struct tipc_node *n_ptr);
45static void node_established_contact(struct tipc_node *n_ptr); 45static void node_established_contact(struct tipc_node *n_ptr);
46 46
47static DEFINE_SPINLOCK(node_create_lock);
48
49static struct hlist_head node_htable[NODE_HTABLE_SIZE]; 47static struct hlist_head node_htable[NODE_HTABLE_SIZE];
50LIST_HEAD(tipc_node_list); 48LIST_HEAD(tipc_node_list);
51static u32 tipc_num_nodes; 49static u32 tipc_num_nodes;
52 50static u32 tipc_num_links;
53static atomic_t tipc_num_links = ATOMIC_INIT(0); 51static 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 */
92struct tipc_node *tipc_node_create(u32 addr) 85struct 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
133void tipc_node_delete(struct tipc_node *n_ptr) 120static 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
129void 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)
243void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) 240void 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
250void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) 249void 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
257static void node_established_contact(struct tipc_node *n_ptr) 264static 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
108struct tipc_node *tipc_node_find(u32 addr); 110struct tipc_node *tipc_node_find(u32 addr);
109struct tipc_node *tipc_node_create(u32 addr); 111struct tipc_node *tipc_node_create(u32 addr);
110void tipc_node_delete(struct tipc_node *n_ptr); 112void tipc_node_stop(void);
111void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); 113void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
112void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); 114void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
113void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); 115void 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);
54static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err); 55static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err);
55static void port_timeout(unsigned long ref); 56static void port_timeout(unsigned long ref);
56 57
57
58static u32 port_peernode(struct tipc_port *p_ptr)
59{
60 return msg_destnode(&p_ptr->phdr);
61}
62
63static 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 */
92int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, 83int 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 */
155void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp) 144void 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 }
197exit: 186exit:
@@ -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 192void 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 */
207struct tipc_port *tipc_createport(struct sock *sk, 201u32 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
254int tipc_deleteport(struct tipc_port *p_ptr) 235void 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
280static int port_unreliable(struct tipc_port *p_ptr)
281{
282 return msg_src_droppable(&p_ptr->phdr);
283}
284
285int 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
297int 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
309static int port_unreturnable(struct tipc_port *p_ptr)
310{
311 return msg_dest_droppable(&p_ptr->phdr);
312}
313
314int 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
326int 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));
428exit: 349exit:
429 kfree_skb(buf); 350 kfree_skb(buf);
430 return data_sz; 351 return data_sz;
431} 352}
432 353
433int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, 354int 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
522void tipc_port_recv_proto_msg(struct sk_buff *buf) 443void 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
676int 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
688int 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
704int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, 596int 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
763int tipc_connect(u32 ref, struct tipc_portid const *peer) 655int 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 */
781int __tipc_connect(u32 ref, struct tipc_port *p_ptr, 673int __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 */
818int __tipc_disconnect(struct tipc_port *tp_ptr) 710int __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 */
834int tipc_disconnect(u32 ref) 726int 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 */
850int tipc_shutdown(u32 ref) 742int 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 */
868int tipc_port_recv_msg(struct sk_buff *buf) 760int 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 */
900static int tipc_port_recv_sections(struct tipc_port *sender, 792static 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 */
916int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) 808int 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 */
952int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, 844int 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 */
1001int tipc_send2port(u32 ref, struct tipc_portid const *dest, 894int 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 */
76struct tipc_port { 73struct 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 */
109struct tipc_port *tipc_createport(struct sock *sk, 103u32 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
115int tipc_reject_msg(struct sk_buff *buf, u32 err); 106int tipc_reject_msg(struct sk_buff *buf, u32 err);
116 107
117void tipc_acknowledge(u32 port_ref, u32 ack); 108void tipc_acknowledge(u32 port_ref, u32 ack);
118 109
119int tipc_deleteport(struct tipc_port *p_ptr); 110void tipc_port_destroy(struct tipc_port *p_ptr);
120
121int tipc_portimportance(u32 portref, unsigned int *importance);
122int tipc_set_portimportance(u32 portref, unsigned int importance);
123
124int tipc_portunreliable(u32 portref, unsigned int *isunreliable);
125int tipc_set_portunreliable(u32 portref, unsigned int isunreliable);
126
127int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable);
128int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable);
129 111
130int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, 112int 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
132int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, 115int 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
135int tipc_connect(u32 portref, struct tipc_portid const *port); 118int tipc_port_connect(u32 portref, struct tipc_portid const *port);
136 119
137int tipc_disconnect(u32 portref); 120int tipc_port_disconnect(u32 portref);
138 121
139int tipc_shutdown(u32 ref); 122int tipc_port_shutdown(u32 ref);
140 123
124void 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 */
145int __tipc_disconnect(struct tipc_port *tp_ptr); 129int __tipc_port_disconnect(struct tipc_port *tp_ptr);
146int __tipc_connect(u32 ref, struct tipc_port *p_ptr, 130int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr,
147 struct tipc_portid const *peer); 131 struct tipc_portid const *peer);
148int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg); 132int 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 */
153int tipc_port_recv_msg(struct sk_buff *buf); 137int tipc_port_rcv(struct sk_buff *buf);
154int tipc_send(u32 portref, struct iovec const *msg_sect, unsigned int len); 138
155 139int tipc_send(struct tipc_port *port,
156int 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
143int 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
149int tipc_send2port(struct tipc_port *port,
150 struct tipc_portid const *dest,
151 struct iovec const *msg_sect,
152 unsigned int len);
153
154int 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
159int 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
159int tipc_send2port(u32 portref, struct tipc_portid const *dest,
160 struct iovec const *msg_sect, unsigned int len);
161
162int tipc_multicast(u32 portref, struct tipc_name_seq const *seq,
163 struct iovec const *msg, unsigned int len);
164
165int 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);
168struct sk_buff *tipc_port_get_ports(void); 165struct sk_buff *tipc_port_get_ports(void);
169void tipc_port_recv_proto_msg(struct sk_buff *buf); 166void tipc_port_proto_rcv(struct sk_buff *buf);
170void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp); 167void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp);
171void tipc_port_reinit(void); 168void 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
191static inline struct tipc_port *tipc_port_deref(u32 ref) 188static 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
196static inline int tipc_port_congested(struct tipc_port *p_ptr) 193
194static 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
199static inline u32 tipc_port_peerport(struct tipc_port *p_ptr)
200{
201 return msg_destport(&p_ptr->phdr);
202}
203
204static inline bool tipc_port_unreliable(struct tipc_port *port)
205{
206 return msg_src_droppable(&port->phdr) != 0;
207}
208
209static 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
215static inline bool tipc_port_unreturnable(struct tipc_port *port)
216{
217 return msg_dest_droppable(&port->phdr) != 0;
218}
219
220static 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
227static inline int tipc_port_importance(struct tipc_port *port)
228{
229 return msg_importance(&port->phdr);
230}
231
232static 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 de3d593e2fee..3d4ecd754eee 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -89,7 +89,7 @@ struct ref_table {
89 89
90static struct ref_table tipc_ref_table; 90static struct ref_table tipc_ref_table;
91 91
92static DEFINE_RWLOCK(ref_table_lock); 92static 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
@@ -159,7 +159,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
159 } 159 }
160 160
161 /* take a free entry, if available; otherwise initialize a new entry */ 161 /* take a free entry, if available; otherwise initialize a new entry */
162 write_lock_bh(&ref_table_lock); 162 spin_lock_bh(&ref_table_lock);
163 if (tipc_ref_table.first_free) { 163 if (tipc_ref_table.first_free) {
164 index = tipc_ref_table.first_free; 164 index = tipc_ref_table.first_free;
165 entry = &(tipc_ref_table.entries[index]); 165 entry = &(tipc_ref_table.entries[index]);
@@ -175,7 +175,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
175 } else { 175 } else {
176 ref = 0; 176 ref = 0;
177 } 177 }
178 write_unlock_bh(&ref_table_lock); 178 spin_unlock_bh(&ref_table_lock);
179 179
180 /* 180 /*
181 * Grab the lock so no one else can modify this entry 181 * Grab the lock so no one else can modify this entry
@@ -216,7 +216,7 @@ void tipc_ref_discard(u32 ref)
216 index = ref & index_mask; 216 index = ref & index_mask;
217 entry = &(tipc_ref_table.entries[index]); 217 entry = &(tipc_ref_table.entries[index]);
218 218
219 write_lock_bh(&ref_table_lock); 219 spin_lock_bh(&ref_table_lock);
220 220
221 if (!entry->object) { 221 if (!entry->object) {
222 pr_err("Attempt to discard ref. to non-existent obj\n"); 222 pr_err("Attempt to discard ref. to non-existent obj\n");
@@ -242,7 +242,7 @@ void tipc_ref_discard(u32 ref)
242 tipc_ref_table.last_free = index; 242 tipc_ref_table.last_free = index;
243 243
244exit: 244exit:
245 write_unlock_bh(&ref_table_lock); 245 spin_unlock_bh(&ref_table_lock);
246} 246}
247 247
248/** 248/**
@@ -264,20 +264,3 @@ void *tipc_ref_lock(u32 ref)
264 } 264 }
265 return NULL; 265 return NULL;
266} 266}
267
268
269/**
270 * tipc_ref_deref - return pointer referenced object (without locking it)
271 */
272void *tipc_ref_deref(u32 ref)
273{
274 if (likely(tipc_ref_table.entries)) {
275 struct reference *entry;
276
277 entry = &tipc_ref_table.entries[ref &
278 tipc_ref_table.index_mask];
279 if (likely(entry->ref == ref))
280 return entry->object;
281 }
282 return NULL;
283}
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);
44void tipc_ref_discard(u32 ref); 44void tipc_ref_discard(u32 ref);
45 45
46void *tipc_ref_lock(u32 ref); 46void *tipc_ref_lock(u32 ref);
47void *tipc_ref_deref(u32 ref);
48 47
49#endif 48#endif
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 0ed0eaa62f29..29b7f26a12cf 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
48struct 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
58static int backlog_rcv(struct sock *sk, struct sk_buff *skb); 47static int backlog_rcv(struct sock *sk, struct sk_buff *skb);
59static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
60static void wakeupdispatch(struct tipc_port *tport);
61static void tipc_data_ready(struct sock *sk, int len); 48static void tipc_data_ready(struct sock *sk, int len);
62static void tipc_write_space(struct sock *sk); 49static void tipc_write_space(struct sock *sk);
63static int release(struct socket *sock); 50static int tipc_release(struct socket *sock);
64static int accept(struct socket *sock, struct socket *new_sock, int flags); 51static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
65 52
66static const struct proto_ops packet_ops; 53static const struct proto_ops packet_ops;
67static const struct proto_ops stream_ops; 54static const struct proto_ops stream_ops;
@@ -115,6 +102,8 @@ static struct proto tipc_proto_kern;
115 * - port reference 102 * - port reference
116 */ 103 */
117 104
105#include "socket.h"
106
118/** 107/**
119 * advance_rx_queue - discard first buffer in socket receive queue 108 * advance_rx_queue - discard first buffer in socket receive queue
120 * 109 *
@@ -150,13 +139,15 @@ static void reject_rx_queue(struct sock *sk)
150 * 139 *
151 * Returns 0 on success, errno otherwise 140 * Returns 0 on success, errno otherwise
152 */ 141 */
153static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, 142static int tipc_sk_create(struct net *net, struct socket *sock,
154 int kern) 143 int protocol, int kern)
155{ 144{
156 const struct proto_ops *ops; 145 const struct proto_ops *ops;
157 socket_state state; 146 socket_state state;
158 struct sock *sk; 147 struct sock *sk;
159 struct tipc_port *tp_ptr; 148 struct tipc_sock *tsk;
149 struct tipc_port *port;
150 u32 ref;
160 151
161 /* Validate arguments */ 152 /* Validate arguments */
162 if (unlikely(protocol != 0)) 153 if (unlikely(protocol != 0))
@@ -189,10 +180,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
189 if (sk == NULL) 180 if (sk == NULL)
190 return -ENOMEM; 181 return -ENOMEM;
191 182
192 /* Allocate TIPC port for socket to use */ 183 tsk = tipc_sk(sk);
193 tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch, 184 port = &tsk->port;
194 TIPC_LOW_IMPORTANCE); 185
195 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");
196 sk_free(sk); 189 sk_free(sk);
197 return -ENOMEM; 190 return -ENOMEM;
198 } 191 }
@@ -206,17 +199,14 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
206 sk->sk_rcvbuf = sysctl_tipc_rmem[1]; 199 sk->sk_rcvbuf = sysctl_tipc_rmem[1];
207 sk->sk_data_ready = tipc_data_ready; 200 sk->sk_data_ready = tipc_data_ready;
208 sk->sk_write_space = tipc_write_space; 201 sk->sk_write_space = tipc_write_space;
209 tipc_sk(sk)->p = tp_ptr;
210 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; 202 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
211 203 tipc_port_unlock(port);
212 spin_unlock_bh(tp_ptr->lock);
213 204
214 if (sock->state == SS_READY) { 205 if (sock->state == SS_READY) {
215 tipc_set_portunreturnable(tp_ptr->ref, 1); 206 tipc_port_set_unreturnable(port, true);
216 if (sock->type == SOCK_DGRAM) 207 if (sock->type == SOCK_DGRAM)
217 tipc_set_portunreliable(tp_ptr->ref, 1); 208 tipc_port_set_unreliable(port, true);
218 } 209 }
219
220 return 0; 210 return 0;
221} 211}
222 212
@@ -254,7 +244,7 @@ int tipc_sock_create_local(int type, struct socket **res)
254 */ 244 */
255void tipc_sock_release_local(struct socket *sock) 245void tipc_sock_release_local(struct socket *sock)
256{ 246{
257 release(sock); 247 tipc_release(sock);
258 sock->ops = NULL; 248 sock->ops = NULL;
259 sock_release(sock); 249 sock_release(sock);
260} 250}
@@ -280,7 +270,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
280 if (ret < 0) 270 if (ret < 0)
281 return ret; 271 return ret;
282 272
283 ret = accept(sock, *newsock, flags); 273 ret = tipc_accept(sock, *newsock, flags);
284 if (ret < 0) { 274 if (ret < 0) {
285 sock_release(*newsock); 275 sock_release(*newsock);
286 return ret; 276 return ret;
@@ -290,7 +280,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
290} 280}
291 281
292/** 282/**
293 * release - destroy a TIPC socket 283 * tipc_release - destroy a TIPC socket
294 * @sock: socket to destroy 284 * @sock: socket to destroy
295 * 285 *
296 * 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.
@@ -305,10 +295,11 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
305 * 295 *
306 * Returns 0 on success, errno otherwise 296 * Returns 0 on success, errno otherwise
307 */ 297 */
308static int release(struct socket *sock) 298static int tipc_release(struct socket *sock)
309{ 299{
310 struct sock *sk = sock->sk; 300 struct sock *sk = sock->sk;
311 struct tipc_port *tport; 301 struct tipc_sock *tsk;
302 struct tipc_port *port;
312 struct sk_buff *buf; 303 struct sk_buff *buf;
313 int res; 304 int res;
314 305
@@ -319,7 +310,8 @@ static int release(struct socket *sock)
319 if (sk == NULL) 310 if (sk == NULL)
320 return 0; 311 return 0;
321 312
322 tport = tipc_sk_port(sk); 313 tsk = tipc_sk(sk);
314 port = &tsk->port;
323 lock_sock(sk); 315 lock_sock(sk);
324 316
325 /* 317 /*
@@ -336,17 +328,16 @@ static int release(struct socket *sock)
336 if ((sock->state == SS_CONNECTING) || 328 if ((sock->state == SS_CONNECTING) ||
337 (sock->state == SS_CONNECTED)) { 329 (sock->state == SS_CONNECTED)) {
338 sock->state = SS_DISCONNECTING; 330 sock->state = SS_DISCONNECTING;
339 tipc_disconnect(tport->ref); 331 tipc_port_disconnect(port->ref);
340 } 332 }
341 tipc_reject_msg(buf, TIPC_ERR_NO_PORT); 333 tipc_reject_msg(buf, TIPC_ERR_NO_PORT);
342 } 334 }
343 } 335 }
344 336
345 /* 337 /* Destroy TIPC port; also disconnects an active connection and
346 * Delete TIPC port; this ensures no more messages are queued 338 * sends a 'FIN-' to peer.
347 * (also disconnects an active connection & sends a 'FIN-' to peer)
348 */ 339 */
349 res = tipc_deleteport(tport); 340 tipc_port_destroy(port);
350 341
351 /* Discard any remaining (connection-based) messages in receive queue */ 342 /* Discard any remaining (connection-based) messages in receive queue */
352 __skb_queue_purge(&sk->sk_receive_queue); 343 __skb_queue_purge(&sk->sk_receive_queue);
@@ -362,7 +353,7 @@ static int release(struct socket *sock)
362} 353}
363 354
364/** 355/**
365 * bind - associate or disassocate TIPC name(s) with a socket 356 * tipc_bind - associate or disassocate TIPC name(s) with a socket
366 * @sock: socket structure 357 * @sock: socket structure
367 * @uaddr: socket address describing name(s) and desired operation 358 * @uaddr: socket address describing name(s) and desired operation
368 * @uaddr_len: size of socket address data structure 359 * @uaddr_len: size of socket address data structure
@@ -376,16 +367,17 @@ static int release(struct socket *sock)
376 * NOTE: This routine doesn't need to take the socket lock since it doesn't 367 * NOTE: This routine doesn't need to take the socket lock since it doesn't
377 * access any non-constant socket information. 368 * access any non-constant socket information.
378 */ 369 */
379static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) 370static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
371 int uaddr_len)
380{ 372{
381 struct sock *sk = sock->sk; 373 struct sock *sk = sock->sk;
382 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 374 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
383 struct tipc_port *tport = tipc_sk_port(sock->sk); 375 struct tipc_sock *tsk = tipc_sk(sk);
384 int res = -EINVAL; 376 int res = -EINVAL;
385 377
386 lock_sock(sk); 378 lock_sock(sk);
387 if (unlikely(!uaddr_len)) { 379 if (unlikely(!uaddr_len)) {
388 res = tipc_withdraw(tport, 0, NULL); 380 res = tipc_withdraw(&tsk->port, 0, NULL);
389 goto exit; 381 goto exit;
390 } 382 }
391 383
@@ -413,15 +405,15 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
413 } 405 }
414 406
415 res = (addr->scope > 0) ? 407 res = (addr->scope > 0) ?
416 tipc_publish(tport, addr->scope, &addr->addr.nameseq) : 408 tipc_publish(&tsk->port, addr->scope, &addr->addr.nameseq) :
417 tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq); 409 tipc_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq);
418exit: 410exit:
419 release_sock(sk); 411 release_sock(sk);
420 return res; 412 return res;
421} 413}
422 414
423/** 415/**
424 * get_name - get port ID of socket or peer socket 416 * tipc_getname - get port ID of socket or peer socket
425 * @sock: socket structure 417 * @sock: socket structure
426 * @uaddr: area for returned socket address 418 * @uaddr: area for returned socket address
427 * @uaddr_len: area for returned length of socket address 419 * @uaddr_len: area for returned length of socket address
@@ -433,21 +425,21 @@ exit:
433 * accesses socket information that is unchanging (or which changes in 425 * accesses socket information that is unchanging (or which changes in
434 * a completely predictable manner). 426 * a completely predictable manner).
435 */ 427 */
436static int get_name(struct socket *sock, struct sockaddr *uaddr, 428static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
437 int *uaddr_len, int peer) 429 int *uaddr_len, int peer)
438{ 430{
439 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 431 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
440 struct tipc_sock *tsock = tipc_sk(sock->sk); 432 struct tipc_sock *tsk = tipc_sk(sock->sk);
441 433
442 memset(addr, 0, sizeof(*addr)); 434 memset(addr, 0, sizeof(*addr));
443 if (peer) { 435 if (peer) {
444 if ((sock->state != SS_CONNECTED) && 436 if ((sock->state != SS_CONNECTED) &&
445 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 437 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
446 return -ENOTCONN; 438 return -ENOTCONN;
447 addr->addr.id.ref = tsock->peer_name.ref; 439 addr->addr.id.ref = tipc_port_peerport(&tsk->port);
448 addr->addr.id.node = tsock->peer_name.node; 440 addr->addr.id.node = tipc_port_peernode(&tsk->port);
449 } else { 441 } else {
450 addr->addr.id.ref = tsock->p->ref; 442 addr->addr.id.ref = tsk->port.ref;
451 addr->addr.id.node = tipc_own_addr; 443 addr->addr.id.node = tipc_own_addr;
452 } 444 }
453 445
@@ -461,7 +453,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
461} 453}
462 454
463/** 455/**
464 * poll - read and possibly block on pollmask 456 * tipc_poll - read and possibly block on pollmask
465 * @file: file structure associated with the socket 457 * @file: file structure associated with the socket
466 * @sock: socket for which to calculate the poll bits 458 * @sock: socket for which to calculate the poll bits
467 * @wait: ??? 459 * @wait: ???
@@ -500,22 +492,23 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
500 * imply that the operation will succeed, merely that it should be performed 492 * imply that the operation will succeed, merely that it should be performed
501 * and will not block. 493 * and will not block.
502 */ 494 */
503static unsigned int poll(struct file *file, struct socket *sock, 495static unsigned int tipc_poll(struct file *file, struct socket *sock,
504 poll_table *wait) 496 poll_table *wait)
505{ 497{
506 struct sock *sk = sock->sk; 498 struct sock *sk = sock->sk;
499 struct tipc_sock *tsk = tipc_sk(sk);
507 u32 mask = 0; 500 u32 mask = 0;
508 501
509 sock_poll_wait(file, sk_sleep(sk), wait); 502 sock_poll_wait(file, sk_sleep(sk), wait);
510 503
511 switch ((int)sock->state) { 504 switch ((int)sock->state) {
512 case SS_UNCONNECTED: 505 case SS_UNCONNECTED:
513 if (!tipc_sk_port(sk)->congested) 506 if (!tsk->port.congested)
514 mask |= POLLOUT; 507 mask |= POLLOUT;
515 break; 508 break;
516 case SS_READY: 509 case SS_READY:
517 case SS_CONNECTED: 510 case SS_CONNECTED:
518 if (!tipc_sk_port(sk)->congested) 511 if (!tsk->port.congested)
519 mask |= POLLOUT; 512 mask |= POLLOUT;
520 /* fall thru' */ 513 /* fall thru' */
521 case SS_CONNECTING: 514 case SS_CONNECTING:
@@ -565,7 +558,7 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
565static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) 558static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
566{ 559{
567 struct sock *sk = sock->sk; 560 struct sock *sk = sock->sk;
568 struct tipc_port *tport = tipc_sk_port(sk); 561 struct tipc_sock *tsk = tipc_sk(sk);
569 DEFINE_WAIT(wait); 562 DEFINE_WAIT(wait);
570 int done; 563 int done;
571 564
@@ -581,14 +574,15 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
581 return sock_intr_errno(*timeo_p); 574 return sock_intr_errno(*timeo_p);
582 575
583 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 576 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
584 done = sk_wait_event(sk, timeo_p, !tport->congested); 577 done = sk_wait_event(sk, timeo_p, !tsk->port.congested);
585 finish_wait(sk_sleep(sk), &wait); 578 finish_wait(sk_sleep(sk), &wait);
586 } while (!done); 579 } while (!done);
587 return 0; 580 return 0;
588} 581}
589 582
583
590/** 584/**
591 * send_msg - send message in connectionless manner 585 * tipc_sendmsg - send message in connectionless manner
592 * @iocb: if NULL, indicates that socket lock is already held 586 * @iocb: if NULL, indicates that socket lock is already held
593 * @sock: socket structure 587 * @sock: socket structure
594 * @m: message to send 588 * @m: message to send
@@ -601,11 +595,12 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
601 * 595 *
602 * Returns the number of bytes sent on success, or errno otherwise 596 * Returns the number of bytes sent on success, or errno otherwise
603 */ 597 */
604static int send_msg(struct kiocb *iocb, struct socket *sock, 598static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
605 struct msghdr *m, size_t total_len) 599 struct msghdr *m, size_t total_len)
606{ 600{
607 struct sock *sk = sock->sk; 601 struct sock *sk = sock->sk;
608 struct tipc_port *tport = tipc_sk_port(sk); 602 struct tipc_sock *tsk = tipc_sk(sk);
603 struct tipc_port *port = &tsk->port;
609 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 604 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
610 int needs_conn; 605 int needs_conn;
611 long timeo; 606 long timeo;
@@ -632,13 +627,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
632 res = -EISCONN; 627 res = -EISCONN;
633 goto exit; 628 goto exit;
634 } 629 }
635 if (tport->published) { 630 if (tsk->port.published) {
636 res = -EOPNOTSUPP; 631 res = -EOPNOTSUPP;
637 goto exit; 632 goto exit;
638 } 633 }
639 if (dest->addrtype == TIPC_ADDR_NAME) { 634 if (dest->addrtype == TIPC_ADDR_NAME) {
640 tport->conn_type = dest->addr.name.name.type; 635 tsk->port.conn_type = dest->addr.name.name.type;
641 tport->conn_instance = dest->addr.name.name.instance; 636 tsk->port.conn_instance = dest->addr.name.name.instance;
642 } 637 }
643 638
644 /* Abort any pending connection attempts (very unlikely) */ 639 /* Abort any pending connection attempts (very unlikely) */
@@ -651,13 +646,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
651 res = dest_name_check(dest, m); 646 res = dest_name_check(dest, m);
652 if (res) 647 if (res)
653 break; 648 break;
654 res = tipc_send2name(tport->ref, 649 res = tipc_send2name(port,
655 &dest->addr.name.name, 650 &dest->addr.name.name,
656 dest->addr.name.domain, 651 dest->addr.name.domain,
657 m->msg_iov, 652 m->msg_iov,
658 total_len); 653 total_len);
659 } else if (dest->addrtype == TIPC_ADDR_ID) { 654 } else if (dest->addrtype == TIPC_ADDR_ID) {
660 res = tipc_send2port(tport->ref, 655 res = tipc_send2port(port,
661 &dest->addr.id, 656 &dest->addr.id,
662 m->msg_iov, 657 m->msg_iov,
663 total_len); 658 total_len);
@@ -669,10 +664,10 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
669 res = dest_name_check(dest, m); 664 res = dest_name_check(dest, m);
670 if (res) 665 if (res)
671 break; 666 break;
672 res = tipc_multicast(tport->ref, 667 res = tipc_port_mcast_xmit(port,
673 &dest->addr.nameseq, 668 &dest->addr.nameseq,
674 m->msg_iov, 669 m->msg_iov,
675 total_len); 670 total_len);
676 } 671 }
677 if (likely(res != -ELINKCONG)) { 672 if (likely(res != -ELINKCONG)) {
678 if (needs_conn && (res >= 0)) 673 if (needs_conn && (res >= 0))
@@ -693,7 +688,8 @@ exit:
693static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) 688static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
694{ 689{
695 struct sock *sk = sock->sk; 690 struct sock *sk = sock->sk;
696 struct tipc_port *tport = tipc_sk_port(sk); 691 struct tipc_sock *tsk = tipc_sk(sk);
692 struct tipc_port *port = &tsk->port;
697 DEFINE_WAIT(wait); 693 DEFINE_WAIT(wait);
698 int done; 694 int done;
699 695
@@ -712,14 +708,14 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
712 708
713 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 709 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
714 done = sk_wait_event(sk, timeo_p, 710 done = sk_wait_event(sk, timeo_p,
715 (!tport->congested || !tport->connected)); 711 (!port->congested || !port->connected));
716 finish_wait(sk_sleep(sk), &wait); 712 finish_wait(sk_sleep(sk), &wait);
717 } while (!done); 713 } while (!done);
718 return 0; 714 return 0;
719} 715}
720 716
721/** 717/**
722 * send_packet - send a connection-oriented message 718 * tipc_send_packet - send a connection-oriented message
723 * @iocb: if NULL, indicates that socket lock is already held 719 * @iocb: if NULL, indicates that socket lock is already held
724 * @sock: socket structure 720 * @sock: socket structure
725 * @m: message to send 721 * @m: message to send
@@ -729,18 +725,18 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
729 * 725 *
730 * Returns the number of bytes sent on success, or errno otherwise 726 * Returns the number of bytes sent on success, or errno otherwise
731 */ 727 */
732static int send_packet(struct kiocb *iocb, struct socket *sock, 728static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
733 struct msghdr *m, size_t total_len) 729 struct msghdr *m, size_t total_len)
734{ 730{
735 struct sock *sk = sock->sk; 731 struct sock *sk = sock->sk;
736 struct tipc_port *tport = tipc_sk_port(sk); 732 struct tipc_sock *tsk = tipc_sk(sk);
737 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 733 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
738 int res = -EINVAL; 734 int res = -EINVAL;
739 long timeo; 735 long timeo;
740 736
741 /* Handle implied connection establishment */ 737 /* Handle implied connection establishment */
742 if (unlikely(dest)) 738 if (unlikely(dest))
743 return send_msg(iocb, sock, m, total_len); 739 return tipc_sendmsg(iocb, sock, m, total_len);
744 740
745 if (total_len > TIPC_MAX_USER_MSG_SIZE) 741 if (total_len > TIPC_MAX_USER_MSG_SIZE)
746 return -EMSGSIZE; 742 return -EMSGSIZE;
@@ -758,7 +754,7 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
758 754
759 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); 755 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
760 do { 756 do {
761 res = tipc_send(tport->ref, m->msg_iov, total_len); 757 res = tipc_send(&tsk->port, m->msg_iov, total_len);
762 if (likely(res != -ELINKCONG)) 758 if (likely(res != -ELINKCONG))
763 break; 759 break;
764 res = tipc_wait_for_sndpkt(sock, &timeo); 760 res = tipc_wait_for_sndpkt(sock, &timeo);
@@ -772,7 +768,7 @@ exit:
772} 768}
773 769
774/** 770/**
775 * send_stream - send stream-oriented data 771 * tipc_send_stream - send stream-oriented data
776 * @iocb: (unused) 772 * @iocb: (unused)
777 * @sock: socket structure 773 * @sock: socket structure
778 * @m: data to send 774 * @m: data to send
@@ -783,11 +779,11 @@ exit:
783 * Returns the number of bytes sent on success (or partial success), 779 * Returns the number of bytes sent on success (or partial success),
784 * or errno if no data sent 780 * or errno if no data sent
785 */ 781 */
786static int send_stream(struct kiocb *iocb, struct socket *sock, 782static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
787 struct msghdr *m, size_t total_len) 783 struct msghdr *m, size_t total_len)
788{ 784{
789 struct sock *sk = sock->sk; 785 struct sock *sk = sock->sk;
790 struct tipc_port *tport = tipc_sk_port(sk); 786 struct tipc_sock *tsk = tipc_sk(sk);
791 struct msghdr my_msg; 787 struct msghdr my_msg;
792 struct iovec my_iov; 788 struct iovec my_iov;
793 struct iovec *curr_iov; 789 struct iovec *curr_iov;
@@ -804,7 +800,7 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
804 /* Handle special cases where there is no connection */ 800 /* Handle special cases where there is no connection */
805 if (unlikely(sock->state != SS_CONNECTED)) { 801 if (unlikely(sock->state != SS_CONNECTED)) {
806 if (sock->state == SS_UNCONNECTED) 802 if (sock->state == SS_UNCONNECTED)
807 res = send_packet(NULL, sock, m, total_len); 803 res = tipc_send_packet(NULL, sock, m, total_len);
808 else 804 else
809 res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; 805 res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN;
810 goto exit; 806 goto exit;
@@ -835,21 +831,22 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
835 my_msg.msg_name = NULL; 831 my_msg.msg_name = NULL;
836 bytes_sent = 0; 832 bytes_sent = 0;
837 833
838 hdr_size = msg_hdr_sz(&tport->phdr); 834 hdr_size = msg_hdr_sz(&tsk->port.phdr);
839 835
840 while (curr_iovlen--) { 836 while (curr_iovlen--) {
841 curr_start = curr_iov->iov_base; 837 curr_start = curr_iov->iov_base;
842 curr_left = curr_iov->iov_len; 838 curr_left = curr_iov->iov_len;
843 839
844 while (curr_left) { 840 while (curr_left) {
845 bytes_to_send = tport->max_pkt - hdr_size; 841 bytes_to_send = tsk->port.max_pkt - hdr_size;
846 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) 842 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE)
847 bytes_to_send = TIPC_MAX_USER_MSG_SIZE; 843 bytes_to_send = TIPC_MAX_USER_MSG_SIZE;
848 if (curr_left < bytes_to_send) 844 if (curr_left < bytes_to_send)
849 bytes_to_send = curr_left; 845 bytes_to_send = curr_left;
850 my_iov.iov_base = curr_start; 846 my_iov.iov_base = curr_start;
851 my_iov.iov_len = bytes_to_send; 847 my_iov.iov_len = bytes_to_send;
852 res = send_packet(NULL, sock, &my_msg, bytes_to_send); 848 res = tipc_send_packet(NULL, sock, &my_msg,
849 bytes_to_send);
853 if (res < 0) { 850 if (res < 0) {
854 if (bytes_sent) 851 if (bytes_sent)
855 res = bytes_sent; 852 res = bytes_sent;
@@ -870,27 +867,25 @@ exit:
870 867
871/** 868/**
872 * auto_connect - complete connection setup to a remote port 869 * auto_connect - complete connection setup to a remote port
873 * @sock: socket structure 870 * @tsk: tipc socket structure
874 * @msg: peer's response message 871 * @msg: peer's response message
875 * 872 *
876 * Returns 0 on success, errno otherwise 873 * Returns 0 on success, errno otherwise
877 */ 874 */
878static int auto_connect(struct socket *sock, struct tipc_msg *msg) 875static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg)
879{ 876{
880 struct tipc_sock *tsock = tipc_sk(sock->sk); 877 struct tipc_port *port = &tsk->port;
881 struct tipc_port *p_ptr; 878 struct socket *sock = tsk->sk.sk_socket;
879 struct tipc_portid peer;
882 880
883 tsock->peer_name.ref = msg_origport(msg); 881 peer.ref = msg_origport(msg);
884 tsock->peer_name.node = msg_orignode(msg); 882 peer.node = msg_orignode(msg);
885 p_ptr = tipc_port_deref(tsock->p->ref);
886 if (!p_ptr)
887 return -EINVAL;
888 883
889 __tipc_connect(tsock->p->ref, p_ptr, &tsock->peer_name); 884 __tipc_port_connect(port->ref, port, &peer);
890 885
891 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) 886 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)
892 return -EINVAL; 887 return -EINVAL;
893 msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg)); 888 msg_set_importance(&port->phdr, (u32)msg_importance(msg));
894 sock->state = SS_CONNECTED; 889 sock->state = SS_CONNECTED;
895 return 0; 890 return 0;
896} 891}
@@ -1021,7 +1016,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
1021} 1016}
1022 1017
1023/** 1018/**
1024 * recv_msg - receive packet-oriented message 1019 * tipc_recvmsg - receive packet-oriented message
1025 * @iocb: (unused) 1020 * @iocb: (unused)
1026 * @m: descriptor for message info 1021 * @m: descriptor for message info
1027 * @buf_len: total size of user buffer area 1022 * @buf_len: total size of user buffer area
@@ -1032,11 +1027,12 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
1032 * 1027 *
1033 * Returns size of returned message data, errno otherwise 1028 * Returns size of returned message data, errno otherwise
1034 */ 1029 */
1035static int recv_msg(struct kiocb *iocb, struct socket *sock, 1030static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock,
1036 struct msghdr *m, size_t buf_len, int flags) 1031 struct msghdr *m, size_t buf_len, int flags)
1037{ 1032{
1038 struct sock *sk = sock->sk; 1033 struct sock *sk = sock->sk;
1039 struct tipc_port *tport = tipc_sk_port(sk); 1034 struct tipc_sock *tsk = tipc_sk(sk);
1035 struct tipc_port *port = &tsk->port;
1040 struct sk_buff *buf; 1036 struct sk_buff *buf;
1041 struct tipc_msg *msg; 1037 struct tipc_msg *msg;
1042 long timeo; 1038 long timeo;
@@ -1079,7 +1075,7 @@ restart:
1079 set_orig_addr(m, msg); 1075 set_orig_addr(m, msg);
1080 1076
1081 /* Capture ancillary data (optional) */ 1077 /* Capture ancillary data (optional) */
1082 res = anc_data_recv(m, msg, tport); 1078 res = anc_data_recv(m, msg, port);
1083 if (res) 1079 if (res)
1084 goto exit; 1080 goto exit;
1085 1081
@@ -1105,8 +1101,8 @@ restart:
1105 /* Consume received message (optional) */ 1101 /* Consume received message (optional) */
1106 if (likely(!(flags & MSG_PEEK))) { 1102 if (likely(!(flags & MSG_PEEK))) {
1107 if ((sock->state != SS_READY) && 1103 if ((sock->state != SS_READY) &&
1108 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1104 (++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1109 tipc_acknowledge(tport->ref, tport->conn_unacked); 1105 tipc_acknowledge(port->ref, port->conn_unacked);
1110 advance_rx_queue(sk); 1106 advance_rx_queue(sk);
1111 } 1107 }
1112exit: 1108exit:
@@ -1115,7 +1111,7 @@ exit:
1115} 1111}
1116 1112
1117/** 1113/**
1118 * recv_stream - receive stream-oriented data 1114 * tipc_recv_stream - receive stream-oriented data
1119 * @iocb: (unused) 1115 * @iocb: (unused)
1120 * @m: descriptor for message info 1116 * @m: descriptor for message info
1121 * @buf_len: total size of user buffer area 1117 * @buf_len: total size of user buffer area
@@ -1126,11 +1122,12 @@ exit:
1126 * 1122 *
1127 * Returns size of returned message data, errno otherwise 1123 * Returns size of returned message data, errno otherwise
1128 */ 1124 */
1129static int recv_stream(struct kiocb *iocb, struct socket *sock, 1125static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock,
1130 struct msghdr *m, size_t buf_len, int flags) 1126 struct msghdr *m, size_t buf_len, int flags)
1131{ 1127{
1132 struct sock *sk = sock->sk; 1128 struct sock *sk = sock->sk;
1133 struct tipc_port *tport = tipc_sk_port(sk); 1129 struct tipc_sock *tsk = tipc_sk(sk);
1130 struct tipc_port *port = &tsk->port;
1134 struct sk_buff *buf; 1131 struct sk_buff *buf;
1135 struct tipc_msg *msg; 1132 struct tipc_msg *msg;
1136 long timeo; 1133 long timeo;
@@ -1175,7 +1172,7 @@ restart:
1175 /* Optionally capture sender's address & ancillary data of first msg */ 1172 /* Optionally capture sender's address & ancillary data of first msg */
1176 if (sz_copied == 0) { 1173 if (sz_copied == 0) {
1177 set_orig_addr(m, msg); 1174 set_orig_addr(m, msg);
1178 res = anc_data_recv(m, msg, tport); 1175 res = anc_data_recv(m, msg, port);
1179 if (res) 1176 if (res)
1180 goto exit; 1177 goto exit;
1181 } 1178 }
@@ -1213,8 +1210,8 @@ restart:
1213 1210
1214 /* Consume received message (optional) */ 1211 /* Consume received message (optional) */
1215 if (likely(!(flags & MSG_PEEK))) { 1212 if (likely(!(flags & MSG_PEEK))) {
1216 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1213 if (unlikely(++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1217 tipc_acknowledge(tport->ref, tport->conn_unacked); 1214 tipc_acknowledge(port->ref, port->conn_unacked);
1218 advance_rx_queue(sk); 1215 advance_rx_queue(sk);
1219 } 1216 }
1220 1217
@@ -1266,17 +1263,19 @@ static void tipc_data_ready(struct sock *sk, int len)
1266 1263
1267/** 1264/**
1268 * filter_connect - Handle all incoming messages for a connection-based socket 1265 * filter_connect - Handle all incoming messages for a connection-based socket
1269 * @tsock: TIPC socket 1266 * @tsk: TIPC socket
1270 * @msg: message 1267 * @msg: message
1271 * 1268 *
1272 * Returns TIPC error status code and socket error status code 1269 * Returns TIPC error status code and socket error status code
1273 * once it encounters some errors 1270 * once it encounters some errors
1274 */ 1271 */
1275static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) 1272static u32 filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1276{ 1273{
1277 struct socket *sock = tsock->sk.sk_socket; 1274 struct sock *sk = &tsk->sk;
1275 struct tipc_port *port = &tsk->port;
1276 struct socket *sock = sk->sk_socket;
1278 struct tipc_msg *msg = buf_msg(*buf); 1277 struct tipc_msg *msg = buf_msg(*buf);
1279 struct sock *sk = &tsock->sk; 1278
1280 u32 retval = TIPC_ERR_NO_PORT; 1279 u32 retval = TIPC_ERR_NO_PORT;
1281 int res; 1280 int res;
1282 1281
@@ -1286,10 +1285,10 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1286 switch ((int)sock->state) { 1285 switch ((int)sock->state) {
1287 case SS_CONNECTED: 1286 case SS_CONNECTED:
1288 /* Accept only connection-based messages sent by peer */ 1287 /* Accept only connection-based messages sent by peer */
1289 if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) { 1288 if (msg_connected(msg) && tipc_port_peer_msg(port, msg)) {
1290 if (unlikely(msg_errcode(msg))) { 1289 if (unlikely(msg_errcode(msg))) {
1291 sock->state = SS_DISCONNECTING; 1290 sock->state = SS_DISCONNECTING;
1292 __tipc_disconnect(tsock->p); 1291 __tipc_port_disconnect(port);
1293 } 1292 }
1294 retval = TIPC_OK; 1293 retval = TIPC_OK;
1295 } 1294 }
@@ -1306,7 +1305,7 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1306 if (unlikely(!msg_connected(msg))) 1305 if (unlikely(!msg_connected(msg)))
1307 break; 1306 break;
1308 1307
1309 res = auto_connect(sock, msg); 1308 res = auto_connect(tsk, msg);
1310 if (res) { 1309 if (res) {
1311 sock->state = SS_DISCONNECTING; 1310 sock->state = SS_DISCONNECTING;
1312 sk->sk_err = -res; 1311 sk->sk_err = -res;
@@ -1385,6 +1384,7 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1385static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) 1384static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1386{ 1385{
1387 struct socket *sock = sk->sk_socket; 1386 struct socket *sock = sk->sk_socket;
1387 struct tipc_sock *tsk = tipc_sk(sk);
1388 struct tipc_msg *msg = buf_msg(buf); 1388 struct tipc_msg *msg = buf_msg(buf);
1389 unsigned int limit = rcvbuf_limit(sk, buf); 1389 unsigned int limit = rcvbuf_limit(sk, buf);
1390 u32 res = TIPC_OK; 1390 u32 res = TIPC_OK;
@@ -1397,7 +1397,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1397 if (msg_connected(msg)) 1397 if (msg_connected(msg))
1398 return TIPC_ERR_NO_PORT; 1398 return TIPC_ERR_NO_PORT;
1399 } else { 1399 } else {
1400 res = filter_connect(tipc_sk(sk), &buf); 1400 res = filter_connect(tsk, &buf);
1401 if (res != TIPC_OK || buf == NULL) 1401 if (res != TIPC_OK || buf == NULL)
1402 return res; 1402 return res;
1403 } 1403 }
@@ -1435,17 +1435,16 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1435} 1435}
1436 1436
1437/** 1437/**
1438 * dispatch - handle incoming message 1438 * tipc_sk_rcv - handle incoming message
1439 * @tport: TIPC port that received message 1439 * @sk: socket receiving message
1440 * @buf: message 1440 * @buf: message
1441 * 1441 *
1442 * Called with port lock already taken. 1442 * Called with port lock already taken.
1443 * 1443 *
1444 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1444 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1445 */ 1445 */
1446static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) 1446u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf)
1447{ 1447{
1448 struct sock *sk = tport->sk;
1449 u32 res; 1448 u32 res;
1450 1449
1451 /* 1450 /*
@@ -1468,19 +1467,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1468 return res; 1467 return res;
1469} 1468}
1470 1469
1471/**
1472 * wakeupdispatch - wake up port after congestion
1473 * @tport: port to wakeup
1474 *
1475 * Called with port lock already taken.
1476 */
1477static void wakeupdispatch(struct tipc_port *tport)
1478{
1479 struct sock *sk = tport->sk;
1480
1481 sk->sk_write_space(sk);
1482}
1483
1484static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) 1470static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1485{ 1471{
1486 struct sock *sk = sock->sk; 1472 struct sock *sk = sock->sk;
@@ -1504,7 +1490,7 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1504} 1490}
1505 1491
1506/** 1492/**
1507 * connect - establish a connection to another TIPC port 1493 * tipc_connect - establish a connection to another TIPC port
1508 * @sock: socket structure 1494 * @sock: socket structure
1509 * @dest: socket address for destination port 1495 * @dest: socket address for destination port
1510 * @destlen: size of socket address data structure 1496 * @destlen: size of socket address data structure
@@ -1512,8 +1498,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1512 * 1498 *
1513 * Returns 0 on success, errno otherwise 1499 * Returns 0 on success, errno otherwise
1514 */ 1500 */
1515static int connect(struct socket *sock, struct sockaddr *dest, int destlen, 1501static int tipc_connect(struct socket *sock, struct sockaddr *dest,
1516 int flags) 1502 int destlen, int flags)
1517{ 1503{
1518 struct sock *sk = sock->sk; 1504 struct sock *sk = sock->sk;
1519 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; 1505 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest;
@@ -1554,7 +1540,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1554 if (!timeout) 1540 if (!timeout)
1555 m.msg_flags = MSG_DONTWAIT; 1541 m.msg_flags = MSG_DONTWAIT;
1556 1542
1557 res = send_msg(NULL, sock, &m, 0); 1543 res = tipc_sendmsg(NULL, sock, &m, 0);
1558 if ((res < 0) && (res != -EWOULDBLOCK)) 1544 if ((res < 0) && (res != -EWOULDBLOCK))
1559 goto exit; 1545 goto exit;
1560 1546
@@ -1585,13 +1571,13 @@ exit:
1585} 1571}
1586 1572
1587/** 1573/**
1588 * listen - allow socket to listen for incoming connections 1574 * tipc_listen - allow socket to listen for incoming connections
1589 * @sock: socket structure 1575 * @sock: socket structure
1590 * @len: (unused) 1576 * @len: (unused)
1591 * 1577 *
1592 * Returns 0 on success, errno otherwise 1578 * Returns 0 on success, errno otherwise
1593 */ 1579 */
1594static int listen(struct socket *sock, int len) 1580static int tipc_listen(struct socket *sock, int len)
1595{ 1581{
1596 struct sock *sk = sock->sk; 1582 struct sock *sk = sock->sk;
1597 int res; 1583 int res;
@@ -1646,20 +1632,20 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
1646} 1632}
1647 1633
1648/** 1634/**
1649 * accept - wait for connection request 1635 * tipc_accept - wait for connection request
1650 * @sock: listening socket 1636 * @sock: listening socket
1651 * @newsock: new socket that is to be connected 1637 * @newsock: new socket that is to be connected
1652 * @flags: file-related flags associated with socket 1638 * @flags: file-related flags associated with socket
1653 * 1639 *
1654 * Returns 0 on success, errno otherwise 1640 * Returns 0 on success, errno otherwise
1655 */ 1641 */
1656static int accept(struct socket *sock, struct socket *new_sock, int flags) 1642static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1657{ 1643{
1658 struct sock *new_sk, *sk = sock->sk; 1644 struct sock *new_sk, *sk = sock->sk;
1659 struct sk_buff *buf; 1645 struct sk_buff *buf;
1660 struct tipc_sock *new_tsock; 1646 struct tipc_port *new_port;
1661 struct tipc_port *new_tport;
1662 struct tipc_msg *msg; 1647 struct tipc_msg *msg;
1648 struct tipc_portid peer;
1663 u32 new_ref; 1649 u32 new_ref;
1664 long timeo; 1650 long timeo;
1665 int res; 1651 int res;
@@ -1670,7 +1656,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1670 res = -EINVAL; 1656 res = -EINVAL;
1671 goto exit; 1657 goto exit;
1672 } 1658 }
1673
1674 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); 1659 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1675 res = tipc_wait_for_accept(sock, timeo); 1660 res = tipc_wait_for_accept(sock, timeo);
1676 if (res) 1661 if (res)
@@ -1683,9 +1668,8 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1683 goto exit; 1668 goto exit;
1684 1669
1685 new_sk = new_sock->sk; 1670 new_sk = new_sock->sk;
1686 new_tsock = tipc_sk(new_sk); 1671 new_port = &tipc_sk(new_sk)->port;
1687 new_tport = new_tsock->p; 1672 new_ref = new_port->ref;
1688 new_ref = new_tport->ref;
1689 msg = buf_msg(buf); 1673 msg = buf_msg(buf);
1690 1674
1691 /* we lock on new_sk; but lockdep sees the lock on sk */ 1675 /* we lock on new_sk; but lockdep sees the lock on sk */
@@ -1698,15 +1682,15 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1698 reject_rx_queue(new_sk); 1682 reject_rx_queue(new_sk);
1699 1683
1700 /* Connect new socket to it's peer */ 1684 /* Connect new socket to it's peer */
1701 new_tsock->peer_name.ref = msg_origport(msg); 1685 peer.ref = msg_origport(msg);
1702 new_tsock->peer_name.node = msg_orignode(msg); 1686 peer.node = msg_orignode(msg);
1703 tipc_connect(new_ref, &new_tsock->peer_name); 1687 tipc_port_connect(new_ref, &peer);
1704 new_sock->state = SS_CONNECTED; 1688 new_sock->state = SS_CONNECTED;
1705 1689
1706 tipc_set_portimportance(new_ref, msg_importance(msg)); 1690 tipc_port_set_importance(new_port, msg_importance(msg));
1707 if (msg_named(msg)) { 1691 if (msg_named(msg)) {
1708 new_tport->conn_type = msg_nametype(msg); 1692 new_port->conn_type = msg_nametype(msg);
1709 new_tport->conn_instance = msg_nameinst(msg); 1693 new_port->conn_instance = msg_nameinst(msg);
1710 } 1694 }
1711 1695
1712 /* 1696 /*
@@ -1717,21 +1701,20 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1717 struct msghdr m = {NULL,}; 1701 struct msghdr m = {NULL,};
1718 1702
1719 advance_rx_queue(sk); 1703 advance_rx_queue(sk);
1720 send_packet(NULL, new_sock, &m, 0); 1704 tipc_send_packet(NULL, new_sock, &m, 0);
1721 } else { 1705 } else {
1722 __skb_dequeue(&sk->sk_receive_queue); 1706 __skb_dequeue(&sk->sk_receive_queue);
1723 __skb_queue_head(&new_sk->sk_receive_queue, buf); 1707 __skb_queue_head(&new_sk->sk_receive_queue, buf);
1724 skb_set_owner_r(buf, new_sk); 1708 skb_set_owner_r(buf, new_sk);
1725 } 1709 }
1726 release_sock(new_sk); 1710 release_sock(new_sk);
1727
1728exit: 1711exit:
1729 release_sock(sk); 1712 release_sock(sk);
1730 return res; 1713 return res;
1731} 1714}
1732 1715
1733/** 1716/**
1734 * shutdown - shutdown socket connection 1717 * tipc_shutdown - shutdown socket connection
1735 * @sock: socket structure 1718 * @sock: socket structure
1736 * @how: direction to close (must be SHUT_RDWR) 1719 * @how: direction to close (must be SHUT_RDWR)
1737 * 1720 *
@@ -1739,10 +1722,11 @@ exit:
1739 * 1722 *
1740 * Returns 0 on success, errno otherwise 1723 * Returns 0 on success, errno otherwise
1741 */ 1724 */
1742static int shutdown(struct socket *sock, int how) 1725static int tipc_shutdown(struct socket *sock, int how)
1743{ 1726{
1744 struct sock *sk = sock->sk; 1727 struct sock *sk = sock->sk;
1745 struct tipc_port *tport = tipc_sk_port(sk); 1728 struct tipc_sock *tsk = tipc_sk(sk);
1729 struct tipc_port *port = &tsk->port;
1746 struct sk_buff *buf; 1730 struct sk_buff *buf;
1747 int res; 1731 int res;
1748 1732
@@ -1763,10 +1747,10 @@ restart:
1763 kfree_skb(buf); 1747 kfree_skb(buf);
1764 goto restart; 1748 goto restart;
1765 } 1749 }
1766 tipc_disconnect(tport->ref); 1750 tipc_port_disconnect(port->ref);
1767 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); 1751 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN);
1768 } else { 1752 } else {
1769 tipc_shutdown(tport->ref); 1753 tipc_port_shutdown(port->ref);
1770 } 1754 }
1771 1755
1772 sock->state = SS_DISCONNECTING; 1756 sock->state = SS_DISCONNECTING;
@@ -1792,7 +1776,7 @@ restart:
1792} 1776}
1793 1777
1794/** 1778/**
1795 * setsockopt - set socket option 1779 * tipc_setsockopt - set socket option
1796 * @sock: socket structure 1780 * @sock: socket structure
1797 * @lvl: option level 1781 * @lvl: option level
1798 * @opt: option identifier 1782 * @opt: option identifier
@@ -1804,11 +1788,12 @@ restart:
1804 * 1788 *
1805 * Returns 0 on success, errno otherwise 1789 * Returns 0 on success, errno otherwise
1806 */ 1790 */
1807static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, 1791static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
1808 unsigned int ol) 1792 char __user *ov, unsigned int ol)
1809{ 1793{
1810 struct sock *sk = sock->sk; 1794 struct sock *sk = sock->sk;
1811 struct tipc_port *tport = tipc_sk_port(sk); 1795 struct tipc_sock *tsk = tipc_sk(sk);
1796 struct tipc_port *port = &tsk->port;
1812 u32 value; 1797 u32 value;
1813 int res; 1798 int res;
1814 1799
@@ -1826,16 +1811,16 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1826 1811
1827 switch (opt) { 1812 switch (opt) {
1828 case TIPC_IMPORTANCE: 1813 case TIPC_IMPORTANCE:
1829 res = tipc_set_portimportance(tport->ref, value); 1814 tipc_port_set_importance(port, value);
1830 break; 1815 break;
1831 case TIPC_SRC_DROPPABLE: 1816 case TIPC_SRC_DROPPABLE:
1832 if (sock->type != SOCK_STREAM) 1817 if (sock->type != SOCK_STREAM)
1833 res = tipc_set_portunreliable(tport->ref, value); 1818 tipc_port_set_unreliable(port, value);
1834 else 1819 else
1835 res = -ENOPROTOOPT; 1820 res = -ENOPROTOOPT;
1836 break; 1821 break;
1837 case TIPC_DEST_DROPPABLE: 1822 case TIPC_DEST_DROPPABLE:
1838 res = tipc_set_portunreturnable(tport->ref, value); 1823 tipc_port_set_unreturnable(port, value);
1839 break; 1824 break;
1840 case TIPC_CONN_TIMEOUT: 1825 case TIPC_CONN_TIMEOUT:
1841 tipc_sk(sk)->conn_timeout = value; 1826 tipc_sk(sk)->conn_timeout = value;
@@ -1851,7 +1836,7 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1851} 1836}
1852 1837
1853/** 1838/**
1854 * getsockopt - get socket option 1839 * tipc_getsockopt - get socket option
1855 * @sock: socket structure 1840 * @sock: socket structure
1856 * @lvl: option level 1841 * @lvl: option level
1857 * @opt: option identifier 1842 * @opt: option identifier
@@ -1863,11 +1848,12 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1863 * 1848 *
1864 * Returns 0 on success, errno otherwise 1849 * Returns 0 on success, errno otherwise
1865 */ 1850 */
1866static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, 1851static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
1867 int __user *ol) 1852 char __user *ov, int __user *ol)
1868{ 1853{
1869 struct sock *sk = sock->sk; 1854 struct sock *sk = sock->sk;
1870 struct tipc_port *tport = tipc_sk_port(sk); 1855 struct tipc_sock *tsk = tipc_sk(sk);
1856 struct tipc_port *port = &tsk->port;
1871 int len; 1857 int len;
1872 u32 value; 1858 u32 value;
1873 int res; 1859 int res;
@@ -1884,13 +1870,13 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1884 1870
1885 switch (opt) { 1871 switch (opt) {
1886 case TIPC_IMPORTANCE: 1872 case TIPC_IMPORTANCE:
1887 res = tipc_portimportance(tport->ref, &value); 1873 value = tipc_port_importance(port);
1888 break; 1874 break;
1889 case TIPC_SRC_DROPPABLE: 1875 case TIPC_SRC_DROPPABLE:
1890 res = tipc_portunreliable(tport->ref, &value); 1876 value = tipc_port_unreliable(port);
1891 break; 1877 break;
1892 case TIPC_DEST_DROPPABLE: 1878 case TIPC_DEST_DROPPABLE:
1893 res = tipc_portunreturnable(tport->ref, &value); 1879 value = tipc_port_unreturnable(port);
1894 break; 1880 break;
1895 case TIPC_CONN_TIMEOUT: 1881 case TIPC_CONN_TIMEOUT:
1896 value = tipc_sk(sk)->conn_timeout; 1882 value = tipc_sk(sk)->conn_timeout;
@@ -1925,20 +1911,20 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1925static const struct proto_ops msg_ops = { 1911static const struct proto_ops msg_ops = {
1926 .owner = THIS_MODULE, 1912 .owner = THIS_MODULE,
1927 .family = AF_TIPC, 1913 .family = AF_TIPC,
1928 .release = release, 1914 .release = tipc_release,
1929 .bind = bind, 1915 .bind = tipc_bind,
1930 .connect = connect, 1916 .connect = tipc_connect,
1931 .socketpair = sock_no_socketpair, 1917 .socketpair = sock_no_socketpair,
1932 .accept = sock_no_accept, 1918 .accept = sock_no_accept,
1933 .getname = get_name, 1919 .getname = tipc_getname,
1934 .poll = poll, 1920 .poll = tipc_poll,
1935 .ioctl = sock_no_ioctl, 1921 .ioctl = sock_no_ioctl,
1936 .listen = sock_no_listen, 1922 .listen = sock_no_listen,
1937 .shutdown = shutdown, 1923 .shutdown = tipc_shutdown,
1938 .setsockopt = setsockopt, 1924 .setsockopt = tipc_setsockopt,
1939 .getsockopt = getsockopt, 1925 .getsockopt = tipc_getsockopt,
1940 .sendmsg = send_msg, 1926 .sendmsg = tipc_sendmsg,
1941 .recvmsg = recv_msg, 1927 .recvmsg = tipc_recvmsg,
1942 .mmap = sock_no_mmap, 1928 .mmap = sock_no_mmap,
1943 .sendpage = sock_no_sendpage 1929 .sendpage = sock_no_sendpage
1944}; 1930};
@@ -1946,20 +1932,20 @@ static const struct proto_ops msg_ops = {
1946static const struct proto_ops packet_ops = { 1932static const struct proto_ops packet_ops = {
1947 .owner = THIS_MODULE, 1933 .owner = THIS_MODULE,
1948 .family = AF_TIPC, 1934 .family = AF_TIPC,
1949 .release = release, 1935 .release = tipc_release,
1950 .bind = bind, 1936 .bind = tipc_bind,
1951 .connect = connect, 1937 .connect = tipc_connect,
1952 .socketpair = sock_no_socketpair, 1938 .socketpair = sock_no_socketpair,
1953 .accept = accept, 1939 .accept = tipc_accept,
1954 .getname = get_name, 1940 .getname = tipc_getname,
1955 .poll = poll, 1941 .poll = tipc_poll,
1956 .ioctl = sock_no_ioctl, 1942 .ioctl = sock_no_ioctl,
1957 .listen = listen, 1943 .listen = tipc_listen,
1958 .shutdown = shutdown, 1944 .shutdown = tipc_shutdown,
1959 .setsockopt = setsockopt, 1945 .setsockopt = tipc_setsockopt,
1960 .getsockopt = getsockopt, 1946 .getsockopt = tipc_getsockopt,
1961 .sendmsg = send_packet, 1947 .sendmsg = tipc_send_packet,
1962 .recvmsg = recv_msg, 1948 .recvmsg = tipc_recvmsg,
1963 .mmap = sock_no_mmap, 1949 .mmap = sock_no_mmap,
1964 .sendpage = sock_no_sendpage 1950 .sendpage = sock_no_sendpage
1965}; 1951};
@@ -1967,20 +1953,20 @@ static const struct proto_ops packet_ops = {
1967static const struct proto_ops stream_ops = { 1953static const struct proto_ops stream_ops = {
1968 .owner = THIS_MODULE, 1954 .owner = THIS_MODULE,
1969 .family = AF_TIPC, 1955 .family = AF_TIPC,
1970 .release = release, 1956 .release = tipc_release,
1971 .bind = bind, 1957 .bind = tipc_bind,
1972 .connect = connect, 1958 .connect = tipc_connect,
1973 .socketpair = sock_no_socketpair, 1959 .socketpair = sock_no_socketpair,
1974 .accept = accept, 1960 .accept = tipc_accept,
1975 .getname = get_name, 1961 .getname = tipc_getname,
1976 .poll = poll, 1962 .poll = tipc_poll,
1977 .ioctl = sock_no_ioctl, 1963 .ioctl = sock_no_ioctl,
1978 .listen = listen, 1964 .listen = tipc_listen,
1979 .shutdown = shutdown, 1965 .shutdown = tipc_shutdown,
1980 .setsockopt = setsockopt, 1966 .setsockopt = tipc_setsockopt,
1981 .getsockopt = getsockopt, 1967 .getsockopt = tipc_getsockopt,
1982 .sendmsg = send_stream, 1968 .sendmsg = tipc_send_stream,
1983 .recvmsg = recv_stream, 1969 .recvmsg = tipc_recv_stream,
1984 .mmap = sock_no_mmap, 1970 .mmap = sock_no_mmap,
1985 .sendpage = sock_no_sendpage 1971 .sendpage = sock_no_sendpage
1986}; 1972};
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
49struct tipc_sock {
50 struct sock sk;
51 struct tipc_port port;
52 unsigned int conn_timeout;
53};
54
55static inline struct tipc_sock *tipc_sk(const struct sock *sk)
56{
57 return container_of(sk, struct tipc_sock, sk);
58}
59
60static 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
65static inline void tipc_sock_wakeup(struct tipc_sock *tsk)
66{
67 tsk->sk.sk_write_space(&tsk->sk);
68}
69
70u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf);
71
72#endif