4 * This is ALPHA test software. This code may break your machine, randomly fail to work with new 5 * releases, misbehave and/or generally screw up. It might even work. 7 * This code REQUIRES 2.1.15 or higher/ NET3.038 10 * This module is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 13 * 2 of the License, or (at your option) any later version. 16 * NET/ROM 001 Jonathan(G4KLX) Cloned from the AX25 code. 17 * NET/ROM 002 Darryl(G7LED) Fixes and address enhancement. 18 * Jonathan(G4KLX) Complete bind re-think. 19 * Alan(GW4PTS) Trivial tweaks into new format. 20 * NET/ROM 003 Jonathan(G4KLX) Added G8BPQ extensions. 21 * Added NET/ROM routing ioctl. 22 * Darryl(G7LED) Fix autobinding (on connect). 23 * Fixed nr_release(), set TCP_CLOSE, wakeup app 24 * context, THEN make the sock dead. 25 * Circuit ID check before allocating it on 27 * Alan(GW4PTS) sendmsg/recvmsg only. Fixed connect clear bug 28 * inherited from AX.25 29 * NET/ROM 004 Jonathan(G4KLX) Converted to module. 30 * NET/ROM 005 Jonathan(G4KLX) Linux 2.1 31 * Alan(GW4PTS) Started POSIXisms 32 * NET/ROM 006 Alan(GW4PTS) Brought in line with the ANK changes 35 #include <linux/config.h> 36 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) 37 #include <linux/module.h> 38 #include <linux/errno.h> 39 #include <linux/types.h> 40 #include <linux/socket.h> 42 #include <linux/kernel.h> 43 #include <linux/sched.h> 44 #include <linux/timer.h> 45 #include <linux/string.h> 46 #include <linux/sockios.h> 47 #include <linux/net.h> 48 #include <linux/stat.h> 50 #include <linux/inet.h> 51 #include <linux/netdevice.h> 52 #include <linux/if_arp.h> 53 #include <linux/skbuff.h> 55 #include <asm/uaccess.h> 56 #include <asm/system.h> 57 #include <linux/fcntl.h> 58 #include <linux/termios.h>/* For TIOCINQ/OUTQ */ 60 #include <linux/interrupt.h> 61 #include <linux/notifier.h> 62 #include <net/netrom.h> 63 #include <linux/proc_fs.h> 66 #include <linux/if_arp.h> 68 int sysctl_netrom_default_path_quality
= NR_DEFAULT_QUAL
; 69 int sysctl_netrom_obsolescence_count_initialiser
= NR_DEFAULT_OBS
; 70 int sysctl_netrom_network_ttl_initialiser
= NR_DEFAULT_TTL
; 71 int sysctl_netrom_transport_timeout
= NR_DEFAULT_T1
; 72 int sysctl_netrom_transport_maximum_tries
= NR_DEFAULT_N2
; 73 int sysctl_netrom_transport_acknowledge_delay
= NR_DEFAULT_T2
; 74 int sysctl_netrom_transport_busy_delay
= NR_DEFAULT_T4
; 75 int sysctl_netrom_transport_requested_window_size
= NR_DEFAULT_WINDOW
; 76 int sysctl_netrom_transport_no_activity_timeout
= NR_DEFAULT_IDLE
; 77 int sysctl_netrom_routing_control
= NR_DEFAULT_ROUTING
; 78 int sysctl_netrom_link_fails_count
= NR_DEFAULT_FAILS
; 80 static unsigned short circuit
=0x101; 82 static struct sock
*volatile nr_list
= NULL
; 84 static struct proto_ops nr_proto_ops
; 86 static voidnr_free_sock(struct sock
*sk
) 88 kfree_s(sk
->protinfo
.nr
,sizeof(*sk
->protinfo
.nr
)); 95 static struct sock
*nr_alloc_sock(void) 100 if((sk
=sk_alloc(GFP_ATOMIC
)) == NULL
) 103 if((nr
= (nr_cb
*)kmalloc(sizeof(*nr
), GFP_ATOMIC
)) == NULL
) { 110 memset(nr
,0x00,sizeof(*nr
)); 112 sk
->protinfo
.nr
= nr
; 119 * Socket removal during an interrupt is now safe. 121 static voidnr_remove_socket(struct sock
*sk
) 129 if((s
= nr_list
) == sk
) { 131 restore_flags(flags
); 135 while(s
!= NULL
&& s
->next
!= NULL
) { 138 restore_flags(flags
); 145 restore_flags(flags
); 149 * Kill all bound sockets on a dropped device. 151 static voidnr_kill_by_device(struct device
*dev
) 155 for(s
= nr_list
; s
!= NULL
; s
= s
->next
) { 156 if(s
->protinfo
.nr
->device
== dev
) { 157 s
->protinfo
.nr
->state
= NR_STATE_0
; 158 s
->protinfo
.nr
->device
= NULL
; 159 s
->state
= TCP_CLOSE
; 160 s
->err
= ENETUNREACH
; 161 s
->shutdown
|= SEND_SHUTDOWN
; 169 * Handle device status changes. 171 static intnr_device_event(struct notifier_block
*this,unsigned long event
,void*ptr
) 173 struct device
*dev
= (struct device
*)ptr
; 175 if(event
!= NETDEV_DOWN
) 178 nr_kill_by_device(dev
); 179 nr_rt_device_down(dev
); 185 * Add a socket to the bound sockets list. 187 static voidnr_insert_socket(struct sock
*sk
) 197 restore_flags(flags
); 201 * Find a socket that wants to accept the Connect Request we just 204 static struct sock
*nr_find_listener(ax25_address
*addr
) 212 for(s
= nr_list
; s
!= NULL
; s
= s
->next
) { 213 if(ax25cmp(&s
->protinfo
.nr
->source_addr
, addr
) ==0&& s
->state
== TCP_LISTEN
) { 214 restore_flags(flags
); 219 restore_flags(flags
); 224 * Find a connected NET/ROM socket given my circuit IDs. 226 static struct sock
*nr_find_socket(unsigned char index
,unsigned char id
) 234 for(s
= nr_list
; s
!= NULL
; s
= s
->next
) { 235 if(s
->protinfo
.nr
->my_index
== index
&& s
->protinfo
.nr
->my_id
== id
) { 236 restore_flags(flags
); 241 restore_flags(flags
); 247 * Find a connected NET/ROM socket given their circuit IDs. 249 static struct sock
*nr_find_peer(unsigned char index
,unsigned char id
) 257 for(s
= nr_list
; s
!= NULL
; s
= s
->next
) { 258 if(s
->protinfo
.nr
->your_index
== index
&& s
->protinfo
.nr
->your_id
== id
) { 259 restore_flags(flags
); 264 restore_flags(flags
); 272 voidnr_destroy_socket(struct sock
*); 275 * Handler for deferred kills. 277 static voidnr_destroy_timer(unsigned long data
) 279 nr_destroy_socket((struct sock
*)data
); 283 * This is called from user mode and the timers. Thus it protects itself against 284 * interrupt users but doesn't worry about being called during work. 285 * Once it is removed from the queue no interrupt or bottom half will 286 * touch it and we are (fairly 8-) ) safe. 288 voidnr_destroy_socket(struct sock
*sk
)/* Not static as it's used by the timer */ 296 del_timer(&sk
->timer
); 298 nr_remove_socket(sk
); 299 nr_clear_queues(sk
);/* Flush the queues */ 301 while((skb
=skb_dequeue(&sk
->receive_queue
)) != NULL
) { 302 if(skb
->sk
!= sk
) {/* A pending connection */ 303 skb
->sk
->dead
=1;/* Queue the unaccepted socket for death */ 304 nr_set_timer(skb
->sk
); 305 skb
->sk
->protinfo
.nr
->state
= NR_STATE_0
; 308 kfree_skb(skb
, FREE_READ
); 311 if(atomic_read(&sk
->wmem_alloc
) !=0||atomic_read(&sk
->rmem_alloc
) !=0) { 312 /* Defer: outstanding buffers */ 313 init_timer(&sk
->timer
); 314 sk
->timer
.expires
= jiffies
+10* HZ
; 315 sk
->timer
.function
= nr_destroy_timer
; 316 sk
->timer
.data
= (unsigned long)sk
; 317 add_timer(&sk
->timer
); 322 restore_flags(flags
); 326 * Handling for system calls applied via the various interfaces to a 327 * NET/ROM socket object. 331 * dl1bke 960311: set parameters for existing NET/ROM connections, 332 * includes a KILL command to abort any connection. 333 * VERY useful for debugging ;-) 335 static intnr_ctl_ioctl(const unsigned int cmd
,void*arg
) 337 struct nr_ctl_struct nr_ctl
; 342 if((err
=verify_area(VERIFY_READ
, arg
,sizeof(nr_ctl
))) !=0) 345 copy_from_user(&nr_ctl
, arg
,sizeof(nr_ctl
)); 347 if((sk
=nr_find_socket(nr_ctl
.index
, nr_ctl
.id
)) == NULL
) 353 nr_write_internal(sk
, NR_DISCREQ
); 354 sk
->protinfo
.nr
->state
= NR_STATE_0
; 355 sk
->state
= TCP_CLOSE
; 357 sk
->shutdown
|= SEND_SHUTDOWN
; 359 sk
->state_change(sk
); 367 sk
->protinfo
.nr
->t1
= nr_ctl
.arg
* NR_SLOWHZ
; 368 save_flags(flags
);cli(); 369 if(sk
->protinfo
.nr
->t1timer
> sk
->protinfo
.nr
->t1
) 370 sk
->protinfo
.nr
->t1timer
= sk
->protinfo
.nr
->t1
; 371 restore_flags(flags
); 377 save_flags(flags
);cli(); 378 sk
->protinfo
.nr
->t2
= nr_ctl
.arg
* NR_SLOWHZ
; 379 if(sk
->protinfo
.nr
->t2timer
> sk
->protinfo
.nr
->t2
) 380 sk
->protinfo
.nr
->t2timer
= sk
->protinfo
.nr
->t2
; 381 restore_flags(flags
); 385 if(nr_ctl
.arg
<1|| nr_ctl
.arg
>10) 387 sk
->protinfo
.nr
->n2count
=0; 388 sk
->protinfo
.nr
->n2
= nr_ctl
.arg
; 394 save_flags(flags
);cli(); 395 sk
->protinfo
.nr
->t4
= nr_ctl
.arg
* NR_SLOWHZ
; 396 if(sk
->protinfo
.nr
->t4timer
> sk
->protinfo
.nr
->t4
) 397 sk
->protinfo
.nr
->t4timer
= sk
->protinfo
.nr
->t4
; 398 restore_flags(flags
); 404 save_flags(flags
);cli(); 405 sk
->protinfo
.nr
->idle
= nr_ctl
.arg
*60* NR_SLOWHZ
; 406 if(sk
->protinfo
.nr
->idletimer
> sk
->protinfo
.nr
->idle
) 407 sk
->protinfo
.nr
->idletimer
= sk
->protinfo
.nr
->idle
; 408 restore_flags(flags
); 418 static intnr_setsockopt(struct socket
*sock
,int level
,int optname
, 419 char*optval
,int optlen
) 421 struct sock
*sk
= sock
->sk
; 424 if(level
!= SOL_NETROM
) 427 if(optlen
<sizeof(int)) 430 if(get_user(opt
, (int*)optval
)) 437 sk
->protinfo
.nr
->t1
= opt
* NR_SLOWHZ
; 443 sk
->protinfo
.nr
->t2
= opt
* NR_SLOWHZ
; 449 sk
->protinfo
.nr
->n2
= opt
; 455 sk
->protinfo
.nr
->t4
= opt
* NR_SLOWHZ
; 461 sk
->protinfo
.nr
->idle
= opt
*60* NR_SLOWHZ
; 465 sk
->protinfo
.nr
->hdrincl
= opt
?1:0; 473 static intnr_getsockopt(struct socket
*sock
,int level
,int optname
, 474 char*optval
,int*optlen
) 476 struct sock
*sk
= sock
->sk
; 480 if(level
!= SOL_NETROM
) 483 if(get_user(len
, optlen
)) 488 val
= (sk
->protinfo
.nr
->t1
*2) / NR_SLOWHZ
; 492 val
= sk
->protinfo
.nr
->t2
/ NR_SLOWHZ
; 496 val
= sk
->protinfo
.nr
->n2
; 500 val
= sk
->protinfo
.nr
->t4
/ NR_SLOWHZ
; 504 val
= sk
->protinfo
.nr
->idle
/ (NR_SLOWHZ
*60); 508 val
= sk
->protinfo
.nr
->hdrincl
; 515 len
=min(len
,sizeof(int)); 517 if(put_user(len
, optlen
)) 520 if(copy_to_user(optval
, &val
, len
)) 526 static intnr_listen(struct socket
*sock
,int backlog
) 528 struct sock
*sk
= sock
->sk
; 530 if(sk
->state
!= TCP_LISTEN
) { 531 memset(&sk
->protinfo
.nr
->user_addr
,'\0', AX25_ADDR_LEN
); 532 sk
->max_ack_backlog
= backlog
; 533 sk
->state
= TCP_LISTEN
; 540 static intnr_create(struct socket
*sock
,int protocol
) 545 if(sock
->type
!= SOCK_SEQPACKET
|| protocol
!=0) 546 return-ESOCKTNOSUPPORT
; 548 if((sk
=nr_alloc_sock()) == NULL
) 551 nr
= sk
->protinfo
.nr
; 553 sock_init_data(sock
, sk
); 555 sock
->ops
= &nr_proto_ops
; 556 sk
->protocol
= protocol
; 557 sk
->mtu
= NETROM_MTU
;/* 236 */ 559 skb_queue_head_init(&nr
->ack_queue
); 560 skb_queue_head_init(&nr
->reseq_queue
); 561 skb_queue_head_init(&nr
->frag_queue
); 563 nr
->t1
= sysctl_netrom_transport_timeout
; 564 nr
->t2
= sysctl_netrom_transport_acknowledge_delay
; 565 nr
->n2
= sysctl_netrom_transport_maximum_tries
; 566 nr
->t4
= sysctl_netrom_transport_busy_delay
; 567 nr
->idle
= sysctl_netrom_transport_no_activity_timeout
; 568 nr
->window
= sysctl_netrom_transport_requested_window_size
; 571 nr
->state
= NR_STATE_0
; 576 static struct sock
*nr_make_new(struct sock
*osk
) 581 if(osk
->type
!= SOCK_SEQPACKET
) 584 if((sk
=nr_alloc_sock()) == NULL
) 587 nr
= sk
->protinfo
.nr
; 589 sock_init_data(NULL
, sk
); 591 sk
->type
= osk
->type
; 592 sk
->socket
= osk
->socket
; 593 sk
->priority
= osk
->priority
; 594 sk
->protocol
= osk
->protocol
; 595 sk
->rcvbuf
= osk
->rcvbuf
; 596 sk
->sndbuf
= osk
->sndbuf
; 597 sk
->debug
= osk
->debug
; 598 sk
->state
= TCP_ESTABLISHED
; 600 sk
->sleep
= osk
->sleep
; 601 sk
->zapped
= osk
->zapped
; 603 skb_queue_head_init(&nr
->ack_queue
); 604 skb_queue_head_init(&nr
->reseq_queue
); 605 skb_queue_head_init(&nr
->frag_queue
); 607 nr
->t1
= osk
->protinfo
.nr
->t1
; 608 nr
->t2
= osk
->protinfo
.nr
->t2
; 609 nr
->n2
= osk
->protinfo
.nr
->n2
; 610 nr
->t4
= osk
->protinfo
.nr
->t4
; 611 nr
->idle
= osk
->protinfo
.nr
->idle
; 612 nr
->window
= osk
->protinfo
.nr
->window
; 614 nr
->device
= osk
->protinfo
.nr
->device
; 615 nr
->bpqext
= osk
->protinfo
.nr
->bpqext
; 616 nr
->hdrincl
= osk
->protinfo
.nr
->hdrincl
; 621 static intnr_dup(struct socket
*newsock
,struct socket
*oldsock
) 623 struct sock
*sk
= oldsock
->sk
; 625 if(sk
== NULL
|| newsock
== NULL
) 628 returnnr_create(newsock
, sk
->protocol
); 631 static intnr_release(struct socket
*sock
,struct socket
*peer
) 633 struct sock
*sk
= sock
->sk
; 635 if(sk
== NULL
)return0; 637 switch(sk
->protinfo
.nr
->state
) { 640 sk
->state
= TCP_CLOSE
; 641 sk
->shutdown
|= SEND_SHUTDOWN
; 642 sk
->state_change(sk
); 644 nr_destroy_socket(sk
); 648 sk
->protinfo
.nr
->state
= NR_STATE_0
; 649 sk
->state
= TCP_CLOSE
; 650 sk
->shutdown
|= SEND_SHUTDOWN
; 651 sk
->state_change(sk
); 653 nr_destroy_socket(sk
); 657 nr_write_internal(sk
, NR_DISCACK
); 658 sk
->protinfo
.nr
->state
= NR_STATE_0
; 659 sk
->state
= TCP_CLOSE
; 660 sk
->shutdown
|= SEND_SHUTDOWN
; 661 sk
->state_change(sk
); 663 nr_destroy_socket(sk
); 668 sk
->protinfo
.nr
->n2count
=0; 669 nr_write_internal(sk
, NR_DISCREQ
); 670 sk
->protinfo
.nr
->t1timer
= sk
->protinfo
.nr
->t1
; 671 sk
->protinfo
.nr
->t2timer
=0; 672 sk
->protinfo
.nr
->t4timer
=0; 673 sk
->protinfo
.nr
->state
= NR_STATE_2
; 674 sk
->state
= TCP_CLOSE
; 675 sk
->shutdown
|= SEND_SHUTDOWN
; 676 sk
->state_change(sk
); 686 sk
->socket
= NULL
;/* Not used, but we should do this */ 691 static intnr_bind(struct socket
*sock
,struct sockaddr
*uaddr
,int addr_len
) 693 struct sock
*sk
= sock
->sk
; 694 struct full_sockaddr_ax25
*addr
= (struct full_sockaddr_ax25
*)uaddr
; 696 ax25_address
*user
, *source
; 701 if(addr_len
!=sizeof(struct sockaddr_ax25
) && addr_len
!=sizeof(struct full_sockaddr_ax25
)) 704 if(addr
->fsa_ax25
.sax25_family
!= AF_NETROM
) 707 if((dev
=nr_dev_get(&addr
->fsa_ax25
.sax25_call
)) == NULL
) { 708 SOCK_DEBUG(sk
,"NET/ROM: bind failed: invalid node callsign\n"); 709 return-EADDRNOTAVAIL
; 713 * Only the super user can set an arbitrary user callsign. 715 if(addr
->fsa_ax25
.sax25_ndigis
==1) { 718 sk
->protinfo
.nr
->user_addr
= addr
->fsa_digipeater
[0]; 719 sk
->protinfo
.nr
->source_addr
= addr
->fsa_ax25
.sax25_call
; 721 source
= &addr
->fsa_ax25
.sax25_call
; 723 if((user
=ax25_findbyuid(current
->euid
)) == NULL
) { 724 if(ax25_uid_policy
&& !suser()) 729 sk
->protinfo
.nr
->user_addr
= *user
; 730 sk
->protinfo
.nr
->source_addr
= *source
; 733 sk
->protinfo
.nr
->device
= dev
; 734 nr_insert_socket(sk
); 737 SOCK_DEBUG(sk
,"NET/ROM: socket is bound\n"); 741 static intnr_connect(struct socket
*sock
,struct sockaddr
*uaddr
, 742 int addr_len
,int flags
) 744 struct sock
*sk
= sock
->sk
; 745 struct sockaddr_ax25
*addr
= (struct sockaddr_ax25
*)uaddr
; 746 ax25_address
*user
, *source
= NULL
; 749 if(sk
->state
== TCP_ESTABLISHED
&& sock
->state
== SS_CONNECTING
) { 750 sock
->state
= SS_CONNECTED
; 751 return0;/* Connect completed during a ERESTARTSYS event */ 754 if(sk
->state
== TCP_CLOSE
&& sock
->state
== SS_CONNECTING
) { 755 sock
->state
= SS_UNCONNECTED
; 759 if(sk
->state
== TCP_ESTABLISHED
) 760 return-EISCONN
;/* No reconnect on a seqpacket socket */ 762 sk
->state
= TCP_CLOSE
; 763 sock
->state
= SS_UNCONNECTED
; 765 if(addr_len
!=sizeof(struct sockaddr_ax25
) && addr_len
!=sizeof(struct full_sockaddr_ax25
)) 768 if(addr
->sax25_family
!= AF_NETROM
) 771 if(sk
->zapped
) {/* Must bind first - autobinding in this may or may not work */ 774 if((dev
=nr_dev_first()) == NULL
) 777 source
= (ax25_address
*)dev
->dev_addr
; 779 if((user
=ax25_findbyuid(current
->euid
)) == NULL
) { 780 if(ax25_uid_policy
&& !suser()) 785 sk
->protinfo
.nr
->user_addr
= *user
; 786 sk
->protinfo
.nr
->source_addr
= *source
; 787 sk
->protinfo
.nr
->device
= dev
; 789 nr_insert_socket(sk
);/* Finish the bind */ 792 sk
->protinfo
.nr
->dest_addr
= addr
->sax25_call
; 794 while(nr_find_socket((unsigned char)circuit
/256, (unsigned char)circuit
%256) != NULL
) 797 sk
->protinfo
.nr
->my_index
= circuit
/256; 798 sk
->protinfo
.nr
->my_id
= circuit
%256; 802 /* Move to connecting socket, start sending Connect Requests */ 803 sock
->state
= SS_CONNECTING
; 804 sk
->state
= TCP_SYN_SENT
; 805 nr_establish_data_link(sk
); 806 sk
->protinfo
.nr
->state
= NR_STATE_1
; 810 if(sk
->state
!= TCP_ESTABLISHED
&& (flags
& O_NONBLOCK
)) 813 cli();/* To avoid races on the sleep */ 816 * A Connect Ack with Choke or timeout or failed routing will go to closed. 818 while(sk
->state
== TCP_SYN_SENT
) { 819 interruptible_sleep_on(sk
->sleep
); 820 if(current
->signal
& ~current
->blocked
) { 826 if(sk
->state
!= TCP_ESTABLISHED
) { 828 sock
->state
= SS_UNCONNECTED
; 829 returnsock_error(sk
);/* Always set at this point */ 832 sock
->state
= SS_CONNECTED
; 839 static intnr_socketpair(struct socket
*sock1
,struct socket
*sock2
) 844 static intnr_accept(struct socket
*sock
,struct socket
*newsock
,int flags
) 850 if(newsock
->sk
!= NULL
) 851 nr_destroy_socket(newsock
->sk
); 855 if((sk
= sock
->sk
) == NULL
) 858 if(sk
->type
!= SOCK_SEQPACKET
) 861 if(sk
->state
!= TCP_LISTEN
) 865 * The write queue this time is holding sockets ready to use 866 * hooked into the SABM we saved 870 if((skb
=skb_dequeue(&sk
->receive_queue
)) == NULL
) { 871 if(flags
& O_NONBLOCK
) { 875 interruptible_sleep_on(sk
->sleep
); 876 if(current
->signal
& ~current
->blocked
) { 887 /* Now attach up the new socket */ 889 kfree_skb(skb
, FREE_READ
); 896 static intnr_getname(struct socket
*sock
,struct sockaddr
*uaddr
, 897 int*uaddr_len
,int peer
) 899 struct full_sockaddr_ax25
*sax
= (struct full_sockaddr_ax25
*)uaddr
; 900 struct sock
*sk
= sock
->sk
; 903 if(sk
->state
!= TCP_ESTABLISHED
) 905 sax
->fsa_ax25
.sax25_family
= AF_NETROM
; 906 sax
->fsa_ax25
.sax25_ndigis
=1; 907 sax
->fsa_ax25
.sax25_call
= sk
->protinfo
.nr
->user_addr
; 908 sax
->fsa_digipeater
[0] = sk
->protinfo
.nr
->dest_addr
; 909 *uaddr_len
=sizeof(struct full_sockaddr_ax25
); 911 sax
->fsa_ax25
.sax25_family
= AF_NETROM
; 912 sax
->fsa_ax25
.sax25_ndigis
=0; 913 sax
->fsa_ax25
.sax25_call
= sk
->protinfo
.nr
->source_addr
; 914 *uaddr_len
=sizeof(struct sockaddr_ax25
); 920 intnr_rx_frame(struct sk_buff
*skb
,struct device
*dev
) 924 ax25_address
*src
, *dest
, *user
; 925 unsigned short circuit_index
, circuit_id
; 926 unsigned short frametype
, window
, timeout
; 928 skb
->sk
= NULL
;/* Initially we don't know who it's for */ 931 * skb->data points to the netrom frame start 934 src
= (ax25_address
*)(skb
->data
+0); 935 dest
= (ax25_address
*)(skb
->data
+7); 937 circuit_index
= skb
->data
[15]; 938 circuit_id
= skb
->data
[16]; 939 frametype
= skb
->data
[19]; 943 * Check for an incoming IP over NET/ROM frame. 945 if((frametype
&0x0F) == NR_PROTOEXT
&& circuit_index
== NR_PROTO_IP
&& circuit_id
== NR_PROTO_IP
) { 946 skb_pull(skb
, NR_NETWORK_LEN
+ NR_TRANSPORT_LEN
); 947 skb
->h
.raw
= skb
->data
; 949 returnnr_rx_ip(skb
, dev
); 954 * Find an existing socket connection, based on circuit ID, if it's 955 * a Connect Request base it on their circuit ID. 957 if(((frametype
&0x0F) != NR_CONNREQ
&& (sk
=nr_find_socket(circuit_index
, circuit_id
)) != NULL
) || 958 ((frametype
&0x0F) == NR_CONNREQ
&& (sk
=nr_find_peer(circuit_index
, circuit_id
)) != NULL
)) { 959 skb
->h
.raw
= skb
->data
; 961 if((frametype
&0x0F) == NR_CONNACK
&& skb
->len
==22) 962 sk
->protinfo
.nr
->bpqext
=1; 964 sk
->protinfo
.nr
->bpqext
=0; 966 returnnr_process_rx_frame(sk
, skb
); 969 if((frametype
&0x0F) != NR_CONNREQ
) 972 sk
=nr_find_listener(dest
); 974 user
= (ax25_address
*)(skb
->data
+21); 976 if(sk
== NULL
|| sk
->ack_backlog
== sk
->max_ack_backlog
|| (make
=nr_make_new(sk
)) == NULL
) { 981 window
= skb
->data
[20]; 984 make
->state
= TCP_ESTABLISHED
; 986 /* Fill in his circuit details */ 987 make
->protinfo
.nr
->source_addr
= *dest
; 988 make
->protinfo
.nr
->dest_addr
= *src
; 989 make
->protinfo
.nr
->user_addr
= *user
; 991 make
->protinfo
.nr
->your_index
= circuit_index
; 992 make
->protinfo
.nr
->your_id
= circuit_id
; 994 make
->protinfo
.nr
->my_index
= circuit
/256; 995 make
->protinfo
.nr
->my_id
= circuit
%256; 999 /* Window negotiation */ 1000 if(window
< make
->protinfo
.nr
->window
) 1001 make
->protinfo
.nr
->window
= window
; 1003 /* L4 timeout negotiation */ 1005 timeout
= skb
->data
[36] *256+ skb
->data
[35]; 1006 if(timeout
* NR_SLOWHZ
< make
->protinfo
.nr
->t1
) 1007 make
->protinfo
.nr
->t1
= timeout
* NR_SLOWHZ
; 1008 make
->protinfo
.nr
->bpqext
=1; 1010 make
->protinfo
.nr
->bpqext
=0; 1013 nr_write_internal(make
, NR_CONNACK
); 1015 make
->protinfo
.nr
->condition
=0x00; 1016 make
->protinfo
.nr
->vs
=0; 1017 make
->protinfo
.nr
->va
=0; 1018 make
->protinfo
.nr
->vr
=0; 1019 make
->protinfo
.nr
->vl
=0; 1020 make
->protinfo
.nr
->state
= NR_STATE_3
; 1024 nr_insert_socket(make
); 1026 skb_queue_head(&sk
->receive_queue
, skb
); 1031 sk
->data_ready(sk
, skb
->len
); 1036 static intnr_sendmsg(struct socket
*sock
,struct msghdr
*msg
,int len
,struct scm_cookie
*scm
) 1038 struct sock
*sk
= sock
->sk
; 1039 struct sockaddr_ax25
*usax
= (struct sockaddr_ax25
*)msg
->msg_name
; 1041 struct sockaddr_ax25 sax
; 1042 struct sk_buff
*skb
; 1043 unsigned char*asmptr
; 1046 if(msg
->msg_flags
& ~MSG_DONTWAIT
) 1050 return-EADDRNOTAVAIL
; 1052 if(sk
->shutdown
& SEND_SHUTDOWN
) { 1053 send_sig(SIGPIPE
, current
,0); 1057 if(sk
->protinfo
.nr
->device
== NULL
) 1061 if(msg
->msg_namelen
<sizeof(sax
)) 1064 if(ax25cmp(&sk
->protinfo
.nr
->dest_addr
, &sax
.sax25_call
) !=0) 1066 if(sax
.sax25_family
!= AF_NETROM
) 1069 if(sk
->state
!= TCP_ESTABLISHED
) 1071 sax
.sax25_family
= AF_NETROM
; 1072 sax
.sax25_call
= sk
->protinfo
.nr
->dest_addr
; 1074 SOCK_DEBUG(sk
,"NET/ROM: sendto: Addresses built.\n"); 1076 /* Build a packet */ 1077 SOCK_DEBUG(sk
,"NET/ROM: sendto: building packet.\n"); 1078 size
= len
+ AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ NR_NETWORK_LEN
+ NR_TRANSPORT_LEN
; 1080 if((skb
=sock_alloc_send_skb(sk
, size
,0, msg
->msg_flags
& MSG_DONTWAIT
, &err
)) == NULL
) 1083 skb_reserve(skb
, size
- len
); 1086 * Push down the NET/ROM header 1089 asmptr
=skb_push(skb
, NR_TRANSPORT_LEN
); 1090 SOCK_DEBUG(sk
,"Building NET/ROM Header.\n"); 1092 /* Build a NET/ROM Transport header */ 1094 *asmptr
++ = sk
->protinfo
.nr
->your_index
; 1095 *asmptr
++ = sk
->protinfo
.nr
->your_id
; 1096 *asmptr
++ =0;/* To be filled in later */ 1097 *asmptr
++ =0;/* Ditto */ 1098 *asmptr
++ = NR_INFO
; 1099 SOCK_DEBUG(sk
,"Built header.\n"); 1102 * Put the data on the end 1105 skb
->h
.raw
=skb_put(skb
, len
); 1107 asmptr
= skb
->h
.raw
; 1108 SOCK_DEBUG(sk
,"NET/ROM: Appending user data\n"); 1110 /* User data follows immediately after the NET/ROM transport header */ 1111 memcpy_fromiovec(asmptr
, msg
->msg_iov
, len
); 1112 SOCK_DEBUG(sk
,"NET/ROM: Transmitting buffer\n"); 1114 if(sk
->state
!= TCP_ESTABLISHED
) { 1115 kfree_skb(skb
, FREE_WRITE
); 1119 nr_output(sk
, skb
);/* Shove it onto the queue */ 1125 static intnr_recvmsg(struct socket
*sock
,struct msghdr
*msg
,int size
, 1126 int flags
,struct scm_cookie
*scm
) 1128 struct sock
*sk
= sock
->sk
; 1129 struct sockaddr_ax25
*sax
= (struct sockaddr_ax25
*)msg
->msg_name
; 1131 struct sk_buff
*skb
; 1135 * This works for seqpacket too. The receiver has ordered the queue for 1136 * us! We do one quick check first though 1139 if(sk
->state
!= TCP_ESTABLISHED
) 1142 /* Now we can treat all alike */ 1143 if((skb
=skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
, flags
& MSG_DONTWAIT
, &er
)) == NULL
) 1146 if(!sk
->protinfo
.nr
->hdrincl
) { 1147 skb_pull(skb
, NR_NETWORK_LEN
+ NR_TRANSPORT_LEN
); 1148 skb
->h
.raw
= skb
->data
; 1155 msg
->msg_flags
|= MSG_TRUNC
; 1158 skb_copy_datagram_iovec(skb
,0, msg
->msg_iov
, copied
); 1161 sax
->sax25_family
= AF_NETROM
; 1162 memcpy(sax
->sax25_call
.ax25_call
, skb
->data
+7, AX25_ADDR_LEN
); 1165 msg
->msg_namelen
=sizeof(*sax
); 1167 skb_free_datagram(sk
, skb
); 1172 static intnr_shutdown(struct socket
*sk
,int how
) 1177 static intnr_ioctl(struct socket
*sock
,unsigned int cmd
,unsigned long arg
) 1179 struct sock
*sk
= sock
->sk
; 1185 if((err
=verify_area(VERIFY_WRITE
, (void*)arg
,sizeof(int))) !=0) 1187 amount
= sk
->sndbuf
-atomic_read(&sk
->wmem_alloc
); 1190 put_user(amount
, (int*)arg
); 1194 struct sk_buff
*skb
; 1195 /* These two are safe on a single CPU system as only user tasks fiddle here */ 1196 if((skb
=skb_peek(&sk
->receive_queue
)) != NULL
) 1197 amount
= skb
->len
-20; 1198 if((err
=verify_area(VERIFY_WRITE
, (void*)arg
,sizeof(int))) !=0) 1200 put_user(amount
, (int*)arg
); 1206 if(sk
->stamp
.tv_sec
==0) 1208 if((err
=verify_area(VERIFY_WRITE
,(void*)arg
,sizeof(struct timeval
))) !=0) 1210 copy_to_user((void*)arg
, &sk
->stamp
,sizeof(struct timeval
)); 1217 case SIOCGIFDSTADDR
: 1218 case SIOCSIFDSTADDR
: 1219 case SIOCGIFBRDADDR
: 1220 case SIOCSIFBRDADDR
: 1221 case SIOCGIFNETMASK
: 1222 case SIOCSIFNETMASK
: 1230 if(!suser())return-EPERM
; 1231 returnnr_rt_ioctl(cmd
, (void*)arg
); 1234 if(!suser())return-EPERM
; 1235 returnnr_ctl_ioctl(cmd
, (void*)arg
); 1238 returndev_ioctl(cmd
, (void*)arg
); 1245 static intnr_get_info(char*buffer
,char**start
, off_t offset
,int length
,int dummy
) 1256 len
+=sprintf(buffer
,"user_addr dest_node src_node dev my your st vs vr va t1 t2 n2 wnd Snd-Q Rcv-Q\n"); 1258 for(s
= nr_list
; s
!= NULL
; s
= s
->next
) { 1259 if((dev
= s
->protinfo
.nr
->device
) == NULL
) 1262 devname
= dev
->name
; 1264 len
+=sprintf(buffer
+ len
,"%-9s ", 1265 ax2asc(&s
->protinfo
.nr
->user_addr
)); 1266 len
+=sprintf(buffer
+ len
,"%-9s ", 1267 ax2asc(&s
->protinfo
.nr
->dest_addr
)); 1268 len
+=sprintf(buffer
+ len
,"%-9s %-3s %02X/%02X %02X/%02X %2d %3d %3d %3d %3d/%03d %2d/%02d %2d/%02d %3d %5d %5d\n", 1269 ax2asc(&s
->protinfo
.nr
->source_addr
), 1270 devname
, s
->protinfo
.nr
->my_index
, s
->protinfo
.nr
->my_id
, 1271 s
->protinfo
.nr
->your_index
, s
->protinfo
.nr
->your_id
, 1272 s
->protinfo
.nr
->state
, 1273 s
->protinfo
.nr
->vs
, s
->protinfo
.nr
->vr
, s
->protinfo
.nr
->va
, 1274 s
->protinfo
.nr
->t1timer
/ NR_SLOWHZ
, 1275 s
->protinfo
.nr
->t1
/ NR_SLOWHZ
, 1276 s
->protinfo
.nr
->t2timer
/ NR_SLOWHZ
, 1277 s
->protinfo
.nr
->t2
/ NR_SLOWHZ
, 1278 s
->protinfo
.nr
->n2count
, 1280 s
->protinfo
.nr
->window
, 1281 atomic_read(&s
->wmem_alloc
),atomic_read(&s
->rmem_alloc
)); 1290 if(pos
> offset
+ length
) 1296 *start
= buffer
+ (offset
- begin
); 1297 len
-= (offset
- begin
); 1299 if(len
> length
) len
= length
; 1304 static struct net_proto_family nr_family_ops
= 1310 static struct proto_ops nr_proto_ops
= { 1331 static struct notifier_block nr_dev_notifier
= { 1336 #ifdef CONFIG_PROC_FS 1337 static struct proc_dir_entry proc_net_nr
= { 1339 S_IFREG
| S_IRUGO
,1,0,0, 1340 0, &proc_net_inode_operations
, 1343 static struct proc_dir_entry proc_net_nr_neigh
= { 1344 PROC_NET_NR_NEIGH
,8,"nr_neigh", 1345 S_IFREG
| S_IRUGO
,1,0,0, 1346 0, &proc_net_inode_operations
, 1349 static struct proc_dir_entry proc_net_nr_nodes
= { 1350 PROC_NET_NR_NODES
,8,"nr_nodes", 1351 S_IFREG
| S_IRUGO
,1,0,0, 1352 0, &proc_net_inode_operations
, 1357 static struct device dev_nr
[] = { 1358 {"nr0",0,0,0,0,0,0,0,0,0, NULL
, nr_init
}, 1359 {"nr1",0,0,0,0,0,0,0,0,0, NULL
, nr_init
}, 1360 {"nr2",0,0,0,0,0,0,0,0,0, NULL
, nr_init
}, 1361 {"nr3",0,0,0,0,0,0,0,0,0, NULL
, nr_init
} 1364 voidnr_proto_init(struct net_proto
*pro
) 1368 sock_register(&nr_family_ops
); 1369 register_netdevice_notifier(&nr_dev_notifier
); 1370 printk(KERN_INFO
"G4KLX NET/ROM for Linux. Version 0.6 for AX25.035 Linux 2.1\n"); 1372 if(!ax25_protocol_register(AX25_P_NETROM
, nr_route_frame
)) 1373 printk(KERN_ERR
"NET/ROM unable to register protocol with AX.25\n"); 1374 if(!ax25_linkfail_register(nr_link_failed
)) 1375 printk(KERN_ERR
"NET/ROM unable to register linkfail handler with AX.25\n"); 1377 for(i
=0; i
<4; i
++) 1378 register_netdev(&dev_nr
[i
]); 1380 #ifdef CONFIG_SYSCTL 1381 nr_register_sysctl(); 1384 #ifdef CONFIG_PROC_FS 1385 proc_net_register(&proc_net_nr
); 1386 proc_net_register(&proc_net_nr_neigh
); 1387 proc_net_register(&proc_net_nr_nodes
); 1394 intinit_module(void) 1396 nr_proto_init(NULL
); 1401 voidcleanup_module(void) 1405 #ifdef CONFIG_PROC_FS 1406 proc_net_unregister(PROC_NET_NR
); 1407 proc_net_unregister(PROC_NET_NR_NEIGH
); 1408 proc_net_unregister(PROC_NET_NR_NODES
); 1412 ax25_protocol_release(AX25_P_NETROM
); 1413 ax25_linkfail_release(nr_link_failed
); 1415 unregister_netdevice_notifier(&nr_dev_notifier
); 1417 #ifdef CONFIG_SYSCTL 1418 nr_unregister_sysctl(); 1420 sock_unregister(AF_NETROM
); 1422 for(i
=0; i
<4; i
++) { 1423 if(dev_nr
[i
].priv
!= NULL
) { 1424 kfree(dev_nr
[i
].priv
); 1425 dev_nr
[i
].priv
= NULL
; 1426 unregister_netdev(&dev_nr
[i
]);