@@ -50,34 +50,6 @@ struct tipc_subscriber {
5050 struct list_head subscription_list ;
5151};
5252
53- static void subscr_conn_msg_event (struct net * net , int conid ,
54- struct sockaddr_tipc * addr , void * usr_data ,
55- void * buf , size_t len );
56- static void * subscr_named_msg_event (int conid );
57- static void subscr_conn_shutdown_event (int conid , void * usr_data );
58-
59- static atomic_t subscription_count = ATOMIC_INIT (0 );
60-
61- static struct sockaddr_tipc topsrv_addr __read_mostly = {
62- .family = AF_TIPC ,
63- .addrtype = TIPC_ADDR_NAMESEQ ,
64- .addr .nameseq .type = TIPC_TOP_SRV ,
65- .addr .nameseq .lower = TIPC_TOP_SRV ,
66- .addr .nameseq .upper = TIPC_TOP_SRV ,
67- .scope = TIPC_NODE_SCOPE
68- };
69-
70- static struct tipc_server topsrv __read_mostly = {
71- .saddr = & topsrv_addr ,
72- .imp = TIPC_CRITICAL_IMPORTANCE ,
73- .type = SOCK_SEQPACKET ,
74- .max_rcvbuf_size = sizeof (struct tipc_subscr ),
75- .name = "topology_server" ,
76- .tipc_conn_recvmsg = subscr_conn_msg_event ,
77- .tipc_conn_new = subscr_named_msg_event ,
78- .tipc_conn_shutdown = subscr_conn_shutdown_event ,
79- };
80-
8153/**
8254 * htohl - convert value to endianness used by destination
8355 * @in: value to convert
@@ -94,6 +66,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
9466 u32 found_upper , u32 event , u32 port_ref ,
9567 u32 node )
9668{
69+ struct tipc_net * tn = net_generic (sub -> net , tipc_net_id );
9770 struct tipc_subscriber * subscriber = sub -> subscriber ;
9871 struct kvec msg_sect ;
9972
@@ -104,8 +77,8 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
10477 sub -> evt .found_upper = htohl (found_upper , sub -> swap );
10578 sub -> evt .port .ref = htohl (port_ref , sub -> swap );
10679 sub -> evt .port .node = htohl (node , sub -> swap );
107- tipc_conn_sendmsg (& topsrv , subscriber -> conid , NULL , msg_sect . iov_base ,
108- msg_sect .iov_len );
80+ tipc_conn_sendmsg (tn -> topsrv , subscriber -> conid , NULL ,
81+ msg_sect .iov_base , msg_sect . iov_len );
10982}
11083
11184/**
@@ -146,6 +119,7 @@ static void subscr_timeout(unsigned long data)
146119{
147120 struct tipc_subscription * sub = (struct tipc_subscription * )data ;
148121 struct tipc_subscriber * subscriber = sub -> subscriber ;
122+ struct tipc_net * tn = net_generic (sub -> net , tipc_net_id );
149123
150124 /* The spin lock per subscriber is used to protect its members */
151125 spin_lock_bh (& subscriber -> lock );
@@ -170,7 +144,7 @@ static void subscr_timeout(unsigned long data)
170144
171145 /* Now destroy subscription */
172146 kfree (sub );
173- atomic_dec (& subscription_count );
147+ atomic_dec (& tn -> subscription_count );
174148}
175149
176150/**
@@ -180,20 +154,25 @@ static void subscr_timeout(unsigned long data)
180154 */
181155static void subscr_del (struct tipc_subscription * sub )
182156{
157+ struct tipc_net * tn = net_generic (sub -> net , tipc_net_id );
158+
183159 tipc_nametbl_unsubscribe (sub );
184160 list_del (& sub -> subscription_list );
185161 kfree (sub );
186- atomic_dec (& subscription_count );
162+ atomic_dec (& tn -> subscription_count );
187163}
188164
189165/**
190166 * subscr_terminate - terminate communication with a subscriber
191167 *
192168 * Note: Must call it in process context since it might sleep.
193169 */
194- static void subscr_terminate (struct tipc_subscriber * subscriber )
170+ static void subscr_terminate (struct tipc_subscription * sub )
195171{
196- tipc_conn_terminate (& topsrv , subscriber -> conid );
172+ struct tipc_subscriber * subscriber = sub -> subscriber ;
173+ struct tipc_net * tn = net_generic (sub -> net , tipc_net_id );
174+
175+ tipc_conn_terminate (tn -> topsrv , subscriber -> conid );
197176}
198177
199178static void subscr_release (struct tipc_subscriber * subscriber )
@@ -263,7 +242,9 @@ static void subscr_cancel(struct tipc_subscr *s,
263242 */
264243static int subscr_subscribe (struct net * net , struct tipc_subscr * s ,
265244 struct tipc_subscriber * subscriber ,
266- struct tipc_subscription * * sub_p ) {
245+ struct tipc_subscription * * sub_p )
246+ {
247+ struct tipc_net * tn = net_generic (net , tipc_net_id );
267248 struct tipc_subscription * sub ;
268249 int swap ;
269250
@@ -278,7 +259,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
278259 }
279260
280261 /* Refuse subscription if global limit exceeded */
281- if (atomic_read (& subscription_count ) >= TIPC_MAX_SUBSCRIPTIONS ) {
262+ if (atomic_read (& tn -> subscription_count ) >= TIPC_MAX_SUBSCRIPTIONS ) {
282263 pr_warn ("Subscription rejected, limit reached (%u)\n" ,
283264 TIPC_MAX_SUBSCRIPTIONS );
284265 return - EINVAL ;
@@ -309,7 +290,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
309290 sub -> subscriber = subscriber ;
310291 sub -> swap = swap ;
311292 memcpy (& sub -> evt .s , s , sizeof (struct tipc_subscr ));
312- atomic_inc (& subscription_count );
293+ atomic_inc (& tn -> subscription_count );
313294 if (sub -> timeout != TIPC_WAIT_FOREVER ) {
314295 setup_timer (& sub -> timer , subscr_timeout , (unsigned long )sub );
315296 mod_timer (& sub -> timer , jiffies + sub -> timeout );
@@ -336,15 +317,14 @@ static void subscr_conn_msg_event(struct net *net, int conid,
336317 if (subscr_subscribe (net , (struct tipc_subscr * )buf , subscriber ,
337318 & sub ) < 0 ) {
338319 spin_unlock_bh (& subscriber -> lock );
339- subscr_terminate (subscriber );
320+ subscr_terminate (sub );
340321 return ;
341322 }
342323 if (sub )
343324 tipc_nametbl_subscribe (sub );
344325 spin_unlock_bh (& subscriber -> lock );
345326}
346327
347-
348328/* Handle one request to establish a new subscriber */
349329static void * subscr_named_msg_event (int conid )
350330{
@@ -363,12 +343,50 @@ static void *subscr_named_msg_event(int conid)
363343 return (void * )subscriber ;
364344}
365345
366- int tipc_subscr_start (void )
346+ int tipc_subscr_start (struct net * net )
367347{
368- return tipc_server_start (& topsrv );
348+ struct tipc_net * tn = net_generic (net , tipc_net_id );
349+ const char name [] = "topology_server" ;
350+ struct tipc_server * topsrv ;
351+ struct sockaddr_tipc * saddr ;
352+
353+ saddr = kzalloc (sizeof (* saddr ), GFP_ATOMIC );
354+ if (!saddr )
355+ return - ENOMEM ;
356+ saddr -> family = AF_TIPC ;
357+ saddr -> addrtype = TIPC_ADDR_NAMESEQ ;
358+ saddr -> addr .nameseq .type = TIPC_TOP_SRV ;
359+ saddr -> addr .nameseq .lower = TIPC_TOP_SRV ;
360+ saddr -> addr .nameseq .upper = TIPC_TOP_SRV ;
361+ saddr -> scope = TIPC_NODE_SCOPE ;
362+
363+ topsrv = kzalloc (sizeof (* topsrv ), GFP_ATOMIC );
364+ if (!topsrv ) {
365+ kfree (saddr );
366+ return - ENOMEM ;
367+ }
368+ topsrv -> net = net ;
369+ topsrv -> saddr = saddr ;
370+ topsrv -> imp = TIPC_CRITICAL_IMPORTANCE ;
371+ topsrv -> type = SOCK_SEQPACKET ;
372+ topsrv -> max_rcvbuf_size = sizeof (struct tipc_subscr );
373+ topsrv -> tipc_conn_recvmsg = subscr_conn_msg_event ;
374+ topsrv -> tipc_conn_new = subscr_named_msg_event ;
375+ topsrv -> tipc_conn_shutdown = subscr_conn_shutdown_event ;
376+
377+ strncpy (topsrv -> name , name , strlen (name ) + 1 );
378+ tn -> topsrv = topsrv ;
379+ atomic_set (& tn -> subscription_count , 0 );
380+
381+ return tipc_server_start (topsrv );
369382}
370383
371- void tipc_subscr_stop (void )
384+ void tipc_subscr_stop (struct net * net )
372385{
373- tipc_server_stop (& topsrv );
386+ struct tipc_net * tn = net_generic (net , tipc_net_id );
387+ struct tipc_server * topsrv = tn -> topsrv ;
388+
389+ tipc_server_stop (topsrv );
390+ kfree (topsrv -> saddr );
391+ kfree (topsrv );
374392}
0 commit comments