* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / net / rose / af_rose.c
blobba9935aac9865a6cfc371be52423b3dd543c8469
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.
25 #include <linux/config.h>
26 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
27 #include <linux/module.h>
28 #include <linux/errno.h>
29 #include <linux/types.h>
30 #include <linux/socket.h>
31 #include <linux/in.h>
32 #include <linux/kernel.h>
33 #include <linux/sched.h>
34 #include <linux/timer.h>
35 #include <linux/string.h>
36 #include <linux/sockios.h>
37 #include <linux/net.h>
38 #include <linux/stat.h>
39 #include <net/ax25.h>
40 #include <linux/inet.h>
41 #include <linux/netdevice.h>
42 #include <linux/if_arp.h>
43 #include <linux/skbuff.h>
44 #include <net/sock.h>
45 #include <asm/segment.h>
46 #include <asm/system.h>
47 #include <asm/uaccess.h>
48 #include <linux/fcntl.h>
49 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
50 #include <linux/mm.h>
51 #include <linux/interrupt.h>
52 #include <linux/notifier.h>
53 #include <net/rose.h>
54 #include <linux/proc_fs.h>
55 #include <net/ip.h>
56 #include <net/arp.h>
57 #include <linux/init.h>
59 int rose_ndevs = 10;
61 int sysctl_rose_restart_request_timeout = ROSE_DEFAULT_T0;
62 int sysctl_rose_call_request_timeout = ROSE_DEFAULT_T1;
63 int sysctl_rose_reset_request_timeout = ROSE_DEFAULT_T2;
64 int sysctl_rose_clear_request_timeout = ROSE_DEFAULT_T3;
65 int sysctl_rose_no_activity_timeout = ROSE_DEFAULT_IDLE;
66 int sysctl_rose_ack_hold_back_timeout = ROSE_DEFAULT_HB;
67 int sysctl_rose_routing_control = ROSE_DEFAULT_ROUTING;
68 int sysctl_rose_link_fail_timeout = ROSE_DEFAULT_FAIL_TIMEOUT;
69 int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC;
70 int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
72 static struct sock *volatile rose_list = NULL;
74 static struct proto_ops rose_proto_ops;
76 ax25_address rose_callsign;
79 * Convert a ROSE address into text.
81 char *rose2asc(rose_address *addr)
83 static char buffer[11];
85 if (addr->rose_addr[0] == 0x00 && addr->rose_addr[1] == 0x00 &&
86 addr->rose_addr[2] == 0x00 && addr->rose_addr[3] == 0x00 &&
87 addr->rose_addr[4] == 0x00) {
88 strcpy(buffer, "*");
89 } else {
90 sprintf(buffer, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
91 addr->rose_addr[1] & 0xFF,
92 addr->rose_addr[2] & 0xFF,
93 addr->rose_addr[3] & 0xFF,
94 addr->rose_addr[4] & 0xFF);
97 return buffer;
101 * Compare two ROSE addresses, 0 == equal.
103 int rosecmp(rose_address *addr1, rose_address *addr2)
105 int i;
107 for (i = 0; i < 5; i++)
108 if (addr1->rose_addr[i] != addr2->rose_addr[i])
109 return 1;
111 return 0;
115 * Compare two ROSE addresses for only mask digits, 0 == equal.
117 int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
119 int i, j;
121 if (mask > 10)
122 return 1;
124 for (i = 0; i < mask; i++) {
125 j = i / 2;
127 if ((i % 2) != 0) {
128 if ((addr1->rose_addr[j] & 0x0F) != (addr2->rose_addr[j] & 0x0F))
129 return 1;
130 } else {
131 if ((addr1->rose_addr[j] & 0xF0) != (addr2->rose_addr[j] & 0xF0))
132 return 1;
136 return 0;
139 static void rose_free_sock(struct sock *sk)
141 sk_free(sk);
143 MOD_DEC_USE_COUNT;
146 static struct sock *rose_alloc_sock(void)
148 struct sock *sk;
149 rose_cb *rose;
151 if ((sk = sk_alloc(PF_ROSE, GFP_ATOMIC, 1)) == NULL)
152 return NULL;
154 if ((rose = kmalloc(sizeof(*rose), GFP_ATOMIC)) == NULL) {
155 sk_free(sk);
156 return NULL;
159 MOD_INC_USE_COUNT;
161 memset(rose, 0x00, sizeof(*rose));
163 sk->protinfo.rose = rose;
164 rose->sk = sk;
166 return sk;
170 * Socket removal during an interrupt is now safe.
172 static void rose_remove_socket(struct sock *sk)
174 struct sock *s;
175 unsigned long flags;
177 save_flags(flags); cli();
179 if ((s = rose_list) == sk) {
180 rose_list = s->next;
181 restore_flags(flags);
182 return;
185 while (s != NULL && s->next != NULL) {
186 if (s->next == sk) {
187 s->next = sk->next;
188 restore_flags(flags);
189 return;
192 s = s->next;
195 restore_flags(flags);
199 * Kill all bound sockets on a broken link layer connection to a
200 * particular neighbour.
202 void rose_kill_by_neigh(struct rose_neigh *neigh)
204 struct sock *s;
206 for (s = rose_list; s != NULL; s = s->next) {
207 if (s->protinfo.rose->neighbour == neigh) {
208 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
209 s->protinfo.rose->neighbour->use--;
210 s->protinfo.rose->neighbour = NULL;
216 * Kill all bound sockets on a dropped device.
218 static void rose_kill_by_device(struct net_device *dev)
220 struct sock *s;
222 for (s = rose_list; s != NULL; s = s->next) {
223 if (s->protinfo.rose->device == dev) {
224 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
225 s->protinfo.rose->neighbour->use--;
226 s->protinfo.rose->device = NULL;
232 * Handle device status changes.
234 static int rose_device_event(struct notifier_block *this, unsigned long event, void *ptr)
236 struct net_device *dev = (struct net_device *)ptr;
238 if (event != NETDEV_DOWN)
239 return NOTIFY_DONE;
241 switch (dev->type) {
242 case ARPHRD_ROSE:
243 rose_kill_by_device(dev);
244 break;
245 case ARPHRD_AX25:
246 rose_link_device_down(dev);
247 rose_rt_device_down(dev);
248 break;
251 return NOTIFY_DONE;
255 * Add a socket to the bound sockets list.
257 static void rose_insert_socket(struct sock *sk)
259 unsigned long flags;
261 save_flags(flags); cli();
263 sk->next = rose_list;
264 rose_list = sk;
266 restore_flags(flags);
270 * Find a socket that wants to accept the Call Request we just
271 * received.
273 static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
275 unsigned long flags;
276 struct sock *s;
278 save_flags(flags); cli();
280 for (s = rose_list; s != NULL; s = s->next) {
281 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) {
282 restore_flags(flags);
283 return s;
287 for (s = rose_list; s != NULL; s = s->next) {
288 if (rosecmp(&s->protinfo.rose->source_addr, addr) == 0 && ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0 && s->state == TCP_LISTEN) {
289 restore_flags(flags);
290 return s;
294 restore_flags(flags);
295 return NULL;
299 * Find a connected ROSE socket given my LCI and device.
301 struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
303 struct sock *s;
304 unsigned long flags;
306 save_flags(flags); cli();
308 for (s = rose_list; s != NULL; s = s->next) {
309 if (s->protinfo.rose->lci == lci && s->protinfo.rose->neighbour == neigh) {
310 restore_flags(flags);
311 return s;
315 restore_flags(flags);
317 return NULL;
321 * Find a unique LCI for a given device.
323 unsigned int rose_new_lci(struct rose_neigh *neigh)
325 int lci;
327 if (neigh->dce_mode) {
328 for (lci = 1; lci <= sysctl_rose_maximum_vcs; lci++)
329 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
330 return lci;
331 } else {
332 for (lci = sysctl_rose_maximum_vcs; lci > 0; lci--)
333 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
334 return lci;
337 return 0;
341 * Deferred destroy.
343 void rose_destroy_socket(struct sock *);
346 * Handler for deferred kills.
348 static void rose_destroy_timer(unsigned long data)
350 rose_destroy_socket((struct sock *)data);
354 * This is called from user mode and the timers. Thus it protects itself against
355 * interrupt users but doesn't worry about being called during work.
356 * Once it is removed from the queue no interrupt or bottom half will
357 * touch it and we are (fairly 8-) ) safe.
359 void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the timer */
361 struct sk_buff *skb;
362 unsigned long flags;
364 save_flags(flags); cli();
366 rose_stop_heartbeat(sk);
367 rose_stop_idletimer(sk);
368 rose_stop_timer(sk);
370 rose_remove_socket(sk);
371 rose_clear_queues(sk); /* Flush the queues */
373 while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
374 if (skb->sk != sk) { /* A pending connection */
375 skb->sk->dead = 1; /* Queue the unaccepted socket for death */
376 rose_start_heartbeat(skb->sk);
377 skb->sk->protinfo.rose->state = ROSE_STATE_0;
380 kfree_skb(skb);
383 if (atomic_read(&sk->wmem_alloc) != 0 || atomic_read(&sk->rmem_alloc) != 0) {
384 /* Defer: outstanding buffers */
385 init_timer(&sk->timer);
386 sk->timer.expires = jiffies + 10 * HZ;
387 sk->timer.function = rose_destroy_timer;
388 sk->timer.data = (unsigned long)sk;
389 add_timer(&sk->timer);
390 } else {
391 rose_free_sock(sk);
394 restore_flags(flags);
398 * Handling for system calls applied via the various interfaces to a
399 * ROSE socket object.
402 static int rose_setsockopt(struct socket *sock, int level, int optname,
403 char *optval, int optlen)
405 struct sock *sk = sock->sk;
406 int opt;
408 if (level != SOL_ROSE)
409 return -ENOPROTOOPT;
411 if (optlen < sizeof(int))
412 return -EINVAL;
414 if (get_user(opt, (int *)optval))
415 return -EFAULT;
417 switch (optname) {
418 case ROSE_DEFER:
419 sk->protinfo.rose->defer = opt ? 1 : 0;
420 return 0;
422 case ROSE_T1:
423 if (opt < 1)
424 return -EINVAL;
425 sk->protinfo.rose->t1 = opt * HZ;
426 return 0;
428 case ROSE_T2:
429 if (opt < 1)
430 return -EINVAL;
431 sk->protinfo.rose->t2 = opt * HZ;
432 return 0;
434 case ROSE_T3:
435 if (opt < 1)
436 return -EINVAL;
437 sk->protinfo.rose->t3 = opt * HZ;
438 return 0;
440 case ROSE_HOLDBACK:
441 if (opt < 1)
442 return -EINVAL;
443 sk->protinfo.rose->hb = opt * HZ;
444 return 0;
446 case ROSE_IDLE:
447 if (opt < 0)
448 return -EINVAL;
449 sk->protinfo.rose->idle = opt * 60 * HZ;
450 return 0;
452 case ROSE_QBITINCL:
453 sk->protinfo.rose->qbitincl = opt ? 1 : 0;
454 return 0;
456 default:
457 return -ENOPROTOOPT;
461 static int rose_getsockopt(struct socket *sock, int level, int optname,
462 char *optval, int *optlen)
464 struct sock *sk = sock->sk;
465 int val = 0;
466 int len;
468 if (level != SOL_ROSE)
469 return -ENOPROTOOPT;
471 if (get_user(len, optlen))
472 return -EFAULT;
474 switch (optname) {
475 case ROSE_DEFER:
476 val = sk->protinfo.rose->defer;
477 break;
479 case ROSE_T1:
480 val = sk->protinfo.rose->t1 / HZ;
481 break;
483 case ROSE_T2:
484 val = sk->protinfo.rose->t2 / HZ;
485 break;
487 case ROSE_T3:
488 val = sk->protinfo.rose->t3 / HZ;
489 break;
491 case ROSE_HOLDBACK:
492 val = sk->protinfo.rose->hb / HZ;
493 break;
495 case ROSE_IDLE:
496 val = sk->protinfo.rose->idle / (60 * HZ);
497 break;
499 case ROSE_QBITINCL:
500 val = sk->protinfo.rose->qbitincl;
501 break;
503 default:
504 return -ENOPROTOOPT;
507 len = min(len, sizeof(int));
509 if (put_user(len, optlen))
510 return -EFAULT;
512 if (copy_to_user(optval, &val, len))
513 return -EFAULT;
515 return 0;
518 static int rose_listen(struct socket *sock, int backlog)
520 struct sock *sk = sock->sk;
522 if (sk->state != TCP_LISTEN) {
523 sk->protinfo.rose->dest_ndigis = 0;
524 memset(&sk->protinfo.rose->dest_addr, '\0', ROSE_ADDR_LEN);
525 memset(&sk->protinfo.rose->dest_call, '\0', AX25_ADDR_LEN);
526 memset(sk->protinfo.rose->dest_digis, '\0', AX25_ADDR_LEN*ROSE_MAX_DIGIS);
527 sk->max_ack_backlog = backlog;
528 sk->state = TCP_LISTEN;
529 return 0;
532 return -EOPNOTSUPP;
535 static int rose_create(struct socket *sock, int protocol)
537 struct sock *sk;
538 rose_cb *rose;
540 if (sock->type != SOCK_SEQPACKET || protocol != 0)
541 return -ESOCKTNOSUPPORT;
543 if ((sk = rose_alloc_sock()) == NULL)
544 return -ENOMEM;
546 rose = sk->protinfo.rose;
548 sock_init_data(sock, sk);
550 skb_queue_head_init(&rose->ack_queue);
551 #ifdef M_BIT
552 skb_queue_head_init(&rose->frag_queue);
553 rose->fraglen = 0;
554 #endif
556 sock->ops = &rose_proto_ops;
557 sk->protocol = protocol;
559 init_timer(&rose->timer);
560 init_timer(&rose->idletimer);
562 rose->t1 = sysctl_rose_call_request_timeout;
563 rose->t2 = sysctl_rose_reset_request_timeout;
564 rose->t3 = sysctl_rose_clear_request_timeout;
565 rose->hb = sysctl_rose_ack_hold_back_timeout;
566 rose->idle = sysctl_rose_no_activity_timeout;
568 rose->state = ROSE_STATE_0;
570 return 0;
573 static struct sock *rose_make_new(struct sock *osk)
575 struct sock *sk;
576 rose_cb *rose;
578 if (osk->type != SOCK_SEQPACKET)
579 return NULL;
581 if ((sk = rose_alloc_sock()) == NULL)
582 return NULL;
584 rose = sk->protinfo.rose;
586 sock_init_data(NULL, sk);
588 skb_queue_head_init(&rose->ack_queue);
589 #ifdef M_BIT
590 skb_queue_head_init(&rose->frag_queue);
591 rose->fraglen = 0;
592 #endif
594 sk->type = osk->type;
595 sk->socket = osk->socket;
596 sk->priority = osk->priority;
597 sk->protocol = osk->protocol;
598 sk->rcvbuf = osk->rcvbuf;
599 sk->sndbuf = osk->sndbuf;
600 sk->debug = osk->debug;
601 sk->state = TCP_ESTABLISHED;
602 sk->sleep = osk->sleep;
603 sk->zapped = osk->zapped;
605 init_timer(&rose->timer);
606 init_timer(&rose->idletimer);
608 rose->t1 = osk->protinfo.rose->t1;
609 rose->t2 = osk->protinfo.rose->t2;
610 rose->t3 = osk->protinfo.rose->t3;
611 rose->hb = osk->protinfo.rose->hb;
612 rose->idle = osk->protinfo.rose->idle;
614 rose->defer = osk->protinfo.rose->defer;
615 rose->device = osk->protinfo.rose->device;
616 rose->qbitincl = osk->protinfo.rose->qbitincl;
618 return sk;
621 static int rose_release(struct socket *sock)
623 struct sock *sk = sock->sk;
625 if (sk == NULL) return 0;
627 switch (sk->protinfo.rose->state) {
629 case ROSE_STATE_0:
630 rose_disconnect(sk, 0, -1, -1);
631 rose_destroy_socket(sk);
632 break;
634 case ROSE_STATE_2:
635 sk->protinfo.rose->neighbour->use--;
636 rose_disconnect(sk, 0, -1, -1);
637 rose_destroy_socket(sk);
638 break;
640 case ROSE_STATE_1:
641 case ROSE_STATE_3:
642 case ROSE_STATE_4:
643 case ROSE_STATE_5:
644 rose_clear_queues(sk);
645 rose_stop_idletimer(sk);
646 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
647 rose_start_t3timer(sk);
648 sk->protinfo.rose->state = ROSE_STATE_2;
649 sk->state = TCP_CLOSE;
650 sk->shutdown |= SEND_SHUTDOWN;
651 sk->state_change(sk);
652 sk->dead = 1;
653 sk->destroy = 1;
654 break;
656 default:
657 break;
660 sock->sk = NULL;
661 sk->socket = NULL; /* Not used, but we should do this. **/
663 return 0;
666 static int rose_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
668 struct sock *sk = sock->sk;
669 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
670 struct net_device *dev;
671 ax25_address *user, *source;
672 int n;
674 if (sk->zapped == 0)
675 return -EINVAL;
677 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
678 return -EINVAL;
680 if (addr->srose_family != AF_ROSE)
681 return -EINVAL;
683 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
684 return -EINVAL;
686 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
687 return -EINVAL;
689 if ((dev = rose_dev_get(&addr->srose_addr)) == NULL) {
690 SOCK_DEBUG(sk, "ROSE: bind failed: invalid address\n");
691 return -EADDRNOTAVAIL;
694 source = &addr->srose_call;
696 if ((user = ax25_findbyuid(current->euid)) == NULL) {
697 if (ax25_uid_policy && !suser())
698 return -EACCES;
699 user = source;
702 sk->protinfo.rose->source_addr = addr->srose_addr;
703 sk->protinfo.rose->source_call = *user;
704 sk->protinfo.rose->device = dev;
705 sk->protinfo.rose->source_ndigis = addr->srose_ndigis;
707 if (addr_len == sizeof(struct full_sockaddr_rose)) {
708 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
709 for (n = 0 ; n < addr->srose_ndigis ; n++)
710 sk->protinfo.rose->source_digis[n] = full_addr->srose_digis[n];
711 } else {
712 if (sk->protinfo.rose->source_ndigis == 1) {
713 sk->protinfo.rose->source_digis[0] = addr->srose_digi;
717 rose_insert_socket(sk);
719 sk->zapped = 0;
720 SOCK_DEBUG(sk, "ROSE: socket is bound\n");
721 return 0;
724 static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
726 struct sock *sk = sock->sk;
727 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
728 unsigned char cause, diagnostic;
729 ax25_address *user;
730 struct net_device *dev;
731 int n;
733 if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
734 sock->state = SS_CONNECTED;
735 return 0; /* Connect completed during a ERESTARTSYS event */
738 if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
739 sock->state = SS_UNCONNECTED;
740 return -ECONNREFUSED;
743 if (sk->state == TCP_ESTABLISHED)
744 return -EISCONN; /* No reconnect on a seqpacket socket */
746 sk->state = TCP_CLOSE;
747 sock->state = SS_UNCONNECTED;
749 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
750 return -EINVAL;
752 if (addr->srose_family != AF_ROSE)
753 return -EINVAL;
755 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
756 return -EINVAL;
758 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
759 return -EINVAL;
761 /* Source + Destination digis should not exceed ROSE_MAX_DIGIS */
762 if ((sk->protinfo.rose->source_ndigis + addr->srose_ndigis) > ROSE_MAX_DIGIS)
763 return -EINVAL;
765 if ((sk->protinfo.rose->neighbour = rose_get_neigh(&addr->srose_addr, &cause, &diagnostic)) == NULL)
766 return -ENETUNREACH;
768 if ((sk->protinfo.rose->lci = rose_new_lci(sk->protinfo.rose->neighbour)) == 0)
769 return -ENETUNREACH;
771 if (sk->zapped) { /* Must bind first - autobinding in this may or may not work */
772 sk->zapped = 0;
774 if ((dev = rose_dev_first()) == NULL)
775 return -ENETUNREACH;
777 if ((user = ax25_findbyuid(current->euid)) == NULL)
778 return -EINVAL;
780 memcpy(&sk->protinfo.rose->source_addr, dev->dev_addr, ROSE_ADDR_LEN);
781 sk->protinfo.rose->source_call = *user;
782 sk->protinfo.rose->device = dev;
784 rose_insert_socket(sk); /* Finish the bind */
787 sk->protinfo.rose->dest_addr = addr->srose_addr;
788 sk->protinfo.rose->dest_call = addr->srose_call;
789 sk->protinfo.rose->rand = ((int)sk->protinfo.rose & 0xFFFF) + sk->protinfo.rose->lci;
790 sk->protinfo.rose->dest_ndigis = addr->srose_ndigis;
792 if (addr_len == sizeof(struct full_sockaddr_rose)) {
793 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
794 for (n = 0 ; n < addr->srose_ndigis ; n++)
795 sk->protinfo.rose->dest_digis[n] = full_addr->srose_digis[n];
796 } else {
797 if (sk->protinfo.rose->dest_ndigis == 1) {
798 sk->protinfo.rose->dest_digis[0] = addr->srose_digi;
802 /* Move to connecting socket, start sending Connect Requests */
803 sock->state = SS_CONNECTING;
804 sk->state = TCP_SYN_SENT;
806 sk->protinfo.rose->state = ROSE_STATE_1;
808 sk->protinfo.rose->neighbour->use++;
810 rose_write_internal(sk, ROSE_CALL_REQUEST);
811 rose_start_heartbeat(sk);
812 rose_start_t1timer(sk);
814 /* Now the loop */
815 if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
816 return -EINPROGRESS;
818 cli(); /* To avoid races on the sleep */
821 * A Connect Ack with Choke or timeout or failed routing will go to closed.
823 while (sk->state == TCP_SYN_SENT) {
824 interruptible_sleep_on(sk->sleep);
825 if (signal_pending(current)) {
826 sti();
827 return -ERESTARTSYS;
831 if (sk->state != TCP_ESTABLISHED) {
832 sti();
833 sock->state = SS_UNCONNECTED;
834 return sock_error(sk); /* Always set at this point */
837 sock->state = SS_CONNECTED;
839 sti();
841 return 0;
844 static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
846 struct sock *sk;
847 struct sock *newsk;
848 struct sk_buff *skb;
850 if ((sk = sock->sk) == NULL)
851 return -EINVAL;
853 if (sk->type != SOCK_SEQPACKET)
854 return -EOPNOTSUPP;
856 if (sk->state != TCP_LISTEN)
857 return -EINVAL;
860 * The write queue this time is holding sockets ready to use
861 * hooked into the SABM we saved
863 do {
864 cli();
865 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
866 if (flags & O_NONBLOCK) {
867 sti();
868 return -EWOULDBLOCK;
870 interruptible_sleep_on(sk->sleep);
871 if (signal_pending(current)) {
872 sti();
873 return -ERESTARTSYS;
876 } while (skb == NULL);
878 newsk = skb->sk;
879 newsk->pair = NULL;
880 newsk->socket = newsock;
881 newsk->sleep = &newsock->wait;
882 sti();
884 /* Now attach up the new socket */
885 skb->sk = NULL;
886 kfree_skb(skb);
887 sk->ack_backlog--;
888 newsock->sk = newsk;
890 return 0;
893 static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
894 int *uaddr_len, int peer)
896 struct sockaddr_rose *srose = (struct sockaddr_rose *)uaddr;
897 struct sock *sk = sock->sk;
898 int n;
900 if (peer != 0) {
901 if (sk->state != TCP_ESTABLISHED)
902 return -ENOTCONN;
903 srose->srose_family = AF_ROSE;
904 srose->srose_ndigis = 0;
905 srose->srose_addr = sk->protinfo.rose->dest_addr;
906 srose->srose_call = sk->protinfo.rose->dest_call;
907 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
908 if (*uaddr_len >= sizeof(struct full_sockaddr_rose)) {
909 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)uaddr;
910 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
911 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
912 *uaddr_len = sizeof(struct full_sockaddr_rose);
913 } else {
914 if (sk->protinfo.rose->dest_ndigis >= 1) {
915 srose->srose_ndigis = 1;
916 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
918 *uaddr_len = sizeof(struct sockaddr_rose);
920 } else {
921 srose->srose_family = AF_ROSE;
922 srose->srose_ndigis = 0;
923 srose->srose_addr = sk->protinfo.rose->source_addr;
924 srose->srose_call = sk->protinfo.rose->source_call;
925 srose->srose_ndigis = sk->protinfo.rose->source_ndigis;
926 if (*uaddr_len >= sizeof(struct full_sockaddr_rose)) {
927 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)uaddr;
928 for (n = 0 ; n < sk->protinfo.rose->source_ndigis ; n++)
929 full_srose->srose_digis[n] = sk->protinfo.rose->source_digis[n];
930 *uaddr_len = sizeof(struct full_sockaddr_rose);
931 } else {
932 if (sk->protinfo.rose->source_ndigis >= 1) {
933 srose->srose_ndigis = 1;
934 srose->srose_digi = sk->protinfo.rose->source_digis[sk->protinfo.rose->source_ndigis-1];
936 *uaddr_len = sizeof(struct sockaddr_rose);
940 return 0;
943 int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct rose_neigh *neigh, unsigned int lci)
945 struct sock *sk;
946 struct sock *make;
947 struct rose_facilities_struct facilities;
948 int n, len;
950 skb->sk = NULL; /* Initially we don't know who it's for */
953 * skb->data points to the rose frame start
955 memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
957 len = (((skb->data[3] >> 4) & 0x0F) + 1) / 2;
958 len += (((skb->data[3] >> 0) & 0x0F) + 1) / 2;
959 if (!rose_parse_facilities(skb->data + len + 4, &facilities)) {
960 rose_transmit_clear_request(neigh, lci, ROSE_INVALID_FACILITY, 76);
961 return 0;
964 sk = rose_find_listener(&facilities.source_addr, &facilities.source_call);
967 * We can't accept the Call Request.
969 if (sk == NULL || sk->ack_backlog == sk->max_ack_backlog || (make = rose_make_new(sk)) == NULL) {
970 rose_transmit_clear_request(neigh, lci, ROSE_NETWORK_CONGESTION, 120);
971 return 0;
974 skb->sk = make;
975 make->state = TCP_ESTABLISHED;
977 make->protinfo.rose->lci = lci;
978 make->protinfo.rose->dest_addr = facilities.dest_addr;
979 make->protinfo.rose->dest_call = facilities.dest_call;
980 make->protinfo.rose->dest_ndigis = facilities.dest_ndigis;
981 for (n = 0 ; n < facilities.dest_ndigis ; n++)
982 make->protinfo.rose->dest_digis[n] = facilities.dest_digis[n];
983 make->protinfo.rose->source_addr = facilities.source_addr;
984 make->protinfo.rose->source_call = facilities.source_call;
985 make->protinfo.rose->source_ndigis = facilities.source_ndigis;
986 for (n = 0 ; n < facilities.source_ndigis ; n++)
987 make->protinfo.rose->source_digis[n]= facilities.source_digis[n];
988 make->protinfo.rose->neighbour = neigh;
989 make->protinfo.rose->device = dev;
990 make->protinfo.rose->facilities = facilities;
992 make->protinfo.rose->neighbour->use++;
994 if (sk->protinfo.rose->defer) {
995 make->protinfo.rose->state = ROSE_STATE_5;
996 } else {
997 rose_write_internal(make, ROSE_CALL_ACCEPTED);
998 make->protinfo.rose->state = ROSE_STATE_3;
999 rose_start_idletimer(make);
1002 make->protinfo.rose->condition = 0x00;
1003 make->protinfo.rose->vs = 0;
1004 make->protinfo.rose->va = 0;
1005 make->protinfo.rose->vr = 0;
1006 make->protinfo.rose->vl = 0;
1007 sk->ack_backlog++;
1008 make->pair = sk;
1010 rose_insert_socket(make);
1012 skb_queue_head(&sk->receive_queue, skb);
1014 rose_start_heartbeat(make);
1016 if (!sk->dead)
1017 sk->data_ready(sk, skb->len);
1019 return 1;
1022 static int rose_sendmsg(struct socket *sock, struct msghdr *msg, int len,
1023 struct scm_cookie *scm)
1025 struct sock *sk = sock->sk;
1026 struct sockaddr_rose *usrose = (struct sockaddr_rose *)msg->msg_name;
1027 int err;
1028 struct full_sockaddr_rose srose;
1029 struct sk_buff *skb;
1030 unsigned char *asmptr;
1031 int n, size, qbit = 0;
1033 if (msg->msg_flags & ~MSG_DONTWAIT)
1034 return -EINVAL;
1036 if (sk->zapped)
1037 return -EADDRNOTAVAIL;
1039 if (sk->shutdown & SEND_SHUTDOWN) {
1040 send_sig(SIGPIPE, current, 0);
1041 return -EPIPE;
1044 if (sk->protinfo.rose->neighbour == NULL || sk->protinfo.rose->device == NULL)
1045 return -ENETUNREACH;
1047 if (usrose != NULL) {
1048 if (msg->msg_namelen != sizeof(struct sockaddr_rose) && msg->msg_namelen != sizeof(struct full_sockaddr_rose))
1049 return -EINVAL;
1050 memset(&srose, 0, sizeof(struct full_sockaddr_rose));
1051 memcpy(&srose, usrose, msg->msg_namelen);
1052 if (rosecmp(&sk->protinfo.rose->dest_addr, &srose.srose_addr) != 0 ||
1053 ax25cmp(&sk->protinfo.rose->dest_call, &srose.srose_call) != 0)
1054 return -EISCONN;
1055 if (srose.srose_ndigis != sk->protinfo.rose->dest_ndigis)
1056 return -EISCONN;
1057 if (srose.srose_ndigis == sk->protinfo.rose->dest_ndigis) {
1058 for (n = 0 ; n < srose.srose_ndigis ; n++)
1059 if (ax25cmp(&sk->protinfo.rose->dest_digis[n], &srose.srose_digis[n]) != 0)
1060 return -EISCONN;
1062 if (srose.srose_family != AF_ROSE)
1063 return -EINVAL;
1064 } else {
1065 if (sk->state != TCP_ESTABLISHED)
1066 return -ENOTCONN;
1068 srose.srose_family = AF_ROSE;
1069 srose.srose_addr = sk->protinfo.rose->dest_addr;
1070 srose.srose_call = sk->protinfo.rose->dest_call;
1071 srose.srose_ndigis = sk->protinfo.rose->dest_ndigis;
1072 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1073 srose.srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1076 SOCK_DEBUG(sk, "ROSE: sendto: Addresses built.\n");
1078 /* Build a packet */
1079 SOCK_DEBUG(sk, "ROSE: sendto: building packet.\n");
1080 size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
1082 if ((skb = sock_alloc_send_skb(sk, size, 0, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
1083 return err;
1085 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN);
1088 * Put the data on the end
1090 SOCK_DEBUG(sk, "ROSE: Appending user data\n");
1092 asmptr = skb->h.raw = skb_put(skb, len);
1094 memcpy_fromiovec(asmptr, msg->msg_iov, len);
1097 * If the Q BIT Include socket option is in force, the first
1098 * byte of the user data is the logical value of the Q Bit.
1100 if (sk->protinfo.rose->qbitincl) {
1101 qbit = skb->data[0];
1102 skb_pull(skb, 1);
1106 * Push down the ROSE header
1108 asmptr = skb_push(skb, ROSE_MIN_LEN);
1110 SOCK_DEBUG(sk, "ROSE: Building Network Header.\n");
1112 /* Build a ROSE Network header */
1113 asmptr[0] = ((sk->protinfo.rose->lci >> 8) & 0x0F) | ROSE_GFI;
1114 asmptr[1] = (sk->protinfo.rose->lci >> 0) & 0xFF;
1115 asmptr[2] = ROSE_DATA;
1117 if (qbit)
1118 asmptr[0] |= ROSE_Q_BIT;
1120 SOCK_DEBUG(sk, "ROSE: Built header.\n");
1122 SOCK_DEBUG(sk, "ROSE: Transmitting buffer\n");
1124 if (sk->state != TCP_ESTABLISHED) {
1125 kfree_skb(skb);
1126 return -ENOTCONN;
1129 #ifdef M_BIT
1130 #define ROSE_PACLEN (256-ROSE_MIN_LEN)
1131 if (skb->len - ROSE_MIN_LEN > ROSE_PACLEN) {
1132 unsigned char header[ROSE_MIN_LEN];
1133 struct sk_buff *skbn;
1134 int frontlen;
1135 int lg;
1137 /* Save a copy of the Header */
1138 memcpy(header, skb->data, ROSE_MIN_LEN);
1139 skb_pull(skb, ROSE_MIN_LEN);
1141 frontlen = skb_headroom(skb);
1143 while (skb->len > 0) {
1144 if ((skbn = sock_alloc_send_skb(sk, frontlen + ROSE_PACLEN, 0, 0, &err)) == NULL)
1145 return err;
1147 skbn->sk = sk;
1148 skbn->free = 1;
1149 skbn->arp = 1;
1151 skb_reserve(skbn, frontlen);
1153 lg = (ROSE_PACLEN > skb->len) ? skb->len : ROSE_PACLEN;
1155 /* Copy the user data */
1156 memcpy(skb_put(skbn, lg), skb->data, lg);
1157 skb_pull(skb, lg);
1159 /* Duplicate the Header */
1160 skb_push(skbn, ROSE_MIN_LEN);
1161 memcpy(skbn->data, header, ROSE_MIN_LEN);
1163 if (skb->len > 0)
1164 skbn->data[2] |= M_BIT;
1166 skb_queue_tail(&sk->write_queue, skbn); /* Throw it on the queue */
1169 skb->free = 1;
1170 kfree_skb(skb, FREE_WRITE);
1171 } else {
1172 skb_queue_tail(&sk->write_queue, skb); /* Throw it on the queue */
1174 #else
1175 skb_queue_tail(&sk->write_queue, skb); /* Shove it onto the queue */
1176 #endif
1178 rose_kick(sk);
1180 return len;
1184 static int rose_recvmsg(struct socket *sock, struct msghdr *msg, int size,
1185 int flags, struct scm_cookie *scm)
1187 struct sock *sk = sock->sk;
1188 struct sockaddr_rose *srose = (struct sockaddr_rose *)msg->msg_name;
1189 int copied, qbit;
1190 unsigned char *asmptr;
1191 struct sk_buff *skb;
1192 int n, er;
1195 * This works for seqpacket too. The receiver has ordered the queue for
1196 * us! We do one quick check first though
1198 if (sk->state != TCP_ESTABLISHED)
1199 return -ENOTCONN;
1201 /* Now we can treat all alike */
1202 if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL)
1203 return er;
1205 qbit = (skb->data[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
1207 skb_pull(skb, ROSE_MIN_LEN);
1209 if (sk->protinfo.rose->qbitincl) {
1210 asmptr = skb_push(skb, 1);
1211 *asmptr = qbit;
1214 skb->h.raw = skb->data;
1215 copied = skb->len;
1217 if (copied > size) {
1218 copied = size;
1219 msg->msg_flags |= MSG_TRUNC;
1222 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1224 if (srose != NULL) {
1225 srose->srose_family = AF_ROSE;
1226 srose->srose_addr = sk->protinfo.rose->dest_addr;
1227 srose->srose_call = sk->protinfo.rose->dest_call;
1228 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
1229 if (msg->msg_namelen >= sizeof(struct full_sockaddr_rose)) {
1230 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)msg->msg_name;
1231 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1232 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1233 msg->msg_namelen = sizeof(struct full_sockaddr_rose);
1234 } else {
1235 if (sk->protinfo.rose->dest_ndigis >= 1) {
1236 srose->srose_ndigis = 1;
1237 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
1239 msg->msg_namelen = sizeof(struct sockaddr_rose);
1243 skb_free_datagram(sk, skb);
1245 return copied;
1249 static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1251 struct sock *sk = sock->sk;
1253 switch (cmd) {
1254 case TIOCOUTQ: {
1255 long amount;
1256 amount = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1257 if (amount < 0)
1258 amount = 0;
1259 if (put_user(amount, (unsigned int *)arg))
1260 return -EFAULT;
1261 return 0;
1264 case TIOCINQ: {
1265 struct sk_buff *skb;
1266 long amount = 0L;
1267 /* These two are safe on a single CPU system as only user tasks fiddle here */
1268 if ((skb = skb_peek(&sk->receive_queue)) != NULL)
1269 amount = skb->len;
1270 if (put_user(amount, (unsigned int *)arg))
1271 return -EFAULT;
1272 return 0;
1275 case SIOCGSTAMP:
1276 if (sk != NULL) {
1277 if (sk->stamp.tv_sec == 0)
1278 return -ENOENT;
1279 if (copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)))
1280 return -EFAULT;
1281 return 0;
1283 return -EINVAL;
1285 case SIOCGIFADDR:
1286 case SIOCSIFADDR:
1287 case SIOCGIFDSTADDR:
1288 case SIOCSIFDSTADDR:
1289 case SIOCGIFBRDADDR:
1290 case SIOCSIFBRDADDR:
1291 case SIOCGIFNETMASK:
1292 case SIOCSIFNETMASK:
1293 case SIOCGIFMETRIC:
1294 case SIOCSIFMETRIC:
1295 return -EINVAL;
1297 case SIOCADDRT:
1298 case SIOCDELRT:
1299 case SIOCRSCLRRT:
1300 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1301 return rose_rt_ioctl(cmd, (void *)arg);
1303 case SIOCRSGCAUSE: {
1304 struct rose_cause_struct rose_cause;
1305 rose_cause.cause = sk->protinfo.rose->cause;
1306 rose_cause.diagnostic = sk->protinfo.rose->diagnostic;
1307 if (copy_to_user((void *)arg, &rose_cause, sizeof(struct rose_cause_struct)))
1308 return -EFAULT;
1309 return 0;
1312 case SIOCRSSCAUSE: {
1313 struct rose_cause_struct rose_cause;
1314 if (copy_from_user(&rose_cause, (void *)arg, sizeof(struct rose_cause_struct)))
1315 return -EFAULT;
1316 sk->protinfo.rose->cause = rose_cause.cause;
1317 sk->protinfo.rose->diagnostic = rose_cause.diagnostic;
1318 return 0;
1321 case SIOCRSSL2CALL:
1322 if (!suser()) return -EPERM;
1323 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1324 ax25_listen_release(&rose_callsign, NULL);
1325 if (copy_from_user(&rose_callsign, (void *)arg, sizeof(ax25_address)))
1326 return -EFAULT;
1327 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1328 ax25_listen_register(&rose_callsign, NULL);
1329 return 0;
1331 case SIOCRSGL2CALL:
1332 if (copy_to_user((void *)arg, &rose_callsign, sizeof(ax25_address)))
1333 return -EFAULT;
1334 return 0;
1336 case SIOCRSACCEPT:
1337 if (sk->protinfo.rose->state == ROSE_STATE_5) {
1338 rose_write_internal(sk, ROSE_CALL_ACCEPTED);
1339 rose_start_idletimer(sk);
1340 sk->protinfo.rose->condition = 0x00;
1341 sk->protinfo.rose->vs = 0;
1342 sk->protinfo.rose->va = 0;
1343 sk->protinfo.rose->vr = 0;
1344 sk->protinfo.rose->vl = 0;
1345 sk->protinfo.rose->state = ROSE_STATE_3;
1347 return 0;
1349 default:
1350 return dev_ioctl(cmd, (void *)arg);
1353 /*NOTREACHED*/
1354 return 0;
1357 static int rose_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
1359 struct sock *s;
1360 struct net_device *dev;
1361 const char *devname, *callsign;
1362 int len = 0;
1363 off_t pos = 0;
1364 off_t begin = 0;
1366 cli();
1368 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");
1370 for (s = rose_list; s != NULL; s = s->next) {
1371 if ((dev = s->protinfo.rose->device) == NULL)
1372 devname = "???";
1373 else
1374 devname = dev->name;
1376 len += sprintf(buffer + len, "%-10s %-9s ",
1377 rose2asc(&s->protinfo.rose->dest_addr),
1378 ax2asc(&s->protinfo.rose->dest_call));
1380 if (ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0)
1381 callsign = "??????-?";
1382 else
1383 callsign = ax2asc(&s->protinfo.rose->source_call);
1385 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",
1386 rose2asc(&s->protinfo.rose->source_addr),
1387 callsign,
1388 devname,
1389 s->protinfo.rose->lci & 0x0FFF,
1390 (s->protinfo.rose->neighbour) ? s->protinfo.rose->neighbour->number : 0,
1391 s->protinfo.rose->state,
1392 s->protinfo.rose->vs,
1393 s->protinfo.rose->vr,
1394 s->protinfo.rose->va,
1395 ax25_display_timer(&s->protinfo.rose->timer) / HZ,
1396 s->protinfo.rose->t1 / HZ,
1397 s->protinfo.rose->t2 / HZ,
1398 s->protinfo.rose->t3 / HZ,
1399 s->protinfo.rose->hb / HZ,
1400 ax25_display_timer(&s->protinfo.rose->idletimer) / (60 * HZ),
1401 s->protinfo.rose->idle / (60 * HZ),
1402 atomic_read(&s->wmem_alloc),
1403 atomic_read(&s->rmem_alloc),
1404 s->socket != NULL ? s->socket->inode->i_ino : 0L);
1406 pos = begin + len;
1408 if (pos < offset) {
1409 len = 0;
1410 begin = pos;
1413 if (pos > offset + length)
1414 break;
1417 sti();
1419 *start = buffer + (offset - begin);
1420 len -= (offset - begin);
1422 if (len > length) len = length;
1424 return(len);
1427 static struct net_proto_family rose_family_ops = {
1428 PF_ROSE,
1429 rose_create
1432 static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = {
1433 PF_ROSE,
1435 rose_release,
1436 rose_bind,
1437 rose_connect,
1438 sock_no_socketpair,
1439 rose_accept,
1440 rose_getname,
1441 datagram_poll,
1442 rose_ioctl,
1443 rose_listen,
1444 sock_no_shutdown,
1445 rose_setsockopt,
1446 rose_getsockopt,
1447 sock_no_fcntl,
1448 rose_sendmsg,
1449 rose_recvmsg,
1450 sock_no_mmap
1453 #include <linux/smp_lock.h>
1454 SOCKOPS_WRAP(rose_proto, PF_ROSE);
1456 static struct notifier_block rose_dev_notifier = {
1457 rose_device_event,
1461 #ifdef CONFIG_PROC_FS
1462 static struct proc_dir_entry proc_net_rose = {
1463 PROC_NET_RS, 4, "rose",
1464 S_IFREG | S_IRUGO, 1, 0, 0,
1465 0, &proc_net_inode_operations,
1466 rose_get_info
1468 static struct proc_dir_entry proc_net_rose_neigh = {
1469 PROC_NET_RS_NEIGH, 10, "rose_neigh",
1470 S_IFREG | S_IRUGO, 1, 0, 0,
1471 0, &proc_net_inode_operations,
1472 rose_neigh_get_info
1474 static struct proc_dir_entry proc_net_rose_nodes = {
1475 PROC_NET_RS_NODES, 10, "rose_nodes",
1476 S_IFREG | S_IRUGO, 1, 0, 0,
1477 0, &proc_net_inode_operations,
1478 rose_nodes_get_info
1480 static struct proc_dir_entry proc_net_rose_routes = {
1481 PROC_NET_RS_ROUTES, 11, "rose_routes",
1482 S_IFREG | S_IRUGO, 1, 0, 0,
1483 0, &proc_net_inode_operations,
1484 rose_routes_get_info
1486 #endif
1488 static struct net_device *dev_rose;
1490 void __init rose_proto_init(struct net_proto *pro)
1492 int i;
1494 rose_callsign = null_ax25_address;
1496 if ((dev_rose = kmalloc(rose_ndevs * sizeof(struct net_device), GFP_KERNEL)) == NULL) {
1497 printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
1498 return;
1501 memset(dev_rose, 0x00, rose_ndevs * sizeof(struct net_device));
1503 for (i = 0; i < rose_ndevs; i++) {
1504 dev_rose[i].name = kmalloc(20, GFP_KERNEL);
1505 if(dev_rose[i].name == NULL)
1507 printk(KERN_ERR "Rose: unable to register ROSE devices.\n");
1508 break;
1510 sprintf(dev_rose[i].name, "rose%d", i);
1511 dev_rose[i].init = rose_init;
1512 register_netdev(&dev_rose[i]);
1515 sock_register(&rose_family_ops);
1516 register_netdevice_notifier(&rose_dev_notifier);
1517 printk(KERN_INFO "F6FBB/G4KLX ROSE for Linux. Version 0.62 for AX25.037 Linux 2.1\n");
1519 ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
1520 ax25_linkfail_register(rose_link_failed);
1522 #ifdef CONFIG_SYSCTL
1523 rose_register_sysctl();
1524 #endif
1525 rose_loopback_init();
1527 rose_add_loopback_neigh();
1529 #ifdef CONFIG_PROC_FS
1530 proc_net_register(&proc_net_rose);
1531 proc_net_register(&proc_net_rose_neigh);
1532 proc_net_register(&proc_net_rose_nodes);
1533 proc_net_register(&proc_net_rose_routes);
1534 #endif
1537 #ifdef MODULE
1538 EXPORT_NO_SYMBOLS;
1540 MODULE_PARM(rose_ndevs, "i");
1541 MODULE_PARM_DESC(rose_ndevs, "number of ROSE devices");
1543 MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
1544 MODULE_DESCRIPTION("The amateur radio ROSE network layer protocol");
1546 int init_module(void)
1548 rose_proto_init(NULL);
1550 return 0;
1553 void cleanup_module(void)
1555 int i;
1557 #ifdef CONFIG_PROC_FS
1558 proc_net_unregister(PROC_NET_RS);
1559 proc_net_unregister(PROC_NET_RS_NEIGH);
1560 proc_net_unregister(PROC_NET_RS_NODES);
1561 proc_net_unregister(PROC_NET_RS_ROUTES);
1562 #endif
1563 rose_loopback_clear();
1565 rose_rt_free();
1567 ax25_protocol_release(AX25_P_ROSE);
1568 ax25_linkfail_release(rose_link_failed);
1570 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1571 ax25_listen_release(&rose_callsign, NULL);
1573 #ifdef CONFIG_SYSCTL
1574 rose_unregister_sysctl();
1575 #endif
1576 unregister_netdevice_notifier(&rose_dev_notifier);
1578 sock_unregister(PF_ROSE);
1580 for (i = 0; i < rose_ndevs; i++) {
1581 if (dev_rose[i].priv != NULL) {
1582 kfree(dev_rose[i].priv);
1583 dev_rose[i].priv = NULL;
1584 unregister_netdev(&dev_rose[i]);
1586 kfree(dev_rose[i].name);
1589 kfree(dev_rose);
1592 #endif
1594 #endif