]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 ([email protected]) | |
8 | */ | |
9 | #include <linux/types.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
1da177e4 LT |
11 | #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 | ||
18 | static struct sk_buff_head loopback_queue; | |
19 | static struct timer_list loopback_timer; | |
20 | ||
21 | static void rose_set_loopback_timer(void); | |
4966babd | 22 | static void rose_loopback_timer(struct timer_list *unused); |
1da177e4 LT |
23 | |
24 | void rose_loopback_init(void) | |
25 | { | |
26 | skb_queue_head_init(&loopback_queue); | |
27 | ||
4966babd | 28 | timer_setup(&loopback_timer, rose_loopback_timer, 0); |
1da177e4 LT |
29 | } |
30 | ||
31 | static int rose_loopback_running(void) | |
32 | { | |
33 | return timer_pending(&loopback_timer); | |
34 | } | |
35 | ||
36 | int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh) | |
37 | { | |
38 | struct sk_buff *skbn; | |
39 | ||
40 | skbn = skb_clone(skb, GFP_ATOMIC); | |
41 | ||
42 | kfree_skb(skb); | |
43 | ||
44 | if (skbn != NULL) { | |
45 | skb_queue_tail(&loopback_queue, skbn); | |
46 | ||
47 | if (!rose_loopback_running()) | |
48 | rose_set_loopback_timer(); | |
49 | } | |
50 | ||
51 | return 1; | |
52 | } | |
53 | ||
1da177e4 LT |
54 | |
55 | static void rose_set_loopback_timer(void) | |
56 | { | |
57 | del_timer(&loopback_timer); | |
58 | ||
1da177e4 | 59 | loopback_timer.expires = jiffies + 10; |
1da177e4 LT |
60 | add_timer(&loopback_timer); |
61 | } | |
62 | ||
4966babd | 63 | static void rose_loopback_timer(struct timer_list *unused) |
1da177e4 LT |
64 | { |
65 | struct sk_buff *skb; | |
66 | struct net_device *dev; | |
67 | rose_address *dest; | |
68 | struct sock *sk; | |
69 | unsigned short frametype; | |
70 | unsigned int lci_i, lci_o; | |
71 | ||
72 | while ((skb = skb_dequeue(&loopback_queue)) != NULL) { | |
e0bccd31 BH |
73 | if (skb->len < ROSE_MIN_LEN) { |
74 | kfree_skb(skb); | |
75 | continue; | |
76 | } | |
1da177e4 LT |
77 | lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF); |
78 | frametype = skb->data[2]; | |
e0bccd31 BH |
79 | if (frametype == ROSE_CALL_REQUEST && |
80 | (skb->len <= ROSE_CALL_REQ_FACILITIES_OFF || | |
81 | skb->data[ROSE_CALL_REQ_ADDR_LEN_OFF] != | |
82 | ROSE_CALL_REQ_ADDR_LEN_VAL)) { | |
83 | kfree_skb(skb); | |
84 | continue; | |
85 | } | |
86 | dest = (rose_address *)(skb->data + ROSE_CALL_REQ_DEST_ADDR_OFF); | |
1f731b63 | 87 | lci_o = ROSE_DEFAULT_MAXVC + 1 - lci_i; |
1da177e4 | 88 | |
badff6d0 | 89 | skb_reset_transport_header(skb); |
1da177e4 | 90 | |
891e6a93 | 91 | sk = rose_find_socket(lci_o, rose_loopback_neigh); |
a3d38402 | 92 | if (sk) { |
1da177e4 LT |
93 | if (rose_process_rx_frame(sk, skb) == 0) |
94 | kfree_skb(skb); | |
95 | continue; | |
96 | } | |
97 | ||
98 | if (frametype == ROSE_CALL_REQUEST) { | |
99 | if ((dev = rose_dev_get(dest)) != NULL) { | |
891e6a93 | 100 | if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0) |
1da177e4 LT |
101 | kfree_skb(skb); |
102 | } else { | |
103 | kfree_skb(skb); | |
104 | } | |
105 | } else { | |
106 | kfree_skb(skb); | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 | void __exit rose_loopback_clear(void) | |
112 | { | |
113 | struct sk_buff *skb; | |
114 | ||
115 | del_timer(&loopback_timer); | |
116 | ||
117 | while ((skb = skb_dequeue(&loopback_queue)) != NULL) { | |
118 | skb->sk = NULL; | |
119 | kfree_skb(skb); | |
120 | } | |
121 | } |