blob: 968e8bac1b5dfd8f33578633c1f4338a5fe66624 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 */
9#include <linux/types.h>
10#include <linux/socket.h>
11#include <linux/timer.h>
12#include <net/ax25.h>
13#include <linux/skbuff.h>
14#include <net/rose.h>
15#include <linux/init.h>
16
17static struct sk_buff_head loopback_queue;
18static struct timer_list loopback_timer;
19
20static void rose_set_loopback_timer(void);
21
22void rose_loopback_init(void)
23{
24 skb_queue_head_init(&loopback_queue);
25
26 init_timer(&loopback_timer);
27}
28
29static int rose_loopback_running(void)
30{
31 return timer_pending(&loopback_timer);
32}
33
34int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
35{
36 struct sk_buff *skbn;
37
38 skbn = skb_clone(skb, GFP_ATOMIC);
39
40 kfree_skb(skb);
41
42 if (skbn != NULL) {
43 skb_queue_tail(&loopback_queue, skbn);
44
45 if (!rose_loopback_running())
46 rose_set_loopback_timer();
47 }
48
49 return 1;
50}
51
52static void rose_loopback_timer(unsigned long);
53
54static void rose_set_loopback_timer(void)
55{
56 del_timer(&loopback_timer);
57
58 loopback_timer.data = 0;
59 loopback_timer.function = &rose_loopback_timer;
60 loopback_timer.expires = jiffies + 10;
61
62 add_timer(&loopback_timer);
63}
64
65static void rose_loopback_timer(unsigned long param)
66{
67 struct sk_buff *skb;
68 struct net_device *dev;
69 rose_address *dest;
70 struct sock *sk;
71 unsigned short frametype;
72 unsigned int lci_i, lci_o;
73
74 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
75 lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
76 frametype = skb->data[2];
77 dest = (rose_address *)(skb->data + 4);
Bernard Pidoux F6BVP1f731b62009-12-17 05:25:18 +000078 lci_o = ROSE_DEFAULT_MAXVC + 1 - lci_i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -030080 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Alexey Dobriyan891e6a92007-10-07 23:44:17 -070082 sk = rose_find_socket(lci_o, rose_loopback_neigh);
Ralf Baechlea3d38402006-12-14 15:52:13 -080083 if (sk) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (rose_process_rx_frame(sk, skb) == 0)
85 kfree_skb(skb);
86 continue;
87 }
88
89 if (frametype == ROSE_CALL_REQUEST) {
90 if ((dev = rose_dev_get(dest)) != NULL) {
Alexey Dobriyan891e6a92007-10-07 23:44:17 -070091 if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 kfree_skb(skb);
93 } else {
94 kfree_skb(skb);
95 }
96 } else {
97 kfree_skb(skb);
98 }
99 }
100}
101
102void __exit rose_loopback_clear(void)
103{
104 struct sk_buff *skb;
105
106 del_timer(&loopback_timer);
107
108 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
109 skb->sk = NULL;
110 kfree_skb(skb);
111 }
112}