1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
6 #include <linux/types.h>
7 #include <linux/slab.h>
8 #include <linux/socket.h>
9 #include <linux/timer.h>
11 #include <linux/skbuff.h>
12 #include <net/netrom.h>
13 #include <linux/init.h>
15 static void nr_loopback_timer(struct timer_list
*);
17 static struct sk_buff_head loopback_queue
;
18 static DEFINE_TIMER(loopback_timer
, nr_loopback_timer
);
20 void __init
nr_loopback_init(void)
22 skb_queue_head_init(&loopback_queue
);
25 static inline int nr_loopback_running(void)
27 return timer_pending(&loopback_timer
);
30 int nr_loopback_queue(struct sk_buff
*skb
)
34 if ((skbn
= alloc_skb(skb
->len
, GFP_ATOMIC
)) != NULL
) {
35 skb_copy_from_linear_data(skb
, skb_put(skbn
, skb
->len
), skb
->len
);
36 skb_reset_transport_header(skbn
);
38 skb_queue_tail(&loopback_queue
, skbn
);
40 if (!nr_loopback_running())
41 mod_timer(&loopback_timer
, jiffies
+ 10);
48 static void nr_loopback_timer(struct timer_list
*unused
)
51 ax25_address
*nr_dest
;
52 struct net_device
*dev
;
54 if ((skb
= skb_dequeue(&loopback_queue
)) != NULL
) {
55 nr_dest
= (ax25_address
*)(skb
->data
+ 7);
57 dev
= nr_dev_get(nr_dest
);
59 if (dev
== NULL
|| nr_rx_frame(skb
, dev
) == 0)
65 if (!skb_queue_empty(&loopback_queue
) && !nr_loopback_running())
66 mod_timer(&loopback_timer
, jiffies
+ 10);
70 void nr_loopback_clear(void)
72 del_timer_sync(&loopback_timer
);
73 skb_queue_purge(&loopback_queue
);