Blame view

net/ax25/ax25_route.c 10.7 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
8
9
10
   *
   * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
   * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
   * Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
   * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
   * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
   * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
   */
4fc268d24   Randy Dunlap   [PATCH] capable/c...
11
12
  
  #include <linux/capability.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
15
16
17
18
19
20
21
22
  #include <linux/errno.h>
  #include <linux/types.h>
  #include <linux/socket.h>
  #include <linux/timer.h>
  #include <linux/in.h>
  #include <linux/kernel.h>
  #include <linux/sched.h>
  #include <linux/string.h>
  #include <linux/sockios.h>
  #include <linux/net.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
23
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
30
  #include <net/ax25.h>
  #include <linux/inet.h>
  #include <linux/netdevice.h>
  #include <linux/if_arp.h>
  #include <linux/skbuff.h>
  #include <linux/spinlock.h>
  #include <net/sock.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
31
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
36
  #include <linux/fcntl.h>
  #include <linux/mm.h>
  #include <linux/interrupt.h>
  #include <linux/init.h>
  #include <linux/seq_file.h>
bc3b2d7fb   Paul Gortmaker   net: Add export.h...
37
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
  
  static ax25_route *ax25_route_list;
63530aba7   Eric Dumazet   ax25: fix possibl...
40
  DEFINE_RWLOCK(ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
  void ax25_rt_device_down(struct net_device *dev)
  {
  	ax25_route *s, *t, *ax25_rt;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
45
  	write_lock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
51
52
53
  	ax25_rt = ax25_route_list;
  	while (ax25_rt != NULL) {
  		s       = ax25_rt;
  		ax25_rt = ax25_rt->next;
  
  		if (s->dev == dev) {
  			if (ax25_route_list == s) {
  				ax25_route_list = s->next;
a51482bde   Jesper Juhl   [NET]: kfree cleanup
54
  				kfree(s->digipeat);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
  				kfree(s);
  			} else {
  				for (t = ax25_route_list; t != NULL; t = t->next) {
  					if (t->next == s) {
  						t->next = s->next;
a51482bde   Jesper Juhl   [NET]: kfree cleanup
60
  						kfree(s->digipeat);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
64
65
66
67
  						kfree(s);
  						break;
  					}
  				}
  			}
  		}
  	}
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
68
  	write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  }
c9266b99e   Ralf Baechle   [AX.25]: Mark all...
70
  static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
75
76
77
78
79
  {
  	ax25_route *ax25_rt;
  	ax25_dev *ax25_dev;
  	int i;
  
  	if ((ax25_dev = ax25_addr_ax25dev(&route->port_addr)) == NULL)
  		return -EINVAL;
  	if (route->digi_count > AX25_MAX_DIGIS)
  		return -EINVAL;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
80
  	write_lock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
83
84
  
  	ax25_rt = ax25_route_list;
  	while (ax25_rt != NULL) {
  		if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
528930b91   YOSHIFUJI Hideaki   [NET] AX25: Fix w...
85
  			    ax25_rt->dev == ax25_dev->dev) {
a51482bde   Jesper Juhl   [NET]: kfree cleanup
86
87
  			kfree(ax25_rt->digipeat);
  			ax25_rt->digipeat = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
  			if (route->digi_count != 0) {
  				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
90
  					write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
92
93
94
95
96
97
98
99
  					return -ENOMEM;
  				}
  				ax25_rt->digipeat->lastrepeat = -1;
  				ax25_rt->digipeat->ndigi      = route->digi_count;
  				for (i = 0; i < route->digi_count; i++) {
  					ax25_rt->digipeat->repeated[i] = 0;
  					ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
  				}
  			}
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
100
  			write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
102
103
104
105
106
  			return 0;
  		}
  		ax25_rt = ax25_rt->next;
  	}
  
  	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL) {
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
107
  		write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
109
  		return -ENOMEM;
  	}
39f25d42c   Reshetova, Elena   net, ax25: conver...
110
  	refcount_set(&ax25_rt->refcount, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
116
  	ax25_rt->callsign     = route->dest_addr;
  	ax25_rt->dev          = ax25_dev->dev;
  	ax25_rt->digipeat     = NULL;
  	ax25_rt->ip_mode      = ' ';
  	if (route->digi_count != 0) {
  		if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
117
  			write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
120
121
122
123
124
125
126
127
128
129
  			kfree(ax25_rt);
  			return -ENOMEM;
  		}
  		ax25_rt->digipeat->lastrepeat = -1;
  		ax25_rt->digipeat->ndigi      = route->digi_count;
  		for (i = 0; i < route->digi_count; i++) {
  			ax25_rt->digipeat->repeated[i] = 0;
  			ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
  		}
  	}
  	ax25_rt->next   = ax25_route_list;
  	ax25_route_list = ax25_rt;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
130
  	write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
  
  	return 0;
  }
006f68b84   Ralf Baechle   [AX.25]: Referenc...
134
  void __ax25_put_route(ax25_route *ax25_rt)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
  {
006f68b84   Ralf Baechle   [AX.25]: Referenc...
136
137
  	kfree(ax25_rt->digipeat);
  	kfree(ax25_rt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
145
146
  }
  
  static int ax25_rt_del(struct ax25_routes_struct *route)
  {
  	ax25_route *s, *t, *ax25_rt;
  	ax25_dev *ax25_dev;
  
  	if ((ax25_dev = ax25_addr_ax25dev(&route->port_addr)) == NULL)
  		return -EINVAL;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
147
  	write_lock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
149
150
151
152
153
154
155
156
  
  	ax25_rt = ax25_route_list;
  	while (ax25_rt != NULL) {
  		s       = ax25_rt;
  		ax25_rt = ax25_rt->next;
  		if (s->dev == ax25_dev->dev &&
  		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
  			if (ax25_route_list == s) {
  				ax25_route_list = s->next;
006f68b84   Ralf Baechle   [AX.25]: Referenc...
157
  				ax25_put_route(s);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
159
160
161
  			} else {
  				for (t = ax25_route_list; t != NULL; t = t->next) {
  					if (t->next == s) {
  						t->next = s->next;
006f68b84   Ralf Baechle   [AX.25]: Referenc...
162
  						ax25_put_route(s);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
164
165
166
167
168
  						break;
  					}
  				}
  			}
  		}
  	}
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
169
  	write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
174
175
176
177
178
179
180
181
  
  	return 0;
  }
  
  static int ax25_rt_opt(struct ax25_route_opt_struct *rt_option)
  {
  	ax25_route *ax25_rt;
  	ax25_dev *ax25_dev;
  	int err = 0;
  
  	if ((ax25_dev = ax25_addr_ax25dev(&rt_option->port_addr)) == NULL)
  		return -EINVAL;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
182
  	write_lock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  
  	ax25_rt = ax25_route_list;
  	while (ax25_rt != NULL) {
  		if (ax25_rt->dev == ax25_dev->dev &&
  		    ax25cmp(&rt_option->dest_addr, &ax25_rt->callsign) == 0) {
  			switch (rt_option->cmd) {
  			case AX25_SET_RT_IPMODE:
  				switch (rt_option->arg) {
  				case ' ':
  				case 'D':
  				case 'V':
  					ax25_rt->ip_mode = rt_option->arg;
  					break;
  				default:
  					err = -EINVAL;
  					goto out;
  				}
  				break;
  			default:
  				err = -EINVAL;
  				goto out;
  			}
  		}
  		ax25_rt = ax25_rt->next;
  	}
  
  out:
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
210
  	write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
  	return err;
  }
  
  int ax25_rt_ioctl(unsigned int cmd, void __user *arg)
  {
  	struct ax25_route_opt_struct rt_option;
  	struct ax25_routes_struct route;
  
  	switch (cmd) {
  	case SIOCADDRT:
  		if (copy_from_user(&route, arg, sizeof(route)))
  			return -EFAULT;
  		return ax25_rt_add(&route);
  
  	case SIOCDELRT:
  		if (copy_from_user(&route, arg, sizeof(route)))
  			return -EFAULT;
  		return ax25_rt_del(&route);
  
  	case SIOCAX25OPTRT:
  		if (copy_from_user(&rt_option, arg, sizeof(rt_option)))
  			return -EFAULT;
  		return ax25_rt_opt(&rt_option);
  
  	default:
  		return -EINVAL;
  	}
  }
  
  #ifdef CONFIG_PROC_FS
  
  static void *ax25_rt_seq_start(struct seq_file *seq, loff_t *pos)
f16f3026d   Eric Dumazet   [AX25]: sparse cl...
243
  	__acquires(ax25_route_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
246
  {
  	struct ax25_route *ax25_rt;
  	int i = 1;
528930b91   YOSHIFUJI Hideaki   [NET] AX25: Fix w...
247
248
  
  	read_lock(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  	if (*pos == 0)
  		return SEQ_START_TOKEN;
  
  	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
  		if (i == *pos)
  			return ax25_rt;
  		++i;
  	}
  
  	return NULL;
  }
  
  static void *ax25_rt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  {
  	++*pos;
528930b91   YOSHIFUJI Hideaki   [NET] AX25: Fix w...
264
  	return (v == SEQ_START_TOKEN) ? ax25_route_list :
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
268
  		((struct ax25_route *) v)->next;
  }
  
  static void ax25_rt_seq_stop(struct seq_file *seq, void *v)
f16f3026d   Eric Dumazet   [AX25]: sparse cl...
269
  	__releases(ax25_route_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
271
272
273
274
275
  {
  	read_unlock(&ax25_route_lock);
  }
  
  static int ax25_rt_seq_show(struct seq_file *seq, void *v)
  {
f75268cd6   Ralf Baechle   [AX25]: Make ax2a...
276
  	char buf[11];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
279
280
281
282
283
284
285
286
287
  	if (v == SEQ_START_TOKEN)
  		seq_puts(seq, "callsign  dev  mode digipeaters
  ");
  	else {
  		struct ax25_route *ax25_rt = v;
  		const char *callsign;
  		int i;
  
  		if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0)
  			callsign = "default";
  		else
f75268cd6   Ralf Baechle   [AX25]: Make ax2a...
288
  			callsign = ax2asc(buf, &ax25_rt->callsign);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  
  		seq_printf(seq, "%-9s %-4s",
  			callsign,
  			ax25_rt->dev ? ax25_rt->dev->name : "???");
  
  		switch (ax25_rt->ip_mode) {
  		case 'V':
  			seq_puts(seq, "   vc");
  			break;
  		case 'D':
  			seq_puts(seq, "   dg");
  			break;
  		default:
  			seq_puts(seq, "    *");
  			break;
  		}
  
  		if (ax25_rt->digipeat != NULL)
  			for (i = 0; i < ax25_rt->digipeat->ndigi; i++)
f75268cd6   Ralf Baechle   [AX25]: Make ax2a...
308
309
  				seq_printf(seq, " %s",
  				     ax2asc(buf, &ax25_rt->digipeat->calls[i]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
314
315
  
  		seq_puts(seq, "
  ");
  	}
  	return 0;
  }
fddda2b7b   Christoph Hellwig   proc: introduce p...
316
  const struct seq_operations ax25_rt_seqops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
319
320
321
  	.start = ax25_rt_seq_start,
  	.next = ax25_rt_seq_next,
  	.stop = ax25_rt_seq_stop,
  	.show = ax25_rt_seq_show,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
323
324
325
326
  #endif
  
  /*
   *	Find AX.25 route
   *
3f072310d   Ralf Baechle   [AX.25]: Spelling...
327
   *	Only routes with a reference count of zero can be destroyed.
63530aba7   Eric Dumazet   ax25: fix possibl...
328
   *	Must be called with ax25_route_lock read locked.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
   */
006f68b84   Ralf Baechle   [AX.25]: Referenc...
330
  ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
334
  {
  	ax25_route *ax25_spe_rt = NULL;
  	ax25_route *ax25_def_rt = NULL;
  	ax25_route *ax25_rt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
  	/*
  	 *	Bind to the physical interface we heard them on, or the default
  	 *	route if none is found;
  	 */
  	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
  		if (dev == NULL) {
  			if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev != NULL)
  				ax25_spe_rt = ax25_rt;
  			if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev != NULL)
  				ax25_def_rt = ax25_rt;
  		} else {
  			if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev == dev)
  				ax25_spe_rt = ax25_rt;
  			if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev == dev)
  				ax25_def_rt = ax25_rt;
  		}
  	}
  
  	ax25_rt = ax25_def_rt;
  	if (ax25_spe_rt != NULL)
  		ax25_rt = ax25_spe_rt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  	return ax25_rt;
  }
  
  /*
   *	Adjust path: If you specify a default route and want to connect
   *      a target on the digipeater path but w/o having a special route
   *	set before, the path has to be truncated from your target on.
   */
  static inline void ax25_adjust_path(ax25_address *addr, ax25_digi *digipeat)
  {
  	int k;
  
  	for (k = 0; k < digipeat->ndigi; k++) {
  		if (ax25cmp(addr, &digipeat->calls[k]) == 0)
  			break;
  	}
  
  	digipeat->ndigi = k;
  }
  
  
  /*
   *	Find which interface to use.
   */
  int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
  {
01d7dd0e9   Ralf Baechle   [AX25]: UID fixes
382
  	ax25_uid_assoc *user;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
  	ax25_route *ax25_rt;
b3d18f150   Julia Lawall   net/ax25: Use ava...
384
  	int err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385

63530aba7   Eric Dumazet   ax25: fix possibl...
386
387
388
389
  	ax25_route_lock_use();
  	ax25_rt = ax25_get_route(addr, NULL);
  	if (!ax25_rt) {
  		ax25_route_lock_unuse();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
  		return -EHOSTUNREACH;
63530aba7   Eric Dumazet   ax25: fix possibl...
391
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392
393
394
395
  	if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL) {
  		err = -EHOSTUNREACH;
  		goto put;
  	}
734004072   David Howells   CRED: Wrap task c...
396
  	user = ax25_findbyuid(current_euid());
01d7dd0e9   Ralf Baechle   [AX25]: UID fixes
397
398
399
400
  	if (user) {
  		ax25->source_addr = user->call;
  		ax25_uid_put(user);
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
402
403
404
  		if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE)) {
  			err = -EPERM;
  			goto put;
  		}
01d7dd0e9   Ralf Baechle   [AX25]: UID fixes
405
  		ax25->source_addr = *(ax25_address *)ax25->ax25_dev->dev->dev_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
  	if (ax25_rt->digipeat != NULL) {
0459d70ad   Arnaldo Carvalho de Melo   [AX25]: Use kmemdup
408
409
410
  		ax25->digipeat = kmemdup(ax25_rt->digipeat, sizeof(ax25_digi),
  					 GFP_ATOMIC);
  		if (ax25->digipeat == NULL) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
412
413
  			err = -ENOMEM;
  			goto put;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
414
415
416
417
  		ax25_adjust_path(addr, ax25->digipeat);
  	}
  
  	if (ax25->sk != NULL) {
d4d5d8e83   Eric Dumazet   ax25: fix inconsi...
418
  		local_bh_disable();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
421
  		bh_lock_sock(ax25->sk);
  		sock_reset_flag(ax25->sk, SOCK_ZAPPED);
  		bh_unlock_sock(ax25->sk);
d4d5d8e83   Eric Dumazet   ax25: fix inconsi...
422
  		local_bh_enable();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
423
424
425
  	}
  
  put:
63530aba7   Eric Dumazet   ax25: fix possibl...
426
  	ax25_route_lock_unuse();
b3d18f150   Julia Lawall   net/ax25: Use ava...
427
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
  struct sk_buff *ax25_rt_build_path(struct sk_buff *skb, ax25_address *src,
  	ax25_address *dest, ax25_digi *digi)
  {
  	struct sk_buff *skbn;
  	unsigned char *bp;
  	int len;
  
  	len = digi->ndigi * AX25_ADDR_LEN;
  
  	if (skb_headroom(skb) < len) {
  		if ((skbn = skb_realloc_headroom(skb, len)) == NULL) {
  			printk(KERN_CRIT "AX.25: ax25_dg_build_path - out of memory
  ");
  			return NULL;
  		}
  
  		if (skb->sk != NULL)
  			skb_set_owner_w(skbn, skb->sk);
5d0ba55b6   Eric Dumazet   net: use consume_...
447
  		consume_skb(skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
  
  		skb = skbn;
  	}
  
  	bp = skb_push(skb, len);
  
  	ax25_addr_build(bp, src, dest, digi, AX25_COMMAND, AX25_MODULUS);
  
  	return skb;
  }
  
  /*
   *	Free all memory associated with routing structures.
   */
  void __exit ax25_rt_free(void)
  {
  	ax25_route *s, *ax25_rt = ax25_route_list;
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
465
  	write_lock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466
467
468
  	while (ax25_rt != NULL) {
  		s       = ax25_rt;
  		ax25_rt = ax25_rt->next;
a51482bde   Jesper Juhl   [NET]: kfree cleanup
469
  		kfree(s->digipeat);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
470
471
  		kfree(s);
  	}
4de211f1a   Jarek Poplawski   [AX25] ax25_route...
472
  	write_unlock_bh(&ax25_route_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
  }