aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/tipc/Makefile2
-rw-r--r--net/tipc/config.c2
-rw-r--r--net/tipc/core.c3
-rw-r--r--net/tipc/port.c11
-rw-r--r--net/tipc/port.h6
-rw-r--r--net/tipc/subscr.c6
-rw-r--r--net/tipc/user_reg.c218
-rw-r--r--net/tipc/user_reg.h51
8 files changed, 7 insertions, 292 deletions
diff --git a/net/tipc/Makefile b/net/tipc/Makefile
index 849d819bfc74..d41cd110fe7d 100644
--- a/net/tipc/Makefile
+++ b/net/tipc/Makefile
@@ -8,6 +8,6 @@ tipc-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 dbg.o eth_media.o 11 socket.o dbg.o eth_media.o
12 12
13# End of file 13# End of file
diff --git a/net/tipc/config.c b/net/tipc/config.c
index 322367b2618f..afa6e853c04b 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -500,7 +500,7 @@ int tipc_cfg_init(void)
500 struct tipc_name_seq seq; 500 struct tipc_name_seq seq;
501 int res; 501 int res;
502 502
503 res = tipc_createport(0, NULL, TIPC_CRITICAL_IMPORTANCE, 503 res = tipc_createport(NULL, TIPC_CRITICAL_IMPORTANCE,
504 NULL, NULL, NULL, 504 NULL, NULL, NULL,
505 NULL, cfg_named_msg_event, NULL, 505 NULL, cfg_named_msg_event, NULL,
506 NULL, &config_port_ref); 506 NULL, &config_port_ref);
diff --git a/net/tipc/core.c b/net/tipc/core.c
index b9a3ef13f7e7..a02bc490caae 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -42,7 +42,6 @@
42#include "core.h" 42#include "core.h"
43#include "ref.h" 43#include "ref.h"
44#include "net.h" 44#include "net.h"
45#include "user_reg.h"
46#include "name_table.h" 45#include "name_table.h"
47#include "subscr.h" 46#include "subscr.h"
48#include "config.h" 47#include "config.h"
@@ -144,7 +143,6 @@ static void tipc_core_stop(void)
144 tipc_handler_stop(); 143 tipc_handler_stop();
145 tipc_cfg_stop(); 144 tipc_cfg_stop();
146 tipc_subscr_stop(); 145 tipc_subscr_stop();
147 tipc_reg_stop();
148 tipc_nametbl_stop(); 146 tipc_nametbl_stop();
149 tipc_ref_table_stop(); 147 tipc_ref_table_stop();
150 tipc_socket_stop(); 148 tipc_socket_stop();
@@ -167,7 +165,6 @@ static int tipc_core_start(void)
167 165
168 if ((res = tipc_handler_start()) || 166 if ((res = tipc_handler_start()) ||
169 (res = tipc_ref_table_init(tipc_max_ports, tipc_random)) || 167 (res = tipc_ref_table_init(tipc_max_ports, tipc_random)) ||
170 (res = tipc_reg_start()) ||
171 (res = tipc_nametbl_init()) || 168 (res = tipc_nametbl_init()) ||
172 (res = tipc_k_signal((Handler)tipc_subscr_start, 0)) || 169 (res = tipc_k_signal((Handler)tipc_subscr_start, 0)) ||
173 (res = tipc_k_signal((Handler)tipc_cfg_init, 0)) || 170 (res = tipc_k_signal((Handler)tipc_cfg_init, 0)) ||
diff --git a/net/tipc/port.c b/net/tipc/port.c
index c033cb87b964..33d0b3b7175f 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -38,7 +38,6 @@
38#include "config.h" 38#include "config.h"
39#include "port.h" 39#include "port.h"
40#include "name_table.h" 40#include "name_table.h"
41#include "user_reg.h"
42 41
43/* Connection management: */ 42/* Connection management: */
44#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ 43#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
@@ -272,7 +271,6 @@ int tipc_deleteport(u32 ref)
272 tipc_nodesub_unsubscribe(&p_ptr->subscription); 271 tipc_nodesub_unsubscribe(&p_ptr->subscription);
273 } 272 }
274 if (p_ptr->user_port) { 273 if (p_ptr->user_port) {
275 tipc_reg_remove_port(p_ptr->user_port);
276 kfree(p_ptr->user_port); 274 kfree(p_ptr->user_port);
277 } 275 }
278 276
@@ -934,12 +932,10 @@ void tipc_acknowledge(u32 ref, u32 ack)
934} 932}
935 933
936/* 934/*
937 * tipc_createport(): user level call. Will add port to 935 * tipc_createport(): user level call.
938 * registry if non-zero user_ref.
939 */ 936 */
940 937
941int tipc_createport(u32 user_ref, 938int tipc_createport(void *usr_handle,
942 void *usr_handle,
943 unsigned int importance, 939 unsigned int importance,
944 tipc_msg_err_event error_cb, 940 tipc_msg_err_event error_cb,
945 tipc_named_msg_err_event named_error_cb, 941 tipc_named_msg_err_event named_error_cb,
@@ -966,7 +962,6 @@ int tipc_createport(u32 user_ref,
966 } 962 }
967 963
968 p_ptr->user_port = up_ptr; 964 p_ptr->user_port = up_ptr;
969 up_ptr->user_ref = user_ref;
970 up_ptr->usr_handle = usr_handle; 965 up_ptr->usr_handle = usr_handle;
971 up_ptr->ref = p_ptr->publ.ref; 966 up_ptr->ref = p_ptr->publ.ref;
972 up_ptr->err_cb = error_cb; 967 up_ptr->err_cb = error_cb;
@@ -976,8 +971,6 @@ int tipc_createport(u32 user_ref,
976 up_ptr->named_msg_cb = named_msg_cb; 971 up_ptr->named_msg_cb = named_msg_cb;
977 up_ptr->conn_msg_cb = conn_msg_cb; 972 up_ptr->conn_msg_cb = conn_msg_cb;
978 up_ptr->continue_event_cb = continue_event_cb; 973 up_ptr->continue_event_cb = continue_event_cb;
979 INIT_LIST_HEAD(&up_ptr->uport_list);
980 tipc_reg_add_port(up_ptr);
981 *portref = p_ptr->publ.ref; 974 *portref = p_ptr->publ.ref;
982 tipc_port_unlock(p_ptr); 975 tipc_port_unlock(p_ptr);
983 return 0; 976 return 0;
diff --git a/net/tipc/port.h b/net/tipc/port.h
index 3a807fcec2be..da607a8a2f35 100644
--- a/net/tipc/port.h
+++ b/net/tipc/port.h
@@ -77,15 +77,12 @@ typedef void (*tipc_continue_event) (void *usr_handle, u32 portref);
77 77
78/** 78/**
79 * struct user_port - TIPC user port (used with native API) 79 * struct user_port - TIPC user port (used with native API)
80 * @user_ref: id of user who created user port
81 * @usr_handle: user-specified field 80 * @usr_handle: user-specified field
82 * @ref: object reference to associated TIPC port 81 * @ref: object reference to associated TIPC port
83 * <various callback routines> 82 * <various callback routines>
84 * @uport_list: adjacent user ports in list of ports held by user
85 */ 83 */
86 84
87struct user_port { 85struct user_port {
88 u32 user_ref;
89 void *usr_handle; 86 void *usr_handle;
90 u32 ref; 87 u32 ref;
91 tipc_msg_err_event err_cb; 88 tipc_msg_err_event err_cb;
@@ -95,7 +92,6 @@ struct user_port {
95 tipc_named_msg_event named_msg_cb; 92 tipc_named_msg_event named_msg_cb;
96 tipc_conn_msg_event conn_msg_cb; 93 tipc_conn_msg_event conn_msg_cb;
97 tipc_continue_event continue_event_cb; 94 tipc_continue_event continue_event_cb;
98 struct list_head uport_list;
99}; 95};
100 96
101/** 97/**
@@ -181,7 +177,7 @@ int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode);
181 177
182void tipc_acknowledge(u32 port_ref, u32 ack); 178void tipc_acknowledge(u32 port_ref, u32 ack);
183 179
184int tipc_createport(unsigned int tipc_user, void *usr_handle, 180int tipc_createport(void *usr_handle,
185 unsigned int importance, tipc_msg_err_event error_cb, 181 unsigned int importance, tipc_msg_err_event error_cb,
186 tipc_named_msg_err_event named_error_cb, 182 tipc_named_msg_err_event named_error_cb,
187 tipc_conn_shutdown_event conn_error_cb, tipc_msg_event msg_cb, 183 tipc_conn_shutdown_event conn_error_cb, tipc_msg_event msg_cb,
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 21abf1765b02..c5ba323dba47 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -493,8 +493,7 @@ static void subscr_named_msg_event(void *usr_handle,
493 493
494 /* Create server port & establish connection to subscriber */ 494 /* Create server port & establish connection to subscriber */
495 495
496 tipc_createport(0, 496 tipc_createport(subscriber,
497 subscriber,
498 importance, 497 importance,
499 NULL, 498 NULL,
500 NULL, 499 NULL,
@@ -548,8 +547,7 @@ int tipc_subscr_start(void)
548 INIT_LIST_HEAD(&topsrv.subscriber_list); 547 INIT_LIST_HEAD(&topsrv.subscriber_list);
549 548
550 spin_lock_bh(&topsrv.lock); 549 spin_lock_bh(&topsrv.lock);
551 res = tipc_createport(0, 550 res = tipc_createport(NULL,
552 NULL,
553 TIPC_CRITICAL_IMPORTANCE, 551 TIPC_CRITICAL_IMPORTANCE,
554 NULL, 552 NULL,
555 NULL, 553 NULL,
diff --git a/net/tipc/user_reg.c b/net/tipc/user_reg.c
deleted file mode 100644
index 2e2702e2049c..000000000000
--- a/net/tipc/user_reg.c
+++ /dev/null
@@ -1,218 +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 * @ports: list of user ports owned by the user
54 */
55
56struct tipc_user {
57 int next;
58 struct list_head ports;
59};
60
61#define MAX_USERID 64
62#define USER_LIST_SIZE ((MAX_USERID + 1) * sizeof(struct tipc_user))
63
64static struct tipc_user *users = NULL;
65static u32 next_free_user = MAX_USERID + 1;
66static DEFINE_SPINLOCK(reg_lock);
67
68/**
69 * reg_init - create TIPC user registry (but don't activate it)
70 *
71 * If registry has been pre-initialized it is left "as is".
72 * NOTE: This routine may be called when TIPC is inactive.
73 */
74
75static int reg_init(void)
76{
77 u32 i;
78
79 spin_lock_bh(&reg_lock);
80 if (!users) {
81 users = kzalloc(USER_LIST_SIZE, GFP_ATOMIC);
82 if (users) {
83 for (i = 1; i <= MAX_USERID; i++) {
84 users[i].next = i - 1;
85 }
86 next_free_user = MAX_USERID;
87 }
88 }
89 spin_unlock_bh(&reg_lock);
90 return users ? 0 : -ENOMEM;
91}
92
93/**
94 * tipc_reg_start - activate TIPC user registry
95 */
96
97int tipc_reg_start(void)
98{
99 return reg_init();
100}
101
102/**
103 * tipc_reg_stop - shut down & delete TIPC user registry
104 */
105
106void tipc_reg_stop(void)
107{
108 if (!users)
109 return;
110
111 kfree(users);
112 users = NULL;
113}
114
115/**
116 * tipc_attach - register a TIPC user
117 *
118 * NOTE: This routine may be called when TIPC is inactive.
119 */
120
121int tipc_attach(u32 *userid)
122{
123 struct tipc_user *user_ptr;
124
125 if (!users)
126 reg_init();
127
128 spin_lock_bh(&reg_lock);
129 if (!next_free_user) {
130 spin_unlock_bh(&reg_lock);
131 return -EBUSY;
132 }
133 user_ptr = &users[next_free_user];
134 *userid = next_free_user;
135 next_free_user = user_ptr->next;
136 user_ptr->next = -1;
137 spin_unlock_bh(&reg_lock);
138
139 INIT_LIST_HEAD(&user_ptr->ports);
140 atomic_inc(&tipc_user_count);
141
142 return 0;
143}
144
145/**
146 * tipc_detach - deregister a TIPC user
147 */
148
149void tipc_detach(u32 userid)
150{
151 struct tipc_user *user_ptr;
152 struct list_head ports_temp;
153 struct user_port *up_ptr, *temp_up_ptr;
154
155 if ((userid == 0) || (userid > MAX_USERID))
156 return;
157
158 spin_lock_bh(&reg_lock);
159 if ((!users) || (users[userid].next >= 0)) {
160 spin_unlock_bh(&reg_lock);
161 return;
162 }
163
164 user_ptr = &users[userid];
165 INIT_LIST_HEAD(&ports_temp);
166 list_splice(&user_ptr->ports, &ports_temp);
167 user_ptr->next = next_free_user;
168 next_free_user = userid;
169 spin_unlock_bh(&reg_lock);
170
171 atomic_dec(&tipc_user_count);
172
173 list_for_each_entry_safe(up_ptr, temp_up_ptr, &ports_temp, uport_list) {
174 tipc_deleteport(up_ptr->ref);
175 }
176}
177
178/**
179 * tipc_reg_add_port - register a user's driver port
180 */
181
182int tipc_reg_add_port(struct user_port *up_ptr)
183{
184 struct tipc_user *user_ptr;
185
186 if (up_ptr->user_ref == 0)
187 return 0;
188 if (up_ptr->user_ref > MAX_USERID)
189 return -EINVAL;
190 if ((tipc_mode == TIPC_NOT_RUNNING) || !users )
191 return -ENOPROTOOPT;
192
193 spin_lock_bh(&reg_lock);
194 user_ptr = &users[up_ptr->user_ref];
195 list_add(&up_ptr->uport_list, &user_ptr->ports);
196 spin_unlock_bh(&reg_lock);
197 return 0;
198}
199
200/**
201 * tipc_reg_remove_port - deregister a user's driver port
202 */
203
204int tipc_reg_remove_port(struct user_port *up_ptr)
205{
206 if (up_ptr->user_ref == 0)
207 return 0;
208 if (up_ptr->user_ref > MAX_USERID)
209 return -EINVAL;
210 if (!users )
211 return -ENOPROTOOPT;
212
213 spin_lock_bh(&reg_lock);
214 list_del_init(&up_ptr->uport_list);
215 spin_unlock_bh(&reg_lock);
216 return 0;
217}
218
diff --git a/net/tipc/user_reg.h b/net/tipc/user_reg.h
deleted file mode 100644
index 109eed0d6de3..000000000000
--- a/net/tipc/user_reg.h
+++ /dev/null
@@ -1,51 +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_attach(unsigned int *userref);
46void tipc_detach(unsigned int userref);
47
48int tipc_reg_add_port(struct user_port *up_ptr);
49int tipc_reg_remove_port(struct user_port *up_ptr);
50
51#endif