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 #define ROSE_LOOPBACK_LIMIT 1000
20 static struct timer_list loopback_timer;
22 static void rose_set_loopback_timer(void);
23 static void rose_loopback_timer(struct timer_list *unused);
25 void rose_loopback_init(void)
27 skb_queue_head_init(&loopback_queue);
29 timer_setup(&loopback_timer, rose_loopback_timer, 0);
32 static int rose_loopback_running(void)
34 return timer_pending(&loopback_timer);
37 int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
39 struct sk_buff *skbn = NULL;
41 if (skb_queue_len(&loopback_queue) < ROSE_LOOPBACK_LIMIT)
42 skbn = skb_clone(skb, GFP_ATOMIC);
46 skb_queue_tail(&loopback_queue, skbn);
48 if (!rose_loopback_running())
49 rose_set_loopback_timer();
57 static void rose_set_loopback_timer(void)
59 mod_timer(&loopback_timer, jiffies + 10);
62 static void rose_loopback_timer(struct timer_list *unused)
65 struct net_device *dev;
68 unsigned short frametype;
69 unsigned int lci_i, lci_o;
72 for (count = 0; count < ROSE_LOOPBACK_LIMIT; count++) {
73 skb = skb_dequeue(&loopback_queue);
76 if (skb->len < ROSE_MIN_LEN) {
80 lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
81 frametype = skb->data[2];
82 if (frametype == ROSE_CALL_REQUEST &&
83 (skb->len <= ROSE_CALL_REQ_FACILITIES_OFF ||
84 skb->data[ROSE_CALL_REQ_ADDR_LEN_OFF] !=
85 ROSE_CALL_REQ_ADDR_LEN_VAL)) {
89 dest = (rose_address *)(skb->data + ROSE_CALL_REQ_DEST_ADDR_OFF);
90 lci_o = ROSE_DEFAULT_MAXVC + 1 - lci_i;
92 skb_reset_transport_header(skb);
94 sk = rose_find_socket(lci_o, rose_loopback_neigh);
96 if (rose_process_rx_frame(sk, skb) == 0)
101 if (frametype == ROSE_CALL_REQUEST) {
102 if (!rose_loopback_neigh->dev) {
107 dev = rose_dev_get(dest);
113 if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0) {
121 if (!skb_queue_empty(&loopback_queue))
122 mod_timer(&loopback_timer, jiffies + 1);
125 void __exit rose_loopback_clear(void)
129 del_timer(&loopback_timer);
131 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {