~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ax25/af_ax25.c

Version: ~ [ linux-5.1-rc1 ] ~ [ linux-5.0.3 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.30 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.107 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.164 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.176 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.136 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * This program is free software; you can redistribute it and/or modify
  3  * it under the terms of the GNU General Public License as published by
  4  * the Free Software Foundation; either version 2 of the License, or
  5  * (at your option) any later version.
  6  *
  7  * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
  8  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  9  * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
 10  * Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
 11  * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
 12  * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
 13  * Copyright (C) Hans Alblas PE1AYX (hans@esrac.ele.tue.nl)
 14  * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
 15  */
 16 #include <linux/config.h>
 17 #include <linux/module.h>
 18 #include <linux/errno.h>
 19 #include <linux/types.h>
 20 #include <linux/socket.h>
 21 #include <linux/in.h>
 22 #include <linux/kernel.h>
 23 #include <linux/sched.h>
 24 #include <linux/timer.h>
 25 #include <linux/string.h>
 26 #include <linux/smp_lock.h>
 27 #include <linux/sockios.h>
 28 #include <linux/net.h>
 29 #include <net/ax25.h>
 30 #include <linux/inet.h>
 31 #include <linux/netdevice.h>
 32 #include <linux/if_arp.h>
 33 #include <linux/skbuff.h>
 34 #include <net/sock.h>
 35 #include <asm/uaccess.h>
 36 #include <asm/system.h>
 37 #include <linux/fcntl.h>
 38 #include <linux/termios.h>      /* For TIOCINQ/OUTQ */
 39 #include <linux/mm.h>
 40 #include <linux/interrupt.h>
 41 #include <linux/notifier.h>
 42 #include <linux/proc_fs.h>
 43 #include <linux/stat.h>
 44 #include <linux/netfilter.h>
 45 #include <linux/sysctl.h>
 46 #include <linux/init.h>
 47 #include <linux/spinlock.h>
 48 #include <net/tcp.h>
 49 #include <net/ip.h>
 50 #include <net/arp.h>
 51 
 52 
 53 
 54 HLIST_HEAD(ax25_list);
 55 spinlock_t ax25_list_lock = SPIN_LOCK_UNLOCKED;
 56 
 57 static struct proto_ops ax25_proto_ops;
 58 
 59 static void ax25_free_sock(struct sock *sk)
 60 {
 61         ax25_cb_put(ax25_sk(sk));
 62 }
 63 
 64 /*
 65  *      Socket removal during an interrupt is now safe.
 66  */
 67 static void ax25_cb_del(ax25_cb *ax25)
 68 {
 69         if (!hlist_unhashed(&ax25->ax25_node)) {
 70                 spin_lock_bh(&ax25_list_lock);
 71                 hlist_del_init(&ax25->ax25_node);
 72                 spin_unlock_bh(&ax25_list_lock);
 73                 ax25_cb_put(ax25);
 74         }
 75 }
 76 
 77 /*
 78  *      Kill all bound sockets on a dropped device.
 79  */
 80 static void ax25_kill_by_device(struct net_device *dev)
 81 {
 82         ax25_dev *ax25_dev;
 83         ax25_cb *s;
 84         struct hlist_node *node;
 85 
 86         if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
 87                 return;
 88 
 89         spin_lock_bh(&ax25_list_lock);
 90         ax25_for_each(s, node, &ax25_list) {
 91                 if (s->ax25_dev == ax25_dev) {
 92                         s->ax25_dev = NULL;
 93                         ax25_disconnect(s, ENETUNREACH);
 94                 }
 95         }
 96         spin_unlock_bh(&ax25_list_lock);
 97 }
 98 
 99 /*
100  *      Handle device status changes.
101  */
102 static int ax25_device_event(struct notifier_block *this, unsigned long event,
103         void *ptr)
104 {
105         struct net_device *dev = (struct net_device *)ptr;
106 
107         /* Reject non AX.25 devices */
108         if (dev->type != ARPHRD_AX25)
109                 return NOTIFY_DONE;
110 
111         switch (event) {
112         case NETDEV_UP:
113                 ax25_dev_device_up(dev);
114                 break;
115         case NETDEV_DOWN:
116                 ax25_kill_by_device(dev);
117                 ax25_rt_device_down(dev);
118                 ax25_dev_device_down(dev);
119                 break;
120         default:
121                 break;
122         }
123 
124         return NOTIFY_DONE;
125 }
126 
127 /*
128  *      Add a socket to the bound sockets list.
129  */
130 void ax25_cb_add(ax25_cb *ax25)
131 {
132         spin_lock_bh(&ax25_list_lock);
133         ax25_cb_hold(ax25);
134         hlist_add_head(&ax25->ax25_node, &ax25_list);
135         spin_unlock_bh(&ax25_list_lock);
136 }
137 
138 /*
139  *      Find a socket that wants to accept the SABM we have just
140  *      received.
141  */
142 struct sock *ax25_find_listener(ax25_address *addr, int digi,
143         struct net_device *dev, int type)
144 {
145         ax25_cb *s;
146         struct hlist_node *node;
147 
148         spin_lock_bh(&ax25_list_lock);
149         ax25_for_each(s, node, &ax25_list) {
150                 if ((s->iamdigi && !digi) || (!s->iamdigi && digi))
151                         continue;
152                 if (s->sk && !ax25cmp(&s->source_addr, addr) &&
153                     s->sk->sk_type == type && s->sk->sk_state == TCP_LISTEN) {
154                         /* If device is null we match any device */
155                         if (s->ax25_dev == NULL || s->ax25_dev->dev == dev) {
156                                 sock_hold(s->sk);
157                                 spin_unlock_bh(&ax25_list_lock);
158                                 return s->sk;
159                         }
160                 }
161         }
162         spin_unlock_bh(&ax25_list_lock);
163 
164         return NULL;
165 }
166 
167 /*
168  *      Find an AX.25 socket given both ends.
169  */
170 struct sock *ax25_get_socket(ax25_address *my_addr, ax25_address *dest_addr,
171         int type)
172 {
173         struct sock *sk = NULL;
174         ax25_cb *s;
175         struct hlist_node *node;
176 
177         spin_lock_bh(&ax25_list_lock);
178         ax25_for_each(s, node, &ax25_list) {
179                 if (s->sk && !ax25cmp(&s->source_addr, my_addr) &&
180                     !ax25cmp(&s->dest_addr, dest_addr) &&
181                     s->sk->sk_type == type) {
182                         sk = s->sk;
183                         /* XXX Sleeps with spinlock held, use refcounts instead. XXX */
184                         lock_sock(sk);
185                         break;
186                 }
187         }
188 
189         spin_unlock_bh(&ax25_list_lock);
190 
191         return sk;
192 }
193 
194 /*
195  *      Find an AX.25 control block given both ends. It will only pick up
196  *      floating AX.25 control blocks or non Raw socket bound control blocks.
197  */
198 ax25_cb *ax25_find_cb(ax25_address *src_addr, ax25_address *dest_addr,
199         ax25_digi *digi, struct net_device *dev)
200 {
201         ax25_cb *s;
202         struct hlist_node *node;
203 
204         spin_lock_bh(&ax25_list_lock);
205         ax25_for_each(s, node, &ax25_list) {
206                 if (s->sk && s->sk->sk_type != SOCK_SEQPACKET)
207                         continue;
208                 if (s->ax25_dev == NULL)
209                         continue;
210                 if (ax25cmp(&s->source_addr, src_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->ax25_dev->dev == dev) {
211                         if (digi != NULL && digi->ndigi != 0) {
212                                 if (s->digipeat == NULL)
213                                         continue;
214                                 if (ax25digicmp(s->digipeat, digi) != 0)
215                                         continue;
216                         } else {
217                                 if (s->digipeat != NULL && s->digipeat->ndigi != 0)
218                                         continue;
219                         }
220                         ax25_cb_hold(s);
221                         spin_unlock_bh(&ax25_list_lock);
222 
223                         return s;
224                 }
225         }
226         spin_unlock_bh(&ax25_list_lock);
227 
228         return NULL;
229 }
230 
231 /*
232  *      Look for any matching address - RAW sockets can bind to arbitrary names
233  */
234 struct sock *ax25_addr_match(ax25_address *addr)
235 {
236         struct sock *sk = NULL;
237         ax25_cb *s;
238         struct hlist_node *node;
239 
240         spin_lock_bh(&ax25_list_lock);
241         ax25_for_each(s, node, &ax25_list) {
242                 if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 &&
243                     s->sk->sk_type == SOCK_RAW) {
244                         sk = s->sk;
245                         lock_sock(sk);
246                         break;
247                 }
248         }
249 
250         spin_unlock_bh(&ax25_list_lock);
251 
252         return sk;
253 }
254 
255 void ax25_send_to_raw(struct sock *sk, struct sk_buff *skb, int proto)
256 {
257         struct sk_buff *copy;
258         struct hlist_node *node;
259 
260         sk_for_each_from(sk, node)
261                 if (sk->sk_type == SOCK_RAW &&
262                     sk->sk_protocol == proto &&
263                     atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) {
264                         if ((copy = skb_clone(skb, GFP_ATOMIC)) == NULL)
265                                 return;
266 
267                         if (sock_queue_rcv_skb(sk, copy) != 0)
268                                 kfree_skb(copy);
269                 }
270 }
271 
272 /*
273  *      Deferred destroy.
274  */
275 void ax25_destroy_socket(ax25_cb *);
276 
277 /*
278  *      Handler for deferred kills.
279  */
280 static void ax25_destroy_timer(unsigned long data)
281 {
282         ax25_cb *ax25=(ax25_cb *)data;
283         struct sock *sk;
284         
285         sk=ax25->sk;
286         
287         bh_lock_sock(sk);
288         sock_hold(sk);
289         ax25_destroy_socket(ax25);
290         bh_unlock_sock(sk);
291         sock_put(sk);
292 }
293 
294 /*
295  *      This is called from user mode and the timers. Thus it protects itself
296  *      against interrupt users but doesn't worry about being called during
297  *      work. Once it is removed from the queue no interrupt or bottom half
298  *      will touch it and we are (fairly 8-) ) safe.
299  */
300 void ax25_destroy_socket(ax25_cb *ax25)
301 {
302         struct sk_buff *skb;
303 
304         ax25_cb_del(ax25);
305 
306         ax25_stop_heartbeat(ax25);
307         ax25_stop_t1timer(ax25);
308         ax25_stop_t2timer(ax25);
309         ax25_stop_t3timer(ax25);
310         ax25_stop_idletimer(ax25);
311 
312         ax25_clear_queues(ax25);        /* Flush the queues */
313 
314         if (ax25->sk != NULL) {
315                 while ((skb = skb_dequeue(&ax25->sk->sk_receive_queue)) != NULL) {
316                         if (skb->sk != ax25->sk) {
317                                 /* A pending connection */
318                                 ax25_cb *sax25 = ax25_sk(skb->sk);
319 
320                                 /* Queue the unaccepted socket for death */
321                                 sock_set_flag(skb->sk, SOCK_DEAD);
322 
323                                 ax25_start_heartbeat(sax25);
324                                 sax25->state = AX25_STATE_0;
325                         }
326 
327                         kfree_skb(skb);
328                 }
329                 while ((skb = skb_dequeue(&ax25->sk->sk_write_queue)) != NULL) {
330                         kfree_skb(skb);
331                 }
332         }
333 
334         if (ax25->sk != NULL) {
335                 if (atomic_read(&ax25->sk->sk_wmem_alloc) ||
336                     atomic_read(&ax25->sk->sk_rmem_alloc)) {
337                         /* Defer: outstanding buffers */
338                         init_timer(&ax25->dtimer);
339                         ax25->dtimer.expires  = jiffies + 2 * HZ;
340                         ax25->dtimer.function = ax25_destroy_timer;
341                         ax25->dtimer.data     = (unsigned long)ax25;
342                         add_timer(&ax25->dtimer);
343                 } else {
344                         struct sock *sk=ax25->sk;
345                         ax25->sk=NULL;
346                         sock_put(sk);
347                 }
348         } else {
349                 ax25_cb_put(ax25);
350         }
351 }
352 
353 /*
354  * dl1bke 960311: set parameters for existing AX.25 connections,
355  *                includes a KILL command to abort any connection.
356  *                VERY useful for debugging ;-)
357  */
358 static int ax25_ctl_ioctl(const unsigned int cmd, void *arg)
359 {
360         struct ax25_ctl_struct ax25_ctl;
361         ax25_digi digi;
362         ax25_dev *ax25_dev;
363         ax25_cb *ax25;
364         unsigned int k;
365 
366         if (copy_from_user(&ax25_ctl, arg, sizeof(ax25_ctl)))
367                 return -EFAULT;
368 
369         if ((ax25_dev = ax25_addr_ax25dev(&ax25_ctl.port_addr)) == NULL)
370                 return -ENODEV;
371 
372         if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
373                 return -EINVAL;
374 
375         digi.ndigi = ax25_ctl.digi_count;
376         for (k = 0; k < digi.ndigi; k++)
377                 digi.calls[k] = ax25_ctl.digi_addr[k];
378 
379         if ((ax25 = ax25_find_cb(&ax25_ctl.source_addr, &ax25_ctl.dest_addr, &digi, ax25_dev->dev)) == NULL)
380                 return -ENOTCONN;
381 
382         switch (ax25_ctl.cmd) {
383         case AX25_KILL:
384                 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
385 #ifdef CONFIG_AX25_DAMA_SLAVE
386                 if (ax25_dev->dama.slave && ax25->ax25_dev->values[AX25_VALUES_PROTOCOL] == AX25_PROTO_DAMA_SLAVE)
387                         ax25_dama_off(ax25);
388 #endif
389                 ax25_disconnect(ax25, ENETRESET);
390                 break;
391 
392         case AX25_WINDOW:
393                 if (ax25->modulus == AX25_MODULUS) {
394                         if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
395                                 return -EINVAL;
396                 } else {
397                         if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
398                                 return -EINVAL;
399                 }
400                 ax25->window = ax25_ctl.arg;
401                 break;
402 
403         case AX25_T1:
404                 if (ax25_ctl.arg < 1)
405                         return -EINVAL;
406                 ax25->rtt = (ax25_ctl.arg * HZ) / 2;
407                 ax25->t1  = ax25_ctl.arg * HZ;
408                 break;
409 
410         case AX25_T2:
411                 if (ax25_ctl.arg < 1)
412                         return -EINVAL;
413                 ax25->t2 = ax25_ctl.arg * HZ;
414                 break;
415 
416         case AX25_N2:
417                 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
418                         return -EINVAL;
419                 ax25->n2count = 0;
420                 ax25->n2 = ax25_ctl.arg;
421                 break;
422 
423         case AX25_T3:
424                 if (ax25_ctl.arg < 0)
425                         return -EINVAL;
426                 ax25->t3 = ax25_ctl.arg * HZ;
427                 break;
428 
429         case AX25_IDLE:
430                 if (ax25_ctl.arg < 0)
431                         return -EINVAL;
432                 ax25->idle = ax25_ctl.arg * 60 * HZ;
433                 break;
434 
435         case AX25_PACLEN:
436                 if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
437                         return -EINVAL;
438                 ax25->paclen = ax25_ctl.arg;
439                 break;
440 
441         default:
442                 return -EINVAL;
443           }
444 
445         return 0;
446 }
447 
448 /*
449  *      Fill in a created AX.25 created control block with the default
450  *      values for a particular device.
451  */
452 void ax25_fillin_cb(ax25_cb *ax25, ax25_dev *ax25_dev)
453 {
454         ax25->ax25_dev = ax25_dev;
455 
456         if (ax25->ax25_dev != NULL) {
457                 ax25->rtt     = ax25_dev->values[AX25_VALUES_T1] / 2;
458                 ax25->t1      = ax25_dev->values[AX25_VALUES_T1];
459                 ax25->t2      = ax25_dev->values[AX25_VALUES_T2];
460                 ax25->t3      = ax25_dev->values[AX25_VALUES_T3];
461                 ax25->n2      = ax25_dev->values[AX25_VALUES_N2];
462                 ax25->paclen  = ax25_dev->values[AX25_VALUES_PACLEN];
463                 ax25->idle    = ax25_dev->values[AX25_VALUES_IDLE];
464                 ax25->backoff = ax25_dev->values[AX25_VALUES_BACKOFF];
465 
466                 if (ax25_dev->values[AX25_VALUES_AXDEFMODE]) {
467                         ax25->modulus = AX25_EMODULUS;
468                         ax25->window  = ax25_dev->values[AX25_VALUES_EWINDOW];
469                 } else {
470                         ax25->modulus = AX25_MODULUS;
471                         ax25->window  = ax25_dev->values[AX25_VALUES_WINDOW];
472                 }
473         } else {
474                 ax25->rtt     = AX25_DEF_T1 / 2;
475                 ax25->t1      = AX25_DEF_T1;
476                 ax25->t2      = AX25_DEF_T2;
477                 ax25->t3      = AX25_DEF_T3;
478                 ax25->n2      = AX25_DEF_N2;
479                 ax25->paclen  = AX25_DEF_PACLEN;
480                 ax25->idle    = AX25_DEF_IDLE;
481                 ax25->backoff = AX25_DEF_BACKOFF;
482 
483                 if (AX25_DEF_AXDEFMODE) {
484                         ax25->modulus = AX25_EMODULUS;
485                         ax25->window  = AX25_DEF_EWINDOW;
486                 } else {
487                         ax25->modulus = AX25_MODULUS;
488                         ax25->window  = AX25_DEF_WINDOW;
489                 }
490         }
491 }
492 
493 /*
494  * Create an empty AX.25 control block.
495  */
496 ax25_cb *ax25_create_cb(void)
497 {
498         ax25_cb *ax25;
499 
500         if ((ax25 = kmalloc(sizeof(*ax25), GFP_ATOMIC)) == NULL)
501                 return NULL;
502 
503         memset(ax25, 0x00, sizeof(*ax25));
504         atomic_set(&ax25->refcount, 1);
505 
506         skb_queue_head_init(&ax25->write_queue);
507         skb_queue_head_init(&ax25->frag_queue);
508         skb_queue_head_init(&ax25->ack_queue);
509         skb_queue_head_init(&ax25->reseq_queue);
510 
511         init_timer(&ax25->timer);
512         init_timer(&ax25->t1timer);
513         init_timer(&ax25->t2timer);
514         init_timer(&ax25->t3timer);
515         init_timer(&ax25->idletimer);
516 
517         ax25_fillin_cb(ax25, NULL);
518 
519         ax25->state = AX25_STATE_0;
520 
521         return ax25;
522 }
523 
524 /*
525  *      Handling for system calls applied via the various interfaces to an
526  *      AX25 socket object
527  */
528 
529 static int ax25_setsockopt(struct socket *sock, int level, int optname,
530         char *optval, int optlen)
531 {
532         struct sock *sk = sock->sk;
533         ax25_cb *ax25;
534         struct net_device *dev;
535         char devname[IFNAMSIZ];
536         int opt, res = 0;
537 
538         if (level != SOL_AX25)
539                 return -ENOPROTOOPT;
540 
541         if (optlen < sizeof(int))
542                 return -EINVAL;
543 
544         if (get_user(opt, (int *)optval))
545                 return -EFAULT;
546 
547         lock_sock(sk);
548         ax25 = ax25_sk(sk);
549 
550         switch (optname) {
551         case AX25_WINDOW:
552                 if (ax25->modulus == AX25_MODULUS) {
553                         if (opt < 1 || opt > 7) {
554                                 res = -EINVAL;
555                                 break;
556                         }
557                 } else {
558                         if (opt < 1 || opt > 63) {
559                                 res = -EINVAL;
560                                 break;
561                         }
562                 }
563                 ax25->window = opt;
564                 break;
565 
566         case AX25_T1:
567                 if (opt < 1) {
568                         res = -EINVAL;
569                         break;
570                 }
571                 ax25->rtt = (opt * HZ) / 2;
572                 ax25->t1  = opt * HZ;
573                 break;
574 
575         case AX25_T2:
576                 if (opt < 1) {
577                         res = -EINVAL;
578                         break;
579                 }
580                 ax25->t2 = opt * HZ;
581                 break;
582 
583         case AX25_N2:
584                 if (opt < 1 || opt > 31) {
585                         res = -EINVAL;
586                         break;
587                 }
588                 ax25->n2 = opt;
589                 break;
590 
591         case AX25_T3:
592                 if (opt < 1) {
593                         res = -EINVAL;
594                         break;
595                 }
596                 ax25->t3 = opt * HZ;
597                 break;
598 
599         case AX25_IDLE:
600                 if (opt < 0) {
601                         res = -EINVAL;
602                         break;
603                 }
604                 ax25->idle = opt * 60 * HZ;
605                 break;
606 
607         case AX25_BACKOFF:
608                 if (opt < 0 || opt > 2) {
609                         res = -EINVAL;
610                         break;
611                 }
612                 ax25->backoff = opt;
613                 break;
614 
615         case AX25_EXTSEQ:
616                 ax25->modulus = opt ? AX25_EMODULUS : AX25_MODULUS;
617                 break;
618 
619         case AX25_PIDINCL:
620                 ax25->pidincl = opt ? 1 : 0;
621                 break;
622 
623         case AX25_IAMDIGI:
624                 ax25->iamdigi = opt ? 1 : 0;
625                 break;
626 
627         case AX25_PACLEN:
628                 if (opt < 16 || opt > 65535) {
629                         res = -EINVAL;
630                         break;
631                 }
632                 ax25->paclen = opt;
633                 break;
634 
635         case SO_BINDTODEVICE:
636                 if (optlen > IFNAMSIZ)
637                         optlen=IFNAMSIZ;
638                 if (copy_from_user(devname, optval, optlen)) {
639                 res = -EFAULT;
640                         break;
641                 }
642 
643                 dev = dev_get_by_name(devname);
644                 if (dev == NULL) {
645                         res = -ENODEV;
646                         break;
647                 }
648 
649                 if (sk->sk_type == SOCK_SEQPACKET &&
650                    (sock->state != SS_UNCONNECTED ||
651                     sk->sk_state == TCP_LISTEN)) {
652                         res = -EADDRNOTAVAIL;
653                         dev_put(dev);
654                         break;
655                 }
656 
657                 ax25->ax25_dev = ax25_dev_ax25dev(dev);
658                 ax25_fillin_cb(ax25, ax25->ax25_dev);
659                 break;
660 
661         default:
662                 res = -ENOPROTOOPT;
663         }
664         release_sock(sk);
665 
666         return res;
667 }
668 
669 static int ax25_getsockopt(struct socket *sock, int level, int optname,
670         char *optval, int *optlen)
671 {
672         struct sock *sk = sock->sk;
673         ax25_cb *ax25;
674         struct ax25_dev *ax25_dev;
675         char devname[IFNAMSIZ];
676         void *valptr;
677         int val = 0;
678         int maxlen, length;
679 
680         if (level != SOL_AX25)
681                 return -ENOPROTOOPT;
682 
683         if (get_user(maxlen, optlen))
684                 return -EFAULT;
685 
686         if (maxlen < 1)
687                 return -EFAULT;
688 
689         valptr = (void *) &val;
690         length = min_t(unsigned int, maxlen, sizeof(int));
691 
692         lock_sock(sk);
693         ax25 = ax25_sk(sk);
694 
695         switch (optname) {
696         case AX25_WINDOW:
697                 val = ax25->window;
698                 break;
699 
700         case AX25_T1:
701                 val = ax25->t1 / HZ;
702                 break;
703 
704         case AX25_T2:
705                 val = ax25->t2 / HZ;
706                 break;
707 
708         case AX25_N2:
709                 val = ax25->n2;
710                 break;
711 
712         case AX25_T3:
713                 val = ax25->t3 / HZ;
714                 break;
715 
716         case AX25_IDLE:
717                 val = ax25->idle / (60 * HZ);
718                 break;
719 
720         case AX25_BACKOFF:
721                 val = ax25->backoff;
722                 break;
723 
724         case AX25_EXTSEQ:
725                 val = (ax25->modulus == AX25_EMODULUS);
726                 break;
727 
728         case AX25_PIDINCL:
729                 val = ax25->pidincl;
730                 break;
731 
732         case AX25_IAMDIGI:
733                 val = ax25->iamdigi;
734                 break;
735 
736         case AX25_PACLEN:
737                 val = ax25->paclen;
738                 break;
739 
740         case SO_BINDTODEVICE:
741                 ax25_dev = ax25->ax25_dev;
742 
743                 if (ax25_dev != NULL && ax25_dev->dev != NULL) {
744                         strlcpy(devname, ax25_dev->dev->name, sizeof(devname));
745                         length = strlen(devname) + 1;
746                 } else {
747                         *devname = '\0';
748                         length = 1;
749                 }
750 
751                 valptr = (void *) devname;
752                 break;
753 
754         default:
755                 release_sock(sk);
756                 return -ENOPROTOOPT;
757         }
758         release_sock(sk);
759 
760         if (put_user(length, optlen))
761                 return -EFAULT;
762 
763         return copy_to_user(optval, valptr, length) ? -EFAULT : 0;
764 }
765 
766 static int ax25_listen(struct socket *sock, int backlog)
767 {
768         struct sock *sk = sock->sk;
769         int res = 0;
770 
771         lock_sock(sk);
772         if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_LISTEN) {
773                 sk->sk_max_ack_backlog = backlog;
774                 sk->sk_state           = TCP_LISTEN;
775                 goto out;
776         }
777         res = -EOPNOTSUPP;
778 
779 out:
780         release_sock(sk);
781 
782         return res;
783 }
784 
785 int ax25_create(struct socket *sock, int protocol)
786 {
787         struct sock *sk;
788         ax25_cb *ax25;
789 
790         switch (sock->type) {
791         case SOCK_DGRAM:
792                 if (protocol == 0 || protocol == PF_AX25)
793                         protocol = AX25_P_TEXT;
794                 break;
795 
796         case SOCK_SEQPACKET:
797                 switch (protocol) {
798                 case 0:
799                 case PF_AX25:   /* For CLX */
800                         protocol = AX25_P_TEXT;
801                         break;
802                 case AX25_P_SEGMENT:
803 #ifdef CONFIG_INET
804                 case AX25_P_ARP:
805                 case AX25_P_IP:
806 #endif
807 #ifdef CONFIG_NETROM
808                 case AX25_P_NETROM:
809 #endif
810 #ifdef CONFIG_ROSE
811                 case AX25_P_ROSE:
812 #endif
813                         return -ESOCKTNOSUPPORT;
814 #ifdef CONFIG_NETROM_MODULE
815                 case AX25_P_NETROM:
816                         if (ax25_protocol_is_registered(AX25_P_NETROM))
817                                 return -ESOCKTNOSUPPORT;
818 #endif
819 #ifdef CONFIG_ROSE_MODULE
820                 case AX25_P_ROSE:
821                         if (ax25_protocol_is_registered(AX25_P_ROSE))
822                                 return -ESOCKTNOSUPPORT;
823 #endif
824                 default:
825                         break;
826                 }
827                 break;
828 
829         case SOCK_RAW:
830                 break;
831         default:
832                 return -ESOCKTNOSUPPORT;
833         }
834 
835         if ((sk = sk_alloc(PF_AX25, GFP_ATOMIC, 1, NULL)) == NULL)
836                 return -ENOMEM;
837 
838         ax25 = ax25_sk(sk) = ax25_create_cb();
839         if (!ax25) {
840                 sk_free(sk);
841                 return -ENOMEM;
842         }
843 
844         sock_init_data(sock, sk);
845         sk_set_owner(sk, THIS_MODULE);
846 
847         sk->sk_destruct = ax25_free_sock;
848         sock->ops    = &ax25_proto_ops;
849         sk->sk_protocol = protocol;
850 
851         ax25->sk    = sk;
852 
853         return 0;
854 }
855 
856 struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
857 {
858         struct sock *sk;
859         ax25_cb *ax25, *oax25;
860 
861         if ((sk = sk_alloc(PF_AX25, GFP_ATOMIC, 1, NULL)) == NULL)
862                 return NULL;
863 
864         if ((ax25 = ax25_create_cb()) == NULL) {
865                 sk_free(sk);
866                 return NULL;
867         }
868 
869         switch (osk->sk_type) {
870         case SOCK_DGRAM:
871                 break;
872         case SOCK_SEQPACKET:
873                 break;
874         default:
875                 sk_free(sk);
876                 ax25_cb_put(ax25);
877                 return NULL;
878         }
879 
880         sock_init_data(NULL, sk);
881         sk_set_owner(sk, THIS_MODULE);
882 
883         sk->sk_destruct = ax25_free_sock;
884         sk->sk_type     = osk->sk_type;
885         sk->sk_socket   = osk->sk_socket;
886         sk->sk_priority = osk->sk_priority;
887         sk->sk_protocol = osk->sk_protocol;
888         sk->sk_rcvbuf   = osk->sk_rcvbuf;
889         sk->sk_sndbuf   = osk->sk_sndbuf;
890         sk->sk_debug    = osk->sk_debug;
891         sk->sk_state    = TCP_ESTABLISHED;
892         sk->sk_sleep    = osk->sk_sleep;
893         sk->sk_zapped   = osk->sk_zapped;
894 
895         oax25 = ax25_sk(osk);
896 
897         ax25->modulus = oax25->modulus;
898         ax25->backoff = oax25->backoff;
899         ax25->pidincl = oax25->pidincl;
900         ax25->iamdigi = oax25->iamdigi;
901         ax25->rtt     = oax25->rtt;
902         ax25->t1      = oax25->t1;
903         ax25->t2      = oax25->t2;
904         ax25->t3      = oax25->t3;
905         ax25->n2      = oax25->n2;
906         ax25->idle    = oax25->idle;
907         ax25->paclen  = oax25->paclen;
908         ax25->window  = oax25->window;
909 
910         ax25->ax25_dev    = ax25_dev;
911         ax25->source_addr = oax25->source_addr;
912 
913         if (oax25->digipeat != NULL) {
914                 if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
915                         sk_free(sk);
916                         return NULL;
917                 }
918 
919                 memcpy(ax25->digipeat, oax25->digipeat, sizeof(ax25_digi));
920         }
921 
922         ax25_sk(sk) = ax25;
923         ax25->sk    = sk;
924 
925         return sk;
926 }
927 
928 static int ax25_release(struct socket *sock)
929 {
930         struct sock *sk = sock->sk;
931         ax25_cb *ax25;
932 
933         if (sk == NULL)
934                 return 0;
935 
936         sock_hold(sk);
937         lock_sock(sk);
938         ax25 = ax25_sk(sk);
939 
940         if (sk->sk_type == SOCK_SEQPACKET) {
941                 switch (ax25->state) {
942                 case AX25_STATE_0:
943                         ax25_disconnect(ax25, 0);
944                         ax25_destroy_socket(ax25);
945                         break;
946 
947                 case AX25_STATE_1:
948                 case AX25_STATE_2:
949                         ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
950                         ax25_disconnect(ax25, 0);
951                         ax25_destroy_socket(ax25);
952                         break;
953 
954                 case AX25_STATE_3:
955                 case AX25_STATE_4:
956                         ax25_clear_queues(ax25);
957                         ax25->n2count = 0;
958 
959                         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
960                         case AX25_PROTO_STD_SIMPLEX:
961                         case AX25_PROTO_STD_DUPLEX:
962                                 ax25_send_control(ax25,
963                                                   AX25_DISC,
964                                                   AX25_POLLON,
965                                                   AX25_COMMAND);
966                                 ax25_stop_t2timer(ax25);
967                                 ax25_stop_t3timer(ax25);
968                                 ax25_stop_idletimer(ax25);
969                                 break;
970 #ifdef CONFIG_AX25_DAMA_SLAVE
971                         case AX25_PROTO_DAMA_SLAVE:
972                                 ax25_stop_t3timer(ax25);
973                                 ax25_stop_idletimer(ax25);
974                                 break;
975 #endif
976                         }
977                         ax25_calculate_t1(ax25);
978                         ax25_start_t1timer(ax25);
979                         ax25->state = AX25_STATE_2;
980                         sk->sk_state                = TCP_CLOSE;
981                         sk->sk_shutdown            |= SEND_SHUTDOWN;
982                         sk->sk_state_change(sk);
983                         sock_set_flag(sk, SOCK_DEAD);
984                         sock_set_flag(sk, SOCK_DESTROY);
985                         break;
986 
987                 default:
988                         break;
989                 }
990         } else {
991                 sk->sk_state     = TCP_CLOSE;
992                 sk->sk_shutdown |= SEND_SHUTDOWN;
993                 sk->sk_state_change(sk);
994                 sock_set_flag(sk, SOCK_DEAD);
995                 ax25_destroy_socket(ax25);
996         }
997 
998         sock->sk   = NULL;
999         sk->sk_socket = NULL;   /* Not used, but we should do this */
1000         release_sock(sk);
1001         sock_put(sk);
1002 
1003         return 0;
1004 }
1005 
1006 /*
1007  *      We support a funny extension here so you can (as root) give any callsign
1008  *      digipeated via a local address as source. This hack is obsolete now
1009  *      that we've implemented support for SO_BINDTODEVICE. It is however small
1010  *      and trivially backward compatible.
1011  */
1012 static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1013 {
1014         struct sock *sk = sock->sk;
1015         struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
1016         ax25_dev *ax25_dev = NULL;
1017         ax25_address *call;
1018         ax25_cb *ax25;
1019         int err = 0;
1020 
1021         if (addr_len != sizeof(struct sockaddr_ax25) &&
1022             addr_len != sizeof(struct full_sockaddr_ax25)) {
1023                 /* support for old structure may go away some time */
1024                 if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
1025                     (addr_len > sizeof(struct full_sockaddr_ax25))) {
1026                         return -EINVAL;
1027         }
1028 
1029                 printk(KERN_WARNING "ax25_bind(): %s uses old (6 digipeater) socket structure.\n",
1030                         current->comm);
1031         }
1032 
1033         if (addr->fsa_ax25.sax25_family != AF_AX25)
1034                 return -EINVAL;
1035 
1036         call = ax25_findbyuid(current->euid);
1037         if (call == NULL && ax25_uid_policy && !capable(CAP_NET_ADMIN)) {
1038                 return -EACCES;
1039         }
1040 
1041         lock_sock(sk);
1042 
1043         ax25 = ax25_sk(sk);
1044         if (!sk->sk_zapped) {
1045                 err = -EINVAL;
1046                 goto out;
1047         }
1048 
1049         if (call == NULL)
1050                 ax25->source_addr = addr->fsa_ax25.sax25_call;
1051         else
1052                 ax25->source_addr = *call;
1053 
1054         /*
1055          * User already set interface with SO_BINDTODEVICE
1056          */
1057         if (ax25->ax25_dev != NULL)
1058                 goto done;
1059 
1060         if (addr_len > sizeof(struct sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) {
1061                 if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) != 0 &&
1062                     (ax25_dev = ax25_addr_ax25dev(&addr->fsa_digipeater[0])) == NULL) {
1063                         err = -EADDRNOTAVAIL;
1064                         goto out;
1065                 }
1066         } else {
1067                 if ((ax25_dev = ax25_addr_ax25dev(&addr->fsa_ax25.sax25_call)) == NULL) {
1068                         err = -EADDRNOTAVAIL;
1069                         goto out;
1070                 }
1071         }
1072 
1073         if (ax25_dev != NULL)
1074                 ax25_fillin_cb(ax25, ax25_dev);
1075 
1076 done:
1077         ax25_cb_add(ax25);
1078         sk->sk_zapped = 0;
1079 
1080 out:
1081         release_sock(sk);
1082 
1083         return 0;
1084 }
1085 
1086 /*
1087  *      FIXME: nonblock behaviour looks like it may have a bug.
1088  */
1089 static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
1090         int addr_len, int flags)
1091 {
1092         struct sock *sk = sock->sk;
1093         ax25_cb *ax25 = ax25_sk(sk), *ax25t;
1094         struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
1095         ax25_digi *digi = NULL;
1096         int ct = 0, err = 0;
1097 
1098         /*
1099          * some sanity checks. code further down depends on this
1100          */
1101 
1102         if (addr_len == sizeof(struct sockaddr_ax25)) {
1103                 /* support for this will go away in early 2.5.x */
1104                 printk(KERN_WARNING "ax25_connect(): %s uses obsolete socket structure\n",
1105                         current->comm);
1106         }
1107         else if (addr_len != sizeof(struct full_sockaddr_ax25)) {
1108                 /* support for old structure may go away some time */
1109                 if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
1110                     (addr_len > sizeof(struct full_sockaddr_ax25))) {
1111                         return -EINVAL;
1112                 }
1113 
1114                 printk(KERN_WARNING "ax25_connect(): %s uses old (6 digipeater) socket structure.\n",
1115                         current->comm);
1116         }
1117 
1118         if (fsa->fsa_ax25.sax25_family != AF_AX25)
1119                 return -EINVAL;
1120 
1121         lock_sock(sk);
1122 
1123         /* deal with restarts */
1124         if (sock->state == SS_CONNECTING) {
1125                 switch (sk->sk_state) {
1126                 case TCP_SYN_SENT: /* still trying */
1127                         err = -EINPROGRESS;
1128                         goto out;
1129 
1130                 case TCP_ESTABLISHED: /* connection established */
1131                         sock->state = SS_CONNECTED;
1132                         goto out;
1133 
1134                 case TCP_CLOSE: /* connection refused */
1135                         sock->state = SS_UNCONNECTED;
1136                         err = -ECONNREFUSED;
1137                         goto out;
1138                 }
1139         }
1140 
1141         if (sk->sk_state == TCP_ESTABLISHED && sk->sk_type == SOCK_SEQPACKET) {
1142                 err = -EISCONN; /* No reconnect on a seqpacket socket */
1143                 goto out;
1144         }
1145 
1146         sk->sk_state   = TCP_CLOSE;
1147         sock->state = SS_UNCONNECTED;
1148 
1149         if (ax25->digipeat != NULL) {
1150                 kfree(ax25->digipeat);
1151                 ax25->digipeat = NULL;
1152         }
1153 
1154         /*
1155          *      Handle digi-peaters to be used.
1156          */
1157         if (addr_len > sizeof(struct sockaddr_ax25) &&
1158             fsa->fsa_ax25.sax25_ndigis != 0) {
1159                 /* Valid number of digipeaters ? */
1160                 if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS) {
1161                         err = -EINVAL;
1162                         goto out;
1163                 }
1164 
1165                 if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
1166                         err = -ENOBUFS;
1167                         goto out;
1168                 }
1169 
1170                 digi->ndigi      = fsa->fsa_ax25.sax25_ndigis;
1171                 digi->lastrepeat = -1;
1172 
1173                 while (ct < fsa->fsa_ax25.sax25_ndigis) {
1174                         if ((fsa->fsa_digipeater[ct].ax25_call[6] &
1175                              AX25_HBIT) && ax25->iamdigi) {
1176                                 digi->repeated[ct] = 1;
1177                                 digi->lastrepeat   = ct;
1178                         } else {
1179                                 digi->repeated[ct] = 0;
1180                         }
1181                         digi->calls[ct] = fsa->fsa_digipeater[ct];
1182                         ct++;
1183                 }
1184         }
1185 
1186         /*
1187          *      Must bind first - autobinding in this may or may not work. If
1188          *      the socket is already bound, check to see if the device has
1189          *      been filled in, error if it hasn't.
1190          */
1191         if (sk->sk_zapped) {
1192                 /* check if we can remove this feature. It is broken. */
1193                 printk(KERN_WARNING "ax25_connect(): %s uses autobind, please contact jreuter@yaina.de\n",
1194                         current->comm);
1195                 if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0)
1196                         goto out;
1197 
1198                 ax25_fillin_cb(ax25, ax25->ax25_dev);
1199                 ax25_cb_add(ax25);
1200         } else {
1201                 if (ax25->ax25_dev == NULL) {
1202                         err = -EHOSTUNREACH;
1203                         goto out;
1204                 }
1205         }
1206 
1207         if (sk->sk_type == SOCK_SEQPACKET &&
1208             (ax25t=ax25_find_cb(&ax25->source_addr, &fsa->fsa_ax25.sax25_call, digi,
1209                          ax25->ax25_dev->dev))) {
1210                 if (digi != NULL)
1211                         kfree(digi);
1212                 err = -EADDRINUSE;              /* Already such a connection */
1213                 ax25_cb_put(ax25t);
1214                 goto out;
1215         }
1216 
1217         ax25->dest_addr = fsa->fsa_ax25.sax25_call;
1218         ax25->digipeat  = digi;
1219 
1220         /* First the easy one */
1221         if (sk->sk_type != SOCK_SEQPACKET) {
1222                 sock->state = SS_CONNECTED;
1223                 sk->sk_state   = TCP_ESTABLISHED;
1224                 goto out;
1225         }
1226 
1227         /* Move to connecting socket, ax.25 lapb WAIT_UA.. */
1228         sock->state        = SS_CONNECTING;
1229         sk->sk_state          = TCP_SYN_SENT;
1230 
1231         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
1232         case AX25_PROTO_STD_SIMPLEX:
1233         case AX25_PROTO_STD_DUPLEX:
1234                 ax25_std_establish_data_link(ax25);
1235                 break;
1236 
1237 #ifdef CONFIG_AX25_DAMA_SLAVE
1238         case AX25_PROTO_DAMA_SLAVE:
1239                 ax25->modulus = AX25_MODULUS;
1240                 ax25->window  = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
1241                 if (ax25->ax25_dev->dama.slave)
1242                         ax25_ds_establish_data_link(ax25);
1243                 else
1244                         ax25_std_establish_data_link(ax25);
1245                 break;
1246 #endif
1247         }
1248 
1249         ax25->state = AX25_STATE_1;
1250 
1251         ax25_start_heartbeat(ax25);
1252 
1253         /* Now the loop */
1254         if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
1255                 err = -EINPROGRESS;
1256                 goto out;
1257         }
1258 
1259         if (sk->sk_state == TCP_SYN_SENT) {
1260                 struct task_struct *tsk = current;
1261                 DECLARE_WAITQUEUE(wait, tsk);
1262 
1263                 add_wait_queue(sk->sk_sleep, &wait);
1264                 for (;;) {
1265                         if (sk->sk_state != TCP_SYN_SENT)
1266                                 break;
1267                         set_current_state(TASK_INTERRUPTIBLE);
1268                         release_sock(sk);
1269                         if (!signal_pending(tsk)) {
1270                                 schedule();
1271                                 lock_sock(sk);
1272                                 continue;
1273                         }
1274                         current->state = TASK_RUNNING;
1275                         remove_wait_queue(sk->sk_sleep, &wait);
1276                         return -ERESTARTSYS;
1277                 }
1278                 current->state = TASK_RUNNING;
1279                 remove_wait_queue(sk->sk_sleep, &wait);
1280         }
1281 
1282         if (sk->sk_state != TCP_ESTABLISHED) {
1283                 /* Not in ABM, not in WAIT_UA -> failed */
1284                 sock->state = SS_UNCONNECTED;
1285                 err = sock_error(sk);   /* Always set at this point */
1286                 goto out;
1287         }
1288 
1289         sock->state = SS_CONNECTED;
1290 
1291         err=0;
1292 out:
1293         release_sock(sk);
1294 
1295         return err;
1296 }
1297 
1298 
1299 static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
1300 {
1301         struct task_struct *tsk = current;
1302         DECLARE_WAITQUEUE(wait, tsk);
1303         struct sk_buff *skb;
1304         struct sock *newsk;
1305         struct sock *sk;
1306         int err = 0;
1307 
1308         if (sock->state != SS_UNCONNECTED)
1309                 return -EINVAL;
1310 
1311         if ((sk = sock->sk) == NULL)
1312                 return -EINVAL;
1313 
1314         lock_sock(sk);
1315         if (sk->sk_type != SOCK_SEQPACKET) {
1316                 err = -EOPNOTSUPP;
1317                 goto out;
1318         }
1319 
1320         if (sk->sk_state != TCP_LISTEN) {
1321                 err = -EINVAL;
1322                 goto out;
1323         }
1324 
1325         /*
1326          *      The read queue this time is holding sockets ready to use
1327          *      hooked into the SABM we saved
1328          */
1329         add_wait_queue(sk->sk_sleep, &wait);
1330         for (;;) {
1331                 skb = skb_dequeue(&sk->sk_receive_queue);
1332                 if (skb)
1333                         break;
1334 
1335                 release_sock(sk);
1336                 current->state = TASK_INTERRUPTIBLE;
1337                 if (flags & O_NONBLOCK)
1338                         return -EWOULDBLOCK;
1339                 if (!signal_pending(tsk)) {
1340                         schedule();
1341                         current->state = TASK_RUNNING;
1342                         lock_sock(sk);
1343                         continue;
1344                 }
1345                 current->state = TASK_RUNNING;
1346                 remove_wait_queue(sk->sk_sleep, &wait);
1347                 return -ERESTARTSYS;
1348         }
1349         current->state = TASK_RUNNING;
1350         remove_wait_queue(sk->sk_sleep, &wait);
1351 
1352         newsk            = skb->sk;
1353         newsk->sk_pair   = NULL;
1354         newsk->sk_socket = newsock;
1355         newsk->sk_sleep  = &newsock->wait;
1356 
1357         /* Now attach up the new socket */
1358         kfree_skb(skb);
1359         sk->sk_ack_backlog--;
1360         newsock->sk    = newsk;
1361         newsock->state = SS_CONNECTED;
1362 
1363 out:
1364         release_sock(sk);
1365 
1366         return err;
1367 }
1368 
1369 static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
1370         int *uaddr_len, int peer)
1371 {
1372         struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
1373         struct sock *sk = sock->sk;
1374         unsigned char ndigi, i;
1375         ax25_cb *ax25;
1376         int err = 0;
1377 
1378         lock_sock(sk);
1379         ax25 = ax25_sk(sk);
1380 
1381         if (peer != 0) {
1382                 if (sk->sk_state != TCP_ESTABLISHED) {
1383                         err = -ENOTCONN;
1384                         goto out;
1385                 }
1386 
1387                 fsa->fsa_ax25.sax25_family = AF_AX25;
1388                 fsa->fsa_ax25.sax25_call   = ax25->dest_addr;
1389                 fsa->fsa_ax25.sax25_ndigis = 0;
1390 
1391                 if (ax25->digipeat != NULL) {
1392                         ndigi = ax25->digipeat->ndigi;
1393                         fsa->fsa_ax25.sax25_ndigis = ndigi;
1394                         for (i = 0; i < ndigi; i++)
1395                                 fsa->fsa_digipeater[i] =
1396                                                 ax25->digipeat->calls[i];
1397                 }
1398         } else {
1399                 fsa->fsa_ax25.sax25_family = AF_AX25;
1400                 fsa->fsa_ax25.sax25_call   = ax25->source_addr;
1401                 fsa->fsa_ax25.sax25_ndigis = 1;
1402                 if (ax25->ax25_dev != NULL) {
1403                         memcpy(&fsa->fsa_digipeater[0],
1404                                ax25->ax25_dev->dev->dev_addr, AX25_ADDR_LEN);
1405                 } else {
1406                         fsa->fsa_digipeater[0] = null_ax25_address;
1407                 }
1408         }
1409         *uaddr_len = sizeof (struct full_sockaddr_ax25);
1410 
1411 out:
1412         release_sock(sk);
1413 
1414         return err;
1415 }
1416 
1417 static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
1418                         struct msghdr *msg, int len)
1419 {
1420         struct sockaddr_ax25 *usax = (struct sockaddr_ax25 *)msg->msg_name;
1421         struct sock *sk = sock->sk;
1422         struct sockaddr_ax25 sax;
1423         struct sk_buff *skb;
1424         ax25_digi dtmp, *dp;
1425         unsigned char *asmptr;
1426         ax25_cb *ax25;
1427         int lv, size, err, addr_len = msg->msg_namelen;
1428 
1429         if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR)) {
1430                 return -EINVAL;
1431         }
1432 
1433         lock_sock(sk);
1434         ax25 = ax25_sk(sk);
1435 
1436         if (sk->sk_zapped) {
1437                 err = -EADDRNOTAVAIL;
1438                 goto out;
1439         }
1440 
1441         if (sk->sk_shutdown & SEND_SHUTDOWN) {
1442                 send_sig(SIGPIPE, current, 0);
1443                 err = -EPIPE;
1444                 goto out;
1445         }
1446 
1447         if (ax25->ax25_dev == NULL) {
1448                 err = -ENETUNREACH;
1449                 goto out;
1450         }
1451 
1452         if (usax != NULL) {
1453                 if (usax->sax25_family != AF_AX25) {
1454                         err = -EINVAL;
1455                         goto out;
1456                 }
1457 
1458                 if (addr_len == sizeof(struct sockaddr_ax25)) {
1459                         printk(KERN_WARNING "ax25_sendmsg(): %s uses obsolete socket structure\n",
1460                                 current->comm);
1461                 }
1462                 else if (addr_len != sizeof(struct full_sockaddr_ax25)) {
1463                         /* support for old structure may go away some time */
1464                         if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
1465                             (addr_len > sizeof(struct full_sockaddr_ax25))) {
1466                                 err = -EINVAL;
1467                                 goto out;
1468                         }
1469 
1470                         printk(KERN_WARNING "ax25_sendmsg(): %s uses old (6 digipeater) socket structure.\n",
1471                                 current->comm);
1472                 }
1473 
1474                 if (addr_len > sizeof(struct sockaddr_ax25) && usax->sax25_ndigis != 0) {
1475                         int ct           = 0;
1476                         struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)usax;
1477 
1478                         /* Valid number of digipeaters ? */
1479                         if (usax->sax25_ndigis < 1 || usax->sax25_ndigis > AX25_MAX_DIGIS) {
1480                                 err = -EINVAL;
1481                                 goto out;
1482                         }
1483 
1484                         dtmp.ndigi      = usax->sax25_ndigis;
1485 
1486                         while (ct < usax->sax25_ndigis) {
1487                                 dtmp.repeated[ct] = 0;
1488                                 dtmp.calls[ct]    = fsa->fsa_digipeater[ct];
1489                                 ct++;
1490                         }
1491 
1492                         dtmp.lastrepeat = 0;
1493                 }
1494 
1495                 sax = *usax;
1496                 if (sk->sk_type == SOCK_SEQPACKET &&
1497                     ax25cmp(&ax25->dest_addr, &sax.sax25_call)) {
1498                         err = -EISCONN;
1499                         goto out;
1500                 }
1501                 if (usax->sax25_ndigis == 0)
1502                         dp = NULL;
1503                 else
1504                         dp = &dtmp;
1505         } else {
1506                 /*
1507                  *      FIXME: 1003.1g - if the socket is like this because
1508                  *      it has become closed (not started closed) and is VC
1509                  *      we ought to SIGPIPE, EPIPE
1510                  */
1511                 if (sk->sk_state != TCP_ESTABLISHED) {
1512                         err = -ENOTCONN;
1513                         goto out;
1514                 }
1515                 sax.sax25_family = AF_AX25;
1516                 sax.sax25_call   = ax25->dest_addr;
1517                 dp = ax25->digipeat;
1518         }
1519 
1520         SOCK_DEBUG(sk, "AX.25: sendto: Addresses built.\n");
1521 
1522         /* Build a packet */
1523         SOCK_DEBUG(sk, "AX.25: sendto: building packet.\n");
1524 
1525         /* Assume the worst case */
1526         size = len + ax25->ax25_dev->dev->hard_header_len;
1527 
1528         skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT, &err);
1529         if (skb == NULL)
1530                 goto out;
1531 
1532         skb_reserve(skb, size - len);
1533 
1534         SOCK_DEBUG(sk, "AX.25: Appending user data\n");
1535 
1536         /* User data follows immediately after the AX.25 data */
1537         memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1538         skb->nh.raw = skb->data;
1539 
1540         /* Add the PID if one is not supplied by the user in the skb */
1541         if (!ax25->pidincl) {
1542                 asmptr  = skb_push(skb, 1);
1543                 *asmptr = sk->sk_protocol;
1544         }
1545 
1546         SOCK_DEBUG(sk, "AX.25: Transmitting buffer\n");
1547 
1548         if (sk->sk_type == SOCK_SEQPACKET) {
1549                 /* Connected mode sockets go via the LAPB machine */
1550                 if (sk->sk_state != TCP_ESTABLISHED) {
1551                         kfree_skb(skb);
1552                         err = -ENOTCONN;
1553                         goto out;
1554                 }
1555 
1556                 /* Shove it onto the queue and kick */
1557                 ax25_output(ax25, ax25->paclen, skb);
1558 
1559                 err = len;
1560                 goto out;
1561         }
1562 
1563         asmptr = skb_push(skb, 1 + ax25_addr_size(dp));
1564 
1565         SOCK_DEBUG(sk, "Building AX.25 Header (dp=%p).\n", dp);
1566 
1567         if (dp != NULL)
1568                 SOCK_DEBUG(sk, "Num digipeaters=%d\n", dp->ndigi);
1569 
1570         /* Build an AX.25 header */
1571         asmptr += (lv = ax25_addr_build(asmptr, &ax25->source_addr,
1572                                         &sax.sax25_call, dp,
1573                                         AX25_COMMAND, AX25_MODULUS));
1574 
1575         SOCK_DEBUG(sk, "Built header (%d bytes)\n",lv);
1576 
1577         skb->h.raw = asmptr;
1578 
1579         SOCK_DEBUG(sk, "base=%p pos=%p\n", skb->data, asmptr);
1580 
1581         *asmptr = AX25_UI;
1582 
1583         /* Datagram frames go straight out of the door as UI */
1584         skb->dev = ax25->ax25_dev->dev;
1585 
1586         ax25_queue_xmit(skb);
1587 
1588         err = len;
1589 
1590 out:
1591         release_sock(sk);
1592 
1593         return err;
1594 }
1595 
1596 static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
1597         struct msghdr *msg, int size, int flags)
1598 {
1599         struct sock *sk = sock->sk;
1600         struct sk_buff *skb;
1601         int copied;
1602         int err = 0;
1603 
1604         lock_sock(sk);
1605         /*
1606          *      This works for seqpacket too. The receiver has ordered the
1607          *      queue for us! We do one quick check first though
1608          */
1609         if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_ESTABLISHED) {
1610                 err =  -ENOTCONN;
1611                 goto out;
1612         }
1613 
1614         /* Now we can treat all alike */
1615         skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1616                                 flags & MSG_DONTWAIT, &err);
1617         if (skb == NULL)
1618                 goto out;
1619 
1620         if (!ax25_sk(sk)->pidincl)
1621                 skb_pull(skb, 1);               /* Remove PID */
1622 
1623         skb->h.raw = skb->data;
1624         copied     = skb->len;
1625 
1626         if (copied > size) {
1627                 copied = size;
1628                 msg->msg_flags |= MSG_TRUNC;
1629         }
1630 
1631         skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1632 
1633         if (msg->msg_namelen != 0) {
1634                 struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
1635                 ax25_digi digi;
1636                 ax25_address dest;
1637 
1638                 ax25_addr_parse(skb->mac.raw+1, skb->data-skb->mac.raw-1, NULL, &dest, &digi, NULL, NULL);
1639 
1640                 sax->sax25_family = AF_AX25;
1641                 /* We set this correctly, even though we may not let the
1642                    application know the digi calls further down (because it
1643                    did NOT ask to know them).  This could get political... **/
1644                 sax->sax25_ndigis = digi.ndigi;
1645                 sax->sax25_call   = dest;
1646 
1647                 if (sax->sax25_ndigis != 0) {
1648                         int ct;
1649                         struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)sax;
1650 
1651                         for (ct = 0; ct < digi.ndigi; ct++)
1652                                 fsa->fsa_digipeater[ct] = digi.calls[ct];
1653                 }
1654                 msg->msg_namelen = sizeof(struct full_sockaddr_ax25);
1655         }
1656 
1657         skb_free_datagram(sk, skb);
1658         err = copied;
1659 
1660 out:
1661         release_sock(sk);
1662 
1663         return err;
1664 }
1665 
1666 static int ax25_shutdown(struct socket *sk, int how)
1667 {
1668         /* FIXME - generate DM and RNR states */
1669         return -EOPNOTSUPP;
1670 }
1671 
1672 static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1673 {
1674         struct sock *sk = sock->sk;
1675         int res = 0;
1676 
1677         lock_sock(sk);
1678         switch (cmd) {
1679         case TIOCOUTQ: {
1680                 long amount;
1681                 amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
1682                 if (amount < 0)
1683                         amount = 0;
1684                 res = put_user(amount, (int *)arg);
1685                 break;
1686         }
1687 
1688         case TIOCINQ: {
1689                 struct sk_buff *skb;
1690                 long amount = 0L;
1691                 /* These two are safe on a single CPU system as only user tasks fiddle here */
1692                 if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
1693                         amount = skb->len;
1694                 res = put_user(amount, (int *)arg);
1695                 break;
1696         }
1697 
1698         case SIOCGSTAMP:
1699                 if (sk != NULL) {
1700                         if (!sk->sk_stamp.tv_sec) {
1701                                 res = -ENOENT;
1702                                 break;
1703                         }
1704                         res = copy_to_user((void *)arg, &sk->sk_stamp,
1705                                           sizeof(struct timeval)) ? -EFAULT : 0;
1706                         break;
1707                 }
1708                 res = -EINVAL;
1709                 break;
1710 
1711         case SIOCAX25ADDUID:    /* Add a uid to the uid/call map table */
1712         case SIOCAX25DELUID:    /* Delete a uid from the uid/call map table */
1713         case SIOCAX25GETUID: {
1714                 struct sockaddr_ax25 sax25;
1715                 if (copy_from_user(&sax25, (void *)arg, sizeof(sax25))) {
1716                         res = -EFAULT;
1717                         break;
1718                 }
1719                 res = ax25_uid_ioctl(cmd, &sax25);
1720                 break;
1721         }
1722 
1723         case SIOCAX25NOUID: {   /* Set the default policy (default/bar) */
1724                 long amount;
1725                 if (!capable(CAP_NET_ADMIN)) {
1726                         res = -EPERM;
1727                         break;
1728                 }
1729                 if (get_user(amount, (long *)arg)) {
1730                         res = -EFAULT;
1731                         break;
1732                 }
1733                 if (amount > AX25_NOUID_BLOCK) {
1734                         res = -EINVAL;
1735                         break;
1736                 }
1737                 ax25_uid_policy = amount;
1738                 res = 0;
1739                 break;
1740         }
1741 
1742         case SIOCADDRT:
1743         case SIOCDELRT:
1744         case SIOCAX25OPTRT:
1745                 if (!capable(CAP_NET_ADMIN)) {
1746                         res = -EPERM;
1747                         break;
1748                 }
1749                 res = ax25_rt_ioctl(cmd, (void *)arg);
1750                 break;
1751 
1752         case SIOCAX25CTLCON:
1753                 if (!capable(CAP_NET_ADMIN)) {
1754                         res = -EPERM;
1755                         break;
1756                 }
1757                 res = ax25_ctl_ioctl(cmd, (void *)arg);
1758                 break;
1759 
1760         case SIOCAX25GETINFO:
1761         case SIOCAX25GETINFOOLD: {
1762                 ax25_cb *ax25 = ax25_sk(sk);
1763                 struct ax25_info_struct ax25_info;
1764 
1765                 ax25_info.t1        = ax25->t1   / HZ;
1766                 ax25_info.t2        = ax25->t2   / HZ;
1767                 ax25_info.t3        = ax25->t3   / HZ;
1768                 ax25_info.idle      = ax25->idle / (60 * HZ);
1769                 ax25_info.n2        = ax25->n2;
1770                 ax25_info.t1timer   = ax25_display_timer(&ax25->t1timer)   / HZ;
1771                 ax25_info.t2timer   = ax25_display_timer(&ax25->t2timer)   / HZ;
1772                 ax25_info.t3timer   = ax25_display_timer(&ax25->t3timer)   / HZ;
1773                 ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ);
1774                 ax25_info.n2count   = ax25->n2count;
1775                 ax25_info.state     = ax25->state;
1776                 ax25_info.rcv_q     = atomic_read(&sk->sk_rmem_alloc);
1777                 ax25_info.snd_q     = atomic_read(&sk->sk_wmem_alloc);
1778                 ax25_info.vs        = ax25->vs;
1779                 ax25_info.vr        = ax25->vr;
1780                 ax25_info.va        = ax25->va;
1781                 ax25_info.vs_max    = ax25->vs; /* reserved */
1782                 ax25_info.paclen    = ax25->paclen;
1783                 ax25_info.window    = ax25->window;
1784 
1785                 /* old structure? */
1786                 if (cmd == SIOCAX25GETINFOOLD) {
1787                         static int warned = 0;
1788                         if (!warned) {
1789                                 printk(KERN_INFO "%s uses old SIOCAX25GETINFO\n",
1790                                         current->comm);
1791                                 warned=1;
1792                         }
1793 
1794                         if (copy_to_user((void *)arg, &ax25_info, sizeof(struct ax25_info_struct_deprecated))) {
1795                                 res = -EFAULT;
1796                                 break;
1797                         }
1798                 } else {
1799                         if (copy_to_user((void *)arg, &ax25_info, sizeof(struct ax25_info_struct))) {
1800                                 res = -EINVAL;
1801                                 break;
1802                         }
1803                 }
1804                 res = 0;
1805                 break;
1806         }
1807 
1808         case SIOCAX25ADDFWD:
1809         case SIOCAX25DELFWD: {
1810                 struct ax25_fwd_struct ax25_fwd;
1811                 if (!capable(CAP_NET_ADMIN)) {
1812                         res = -EPERM;
1813                         break;
1814                 }
1815                 if (copy_from_user(&ax25_fwd, (void *)arg, sizeof(ax25_fwd))) {
1816                         res = -EFAULT;
1817                         break;
1818                 }
1819                 res = ax25_fwd_ioctl(cmd, &ax25_fwd);
1820                 break;
1821         }
1822 
1823         case SIOCGIFADDR:
1824         case SIOCSIFADDR:
1825         case SIOCGIFDSTADDR:
1826         case SIOCSIFDSTADDR:
1827         case SIOCGIFBRDADDR:
1828         case SIOCSIFBRDADDR:
1829         case SIOCGIFNETMASK:
1830         case SIOCSIFNETMASK:
1831         case SIOCGIFMETRIC:
1832         case SIOCSIFMETRIC:
1833                 res = -EINVAL;
1834                 break;
1835 
1836         default:
1837                 res = dev_ioctl(cmd, (void *)arg);
1838                 break;
1839         }
1840         release_sock(sk);
1841 
1842         return res;
1843 }
1844 
1845 #ifdef CONFIG_PROC_FS
1846 
1847 static void *ax25_info_start(struct seq_file *seq, loff_t *pos)
1848 {
1849         struct ax25_cb *ax25;
1850         struct hlist_node *node;
1851         int i = 0;
1852 
1853         spin_lock_bh(&ax25_list_lock);
1854         ax25_for_each(ax25, node, &ax25_list) {
1855                 if (i == *pos)
1856                         return ax25;
1857                 ++i;
1858         }
1859         return NULL;
1860 }
1861 
1862 static void *ax25_info_next(struct seq_file *seq, void *v, loff_t *pos)
1863 {
1864         ++*pos;
1865 
1866         return hlist_entry( ((struct ax25_cb *)v)->ax25_node.next,
1867                             struct ax25_cb, ax25_node);
1868 }
1869         
1870 static void ax25_info_stop(struct seq_file *seq, void *v)
1871 {
1872         spin_unlock_bh(&ax25_list_lock);
1873 }
1874 
1875 static int ax25_info_show(struct seq_file *seq, void *v)
1876 {
1877         ax25_cb *ax25 = v;
1878         int k;
1879 
1880 
1881         /*
1882          * New format:
1883          * magic dev src_addr dest_addr,digi1,digi2,.. st vs vr va t1 t1 t2 t2 t3 t3 idle idle n2 n2 rtt window paclen Snd-Q Rcv-Q inode
1884          */
1885 
1886         seq_printf(seq, "%8.8lx %s %s%s ",
1887                    (long) ax25,
1888                    ax25->ax25_dev == NULL? "???" : ax25->ax25_dev->dev->name,
1889                    ax2asc(&ax25->source_addr),
1890                    ax25->iamdigi? "*":"");
1891         seq_printf(seq, "%s", ax2asc(&ax25->dest_addr));
1892 
1893         for (k=0; (ax25->digipeat != NULL) && (k < ax25->digipeat->ndigi); k++) {
1894                 seq_printf(seq, ",%s%s",
1895                            ax2asc(&ax25->digipeat->calls[k]),
1896                            ax25->digipeat->repeated[k]? "*":"");
1897         }
1898 
1899         seq_printf(seq, " %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %d %d",
1900                    ax25->state,
1901                    ax25->vs, ax25->vr, ax25->va,
1902                    ax25_display_timer(&ax25->t1timer) / HZ, ax25->t1 / HZ,
1903                    ax25_display_timer(&ax25->t2timer) / HZ, ax25->t2 / HZ,
1904                    ax25_display_timer(&ax25->t3timer) / HZ, ax25->t3 / HZ,
1905                    ax25_display_timer(&ax25->idletimer) / (60 * HZ),
1906                    ax25->idle / (60 * HZ),
1907                    ax25->n2count, ax25->n2,
1908                    ax25->rtt / HZ,
1909                    ax25->window,
1910                    ax25->paclen);
1911 
1912         if (ax25->sk != NULL) {
1913                 bh_lock_sock(ax25->sk);
1914                 seq_printf(seq," %d %d %ld\n",
1915                            atomic_read(&ax25->sk->sk_wmem_alloc),
1916                            atomic_read(&ax25->sk->sk_rmem_alloc),
1917                            ax25->sk->sk_socket != NULL ? SOCK_INODE(ax25->sk->sk_socket)->i_ino : 0L);
1918                 bh_unlock_sock(ax25->sk);
1919         } else {
1920                 seq_puts(seq, " * * *\n");
1921         }
1922         return 0;
1923 }
1924 
1925 static struct seq_operations ax25_info_seqops = {
1926         .start = ax25_info_start,
1927         .next = ax25_info_next,
1928         .stop = ax25_info_stop,
1929         .show = ax25_info_show,
1930 };
1931 
1932 static int ax25_info_open(struct inode *inode, struct file *file)
1933 {
1934         return seq_open(file, &ax25_info_seqops);
1935 }
1936 
1937 static struct file_operations ax25_info_fops = {
1938         .owner = THIS_MODULE,
1939         .open = ax25_info_open,
1940         .read = seq_read,
1941         .llseek = seq_lseek,
1942         .release = seq_release,
1943 };
1944 
1945 #endif
1946 
1947 static struct net_proto_family ax25_family_ops = {
1948         .family =       PF_AX25,
1949         .create =       ax25_create,
1950         .owner  =       THIS_MODULE,
1951 };
1952 
1953 static struct proto_ops ax25_proto_ops = {
1954         .family =       PF_AX25,
1955         .owner =        THIS_MODULE,
1956         .release =      ax25_release,
1957         .bind =         ax25_bind,
1958         .connect =      ax25_connect,
1959         .socketpair =   sock_no_socketpair,
1960         .accept =       ax25_accept,
1961         .getname =      ax25_getname,
1962         .poll =         datagram_poll,
1963         .ioctl =        ax25_ioctl,
1964         .listen =       ax25_listen,
1965         .shutdown =     ax25_shutdown,
1966         .setsockopt =   ax25_setsockopt,
1967         .getsockopt =   ax25_getsockopt,
1968         .sendmsg =      ax25_sendmsg,
1969         .recvmsg =      ax25_recvmsg,
1970         .mmap =         sock_no_mmap,
1971         .sendpage =     sock_no_sendpage,
1972 };
1973 
1974 /*
1975  *      Called by socket.c on kernel start up
1976  */
1977 static struct packet_type ax25_packet_type = {
1978         .type   =       __constant_htons(ETH_P_AX25),
1979         .dev    =       NULL,                           /* All devices */
1980         .func   =       ax25_kiss_rcv,
1981 };
1982 
1983 static struct notifier_block ax25_dev_notifier = {
1984         .notifier_call =ax25_device_event,
1985 };
1986 
1987 EXPORT_SYMBOL(ax25_encapsulate);
1988 EXPORT_SYMBOL(ax25_rebuild_header);
1989 EXPORT_SYMBOL(ax25_findbyuid);
1990 EXPORT_SYMBOL(ax25_find_cb);
1991 EXPORT_SYMBOL(ax25_linkfail_register);
1992 EXPORT_SYMBOL(ax25_linkfail_release);
1993 EXPORT_SYMBOL(ax25_listen_register);
1994 EXPORT_SYMBOL(ax25_listen_release);
1995 EXPORT_SYMBOL(ax25_protocol_register);
1996 EXPORT_SYMBOL(ax25_protocol_release);
1997 EXPORT_SYMBOL(ax25_send_frame);
1998 EXPORT_SYMBOL(ax25_uid_policy);
1999 EXPORT_SYMBOL(ax25cmp);
2000 EXPORT_SYMBOL(ax2asc);
2001 EXPORT_SYMBOL(asc2ax);
2002 EXPORT_SYMBOL(null_ax25_address);
2003 EXPORT_SYMBOL(ax25_display_timer);
2004 
2005 static int __init ax25_init(void)
2006 {
2007         sock_register(&ax25_family_ops);
2008         dev_add_pack(&ax25_packet_type);
2009         register_netdevice_notifier(&ax25_dev_notifier);
2010         ax25_register_sysctl();
2011 
2012         proc_net_fops_create("ax25_route", S_IRUGO, &ax25_route_fops);
2013         proc_net_fops_create("ax25", S_IRUGO, &ax25_info_fops);
2014         proc_net_fops_create("ax25_calls", S_IRUGO, &ax25_uid_fops);
2015 
2016         return 0;
2017 }
2018 module_init(ax25_init);
2019 
2020 
2021 MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
2022 MODULE_DESCRIPTION("The amateur radio AX.25 link layer protocol");
2023 MODULE_LICENSE("GPL");
2024 MODULE_ALIAS_NETPROTO(PF_AX25);
2025 
2026 static void __exit ax25_exit(void)
2027 {
2028         proc_net_remove("ax25_route");
2029         proc_net_remove("ax25");
2030         proc_net_remove("ax25_calls");
2031         ax25_rt_free();
2032         ax25_uid_free();
2033         ax25_dev_free();
2034 
2035         ax25_unregister_sysctl();
2036         unregister_netdevice_notifier(&ax25_dev_notifier);
2037 
2038         dev_remove_pack(&ax25_packet_type);
2039 
2040         sock_unregister(PF_AX25);
2041 }
2042 module_exit(ax25_exit);
2043 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp