Blame view

net/tipc/subscr.c 11.5 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
  static void tipc_subscrb_put(struct tipc_subscriber *subscriber);
b97bf3fd8   Per Liden   [TIPC] Initial merge
55
  /**
db5a753bf   Neil Horman   Revert d88dca79d3...
56
57
58
59
60
61
   * 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...
62
63
64
65
  static u32 htohl(u32 in, int swap)
  {
  	return swap ? swab32(in) : in;
  }
57f1d1868   Ying Xue   tipc: rename func...
66
67
68
  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
69
  {
a62fbccec   Ying Xue   tipc: make subscr...
70
  	struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
13a2e8987   Ying Xue   tipc: convert top...
71
72
  	struct tipc_subscriber *subscriber = sub->subscriber;
  	struct kvec msg_sect;
b97bf3fd8   Per Liden   [TIPC] Initial merge
73
74
75
  
  	msg_sect.iov_base = (void *)&sub->evt;
  	msg_sect.iov_len = sizeof(struct tipc_event);
db5a753bf   Neil Horman   Revert d88dca79d3...
76
77
78
79
80
  	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...
81
82
  	tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL,
  			  msg_sect.iov_base, msg_sect.iov_len);
b97bf3fd8   Per Liden   [TIPC] Initial merge
83
84
85
  }
  
  /**
57f1d1868   Ying Xue   tipc: rename func...
86
87
   * tipc_subscrp_check_overlap - test for subscription overlap with the
   * given values
b97bf3fd8   Per Liden   [TIPC] Initial merge
88
89
90
   *
   * Returns 1 if there is overlap, otherwise 0.
   */
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
91
  int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
57f1d1868   Ying Xue   tipc: rename func...
92
  			       u32 found_upper)
b97bf3fd8   Per Liden   [TIPC] Initial merge
93
  {
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
94
95
96
97
  	if (found_lower < seq->lower)
  		found_lower = seq->lower;
  	if (found_upper > seq->upper)
  		found_upper = seq->upper;
b97bf3fd8   Per Liden   [TIPC] Initial merge
98
99
100
101
  	if (found_lower > found_upper)
  		return 0;
  	return 1;
  }
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
102
103
104
105
106
107
108
109
110
111
112
113
  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...
114
115
116
  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
117
  {
a4273c73e   Parthasarathy Bhuvaragan   tipc: remove stru...
118
119
120
121
  	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
122
  		return;
308652314   Parthasarathy Bhuvaragan   tipc: remove filt...
123
124
  	if (!must &&
  	    !(htohl(sub->evt.s.filter, sub->swap) & TIPC_SUB_PORTS))
b97bf3fd8   Per Liden   [TIPC] Initial merge
125
  		return;
e15f88040   Allan Stephens   tipc: Add support...
126

57f1d1868   Ying Xue   tipc: rename func...
127
128
  	tipc_subscrp_send_event(sub, found_lower, found_upper, event, port_ref,
  				node);
b97bf3fd8   Per Liden   [TIPC] Initial merge
129
  }
57f1d1868   Ying Xue   tipc: rename func...
130
  static void tipc_subscrp_timeout(unsigned long data)
b97bf3fd8   Per Liden   [TIPC] Initial merge
131
  {
2f55c4378   Ying Xue   tipc: remove unne...
132
  	struct tipc_subscription *sub = (struct tipc_subscription *)data;
557d054c0   Ying Xue   tipc: fix nametbl...
133
134
135
136
  	struct tipc_subscriber *subscriber = sub->subscriber;
  
  	spin_lock_bh(&subscriber->lock);
  	tipc_nametbl_unsubscribe(sub);
139bb36f7   Ying Xue   tipc: advance the...
137
  	list_del(&sub->subscrp_list);
557d054c0   Ying Xue   tipc: fix nametbl...
138
  	spin_unlock_bh(&subscriber->lock);
28353e7fa   Allan Stephens   tipc: Consolidate...
139
140
  
  	/* Notify subscriber of timeout */
57f1d1868   Ying Xue   tipc: rename func...
141
142
  	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...
143

d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
144
  	tipc_subscrp_put(sub);
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
  {
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
148
  	kfree(container_of(kref,struct tipc_subscriber, kref));
00bc00a93   Ying Xue   tipc: involve ref...
149
150
151
152
153
154
155
156
157
158
  }
  
  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...
159
  }
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
160
161
162
163
164
165
166
  static void tipc_subscrp_kref_release(struct kref *kref)
  {
  	struct tipc_subscription *sub = container_of(kref,
  						     struct tipc_subscription,
  						     kref);
  	struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
  	struct tipc_subscriber *subscriber = sub->subscriber;
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
167
  	atomic_dec(&tn->subscription_count);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
168
169
170
  	kfree(sub);
  	tipc_subscrb_put(subscriber);
  }
7efea60dc   Ying Xue   tipc: adjust the ...
171
  void tipc_subscrp_put(struct tipc_subscription *subscription)
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
172
173
174
  {
  	kref_put(&subscription->kref, tipc_subscrp_kref_release);
  }
7efea60dc   Ying Xue   tipc: adjust the ...
175
  void tipc_subscrp_get(struct tipc_subscription *subscription)
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
176
177
178
179
180
181
182
183
184
185
186
187
  {
  	kref_get(&subscription->kref);
  }
  
  /* tipc_subscrb_subscrp_delete - delete a specific subscription or all
   * subscriptions for a given subscriber.
   */
  static void tipc_subscrb_subscrp_delete(struct tipc_subscriber *subscriber,
  					struct tipc_subscr *s)
  {
  	struct list_head *subscription_list = &subscriber->subscrp_list;
  	struct tipc_subscription *sub, *temp;
458be024e   Parthasarathy Bhuvaragan   tipc: remove subs...
188
  	u32 timeout;
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
189
190
191
192
193
  
  	spin_lock_bh(&subscriber->lock);
  	list_for_each_entry_safe(sub, temp, subscription_list,  subscrp_list) {
  		if (s && memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr)))
  			continue;
458be024e   Parthasarathy Bhuvaragan   tipc: remove subs...
194
195
196
197
198
199
  		timeout = htohl(sub->evt.s.timeout, sub->swap);
  		if (timeout == TIPC_WAIT_FOREVER || del_timer(&sub->timer)) {
  			tipc_nametbl_unsubscribe(sub);
  			list_del(&sub->subscrp_list);
  			tipc_subscrp_put(sub);
  		}
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
200
201
202
203
204
205
  
  		if (s)
  			break;
  	}
  	spin_unlock_bh(&subscriber->lock);
  }
1b764828a   Ying Xue   tipc: introduce t...
206
207
208
209
210
211
212
213
214
215
216
  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;
  	}
  	INIT_LIST_HEAD(&subscriber->subscrp_list);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
217
  	kref_init(&subscriber->kref);
1b764828a   Ying Xue   tipc: introduce t...
218
219
220
221
222
  	subscriber->conid = conid;
  	spin_lock_init(&subscriber->lock);
  
  	return subscriber;
  }
57f1d1868   Ying Xue   tipc: rename func...
223
  static void tipc_subscrb_delete(struct tipc_subscriber *subscriber)
13a2e8987   Ying Xue   tipc: convert top...
224
  {
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
225
  	tipc_subscrb_subscrp_delete(subscriber, NULL);
00bc00a93   Ying Xue   tipc: involve ref...
226
227
  	tipc_subscrb_put(subscriber);
  }
57f1d1868   Ying Xue   tipc: rename func...
228
229
  static void tipc_subscrp_cancel(struct tipc_subscr *s,
  				struct tipc_subscriber *subscriber)
eb409460b   Lijun Chen   [TIPC]: Added sub...
230
  {
fd849b7c4   Ying Xue   tipc: fix a race ...
231
  	tipc_subscrb_get(subscriber);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
232
  	tipc_subscrb_subscrp_delete(subscriber, s);
fd849b7c4   Ying Xue   tipc: fix a race ...
233
  	tipc_subscrb_put(subscriber);
eb409460b   Lijun Chen   [TIPC]: Added sub...
234
  }
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
235
236
  static struct tipc_subscription *tipc_subscrp_create(struct net *net,
  						     struct tipc_subscr *s,
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
237
  						     int swap)
a62fbccec   Ying Xue   tipc: make subscr...
238
239
  {
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
fead39098   Paul Gortmaker   tipc: rename stru...
240
  	struct tipc_subscription *sub;
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
241
  	u32 filter = htohl(s->filter, swap);
eb409460b   Lijun Chen   [TIPC]: Added sub...
242

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

db5a753bf   Neil Horman   Revert d88dca79d3...
268
  	sub->swap = swap;
57f1d1868   Ying Xue   tipc: rename func...
269
  	memcpy(&sub->evt.s, s, sizeof(*s));
a62fbccec   Ying Xue   tipc: make subscr...
270
  	atomic_inc(&tn->subscription_count);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
271
  	kref_init(&sub->kref);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
272
273
274
275
  	return sub;
  }
  
  static void tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s,
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
276
  				   struct tipc_subscriber *subscriber, int swap)
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
277
278
279
280
  {
  	struct tipc_net *tn = net_generic(net, tipc_net_id);
  	struct tipc_subscription *sub = NULL;
  	u32 timeout;
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
281
  	sub = tipc_subscrp_create(net, s, swap);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
282
283
284
285
286
  	if (!sub)
  		return tipc_conn_terminate(tn->topsrv, subscriber->conid);
  
  	spin_lock_bh(&subscriber->lock);
  	list_add(&sub->subscrp_list, &subscriber->subscrp_list);
d4091899c   Parthasarathy Bhuvaragan   tipc: hold subscr...
287
288
  	sub->subscriber = subscriber;
  	tipc_nametbl_subscribe(sub);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
289
  	tipc_subscrb_get(subscriber);
7c13c6224   Parthasarathy Bhuvaragan   tipc: introduce t...
290
  	spin_unlock_bh(&subscriber->lock);
d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
291
  	setup_timer(&sub->timer, tipc_subscrp_timeout, (unsigned long)sub);
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
292
  	timeout = htohl(sub->evt.s.timeout, swap);
ae245557f   Parthasarathy Bhuvaragan   tipc: donot creat...
293

d094c4d5f   Parthasarathy Bhuvaragan   tipc: add subscri...
294
295
  	if (timeout != TIPC_WAIT_FOREVER)
  		mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
b97bf3fd8   Per Liden   [TIPC] Initial merge
296
  }
13a2e8987   Ying Xue   tipc: convert top...
297
  /* Handle one termination request for the subscriber */
333f79623   Parthasarathy Bhuvaragan   tipc: fix a race ...
298
  static void tipc_subscrb_release_cb(int conid, void *usr_data)
b97bf3fd8   Per Liden   [TIPC] Initial merge
299
  {
57f1d1868   Ying Xue   tipc: rename func...
300
  	tipc_subscrb_delete((struct tipc_subscriber *)usr_data);
b97bf3fd8   Per Liden   [TIPC] Initial merge
301
  }
13a2e8987   Ying Xue   tipc: convert top...
302
  /* Handle one request to create a new subscription for the subscriber */
57f1d1868   Ying Xue   tipc: rename func...
303
304
305
  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
306
  {
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
307
308
309
310
311
  	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...
312
313
  	swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE |
  			      TIPC_SUB_CANCEL));
c8beccc67   Parthasarathy Bhuvaragan   tipc: fix connect...
314
315
316
317
318
319
  
  	/* 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);
  	}
b43586576   Dan Carpenter   tipc: remove an u...
320
  	tipc_subscrp_subscribe(net, s, subscriber, swap);
b97bf3fd8   Per Liden   [TIPC] Initial merge
321
  }
13a2e8987   Ying Xue   tipc: convert top...
322
  /* Handle one request to establish a new subscriber */
57f1d1868   Ying Xue   tipc: rename func...
323
  static void *tipc_subscrb_connect_cb(int conid)
b97bf3fd8   Per Liden   [TIPC] Initial merge
324
  {
1b764828a   Ying Xue   tipc: introduce t...
325
  	return (void *)tipc_subscrb_create(conid);
b97bf3fd8   Per Liden   [TIPC] Initial merge
326
  }
57f1d1868   Ying Xue   tipc: rename func...
327
  int tipc_topsrv_start(struct net *net)
b97bf3fd8   Per Liden   [TIPC] Initial merge
328
  {
a62fbccec   Ying Xue   tipc: make subscr...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  	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...
354
355
  	topsrv->tipc_conn_recvmsg	= tipc_subscrb_rcv_cb;
  	topsrv->tipc_conn_new		= tipc_subscrb_connect_cb;
333f79623   Parthasarathy Bhuvaragan   tipc: fix a race ...
356
  	topsrv->tipc_conn_release	= tipc_subscrb_release_cb;
a62fbccec   Ying Xue   tipc: make subscr...
357

88b58409f   Guoqing Jiang   tipc: use destina...
358
  	strscpy(topsrv->name, name, sizeof(topsrv->name));
a62fbccec   Ying Xue   tipc: make subscr...
359
360
361
362
  	tn->topsrv = topsrv;
  	atomic_set(&tn->subscription_count, 0);
  
  	return tipc_server_start(topsrv);
b97bf3fd8   Per Liden   [TIPC] Initial merge
363
  }
57f1d1868   Ying Xue   tipc: rename func...
364
  void tipc_topsrv_stop(struct net *net)
b97bf3fd8   Per Liden   [TIPC] Initial merge
365
  {
a62fbccec   Ying Xue   tipc: make subscr...
366
367
368
369
370
371
  	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
372
  }