- pre2
[davej-history.git] / net / rose / af_rose.c
blobf61d9cd34df177d57d069259323464d789c40bcd
1 /*
2 * ROSE release 003
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
6 * This module:
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * History
13 * ROSE 001 Jonathan(G4KLX) Cloned from af_netrom.c.
14 * Alan(GW4PTS) Hacked up for newer API stuff
15 * Terry (VK2KTJ) Added support for variable length
16 * address masks.
17 * ROSE 002 Jonathan(G4KLX) Changed hdrincl to qbitincl.
18 * Added random number facilities entry.
19 * Variable number of ROSE devices.
20 * ROSE 003 Jonathan(G4KLX) New timer architecture.
21 * Implemented idle timer.
22 * Added use count to neighbour.
23 * Tomi(OH2BNS) Fixed rose_getname().
24 * Arnaldo C. Melo s/suser/capable/ + micro cleanups
27 #include <linux/config.h>
28 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
29 #include <linux/module.h>
30 #include <linux/errno.h>
31 #include <linux/types.h>
32 #include <linux/socket.h>
33 #include <linux/in.h>
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/timer.h>
37 #include <linux/string.h>
38 #include <linux/sockios.h>
39 #include <linux/net.h>
40 #include <linux/stat.h>
41 #include <net/ax25.h>
42 #include <linux/inet.h>
43 #include <linux/netdevice.h>
44 #include <linux/if_arp.h>
45 #include <linux/skbuff.h>
46 #include <net/sock.h>
47 #include <asm/segment.h>
48 #include <asm/system.h>
49 #include <asm/uaccess.h>
50 #include <linux/fcntl.h>
51 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
52 #include <linux/mm.h>
53 #include <linux/interrupt.h>
54 #include <linux/notifier.h>
55 #include <net/rose.h>
56 #include <linux/proc_fs.h>
57 #include <net/ip.h>
58 #include <net/arp.h>
59 #include <linux/init.h>
61 int rose_ndevs = 10;
63 int sysctl_rose_restart_request_timeout = ROSE_DEFAULT_T0;
64 int sysctl_rose_call_request_timeout = ROSE_DEFAULT_T1;
65 int sysctl_rose_reset_request_timeout = ROSE_DEFAULT_T2;
66 int sysctl_rose_clear_request_timeout = ROSE_DEFAULT_T3;
67 int sysctl_rose_no_activity_timeout = ROSE_DEFAULT_IDLE;
68 int sysctl_rose_ack_hold_back_timeout = ROSE_DEFAULT_HB;
69 int sysctl_rose_routing_control = ROSE_DEFAULT_ROUTING;
70 int sysctl_rose_link_fail_timeout = ROSE_DEFAULT_FAIL_TIMEOUT;
71 int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC;
72 int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
74 static struct sock *volatile rose_list = NULL;
76 static struct proto_ops rose_proto_ops;
78 ax25_address rose_callsign;
81 * Convert a ROSE address into text.
83 char *rose2asc(rose_address *addr)
85 static char buffer[11];
87 if (addr->rose_addr[0] == 0x00 && addr->rose_addr[1] == 0x00 &&
88 addr->rose_addr[2] == 0x00 && addr->rose_addr[3] == 0x00 &&
89 addr->rose_addr[4] == 0x00) {
90 strcpy(buffer, "*");
91 } else {
92 sprintf(buffer, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
93 addr->rose_addr[1] & 0xFF,
94 addr->rose_addr[2] & 0xFF,
95 addr->rose_addr[3] & 0xFF,
96 addr->rose_addr[4] & 0xFF);
99 return buffer;
103 * Compare two ROSE addresses, 0 == equal.
105 int rosecmp(rose_address *addr1, rose_address *addr2)
107 int i;
109 for (i = 0; i < 5; i++)
110 if (addr1->rose_addr[i] != addr2->rose_addr[i])
111 return 1;
113 return 0;
117 * Compare two ROSE addresses for only mask digits, 0 == equal.
119 int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
121 int i, j;
123 if (mask > 10)
124 return 1;
126 for (i = 0; i < mask; i++) {
127 j = i / 2;
129 if ((i % 2) != 0) {
130 if ((addr1->rose_addr[j] & 0x0F) != (addr2->rose_addr[j] & 0x0F))
131 return 1;
132 } else {
133 if ((addr1->rose_addr[j] & 0xF0) != (addr2->rose_addr[j] & 0xF0))
134 return 1;
138 return 0;
141 static void rose_free_sock(struct sock *sk)
143 sk_free(sk);
145 MOD_DEC_USE_COUNT;
148 static struct sock *rose_alloc_sock(void)
150 struct sock *sk;
151 rose_cb *rose;
153 if ((sk = sk_alloc(PF_ROSE, GFP_ATOMIC, 1)) == NULL)
154 return NULL;
156 if ((rose = kmalloc(sizeof(*rose), GFP_ATOMIC)) == NULL) {
157 sk_free(sk);
158 return NULL;
161 MOD_INC_USE_COUNT;
163 memset(rose, 0x00, sizeof(*rose));
165 sk->protinfo.rose = rose;
166 rose->sk = sk;
168 return sk;
172 * Socket removal during an interrupt is now safe.
174 static void rose_remove_socket(struct sock *sk)
176 struct sock *s;
177 unsigned long flags;
179 save_flags(flags); cli();
181 if ((s = rose_list) == sk) {
182 rose_list = s->next;
183 restore_flags(flags);
184 return;
187 while (s != NULL && s->next != NULL) {
188 if (s->next == sk) {
189 s->next = sk->next;
190 restore_flags(flags);
191 return;
194 s = s->next;
197 restore_flags(flags);
201 * Kill all bound sockets on a broken link layer connection to a
202 * particular neighbour.
204 void rose_kill_by_neigh(struct rose_neigh *neigh)
206 struct sock *s;
208 for (s = rose_list; s != NULL; s = s->next) {
209 if (s->protinfo.rose->neighbour == neigh) {
210 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
211 s->protinfo.rose->neighbour->use--;
212 s->protinfo.rose->neighbour = NULL;
218 * Kill all bound sockets on a dropped device.
220 static void rose_kill_by_device(struct net_device *dev)
222 struct sock *s;
224 for (s = rose_list; s != NULL; s = s->next) {
225 if (s->protinfo.rose->device == dev) {
226 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
227 s->protinfo.rose->neighbour->use--;
228 s->protinfo.rose->device = NULL;
234 * Handle device status changes.
236 static int rose_device_event(struct notifier_block *this, unsigned long event, void *ptr)
238 struct net_device *dev = (struct net_device *)ptr;
240 if (event != NETDEV_DOWN)
241 return NOTIFY_DONE;
243 switch (dev->type) {
244 case ARPHRD_ROSE:
245 rose_kill_by_device(dev);
246 break;
247 case ARPHRD_AX25:
248 rose_link_device_down(dev);
249 rose_rt_device_down(dev);
250 break;
253 return NOTIFY_DONE;
257 * Add a socket to the bound sockets list.
259 static void rose_insert_socket(struct sock *sk)
261 unsigned long flags;
263 save_flags(flags); cli();
265 sk->next = rose_list;
266 rose_list = sk;
268 restore_flags(flags);
272 * Find a socket that wants to accept the Call Request we just
273 * received.
275 static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
277 unsigned long flags;
278 struct sock *s;
280 save_flags(flags); cli();
282 for (s = rose_list; s != NULL; s = s->next) {
283 if (rosecmp(&s->protinfo.rose->source_addr, addr) == 0 && ax25cmp(&s->protinfo.rose->source_call, call) == 0 && s->protinfo.rose->source_ndigis == 0 && s->state == TCP_LISTEN) {
284 restore_flags(flags);
285 return s;
289 for (s = rose_list; s != NULL; s = s->next) {
290 if (rosecmp(&s->protinfo.rose->source_addr, addr) == 0 && ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0 && s->state == TCP_LISTEN) {
291 restore_flags(flags);
292 return s;
296 restore_flags(flags);
297 return NULL;
301 * Find a connected ROSE socket given my LCI and device.
303 struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
305 struct sock *s;
306 unsigned long flags;
308 save_flags(flags); cli();
310 for (s = rose_list; s != NULL; s = s->next) {
311 if (s->protinfo.rose->lci == lci && s->protinfo.rose->neighbour == neigh) {
312 restore_flags(flags);
313 return s;
317 restore_flags(flags);
319 return NULL;
323 * Find a unique LCI for a given device.
325 unsigned int rose_new_lci(struct rose_neigh *neigh)
327 int lci;
329 if (neigh->dce_mode) {
330 for (lci = 1; lci <= sysctl_rose_maximum_vcs; lci++)
331 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
332 return lci;
333 } else {
334 for (lci = sysctl_rose_maximum_vcs; lci > 0; lci--)
335 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
336 return lci;
339 return 0;
343 * Deferred destroy.
345 void rose_destroy_socket(struct sock *);
348 * Handler for deferred kills.
350 static void rose_destroy_timer(unsigned long data)
352 rose_destroy_socket((struct sock *)data);
356 * This is called from user mode and the timers. Thus it protects itself against
357 * interrupt users but doesn't worry about being called during work.
358 * Once it is removed from the queue no interrupt or bottom half will
359 * touch it and we are (fairly 8-) ) safe.
361 void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the timer */
363 struct sk_buff *skb;
364 unsigned long flags;
366 save_flags(flags); cli();
368 rose_stop_heartbeat(sk);
369 rose_stop_idletimer(sk);
370 rose_stop_timer(sk);
372 rose_remove_socket(sk);
373 rose_clear_queues(sk); /* Flush the queues */
375 while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
376 if (skb->sk != sk) { /* A pending connection */
377 skb->sk->dead = 1; /* Queue the unaccepted socket for death */
378 rose_start_heartbeat(skb->sk);
379 skb->sk->protinfo.rose->state = ROSE_STATE_0;
382 kfree_skb(skb);
385 if (atomic_read(&sk->wmem_alloc) != 0 || atomic_read(&sk->rmem_alloc) != 0) {
386 /* Defer: outstanding buffers */
387 init_timer(&sk->timer);
388 sk->timer.expires = jiffies + 10 * HZ;
389 sk->timer.function = rose_destroy_timer;
390 sk->timer.data = (unsigned long)sk;
391 add_timer(&sk->timer);
392 } else {
393 rose_free_sock(sk);
396 restore_flags(flags);
400 * Handling for system calls applied via the various interfaces to a
401 * ROSE socket object.
404 static int rose_setsockopt(struct socket *sock, int level, int optname,
405 char *optval, int optlen)
407 struct sock *sk = sock->sk;
408 int opt;
410 if (level != SOL_ROSE)
411 return -ENOPROTOOPT;
413 if (optlen < sizeof(int))
414 return -EINVAL;
416 if (get_user(opt, (int *)optval))
417 return -EFAULT;
419 switch (optname) {
420 case ROSE_DEFER:
421 sk->protinfo.rose->defer = opt ? 1 : 0;
422 return 0;
424 case ROSE_T1:
425 if (opt < 1)
426 return -EINVAL;
427 sk->protinfo.rose->t1 = opt * HZ;
428 return 0;
430 case ROSE_T2:
431 if (opt < 1)
432 return -EINVAL;
433 sk->protinfo.rose->t2 = opt * HZ;
434 return 0;
436 case ROSE_T3:
437 if (opt < 1)
438 return -EINVAL;
439 sk->protinfo.rose->t3 = opt * HZ;
440 return 0;
442 case ROSE_HOLDBACK:
443 if (opt < 1)
444 return -EINVAL;
445 sk->protinfo.rose->hb = opt * HZ;
446 return 0;
448 case ROSE_IDLE:
449 if (opt < 0)
450 return -EINVAL;
451 sk->protinfo.rose->idle = opt * 60 * HZ;
452 return 0;
454 case ROSE_QBITINCL:
455 sk->protinfo.rose->qbitincl = opt ? 1 : 0;
456 return 0;
458 default:
459 return -ENOPROTOOPT;
463 static int rose_getsockopt(struct socket *sock, int level, int optname,
464 char *optval, int *optlen)
466 struct sock *sk = sock->sk;
467 int val = 0;
468 int len;
470 if (level != SOL_ROSE)
471 return -ENOPROTOOPT;
473 if (get_user(len, optlen))
474 return -EFAULT;
476 switch (optname) {
477 case ROSE_DEFER:
478 val = sk->protinfo.rose->defer;
479 break;
481 case ROSE_T1:
482 val = sk->protinfo.rose->t1 / HZ;
483 break;
485 case ROSE_T2:
486 val = sk->protinfo.rose->t2 / HZ;
487 break;
489 case ROSE_T3:
490 val = sk->protinfo.rose->t3 / HZ;
491 break;
493 case ROSE_HOLDBACK:
494 val = sk->protinfo.rose->hb / HZ;
495 break;
497 case ROSE_IDLE:
498 val = sk->protinfo.rose->idle / (60 * HZ);
499 break;
501 case ROSE_QBITINCL:
502 val = sk->protinfo.rose->qbitincl;
503 break;
505 default:
506 return -ENOPROTOOPT;
509 len = min(len, sizeof(int));
511 if (put_user(len, optlen))
512 return -EFAULT;
514 return copy_to_user(optval, &val, len) ? -EFAULT : 0;
517 static int rose_listen(struct socket *sock, int backlog)
519 struct sock *sk = sock->sk;
521 if (sk->state != TCP_LISTEN) {
522 sk->protinfo.rose->dest_ndigis = 0;
523 memset(&sk->protinfo.rose->dest_addr, '\0', ROSE_ADDR_LEN);
524 memset(&sk->protinfo.rose->dest_call, '\0', AX25_ADDR_LEN);
525 memset(sk->protinfo.rose->dest_digis, '\0', AX25_ADDR_LEN*ROSE_MAX_DIGIS);
526 sk->max_ack_backlog = backlog;
527 sk->state = TCP_LISTEN;
528 return 0;
531 return -EOPNOTSUPP;
534 static int rose_create(struct socket *sock, int protocol)
536 struct sock *sk;
537 rose_cb *rose;
539 if (sock->type != SOCK_SEQPACKET || protocol != 0)
540 return -ESOCKTNOSUPPORT;
542 if ((sk = rose_alloc_sock()) == NULL)
543 return -ENOMEM;
545 rose = sk->protinfo.rose;
547 sock_init_data(sock, sk);
549 skb_queue_head_init(&rose->ack_queue);
550 #ifdef M_BIT
551 skb_queue_head_init(&rose->frag_queue);
552 rose->fraglen = 0;
553 #endif
555 sock->ops = &rose_proto_ops;
556 sk->protocol = protocol;
558 init_timer(&rose->timer);
559 init_timer(&rose->idletimer);
561 rose->t1 = sysctl_rose_call_request_timeout;
562 rose->t2 = sysctl_rose_reset_request_timeout;
563 rose->t3 = sysctl_rose_clear_request_timeout;
564 rose->hb = sysctl_rose_ack_hold_back_timeout;
565 rose->idle = sysctl_rose_no_activity_timeout;
567 rose->state = ROSE_STATE_0;
569 return 0;
572 static struct sock *rose_make_new(struct sock *osk)
574 struct sock *sk;
575 rose_cb *rose;
577 if (osk->type != SOCK_SEQPACKET)
578 return NULL;
580 if ((sk = rose_alloc_sock()) == NULL)
581 return NULL;
583 rose = sk->protinfo.rose;
585 sock_init_data(NULL, sk);
587 skb_queue_head_init(&rose->ack_queue);
588 #ifdef M_BIT
589 skb_queue_head_init(&rose->frag_queue);
590 rose->fraglen = 0;
591 #endif
593 sk->type = osk->type;
594 sk->socket = osk->socket;
595 sk->priority = osk->priority;
596 sk->protocol = osk->protocol;
597 sk->rcvbuf = osk->rcvbuf;
598 sk->sndbuf = osk->sndbuf;
599 sk->debug = osk->debug;
600 sk->state = TCP_ESTABLISHED;
601 sk->sleep = osk->sleep;
602 sk->zapped = osk->zapped;
604 init_timer(&rose->timer);
605 init_timer(&rose->idletimer);
607 rose->t1 = osk->protinfo.rose->t1;
608 rose->t2 = osk->protinfo.rose->t2;
609 rose->t3 = osk->protinfo.rose->t3;
610 rose->hb = osk->protinfo.rose->hb;
611 rose->idle = osk->protinfo.rose->idle;
613 rose->defer = osk->protinfo.rose->defer;
614 rose->device = osk->protinfo.rose->device;
615 rose->qbitincl = osk->protinfo.rose->qbitincl;
617 return sk;
620 static int rose_release(struct socket *sock)
622 struct sock *sk = sock->sk;
624 if (sk == NULL) return 0;
626 switch (sk->protinfo.rose->state) {
628 case ROSE_STATE_0:
629 rose_disconnect(sk, 0, -1, -1);
630 rose_destroy_socket(sk);
631 break;
633 case ROSE_STATE_2:
634 sk->protinfo.rose->neighbour->use--;
635 rose_disconnect(sk, 0, -1, -1);
636 rose_destroy_socket(sk);
637 break;
639 case ROSE_STATE_1:
640 case ROSE_STATE_3:
641 case ROSE_STATE_4:
642 case ROSE_STATE_5:
643 rose_clear_queues(sk);
644 rose_stop_idletimer(sk);
645 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
646 rose_start_t3timer(sk);
647 sk->protinfo.rose->state = ROSE_STATE_2;
648 sk->state = TCP_CLOSE;
649 sk->shutdown |= SEND_SHUTDOWN;
650 sk->state_change(sk);
651 sk->dead = 1;
652 sk->destroy = 1;
653 break;
655 default:
656 break;
659 sock->sk = NULL;
660 sk->socket = NULL; /* Not used, but we should do this. **/
662 return 0;
665 static int rose_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
667 struct sock *sk = sock->sk;
668 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
669 struct net_device *dev;
670 ax25_address *user, *source;
671 int n;
673 if (sk->zapped == 0)
674 return -EINVAL;
676 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
677 return -EINVAL;
679 if (addr->srose_family != AF_ROSE)
680 return -EINVAL;
682 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
683 return -EINVAL;
685 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
686 return -EINVAL;
688 if ((dev = rose_dev_get(&addr->srose_addr)) == NULL) {
689 SOCK_DEBUG(sk, "ROSE: bind failed: invalid address\n");
690 return -EADDRNOTAVAIL;
693 source = &addr->srose_call;
695 if ((user = ax25_findbyuid(current->euid)) == NULL) {
696 if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE))
697 return -EACCES;
698 user = source;
701 sk->protinfo.rose->source_addr = addr->srose_addr;
702 sk->protinfo.rose->source_call = *user;
703 sk->protinfo.rose->device = dev;
704 sk->protinfo.rose->source_ndigis = addr->srose_ndigis;
706 if (addr_len == sizeof(struct full_sockaddr_rose)) {
707 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
708 for (n = 0 ; n < addr->srose_ndigis ; n++)
709 sk->protinfo.rose->source_digis[n] = full_addr->srose_digis[n];
710 } else {
711 if (sk->protinfo.rose->source_ndigis == 1) {
712 sk->protinfo.rose->source_digis[0] = addr->srose_digi;
716 rose_insert_socket(sk);
718 sk->zapped = 0;
719 SOCK_DEBUG(sk, "ROSE: socket is bound\n");
720 return 0;
723 static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
725 struct sock *sk = sock->sk;
726 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
727 unsigned char cause, diagnostic;
728 ax25_address *user;
729 struct net_device *dev;
730 int n;
732 if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
733 sock->state = SS_CONNECTED;
734 return 0; /* Connect completed during a ERESTARTSYS event */
737 if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
738 sock->state = SS_UNCONNECTED;
739 return -ECONNREFUSED;
742 if (sk->state == TCP_ESTABLISHED)
743 return -EISCONN; /* No reconnect on a seqpacket socket */
745 sk->state = TCP_CLOSE;
746 sock->state = SS_UNCONNECTED;
748 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
749 return -EINVAL;
751 if (addr->srose_family != AF_ROSE)
752 return -EINVAL;
754 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
755 return -EINVAL;
757 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
758 return -EINVAL;
760 /* Source + Destination digis should not exceed ROSE_MAX_DIGIS */
761 if ((sk->protinfo.rose->source_ndigis + addr->srose_ndigis) > ROSE_MAX_DIGIS)
762 return -EINVAL;
764 if ((sk->protinfo.rose->neighbour = rose_get_neigh(&addr->srose_addr, &cause, &diagnostic)) == NULL)
765 return -ENETUNREACH;
767 if ((sk->protinfo.rose->lci = rose_new_lci(sk->protinfo.rose->neighbour)) == 0)
768 return -ENETUNREACH;
770 if (sk->zapped) { /* Must bind first - autobinding in this may or may not work */
771 sk->zapped = 0;
773 if ((dev = rose_dev_first()) == NULL)
774 return -ENETUNREACH;
776 if ((user = ax25_findbyuid(current->euid)) == NULL)
777 return -EINVAL;
779 memcpy(&sk->protinfo.rose->source_addr, dev->dev_addr, ROSE_ADDR_LEN);
780 sk->protinfo.rose->source_call = *user;
781 sk->protinfo.rose->device = dev;
783 rose_insert_socket(sk); /* Finish the bind */
786 sk->protinfo.rose->dest_addr = addr->srose_addr;
787 sk->protinfo.rose->dest_call = addr->srose_call;
788 sk->protinfo.rose->rand = ((int)sk->protinfo.rose & 0xFFFF) + sk->protinfo.rose->lci;
789 sk->protinfo.rose->dest_ndigis = addr->srose_ndigis;
791 if (addr_len == sizeof(struct full_sockaddr_rose)) {
792 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
793 for (n = 0 ; n < addr->srose_ndigis ; n++)
794 sk->protinfo.rose->dest_digis[n] = full_addr->srose_digis[n];
795 } else {
796 if (sk->protinfo.rose->dest_ndigis == 1) {
797 sk->protinfo.rose->dest_digis[0] = addr->srose_digi;
801 /* Move to connecting socket, start sending Connect Requests */
802 sock->state = SS_CONNECTING;
803 sk->state = TCP_SYN_SENT;
805 sk->protinfo.rose->state = ROSE_STATE_1;
807 sk->protinfo.rose->neighbour->use++;
809 rose_write_internal(sk, ROSE_CALL_REQUEST);
810 rose_start_heartbeat(sk);
811 rose_start_t1timer(sk);
813 /* Now the loop */
814 if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
815 return -EINPROGRESS;
817 cli(); /* To avoid races on the sleep */
820 * A Connect Ack with Choke or timeout or failed routing will go to closed.
822 while (sk->state == TCP_SYN_SENT) {
823 interruptible_sleep_on(sk->sleep);
824 if (signal_pending(current)) {
825 sti();
826 return -ERESTARTSYS;
830 if (sk->state != TCP_ESTABLISHED) {
831 sti();
832 sock->state = SS_UNCONNECTED;
833 return sock_error(sk); /* Always set at this point */
836 sock->state = SS_CONNECTED;
838 sti();
840 return 0;
843 static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
845 struct sock *sk;
846 struct sock *newsk;
847 struct sk_buff *skb;
849 if ((sk = sock->sk) == NULL)
850 return -EINVAL;
852 if (sk->type != SOCK_SEQPACKET)
853 return -EOPNOTSUPP;
855 if (sk->state != TCP_LISTEN)
856 return -EINVAL;
859 * The write queue this time is holding sockets ready to use
860 * hooked into the SABM we saved
862 do {
863 cli();
864 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
865 if (flags & O_NONBLOCK) {
866 sti();
867 return -EWOULDBLOCK;
869 interruptible_sleep_on(sk->sleep);
870 if (signal_pending(current)) {
871 sti();
872 return -ERESTARTSYS;
875 } while (skb == NULL);
877 newsk = skb->sk;
878 newsk->pair = NULL;
879 newsk->socket = newsock;
880 newsk->sleep = &newsock->wait;
881 sti();
883 /* Now attach up the new socket */
884 skb->sk = NULL;
885 kfree_skb(skb);
886 sk->ack_backlog--;
887 newsock->sk = newsk;
889 return 0;
892 static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
893 int *uaddr_len, int peer)
895 struct full_sockaddr_rose *srose = (struct full_sockaddr_rose *)uaddr;
896 struct sock *sk = sock->sk;
897 int n;
899 if (peer != 0) {
900 if (sk->state != TCP_ESTABLISHED)
901 return -ENOTCONN;
902 srose->srose_family = AF_ROSE;
903 srose->srose_addr = sk->protinfo.rose->dest_addr;
904 srose->srose_call = sk->protinfo.rose->dest_call;
905 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
906 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
907 srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
908 } else {
909 srose->srose_family = AF_ROSE;
910 srose->srose_addr = sk->protinfo.rose->source_addr;
911 srose->srose_call = sk->protinfo.rose->source_call;
912 srose->srose_ndigis = sk->protinfo.rose->source_ndigis;
913 for (n = 0 ; n < sk->protinfo.rose->source_ndigis ; n++)
914 srose->srose_digis[n] = sk->protinfo.rose->source_digis[n];
917 *uaddr_len = sizeof(struct full_sockaddr_rose);
918 return 0;
921 int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct rose_neigh *neigh, unsigned int lci)
923 struct sock *sk;
924 struct sock *make;
925 struct rose_facilities_struct facilities;
926 int n, len;
928 skb->sk = NULL; /* Initially we don't know who it's for */
931 * skb->data points to the rose frame start
933 memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
935 len = (((skb->data[3] >> 4) & 0x0F) + 1) / 2;
936 len += (((skb->data[3] >> 0) & 0x0F) + 1) / 2;
937 if (!rose_parse_facilities(skb->data + len + 4, &facilities)) {
938 rose_transmit_clear_request(neigh, lci, ROSE_INVALID_FACILITY, 76);
939 return 0;
942 sk = rose_find_listener(&facilities.source_addr, &facilities.source_call);
945 * We can't accept the Call Request.
947 if (sk == NULL || sk->ack_backlog == sk->max_ack_backlog || (make = rose_make_new(sk)) == NULL) {
948 rose_transmit_clear_request(neigh, lci, ROSE_NETWORK_CONGESTION, 120);
949 return 0;
952 skb->sk = make;
953 make->state = TCP_ESTABLISHED;
955 make->protinfo.rose->lci = lci;
956 make->protinfo.rose->dest_addr = facilities.dest_addr;
957 make->protinfo.rose->dest_call = facilities.dest_call;
958 make->protinfo.rose->dest_ndigis = facilities.dest_ndigis;
959 for (n = 0 ; n < facilities.dest_ndigis ; n++)
960 make->protinfo.rose->dest_digis[n] = facilities.dest_digis[n];
961 make->protinfo.rose->source_addr = facilities.source_addr;
962 make->protinfo.rose->source_call = facilities.source_call;
963 make->protinfo.rose->source_ndigis = facilities.source_ndigis;
964 for (n = 0 ; n < facilities.source_ndigis ; n++)
965 make->protinfo.rose->source_digis[n]= facilities.source_digis[n];
966 make->protinfo.rose->neighbour = neigh;
967 make->protinfo.rose->device = dev;
968 make->protinfo.rose->facilities = facilities;
970 make->protinfo.rose->neighbour->use++;
972 if (sk->protinfo.rose->defer) {
973 make->protinfo.rose->state = ROSE_STATE_5;
974 } else {
975 rose_write_internal(make, ROSE_CALL_ACCEPTED);
976 make->protinfo.rose->state = ROSE_STATE_3;
977 rose_start_idletimer(make);
980 make->protinfo.rose->condition = 0x00;
981 make->protinfo.rose->vs = 0;
982 make->protinfo.rose->va = 0;
983 make->protinfo.rose->vr = 0;
984 make->protinfo.rose->vl = 0;
985 sk->ack_backlog++;
986 make->pair = sk;
988 rose_insert_socket(make);
990 skb_queue_head(&sk->receive_queue, skb);
992 rose_start_heartbeat(make);
994 if (!sk->dead)
995 sk->data_ready(sk, skb->len);
997 return 1;
1000 static int rose_sendmsg(struct socket *sock, struct msghdr *msg, int len,
1001 struct scm_cookie *scm)
1003 struct sock *sk = sock->sk;
1004 struct sockaddr_rose *usrose = (struct sockaddr_rose *)msg->msg_name;
1005 int err;
1006 struct full_sockaddr_rose srose;
1007 struct sk_buff *skb;
1008 unsigned char *asmptr;
1009 int n, size, qbit = 0;
1011 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR))
1012 return -EINVAL;
1014 if (sk->zapped)
1015 return -EADDRNOTAVAIL;
1017 if (sk->shutdown & SEND_SHUTDOWN) {
1018 send_sig(SIGPIPE, current, 0);
1019 return -EPIPE;
1022 if (sk->protinfo.rose->neighbour == NULL || sk->protinfo.rose->device == NULL)
1023 return -ENETUNREACH;
1025 if (usrose != NULL) {
1026 if (msg->msg_namelen != sizeof(struct sockaddr_rose) && msg->msg_namelen != sizeof(struct full_sockaddr_rose))
1027 return -EINVAL;
1028 memset(&srose, 0, sizeof(struct full_sockaddr_rose));
1029 memcpy(&srose, usrose, msg->msg_namelen);
1030 if (rosecmp(&sk->protinfo.rose->dest_addr, &srose.srose_addr) != 0 ||
1031 ax25cmp(&sk->protinfo.rose->dest_call, &srose.srose_call) != 0)
1032 return -EISCONN;
1033 if (srose.srose_ndigis != sk->protinfo.rose->dest_ndigis)
1034 return -EISCONN;
1035 if (srose.srose_ndigis == sk->protinfo.rose->dest_ndigis) {
1036 for (n = 0 ; n < srose.srose_ndigis ; n++)
1037 if (ax25cmp(&sk->protinfo.rose->dest_digis[n], &srose.srose_digis[n]) != 0)
1038 return -EISCONN;
1040 if (srose.srose_family != AF_ROSE)
1041 return -EINVAL;
1042 } else {
1043 if (sk->state != TCP_ESTABLISHED)
1044 return -ENOTCONN;
1046 srose.srose_family = AF_ROSE;
1047 srose.srose_addr = sk->protinfo.rose->dest_addr;
1048 srose.srose_call = sk->protinfo.rose->dest_call;
1049 srose.srose_ndigis = sk->protinfo.rose->dest_ndigis;
1050 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1051 srose.srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1054 SOCK_DEBUG(sk, "ROSE: sendto: Addresses built.\n");
1056 /* Build a packet */
1057 SOCK_DEBUG(sk, "ROSE: sendto: building packet.\n");
1058 size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
1060 if ((skb = sock_alloc_send_skb(sk, size, 0, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
1061 return err;
1063 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN);
1066 * Put the data on the end
1068 SOCK_DEBUG(sk, "ROSE: Appending user data\n");
1070 asmptr = skb->h.raw = skb_put(skb, len);
1072 memcpy_fromiovec(asmptr, msg->msg_iov, len);
1075 * If the Q BIT Include socket option is in force, the first
1076 * byte of the user data is the logical value of the Q Bit.
1078 if (sk->protinfo.rose->qbitincl) {
1079 qbit = skb->data[0];
1080 skb_pull(skb, 1);
1084 * Push down the ROSE header
1086 asmptr = skb_push(skb, ROSE_MIN_LEN);
1088 SOCK_DEBUG(sk, "ROSE: Building Network Header.\n");
1090 /* Build a ROSE Network header */
1091 asmptr[0] = ((sk->protinfo.rose->lci >> 8) & 0x0F) | ROSE_GFI;
1092 asmptr[1] = (sk->protinfo.rose->lci >> 0) & 0xFF;
1093 asmptr[2] = ROSE_DATA;
1095 if (qbit)
1096 asmptr[0] |= ROSE_Q_BIT;
1098 SOCK_DEBUG(sk, "ROSE: Built header.\n");
1100 SOCK_DEBUG(sk, "ROSE: Transmitting buffer\n");
1102 if (sk->state != TCP_ESTABLISHED) {
1103 kfree_skb(skb);
1104 return -ENOTCONN;
1107 #ifdef M_BIT
1108 #define ROSE_PACLEN (256-ROSE_MIN_LEN)
1109 if (skb->len - ROSE_MIN_LEN > ROSE_PACLEN) {
1110 unsigned char header[ROSE_MIN_LEN];
1111 struct sk_buff *skbn;
1112 int frontlen;
1113 int lg;
1115 /* Save a copy of the Header */
1116 memcpy(header, skb->data, ROSE_MIN_LEN);
1117 skb_pull(skb, ROSE_MIN_LEN);
1119 frontlen = skb_headroom(skb);
1121 while (skb->len > 0) {
1122 if ((skbn = sock_alloc_send_skb(sk, frontlen + ROSE_PACLEN, 0, 0, &err)) == NULL)
1123 return err;
1125 skbn->sk = sk;
1126 skbn->free = 1;
1127 skbn->arp = 1;
1129 skb_reserve(skbn, frontlen);
1131 lg = (ROSE_PACLEN > skb->len) ? skb->len : ROSE_PACLEN;
1133 /* Copy the user data */
1134 memcpy(skb_put(skbn, lg), skb->data, lg);
1135 skb_pull(skb, lg);
1137 /* Duplicate the Header */
1138 skb_push(skbn, ROSE_MIN_LEN);
1139 memcpy(skbn->data, header, ROSE_MIN_LEN);
1141 if (skb->len > 0)
1142 skbn->data[2] |= M_BIT;
1144 skb_queue_tail(&sk->write_queue, skbn); /* Throw it on the queue */
1147 skb->free = 1;
1148 kfree_skb(skb, FREE_WRITE);
1149 } else {
1150 skb_queue_tail(&sk->write_queue, skb); /* Throw it on the queue */
1152 #else
1153 skb_queue_tail(&sk->write_queue, skb); /* Shove it onto the queue */
1154 #endif
1156 rose_kick(sk);
1158 return len;
1162 static int rose_recvmsg(struct socket *sock, struct msghdr *msg, int size,
1163 int flags, struct scm_cookie *scm)
1165 struct sock *sk = sock->sk;
1166 struct sockaddr_rose *srose = (struct sockaddr_rose *)msg->msg_name;
1167 int copied, qbit;
1168 unsigned char *asmptr;
1169 struct sk_buff *skb;
1170 int n, er;
1173 * This works for seqpacket too. The receiver has ordered the queue for
1174 * us! We do one quick check first though
1176 if (sk->state != TCP_ESTABLISHED)
1177 return -ENOTCONN;
1179 /* Now we can treat all alike */
1180 if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL)
1181 return er;
1183 qbit = (skb->data[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
1185 skb_pull(skb, ROSE_MIN_LEN);
1187 if (sk->protinfo.rose->qbitincl) {
1188 asmptr = skb_push(skb, 1);
1189 *asmptr = qbit;
1192 skb->h.raw = skb->data;
1193 copied = skb->len;
1195 if (copied > size) {
1196 copied = size;
1197 msg->msg_flags |= MSG_TRUNC;
1200 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1202 if (srose != NULL) {
1203 srose->srose_family = AF_ROSE;
1204 srose->srose_addr = sk->protinfo.rose->dest_addr;
1205 srose->srose_call = sk->protinfo.rose->dest_call;
1206 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
1207 if (msg->msg_namelen >= sizeof(struct full_sockaddr_rose)) {
1208 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)msg->msg_name;
1209 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1210 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1211 msg->msg_namelen = sizeof(struct full_sockaddr_rose);
1212 } else {
1213 if (sk->protinfo.rose->dest_ndigis >= 1) {
1214 srose->srose_ndigis = 1;
1215 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
1217 msg->msg_namelen = sizeof(struct sockaddr_rose);
1221 skb_free_datagram(sk, skb);
1223 return copied;
1227 static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1229 struct sock *sk = sock->sk;
1231 switch (cmd) {
1232 case TIOCOUTQ: {
1233 long amount;
1234 amount = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1235 if (amount < 0)
1236 amount = 0;
1237 return put_user(amount, (unsigned int *)arg);
1240 case TIOCINQ: {
1241 struct sk_buff *skb;
1242 long amount = 0L;
1243 /* These two are safe on a single CPU system as only user tasks fiddle here */
1244 if ((skb = skb_peek(&sk->receive_queue)) != NULL)
1245 amount = skb->len;
1246 return put_user(amount, (unsigned int *)arg);
1249 case SIOCGSTAMP:
1250 if (sk != NULL) {
1251 if (sk->stamp.tv_sec == 0)
1252 return -ENOENT;
1253 return copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)) ? -EFAULT : 0;
1255 return -EINVAL;
1257 case SIOCGIFADDR:
1258 case SIOCSIFADDR:
1259 case SIOCGIFDSTADDR:
1260 case SIOCSIFDSTADDR:
1261 case SIOCGIFBRDADDR:
1262 case SIOCSIFBRDADDR:
1263 case SIOCGIFNETMASK:
1264 case SIOCSIFNETMASK:
1265 case SIOCGIFMETRIC:
1266 case SIOCSIFMETRIC:
1267 return -EINVAL;
1269 case SIOCADDRT:
1270 case SIOCDELRT:
1271 case SIOCRSCLRRT:
1272 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1273 return rose_rt_ioctl(cmd, (void *)arg);
1275 case SIOCRSGCAUSE: {
1276 struct rose_cause_struct rose_cause;
1277 rose_cause.cause = sk->protinfo.rose->cause;
1278 rose_cause.diagnostic = sk->protinfo.rose->diagnostic;
1279 return copy_to_user((void *)arg, &rose_cause, sizeof(struct rose_cause_struct)) ? -EFAULT : 0;
1282 case SIOCRSSCAUSE: {
1283 struct rose_cause_struct rose_cause;
1284 if (copy_from_user(&rose_cause, (void *)arg, sizeof(struct rose_cause_struct)))
1285 return -EFAULT;
1286 sk->protinfo.rose->cause = rose_cause.cause;
1287 sk->protinfo.rose->diagnostic = rose_cause.diagnostic;
1288 return 0;
1291 case SIOCRSSL2CALL:
1292 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1293 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1294 ax25_listen_release(&rose_callsign, NULL);
1295 if (copy_from_user(&rose_callsign, (void *)arg, sizeof(ax25_address)))
1296 return -EFAULT;
1297 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1298 ax25_listen_register(&rose_callsign, NULL);
1299 return 0;
1301 case SIOCRSGL2CALL:
1302 return copy_to_user((void *)arg, &rose_callsign, sizeof(ax25_address)) ? -EFAULT : 0;
1304 case SIOCRSACCEPT:
1305 if (sk->protinfo.rose->state == ROSE_STATE_5) {
1306 rose_write_internal(sk, ROSE_CALL_ACCEPTED);
1307 rose_start_idletimer(sk);
1308 sk->protinfo.rose->condition = 0x00;
1309 sk->protinfo.rose->vs = 0;
1310 sk->protinfo.rose->va = 0;
1311 sk->protinfo.rose->vr = 0;
1312 sk->protinfo.rose->vl = 0;
1313 sk->protinfo.rose->state = ROSE_STATE_3;
1315 return 0;
1317 default:
1318 return dev_ioctl(cmd, (void *)arg);
1321 /*NOTREACHED*/
1322 return 0;
1325 static int rose_get_info(char *buffer, char **start, off_t offset, int length)
1327 struct sock *s;
1328 struct net_device *dev;
1329 const char *devname, *callsign;
1330 int len = 0;
1331 off_t pos = 0;
1332 off_t begin = 0;
1334 cli();
1336 len += sprintf(buffer, "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n");
1338 for (s = rose_list; s != NULL; s = s->next) {
1339 if ((dev = s->protinfo.rose->device) == NULL)
1340 devname = "???";
1341 else
1342 devname = dev->name;
1344 len += sprintf(buffer + len, "%-10s %-9s ",
1345 rose2asc(&s->protinfo.rose->dest_addr),
1346 ax2asc(&s->protinfo.rose->dest_call));
1348 if (ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0)
1349 callsign = "??????-?";
1350 else
1351 callsign = ax2asc(&s->protinfo.rose->source_call);
1353 len += sprintf(buffer + len, "%-10s %-9s %-5s %3.3X %05d %d %d %d %d %3lu %3lu %3lu %3lu %3lu %3lu/%03lu %5d %5d %ld\n",
1354 rose2asc(&s->protinfo.rose->source_addr),
1355 callsign,
1356 devname,
1357 s->protinfo.rose->lci & 0x0FFF,
1358 (s->protinfo.rose->neighbour) ? s->protinfo.rose->neighbour->number : 0,
1359 s->protinfo.rose->state,
1360 s->protinfo.rose->vs,
1361 s->protinfo.rose->vr,
1362 s->protinfo.rose->va,
1363 ax25_display_timer(&s->protinfo.rose->timer) / HZ,
1364 s->protinfo.rose->t1 / HZ,
1365 s->protinfo.rose->t2 / HZ,
1366 s->protinfo.rose->t3 / HZ,
1367 s->protinfo.rose->hb / HZ,
1368 ax25_display_timer(&s->protinfo.rose->idletimer) / (60 * HZ),
1369 s->protinfo.rose->idle / (60 * HZ),
1370 atomic_read(&s->wmem_alloc),
1371 atomic_read(&s->rmem_alloc),
1372 s->socket != NULL ? s->socket->inode->i_ino : 0L);
1374 pos = begin + len;
1376 if (pos < offset) {
1377 len = 0;
1378 begin = pos;
1381 if (pos > offset + length)
1382 break;
1385 sti();
1387 *start = buffer + (offset - begin);
1388 len -= (offset - begin);
1390 if (len > length) len = length;
1392 return(len);
1395 static struct net_proto_family rose_family_ops = {
1396 PF_ROSE,
1397 rose_create
1400 static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = {
1401 family: PF_ROSE,
1403 release: rose_release,
1404 bind: rose_bind,
1405 connect: rose_connect,
1406 socketpair: sock_no_socketpair,
1407 accept: rose_accept,
1408 getname: rose_getname,
1409 poll: datagram_poll,
1410 ioctl: rose_ioctl,
1411 listen: rose_listen,
1412 shutdown: sock_no_shutdown,
1413 setsockopt: rose_setsockopt,
1414 getsockopt: rose_getsockopt,
1415 sendmsg: rose_sendmsg,
1416 recvmsg: rose_recvmsg,
1417 mmap: sock_no_mmap,
1420 #include <linux/smp_lock.h>
1421 SOCKOPS_WRAP(rose_proto, PF_ROSE);
1423 static struct notifier_block rose_dev_notifier = {
1424 rose_device_event,
1428 static struct net_device *dev_rose;
1430 void __init rose_proto_init(struct net_proto *pro)
1432 int i;
1434 rose_callsign = null_ax25_address;
1436 if ((dev_rose = kmalloc(rose_ndevs * sizeof(struct net_device), GFP_KERNEL)) == NULL) {
1437 printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
1438 return;
1441 memset(dev_rose, 0x00, rose_ndevs * sizeof(struct net_device));
1443 for (i = 0; i < rose_ndevs; i++) {
1444 sprintf(dev_rose[i].name, "rose%d", i);
1445 dev_rose[i].init = rose_init;
1446 register_netdev(&dev_rose[i]);
1449 sock_register(&rose_family_ops);
1450 register_netdevice_notifier(&rose_dev_notifier);
1451 printk(KERN_INFO "F6FBB/G4KLX ROSE for Linux. Version 0.62 for AX25.037 Linux 2.1\n");
1453 ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
1454 ax25_linkfail_register(rose_link_failed);
1456 #ifdef CONFIG_SYSCTL
1457 rose_register_sysctl();
1458 #endif
1459 rose_loopback_init();
1461 rose_add_loopback_neigh();
1463 #ifdef CONFIG_PROC_FS
1464 proc_net_create("rose", 0, rose_get_info);
1465 proc_net_create("rose_neigh", 0, rose_neigh_get_info);
1466 proc_net_create("rose_nodes", 0, rose_nodes_get_info);
1467 proc_net_create("rose_routes", 0, rose_routes_get_info);
1468 #endif
1471 #ifdef MODULE
1472 EXPORT_NO_SYMBOLS;
1474 MODULE_PARM(rose_ndevs, "i");
1475 MODULE_PARM_DESC(rose_ndevs, "number of ROSE devices");
1477 MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
1478 MODULE_DESCRIPTION("The amateur radio ROSE network layer protocol");
1480 int init_module(void)
1482 rose_proto_init(NULL);
1484 return 0;
1487 void cleanup_module(void)
1489 int i;
1491 #ifdef CONFIG_PROC_FS
1492 proc_net_remove("rose");
1493 proc_net_remove("rose_neigh");
1494 proc_net_remove("rose_nodes");
1495 proc_net_remove("rose_routes");
1496 #endif
1497 rose_loopback_clear();
1499 rose_rt_free();
1501 ax25_protocol_release(AX25_P_ROSE);
1502 ax25_linkfail_release(rose_link_failed);
1504 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1505 ax25_listen_release(&rose_callsign, NULL);
1507 #ifdef CONFIG_SYSCTL
1508 rose_unregister_sysctl();
1509 #endif
1510 unregister_netdevice_notifier(&rose_dev_notifier);
1512 sock_unregister(PF_ROSE);
1514 for (i = 0; i < rose_ndevs; i++) {
1515 if (dev_rose[i].priv != NULL) {
1516 kfree(dev_rose[i].priv);
1517 dev_rose[i].priv = NULL;
1518 unregister_netdev(&dev_rose[i]);
1520 kfree(dev_rose[i].name);
1523 kfree(dev_rose);
1526 #endif
1528 #endif