Linux 2.3.0
[davej-history.git] / net / rose / af_rose.c
blob1c27a4724106f2909b8fb8b1a8964f3f81490418
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/if_arp.h>
58 #include <linux/init.h>
60 int rose_ndevs = 10;
62 int sysctl_rose_restart_request_timeout = ROSE_DEFAULT_T0;
63 int sysctl_rose_call_request_timeout = ROSE_DEFAULT_T1;
64 int sysctl_rose_reset_request_timeout = ROSE_DEFAULT_T2;
65 int sysctl_rose_clear_request_timeout = ROSE_DEFAULT_T3;
66 int sysctl_rose_no_activity_timeout = ROSE_DEFAULT_IDLE;
67 int sysctl_rose_ack_hold_back_timeout = ROSE_DEFAULT_HB;
68 int sysctl_rose_routing_control = ROSE_DEFAULT_ROUTING;
69 int sysctl_rose_link_fail_timeout = ROSE_DEFAULT_FAIL_TIMEOUT;
70 int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC;
71 int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
73 static struct sock *volatile rose_list = NULL;
75 static struct proto_ops rose_proto_ops;
77 ax25_address rose_callsign;
80 * Convert a ROSE address into text.
82 char *rose2asc(rose_address *addr)
84 static char buffer[11];
86 if (addr->rose_addr[0] == 0x00 && addr->rose_addr[1] == 0x00 &&
87 addr->rose_addr[2] == 0x00 && addr->rose_addr[3] == 0x00 &&
88 addr->rose_addr[4] == 0x00) {
89 strcpy(buffer, "*");
90 } else {
91 sprintf(buffer, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
92 addr->rose_addr[1] & 0xFF,
93 addr->rose_addr[2] & 0xFF,
94 addr->rose_addr[3] & 0xFF,
95 addr->rose_addr[4] & 0xFF);
98 return buffer;
102 * Compare two ROSE addresses, 0 == equal.
104 int rosecmp(rose_address *addr1, rose_address *addr2)
106 int i;
108 for (i = 0; i < 5; i++)
109 if (addr1->rose_addr[i] != addr2->rose_addr[i])
110 return 1;
112 return 0;
116 * Compare two ROSE addresses for only mask digits, 0 == equal.
118 int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
120 int i, j;
122 if (mask > 10)
123 return 1;
125 for (i = 0; i < mask; i++) {
126 j = i / 2;
128 if ((i % 2) != 0) {
129 if ((addr1->rose_addr[j] & 0x0F) != (addr2->rose_addr[j] & 0x0F))
130 return 1;
131 } else {
132 if ((addr1->rose_addr[j] & 0xF0) != (addr2->rose_addr[j] & 0xF0))
133 return 1;
137 return 0;
140 static void rose_free_sock(struct sock *sk)
142 sk_free(sk);
144 MOD_DEC_USE_COUNT;
147 static struct sock *rose_alloc_sock(void)
149 struct sock *sk;
150 rose_cb *rose;
152 if ((sk = sk_alloc(PF_ROSE, GFP_ATOMIC, 1)) == NULL)
153 return NULL;
155 if ((rose = kmalloc(sizeof(*rose), GFP_ATOMIC)) == NULL) {
156 sk_free(sk);
157 return NULL;
160 MOD_INC_USE_COUNT;
162 memset(rose, 0x00, sizeof(*rose));
164 sk->protinfo.rose = rose;
165 rose->sk = sk;
167 return sk;
171 * Socket removal during an interrupt is now safe.
173 static void rose_remove_socket(struct sock *sk)
175 struct sock *s;
176 unsigned long flags;
178 save_flags(flags); cli();
180 if ((s = rose_list) == sk) {
181 rose_list = s->next;
182 restore_flags(flags);
183 return;
186 while (s != NULL && s->next != NULL) {
187 if (s->next == sk) {
188 s->next = sk->next;
189 restore_flags(flags);
190 return;
193 s = s->next;
196 restore_flags(flags);
200 * Kill all bound sockets on a broken link layer connection to a
201 * particular neighbour.
203 void rose_kill_by_neigh(struct rose_neigh *neigh)
205 struct sock *s;
207 for (s = rose_list; s != NULL; s = s->next) {
208 if (s->protinfo.rose->neighbour == neigh) {
209 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
210 s->protinfo.rose->neighbour->use--;
211 s->protinfo.rose->neighbour = NULL;
217 * Kill all bound sockets on a dropped device.
219 static void rose_kill_by_device(struct device *dev)
221 struct sock *s;
223 for (s = rose_list; s != NULL; s = s->next) {
224 if (s->protinfo.rose->device == dev) {
225 rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
226 s->protinfo.rose->neighbour->use--;
227 s->protinfo.rose->device = NULL;
233 * Handle device status changes.
235 static int rose_device_event(struct notifier_block *this, unsigned long event, void *ptr)
237 struct device *dev = (struct device *)ptr;
239 if (event != NETDEV_DOWN)
240 return NOTIFY_DONE;
242 switch (dev->type) {
243 case ARPHRD_ROSE:
244 rose_kill_by_device(dev);
245 break;
246 case ARPHRD_AX25:
247 rose_link_device_down(dev);
248 rose_rt_device_down(dev);
249 break;
252 return NOTIFY_DONE;
256 * Add a socket to the bound sockets list.
258 static void rose_insert_socket(struct sock *sk)
260 unsigned long flags;
262 save_flags(flags); cli();
264 sk->next = rose_list;
265 rose_list = sk;
267 restore_flags(flags);
271 * Find a socket that wants to accept the Call Request we just
272 * received.
274 static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
276 unsigned long flags;
277 struct sock *s;
279 save_flags(flags); cli();
281 for (s = rose_list; s != NULL; s = s->next) {
282 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) {
283 restore_flags(flags);
284 return s;
288 for (s = rose_list; s != NULL; s = s->next) {
289 if (rosecmp(&s->protinfo.rose->source_addr, addr) == 0 && ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0 && s->state == TCP_LISTEN) {
290 restore_flags(flags);
291 return s;
295 restore_flags(flags);
296 return NULL;
300 * Find a connected ROSE socket given my LCI and device.
302 struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
304 struct sock *s;
305 unsigned long flags;
307 save_flags(flags); cli();
309 for (s = rose_list; s != NULL; s = s->next) {
310 if (s->protinfo.rose->lci == lci && s->protinfo.rose->neighbour == neigh) {
311 restore_flags(flags);
312 return s;
316 restore_flags(flags);
318 return NULL;
322 * Find a unique LCI for a given device.
324 unsigned int rose_new_lci(struct rose_neigh *neigh)
326 int lci;
328 if (neigh->dce_mode) {
329 for (lci = 1; lci <= sysctl_rose_maximum_vcs; lci++)
330 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
331 return lci;
332 } else {
333 for (lci = sysctl_rose_maximum_vcs; lci > 0; lci--)
334 if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
335 return lci;
338 return 0;
342 * Deferred destroy.
344 void rose_destroy_socket(struct sock *);
347 * Handler for deferred kills.
349 static void rose_destroy_timer(unsigned long data)
351 rose_destroy_socket((struct sock *)data);
355 * This is called from user mode and the timers. Thus it protects itself against
356 * interrupt users but doesn't worry about being called during work.
357 * Once it is removed from the queue no interrupt or bottom half will
358 * touch it and we are (fairly 8-) ) safe.
360 void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the timer */
362 struct sk_buff *skb;
363 unsigned long flags;
365 save_flags(flags); cli();
367 rose_stop_heartbeat(sk);
368 rose_stop_idletimer(sk);
369 rose_stop_timer(sk);
371 rose_remove_socket(sk);
372 rose_clear_queues(sk); /* Flush the queues */
374 while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
375 if (skb->sk != sk) { /* A pending connection */
376 skb->sk->dead = 1; /* Queue the unaccepted socket for death */
377 rose_start_heartbeat(skb->sk);
378 skb->sk->protinfo.rose->state = ROSE_STATE_0;
381 kfree_skb(skb);
384 if (atomic_read(&sk->wmem_alloc) != 0 || atomic_read(&sk->rmem_alloc) != 0) {
385 /* Defer: outstanding buffers */
386 init_timer(&sk->timer);
387 sk->timer.expires = jiffies + 10 * HZ;
388 sk->timer.function = rose_destroy_timer;
389 sk->timer.data = (unsigned long)sk;
390 add_timer(&sk->timer);
391 } else {
392 rose_free_sock(sk);
395 restore_flags(flags);
399 * Handling for system calls applied via the various interfaces to a
400 * ROSE socket object.
403 static int rose_setsockopt(struct socket *sock, int level, int optname,
404 char *optval, int optlen)
406 struct sock *sk = sock->sk;
407 int opt;
409 if (level != SOL_ROSE)
410 return -ENOPROTOOPT;
412 if (optlen < sizeof(int))
413 return -EINVAL;
415 if (get_user(opt, (int *)optval))
416 return -EFAULT;
418 switch (optname) {
419 case ROSE_DEFER:
420 sk->protinfo.rose->defer = opt ? 1 : 0;
421 return 0;
423 case ROSE_T1:
424 if (opt < 1)
425 return -EINVAL;
426 sk->protinfo.rose->t1 = opt * HZ;
427 return 0;
429 case ROSE_T2:
430 if (opt < 1)
431 return -EINVAL;
432 sk->protinfo.rose->t2 = opt * HZ;
433 return 0;
435 case ROSE_T3:
436 if (opt < 1)
437 return -EINVAL;
438 sk->protinfo.rose->t3 = opt * HZ;
439 return 0;
441 case ROSE_HOLDBACK:
442 if (opt < 1)
443 return -EINVAL;
444 sk->protinfo.rose->hb = opt * HZ;
445 return 0;
447 case ROSE_IDLE:
448 if (opt < 0)
449 return -EINVAL;
450 sk->protinfo.rose->idle = opt * 60 * HZ;
451 return 0;
453 case ROSE_QBITINCL:
454 sk->protinfo.rose->qbitincl = opt ? 1 : 0;
455 return 0;
457 default:
458 return -ENOPROTOOPT;
462 static int rose_getsockopt(struct socket *sock, int level, int optname,
463 char *optval, int *optlen)
465 struct sock *sk = sock->sk;
466 int val = 0;
467 int len;
469 if (level != SOL_ROSE)
470 return -ENOPROTOOPT;
472 if (get_user(len, optlen))
473 return -EFAULT;
475 switch (optname) {
476 case ROSE_DEFER:
477 val = sk->protinfo.rose->defer;
478 break;
480 case ROSE_T1:
481 val = sk->protinfo.rose->t1 / HZ;
482 break;
484 case ROSE_T2:
485 val = sk->protinfo.rose->t2 / HZ;
486 break;
488 case ROSE_T3:
489 val = sk->protinfo.rose->t3 / HZ;
490 break;
492 case ROSE_HOLDBACK:
493 val = sk->protinfo.rose->hb / HZ;
494 break;
496 case ROSE_IDLE:
497 val = sk->protinfo.rose->idle / (60 * HZ);
498 break;
500 case ROSE_QBITINCL:
501 val = sk->protinfo.rose->qbitincl;
502 break;
504 default:
505 return -ENOPROTOOPT;
508 len = min(len, sizeof(int));
510 if (put_user(len, optlen))
511 return -EFAULT;
513 if (copy_to_user(optval, &val, len))
514 return -EFAULT;
516 return 0;
519 static int rose_listen(struct socket *sock, int backlog)
521 struct sock *sk = sock->sk;
523 if (sk->state != TCP_LISTEN) {
524 sk->protinfo.rose->dest_ndigis = 0;
525 memset(&sk->protinfo.rose->dest_addr, '\0', ROSE_ADDR_LEN);
526 memset(&sk->protinfo.rose->dest_call, '\0', AX25_ADDR_LEN);
527 memset(sk->protinfo.rose->dest_digis, '\0', AX25_ADDR_LEN*ROSE_MAX_DIGIS);
528 sk->max_ack_backlog = backlog;
529 sk->state = TCP_LISTEN;
530 return 0;
533 return -EOPNOTSUPP;
536 static int rose_create(struct socket *sock, int protocol)
538 struct sock *sk;
539 rose_cb *rose;
541 if (sock->type != SOCK_SEQPACKET || protocol != 0)
542 return -ESOCKTNOSUPPORT;
544 if ((sk = rose_alloc_sock()) == NULL)
545 return -ENOMEM;
547 rose = sk->protinfo.rose;
549 sock_init_data(sock, sk);
551 skb_queue_head_init(&rose->ack_queue);
552 #ifdef M_BIT
553 skb_queue_head_init(&rose->frag_queue);
554 rose->fraglen = 0;
555 #endif
557 sock->ops = &rose_proto_ops;
558 sk->protocol = protocol;
560 init_timer(&rose->timer);
561 init_timer(&rose->idletimer);
563 rose->t1 = sysctl_rose_call_request_timeout;
564 rose->t2 = sysctl_rose_reset_request_timeout;
565 rose->t3 = sysctl_rose_clear_request_timeout;
566 rose->hb = sysctl_rose_ack_hold_back_timeout;
567 rose->idle = sysctl_rose_no_activity_timeout;
569 rose->state = ROSE_STATE_0;
571 return 0;
574 static struct sock *rose_make_new(struct sock *osk)
576 struct sock *sk;
577 rose_cb *rose;
579 if (osk->type != SOCK_SEQPACKET)
580 return NULL;
582 if ((sk = rose_alloc_sock()) == NULL)
583 return NULL;
585 rose = sk->protinfo.rose;
587 sock_init_data(NULL, sk);
589 skb_queue_head_init(&rose->ack_queue);
590 #ifdef M_BIT
591 skb_queue_head_init(&rose->frag_queue);
592 rose->fraglen = 0;
593 #endif
595 sk->type = osk->type;
596 sk->socket = osk->socket;
597 sk->priority = osk->priority;
598 sk->protocol = osk->protocol;
599 sk->rcvbuf = osk->rcvbuf;
600 sk->sndbuf = osk->sndbuf;
601 sk->debug = osk->debug;
602 sk->state = TCP_ESTABLISHED;
603 sk->sleep = osk->sleep;
604 sk->zapped = osk->zapped;
606 init_timer(&rose->timer);
607 init_timer(&rose->idletimer);
609 rose->t1 = osk->protinfo.rose->t1;
610 rose->t2 = osk->protinfo.rose->t2;
611 rose->t3 = osk->protinfo.rose->t3;
612 rose->hb = osk->protinfo.rose->hb;
613 rose->idle = osk->protinfo.rose->idle;
615 rose->defer = osk->protinfo.rose->defer;
616 rose->device = osk->protinfo.rose->device;
617 rose->qbitincl = osk->protinfo.rose->qbitincl;
619 return sk;
622 static int rose_release(struct socket *sock, struct socket *peer)
624 struct sock *sk = sock->sk;
626 if (sk == NULL) return 0;
628 switch (sk->protinfo.rose->state) {
630 case ROSE_STATE_0:
631 rose_disconnect(sk, 0, -1, -1);
632 rose_destroy_socket(sk);
633 break;
635 case ROSE_STATE_2:
636 sk->protinfo.rose->neighbour->use--;
637 rose_disconnect(sk, 0, -1, -1);
638 rose_destroy_socket(sk);
639 break;
641 case ROSE_STATE_1:
642 case ROSE_STATE_3:
643 case ROSE_STATE_4:
644 case ROSE_STATE_5:
645 rose_clear_queues(sk);
646 rose_stop_idletimer(sk);
647 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
648 rose_start_t3timer(sk);
649 sk->protinfo.rose->state = ROSE_STATE_2;
650 sk->state = TCP_CLOSE;
651 sk->shutdown |= SEND_SHUTDOWN;
652 sk->state_change(sk);
653 sk->dead = 1;
654 sk->destroy = 1;
655 break;
657 default:
658 break;
661 sock->sk = NULL;
662 sk->socket = NULL; /* Not used, but we should do this. **/
664 return 0;
667 static int rose_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
669 struct sock *sk = sock->sk;
670 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
671 struct device *dev;
672 ax25_address *user, *source;
673 int n;
675 if (sk->zapped == 0)
676 return -EINVAL;
678 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
679 return -EINVAL;
681 if (addr->srose_family != AF_ROSE)
682 return -EINVAL;
684 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
685 return -EINVAL;
687 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
688 return -EINVAL;
690 if ((dev = rose_dev_get(&addr->srose_addr)) == NULL) {
691 SOCK_DEBUG(sk, "ROSE: bind failed: invalid address\n");
692 return -EADDRNOTAVAIL;
695 source = &addr->srose_call;
697 if ((user = ax25_findbyuid(current->euid)) == NULL) {
698 if (ax25_uid_policy && !suser())
699 return -EACCES;
700 user = source;
703 sk->protinfo.rose->source_addr = addr->srose_addr;
704 sk->protinfo.rose->source_call = *user;
705 sk->protinfo.rose->device = dev;
706 sk->protinfo.rose->source_ndigis = addr->srose_ndigis;
708 if (addr_len == sizeof(struct full_sockaddr_rose)) {
709 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
710 for (n = 0 ; n < addr->srose_ndigis ; n++)
711 sk->protinfo.rose->source_digis[n] = full_addr->srose_digis[n];
712 } else {
713 if (sk->protinfo.rose->source_ndigis == 1) {
714 sk->protinfo.rose->source_digis[0] = addr->srose_digi;
718 rose_insert_socket(sk);
720 sk->zapped = 0;
721 SOCK_DEBUG(sk, "ROSE: socket is bound\n");
722 return 0;
725 static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
727 struct sock *sk = sock->sk;
728 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
729 unsigned char cause, diagnostic;
730 ax25_address *user;
731 struct device *dev;
732 int n;
734 if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
735 sock->state = SS_CONNECTED;
736 return 0; /* Connect completed during a ERESTARTSYS event */
739 if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
740 sock->state = SS_UNCONNECTED;
741 return -ECONNREFUSED;
744 if (sk->state == TCP_ESTABLISHED)
745 return -EISCONN; /* No reconnect on a seqpacket socket */
747 sk->state = TCP_CLOSE;
748 sock->state = SS_UNCONNECTED;
750 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
751 return -EINVAL;
753 if (addr->srose_family != AF_ROSE)
754 return -EINVAL;
756 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
757 return -EINVAL;
759 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
760 return -EINVAL;
762 /* Source + Destination digis should not exceed ROSE_MAX_DIGIS */
763 if ((sk->protinfo.rose->source_ndigis + addr->srose_ndigis) > ROSE_MAX_DIGIS)
764 return -EINVAL;
766 if ((sk->protinfo.rose->neighbour = rose_get_neigh(&addr->srose_addr, &cause, &diagnostic)) == NULL)
767 return -ENETUNREACH;
769 if ((sk->protinfo.rose->lci = rose_new_lci(sk->protinfo.rose->neighbour)) == 0)
770 return -ENETUNREACH;
772 if (sk->zapped) { /* Must bind first - autobinding in this may or may not work */
773 sk->zapped = 0;
775 if ((dev = rose_dev_first()) == NULL)
776 return -ENETUNREACH;
778 if ((user = ax25_findbyuid(current->euid)) == NULL)
779 return -EINVAL;
781 memcpy(&sk->protinfo.rose->source_addr, dev->dev_addr, ROSE_ADDR_LEN);
782 sk->protinfo.rose->source_call = *user;
783 sk->protinfo.rose->device = dev;
785 rose_insert_socket(sk); /* Finish the bind */
788 sk->protinfo.rose->dest_addr = addr->srose_addr;
789 sk->protinfo.rose->dest_call = addr->srose_call;
790 sk->protinfo.rose->rand = ((int)sk->protinfo.rose & 0xFFFF) + sk->protinfo.rose->lci;
791 sk->protinfo.rose->dest_ndigis = addr->srose_ndigis;
793 if (addr_len == sizeof(struct full_sockaddr_rose)) {
794 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
795 for (n = 0 ; n < addr->srose_ndigis ; n++)
796 sk->protinfo.rose->dest_digis[n] = full_addr->srose_digis[n];
797 } else {
798 if (sk->protinfo.rose->dest_ndigis == 1) {
799 sk->protinfo.rose->dest_digis[0] = addr->srose_digi;
803 /* Move to connecting socket, start sending Connect Requests */
804 sock->state = SS_CONNECTING;
805 sk->state = TCP_SYN_SENT;
807 sk->protinfo.rose->state = ROSE_STATE_1;
809 sk->protinfo.rose->neighbour->use++;
811 rose_write_internal(sk, ROSE_CALL_REQUEST);
812 rose_start_heartbeat(sk);
813 rose_start_t1timer(sk);
815 /* Now the loop */
816 if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
817 return -EINPROGRESS;
819 cli(); /* To avoid races on the sleep */
822 * A Connect Ack with Choke or timeout or failed routing will go to closed.
824 while (sk->state == TCP_SYN_SENT) {
825 interruptible_sleep_on(sk->sleep);
826 if (signal_pending(current)) {
827 sti();
828 return -ERESTARTSYS;
832 if (sk->state != TCP_ESTABLISHED) {
833 sti();
834 sock->state = SS_UNCONNECTED;
835 return sock_error(sk); /* Always set at this point */
838 sock->state = SS_CONNECTED;
840 sti();
842 return 0;
845 static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
847 struct sock *sk;
848 struct sock *newsk;
849 struct sk_buff *skb;
851 if (newsock->sk != NULL)
852 rose_destroy_socket(newsock->sk);
854 newsock->sk = NULL;
856 if ((sk = sock->sk) == NULL)
857 return -EINVAL;
859 if (sk->type != SOCK_SEQPACKET)
860 return -EOPNOTSUPP;
862 if (sk->state != TCP_LISTEN)
863 return -EINVAL;
866 * The write queue this time is holding sockets ready to use
867 * hooked into the SABM we saved
869 do {
870 cli();
871 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
872 if (flags & O_NONBLOCK) {
873 sti();
874 return -EWOULDBLOCK;
876 interruptible_sleep_on(sk->sleep);
877 if (signal_pending(current)) {
878 sti();
879 return -ERESTARTSYS;
882 } while (skb == NULL);
884 newsk = skb->sk;
885 newsk->pair = NULL;
886 newsk->socket = newsock;
887 newsk->sleep = &newsock->wait;
888 sti();
890 /* Now attach up the new socket */
891 skb->sk = NULL;
892 kfree_skb(skb);
893 sk->ack_backlog--;
894 newsock->sk = newsk;
896 return 0;
899 static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
900 int *uaddr_len, int peer)
902 struct sockaddr_rose *srose = (struct sockaddr_rose *)uaddr;
903 struct sock *sk = sock->sk;
904 int n;
906 if (peer != 0) {
907 if (sk->state != TCP_ESTABLISHED)
908 return -ENOTCONN;
909 srose->srose_family = AF_ROSE;
910 srose->srose_ndigis = 0;
911 srose->srose_addr = sk->protinfo.rose->dest_addr;
912 srose->srose_call = sk->protinfo.rose->dest_call;
913 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
914 if (*uaddr_len >= sizeof(struct full_sockaddr_rose)) {
915 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)uaddr;
916 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
917 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
918 *uaddr_len = sizeof(struct full_sockaddr_rose);
919 } else {
920 if (sk->protinfo.rose->dest_ndigis >= 1) {
921 srose->srose_ndigis = 1;
922 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
924 *uaddr_len = sizeof(struct sockaddr_rose);
926 } else {
927 srose->srose_family = AF_ROSE;
928 srose->srose_ndigis = 0;
929 srose->srose_addr = sk->protinfo.rose->source_addr;
930 srose->srose_call = sk->protinfo.rose->source_call;
931 srose->srose_ndigis = sk->protinfo.rose->source_ndigis;
932 if (*uaddr_len >= sizeof(struct full_sockaddr_rose)) {
933 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)uaddr;
934 for (n = 0 ; n < sk->protinfo.rose->source_ndigis ; n++)
935 full_srose->srose_digis[n] = sk->protinfo.rose->source_digis[n];
936 *uaddr_len = sizeof(struct full_sockaddr_rose);
937 } else {
938 if (sk->protinfo.rose->source_ndigis >= 1) {
939 srose->srose_ndigis = 1;
940 srose->srose_digi = sk->protinfo.rose->source_digis[sk->protinfo.rose->source_ndigis-1];
942 *uaddr_len = sizeof(struct sockaddr_rose);
946 return 0;
949 int rose_rx_call_request(struct sk_buff *skb, struct device *dev, struct rose_neigh *neigh, unsigned int lci)
951 struct sock *sk;
952 struct sock *make;
953 struct rose_facilities_struct facilities;
954 int n, len;
956 skb->sk = NULL; /* Initially we don't know who it's for */
959 * skb->data points to the rose frame start
961 memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
963 len = (((skb->data[3] >> 4) & 0x0F) + 1) / 2;
964 len += (((skb->data[3] >> 0) & 0x0F) + 1) / 2;
965 if (!rose_parse_facilities(skb->data + len + 4, &facilities)) {
966 rose_transmit_clear_request(neigh, lci, ROSE_INVALID_FACILITY, 76);
967 return 0;
970 sk = rose_find_listener(&facilities.source_addr, &facilities.source_call);
973 * We can't accept the Call Request.
975 if (sk == NULL || sk->ack_backlog == sk->max_ack_backlog || (make = rose_make_new(sk)) == NULL) {
976 rose_transmit_clear_request(neigh, lci, ROSE_NETWORK_CONGESTION, 120);
977 return 0;
980 skb->sk = make;
981 make->state = TCP_ESTABLISHED;
983 make->protinfo.rose->lci = lci;
984 make->protinfo.rose->dest_addr = facilities.dest_addr;
985 make->protinfo.rose->dest_call = facilities.dest_call;
986 make->protinfo.rose->dest_ndigis = facilities.dest_ndigis;
987 for (n = 0 ; n < facilities.dest_ndigis ; n++)
988 make->protinfo.rose->dest_digis[n] = facilities.dest_digis[n];
989 make->protinfo.rose->source_addr = facilities.source_addr;
990 make->protinfo.rose->source_call = facilities.source_call;
991 make->protinfo.rose->source_ndigis = facilities.source_ndigis;
992 for (n = 0 ; n < facilities.source_ndigis ; n++)
993 make->protinfo.rose->source_digis[n]= facilities.source_digis[n];
994 make->protinfo.rose->neighbour = neigh;
995 make->protinfo.rose->device = dev;
996 make->protinfo.rose->facilities = facilities;
998 make->protinfo.rose->neighbour->use++;
1000 if (sk->protinfo.rose->defer) {
1001 make->protinfo.rose->state = ROSE_STATE_5;
1002 } else {
1003 rose_write_internal(make, ROSE_CALL_ACCEPTED);
1004 make->protinfo.rose->state = ROSE_STATE_3;
1005 rose_start_idletimer(make);
1008 make->protinfo.rose->condition = 0x00;
1009 make->protinfo.rose->vs = 0;
1010 make->protinfo.rose->va = 0;
1011 make->protinfo.rose->vr = 0;
1012 make->protinfo.rose->vl = 0;
1013 sk->ack_backlog++;
1014 make->pair = sk;
1016 rose_insert_socket(make);
1018 skb_queue_head(&sk->receive_queue, skb);
1020 rose_start_heartbeat(make);
1022 if (!sk->dead)
1023 sk->data_ready(sk, skb->len);
1025 return 1;
1028 static int rose_sendmsg(struct socket *sock, struct msghdr *msg, int len,
1029 struct scm_cookie *scm)
1031 struct sock *sk = sock->sk;
1032 struct sockaddr_rose *usrose = (struct sockaddr_rose *)msg->msg_name;
1033 int err;
1034 struct full_sockaddr_rose srose;
1035 struct sk_buff *skb;
1036 unsigned char *asmptr;
1037 int n, size, qbit = 0;
1039 if (msg->msg_flags & ~MSG_DONTWAIT)
1040 return -EINVAL;
1042 if (sk->zapped)
1043 return -EADDRNOTAVAIL;
1045 if (sk->shutdown & SEND_SHUTDOWN) {
1046 send_sig(SIGPIPE, current, 0);
1047 return -EPIPE;
1050 if (sk->protinfo.rose->neighbour == NULL || sk->protinfo.rose->device == NULL)
1051 return -ENETUNREACH;
1053 if (usrose != NULL) {
1054 if (msg->msg_namelen != sizeof(struct sockaddr_rose) && msg->msg_namelen != sizeof(struct full_sockaddr_rose))
1055 return -EINVAL;
1056 memset(&srose, 0, sizeof(struct full_sockaddr_rose));
1057 memcpy(&srose, usrose, msg->msg_namelen);
1058 if (rosecmp(&sk->protinfo.rose->dest_addr, &srose.srose_addr) != 0 ||
1059 ax25cmp(&sk->protinfo.rose->dest_call, &srose.srose_call) != 0)
1060 return -EISCONN;
1061 if (srose.srose_ndigis != sk->protinfo.rose->dest_ndigis)
1062 return -EISCONN;
1063 if (srose.srose_ndigis == sk->protinfo.rose->dest_ndigis) {
1064 for (n = 0 ; n < srose.srose_ndigis ; n++)
1065 if (ax25cmp(&sk->protinfo.rose->dest_digis[n], &srose.srose_digis[n]) != 0)
1066 return -EISCONN;
1068 if (srose.srose_family != AF_ROSE)
1069 return -EINVAL;
1070 } else {
1071 if (sk->state != TCP_ESTABLISHED)
1072 return -ENOTCONN;
1074 srose.srose_family = AF_ROSE;
1075 srose.srose_addr = sk->protinfo.rose->dest_addr;
1076 srose.srose_call = sk->protinfo.rose->dest_call;
1077 srose.srose_ndigis = sk->protinfo.rose->dest_ndigis;
1078 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1079 srose.srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1082 SOCK_DEBUG(sk, "ROSE: sendto: Addresses built.\n");
1084 /* Build a packet */
1085 SOCK_DEBUG(sk, "ROSE: sendto: building packet.\n");
1086 size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
1088 if ((skb = sock_alloc_send_skb(sk, size, 0, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
1089 return err;
1091 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN);
1094 * Put the data on the end
1096 SOCK_DEBUG(sk, "ROSE: Appending user data\n");
1098 asmptr = skb->h.raw = skb_put(skb, len);
1100 memcpy_fromiovec(asmptr, msg->msg_iov, len);
1103 * If the Q BIT Include socket option is in force, the first
1104 * byte of the user data is the logical value of the Q Bit.
1106 if (sk->protinfo.rose->qbitincl) {
1107 qbit = skb->data[0];
1108 skb_pull(skb, 1);
1112 * Push down the ROSE header
1114 asmptr = skb_push(skb, ROSE_MIN_LEN);
1116 SOCK_DEBUG(sk, "ROSE: Building Network Header.\n");
1118 /* Build a ROSE Network header */
1119 asmptr[0] = ((sk->protinfo.rose->lci >> 8) & 0x0F) | ROSE_GFI;
1120 asmptr[1] = (sk->protinfo.rose->lci >> 0) & 0xFF;
1121 asmptr[2] = ROSE_DATA;
1123 if (qbit)
1124 asmptr[0] |= ROSE_Q_BIT;
1126 SOCK_DEBUG(sk, "ROSE: Built header.\n");
1128 SOCK_DEBUG(sk, "ROSE: Transmitting buffer\n");
1130 if (sk->state != TCP_ESTABLISHED) {
1131 kfree_skb(skb);
1132 return -ENOTCONN;
1135 #ifdef M_BIT
1136 #define ROSE_PACLEN (256-ROSE_MIN_LEN)
1137 if (skb->len - ROSE_MIN_LEN > ROSE_PACLEN) {
1138 unsigned char header[ROSE_MIN_LEN];
1139 struct sk_buff *skbn;
1140 int frontlen;
1141 int lg;
1143 /* Save a copy of the Header */
1144 memcpy(header, skb->data, ROSE_MIN_LEN);
1145 skb_pull(skb, ROSE_MIN_LEN);
1147 frontlen = skb_headroom(skb);
1149 while (skb->len > 0) {
1150 if ((skbn = sock_alloc_send_skb(sk, frontlen + ROSE_PACLEN, 0, 0, &err)) == NULL)
1151 return err;
1153 skbn->sk = sk;
1154 skbn->free = 1;
1155 skbn->arp = 1;
1157 skb_reserve(skbn, frontlen);
1159 lg = (ROSE_PACLEN > skb->len) ? skb->len : ROSE_PACLEN;
1161 /* Copy the user data */
1162 memcpy(skb_put(skbn, lg), skb->data, lg);
1163 skb_pull(skb, lg);
1165 /* Duplicate the Header */
1166 skb_push(skbn, ROSE_MIN_LEN);
1167 memcpy(skbn->data, header, ROSE_MIN_LEN);
1169 if (skb->len > 0)
1170 skbn->data[2] |= M_BIT;
1172 skb_queue_tail(&sk->write_queue, skbn); /* Throw it on the queue */
1175 skb->free = 1;
1176 kfree_skb(skb, FREE_WRITE);
1177 } else {
1178 skb_queue_tail(&sk->write_queue, skb); /* Throw it on the queue */
1180 #else
1181 skb_queue_tail(&sk->write_queue, skb); /* Shove it onto the queue */
1182 #endif
1184 rose_kick(sk);
1186 return len;
1190 static int rose_recvmsg(struct socket *sock, struct msghdr *msg, int size,
1191 int flags, struct scm_cookie *scm)
1193 struct sock *sk = sock->sk;
1194 struct sockaddr_rose *srose = (struct sockaddr_rose *)msg->msg_name;
1195 int copied, qbit;
1196 unsigned char *asmptr;
1197 struct sk_buff *skb;
1198 int n, er;
1201 * This works for seqpacket too. The receiver has ordered the queue for
1202 * us! We do one quick check first though
1204 if (sk->state != TCP_ESTABLISHED)
1205 return -ENOTCONN;
1207 /* Now we can treat all alike */
1208 if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL)
1209 return er;
1211 qbit = (skb->data[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
1213 skb_pull(skb, ROSE_MIN_LEN);
1215 if (sk->protinfo.rose->qbitincl) {
1216 asmptr = skb_push(skb, 1);
1217 *asmptr = qbit;
1220 skb->h.raw = skb->data;
1221 copied = skb->len;
1223 if (copied > size) {
1224 copied = size;
1225 msg->msg_flags |= MSG_TRUNC;
1228 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1230 if (srose != NULL) {
1231 srose->srose_family = AF_ROSE;
1232 srose->srose_addr = sk->protinfo.rose->dest_addr;
1233 srose->srose_call = sk->protinfo.rose->dest_call;
1234 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
1235 if (msg->msg_namelen >= sizeof(struct full_sockaddr_rose)) {
1236 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)msg->msg_name;
1237 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1238 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1239 msg->msg_namelen = sizeof(struct full_sockaddr_rose);
1240 } else {
1241 if (sk->protinfo.rose->dest_ndigis >= 1) {
1242 srose->srose_ndigis = 1;
1243 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
1245 msg->msg_namelen = sizeof(struct sockaddr_rose);
1249 skb_free_datagram(sk, skb);
1251 return copied;
1254 static int rose_shutdown(struct socket *sk, int how)
1256 return -EOPNOTSUPP;
1259 static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1261 struct sock *sk = sock->sk;
1263 switch (cmd) {
1264 case TIOCOUTQ: {
1265 long amount;
1266 amount = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1267 if (amount < 0)
1268 amount = 0;
1269 if (put_user(amount, (unsigned int *)arg))
1270 return -EFAULT;
1271 return 0;
1274 case TIOCINQ: {
1275 struct sk_buff *skb;
1276 long amount = 0L;
1277 /* These two are safe on a single CPU system as only user tasks fiddle here */
1278 if ((skb = skb_peek(&sk->receive_queue)) != NULL)
1279 amount = skb->len;
1280 if (put_user(amount, (unsigned int *)arg))
1281 return -EFAULT;
1282 return 0;
1285 case SIOCGSTAMP:
1286 if (sk != NULL) {
1287 if (sk->stamp.tv_sec == 0)
1288 return -ENOENT;
1289 if (copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)))
1290 return -EFAULT;
1291 return 0;
1293 return -EINVAL;
1295 case SIOCGIFADDR:
1296 case SIOCSIFADDR:
1297 case SIOCGIFDSTADDR:
1298 case SIOCSIFDSTADDR:
1299 case SIOCGIFBRDADDR:
1300 case SIOCSIFBRDADDR:
1301 case SIOCGIFNETMASK:
1302 case SIOCSIFNETMASK:
1303 case SIOCGIFMETRIC:
1304 case SIOCSIFMETRIC:
1305 return -EINVAL;
1307 case SIOCADDRT:
1308 case SIOCDELRT:
1309 case SIOCRSCLRRT:
1310 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1311 return rose_rt_ioctl(cmd, (void *)arg);
1313 case SIOCRSGCAUSE: {
1314 struct rose_cause_struct rose_cause;
1315 rose_cause.cause = sk->protinfo.rose->cause;
1316 rose_cause.diagnostic = sk->protinfo.rose->diagnostic;
1317 if (copy_to_user((void *)arg, &rose_cause, sizeof(struct rose_cause_struct)))
1318 return -EFAULT;
1319 return 0;
1322 case SIOCRSSCAUSE: {
1323 struct rose_cause_struct rose_cause;
1324 if (copy_from_user(&rose_cause, (void *)arg, sizeof(struct rose_cause_struct)))
1325 return -EFAULT;
1326 sk->protinfo.rose->cause = rose_cause.cause;
1327 sk->protinfo.rose->diagnostic = rose_cause.diagnostic;
1328 return 0;
1331 case SIOCRSSL2CALL:
1332 if (!suser()) return -EPERM;
1333 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1334 ax25_listen_release(&rose_callsign, NULL);
1335 if (copy_from_user(&rose_callsign, (void *)arg, sizeof(ax25_address)))
1336 return -EFAULT;
1337 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1338 ax25_listen_register(&rose_callsign, NULL);
1339 return 0;
1341 case SIOCRSGL2CALL:
1342 if (copy_to_user((void *)arg, &rose_callsign, sizeof(ax25_address)))
1343 return -EFAULT;
1344 return 0;
1346 case SIOCRSACCEPT:
1347 if (sk->protinfo.rose->state == ROSE_STATE_5) {
1348 rose_write_internal(sk, ROSE_CALL_ACCEPTED);
1349 rose_start_idletimer(sk);
1350 sk->protinfo.rose->condition = 0x00;
1351 sk->protinfo.rose->vs = 0;
1352 sk->protinfo.rose->va = 0;
1353 sk->protinfo.rose->vr = 0;
1354 sk->protinfo.rose->vl = 0;
1355 sk->protinfo.rose->state = ROSE_STATE_3;
1357 return 0;
1359 default:
1360 return dev_ioctl(cmd, (void *)arg);
1363 /*NOTREACHED*/
1364 return 0;
1367 static int rose_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
1369 struct sock *s;
1370 struct device *dev;
1371 const char *devname, *callsign;
1372 int len = 0;
1373 off_t pos = 0;
1374 off_t begin = 0;
1376 cli();
1378 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");
1380 for (s = rose_list; s != NULL; s = s->next) {
1381 if ((dev = s->protinfo.rose->device) == NULL)
1382 devname = "???";
1383 else
1384 devname = dev->name;
1386 len += sprintf(buffer + len, "%-10s %-9s ",
1387 rose2asc(&s->protinfo.rose->dest_addr),
1388 ax2asc(&s->protinfo.rose->dest_call));
1390 if (ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0)
1391 callsign = "??????-?";
1392 else
1393 callsign = ax2asc(&s->protinfo.rose->source_call);
1395 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",
1396 rose2asc(&s->protinfo.rose->source_addr),
1397 callsign,
1398 devname,
1399 s->protinfo.rose->lci & 0x0FFF,
1400 (s->protinfo.rose->neighbour) ? s->protinfo.rose->neighbour->number : 0,
1401 s->protinfo.rose->state,
1402 s->protinfo.rose->vs,
1403 s->protinfo.rose->vr,
1404 s->protinfo.rose->va,
1405 ax25_display_timer(&s->protinfo.rose->timer) / HZ,
1406 s->protinfo.rose->t1 / HZ,
1407 s->protinfo.rose->t2 / HZ,
1408 s->protinfo.rose->t3 / HZ,
1409 s->protinfo.rose->hb / HZ,
1410 ax25_display_timer(&s->protinfo.rose->idletimer) / (60 * HZ),
1411 s->protinfo.rose->idle / (60 * HZ),
1412 atomic_read(&s->wmem_alloc),
1413 atomic_read(&s->rmem_alloc),
1414 s->socket != NULL ? s->socket->inode->i_ino : 0L);
1416 pos = begin + len;
1418 if (pos < offset) {
1419 len = 0;
1420 begin = pos;
1423 if (pos > offset + length)
1424 break;
1427 sti();
1429 *start = buffer + (offset - begin);
1430 len -= (offset - begin);
1432 if (len > length) len = length;
1434 return(len);
1437 static struct net_proto_family rose_family_ops = {
1438 PF_ROSE,
1439 rose_create
1442 static struct proto_ops rose_proto_ops = {
1443 PF_ROSE,
1445 sock_no_dup,
1446 rose_release,
1447 rose_bind,
1448 rose_connect,
1449 sock_no_socketpair,
1450 rose_accept,
1451 rose_getname,
1452 datagram_poll,
1453 rose_ioctl,
1454 rose_listen,
1455 rose_shutdown,
1456 rose_setsockopt,
1457 rose_getsockopt,
1458 sock_no_fcntl,
1459 rose_sendmsg,
1460 rose_recvmsg
1463 static struct notifier_block rose_dev_notifier = {
1464 rose_device_event,
1468 #ifdef CONFIG_PROC_FS
1469 static struct proc_dir_entry proc_net_rose = {
1470 PROC_NET_RS, 4, "rose",
1471 S_IFREG | S_IRUGO, 1, 0, 0,
1472 0, &proc_net_inode_operations,
1473 rose_get_info
1475 static struct proc_dir_entry proc_net_rose_neigh = {
1476 PROC_NET_RS_NEIGH, 10, "rose_neigh",
1477 S_IFREG | S_IRUGO, 1, 0, 0,
1478 0, &proc_net_inode_operations,
1479 rose_neigh_get_info
1481 static struct proc_dir_entry proc_net_rose_nodes = {
1482 PROC_NET_RS_NODES, 10, "rose_nodes",
1483 S_IFREG | S_IRUGO, 1, 0, 0,
1484 0, &proc_net_inode_operations,
1485 rose_nodes_get_info
1487 static struct proc_dir_entry proc_net_rose_routes = {
1488 PROC_NET_RS_ROUTES, 11, "rose_routes",
1489 S_IFREG | S_IRUGO, 1, 0, 0,
1490 0, &proc_net_inode_operations,
1491 rose_routes_get_info
1493 #endif
1495 static struct device *dev_rose;
1497 __initfunc(void rose_proto_init(struct net_proto *pro))
1499 int i;
1501 rose_callsign = null_ax25_address;
1503 if ((dev_rose = kmalloc(rose_ndevs * sizeof(struct device), GFP_KERNEL)) == NULL) {
1504 printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
1505 return;
1508 memset(dev_rose, 0x00, rose_ndevs * sizeof(struct device));
1510 for (i = 0; i < rose_ndevs; i++) {
1511 dev_rose[i].name = kmalloc(20, GFP_KERNEL);
1512 sprintf(dev_rose[i].name, "rose%d", i);
1513 dev_rose[i].init = rose_init;
1514 register_netdev(&dev_rose[i]);
1517 sock_register(&rose_family_ops);
1518 register_netdevice_notifier(&rose_dev_notifier);
1519 printk(KERN_INFO "F6FBB/G4KLX ROSE for Linux. Version 0.62 for AX25.037 Linux 2.1\n");
1521 ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
1522 ax25_linkfail_register(rose_link_failed);
1524 #ifdef CONFIG_SYSCTL
1525 rose_register_sysctl();
1526 #endif
1527 rose_loopback_init();
1529 rose_add_loopback_neigh();
1531 #ifdef CONFIG_PROC_FS
1532 proc_net_register(&proc_net_rose);
1533 proc_net_register(&proc_net_rose_neigh);
1534 proc_net_register(&proc_net_rose_nodes);
1535 proc_net_register(&proc_net_rose_routes);
1536 #endif
1539 #ifdef MODULE
1540 EXPORT_NO_SYMBOLS;
1542 MODULE_PARM(rose_ndevs, "i");
1543 MODULE_PARM_DESC(rose_ndevs, "number of ROSE devices");
1545 MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
1546 MODULE_DESCRIPTION("The amateur radio ROSE network layer protocol");
1548 int init_module(void)
1550 rose_proto_init(NULL);
1552 return 0;
1555 void cleanup_module(void)
1557 int i;
1559 #ifdef CONFIG_PROC_FS
1560 proc_net_unregister(PROC_NET_RS);
1561 proc_net_unregister(PROC_NET_RS_NEIGH);
1562 proc_net_unregister(PROC_NET_RS_NODES);
1563 proc_net_unregister(PROC_NET_RS_ROUTES);
1564 #endif
1565 rose_loopback_clear();
1567 rose_rt_free();
1569 ax25_protocol_release(AX25_P_ROSE);
1570 ax25_linkfail_release(rose_link_failed);
1572 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1573 ax25_listen_release(&rose_callsign, NULL);
1575 #ifdef CONFIG_SYSCTL
1576 rose_unregister_sysctl();
1577 #endif
1578 unregister_netdevice_notifier(&rose_dev_notifier);
1580 sock_unregister(PF_ROSE);
1582 for (i = 0; i < rose_ndevs; i++) {
1583 if (dev_rose[i].priv != NULL) {
1584 kfree(dev_rose[i].priv);
1585 dev_rose[i].priv = NULL;
1586 unregister_netdev(&dev_rose[i]);
1588 kfree(dev_rose[i].name);
1591 kfree(dev_rose);
1594 #endif
1596 #endif