1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 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. 3 * 6 * 4 * Copyright Tomi Manninen OH2BNS (oh2bns@sral 7 * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi) 5 */ 8 */ 6 #include <linux/types.h> 9 #include <linux/types.h> 7 #include <linux/slab.h> 10 #include <linux/slab.h> 8 #include <linux/socket.h> 11 #include <linux/socket.h> 9 #include <linux/timer.h> 12 #include <linux/timer.h> 10 #include <net/ax25.h> 13 #include <net/ax25.h> 11 #include <linux/skbuff.h> 14 #include <linux/skbuff.h> 12 #include <net/netrom.h> 15 #include <net/netrom.h> 13 #include <linux/init.h> 16 #include <linux/init.h> 14 17 15 static void nr_loopback_timer(struct timer_lis !! 18 static void nr_loopback_timer(unsigned long); 16 19 17 static struct sk_buff_head loopback_queue; 20 static struct sk_buff_head loopback_queue; 18 static DEFINE_TIMER(loopback_timer, nr_loopbac !! 21 static DEFINE_TIMER(loopback_timer, nr_loopback_timer, 0, 0); 19 22 20 void __init nr_loopback_init(void) 23 void __init nr_loopback_init(void) 21 { 24 { 22 skb_queue_head_init(&loopback_queue); 25 skb_queue_head_init(&loopback_queue); 23 } 26 } 24 27 25 static inline int nr_loopback_running(void) 28 static inline int nr_loopback_running(void) 26 { 29 { 27 return timer_pending(&loopback_timer); 30 return timer_pending(&loopback_timer); 28 } 31 } 29 32 30 int nr_loopback_queue(struct sk_buff *skb) 33 int nr_loopback_queue(struct sk_buff *skb) 31 { 34 { 32 struct sk_buff *skbn; 35 struct sk_buff *skbn; 33 36 34 if ((skbn = alloc_skb(skb->len, GFP_AT 37 if ((skbn = alloc_skb(skb->len, GFP_ATOMIC)) != NULL) { 35 skb_copy_from_linear_data(skb, 38 skb_copy_from_linear_data(skb, skb_put(skbn, skb->len), skb->len); 36 skb_reset_transport_header(skb 39 skb_reset_transport_header(skbn); 37 40 38 skb_queue_tail(&loopback_queue 41 skb_queue_tail(&loopback_queue, skbn); 39 42 40 if (!nr_loopback_running()) 43 if (!nr_loopback_running()) 41 mod_timer(&loopback_ti 44 mod_timer(&loopback_timer, jiffies + 10); 42 } 45 } 43 46 44 kfree_skb(skb); 47 kfree_skb(skb); 45 return 1; 48 return 1; 46 } 49 } 47 50 48 static void nr_loopback_timer(struct timer_lis !! 51 static void nr_loopback_timer(unsigned long param) 49 { 52 { 50 struct sk_buff *skb; 53 struct sk_buff *skb; 51 ax25_address *nr_dest; 54 ax25_address *nr_dest; 52 struct net_device *dev; 55 struct net_device *dev; 53 56 54 if ((skb = skb_dequeue(&loopback_queue 57 if ((skb = skb_dequeue(&loopback_queue)) != NULL) { 55 nr_dest = (ax25_address *)(skb 58 nr_dest = (ax25_address *)(skb->data + 7); 56 59 57 dev = nr_dev_get(nr_dest); 60 dev = nr_dev_get(nr_dest); 58 61 59 if (dev == NULL || nr_rx_frame 62 if (dev == NULL || nr_rx_frame(skb, dev) == 0) 60 kfree_skb(skb); 63 kfree_skb(skb); 61 64 62 dev_put(dev); !! 65 if (dev != NULL) >> 66 dev_put(dev); 63 67 64 if (!skb_queue_empty(&loopback 68 if (!skb_queue_empty(&loopback_queue) && !nr_loopback_running()) 65 mod_timer(&loopback_ti 69 mod_timer(&loopback_timer, jiffies + 10); 66 } 70 } 67 } 71 } 68 72 69 void nr_loopback_clear(void) !! 73 void __exit nr_loopback_clear(void) 70 { 74 { 71 del_timer_sync(&loopback_timer); 75 del_timer_sync(&loopback_timer); 72 skb_queue_purge(&loopback_queue); 76 skb_queue_purge(&loopback_queue); 73 } 77 } 74 78
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.