blob: ae4a9d99aec70da821722a4e204ee6eacf1df872 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/socket.h>
12#include <linux/timer.h>
13#include <net/ax25.h>
14#include <linux/skbuff.h>
15#include <net/rose.h>
16#include <linux/init.h>
17
18static struct sk_buff_head loopback_queue;
19static struct timer_list loopback_timer;
20
21static void rose_set_loopback_timer(void);
22
23void rose_loopback_init(void)
24{
25 skb_queue_head_init(&loopback_queue);
26
27 init_timer(&loopback_timer);
28}
29
30static int rose_loopback_running(void)
31{
32 return timer_pending(&loopback_timer);
33}
34
35int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
36{
37 struct sk_buff *skbn;
38
39 skbn = skb_clone(skb, GFP_ATOMIC);
40
41 kfree_skb(skb);
42
43 if (skbn != NULL) {
44 skb_queue_tail(&loopback_queue, skbn);
45
46 if (!rose_loopback_running())
47 rose_set_loopback_timer();
48 }
49
50 return 1;
51}
52
53static void rose_loopback_timer(unsigned long);
54
55static void rose_set_loopback_timer(void)
56{
57 del_timer(&loopback_timer);
58
59 loopback_timer.data = 0;
60 loopback_timer.function = &rose_loopback_timer;
61 loopback_timer.expires = jiffies + 10;
62
63 add_timer(&loopback_timer);
64}
65
66static void rose_loopback_timer(unsigned long param)
67{
68 struct sk_buff *skb;
69 struct net_device *dev;
70 rose_address *dest;
71 struct sock *sk;
72 unsigned short frametype;
73 unsigned int lci_i, lci_o;
74
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);
Bernard Pidoux F6BVP1f731b62009-12-17 05:25:18 +000079 lci_o = ROSE_DEFAULT_MAXVC + 1 - lci_i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -030081 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Alexey Dobriyan891e6a92007-10-07 23:44:17 -070083 sk = rose_find_socket(lci_o, rose_loopback_neigh);
Ralf Baechlea3d38402006-12-14 15:52:13 -080084 if (sk) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (rose_process_rx_frame(sk, skb) == 0)
86 kfree_skb(skb);
87 continue;
88 }
89
90 if (frametype == ROSE_CALL_REQUEST) {
91 if ((dev = rose_dev_get(dest)) != NULL) {
Alexey Dobriyan891e6a92007-10-07 23:44:17 -070092 if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 kfree_skb(skb);
94 } else {
95 kfree_skb(skb);
96 }
97 } else {
98 kfree_skb(skb);
99 }
100 }
101}
102
103void __exit rose_loopback_clear(void)
104{
105 struct sk_buff *skb;
106
107 del_timer(&loopback_timer);
108
109 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
110 skb->sk = NULL;
111 kfree_skb(skb);
112 }
113}