1 /*
2 * ROSE release 003
3 *
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
5 *
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.
11 *
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
25 */
26
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/init.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
60 int rose_ndevs = 10;
61
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;
72
73 static struct sock *volatile rose_list = NULL;
74
75 static struct proto_ops rose_proto_ops;
76
77 ax25_address rose_callsign;
78
79 /*
80 * Convert a ROSE address into text.
81 */
82 char *rose2asc(rose_address *addr)
83 {
84 static char buffer[11];
85
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);
96 }
97
98 return buffer;
99 }
100
101 /*
102 * Compare two ROSE addresses, 0 == equal.
103 */
104 int rosecmp(rose_address *addr1, rose_address *addr2)
105 {
106 int i;
107
108 for (i = 0; i < 5; i++)
109 if (addr1->rose_addr[i] != addr2->rose_addr[i])
110 return 1;
111
112 return 0;
113 }
114
115 /*
116 * Compare two ROSE addresses for only mask digits, 0 == equal.
117 */
118 int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
119 {
120 int i, j;
121
122 if (mask > 10)
123 return 1;
124
125 for (i = 0; i < mask; i++) {
126 j = i / 2;
127
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;
134 }
135 }
136
137 return 0;
138 }
139
140 static void rose_free_sock(struct sock *sk)
141 {
142 sk_free(sk);
143
144 MOD_DEC_USE_COUNT;
145 }
146
147 static struct sock *rose_alloc_sock(void)
148 {
149 struct sock *sk;
150 rose_cb *rose;
151
152 if ((sk = sk_alloc(PF_ROSE, GFP_ATOMIC, 1)) == NULL)
153 return NULL;
154
155 if ((rose = kmalloc(sizeof(*rose), GFP_ATOMIC)) == NULL) {
156 sk_free(sk);
157 return NULL;
158 }
159
160 MOD_INC_USE_COUNT;
161
162 memset(rose, 0x00, sizeof(*rose));
163
164 sk->protinfo.rose = rose;
165 rose->sk = sk;
166
167 return sk;
168 }
169
170 /*
171 * Socket removal during an interrupt is now safe.
172 */
173 static void rose_remove_socket(struct sock *sk)
174 {
175 struct sock *s;
176 unsigned long flags;
177
178 save_flags(flags); cli();
179
180 if ((s = rose_list) == sk) {
181 rose_list = s->next;
182 restore_flags(flags);
183 return;
184 }
185
186 while (s != NULL && s->next != NULL) {
187 if (s->next == sk) {
188 s->next = sk->next;
189 restore_flags(flags);
190 return;
191 }
192
193 s = s->next;
194 }
195
196 restore_flags(flags);
197 }
198
199 /*
200 * Kill all bound sockets on a broken link layer connection to a
201 * particular neighbour.
202 */
203 void rose_kill_by_neigh(struct rose_neigh *neigh)
204 {
205 struct sock *s;
206
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;
212 }
213 }
214 }
215
216 /*
217 * Kill all bound sockets on a dropped device.
218 */
219 static void rose_kill_by_device(struct net_device *dev)
220 {
221 struct sock *s;
222
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;
228 }
229 }
230 }
231
232 /*
233 * Handle device status changes.
234 */
235 static int rose_device_event(struct notifier_block *this, unsigned long event, void *ptr)
236 {
237 struct net_device *dev = (struct net_device *)ptr;
238
239 if (event != NETDEV_DOWN)
240 return NOTIFY_DONE;
241
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;
250 }
251
252 return NOTIFY_DONE;
253 }
254
255 /*
256 * Add a socket to the bound sockets list.
257 */
258 static void rose_insert_socket(struct sock *sk)
259 {
260 unsigned long flags;
261
262 save_flags(flags); cli();
263
264 sk->next = rose_list;
265 rose_list = sk;
266
267 restore_flags(flags);
268 }
269
270 /*
271 * Find a socket that wants to accept the Call Request we just
272 * received.
273 */
274 static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
275 {
276 unsigned long flags;
277 struct sock *s;
278
279 save_flags(flags); cli();
280
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;
285 }
286 }
287
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;
292 }
293 }
294
295 restore_flags(flags);
296 return NULL;
297 }
298
299 /*
300 * Find a connected ROSE socket given my LCI and device.
301 */
302 struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
303 {
304 struct sock *s;
305 unsigned long flags;
306
307 save_flags(flags); cli();
308
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;
313 }
314 }
315
316 restore_flags(flags);
317
318 return NULL;
319 }
320
321 /*
322 * Find a unique LCI for a given device.
323 */
324 unsigned int rose_new_lci(struct rose_neigh *neigh)
325 {
326 int lci;
327
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;
336 }
337
338 return 0;
339 }
340
341 /*
342 * Deferred destroy.
343 */
344 void rose_destroy_socket(struct sock *);
345
346 /*
347 * Handler for deferred kills.
348 */
349 static void rose_destroy_timer(unsigned long data)
350 {
351 rose_destroy_socket((struct sock *)data);
352 }
353
354 /*
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.
359 */
360 void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the timer */
361 {
362 struct sk_buff *skb;
363 unsigned long flags;
364
365 save_flags(flags); cli();
366
367 rose_stop_heartbeat(sk);
368 rose_stop_idletimer(sk);
369 rose_stop_timer(sk);
370
371 rose_remove_socket(sk);
372 rose_clear_queues(sk); /* Flush the queues */
373
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;
379 }
380
381 kfree_skb(skb);
382 }
383
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);
393 }
394
395 restore_flags(flags);
396 }
397
398 /*
399 * Handling for system calls applied via the various interfaces to a
400 * ROSE socket object.
401 */
402
403 static int rose_setsockopt(struct socket *sock, int level, int optname,
404 char *optval, int optlen)
405 {
406 struct sock *sk = sock->sk;
407 int opt;
408
409 if (level != SOL_ROSE)
410 return -ENOPROTOOPT;
411
412 if (optlen < sizeof(int))
413 return -EINVAL;
414
415 if (get_user(opt, (int *)optval))
416 return -EFAULT;
417
418 switch (optname) {
419 case ROSE_DEFER:
420 sk->protinfo.rose->defer = opt ? 1 : 0;
421 return 0;
422
423 case ROSE_T1:
424 if (opt < 1)
425 return -EINVAL;
426 sk->protinfo.rose->t1 = opt * HZ;
427 return 0;
428
429 case ROSE_T2:
430 if (opt < 1)
431 return -EINVAL;
432 sk->protinfo.rose->t2 = opt * HZ;
433 return 0;
434
435 case ROSE_T3:
436 if (opt < 1)
437 return -EINVAL;
438 sk->protinfo.rose->t3 = opt * HZ;
439 return 0;
440
441 case ROSE_HOLDBACK:
442 if (opt < 1)
443 return -EINVAL;
444 sk->protinfo.rose->hb = opt * HZ;
445 return 0;
446
447 case ROSE_IDLE:
448 if (opt < 0)
449 return -EINVAL;
450 sk->protinfo.rose->idle = opt * 60 * HZ;
451 return 0;
452
453 case ROSE_QBITINCL:
454 sk->protinfo.rose->qbitincl = opt ? 1 : 0;
455 return 0;
456
457 default:
458 return -ENOPROTOOPT;
459 }
460 }
461
462 static int rose_getsockopt(struct socket *sock, int level, int optname,
463 char *optval, int *optlen)
464 {
465 struct sock *sk = sock->sk;
466 int val = 0;
467 int len;
468
469 if (level != SOL_ROSE)
470 return -ENOPROTOOPT;
471
472 if (get_user(len, optlen))
473 return -EFAULT;
474
475 switch (optname) {
476 case ROSE_DEFER:
477 val = sk->protinfo.rose->defer;
478 break;
479
480 case ROSE_T1:
481 val = sk->protinfo.rose->t1 / HZ;
482 break;
483
484 case ROSE_T2:
485 val = sk->protinfo.rose->t2 / HZ;
486 break;
487
488 case ROSE_T3:
489 val = sk->protinfo.rose->t3 / HZ;
490 break;
491
492 case ROSE_HOLDBACK:
493 val = sk->protinfo.rose->hb / HZ;
494 break;
495
496 case ROSE_IDLE:
497 val = sk->protinfo.rose->idle / (60 * HZ);
498 break;
499
500 case ROSE_QBITINCL:
501 val = sk->protinfo.rose->qbitincl;
502 break;
503
504 default:
505 return -ENOPROTOOPT;
506 }
507
508 len = min(len, sizeof(int));
509
510 if (put_user(len, optlen))
511 return -EFAULT;
512
513 return copy_to_user(optval, &val, len) ? -EFAULT : 0;
514 }
515
516 static int rose_listen(struct socket *sock, int backlog)
517 {
518 struct sock *sk = sock->sk;
519
520 if (sk->state != TCP_LISTEN) {
521 sk->protinfo.rose->dest_ndigis = 0;
522 memset(&sk->protinfo.rose->dest_addr, '\0', ROSE_ADDR_LEN);
523 memset(&sk->protinfo.rose->dest_call, '\0', AX25_ADDR_LEN);
524 memset(sk->protinfo.rose->dest_digis, '\0', AX25_ADDR_LEN*ROSE_MAX_DIGIS);
525 sk->max_ack_backlog = backlog;
526 sk->state = TCP_LISTEN;
527 return 0;
528 }
529
530 return -EOPNOTSUPP;
531 }
532
533 static int rose_create(struct socket *sock, int protocol)
534 {
535 struct sock *sk;
536 rose_cb *rose;
537
538 if (sock->type != SOCK_SEQPACKET || protocol != 0)
539 return -ESOCKTNOSUPPORT;
540
541 if ((sk = rose_alloc_sock()) == NULL)
542 return -ENOMEM;
543
544 rose = sk->protinfo.rose;
545
546 sock_init_data(sock, sk);
547
548 skb_queue_head_init(&rose->ack_queue);
549 #ifdef M_BIT
550 skb_queue_head_init(&rose->frag_queue);
551 rose->fraglen = 0;
552 #endif
553
554 sock->ops = &rose_proto_ops;
555 sk->protocol = protocol;
556
557 init_timer(&rose->timer);
558 init_timer(&rose->idletimer);
559
560 rose->t1 = sysctl_rose_call_request_timeout;
561 rose->t2 = sysctl_rose_reset_request_timeout;
562 rose->t3 = sysctl_rose_clear_request_timeout;
563 rose->hb = sysctl_rose_ack_hold_back_timeout;
564 rose->idle = sysctl_rose_no_activity_timeout;
565
566 rose->state = ROSE_STATE_0;
567
568 return 0;
569 }
570
571 static struct sock *rose_make_new(struct sock *osk)
572 {
573 struct sock *sk;
574 rose_cb *rose;
575
576 if (osk->type != SOCK_SEQPACKET)
577 return NULL;
578
579 if ((sk = rose_alloc_sock()) == NULL)
580 return NULL;
581
582 rose = sk->protinfo.rose;
583
584 sock_init_data(NULL, sk);
585
586 skb_queue_head_init(&rose->ack_queue);
587 #ifdef M_BIT
588 skb_queue_head_init(&rose->frag_queue);
589 rose->fraglen = 0;
590 #endif
591
592 sk->type = osk->type;
593 sk->socket = osk->socket;
594 sk->priority = osk->priority;
595 sk->protocol = osk->protocol;
596 sk->rcvbuf = osk->rcvbuf;
597 sk->sndbuf = osk->sndbuf;
598 sk->debug = osk->debug;
599 sk->state = TCP_ESTABLISHED;
600 sk->sleep = osk->sleep;
601 sk->zapped = osk->zapped;
602
603 init_timer(&rose->timer);
604 init_timer(&rose->idletimer);
605
606 rose->t1 = osk->protinfo.rose->t1;
607 rose->t2 = osk->protinfo.rose->t2;
608 rose->t3 = osk->protinfo.rose->t3;
609 rose->hb = osk->protinfo.rose->hb;
610 rose->idle = osk->protinfo.rose->idle;
611
612 rose->defer = osk->protinfo.rose->defer;
613 rose->device = osk->protinfo.rose->device;
614 rose->qbitincl = osk->protinfo.rose->qbitincl;
615
616 return sk;
617 }
618
619 static int rose_release(struct socket *sock)
620 {
621 struct sock *sk = sock->sk;
622
623 if (sk == NULL) return 0;
624
625 switch (sk->protinfo.rose->state) {
626
627 case ROSE_STATE_0:
628 rose_disconnect(sk, 0, -1, -1);
629 rose_destroy_socket(sk);
630 break;
631
632 case ROSE_STATE_2:
633 sk->protinfo.rose->neighbour->use--;
634 rose_disconnect(sk, 0, -1, -1);
635 rose_destroy_socket(sk);
636 break;
637
638 case ROSE_STATE_1:
639 case ROSE_STATE_3:
640 case ROSE_STATE_4:
641 case ROSE_STATE_5:
642 rose_clear_queues(sk);
643 rose_stop_idletimer(sk);
644 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
645 rose_start_t3timer(sk);
646 sk->protinfo.rose->state = ROSE_STATE_2;
647 sk->state = TCP_CLOSE;
648 sk->shutdown |= SEND_SHUTDOWN;
649 sk->state_change(sk);
650 sk->dead = 1;
651 sk->destroy = 1;
652 break;
653
654 default:
655 break;
656 }
657
658 sock->sk = NULL;
659 sk->socket = NULL; /* Not used, but we should do this. **/
660
661 return 0;
662 }
663
664 static int rose_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
665 {
666 struct sock *sk = sock->sk;
667 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
668 struct net_device *dev;
669 ax25_address *user, *source;
670 int n;
671
672 if (sk->zapped == 0)
673 return -EINVAL;
674
675 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
676 return -EINVAL;
677
678 if (addr->srose_family != AF_ROSE)
679 return -EINVAL;
680
681 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
682 return -EINVAL;
683
684 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
685 return -EINVAL;
686
687 if ((dev = rose_dev_get(&addr->srose_addr)) == NULL) {
688 SOCK_DEBUG(sk, "ROSE: bind failed: invalid address\n");
689 return -EADDRNOTAVAIL;
690 }
691
692 source = &addr->srose_call;
693
694 if ((user = ax25_findbyuid(current->euid)) == NULL) {
695 if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE))
696 return -EACCES;
697 user = source;
698 }
699
700 sk->protinfo.rose->source_addr = addr->srose_addr;
701 sk->protinfo.rose->source_call = *user;
702 sk->protinfo.rose->device = dev;
703 sk->protinfo.rose->source_ndigis = addr->srose_ndigis;
704
705 if (addr_len == sizeof(struct full_sockaddr_rose)) {
706 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
707 for (n = 0 ; n < addr->srose_ndigis ; n++)
708 sk->protinfo.rose->source_digis[n] = full_addr->srose_digis[n];
709 } else {
710 if (sk->protinfo.rose->source_ndigis == 1) {
711 sk->protinfo.rose->source_digis[0] = addr->srose_digi;
712 }
713 }
714
715 rose_insert_socket(sk);
716
717 sk->zapped = 0;
718 SOCK_DEBUG(sk, "ROSE: socket is bound\n");
719 return 0;
720 }
721
722 static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
723 {
724 struct sock *sk = sock->sk;
725 struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
726 unsigned char cause, diagnostic;
727 ax25_address *user;
728 struct net_device *dev;
729 int n;
730
731 if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
732 sock->state = SS_CONNECTED;
733 return 0; /* Connect completed during a ERESTARTSYS event */
734 }
735
736 if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
737 sock->state = SS_UNCONNECTED;
738 return -ECONNREFUSED;
739 }
740
741 if (sk->state == TCP_ESTABLISHED)
742 return -EISCONN; /* No reconnect on a seqpacket socket */
743
744 sk->state = TCP_CLOSE;
745 sock->state = SS_UNCONNECTED;
746
747 if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
748 return -EINVAL;
749
750 if (addr->srose_family != AF_ROSE)
751 return -EINVAL;
752
753 if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
754 return -EINVAL;
755
756 if (addr->srose_ndigis > ROSE_MAX_DIGIS)
757 return -EINVAL;
758
759 /* Source + Destination digis should not exceed ROSE_MAX_DIGIS */
760 if ((sk->protinfo.rose->source_ndigis + addr->srose_ndigis) > ROSE_MAX_DIGIS)
761 return -EINVAL;
762
763 if ((sk->protinfo.rose->neighbour = rose_get_neigh(&addr->srose_addr, &cause, &diagnostic)) == NULL)
764 return -ENETUNREACH;
765
766 if ((sk->protinfo.rose->lci = rose_new_lci(sk->protinfo.rose->neighbour)) == 0)
767 return -ENETUNREACH;
768
769 if (sk->zapped) { /* Must bind first - autobinding in this may or may not work */
770 sk->zapped = 0;
771
772 if ((dev = rose_dev_first()) == NULL)
773 return -ENETUNREACH;
774
775 if ((user = ax25_findbyuid(current->euid)) == NULL)
776 return -EINVAL;
777
778 memcpy(&sk->protinfo.rose->source_addr, dev->dev_addr, ROSE_ADDR_LEN);
779 sk->protinfo.rose->source_call = *user;
780 sk->protinfo.rose->device = dev;
781
782 rose_insert_socket(sk); /* Finish the bind */
783 }
784
785 sk->protinfo.rose->dest_addr = addr->srose_addr;
786 sk->protinfo.rose->dest_call = addr->srose_call;
787 sk->protinfo.rose->rand = ((int)sk->protinfo.rose & 0xFFFF) + sk->protinfo.rose->lci;
788 sk->protinfo.rose->dest_ndigis = addr->srose_ndigis;
789
790 if (addr_len == sizeof(struct full_sockaddr_rose)) {
791 struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
792 for (n = 0 ; n < addr->srose_ndigis ; n++)
793 sk->protinfo.rose->dest_digis[n] = full_addr->srose_digis[n];
794 } else {
795 if (sk->protinfo.rose->dest_ndigis == 1) {
796 sk->protinfo.rose->dest_digis[0] = addr->srose_digi;
797 }
798 }
799
800 /* Move to connecting socket, start sending Connect Requests */
801 sock->state = SS_CONNECTING;
802 sk->state = TCP_SYN_SENT;
803
804 sk->protinfo.rose->state = ROSE_STATE_1;
805
806 sk->protinfo.rose->neighbour->use++;
807
808 rose_write_internal(sk, ROSE_CALL_REQUEST);
809 rose_start_heartbeat(sk);
810 rose_start_t1timer(sk);
811
812 /* Now the loop */
813 if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
814 return -EINPROGRESS;
815
816 cli(); /* To avoid races on the sleep */
817
818 /*
819 * A Connect Ack with Choke or timeout or failed routing will go to closed.
820 */
821 while (sk->state == TCP_SYN_SENT) {
822 interruptible_sleep_on(sk->sleep);
823 if (signal_pending(current)) {
824 sti();
825 return -ERESTARTSYS;
826 }
827 }
828
829 if (sk->state != TCP_ESTABLISHED) {
830 sti();
831 sock->state = SS_UNCONNECTED;
832 return sock_error(sk); /* Always set at this point */
833 }
834
835 sock->state = SS_CONNECTED;
836
837 sti();
838
839 return 0;
840 }
841
842 static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
843 {
844 struct sock *sk;
845 struct sock *newsk;
846 struct sk_buff *skb;
847
848 if ((sk = sock->sk) == NULL)
849 return -EINVAL;
850
851 if (sk->type != SOCK_SEQPACKET)
852 return -EOPNOTSUPP;
853
854 if (sk->state != TCP_LISTEN)
855 return -EINVAL;
856
857 /*
858 * The write queue this time is holding sockets ready to use
859 * hooked into the SABM we saved
860 */
861 do {
862 cli();
863 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
864 if (flags & O_NONBLOCK) {
865 sti();
866 return -EWOULDBLOCK;
867 }
868 interruptible_sleep_on(sk->sleep);
869 if (signal_pending(current)) {
870 sti();
871 return -ERESTARTSYS;
872 }
873 }
874 } while (skb == NULL);
875
876 newsk = skb->sk;
877 newsk->pair = NULL;
878 newsk->socket = newsock;
879 newsk->sleep = &newsock->wait;
880 sti();
881
882 /* Now attach up the new socket */
883 skb->sk = NULL;
884 kfree_skb(skb);
885 sk->ack_backlog--;
886 newsock->sk = newsk;
887
888 return 0;
889 }
890
891 static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
892 int *uaddr_len, int peer)
893 {
894 struct full_sockaddr_rose *srose = (struct full_sockaddr_rose *)uaddr;
895 struct sock *sk = sock->sk;
896 int n;
897
898 if (peer != 0) {
899 if (sk->state != TCP_ESTABLISHED)
900 return -ENOTCONN;
901 srose->srose_family = AF_ROSE;
902 srose->srose_addr = sk->protinfo.rose->dest_addr;
903 srose->srose_call = sk->protinfo.rose->dest_call;
904 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
905 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
906 srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
907 } else {
908 srose->srose_family = AF_ROSE;
909 srose->srose_addr = sk->protinfo.rose->source_addr;
910 srose->srose_call = sk->protinfo.rose->source_call;
911 srose->srose_ndigis = sk->protinfo.rose->source_ndigis;
912 for (n = 0 ; n < sk->protinfo.rose->source_ndigis ; n++)
913 srose->srose_digis[n] = sk->protinfo.rose->source_digis[n];
914 }
915
916 *uaddr_len = sizeof(struct full_sockaddr_rose);
917 return 0;
918 }
919
920 int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct rose_neigh *neigh, unsigned int lci)
921 {
922 struct sock *sk;
923 struct sock *make;
924 struct rose_facilities_struct facilities;
925 int n, len;
926
927 skb->sk = NULL; /* Initially we don't know who it's for */
928
929 /*
930 * skb->data points to the rose frame start
931 */
932 memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
933
934 len = (((skb->data[3] >> 4) & 0x0F) + 1) / 2;
935 len += (((skb->data[3] >> 0) & 0x0F) + 1) / 2;
936 if (!rose_parse_facilities(skb->data + len + 4, &facilities)) {
937 rose_transmit_clear_request(neigh, lci, ROSE_INVALID_FACILITY, 76);
938 return 0;
939 }
940
941 sk = rose_find_listener(&facilities.source_addr, &facilities.source_call);
942
943 /*
944 * We can't accept the Call Request.
945 */
946 if (sk == NULL || sk->ack_backlog == sk->max_ack_backlog || (make = rose_make_new(sk)) == NULL) {
947 rose_transmit_clear_request(neigh, lci, ROSE_NETWORK_CONGESTION, 120);
948 return 0;
949 }
950
951 skb->sk = make;
952 make->state = TCP_ESTABLISHED;
953
954 make->protinfo.rose->lci = lci;
955 make->protinfo.rose->dest_addr = facilities.dest_addr;
956 make->protinfo.rose->dest_call = facilities.dest_call;
957 make->protinfo.rose->dest_ndigis = facilities.dest_ndigis;
958 for (n = 0 ; n < facilities.dest_ndigis ; n++)
959 make->protinfo.rose->dest_digis[n] = facilities.dest_digis[n];
960 make->protinfo.rose->source_addr = facilities.source_addr;
961 make->protinfo.rose->source_call = facilities.source_call;
962 make->protinfo.rose->source_ndigis = facilities.source_ndigis;
963 for (n = 0 ; n < facilities.source_ndigis ; n++)
964 make->protinfo.rose->source_digis[n]= facilities.source_digis[n];
965 make->protinfo.rose->neighbour = neigh;
966 make->protinfo.rose->device = dev;
967 make->protinfo.rose->facilities = facilities;
968
969 make->protinfo.rose->neighbour->use++;
970
971 if (sk->protinfo.rose->defer) {
972 make->protinfo.rose->state = ROSE_STATE_5;
973 } else {
974 rose_write_internal(make, ROSE_CALL_ACCEPTED);
975 make->protinfo.rose->state = ROSE_STATE_3;
976 rose_start_idletimer(make);
977 }
978
979 make->protinfo.rose->condition = 0x00;
980 make->protinfo.rose->vs = 0;
981 make->protinfo.rose->va = 0;
982 make->protinfo.rose->vr = 0;
983 make->protinfo.rose->vl = 0;
984 sk->ack_backlog++;
985 make->pair = sk;
986
987 rose_insert_socket(make);
988
989 skb_queue_head(&sk->receive_queue, skb);
990
991 rose_start_heartbeat(make);
992
993 if (!sk->dead)
994 sk->data_ready(sk, skb->len);
995
996 return 1;
997 }
998
999 static int rose_sendmsg(struct socket *sock, struct msghdr *msg, int len,
1000 struct scm_cookie *scm)
1001 {
1002 struct sock *sk = sock->sk;
1003 struct sockaddr_rose *usrose = (struct sockaddr_rose *)msg->msg_name;
1004 int err;
1005 struct full_sockaddr_rose srose;
1006 struct sk_buff *skb;
1007 unsigned char *asmptr;
1008 int n, size, qbit = 0;
1009
1010 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR))
1011 return -EINVAL;
1012
1013 if (sk->zapped)
1014 return -EADDRNOTAVAIL;
1015
1016 if (sk->shutdown & SEND_SHUTDOWN) {
1017 send_sig(SIGPIPE, current, 0);
1018 return -EPIPE;
1019 }
1020
1021 if (sk->protinfo.rose->neighbour == NULL || sk->protinfo.rose->device == NULL)
1022 return -ENETUNREACH;
1023
1024 if (usrose != NULL) {
1025 if (msg->msg_namelen != sizeof(struct sockaddr_rose) && msg->msg_namelen != sizeof(struct full_sockaddr_rose))
1026 return -EINVAL;
1027 memset(&srose, 0, sizeof(struct full_sockaddr_rose));
1028 memcpy(&srose, usrose, msg->msg_namelen);
1029 if (rosecmp(&sk->protinfo.rose->dest_addr, &srose.srose_addr) != 0 ||
1030 ax25cmp(&sk->protinfo.rose->dest_call, &srose.srose_call) != 0)
1031 return -EISCONN;
1032 if (srose.srose_ndigis != sk->protinfo.rose->dest_ndigis)
1033 return -EISCONN;
1034 if (srose.srose_ndigis == sk->protinfo.rose->dest_ndigis) {
1035 for (n = 0 ; n < srose.srose_ndigis ; n++)
1036 if (ax25cmp(&sk->protinfo.rose->dest_digis[n], &srose.srose_digis[n]) != 0)
1037 return -EISCONN;
1038 }
1039 if (srose.srose_family != AF_ROSE)
1040 return -EINVAL;
1041 } else {
1042 if (sk->state != TCP_ESTABLISHED)
1043 return -ENOTCONN;
1044
1045 srose.srose_family = AF_ROSE;
1046 srose.srose_addr = sk->protinfo.rose->dest_addr;
1047 srose.srose_call = sk->protinfo.rose->dest_call;
1048 srose.srose_ndigis = sk->protinfo.rose->dest_ndigis;
1049 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1050 srose.srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1051 }
1052
1053 SOCK_DEBUG(sk, "ROSE: sendto: Addresses built.\n");
1054
1055 /* Build a packet */
1056 SOCK_DEBUG(sk, "ROSE: sendto: building packet.\n");
1057 size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
1058
1059 if ((skb = sock_alloc_send_skb(sk, size, 0, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
1060 return err;
1061
1062 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN);
1063
1064 /*
1065 * Put the data on the end
1066 */
1067 SOCK_DEBUG(sk, "ROSE: Appending user data\n");
1068
1069 asmptr = skb->h.raw = skb_put(skb, len);
1070
1071 memcpy_fromiovec(asmptr, msg->msg_iov, len);
1072
1073 /*
1074 * If the Q BIT Include socket option is in force, the first
1075 * byte of the user data is the logical value of the Q Bit.
1076 */
1077 if (sk->protinfo.rose->qbitincl) {
1078 qbit = skb->data[0];
1079 skb_pull(skb, 1);
1080 }
1081
1082 /*
1083 * Push down the ROSE header
1084 */
1085 asmptr = skb_push(skb, ROSE_MIN_LEN);
1086
1087 SOCK_DEBUG(sk, "ROSE: Building Network Header.\n");
1088
1089 /* Build a ROSE Network header */
1090 asmptr[0] = ((sk->protinfo.rose->lci >> 8) & 0x0F) | ROSE_GFI;
1091 asmptr[1] = (sk->protinfo.rose->lci >> 0) & 0xFF;
1092 asmptr[2] = ROSE_DATA;
1093
1094 if (qbit)
1095 asmptr[0] |= ROSE_Q_BIT;
1096
1097 SOCK_DEBUG(sk, "ROSE: Built header.\n");
1098
1099 SOCK_DEBUG(sk, "ROSE: Transmitting buffer\n");
1100
1101 if (sk->state != TCP_ESTABLISHED) {
1102 kfree_skb(skb);
1103 return -ENOTCONN;
1104 }
1105
1106 #ifdef M_BIT
1107 #define ROSE_PACLEN (256-ROSE_MIN_LEN)
1108 if (skb->len - ROSE_MIN_LEN > ROSE_PACLEN) {
1109 unsigned char header[ROSE_MIN_LEN];
1110 struct sk_buff *skbn;
1111 int frontlen;
1112 int lg;
1113
1114 /* Save a copy of the Header */
1115 memcpy(header, skb->data, ROSE_MIN_LEN);
1116 skb_pull(skb, ROSE_MIN_LEN);
1117
1118 frontlen = skb_headroom(skb);
1119
1120 while (skb->len > 0) {
1121 if ((skbn = sock_alloc_send_skb(sk, frontlen + ROSE_PACLEN, 0, 0, &err)) == NULL)
1122 return err;
1123
1124 skbn->sk = sk;
1125 skbn->free = 1;
1126 skbn->arp = 1;
1127
1128 skb_reserve(skbn, frontlen);
1129
1130 lg = (ROSE_PACLEN > skb->len) ? skb->len : ROSE_PACLEN;
1131
1132 /* Copy the user data */
1133 memcpy(skb_put(skbn, lg), skb->data, lg);
1134 skb_pull(skb, lg);
1135
1136 /* Duplicate the Header */
1137 skb_push(skbn, ROSE_MIN_LEN);
1138 memcpy(skbn->data, header, ROSE_MIN_LEN);
1139
1140 if (skb->len > 0)
1141 skbn->data[2] |= M_BIT;
1142
1143 skb_queue_tail(&sk->write_queue, skbn); /* Throw it on the queue */
1144 }
1145
1146 skb->free = 1;
1147 kfree_skb(skb, FREE_WRITE);
1148 } else {
1149 skb_queue_tail(&sk->write_queue, skb); /* Throw it on the queue */
1150 }
1151 #else
1152 skb_queue_tail(&sk->write_queue, skb); /* Shove it onto the queue */
1153 #endif
1154
1155 rose_kick(sk);
1156
1157 return len;
1158 }
1159
1160
1161 static int rose_recvmsg(struct socket *sock, struct msghdr *msg, int size,
1162 int flags, struct scm_cookie *scm)
1163 {
1164 struct sock *sk = sock->sk;
1165 struct sockaddr_rose *srose = (struct sockaddr_rose *)msg->msg_name;
1166 int copied, qbit;
1167 unsigned char *asmptr;
1168 struct sk_buff *skb;
1169 int n, er;
1170
1171 /*
1172 * This works for seqpacket too. The receiver has ordered the queue for
1173 * us! We do one quick check first though
1174 */
1175 if (sk->state != TCP_ESTABLISHED)
1176 return -ENOTCONN;
1177
1178 /* Now we can treat all alike */
1179 if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL)
1180 return er;
1181
1182 qbit = (skb->data[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
1183
1184 skb_pull(skb, ROSE_MIN_LEN);
1185
1186 if (sk->protinfo.rose->qbitincl) {
1187 asmptr = skb_push(skb, 1);
1188 *asmptr = qbit;
1189 }
1190
1191 skb->h.raw = skb->data;
1192 copied = skb->len;
1193
1194 if (copied > size) {
1195 copied = size;
1196 msg->msg_flags |= MSG_TRUNC;
1197 }
1198
1199 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1200
1201 if (srose != NULL) {
1202 srose->srose_family = AF_ROSE;
1203 srose->srose_addr = sk->protinfo.rose->dest_addr;
1204 srose->srose_call = sk->protinfo.rose->dest_call;
1205 srose->srose_ndigis = sk->protinfo.rose->dest_ndigis;
1206 if (msg->msg_namelen >= sizeof(struct full_sockaddr_rose)) {
1207 struct full_sockaddr_rose *full_srose = (struct full_sockaddr_rose *)msg->msg_name;
1208 for (n = 0 ; n < sk->protinfo.rose->dest_ndigis ; n++)
1209 full_srose->srose_digis[n] = sk->protinfo.rose->dest_digis[n];
1210 msg->msg_namelen = sizeof(struct full_sockaddr_rose);
1211 } else {
1212 if (sk->protinfo.rose->dest_ndigis >= 1) {
1213 srose->srose_ndigis = 1;
1214 srose->srose_digi = sk->protinfo.rose->dest_digis[0];
1215 }
1216 msg->msg_namelen = sizeof(struct sockaddr_rose);
1217 }
1218 }
1219
1220 skb_free_datagram(sk, skb);
1221
1222 return copied;
1223 }
1224
1225
1226 static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1227 {
1228 struct sock *sk = sock->sk;
1229
1230 switch (cmd) {
1231 case TIOCOUTQ: {
1232 long amount;
1233 amount = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1234 if (amount < 0)
1235 amount = 0;
1236 return put_user(amount, (unsigned int *)arg);
1237 }
1238
1239 case TIOCINQ: {
1240 struct sk_buff *skb;
1241 long amount = 0L;
1242 /* These two are safe on a single CPU system as only user tasks fiddle here */
1243 if ((skb = skb_peek(&sk->receive_queue)) != NULL)
1244 amount = skb->len;
1245 return put_user(amount, (unsigned int *)arg);
1246 }
1247
1248 case SIOCGSTAMP:
1249 if (sk != NULL) {
1250 if (sk->stamp.tv_sec == 0)
1251 return -ENOENT;
1252 return copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)) ? -EFAULT : 0;
1253 }
1254 return -EINVAL;
1255
1256 case SIOCGIFADDR:
1257 case SIOCSIFADDR:
1258 case SIOCGIFDSTADDR:
1259 case SIOCSIFDSTADDR:
1260 case SIOCGIFBRDADDR:
1261 case SIOCSIFBRDADDR:
1262 case SIOCGIFNETMASK:
1263 case SIOCSIFNETMASK:
1264 case SIOCGIFMETRIC:
1265 case SIOCSIFMETRIC:
1266 return -EINVAL;
1267
1268 case SIOCADDRT:
1269 case SIOCDELRT:
1270 case SIOCRSCLRRT:
1271 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1272 return rose_rt_ioctl(cmd, (void *)arg);
1273
1274 case SIOCRSGCAUSE: {
1275 struct rose_cause_struct rose_cause;
1276 rose_cause.cause = sk->protinfo.rose->cause;
1277 rose_cause.diagnostic = sk->protinfo.rose->diagnostic;
1278 return copy_to_user((void *)arg, &rose_cause, sizeof(struct rose_cause_struct)) ? -EFAULT : 0;
1279 }
1280
1281 case SIOCRSSCAUSE: {
1282 struct rose_cause_struct rose_cause;
1283 if (copy_from_user(&rose_cause, (void *)arg, sizeof(struct rose_cause_struct)))
1284 return -EFAULT;
1285 sk->protinfo.rose->cause = rose_cause.cause;
1286 sk->protinfo.rose->diagnostic = rose_cause.diagnostic;
1287 return 0;
1288 }
1289
1290 case SIOCRSSL2CALL:
1291 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1292 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1293 ax25_listen_release(&rose_callsign, NULL);
1294 if (copy_from_user(&rose_callsign, (void *)arg, sizeof(ax25_address)))
1295 return -EFAULT;
1296 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1297 ax25_listen_register(&rose_callsign, NULL);
1298 return 0;
1299
1300 case SIOCRSGL2CALL:
1301 return copy_to_user((void *)arg, &rose_callsign, sizeof(ax25_address)) ? -EFAULT : 0;
1302
1303 case SIOCRSACCEPT:
1304 if (sk->protinfo.rose->state == ROSE_STATE_5) {
1305 rose_write_internal(sk, ROSE_CALL_ACCEPTED);
1306 rose_start_idletimer(sk);
1307 sk->protinfo.rose->condition = 0x00;
1308 sk->protinfo.rose->vs = 0;
1309 sk->protinfo.rose->va = 0;
1310 sk->protinfo.rose->vr = 0;
1311 sk->protinfo.rose->vl = 0;
1312 sk->protinfo.rose->state = ROSE_STATE_3;
1313 }
1314 return 0;
1315
1316 default:
1317 return dev_ioctl(cmd, (void *)arg);
1318 }
1319
1320 /*NOTREACHED*/
1321 return 0;
1322 }
1323
1324 static int rose_get_info(char *buffer, char **start, off_t offset, int length)
1325 {
1326 struct sock *s;
1327 struct net_device *dev;
1328 const char *devname, *callsign;
1329 int len = 0;
1330 off_t pos = 0;
1331 off_t begin = 0;
1332
1333 cli();
1334
1335 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");
1336
1337 for (s = rose_list; s != NULL; s = s->next) {
1338 if ((dev = s->protinfo.rose->device) == NULL)
1339 devname = "???";
1340 else
1341 devname = dev->name;
1342
1343 len += sprintf(buffer + len, "%-10s %-9s ",
1344 rose2asc(&s->protinfo.rose->dest_addr),
1345 ax2asc(&s->protinfo.rose->dest_call));
1346
1347 if (ax25cmp(&s->protinfo.rose->source_call, &null_ax25_address) == 0)
1348 callsign = "??????-?";
1349 else
1350 callsign = ax2asc(&s->protinfo.rose->source_call);
1351
1352 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",
1353 rose2asc(&s->protinfo.rose->source_addr),
1354 callsign,
1355 devname,
1356 s->protinfo.rose->lci & 0x0FFF,
1357 (s->protinfo.rose->neighbour) ? s->protinfo.rose->neighbour->number : 0,
1358 s->protinfo.rose->state,
1359 s->protinfo.rose->vs,
1360 s->protinfo.rose->vr,
1361 s->protinfo.rose->va,
1362 ax25_display_timer(&s->protinfo.rose->timer) / HZ,
1363 s->protinfo.rose->t1 / HZ,
1364 s->protinfo.rose->t2 / HZ,
1365 s->protinfo.rose->t3 / HZ,
1366 s->protinfo.rose->hb / HZ,
1367 ax25_display_timer(&s->protinfo.rose->idletimer) / (60 * HZ),
1368 s->protinfo.rose->idle / (60 * HZ),
1369 atomic_read(&s->wmem_alloc),
1370 atomic_read(&s->rmem_alloc),
1371 s->socket != NULL ? s->socket->inode->i_ino : 0L);
1372
1373 pos = begin + len;
1374
1375 if (pos < offset) {
1376 len = 0;
1377 begin = pos;
1378 }
1379
1380 if (pos > offset + length)
1381 break;
1382 }
1383
1384 sti();
1385
1386 *start = buffer + (offset - begin);
1387 len -= (offset - begin);
1388
1389 if (len > length) len = length;
1390
1391 return(len);
1392 }
1393
1394 static struct net_proto_family rose_family_ops = {
1395 PF_ROSE,
1396 rose_create
1397 };
1398
1399 static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = {
1400 family: PF_ROSE,
1401
1402 release: rose_release,
1403 bind: rose_bind,
1404 connect: rose_connect,
1405 socketpair: sock_no_socketpair,
1406 accept: rose_accept,
1407 getname: rose_getname,
1408 poll: datagram_poll,
1409 ioctl: rose_ioctl,
1410 listen: rose_listen,
1411 shutdown: sock_no_shutdown,
1412 setsockopt: rose_setsockopt,
1413 getsockopt: rose_getsockopt,
1414 sendmsg: rose_sendmsg,
1415 recvmsg: rose_recvmsg,
1416 mmap: sock_no_mmap,
1417 };
1418
1419 #include <linux/smp_lock.h>
1420 SOCKOPS_WRAP(rose_proto, PF_ROSE);
1421
1422 static struct notifier_block rose_dev_notifier = {
1423 rose_device_event,
1424 0
1425 };
1426
1427 static struct net_device *dev_rose;
1428
1429 static int __init rose_proto_init(void)
1430 {
1431 int i;
1432
1433 rose_callsign = null_ax25_address;
1434
1435 if ((dev_rose = kmalloc(rose_ndevs * sizeof(struct net_device), GFP_KERNEL)) == NULL) {
1436 printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
1437 return -1;
1438 }
1439
1440 memset(dev_rose, 0x00, rose_ndevs * sizeof(struct net_device));
1441
1442 for (i = 0; i < rose_ndevs; i++) {
1443 sprintf(dev_rose[i].name, "rose%d", i);
1444 dev_rose[i].init = rose_init;
1445 register_netdev(&dev_rose[i]);
1446 }
1447
1448 sock_register(&rose_family_ops);
1449 register_netdevice_notifier(&rose_dev_notifier);
1450 printk(KERN_INFO "F6FBB/G4KLX ROSE for Linux. Version 0.62 for AX25.037 Linux 2.4\n");
1451
1452 ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
1453 ax25_linkfail_register(rose_link_failed);
1454
1455 #ifdef CONFIG_SYSCTL
1456 rose_register_sysctl();
1457 #endif
1458 rose_loopback_init();
1459
1460 rose_add_loopback_neigh();
1461
1462 proc_net_create("rose", 0, rose_get_info);
1463 proc_net_create("rose_neigh", 0, rose_neigh_get_info);
1464 proc_net_create("rose_nodes", 0, rose_nodes_get_info);
1465 proc_net_create("rose_routes", 0, rose_routes_get_info);
1466 return 0;
1467 }
1468 module_init(rose_proto_init);
1469
1470 EXPORT_NO_SYMBOLS;
1471
1472 MODULE_PARM(rose_ndevs, "i");
1473 MODULE_PARM_DESC(rose_ndevs, "number of ROSE devices");
1474
1475 MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
1476 MODULE_DESCRIPTION("The amateur radio ROSE network layer protocol");
1477
1478 static void __exit rose_exit(void)
1479 {
1480 int i;
1481
1482 proc_net_remove("rose");
1483 proc_net_remove("rose_neigh");
1484 proc_net_remove("rose_nodes");
1485 proc_net_remove("rose_routes");
1486 rose_loopback_clear();
1487
1488 rose_rt_free();
1489
1490 ax25_protocol_release(AX25_P_ROSE);
1491 ax25_linkfail_release(rose_link_failed);
1492
1493 if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
1494 ax25_listen_release(&rose_callsign, NULL);
1495
1496 #ifdef CONFIG_SYSCTL
1497 rose_unregister_sysctl();
1498 #endif
1499 unregister_netdevice_notifier(&rose_dev_notifier);
1500
1501 sock_unregister(PF_ROSE);
1502
1503 for (i = 0; i < rose_ndevs; i++) {
1504 if (dev_rose[i].priv != NULL) {
1505 kfree(dev_rose[i].priv);
1506 dev_rose[i].priv = NULL;
1507 unregister_netdev(&dev_rose[i]);
1508 }
1509 kfree(dev_rose[i].name);
1510 }
1511
1512 kfree(dev_rose);
1513 }
1514 module_exit(rose_exit);
1515
1516
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.