aboutsummaryrefslogtreecommitdiffstats
path: root/net/rose/rose_loopback.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/rose/rose_loopback.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/rose/rose_loopback.c')
-rw-r--r--net/rose/rose_loopback.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/net/rose/rose_loopback.c b/net/rose/rose_loopback.c
new file mode 100644
index 000000000000..103b4d38f88a
--- /dev/null
+++ b/net/rose/rose_loopback.c
@@ -0,0 +1,111 @@
1/*
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);
78 lci_o = 0xFFF - lci_i;
79
80 skb->h.raw = skb->data;
81
82 if ((sk = rose_find_socket(lci_o, rose_loopback_neigh)) != NULL) {
83 if (rose_process_rx_frame(sk, skb) == 0)
84 kfree_skb(skb);
85 continue;
86 }
87
88 if (frametype == ROSE_CALL_REQUEST) {
89 if ((dev = rose_dev_get(dest)) != NULL) {
90 if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
91 kfree_skb(skb);
92 } else {
93 kfree_skb(skb);
94 }
95 } else {
96 kfree_skb(skb);
97 }
98 }
99}
100
101void __exit rose_loopback_clear(void)
102{
103 struct sk_buff *skb;
104
105 del_timer(&loopback_timer);
106
107 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
108 skb->sk = NULL;
109 kfree_skb(skb);
110 }
111}