aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2011-01-14 08:12:37 -0500
committerPatrick McHardy <kaber@trash.net>2011-01-14 08:12:37 -0500
commit0134e89c7bcc9fde1da962c82a120691e185619f (patch)
tree3e03335cf001019a2687d161e956de4f73379984 /net/tipc
parentc7066f70d9610df0b9406cc635fc09e86136e714 (diff)
parent6faee60a4e82075853a437831768cc9e2e563e4e (diff)
Merge branch 'master' of git://1984.lsi.us.es/net-next-2.6
Conflicts: net/ipv4/route.c Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/Kconfig35
-rw-r--r--net/tipc/Makefile4
-rw-r--r--net/tipc/addr.c10
-rw-r--r--net/tipc/addr.h25
-rw-r--r--net/tipc/bcast.c50
-rw-r--r--net/tipc/bcast.h1
-rw-r--r--net/tipc/bearer.c22
-rw-r--r--net/tipc/bearer.h71
-rw-r--r--net/tipc/cluster.c557
-rw-r--r--net/tipc/cluster.h92
-rw-r--r--net/tipc/config.c118
-rw-r--r--net/tipc/config.h1
-rw-r--r--net/tipc/core.c101
-rw-r--r--net/tipc/core.h76
-rw-r--r--net/tipc/discover.c14
-rw-r--r--net/tipc/discover.h2
-rw-r--r--net/tipc/eth_media.c15
-rw-r--r--net/tipc/handler.c2
-rw-r--r--net/tipc/link.c383
-rw-r--r--net/tipc/link.h10
-rw-r--r--net/tipc/log.c (renamed from net/tipc/dbg.c)111
-rw-r--r--net/tipc/log.h (renamed from net/tipc/dbg.h)6
-rw-r--r--net/tipc/msg.c75
-rw-r--r--net/tipc/msg.h185
-rw-r--r--net/tipc/name_distr.c47
-rw-r--r--net/tipc/name_table.c60
-rw-r--r--net/tipc/name_table.h2
-rw-r--r--net/tipc/net.c72
-rw-r--r--net/tipc/net.h14
-rw-r--r--net/tipc/node.c301
-rw-r--r--net/tipc/node.h27
-rw-r--r--net/tipc/node_subscr.c2
-rw-r--r--net/tipc/port.c170
-rw-r--r--net/tipc/port.h137
-rw-r--r--net/tipc/ref.c8
-rw-r--r--net/tipc/socket.c156
-rw-r--r--net/tipc/subscr.c38
-rw-r--r--net/tipc/user_reg.c264
-rw-r--r--net/tipc/user_reg.h48
-rw-r--r--net/tipc/zone.c162
-rw-r--r--net/tipc/zone.h70
41 files changed, 813 insertions, 2731 deletions
diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig
index b74f78d0c033..0436927369f3 100644
--- a/net/tipc/Kconfig
+++ b/net/tipc/Kconfig
@@ -29,28 +29,6 @@ config TIPC_ADVANCED
29 Saying Y here will open some advanced configuration for TIPC. 29 Saying Y here will open some advanced configuration for TIPC.
30 Most users do not need to bother; if unsure, just say N. 30 Most users do not need to bother; if unsure, just say N.
31 31
32config TIPC_ZONES
33 int "Maximum number of zones in a network"
34 depends on TIPC_ADVANCED
35 range 1 255
36 default "3"
37 help
38 Specifies how many zones can be supported in a TIPC network.
39 Can range from 1 to 255 zones; default is 3.
40
41 Setting this to a smaller value saves some memory;
42 setting it to a higher value allows for more zones.
43
44config TIPC_CLUSTERS
45 int "Maximum number of clusters in a zone"
46 depends on TIPC_ADVANCED
47 range 1 1
48 default "1"
49 help
50 Specifies how many clusters can be supported in a TIPC zone.
51
52 *** Currently TIPC only supports a single cluster per zone. ***
53
54config TIPC_NODES 32config TIPC_NODES
55 int "Maximum number of nodes in a cluster" 33 int "Maximum number of nodes in a cluster"
56 depends on TIPC_ADVANCED 34 depends on TIPC_ADVANCED
@@ -72,7 +50,7 @@ config TIPC_PORTS
72 Specifies how many ports can be supported by a node. 50 Specifies how many ports can be supported by a node.
73 Can range from 127 to 65535 ports; default is 8191. 51 Can range from 127 to 65535 ports; default is 8191.
74 52
75 Setting this to a smaller value saves some memory, 53 Setting this to a smaller value saves some memory,
76 setting it to higher allows for more ports. 54 setting it to higher allows for more ports.
77 55
78config TIPC_LOG 56config TIPC_LOG
@@ -89,12 +67,15 @@ config TIPC_LOG
89 managed remotely via TIPC. 67 managed remotely via TIPC.
90 68
91config TIPC_DEBUG 69config TIPC_DEBUG
92 bool "Enable debug messages" 70 bool "Enable debugging support"
93 default n 71 default n
94 help 72 help
95 This enables debugging of TIPC. 73 Saying Y here enables TIPC debugging capabilities used by developers.
74 Most users do not need to bother; if unsure, just say N.
96 75
97 Only say Y here if you are having trouble with TIPC. It will 76 Enabling debugging support causes TIPC to display data about its
98 enable the display of detailed information about what is going on. 77 internal state when certain abnormal conditions occur. It also
78 makes it easy for developers to capture additional information of
79 interest using the dbg() or msg_dbg() macros.
99 80
100endif # TIPC 81endif # TIPC
diff --git a/net/tipc/Makefile b/net/tipc/Makefile
index dceb7027946c..521d24d04ab2 100644
--- a/net/tipc/Makefile
+++ b/net/tipc/Makefile
@@ -4,10 +4,10 @@
4 4
5obj-$(CONFIG_TIPC) := tipc.o 5obj-$(CONFIG_TIPC) := tipc.o
6 6
7tipc-y += addr.o bcast.o bearer.o config.o cluster.o \ 7tipc-y += addr.o bcast.o bearer.o config.o \
8 core.o handler.o link.o discover.o msg.o \ 8 core.o handler.o link.o discover.o msg.o \
9 name_distr.o subscr.o name_table.o net.o \ 9 name_distr.o subscr.o name_table.o net.o \
10 netlink.o node.o node_subscr.o port.o ref.o \ 10 netlink.o node.o node_subscr.o port.o ref.o \
11 socket.o user_reg.o zone.o dbg.o eth_media.o 11 socket.o log.o eth_media.o
12 12
13# End of file 13# End of file
diff --git a/net/tipc/addr.c b/net/tipc/addr.c
index 8a2e89bffde5..88463d9a6f12 100644
--- a/net/tipc/addr.c
+++ b/net/tipc/addr.c
@@ -35,11 +35,7 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "addr.h" 38#include "addr.h"
40#include "zone.h"
41#include "cluster.h"
42#include "net.h"
43 39
44/** 40/**
45 * tipc_addr_domain_valid - validates a network domain address 41 * tipc_addr_domain_valid - validates a network domain address
@@ -57,14 +53,8 @@ int tipc_addr_domain_valid(u32 addr)
57 u32 z = tipc_zone(addr); 53 u32 z = tipc_zone(addr);
58 u32 max_nodes = tipc_max_nodes; 54 u32 max_nodes = tipc_max_nodes;
59 55
60 if (is_slave(addr))
61 max_nodes = LOWEST_SLAVE + tipc_max_slaves;
62 if (n > max_nodes) 56 if (n > max_nodes)
63 return 0; 57 return 0;
64 if (c > tipc_max_clusters)
65 return 0;
66 if (z > tipc_max_zones)
67 return 0;
68 58
69 if (n && (!z || !c)) 59 if (n && (!z || !c))
70 return 0; 60 return 0;
diff --git a/net/tipc/addr.h b/net/tipc/addr.h
index c1cc5724d8cc..2490fadd0caf 100644
--- a/net/tipc/addr.h
+++ b/net/tipc/addr.h
@@ -37,36 +37,11 @@
37#ifndef _TIPC_ADDR_H 37#ifndef _TIPC_ADDR_H
38#define _TIPC_ADDR_H 38#define _TIPC_ADDR_H
39 39
40static inline u32 own_node(void)
41{
42 return tipc_node(tipc_own_addr);
43}
44
45static inline u32 own_cluster(void)
46{
47 return tipc_cluster(tipc_own_addr);
48}
49
50static inline u32 own_zone(void)
51{
52 return tipc_zone(tipc_own_addr);
53}
54
55static inline int in_own_cluster(u32 addr) 40static inline int in_own_cluster(u32 addr)
56{ 41{
57 return !((addr ^ tipc_own_addr) >> 12); 42 return !((addr ^ tipc_own_addr) >> 12);
58} 43}
59 44
60static inline int is_slave(u32 addr)
61{
62 return addr & 0x800;
63}
64
65static inline int may_route(u32 addr)
66{
67 return(addr ^ tipc_own_addr) >> 11;
68}
69
70/** 45/**
71 * addr_domain - convert 2-bit scope value to equivalent message lookup domain 46 * addr_domain - convert 2-bit scope value to equivalent message lookup domain
72 * 47 *
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 22a60fc98392..70ab5ef48766 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -36,25 +36,14 @@
36 */ 36 */
37 37
38#include "core.h" 38#include "core.h"
39#include "msg.h"
40#include "dbg.h"
41#include "link.h" 39#include "link.h"
42#include "net.h"
43#include "node.h"
44#include "port.h" 40#include "port.h"
45#include "addr.h"
46#include "node_subscr.h"
47#include "name_distr.h"
48#include "bearer.h"
49#include "name_table.h"
50#include "bcast.h" 41#include "bcast.h"
51 42
52#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ 43#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
53 44
54#define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ 45#define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */
55 46
56#define BCLINK_LOG_BUF_SIZE 0
57
58/* 47/*
59 * Loss rate for incoming broadcast frames; used to test retransmission code. 48 * Loss rate for incoming broadcast frames; used to test retransmission code.
60 * Set to N to cause every N'th frame to be discarded; 0 => don't discard any. 49 * Set to N to cause every N'th frame to be discarded; 0 => don't discard any.
@@ -114,11 +103,14 @@ struct bclink {
114}; 103};
115 104
116 105
117static struct bcbearer *bcbearer = NULL; 106static struct bcbearer *bcbearer;
118static struct bclink *bclink = NULL; 107static struct bclink *bclink;
119static struct link *bcl = NULL; 108static struct link *bcl;
120static DEFINE_SPINLOCK(bc_lock); 109static DEFINE_SPINLOCK(bc_lock);
121 110
111/* broadcast-capable node map */
112struct tipc_node_map tipc_bcast_nmap;
113
122const char tipc_bclink_name[] = "broadcast-link"; 114const char tipc_bclink_name[] = "broadcast-link";
123 115
124static void tipc_nmap_diff(struct tipc_node_map *nm_a, 116static void tipc_nmap_diff(struct tipc_node_map *nm_a,
@@ -204,9 +196,8 @@ static void bclink_retransmit_pkt(u32 after, u32 to)
204 struct sk_buff *buf; 196 struct sk_buff *buf;
205 197
206 buf = bcl->first_out; 198 buf = bcl->first_out;
207 while (buf && less_eq(buf_seqno(buf), after)) { 199 while (buf && less_eq(buf_seqno(buf), after))
208 buf = buf->next; 200 buf = buf->next;
209 }
210 tipc_link_retransmit(bcl, buf, mod(to - after)); 201 tipc_link_retransmit(bcl, buf, mod(to - after));
211} 202}
212 203
@@ -232,9 +223,8 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
232 /* Skip over packets that node has previously acknowledged */ 223 /* Skip over packets that node has previously acknowledged */
233 224
234 crs = bcl->first_out; 225 crs = bcl->first_out;
235 while (crs && less_eq(buf_seqno(crs), n_ptr->bclink.acked)) { 226 while (crs && less_eq(buf_seqno(crs), n_ptr->bclink.acked))
236 crs = crs->next; 227 crs = crs->next;
237 }
238 228
239 /* Update packets that node is now acknowledging */ 229 /* Update packets that node is now acknowledging */
240 230
@@ -433,16 +423,14 @@ int tipc_bclink_send_msg(struct sk_buff *buf)
433void tipc_bclink_recv_pkt(struct sk_buff *buf) 423void tipc_bclink_recv_pkt(struct sk_buff *buf)
434{ 424{
435#if (TIPC_BCAST_LOSS_RATE) 425#if (TIPC_BCAST_LOSS_RATE)
436 static int rx_count = 0; 426 static int rx_count;
437#endif 427#endif
438 struct tipc_msg *msg = buf_msg(buf); 428 struct tipc_msg *msg = buf_msg(buf);
439 struct tipc_node* node = tipc_node_find(msg_prevnode(msg)); 429 struct tipc_node *node = tipc_node_find(msg_prevnode(msg));
440 u32 next_in; 430 u32 next_in;
441 u32 seqno; 431 u32 seqno;
442 struct sk_buff *deferred; 432 struct sk_buff *deferred;
443 433
444 msg_dbg(msg, "<BC<<<");
445
446 if (unlikely(!node || !tipc_node_is_up(node) || !node->bclink.supported || 434 if (unlikely(!node || !tipc_node_is_up(node) || !node->bclink.supported ||
447 (msg_mc_netid(msg) != tipc_net_id))) { 435 (msg_mc_netid(msg) != tipc_net_id))) {
448 buf_discard(buf); 436 buf_discard(buf);
@@ -450,7 +438,6 @@ void tipc_bclink_recv_pkt(struct sk_buff *buf)
450 } 438 }
451 439
452 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) { 440 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
453 msg_dbg(msg, "<BCNACK<<<");
454 if (msg_destnode(msg) == tipc_own_addr) { 441 if (msg_destnode(msg) == tipc_own_addr) {
455 tipc_node_lock(node); 442 tipc_node_lock(node);
456 tipc_bclink_acknowledge(node, msg_bcast_ack(msg)); 443 tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
@@ -574,8 +561,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
574 if (likely(!msg_non_seq(buf_msg(buf)))) { 561 if (likely(!msg_non_seq(buf_msg(buf)))) {
575 struct tipc_msg *msg; 562 struct tipc_msg *msg;
576 563
577 assert(tipc_cltr_bcast_nodes.count != 0); 564 assert(tipc_bcast_nmap.count != 0);
578 bcbuf_set_acks(buf, tipc_cltr_bcast_nodes.count); 565 bcbuf_set_acks(buf, tipc_bcast_nmap.count);
579 msg = buf_msg(buf); 566 msg = buf_msg(buf);
580 msg_set_non_seq(msg, 1); 567 msg_set_non_seq(msg, 1);
581 msg_set_mc_netid(msg, tipc_net_id); 568 msg_set_mc_netid(msg, tipc_net_id);
@@ -584,7 +571,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
584 571
585 /* Send buffer over bearers until all targets reached */ 572 /* Send buffer over bearers until all targets reached */
586 573
587 bcbearer->remains = tipc_cltr_bcast_nodes; 574 bcbearer->remains = tipc_bcast_nmap;
588 575
589 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) { 576 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
590 struct bearer *p = bcbearer->bpairs[bp_index].primary; 577 struct bearer *p = bcbearer->bpairs[bp_index].primary;
@@ -782,7 +769,6 @@ int tipc_bclink_init(void)
782 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); 769 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
783 bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC); 770 bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC);
784 if (!bcbearer || !bclink) { 771 if (!bcbearer || !bclink) {
785 nomem:
786 warn("Multicast link creation failed, no memory\n"); 772 warn("Multicast link creation failed, no memory\n");
787 kfree(bcbearer); 773 kfree(bcbearer);
788 bcbearer = NULL; 774 bcbearer = NULL;
@@ -807,14 +793,6 @@ int tipc_bclink_init(void)
807 bcl->state = WORKING_WORKING; 793 bcl->state = WORKING_WORKING;
808 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); 794 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME);
809 795
810 if (BCLINK_LOG_BUF_SIZE) {
811 char *pb = kmalloc(BCLINK_LOG_BUF_SIZE, GFP_ATOMIC);
812
813 if (!pb)
814 goto nomem;
815 tipc_printbuf_init(&bcl->print_buf, pb, BCLINK_LOG_BUF_SIZE);
816 }
817
818 return 0; 796 return 0;
819} 797}
820 798
@@ -823,8 +801,6 @@ void tipc_bclink_stop(void)
823 spin_lock_bh(&bc_lock); 801 spin_lock_bh(&bc_lock);
824 if (bcbearer) { 802 if (bcbearer) {
825 tipc_link_stop(bcl); 803 tipc_link_stop(bcl);
826 if (BCLINK_LOG_BUF_SIZE)
827 kfree(bcl->print_buf.buf);
828 bcl = NULL; 804 bcl = NULL;
829 kfree(bclink); 805 kfree(bclink);
830 bclink = NULL; 806 bclink = NULL;
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h
index 011c03f0a4ab..51f8c5326ce6 100644
--- a/net/tipc/bcast.h
+++ b/net/tipc/bcast.h
@@ -51,6 +51,7 @@ struct tipc_node_map {
51 u32 map[MAX_NODES / WSIZE]; 51 u32 map[MAX_NODES / WSIZE];
52}; 52};
53 53
54extern struct tipc_node_map tipc_bcast_nmap;
54 55
55#define PLSIZE 32 56#define PLSIZE 32
56 57
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 9927d1d56c4f..837b7a467885 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -36,17 +36,13 @@
36 36
37#include "core.h" 37#include "core.h"
38#include "config.h" 38#include "config.h"
39#include "dbg.h"
40#include "bearer.h" 39#include "bearer.h"
41#include "link.h"
42#include "port.h"
43#include "discover.h" 40#include "discover.h"
44#include "bcast.h"
45 41
46#define MAX_ADDR_STR 32 42#define MAX_ADDR_STR 32
47 43
48static struct media media_list[MAX_MEDIA]; 44static struct media media_list[MAX_MEDIA];
49static u32 media_count = 0; 45static u32 media_count;
50 46
51struct bearer tipc_bearers[MAX_BEARERS]; 47struct bearer tipc_bearers[MAX_BEARERS];
52 48
@@ -167,7 +163,6 @@ int tipc_register_media(u32 media_type,
167 m_ptr->priority = bearer_priority; 163 m_ptr->priority = bearer_priority;
168 m_ptr->tolerance = link_tolerance; 164 m_ptr->tolerance = link_tolerance;
169 m_ptr->window = send_window_limit; 165 m_ptr->window = send_window_limit;
170 dbg("Media <%s> registered\n", name);
171 res = 0; 166 res = 0;
172exit: 167exit:
173 write_unlock_bh(&tipc_net_lock); 168 write_unlock_bh(&tipc_net_lock);
@@ -199,9 +194,8 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
199 unchar *addr = (unchar *)&a->dev_addr; 194 unchar *addr = (unchar *)&a->dev_addr;
200 195
201 tipc_printf(pb, "UNKNOWN(%u)", media_type); 196 tipc_printf(pb, "UNKNOWN(%u)", media_type);
202 for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++) { 197 for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
203 tipc_printf(pb, "-%02x", addr[i]); 198 tipc_printf(pb, "-%02x", addr[i]);
204 }
205 } 199 }
206} 200}
207 201
@@ -256,7 +250,8 @@ static int bearer_name_validate(const char *name,
256 /* ensure all component parts of bearer name are present */ 250 /* ensure all component parts of bearer name are present */
257 251
258 media_name = name_copy; 252 media_name = name_copy;
259 if ((if_name = strchr(media_name, ':')) == NULL) 253 if_name = strchr(media_name, ':');
254 if (if_name == NULL)
260 return 0; 255 return 0;
261 *(if_name++) = 0; 256 *(if_name++) = 0;
262 media_len = if_name - media_name; 257 media_len = if_name - media_name;
@@ -625,7 +620,7 @@ int tipc_block_bearer(const char *name)
625 * Note: This routine assumes caller holds tipc_net_lock. 620 * Note: This routine assumes caller holds tipc_net_lock.
626 */ 621 */
627 622
628static int bearer_disable(struct bearer *b_ptr) 623static void bearer_disable(struct bearer *b_ptr)
629{ 624{
630 struct link *l_ptr; 625 struct link *l_ptr;
631 struct link *temp_l_ptr; 626 struct link *temp_l_ptr;
@@ -641,7 +636,6 @@ static int bearer_disable(struct bearer *b_ptr)
641 } 636 }
642 spin_unlock_bh(&b_ptr->publ.lock); 637 spin_unlock_bh(&b_ptr->publ.lock);
643 memset(b_ptr, 0, sizeof(struct bearer)); 638 memset(b_ptr, 0, sizeof(struct bearer));
644 return 0;
645} 639}
646 640
647int tipc_disable_bearer(const char *name) 641int tipc_disable_bearer(const char *name)
@@ -654,8 +648,10 @@ int tipc_disable_bearer(const char *name)
654 if (b_ptr == NULL) { 648 if (b_ptr == NULL) {
655 warn("Attempt to disable unknown bearer <%s>\n", name); 649 warn("Attempt to disable unknown bearer <%s>\n", name);
656 res = -EINVAL; 650 res = -EINVAL;
657 } else 651 } else {
658 res = bearer_disable(b_ptr); 652 bearer_disable(b_ptr);
653 res = 0;
654 }
659 write_unlock_bh(&tipc_net_lock); 655 write_unlock_bh(&tipc_net_lock);
660 return res; 656 return res;
661} 657}
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index a850b389663e..85f451d5aacf 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -37,12 +37,50 @@
37#ifndef _TIPC_BEARER_H 37#ifndef _TIPC_BEARER_H
38#define _TIPC_BEARER_H 38#define _TIPC_BEARER_H
39 39
40#include "core.h"
41#include "bcast.h" 40#include "bcast.h"
42 41
43#define MAX_BEARERS 8 42#define MAX_BEARERS 8
44#define MAX_MEDIA 4 43#define MAX_MEDIA 4
45 44
45/*
46 * Identifiers of supported TIPC media types
47 */
48#define TIPC_MEDIA_TYPE_ETH 1
49
50/*
51 * Destination address structure used by TIPC bearers when sending messages
52 *
53 * IMPORTANT: The fields of this structure MUST be stored using the specified
54 * byte order indicated below, as the structure is exchanged between nodes
55 * as part of a link setup process.
56 */
57struct tipc_media_addr {
58 __be32 type; /* bearer type (network byte order) */
59 union {
60 __u8 eth_addr[6]; /* 48 bit Ethernet addr (byte array) */
61 } dev_addr;
62};
63
64/**
65 * struct tipc_bearer - TIPC bearer info available to media code
66 * @usr_handle: pointer to additional media-specific information about bearer
67 * @mtu: max packet size bearer can support
68 * @blocked: non-zero if bearer is blocked
69 * @lock: spinlock for controlling access to bearer
70 * @addr: media-specific address associated with bearer
71 * @name: bearer name (format = media:interface)
72 *
73 * Note: TIPC initializes "name" and "lock" fields; media code is responsible
74 * for initialization all other fields when a bearer is enabled.
75 */
76struct tipc_bearer {
77 void *usr_handle;
78 u32 mtu;
79 int blocked;
80 spinlock_t lock;
81 struct tipc_media_addr addr;
82 char name[TIPC_MAX_BEARER_NAME];
83};
46 84
47/** 85/**
48 * struct media - TIPC media information available to internal users 86 * struct media - TIPC media information available to internal users
@@ -55,7 +93,7 @@
55 * @priority: default link (and bearer) priority 93 * @priority: default link (and bearer) priority
56 * @tolerance: default time (in ms) before declaring link failure 94 * @tolerance: default time (in ms) before declaring link failure
57 * @window: default window (in packets) before declaring link congestion 95 * @window: default window (in packets) before declaring link congestion
58 * @type_id: TIPC media identifier [defined in tipc_bearer.h] 96 * @type_id: TIPC media identifier
59 * @name: media name 97 * @name: media name
60 */ 98 */
61 99
@@ -116,6 +154,34 @@ struct link;
116 154
117extern struct bearer tipc_bearers[]; 155extern struct bearer tipc_bearers[];
118 156
157/*
158 * TIPC routines available to supported media types
159 */
160int tipc_register_media(u32 media_type,
161 char *media_name, int (*enable)(struct tipc_bearer *),
162 void (*disable)(struct tipc_bearer *),
163 int (*send_msg)(struct sk_buff *,
164 struct tipc_bearer *, struct tipc_media_addr *),
165 char *(*addr2str)(struct tipc_media_addr *a,
166 char *str_buf, int str_size),
167 struct tipc_media_addr *bcast_addr, const u32 bearer_priority,
168 const u32 link_tolerance, /* [ms] */
169 const u32 send_window_limit);
170
171void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
172
173int tipc_block_bearer(const char *name);
174void tipc_continue(struct tipc_bearer *tb_ptr);
175
176int tipc_enable_bearer(const char *bearer_name, u32 bcast_scope, u32 priority);
177int tipc_disable_bearer(const char *name);
178
179/*
180 * Routines made available to TIPC by supported media types
181 */
182int tipc_eth_media_start(void);
183void tipc_eth_media_stop(void);
184
119void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a); 185void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a);
120struct sk_buff *tipc_media_get_names(void); 186struct sk_buff *tipc_media_get_names(void);
121 187
@@ -126,7 +192,6 @@ void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr);
126struct bearer *tipc_bearer_find_interface(const char *if_name); 192struct bearer *tipc_bearer_find_interface(const char *if_name);
127int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr); 193int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr);
128int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr); 194int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr);
129int tipc_bearer_init(void);
130void tipc_bearer_stop(void); 195void tipc_bearer_stop(void);
131void tipc_bearer_lock_push(struct bearer *b_ptr); 196void tipc_bearer_lock_push(struct bearer *b_ptr);
132 197
diff --git a/net/tipc/cluster.c b/net/tipc/cluster.c
deleted file mode 100644
index 7fea14b98b97..000000000000
--- a/net/tipc/cluster.c
+++ /dev/null
@@ -1,557 +0,0 @@
1/*
2 * net/tipc/cluster.c: TIPC cluster management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "cluster.h"
39#include "addr.h"
40#include "node_subscr.h"
41#include "link.h"
42#include "node.h"
43#include "net.h"
44#include "msg.h"
45#include "bearer.h"
46
47static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf,
48 u32 lower, u32 upper);
49static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest);
50
51struct tipc_node **tipc_local_nodes = NULL;
52struct tipc_node_map tipc_cltr_bcast_nodes = {0,{0,}};
53u32 tipc_highest_allowed_slave = 0;
54
55struct cluster *tipc_cltr_create(u32 addr)
56{
57 struct _zone *z_ptr;
58 struct cluster *c_ptr;
59 int max_nodes;
60
61 c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC);
62 if (c_ptr == NULL) {
63 warn("Cluster creation failure, no memory\n");
64 return NULL;
65 }
66
67 c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
68 if (in_own_cluster(addr))
69 max_nodes = LOWEST_SLAVE + tipc_max_slaves;
70 else
71 max_nodes = tipc_max_nodes + 1;
72
73 c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC);
74 if (c_ptr->nodes == NULL) {
75 warn("Cluster creation failure, no memory for node area\n");
76 kfree(c_ptr);
77 return NULL;
78 }
79
80 if (in_own_cluster(addr))
81 tipc_local_nodes = c_ptr->nodes;
82 c_ptr->highest_slave = LOWEST_SLAVE - 1;
83 c_ptr->highest_node = 0;
84
85 z_ptr = tipc_zone_find(tipc_zone(addr));
86 if (!z_ptr) {
87 z_ptr = tipc_zone_create(addr);
88 }
89 if (!z_ptr) {
90 kfree(c_ptr->nodes);
91 kfree(c_ptr);
92 return NULL;
93 }
94
95 tipc_zone_attach_cluster(z_ptr, c_ptr);
96 c_ptr->owner = z_ptr;
97 return c_ptr;
98}
99
100void tipc_cltr_delete(struct cluster *c_ptr)
101{
102 u32 n_num;
103
104 if (!c_ptr)
105 return;
106 for (n_num = 1; n_num <= c_ptr->highest_node; n_num++) {
107 tipc_node_delete(c_ptr->nodes[n_num]);
108 }
109 for (n_num = LOWEST_SLAVE; n_num <= c_ptr->highest_slave; n_num++) {
110 tipc_node_delete(c_ptr->nodes[n_num]);
111 }
112 kfree(c_ptr->nodes);
113 kfree(c_ptr);
114}
115
116
117void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr)
118{
119 u32 n_num = tipc_node(n_ptr->addr);
120 u32 max_n_num = tipc_max_nodes;
121
122 if (in_own_cluster(n_ptr->addr))
123 max_n_num = tipc_highest_allowed_slave;
124 assert(n_num > 0);
125 assert(n_num <= max_n_num);
126 assert(c_ptr->nodes[n_num] == NULL);
127 c_ptr->nodes[n_num] = n_ptr;
128 if (n_num > c_ptr->highest_node)
129 c_ptr->highest_node = n_num;
130}
131
132/**
133 * tipc_cltr_select_router - select router to a cluster
134 *
135 * Uses deterministic and fair algorithm.
136 */
137
138u32 tipc_cltr_select_router(struct cluster *c_ptr, u32 ref)
139{
140 u32 n_num;
141 u32 ulim = c_ptr->highest_node;
142 u32 mask;
143 u32 tstart;
144
145 assert(!in_own_cluster(c_ptr->addr));
146 if (!ulim)
147 return 0;
148
149 /* Start entry must be random */
150 mask = tipc_max_nodes;
151 while (mask > ulim)
152 mask >>= 1;
153 tstart = ref & mask;
154 n_num = tstart;
155
156 /* Lookup upwards with wrap-around */
157 do {
158 if (tipc_node_is_up(c_ptr->nodes[n_num]))
159 break;
160 } while (++n_num <= ulim);
161 if (n_num > ulim) {
162 n_num = 1;
163 do {
164 if (tipc_node_is_up(c_ptr->nodes[n_num]))
165 break;
166 } while (++n_num < tstart);
167 if (n_num == tstart)
168 return 0;
169 }
170 assert(n_num <= ulim);
171 return tipc_node_select_router(c_ptr->nodes[n_num], ref);
172}
173
174/**
175 * tipc_cltr_select_node - select destination node within a remote cluster
176 *
177 * Uses deterministic and fair algorithm.
178 */
179
180struct tipc_node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector)
181{
182 u32 n_num;
183 u32 mask = tipc_max_nodes;
184 u32 start_entry;
185
186 assert(!in_own_cluster(c_ptr->addr));
187 if (!c_ptr->highest_node)
188 return NULL;
189
190 /* Start entry must be random */
191 while (mask > c_ptr->highest_node) {
192 mask >>= 1;
193 }
194 start_entry = (selector & mask) ? selector & mask : 1u;
195 assert(start_entry <= c_ptr->highest_node);
196
197 /* Lookup upwards with wrap-around */
198 for (n_num = start_entry; n_num <= c_ptr->highest_node; n_num++) {
199 if (tipc_node_has_active_links(c_ptr->nodes[n_num]))
200 return c_ptr->nodes[n_num];
201 }
202 for (n_num = 1; n_num < start_entry; n_num++) {
203 if (tipc_node_has_active_links(c_ptr->nodes[n_num]))
204 return c_ptr->nodes[n_num];
205 }
206 return NULL;
207}
208
209/*
210 * Routing table management: See description in node.c
211 */
212
213static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest)
214{
215 u32 size = INT_H_SIZE + data_size;
216 struct sk_buff *buf = tipc_buf_acquire(size);
217 struct tipc_msg *msg;
218
219 if (buf) {
220 msg = buf_msg(buf);
221 memset((char *)msg, 0, size);
222 tipc_msg_init(msg, ROUTE_DISTRIBUTOR, 0, INT_H_SIZE, dest);
223 }
224 return buf;
225}
226
227void tipc_cltr_bcast_new_route(struct cluster *c_ptr, u32 dest,
228 u32 lower, u32 upper)
229{
230 struct sk_buff *buf = tipc_cltr_prepare_routing_msg(0, c_ptr->addr);
231 struct tipc_msg *msg;
232
233 if (buf) {
234 msg = buf_msg(buf);
235 msg_set_remote_node(msg, dest);
236 msg_set_type(msg, ROUTE_ADDITION);
237 tipc_cltr_multicast(c_ptr, buf, lower, upper);
238 } else {
239 warn("Memory squeeze: broadcast of new route failed\n");
240 }
241}
242
243void tipc_cltr_bcast_lost_route(struct cluster *c_ptr, u32 dest,
244 u32 lower, u32 upper)
245{
246 struct sk_buff *buf = tipc_cltr_prepare_routing_msg(0, c_ptr->addr);
247 struct tipc_msg *msg;
248
249 if (buf) {
250 msg = buf_msg(buf);
251 msg_set_remote_node(msg, dest);
252 msg_set_type(msg, ROUTE_REMOVAL);
253 tipc_cltr_multicast(c_ptr, buf, lower, upper);
254 } else {
255 warn("Memory squeeze: broadcast of lost route failed\n");
256 }
257}
258
259void tipc_cltr_send_slave_routes(struct cluster *c_ptr, u32 dest)
260{
261 struct sk_buff *buf;
262 struct tipc_msg *msg;
263 u32 highest = c_ptr->highest_slave;
264 u32 n_num;
265 int send = 0;
266
267 assert(!is_slave(dest));
268 assert(in_own_cluster(dest));
269 assert(in_own_cluster(c_ptr->addr));
270 if (highest <= LOWEST_SLAVE)
271 return;
272 buf = tipc_cltr_prepare_routing_msg(highest - LOWEST_SLAVE + 1,
273 c_ptr->addr);
274 if (buf) {
275 msg = buf_msg(buf);
276 msg_set_remote_node(msg, c_ptr->addr);
277 msg_set_type(msg, SLAVE_ROUTING_TABLE);
278 for (n_num = LOWEST_SLAVE; n_num <= highest; n_num++) {
279 if (c_ptr->nodes[n_num] &&
280 tipc_node_has_active_links(c_ptr->nodes[n_num])) {
281 send = 1;
282 msg_set_dataoctet(msg, n_num);
283 }
284 }
285 if (send)
286 tipc_link_send(buf, dest, dest);
287 else
288 buf_discard(buf);
289 } else {
290 warn("Memory squeeze: broadcast of lost route failed\n");
291 }
292}
293
294void tipc_cltr_send_ext_routes(struct cluster *c_ptr, u32 dest)
295{
296 struct sk_buff *buf;
297 struct tipc_msg *msg;
298 u32 highest = c_ptr->highest_node;
299 u32 n_num;
300 int send = 0;
301
302 if (in_own_cluster(c_ptr->addr))
303 return;
304 assert(!is_slave(dest));
305 assert(in_own_cluster(dest));
306 highest = c_ptr->highest_node;
307 buf = tipc_cltr_prepare_routing_msg(highest + 1, c_ptr->addr);
308 if (buf) {
309 msg = buf_msg(buf);
310 msg_set_remote_node(msg, c_ptr->addr);
311 msg_set_type(msg, EXT_ROUTING_TABLE);
312 for (n_num = 1; n_num <= highest; n_num++) {
313 if (c_ptr->nodes[n_num] &&
314 tipc_node_has_active_links(c_ptr->nodes[n_num])) {
315 send = 1;
316 msg_set_dataoctet(msg, n_num);
317 }
318 }
319 if (send)
320 tipc_link_send(buf, dest, dest);
321 else
322 buf_discard(buf);
323 } else {
324 warn("Memory squeeze: broadcast of external route failed\n");
325 }
326}
327
328void tipc_cltr_send_local_routes(struct cluster *c_ptr, u32 dest)
329{
330 struct sk_buff *buf;
331 struct tipc_msg *msg;
332 u32 highest = c_ptr->highest_node;
333 u32 n_num;
334 int send = 0;
335
336 assert(is_slave(dest));
337 assert(in_own_cluster(c_ptr->addr));
338 buf = tipc_cltr_prepare_routing_msg(highest, c_ptr->addr);
339 if (buf) {
340 msg = buf_msg(buf);
341 msg_set_remote_node(msg, c_ptr->addr);
342 msg_set_type(msg, LOCAL_ROUTING_TABLE);
343 for (n_num = 1; n_num <= highest; n_num++) {
344 if (c_ptr->nodes[n_num] &&
345 tipc_node_has_active_links(c_ptr->nodes[n_num])) {
346 send = 1;
347 msg_set_dataoctet(msg, n_num);
348 }
349 }
350 if (send)
351 tipc_link_send(buf, dest, dest);
352 else
353 buf_discard(buf);
354 } else {
355 warn("Memory squeeze: broadcast of local route failed\n");
356 }
357}
358
359void tipc_cltr_recv_routing_table(struct sk_buff *buf)
360{
361 struct tipc_msg *msg = buf_msg(buf);
362 struct cluster *c_ptr;
363 struct tipc_node *n_ptr;
364 unchar *node_table;
365 u32 table_size;
366 u32 router;
367 u32 rem_node = msg_remote_node(msg);
368 u32 z_num;
369 u32 c_num;
370 u32 n_num;
371
372 c_ptr = tipc_cltr_find(rem_node);
373 if (!c_ptr) {
374 c_ptr = tipc_cltr_create(rem_node);
375 if (!c_ptr) {
376 buf_discard(buf);
377 return;
378 }
379 }
380
381 node_table = buf->data + msg_hdr_sz(msg);
382 table_size = msg_size(msg) - msg_hdr_sz(msg);
383 router = msg_prevnode(msg);
384 z_num = tipc_zone(rem_node);
385 c_num = tipc_cluster(rem_node);
386
387 switch (msg_type(msg)) {
388 case LOCAL_ROUTING_TABLE:
389 assert(is_slave(tipc_own_addr));
390 case EXT_ROUTING_TABLE:
391 for (n_num = 1; n_num < table_size; n_num++) {
392 if (node_table[n_num]) {
393 u32 addr = tipc_addr(z_num, c_num, n_num);
394 n_ptr = c_ptr->nodes[n_num];
395 if (!n_ptr) {
396 n_ptr = tipc_node_create(addr);
397 }
398 if (n_ptr)
399 tipc_node_add_router(n_ptr, router);
400 }
401 }
402 break;
403 case SLAVE_ROUTING_TABLE:
404 assert(!is_slave(tipc_own_addr));
405 assert(in_own_cluster(c_ptr->addr));
406 for (n_num = 1; n_num < table_size; n_num++) {
407 if (node_table[n_num]) {
408 u32 slave_num = n_num + LOWEST_SLAVE;
409 u32 addr = tipc_addr(z_num, c_num, slave_num);
410 n_ptr = c_ptr->nodes[slave_num];
411 if (!n_ptr) {
412 n_ptr = tipc_node_create(addr);
413 }
414 if (n_ptr)
415 tipc_node_add_router(n_ptr, router);
416 }
417 }
418 break;
419 case ROUTE_ADDITION:
420 if (!is_slave(tipc_own_addr)) {
421 assert(!in_own_cluster(c_ptr->addr) ||
422 is_slave(rem_node));
423 } else {
424 assert(in_own_cluster(c_ptr->addr) &&
425 !is_slave(rem_node));
426 }
427 n_ptr = c_ptr->nodes[tipc_node(rem_node)];
428 if (!n_ptr)
429 n_ptr = tipc_node_create(rem_node);
430 if (n_ptr)
431 tipc_node_add_router(n_ptr, router);
432 break;
433 case ROUTE_REMOVAL:
434 if (!is_slave(tipc_own_addr)) {
435 assert(!in_own_cluster(c_ptr->addr) ||
436 is_slave(rem_node));
437 } else {
438 assert(in_own_cluster(c_ptr->addr) &&
439 !is_slave(rem_node));
440 }
441 n_ptr = c_ptr->nodes[tipc_node(rem_node)];
442 if (n_ptr)
443 tipc_node_remove_router(n_ptr, router);
444 break;
445 default:
446 assert(!"Illegal routing manager message received\n");
447 }
448 buf_discard(buf);
449}
450
451void tipc_cltr_remove_as_router(struct cluster *c_ptr, u32 router)
452{
453 u32 start_entry;
454 u32 tstop;
455 u32 n_num;
456
457 if (is_slave(router))
458 return; /* Slave nodes can not be routers */
459
460 if (in_own_cluster(c_ptr->addr)) {
461 start_entry = LOWEST_SLAVE;
462 tstop = c_ptr->highest_slave;
463 } else {
464 start_entry = 1;
465 tstop = c_ptr->highest_node;
466 }
467
468 for (n_num = start_entry; n_num <= tstop; n_num++) {
469 if (c_ptr->nodes[n_num]) {
470 tipc_node_remove_router(c_ptr->nodes[n_num], router);
471 }
472 }
473}
474
475/**
476 * tipc_cltr_multicast - multicast message to local nodes
477 */
478
479static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf,
480 u32 lower, u32 upper)
481{
482 struct sk_buff *buf_copy;
483 struct tipc_node *n_ptr;
484 u32 n_num;
485 u32 tstop;
486
487 assert(lower <= upper);
488 assert(((lower >= 1) && (lower <= tipc_max_nodes)) ||
489 ((lower >= LOWEST_SLAVE) && (lower <= tipc_highest_allowed_slave)));
490 assert(((upper >= 1) && (upper <= tipc_max_nodes)) ||
491 ((upper >= LOWEST_SLAVE) && (upper <= tipc_highest_allowed_slave)));
492 assert(in_own_cluster(c_ptr->addr));
493
494 tstop = is_slave(upper) ? c_ptr->highest_slave : c_ptr->highest_node;
495 if (tstop > upper)
496 tstop = upper;
497 for (n_num = lower; n_num <= tstop; n_num++) {
498 n_ptr = c_ptr->nodes[n_num];
499 if (n_ptr && tipc_node_has_active_links(n_ptr)) {
500 buf_copy = skb_copy(buf, GFP_ATOMIC);
501 if (buf_copy == NULL)
502 break;
503 msg_set_destnode(buf_msg(buf_copy), n_ptr->addr);
504 tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr);
505 }
506 }
507 buf_discard(buf);
508}
509
510/**
511 * tipc_cltr_broadcast - broadcast message to all nodes within cluster
512 */
513
514void tipc_cltr_broadcast(struct sk_buff *buf)
515{
516 struct sk_buff *buf_copy;
517 struct cluster *c_ptr;
518 struct tipc_node *n_ptr;
519 u32 n_num;
520 u32 tstart;
521 u32 tstop;
522 u32 node_type;
523
524 if (tipc_mode == TIPC_NET_MODE) {
525 c_ptr = tipc_cltr_find(tipc_own_addr);
526 assert(in_own_cluster(c_ptr->addr)); /* For now */
527
528 /* Send to standard nodes, then repeat loop sending to slaves */
529 tstart = 1;
530 tstop = c_ptr->highest_node;
531 for (node_type = 1; node_type <= 2; node_type++) {
532 for (n_num = tstart; n_num <= tstop; n_num++) {
533 n_ptr = c_ptr->nodes[n_num];
534 if (n_ptr && tipc_node_has_active_links(n_ptr)) {
535 buf_copy = skb_copy(buf, GFP_ATOMIC);
536 if (buf_copy == NULL)
537 goto exit;
538 msg_set_destnode(buf_msg(buf_copy),
539 n_ptr->addr);
540 tipc_link_send(buf_copy, n_ptr->addr,
541 n_ptr->addr);
542 }
543 }
544 tstart = LOWEST_SLAVE;
545 tstop = c_ptr->highest_slave;
546 }
547 }
548exit:
549 buf_discard(buf);
550}
551
552int tipc_cltr_init(void)
553{
554 tipc_highest_allowed_slave = LOWEST_SLAVE + tipc_max_slaves;
555 return tipc_cltr_create(tipc_own_addr) ? 0 : -ENOMEM;
556}
557
diff --git a/net/tipc/cluster.h b/net/tipc/cluster.h
deleted file mode 100644
index 32636d98c9c6..000000000000
--- a/net/tipc/cluster.h
+++ /dev/null
@@ -1,92 +0,0 @@
1/*
2 * net/tipc/cluster.h: Include file for TIPC cluster management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _TIPC_CLUSTER_H
38#define _TIPC_CLUSTER_H
39
40#include "addr.h"
41#include "zone.h"
42
43#define LOWEST_SLAVE 2048u
44
45/**
46 * struct cluster - TIPC cluster structure
47 * @addr: network address of cluster
48 * @owner: pointer to zone that cluster belongs to
49 * @nodes: array of pointers to all nodes within cluster
50 * @highest_node: id of highest numbered node within cluster
51 * @highest_slave: (used for secondary node support)
52 */
53
54struct cluster {
55 u32 addr;
56 struct _zone *owner;
57 struct tipc_node **nodes;
58 u32 highest_node;
59 u32 highest_slave;
60};
61
62
63extern struct tipc_node **tipc_local_nodes;
64extern u32 tipc_highest_allowed_slave;
65extern struct tipc_node_map tipc_cltr_bcast_nodes;
66
67void tipc_cltr_remove_as_router(struct cluster *c_ptr, u32 router);
68void tipc_cltr_send_ext_routes(struct cluster *c_ptr, u32 dest);
69struct tipc_node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector);
70u32 tipc_cltr_select_router(struct cluster *c_ptr, u32 ref);
71void tipc_cltr_recv_routing_table(struct sk_buff *buf);
72struct cluster *tipc_cltr_create(u32 addr);
73void tipc_cltr_delete(struct cluster *c_ptr);
74void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr);
75void tipc_cltr_send_slave_routes(struct cluster *c_ptr, u32 dest);
76void tipc_cltr_broadcast(struct sk_buff *buf);
77int tipc_cltr_init(void);
78
79void tipc_cltr_bcast_new_route(struct cluster *c_ptr, u32 dest, u32 lo, u32 hi);
80void tipc_cltr_send_local_routes(struct cluster *c_ptr, u32 dest);
81void tipc_cltr_bcast_lost_route(struct cluster *c_ptr, u32 dest, u32 lo, u32 hi);
82
83static inline struct cluster *tipc_cltr_find(u32 addr)
84{
85 struct _zone *z_ptr = tipc_zone_find(addr);
86
87 if (z_ptr)
88 return z_ptr->clusters[1];
89 return NULL;
90}
91
92#endif
diff --git a/net/tipc/config.c b/net/tipc/config.c
index 50a6133a3668..e16750dcf3c1 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -35,30 +35,11 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "bearer.h"
40#include "port.h" 38#include "port.h"
41#include "link.h"
42#include "zone.h"
43#include "addr.h"
44#include "name_table.h" 39#include "name_table.h"
45#include "node.h"
46#include "config.h" 40#include "config.h"
47#include "discover.h"
48 41
49struct subscr_data { 42static u32 config_port_ref;
50 char usr_handle[8];
51 u32 domain;
52 u32 port_ref;
53 struct list_head subd_list;
54};
55
56struct manager {
57 u32 user_ref;
58 u32 port_ref;
59};
60
61static struct manager mng = { 0};
62 43
63static DEFINE_SPINLOCK(config_lock); 44static DEFINE_SPINLOCK(config_lock);
64 45
@@ -83,10 +64,8 @@ int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
83 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf); 64 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
84 int new_tlv_space = TLV_SPACE(tlv_data_size); 65 int new_tlv_space = TLV_SPACE(tlv_data_size);
85 66
86 if (skb_tailroom(buf) < new_tlv_space) { 67 if (skb_tailroom(buf) < new_tlv_space)
87 dbg("tipc_cfg_append_tlv unable to append TLV\n");
88 return 0; 68 return 0;
89 }
90 skb_put(buf, new_tlv_space); 69 skb_put(buf, new_tlv_space);
91 tlv->tlv_type = htons(tlv_type); 70 tlv->tlv_type = htons(tlv_type);
92 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size)); 71 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
@@ -281,38 +260,6 @@ static struct sk_buff *cfg_set_max_ports(void)
281 return tipc_cfg_reply_none(); 260 return tipc_cfg_reply_none();
282} 261}
283 262
284static struct sk_buff *cfg_set_max_zones(void)
285{
286 u32 value;
287
288 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
289 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
290 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
291 if (value == tipc_max_zones)
292 return tipc_cfg_reply_none();
293 if (value != delimit(value, 1, 255))
294 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
295 " (max zones must be 1-255)");
296 if (tipc_mode == TIPC_NET_MODE)
297 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
298 " (cannot change max zones once TIPC has joined a network)");
299 tipc_max_zones = value;
300 return tipc_cfg_reply_none();
301}
302
303static struct sk_buff *cfg_set_max_clusters(void)
304{
305 u32 value;
306
307 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
308 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
309 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
310 if (value != delimit(value, 1, 1))
311 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
312 " (max clusters fixed at 1)");
313 return tipc_cfg_reply_none();
314}
315
316static struct sk_buff *cfg_set_max_nodes(void) 263static struct sk_buff *cfg_set_max_nodes(void)
317{ 264{
318 u32 value; 265 u32 value;
@@ -332,19 +279,6 @@ static struct sk_buff *cfg_set_max_nodes(void)
332 return tipc_cfg_reply_none(); 279 return tipc_cfg_reply_none();
333} 280}
334 281
335static struct sk_buff *cfg_set_max_slaves(void)
336{
337 u32 value;
338
339 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
340 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
341 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
342 if (value != 0)
343 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
344 " (max secondary nodes fixed at 0)");
345 return tipc_cfg_reply_none();
346}
347
348static struct sk_buff *cfg_set_netid(void) 282static struct sk_buff *cfg_set_netid(void)
349{ 283{
350 u32 value; 284 u32 value;
@@ -388,8 +322,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
388 } else if (!tipc_remote_management) { 322 } else if (!tipc_remote_management) {
389 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE); 323 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
390 goto exit; 324 goto exit;
391 } 325 } else if (cmd >= 0x4000) {
392 else if (cmd >= 0x4000) {
393 u32 domain = 0; 326 u32 domain = 0;
394 327
395 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) || 328 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
@@ -464,18 +397,9 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
464 case TIPC_CMD_SET_MAX_SUBSCR: 397 case TIPC_CMD_SET_MAX_SUBSCR:
465 rep_tlv_buf = cfg_set_max_subscriptions(); 398 rep_tlv_buf = cfg_set_max_subscriptions();
466 break; 399 break;
467 case TIPC_CMD_SET_MAX_ZONES:
468 rep_tlv_buf = cfg_set_max_zones();
469 break;
470 case TIPC_CMD_SET_MAX_CLUSTERS:
471 rep_tlv_buf = cfg_set_max_clusters();
472 break;
473 case TIPC_CMD_SET_MAX_NODES: 400 case TIPC_CMD_SET_MAX_NODES:
474 rep_tlv_buf = cfg_set_max_nodes(); 401 rep_tlv_buf = cfg_set_max_nodes();
475 break; 402 break;
476 case TIPC_CMD_SET_MAX_SLAVES:
477 rep_tlv_buf = cfg_set_max_slaves();
478 break;
479 case TIPC_CMD_SET_NETID: 403 case TIPC_CMD_SET_NETID:
480 rep_tlv_buf = cfg_set_netid(); 404 rep_tlv_buf = cfg_set_netid();
481 break; 405 break;
@@ -491,18 +415,9 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
491 case TIPC_CMD_GET_MAX_SUBSCR: 415 case TIPC_CMD_GET_MAX_SUBSCR:
492 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions); 416 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
493 break; 417 break;
494 case TIPC_CMD_GET_MAX_ZONES:
495 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
496 break;
497 case TIPC_CMD_GET_MAX_CLUSTERS:
498 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
499 break;
500 case TIPC_CMD_GET_MAX_NODES: 418 case TIPC_CMD_GET_MAX_NODES:
501 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes); 419 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
502 break; 420 break;
503 case TIPC_CMD_GET_MAX_SLAVES:
504 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
505 break;
506 case TIPC_CMD_GET_NETID: 421 case TIPC_CMD_GET_NETID:
507 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); 422 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
508 break; 423 break;
@@ -510,6 +425,15 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
510 rep_tlv_buf = 425 rep_tlv_buf =
511 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN); 426 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
512 break; 427 break;
428 case TIPC_CMD_SET_MAX_ZONES:
429 case TIPC_CMD_GET_MAX_ZONES:
430 case TIPC_CMD_SET_MAX_SLAVES:
431 case TIPC_CMD_GET_MAX_SLAVES:
432 case TIPC_CMD_SET_MAX_CLUSTERS:
433 case TIPC_CMD_GET_MAX_CLUSTERS:
434 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
435 " (obsolete command)");
436 break;
513 default: 437 default:
514 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED 438 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
515 " (unknown command)"); 439 " (unknown command)");
@@ -572,20 +496,16 @@ int tipc_cfg_init(void)
572 struct tipc_name_seq seq; 496 struct tipc_name_seq seq;
573 int res; 497 int res;
574 498
575 res = tipc_attach(&mng.user_ref, NULL, NULL); 499 res = tipc_createport(NULL, TIPC_CRITICAL_IMPORTANCE,
576 if (res)
577 goto failed;
578
579 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
580 NULL, NULL, NULL, 500 NULL, NULL, NULL,
581 NULL, cfg_named_msg_event, NULL, 501 NULL, cfg_named_msg_event, NULL,
582 NULL, &mng.port_ref); 502 NULL, &config_port_ref);
583 if (res) 503 if (res)
584 goto failed; 504 goto failed;
585 505
586 seq.type = TIPC_CFG_SRV; 506 seq.type = TIPC_CFG_SRV;
587 seq.lower = seq.upper = tipc_own_addr; 507 seq.lower = seq.upper = tipc_own_addr;
588 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq); 508 res = tipc_nametbl_publish_rsv(config_port_ref, TIPC_ZONE_SCOPE, &seq);
589 if (res) 509 if (res)
590 goto failed; 510 goto failed;
591 511
@@ -593,15 +513,13 @@ int tipc_cfg_init(void)
593 513
594failed: 514failed:
595 err("Unable to create configuration service\n"); 515 err("Unable to create configuration service\n");
596 tipc_detach(mng.user_ref);
597 mng.user_ref = 0;
598 return res; 516 return res;
599} 517}
600 518
601void tipc_cfg_stop(void) 519void tipc_cfg_stop(void)
602{ 520{
603 if (mng.user_ref) { 521 if (config_port_ref) {
604 tipc_detach(mng.user_ref); 522 tipc_deleteport(config_port_ref);
605 mng.user_ref = 0; 523 config_port_ref = 0;
606 } 524 }
607} 525}
diff --git a/net/tipc/config.h b/net/tipc/config.h
index 481e12ece715..443159a166fd 100644
--- a/net/tipc/config.h
+++ b/net/tipc/config.h
@@ -39,7 +39,6 @@
39 39
40/* ---------------------------------------------------------------------- */ 40/* ---------------------------------------------------------------------- */
41 41
42#include "core.h"
43#include "link.h" 42#include "link.h"
44 43
45struct sk_buff *tipc_cfg_reply_alloc(int payload_size); 44struct sk_buff *tipc_cfg_reply_alloc(int payload_size);
diff --git a/net/tipc/core.c b/net/tipc/core.c
index e2a09eb8efd4..e071579e0850 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -34,37 +34,17 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <linux/init.h>
38#include <linux/module.h>
39#include <linux/kernel.h>
40#include <linux/random.h>
41
42#include "core.h" 37#include "core.h"
43#include "dbg.h"
44#include "ref.h" 38#include "ref.h"
45#include "net.h"
46#include "user_reg.h"
47#include "name_table.h" 39#include "name_table.h"
48#include "subscr.h" 40#include "subscr.h"
49#include "config.h" 41#include "config.h"
50 42
51 43
52#ifndef CONFIG_TIPC_ZONES
53#define CONFIG_TIPC_ZONES 3
54#endif
55
56#ifndef CONFIG_TIPC_CLUSTERS
57#define CONFIG_TIPC_CLUSTERS 1
58#endif
59
60#ifndef CONFIG_TIPC_NODES 44#ifndef CONFIG_TIPC_NODES
61#define CONFIG_TIPC_NODES 255 45#define CONFIG_TIPC_NODES 255
62#endif 46#endif
63 47
64#ifndef CONFIG_TIPC_SLAVE_NODES
65#define CONFIG_TIPC_SLAVE_NODES 0
66#endif
67
68#ifndef CONFIG_TIPC_PORTS 48#ifndef CONFIG_TIPC_PORTS
69#define CONFIG_TIPC_PORTS 8191 49#define CONFIG_TIPC_PORTS 8191
70#endif 50#endif
@@ -85,10 +65,7 @@ const char tipc_alphabet[] =
85/* configurable TIPC parameters */ 65/* configurable TIPC parameters */
86 66
87u32 tipc_own_addr; 67u32 tipc_own_addr;
88int tipc_max_zones;
89int tipc_max_clusters;
90int tipc_max_nodes; 68int tipc_max_nodes;
91int tipc_max_slaves;
92int tipc_max_ports; 69int tipc_max_ports;
93int tipc_max_subscriptions; 70int tipc_max_subscriptions;
94int tipc_max_publications; 71int tipc_max_publications;
@@ -138,10 +115,11 @@ int tipc_core_start_net(unsigned long addr)
138{ 115{
139 int res; 116 int res;
140 117
141 if ((res = tipc_net_start(addr)) || 118 res = tipc_net_start(addr);
142 (res = tipc_eth_media_start())) { 119 if (!res)
120 res = tipc_eth_media_start();
121 if (res)
143 tipc_core_stop_net(); 122 tipc_core_stop_net();
144 }
145 return res; 123 return res;
146} 124}
147 125
@@ -160,7 +138,6 @@ static void tipc_core_stop(void)
160 tipc_handler_stop(); 138 tipc_handler_stop();
161 tipc_cfg_stop(); 139 tipc_cfg_stop();
162 tipc_subscr_stop(); 140 tipc_subscr_stop();
163 tipc_reg_stop();
164 tipc_nametbl_stop(); 141 tipc_nametbl_stop();
165 tipc_ref_table_stop(); 142 tipc_ref_table_stop();
166 tipc_socket_stop(); 143 tipc_socket_stop();
@@ -181,16 +158,22 @@ static int tipc_core_start(void)
181 get_random_bytes(&tipc_random, sizeof(tipc_random)); 158 get_random_bytes(&tipc_random, sizeof(tipc_random));
182 tipc_mode = TIPC_NODE_MODE; 159 tipc_mode = TIPC_NODE_MODE;
183 160
184 if ((res = tipc_handler_start()) || 161 res = tipc_handler_start();
185 (res = tipc_ref_table_init(tipc_max_ports, tipc_random)) || 162 if (!res)
186 (res = tipc_reg_start()) || 163 res = tipc_ref_table_init(tipc_max_ports, tipc_random);
187 (res = tipc_nametbl_init()) || 164 if (!res)
188 (res = tipc_k_signal((Handler)tipc_subscr_start, 0)) || 165 res = tipc_nametbl_init();
189 (res = tipc_k_signal((Handler)tipc_cfg_init, 0)) || 166 if (!res)
190 (res = tipc_netlink_start()) || 167 res = tipc_k_signal((Handler)tipc_subscr_start, 0);
191 (res = tipc_socket_init())) { 168 if (!res)
169 res = tipc_k_signal((Handler)tipc_cfg_init, 0);
170 if (!res)
171 res = tipc_netlink_start();
172 if (!res)
173 res = tipc_socket_init();
174 if (res)
192 tipc_core_stop(); 175 tipc_core_stop();
193 } 176
194 return res; 177 return res;
195} 178}
196 179
@@ -210,13 +193,11 @@ static int __init tipc_init(void)
210 tipc_max_publications = 10000; 193 tipc_max_publications = 10000;
211 tipc_max_subscriptions = 2000; 194 tipc_max_subscriptions = 2000;
212 tipc_max_ports = CONFIG_TIPC_PORTS; 195 tipc_max_ports = CONFIG_TIPC_PORTS;
213 tipc_max_zones = CONFIG_TIPC_ZONES;
214 tipc_max_clusters = CONFIG_TIPC_CLUSTERS;
215 tipc_max_nodes = CONFIG_TIPC_NODES; 196 tipc_max_nodes = CONFIG_TIPC_NODES;
216 tipc_max_slaves = CONFIG_TIPC_SLAVE_NODES;
217 tipc_net_id = 4711; 197 tipc_net_id = 4711;
218 198
219 if ((res = tipc_core_start())) 199 res = tipc_core_start();
200 if (res)
220 err("Unable to start in single node mode\n"); 201 err("Unable to start in single node mode\n");
221 else 202 else
222 info("Started in single node mode\n"); 203 info("Started in single node mode\n");
@@ -236,43 +217,3 @@ module_exit(tipc_exit);
236MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication"); 217MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication");
237MODULE_LICENSE("Dual BSD/GPL"); 218MODULE_LICENSE("Dual BSD/GPL");
238MODULE_VERSION(TIPC_MOD_VER); 219MODULE_VERSION(TIPC_MOD_VER);
239
240/* Native TIPC API for kernel-space applications (see tipc.h) */
241
242EXPORT_SYMBOL(tipc_attach);
243EXPORT_SYMBOL(tipc_detach);
244EXPORT_SYMBOL(tipc_createport);
245EXPORT_SYMBOL(tipc_deleteport);
246EXPORT_SYMBOL(tipc_ownidentity);
247EXPORT_SYMBOL(tipc_portimportance);
248EXPORT_SYMBOL(tipc_set_portimportance);
249EXPORT_SYMBOL(tipc_portunreliable);
250EXPORT_SYMBOL(tipc_set_portunreliable);
251EXPORT_SYMBOL(tipc_portunreturnable);
252EXPORT_SYMBOL(tipc_set_portunreturnable);
253EXPORT_SYMBOL(tipc_publish);
254EXPORT_SYMBOL(tipc_withdraw);
255EXPORT_SYMBOL(tipc_connect2port);
256EXPORT_SYMBOL(tipc_disconnect);
257EXPORT_SYMBOL(tipc_shutdown);
258EXPORT_SYMBOL(tipc_send);
259EXPORT_SYMBOL(tipc_send2name);
260EXPORT_SYMBOL(tipc_send2port);
261EXPORT_SYMBOL(tipc_multicast);
262
263/* TIPC API for external bearers (see tipc_bearer.h) */
264
265EXPORT_SYMBOL(tipc_block_bearer);
266EXPORT_SYMBOL(tipc_continue);
267EXPORT_SYMBOL(tipc_disable_bearer);
268EXPORT_SYMBOL(tipc_enable_bearer);
269EXPORT_SYMBOL(tipc_recv_msg);
270EXPORT_SYMBOL(tipc_register_media);
271
272/* TIPC API for external APIs (see tipc_port.h) */
273
274EXPORT_SYMBOL(tipc_createport_raw);
275EXPORT_SYMBOL(tipc_reject_msg);
276EXPORT_SYMBOL(tipc_send_buf_fast);
277EXPORT_SYMBOL(tipc_acknowledge);
278
diff --git a/net/tipc/core.h b/net/tipc/core.h
index e19389e57227..997158546e25 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -39,10 +39,6 @@
39 39
40#include <linux/tipc.h> 40#include <linux/tipc.h>
41#include <linux/tipc_config.h> 41#include <linux/tipc_config.h>
42#include <net/tipc/tipc_msg.h>
43#include <net/tipc/tipc_port.h>
44#include <net/tipc/tipc_bearer.h>
45#include <net/tipc/tipc.h>
46#include <linux/types.h> 42#include <linux/types.h>
47#include <linux/kernel.h> 43#include <linux/kernel.h>
48#include <linux/errno.h> 44#include <linux/errno.h>
@@ -62,6 +58,9 @@
62 58
63#define TIPC_MOD_VER "2.0.0" 59#define TIPC_MOD_VER "2.0.0"
64 60
61struct tipc_msg; /* msg.h */
62struct print_buf; /* log.h */
63
65/* 64/*
66 * TIPC sanity test macros 65 * TIPC sanity test macros
67 */ 66 */
@@ -84,6 +83,7 @@
84 * user-defined buffers can be configured to do the same thing. 83 * user-defined buffers can be configured to do the same thing.
85 */ 84 */
86extern struct print_buf *const TIPC_NULL; 85extern struct print_buf *const TIPC_NULL;
86extern struct print_buf *const TIPC_CONS;
87extern struct print_buf *const TIPC_LOG; 87extern struct print_buf *const TIPC_LOG;
88 88
89void tipc_printf(struct print_buf *, const char *fmt, ...); 89void tipc_printf(struct print_buf *, const char *fmt, ...);
@@ -96,73 +96,35 @@ void tipc_printf(struct print_buf *, const char *fmt, ...);
96#define TIPC_OUTPUT TIPC_LOG 96#define TIPC_OUTPUT TIPC_LOG
97#endif 97#endif
98 98
99/*
100 * TIPC can be configured to send system messages to TIPC_OUTPUT
101 * or to the system console only.
102 */
103
104#ifdef CONFIG_TIPC_DEBUG
105
106#define err(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ 99#define err(fmt, arg...) tipc_printf(TIPC_OUTPUT, \
107 KERN_ERR "TIPC: " fmt, ## arg) 100 KERN_ERR "TIPC: " fmt, ## arg)
108#define warn(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ 101#define warn(fmt, arg...) tipc_printf(TIPC_OUTPUT, \
109 KERN_WARNING "TIPC: " fmt, ## arg) 102 KERN_WARNING "TIPC: " fmt, ## arg)
110#define info(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ 103#define info(fmt, arg...) tipc_printf(TIPC_OUTPUT, \
111 KERN_NOTICE "TIPC: " fmt, ## arg) 104 KERN_NOTICE "TIPC: " fmt, ## arg)
112
113#else
114
115#define err(fmt, arg...) printk(KERN_ERR "TIPC: " fmt , ## arg)
116#define info(fmt, arg...) printk(KERN_INFO "TIPC: " fmt , ## arg)
117#define warn(fmt, arg...) printk(KERN_WARNING "TIPC: " fmt , ## arg)
118 105
119#endif 106#ifdef CONFIG_TIPC_DEBUG
120 107
121/* 108/*
122 * DBG_OUTPUT is the destination print buffer for debug messages. 109 * DBG_OUTPUT is the destination print buffer for debug messages.
123 * It defaults to the the null print buffer, but can be redefined
124 * (typically in the individual .c files being debugged) to allow
125 * selected debug messages to be generated where needed.
126 */ 110 */
127 111
128#ifndef DBG_OUTPUT 112#ifndef DBG_OUTPUT
129#define DBG_OUTPUT TIPC_NULL 113#define DBG_OUTPUT TIPC_LOG
130#endif 114#endif
131 115
132/* 116#define dbg(fmt, arg...) tipc_printf(DBG_OUTPUT, KERN_DEBUG fmt, ## arg);
133 * TIPC can be configured to send debug messages to the specified print buffer
134 * (typically DBG_OUTPUT) or to suppress them entirely.
135 */
136 117
137#ifdef CONFIG_TIPC_DEBUG 118#define msg_dbg(msg, txt) tipc_msg_dbg(DBG_OUTPUT, msg, txt);
138
139#define dbg(fmt, arg...) \
140 do { \
141 if (DBG_OUTPUT != TIPC_NULL) \
142 tipc_printf(DBG_OUTPUT, fmt, ## arg); \
143 } while (0)
144#define msg_dbg(msg, txt) \
145 do { \
146 if (DBG_OUTPUT != TIPC_NULL) \
147 tipc_msg_dbg(DBG_OUTPUT, msg, txt); \
148 } while (0)
149#define dump(fmt, arg...) \
150 do { \
151 if (DBG_OUTPUT != TIPC_NULL) \
152 tipc_dump_dbg(DBG_OUTPUT, fmt, ##arg); \
153 } while (0)
154 119
155void tipc_msg_dbg(struct print_buf *, struct tipc_msg *, const char *); 120void tipc_msg_dbg(struct print_buf *, struct tipc_msg *, const char *);
156void tipc_dump_dbg(struct print_buf *, const char *fmt, ...);
157 121
158#else 122#else
159 123
160#define dbg(fmt, arg...) do {} while (0) 124#define dbg(fmt, arg...) do {} while (0)
161#define msg_dbg(msg, txt) do {} while (0) 125#define msg_dbg(msg, txt) do {} while (0)
162#define dump(fmt, arg...) do {} while (0)
163 126
164#define tipc_msg_dbg(...) do {} while (0) 127#define tipc_msg_dbg(buf, msg, txt) do {} while (0)
165#define tipc_dump_dbg(...) do {} while (0)
166 128
167#endif 129#endif
168 130
@@ -174,14 +136,18 @@ void tipc_dump_dbg(struct print_buf *, const char *fmt, ...);
174#define ELINKCONG EAGAIN /* link congestion <=> resource unavailable */ 136#define ELINKCONG EAGAIN /* link congestion <=> resource unavailable */
175 137
176/* 138/*
139 * TIPC operating mode routines
140 */
141#define TIPC_NOT_RUNNING 0
142#define TIPC_NODE_MODE 1
143#define TIPC_NET_MODE 2
144
145/*
177 * Global configuration variables 146 * Global configuration variables
178 */ 147 */
179 148
180extern u32 tipc_own_addr; 149extern u32 tipc_own_addr;
181extern int tipc_max_zones;
182extern int tipc_max_clusters;
183extern int tipc_max_nodes; 150extern int tipc_max_nodes;
184extern int tipc_max_slaves;
185extern int tipc_max_ports; 151extern int tipc_max_ports;
186extern int tipc_max_subscriptions; 152extern int tipc_max_subscriptions;
187extern int tipc_max_publications; 153extern int tipc_max_publications;
@@ -240,7 +206,6 @@ u32 tipc_k_signal(Handler routine, unsigned long argument);
240static inline void k_init_timer(struct timer_list *timer, Handler routine, 206static inline void k_init_timer(struct timer_list *timer, Handler routine,
241 unsigned long argument) 207 unsigned long argument)
242{ 208{
243 dbg("initializing timer %p\n", timer);
244 setup_timer(timer, routine, argument); 209 setup_timer(timer, routine, argument);
245} 210}
246 211
@@ -260,7 +225,6 @@ static inline void k_init_timer(struct timer_list *timer, Handler routine,
260 225
261static inline void k_start_timer(struct timer_list *timer, unsigned long msec) 226static inline void k_start_timer(struct timer_list *timer, unsigned long msec)
262{ 227{
263 dbg("starting timer %p for %u\n", timer, msec);
264 mod_timer(timer, jiffies + msecs_to_jiffies(msec) + 1); 228 mod_timer(timer, jiffies + msecs_to_jiffies(msec) + 1);
265} 229}
266 230
@@ -277,7 +241,6 @@ static inline void k_start_timer(struct timer_list *timer, unsigned long msec)
277 241
278static inline void k_cancel_timer(struct timer_list *timer) 242static inline void k_cancel_timer(struct timer_list *timer)
279{ 243{
280 dbg("cancelling timer %p\n", timer);
281 del_timer_sync(timer); 244 del_timer_sync(timer);
282} 245}
283 246
@@ -295,7 +258,6 @@ static inline void k_cancel_timer(struct timer_list *timer)
295 258
296static inline void k_term_timer(struct timer_list *timer) 259static inline void k_term_timer(struct timer_list *timer)
297{ 260{
298 dbg("terminating timer %p\n", timer);
299} 261}
300 262
301 263
diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index 4a7cd3719b78..fa026bd91a68 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -35,12 +35,8 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "link.h" 38#include "link.h"
40#include "zone.h"
41#include "discover.h" 39#include "discover.h"
42#include "port.h"
43#include "name_table.h"
44 40
45#define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */ 41#define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */
46#define TIPC_LINK_REQ_FAST 2000 /* normal delay if bearer has no links */ 42#define TIPC_LINK_REQ_FAST 2000 /* normal delay if bearer has no links */
@@ -134,8 +130,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
134 u32 net_id = msg_bc_netid(msg); 130 u32 net_id = msg_bc_netid(msg);
135 u32 type = msg_type(msg); 131 u32 type = msg_type(msg);
136 132
137 msg_get_media_addr(msg,&media_addr); 133 msg_get_media_addr(msg, &media_addr);
138 msg_dbg(msg, "RECV:");
139 buf_discard(buf); 134 buf_discard(buf);
140 135
141 if (net_id != tipc_net_id) 136 if (net_id != tipc_net_id)
@@ -151,10 +146,6 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
151 } 146 }
152 if (!tipc_in_scope(dest, tipc_own_addr)) 147 if (!tipc_in_scope(dest, tipc_own_addr))
153 return; 148 return;
154 if (is_slave(tipc_own_addr) && is_slave(orig))
155 return;
156 if (is_slave(orig) && !in_own_cluster(orig))
157 return;
158 if (in_own_cluster(orig)) { 149 if (in_own_cluster(orig)) {
159 /* Always accept link here */ 150 /* Always accept link here */
160 struct sk_buff *rbuf; 151 struct sk_buff *rbuf;
@@ -162,7 +153,6 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
162 struct tipc_node *n_ptr = tipc_node_find(orig); 153 struct tipc_node *n_ptr = tipc_node_find(orig);
163 int link_fully_up; 154 int link_fully_up;
164 155
165 dbg(" in own cluster\n");
166 if (n_ptr == NULL) { 156 if (n_ptr == NULL) {
167 n_ptr = tipc_node_create(orig); 157 n_ptr = tipc_node_create(orig);
168 if (!n_ptr) 158 if (!n_ptr)
@@ -179,7 +169,6 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
179 169
180 link = n_ptr->links[b_ptr->identity]; 170 link = n_ptr->links[b_ptr->identity];
181 if (!link) { 171 if (!link) {
182 dbg("creating link\n");
183 link = tipc_link_create(b_ptr, orig, &media_addr); 172 link = tipc_link_create(b_ptr, orig, &media_addr);
184 if (!link) { 173 if (!link) {
185 spin_unlock_bh(&n_ptr->lock); 174 spin_unlock_bh(&n_ptr->lock);
@@ -204,7 +193,6 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr)
204 return; 193 return;
205 rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr); 194 rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr);
206 if (rbuf != NULL) { 195 if (rbuf != NULL) {
207 msg_dbg(buf_msg(rbuf),"SEND:");
208 b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr); 196 b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr);
209 buf_discard(rbuf); 197 buf_discard(rbuf);
210 } 198 }
diff --git a/net/tipc/discover.h b/net/tipc/discover.h
index f8e750636123..d2c3cffb79fc 100644
--- a/net/tipc/discover.h
+++ b/net/tipc/discover.h
@@ -37,8 +37,6 @@
37#ifndef _TIPC_DISCOVER_H 37#ifndef _TIPC_DISCOVER_H
38#define _TIPC_DISCOVER_H 38#define _TIPC_DISCOVER_H
39 39
40#include "core.h"
41
42struct link_req; 40struct link_req;
43 41
44struct link_req *tipc_disc_init_link_req(struct bearer *b_ptr, 42struct link_req *tipc_disc_init_link_req(struct bearer *b_ptr,
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 6e988ba485fd..b69092eb95d8 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -34,12 +34,8 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <net/tipc/tipc.h> 37#include "core.h"
38#include <net/tipc/tipc_bearer.h> 38#include "bearer.h"
39#include <net/tipc/tipc_msg.h>
40#include <linux/netdevice.h>
41#include <linux/slab.h>
42#include <net/net_namespace.h>
43 39
44#define MAX_ETH_BEARERS 2 40#define MAX_ETH_BEARERS 2
45#define ETH_LINK_PRIORITY TIPC_DEF_LINK_PRI 41#define ETH_LINK_PRIORITY TIPC_DEF_LINK_PRI
@@ -60,7 +56,7 @@ struct eth_bearer {
60}; 56};
61 57
62static struct eth_bearer eth_bearers[MAX_ETH_BEARERS]; 58static struct eth_bearer eth_bearers[MAX_ETH_BEARERS];
63static int eth_started = 0; 59static int eth_started;
64static struct notifier_block notifier; 60static struct notifier_block notifier;
65 61
66/** 62/**
@@ -148,7 +144,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
148 144
149 /* Find device with specified name */ 145 /* Find device with specified name */
150 146
151 for_each_netdev(&init_net, pdev){ 147 for_each_netdev(&init_net, pdev) {
152 if (!strncmp(pdev->name, driver_name, IFNAMSIZ)) { 148 if (!strncmp(pdev->name, driver_name, IFNAMSIZ)) {
153 dev = pdev; 149 dev = pdev;
154 break; 150 break;
@@ -159,7 +155,8 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
159 155
160 /* Find Ethernet bearer for device (or create one) */ 156 /* Find Ethernet bearer for device (or create one) */
161 157
162 for (;(eb_ptr != stop) && eb_ptr->dev && (eb_ptr->dev != dev); eb_ptr++); 158 while ((eb_ptr != stop) && eb_ptr->dev && (eb_ptr->dev != dev))
159 eb_ptr++;
163 if (eb_ptr == stop) 160 if (eb_ptr == stop)
164 return -EDQUOT; 161 return -EDQUOT;
165 if (!eb_ptr->dev) { 162 if (!eb_ptr->dev) {
diff --git a/net/tipc/handler.c b/net/tipc/handler.c
index 0c70010a7dfe..274c98e164b7 100644
--- a/net/tipc/handler.c
+++ b/net/tipc/handler.c
@@ -45,7 +45,7 @@ struct queue_item {
45static struct kmem_cache *tipc_queue_item_cache; 45static struct kmem_cache *tipc_queue_item_cache;
46static struct list_head signal_queue_head; 46static struct list_head signal_queue_head;
47static DEFINE_SPINLOCK(qitem_lock); 47static DEFINE_SPINLOCK(qitem_lock);
48static int handler_enabled = 0; 48static int handler_enabled;
49 49
50static void process_signal_queue(unsigned long dummy); 50static void process_signal_queue(unsigned long dummy);
51 51
diff --git a/net/tipc/link.c b/net/tipc/link.c
index b31992ccd5d3..18702f58d111 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -35,19 +35,11 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "link.h" 38#include "link.h"
40#include "net.h"
41#include "node.h"
42#include "port.h" 39#include "port.h"
43#include "addr.h"
44#include "node_subscr.h"
45#include "name_distr.h" 40#include "name_distr.h"
46#include "bearer.h"
47#include "name_table.h"
48#include "discover.h" 41#include "discover.h"
49#include "config.h" 42#include "config.h"
50#include "bcast.h"
51 43
52 44
53/* 45/*
@@ -57,12 +49,6 @@
57#define INVALID_SESSION 0x10000 49#define INVALID_SESSION 0x10000
58 50
59/* 51/*
60 * Limit for deferred reception queue:
61 */
62
63#define DEF_QUEUE_LIMIT 256u
64
65/*
66 * Link state events: 52 * Link state events:
67 */ 53 */
68 54
@@ -110,75 +96,10 @@ static int link_send_sections_long(struct port *sender,
110static void link_check_defragm_bufs(struct link *l_ptr); 96static void link_check_defragm_bufs(struct link *l_ptr);
111static void link_state_event(struct link *l_ptr, u32 event); 97static void link_state_event(struct link *l_ptr, u32 event);
112static void link_reset_statistics(struct link *l_ptr); 98static void link_reset_statistics(struct link *l_ptr);
113static void link_print(struct link *l_ptr, struct print_buf *buf, 99static void link_print(struct link *l_ptr, const char *str);
114 const char *str);
115static void link_start(struct link *l_ptr); 100static void link_start(struct link *l_ptr);
116static int link_send_long_buf(struct link *l_ptr, struct sk_buff *buf); 101static int link_send_long_buf(struct link *l_ptr, struct sk_buff *buf);
117 102
118
119/*
120 * Debugging code used by link routines only
121 *
122 * When debugging link problems on a system that has multiple links,
123 * the standard TIPC debugging routines may not be useful since they
124 * allow the output from multiple links to be intermixed. For this reason
125 * routines of the form "dbg_link_XXX()" have been created that will capture
126 * debug info into a link's personal print buffer, which can then be dumped
127 * into the TIPC system log (TIPC_LOG) upon request.
128 *
129 * To enable per-link debugging, use LINK_LOG_BUF_SIZE to specify the size
130 * of the print buffer used by each link. If LINK_LOG_BUF_SIZE is set to 0,
131 * the dbg_link_XXX() routines simply send their output to the standard
132 * debug print buffer (DBG_OUTPUT), if it has been defined; this can be useful
133 * when there is only a single link in the system being debugged.
134 *
135 * Notes:
136 * - When enabled, LINK_LOG_BUF_SIZE should be set to at least TIPC_PB_MIN_SIZE
137 * - "l_ptr" must be valid when using dbg_link_XXX() macros
138 */
139
140#define LINK_LOG_BUF_SIZE 0
141
142#define dbg_link(fmt, arg...) \
143 do { \
144 if (LINK_LOG_BUF_SIZE) \
145 tipc_printf(&l_ptr->print_buf, fmt, ## arg); \
146 } while (0)
147#define dbg_link_msg(msg, txt) \
148 do { \
149 if (LINK_LOG_BUF_SIZE) \
150 tipc_msg_dbg(&l_ptr->print_buf, msg, txt); \
151 } while (0)
152#define dbg_link_state(txt) \
153 do { \
154 if (LINK_LOG_BUF_SIZE) \
155 link_print(l_ptr, &l_ptr->print_buf, txt); \
156 } while (0)
157#define dbg_link_dump() do { \
158 if (LINK_LOG_BUF_SIZE) { \
159 tipc_printf(LOG, "\n\nDumping link <%s>:\n", l_ptr->name); \
160 tipc_printbuf_move(LOG, &l_ptr->print_buf); \
161 } \
162} while (0)
163
164static void dbg_print_link(struct link *l_ptr, const char *str)
165{
166 if (DBG_OUTPUT != TIPC_NULL)
167 link_print(l_ptr, DBG_OUTPUT, str);
168}
169
170static void dbg_print_buf_chain(struct sk_buff *root_buf)
171{
172 if (DBG_OUTPUT != TIPC_NULL) {
173 struct sk_buff *buf = root_buf;
174
175 while (buf) {
176 msg_dbg(buf_msg(buf), "In chain: ");
177 buf = buf->next;
178 }
179 }
180}
181
182/* 103/*
183 * Simple link routines 104 * Simple link routines
184 */ 105 */
@@ -266,14 +187,17 @@ static int link_name_validate(const char *name, struct link_name *name_parts)
266 /* ensure all component parts of link name are present */ 187 /* ensure all component parts of link name are present */
267 188
268 addr_local = name_copy; 189 addr_local = name_copy;
269 if ((if_local = strchr(addr_local, ':')) == NULL) 190 if_local = strchr(addr_local, ':');
191 if (if_local == NULL)
270 return 0; 192 return 0;
271 *(if_local++) = 0; 193 *(if_local++) = 0;
272 if ((addr_peer = strchr(if_local, '-')) == NULL) 194 addr_peer = strchr(if_local, '-');
195 if (addr_peer == NULL)
273 return 0; 196 return 0;
274 *(addr_peer++) = 0; 197 *(addr_peer++) = 0;
275 if_local_len = addr_peer - if_local; 198 if_local_len = addr_peer - if_local;
276 if ((if_peer = strchr(addr_peer, ':')) == NULL) 199 if_peer = strchr(addr_peer, ':');
200 if (if_peer == NULL)
277 return 0; 201 return 0;
278 *(if_peer++) = 0; 202 *(if_peer++) = 0;
279 if_peer_len = strlen(if_peer) + 1; 203 if_peer_len = strlen(if_peer) + 1;
@@ -392,17 +316,6 @@ struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
392 return NULL; 316 return NULL;
393 } 317 }
394 318
395 if (LINK_LOG_BUF_SIZE) {
396 char *pb = kmalloc(LINK_LOG_BUF_SIZE, GFP_ATOMIC);
397
398 if (!pb) {
399 kfree(l_ptr);
400 warn("Link creation failed, no memory for print buffer\n");
401 return NULL;
402 }
403 tipc_printbuf_init(&l_ptr->print_buf, pb, LINK_LOG_BUF_SIZE);
404 }
405
406 l_ptr->addr = peer; 319 l_ptr->addr = peer;
407 if_name = strchr(b_ptr->publ.name, ':') + 1; 320 if_name = strchr(b_ptr->publ.name, ':') + 1;
408 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:", 321 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:",
@@ -437,8 +350,6 @@ struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
437 350
438 l_ptr->owner = tipc_node_attach_link(l_ptr); 351 l_ptr->owner = tipc_node_attach_link(l_ptr);
439 if (!l_ptr->owner) { 352 if (!l_ptr->owner) {
440 if (LINK_LOG_BUF_SIZE)
441 kfree(l_ptr->print_buf.buf);
442 kfree(l_ptr); 353 kfree(l_ptr);
443 return NULL; 354 return NULL;
444 } 355 }
@@ -447,9 +358,6 @@ struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
447 list_add_tail(&l_ptr->link_list, &b_ptr->links); 358 list_add_tail(&l_ptr->link_list, &b_ptr->links);
448 tipc_k_signal((Handler)link_start, (unsigned long)l_ptr); 359 tipc_k_signal((Handler)link_start, (unsigned long)l_ptr);
449 360
450 dbg("tipc_link_create(): tolerance = %u,cont intv = %u, abort_limit = %u\n",
451 l_ptr->tolerance, l_ptr->continuity_interval, l_ptr->abort_limit);
452
453 return l_ptr; 361 return l_ptr;
454} 362}
455 363
@@ -469,8 +377,6 @@ void tipc_link_delete(struct link *l_ptr)
469 return; 377 return;
470 } 378 }
471 379
472 dbg("tipc_link_delete()\n");
473
474 k_cancel_timer(&l_ptr->timer); 380 k_cancel_timer(&l_ptr->timer);
475 381
476 tipc_node_lock(l_ptr->owner); 382 tipc_node_lock(l_ptr->owner);
@@ -478,8 +384,6 @@ void tipc_link_delete(struct link *l_ptr)
478 tipc_node_detach_link(l_ptr->owner, l_ptr); 384 tipc_node_detach_link(l_ptr->owner, l_ptr);
479 tipc_link_stop(l_ptr); 385 tipc_link_stop(l_ptr);
480 list_del_init(&l_ptr->link_list); 386 list_del_init(&l_ptr->link_list);
481 if (LINK_LOG_BUF_SIZE)
482 kfree(l_ptr->print_buf.buf);
483 tipc_node_unlock(l_ptr->owner); 387 tipc_node_unlock(l_ptr->owner);
484 k_term_timer(&l_ptr->timer); 388 k_term_timer(&l_ptr->timer);
485 kfree(l_ptr); 389 kfree(l_ptr);
@@ -487,7 +391,6 @@ void tipc_link_delete(struct link *l_ptr)
487 391
488static void link_start(struct link *l_ptr) 392static void link_start(struct link *l_ptr)
489{ 393{
490 dbg("link_start %x\n", l_ptr);
491 link_state_event(l_ptr, STARTING_EVT); 394 link_state_event(l_ptr, STARTING_EVT);
492} 395}
493 396
@@ -639,7 +542,6 @@ void tipc_link_reset(struct link *l_ptr)
639 link_init_max_pkt(l_ptr); 542 link_init_max_pkt(l_ptr);
640 543
641 l_ptr->state = RESET_UNKNOWN; 544 l_ptr->state = RESET_UNKNOWN;
642 dbg_link_state("Resetting Link\n");
643 545
644 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET)) 546 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
645 return; 547 return;
@@ -713,25 +615,18 @@ static void link_state_event(struct link *l_ptr, unsigned event)
713 return; /* Not yet. */ 615 return; /* Not yet. */
714 616
715 if (link_blocked(l_ptr)) { 617 if (link_blocked(l_ptr)) {
716 if (event == TIMEOUT_EVT) { 618 if (event == TIMEOUT_EVT)
717 link_set_timer(l_ptr, cont_intv); 619 link_set_timer(l_ptr, cont_intv);
718 }
719 return; /* Changeover going on */ 620 return; /* Changeover going on */
720 } 621 }
721 dbg_link("STATE_EV: <%s> ", l_ptr->name);
722 622
723 switch (l_ptr->state) { 623 switch (l_ptr->state) {
724 case WORKING_WORKING: 624 case WORKING_WORKING:
725 dbg_link("WW/");
726 switch (event) { 625 switch (event) {
727 case TRAFFIC_MSG_EVT: 626 case TRAFFIC_MSG_EVT:
728 dbg_link("TRF-");
729 /* fall through */
730 case ACTIVATE_MSG: 627 case ACTIVATE_MSG:
731 dbg_link("ACT\n");
732 break; 628 break;
733 case TIMEOUT_EVT: 629 case TIMEOUT_EVT:
734 dbg_link("TIM ");
735 if (l_ptr->next_in_no != l_ptr->checkpoint) { 630 if (l_ptr->next_in_no != l_ptr->checkpoint) {
736 l_ptr->checkpoint = l_ptr->next_in_no; 631 l_ptr->checkpoint = l_ptr->next_in_no;
737 if (tipc_bclink_acks_missing(l_ptr->owner)) { 632 if (tipc_bclink_acks_missing(l_ptr->owner)) {
@@ -746,7 +641,6 @@ static void link_state_event(struct link *l_ptr, unsigned event)
746 link_set_timer(l_ptr, cont_intv); 641 link_set_timer(l_ptr, cont_intv);
747 break; 642 break;
748 } 643 }
749 dbg_link(" -> WU\n");
750 l_ptr->state = WORKING_UNKNOWN; 644 l_ptr->state = WORKING_UNKNOWN;
751 l_ptr->fsm_msg_cnt = 0; 645 l_ptr->fsm_msg_cnt = 0;
752 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); 646 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
@@ -754,7 +648,6 @@ static void link_state_event(struct link *l_ptr, unsigned event)
754 link_set_timer(l_ptr, cont_intv / 4); 648 link_set_timer(l_ptr, cont_intv / 4);
755 break; 649 break;
756 case RESET_MSG: 650 case RESET_MSG:
757 dbg_link("RES -> RR\n");
758 info("Resetting link <%s>, requested by peer\n", 651 info("Resetting link <%s>, requested by peer\n",
759 l_ptr->name); 652 l_ptr->name);
760 tipc_link_reset(l_ptr); 653 tipc_link_reset(l_ptr);
@@ -769,18 +662,14 @@ static void link_state_event(struct link *l_ptr, unsigned event)
769 } 662 }
770 break; 663 break;
771 case WORKING_UNKNOWN: 664 case WORKING_UNKNOWN:
772 dbg_link("WU/");
773 switch (event) { 665 switch (event) {
774 case TRAFFIC_MSG_EVT: 666 case TRAFFIC_MSG_EVT:
775 dbg_link("TRF-");
776 case ACTIVATE_MSG: 667 case ACTIVATE_MSG:
777 dbg_link("ACT -> WW\n");
778 l_ptr->state = WORKING_WORKING; 668 l_ptr->state = WORKING_WORKING;
779 l_ptr->fsm_msg_cnt = 0; 669 l_ptr->fsm_msg_cnt = 0;
780 link_set_timer(l_ptr, cont_intv); 670 link_set_timer(l_ptr, cont_intv);
781 break; 671 break;
782 case RESET_MSG: 672 case RESET_MSG:
783 dbg_link("RES -> RR\n");
784 info("Resetting link <%s>, requested by peer " 673 info("Resetting link <%s>, requested by peer "
785 "while probing\n", l_ptr->name); 674 "while probing\n", l_ptr->name);
786 tipc_link_reset(l_ptr); 675 tipc_link_reset(l_ptr);
@@ -791,9 +680,7 @@ static void link_state_event(struct link *l_ptr, unsigned event)
791 link_set_timer(l_ptr, cont_intv); 680 link_set_timer(l_ptr, cont_intv);
792 break; 681 break;
793 case TIMEOUT_EVT: 682 case TIMEOUT_EVT:
794 dbg_link("TIM ");
795 if (l_ptr->next_in_no != l_ptr->checkpoint) { 683 if (l_ptr->next_in_no != l_ptr->checkpoint) {
796 dbg_link("-> WW\n");
797 l_ptr->state = WORKING_WORKING; 684 l_ptr->state = WORKING_WORKING;
798 l_ptr->fsm_msg_cnt = 0; 685 l_ptr->fsm_msg_cnt = 0;
799 l_ptr->checkpoint = l_ptr->next_in_no; 686 l_ptr->checkpoint = l_ptr->next_in_no;
@@ -804,16 +691,11 @@ static void link_state_event(struct link *l_ptr, unsigned event)
804 } 691 }
805 link_set_timer(l_ptr, cont_intv); 692 link_set_timer(l_ptr, cont_intv);
806 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { 693 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
807 dbg_link("Probing %u/%u,timer = %u ms)\n",
808 l_ptr->fsm_msg_cnt, l_ptr->abort_limit,
809 cont_intv / 4);
810 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 694 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
811 1, 0, 0, 0, 0); 695 1, 0, 0, 0, 0);
812 l_ptr->fsm_msg_cnt++; 696 l_ptr->fsm_msg_cnt++;
813 link_set_timer(l_ptr, cont_intv / 4); 697 link_set_timer(l_ptr, cont_intv / 4);
814 } else { /* Link has failed */ 698 } else { /* Link has failed */
815 dbg_link("-> RU (%u probes unanswered)\n",
816 l_ptr->fsm_msg_cnt);
817 warn("Resetting link <%s>, peer not responding\n", 699 warn("Resetting link <%s>, peer not responding\n",
818 l_ptr->name); 700 l_ptr->name);
819 tipc_link_reset(l_ptr); 701 tipc_link_reset(l_ptr);
@@ -830,18 +712,13 @@ static void link_state_event(struct link *l_ptr, unsigned event)
830 } 712 }
831 break; 713 break;
832 case RESET_UNKNOWN: 714 case RESET_UNKNOWN:
833 dbg_link("RU/");
834 switch (event) { 715 switch (event) {
835 case TRAFFIC_MSG_EVT: 716 case TRAFFIC_MSG_EVT:
836 dbg_link("TRF-\n");
837 break; 717 break;
838 case ACTIVATE_MSG: 718 case ACTIVATE_MSG:
839 other = l_ptr->owner->active_links[0]; 719 other = l_ptr->owner->active_links[0];
840 if (other && link_working_unknown(other)) { 720 if (other && link_working_unknown(other))
841 dbg_link("ACT\n");
842 break; 721 break;
843 }
844 dbg_link("ACT -> WW\n");
845 l_ptr->state = WORKING_WORKING; 722 l_ptr->state = WORKING_WORKING;
846 l_ptr->fsm_msg_cnt = 0; 723 l_ptr->fsm_msg_cnt = 0;
847 link_activate(l_ptr); 724 link_activate(l_ptr);
@@ -850,8 +727,6 @@ static void link_state_event(struct link *l_ptr, unsigned event)
850 link_set_timer(l_ptr, cont_intv); 727 link_set_timer(l_ptr, cont_intv);
851 break; 728 break;
852 case RESET_MSG: 729 case RESET_MSG:
853 dbg_link("RES\n");
854 dbg_link(" -> RR\n");
855 l_ptr->state = RESET_RESET; 730 l_ptr->state = RESET_RESET;
856 l_ptr->fsm_msg_cnt = 0; 731 l_ptr->fsm_msg_cnt = 0;
857 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0); 732 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0);
@@ -859,11 +734,9 @@ static void link_state_event(struct link *l_ptr, unsigned event)
859 link_set_timer(l_ptr, cont_intv); 734 link_set_timer(l_ptr, cont_intv);
860 break; 735 break;
861 case STARTING_EVT: 736 case STARTING_EVT:
862 dbg_link("START-");
863 l_ptr->started = 1; 737 l_ptr->started = 1;
864 /* fall through */ 738 /* fall through */
865 case TIMEOUT_EVT: 739 case TIMEOUT_EVT:
866 dbg_link("TIM\n");
867 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); 740 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
868 l_ptr->fsm_msg_cnt++; 741 l_ptr->fsm_msg_cnt++;
869 link_set_timer(l_ptr, cont_intv); 742 link_set_timer(l_ptr, cont_intv);
@@ -873,18 +746,12 @@ static void link_state_event(struct link *l_ptr, unsigned event)
873 } 746 }
874 break; 747 break;
875 case RESET_RESET: 748 case RESET_RESET:
876 dbg_link("RR/ ");
877 switch (event) { 749 switch (event) {
878 case TRAFFIC_MSG_EVT: 750 case TRAFFIC_MSG_EVT:
879 dbg_link("TRF-");
880 /* fall through */
881 case ACTIVATE_MSG: 751 case ACTIVATE_MSG:
882 other = l_ptr->owner->active_links[0]; 752 other = l_ptr->owner->active_links[0];
883 if (other && link_working_unknown(other)) { 753 if (other && link_working_unknown(other))
884 dbg_link("ACT\n");
885 break; 754 break;
886 }
887 dbg_link("ACT -> WW\n");
888 l_ptr->state = WORKING_WORKING; 755 l_ptr->state = WORKING_WORKING;
889 l_ptr->fsm_msg_cnt = 0; 756 l_ptr->fsm_msg_cnt = 0;
890 link_activate(l_ptr); 757 link_activate(l_ptr);
@@ -893,14 +760,11 @@ static void link_state_event(struct link *l_ptr, unsigned event)
893 link_set_timer(l_ptr, cont_intv); 760 link_set_timer(l_ptr, cont_intv);
894 break; 761 break;
895 case RESET_MSG: 762 case RESET_MSG:
896 dbg_link("RES\n");
897 break; 763 break;
898 case TIMEOUT_EVT: 764 case TIMEOUT_EVT:
899 dbg_link("TIM\n");
900 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); 765 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
901 l_ptr->fsm_msg_cnt++; 766 l_ptr->fsm_msg_cnt++;
902 link_set_timer(l_ptr, cont_intv); 767 link_set_timer(l_ptr, cont_intv);
903 dbg_link("fsm_msg_cnt %u\n", l_ptr->fsm_msg_cnt);
904 break; 768 break;
905 default: 769 default:
906 err("Unknown link event %u in RR state\n", event); 770 err("Unknown link event %u in RR state\n", event);
@@ -940,9 +804,6 @@ static int link_bundle_buf(struct link *l_ptr,
940 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size); 804 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
941 msg_set_size(bundler_msg, to_pos + size); 805 msg_set_size(bundler_msg, to_pos + size);
942 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1); 806 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
943 dbg("Packed msg # %u(%u octets) into pos %u in buf(#%u)\n",
944 msg_msgcnt(bundler_msg), size, to_pos, msg_seqno(bundler_msg));
945 msg_dbg(msg, "PACKD:");
946 buf_discard(buf); 807 buf_discard(buf);
947 l_ptr->stats.sent_bundled++; 808 l_ptr->stats.sent_bundled++;
948 return 1; 809 return 1;
@@ -991,7 +852,6 @@ int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf)
991 return link_schedule_port(l_ptr, msg_origport(msg), 852 return link_schedule_port(l_ptr, msg_origport(msg),
992 size); 853 size);
993 } 854 }
994 msg_dbg(msg, "TIPC: Congestion, throwing away\n");
995 buf_discard(buf); 855 buf_discard(buf);
996 if (imp > CONN_MANAGER) { 856 if (imp > CONN_MANAGER) {
997 warn("Resetting link <%s>, send queue full", l_ptr->name); 857 warn("Resetting link <%s>, send queue full", l_ptr->name);
@@ -1075,22 +935,16 @@ int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
1075 int res = -ELINKCONG; 935 int res = -ELINKCONG;
1076 936
1077 read_lock_bh(&tipc_net_lock); 937 read_lock_bh(&tipc_net_lock);
1078 n_ptr = tipc_node_select(dest, selector); 938 n_ptr = tipc_node_find(dest);
1079 if (n_ptr) { 939 if (n_ptr) {
1080 tipc_node_lock(n_ptr); 940 tipc_node_lock(n_ptr);
1081 l_ptr = n_ptr->active_links[selector & 1]; 941 l_ptr = n_ptr->active_links[selector & 1];
1082 if (l_ptr) { 942 if (l_ptr)
1083 dbg("tipc_link_send: found link %x for dest %x\n", l_ptr, dest);
1084 res = tipc_link_send_buf(l_ptr, buf); 943 res = tipc_link_send_buf(l_ptr, buf);
1085 } else { 944 else
1086 dbg("Attempt to send msg to unreachable node:\n");
1087 msg_dbg(buf_msg(buf),">>>");
1088 buf_discard(buf); 945 buf_discard(buf);
1089 }
1090 tipc_node_unlock(n_ptr); 946 tipc_node_unlock(n_ptr);
1091 } else { 947 } else {
1092 dbg("Attempt to send msg to unknown node:\n");
1093 msg_dbg(buf_msg(buf),">>>");
1094 buf_discard(buf); 948 buf_discard(buf);
1095 } 949 }
1096 read_unlock_bh(&tipc_net_lock); 950 read_unlock_bh(&tipc_net_lock);
@@ -1117,17 +971,14 @@ static int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf,
1117 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, 971 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf,
1118 &l_ptr->media_addr))) { 972 &l_ptr->media_addr))) {
1119 l_ptr->unacked_window = 0; 973 l_ptr->unacked_window = 0;
1120 msg_dbg(msg,"SENT_FAST:");
1121 return res; 974 return res;
1122 } 975 }
1123 dbg("failed sent fast...\n");
1124 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); 976 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
1125 l_ptr->stats.bearer_congs++; 977 l_ptr->stats.bearer_congs++;
1126 l_ptr->next_out = buf; 978 l_ptr->next_out = buf;
1127 return res; 979 return res;
1128 } 980 }
1129 } 981 } else
1130 else
1131 *used_max_pkt = l_ptr->max_pkt; 982 *used_max_pkt = l_ptr->max_pkt;
1132 } 983 }
1133 return tipc_link_send_buf(l_ptr, buf); /* All other cases */ 984 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
@@ -1151,12 +1002,10 @@ int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode)
1151 return tipc_port_recv_msg(buf); 1002 return tipc_port_recv_msg(buf);
1152 1003
1153 read_lock_bh(&tipc_net_lock); 1004 read_lock_bh(&tipc_net_lock);
1154 n_ptr = tipc_node_select(destnode, selector); 1005 n_ptr = tipc_node_find(destnode);
1155 if (likely(n_ptr)) { 1006 if (likely(n_ptr)) {
1156 tipc_node_lock(n_ptr); 1007 tipc_node_lock(n_ptr);
1157 l_ptr = n_ptr->active_links[selector]; 1008 l_ptr = n_ptr->active_links[selector];
1158 dbg("send_fast: buf %x selected %x, destnode = %x\n",
1159 buf, l_ptr, destnode);
1160 if (likely(l_ptr)) { 1009 if (likely(l_ptr)) {
1161 res = link_send_buf_fast(l_ptr, buf, &dummy); 1010 res = link_send_buf_fast(l_ptr, buf, &dummy);
1162 tipc_node_unlock(n_ptr); 1011 tipc_node_unlock(n_ptr);
@@ -1200,7 +1049,7 @@ again:
1200 !sender->user_port, &buf); 1049 !sender->user_port, &buf);
1201 1050
1202 read_lock_bh(&tipc_net_lock); 1051 read_lock_bh(&tipc_net_lock);
1203 node = tipc_node_select(destaddr, selector); 1052 node = tipc_node_find(destaddr);
1204 if (likely(node)) { 1053 if (likely(node)) {
1205 tipc_node_lock(node); 1054 tipc_node_lock(node);
1206 l_ptr = node->active_links[selector]; 1055 l_ptr = node->active_links[selector];
@@ -1283,10 +1132,10 @@ static int link_send_sections_long(struct port *sender,
1283 struct tipc_node *node; 1132 struct tipc_node *node;
1284 struct tipc_msg *hdr = &sender->publ.phdr; 1133 struct tipc_msg *hdr = &sender->publ.phdr;
1285 u32 dsz = msg_data_sz(hdr); 1134 u32 dsz = msg_data_sz(hdr);
1286 u32 max_pkt,fragm_sz,rest; 1135 u32 max_pkt, fragm_sz, rest;
1287 struct tipc_msg fragm_hdr; 1136 struct tipc_msg fragm_hdr;
1288 struct sk_buff *buf,*buf_chain,*prev; 1137 struct sk_buff *buf, *buf_chain, *prev;
1289 u32 fragm_crs,fragm_rest,hsz,sect_rest; 1138 u32 fragm_crs, fragm_rest, hsz, sect_rest;
1290 const unchar *sect_crs; 1139 const unchar *sect_crs;
1291 int curr_sect; 1140 int curr_sect;
1292 u32 fragm_no; 1141 u32 fragm_no;
@@ -1306,7 +1155,6 @@ again:
1306 1155
1307 /* Prepare reusable fragment header: */ 1156 /* Prepare reusable fragment header: */
1308 1157
1309 msg_dbg(hdr, ">FRAGMENTING>");
1310 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, 1158 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
1311 INT_H_SIZE, msg_destnode(hdr)); 1159 INT_H_SIZE, msg_destnode(hdr));
1312 msg_set_link_selector(&fragm_hdr, sender->publ.ref); 1160 msg_set_link_selector(&fragm_hdr, sender->publ.ref);
@@ -1322,7 +1170,6 @@ again:
1322 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); 1170 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
1323 hsz = msg_hdr_sz(hdr); 1171 hsz = msg_hdr_sz(hdr);
1324 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz); 1172 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
1325 msg_dbg(buf_msg(buf), ">BUILD>");
1326 1173
1327 /* Chop up message: */ 1174 /* Chop up message: */
1328 1175
@@ -1365,7 +1212,7 @@ error:
1365 /* Initiate new fragment: */ 1212 /* Initiate new fragment: */
1366 if (rest <= fragm_sz) { 1213 if (rest <= fragm_sz) {
1367 fragm_sz = rest; 1214 fragm_sz = rest;
1368 msg_set_type(&fragm_hdr,LAST_FRAGMENT); 1215 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
1369 } else { 1216 } else {
1370 msg_set_type(&fragm_hdr, FRAGMENT); 1217 msg_set_type(&fragm_hdr, FRAGMENT);
1371 } 1218 }
@@ -1381,16 +1228,14 @@ error:
1381 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); 1228 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
1382 fragm_crs = INT_H_SIZE; 1229 fragm_crs = INT_H_SIZE;
1383 fragm_rest = fragm_sz; 1230 fragm_rest = fragm_sz;
1384 msg_dbg(buf_msg(buf)," >BUILD>");
1385 } 1231 }
1386 } 1232 } while (rest > 0);
1387 while (rest > 0);
1388 1233
1389 /* 1234 /*
1390 * Now we have a buffer chain. Select a link and check 1235 * Now we have a buffer chain. Select a link and check
1391 * that packet size is still OK 1236 * that packet size is still OK
1392 */ 1237 */
1393 node = tipc_node_select(destaddr, sender->publ.ref & 1); 1238 node = tipc_node_find(destaddr);
1394 if (likely(node)) { 1239 if (likely(node)) {
1395 tipc_node_lock(node); 1240 tipc_node_lock(node);
1396 l_ptr = node->active_links[sender->publ.ref & 1]; 1241 l_ptr = node->active_links[sender->publ.ref & 1];
@@ -1431,7 +1276,6 @@ reject:
1431 l_ptr->stats.sent_fragments++; 1276 l_ptr->stats.sent_fragments++;
1432 msg_set_long_msgno(msg, l_ptr->long_msg_seq_no); 1277 msg_set_long_msgno(msg, l_ptr->long_msg_seq_no);
1433 link_add_to_outqueue(l_ptr, buf, msg); 1278 link_add_to_outqueue(l_ptr, buf, msg);
1434 msg_dbg(msg, ">ADD>");
1435 buf = next; 1279 buf = next;
1436 } 1280 }
1437 1281
@@ -1473,14 +1317,12 @@ u32 tipc_link_push_packet(struct link *l_ptr)
1473 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); 1317 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
1474 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); 1318 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
1475 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { 1319 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
1476 msg_dbg(buf_msg(buf), ">DEF-RETR>");
1477 l_ptr->retransm_queue_head = mod(++r_q_head); 1320 l_ptr->retransm_queue_head = mod(++r_q_head);
1478 l_ptr->retransm_queue_size = --r_q_size; 1321 l_ptr->retransm_queue_size = --r_q_size;
1479 l_ptr->stats.retransmitted++; 1322 l_ptr->stats.retransmitted++;
1480 return 0; 1323 return 0;
1481 } else { 1324 } else {
1482 l_ptr->stats.bearer_congs++; 1325 l_ptr->stats.bearer_congs++;
1483 msg_dbg(buf_msg(buf), "|>DEF-RETR>");
1484 return PUSH_FAILED; 1326 return PUSH_FAILED;
1485 } 1327 }
1486 } 1328 }
@@ -1490,15 +1332,13 @@ u32 tipc_link_push_packet(struct link *l_ptr)
1490 buf = l_ptr->proto_msg_queue; 1332 buf = l_ptr->proto_msg_queue;
1491 if (buf) { 1333 if (buf) {
1492 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); 1334 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
1493 msg_set_bcast_ack(buf_msg(buf),l_ptr->owner->bclink.last_in); 1335 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
1494 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { 1336 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
1495 msg_dbg(buf_msg(buf), ">DEF-PROT>");
1496 l_ptr->unacked_window = 0; 1337 l_ptr->unacked_window = 0;
1497 buf_discard(buf); 1338 buf_discard(buf);
1498 l_ptr->proto_msg_queue = NULL; 1339 l_ptr->proto_msg_queue = NULL;
1499 return 0; 1340 return 0;
1500 } else { 1341 } else {
1501 msg_dbg(buf_msg(buf), "|>DEF-PROT>");
1502 l_ptr->stats.bearer_congs++; 1342 l_ptr->stats.bearer_congs++;
1503 return PUSH_FAILED; 1343 return PUSH_FAILED;
1504 } 1344 }
@@ -1518,11 +1358,9 @@ u32 tipc_link_push_packet(struct link *l_ptr)
1518 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { 1358 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
1519 if (msg_user(msg) == MSG_BUNDLER) 1359 if (msg_user(msg) == MSG_BUNDLER)
1520 msg_set_type(msg, CLOSED_MSG); 1360 msg_set_type(msg, CLOSED_MSG);
1521 msg_dbg(msg, ">PUSH-DATA>");
1522 l_ptr->next_out = buf->next; 1361 l_ptr->next_out = buf->next;
1523 return 0; 1362 return 0;
1524 } else { 1363 } else {
1525 msg_dbg(msg, "|PUSH-DATA|");
1526 l_ptr->stats.bearer_congs++; 1364 l_ptr->stats.bearer_congs++;
1527 return PUSH_FAILED; 1365 return PUSH_FAILED;
1528 } 1366 }
@@ -1570,8 +1408,7 @@ static void link_reset_all(unsigned long addr)
1570 1408
1571 for (i = 0; i < MAX_BEARERS; i++) { 1409 for (i = 0; i < MAX_BEARERS; i++) {
1572 if (n_ptr->links[i]) { 1410 if (n_ptr->links[i]) {
1573 link_print(n_ptr->links[i], TIPC_OUTPUT, 1411 link_print(n_ptr->links[i], "Resetting link\n");
1574 "Resetting link\n");
1575 tipc_link_reset(n_ptr->links[i]); 1412 tipc_link_reset(n_ptr->links[i]);
1576 } 1413 }
1577 } 1414 }
@@ -1585,13 +1422,12 @@ static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf)
1585 struct tipc_msg *msg = buf_msg(buf); 1422 struct tipc_msg *msg = buf_msg(buf);
1586 1423
1587 warn("Retransmission failure on link <%s>\n", l_ptr->name); 1424 warn("Retransmission failure on link <%s>\n", l_ptr->name);
1588 tipc_msg_dbg(TIPC_OUTPUT, msg, ">RETR-FAIL>");
1589 1425
1590 if (l_ptr->addr) { 1426 if (l_ptr->addr) {
1591 1427
1592 /* Handle failure on standard link */ 1428 /* Handle failure on standard link */
1593 1429
1594 link_print(l_ptr, TIPC_OUTPUT, "Resetting link\n"); 1430 link_print(l_ptr, "Resetting link\n");
1595 tipc_link_reset(l_ptr); 1431 tipc_link_reset(l_ptr);
1596 1432
1597 } else { 1433 } else {
@@ -1601,21 +1437,21 @@ static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf)
1601 struct tipc_node *n_ptr; 1437 struct tipc_node *n_ptr;
1602 char addr_string[16]; 1438 char addr_string[16];
1603 1439
1604 tipc_printf(TIPC_OUTPUT, "Msg seq number: %u, ", msg_seqno(msg)); 1440 info("Msg seq number: %u, ", msg_seqno(msg));
1605 tipc_printf(TIPC_OUTPUT, "Outstanding acks: %lu\n", 1441 info("Outstanding acks: %lu\n",
1606 (unsigned long) TIPC_SKB_CB(buf)->handle); 1442 (unsigned long) TIPC_SKB_CB(buf)->handle);
1607 1443
1608 n_ptr = l_ptr->owner->next; 1444 n_ptr = l_ptr->owner->next;
1609 tipc_node_lock(n_ptr); 1445 tipc_node_lock(n_ptr);
1610 1446
1611 tipc_addr_string_fill(addr_string, n_ptr->addr); 1447 tipc_addr_string_fill(addr_string, n_ptr->addr);
1612 tipc_printf(TIPC_OUTPUT, "Multicast link info for %s\n", addr_string); 1448 info("Multicast link info for %s\n", addr_string);
1613 tipc_printf(TIPC_OUTPUT, "Supported: %d, ", n_ptr->bclink.supported); 1449 info("Supported: %d, ", n_ptr->bclink.supported);
1614 tipc_printf(TIPC_OUTPUT, "Acked: %u\n", n_ptr->bclink.acked); 1450 info("Acked: %u\n", n_ptr->bclink.acked);
1615 tipc_printf(TIPC_OUTPUT, "Last in: %u, ", n_ptr->bclink.last_in); 1451 info("Last in: %u, ", n_ptr->bclink.last_in);
1616 tipc_printf(TIPC_OUTPUT, "Gap after: %u, ", n_ptr->bclink.gap_after); 1452 info("Gap after: %u, ", n_ptr->bclink.gap_after);
1617 tipc_printf(TIPC_OUTPUT, "Gap to: %u\n", n_ptr->bclink.gap_to); 1453 info("Gap to: %u\n", n_ptr->bclink.gap_to);
1618 tipc_printf(TIPC_OUTPUT, "Nack sync: %u\n\n", n_ptr->bclink.nack_sync); 1454 info("Nack sync: %u\n\n", n_ptr->bclink.nack_sync);
1619 1455
1620 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr); 1456 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
1621 1457
@@ -1635,12 +1471,8 @@ void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf,
1635 1471
1636 msg = buf_msg(buf); 1472 msg = buf_msg(buf);
1637 1473
1638 dbg("Retransmitting %u in link %x\n", retransmits, l_ptr);
1639
1640 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) { 1474 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
1641 if (l_ptr->retransm_queue_size == 0) { 1475 if (l_ptr->retransm_queue_size == 0) {
1642 msg_dbg(msg, ">NO_RETR->BCONG>");
1643 dbg_print_link(l_ptr, " ");
1644 l_ptr->retransm_queue_head = msg_seqno(msg); 1476 l_ptr->retransm_queue_head = msg_seqno(msg);
1645 l_ptr->retransm_queue_size = retransmits; 1477 l_ptr->retransm_queue_size = retransmits;
1646 } else { 1478 } else {
@@ -1667,7 +1499,6 @@ void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf,
1667 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); 1499 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1668 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); 1500 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1669 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { 1501 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
1670 msg_dbg(buf_msg(buf), ">RETR>");
1671 buf = buf->next; 1502 buf = buf->next;
1672 retransmits--; 1503 retransmits--;
1673 l_ptr->stats.retransmitted++; 1504 l_ptr->stats.retransmitted++;
@@ -1793,9 +1624,8 @@ void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *tb_ptr)
1793 1624
1794 /* Ensure message data is a single contiguous unit */ 1625 /* Ensure message data is a single contiguous unit */
1795 1626
1796 if (unlikely(buf_linearize(buf))) { 1627 if (unlikely(buf_linearize(buf)))
1797 goto cont; 1628 goto cont;
1798 }
1799 1629
1800 /* Handle arrival of a non-unicast link message */ 1630 /* Handle arrival of a non-unicast link message */
1801 1631
@@ -1907,7 +1737,7 @@ deliver:
1907 continue; 1737 continue;
1908 case ROUTE_DISTRIBUTOR: 1738 case ROUTE_DISTRIBUTOR:
1909 tipc_node_unlock(n_ptr); 1739 tipc_node_unlock(n_ptr);
1910 tipc_cltr_recv_routing_table(buf); 1740 buf_discard(buf);
1911 continue; 1741 continue;
1912 case NAME_DISTRIBUTOR: 1742 case NAME_DISTRIBUTOR:
1913 tipc_node_unlock(n_ptr); 1743 tipc_node_unlock(n_ptr);
@@ -1953,12 +1783,10 @@ deliver:
1953 tipc_node_unlock(n_ptr); 1783 tipc_node_unlock(n_ptr);
1954 continue; 1784 continue;
1955 } 1785 }
1956 msg_dbg(msg,"NSEQ<REC<");
1957 link_state_event(l_ptr, TRAFFIC_MSG_EVT); 1786 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1958 1787
1959 if (link_working_working(l_ptr)) { 1788 if (link_working_working(l_ptr)) {
1960 /* Re-insert in front of queue */ 1789 /* Re-insert in front of queue */
1961 msg_dbg(msg,"RECV-REINS:");
1962 buf->next = head; 1790 buf->next = head;
1963 head = buf; 1791 head = buf;
1964 tipc_node_unlock(n_ptr); 1792 tipc_node_unlock(n_ptr);
@@ -2012,13 +1840,11 @@ u32 tipc_link_defer_pkt(struct sk_buff **head,
2012 *head = buf; 1840 *head = buf;
2013 return 1; 1841 return 1;
2014 } 1842 }
2015 if (seq_no == msg_seqno(msg)) { 1843 if (seq_no == msg_seqno(msg))
2016 break; 1844 break;
2017 }
2018 prev = crs; 1845 prev = crs;
2019 crs = crs->next; 1846 crs = crs->next;
2020 } 1847 } while (crs);
2021 while (crs);
2022 1848
2023 /* Message is a duplicate of an existing message */ 1849 /* Message is a duplicate of an existing message */
2024 1850
@@ -2040,9 +1866,6 @@ static void link_handle_out_of_seq_msg(struct link *l_ptr,
2040 return; 1866 return;
2041 } 1867 }
2042 1868
2043 dbg("rx OOS msg: seq_no %u, expecting %u (%u)\n",
2044 seq_no, mod(l_ptr->next_in_no), l_ptr->next_in_no);
2045
2046 /* Record OOS packet arrival (force mismatch on next timeout) */ 1869 /* Record OOS packet arrival (force mismatch on next timeout) */
2047 1870
2048 l_ptr->checkpoint--; 1871 l_ptr->checkpoint--;
@@ -2132,11 +1955,10 @@ void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
2132 msg_set_max_pkt(msg, l_ptr->max_pkt_target); 1955 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
2133 } 1956 }
2134 1957
2135 if (tipc_node_has_redundant_links(l_ptr->owner)) { 1958 if (tipc_node_has_redundant_links(l_ptr->owner))
2136 msg_set_redundant_link(msg); 1959 msg_set_redundant_link(msg);
2137 } else { 1960 else
2138 msg_clear_redundant_link(msg); 1961 msg_clear_redundant_link(msg);
2139 }
2140 msg_set_linkprio(msg, l_ptr->priority); 1962 msg_set_linkprio(msg, l_ptr->priority);
2141 1963
2142 /* Ensure sequence number will not fit : */ 1964 /* Ensure sequence number will not fit : */
@@ -2160,8 +1982,6 @@ void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
2160 1982
2161 /* Message can be sent */ 1983 /* Message can be sent */
2162 1984
2163 msg_dbg(msg, ">>");
2164
2165 buf = tipc_buf_acquire(msg_size); 1985 buf = tipc_buf_acquire(msg_size);
2166 if (!buf) 1986 if (!buf)
2167 return; 1987 return;
@@ -2195,8 +2015,6 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2195 u32 msg_tol; 2015 u32 msg_tol;
2196 struct tipc_msg *msg = buf_msg(buf); 2016 struct tipc_msg *msg = buf_msg(buf);
2197 2017
2198 dbg("AT(%u):", jiffies_to_msecs(jiffies));
2199 msg_dbg(msg, "<<");
2200 if (link_blocked(l_ptr)) 2018 if (link_blocked(l_ptr))
2201 goto exit; 2019 goto exit;
2202 2020
@@ -2215,11 +2033,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2215 case RESET_MSG: 2033 case RESET_MSG:
2216 if (!link_working_unknown(l_ptr) && 2034 if (!link_working_unknown(l_ptr) &&
2217 (l_ptr->peer_session != INVALID_SESSION)) { 2035 (l_ptr->peer_session != INVALID_SESSION)) {
2218 if (msg_session(msg) == l_ptr->peer_session) { 2036 if (msg_session(msg) == l_ptr->peer_session)
2219 dbg("Duplicate RESET: %u<->%u\n",
2220 msg_session(msg), l_ptr->peer_session);
2221 break; /* duplicate: ignore */ 2037 break; /* duplicate: ignore */
2222 }
2223 } 2038 }
2224 /* fall thru' */ 2039 /* fall thru' */
2225 case ACTIVATE_MSG: 2040 case ACTIVATE_MSG:
@@ -2227,8 +2042,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2227 2042
2228 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg)); 2043 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
2229 2044
2230 if ((msg_tol = msg_link_tolerance(msg)) && 2045 msg_tol = msg_link_tolerance(msg);
2231 (msg_tol > l_ptr->tolerance)) 2046 if (msg_tol > l_ptr->tolerance)
2232 link_set_supervision_props(l_ptr, msg_tol); 2047 link_set_supervision_props(l_ptr, msg_tol);
2233 2048
2234 if (msg_linkprio(msg) > l_ptr->priority) 2049 if (msg_linkprio(msg) > l_ptr->priority)
@@ -2251,13 +2066,13 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2251 l_ptr->peer_bearer_id = msg_bearer_id(msg); 2066 l_ptr->peer_bearer_id = msg_bearer_id(msg);
2252 2067
2253 /* Synchronize broadcast sequence numbers */ 2068 /* Synchronize broadcast sequence numbers */
2254 if (!tipc_node_has_redundant_links(l_ptr->owner)) { 2069 if (!tipc_node_has_redundant_links(l_ptr->owner))
2255 l_ptr->owner->bclink.last_in = mod(msg_last_bcast(msg)); 2070 l_ptr->owner->bclink.last_in = mod(msg_last_bcast(msg));
2256 }
2257 break; 2071 break;
2258 case STATE_MSG: 2072 case STATE_MSG:
2259 2073
2260 if ((msg_tol = msg_link_tolerance(msg))) 2074 msg_tol = msg_link_tolerance(msg);
2075 if (msg_tol)
2261 link_set_supervision_props(l_ptr, msg_tol); 2076 link_set_supervision_props(l_ptr, msg_tol);
2262 2077
2263 if (msg_linkprio(msg) && 2078 if (msg_linkprio(msg) &&
@@ -2280,8 +2095,6 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2280 2095
2281 max_pkt_ack = msg_max_pkt(msg); 2096 max_pkt_ack = msg_max_pkt(msg);
2282 if (max_pkt_ack > l_ptr->max_pkt) { 2097 if (max_pkt_ack > l_ptr->max_pkt) {
2283 dbg("Link <%s> updated MTU %u -> %u\n",
2284 l_ptr->name, l_ptr->max_pkt, max_pkt_ack);
2285 l_ptr->max_pkt = max_pkt_ack; 2098 l_ptr->max_pkt = max_pkt_ack;
2286 l_ptr->max_pkt_probes = 0; 2099 l_ptr->max_pkt_probes = 0;
2287 } 2100 }
@@ -2289,9 +2102,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2289 max_pkt_ack = 0; 2102 max_pkt_ack = 0;
2290 if (msg_probe(msg)) { 2103 if (msg_probe(msg)) {
2291 l_ptr->stats.recv_probes++; 2104 l_ptr->stats.recv_probes++;
2292 if (msg_size(msg) > sizeof(l_ptr->proto_msg)) { 2105 if (msg_size(msg) > sizeof(l_ptr->proto_msg))
2293 max_pkt_ack = msg_size(msg); 2106 max_pkt_ack = msg_size(msg);
2294 }
2295 } 2107 }
2296 2108
2297 /* Protocol message before retransmits, reduce loss risk */ 2109 /* Protocol message before retransmits, reduce loss risk */
@@ -2303,14 +2115,11 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2303 0, rec_gap, 0, 0, max_pkt_ack); 2115 0, rec_gap, 0, 0, max_pkt_ack);
2304 } 2116 }
2305 if (msg_seq_gap(msg)) { 2117 if (msg_seq_gap(msg)) {
2306 msg_dbg(msg, "With Gap:");
2307 l_ptr->stats.recv_nacks++; 2118 l_ptr->stats.recv_nacks++;
2308 tipc_link_retransmit(l_ptr, l_ptr->first_out, 2119 tipc_link_retransmit(l_ptr, l_ptr->first_out,
2309 msg_seq_gap(msg)); 2120 msg_seq_gap(msg));
2310 } 2121 }
2311 break; 2122 break;
2312 default:
2313 msg_dbg(buf_msg(buf), "<DISCARDING UNKNOWN<");
2314 } 2123 }
2315exit: 2124exit:
2316 buf_discard(buf); 2125 buf_discard(buf);
@@ -2345,8 +2154,6 @@ static void tipc_link_tunnel(struct link *l_ptr,
2345 } 2154 }
2346 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); 2155 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
2347 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); 2156 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
2348 dbg("%c->%c:", l_ptr->b_ptr->net_plane, tunnel->b_ptr->net_plane);
2349 msg_dbg(buf_msg(buf), ">SEND>");
2350 tipc_link_send_buf(tunnel, buf); 2157 tipc_link_send_buf(tunnel, buf);
2351} 2158}
2352 2159
@@ -2378,7 +2185,6 @@ void tipc_link_changeover(struct link *l_ptr)
2378 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); 2185 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
2379 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); 2186 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2380 msg_set_msgcnt(&tunnel_hdr, msgcount); 2187 msg_set_msgcnt(&tunnel_hdr, msgcount);
2381 dbg("Link changeover requires %u tunnel messages\n", msgcount);
2382 2188
2383 if (!l_ptr->first_out) { 2189 if (!l_ptr->first_out) {
2384 struct sk_buff *buf; 2190 struct sk_buff *buf;
@@ -2387,9 +2193,6 @@ void tipc_link_changeover(struct link *l_ptr)
2387 if (buf) { 2193 if (buf) {
2388 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); 2194 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
2389 msg_set_size(&tunnel_hdr, INT_H_SIZE); 2195 msg_set_size(&tunnel_hdr, INT_H_SIZE);
2390 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2391 tunnel->b_ptr->net_plane);
2392 msg_dbg(&tunnel_hdr, "EMPTY>SEND>");
2393 tipc_link_send_buf(tunnel, buf); 2196 tipc_link_send_buf(tunnel, buf);
2394 } else { 2197 } else {
2395 warn("Link changeover error, " 2198 warn("Link changeover error, "
@@ -2406,11 +2209,11 @@ void tipc_link_changeover(struct link *l_ptr)
2406 2209
2407 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) { 2210 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
2408 struct tipc_msg *m = msg_get_wrapped(msg); 2211 struct tipc_msg *m = msg_get_wrapped(msg);
2409 unchar* pos = (unchar*)m; 2212 unchar *pos = (unchar *)m;
2410 2213
2411 msgcount = msg_msgcnt(msg); 2214 msgcount = msg_msgcnt(msg);
2412 while (msgcount--) { 2215 while (msgcount--) {
2413 msg_set_seqno(m,msg_seqno(msg)); 2216 msg_set_seqno(m, msg_seqno(msg));
2414 tipc_link_tunnel(l_ptr, &tunnel_hdr, m, 2217 tipc_link_tunnel(l_ptr, &tunnel_hdr, m,
2415 msg_link_selector(m)); 2218 msg_link_selector(m));
2416 pos += align(msg_size(m)); 2219 pos += align(msg_size(m));
@@ -2453,9 +2256,6 @@ void tipc_link_send_duplicate(struct link *l_ptr, struct link *tunnel)
2453 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); 2256 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2454 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, 2257 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
2455 length); 2258 length);
2456 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2457 tunnel->b_ptr->net_plane);
2458 msg_dbg(buf_msg(outbuf), ">SEND>");
2459 tipc_link_send_buf(tunnel, outbuf); 2259 tipc_link_send_buf(tunnel, outbuf);
2460 if (!tipc_link_is_up(l_ptr)) 2260 if (!tipc_link_is_up(l_ptr))
2461 return; 2261 return;
@@ -2502,31 +2302,24 @@ static int link_recv_changeover_msg(struct link **l_ptr,
2502 u32 msg_count = msg_msgcnt(tunnel_msg); 2302 u32 msg_count = msg_msgcnt(tunnel_msg);
2503 2303
2504 dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)]; 2304 dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)];
2505 if (!dest_link) { 2305 if (!dest_link)
2506 msg_dbg(tunnel_msg, "NOLINK/<REC<");
2507 goto exit; 2306 goto exit;
2508 }
2509 if (dest_link == *l_ptr) { 2307 if (dest_link == *l_ptr) {
2510 err("Unexpected changeover message on link <%s>\n", 2308 err("Unexpected changeover message on link <%s>\n",
2511 (*l_ptr)->name); 2309 (*l_ptr)->name);
2512 goto exit; 2310 goto exit;
2513 } 2311 }
2514 dbg("%c<-%c:", dest_link->b_ptr->net_plane,
2515 (*l_ptr)->b_ptr->net_plane);
2516 *l_ptr = dest_link; 2312 *l_ptr = dest_link;
2517 msg = msg_get_wrapped(tunnel_msg); 2313 msg = msg_get_wrapped(tunnel_msg);
2518 2314
2519 if (msg_typ == DUPLICATE_MSG) { 2315 if (msg_typ == DUPLICATE_MSG) {
2520 if (less(msg_seqno(msg), mod(dest_link->next_in_no))) { 2316 if (less(msg_seqno(msg), mod(dest_link->next_in_no)))
2521 msg_dbg(tunnel_msg, "DROP/<REC<");
2522 goto exit; 2317 goto exit;
2523 } 2318 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2524 *buf = buf_extract(tunnel_buf,INT_H_SIZE);
2525 if (*buf == NULL) { 2319 if (*buf == NULL) {
2526 warn("Link changeover error, duplicate msg dropped\n"); 2320 warn("Link changeover error, duplicate msg dropped\n");
2527 goto exit; 2321 goto exit;
2528 } 2322 }
2529 msg_dbg(tunnel_msg, "TNL<REC<");
2530 buf_discard(tunnel_buf); 2323 buf_discard(tunnel_buf);
2531 return 1; 2324 return 1;
2532 } 2325 }
@@ -2534,18 +2327,14 @@ static int link_recv_changeover_msg(struct link **l_ptr,
2534 /* First original message ?: */ 2327 /* First original message ?: */
2535 2328
2536 if (tipc_link_is_up(dest_link)) { 2329 if (tipc_link_is_up(dest_link)) {
2537 msg_dbg(tunnel_msg, "UP/FIRST/<REC<");
2538 info("Resetting link <%s>, changeover initiated by peer\n", 2330 info("Resetting link <%s>, changeover initiated by peer\n",
2539 dest_link->name); 2331 dest_link->name);
2540 tipc_link_reset(dest_link); 2332 tipc_link_reset(dest_link);
2541 dest_link->exp_msg_count = msg_count; 2333 dest_link->exp_msg_count = msg_count;
2542 dbg("Expecting %u tunnelled messages\n", msg_count);
2543 if (!msg_count) 2334 if (!msg_count)
2544 goto exit; 2335 goto exit;
2545 } else if (dest_link->exp_msg_count == START_CHANGEOVER) { 2336 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
2546 msg_dbg(tunnel_msg, "BLK/FIRST/<REC<");
2547 dest_link->exp_msg_count = msg_count; 2337 dest_link->exp_msg_count = msg_count;
2548 dbg("Expecting %u tunnelled messages\n", msg_count);
2549 if (!msg_count) 2338 if (!msg_count)
2550 goto exit; 2339 goto exit;
2551 } 2340 }
@@ -2555,18 +2344,14 @@ static int link_recv_changeover_msg(struct link **l_ptr,
2555 if (dest_link->exp_msg_count == 0) { 2344 if (dest_link->exp_msg_count == 0) {
2556 warn("Link switchover error, " 2345 warn("Link switchover error, "
2557 "got too many tunnelled messages\n"); 2346 "got too many tunnelled messages\n");
2558 msg_dbg(tunnel_msg, "OVERDUE/DROP/<REC<");
2559 dbg_print_link(dest_link, "LINK:");
2560 goto exit; 2347 goto exit;
2561 } 2348 }
2562 dest_link->exp_msg_count--; 2349 dest_link->exp_msg_count--;
2563 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { 2350 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) {
2564 msg_dbg(tunnel_msg, "DROP/DUPL/<REC<");
2565 goto exit; 2351 goto exit;
2566 } else { 2352 } else {
2567 *buf = buf_extract(tunnel_buf, INT_H_SIZE); 2353 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2568 if (*buf != NULL) { 2354 if (*buf != NULL) {
2569 msg_dbg(tunnel_msg, "TNL<REC<");
2570 buf_discard(tunnel_buf); 2355 buf_discard(tunnel_buf);
2571 return 1; 2356 return 1;
2572 } else { 2357 } else {
@@ -2588,7 +2373,6 @@ void tipc_link_recv_bundle(struct sk_buff *buf)
2588 u32 pos = INT_H_SIZE; 2373 u32 pos = INT_H_SIZE;
2589 struct sk_buff *obuf; 2374 struct sk_buff *obuf;
2590 2375
2591 msg_dbg(buf_msg(buf), "<BNDL<: ");
2592 while (msgcount--) { 2376 while (msgcount--) {
2593 obuf = buf_extract(buf, pos); 2377 obuf = buf_extract(buf, pos);
2594 if (obuf == NULL) { 2378 if (obuf == NULL) {
@@ -2596,7 +2380,6 @@ void tipc_link_recv_bundle(struct sk_buff *buf)
2596 break; 2380 break;
2597 } 2381 }
2598 pos += align(msg_size(buf_msg(obuf))); 2382 pos += align(msg_size(buf_msg(obuf)));
2599 msg_dbg(buf_msg(obuf), " /");
2600 tipc_net_route_msg(obuf); 2383 tipc_net_route_msg(obuf);
2601 } 2384 }
2602 buf_discard(buf); 2385 buf_discard(buf);
@@ -2733,7 +2516,6 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2733 u32 long_msg_seq_no = msg_long_msgno(fragm); 2516 u32 long_msg_seq_no = msg_long_msgno(fragm);
2734 2517
2735 *fb = NULL; 2518 *fb = NULL;
2736 msg_dbg(fragm,"FRG<REC<");
2737 2519
2738 /* Is there an incomplete message waiting for this fragment? */ 2520 /* Is there an incomplete message waiting for this fragment? */
2739 2521
@@ -2752,7 +2534,6 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2752 if (msg_type(imsg) == TIPC_MCAST_MSG) 2534 if (msg_type(imsg) == TIPC_MCAST_MSG)
2753 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE; 2535 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
2754 if (msg_size(imsg) > max) { 2536 if (msg_size(imsg) > max) {
2755 msg_dbg(fragm,"<REC<Oversized: ");
2756 buf_discard(fbuf); 2537 buf_discard(fbuf);
2757 return 0; 2538 return 0;
2758 } 2539 }
@@ -2765,8 +2546,8 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2765 /* Prepare buffer for subsequent fragments. */ 2546 /* Prepare buffer for subsequent fragments. */
2766 2547
2767 set_long_msg_seqno(pbuf, long_msg_seq_no); 2548 set_long_msg_seqno(pbuf, long_msg_seq_no);
2768 set_fragm_size(pbuf,fragm_sz); 2549 set_fragm_size(pbuf, fragm_sz);
2769 set_expected_frags(pbuf,exp_fragm_cnt - 1); 2550 set_expected_frags(pbuf, exp_fragm_cnt - 1);
2770 } else { 2551 } else {
2771 warn("Link unable to reassemble fragmented message\n"); 2552 warn("Link unable to reassemble fragmented message\n");
2772 } 2553 }
@@ -2793,13 +2574,9 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2793 *m = buf_msg(pbuf); 2574 *m = buf_msg(pbuf);
2794 return 1; 2575 return 1;
2795 } 2576 }
2796 set_expected_frags(pbuf,exp_frags); 2577 set_expected_frags(pbuf, exp_frags);
2797 return 0; 2578 return 0;
2798 } 2579 }
2799 dbg(" Discarding orphan fragment %x\n",fbuf);
2800 msg_dbg(fragm,"ORPHAN:");
2801 dbg("Pending long buffers:\n");
2802 dbg_print_buf_chain(*pending);
2803 buf_discard(fbuf); 2580 buf_discard(fbuf);
2804 return 0; 2581 return 0;
2805} 2582}
@@ -2827,11 +2604,6 @@ static void link_check_defragm_bufs(struct link *l_ptr)
2827 incr_timer_cnt(buf); 2604 incr_timer_cnt(buf);
2828 prev = buf; 2605 prev = buf;
2829 } else { 2606 } else {
2830 dbg(" Discarding incomplete long buffer\n");
2831 msg_dbg(buf_msg(buf), "LONG:");
2832 dbg_print_link(l_ptr, "curr:");
2833 dbg("Pending long buffers:\n");
2834 dbg_print_buf_chain(l_ptr->defragm_buf);
2835 if (prev) 2607 if (prev)
2836 prev->next = buf->next; 2608 prev->next = buf->next;
2837 else 2609 else
@@ -2866,7 +2638,6 @@ void tipc_link_set_queue_limits(struct link *l_ptr, u32 window)
2866 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900; 2638 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
2867 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200; 2639 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
2868 l_ptr->queue_limit[CONN_MANAGER] = 1200; 2640 l_ptr->queue_limit[CONN_MANAGER] = 1200;
2869 l_ptr->queue_limit[ROUTE_DISTRIBUTOR] = 1200;
2870 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500; 2641 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
2871 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000; 2642 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
2872 /* FRAGMENT and LAST_FRAGMENT packets */ 2643 /* FRAGMENT and LAST_FRAGMENT packets */
@@ -3168,7 +2939,7 @@ u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
3168 return MAX_MSG_SIZE; 2939 return MAX_MSG_SIZE;
3169 2940
3170 read_lock_bh(&tipc_net_lock); 2941 read_lock_bh(&tipc_net_lock);
3171 n_ptr = tipc_node_select(dest, selector); 2942 n_ptr = tipc_node_find(dest);
3172 if (n_ptr) { 2943 if (n_ptr) {
3173 tipc_node_lock(n_ptr); 2944 tipc_node_lock(n_ptr);
3174 l_ptr = n_ptr->active_links[selector & 1]; 2945 l_ptr = n_ptr->active_links[selector & 1];
@@ -3180,27 +2951,22 @@ u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
3180 return res; 2951 return res;
3181} 2952}
3182 2953
3183static void link_dump_send_queue(struct link *l_ptr) 2954static void link_print(struct link *l_ptr, const char *str)
3184{ 2955{
3185 if (l_ptr->next_out) { 2956 char print_area[256];
3186 info("\nContents of unsent queue:\n"); 2957 struct print_buf pb;
3187 dbg_print_buf_chain(l_ptr->next_out); 2958 struct print_buf *buf = &pb;
3188 } 2959
3189 info("\nContents of send queue:\n"); 2960 tipc_printbuf_init(buf, print_area, sizeof(print_area));
3190 if (l_ptr->first_out) {
3191 dbg_print_buf_chain(l_ptr->first_out);
3192 }
3193 info("Empty send queue\n");
3194}
3195 2961
3196static void link_print(struct link *l_ptr, struct print_buf *buf,
3197 const char *str)
3198{
3199 tipc_printf(buf, str); 2962 tipc_printf(buf, str);
3200 if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr))
3201 return;
3202 tipc_printf(buf, "Link %x<%s>:", 2963 tipc_printf(buf, "Link %x<%s>:",
3203 l_ptr->addr, l_ptr->b_ptr->publ.name); 2964 l_ptr->addr, l_ptr->b_ptr->publ.name);
2965
2966#ifdef CONFIG_TIPC_DEBUG
2967 if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr))
2968 goto print_state;
2969
3204 tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no)); 2970 tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no));
3205 tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no)); 2971 tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no));
3206 tipc_printf(buf, "SQUE"); 2972 tipc_printf(buf, "SQUE");
@@ -3218,7 +2984,6 @@ static void link_print(struct link *l_ptr, struct print_buf *buf,
3218 tipc_printf(buf, "first_out= %x ", l_ptr->first_out); 2984 tipc_printf(buf, "first_out= %x ", l_ptr->first_out);
3219 tipc_printf(buf, "next_out= %x ", l_ptr->next_out); 2985 tipc_printf(buf, "next_out= %x ", l_ptr->next_out);
3220 tipc_printf(buf, "last_out= %x ", l_ptr->last_out); 2986 tipc_printf(buf, "last_out= %x ", l_ptr->last_out);
3221 link_dump_send_queue(l_ptr);
3222 } 2987 }
3223 } else 2988 } else
3224 tipc_printf(buf, "[]"); 2989 tipc_printf(buf, "[]");
@@ -3232,14 +2997,20 @@ static void link_print(struct link *l_ptr, struct print_buf *buf,
3232 l_ptr->deferred_inqueue_sz); 2997 l_ptr->deferred_inqueue_sz);
3233 } 2998 }
3234 } 2999 }
3000print_state:
3001#endif
3002
3235 if (link_working_unknown(l_ptr)) 3003 if (link_working_unknown(l_ptr))
3236 tipc_printf(buf, ":WU"); 3004 tipc_printf(buf, ":WU");
3237 if (link_reset_reset(l_ptr)) 3005 else if (link_reset_reset(l_ptr))
3238 tipc_printf(buf, ":RR"); 3006 tipc_printf(buf, ":RR");
3239 if (link_reset_unknown(l_ptr)) 3007 else if (link_reset_unknown(l_ptr))
3240 tipc_printf(buf, ":RU"); 3008 tipc_printf(buf, ":RU");
3241 if (link_working_working(l_ptr)) 3009 else if (link_working_working(l_ptr))
3242 tipc_printf(buf, ":WW"); 3010 tipc_printf(buf, ":WW");
3243 tipc_printf(buf, "\n"); 3011 tipc_printf(buf, "\n");
3012
3013 tipc_printbuf_validate(buf);
3014 info("%s", print_area);
3244} 3015}
3245 3016
diff --git a/net/tipc/link.h b/net/tipc/link.h
index f98bc613de67..70967e637027 100644
--- a/net/tipc/link.h
+++ b/net/tipc/link.h
@@ -37,9 +37,8 @@
37#ifndef _TIPC_LINK_H 37#ifndef _TIPC_LINK_H
38#define _TIPC_LINK_H 38#define _TIPC_LINK_H
39 39
40#include "dbg.h" 40#include "log.h"
41#include "msg.h" 41#include "msg.h"
42#include "bearer.h"
43#include "node.h" 42#include "node.h"
44 43
45#define PUSH_FAILED 1 44#define PUSH_FAILED 1
@@ -108,7 +107,6 @@
108 * @long_msg_seq_no: next identifier to use for outbound fragmented messages 107 * @long_msg_seq_no: next identifier to use for outbound fragmented messages
109 * @defragm_buf: list of partially reassembled inbound message fragments 108 * @defragm_buf: list of partially reassembled inbound message fragments
110 * @stats: collects statistics regarding link activity 109 * @stats: collects statistics regarding link activity
111 * @print_buf: print buffer used to log link activity
112 */ 110 */
113 111
114struct link { 112struct link {
@@ -211,8 +209,6 @@ struct link {
211 u32 msg_lengths_total; 209 u32 msg_lengths_total;
212 u32 msg_length_profile[7]; 210 u32 msg_length_profile[7];
213 } stats; 211 } stats;
214
215 struct print_buf print_buf;
216}; 212};
217 213
218struct port; 214struct port;
@@ -233,8 +229,8 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_
233void tipc_link_reset(struct link *l_ptr); 229void tipc_link_reset(struct link *l_ptr);
234int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector); 230int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector);
235int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf); 231int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf);
236u32 tipc_link_get_max_pkt(u32 dest,u32 selector); 232u32 tipc_link_get_max_pkt(u32 dest, u32 selector);
237int tipc_link_send_sections_fast(struct port* sender, 233int tipc_link_send_sections_fast(struct port *sender,
238 struct iovec const *msg_sect, 234 struct iovec const *msg_sect,
239 const u32 num_sect, 235 const u32 num_sect,
240 u32 destnode); 236 u32 destnode);
diff --git a/net/tipc/dbg.c b/net/tipc/log.c
index 46f51d208e5e..952c39f643e6 100644
--- a/net/tipc/dbg.c
+++ b/net/tipc/log.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * net/tipc/dbg.c: TIPC print buffer routines for debugging 2 * net/tipc/log.c: TIPC print buffer routines for debugging
3 * 3 *
4 * Copyright (c) 1996-2006, Ericsson AB 4 * Copyright (c) 1996-2006, Ericsson AB
5 * Copyright (c) 2005-2007, Wind River Systems 5 * Copyright (c) 2005-2007, Wind River Systems
@@ -36,7 +36,7 @@
36 36
37#include "core.h" 37#include "core.h"
38#include "config.h" 38#include "config.h"
39#include "dbg.h" 39#include "log.h"
40 40
41/* 41/*
42 * TIPC pre-defines the following print buffers: 42 * TIPC pre-defines the following print buffers:
@@ -52,7 +52,7 @@ static struct print_buf null_buf = { NULL, 0, NULL, 0 };
52struct print_buf *const TIPC_NULL = &null_buf; 52struct print_buf *const TIPC_NULL = &null_buf;
53 53
54static struct print_buf cons_buf = { NULL, 0, NULL, 1 }; 54static struct print_buf cons_buf = { NULL, 0, NULL, 1 };
55static struct print_buf *const TIPC_CONS = &cons_buf; 55struct print_buf *const TIPC_CONS = &cons_buf;
56 56
57static struct print_buf log_buf = { NULL, 0, NULL, 1 }; 57static struct print_buf log_buf = { NULL, 0, NULL, 1 };
58struct print_buf *const TIPC_LOG = &log_buf; 58struct print_buf *const TIPC_LOG = &log_buf;
@@ -64,9 +64,9 @@ struct print_buf *const TIPC_LOG = &log_buf;
64 * 'print_string' when writing to a print buffer. This also protects against 64 * 'print_string' when writing to a print buffer. This also protects against
65 * concurrent writes to the print buffer being written to. 65 * concurrent writes to the print buffer being written to.
66 * 66 *
67 * 2) tipc_dump() and tipc_log_XXX() leverage the aforementioned 67 * 2) tipc_log_XXX() leverages the aforementioned use of 'print_lock' to
68 * use of 'print_lock' to protect against all types of concurrent operations 68 * protect against all types of concurrent operations on their associated
69 * on their associated print buffer (not just write operations). 69 * print buffer (not just write operations).
70 * 70 *
71 * Note: All routines of the form tipc_printbuf_XXX() are lock-free, and rely 71 * Note: All routines of the form tipc_printbuf_XXX() are lock-free, and rely
72 * on the caller to prevent simultaneous use of the print buffer(s) being 72 * on the caller to prevent simultaneous use of the print buffer(s) being
@@ -76,18 +76,16 @@ struct print_buf *const TIPC_LOG = &log_buf;
76static char print_string[TIPC_PB_MAX_STR]; 76static char print_string[TIPC_PB_MAX_STR];
77static DEFINE_SPINLOCK(print_lock); 77static DEFINE_SPINLOCK(print_lock);
78 78
79static void tipc_printbuf_reset(struct print_buf *pb);
80static int tipc_printbuf_empty(struct print_buf *pb);
81static void tipc_printbuf_move(struct print_buf *pb_to, 79static void tipc_printbuf_move(struct print_buf *pb_to,
82 struct print_buf *pb_from); 80 struct print_buf *pb_from);
83 81
84#define FORMAT(PTR,LEN,FMT) \ 82#define FORMAT(PTR, LEN, FMT) \
85{\ 83{\
86 va_list args;\ 84 va_list args;\
87 va_start(args, FMT);\ 85 va_start(args, FMT);\
88 LEN = vsprintf(PTR, FMT, args);\ 86 LEN = vsprintf(PTR, FMT, args);\
89 va_end(args);\ 87 va_end(args);\
90 *(PTR + LEN) = '\0';\ 88 *(PTR + LEN) = '\0';\
91} 89}
92 90
93/** 91/**
@@ -268,81 +266,6 @@ void tipc_printf(struct print_buf *pb, const char *fmt, ...)
268 spin_unlock_bh(&print_lock); 266 spin_unlock_bh(&print_lock);
269} 267}
270 268
271#ifdef CONFIG_TIPC_DEBUG
272
273/**
274 * print_to_console - write string of bytes to console in multiple chunks
275 */
276
277static void print_to_console(char *crs, int len)
278{
279 int rest = len;
280
281 while (rest > 0) {
282 int sz = rest < TIPC_PB_MAX_STR ? rest : TIPC_PB_MAX_STR;
283 char c = crs[sz];
284
285 crs[sz] = 0;
286 printk((const char *)crs);
287 crs[sz] = c;
288 rest -= sz;
289 crs += sz;
290 }
291}
292
293/**
294 * printbuf_dump - write print buffer contents to console
295 */
296
297static void printbuf_dump(struct print_buf *pb)
298{
299 int len;
300
301 if (!pb->buf) {
302 printk("*** PRINT BUFFER NOT ALLOCATED ***");
303 return;
304 }
305
306 /* Dump print buffer from char after cursor to end (if used) */
307
308 len = pb->buf + pb->size - pb->crs - 2;
309 if ((pb->buf[pb->size - 1] == 0) && (len > 0))
310 print_to_console(pb->crs + 1, len);
311
312 /* Dump print buffer from start to cursor (always) */
313
314 len = pb->crs - pb->buf;
315 print_to_console(pb->buf, len);
316}
317
318/**
319 * tipc_dump_dbg - dump (non-console) print buffer to console
320 * @pb: pointer to print buffer
321 */
322
323void tipc_dump_dbg(struct print_buf *pb, const char *fmt, ...)
324{
325 int len;
326
327 if (pb == TIPC_CONS)
328 return;
329
330 spin_lock_bh(&print_lock);
331
332 FORMAT(print_string, len, fmt);
333 printk(print_string);
334
335 printk("\n---- Start of %s log dump ----\n\n",
336 (pb == TIPC_LOG) ? "global" : "local");
337 printbuf_dump(pb);
338 tipc_printbuf_reset(pb);
339 printk("\n---- End of dump ----\n");
340
341 spin_unlock_bh(&print_lock);
342}
343
344#endif
345
346/** 269/**
347 * tipc_log_resize - change the size of the TIPC log buffer 270 * tipc_log_resize - change the size of the TIPC log buffer
348 * @log_size: print buffer size to use 271 * @log_size: print buffer size to use
@@ -353,10 +276,8 @@ int tipc_log_resize(int log_size)
353 int res = 0; 276 int res = 0;
354 277
355 spin_lock_bh(&print_lock); 278 spin_lock_bh(&print_lock);
356 if (TIPC_LOG->buf) { 279 kfree(TIPC_LOG->buf);
357 kfree(TIPC_LOG->buf); 280 TIPC_LOG->buf = NULL;
358 TIPC_LOG->buf = NULL;
359 }
360 if (log_size) { 281 if (log_size) {
361 if (log_size < TIPC_PB_MIN_SIZE) 282 if (log_size < TIPC_PB_MIN_SIZE)
362 log_size = TIPC_PB_MIN_SIZE; 283 log_size = TIPC_PB_MIN_SIZE;
@@ -407,8 +328,7 @@ struct sk_buff *tipc_log_dump(void)
407 } else if (tipc_printbuf_empty(TIPC_LOG)) { 328 } else if (tipc_printbuf_empty(TIPC_LOG)) {
408 spin_unlock_bh(&print_lock); 329 spin_unlock_bh(&print_lock);
409 reply = tipc_cfg_reply_ultra_string("log is empty\n"); 330 reply = tipc_cfg_reply_ultra_string("log is empty\n");
410 } 331 } else {
411 else {
412 struct tlv_desc *rep_tlv; 332 struct tlv_desc *rep_tlv;
413 struct print_buf pb; 333 struct print_buf pb;
414 int str_len; 334 int str_len;
@@ -429,4 +349,3 @@ struct sk_buff *tipc_log_dump(void)
429 } 349 }
430 return reply; 350 return reply;
431} 351}
432
diff --git a/net/tipc/dbg.h b/net/tipc/log.h
index 3ba6ba8b434a..2248d96238e6 100644
--- a/net/tipc/dbg.h
+++ b/net/tipc/log.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * net/tipc/dbg.h: Include file for TIPC print buffer routines 2 * net/tipc/log.h: Include file for TIPC print buffer routines
3 * 3 *
4 * Copyright (c) 1997-2006, Ericsson AB 4 * Copyright (c) 1997-2006, Ericsson AB
5 * Copyright (c) 2005-2007, Wind River Systems 5 * Copyright (c) 2005-2007, Wind River Systems
@@ -34,8 +34,8 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#ifndef _TIPC_DBG_H 37#ifndef _TIPC_LOG_H
38#define _TIPC_DBG_H 38#define _TIPC_LOG_H
39 39
40/** 40/**
41 * struct print_buf - TIPC print buffer structure 41 * struct print_buf - TIPC print buffer structure
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index ecb532fb0351..bb6180c4fcbb 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -35,10 +35,7 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "addr.h"
39#include "dbg.h"
40#include "msg.h" 38#include "msg.h"
41#include "bearer.h"
42 39
43u32 tipc_msg_tot_importance(struct tipc_msg *m) 40u32 tipc_msg_tot_importance(struct tipc_msg *m)
44{ 41{
@@ -94,7 +91,7 @@ int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect)
94 91
95int tipc_msg_build(struct tipc_msg *hdr, 92int tipc_msg_build(struct tipc_msg *hdr,
96 struct iovec const *msg_sect, u32 num_sect, 93 struct iovec const *msg_sect, u32 num_sect,
97 int max_size, int usrmem, struct sk_buff** buf) 94 int max_size, int usrmem, struct sk_buff **buf)
98{ 95{
99 int dsz, sz, hsz, pos, res, cnt; 96 int dsz, sz, hsz, pos, res, cnt;
100 97
@@ -140,6 +137,7 @@ int tipc_msg_build(struct tipc_msg *hdr,
140void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str) 137void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
141{ 138{
142 u32 usr = msg_user(msg); 139 u32 usr = msg_user(msg);
140 tipc_printf(buf, KERN_DEBUG);
143 tipc_printf(buf, str); 141 tipc_printf(buf, str);
144 142
145 switch (usr) { 143 switch (usr) {
@@ -163,10 +161,10 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
163 tipc_printf(buf, "LAST:"); 161 tipc_printf(buf, "LAST:");
164 break; 162 break;
165 default: 163 default:
166 tipc_printf(buf, "UNKNOWN:%x",msg_type(msg)); 164 tipc_printf(buf, "UNKNOWN:%x", msg_type(msg));
167 165
168 } 166 }
169 tipc_printf(buf, "NO(%u/%u):",msg_long_msgno(msg), 167 tipc_printf(buf, "NO(%u/%u):", msg_long_msgno(msg),
170 msg_fragm_no(msg)); 168 msg_fragm_no(msg));
171 break; 169 break;
172 case TIPC_LOW_IMPORTANCE: 170 case TIPC_LOW_IMPORTANCE:
@@ -192,7 +190,7 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
192 tipc_printf(buf, "DIR:"); 190 tipc_printf(buf, "DIR:");
193 break; 191 break;
194 default: 192 default:
195 tipc_printf(buf, "UNKNOWN TYPE %u",msg_type(msg)); 193 tipc_printf(buf, "UNKNOWN TYPE %u", msg_type(msg));
196 } 194 }
197 if (msg_routed(msg) && !msg_non_seq(msg)) 195 if (msg_routed(msg) && !msg_non_seq(msg))
198 tipc_printf(buf, "ROUT:"); 196 tipc_printf(buf, "ROUT:");
@@ -210,7 +208,7 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
210 tipc_printf(buf, "WDRW:"); 208 tipc_printf(buf, "WDRW:");
211 break; 209 break;
212 default: 210 default:
213 tipc_printf(buf, "UNKNOWN:%x",msg_type(msg)); 211 tipc_printf(buf, "UNKNOWN:%x", msg_type(msg));
214 } 212 }
215 if (msg_routed(msg)) 213 if (msg_routed(msg))
216 tipc_printf(buf, "ROUT:"); 214 tipc_printf(buf, "ROUT:");
@@ -229,39 +227,39 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
229 break; 227 break;
230 case CONN_ACK: 228 case CONN_ACK:
231 tipc_printf(buf, "CONN_ACK:"); 229 tipc_printf(buf, "CONN_ACK:");
232 tipc_printf(buf, "ACK(%u):",msg_msgcnt(msg)); 230 tipc_printf(buf, "ACK(%u):", msg_msgcnt(msg));
233 break; 231 break;
234 default: 232 default:
235 tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); 233 tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg));
236 } 234 }
237 if (msg_routed(msg)) 235 if (msg_routed(msg))
238 tipc_printf(buf, "ROUT:"); 236 tipc_printf(buf, "ROUT:");
239 if (msg_reroute_cnt(msg)) 237 if (msg_reroute_cnt(msg))
240 tipc_printf(buf, "REROUTED(%u):",msg_reroute_cnt(msg)); 238 tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg));
241 break; 239 break;
242 case LINK_PROTOCOL: 240 case LINK_PROTOCOL:
243 tipc_printf(buf, "PROT:TIM(%u):",msg_timestamp(msg)); 241 tipc_printf(buf, "PROT:TIM(%u):", msg_timestamp(msg));
244 switch (msg_type(msg)) { 242 switch (msg_type(msg)) {
245 case STATE_MSG: 243 case STATE_MSG:
246 tipc_printf(buf, "STATE:"); 244 tipc_printf(buf, "STATE:");
247 tipc_printf(buf, "%s:",msg_probe(msg) ? "PRB" :""); 245 tipc_printf(buf, "%s:", msg_probe(msg) ? "PRB" : "");
248 tipc_printf(buf, "NXS(%u):",msg_next_sent(msg)); 246 tipc_printf(buf, "NXS(%u):", msg_next_sent(msg));
249 tipc_printf(buf, "GAP(%u):",msg_seq_gap(msg)); 247 tipc_printf(buf, "GAP(%u):", msg_seq_gap(msg));
250 tipc_printf(buf, "LSTBC(%u):",msg_last_bcast(msg)); 248 tipc_printf(buf, "LSTBC(%u):", msg_last_bcast(msg));
251 break; 249 break;
252 case RESET_MSG: 250 case RESET_MSG:
253 tipc_printf(buf, "RESET:"); 251 tipc_printf(buf, "RESET:");
254 if (msg_size(msg) != msg_hdr_sz(msg)) 252 if (msg_size(msg) != msg_hdr_sz(msg))
255 tipc_printf(buf, "BEAR:%s:",msg_data(msg)); 253 tipc_printf(buf, "BEAR:%s:", msg_data(msg));
256 break; 254 break;
257 case ACTIVATE_MSG: 255 case ACTIVATE_MSG:
258 tipc_printf(buf, "ACTIVATE:"); 256 tipc_printf(buf, "ACTIVATE:");
259 break; 257 break;
260 default: 258 default:
261 tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); 259 tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg));
262 } 260 }
263 tipc_printf(buf, "PLANE(%c):",msg_net_plane(msg)); 261 tipc_printf(buf, "PLANE(%c):", msg_net_plane(msg));
264 tipc_printf(buf, "SESS(%u):",msg_session(msg)); 262 tipc_printf(buf, "SESS(%u):", msg_session(msg));
265 break; 263 break;
266 case CHANGEOVER_PROTOCOL: 264 case CHANGEOVER_PROTOCOL:
267 tipc_printf(buf, "TUNL:"); 265 tipc_printf(buf, "TUNL:");
@@ -271,10 +269,10 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
271 break; 269 break;
272 case ORIGINAL_MSG: 270 case ORIGINAL_MSG:
273 tipc_printf(buf, "ORIG:"); 271 tipc_printf(buf, "ORIG:");
274 tipc_printf(buf, "EXP(%u)",msg_msgcnt(msg)); 272 tipc_printf(buf, "EXP(%u)", msg_msgcnt(msg));
275 break; 273 break;
276 default: 274 default:
277 tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); 275 tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg));
278 } 276 }
279 break; 277 break;
280 case ROUTE_DISTRIBUTOR: 278 case ROUTE_DISTRIBUTOR:
@@ -282,26 +280,26 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
282 switch (msg_type(msg)) { 280 switch (msg_type(msg)) {
283 case EXT_ROUTING_TABLE: 281 case EXT_ROUTING_TABLE:
284 tipc_printf(buf, "EXT_TBL:"); 282 tipc_printf(buf, "EXT_TBL:");
285 tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); 283 tipc_printf(buf, "TO:%x:", msg_remote_node(msg));
286 break; 284 break;
287 case LOCAL_ROUTING_TABLE: 285 case LOCAL_ROUTING_TABLE:
288 tipc_printf(buf, "LOCAL_TBL:"); 286 tipc_printf(buf, "LOCAL_TBL:");
289 tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); 287 tipc_printf(buf, "TO:%x:", msg_remote_node(msg));
290 break; 288 break;
291 case SLAVE_ROUTING_TABLE: 289 case SLAVE_ROUTING_TABLE:
292 tipc_printf(buf, "DP_TBL:"); 290 tipc_printf(buf, "DP_TBL:");
293 tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); 291 tipc_printf(buf, "TO:%x:", msg_remote_node(msg));
294 break; 292 break;
295 case ROUTE_ADDITION: 293 case ROUTE_ADDITION:
296 tipc_printf(buf, "ADD:"); 294 tipc_printf(buf, "ADD:");
297 tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); 295 tipc_printf(buf, "TO:%x:", msg_remote_node(msg));
298 break; 296 break;
299 case ROUTE_REMOVAL: 297 case ROUTE_REMOVAL:
300 tipc_printf(buf, "REMOVE:"); 298 tipc_printf(buf, "REMOVE:");
301 tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); 299 tipc_printf(buf, "TO:%x:", msg_remote_node(msg));
302 break; 300 break;
303 default: 301 default:
304 tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); 302 tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg));
305 } 303 }
306 break; 304 break;
307 case LINK_CONFIG: 305 case LINK_CONFIG:
@@ -314,7 +312,7 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
314 tipc_printf(buf, "DSC_RESP:"); 312 tipc_printf(buf, "DSC_RESP:");
315 break; 313 break;
316 default: 314 default:
317 tipc_printf(buf, "UNKNOWN TYPE:%x:",msg_type(msg)); 315 tipc_printf(buf, "UNKNOWN TYPE:%x:", msg_type(msg));
318 break; 316 break;
319 } 317 }
320 break; 318 break;
@@ -350,7 +348,8 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
350 tipc_printf(buf, "UNKNOWN ERROR(%x):", 348 tipc_printf(buf, "UNKNOWN ERROR(%x):",
351 msg_errcode(msg)); 349 msg_errcode(msg));
352 } 350 }
353 default:{} 351 default:
352 break;
354 } 353 }
355 354
356 tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg)); 355 tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg));
@@ -359,9 +358,8 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
359 358
360 if (msg_non_seq(msg)) 359 if (msg_non_seq(msg))
361 tipc_printf(buf, "NOSEQ:"); 360 tipc_printf(buf, "NOSEQ:");
362 else { 361 else
363 tipc_printf(buf, "ACK(%u):", msg_ack(msg)); 362 tipc_printf(buf, "ACK(%u):", msg_ack(msg));
364 }
365 tipc_printf(buf, "BACK(%u):", msg_bcast_ack(msg)); 363 tipc_printf(buf, "BACK(%u):", msg_bcast_ack(msg));
366 tipc_printf(buf, "PRND(%x)", msg_prevnode(msg)); 364 tipc_printf(buf, "PRND(%x)", msg_prevnode(msg));
367 365
@@ -389,14 +387,13 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
389 if (msg_user(msg) == NAME_DISTRIBUTOR) { 387 if (msg_user(msg) == NAME_DISTRIBUTOR) {
390 tipc_printf(buf, ":ONOD(%x):", msg_orignode(msg)); 388 tipc_printf(buf, ":ONOD(%x):", msg_orignode(msg));
391 tipc_printf(buf, ":DNOD(%x):", msg_destnode(msg)); 389 tipc_printf(buf, ":DNOD(%x):", msg_destnode(msg));
392 if (msg_routed(msg)) { 390 if (msg_routed(msg))
393 tipc_printf(buf, ":CSEQN(%u)", msg_transp_seqno(msg)); 391 tipc_printf(buf, ":CSEQN(%u)", msg_transp_seqno(msg));
394 }
395 } 392 }
396 393
397 if (msg_user(msg) == LINK_CONFIG) { 394 if (msg_user(msg) == LINK_CONFIG) {
398 u32* raw = (u32*)msg; 395 u32 *raw = (u32 *)msg;
399 struct tipc_media_addr* orig = (struct tipc_media_addr*)&raw[5]; 396 struct tipc_media_addr *orig = (struct tipc_media_addr *)&raw[5];
400 tipc_printf(buf, ":REQL(%u):", msg_req_links(msg)); 397 tipc_printf(buf, ":REQL(%u):", msg_req_links(msg));
401 tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg)); 398 tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg));
402 tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg)); 399 tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg));
@@ -407,12 +404,10 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
407 tipc_printf(buf, "TO(%u):", msg_bcgap_to(msg)); 404 tipc_printf(buf, "TO(%u):", msg_bcgap_to(msg));
408 } 405 }
409 tipc_printf(buf, "\n"); 406 tipc_printf(buf, "\n");
410 if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) { 407 if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg)))
411 tipc_msg_dbg(buf, msg_get_wrapped(msg), " /"); 408 tipc_msg_dbg(buf, msg_get_wrapped(msg), " /");
412 } 409 if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT))
413 if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) {
414 tipc_msg_dbg(buf, msg_get_wrapped(msg), " /"); 410 tipc_msg_dbg(buf, msg_get_wrapped(msg), " /");
415 }
416} 411}
417 412
418#endif 413#endif
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index 031aad18efce..92c4c4fd7b3f 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -37,10 +37,51 @@
37#ifndef _TIPC_MSG_H 37#ifndef _TIPC_MSG_H
38#define _TIPC_MSG_H 38#define _TIPC_MSG_H
39 39
40#include "core.h" 40#include "bearer.h"
41 41
42#define TIPC_VERSION 2 42#define TIPC_VERSION 2
43 43
44/*
45 * TIPC user data message header format, version 2:
46 *
47 *
48 * 1 0 9 8 7 6 5 4|3 2 1 0 9 8 7 6|5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * w0:|vers | user |hdr sz |n|d|s|-| message size |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * w1:|mstyp| error |rer cnt|lsc|opt p| broadcast ack no |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * w2:| link level ack no | broadcast/link level seq no |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * w3:| previous node |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * w4:| originating port |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * w5:| destination port |
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * w6:| originating node |
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * w7:| destination node |
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 * w8:| name type / transport sequence number |
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * w9:| name instance/multicast lower bound |
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * wA:| multicast upper bound |
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 * / /
73 * \ options \
74 * / /
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 *
77 */
78
79#define TIPC_CONN_MSG 0
80#define TIPC_MCAST_MSG 1
81#define TIPC_NAMED_MSG 2
82#define TIPC_DIRECT_MSG 3
83
84
44#define SHORT_H_SIZE 24 /* Connected, in-cluster messages */ 85#define SHORT_H_SIZE 24 /* Connected, in-cluster messages */
45#define DIR_MSG_H_SIZE 32 /* Directly addressed messages */ 86#define DIR_MSG_H_SIZE 32 /* Directly addressed messages */
46#define LONG_H_SIZE 40 /* Named messages */ 87#define LONG_H_SIZE 40 /* Named messages */
@@ -52,20 +93,26 @@
52#define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE) 93#define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
53 94
54 95
55/* 96struct tipc_msg {
56 TIPC user data message header format, version 2 97 __be32 hdr[15];
98};
57 99
58 - Fundamental definitions available to privileged TIPC users
59 are located in tipc_msg.h.
60 - Remaining definitions available to TIPC internal users appear below.
61*/
62 100
101static inline u32 msg_word(struct tipc_msg *m, u32 pos)
102{
103 return ntohl(m->hdr[pos]);
104}
63 105
64static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val) 106static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val)
65{ 107{
66 m->hdr[w] = htonl(val); 108 m->hdr[w] = htonl(val);
67} 109}
68 110
111static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
112{
113 return (msg_word(m, w) >> pos) & mask;
114}
115
69static inline void msg_set_bits(struct tipc_msg *m, u32 w, 116static inline void msg_set_bits(struct tipc_msg *m, u32 w,
70 u32 pos, u32 mask, u32 val) 117 u32 pos, u32 mask, u32 val)
71{ 118{
@@ -112,16 +159,36 @@ static inline void msg_set_user(struct tipc_msg *m, u32 n)
112 msg_set_bits(m, 0, 25, 0xf, n); 159 msg_set_bits(m, 0, 25, 0xf, n);
113} 160}
114 161
162static inline u32 msg_importance(struct tipc_msg *m)
163{
164 return msg_bits(m, 0, 25, 0xf);
165}
166
115static inline void msg_set_importance(struct tipc_msg *m, u32 i) 167static inline void msg_set_importance(struct tipc_msg *m, u32 i)
116{ 168{
117 msg_set_user(m, i); 169 msg_set_user(m, i);
118} 170}
119 171
120static inline void msg_set_hdr_sz(struct tipc_msg *m,u32 n) 172static inline u32 msg_hdr_sz(struct tipc_msg *m)
173{
174 return msg_bits(m, 0, 21, 0xf) << 2;
175}
176
177static inline void msg_set_hdr_sz(struct tipc_msg *m, u32 n)
121{ 178{
122 msg_set_bits(m, 0, 21, 0xf, n>>2); 179 msg_set_bits(m, 0, 21, 0xf, n>>2);
123} 180}
124 181
182static inline u32 msg_size(struct tipc_msg *m)
183{
184 return msg_bits(m, 0, 0, 0x1ffff);
185}
186
187static inline u32 msg_data_sz(struct tipc_msg *m)
188{
189 return msg_size(m) - msg_hdr_sz(m);
190}
191
125static inline int msg_non_seq(struct tipc_msg *m) 192static inline int msg_non_seq(struct tipc_msg *m)
126{ 193{
127 return msg_bits(m, 0, 20, 1); 194 return msg_bits(m, 0, 20, 1);
@@ -162,11 +229,36 @@ static inline void msg_set_size(struct tipc_msg *m, u32 sz)
162 * Word 1 229 * Word 1
163 */ 230 */
164 231
232static inline u32 msg_type(struct tipc_msg *m)
233{
234 return msg_bits(m, 1, 29, 0x7);
235}
236
165static inline void msg_set_type(struct tipc_msg *m, u32 n) 237static inline void msg_set_type(struct tipc_msg *m, u32 n)
166{ 238{
167 msg_set_bits(m, 1, 29, 0x7, n); 239 msg_set_bits(m, 1, 29, 0x7, n);
168} 240}
169 241
242static inline u32 msg_named(struct tipc_msg *m)
243{
244 return msg_type(m) == TIPC_NAMED_MSG;
245}
246
247static inline u32 msg_mcast(struct tipc_msg *m)
248{
249 return msg_type(m) == TIPC_MCAST_MSG;
250}
251
252static inline u32 msg_connected(struct tipc_msg *m)
253{
254 return msg_type(m) == TIPC_CONN_MSG;
255}
256
257static inline u32 msg_errcode(struct tipc_msg *m)
258{
259 return msg_bits(m, 1, 25, 0xf);
260}
261
170static inline void msg_set_errcode(struct tipc_msg *m, u32 err) 262static inline void msg_set_errcode(struct tipc_msg *m, u32 err)
171{ 263{
172 msg_set_bits(m, 1, 25, 0xf, err); 264 msg_set_bits(m, 1, 25, 0xf, err);
@@ -257,31 +349,68 @@ static inline void msg_set_destnode_cache(struct tipc_msg *m, u32 dnode)
257 */ 349 */
258 350
259 351
352static inline u32 msg_prevnode(struct tipc_msg *m)
353{
354 return msg_word(m, 3);
355}
356
260static inline void msg_set_prevnode(struct tipc_msg *m, u32 a) 357static inline void msg_set_prevnode(struct tipc_msg *m, u32 a)
261{ 358{
262 msg_set_word(m, 3, a); 359 msg_set_word(m, 3, a);
263} 360}
264 361
362static inline u32 msg_origport(struct tipc_msg *m)
363{
364 return msg_word(m, 4);
365}
366
265static inline void msg_set_origport(struct tipc_msg *m, u32 p) 367static inline void msg_set_origport(struct tipc_msg *m, u32 p)
266{ 368{
267 msg_set_word(m, 4, p); 369 msg_set_word(m, 4, p);
268} 370}
269 371
372static inline u32 msg_destport(struct tipc_msg *m)
373{
374 return msg_word(m, 5);
375}
376
270static inline void msg_set_destport(struct tipc_msg *m, u32 p) 377static inline void msg_set_destport(struct tipc_msg *m, u32 p)
271{ 378{
272 msg_set_word(m, 5, p); 379 msg_set_word(m, 5, p);
273} 380}
274 381
382static inline u32 msg_mc_netid(struct tipc_msg *m)
383{
384 return msg_word(m, 5);
385}
386
275static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p) 387static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p)
276{ 388{
277 msg_set_word(m, 5, p); 389 msg_set_word(m, 5, p);
278} 390}
279 391
392static inline int msg_short(struct tipc_msg *m)
393{
394 return msg_hdr_sz(m) == 24;
395}
396
397static inline u32 msg_orignode(struct tipc_msg *m)
398{
399 if (likely(msg_short(m)))
400 return msg_prevnode(m);
401 return msg_word(m, 6);
402}
403
280static inline void msg_set_orignode(struct tipc_msg *m, u32 a) 404static inline void msg_set_orignode(struct tipc_msg *m, u32 a)
281{ 405{
282 msg_set_word(m, 6, a); 406 msg_set_word(m, 6, a);
283} 407}
284 408
409static inline u32 msg_destnode(struct tipc_msg *m)
410{
411 return msg_word(m, 7);
412}
413
285static inline void msg_set_destnode(struct tipc_msg *m, u32 a) 414static inline void msg_set_destnode(struct tipc_msg *m, u32 a)
286{ 415{
287 msg_set_word(m, 7, a); 416 msg_set_word(m, 7, a);
@@ -296,7 +425,12 @@ static inline u32 msg_routed(struct tipc_msg *m)
296{ 425{
297 if (likely(msg_short(m))) 426 if (likely(msg_short(m)))
298 return 0; 427 return 0;
299 return(msg_destnode(m) ^ msg_orignode(m)) >> 11; 428 return (msg_destnode(m) ^ msg_orignode(m)) >> 11;
429}
430
431static inline u32 msg_nametype(struct tipc_msg *m)
432{
433 return msg_word(m, 8);
300} 434}
301 435
302static inline void msg_set_nametype(struct tipc_msg *m, u32 n) 436static inline void msg_set_nametype(struct tipc_msg *m, u32 n)
@@ -324,6 +458,16 @@ static inline void msg_set_transp_seqno(struct tipc_msg *m, u32 n)
324 msg_set_word(m, 8, n); 458 msg_set_word(m, 8, n);
325} 459}
326 460
461static inline u32 msg_nameinst(struct tipc_msg *m)
462{
463 return msg_word(m, 9);
464}
465
466static inline u32 msg_namelower(struct tipc_msg *m)
467{
468 return msg_nameinst(m);
469}
470
327static inline void msg_set_namelower(struct tipc_msg *m, u32 n) 471static inline void msg_set_namelower(struct tipc_msg *m, u32 n)
328{ 472{
329 msg_set_word(m, 9, n); 473 msg_set_word(m, 9, n);
@@ -334,11 +478,21 @@ static inline void msg_set_nameinst(struct tipc_msg *m, u32 n)
334 msg_set_namelower(m, n); 478 msg_set_namelower(m, n);
335} 479}
336 480
481static inline u32 msg_nameupper(struct tipc_msg *m)
482{
483 return msg_word(m, 10);
484}
485
337static inline void msg_set_nameupper(struct tipc_msg *m, u32 n) 486static inline void msg_set_nameupper(struct tipc_msg *m, u32 n)
338{ 487{
339 msg_set_word(m, 10, n); 488 msg_set_word(m, 10, n);
340} 489}
341 490
491static inline unchar *msg_data(struct tipc_msg *m)
492{
493 return ((unchar *)m) + msg_hdr_sz(m);
494}
495
342static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m) 496static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)
343{ 497{
344 return (struct tipc_msg *)msg_data(m); 498 return (struct tipc_msg *)msg_data(m);
@@ -386,7 +540,7 @@ static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)
386#define MSG_BUNDLER 6 540#define MSG_BUNDLER 6
387#define LINK_PROTOCOL 7 541#define LINK_PROTOCOL 7
388#define CONN_MANAGER 8 542#define CONN_MANAGER 8
389#define ROUTE_DISTRIBUTOR 9 543#define ROUTE_DISTRIBUTOR 9 /* obsoleted */
390#define CHANGEOVER_PROTOCOL 10 544#define CHANGEOVER_PROTOCOL 10
391#define NAME_DISTRIBUTOR 11 545#define NAME_DISTRIBUTOR 11
392#define MSG_FRAGMENTER 12 546#define MSG_FRAGMENTER 12
@@ -665,11 +819,6 @@ static inline void msg_set_remote_node(struct tipc_msg *m, u32 a)
665 msg_set_word(m, msg_hdr_sz(m)/4, a); 819 msg_set_word(m, msg_hdr_sz(m)/4, a);
666} 820}
667 821
668static inline void msg_set_dataoctet(struct tipc_msg *m, u32 pos)
669{
670 msg_data(m)[pos + 4] = 1;
671}
672
673/* 822/*
674 * Segmentation message types 823 * Segmentation message types
675 */ 824 */
@@ -696,7 +845,7 @@ static inline void msg_set_dataoctet(struct tipc_msg *m, u32 pos)
696 * Routing table message types 845 * Routing table message types
697 */ 846 */
698#define EXT_ROUTING_TABLE 0 847#define EXT_ROUTING_TABLE 0
699#define LOCAL_ROUTING_TABLE 1 848#define LOCAL_ROUTING_TABLE 1 /* obsoleted */
700#define SLAVE_ROUTING_TABLE 2 849#define SLAVE_ROUTING_TABLE 2
701#define ROUTE_ADDITION 3 850#define ROUTE_ADDITION 3
702#define ROUTE_REMOVAL 4 851#define ROUTE_REMOVAL 4
@@ -714,7 +863,7 @@ void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type,
714int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect); 863int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect);
715int tipc_msg_build(struct tipc_msg *hdr, 864int tipc_msg_build(struct tipc_msg *hdr,
716 struct iovec const *msg_sect, u32 num_sect, 865 struct iovec const *msg_sect, u32 num_sect,
717 int max_size, int usrmem, struct sk_buff** buf); 866 int max_size, int usrmem, struct sk_buff **buf);
718 867
719static inline void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr *a) 868static inline void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
720{ 869{
@@ -723,7 +872,7 @@ static inline void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr
723 872
724static inline void msg_get_media_addr(struct tipc_msg *m, struct tipc_media_addr *a) 873static inline void msg_get_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
725{ 874{
726 memcpy(a, &((int*)m)[5], sizeof(*a)); 875 memcpy(a, &((int *)m)[5], sizeof(*a));
727} 876}
728 877
729#endif 878#endif
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c
index 7b907171f879..483c226c9581 100644
--- a/net/tipc/name_distr.c
+++ b/net/tipc/name_distr.c
@@ -35,10 +35,7 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "cluster.h"
39#include "dbg.h"
40#include "link.h" 38#include "link.h"
41#include "msg.h"
42#include "name_distr.h" 39#include "name_distr.h"
43 40
44#define ITEM_SIZE sizeof(struct distr_item) 41#define ITEM_SIZE sizeof(struct distr_item)
@@ -76,7 +73,7 @@ struct distr_item {
76 */ 73 */
77 74
78static LIST_HEAD(publ_root); 75static LIST_HEAD(publ_root);
79static u32 publ_cnt = 0; 76static u32 publ_cnt;
80 77
81/** 78/**
82 * publ_to_item - add publication info to a publication message 79 * publ_to_item - add publication info to a publication message
@@ -89,7 +86,6 @@ static void publ_to_item(struct distr_item *i, struct publication *p)
89 i->upper = htonl(p->upper); 86 i->upper = htonl(p->upper);
90 i->ref = htonl(p->ref); 87 i->ref = htonl(p->ref);
91 i->key = htonl(p->key); 88 i->key = htonl(p->key);
92 dbg("publ_to_item: %u, %u, %u\n", p->type, p->lower, p->upper);
93} 89}
94 90
95/** 91/**
@@ -109,6 +105,26 @@ static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest)
109 return buf; 105 return buf;
110} 106}
111 107
108static void named_cluster_distribute(struct sk_buff *buf)
109{
110 struct sk_buff *buf_copy;
111 struct tipc_node *n_ptr;
112 u32 n_num;
113
114 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++) {
115 n_ptr = tipc_net.nodes[n_num];
116 if (n_ptr && tipc_node_has_active_links(n_ptr)) {
117 buf_copy = skb_copy(buf, GFP_ATOMIC);
118 if (!buf_copy)
119 break;
120 msg_set_destnode(buf_msg(buf_copy), n_ptr->addr);
121 tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr);
122 }
123 }
124
125 buf_discard(buf);
126}
127
112/** 128/**
113 * tipc_named_publish - tell other nodes about a new publication by this node 129 * tipc_named_publish - tell other nodes about a new publication by this node
114 */ 130 */
@@ -129,8 +145,7 @@ void tipc_named_publish(struct publication *publ)
129 145
130 item = (struct distr_item *)msg_data(buf_msg(buf)); 146 item = (struct distr_item *)msg_data(buf_msg(buf));
131 publ_to_item(item, publ); 147 publ_to_item(item, publ);
132 dbg("tipc_named_withdraw: broadcasting publish msg\n"); 148 named_cluster_distribute(buf);
133 tipc_cltr_broadcast(buf);
134} 149}
135 150
136/** 151/**
@@ -153,8 +168,7 @@ void tipc_named_withdraw(struct publication *publ)
153 168
154 item = (struct distr_item *)msg_data(buf_msg(buf)); 169 item = (struct distr_item *)msg_data(buf_msg(buf));
155 publ_to_item(item, publ); 170 publ_to_item(item, publ);
156 dbg("tipc_named_withdraw: broadcasting withdraw msg\n"); 171 named_cluster_distribute(buf);
157 tipc_cltr_broadcast(buf);
158} 172}
159 173
160/** 174/**
@@ -191,9 +205,6 @@ void tipc_named_node_up(unsigned long node)
191 left -= ITEM_SIZE; 205 left -= ITEM_SIZE;
192 if (!left) { 206 if (!left) {
193 msg_set_link_selector(buf_msg(buf), node); 207 msg_set_link_selector(buf_msg(buf), node);
194 dbg("tipc_named_node_up: sending publish msg to "
195 "<%u.%u.%u>\n", tipc_zone(node),
196 tipc_cluster(node), tipc_node(node));
197 tipc_link_send(buf, node, node); 208 tipc_link_send(buf, node, node);
198 buf = NULL; 209 buf = NULL;
199 } 210 }
@@ -218,8 +229,6 @@ static void node_is_down(struct publication *publ)
218 struct publication *p; 229 struct publication *p;
219 230
220 write_lock_bh(&tipc_nametbl_lock); 231 write_lock_bh(&tipc_nametbl_lock);
221 dbg("node_is_down: withdrawing %u, %u, %u\n",
222 publ->type, publ->lower, publ->upper);
223 publ->key += 1222345; 232 publ->key += 1222345;
224 p = tipc_nametbl_remove_publ(publ->type, publ->lower, 233 p = tipc_nametbl_remove_publ(publ->type, publ->lower,
225 publ->node, publ->ref, publ->key); 234 publ->node, publ->ref, publ->key);
@@ -231,9 +240,7 @@ static void node_is_down(struct publication *publ)
231 publ->type, publ->lower, publ->node, publ->ref, publ->key); 240 publ->type, publ->lower, publ->node, publ->ref, publ->key);
232 } 241 }
233 242
234 if (p) { 243 kfree(p);
235 kfree(p);
236 }
237} 244}
238 245
239/** 246/**
@@ -250,9 +257,6 @@ void tipc_named_recv(struct sk_buff *buf)
250 write_lock_bh(&tipc_nametbl_lock); 257 write_lock_bh(&tipc_nametbl_lock);
251 while (count--) { 258 while (count--) {
252 if (msg_type(msg) == PUBLICATION) { 259 if (msg_type(msg) == PUBLICATION) {
253 dbg("tipc_named_recv: got publication for %u, %u, %u\n",
254 ntohl(item->type), ntohl(item->lower),
255 ntohl(item->upper));
256 publ = tipc_nametbl_insert_publ(ntohl(item->type), 260 publ = tipc_nametbl_insert_publ(ntohl(item->type),
257 ntohl(item->lower), 261 ntohl(item->lower),
258 ntohl(item->upper), 262 ntohl(item->upper),
@@ -267,9 +271,6 @@ void tipc_named_recv(struct sk_buff *buf)
267 (net_ev_handler)node_is_down); 271 (net_ev_handler)node_is_down);
268 } 272 }
269 } else if (msg_type(msg) == WITHDRAWAL) { 273 } else if (msg_type(msg) == WITHDRAWAL) {
270 dbg("tipc_named_recv: got withdrawl for %u, %u, %u\n",
271 ntohl(item->type), ntohl(item->lower),
272 ntohl(item->upper));
273 publ = tipc_nametbl_remove_publ(ntohl(item->type), 274 publ = tipc_nametbl_remove_publ(ntohl(item->type),
274 ntohl(item->lower), 275 ntohl(item->lower),
275 msg_orignode(msg), 276 msg_orignode(msg),
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 3a8de4334da1..205ed4a4e186 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -36,15 +36,10 @@
36 36
37#include "core.h" 37#include "core.h"
38#include "config.h" 38#include "config.h"
39#include "dbg.h"
40#include "name_table.h" 39#include "name_table.h"
41#include "name_distr.h" 40#include "name_distr.h"
42#include "addr.h"
43#include "node_subscr.h"
44#include "subscr.h" 41#include "subscr.h"
45#include "port.h" 42#include "port.h"
46#include "cluster.h"
47#include "bcast.h"
48 43
49static int tipc_nametbl_size = 1024; /* must be a power of 2 */ 44static int tipc_nametbl_size = 1024; /* must be a power of 2 */
50 45
@@ -109,7 +104,7 @@ struct name_table {
109 u32 local_publ_count; 104 u32 local_publ_count;
110}; 105};
111 106
112static struct name_table table = { NULL } ; 107static struct name_table table;
113static atomic_t rsv_publ_ok = ATOMIC_INIT(0); 108static atomic_t rsv_publ_ok = ATOMIC_INIT(0);
114DEFINE_RWLOCK(tipc_nametbl_lock); 109DEFINE_RWLOCK(tipc_nametbl_lock);
115 110
@@ -177,8 +172,6 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea
177 spin_lock_init(&nseq->lock); 172 spin_lock_init(&nseq->lock);
178 nseq->type = type; 173 nseq->type = type;
179 nseq->sseqs = sseq; 174 nseq->sseqs = sseq;
180 dbg("tipc_nameseq_create(): nseq = %p, type %u, ssseqs %p, ff: %u\n",
181 nseq, type, nseq->sseqs, nseq->first_free);
182 nseq->alloc = 1; 175 nseq->alloc = 1;
183 INIT_HLIST_NODE(&nseq->ns_list); 176 INIT_HLIST_NODE(&nseq->ns_list);
184 INIT_LIST_HEAD(&nseq->subscriptions); 177 INIT_LIST_HEAD(&nseq->subscriptions);
@@ -256,8 +249,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
256 int created_subseq = 0; 249 int created_subseq = 0;
257 250
258 sseq = nameseq_find_subseq(nseq, lower); 251 sseq = nameseq_find_subseq(nseq, lower);
259 dbg("nameseq_ins: for seq %p, {%u,%u}, found sseq %p\n",
260 nseq, type, lower, sseq);
261 if (sseq) { 252 if (sseq) {
262 253
263 /* Lower end overlaps existing entry => need an exact match */ 254 /* Lower end overlaps existing entry => need an exact match */
@@ -294,38 +285,30 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
294 type, lower, upper); 285 type, lower, upper);
295 return NULL; 286 return NULL;
296 } 287 }
297 dbg("Allocated %u more sseqs\n", nseq->alloc);
298 memcpy(sseqs, nseq->sseqs, 288 memcpy(sseqs, nseq->sseqs,
299 nseq->alloc * sizeof(struct sub_seq)); 289 nseq->alloc * sizeof(struct sub_seq));
300 kfree(nseq->sseqs); 290 kfree(nseq->sseqs);
301 nseq->sseqs = sseqs; 291 nseq->sseqs = sseqs;
302 nseq->alloc *= 2; 292 nseq->alloc *= 2;
303 } 293 }
304 dbg("Have %u sseqs for type %u\n", nseq->alloc, type);
305 294
306 /* Insert new sub-sequence */ 295 /* Insert new sub-sequence */
307 296
308 dbg("ins in pos %u, ff = %u\n", inspos, nseq->first_free);
309 sseq = &nseq->sseqs[inspos]; 297 sseq = &nseq->sseqs[inspos];
310 freesseq = &nseq->sseqs[nseq->first_free]; 298 freesseq = &nseq->sseqs[nseq->first_free];
311 memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof (*sseq)); 299 memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq));
312 memset(sseq, 0, sizeof (*sseq)); 300 memset(sseq, 0, sizeof(*sseq));
313 nseq->first_free++; 301 nseq->first_free++;
314 sseq->lower = lower; 302 sseq->lower = lower;
315 sseq->upper = upper; 303 sseq->upper = upper;
316 created_subseq = 1; 304 created_subseq = 1;
317 } 305 }
318 dbg("inserting {%u,%u,%u} from <0x%x:%u> into sseq %p(%u,%u) of seq %p\n",
319 type, lower, upper, node, port, sseq,
320 sseq->lower, sseq->upper, nseq);
321 306
322 /* Insert a publication: */ 307 /* Insert a publication: */
323 308
324 publ = publ_create(type, lower, upper, scope, node, port, key); 309 publ = publ_create(type, lower, upper, scope, node, port, key);
325 if (!publ) 310 if (!publ)
326 return NULL; 311 return NULL;
327 dbg("inserting publ %p, node=0x%x publ->node=0x%x, subscr->node=%p\n",
328 publ, node, publ->node, publ->subscr.node);
329 312
330 sseq->zone_list_size++; 313 sseq->zone_list_size++;
331 if (!sseq->zone_list) 314 if (!sseq->zone_list)
@@ -360,7 +343,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq,
360 * Any subscriptions waiting for notification? 343 * Any subscriptions waiting for notification?
361 */ 344 */
362 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { 345 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
363 dbg("calling report_overlap()\n");
364 tipc_subscr_report_overlap(s, 346 tipc_subscr_report_overlap(s,
365 publ->lower, 347 publ->lower,
366 publ->upper, 348 publ->upper,
@@ -398,9 +380,6 @@ static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 i
398 if (!sseq) 380 if (!sseq)
399 return NULL; 381 return NULL;
400 382
401 dbg("tipc_nameseq_remove_publ: seq: %p, sseq %p, {%u,%u}, key %u\n",
402 nseq, sseq, nseq->type, inst, key);
403
404 /* Remove publication from zone scope list */ 383 /* Remove publication from zone scope list */
405 384
406 prev = sseq->zone_list; 385 prev = sseq->zone_list;
@@ -492,7 +471,7 @@ end_node:
492 471
493 if (!sseq->zone_list) { 472 if (!sseq->zone_list) {
494 free = &nseq->sseqs[nseq->first_free--]; 473 free = &nseq->sseqs[nseq->first_free--];
495 memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof (*sseq)); 474 memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq));
496 removed_subseq = 1; 475 removed_subseq = 1;
497 } 476 }
498 477
@@ -528,7 +507,7 @@ static void tipc_nameseq_subscribe(struct name_seq *nseq, struct subscription *s
528 507
529 while (sseq != &nseq->sseqs[nseq->first_free]) { 508 while (sseq != &nseq->sseqs[nseq->first_free]) {
530 struct publication *zl = sseq->zone_list; 509 struct publication *zl = sseq->zone_list;
531 if (zl && tipc_subscr_overlap(s,sseq->lower,sseq->upper)) { 510 if (zl && tipc_subscr_overlap(s, sseq->lower, sseq->upper)) {
532 struct publication *crs = zl; 511 struct publication *crs = zl;
533 int must_report = 1; 512 int must_report = 1;
534 513
@@ -554,15 +533,10 @@ static struct name_seq *nametbl_find_seq(u32 type)
554 struct hlist_node *seq_node; 533 struct hlist_node *seq_node;
555 struct name_seq *ns; 534 struct name_seq *ns;
556 535
557 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n",
558 type, htonl(type), type, table.types, hash(type));
559
560 seq_head = &table.types[hash(type)]; 536 seq_head = &table.types[hash(type)];
561 hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { 537 hlist_for_each_entry(ns, seq_node, seq_head, ns_list) {
562 if (ns->type == type) { 538 if (ns->type == type)
563 dbg("found %p\n", ns);
564 return ns; 539 return ns;
565 }
566 } 540 }
567 541
568 return NULL; 542 return NULL;
@@ -573,18 +547,14 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
573{ 547{
574 struct name_seq *seq = nametbl_find_seq(type); 548 struct name_seq *seq = nametbl_find_seq(type);
575 549
576 dbg("tipc_nametbl_insert_publ: {%u,%u,%u} found %p\n", type, lower, upper, seq);
577 if (lower > upper) { 550 if (lower > upper) {
578 warn("Failed to publish illegal {%u,%u,%u}\n", 551 warn("Failed to publish illegal {%u,%u,%u}\n",
579 type, lower, upper); 552 type, lower, upper);
580 return NULL; 553 return NULL;
581 } 554 }
582 555
583 dbg("Publishing {%u,%u,%u} from 0x%x\n", type, lower, upper, node); 556 if (!seq)
584 if (!seq) {
585 seq = tipc_nameseq_create(type, &table.types[hash(type)]); 557 seq = tipc_nameseq_create(type, &table.types[hash(type)]);
586 dbg("tipc_nametbl_insert_publ: created %p\n", seq);
587 }
588 if (!seq) 558 if (!seq)
589 return NULL; 559 return NULL;
590 560
@@ -601,7 +571,6 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower,
601 if (!seq) 571 if (!seq)
602 return NULL; 572 return NULL;
603 573
604 dbg("Withdrawing {%u,%u} from 0x%x\n", type, lower, node);
605 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); 574 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key);
606 575
607 if (!seq->first_free && list_empty(&seq->subscriptions)) { 576 if (!seq->first_free && list_empty(&seq->subscriptions)) {
@@ -782,9 +751,8 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
782 table.local_publ_count++; 751 table.local_publ_count++;
783 publ = tipc_nametbl_insert_publ(type, lower, upper, scope, 752 publ = tipc_nametbl_insert_publ(type, lower, upper, scope,
784 tipc_own_addr, port_ref, key); 753 tipc_own_addr, port_ref, key);
785 if (publ && (scope != TIPC_NODE_SCOPE)) { 754 if (publ && (scope != TIPC_NODE_SCOPE))
786 tipc_named_publish(publ); 755 tipc_named_publish(publ);
787 }
788 write_unlock_bh(&tipc_nametbl_lock); 756 write_unlock_bh(&tipc_nametbl_lock);
789 return publ; 757 return publ;
790} 758}
@@ -797,7 +765,6 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
797{ 765{
798 struct publication *publ; 766 struct publication *publ;
799 767
800 dbg("tipc_nametbl_withdraw: {%u,%u}, key=%u\n", type, lower, key);
801 write_lock_bh(&tipc_nametbl_lock); 768 write_lock_bh(&tipc_nametbl_lock);
802 publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); 769 publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key);
803 if (likely(publ)) { 770 if (likely(publ)) {
@@ -827,13 +794,10 @@ void tipc_nametbl_subscribe(struct subscription *s)
827 794
828 write_lock_bh(&tipc_nametbl_lock); 795 write_lock_bh(&tipc_nametbl_lock);
829 seq = nametbl_find_seq(type); 796 seq = nametbl_find_seq(type);
830 if (!seq) { 797 if (!seq)
831 seq = tipc_nameseq_create(type, &table.types[hash(type)]); 798 seq = tipc_nameseq_create(type, &table.types[hash(type)]);
832 } 799 if (seq) {
833 if (seq){
834 spin_lock_bh(&seq->lock); 800 spin_lock_bh(&seq->lock);
835 dbg("tipc_nametbl_subscribe:found %p for {%u,%u,%u}\n",
836 seq, type, s->seq.lower, s->seq.upper);
837 tipc_nameseq_subscribe(seq, s); 801 tipc_nameseq_subscribe(seq, s);
838 spin_unlock_bh(&seq->lock); 802 spin_unlock_bh(&seq->lock);
839 } else { 803 } else {
@@ -853,7 +817,7 @@ void tipc_nametbl_unsubscribe(struct subscription *s)
853 817
854 write_lock_bh(&tipc_nametbl_lock); 818 write_lock_bh(&tipc_nametbl_lock);
855 seq = nametbl_find_seq(s->seq.type); 819 seq = nametbl_find_seq(s->seq.type);
856 if (seq != NULL){ 820 if (seq != NULL) {
857 spin_lock_bh(&seq->lock); 821 spin_lock_bh(&seq->lock);
858 list_del_init(&s->nameseq_list); 822 list_del_init(&s->nameseq_list);
859 spin_unlock_bh(&seq->lock); 823 spin_unlock_bh(&seq->lock);
@@ -886,7 +850,7 @@ static void subseq_list(struct sub_seq *sseq, struct print_buf *buf, u32 depth,
886 } 850 }
887 851
888 do { 852 do {
889 sprintf (portIdStr, "<%u.%u.%u:%u>", 853 sprintf(portIdStr, "<%u.%u.%u:%u>",
890 tipc_zone(publ->node), tipc_cluster(publ->node), 854 tipc_zone(publ->node), tipc_cluster(publ->node),
891 tipc_node(publ->node), publ->ref); 855 tipc_node(publ->node), publ->ref);
892 tipc_printf(buf, "%-26s ", portIdStr); 856 tipc_printf(buf, "%-26s ", portIdStr);
diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h
index 139882d4ed00..d228bd682655 100644
--- a/net/tipc/name_table.h
+++ b/net/tipc/name_table.h
@@ -46,7 +46,7 @@ struct port_list;
46 * TIPC name types reserved for internal TIPC use (both current and planned) 46 * TIPC name types reserved for internal TIPC use (both current and planned)
47 */ 47 */
48 48
49#define TIPC_ZM_SRV 3 /* zone master service name type */ 49#define TIPC_ZM_SRV 3 /* zone master service name type */
50 50
51 51
52/** 52/**
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 1a621cfd6604..9bacfd00b91e 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -35,18 +35,10 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "bearer.h"
39#include "net.h" 38#include "net.h"
40#include "zone.h"
41#include "addr.h"
42#include "name_table.h"
43#include "name_distr.h" 39#include "name_distr.h"
44#include "subscr.h" 40#include "subscr.h"
45#include "link.h"
46#include "msg.h"
47#include "port.h" 41#include "port.h"
48#include "bcast.h"
49#include "discover.h"
50#include "config.h" 42#include "config.h"
51 43
52/* 44/*
@@ -116,46 +108,25 @@
116*/ 108*/
117 109
118DEFINE_RWLOCK(tipc_net_lock); 110DEFINE_RWLOCK(tipc_net_lock);
119static struct _zone *tipc_zones[256] = { NULL, }; 111struct network tipc_net;
120struct network tipc_net = { tipc_zones };
121 112
122struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref) 113static int net_start(void)
123{ 114{
124 return tipc_zone_select_remote_node(tipc_net.zones[tipc_zone(addr)], addr, ref); 115 tipc_net.nodes = kcalloc(tipc_max_nodes + 1,
125} 116 sizeof(*tipc_net.nodes), GFP_ATOMIC);
126 117 tipc_net.highest_node = 0;
127u32 tipc_net_select_router(u32 addr, u32 ref)
128{
129 return tipc_zone_select_router(tipc_net.zones[tipc_zone(addr)], addr, ref);
130}
131
132void tipc_net_remove_as_router(u32 router)
133{
134 u32 z_num;
135
136 for (z_num = 1; z_num <= tipc_max_zones; z_num++) {
137 if (!tipc_net.zones[z_num])
138 continue;
139 tipc_zone_remove_as_router(tipc_net.zones[z_num], router);
140 }
141}
142
143void tipc_net_send_external_routes(u32 dest)
144{
145 u32 z_num;
146 118
147 for (z_num = 1; z_num <= tipc_max_zones; z_num++) { 119 return tipc_net.nodes ? 0 : -ENOMEM;
148 if (tipc_net.zones[z_num])
149 tipc_zone_send_external_routes(tipc_net.zones[z_num], dest);
150 }
151} 120}
152 121
153static void net_stop(void) 122static void net_stop(void)
154{ 123{
155 u32 z_num; 124 u32 n_num;
156 125
157 for (z_num = 1; z_num <= tipc_max_zones; z_num++) 126 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++)
158 tipc_zone_delete(tipc_net.zones[z_num]); 127 tipc_node_delete(tipc_net.nodes[n_num]);
128 kfree(tipc_net.nodes);
129 tipc_net.nodes = NULL;
159} 130}
160 131
161static void net_route_named_msg(struct sk_buff *buf) 132static void net_route_named_msg(struct sk_buff *buf)
@@ -165,22 +136,18 @@ static void net_route_named_msg(struct sk_buff *buf)
165 u32 dport; 136 u32 dport;
166 137
167 if (!msg_named(msg)) { 138 if (!msg_named(msg)) {
168 msg_dbg(msg, "tipc_net->drop_nam:");
169 buf_discard(buf); 139 buf_discard(buf);
170 return; 140 return;
171 } 141 }
172 142
173 dnode = addr_domain(msg_lookup_scope(msg)); 143 dnode = addr_domain(msg_lookup_scope(msg));
174 dport = tipc_nametbl_translate(msg_nametype(msg), msg_nameinst(msg), &dnode); 144 dport = tipc_nametbl_translate(msg_nametype(msg), msg_nameinst(msg), &dnode);
175 dbg("tipc_net->lookup<%u,%u>-><%u,%x>\n",
176 msg_nametype(msg), msg_nameinst(msg), dport, dnode);
177 if (dport) { 145 if (dport) {
178 msg_set_destnode(msg, dnode); 146 msg_set_destnode(msg, dnode);
179 msg_set_destport(msg, dport); 147 msg_set_destport(msg, dport);
180 tipc_net_route_msg(buf); 148 tipc_net_route_msg(buf);
181 return; 149 return;
182 } 150 }
183 msg_dbg(msg, "tipc_net->rej:NO NAME: ");
184 tipc_reject_msg(buf, TIPC_ERR_NO_NAME); 151 tipc_reject_msg(buf, TIPC_ERR_NO_NAME);
185} 152}
186 153
@@ -196,18 +163,14 @@ void tipc_net_route_msg(struct sk_buff *buf)
196 msg_incr_reroute_cnt(msg); 163 msg_incr_reroute_cnt(msg);
197 if (msg_reroute_cnt(msg) > 6) { 164 if (msg_reroute_cnt(msg) > 6) {
198 if (msg_errcode(msg)) { 165 if (msg_errcode(msg)) {
199 msg_dbg(msg, "NET>DISC>:");
200 buf_discard(buf); 166 buf_discard(buf);
201 } else { 167 } else {
202 msg_dbg(msg, "NET>REJ>:");
203 tipc_reject_msg(buf, msg_destport(msg) ? 168 tipc_reject_msg(buf, msg_destport(msg) ?
204 TIPC_ERR_NO_PORT : TIPC_ERR_NO_NAME); 169 TIPC_ERR_NO_PORT : TIPC_ERR_NO_NAME);
205 } 170 }
206 return; 171 return;
207 } 172 }
208 173
209 msg_dbg(msg, "tipc_net->rout: ");
210
211 /* Handle message for this node */ 174 /* Handle message for this node */
212 dnode = msg_short(msg) ? tipc_own_addr : msg_destnode(msg); 175 dnode = msg_short(msg) ? tipc_own_addr : msg_destnode(msg);
213 if (tipc_in_scope(dnode, tipc_own_addr)) { 176 if (tipc_in_scope(dnode, tipc_own_addr)) {
@@ -221,9 +184,6 @@ void tipc_net_route_msg(struct sk_buff *buf)
221 return; 184 return;
222 } 185 }
223 switch (msg_user(msg)) { 186 switch (msg_user(msg)) {
224 case ROUTE_DISTRIBUTOR:
225 tipc_cltr_recv_routing_table(buf);
226 break;
227 case NAME_DISTRIBUTOR: 187 case NAME_DISTRIBUTOR:
228 tipc_named_recv(buf); 188 tipc_named_recv(buf);
229 break; 189 break;
@@ -231,14 +191,12 @@ void tipc_net_route_msg(struct sk_buff *buf)
231 tipc_port_recv_proto_msg(buf); 191 tipc_port_recv_proto_msg(buf);
232 break; 192 break;
233 default: 193 default:
234 msg_dbg(msg,"DROP/NET/<REC<");
235 buf_discard(buf); 194 buf_discard(buf);
236 } 195 }
237 return; 196 return;
238 } 197 }
239 198
240 /* Handle message for another node */ 199 /* Handle message for another node */
241 msg_dbg(msg, "NET>SEND>: ");
242 skb_trim(buf, msg_size(msg)); 200 skb_trim(buf, msg_size(msg));
243 tipc_link_send(buf, dnode, msg_link_selector(msg)); 201 tipc_link_send(buf, dnode, msg_link_selector(msg));
244} 202}
@@ -259,10 +217,12 @@ int tipc_net_start(u32 addr)
259 tipc_named_reinit(); 217 tipc_named_reinit();
260 tipc_port_reinit(); 218 tipc_port_reinit();
261 219
262 if ((res = tipc_cltr_init()) || 220 res = net_start();
263 (res = tipc_bclink_init())) { 221 if (res)
222 return res;
223 res = tipc_bclink_init();
224 if (res)
264 return res; 225 return res;
265 }
266 226
267 tipc_k_signal((Handler)tipc_subscr_start, 0); 227 tipc_k_signal((Handler)tipc_subscr_start, 0);
268 tipc_k_signal((Handler)tipc_cfg_init, 0); 228 tipc_k_signal((Handler)tipc_cfg_init, 0);
diff --git a/net/tipc/net.h b/net/tipc/net.h
index de2b9ad8f646..4ae59ad04893 100644
--- a/net/tipc/net.h
+++ b/net/tipc/net.h
@@ -37,26 +37,26 @@
37#ifndef _TIPC_NET_H 37#ifndef _TIPC_NET_H
38#define _TIPC_NET_H 38#define _TIPC_NET_H
39 39
40struct _zone; 40struct tipc_node;
41 41
42/** 42/**
43 * struct network - TIPC network structure 43 * struct network - TIPC network structure
44 * @zones: array of pointers to all zones within network 44 * @nodes: array of pointers to all nodes within cluster
45 * @highest_node: id of highest numbered node within cluster
46 * @links: number of (unicast) links to cluster
45 */ 47 */
46 48
47struct network { 49struct network {
48 struct _zone **zones; 50 struct tipc_node **nodes;
51 u32 highest_node;
52 u32 links;
49}; 53};
50 54
51 55
52extern struct network tipc_net; 56extern struct network tipc_net;
53extern rwlock_t tipc_net_lock; 57extern rwlock_t tipc_net_lock;
54 58
55void tipc_net_remove_as_router(u32 router);
56void tipc_net_send_external_routes(u32 dest);
57void tipc_net_route_msg(struct sk_buff *buf); 59void tipc_net_route_msg(struct sk_buff *buf);
58struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref);
59u32 tipc_net_select_router(u32 addr, u32 ref);
60 60
61int tipc_net_start(u32 addr); 61int tipc_net_start(u32 addr);
62void tipc_net_stop(void); 62void tipc_net_stop(void);
diff --git a/net/tipc/node.c b/net/tipc/node.c
index b4d87eb2dc5d..3af53e327f49 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -37,25 +37,14 @@
37#include "core.h" 37#include "core.h"
38#include "config.h" 38#include "config.h"
39#include "node.h" 39#include "node.h"
40#include "cluster.h"
41#include "net.h"
42#include "addr.h"
43#include "node_subscr.h"
44#include "link.h"
45#include "port.h"
46#include "bearer.h"
47#include "name_distr.h" 40#include "name_distr.h"
48 41
49void node_print(struct print_buf *buf, struct tipc_node *n_ptr, char *str);
50static void node_lost_contact(struct tipc_node *n_ptr); 42static void node_lost_contact(struct tipc_node *n_ptr);
51static void node_established_contact(struct tipc_node *n_ptr); 43static void node_established_contact(struct tipc_node *n_ptr);
52 44
53/* sorted list of nodes within cluster */
54static struct tipc_node *tipc_nodes = NULL;
55
56static DEFINE_SPINLOCK(node_create_lock); 45static DEFINE_SPINLOCK(node_create_lock);
57 46
58u32 tipc_own_tag = 0; 47u32 tipc_own_tag;
59 48
60/** 49/**
61 * tipc_node_create - create neighboring node 50 * tipc_node_create - create neighboring node
@@ -69,65 +58,51 @@ u32 tipc_own_tag = 0;
69 58
70struct tipc_node *tipc_node_create(u32 addr) 59struct tipc_node *tipc_node_create(u32 addr)
71{ 60{
72 struct cluster *c_ptr;
73 struct tipc_node *n_ptr; 61 struct tipc_node *n_ptr;
74 struct tipc_node **curr_node; 62 u32 n_num;
75 63
76 spin_lock_bh(&node_create_lock); 64 spin_lock_bh(&node_create_lock);
77 65
78 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { 66 n_ptr = tipc_node_find(addr);
79 if (addr < n_ptr->addr) 67 if (n_ptr) {
80 break; 68 spin_unlock_bh(&node_create_lock);
81 if (addr == n_ptr->addr) { 69 return n_ptr;
82 spin_unlock_bh(&node_create_lock);
83 return n_ptr;
84 }
85 } 70 }
86 71
87 n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC); 72 n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC);
88 if (!n_ptr) { 73 if (!n_ptr) {
89 spin_unlock_bh(&node_create_lock); 74 spin_unlock_bh(&node_create_lock);
90 warn("Node creation failed, no memory\n"); 75 warn("Node creation failed, no memory\n");
91 return NULL; 76 return NULL;
92 } 77 }
93 78
94 c_ptr = tipc_cltr_find(addr);
95 if (!c_ptr) {
96 c_ptr = tipc_cltr_create(addr);
97 }
98 if (!c_ptr) {
99 spin_unlock_bh(&node_create_lock);
100 kfree(n_ptr);
101 return NULL;
102 }
103
104 n_ptr->addr = addr; 79 n_ptr->addr = addr;
105 spin_lock_init(&n_ptr->lock); 80 spin_lock_init(&n_ptr->lock);
106 INIT_LIST_HEAD(&n_ptr->nsub); 81 INIT_LIST_HEAD(&n_ptr->nsub);
107 n_ptr->owner = c_ptr; 82
108 tipc_cltr_attach_node(c_ptr, n_ptr); 83 n_num = tipc_node(addr);
109 n_ptr->last_router = -1; 84 tipc_net.nodes[n_num] = n_ptr;
110 85 if (n_num > tipc_net.highest_node)
111 /* Insert node into ordered list */ 86 tipc_net.highest_node = n_num;
112 for (curr_node = &tipc_nodes; *curr_node; 87
113 curr_node = &(*curr_node)->next) {
114 if (addr < (*curr_node)->addr) {
115 n_ptr->next = *curr_node;
116 break;
117 }
118 }
119 (*curr_node) = n_ptr;
120 spin_unlock_bh(&node_create_lock); 88 spin_unlock_bh(&node_create_lock);
121 return n_ptr; 89 return n_ptr;
122} 90}
123 91
124void tipc_node_delete(struct tipc_node *n_ptr) 92void tipc_node_delete(struct tipc_node *n_ptr)
125{ 93{
94 u32 n_num;
95
126 if (!n_ptr) 96 if (!n_ptr)
127 return; 97 return;
128 98
129 dbg("node %x deleted\n", n_ptr->addr); 99 n_num = tipc_node(n_ptr->addr);
100 tipc_net.nodes[n_num] = NULL;
130 kfree(n_ptr); 101 kfree(n_ptr);
102
103 while (!tipc_net.nodes[tipc_net.highest_node])
104 if (--tipc_net.highest_node == 0)
105 break;
131} 106}
132 107
133 108
@@ -147,7 +122,6 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr)
147 l_ptr->name, l_ptr->b_ptr->net_plane); 122 l_ptr->name, l_ptr->b_ptr->net_plane);
148 123
149 if (!active[0]) { 124 if (!active[0]) {
150 dbg(" link %x into %x/%x\n", l_ptr, &active[0], &active[1]);
151 active[0] = active[1] = l_ptr; 125 active[0] = active[1] = l_ptr;
152 node_established_contact(n_ptr); 126 node_established_contact(n_ptr);
153 return; 127 return;
@@ -236,14 +210,9 @@ int tipc_node_has_redundant_links(struct tipc_node *n_ptr)
236 return n_ptr->working_links > 1; 210 return n_ptr->working_links > 1;
237} 211}
238 212
239static int tipc_node_has_active_routes(struct tipc_node *n_ptr)
240{
241 return n_ptr && (n_ptr->last_router >= 0);
242}
243
244int tipc_node_is_up(struct tipc_node *n_ptr) 213int tipc_node_is_up(struct tipc_node *n_ptr)
245{ 214{
246 return tipc_node_has_active_links(n_ptr) || tipc_node_has_active_routes(n_ptr); 215 return tipc_node_has_active_links(n_ptr);
247} 216}
248 217
249struct tipc_node *tipc_node_attach_link(struct link *l_ptr) 218struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
@@ -264,7 +233,7 @@ struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
264 233
265 if (!n_ptr->links[bearer_id]) { 234 if (!n_ptr->links[bearer_id]) {
266 n_ptr->links[bearer_id] = l_ptr; 235 n_ptr->links[bearer_id] = l_ptr;
267 tipc_net.zones[tipc_zone(l_ptr->addr)]->links++; 236 tipc_net.links++;
268 n_ptr->link_cnt++; 237 n_ptr->link_cnt++;
269 return n_ptr; 238 return n_ptr;
270 } 239 }
@@ -278,7 +247,7 @@ struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
278void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr) 247void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr)
279{ 248{
280 n_ptr->links[l_ptr->b_ptr->identity] = NULL; 249 n_ptr->links[l_ptr->b_ptr->identity] = NULL;
281 tipc_net.zones[tipc_zone(l_ptr->addr)]->links--; 250 tipc_net.links--;
282 n_ptr->link_cnt--; 251 n_ptr->link_cnt--;
283} 252}
284 253
@@ -330,48 +299,16 @@ void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr)
330 299
331static void node_established_contact(struct tipc_node *n_ptr) 300static void node_established_contact(struct tipc_node *n_ptr)
332{ 301{
333 struct cluster *c_ptr; 302 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
334
335 dbg("node_established_contact:-> %x\n", n_ptr->addr);
336 if (!tipc_node_has_active_routes(n_ptr) && in_own_cluster(n_ptr->addr)) {
337 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
338 }
339 303
340 /* Syncronize broadcast acks */ 304 /* Syncronize broadcast acks */
341 n_ptr->bclink.acked = tipc_bclink_get_last_sent(); 305 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
342 306
343 if (is_slave(tipc_own_addr))
344 return;
345 if (!in_own_cluster(n_ptr->addr)) {
346 /* Usage case 1 (see above) */
347 c_ptr = tipc_cltr_find(tipc_own_addr);
348 if (!c_ptr)
349 c_ptr = tipc_cltr_create(tipc_own_addr);
350 if (c_ptr)
351 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1,
352 tipc_max_nodes);
353 return;
354 }
355
356 c_ptr = n_ptr->owner;
357 if (is_slave(n_ptr->addr)) {
358 /* Usage case 2 (see above) */
359 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);
360 tipc_cltr_send_local_routes(c_ptr, n_ptr->addr);
361 return;
362 }
363
364 if (n_ptr->bclink.supported) { 307 if (n_ptr->bclink.supported) {
365 tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr); 308 tipc_nmap_add(&tipc_bcast_nmap, n_ptr->addr);
366 if (n_ptr->addr < tipc_own_addr) 309 if (n_ptr->addr < tipc_own_addr)
367 tipc_own_tag++; 310 tipc_own_tag++;
368 } 311 }
369
370 /* Case 3 (see above) */
371 tipc_net_send_external_routes(n_ptr->addr);
372 tipc_cltr_send_slave_routes(c_ptr, n_ptr->addr);
373 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,
374 tipc_highest_allowed_slave);
375} 312}
376 313
377static void node_cleanup_finished(unsigned long node_addr) 314static void node_cleanup_finished(unsigned long node_addr)
@@ -390,7 +327,6 @@ static void node_cleanup_finished(unsigned long node_addr)
390 327
391static void node_lost_contact(struct tipc_node *n_ptr) 328static void node_lost_contact(struct tipc_node *n_ptr)
392{ 329{
393 struct cluster *c_ptr;
394 struct tipc_node_subscr *ns, *tns; 330 struct tipc_node_subscr *ns, *tns;
395 char addr_string[16]; 331 char addr_string[16];
396 u32 i; 332 u32 i;
@@ -398,7 +334,7 @@ static void node_lost_contact(struct tipc_node *n_ptr)
398 /* Clean up broadcast reception remains */ 334 /* Clean up broadcast reception remains */
399 n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0; 335 n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;
400 while (n_ptr->bclink.deferred_head) { 336 while (n_ptr->bclink.deferred_head) {
401 struct sk_buff* buf = n_ptr->bclink.deferred_head; 337 struct sk_buff *buf = n_ptr->bclink.deferred_head;
402 n_ptr->bclink.deferred_head = buf->next; 338 n_ptr->bclink.deferred_head = buf->next;
403 buf_discard(buf); 339 buf_discard(buf);
404 } 340 }
@@ -406,41 +342,14 @@ static void node_lost_contact(struct tipc_node *n_ptr)
406 buf_discard(n_ptr->bclink.defragm); 342 buf_discard(n_ptr->bclink.defragm);
407 n_ptr->bclink.defragm = NULL; 343 n_ptr->bclink.defragm = NULL;
408 } 344 }
409 if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {
410 tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
411 }
412 345
413 /* Update routing tables */ 346 if (n_ptr->bclink.supported) {
414 if (is_slave(tipc_own_addr)) { 347 tipc_bclink_acknowledge(n_ptr,
415 tipc_net_remove_as_router(n_ptr->addr); 348 mod(n_ptr->bclink.acked + 10000));
416 } else { 349 tipc_nmap_remove(&tipc_bcast_nmap, n_ptr->addr);
417 if (!in_own_cluster(n_ptr->addr)) { 350 if (n_ptr->addr < tipc_own_addr)
418 /* Case 4 (see above) */ 351 tipc_own_tag--;
419 c_ptr = tipc_cltr_find(tipc_own_addr);
420 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
421 tipc_max_nodes);
422 } else {
423 /* Case 5 (see above) */
424 c_ptr = tipc_cltr_find(n_ptr->addr);
425 if (is_slave(n_ptr->addr)) {
426 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
427 tipc_max_nodes);
428 } else {
429 if (n_ptr->bclink.supported) {
430 tipc_nmap_remove(&tipc_cltr_bcast_nodes,
431 n_ptr->addr);
432 if (n_ptr->addr < tipc_own_addr)
433 tipc_own_tag--;
434 }
435 tipc_net_remove_as_router(n_ptr->addr);
436 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr,
437 LOWEST_SLAVE,
438 tipc_highest_allowed_slave);
439 }
440 }
441 } 352 }
442 if (tipc_node_has_active_routes(n_ptr))
443 return;
444 353
445 info("Lost contact with %s\n", 354 info("Lost contact with %s\n",
446 tipc_addr_string_fill(addr_string, n_ptr->addr)); 355 tipc_addr_string_fill(addr_string, n_ptr->addr));
@@ -469,125 +378,6 @@ static void node_lost_contact(struct tipc_node *n_ptr)
469 tipc_k_signal((Handler)node_cleanup_finished, n_ptr->addr); 378 tipc_k_signal((Handler)node_cleanup_finished, n_ptr->addr);
470} 379}
471 380
472/**
473 * tipc_node_select_next_hop - find the next-hop node for a message
474 *
475 * Called by when cluster local lookup has failed.
476 */
477
478struct tipc_node *tipc_node_select_next_hop(u32 addr, u32 selector)
479{
480 struct tipc_node *n_ptr;
481 u32 router_addr;
482
483 if (!tipc_addr_domain_valid(addr))
484 return NULL;
485
486 /* Look for direct link to destination processsor */
487 n_ptr = tipc_node_find(addr);
488 if (n_ptr && tipc_node_has_active_links(n_ptr))
489 return n_ptr;
490
491 /* Cluster local system nodes *must* have direct links */
492 if (!is_slave(addr) && in_own_cluster(addr))
493 return NULL;
494
495 /* Look for cluster local router with direct link to node */
496 router_addr = tipc_node_select_router(n_ptr, selector);
497 if (router_addr)
498 return tipc_node_select(router_addr, selector);
499
500 /* Slave nodes can only be accessed within own cluster via a
501 known router with direct link -- if no router was found,give up */
502 if (is_slave(addr))
503 return NULL;
504
505 /* Inter zone/cluster -- find any direct link to remote cluster */
506 addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
507 n_ptr = tipc_net_select_remote_node(addr, selector);
508 if (n_ptr && tipc_node_has_active_links(n_ptr))
509 return n_ptr;
510
511 /* Last resort -- look for any router to anywhere in remote zone */
512 router_addr = tipc_net_select_router(addr, selector);
513 if (router_addr)
514 return tipc_node_select(router_addr, selector);
515
516 return NULL;
517}
518
519/**
520 * tipc_node_select_router - select router to reach specified node
521 *
522 * Uses a deterministic and fair algorithm for selecting router node.
523 */
524
525u32 tipc_node_select_router(struct tipc_node *n_ptr, u32 ref)
526{
527 u32 ulim;
528 u32 mask;
529 u32 start;
530 u32 r;
531
532 if (!n_ptr)
533 return 0;
534
535 if (n_ptr->last_router < 0)
536 return 0;
537 ulim = ((n_ptr->last_router + 1) * 32) - 1;
538
539 /* Start entry must be random */
540 mask = tipc_max_nodes;
541 while (mask > ulim)
542 mask >>= 1;
543 start = ref & mask;
544 r = start;
545
546 /* Lookup upwards with wrap-around */
547 do {
548 if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
549 break;
550 } while (++r <= ulim);
551 if (r > ulim) {
552 r = 1;
553 do {
554 if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
555 break;
556 } while (++r < start);
557 assert(r != start);
558 }
559 assert(r && (r <= ulim));
560 return tipc_addr(own_zone(), own_cluster(), r);
561}
562
563void tipc_node_add_router(struct tipc_node *n_ptr, u32 router)
564{
565 u32 r_num = tipc_node(router);
566
567 n_ptr->routers[r_num / 32] =
568 ((1 << (r_num % 32)) | n_ptr->routers[r_num / 32]);
569 n_ptr->last_router = tipc_max_nodes / 32;
570 while ((--n_ptr->last_router >= 0) &&
571 !n_ptr->routers[n_ptr->last_router]);
572}
573
574void tipc_node_remove_router(struct tipc_node *n_ptr, u32 router)
575{
576 u32 r_num = tipc_node(router);
577
578 if (n_ptr->last_router < 0)
579 return; /* No routes */
580
581 n_ptr->routers[r_num / 32] =
582 ((~(1 << (r_num % 32))) & (n_ptr->routers[r_num / 32]));
583 n_ptr->last_router = tipc_max_nodes / 32;
584 while ((--n_ptr->last_router >= 0) &&
585 !n_ptr->routers[n_ptr->last_router]);
586
587 if (!tipc_node_is_up(n_ptr))
588 node_lost_contact(n_ptr);
589}
590
591struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) 381struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
592{ 382{
593 u32 domain; 383 u32 domain;
@@ -595,6 +385,7 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
595 struct tipc_node *n_ptr; 385 struct tipc_node *n_ptr;
596 struct tipc_node_info node_info; 386 struct tipc_node_info node_info;
597 u32 payload_size; 387 u32 payload_size;
388 u32 n_num;
598 389
599 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) 390 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
600 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); 391 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
@@ -605,15 +396,15 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
605 " (network address)"); 396 " (network address)");
606 397
607 read_lock_bh(&tipc_net_lock); 398 read_lock_bh(&tipc_net_lock);
608 if (!tipc_nodes) { 399 if (!tipc_net.nodes) {
609 read_unlock_bh(&tipc_net_lock); 400 read_unlock_bh(&tipc_net_lock);
610 return tipc_cfg_reply_none(); 401 return tipc_cfg_reply_none();
611 } 402 }
612 403
613 /* For now, get space for all other nodes 404 /* For now, get space for all other nodes */
614 (will need to modify this when slave nodes are supported */
615 405
616 payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1); 406 payload_size = TLV_SPACE(sizeof(node_info)) *
407 (tipc_net.highest_node - 1);
617 if (payload_size > 32768u) { 408 if (payload_size > 32768u) {
618 read_unlock_bh(&tipc_net_lock); 409 read_unlock_bh(&tipc_net_lock);
619 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED 410 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
@@ -627,8 +418,9 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
627 418
628 /* Add TLVs for all nodes in scope */ 419 /* Add TLVs for all nodes in scope */
629 420
630 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { 421 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++) {
631 if (!tipc_in_scope(domain, n_ptr->addr)) 422 n_ptr = tipc_net.nodes[n_num];
423 if (!n_ptr || !tipc_in_scope(domain, n_ptr->addr))
632 continue; 424 continue;
633 node_info.addr = htonl(n_ptr->addr); 425 node_info.addr = htonl(n_ptr->addr);
634 node_info.up = htonl(tipc_node_is_up(n_ptr)); 426 node_info.up = htonl(tipc_node_is_up(n_ptr));
@@ -647,6 +439,7 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
647 struct tipc_node *n_ptr; 439 struct tipc_node *n_ptr;
648 struct tipc_link_info link_info; 440 struct tipc_link_info link_info;
649 u32 payload_size; 441 u32 payload_size;
442 u32 n_num;
650 443
651 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) 444 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
652 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); 445 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
@@ -663,8 +456,7 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
663 456
664 /* Get space for all unicast links + multicast link */ 457 /* Get space for all unicast links + multicast link */
665 458
666 payload_size = TLV_SPACE(sizeof(link_info)) * 459 payload_size = TLV_SPACE(sizeof(link_info)) * (tipc_net.links + 1);
667 (tipc_net.zones[tipc_zone(tipc_own_addr)]->links + 1);
668 if (payload_size > 32768u) { 460 if (payload_size > 32768u) {
669 read_unlock_bh(&tipc_net_lock); 461 read_unlock_bh(&tipc_net_lock);
670 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED 462 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
@@ -685,10 +477,11 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
685 477
686 /* Add TLVs for any other links in scope */ 478 /* Add TLVs for any other links in scope */
687 479
688 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { 480 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++) {
689 u32 i; 481 u32 i;
690 482
691 if (!tipc_in_scope(domain, n_ptr->addr)) 483 n_ptr = tipc_net.nodes[n_num];
484 if (!n_ptr || !tipc_in_scope(domain, n_ptr->addr))
692 continue; 485 continue;
693 tipc_node_lock(n_ptr); 486 tipc_node_lock(n_ptr);
694 for (i = 0; i < MAX_BEARERS; i++) { 487 for (i = 0; i < MAX_BEARERS; i++) {
diff --git a/net/tipc/node.h b/net/tipc/node.h
index fff331b2d26c..206a8efa410e 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -39,14 +39,13 @@
39 39
40#include "node_subscr.h" 40#include "node_subscr.h"
41#include "addr.h" 41#include "addr.h"
42#include "cluster.h" 42#include "net.h"
43#include "bearer.h" 43#include "bearer.h"
44 44
45/** 45/**
46 * struct tipc_node - TIPC node structure 46 * struct tipc_node - TIPC node structure
47 * @addr: network address of node 47 * @addr: network address of node
48 * @lock: spinlock governing access to structure 48 * @lock: spinlock governing access to structure
49 * @owner: pointer to cluster that node belongs to
50 * @next: pointer to next node in sorted list of cluster's nodes 49 * @next: pointer to next node in sorted list of cluster's nodes
51 * @nsub: list of "node down" subscriptions monitoring node 50 * @nsub: list of "node down" subscriptions monitoring node
52 * @active_links: pointers to active links to node 51 * @active_links: pointers to active links to node
@@ -55,8 +54,6 @@
55 * @cleanup_required: non-zero if cleaning up after a prior loss of contact 54 * @cleanup_required: non-zero if cleaning up after a prior loss of contact
56 * @link_cnt: number of links to node 55 * @link_cnt: number of links to node
57 * @permit_changeover: non-zero if node has redundant links to this system 56 * @permit_changeover: non-zero if node has redundant links to this system
58 * @routers: bitmap (used for multicluster communication)
59 * @last_router: (used for multicluster communication)
60 * @bclink: broadcast-related info 57 * @bclink: broadcast-related info
61 * @supported: non-zero if node supports TIPC b'cast capability 58 * @supported: non-zero if node supports TIPC b'cast capability
62 * @acked: sequence # of last outbound b'cast message acknowledged by node 59 * @acked: sequence # of last outbound b'cast message acknowledged by node
@@ -72,7 +69,6 @@
72struct tipc_node { 69struct tipc_node {
73 u32 addr; 70 u32 addr;
74 spinlock_t lock; 71 spinlock_t lock;
75 struct cluster *owner;
76 struct tipc_node *next; 72 struct tipc_node *next;
77 struct list_head nsub; 73 struct list_head nsub;
78 struct link *active_links[2]; 74 struct link *active_links[2];
@@ -81,8 +77,6 @@ struct tipc_node {
81 int working_links; 77 int working_links;
82 int cleanup_required; 78 int cleanup_required;
83 int permit_changeover; 79 int permit_changeover;
84 u32 routers[512/32];
85 int last_router;
86 struct { 80 struct {
87 int supported; 81 int supported;
88 u32 acked; 82 u32 acked;
@@ -106,34 +100,17 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct link *l_ptr);
106void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr); 100void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr);
107int tipc_node_has_active_links(struct tipc_node *n_ptr); 101int tipc_node_has_active_links(struct tipc_node *n_ptr);
108int tipc_node_has_redundant_links(struct tipc_node *n_ptr); 102int tipc_node_has_redundant_links(struct tipc_node *n_ptr);
109u32 tipc_node_select_router(struct tipc_node *n_ptr, u32 ref);
110struct tipc_node *tipc_node_select_next_hop(u32 addr, u32 selector);
111int tipc_node_is_up(struct tipc_node *n_ptr); 103int tipc_node_is_up(struct tipc_node *n_ptr);
112void tipc_node_add_router(struct tipc_node *n_ptr, u32 router);
113void tipc_node_remove_router(struct tipc_node *n_ptr, u32 router);
114struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); 104struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space);
115struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); 105struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space);
116 106
117static inline struct tipc_node *tipc_node_find(u32 addr) 107static inline struct tipc_node *tipc_node_find(u32 addr)
118{ 108{
119 if (likely(in_own_cluster(addr))) 109 if (likely(in_own_cluster(addr)))
120 return tipc_local_nodes[tipc_node(addr)]; 110 return tipc_net.nodes[tipc_node(addr)];
121 else if (tipc_addr_domain_valid(addr)) {
122 struct cluster *c_ptr = tipc_cltr_find(addr);
123
124 if (c_ptr)
125 return c_ptr->nodes[tipc_node(addr)];
126 }
127 return NULL; 111 return NULL;
128} 112}
129 113
130static inline struct tipc_node *tipc_node_select(u32 addr, u32 selector)
131{
132 if (likely(in_own_cluster(addr)))
133 return tipc_local_nodes[tipc_node(addr)];
134 return tipc_node_select_next_hop(addr, selector);
135}
136
137static inline void tipc_node_lock(struct tipc_node *n_ptr) 114static inline void tipc_node_lock(struct tipc_node *n_ptr)
138{ 115{
139 spin_lock_bh(&n_ptr->lock); 116 spin_lock_bh(&n_ptr->lock);
diff --git a/net/tipc/node_subscr.c b/net/tipc/node_subscr.c
index 19194d476a9e..018a55332d91 100644
--- a/net/tipc/node_subscr.c
+++ b/net/tipc/node_subscr.c
@@ -35,10 +35,8 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "node_subscr.h" 38#include "node_subscr.h"
40#include "node.h" 39#include "node.h"
41#include "addr.h"
42 40
43/** 41/**
44 * tipc_nodesub_subscribe - create "node down" subscription for specified node 42 * tipc_nodesub_subscribe - create "node down" subscription for specified node
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 82092eaa1536..067bab2a0b98 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -36,15 +36,8 @@
36 36
37#include "core.h" 37#include "core.h"
38#include "config.h" 38#include "config.h"
39#include "dbg.h"
40#include "port.h" 39#include "port.h"
41#include "addr.h"
42#include "link.h"
43#include "node.h"
44#include "name_table.h" 40#include "name_table.h"
45#include "user_reg.h"
46#include "msg.h"
47#include "bcast.h"
48 41
49/* Connection management: */ 42/* Connection management: */
50#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ 43#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
@@ -53,16 +46,16 @@
53 46
54#define MAX_REJECT_SIZE 1024 47#define MAX_REJECT_SIZE 1024
55 48
56static struct sk_buff *msg_queue_head = NULL; 49static struct sk_buff *msg_queue_head;
57static struct sk_buff *msg_queue_tail = NULL; 50static struct sk_buff *msg_queue_tail;
58 51
59DEFINE_SPINLOCK(tipc_port_list_lock); 52DEFINE_SPINLOCK(tipc_port_list_lock);
60static DEFINE_SPINLOCK(queue_lock); 53static DEFINE_SPINLOCK(queue_lock);
61 54
62static LIST_HEAD(ports); 55static LIST_HEAD(ports);
63static void port_handle_node_down(unsigned long ref); 56static void port_handle_node_down(unsigned long ref);
64static struct sk_buff* port_build_self_abort_msg(struct port *,u32 err); 57static struct sk_buff *port_build_self_abort_msg(struct port *, u32 err);
65static struct sk_buff* port_build_peer_abort_msg(struct port *,u32 err); 58static struct sk_buff *port_build_peer_abort_msg(struct port *, u32 err);
66static void port_timeout(unsigned long ref); 59static void port_timeout(unsigned long ref);
67 60
68 61
@@ -94,7 +87,7 @@ static void port_incr_out_seqno(struct port *p_ptr)
94 * tipc_multicast - send a multicast message to local and remote destinations 87 * tipc_multicast - send a multicast message to local and remote destinations
95 */ 88 */
96 89
97int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, 90int tipc_multicast(u32 ref, struct tipc_name_seq const *seq,
98 u32 num_sect, struct iovec const *msg_sect) 91 u32 num_sect, struct iovec const *msg_sect)
99{ 92{
100 struct tipc_msg *hdr; 93 struct tipc_msg *hdr;
@@ -138,9 +131,8 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain,
138 } 131 }
139 } 132 }
140 res = tipc_bclink_send_msg(buf); 133 res = tipc_bclink_send_msg(buf);
141 if ((res < 0) && (dports.count != 0)) { 134 if ((res < 0) && (dports.count != 0))
142 buf_discard(ibuf); 135 buf_discard(ibuf);
143 }
144 } else { 136 } else {
145 ibuf = buf; 137 ibuf = buf;
146 } 138 }
@@ -162,7 +154,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain,
162 154
163void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) 155void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp)
164{ 156{
165 struct tipc_msg* msg; 157 struct tipc_msg *msg;
166 struct port_list dports = {0, NULL, }; 158 struct port_list dports = {0, NULL, };
167 struct port_list *item = dp; 159 struct port_list *item = dp;
168 int cnt = 0; 160 int cnt = 0;
@@ -195,13 +187,11 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp)
195 187
196 if (b == NULL) { 188 if (b == NULL) {
197 warn("Unable to deliver multicast message(s)\n"); 189 warn("Unable to deliver multicast message(s)\n");
198 msg_dbg(msg, "LOST:");
199 goto exit; 190 goto exit;
200 } 191 }
201 if ((index == 0) && (cnt != 0)) { 192 if ((index == 0) && (cnt != 0))
202 item = item->next; 193 item = item->next;
203 } 194 msg_set_destport(buf_msg(b), item->ports[index]);
204 msg_set_destport(buf_msg(b),item->ports[index]);
205 tipc_port_recv_msg(b); 195 tipc_port_recv_msg(b);
206 } 196 }
207 } 197 }
@@ -277,10 +267,7 @@ int tipc_deleteport(u32 ref)
277 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); 267 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
278 tipc_nodesub_unsubscribe(&p_ptr->subscription); 268 tipc_nodesub_unsubscribe(&p_ptr->subscription);
279 } 269 }
280 if (p_ptr->user_port) { 270 kfree(p_ptr->user_port);
281 tipc_reg_remove_port(p_ptr->user_port);
282 kfree(p_ptr->user_port);
283 }
284 271
285 spin_lock_bh(&tipc_port_list_lock); 272 spin_lock_bh(&tipc_port_list_lock);
286 list_del(&p_ptr->port_list); 273 list_del(&p_ptr->port_list);
@@ -288,7 +275,6 @@ int tipc_deleteport(u32 ref)
288 spin_unlock_bh(&tipc_port_list_lock); 275 spin_unlock_bh(&tipc_port_list_lock);
289 k_term_timer(&p_ptr->timer); 276 k_term_timer(&p_ptr->timer);
290 kfree(p_ptr); 277 kfree(p_ptr);
291 dbg("Deleted port %u\n", ref);
292 tipc_net_route_msg(buf); 278 tipc_net_route_msg(buf);
293 return 0; 279 return 0;
294} 280}
@@ -374,7 +360,6 @@ static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode,
374 msg_set_orignode(msg, orignode); 360 msg_set_orignode(msg, orignode);
375 msg_set_transp_seqno(msg, seqno); 361 msg_set_transp_seqno(msg, seqno);
376 msg_set_msgcnt(msg, ack); 362 msg_set_msgcnt(msg, ack);
377 msg_dbg(msg, "PORT>SEND>:");
378 } 363 }
379 return buf; 364 return buf;
380} 365}
@@ -392,7 +377,6 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err)
392 data_sz = MAX_REJECT_SIZE; 377 data_sz = MAX_REJECT_SIZE;
393 if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) 378 if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE))
394 imp++; 379 imp++;
395 msg_dbg(msg, "port->rej: ");
396 380
397 /* discard rejected message if it shouldn't be returned to sender */ 381 /* discard rejected message if it shouldn't be returned to sender */
398 if (msg_errcode(msg) || msg_dest_droppable(msg)) { 382 if (msg_errcode(msg) || msg_dest_droppable(msg)) {
@@ -498,7 +482,7 @@ static void port_timeout(unsigned long ref)
498static void port_handle_node_down(unsigned long ref) 482static void port_handle_node_down(unsigned long ref)
499{ 483{
500 struct port *p_ptr = tipc_port_lock(ref); 484 struct port *p_ptr = tipc_port_lock(ref);
501 struct sk_buff* buf = NULL; 485 struct sk_buff *buf = NULL;
502 486
503 if (!p_ptr) 487 if (!p_ptr)
504 return; 488 return;
@@ -555,8 +539,6 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf)
555 struct sk_buff *r_buf = NULL; 539 struct sk_buff *r_buf = NULL;
556 struct sk_buff *abort_buf = NULL; 540 struct sk_buff *abort_buf = NULL;
557 541
558 msg_dbg(msg, "PORT<RECV<:");
559
560 if (!p_ptr) { 542 if (!p_ptr) {
561 err = TIPC_ERR_NO_PORT; 543 err = TIPC_ERR_NO_PORT;
562 } else if (p_ptr->publ.connected) { 544 } else if (p_ptr->publ.connected) {
@@ -636,8 +618,7 @@ static void port_print(struct port *p_ptr, struct print_buf *buf, int full_id)
636 tipc_printf(buf, " via {%u,%u}", 618 tipc_printf(buf, " via {%u,%u}",
637 p_ptr->publ.conn_type, 619 p_ptr->publ.conn_type,
638 p_ptr->publ.conn_instance); 620 p_ptr->publ.conn_instance);
639 } 621 } else if (p_ptr->publ.published) {
640 else if (p_ptr->publ.published) {
641 tipc_printf(buf, " bound to"); 622 tipc_printf(buf, " bound to");
642 list_for_each_entry(publ, &p_ptr->publications, pport_list) { 623 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
643 if (publ->lower == publ->upper) 624 if (publ->lower == publ->upper)
@@ -940,12 +921,10 @@ void tipc_acknowledge(u32 ref, u32 ack)
940} 921}
941 922
942/* 923/*
943 * tipc_createport(): user level call. Will add port to 924 * tipc_createport(): user level call.
944 * registry if non-zero user_ref.
945 */ 925 */
946 926
947int tipc_createport(u32 user_ref, 927int tipc_createport(void *usr_handle,
948 void *usr_handle,
949 unsigned int importance, 928 unsigned int importance,
950 tipc_msg_err_event error_cb, 929 tipc_msg_err_event error_cb,
951 tipc_named_msg_err_event named_error_cb, 930 tipc_named_msg_err_event named_error_cb,
@@ -972,7 +951,6 @@ int tipc_createport(u32 user_ref,
972 } 951 }
973 952
974 p_ptr->user_port = up_ptr; 953 p_ptr->user_port = up_ptr;
975 up_ptr->user_ref = user_ref;
976 up_ptr->usr_handle = usr_handle; 954 up_ptr->usr_handle = usr_handle;
977 up_ptr->ref = p_ptr->publ.ref; 955 up_ptr->ref = p_ptr->publ.ref;
978 up_ptr->err_cb = error_cb; 956 up_ptr->err_cb = error_cb;
@@ -982,20 +960,11 @@ int tipc_createport(u32 user_ref,
982 up_ptr->named_msg_cb = named_msg_cb; 960 up_ptr->named_msg_cb = named_msg_cb;
983 up_ptr->conn_msg_cb = conn_msg_cb; 961 up_ptr->conn_msg_cb = conn_msg_cb;
984 up_ptr->continue_event_cb = continue_event_cb; 962 up_ptr->continue_event_cb = continue_event_cb;
985 INIT_LIST_HEAD(&up_ptr->uport_list);
986 tipc_reg_add_port(up_ptr);
987 *portref = p_ptr->publ.ref; 963 *portref = p_ptr->publ.ref;
988 tipc_port_unlock(p_ptr); 964 tipc_port_unlock(p_ptr);
989 return 0; 965 return 0;
990} 966}
991 967
992int tipc_ownidentity(u32 ref, struct tipc_portid *id)
993{
994 id->ref = ref;
995 id->node = tipc_own_addr;
996 return 0;
997}
998
999int tipc_portimportance(u32 ref, unsigned int *importance) 968int tipc_portimportance(u32 ref, unsigned int *importance)
1000{ 969{
1001 struct port *p_ptr; 970 struct port *p_ptr;
@@ -1035,9 +1004,6 @@ int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
1035 if (!p_ptr) 1004 if (!p_ptr)
1036 return -EINVAL; 1005 return -EINVAL;
1037 1006
1038 dbg("tipc_publ %u, p_ptr = %x, conn = %x, scope = %x, "
1039 "lower = %u, upper = %u\n",
1040 ref, p_ptr, p_ptr->publ.connected, scope, seq->lower, seq->upper);
1041 if (p_ptr->publ.connected) 1007 if (p_ptr->publ.connected)
1042 goto exit; 1008 goto exit;
1043 if (seq->lower > seq->upper) 1009 if (seq->lower > seq->upper)
@@ -1123,17 +1089,14 @@ int tipc_connect2port(u32 ref, struct tipc_portid const *peer)
1123 msg_set_origport(msg, p_ptr->publ.ref); 1089 msg_set_origport(msg, p_ptr->publ.ref);
1124 msg_set_transp_seqno(msg, 42); 1090 msg_set_transp_seqno(msg, 42);
1125 msg_set_type(msg, TIPC_CONN_MSG); 1091 msg_set_type(msg, TIPC_CONN_MSG);
1126 if (!may_route(peer->node)) 1092 msg_set_hdr_sz(msg, SHORT_H_SIZE);
1127 msg_set_hdr_sz(msg, SHORT_H_SIZE);
1128 else
1129 msg_set_hdr_sz(msg, LONG_H_SIZE);
1130 1093
1131 p_ptr->probing_interval = PROBING_INTERVAL; 1094 p_ptr->probing_interval = PROBING_INTERVAL;
1132 p_ptr->probing_state = CONFIRMED; 1095 p_ptr->probing_state = CONFIRMED;
1133 p_ptr->publ.connected = 1; 1096 p_ptr->publ.connected = 1;
1134 k_start_timer(&p_ptr->timer, p_ptr->probing_interval); 1097 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
1135 1098
1136 tipc_nodesub_subscribe(&p_ptr->subscription,peer->node, 1099 tipc_nodesub_subscribe(&p_ptr->subscription, peer->node,
1137 (void *)(unsigned long)ref, 1100 (void *)(unsigned long)ref,
1138 (net_ev_handler)port_handle_node_down); 1101 (net_ev_handler)port_handle_node_down);
1139 res = 0; 1102 res = 0;
@@ -1271,16 +1234,11 @@ int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect)
1271} 1234}
1272 1235
1273/** 1236/**
1274 * tipc_forward2name - forward message sections to port name 1237 * tipc_send2name - send message sections to port name
1275 */ 1238 */
1276 1239
1277static int tipc_forward2name(u32 ref, 1240int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
1278 struct tipc_name const *name, 1241 unsigned int num_sect, struct iovec const *msg_sect)
1279 u32 domain,
1280 u32 num_sect,
1281 struct iovec const *msg_sect,
1282 struct tipc_portid const *orig,
1283 unsigned int importance)
1284{ 1242{
1285 struct port *p_ptr; 1243 struct port *p_ptr;
1286 struct tipc_msg *msg; 1244 struct tipc_msg *msg;
@@ -1294,14 +1252,12 @@ static int tipc_forward2name(u32 ref,
1294 1252
1295 msg = &p_ptr->publ.phdr; 1253 msg = &p_ptr->publ.phdr;
1296 msg_set_type(msg, TIPC_NAMED_MSG); 1254 msg_set_type(msg, TIPC_NAMED_MSG);
1297 msg_set_orignode(msg, orig->node); 1255 msg_set_orignode(msg, tipc_own_addr);
1298 msg_set_origport(msg, orig->ref); 1256 msg_set_origport(msg, ref);
1299 msg_set_hdr_sz(msg, LONG_H_SIZE); 1257 msg_set_hdr_sz(msg, LONG_H_SIZE);
1300 msg_set_nametype(msg, name->type); 1258 msg_set_nametype(msg, name->type);
1301 msg_set_nameinst(msg, name->instance); 1259 msg_set_nameinst(msg, name->instance);
1302 msg_set_lookup_scope(msg, tipc_addr_scope(domain)); 1260 msg_set_lookup_scope(msg, tipc_addr_scope(domain));
1303 if (importance <= TIPC_CRITICAL_IMPORTANCE)
1304 msg_set_importance(msg,importance);
1305 destport = tipc_nametbl_translate(name->type, name->instance, &destnode); 1261 destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
1306 msg_set_destnode(msg, destnode); 1262 msg_set_destnode(msg, destnode);
1307 msg_set_destport(msg, destport); 1263 msg_set_destport(msg, destport);
@@ -1325,33 +1281,11 @@ static int tipc_forward2name(u32 ref,
1325} 1281}
1326 1282
1327/** 1283/**
1328 * tipc_send2name - send message sections to port name 1284 * tipc_send2port - send message sections to port identity
1329 */
1330
1331int tipc_send2name(u32 ref,
1332 struct tipc_name const *name,
1333 unsigned int domain,
1334 unsigned int num_sect,
1335 struct iovec const *msg_sect)
1336{
1337 struct tipc_portid orig;
1338
1339 orig.ref = ref;
1340 orig.node = tipc_own_addr;
1341 return tipc_forward2name(ref, name, domain, num_sect, msg_sect, &orig,
1342 TIPC_PORT_IMPORTANCE);
1343}
1344
1345/**
1346 * tipc_forward2port - forward message sections to port identity
1347 */ 1285 */
1348 1286
1349static int tipc_forward2port(u32 ref, 1287int tipc_send2port(u32 ref, struct tipc_portid const *dest,
1350 struct tipc_portid const *dest, 1288 unsigned int num_sect, struct iovec const *msg_sect)
1351 unsigned int num_sect,
1352 struct iovec const *msg_sect,
1353 struct tipc_portid const *orig,
1354 unsigned int importance)
1355{ 1289{
1356 struct port *p_ptr; 1290 struct port *p_ptr;
1357 struct tipc_msg *msg; 1291 struct tipc_msg *msg;
@@ -1363,13 +1297,11 @@ static int tipc_forward2port(u32 ref,
1363 1297
1364 msg = &p_ptr->publ.phdr; 1298 msg = &p_ptr->publ.phdr;
1365 msg_set_type(msg, TIPC_DIRECT_MSG); 1299 msg_set_type(msg, TIPC_DIRECT_MSG);
1366 msg_set_orignode(msg, orig->node); 1300 msg_set_orignode(msg, tipc_own_addr);
1367 msg_set_origport(msg, orig->ref); 1301 msg_set_origport(msg, ref);
1368 msg_set_destnode(msg, dest->node); 1302 msg_set_destnode(msg, dest->node);
1369 msg_set_destport(msg, dest->ref); 1303 msg_set_destport(msg, dest->ref);
1370 msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); 1304 msg_set_hdr_sz(msg, DIR_MSG_H_SIZE);
1371 if (importance <= TIPC_CRITICAL_IMPORTANCE)
1372 msg_set_importance(msg, importance);
1373 p_ptr->sent++; 1305 p_ptr->sent++;
1374 if (dest->node == tipc_own_addr) 1306 if (dest->node == tipc_own_addr)
1375 return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); 1307 return tipc_port_recv_sections(p_ptr, num_sect, msg_sect);
@@ -1384,31 +1316,11 @@ static int tipc_forward2port(u32 ref,
1384} 1316}
1385 1317
1386/** 1318/**
1387 * tipc_send2port - send message sections to port identity 1319 * tipc_send_buf2port - send message buffer to port identity
1388 */ 1320 */
1389 1321
1390int tipc_send2port(u32 ref, 1322int tipc_send_buf2port(u32 ref, struct tipc_portid const *dest,
1391 struct tipc_portid const *dest, 1323 struct sk_buff *buf, unsigned int dsz)
1392 unsigned int num_sect,
1393 struct iovec const *msg_sect)
1394{
1395 struct tipc_portid orig;
1396
1397 orig.ref = ref;
1398 orig.node = tipc_own_addr;
1399 return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig,
1400 TIPC_PORT_IMPORTANCE);
1401}
1402
1403/**
1404 * tipc_forward_buf2port - forward message buffer to port identity
1405 */
1406static int tipc_forward_buf2port(u32 ref,
1407 struct tipc_portid const *dest,
1408 struct sk_buff *buf,
1409 unsigned int dsz,
1410 struct tipc_portid const *orig,
1411 unsigned int importance)
1412{ 1324{
1413 struct port *p_ptr; 1325 struct port *p_ptr;
1414 struct tipc_msg *msg; 1326 struct tipc_msg *msg;
@@ -1420,20 +1332,17 @@ static int tipc_forward_buf2port(u32 ref,
1420 1332
1421 msg = &p_ptr->publ.phdr; 1333 msg = &p_ptr->publ.phdr;
1422 msg_set_type(msg, TIPC_DIRECT_MSG); 1334 msg_set_type(msg, TIPC_DIRECT_MSG);
1423 msg_set_orignode(msg, orig->node); 1335 msg_set_orignode(msg, tipc_own_addr);
1424 msg_set_origport(msg, orig->ref); 1336 msg_set_origport(msg, ref);
1425 msg_set_destnode(msg, dest->node); 1337 msg_set_destnode(msg, dest->node);
1426 msg_set_destport(msg, dest->ref); 1338 msg_set_destport(msg, dest->ref);
1427 msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); 1339 msg_set_hdr_sz(msg, DIR_MSG_H_SIZE);
1428 if (importance <= TIPC_CRITICAL_IMPORTANCE)
1429 msg_set_importance(msg, importance);
1430 msg_set_size(msg, DIR_MSG_H_SIZE + dsz); 1340 msg_set_size(msg, DIR_MSG_H_SIZE + dsz);
1431 if (skb_cow(buf, DIR_MSG_H_SIZE)) 1341 if (skb_cow(buf, DIR_MSG_H_SIZE))
1432 return -ENOMEM; 1342 return -ENOMEM;
1433 1343
1434 skb_push(buf, DIR_MSG_H_SIZE); 1344 skb_push(buf, DIR_MSG_H_SIZE);
1435 skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); 1345 skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE);
1436 msg_dbg(msg, "buf2port: ");
1437 p_ptr->sent++; 1346 p_ptr->sent++;
1438 if (dest->node == tipc_own_addr) 1347 if (dest->node == tipc_own_addr)
1439 return tipc_port_recv_msg(buf); 1348 return tipc_port_recv_msg(buf);
@@ -1445,20 +1354,3 @@ static int tipc_forward_buf2port(u32 ref,
1445 return -ELINKCONG; 1354 return -ELINKCONG;
1446} 1355}
1447 1356
1448/**
1449 * tipc_send_buf2port - send message buffer to port identity
1450 */
1451
1452int tipc_send_buf2port(u32 ref,
1453 struct tipc_portid const *dest,
1454 struct sk_buff *buf,
1455 unsigned int dsz)
1456{
1457 struct tipc_portid orig;
1458
1459 orig.ref = ref;
1460 orig.node = tipc_own_addr;
1461 return tipc_forward_buf2port(ref, dest, buf, dsz, &orig,
1462 TIPC_PORT_IMPORTANCE);
1463}
1464
diff --git a/net/tipc/port.h b/net/tipc/port.h
index 73bbf442b346..8e84b989949c 100644
--- a/net/tipc/port.h
+++ b/net/tipc/port.h
@@ -37,24 +37,52 @@
37#ifndef _TIPC_PORT_H 37#ifndef _TIPC_PORT_H
38#define _TIPC_PORT_H 38#define _TIPC_PORT_H
39 39
40#include "core.h"
41#include "ref.h" 40#include "ref.h"
42#include "net.h" 41#include "net.h"
43#include "msg.h" 42#include "msg.h"
44#include "dbg.h"
45#include "node_subscr.h" 43#include "node_subscr.h"
46 44
45#define TIPC_FLOW_CONTROL_WIN 512
46
47typedef void (*tipc_msg_err_event) (void *usr_handle, u32 portref,
48 struct sk_buff **buf, unsigned char const *data,
49 unsigned int size, int reason,
50 struct tipc_portid const *attmpt_destid);
51
52typedef void (*tipc_named_msg_err_event) (void *usr_handle, u32 portref,
53 struct sk_buff **buf, unsigned char const *data,
54 unsigned int size, int reason,
55 struct tipc_name_seq const *attmpt_dest);
56
57typedef void (*tipc_conn_shutdown_event) (void *usr_handle, u32 portref,
58 struct sk_buff **buf, unsigned char const *data,
59 unsigned int size, int reason);
60
61typedef void (*tipc_msg_event) (void *usr_handle, u32 portref,
62 struct sk_buff **buf, unsigned char const *data,
63 unsigned int size, unsigned int importance,
64 struct tipc_portid const *origin);
65
66typedef void (*tipc_named_msg_event) (void *usr_handle, u32 portref,
67 struct sk_buff **buf, unsigned char const *data,
68 unsigned int size, unsigned int importance,
69 struct tipc_portid const *orig,
70 struct tipc_name_seq const *dest);
71
72typedef void (*tipc_conn_msg_event) (void *usr_handle, u32 portref,
73 struct sk_buff **buf, unsigned char const *data,
74 unsigned int size);
75
76typedef void (*tipc_continue_event) (void *usr_handle, u32 portref);
77
47/** 78/**
48 * struct user_port - TIPC user port (used with native API) 79 * struct user_port - TIPC user port (used with native API)
49 * @user_ref: id of user who created user port
50 * @usr_handle: user-specified field 80 * @usr_handle: user-specified field
51 * @ref: object reference to associated TIPC port 81 * @ref: object reference to associated TIPC port
52 * <various callback routines> 82 * <various callback routines>
53 * @uport_list: adjacent user ports in list of ports held by user
54 */ 83 */
55 84
56struct user_port { 85struct user_port {
57 u32 user_ref;
58 void *usr_handle; 86 void *usr_handle;
59 u32 ref; 87 u32 ref;
60 tipc_msg_err_event err_cb; 88 tipc_msg_err_event err_cb;
@@ -64,7 +92,34 @@ struct user_port {
64 tipc_named_msg_event named_msg_cb; 92 tipc_named_msg_event named_msg_cb;
65 tipc_conn_msg_event conn_msg_cb; 93 tipc_conn_msg_event conn_msg_cb;
66 tipc_continue_event continue_event_cb; 94 tipc_continue_event continue_event_cb;
67 struct list_head uport_list; 95};
96
97/**
98 * struct tipc_port - TIPC port info available to socket API
99 * @usr_handle: pointer to additional user-defined information about port
100 * @lock: pointer to spinlock for controlling access to port
101 * @connected: non-zero if port is currently connected to a peer port
102 * @conn_type: TIPC type used when connection was established
103 * @conn_instance: TIPC instance used when connection was established
104 * @conn_unacked: number of unacknowledged messages received from peer port
105 * @published: non-zero if port has one or more associated names
106 * @congested: non-zero if cannot send because of link or port congestion
107 * @max_pkt: maximum packet size "hint" used when building messages sent by port
108 * @ref: unique reference to port in TIPC object registry
109 * @phdr: preformatted message header used when sending messages
110 */
111struct tipc_port {
112 void *usr_handle;
113 spinlock_t *lock;
114 int connected;
115 u32 conn_type;
116 u32 conn_instance;
117 u32 conn_unacked;
118 int published;
119 u32 congested;
120 u32 max_pkt;
121 u32 ref;
122 struct tipc_msg phdr;
68}; 123};
69 124
70/** 125/**
@@ -109,11 +164,76 @@ struct port {
109extern spinlock_t tipc_port_list_lock; 164extern spinlock_t tipc_port_list_lock;
110struct port_list; 165struct port_list;
111 166
167/*
168 * TIPC port manipulation routines
169 */
170struct tipc_port *tipc_createport_raw(void *usr_handle,
171 u32 (*dispatcher)(struct tipc_port *, struct sk_buff *),
172 void (*wakeup)(struct tipc_port *), const u32 importance);
173
174int tipc_reject_msg(struct sk_buff *buf, u32 err);
175
176int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode);
177
178void tipc_acknowledge(u32 port_ref, u32 ack);
179
180int tipc_createport(void *usr_handle,
181 unsigned int importance, tipc_msg_err_event error_cb,
182 tipc_named_msg_err_event named_error_cb,
183 tipc_conn_shutdown_event conn_error_cb, tipc_msg_event msg_cb,
184 tipc_named_msg_event named_msg_cb,
185 tipc_conn_msg_event conn_msg_cb,
186 tipc_continue_event continue_event_cb, u32 *portref);
187
188int tipc_deleteport(u32 portref);
189
190int tipc_portimportance(u32 portref, unsigned int *importance);
191int tipc_set_portimportance(u32 portref, unsigned int importance);
192
193int tipc_portunreliable(u32 portref, unsigned int *isunreliable);
194int tipc_set_portunreliable(u32 portref, unsigned int isunreliable);
195
196int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable);
197int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable);
198
199int tipc_publish(u32 portref, unsigned int scope,
200 struct tipc_name_seq const *name_seq);
201int tipc_withdraw(u32 portref, unsigned int scope,
202 struct tipc_name_seq const *name_seq);
203
204int tipc_connect2port(u32 portref, struct tipc_portid const *port);
205
206int tipc_disconnect(u32 portref);
207
208int tipc_shutdown(u32 ref);
209
210
211/*
212 * The following routines require that the port be locked on entry
213 */
214int tipc_disconnect_port(struct tipc_port *tp_ptr);
215
216/*
217 * TIPC messaging routines
218 */
219int tipc_send(u32 portref, unsigned int num_sect, struct iovec const *msg_sect);
220
221int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain,
222 unsigned int num_sect, struct iovec const *msg_sect);
223
224int tipc_send2port(u32 portref, struct tipc_portid const *dest,
225 unsigned int num_sect, struct iovec const *msg_sect);
226
227int tipc_send_buf2port(u32 portref, struct tipc_portid const *dest,
228 struct sk_buff *buf, unsigned int dsz);
229
230int tipc_multicast(u32 portref, struct tipc_name_seq const *seq,
231 unsigned int section_count, struct iovec const *msg);
232
112int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr, 233int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
113 struct iovec const *msg_sect, u32 num_sect, 234 struct iovec const *msg_sect, u32 num_sect,
114 int err); 235 int err);
115struct sk_buff *tipc_port_get_ports(void); 236struct sk_buff *tipc_port_get_ports(void);
116struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space);
117void tipc_port_recv_proto_msg(struct sk_buff *buf); 237void tipc_port_recv_proto_msg(struct sk_buff *buf);
118void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp); 238void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp);
119void tipc_port_reinit(void); 239void tipc_port_reinit(void);
@@ -138,7 +258,7 @@ static inline void tipc_port_unlock(struct port *p_ptr)
138 spin_unlock_bh(p_ptr->publ.lock); 258 spin_unlock_bh(p_ptr->publ.lock);
139} 259}
140 260
141static inline struct port* tipc_port_deref(u32 ref) 261static inline struct port *tipc_port_deref(u32 ref)
142{ 262{
143 return (struct port *)tipc_ref_deref(ref); 263 return (struct port *)tipc_ref_deref(ref);
144} 264}
@@ -196,7 +316,6 @@ static inline int tipc_port_recv_msg(struct sk_buff *buf)
196 err = TIPC_ERR_NO_PORT; 316 err = TIPC_ERR_NO_PORT;
197 } 317 }
198reject: 318reject:
199 dbg("port->rejecting, err = %x..\n",err);
200 return tipc_reject_msg(buf, err); 319 return tipc_reject_msg(buf, err);
201} 320}
202 321
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index ab8ad32d8c20..83116892528b 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -89,7 +89,7 @@ struct ref_table {
89 * have a reference value of 0 (although this is unlikely). 89 * have a reference value of 0 (although this is unlikely).
90 */ 90 */
91 91
92static struct ref_table tipc_ref_table = { NULL }; 92static struct ref_table tipc_ref_table;
93 93
94static DEFINE_RWLOCK(ref_table_lock); 94static DEFINE_RWLOCK(ref_table_lock);
95 95
@@ -178,14 +178,12 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
178 next_plus_upper = entry->ref; 178 next_plus_upper = entry->ref;
179 tipc_ref_table.first_free = next_plus_upper & index_mask; 179 tipc_ref_table.first_free = next_plus_upper & index_mask;
180 ref = (next_plus_upper & ~index_mask) + index; 180 ref = (next_plus_upper & ~index_mask) + index;
181 } 181 } else if (tipc_ref_table.init_point < tipc_ref_table.capacity) {
182 else if (tipc_ref_table.init_point < tipc_ref_table.capacity) {
183 index = tipc_ref_table.init_point++; 182 index = tipc_ref_table.init_point++;
184 entry = &(tipc_ref_table.entries[index]); 183 entry = &(tipc_ref_table.entries[index]);
185 spin_lock_init(&entry->lock); 184 spin_lock_init(&entry->lock);
186 ref = tipc_ref_table.start_mask + index; 185 ref = tipc_ref_table.start_mask + index;
187 } 186 } else {
188 else {
189 ref = 0; 187 ref = 0;
190 } 188 }
191 write_unlock_bh(&ref_table_lock); 189 write_unlock_bh(&ref_table_lock);
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 33217fc3d697..2b02a3a80313 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -34,25 +34,13 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <linux/module.h>
38#include <linux/types.h>
39#include <linux/net.h>
40#include <linux/socket.h>
41#include <linux/errno.h>
42#include <linux/mm.h>
43#include <linux/poll.h>
44#include <linux/fcntl.h>
45#include <linux/gfp.h>
46#include <asm/string.h>
47#include <asm/atomic.h>
48#include <net/sock.h> 37#include <net/sock.h>
49 38
50#include <linux/tipc.h> 39#include <linux/tipc.h>
51#include <linux/tipc_config.h> 40#include <linux/tipc_config.h>
52#include <net/tipc/tipc_msg.h>
53#include <net/tipc/tipc_port.h>
54 41
55#include "core.h" 42#include "core.h"
43#include "port.h"
56 44
57#define SS_LISTENING -1 /* socket is listening */ 45#define SS_LISTENING -1 /* socket is listening */
58#define SS_READY -2 /* socket is connectionless */ 46#define SS_READY -2 /* socket is connectionless */
@@ -80,7 +68,7 @@ static const struct proto_ops msg_ops;
80 68
81static struct proto tipc_proto; 69static struct proto tipc_proto;
82 70
83static int sockets_enabled = 0; 71static int sockets_enabled;
84 72
85static atomic_t tipc_queue_size = ATOMIC_INIT(0); 73static atomic_t tipc_queue_size = ATOMIC_INIT(0);
86 74
@@ -387,7 +375,7 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
387 * 375 *
388 * NOTE: This routine doesn't need to take the socket lock since it only 376 * NOTE: This routine doesn't need to take the socket lock since it only
389 * accesses socket information that is unchanging (or which changes in 377 * accesses socket information that is unchanging (or which changes in
390 * a completely predictable manner). 378 * a completely predictable manner).
391 */ 379 */
392 380
393static int get_name(struct socket *sock, struct sockaddr *uaddr, 381static int get_name(struct socket *sock, struct sockaddr *uaddr,
@@ -396,6 +384,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
396 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 384 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
397 struct tipc_sock *tsock = tipc_sk(sock->sk); 385 struct tipc_sock *tsock = tipc_sk(sock->sk);
398 386
387 memset(addr, 0, sizeof(*addr));
399 if (peer) { 388 if (peer) {
400 if ((sock->state != SS_CONNECTED) && 389 if ((sock->state != SS_CONNECTED) &&
401 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 390 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
@@ -403,7 +392,8 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
403 addr->addr.id.ref = tsock->peer_name.ref; 392 addr->addr.id.ref = tsock->peer_name.ref;
404 addr->addr.id.node = tsock->peer_name.node; 393 addr->addr.id.node = tsock->peer_name.node;
405 } else { 394 } else {
406 tipc_ownidentity(tsock->p->ref, &addr->addr.id); 395 addr->addr.id.ref = tsock->p->ref;
396 addr->addr.id.node = tipc_own_addr;
407 } 397 }
408 398
409 *uaddr_len = sizeof(*addr); 399 *uaddr_len = sizeof(*addr);
@@ -573,37 +563,35 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
573 563
574 do { 564 do {
575 if (dest->addrtype == TIPC_ADDR_NAME) { 565 if (dest->addrtype == TIPC_ADDR_NAME) {
576 if ((res = dest_name_check(dest, m))) 566 res = dest_name_check(dest, m);
567 if (res)
577 break; 568 break;
578 res = tipc_send2name(tport->ref, 569 res = tipc_send2name(tport->ref,
579 &dest->addr.name.name, 570 &dest->addr.name.name,
580 dest->addr.name.domain, 571 dest->addr.name.domain,
581 m->msg_iovlen, 572 m->msg_iovlen,
582 m->msg_iov); 573 m->msg_iov);
583 } 574 } else if (dest->addrtype == TIPC_ADDR_ID) {
584 else if (dest->addrtype == TIPC_ADDR_ID) {
585 res = tipc_send2port(tport->ref, 575 res = tipc_send2port(tport->ref,
586 &dest->addr.id, 576 &dest->addr.id,
587 m->msg_iovlen, 577 m->msg_iovlen,
588 m->msg_iov); 578 m->msg_iov);
589 } 579 } else if (dest->addrtype == TIPC_ADDR_MCAST) {
590 else if (dest->addrtype == TIPC_ADDR_MCAST) {
591 if (needs_conn) { 580 if (needs_conn) {
592 res = -EOPNOTSUPP; 581 res = -EOPNOTSUPP;
593 break; 582 break;
594 } 583 }
595 if ((res = dest_name_check(dest, m))) 584 res = dest_name_check(dest, m);
585 if (res)
596 break; 586 break;
597 res = tipc_multicast(tport->ref, 587 res = tipc_multicast(tport->ref,
598 &dest->addr.nameseq, 588 &dest->addr.nameseq,
599 0,
600 m->msg_iovlen, 589 m->msg_iovlen,
601 m->msg_iov); 590 m->msg_iov);
602 } 591 }
603 if (likely(res != -ELINKCONG)) { 592 if (likely(res != -ELINKCONG)) {
604 if (needs_conn && (res >= 0)) { 593 if (needs_conn && (res >= 0))
605 sock->state = SS_CONNECTING; 594 sock->state = SS_CONNECTING;
606 }
607 break; 595 break;
608 } 596 }
609 if (m->msg_flags & MSG_DONTWAIT) { 597 if (m->msg_flags & MSG_DONTWAIT) {
@@ -662,9 +650,8 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
662 } 650 }
663 651
664 res = tipc_send(tport->ref, m->msg_iovlen, m->msg_iov); 652 res = tipc_send(tport->ref, m->msg_iovlen, m->msg_iov);
665 if (likely(res != -ELINKCONG)) { 653 if (likely(res != -ELINKCONG))
666 break; 654 break;
667 }
668 if (m->msg_flags & MSG_DONTWAIT) { 655 if (m->msg_flags & MSG_DONTWAIT) {
669 res = -EWOULDBLOCK; 656 res = -EWOULDBLOCK;
670 break; 657 break;
@@ -763,7 +750,8 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
763 bytes_to_send = curr_left; 750 bytes_to_send = curr_left;
764 my_iov.iov_base = curr_start; 751 my_iov.iov_base = curr_start;
765 my_iov.iov_len = bytes_to_send; 752 my_iov.iov_len = bytes_to_send;
766 if ((res = send_packet(NULL, sock, &my_msg, 0)) < 0) { 753 res = send_packet(NULL, sock, &my_msg, 0);
754 if (res < 0) {
767 if (bytes_sent) 755 if (bytes_sent)
768 res = bytes_sent; 756 res = bytes_sent;
769 goto exit; 757 goto exit;
@@ -823,8 +811,8 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
823 addr->addrtype = TIPC_ADDR_ID; 811 addr->addrtype = TIPC_ADDR_ID;
824 addr->addr.id.ref = msg_origport(msg); 812 addr->addr.id.ref = msg_origport(msg);
825 addr->addr.id.node = msg_orignode(msg); 813 addr->addr.id.node = msg_orignode(msg);
826 addr->addr.name.domain = 0; /* could leave uninitialized */ 814 addr->addr.name.domain = 0; /* could leave uninitialized */
827 addr->scope = 0; /* could leave uninitialized */ 815 addr->scope = 0; /* could leave uninitialized */
828 m->msg_namelen = sizeof(struct sockaddr_tipc); 816 m->msg_namelen = sizeof(struct sockaddr_tipc);
829 } 817 }
830} 818}
@@ -858,12 +846,15 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
858 if (unlikely(err)) { 846 if (unlikely(err)) {
859 anc_data[0] = err; 847 anc_data[0] = err;
860 anc_data[1] = msg_data_sz(msg); 848 anc_data[1] = msg_data_sz(msg);
861 if ((res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data))) 849 res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data);
862 return res; 850 if (res)
863 if (anc_data[1] &&
864 (res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1],
865 msg_data(msg))))
866 return res; 851 return res;
852 if (anc_data[1]) {
853 res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1],
854 msg_data(msg));
855 if (res)
856 return res;
857 }
867 } 858 }
868 859
869 /* Optionally capture message destination object */ 860 /* Optionally capture message destination object */
@@ -891,9 +882,11 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
891 default: 882 default:
892 has_name = 0; 883 has_name = 0;
893 } 884 }
894 if (has_name && 885 if (has_name) {
895 (res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data))) 886 res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data);
896 return res; 887 if (res)
888 return res;
889 }
897 890
898 return 0; 891 return 0;
899} 892}
@@ -1226,42 +1219,25 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1226 */ 1219 */
1227 1220
1228 if (sock->state == SS_READY) { 1221 if (sock->state == SS_READY) {
1229 if (msg_connected(msg)) { 1222 if (msg_connected(msg))
1230 msg_dbg(msg, "dispatch filter 1\n");
1231 return TIPC_ERR_NO_PORT; 1223 return TIPC_ERR_NO_PORT;
1232 }
1233 } else { 1224 } else {
1234 if (msg_mcast(msg)) { 1225 if (msg_mcast(msg))
1235 msg_dbg(msg, "dispatch filter 2\n");
1236 return TIPC_ERR_NO_PORT; 1226 return TIPC_ERR_NO_PORT;
1237 }
1238 if (sock->state == SS_CONNECTED) { 1227 if (sock->state == SS_CONNECTED) {
1239 if (!msg_connected(msg)) { 1228 if (!msg_connected(msg))
1240 msg_dbg(msg, "dispatch filter 3\n");
1241 return TIPC_ERR_NO_PORT; 1229 return TIPC_ERR_NO_PORT;
1242 } 1230 } else if (sock->state == SS_CONNECTING) {
1243 } 1231 if (!msg_connected(msg) && (msg_errcode(msg) == 0))
1244 else if (sock->state == SS_CONNECTING) {
1245 if (!msg_connected(msg) && (msg_errcode(msg) == 0)) {
1246 msg_dbg(msg, "dispatch filter 4\n");
1247 return TIPC_ERR_NO_PORT; 1232 return TIPC_ERR_NO_PORT;
1248 } 1233 } else if (sock->state == SS_LISTENING) {
1249 } 1234 if (msg_connected(msg) || msg_errcode(msg))
1250 else if (sock->state == SS_LISTENING) {
1251 if (msg_connected(msg) || msg_errcode(msg)) {
1252 msg_dbg(msg, "dispatch filter 5\n");
1253 return TIPC_ERR_NO_PORT; 1235 return TIPC_ERR_NO_PORT;
1254 } 1236 } else if (sock->state == SS_DISCONNECTING) {
1255 }
1256 else if (sock->state == SS_DISCONNECTING) {
1257 msg_dbg(msg, "dispatch filter 6\n");
1258 return TIPC_ERR_NO_PORT; 1237 return TIPC_ERR_NO_PORT;
1259 } 1238 } else /* (sock->state == SS_UNCONNECTED) */ {
1260 else /* (sock->state == SS_UNCONNECTED) */ { 1239 if (msg_connected(msg) || msg_errcode(msg))
1261 if (msg_connected(msg) || msg_errcode(msg)) {
1262 msg_dbg(msg, "dispatch filter 7\n");
1263 return TIPC_ERR_NO_PORT; 1240 return TIPC_ERR_NO_PORT;
1264 }
1265 } 1241 }
1266 } 1242 }
1267 1243
@@ -1280,7 +1256,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1280 1256
1281 /* Enqueue message (finally!) */ 1257 /* Enqueue message (finally!) */
1282 1258
1283 msg_dbg(msg, "<DISP<: ");
1284 TIPC_SKB_CB(buf)->handle = msg_data(msg); 1259 TIPC_SKB_CB(buf)->handle = msg_data(msg);
1285 atomic_inc(&tipc_queue_size); 1260 atomic_inc(&tipc_queue_size);
1286 __skb_queue_tail(&sk->sk_receive_queue, buf); 1261 __skb_queue_tail(&sk->sk_receive_queue, buf);
@@ -1441,9 +1416,8 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1441 m.msg_name = dest; 1416 m.msg_name = dest;
1442 m.msg_namelen = destlen; 1417 m.msg_namelen = destlen;
1443 res = send_msg(NULL, sock, &m, 0); 1418 res = send_msg(NULL, sock, &m, 0);
1444 if (res < 0) { 1419 if (res < 0)
1445 goto exit; 1420 goto exit;
1446 }
1447 1421
1448 /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ 1422 /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
1449 1423
@@ -1465,11 +1439,10 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1465 advance_rx_queue(sk); 1439 advance_rx_queue(sk);
1466 } 1440 }
1467 } else { 1441 } else {
1468 if (sock->state == SS_CONNECTED) { 1442 if (sock->state == SS_CONNECTED)
1469 res = -EISCONN; 1443 res = -EISCONN;
1470 } else { 1444 else
1471 res = -ECONNREFUSED; 1445 res = -ECONNREFUSED;
1472 }
1473 } 1446 }
1474 } else { 1447 } else {
1475 if (res == 0) 1448 if (res == 0)
@@ -1588,7 +1561,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1588 * Respond to 'SYN+' by queuing it on new socket. 1561 * Respond to 'SYN+' by queuing it on new socket.
1589 */ 1562 */
1590 1563
1591 msg_dbg(msg,"<ACC<: ");
1592 if (!msg_data_sz(msg)) { 1564 if (!msg_data_sz(msg)) {
1593 struct msghdr m = {NULL,}; 1565 struct msghdr m = {NULL,};
1594 1566
@@ -1696,7 +1668,8 @@ static int setsockopt(struct socket *sock,
1696 return -ENOPROTOOPT; 1668 return -ENOPROTOOPT;
1697 if (ol < sizeof(value)) 1669 if (ol < sizeof(value))
1698 return -EINVAL; 1670 return -EINVAL;
1699 if ((res = get_user(value, (u32 __user *)ov))) 1671 res = get_user(value, (u32 __user *)ov);
1672 if (res)
1700 return res; 1673 return res;
1701 1674
1702 lock_sock(sk); 1675 lock_sock(sk);
@@ -1754,7 +1727,8 @@ static int getsockopt(struct socket *sock,
1754 return put_user(0, ol); 1727 return put_user(0, ol);
1755 if (lvl != SOL_TIPC) 1728 if (lvl != SOL_TIPC)
1756 return -ENOPROTOOPT; 1729 return -ENOPROTOOPT;
1757 if ((res = get_user(len, ol))) 1730 res = get_user(len, ol);
1731 if (res)
1758 return res; 1732 return res;
1759 1733
1760 lock_sock(sk); 1734 lock_sock(sk);
@@ -1773,10 +1747,10 @@ static int getsockopt(struct socket *sock,
1773 value = jiffies_to_msecs(tipc_sk(sk)->conn_timeout); 1747 value = jiffies_to_msecs(tipc_sk(sk)->conn_timeout);
1774 /* no need to set "res", since already 0 at this point */ 1748 /* no need to set "res", since already 0 at this point */
1775 break; 1749 break;
1776 case TIPC_NODE_RECVQ_DEPTH: 1750 case TIPC_NODE_RECVQ_DEPTH:
1777 value = (u32)atomic_read(&tipc_queue_size); 1751 value = (u32)atomic_read(&tipc_queue_size);
1778 break; 1752 break;
1779 case TIPC_SOCK_RECVQ_DEPTH: 1753 case TIPC_SOCK_RECVQ_DEPTH:
1780 value = skb_queue_len(&sk->sk_receive_queue); 1754 value = skb_queue_len(&sk->sk_receive_queue);
1781 break; 1755 break;
1782 default: 1756 default:
@@ -1785,20 +1759,16 @@ static int getsockopt(struct socket *sock,
1785 1759
1786 release_sock(sk); 1760 release_sock(sk);
1787 1761
1788 if (res) { 1762 if (res)
1789 /* "get" failed */ 1763 return res; /* "get" failed */
1790 }
1791 else if (len < sizeof(value)) {
1792 res = -EINVAL;
1793 }
1794 else if (copy_to_user(ov, &value, sizeof(value))) {
1795 res = -EFAULT;
1796 }
1797 else {
1798 res = put_user(sizeof(value), ol);
1799 }
1800 1764
1801 return res; 1765 if (len < sizeof(value))
1766 return -EINVAL;
1767
1768 if (copy_to_user(ov, &value, sizeof(value)))
1769 return -EFAULT;
1770
1771 return put_user(sizeof(value), ol);
1802} 1772}
1803 1773
1804/** 1774/**
@@ -1806,7 +1776,7 @@ static int getsockopt(struct socket *sock,
1806 */ 1776 */
1807 1777
1808static const struct proto_ops msg_ops = { 1778static const struct proto_ops msg_ops = {
1809 .owner = THIS_MODULE, 1779 .owner = THIS_MODULE,
1810 .family = AF_TIPC, 1780 .family = AF_TIPC,
1811 .release = release, 1781 .release = release,
1812 .bind = bind, 1782 .bind = bind,
@@ -1827,7 +1797,7 @@ static const struct proto_ops msg_ops = {
1827}; 1797};
1828 1798
1829static const struct proto_ops packet_ops = { 1799static const struct proto_ops packet_ops = {
1830 .owner = THIS_MODULE, 1800 .owner = THIS_MODULE,
1831 .family = AF_TIPC, 1801 .family = AF_TIPC,
1832 .release = release, 1802 .release = release,
1833 .bind = bind, 1803 .bind = bind,
@@ -1848,7 +1818,7 @@ static const struct proto_ops packet_ops = {
1848}; 1818};
1849 1819
1850static const struct proto_ops stream_ops = { 1820static const struct proto_ops stream_ops = {
1851 .owner = THIS_MODULE, 1821 .owner = THIS_MODULE,
1852 .family = AF_TIPC, 1822 .family = AF_TIPC,
1853 .release = release, 1823 .release = release,
1854 .bind = bind, 1824 .bind = bind,
@@ -1869,7 +1839,7 @@ static const struct proto_ops stream_ops = {
1869}; 1839};
1870 1840
1871static const struct net_proto_family tipc_family_ops = { 1841static const struct net_proto_family tipc_family_ops = {
1872 .owner = THIS_MODULE, 1842 .owner = THIS_MODULE,
1873 .family = AF_TIPC, 1843 .family = AF_TIPC,
1874 .create = tipc_create 1844 .create = tipc_create
1875}; 1845};
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 33313961d010..ca04479c3d42 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -35,10 +35,8 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "name_table.h" 38#include "name_table.h"
40#include "port.h" 39#include "port.h"
41#include "ref.h"
42#include "subscr.h" 40#include "subscr.h"
43 41
44/** 42/**
@@ -66,14 +64,13 @@ struct subscriber {
66 */ 64 */
67 65
68struct top_srv { 66struct top_srv {
69 u32 user_ref;
70 u32 setup_port; 67 u32 setup_port;
71 atomic_t subscription_count; 68 atomic_t subscription_count;
72 struct list_head subscriber_list; 69 struct list_head subscriber_list;
73 spinlock_t lock; 70 spinlock_t lock;
74}; 71};
75 72
76static struct top_srv topsrv = { 0 }; 73static struct top_srv topsrv;
77 74
78/** 75/**
79 * htohl - convert value to endianness used by destination 76 * htohl - convert value to endianness used by destination
@@ -252,8 +249,6 @@ static void subscr_terminate(struct subscriber *subscriber)
252 k_cancel_timer(&sub->timer); 249 k_cancel_timer(&sub->timer);
253 k_term_timer(&sub->timer); 250 k_term_timer(&sub->timer);
254 } 251 }
255 dbg("Term: Removing sub %u,%u,%u from subscriber %x list\n",
256 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
257 subscr_del(sub); 252 subscr_del(sub);
258 } 253 }
259 254
@@ -310,8 +305,6 @@ static void subscr_cancel(struct tipc_subscr *s,
310 k_term_timer(&sub->timer); 305 k_term_timer(&sub->timer);
311 spin_lock_bh(subscriber->lock); 306 spin_lock_bh(subscriber->lock);
312 } 307 }
313 dbg("Cancel: removing sub %u,%u,%u from subscriber %x list\n",
314 sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber);
315 subscr_del(sub); 308 subscr_del(sub);
316} 309}
317 310
@@ -496,8 +489,7 @@ static void subscr_named_msg_event(void *usr_handle,
496 489
497 /* Create server port & establish connection to subscriber */ 490 /* Create server port & establish connection to subscriber */
498 491
499 tipc_createport(topsrv.user_ref, 492 tipc_createport(subscriber,
500 subscriber,
501 importance, 493 importance,
502 NULL, 494 NULL,
503 NULL, 495 NULL,
@@ -544,21 +536,14 @@ static void subscr_named_msg_event(void *usr_handle,
544int tipc_subscr_start(void) 536int tipc_subscr_start(void)
545{ 537{
546 struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV}; 538 struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV};
547 int res = -1; 539 int res;
548 540
549 memset(&topsrv, 0, sizeof (topsrv)); 541 memset(&topsrv, 0, sizeof(topsrv));
550 spin_lock_init(&topsrv.lock); 542 spin_lock_init(&topsrv.lock);
551 INIT_LIST_HEAD(&topsrv.subscriber_list); 543 INIT_LIST_HEAD(&topsrv.subscriber_list);
552 544
553 spin_lock_bh(&topsrv.lock); 545 spin_lock_bh(&topsrv.lock);
554 res = tipc_attach(&topsrv.user_ref, NULL, NULL); 546 res = tipc_createport(NULL,
555 if (res) {
556 spin_unlock_bh(&topsrv.lock);
557 return res;
558 }
559
560 res = tipc_createport(topsrv.user_ref,
561 NULL,
562 TIPC_CRITICAL_IMPORTANCE, 547 TIPC_CRITICAL_IMPORTANCE,
563 NULL, 548 NULL,
564 NULL, 549 NULL,
@@ -572,16 +557,17 @@ int tipc_subscr_start(void)
572 goto failed; 557 goto failed;
573 558
574 res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq); 559 res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq);
575 if (res) 560 if (res) {
561 tipc_deleteport(topsrv.setup_port);
562 topsrv.setup_port = 0;
576 goto failed; 563 goto failed;
564 }
577 565
578 spin_unlock_bh(&topsrv.lock); 566 spin_unlock_bh(&topsrv.lock);
579 return 0; 567 return 0;
580 568
581failed: 569failed:
582 err("Failed to create subscription service\n"); 570 err("Failed to create subscription service\n");
583 tipc_detach(topsrv.user_ref);
584 topsrv.user_ref = 0;
585 spin_unlock_bh(&topsrv.lock); 571 spin_unlock_bh(&topsrv.lock);
586 return res; 572 return res;
587} 573}
@@ -592,8 +578,10 @@ void tipc_subscr_stop(void)
592 struct subscriber *subscriber_temp; 578 struct subscriber *subscriber_temp;
593 spinlock_t *subscriber_lock; 579 spinlock_t *subscriber_lock;
594 580
595 if (topsrv.user_ref) { 581 if (topsrv.setup_port) {
596 tipc_deleteport(topsrv.setup_port); 582 tipc_deleteport(topsrv.setup_port);
583 topsrv.setup_port = 0;
584
597 list_for_each_entry_safe(subscriber, subscriber_temp, 585 list_for_each_entry_safe(subscriber, subscriber_temp,
598 &topsrv.subscriber_list, 586 &topsrv.subscriber_list,
599 subscriber_list) { 587 subscriber_list) {
@@ -602,7 +590,5 @@ void tipc_subscr_stop(void)
602 subscr_terminate(subscriber); 590 subscr_terminate(subscriber);
603 spin_unlock_bh(subscriber_lock); 591 spin_unlock_bh(subscriber_lock);
604 } 592 }
605 tipc_detach(topsrv.user_ref);
606 topsrv.user_ref = 0;
607 } 593 }
608} 594}
diff --git a/net/tipc/user_reg.c b/net/tipc/user_reg.c
deleted file mode 100644
index 506928803162..000000000000
--- a/net/tipc/user_reg.c
+++ /dev/null
@@ -1,264 +0,0 @@
1/*
2 * net/tipc/user_reg.c: TIPC user registry code
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2004-2005, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "user_reg.h"
39
40/*
41 * TIPC user registry keeps track of users of the tipc_port interface.
42 *
43 * The registry utilizes an array of "TIPC user" entries;
44 * a user's ID is the index of their associated array entry.
45 * Array entry 0 is not used, so userid 0 is not valid;
46 * TIPC sometimes uses this value to denote an anonymous user.
47 * The list of free entries is initially chained from last entry to entry 1.
48 */
49
50/**
51 * struct tipc_user - registered TIPC user info
52 * @next: index of next free registry entry (or -1 for an allocated entry)
53 * @callback: ptr to routine to call when TIPC mode changes (NULL if none)
54 * @usr_handle: user-defined value passed to callback routine
55 * @ports: list of user ports owned by the user
56 */
57
58struct tipc_user {
59 int next;
60 tipc_mode_event callback;
61 void *usr_handle;
62 struct list_head ports;
63};
64
65#define MAX_USERID 64
66#define USER_LIST_SIZE ((MAX_USERID + 1) * sizeof(struct tipc_user))
67
68static struct tipc_user *users = NULL;
69static u32 next_free_user = MAX_USERID + 1;
70static DEFINE_SPINLOCK(reg_lock);
71
72/**
73 * reg_init - create TIPC user registry (but don't activate it)
74 *
75 * If registry has been pre-initialized it is left "as is".
76 * NOTE: This routine may be called when TIPC is inactive.
77 */
78
79static int reg_init(void)
80{
81 u32 i;
82
83 spin_lock_bh(&reg_lock);
84 if (!users) {
85 users = kzalloc(USER_LIST_SIZE, GFP_ATOMIC);
86 if (users) {
87 for (i = 1; i <= MAX_USERID; i++) {
88 users[i].next = i - 1;
89 }
90 next_free_user = MAX_USERID;
91 }
92 }
93 spin_unlock_bh(&reg_lock);
94 return users ? 0 : -ENOMEM;
95}
96
97/**
98 * reg_callback - inform TIPC user about current operating mode
99 */
100
101static void reg_callback(struct tipc_user *user_ptr)
102{
103 tipc_mode_event cb;
104 void *arg;
105
106 spin_lock_bh(&reg_lock);
107 cb = user_ptr->callback;
108 arg = user_ptr->usr_handle;
109 spin_unlock_bh(&reg_lock);
110
111 if (cb)
112 cb(arg, tipc_mode, tipc_own_addr);
113}
114
115/**
116 * tipc_reg_start - activate TIPC user registry
117 */
118
119int tipc_reg_start(void)
120{
121 u32 u;
122 int res;
123
124 if ((res = reg_init()))
125 return res;
126
127 for (u = 1; u <= MAX_USERID; u++) {
128 if (users[u].callback)
129 tipc_k_signal((Handler)reg_callback,
130 (unsigned long)&users[u]);
131 }
132 return 0;
133}
134
135/**
136 * tipc_reg_stop - shut down & delete TIPC user registry
137 */
138
139void tipc_reg_stop(void)
140{
141 int id;
142
143 if (!users)
144 return;
145
146 for (id = 1; id <= MAX_USERID; id++) {
147 if (users[id].callback)
148 reg_callback(&users[id]);
149 }
150 kfree(users);
151 users = NULL;
152}
153
154/**
155 * tipc_attach - register a TIPC user
156 *
157 * NOTE: This routine may be called when TIPC is inactive.
158 */
159
160int tipc_attach(u32 *userid, tipc_mode_event cb, void *usr_handle)
161{
162 struct tipc_user *user_ptr;
163
164 if ((tipc_mode == TIPC_NOT_RUNNING) && !cb)
165 return -ENOPROTOOPT;
166 if (!users)
167 reg_init();
168
169 spin_lock_bh(&reg_lock);
170 if (!next_free_user) {
171 spin_unlock_bh(&reg_lock);
172 return -EBUSY;
173 }
174 user_ptr = &users[next_free_user];
175 *userid = next_free_user;
176 next_free_user = user_ptr->next;
177 user_ptr->next = -1;
178 spin_unlock_bh(&reg_lock);
179
180 user_ptr->callback = cb;
181 user_ptr->usr_handle = usr_handle;
182 INIT_LIST_HEAD(&user_ptr->ports);
183 atomic_inc(&tipc_user_count);
184
185 if (cb && (tipc_mode != TIPC_NOT_RUNNING))
186 tipc_k_signal((Handler)reg_callback, (unsigned long)user_ptr);
187 return 0;
188}
189
190/**
191 * tipc_detach - deregister a TIPC user
192 */
193
194void tipc_detach(u32 userid)
195{
196 struct tipc_user *user_ptr;
197 struct list_head ports_temp;
198 struct user_port *up_ptr, *temp_up_ptr;
199
200 if ((userid == 0) || (userid > MAX_USERID))
201 return;
202
203 spin_lock_bh(&reg_lock);
204 if ((!users) || (users[userid].next >= 0)) {
205 spin_unlock_bh(&reg_lock);
206 return;
207 }
208
209 user_ptr = &users[userid];
210 user_ptr->callback = NULL;
211 INIT_LIST_HEAD(&ports_temp);
212 list_splice(&user_ptr->ports, &ports_temp);
213 user_ptr->next = next_free_user;
214 next_free_user = userid;
215 spin_unlock_bh(&reg_lock);
216
217 atomic_dec(&tipc_user_count);
218
219 list_for_each_entry_safe(up_ptr, temp_up_ptr, &ports_temp, uport_list) {
220 tipc_deleteport(up_ptr->ref);
221 }
222}
223
224/**
225 * tipc_reg_add_port - register a user's driver port
226 */
227
228int tipc_reg_add_port(struct user_port *up_ptr)
229{
230 struct tipc_user *user_ptr;
231
232 if (up_ptr->user_ref == 0)
233 return 0;
234 if (up_ptr->user_ref > MAX_USERID)
235 return -EINVAL;
236 if ((tipc_mode == TIPC_NOT_RUNNING) || !users )
237 return -ENOPROTOOPT;
238
239 spin_lock_bh(&reg_lock);
240 user_ptr = &users[up_ptr->user_ref];
241 list_add(&up_ptr->uport_list, &user_ptr->ports);
242 spin_unlock_bh(&reg_lock);
243 return 0;
244}
245
246/**
247 * tipc_reg_remove_port - deregister a user's driver port
248 */
249
250int tipc_reg_remove_port(struct user_port *up_ptr)
251{
252 if (up_ptr->user_ref == 0)
253 return 0;
254 if (up_ptr->user_ref > MAX_USERID)
255 return -EINVAL;
256 if (!users )
257 return -ENOPROTOOPT;
258
259 spin_lock_bh(&reg_lock);
260 list_del_init(&up_ptr->uport_list);
261 spin_unlock_bh(&reg_lock);
262 return 0;
263}
264
diff --git a/net/tipc/user_reg.h b/net/tipc/user_reg.h
deleted file mode 100644
index 81dc12e2882f..000000000000
--- a/net/tipc/user_reg.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * net/tipc/user_reg.h: Include file for TIPC user registry code
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _TIPC_USER_REG_H
38#define _TIPC_USER_REG_H
39
40#include "port.h"
41
42int tipc_reg_start(void);
43void tipc_reg_stop(void);
44
45int tipc_reg_add_port(struct user_port *up_ptr);
46int tipc_reg_remove_port(struct user_port *up_ptr);
47
48#endif
diff --git a/net/tipc/zone.c b/net/tipc/zone.c
deleted file mode 100644
index 83f8b5e91fc8..000000000000
--- a/net/tipc/zone.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/*
2 * net/tipc/zone.c: TIPC zone management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "zone.h"
39#include "net.h"
40#include "addr.h"
41#include "node_subscr.h"
42#include "cluster.h"
43#include "node.h"
44
45struct _zone *tipc_zone_create(u32 addr)
46{
47 struct _zone *z_ptr;
48 u32 z_num;
49
50 if (!tipc_addr_domain_valid(addr)) {
51 err("Zone creation failed, invalid domain 0x%x\n", addr);
52 return NULL;
53 }
54
55 z_ptr = kzalloc(sizeof(*z_ptr), GFP_ATOMIC);
56 if (!z_ptr) {
57 warn("Zone creation failed, insufficient memory\n");
58 return NULL;
59 }
60
61 z_num = tipc_zone(addr);
62 z_ptr->addr = tipc_addr(z_num, 0, 0);
63 tipc_net.zones[z_num] = z_ptr;
64 return z_ptr;
65}
66
67void tipc_zone_delete(struct _zone *z_ptr)
68{
69 u32 c_num;
70
71 if (!z_ptr)
72 return;
73 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
74 tipc_cltr_delete(z_ptr->clusters[c_num]);
75 }
76 kfree(z_ptr);
77}
78
79void tipc_zone_attach_cluster(struct _zone *z_ptr, struct cluster *c_ptr)
80{
81 u32 c_num = tipc_cluster(c_ptr->addr);
82
83 assert(c_ptr->addr);
84 assert(c_num <= tipc_max_clusters);
85 assert(z_ptr->clusters[c_num] == NULL);
86 z_ptr->clusters[c_num] = c_ptr;
87}
88
89void tipc_zone_remove_as_router(struct _zone *z_ptr, u32 router)
90{
91 u32 c_num;
92
93 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
94 if (z_ptr->clusters[c_num]) {
95 tipc_cltr_remove_as_router(z_ptr->clusters[c_num],
96 router);
97 }
98 }
99}
100
101void tipc_zone_send_external_routes(struct _zone *z_ptr, u32 dest)
102{
103 u32 c_num;
104
105 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
106 if (z_ptr->clusters[c_num]) {
107 if (in_own_cluster(z_ptr->addr))
108 continue;
109 tipc_cltr_send_ext_routes(z_ptr->clusters[c_num], dest);
110 }
111 }
112}
113
114struct tipc_node *tipc_zone_select_remote_node(struct _zone *z_ptr, u32 addr, u32 ref)
115{
116 struct cluster *c_ptr;
117 struct tipc_node *n_ptr;
118 u32 c_num;
119
120 if (!z_ptr)
121 return NULL;
122 c_ptr = z_ptr->clusters[tipc_cluster(addr)];
123 if (!c_ptr)
124 return NULL;
125 n_ptr = tipc_cltr_select_node(c_ptr, ref);
126 if (n_ptr)
127 return n_ptr;
128
129 /* Links to any other clusters within this zone ? */
130 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
131 c_ptr = z_ptr->clusters[c_num];
132 if (!c_ptr)
133 return NULL;
134 n_ptr = tipc_cltr_select_node(c_ptr, ref);
135 if (n_ptr)
136 return n_ptr;
137 }
138 return NULL;
139}
140
141u32 tipc_zone_select_router(struct _zone *z_ptr, u32 addr, u32 ref)
142{
143 struct cluster *c_ptr;
144 u32 c_num;
145 u32 router;
146
147 if (!z_ptr)
148 return 0;
149 c_ptr = z_ptr->clusters[tipc_cluster(addr)];
150 router = c_ptr ? tipc_cltr_select_router(c_ptr, ref) : 0;
151 if (router)
152 return router;
153
154 /* Links to any other clusters within the zone? */
155 for (c_num = 1; c_num <= tipc_max_clusters; c_num++) {
156 c_ptr = z_ptr->clusters[c_num];
157 router = c_ptr ? tipc_cltr_select_router(c_ptr, ref) : 0;
158 if (router)
159 return router;
160 }
161 return 0;
162}
diff --git a/net/tipc/zone.h b/net/tipc/zone.h
deleted file mode 100644
index bd1c20ce9d06..000000000000
--- a/net/tipc/zone.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * net/tipc/zone.h: Include file for TIPC zone management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005-2006, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _TIPC_ZONE_H
38#define _TIPC_ZONE_H
39
40#include "node_subscr.h"
41#include "net.h"
42
43
44/**
45 * struct _zone - TIPC zone structure
46 * @addr: network address of zone
47 * @clusters: array of pointers to all clusters within zone
48 * @links: number of (unicast) links to zone
49 */
50
51struct _zone {
52 u32 addr;
53 struct cluster *clusters[2]; /* currently limited to just 1 cluster */
54 u32 links;
55};
56
57struct tipc_node *tipc_zone_select_remote_node(struct _zone *z_ptr, u32 addr, u32 ref);
58u32 tipc_zone_select_router(struct _zone *z_ptr, u32 addr, u32 ref);
59void tipc_zone_remove_as_router(struct _zone *z_ptr, u32 router);
60void tipc_zone_send_external_routes(struct _zone *z_ptr, u32 dest);
61struct _zone *tipc_zone_create(u32 addr);
62void tipc_zone_delete(struct _zone *z_ptr);
63void tipc_zone_attach_cluster(struct _zone *z_ptr, struct cluster *c_ptr);
64
65static inline struct _zone *tipc_zone_find(u32 addr)
66{
67 return tipc_net.zones[tipc_zone(addr)];
68}
69
70#endif