2 * An implementation of the Acorn Econet and AUN protocols. 3 * Philip Blundell <philb@gnu.org> 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 10 * 2 of the License, or (at your option) any later version. 14 #include <linux/config.h> 15 #include <linux/module.h> 17 #include <asm/uaccess.h> 18 #include <asm/system.h> 19 #include <asm/bitops.h> 20 #include <linux/types.h> 21 #include <linux/kernel.h> 22 #include <linux/sched.h> 23 #include <linux/string.h> 25 #include <linux/socket.h> 26 #include <linux/sockios.h> 28 #include <linux/errno.h> 29 #include <linux/interrupt.h> 30 #include <linux/if_ether.h> 31 #include <linux/netdevice.h> 32 #include <linux/inetdevice.h> 33 #include <linux/route.h> 34 #include <linux/inet.h> 35 #include <linux/etherdevice.h> 36 #include <linux/if_arp.h> 37 #include <linux/wireless.h> 38 #include <linux/skbuff.h> 40 #include <net/inet_common.h> 41 #include <linux/stat.h> 42 #include <linux/init.h> 43 #include <linux/if_ec.h> 46 #include <linux/spinlock.h> 48 static struct proto_ops econet_ops
; 49 static struct sock
*econet_sklist
; 51 static spinlock_t aun_queue_lock
; 53 #ifdef CONFIG_ECONET_AUNUDP 54 static struct socket
*udpsock
; 55 #define AUN_PORT 0x8000 59 unsigned char code
;/* AUN magic protocol byte */ 66 static unsigned long aun_seq
=0; 68 /* Queue of packets waiting to be transmitted. */ 69 static struct sk_buff_head aun_queue
; 70 static struct timer_list ab_cleanup_timer
; 72 #endif/* CONFIG_ECONET_AUNUDP */ 74 /* Per-packet information */ 77 struct sockaddr_ec sec
; 78 unsigned long cookie
;/* Supplied by user. */ 79 #ifdef CONFIG_ECONET_AUNUDP 81 unsigned long seq
;/* Sequencing */ 82 unsigned long timeout
;/* Timeout */ 83 unsigned long start
;/* jiffies */ 85 #ifdef CONFIG_ECONET_NATIVE 86 void(*sent
)(struct sk_buff
*,int result
); 92 struct net_device
*dev
;/* Real device structure */ 93 unsigned char station
, net
;/* Econet protocol address */ 94 struct ec_device
*prev
, *next
;/* Linked list */ 97 static struct ec_device
*edevlist
= NULL
; 99 static spinlock_t edevlist_lock
; 102 * Faster version of edev_get - call with IRQs off 105 static __inline__
struct ec_device
*__edev_get(struct net_device
*dev
) 107 struct ec_device
*edev
; 108 for(edev
= edevlist
; edev
; edev
= edev
->next
) 117 * Find an Econet device given its `dev' pointer. This is IRQ safe. 119 * Against what is it safe? --ANK 122 static struct ec_device
*edev_get(struct net_device
*dev
) 124 struct ec_device
*edev
; 126 spin_lock_irqsave(&edevlist_lock
, flags
); 127 edev
=__edev_get(dev
); 128 spin_unlock_irqrestore(&edevlist_lock
, flags
); 133 * Pull a packet from our receive queue and hand it to the user. 134 * If necessary we block. 137 static inteconet_recvmsg(struct socket
*sock
,struct msghdr
*msg
,int len
, 138 int flags
,struct scm_cookie
*scm
) 140 struct sock
*sk
= sock
->sk
; 144 msg
->msg_namelen
=sizeof(struct sockaddr_ec
); 147 * Call the generic datagram receiver. This handles all sorts 148 * of horrible races and re-entrancy so we can forget about it 149 * in the protocol layers. 151 * Now it will return ENETDOWN, if device have just gone down, 152 * but then it will block. 155 skb
=skb_recv_datagram(sk
,flags
,flags
&MSG_DONTWAIT
,&err
); 158 * An error occurred so return it. Because skb_recv_datagram() 159 * handles the blocking we don't see and worry about blocking 167 * You lose any data beyond the buffer you gave. If it worries a 168 * user program they can ask the device for its MTU anyway. 175 msg
->msg_flags
|=MSG_TRUNC
; 178 /* We can't use skb_copy_datagram here */ 179 err
=memcpy_toiovec(msg
->msg_iov
, skb
->data
, copied
); 182 sk
->stamp
=skb
->stamp
; 185 memcpy(msg
->msg_name
, skb
->cb
, msg
->msg_namelen
); 188 * Free or return the buffer as appropriate. Again this 189 * hides all the races and re-entrancy issues from us. 194 skb_free_datagram(sk
, skb
); 200 * Bind an Econet socket. 203 static inteconet_bind(struct socket
*sock
,struct sockaddr
*uaddr
,int addr_len
) 205 struct sockaddr_ec
*sec
= (struct sockaddr_ec
*)uaddr
; 206 struct sock
*sk
=sock
->sk
; 212 if(addr_len
<sizeof(struct sockaddr_ec
)) 214 if(sec
->sec_family
!= AF_ECONET
) 217 sk
->protinfo
.af_econet
->cb
= sec
->cb
; 218 sk
->protinfo
.af_econet
->port
= sec
->port
; 219 sk
->protinfo
.af_econet
->station
= sec
->addr
.station
; 220 sk
->protinfo
.af_econet
->net
= sec
->addr
.net
; 226 * Queue a transmit result for the user to be told about. 229 static voidtx_result(struct sock
*sk
,unsigned long cookie
,int result
) 231 struct sk_buff
*skb
=alloc_skb(0, GFP_ATOMIC
); 233 struct sockaddr_ec
*sec
; 237 printk(KERN_DEBUG
"ec: memory squeeze, transmit result dropped.\n"); 241 eb
= (struct ec_cb
*)&skb
->cb
; 242 sec
= (struct sockaddr_ec
*)&eb
->sec
; 243 memset(sec
,0,sizeof(struct sockaddr_ec
)); 244 sec
->cookie
= cookie
; 245 sec
->type
= ECTYPE_TRANSMIT_STATUS
| result
; 246 sec
->sec_family
= AF_ECONET
; 248 if(sock_queue_rcv_skb(sk
, skb
) <0) 252 #ifdef CONFIG_ECONET_NATIVE 254 * Called by the Econet hardware driver when a packet transmit 255 * has completed. Tell the user. 258 static voidec_tx_done(struct sk_buff
*skb
,int result
) 260 struct ec_cb
*eb
= (struct ec_cb
*)&skb
->cb
; 261 tx_result(skb
->sk
, eb
->cookie
, result
); 266 * Send a packet. We have to work out which device it's going out on 267 * and hence whether to use real Econet or the UDP emulation. 270 static inteconet_sendmsg(struct socket
*sock
,struct msghdr
*msg
,int len
, 271 struct scm_cookie
*scm
) 273 struct sock
*sk
= sock
->sk
; 274 struct sockaddr_ec
*saddr
=(struct sockaddr_ec
*)msg
->msg_name
; 275 struct net_device
*dev
; 277 struct ec_device
*edev
; 279 unsigned char port
, cb
; 282 #ifdef CONFIG_ECONET_NATIVE 283 unsigned short proto
=0; 285 #ifdef CONFIG_ECONET_AUNUDP 286 struct msghdr udpmsg
; 287 struct iovec iov
[msg
->msg_iovlen
+1]; 289 struct sockaddr_in udpdest
; 290 __kernel_size_t size
; 299 if(msg
->msg_flags
&~MSG_DONTWAIT
) 303 * Get and verify the address. 307 addr
.station
= sk
->protinfo
.af_econet
->station
; 308 addr
.net
= sk
->protinfo
.af_econet
->net
; 309 port
= sk
->protinfo
.af_econet
->port
; 310 cb
= sk
->protinfo
.af_econet
->cb
; 312 if(msg
->msg_namelen
<sizeof(struct sockaddr_ec
)) 314 addr
.station
= saddr
->addr
.station
; 315 addr
.net
= saddr
->addr
.net
; 320 /* Look for a device with the right network number. */ 321 for(edev
= edevlist
; edev
&& (edev
->net
!= addr
.net
); 324 /* Bridge? What's that? */ 330 if(dev
->type
== ARPHRD_ECONET
) 332 /* Real hardware Econet. We're not worthy etc. */ 333 #ifdef CONFIG_ECONET_NATIVE 334 atomic_inc(&dev
->refcnt
); 336 skb
=sock_alloc_send_skb(sk
, len
+dev
->hard_header_len
+15,0, 337 msg
->msg_flags
& MSG_DONTWAIT
, &err
); 341 skb_reserve(skb
, (dev
->hard_header_len
+15)&~15); 342 skb
->nh
.raw
= skb
->data
; 344 eb
= (struct ec_cb
*)&skb
->cb
; 346 eb
->cookie
= saddr
->cookie
; 348 eb
->sent
= ec_tx_done
; 350 if(dev
->hard_header
) { 353 res
= dev
->hard_header(skb
, dev
,ntohs(proto
), &addr
, NULL
, len
); 354 if(sock
->type
!= SOCK_DGRAM
) { 355 skb
->tail
= skb
->data
; 361 /* Copy the data. Returns -EFAULT on error */ 362 err
=memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
); 363 skb
->protocol
= proto
; 365 skb
->priority
= sk
->priority
; 370 if(!(dev
->flags
& IFF_UP
)) 392 #ifdef CONFIG_ECONET_AUNUDP 393 /* AUN virtual Econet. */ 396 return-ENETDOWN
;/* No socket - can't send */ 398 /* Make up a UDP datagram and hand it off to some higher intellect. */ 400 memset(&udpdest
,0,sizeof(udpdest
)); 401 udpdest
.sin_family
= AF_INET
; 402 udpdest
.sin_port
=htons(AUN_PORT
); 404 /* At the moment we use the stupid Acorn scheme of Econet address 405 y.x maps to IP a.b.c.x. This should be replaced with something 406 more flexible and more aware of subnet masks. */ 408 struct in_device
*idev
=in_dev_get(dev
); 409 unsigned long network
=0; 411 read_lock(&idev
->lock
); 413 network
=ntohl(idev
->ifa_list
->ifa_address
) & 415 read_unlock(&idev
->lock
); 418 udpdest
.sin_addr
.s_addr
=htonl(network
| addr
.station
); 423 ah
.code
=2;/* magic */ 426 /* tack our header on the front of the iovec */ 427 size
=sizeof(struct aunhdr
); 428 iov
[0].iov_base
= (void*)&ah
; 429 iov
[0].iov_len
= size
; 430 for(i
=0; i
< msg
->msg_iovlen
; i
++) { 431 void*base
= msg
->msg_iov
[i
].iov_base
; 432 size_t len
= msg
->msg_iov
[i
].iov_len
; 433 /* Check it now since we switch to KERNEL_DS later. */ 434 if((err
=verify_area(VERIFY_READ
, base
, len
)) <0) 436 iov
[i
+1].iov_base
= base
; 437 iov
[i
+1].iov_len
= len
; 441 /* Get a skbuff (no data, just holds our cb information) */ 442 if((skb
=sock_alloc_send_skb(sk
,0,0, 443 msg
->msg_flags
& MSG_DONTWAIT
, &err
)) == NULL
) 446 eb
= (struct ec_cb
*)&skb
->cb
; 448 eb
->cookie
= saddr
->cookie
; 449 eb
->timeout
= (5*HZ
); 452 eb
->seq
= (aun_seq
++); 455 skb_queue_tail(&aun_queue
, skb
); 457 udpmsg
.msg_name
= (void*)&udpdest
; 458 udpmsg
.msg_namelen
=sizeof(udpdest
); 459 udpmsg
.msg_iov
= &iov
[0]; 460 udpmsg
.msg_iovlen
= msg
->msg_iovlen
+1; 461 udpmsg
.msg_control
= NULL
; 462 udpmsg
.msg_controllen
=0; 465 oldfs
=get_fs();set_fs(KERNEL_DS
);/* More privs :-) */ 466 err
=sock_sendmsg(udpsock
, &udpmsg
, size
); 475 * Look up the address of a socket. 478 static inteconet_getname(struct socket
*sock
,struct sockaddr
*uaddr
, 479 int*uaddr_len
,int peer
) 481 struct sock
*sk
= sock
->sk
; 482 struct sockaddr_ec
*sec
= (struct sockaddr_ec
*)uaddr
; 487 sec
->sec_family
= AF_ECONET
; 488 sec
->port
= sk
->protinfo
.af_econet
->port
; 489 sec
->addr
.station
= sk
->protinfo
.af_econet
->station
; 490 sec
->addr
.net
= sk
->protinfo
.af_econet
->net
; 492 *uaddr_len
=sizeof(*sec
); 496 static voideconet_destroy_timer(unsigned long data
) 498 struct sock
*sk
=(struct sock
*)data
; 500 if(!atomic_read(&sk
->wmem_alloc
) && !atomic_read(&sk
->rmem_alloc
)) { 506 sk
->timer
.expires
=jiffies
+10*HZ
; 507 add_timer(&sk
->timer
); 508 printk(KERN_DEBUG
"econet socket destroy delayed\n"); 512 * Close an econet socket. 515 static inteconet_release(struct socket
*sock
) 518 struct sock
*sk
= sock
->sk
; 523 sklist_remove_socket(&econet_sklist
, sk
); 526 * Now the socket is dead. No more input will appear. 529 sk
->state_change(sk
);/* It is useless. Just for sanity. */ 537 while((skb
=skb_dequeue(&sk
->receive_queue
))!=NULL
) 540 if(atomic_read(&sk
->rmem_alloc
) ||atomic_read(&sk
->wmem_alloc
)) { 541 sk
->timer
.data
=(unsigned long)sk
; 542 sk
->timer
.expires
=jiffies
+HZ
; 543 sk
->timer
.function
=econet_destroy_timer
; 544 add_timer(&sk
->timer
); 554 * Create an Econet socket 557 static inteconet_create(struct socket
*sock
,int protocol
) 562 /* Econet only provides datagram services. */ 563 if(sock
->type
!= SOCK_DGRAM
) 564 return-ESOCKTNOSUPPORT
; 566 sock
->state
= SS_UNCONNECTED
; 570 sk
=sk_alloc(PF_ECONET
, GFP_KERNEL
,1); 575 sock
->ops
= &econet_ops
; 576 sock_init_data(sock
,sk
); 578 sk
->protinfo
.af_econet
=kmalloc(sizeof(struct econet_opt
), GFP_KERNEL
); 579 if(sk
->protinfo
.af_econet
== NULL
) 581 memset(sk
->protinfo
.af_econet
,0,sizeof(struct econet_opt
)); 583 sk
->family
= PF_ECONET
; 586 sklist_insert_socket(&econet_sklist
, sk
); 597 * Handle Econet specific ioctls 600 static intec_dev_ioctl(struct socket
*sock
,unsigned int cmd
,void*arg
) 603 struct ec_device
*edev
; 604 struct net_device
*dev
; 606 struct sockaddr_ec
*sec
; 609 * Fetch the caller's info block into kernel space 612 if(copy_from_user(&ifr
, arg
,sizeof(struct ifreq
))) 615 if((dev
=dev_get_by_name(ifr
.ifr_name
)) == NULL
) 618 sec
= (struct sockaddr_ec
*)&ifr
.ifr_addr
; 623 spin_lock_irqsave(&edevlist_lock
, flags
); 624 edev
=__edev_get(dev
); 627 /* Magic up a new one. */ 628 printk("Get fascist grenade!!!\n"); 630 /* Note to author: please, remove this spinlock. 631 You do not change edevlist from interrupts, 632 so that such aggressive protection is redundant. 634 BTW not all scans of edev_list are protected. 636 edev
=kmalloc(GFP_KERNEL
,sizeof(struct ec_device
)); 638 printk("af_ec: memory squeeze.\n"); 639 spin_unlock_irqrestore(&edevlist_lock
, flags
); 643 memset(edev
,0,sizeof(struct ec_device
)); 645 edev
->next
= edevlist
; 648 edev
->station
= sec
->addr
.station
; 649 edev
->net
= sec
->addr
.net
; 650 spin_unlock_irqrestore(&edevlist_lock
, flags
); 655 spin_lock_irqsave(&edevlist_lock
, flags
); 656 edev
=__edev_get(dev
); 659 spin_unlock_irqrestore(&edevlist_lock
, flags
); 663 memset(sec
,0,sizeof(struct sockaddr_ec
)); 664 sec
->addr
.station
= edev
->station
; 665 sec
->addr
.net
= edev
->net
; 666 sec
->sec_family
= AF_ECONET
; 667 spin_unlock_irqrestore(&edevlist_lock
, flags
); 669 if(copy_to_user(arg
, &ifr
,sizeof(struct ifreq
))) 679 * Handle generic ioctls 682 static inteconet_ioctl(struct socket
*sock
,unsigned int cmd
,unsigned long arg
) 684 struct sock
*sk
= sock
->sk
; 692 err
=get_user(pid
, (int*) arg
); 695 if(current
->pid
!= pid
&& current
->pgrp
!= -pid
&& !suser()) 701 returnput_user(sk
->proc
, (int*)arg
); 703 if(sk
->stamp
.tv_sec
==0) 706 if(!copy_to_user((void*)arg
, &sk
->stamp
,sizeof(struct timeval
))) 728 case SIOCSIFHWBROADCAST
: 729 return(dev_ioctl(cmd
,(void*) arg
)); 733 returnec_dev_ioctl(sock
, cmd
, (void*)arg
); 737 return(dev_ioctl(cmd
,(void*) arg
)); 743 static struct net_proto_family econet_family_ops
= { 748 static struct proto_ops
SOCKOPS_WRAPPED(econet_ops
) = { 769 #include <linux/smp_lock.h> 770 SOCKOPS_WRAP(econet
, PF_ECONET
); 773 * Find the listening socket, if any, for the given data. 776 static struct sock
*ec_listening_socket(unsigned char port
,unsigned char 777 station
,unsigned char net
) 779 struct sock
*sk
= econet_sklist
; 783 struct econet_opt
*opt
= sk
->protinfo
.af_econet
; 784 if((opt
->port
== port
|| opt
->port
==0) && 785 (opt
->station
== station
|| opt
->station
==0) && 786 (opt
->net
== net
|| opt
->net
==0)) 795 #ifdef CONFIG_ECONET_AUNUDP 798 * Send an AUN protocol response. 801 static voidaun_send_response(__u32 addr
,unsigned long seq
,int code
,int cb
) 803 struct sockaddr_in sin
; 806 struct msghdr udpmsg
; 810 memset(&sin
,0,sizeof(sin
)); 811 sin
.sin_family
= AF_INET
; 812 sin
.sin_port
=htons(AUN_PORT
); 813 sin
.sin_addr
.s_addr
= addr
; 821 iov
.iov_base
= (void*)&ah
; 822 iov
.iov_len
=sizeof(ah
); 824 udpmsg
.msg_name
= (void*)&sin
; 825 udpmsg
.msg_namelen
=sizeof(sin
); 826 udpmsg
.msg_iov
= &iov
; 827 udpmsg
.msg_iovlen
=1; 828 udpmsg
.msg_control
= NULL
; 829 udpmsg
.msg_controllen
=0; 832 oldfs
=get_fs();set_fs(KERNEL_DS
); 833 err
=sock_sendmsg(udpsock
, &udpmsg
,sizeof(ah
)); 838 * Handle incoming AUN packets. Work out if anybody wants them, 839 * and send positive or negative acknowledgements as appropriate. 842 static voidaun_incoming(struct sk_buff
*skb
,struct aunhdr
*ah
,size_t len
) 844 struct ec_device
*edev
=edev_get(skb
->dev
); 845 struct iphdr
*ip
= skb
->nh
.iph
; 846 unsigned char stn
=ntohl(ip
->saddr
) &0xff; 848 struct sk_buff
*newskb
; 850 struct sockaddr_ec
*sec
; 853 return;/* Device not configured for AUN */ 855 if((sk
=ec_listening_socket(ah
->port
, stn
, edev
->net
)) == NULL
) 856 goto bad
;/* Nobody wants it */ 858 newskb
=alloc_skb((len
-sizeof(struct aunhdr
) +15) & ~15, 862 printk(KERN_DEBUG
"AUN: memory squeeze, dropping packet.\n"); 863 /* Send nack and hope sender tries again */ 867 eb
= (struct ec_cb
*)&newskb
->cb
; 868 sec
= (struct sockaddr_ec
*)&eb
->sec
; 869 memset(sec
,0,sizeof(struct sockaddr_ec
)); 870 sec
->sec_family
= AF_ECONET
; 871 sec
->type
= ECTYPE_PACKET_RECEIVED
; 872 sec
->port
= ah
->port
; 874 sec
->addr
.net
= edev
->net
; 875 sec
->addr
.station
= stn
; 877 memcpy(skb_put(newskb
, len
-sizeof(struct aunhdr
)), (void*)(ah
+1), 878 len
-sizeof(struct aunhdr
)); 880 if(sock_queue_rcv_skb(sk
, newskb
) <0) 882 /* Socket is bankrupt. */ 887 aun_send_response(ip
->saddr
, ah
->handle
,3,0); 891 aun_send_response(ip
->saddr
, ah
->handle
,4,0); 895 * Handle incoming AUN transmit acknowledgements. If the sequence 896 * number matches something in our backlog then kill it and tell 897 * the user. If the remote took too long to reply then we may have 898 * dropped the packet already. 901 static voidaun_tx_ack(unsigned long seq
,int result
) 907 spin_lock_irqsave(&aun_queue_lock
, flags
); 908 skb
=skb_peek(&aun_queue
); 909 while(skb
&& skb
!= (struct sk_buff
*)&aun_queue
) 911 struct sk_buff
*newskb
= skb
->next
; 912 eb
= (struct ec_cb
*)&skb
->cb
; 918 spin_unlock_irqrestore(&aun_queue_lock
, flags
); 919 printk(KERN_DEBUG
"AUN: unknown sequence %ld\n", seq
); 923 tx_result(skb
->sk
, eb
->cookie
, result
); 925 spin_unlock_irqrestore(&aun_queue_lock
, flags
); 929 * Deal with received AUN frames - sort out what type of thing it is 930 * and hand it to the right function. 933 static voidaun_data_available(struct sock
*sk
,int slen
) 942 while((skb
=skb_recv_datagram(sk
,0,1, &err
)) == NULL
) { 944 printk(KERN_ERR
"AUN: no data available?!"); 947 printk(KERN_DEBUG
"AUN: recvfrom() error %d\n", -err
); 950 data
= skb
->h
.raw
+sizeof(struct udphdr
); 951 ah
= (struct aunhdr
*)data
; 952 len
= skb
->len
-sizeof(struct udphdr
); 958 aun_incoming(skb
, ah
, len
); 961 aun_tx_ack(ah
->handle
, ECTYPE_TRANSMIT_OK
); 964 aun_tx_ack(ah
->handle
, ECTYPE_TRANSMIT_NOT_LISTENING
); 967 /* This isn't quite right yet. */ 969 aun_send_response(ip
->saddr
, ah
->handle
,6, ah
->cb
); 973 printk(KERN_DEBUG
"unknown AUN packet (type %d)\n", data
[0]); 976 skb_free_datagram(sk
, skb
); 980 * Called by the timer to manage the AUN transmit queue. If a packet 981 * was sent to a dead or nonexistent host then we will never get an 982 * acknowledgement back. After a few seconds we need to spot this and 987 static voidab_cleanup(unsigned long h
) 992 spin_lock_irqsave(&aun_queue_lock
, flags
); 993 skb
=skb_peek(&aun_queue
); 994 while(skb
&& skb
!= (struct sk_buff
*)&aun_queue
) 996 struct sk_buff
*newskb
= skb
->next
; 997 struct ec_cb
*eb
= (struct ec_cb
*)&skb
->cb
; 998 if((jiffies
- eb
->start
) > eb
->timeout
) 1000 tx_result(skb
->sk
, eb
->cookie
, 1001 ECTYPE_TRANSMIT_NOT_PRESENT
); 1006 spin_unlock_irqrestore(&aun_queue_lock
, flags
); 1008 mod_timer(&ab_cleanup_timer
, jiffies
+ (HZ
*2)); 1011 static int __init
aun_udp_initialise(void) 1014 struct sockaddr_in sin
; 1016 skb_queue_head_init(&aun_queue
); 1017 spin_lock_init(&aun_queue_lock
); 1018 init_timer(&ab_cleanup_timer
); 1019 ab_cleanup_timer
.expires
= jiffies
+ (HZ
*2); 1020 ab_cleanup_timer
.function
= ab_cleanup
; 1021 add_timer(&ab_cleanup_timer
); 1023 memset(&sin
,0,sizeof(sin
)); 1024 sin
.sin_port
=htons(AUN_PORT
); 1026 /* We can count ourselves lucky Acorn machines are too dim to 1028 if((error
=sock_create(PF_INET
, SOCK_DGRAM
,0, &udpsock
)) <0) 1030 printk("AUN: socket error %d\n", -error
); 1034 udpsock
->sk
->reuse
=1; 1035 udpsock
->sk
->allocation
= GFP_ATOMIC
;/* we're going to call it 1038 error
= udpsock
->ops
->bind(udpsock
, (struct sockaddr
*)&sin
, 1042 printk("AUN: bind error %d\n", -error
); 1046 udpsock
->sk
->data_ready
= aun_data_available
; 1051 sock_release(udpsock
); 1057 static inteconet_notifier(struct notifier_block
*this,unsigned long msg
,void*data
) 1059 struct net_device
*dev
= (struct net_device
*)data
; 1060 struct ec_device
*edev
; 1061 unsigned long flags
; 1064 case NETDEV_UNREGISTER
: 1065 /* A device has gone down - kill any data we hold for it. */ 1066 spin_lock_irqsave(&edevlist_lock
, flags
); 1067 for(edev
= edevlist
; edev
; edev
= edev
->next
) 1069 if(edev
->dev
== dev
) 1072 edev
->prev
->next
= edev
->next
; 1074 edevlist
= edev
->next
; 1076 edev
->next
->prev
= edev
->prev
; 1081 spin_unlock_irqrestore(&edevlist_lock
, flags
); 1088 struct notifier_block econet_netdev_notifier
={ 1095 voidcleanup_module(void) 1097 #ifdef CONFIG_ECONET_AUNUDP 1098 del_timer(&ab_cleanup_timer
); 1100 sock_release(udpsock
); 1102 unregister_netdevice_notifier(&econet_netdev_notifier
); 1103 sock_unregister(econet_family_ops
.family
); 1107 intinit_module(void) 1109 void __init
econet_proto_init(struct net_proto
*pro
) 1112 spin_lock_init(&edevlist_lock
); 1113 spin_lock_init(&aun_queue_lock
); 1114 /* Stop warnings from happening on UP systems. */ 1115 (void)edevlist_lock
; 1116 (void)aun_queue_lock
; 1117 sock_register(&econet_family_ops
); 1118 #ifdef CONFIG_ECONET_AUNUDP 1119 aun_udp_initialise(); 1121 register_netdevice_notifier(&econet_netdev_notifier
);