11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 31da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 41da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 51da177e4SLinus Torvalds * (at your option) any later version. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds #include <linux/types.h> 101da177e4SLinus Torvalds #include <linux/socket.h> 111da177e4SLinus Torvalds #include <linux/timer.h> 121da177e4SLinus Torvalds #include <net/ax25.h> 131da177e4SLinus Torvalds #include <linux/skbuff.h> 141da177e4SLinus Torvalds #include <net/rose.h> 151da177e4SLinus Torvalds #include <linux/init.h> 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds static struct sk_buff_head loopback_queue; 181da177e4SLinus Torvalds static struct timer_list loopback_timer; 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds static void rose_set_loopback_timer(void); 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds void rose_loopback_init(void) 231da177e4SLinus Torvalds { 241da177e4SLinus Torvalds skb_queue_head_init(&loopback_queue); 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds init_timer(&loopback_timer); 271da177e4SLinus Torvalds } 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds static int rose_loopback_running(void) 301da177e4SLinus Torvalds { 311da177e4SLinus Torvalds return timer_pending(&loopback_timer); 321da177e4SLinus Torvalds } 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh) 351da177e4SLinus Torvalds { 361da177e4SLinus Torvalds struct sk_buff *skbn; 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds skbn = skb_clone(skb, GFP_ATOMIC); 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds kfree_skb(skb); 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds if (skbn != NULL) { 431da177e4SLinus Torvalds skb_queue_tail(&loopback_queue, skbn); 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds if (!rose_loopback_running()) 461da177e4SLinus Torvalds rose_set_loopback_timer(); 471da177e4SLinus Torvalds } 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds return 1; 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds static void rose_loopback_timer(unsigned long); 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static void rose_set_loopback_timer(void) 551da177e4SLinus Torvalds { 561da177e4SLinus Torvalds del_timer(&loopback_timer); 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds loopback_timer.data = 0; 591da177e4SLinus Torvalds loopback_timer.function = &rose_loopback_timer; 601da177e4SLinus Torvalds loopback_timer.expires = jiffies + 10; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds add_timer(&loopback_timer); 631da177e4SLinus Torvalds } 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds static void rose_loopback_timer(unsigned long param) 661da177e4SLinus Torvalds { 671da177e4SLinus Torvalds struct sk_buff *skb; 681da177e4SLinus Torvalds struct net_device *dev; 691da177e4SLinus Torvalds rose_address *dest; 701da177e4SLinus Torvalds struct sock *sk; 711da177e4SLinus Torvalds unsigned short frametype; 721da177e4SLinus Torvalds unsigned int lci_i, lci_o; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds while ((skb = skb_dequeue(&loopback_queue)) != NULL) { 751da177e4SLinus Torvalds lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF); 761da177e4SLinus Torvalds frametype = skb->data[2]; 771da177e4SLinus Torvalds dest = (rose_address *)(skb->data + 4); 781da177e4SLinus Torvalds lci_o = 0xFFF - lci_i; 791da177e4SLinus Torvalds 80*badff6d0SArnaldo Carvalho de Melo skb_reset_transport_header(skb); 811da177e4SLinus Torvalds 82a3d38402SRalf Baechle sk = rose_find_socket(lci_o, &rose_loopback_neigh); 83a3d38402SRalf Baechle if (sk) { 841da177e4SLinus Torvalds if (rose_process_rx_frame(sk, skb) == 0) 851da177e4SLinus Torvalds kfree_skb(skb); 861da177e4SLinus Torvalds continue; 871da177e4SLinus Torvalds } 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds if (frametype == ROSE_CALL_REQUEST) { 901da177e4SLinus Torvalds if ((dev = rose_dev_get(dest)) != NULL) { 91a3d38402SRalf Baechle if (rose_rx_call_request(skb, dev, &rose_loopback_neigh, lci_o) == 0) 921da177e4SLinus Torvalds kfree_skb(skb); 931da177e4SLinus Torvalds } else { 941da177e4SLinus Torvalds kfree_skb(skb); 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds } else { 971da177e4SLinus Torvalds kfree_skb(skb); 981da177e4SLinus Torvalds } 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds void __exit rose_loopback_clear(void) 1031da177e4SLinus Torvalds { 1041da177e4SLinus Torvalds struct sk_buff *skb; 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds del_timer(&loopback_timer); 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds while ((skb = skb_dequeue(&loopback_queue)) != NULL) { 1091da177e4SLinus Torvalds skb->sk = NULL; 1101da177e4SLinus Torvalds kfree_skb(skb); 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds } 113