Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / rose / rose_loopback.c
blob103b4d38f88ad679dab8d24ce014f76bad98135d
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.
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>
17 static struct sk_buff_head loopback_queue;
18 static struct timer_list loopback_timer;
20 static void rose_set_loopback_timer(void);
22 void rose_loopback_init(void)
24 skb_queue_head_init(&loopback_queue);
26 init_timer(&loopback_timer);
29 static int rose_loopback_running(void)
31 return timer_pending(&loopback_timer);
34 int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
36 struct sk_buff *skbn;
38 skbn = skb_clone(skb, GFP_ATOMIC);
40 kfree_skb(skb);
42 if (skbn != NULL) {
43 skb_queue_tail(&loopback_queue, skbn);
45 if (!rose_loopback_running())
46 rose_set_loopback_timer();
49 return 1;
52 static void rose_loopback_timer(unsigned long);
54 static void rose_set_loopback_timer(void)
56 del_timer(&loopback_timer);
58 loopback_timer.data = 0;
59 loopback_timer.function = &rose_loopback_timer;
60 loopback_timer.expires = jiffies + 10;
62 add_timer(&loopback_timer);
65 static void rose_loopback_timer(unsigned long param)
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;
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;
80 skb->h.raw = skb->data;
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;
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);
95 } else {
96 kfree_skb(skb);
101 void __exit rose_loopback_clear(void)
103 struct sk_buff *skb;
105 del_timer(&loopback_timer);
107 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
108 skb->sk = NULL;
109 kfree_skb(skb);