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)
9 #include <linux/types.h>
10 #include <linux/slab.h>
11 #include <linux/socket.h>
12 #include <linux/timer.h>
14 #include <linux/skbuff.h>
16 #include <linux/init.h>
18 static struct sk_buff_head loopback_queue
;
19 static struct timer_list loopback_timer
;
21 static void rose_set_loopback_timer(void);
23 void rose_loopback_init(void)
25 skb_queue_head_init(&loopback_queue
);
27 init_timer(&loopback_timer
);
30 static int rose_loopback_running(void)
32 return timer_pending(&loopback_timer
);
35 int rose_loopback_queue(struct sk_buff
*skb
, struct rose_neigh
*neigh
)
39 skbn
= skb_clone(skb
, GFP_ATOMIC
);
44 skb_queue_tail(&loopback_queue
, skbn
);
46 if (!rose_loopback_running())
47 rose_set_loopback_timer();
53 static void rose_loopback_timer(unsigned long);
55 static void rose_set_loopback_timer(void)
57 del_timer(&loopback_timer
);
59 loopback_timer
.data
= 0;
60 loopback_timer
.function
= &rose_loopback_timer
;
61 loopback_timer
.expires
= jiffies
+ 10;
63 add_timer(&loopback_timer
);
66 static void rose_loopback_timer(unsigned long param
)
69 struct net_device
*dev
;
72 unsigned short frametype
;
73 unsigned int lci_i
, lci_o
;
75 while ((skb
= skb_dequeue(&loopback_queue
)) != NULL
) {
76 lci_i
= ((skb
->data
[0] << 8) & 0xF00) + ((skb
->data
[1] << 0) & 0x0FF);
77 frametype
= skb
->data
[2];
78 dest
= (rose_address
*)(skb
->data
+ 4);
79 lci_o
= ROSE_DEFAULT_MAXVC
+ 1 - lci_i
;
81 skb_reset_transport_header(skb
);
83 sk
= rose_find_socket(lci_o
, rose_loopback_neigh
);
85 if (rose_process_rx_frame(sk
, skb
) == 0)
90 if (frametype
== ROSE_CALL_REQUEST
) {
91 if ((dev
= rose_dev_get(dest
)) != NULL
) {
92 if (rose_rx_call_request(skb
, dev
, rose_loopback_neigh
, lci_o
) == 0)
103 void __exit
rose_loopback_clear(void)
107 del_timer(&loopback_timer
);
109 while ((skb
= skb_dequeue(&loopback_queue
)) != NULL
) {