Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *
0004  * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
0005  */
0006 #include <linux/types.h>
0007 #include <linux/slab.h>
0008 #include <linux/socket.h>
0009 #include <linux/timer.h>
0010 #include <net/ax25.h>
0011 #include <linux/skbuff.h>
0012 #include <net/netrom.h>
0013 #include <linux/init.h>
0014 
0015 static void nr_loopback_timer(struct timer_list *);
0016 
0017 static struct sk_buff_head loopback_queue;
0018 static DEFINE_TIMER(loopback_timer, nr_loopback_timer);
0019 
0020 void __init nr_loopback_init(void)
0021 {
0022     skb_queue_head_init(&loopback_queue);
0023 }
0024 
0025 static inline int nr_loopback_running(void)
0026 {
0027     return timer_pending(&loopback_timer);
0028 }
0029 
0030 int nr_loopback_queue(struct sk_buff *skb)
0031 {
0032     struct sk_buff *skbn;
0033 
0034     if ((skbn = alloc_skb(skb->len, GFP_ATOMIC)) != NULL) {
0035         skb_copy_from_linear_data(skb, skb_put(skbn, skb->len), skb->len);
0036         skb_reset_transport_header(skbn);
0037 
0038         skb_queue_tail(&loopback_queue, skbn);
0039 
0040         if (!nr_loopback_running())
0041             mod_timer(&loopback_timer, jiffies + 10);
0042     }
0043 
0044     kfree_skb(skb);
0045     return 1;
0046 }
0047 
0048 static void nr_loopback_timer(struct timer_list *unused)
0049 {
0050     struct sk_buff *skb;
0051     ax25_address *nr_dest;
0052     struct net_device *dev;
0053 
0054     if ((skb = skb_dequeue(&loopback_queue)) != NULL) {
0055         nr_dest = (ax25_address *)(skb->data + 7);
0056 
0057         dev = nr_dev_get(nr_dest);
0058 
0059         if (dev == NULL || nr_rx_frame(skb, dev) == 0)
0060             kfree_skb(skb);
0061 
0062         dev_put(dev);
0063 
0064         if (!skb_queue_empty(&loopback_queue) && !nr_loopback_running())
0065             mod_timer(&loopback_timer, jiffies + 10);
0066     }
0067 }
0068 
0069 void nr_loopback_clear(void)
0070 {
0071     del_timer_sync(&loopback_timer);
0072     skb_queue_purge(&loopback_queue);
0073 }