- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / net / netrom / nr_loopback.c
blobfc0665de289ffbe2905bec8d026ee9d849a87411
1 /*
2 * NET/ROM release 007
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 * NET/ROM 007 Tomi(OH2BNS) Created this file.
14 * Small change in nr_loopback_queue().
18 #include <linux/config.h>
19 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
20 #include <linux/types.h>
21 #include <linux/socket.h>
22 #include <linux/timer.h>
23 #include <net/ax25.h>
24 #include <linux/skbuff.h>
25 #include <net/netrom.h>
27 static struct sk_buff_head loopback_queue;
28 static struct timer_list loopback_timer;
30 static void nr_set_loopback_timer(void);
32 void nr_loopback_init(void)
34 skb_queue_head_init(&loopback_queue);
36 init_timer(&loopback_timer);
39 static int nr_loopback_running(void)
41 return timer_pending(&loopback_timer);
44 int nr_loopback_queue(struct sk_buff *skb)
46 struct sk_buff *skbn;
48 if ((skbn = alloc_skb(skb->len, GFP_ATOMIC)) != NULL) {
49 memcpy(skb_put(skbn, skb->len), skb->data, skb->len);
50 skbn->h.raw = skbn->data;
52 skb_queue_tail(&loopback_queue, skbn);
54 if (!nr_loopback_running())
55 nr_set_loopback_timer();
58 kfree_skb(skb);
59 return 1;
62 static void nr_loopback_timer(unsigned long);
64 static void nr_set_loopback_timer(void)
66 del_timer(&loopback_timer);
68 loopback_timer.data = 0;
69 loopback_timer.function = &nr_loopback_timer;
70 loopback_timer.expires = jiffies + 10;
72 add_timer(&loopback_timer);
75 static void nr_loopback_timer(unsigned long param)
77 struct sk_buff *skb;
78 ax25_address *nr_dest;
79 struct net_device *dev;
81 if ((skb = skb_dequeue(&loopback_queue)) != NULL) {
82 nr_dest = (ax25_address *)(skb->data + 7);
84 dev = nr_dev_get(nr_dest);
86 if (dev == NULL || nr_rx_frame(skb, dev) == 0)
87 kfree_skb(skb);
89 if (!skb_queue_empty(&loopback_queue) && !nr_loopback_running())
90 nr_set_loopback_timer();
94 #ifdef MODULE
96 void nr_loopback_clear(void)
98 struct sk_buff *skb;
100 del_timer(&loopback_timer);
102 while ((skb = skb_dequeue(&loopback_queue)) != NULL)
103 kfree_skb(skb);
106 #endif
108 #endif