Blame view

net/tipc/subscr.c 11.3 KB
b97bf3fd8   Per Liden   [TIPC] Initial merge
1
  /*
5b06c85c3   Allan Stephens   tipc: Cosmetic cl...
2
   * net/tipc/subscr.c: TIPC network topology service
c43072852   YOSHIFUJI Hideaki   [NET] TIPC: Fix w...
3
   *
593a5f22d   Per Liden   [TIPC] More updat...
4
   * Copyright (c) 2000-2006, Ericsson AB
13a2e8987   Ying Xue   tipc: convert top...
5
   * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
b97bf3fd8   Per Liden   [TIPC] Initial merge
6
7
   * All rights reserved.
   *
9ea1fd3c1   Per Liden   [TIPC] License he...
8
   * Redistribution and use in source and binary forms, with or without
b97bf3fd8   Per Liden   [TIPC] Initial merge
9
10
   * modification, are permitted provided that the following conditions are met:
   *
9ea1fd3c1   Per Liden   [TIPC] License he...
11
12
13
14
15
16
17
18
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in the
   *    documentation and/or other materials provided with the distribution.
   * 3. Neither the names of the copyright holders nor the names of its
   *    contributors may be used to endorse or promote products derived from
   *    this software without specific prior written permission.
b97bf3fd8   Per Liden   [TIPC] Initial merge
19
   *
9ea1fd3c1   Per Liden   [TIPC] License he...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   * Alternatively, this software may be distributed under the terms of the
   * GNU General Public License ("GPL") version 2 as published by the Free
   * Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
b97bf3fd8   Per Liden   [TIPC] Initial merge
34
35
36
37
   * POSSIBILITY OF SUCH DAMAGE.
   */
  
  #include "core.h"
b97bf3fd8   Per Liden   [TIPC] Initial merge
38
  #include "name_table.h"
5b06c85c3   Allan Stephens   tipc: Cosmetic cl...
39
  #include "subscr.h"
b97bf3fd8   Per Liden   [TIPC] Initial merge
40
41
  
  /**
11f999060   Paul Gortmaker   tipc: rename stru...
42
   * struct tipc_subscriber - TIPC network topology subscriber
00bc00a93   Ying Xue   tipc: involve ref...
43
   * @kref: reference counter to tipc_subscription object
13a2e8987   Ying Xue   tipc: convert top...
44
   * @conid: connection identifier to server connecting to subscriber
963a18553   stephen hemminger   tipc: spelling fixes
45
   * @lock: control access to subscriber
57f1d1868   Ying Xue   tipc: rename func...
46
   * @subscrp_list: list of subscription objects for this subscriber
b97bf3fd8   Per Liden   [TIPC] Initial merge
47
   */
11f999060   Paul Gortmaker   tipc: rename stru...
48
  struct tipc_subscriber {
00bc00a93   Ying Xue   tipc: involve ref...
49
  	struct kref kref;
13a2e8987   Ying Xue   tipc: convert top...
50
51
  	int conid;
  	spinlock_t lock;
57f1d1868   Ying Xue   tipc: rename func...
52
  	struct list_head subscrp_list;
b97bf3fd8   Per Liden   [TIPC] Initial merge
53
  };
00bc00a93   Ying Xue   tipc: involve ref...
54
55
  static void tipc_subscrp_delete(struct tipc_subscription *sub);
  static void tipc_subscrb_put(struct tipc_subscriber *subscriber);
b97bf3fd8   Per Liden   [TIPC] Initial merge
56
  /**
db5a753bf   Neil Horman   Revert d88dca79d3...
57
58
59
60
61
62
   * htohl - convert value to endianness used by destination
   * @in: value to convert
   * @swap: non-zero if endianness must be reversed
   *
   * Returns converted value
   */
db5a753bf   Neil Horman   Revert d88dca79d3...
63
64
65
66
  static u32 htohl(u32 in, int swap)
  {
  	return swap ? swab32(in) : in;
  }
57f1d1868   Ying Xue   tipc: rename func...
67
68
69
  static void tipc_subscrp_send_event(struct tipc_subscription *sub,
  				    u32 found_lower, u32 found_upper,
  				    u32 event, u32 port_ref, u32 node)
b97bf3fd8   Per Liden   [TIPC] Initial merge
70
  {
a62fbccec   Ying Xue   tipc: make subscr...
71
  	struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
13a2e8987   Ying Xue   tipc: convert top...
72
73
  	struct tipc_subscriber *subscriber = sub->subscriber;
  	struct kvec msg_sect;
b97bf3fd8   Per Liden   [TIPC] Initial merge
74
75
76
  
  	msg_sect.iov_base = (void *)&sub->evt;
  	msg_sect.iov_len = sizeof(struct tipc_event);
db5a753bf   Neil Horman   Revert d88dca79d3...
77
78
79
80
81
  	sub->evt.event = htohl(event, sub->swap);
  	sub->evt.found_lower = htohl(found_lower, sub->swap);
  	sub->evt.found_upper = htohl(found_upper, sub->swap);
  	sub->evt.port.ref = htohl(port_ref, sub->swap);
  	sub->evt.port.node = htohl(node, sub->swap);
a62fbccec   Ying Xue   tipc: make subscr...
82
83
  	tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL,
  			  msg_sect.iov_base, msg_sect.iov_len);
b97bf3fd8   Per Liden   [TIPC] Initial merge
84
85
86
  }
  
  /**
57f1d1868   Ying Xue   tipc: rename func...
87
88
   * tipc_subscrp_check_overlap - test for subscription overlap with the
   * given values
b97bf3fd8   Per Liden   [TIPC] Initial merge
89
90
91
   *
   * Returns 1 if there is overlap, otherwise 0.
   */
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
92
  int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
57f1d1868   Ying Xue   tipc: rename func...
93
  			       u32 found_upper)
b97bf3fd8   Per Liden   [TIPC] Initial merge
94
  {
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
95
96
97
98
  	if (found_lower < seq->lower)
  		found_lower = seq->lower;
  	if (found_upper > seq->upper)
  		found_upper = seq->upper;
b97bf3fd8   Per Liden   [TIPC] Initial merge
99
100
101
102
  	if (found_lower > found_upper)
  		return 0;
  	return 1;
  }
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
103
104
105
106
107
108
109
110
111
112
113
114
  u32 tipc_subscrp_convert_seq_type(u32 type, int swap)
  {
  	return htohl(type, swap);
  }
  
  void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap,
  			      struct tipc_name_seq *out)
  {
  	out->type = htohl(in->type, swap);
  	out->lower = htohl(in->lower, swap);
  	out->upper = htohl(in->upper, swap);
  }
57f1d1868   Ying Xue   tipc: rename func...
115
116
117
  void tipc_subscrp_report_overlap(struct tipc_subscription *sub, u32 found_lower,
  				 u32 found_upper, u32 event, u32 port_ref,
  				 u32 node, int must)
b97bf3fd8   Per Liden   [TIPC] Initial merge
118
  {
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
119
120
121
122
  	struct tipc_name_seq seq;
  
  	tipc_subscrp_convert_seq(&sub->evt.s.seq, sub->swap, &seq);
  	if (!tipc_subscrp_check_overlap(&seq, found_lower, found_upper))
b97bf3fd8   Per Liden   [TIPC] Initial merge
123
  		return;
308652314   Parthasarathy Bhuvaragan   tipc: remove filt...
124
125
  	if (!must &&
  	    !(htohl(sub->evt.s.filter, sub->swap) & TIPC_SUB_PORTS))
b97bf3fd8   Per Liden   [TIPC] Initial merge
126
  		return;
e15f88040   Allan Stephens   tipc: Add support...
127

57f1d1868   Ying Xue   tipc: rename func...
128
129
  	tipc_subscrp_send_event(sub, found_lower, found_upper, event, port_ref,
  				node);
b97bf3fd8   Per Liden   [TIPC] Initial merge
130
  }
57f1d1868   Ying Xue   tipc: rename func...
131
  static void tipc_subscrp_timeout(unsigned long data)
b97bf3fd8   Per Liden   [TIPC] Initial merge
132
  {
2f55c4378   Ying Xue   tipc: remove unne...
133
  	struct tipc_subscription *sub = (struct tipc_subscription *)data;
13a2e8987   Ying Xue   tipc: convert top...
134
  	struct tipc_subscriber *subscriber = sub->subscriber;
28353e7fa   Allan Stephens   tipc: Consolidate...
135
136
  
  	/* Notify subscriber of timeout */
57f1d1868   Ying Xue   tipc: rename func...
137
138
  	tipc_subscrp_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper,
  				TIPC_SUBSCR_TIMEOUT, 0, 0);
28353e7fa   Allan Stephens   tipc: Consolidate...
139

00bc00a93   Ying Xue   tipc: involve ref...
140
141
142
143
144
  	spin_lock_bh(&subscriber->lock);
  	tipc_subscrp_delete(sub);
  	spin_unlock_bh(&subscriber->lock);
  
  	tipc_subscrb_put(subscriber);
b97bf3fd8   Per Liden   [TIPC] Initial merge
145
  }
00bc00a93   Ying Xue   tipc: involve ref...
146
  static void tipc_subscrb_kref_release(struct kref *kref)
eb409460b   Lijun Chen   [TIPC]: Added sub...
147
  {
00bc00a93   Ying Xue   tipc: involve ref...
148
149
  	struct tipc_subscriber *subcriber = container_of(kref,
  					    struct tipc_subscriber, kref);
a62fbccec   Ying Xue   tipc: make subscr...
150

00bc00a93   Ying Xue   tipc: involve ref...
151
152
153
154
155
156
157
158
159
160
161
  	kfree(subcriber);
  }
  
  static void tipc_subscrb_put(struct tipc_subscriber *subscriber)
  {
  	kref_put(&subscriber->kref, tipc_subscrb_kref_release);
  }
  
  static void tipc_subscrb_get(struct tipc_subscriber *subscriber)
  {
  	kref_get(&subscriber->kref);
eb409460b   Lijun Chen   [TIPC]: Added sub...
162
  }
1b764828a   Ying Xue   tipc: introduce t...
163
164
165
166
167
168
169
170
171
172
  static struct tipc_subscriber *tipc_subscrb_create(int conid)
  {
  	struct tipc_subscriber *subscriber;
  
  	subscriber = kzalloc(sizeof(*subscriber), GFP_ATOMIC);
  	if (!subscriber) {
  		pr_warn("Subscriber rejected, no memory
  ");
  		return NULL;
  	}
00bc00a93   Ying Xue   tipc: involve ref...
173
  	kref_init(&subscriber->kref);
1b764828a   Ying Xue   tipc: introduce t...
174
175
176
177
178
179
  	INIT_LIST_HEAD(&subscriber->subscrp_list);
  	subscriber->conid = conid;
  	spin_lock_init(&subscriber->lock);
  
  	return subscriber;
  }
57f1d1868   Ying Xue   tipc: rename func...
180
  static void tipc_subscrb_delete(struct tipc_subscriber *subscriber)
13a2e8987   Ying Xue   tipc: convert top...
181
  {
00bc00a93   Ying Xue   tipc: involve ref...
182
  	struct tipc_subscription *sub, *temp;
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
183
  	u32 timeout;
b97bf3fd8   Per Liden   [TIPC] Initial merge
184

13a2e8987   Ying Xue   tipc: convert top...
185
  	spin_lock_bh(&subscriber->lock);
b97bf3fd8   Per Liden   [TIPC] Initial merge
186
  	/* Destroy any existing subscriptions for subscriber */
00bc00a93   Ying Xue   tipc: involve ref...
187
  	list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
57f1d1868   Ying Xue   tipc: rename func...
188
  				 subscrp_list) {
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
189
190
  		timeout = htohl(sub->evt.s.timeout, sub->swap);
  		if ((timeout == TIPC_WAIT_FOREVER) || del_timer(&sub->timer)) {
00bc00a93   Ying Xue   tipc: involve ref...
191
192
  			tipc_subscrp_delete(sub);
  			tipc_subscrb_put(subscriber);
b97bf3fd8   Per Liden   [TIPC] Initial merge
193
  		}
b97bf3fd8   Per Liden   [TIPC] Initial merge
194
  	}
13a2e8987   Ying Xue   tipc: convert top...
195
  	spin_unlock_bh(&subscriber->lock);
28353e7fa   Allan Stephens   tipc: Consolidate...
196

00bc00a93   Ying Xue   tipc: involve ref...
197
198
199
200
201
202
203
204
205
206
207
  	tipc_subscrb_put(subscriber);
  }
  
  static void tipc_subscrp_delete(struct tipc_subscription *sub)
  {
  	struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
  
  	tipc_nametbl_unsubscribe(sub);
  	list_del(&sub->subscrp_list);
  	kfree(sub);
  	atomic_dec(&tn->subscription_count);
b97bf3fd8   Per Liden   [TIPC] Initial merge
208
  }
57f1d1868   Ying Xue   tipc: rename func...
209
210
  static void tipc_subscrp_cancel(struct tipc_subscr *s,
  				struct tipc_subscriber *subscriber)
eb409460b   Lijun Chen   [TIPC]: Added sub...
211
  {
00bc00a93   Ying Xue   tipc: involve ref...
212
  	struct tipc_subscription *sub, *temp;
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
213
  	u32 timeout;
eb409460b   Lijun Chen   [TIPC]: Added sub...
214

a13683f29   Ying Xue   tipc: adjust lock...
215
  	spin_lock_bh(&subscriber->lock);
eb409460b   Lijun Chen   [TIPC]: Added sub...
216
  	/* Find first matching subscription, exit if not found */
00bc00a93   Ying Xue   tipc: involve ref...
217
  	list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
57f1d1868   Ying Xue   tipc: rename func...
218
  				 subscrp_list) {
db5a753bf   Neil Horman   Revert d88dca79d3...
219
  		if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
220
221
222
  			timeout = htohl(sub->evt.s.timeout, sub->swap);
  			if ((timeout == TIPC_WAIT_FOREVER) ||
  			    del_timer(&sub->timer)) {
00bc00a93   Ying Xue   tipc: involve ref...
223
224
225
  				tipc_subscrp_delete(sub);
  				tipc_subscrb_put(subscriber);
  			}
db5a753bf   Neil Horman   Revert d88dca79d3...
226
227
  			break;
  		}
eb409460b   Lijun Chen   [TIPC]: Added sub...
228
  	}
a13683f29   Ying Xue   tipc: adjust lock...
229
  	spin_unlock_bh(&subscriber->lock);
eb409460b   Lijun Chen   [TIPC]: Added sub...
230
  }
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
231
232
  static struct tipc_subscription *tipc_subscrp_create(struct net *net,
  						     struct tipc_subscr *s,
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
233
  						     int swap)
a62fbccec   Ying Xue   tipc: make subscr...
234
235
  {
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
fead39098   Paul Gortmaker   tipc: rename stru...
236
  	struct tipc_subscription *sub;
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
237
  	u32 filter = htohl(s->filter, swap);
eb409460b   Lijun Chen   [TIPC]: Added sub...
238

b97bf3fd8   Per Liden   [TIPC] Initial merge
239
  	/* Refuse subscription if global limit exceeded */
a62fbccec   Ying Xue   tipc: make subscr...
240
  	if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
2cf8aa19f   Erik Hugne   tipc: use standar...
241
242
  		pr_warn("Subscription rejected, limit reached (%u)
  ",
34f256cc7   Ying Xue   tipc: eliminate c...
243
  			TIPC_MAX_SUBSCRIPTIONS);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
244
  		return NULL;
b97bf3fd8   Per Liden   [TIPC] Initial merge
245
246
247
  	}
  
  	/* Allocate subscription object */
28353e7fa   Allan Stephens   tipc: Consolidate...
248
  	sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
a10bd924a   Allan Stephens   [TIPC]: Enhanced ...
249
  	if (!sub) {
2cf8aa19f   Erik Hugne   tipc: use standar...
250
251
  		pr_warn("Subscription rejected, no memory
  ");
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
252
  		return NULL;
b97bf3fd8   Per Liden   [TIPC] Initial merge
253
  	}
b97bf3fd8   Per Liden   [TIPC] Initial merge
254
  	/* Initialize subscription object */
4ac1c8d0e   Ying Xue   tipc: name tipc n...
255
  	sub->net = net;
308652314   Parthasarathy Bhuvaragan   tipc: remove filt...
256
  	if (((filter & TIPC_SUB_PORTS) && (filter & TIPC_SUB_SERVICE)) ||
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
257
  	    (htohl(s->seq.lower, swap) > htohl(s->seq.upper, swap))) {
2cf8aa19f   Erik Hugne   tipc: use standar...
258
259
  		pr_warn("Subscription rejected, illegal request
  ");
b97bf3fd8   Per Liden   [TIPC] Initial merge
260
  		kfree(sub);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
261
  		return NULL;
b97bf3fd8   Per Liden   [TIPC] Initial merge
262
  	}
308652314   Parthasarathy Bhuvaragan   tipc: remove filt...
263

db5a753bf   Neil Horman   Revert d88dca79d3...
264
  	sub->swap = swap;
57f1d1868   Ying Xue   tipc: rename func...
265
  	memcpy(&sub->evt.s, s, sizeof(*s));
a62fbccec   Ying Xue   tipc: make subscr...
266
  	atomic_inc(&tn->subscription_count);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
267
268
269
270
  	return sub;
  }
  
  static void tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s,
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
271
  				   struct tipc_subscriber *subscriber, int swap)
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
272
273
274
275
  {
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
  	struct tipc_subscription *sub = NULL;
  	u32 timeout;
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
276
  	sub = tipc_subscrp_create(net, s, swap);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
277
278
279
280
281
  	if (!sub)
  		return tipc_conn_terminate(tn->topsrv, subscriber->conid);
  
  	spin_lock_bh(&subscriber->lock);
  	list_add(&sub->subscrp_list, &subscriber->subscrp_list);
f3ad288c5   Parthasarathy Bhuvaragan   tipc: protect tip...
282
  	tipc_subscrb_get(subscriber);
d4091899c   Parthasarathy Bhuvaragan   tipc: hold subscr...
283
284
  	sub->subscriber = subscriber;
  	tipc_nametbl_subscribe(sub);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
285
  	spin_unlock_bh(&subscriber->lock);
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
286
  	timeout = htohl(sub->evt.s.timeout, swap);
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
287
288
289
290
  	if (timeout == TIPC_WAIT_FOREVER)
  		return;
  
  	setup_timer(&sub->timer, tipc_subscrp_timeout, (unsigned long)sub);
f3ad288c5   Parthasarathy Bhuvaragan   tipc: protect tip...
291
  	mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
b97bf3fd8   Per Liden   [TIPC] Initial merge
292
  }
13a2e8987   Ying Xue   tipc: convert top...
293
  /* Handle one termination request for the subscriber */
57f1d1868   Ying Xue   tipc: rename func...
294
  static void tipc_subscrb_shutdown_cb(int conid, void *usr_data)
b97bf3fd8   Per Liden   [TIPC] Initial merge
295
  {
57f1d1868   Ying Xue   tipc: rename func...
296
  	tipc_subscrb_delete((struct tipc_subscriber *)usr_data);
b97bf3fd8   Per Liden   [TIPC] Initial merge
297
  }
13a2e8987   Ying Xue   tipc: convert top...
298
  /* Handle one request to create a new subscription for the subscriber */
57f1d1868   Ying Xue   tipc: rename func...
299
300
301
  static void tipc_subscrb_rcv_cb(struct net *net, int conid,
  				struct sockaddr_tipc *addr, void *usr_data,
  				void *buf, size_t len)
b97bf3fd8   Per Liden   [TIPC] Initial merge
302
  {
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
303
304
305
306
307
  	struct tipc_subscriber *subscriber = usr_data;
  	struct tipc_subscr *s = (struct tipc_subscr *)buf;
  	int swap;
  
  	/* Determine subscriber's endianness */
cb01c7c87   Parthasarathy Bhuvaragan   tipc: fix connect...
308
309
  	swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE |
  			      TIPC_SUB_CANCEL));
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
310
311
312
313
314
315
316
317
  
  	/* Detect & process a subscription cancellation request */
  	if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
  		s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
  		return tipc_subscrp_cancel(s, subscriber);
  	}
  
  	tipc_subscrp_subscribe(net, s, subscriber, swap);
b97bf3fd8   Per Liden   [TIPC] Initial merge
318
  }
13a2e8987   Ying Xue   tipc: convert top...
319
  /* Handle one request to establish a new subscriber */
57f1d1868   Ying Xue   tipc: rename func...
320
  static void *tipc_subscrb_connect_cb(int conid)
b97bf3fd8   Per Liden   [TIPC] Initial merge
321
  {
1b764828a   Ying Xue   tipc: introduce t...
322
  	return (void *)tipc_subscrb_create(conid);
b97bf3fd8   Per Liden   [TIPC] Initial merge
323
  }
57f1d1868   Ying Xue   tipc: rename func...
324
  int tipc_topsrv_start(struct net *net)
b97bf3fd8   Per Liden   [TIPC] Initial merge
325
  {
a62fbccec   Ying Xue   tipc: make subscr...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
  	const char name[] = "topology_server";
  	struct tipc_server *topsrv;
  	struct sockaddr_tipc *saddr;
  
  	saddr = kzalloc(sizeof(*saddr), GFP_ATOMIC);
  	if (!saddr)
  		return -ENOMEM;
  	saddr->family			= AF_TIPC;
  	saddr->addrtype			= TIPC_ADDR_NAMESEQ;
  	saddr->addr.nameseq.type	= TIPC_TOP_SRV;
  	saddr->addr.nameseq.lower	= TIPC_TOP_SRV;
  	saddr->addr.nameseq.upper	= TIPC_TOP_SRV;
  	saddr->scope			= TIPC_NODE_SCOPE;
  
  	topsrv = kzalloc(sizeof(*topsrv), GFP_ATOMIC);
  	if (!topsrv) {
  		kfree(saddr);
  		return -ENOMEM;
  	}
  	topsrv->net			= net;
  	topsrv->saddr			= saddr;
  	topsrv->imp			= TIPC_CRITICAL_IMPORTANCE;
  	topsrv->type			= SOCK_SEQPACKET;
  	topsrv->max_rcvbuf_size		= sizeof(struct tipc_subscr);
57f1d1868   Ying Xue   tipc: rename func...
351
352
353
  	topsrv->tipc_conn_recvmsg	= tipc_subscrb_rcv_cb;
  	topsrv->tipc_conn_new		= tipc_subscrb_connect_cb;
  	topsrv->tipc_conn_shutdown	= tipc_subscrb_shutdown_cb;
a62fbccec   Ying Xue   tipc: make subscr...
354
355
356
357
358
359
  
  	strncpy(topsrv->name, name, strlen(name) + 1);
  	tn->topsrv = topsrv;
  	atomic_set(&tn->subscription_count, 0);
  
  	return tipc_server_start(topsrv);
b97bf3fd8   Per Liden   [TIPC] Initial merge
360
  }
57f1d1868   Ying Xue   tipc: rename func...
361
  void tipc_topsrv_stop(struct net *net)
b97bf3fd8   Per Liden   [TIPC] Initial merge
362
  {
a62fbccec   Ying Xue   tipc: make subscr...
363
364
365
366
367
368
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
  	struct tipc_server *topsrv = tn->topsrv;
  
  	tipc_server_stop(topsrv);
  	kfree(topsrv->saddr);
  	kfree(topsrv);
b97bf3fd8   Per Liden   [TIPC] Initial merge
369
  }