1 /*****************************************************************************
2 * af_wanpipe.c WANPIPE(tm) Secure Socket Layer.
4 * Author: Nenad Corbic <ncorbic@sangoma.com>
6 * Copyright: (c) 2000 Sangoma Technologies Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 * ============================================================================
14 * Wanpipe socket layer is based on Packet and
15 * the X25 socket layers. The above sockets were
16 * used for the specific use of Sangoma Technoloiges
18 * Packet socket Authors: Ross Biro, Fred N. van Kempen and
20 * X25 socket Author: Jonathan Naylor.
21 * ============================================================================
22 * Mar 15, 2002 Arnaldo C. Melo o Use wp_sk()->num, as it isnt anymore in sock
23 * Apr 25, 2000 Nenad Corbic o Added the ability to send zero length packets.
24 * Mar 13, 2000 Nenad Corbic o Added a tx buffer check via ioctl call.
25 * Mar 06, 2000 Nenad Corbic o Fixed the corrupt sock lcn problem.
26 * Server and client applicaton can run
27 * simultaneously without conflicts.
28 * Feb 29, 2000 Nenad Corbic o Added support for PVC protocols, such as
29 * CHDLC, Frame Relay and HDLC API.
30 * Jan 17, 2000 Nenad Corbic o Initial version, based on AF_PACKET socket.
31 * X25API support only.
33 ******************************************************************************/
35 #include <linux/config.h>
36 #include <linux/types.h>
37 #include <linux/sched.h>
39 #include <linux/capability.h>
40 #include <linux/fcntl.h>
41 #include <linux/socket.h>
43 #include <linux/inet.h>
44 #include <linux/netdevice.h>
45 #include <linux/poll.h>
46 #include <linux/wireless.h>
47 #include <linux/kmod.h>
49 #include <net/protocol.h>
50 #include <linux/skbuff.h>
52 #include <linux/errno.h>
53 #include <linux/timer.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
56 #include <linux/module.h>
57 #include <linux/init.h>
58 #include <linux/wanpipe.h>
59 #include <linux/if_wanpipe.h>
60 #include <linux/pkt_sched.h>
61 #include <linux/tcp_states.h>
62 #include <linux/if_wanpipe_common.h>
63 #include <linux/sdla_x25.h>
66 #include <net/inet_common.h>
69 #define SLOW_BACKOFF 0.1*HZ
70 #define FAST_BACKOFF 0.01*HZ
74 #define DBG_PRINTK(format, a...) printk(format, ## a)
76 #define DBG_PRINTK(format, a...)
80 /* SECURE SOCKET IMPLEMENTATION
84 * When the user sends a packet via send() system call
85 * the wanpipe_sendmsg() function is executed.
87 * Each packet is enqueud into sk->sk_write_queue transmit
88 * queue. When the packet is enqueued, a delayed transmit
89 * timer is triggerd which acts as a Bottom Half hander.
91 * wanpipe_delay_transmit() function (BH), dequeues packets
92 * from the sk->sk_write_queue transmit queue and sends it
93 * to the deriver via dev->hard_start_xmit(skb, dev) function.
94 * Note, this function is actual a function pointer of if_send()
95 * routine in the wanpipe driver.
97 * X25API GUARANTEED DELIVERY:
99 * In order to provide 100% guaranteed packet delivery,
100 * an atomic 'packet_sent' counter is implemented. Counter
101 * is incremented for each packet enqueued
102 * into sk->sk_write_queue. Counter is decremented each
103 * time wanpipe_delayed_transmit() function successfuly
104 * passes the packet to the driver. Before each send(), a poll
105 * routine checks the sock resources The maximum value of
106 * packet sent counter is 1, thus if one packet is queued, the
107 * application will block until that packet is passed to the
112 * Wanpipe device drivers call the socket bottom half
113 * function, wanpipe_rcv() to queue the incoming packets
114 * into an AF_WANPIPE socket queue. Based on wanpipe_rcv()
115 * return code, the driver knows whether the packet was
116 * successfully queued. If the socket queue is full,
117 * protocol flow control is used by the driver, if any,
118 * to slow down the traffic until the sock queue is free.
120 * Every time a packet arrives into a socket queue the
121 * socket wakes up processes which are waiting to receive
124 * If the socket queue is full, the driver sets a block
125 * bit which signals the socket to kick the wanpipe driver
126 * bottom half hander when the socket queue is partialy
127 * empty. wanpipe_recvmsg() function performs this action.
129 * In case of x25api, packets will never be dropped, since
130 * flow control is available.
132 * In case of streaming protocols like CHDLC, packets will
133 * be dropped but the statistics will be generated.
137 /* The code below is used to test memory leaks. It prints out
138 * a message every time kmalloc and kfree system calls get executed.
139 * If the calls match there is no leak :)
142 /***********FOR DEBUGGING PURPOSES*********************************************
143 #define KMEM_SAFETYZONE 8
145 static void * dbg_kmalloc(unsigned int size, int prio, int line) {
146 void * v = kmalloc(size,prio);
147 printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
150 static void dbg_kfree(void * v, int line) {
151 printk(KERN_INFO "line %d kfree(%p)\n",line,v);
155 #define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
156 #define kfree(x) dbg_kfree(x,__LINE__)
157 ******************************************************************************/
160 /* List of all wanpipe sockets. */
161 HLIST_HEAD(wanpipe_sklist
);
162 static DEFINE_RWLOCK(wanpipe_sklist_lock
);
164 atomic_t wanpipe_socks_nr
;
165 static unsigned long wanpipe_tx_critical
;
168 /* Private wanpipe socket structures. */
171 void *mbox
; /* Mail box */
172 void *card
; /* Card bouded to */
173 struct net_device
*dev
; /* Bounded device */
174 unsigned short lcn
; /* Binded LCN */
175 unsigned char svc
; /* 0=pvc, 1=svc */
176 unsigned char timer
; /* flag for delayed transmit*/
177 struct timer_list tx_timer
;
179 unsigned char force
; /* Used to force sock release */
180 atomic_t packet_sent
;
185 extern const struct proto_ops wanpipe_ops
;
186 static unsigned long find_free_critical
;
188 static void wanpipe_unlink_driver(struct sock
*sk
);
189 static void wanpipe_link_driver(struct net_device
*dev
, struct sock
*sk
);
190 static void wanpipe_wakeup_driver(struct sock
*sk
);
191 static int execute_command(struct sock
*, unsigned char, unsigned int);
192 static int check_dev(struct net_device
*dev
, sdla_t
*card
);
193 struct net_device
*wanpipe_find_free_dev(sdla_t
*card
);
194 static void wanpipe_unlink_card (struct sock
*);
195 static int wanpipe_link_card (struct sock
*);
196 static struct sock
*wanpipe_make_new(struct sock
*);
197 static struct sock
*wanpipe_alloc_socket(void);
198 static inline int get_atomic_device(struct net_device
*dev
);
199 static int wanpipe_exec_cmd(struct sock
*, int, unsigned int);
200 static int get_ioctl_cmd (struct sock
*, void *);
201 static int set_ioctl_cmd (struct sock
*, void *);
202 static void release_device(struct net_device
*dev
);
203 static void wanpipe_kill_sock_timer (unsigned long data
);
204 static void wanpipe_kill_sock_irq (struct sock
*);
205 static void wanpipe_kill_sock_accept (struct sock
*);
206 static int wanpipe_do_bind(struct sock
*sk
, struct net_device
*dev
,
208 struct sock
* get_newsk_from_skb (struct sk_buff
*);
209 static int wanpipe_debug (struct sock
*, void *);
210 static void wanpipe_delayed_transmit (unsigned long data
);
211 static void release_driver(struct sock
*);
212 static void start_cleanup_timer (struct sock
*);
213 static void check_write_queue(struct sock
*);
214 static int check_driver_busy (struct sock
*);
216 /*============================================================
219 * Wanpipe socket bottom half handler. This function
220 * is called by the WANPIPE device drivers to queue a
221 * incoming packet into the socket receive queue.
222 * Once the packet is queued, all processes waiting to
225 * During socket bind, this function is bounded into
226 * WANPIPE driver private.
227 *===========================================================*/
229 static int wanpipe_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
232 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)skb
->cb
;
233 wanpipe_common_t
*chan
= dev
->priv
;
235 * When we registered the protocol we saved the socket in the data
236 * field for just this event.
241 sll
->sll_family
= AF_WANPIPE
;
242 sll
->sll_hatype
= dev
->type
;
243 sll
->sll_protocol
= skb
->protocol
;
244 sll
->sll_pkttype
= skb
->pkt_type
;
245 sll
->sll_ifindex
= dev
->ifindex
;
248 if (dev
->hard_header_parse
)
249 sll
->sll_halen
= dev
->hard_header_parse(skb
, sll
->sll_addr
);
252 * WAN_PACKET_DATA : Data which should be passed up the receive queue.
253 * WAN_PACKET_ASYC : Asynchronous data like place call, which should
254 * be passed up the listening sock.
255 * WAN_PACKET_ERR : Asynchronous data like clear call or restart
256 * which should go into an error queue.
258 switch (skb
->pkt_type
){
260 case WAN_PACKET_DATA
:
261 if (sock_queue_rcv_skb(sk
,skb
)<0){
266 sk
->sk_state
= chan
->state
;
267 /* Bug fix: update Mar6.
268 * Do not set the sock lcn number here, since
269 * cmd is not guaranteed to be executed on the
270 * board, thus Lcn could be wrong */
271 sk
->sk_data_ready(sk
, skb
->len
);
275 sk
->sk_state
= chan
->state
;
276 if (sock_queue_err_skb(sk
,skb
)<0){
281 printk(KERN_INFO
"wansock: BH Illegal Packet Type Dropping\n");
286 //??????????????????????
287 // if (sk->sk_state == WANSOCK_DISCONNECTED){
288 // if (sk->sk_zapped) {
289 // //printk(KERN_INFO "wansock: Disconnected, killing early\n");
290 // wanpipe_unlink_driver(sk);
291 // sk->sk_bound_dev_if = 0;
298 /*============================================================
301 * Wanpipe LISTEN socket bottom half handler. This function
302 * is called by the WANPIPE device drivers to queue an
303 * incoming call into the socket listening queue.
304 * Once the packet is queued, the waiting accept() process
307 * During socket bind, this function is bounded into
308 * WANPIPE driver private.
311 * The accept call() is waiting for an skb packet
312 * which contains a pointer to a device structure.
314 * When we do a bind to a device structre, we
315 * bind a newly created socket into "chan->sk". Thus,
316 * when accept receives the skb packet, it will know
317 * from which dev it came form, and in turn it will know
318 * the address of the new sock.
320 * NOTE: This function gets called from driver ISR.
321 *===========================================================*/
323 static int wanpipe_listen_rcv (struct sk_buff
*skb
, struct sock
*sk
)
325 wanpipe_opt
*wp
= wp_sk(sk
), *newwp
;
326 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)skb
->cb
;
328 struct net_device
*dev
;
330 mbox_cmd_t
*mbox_ptr
;
331 wanpipe_common_t
*chan
;
333 /* Find a free device, if none found, all svc's are busy
336 card
= (sdla_t
*)wp
->card
;
338 printk(KERN_INFO
"wansock: LISTEN ERROR, No Card\n");
342 dev
= wanpipe_find_free_dev(card
);
344 printk(KERN_INFO
"wansock: LISTEN ERROR, No Free Device\n");
349 chan
->state
= WANSOCK_CONNECTING
;
351 /* Allocate a new sock, which accept will bind
352 * and pass up to the user
354 if ((newsk
= wanpipe_make_new(sk
)) == NULL
){
360 /* Initialize the new sock structure
362 newsk
->sk_bound_dev_if
= dev
->ifindex
;
363 newwp
= wp_sk(newsk
);
364 newwp
->card
= wp
->card
;
366 /* Insert the sock into the main wanpipe
369 atomic_inc(&wanpipe_socks_nr
);
371 /* Allocate and fill in the new Mail Box. Then
372 * bind the mail box to the sock. It will be
373 * used by the ioctl call to read call information
374 * and to execute commands.
376 if ((mbox_ptr
= kmalloc(sizeof(mbox_cmd_t
), GFP_ATOMIC
)) == NULL
) {
377 wanpipe_kill_sock_irq (newsk
);
381 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
382 memcpy(mbox_ptr
,skb
->data
,skb
->len
);
384 /* Register the lcn on which incoming call came
385 * from. Thus, if we have to clear it, we know
389 newwp
->lcn
= mbox_ptr
->cmd
.lcn
;
390 newwp
->mbox
= (void *)mbox_ptr
;
392 DBG_PRINTK(KERN_INFO
"NEWSOCK : Device %s, bind to lcn %i\n",
393 dev
->name
,mbox_ptr
->cmd
.lcn
);
395 chan
->lcn
= mbox_ptr
->cmd
.lcn
;
396 card
->u
.x
.svc_to_dev_map
[(chan
->lcn
%MAX_X25_LCN
)] = dev
;
398 sock_reset_flag(newsk
, SOCK_ZAPPED
);
399 newwp
->num
= htons(X25_PROT
);
401 if (wanpipe_do_bind(newsk
, dev
, newwp
->num
)) {
402 wanpipe_kill_sock_irq (newsk
);
406 newsk
->sk_state
= WANSOCK_CONNECTING
;
409 /* Fill in the standard sock address info */
411 sll
->sll_family
= AF_WANPIPE
;
412 sll
->sll_hatype
= dev
->type
;
413 sll
->sll_protocol
= skb
->protocol
;
414 sll
->sll_pkttype
= skb
->pkt_type
;
415 sll
->sll_ifindex
= dev
->ifindex
;
419 sk
->sk_ack_backlog
++;
421 /* We must do this manually, since the sock_queue_rcv_skb()
422 * function sets the skb->dev to NULL. However, we use
423 * the dev field in the accept function.*/
424 if (atomic_read(&sk
->sk_rmem_alloc
) + skb
->truesize
>=
425 (unsigned)sk
->sk_rcvbuf
) {
427 wanpipe_unlink_driver(newsk
);
428 wanpipe_kill_sock_irq (newsk
);
429 --sk
->sk_ack_backlog
;
433 skb_set_owner_r(skb
, sk
);
434 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
435 sk
->sk_data_ready(sk
, skb
->len
);
442 /*============================================================
445 * Create a new sock, and allocate a wanpipe private
446 * structure to it. Also, copy the important data
447 * from the original sock to the new sock.
449 * This function is used by wanpipe_listen_rcv() listen
450 * bottom half handler. A copy of the listening sock
451 * is created using this function.
453 *===========================================================*/
455 static struct sock
*wanpipe_make_new(struct sock
*osk
)
459 if (osk
->sk_type
!= SOCK_RAW
)
462 if ((sk
= wanpipe_alloc_socket()) == NULL
)
465 sk
->sk_type
= osk
->sk_type
;
466 sk
->sk_socket
= osk
->sk_socket
;
467 sk
->sk_priority
= osk
->sk_priority
;
468 sk
->sk_protocol
= osk
->sk_protocol
;
469 wp_sk(sk
)->num
= wp_sk(osk
)->num
;
470 sk
->sk_rcvbuf
= osk
->sk_rcvbuf
;
471 sk
->sk_sndbuf
= osk
->sk_sndbuf
;
472 sk
->sk_state
= WANSOCK_CONNECTING
;
473 sk
->sk_sleep
= osk
->sk_sleep
;
475 if (sock_flag(osk
, SOCK_DBG
))
476 sock_set_flag(sk
, SOCK_DBG
);
482 * FIXME: wanpipe_opt has to include a sock in its definition and stop using
483 * sk_protinfo, but this code is not even compilable now, so lets leave it for
486 static struct proto wanpipe_proto
= {
488 .owner
= THIS_MODULE
,
489 .obj_size
= sizeof(struct sock
),
492 /*============================================================
495 * Allocate memory for the a new sock, and sock
498 * Increment the module use count.
500 * This function is used by wanpipe_create() and
501 * wanpipe_make_new() functions.
503 *===========================================================*/
505 static struct sock
*wanpipe_alloc_socket(void)
508 struct wanpipe_opt
*wan_opt
;
510 if ((sk
= sk_alloc(PF_WANPIPE
, GFP_ATOMIC
, &wanpipe_proto
, 1)) == NULL
)
513 if ((wan_opt
= kmalloc(sizeof(struct wanpipe_opt
), GFP_ATOMIC
)) == NULL
) {
517 memset(wan_opt
, 0x00, sizeof(struct wanpipe_opt
));
521 /* Use timer to send data to the driver. This will act
522 * as a BH handler for sendmsg functions */
523 init_timer(&wan_opt
->tx_timer
);
524 wan_opt
->tx_timer
.data
= (unsigned long)sk
;
525 wan_opt
->tx_timer
.function
= wanpipe_delayed_transmit
;
527 sock_init_data(NULL
, sk
);
532 /*============================================================
535 * This function implements a sendto() system call,
536 * for AF_WANPIPE socket family.
537 * During socket bind() sk->sk_bound_dev_if is initialized
538 * to a correct network device. This number is used
539 * to find a network device to which the packet should
542 * Each packet is queued into sk->sk_write_queue and
543 * delayed transmit bottom half handler is marked for
546 * A socket must be in WANSOCK_CONNECTED state before
547 * a packet is queued into sk->sk_write_queue.
548 *===========================================================*/
550 static int wanpipe_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
551 struct msghdr
*msg
, int len
)
554 struct sock
*sk
= sock
->sk
;
555 struct wan_sockaddr_ll
*saddr
=(struct wan_sockaddr_ll
*)msg
->msg_name
;
557 struct net_device
*dev
;
558 unsigned short proto
;
560 int ifindex
, err
, reserve
= 0;
563 if (!sock_flag(sk
, SOCK_ZAPPED
))
566 if (sk
->sk_state
!= WANSOCK_CONNECTED
)
569 if (msg
->msg_flags
& ~(MSG_DONTWAIT
|MSG_CMSG_COMPAT
))
572 /* it was <=, now one can send
573 * zero length packets */
574 if (len
< sizeof(x25api_hdr_t
))
580 ifindex
= sk
->sk_bound_dev_if
;
585 if (msg
->msg_namelen
< sizeof(struct wan_sockaddr_ll
)){
589 ifindex
= sk
->sk_bound_dev_if
;
590 proto
= saddr
->sll_protocol
;
591 addr
= saddr
->sll_addr
;
594 dev
= dev_get_by_index(ifindex
);
596 printk(KERN_INFO
"wansock: Send failed, dev index: %i\n",ifindex
);
601 if (sock
->type
== SOCK_RAW
)
602 reserve
= dev
->hard_header_len
;
604 if (len
> dev
->mtu
+reserve
){
608 skb
= sock_alloc_send_skb(sk
, len
+ LL_RESERVED_SPACE(dev
),
609 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
615 skb_reserve(skb
, LL_RESERVED_SPACE(dev
));
616 skb
->nh
.raw
= skb
->data
;
618 /* Returns -EFAULT on error */
619 err
= memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
);
624 if (dev
->hard_header
) {
627 res
= dev
->hard_header(skb
, dev
, ntohs(proto
), addr
, NULL
, len
);
633 skb
->protocol
= proto
;
635 skb
->priority
= sk
->sk_priority
;
636 skb
->pkt_type
= WAN_PACKET_DATA
;
639 if (!(dev
->flags
& IFF_UP
))
642 if (atomic_read(&sk
->sk_wmem_alloc
) + skb
->truesize
>
643 (unsigned int)sk
->sk_sndbuf
){
648 skb_queue_tail(&sk
->sk_write_queue
,skb
);
649 atomic_inc(&wp
->packet_sent
);
651 if (!(test_and_set_bit(0, &wp
->timer
)))
652 mod_timer(&wp
->tx_timer
, jiffies
+ 1);
662 /*============================================================
663 * wanpipe_delayed_tarnsmit
665 * Transmit bottom half handler. It dequeues packets
666 * from sk->sk_write_queue and passes them to the
667 * driver. If the driver is busy, the packet is
670 * Packet Sent counter is decremented on successful
672 *===========================================================*/
675 static void wanpipe_delayed_transmit (unsigned long data
)
677 struct sock
*sk
=(struct sock
*)data
;
679 wanpipe_opt
*wp
= wp_sk(sk
);
680 struct net_device
*dev
= wp
->dev
;
681 sdla_t
*card
= (sdla_t
*)wp
->card
;
684 clear_bit(0, &wp
->timer
);
685 DBG_PRINTK(KERN_INFO
"wansock: Transmit delay, no dev or card\n");
689 if (sk
->sk_state
!= WANSOCK_CONNECTED
|| !sock_flag(sk
, SOCK_ZAPPED
)) {
690 clear_bit(0, &wp
->timer
);
691 DBG_PRINTK(KERN_INFO
"wansock: Tx Timer, State not CONNECTED\n");
695 /* If driver is executing command, we must offload
696 * the board by not sending data. Otherwise a
697 * pending command will never get a free buffer
699 if (atomic_read(&card
->u
.x
.command_busy
)){
700 wp
->tx_timer
.expires
= jiffies
+ SLOW_BACKOFF
;
701 add_timer(&wp
->tx_timer
);
702 DBG_PRINTK(KERN_INFO
"wansock: Tx Timer, command bys BACKOFF\n");
707 if (test_and_set_bit(0,&wanpipe_tx_critical
)){
708 printk(KERN_INFO
"WanSock: Tx timer critical %s\n",dev
->name
);
709 wp
->tx_timer
.expires
= jiffies
+ SLOW_BACKOFF
;
710 add_timer(&wp
->tx_timer
);
714 /* Check for a packet in the fifo and send */
715 if ((skb
= skb_dequeue(&sk
->sk_write_queue
)) != NULL
){
717 if (dev
->hard_start_xmit(skb
, dev
) != 0){
719 /* Driver failed to transmit, re-enqueue
720 * the packet and retry again later */
721 skb_queue_head(&sk
->sk_write_queue
,skb
);
722 clear_bit(0,&wanpipe_tx_critical
);
726 /* Packet Sent successful. Check for more packets
727 * if more packets, re-trigger the transmit routine
730 atomic_dec(&wp
->packet_sent
);
732 if (skb_peek(&sk
->sk_write_queue
) == NULL
) {
733 /* If there is nothing to send, kick
734 * the poll routine, which will trigger
735 * the application to send more data */
736 sk
->sk_data_ready(sk
, 0);
737 clear_bit(0, &wp
->timer
);
739 /* Reschedule as fast as possible */
740 wp
->tx_timer
.expires
= jiffies
+ 1;
741 add_timer(&wp
->tx_timer
);
745 clear_bit(0,&wanpipe_tx_critical
);
748 /*============================================================
751 * Execute x25api commands. The atomic variable
752 * chan->command is used to indicate to the driver that
753 * command is pending for execution. The acutal command
754 * structure is placed into a sock mbox structure
757 * The sock private structure, mbox is
758 * used as shared memory between sock and the driver.
759 * Driver uses the sock mbox to execute the command
760 * and return the result.
762 * For all command except PLACE CALL, the function
763 * waits for the result. PLACE CALL can be ether
764 * blocking or nonblocking. The user sets this option
766 *===========================================================*/
769 static int execute_command(struct sock
*sk
, unsigned char cmd
, unsigned int flags
)
771 wanpipe_opt
*wp
= wp_sk(sk
);
772 struct net_device
*dev
;
773 wanpipe_common_t
*chan
=NULL
;
775 DECLARE_WAITQUEUE(wait
, current
);
777 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
779 printk(KERN_INFO
"wansock: Exec failed no dev %i\n",
780 sk
->sk_bound_dev_if
);
785 if ((chan
=dev
->priv
) == NULL
){
786 printk(KERN_INFO
"wansock: Exec cmd failed no priv area\n");
790 if (atomic_read(&chan
->command
)){
791 printk(KERN_INFO
"wansock: ERROR: Command already running %x, %s\n",
792 atomic_read(&chan
->command
),dev
->name
);
797 printk(KERN_INFO
"wansock: In execute without MBOX\n");
801 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.command
= cmd
;
802 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
= wp
->lcn
;
803 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.result
= 0x7F;
806 if (flags
& O_NONBLOCK
){
808 atomic_set(&chan
->command
, cmd
);
810 atomic_set(&chan
->command
, cmd
);
813 add_wait_queue(sk
->sk_sleep
,&wait
);
814 current
->state
= TASK_INTERRUPTIBLE
;
816 if (((mbox_cmd_t
*)wp
->mbox
)->cmd
.result
!= 0x7F) {
820 if (signal_pending(current
)) {
826 current
->state
= TASK_RUNNING
;
827 remove_wait_queue(sk
->sk_sleep
,&wait
);
832 /*============================================================
833 * wanpipe_destroy_timer
835 * Used by wanpipe_release, to delay release of
837 *===========================================================*/
839 static void wanpipe_destroy_timer(unsigned long data
)
841 struct sock
*sk
=(struct sock
*)data
;
842 wanpipe_opt
*wp
= wp_sk(sk
);
844 if ((!atomic_read(&sk
->sk_wmem_alloc
) &&
845 !atomic_read(&sk
->sk_rmem_alloc
)) ||
846 (++wp
->force
== 5)) {
848 if (atomic_read(&sk
->sk_wmem_alloc
) ||
849 atomic_read(&sk
->sk_rmem_alloc
))
850 printk(KERN_INFO
"wansock: Warning, Packet Discarded due to sock shutdown!\n");
855 if (atomic_read(&sk
->sk_refcnt
) != 1) {
856 atomic_set(&sk
->sk_refcnt
, 1);
857 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :delay.\n",
858 atomic_read(&sk
->sk_refcnt
));
861 atomic_dec(&wanpipe_socks_nr
);
865 sk
->sk_timer
.expires
= jiffies
+ 5 * HZ
;
866 add_timer(&sk
->sk_timer
);
867 printk(KERN_INFO
"wansock: packet sk destroy delayed\n");
870 /*============================================================
871 * wanpipe_unlink_driver
873 * When the socket is released, this function is
874 * used to remove links that bind the sock and the
876 *===========================================================*/
877 static void wanpipe_unlink_driver (struct sock
*sk
)
879 struct net_device
*dev
;
880 wanpipe_common_t
*chan
=NULL
;
882 sock_reset_flag(sk
, SOCK_ZAPPED
);
883 sk
->sk_state
= WANSOCK_DISCONNECTED
;
884 wp_sk(sk
)->dev
= NULL
;
886 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
888 printk(KERN_INFO
"wansock: No dev on release\n");
893 if ((chan
= dev
->priv
) == NULL
){
894 printk(KERN_INFO
"wansock: No Priv Area on release\n");
898 set_bit(0,&chan
->common_critical
);
903 clear_bit(0,&chan
->common_critical
);
909 /*============================================================
910 * wanpipe_link_driver
912 * Upon successful bind(), sock is linked to a driver
913 * by binding in the wanpipe_rcv() bottom half handler
914 * to the driver function pointer, as well as sock and
915 * sock mailbox addresses. This way driver can pass
916 * data up the socket.
917 *===========================================================*/
919 static void wanpipe_link_driver(struct net_device
*dev
, struct sock
*sk
)
921 wanpipe_opt
*wp
= wp_sk(sk
);
922 wanpipe_common_t
*chan
= dev
->priv
;
925 set_bit(0,&chan
->common_critical
);
927 chan
->func
=wanpipe_rcv
;
928 chan
->mbox
= wp
->mbox
;
929 chan
->tx_timer
= &wp
->tx_timer
;
931 sock_set_flag(sk
, SOCK_ZAPPED
);
932 clear_bit(0,&chan
->common_critical
);
936 /*============================================================
939 * During sock release, clear a critical bit, which
940 * marks the device a being taken.
941 *===========================================================*/
944 static void release_device(struct net_device
*dev
)
946 wanpipe_common_t
*chan
=dev
->priv
;
947 clear_bit(0,(void*)&chan
->rw_bind
);
950 /*============================================================
953 * Close a PACKET socket. This is fairly simple. We
954 * immediately go to 'closed' state and remove our
955 * protocol entry in the device list.
956 *===========================================================*/
958 static int wanpipe_release(struct socket
*sock
)
961 struct sock
*sk
= sock
->sk
;
967 check_write_queue(sk
);
969 /* Kill the tx timer, if we don't kill it now, the timer
970 * will run after we kill the sock. Timer code will
971 * try to access the sock which has been killed and cause
974 del_timer(&wp
->tx_timer
);
977 * Unhook packet receive handler.
980 if (wp
->num
== htons(X25_PROT
) &&
981 sk
->sk_state
!= WANSOCK_DISCONNECTED
&& sock_flag(sk
, SOCK_ZAPPED
)) {
982 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
983 wanpipe_common_t
*chan
;
986 atomic_set(&chan
->disconnect
,1);
987 DBG_PRINTK(KERN_INFO
"wansock: Sending Clear Indication %i\n",
993 set_bit(1,&wanpipe_tx_critical
);
994 write_lock(&wanpipe_sklist_lock
);
995 sk_del_node_init(sk
);
996 write_unlock(&wanpipe_sklist_lock
);
997 clear_bit(1,&wanpipe_tx_critical
);
1005 * Now the socket is dead. No more input will appear.
1008 sk
->sk_state_change(sk
); /* It is useless. Just for sanity. */
1011 sk
->sk_socket
= NULL
;
1012 sock_set_flag(sk
, SOCK_DEAD
);
1015 skb_queue_purge(&sk
->sk_receive_queue
);
1016 skb_queue_purge(&sk
->sk_write_queue
);
1017 skb_queue_purge(&sk
->sk_error_queue
);
1019 if (atomic_read(&sk
->sk_rmem_alloc
) ||
1020 atomic_read(&sk
->sk_wmem_alloc
)) {
1021 del_timer(&sk
->sk_timer
);
1022 printk(KERN_INFO
"wansock: Killing in Timer R %i , W %i\n",
1023 atomic_read(&sk
->sk_rmem_alloc
),
1024 atomic_read(&sk
->sk_wmem_alloc
));
1025 sk
->sk_timer
.data
= (unsigned long)sk
;
1026 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1027 sk
->sk_timer
.function
= wanpipe_destroy_timer
;
1028 add_timer(&sk
->sk_timer
);
1035 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1036 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i !:release.\n",
1037 atomic_read(&sk
->sk_refcnt
));
1038 atomic_set(&sk
->sk_refcnt
, 1);
1041 atomic_dec(&wanpipe_socks_nr
);
1045 /*============================================================
1048 * During sock shutdown, if the sock state is
1049 * WANSOCK_CONNECTED and there is transmit data
1050 * pending. Wait until data is released
1051 * before proceeding.
1052 *===========================================================*/
1054 static void check_write_queue(struct sock
*sk
)
1057 if (sk
->sk_state
!= WANSOCK_CONNECTED
)
1060 if (!atomic_read(&sk
->sk_wmem_alloc
))
1063 printk(KERN_INFO
"wansock: MAJOR ERROR, Data lost on sock release !!!\n");
1067 /*============================================================
1070 * This function is called during sock shutdown, to
1071 * release any resources and links that bind the sock
1072 * to the driver. It also changes the state of the
1073 * sock to WANSOCK_DISCONNECTED
1074 *===========================================================*/
1076 static void release_driver(struct sock
*sk
)
1079 struct sk_buff
*skb
=NULL
;
1080 struct sock
*deadsk
=NULL
;
1082 if (sk
->sk_state
== WANSOCK_LISTEN
||
1083 sk
->sk_state
== WANSOCK_BIND_LISTEN
) {
1084 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
)) != NULL
) {
1085 if ((deadsk
= get_newsk_from_skb(skb
))){
1086 DBG_PRINTK (KERN_INFO
"wansock: RELEASE: FOUND DEAD SOCK\n");
1087 sock_set_flag(deadsk
, SOCK_DEAD
);
1088 start_cleanup_timer(deadsk
);
1092 if (sock_flag(sk
, SOCK_ZAPPED
))
1093 wanpipe_unlink_card(sk
);
1095 if (sock_flag(sk
, SOCK_ZAPPED
))
1096 wanpipe_unlink_driver(sk
);
1098 sk
->sk_state
= WANSOCK_DISCONNECTED
;
1099 sk
->sk_bound_dev_if
= 0;
1100 sock_reset_flag(sk
, SOCK_ZAPPED
);
1109 /*============================================================
1110 * start_cleanup_timer
1112 * If new incoming call's are pending but the socket
1113 * is being released, start the timer which will
1114 * envoke the kill routines for pending socks.
1115 *===========================================================*/
1118 static void start_cleanup_timer (struct sock
*sk
)
1120 del_timer(&sk
->sk_timer
);
1121 sk
->sk_timer
.data
= (unsigned long)sk
;
1122 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1123 sk
->sk_timer
.function
= wanpipe_kill_sock_timer
;
1124 add_timer(&sk
->sk_timer
);
1128 /*============================================================
1131 * This is a function which performs actual killing
1132 * of the sock. It releases socket resources,
1133 * and unlinks the sock from the driver.
1134 *===========================================================*/
1136 static void wanpipe_kill_sock_timer (unsigned long data
)
1139 struct sock
*sk
= (struct sock
*)data
;
1145 /* This function can be called from interrupt. We must use
1146 * appropriate locks */
1148 if (test_bit(1,&wanpipe_tx_critical
)){
1149 sk
->sk_timer
.expires
= jiffies
+ 10;
1150 add_timer(&sk
->sk_timer
);
1154 write_lock(&wanpipe_sklist_lock
);
1155 sk_del_node_init(sk
);
1156 write_unlock(&wanpipe_sklist_lock
);
1159 if (wp_sk(sk
)->num
== htons(X25_PROT
) &&
1160 sk
->sk_state
!= WANSOCK_DISCONNECTED
) {
1161 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1162 wanpipe_common_t
*chan
;
1165 atomic_set(&chan
->disconnect
,1);
1172 sk
->sk_socket
= NULL
;
1175 skb_queue_purge(&sk
->sk_receive_queue
);
1176 skb_queue_purge(&sk
->sk_write_queue
);
1177 skb_queue_purge(&sk
->sk_error_queue
);
1179 if (atomic_read(&sk
->sk_rmem_alloc
) ||
1180 atomic_read(&sk
->sk_wmem_alloc
)) {
1181 del_timer(&sk
->sk_timer
);
1182 printk(KERN_INFO
"wansock: Killing SOCK in Timer\n");
1183 sk
->sk_timer
.data
= (unsigned long)sk
;
1184 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1185 sk
->sk_timer
.function
= wanpipe_destroy_timer
;
1186 add_timer(&sk
->sk_timer
);
1193 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1194 atomic_set(&sk
->sk_refcnt
, 1);
1195 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :timer.\n",
1196 atomic_read(&sk
->sk_refcnt
));
1199 atomic_dec(&wanpipe_socks_nr
);
1203 static void wanpipe_kill_sock_accept (struct sock
*sk
)
1211 /* This function can be called from interrupt. We must use
1212 * appropriate locks */
1214 write_lock(&wanpipe_sklist_lock
);
1215 sk_del_node_init(sk
);
1216 write_unlock(&wanpipe_sklist_lock
);
1218 sk
->sk_socket
= NULL
;
1224 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1225 atomic_set(&sk
->sk_refcnt
, 1);
1226 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :timer.\n",
1227 atomic_read(&sk
->sk_refcnt
));
1230 atomic_dec(&wanpipe_socks_nr
);
1235 static void wanpipe_kill_sock_irq (struct sock
*sk
)
1241 sk
->sk_socket
= NULL
;
1246 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1247 atomic_set(&sk
->sk_refcnt
, 1);
1248 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i !:listen.\n",
1249 atomic_read(&sk
->sk_refcnt
));
1252 atomic_dec(&wanpipe_socks_nr
);
1256 /*============================================================
1259 * Bottom half of the binding system call.
1260 * Once the wanpipe_bind() function checks the
1261 * legality of the call, this function binds the
1262 * sock to the driver.
1263 *===========================================================*/
1265 static int wanpipe_do_bind(struct sock
*sk
, struct net_device
*dev
,
1268 wanpipe_opt
*wp
= wp_sk(sk
);
1269 wanpipe_common_t
*chan
=NULL
;
1272 if (sock_flag(sk
, SOCK_ZAPPED
)) {
1274 goto bind_unlock_exit
;
1280 release_device(dev
);
1282 goto bind_unlock_exit
;
1286 if (dev
->flags
&IFF_UP
) {
1288 sk
->sk_state
= chan
->state
;
1290 if (wp
->num
== htons(X25_PROT
) &&
1291 sk
->sk_state
!= WANSOCK_DISCONNECTED
&&
1292 sk
->sk_state
!= WANSOCK_CONNECTING
) {
1293 DBG_PRINTK(KERN_INFO
1294 "wansock: Binding to Device not DISCONNECTED %i\n",
1296 release_device(dev
);
1298 goto bind_unlock_exit
;
1301 wanpipe_link_driver(dev
,sk
);
1302 sk
->sk_bound_dev_if
= dev
->ifindex
;
1304 /* X25 Specific option */
1305 if (wp
->num
== htons(X25_PROT
))
1306 wp_sk(sk
)->svc
= chan
->svc
;
1309 sk
->sk_err
= ENETDOWN
;
1310 sk
->sk_error_report(sk
);
1311 release_device(dev
);
1318 /* FIXME where is this lock */
1323 /*============================================================
1326 * BIND() System call, which is bound to the AF_WANPIPE
1327 * operations structure. It checks for correct wanpipe
1328 * card name, and cross references interface names with
1329 * the card names. Thus, interface name must belong to
1331 *===========================================================*/
1334 static int wanpipe_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
1336 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)uaddr
;
1337 struct sock
*sk
=sock
->sk
;
1338 wanpipe_opt
*wp
= wp_sk(sk
);
1339 struct net_device
*dev
= NULL
;
1347 if (addr_len
< sizeof(struct wan_sockaddr_ll
)){
1348 printk(KERN_INFO
"wansock: Address length error\n");
1351 if (sll
->sll_family
!= AF_WANPIPE
){
1352 printk(KERN_INFO
"wansock: Illegal family name specified.\n");
1356 card
= wanpipe_find_card (sll
->sll_card
);
1358 printk(KERN_INFO
"wansock: Wanpipe card not found: %s\n",sll
->sll_card
);
1361 wp_sk(sk
)->card
= (void *)card
;
1364 if (!strcmp(sll
->sll_device
,"svc_listen")){
1366 /* Bind a sock to a card structure for listening
1370 /* This is x25 specific area if protocol doesn't
1371 * match, return error */
1372 if (sll
->sll_protocol
!= htons(X25_PROT
))
1375 err
= wanpipe_link_card (sk
);
1379 if (sll
->sll_protocol
)
1380 wp
->num
= sll
->sll_protocol
;
1381 sk
->sk_state
= WANSOCK_BIND_LISTEN
;
1384 }else if (!strcmp(sll
->sll_device
,"svc_connect")){
1386 /* This is x25 specific area if protocol doesn't
1387 * match, return error */
1388 if (sll
->sll_protocol
!= htons(X25_PROT
))
1391 /* Find a free device
1393 dev
= wanpipe_find_free_dev(card
);
1395 DBG_PRINTK(KERN_INFO
"wansock: No free network devices for card %s\n",
1400 /* Bind a socket to a interface name
1401 * This is used by PVC mostly
1403 strlcpy(name
,sll
->sll_device
,sizeof(name
));
1404 dev
= dev_get_by_name(name
);
1406 printk(KERN_INFO
"wansock: Failed to get Dev from name: %s,\n",
1413 if (check_dev(dev
, card
)){
1414 printk(KERN_INFO
"wansock: Device %s, doesn't belong to card %s\n",
1415 dev
->name
, card
->devname
);
1418 if (get_atomic_device (dev
))
1422 return wanpipe_do_bind(sk
, dev
, sll
->sll_protocol
? : wp
->num
);
1425 /*============================================================
1428 * Sets a bit atomically which indicates that
1429 * the interface is taken. This avoids race conditions.
1430 *===========================================================*/
1433 static inline int get_atomic_device(struct net_device
*dev
)
1435 wanpipe_common_t
*chan
= dev
->priv
;
1436 if (!test_and_set_bit(0,(void *)&chan
->rw_bind
)){
1442 /*============================================================
1445 * Check that device name belongs to a particular card.
1446 *===========================================================*/
1448 static int check_dev(struct net_device
*dev
, sdla_t
*card
)
1450 struct net_device
* tmp_dev
;
1452 for (tmp_dev
= card
->wandev
.dev
; tmp_dev
;
1453 tmp_dev
= *((struct net_device
**)tmp_dev
->priv
)) {
1454 if (tmp_dev
->ifindex
== dev
->ifindex
){
1461 /*============================================================
1462 * wanpipe_find_free_dev
1464 * Find a free network interface. If found set atomic
1465 * bit indicating that the interface is taken.
1467 *===========================================================*/
1469 struct net_device
*wanpipe_find_free_dev(sdla_t
*card
)
1471 struct net_device
* dev
;
1472 volatile wanpipe_common_t
*chan
;
1474 if (test_and_set_bit(0,&find_free_critical
)){
1475 printk(KERN_INFO
"CRITICAL in Find Free\n");
1478 for (dev
= card
->wandev
.dev
; dev
;
1479 dev
= *((struct net_device
**)dev
->priv
)) {
1483 if (chan
->usedby
== API
&& chan
->svc
){
1484 if (!get_atomic_device (dev
)){
1485 if (chan
->state
!= WANSOCK_DISCONNECTED
){
1486 release_device(dev
);
1488 clear_bit(0,&find_free_critical
);
1494 clear_bit(0,&find_free_critical
);
1498 /*============================================================
1501 * SOCKET() System call. It allocates a sock structure
1502 * and adds the socket to the wanpipe_sk_list.
1503 * Crates AF_WANPIPE socket.
1504 *===========================================================*/
1506 static int wanpipe_create(struct socket
*sock
, int protocol
)
1510 //FIXME: This checks for root user, SECURITY ?
1511 //if (!capable(CAP_NET_RAW))
1514 if (sock
->type
!= SOCK_DGRAM
&& sock
->type
!= SOCK_RAW
)
1515 return -ESOCKTNOSUPPORT
;
1517 sock
->state
= SS_UNCONNECTED
;
1519 if ((sk
= wanpipe_alloc_socket()) == NULL
)
1523 sock
->ops
= &wanpipe_ops
;
1524 sock_init_data(sock
,sk
);
1526 sock_reset_flag(sk
, SOCK_ZAPPED
);
1527 sk
->sk_family
= PF_WANPIPE
;
1528 wp_sk(sk
)->num
= protocol
;
1529 sk
->sk_state
= WANSOCK_DISCONNECTED
;
1530 sk
->sk_ack_backlog
= 0;
1531 sk
->sk_bound_dev_if
= 0;
1533 atomic_inc(&wanpipe_socks_nr
);
1535 /* We must disable interrupts because the ISR
1536 * can also change the list */
1537 set_bit(1,&wanpipe_tx_critical
);
1538 write_lock(&wanpipe_sklist_lock
);
1539 sk_add_node(sk
, &wanpipe_sklist
);
1540 write_unlock(&wanpipe_sklist_lock
);
1541 clear_bit(1,&wanpipe_tx_critical
);
1547 /*============================================================
1550 * Pull a packet from our receive queue and hand it
1551 * to the user. If necessary we block.
1552 *===========================================================*/
1554 static int wanpipe_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1555 struct msghdr
*msg
, int len
, int flags
)
1557 struct sock
*sk
= sock
->sk
;
1558 struct sk_buff
*skb
;
1559 int copied
, err
=-ENOBUFS
;
1563 * If the address length field is there to be filled in, we fill
1567 msg
->msg_namelen
= sizeof(struct wan_sockaddr_ll
);
1570 * Call the generic datagram receiver. This handles all sorts
1571 * of horrible races and re-entrancy so we can forget about it
1572 * in the protocol layers.
1574 * Now it will return ENETDOWN, if device have just gone down,
1575 * but then it will block.
1578 if (flags
& MSG_OOB
){
1579 skb
= skb_dequeue(&sk
->sk_error_queue
);
1581 skb
=skb_recv_datagram(sk
,flags
,1,&err
);
1584 * An error occurred so return it. Because skb_recv_datagram()
1585 * handles the blocking we don't see and worry about blocking
1593 * You lose any data beyond the buffer you gave. If it worries a
1594 * user program they can ask the device for its MTU anyway.
1601 msg
->msg_flags
|=MSG_TRUNC
;
1604 wanpipe_wakeup_driver(sk
);
1606 /* We can't use skb_copy_datagram here */
1607 err
= memcpy_toiovec(msg
->msg_iov
, skb
->data
, copied
);
1611 sock_recv_timestamp(msg
, sk
, skb
);
1614 memcpy(msg
->msg_name
, skb
->cb
, msg
->msg_namelen
);
1617 * Free or return the buffer as appropriate. Again this
1618 * hides all the races and re-entrancy issues from us.
1620 err
= (flags
&MSG_TRUNC
) ? skb
->len
: copied
;
1623 skb_free_datagram(sk
, skb
);
1629 /*============================================================
1630 * wanpipe_wakeup_driver
1632 * If socket receive buffer is full and driver cannot
1633 * pass data up the sock, it sets a packet_block flag.
1634 * This function check that flag and if sock receive
1635 * queue has room it kicks the driver BH handler.
1637 * This way, driver doesn't have to poll the sock
1639 *===========================================================*/
1641 static void wanpipe_wakeup_driver(struct sock
*sk
)
1643 struct net_device
*dev
= NULL
;
1644 wanpipe_common_t
*chan
=NULL
;
1646 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1652 if ((chan
= dev
->priv
) == NULL
)
1655 if (atomic_read(&chan
->receive_block
)){
1656 if (atomic_read(&sk
->sk_rmem_alloc
) <
1657 ((unsigned)sk
->sk_rcvbuf
* 0.9)) {
1658 printk(KERN_INFO
"wansock: Queuing task for wanpipe\n");
1659 atomic_set(&chan
->receive_block
,0);
1660 wanpipe_queue_tq(&chan
->wanpipe_task
);
1666 /*============================================================
1669 * I don't know what to do with this yet.
1670 * User can use this function to get sock address
1671 * information. Not very useful for Sangoma's purposes.
1672 *===========================================================*/
1675 static int wanpipe_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
1676 int *uaddr_len
, int peer
)
1678 struct net_device
*dev
;
1679 struct sock
*sk
= sock
->sk
;
1680 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)uaddr
;
1682 sll
->sll_family
= AF_WANPIPE
;
1683 sll
->sll_ifindex
= sk
->sk_bound_dev_if
;
1684 sll
->sll_protocol
= wp_sk(sk
)->num
;
1685 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1687 sll
->sll_hatype
= dev
->type
;
1688 sll
->sll_halen
= dev
->addr_len
;
1689 memcpy(sll
->sll_addr
, dev
->dev_addr
, dev
->addr_len
);
1691 sll
->sll_hatype
= 0; /* Bad: we have no ARPHRD_UNSPEC */
1694 *uaddr_len
= sizeof(*sll
);
1701 /*============================================================
1704 * If driver turns off network interface, this function
1705 * will be envoked. Currently I treate it as a
1706 * call disconnect. More thought should go into this
1709 * FIXME: More thought should go into this function.
1711 *===========================================================*/
1713 static int wanpipe_notifier(struct notifier_block
*this, unsigned long msg
, void *data
)
1717 struct net_device
*dev
= (struct net_device
*)data
;
1719 sk_for_each(sk
, node
, &wanpipe_sklist
) {
1720 struct wanpipe_opt
*po
= wp_sk(sk
);
1729 case NETDEV_UNREGISTER
:
1730 if (dev
->ifindex
== sk
->sk_bound_dev_if
) {
1731 printk(KERN_INFO
"wansock: Device down %s\n",dev
->name
);
1732 if (sock_flag(sk
, SOCK_ZAPPED
)) {
1733 wanpipe_unlink_driver(sk
);
1734 sk
->sk_err
= ENETDOWN
;
1735 sk
->sk_error_report(sk
);
1738 if (msg
== NETDEV_UNREGISTER
) {
1739 printk(KERN_INFO
"wansock: Unregistering Device: %s\n",
1741 wanpipe_unlink_driver(sk
);
1742 sk
->sk_bound_dev_if
= 0;
1747 if (dev
->ifindex
== sk
->sk_bound_dev_if
&&
1748 po
->num
&& !sock_flag(sk
, SOCK_ZAPPED
)) {
1749 printk(KERN_INFO
"wansock: Registering Device: %s\n",
1751 wanpipe_link_driver(dev
,sk
);
1759 /*============================================================
1762 * Execute a user commands, and set socket options.
1764 * FIXME: More thought should go into this function.
1766 *===========================================================*/
1768 static int wanpipe_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1770 struct sock
*sk
= sock
->sk
;
1776 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
1778 case SIOC_WANPIPE_CHECK_TX
:
1780 return atomic_read(&sk
->sk_wmem_alloc
);
1782 case SIOC_WANPIPE_SOCK_STATE
:
1784 if (sk
->sk_state
== WANSOCK_CONNECTED
)
1790 case SIOC_WANPIPE_GET_CALL_DATA
:
1792 return get_ioctl_cmd (sk
,(void*)arg
);
1794 case SIOC_WANPIPE_SET_CALL_DATA
:
1796 return set_ioctl_cmd (sk
,(void*)arg
);
1798 case SIOC_WANPIPE_ACCEPT_CALL
:
1799 case SIOC_WANPIPE_CLEAR_CALL
:
1800 case SIOC_WANPIPE_RESET_CALL
:
1802 if ((err
=set_ioctl_cmd(sk
,(void*)arg
)) < 0)
1805 err
=wanpipe_exec_cmd(sk
,cmd
,0);
1806 get_ioctl_cmd(sk
,(void*)arg
);
1809 case SIOC_WANPIPE_DEBUG
:
1811 return wanpipe_debug(sk
,(void*)arg
);
1813 case SIOC_WANPIPE_SET_NONBLOCK
:
1815 if (sk
->sk_state
!= WANSOCK_DISCONNECTED
)
1818 sock
->file
->f_flags
|= O_NONBLOCK
;
1832 case SIOCGIFBRDADDR
:
1833 case SIOCSIFBRDADDR
:
1834 case SIOCGIFNETMASK
:
1835 case SIOCSIFNETMASK
:
1836 case SIOCGIFDSTADDR
:
1837 case SIOCSIFDSTADDR
:
1839 return inet_dgram_ops
.ioctl(sock
, cmd
, arg
);
1843 return -ENOIOCTLCMD
;
1848 /*============================================================
1851 * This function will pass up information about all
1854 * FIXME: More thought should go into this function.
1856 *===========================================================*/
1858 static int wanpipe_debug (struct sock
*origsk
, void *arg
)
1861 struct hlist_node
*node
;
1862 struct net_device
*dev
= NULL
;
1863 wanpipe_common_t
*chan
=NULL
;
1865 wan_debug_t
*dbg_data
= (wan_debug_t
*)arg
;
1867 sk_for_each(sk
, node
, &wanpipe_sklist
) {
1868 wanpipe_opt
*wp
= wp_sk(sk
);
1874 if ((err
=put_user(1, &dbg_data
->debug
[cnt
].free
)))
1876 if ((err
= put_user(sk
->sk_state
,
1877 &dbg_data
->debug
[cnt
].state_sk
)))
1879 if ((err
= put_user(sk
->sk_rcvbuf
,
1880 &dbg_data
->debug
[cnt
].rcvbuf
)))
1882 if ((err
= put_user(atomic_read(&sk
->sk_rmem_alloc
),
1883 &dbg_data
->debug
[cnt
].rmem
)))
1885 if ((err
= put_user(atomic_read(&sk
->sk_wmem_alloc
),
1886 &dbg_data
->debug
[cnt
].wmem
)))
1888 if ((err
= put_user(sk
->sk_sndbuf
,
1889 &dbg_data
->debug
[cnt
].sndbuf
)))
1891 if ((err
=put_user(sk_count
, &dbg_data
->debug
[cnt
].sk_count
)))
1893 if ((err
=put_user(wp
->poll_cnt
, &dbg_data
->debug
[cnt
].poll_cnt
)))
1895 if ((err
= put_user(sk
->sk_bound_dev_if
,
1896 &dbg_data
->debug
[cnt
].bound
)))
1899 if (sk
->sk_bound_dev_if
) {
1900 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1907 if ((err
=put_user(chan
->state
, &dbg_data
->debug
[cnt
].d_state
)))
1909 if ((err
=put_user(chan
->svc
, &dbg_data
->debug
[cnt
].svc
)))
1912 if ((err
=put_user(atomic_read(&chan
->command
),
1913 &dbg_data
->debug
[cnt
].command
)))
1918 sdla_t
*card
= (sdla_t
*)wp
->card
;
1921 if ((err
=put_user(atomic_read(&card
->u
.x
.command_busy
),
1922 &dbg_data
->debug
[cnt
].cmd_busy
)))
1926 if ((err
=put_user(wp
->lcn
,
1927 &dbg_data
->debug
[cnt
].lcn
)))
1931 if ((err
=put_user(1, &dbg_data
->debug
[cnt
].mbox
)))
1936 if ((err
=put_user(atomic_read(&chan
->receive_block
),
1937 &dbg_data
->debug
[cnt
].rblock
)))
1940 if (copy_to_user(dbg_data
->debug
[cnt
].name
, dev
->name
, strlen(dev
->name
)))
1944 if (++cnt
== MAX_NUM_DEBUG
)
1950 /*============================================================
1953 * Pass up the contents of socket MBOX to the user.
1954 *===========================================================*/
1956 static int get_ioctl_cmd (struct sock
*sk
, void *arg
)
1958 x25api_t
*usr_data
= (x25api_t
*)arg
;
1959 mbox_cmd_t
*mbox_ptr
;
1962 if (usr_data
== NULL
)
1965 if (!wp_sk(sk
)->mbox
) {
1969 mbox_ptr
= (mbox_cmd_t
*)wp_sk(sk
)->mbox
;
1971 if ((err
=put_user(mbox_ptr
->cmd
.qdm
, &usr_data
->hdr
.qdm
)))
1973 if ((err
=put_user(mbox_ptr
->cmd
.cause
, &usr_data
->hdr
.cause
)))
1975 if ((err
=put_user(mbox_ptr
->cmd
.diagn
, &usr_data
->hdr
.diagn
)))
1977 if ((err
=put_user(mbox_ptr
->cmd
.length
, &usr_data
->hdr
.length
)))
1979 if ((err
=put_user(mbox_ptr
->cmd
.result
, &usr_data
->hdr
.result
)))
1981 if ((err
=put_user(mbox_ptr
->cmd
.lcn
, &usr_data
->hdr
.lcn
)))
1984 if (mbox_ptr
->cmd
.length
> 0){
1985 if (mbox_ptr
->cmd
.length
> X25_MAX_DATA
)
1988 if (copy_to_user(usr_data
->data
, mbox_ptr
->data
, mbox_ptr
->cmd
.length
)){
1989 printk(KERN_INFO
"wansock: Copy failed !!!\n");
1996 /*============================================================
1999 * Before command can be execute, socket MBOX must
2000 * be created, and initialized with user data.
2001 *===========================================================*/
2003 static int set_ioctl_cmd (struct sock
*sk
, void *arg
)
2005 x25api_t
*usr_data
= (x25api_t
*)arg
;
2006 mbox_cmd_t
*mbox_ptr
;
2009 if (!wp_sk(sk
)->mbox
) {
2011 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
2017 if ((mbox_ptr
= kmalloc(sizeof(mbox_cmd_t
), GFP_ATOMIC
)) == NULL
)
2020 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
2021 wp_sk(sk
)->mbox
= mbox_ptr
;
2023 wanpipe_link_driver(dev
,sk
);
2026 mbox_ptr
= (mbox_cmd_t
*)wp_sk(sk
)->mbox
;
2027 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
2029 if (usr_data
== NULL
){
2032 if ((err
=get_user(mbox_ptr
->cmd
.qdm
, &usr_data
->hdr
.qdm
)))
2034 if ((err
=get_user(mbox_ptr
->cmd
.cause
, &usr_data
->hdr
.cause
)))
2036 if ((err
=get_user(mbox_ptr
->cmd
.diagn
, &usr_data
->hdr
.diagn
)))
2038 if ((err
=get_user(mbox_ptr
->cmd
.length
, &usr_data
->hdr
.length
)))
2040 if ((err
=get_user(mbox_ptr
->cmd
.result
, &usr_data
->hdr
.result
)))
2043 if (mbox_ptr
->cmd
.length
> 0){
2044 if (mbox_ptr
->cmd
.length
> X25_MAX_DATA
)
2047 if (copy_from_user(mbox_ptr
->data
, usr_data
->data
, mbox_ptr
->cmd
.length
)){
2048 printk(KERN_INFO
"Copy failed\n");
2056 /*======================================================================
2059 * Datagram poll: Again totally generic. This also handles
2060 * sequenced packet sockets providing the socket receive queue
2061 * is only ever holding data ready to receive.
2063 * Note: when you _don't_ use this routine for this protocol,
2064 * and you use a different write policy from sock_writeable()
2065 * then please supply your own write_space callback.
2066 *=====================================================================*/
2068 unsigned int wanpipe_poll(struct file
* file
, struct socket
*sock
, poll_table
*wait
)
2070 struct sock
*sk
= sock
->sk
;
2073 ++wp_sk(sk
)->poll_cnt
;
2075 poll_wait(file
, sk
->sk_sleep
, wait
);
2078 /* exceptional events? */
2079 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
)) {
2083 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
2087 if (!skb_queue_empty(&sk
->sk_receive_queue
)) {
2088 mask
|= POLLIN
| POLLRDNORM
;
2091 /* connection hasn't started yet */
2092 if (sk
->sk_state
== WANSOCK_CONNECTING
) {
2096 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2101 /* This check blocks the user process if there is
2102 * a packet already queued in the socket write queue.
2103 * This option is only for X25API protocol, for other
2104 * protocol like chdlc enable streaming mode,
2105 * where multiple packets can be pending in the socket
2108 if (wp_sk(sk
)->num
== htons(X25_PROT
)) {
2109 if (atomic_read(&wp_sk(sk
)->packet_sent
))
2114 if (sock_writeable(sk
)){
2115 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
2117 set_bit(SOCK_ASYNC_NOSPACE
, &sk
->sk_socket
->flags
);
2123 /*======================================================================
2126 * X25API Specific function. Set a socket into LISTENING MODE.
2127 *=====================================================================*/
2130 static int wanpipe_listen(struct socket
*sock
, int backlog
)
2132 struct sock
*sk
= sock
->sk
;
2134 /* This is x25 specific area if protocol doesn't
2135 * match, return error */
2136 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2139 if (sk
->sk_state
== WANSOCK_BIND_LISTEN
) {
2141 sk
->sk_max_ack_backlog
= backlog
;
2142 sk
->sk_state
= WANSOCK_LISTEN
;
2145 printk(KERN_INFO
"wansock: Listening sock was not binded\n");
2151 /*======================================================================
2154 * Connects the listening socket to the driver
2155 *=====================================================================*/
2157 static int wanpipe_link_card (struct sock
*sk
)
2159 sdla_t
*card
= (sdla_t
*)wp_sk(sk
)->card
;
2164 if ((card
->sk
!= NULL
) || (card
->func
!= NULL
)){
2165 printk(KERN_INFO
"wansock: Listening queue is already established\n");
2170 card
->func
=wanpipe_listen_rcv
;
2171 sock_set_flag(sk
, SOCK_ZAPPED
);
2176 /*======================================================================
2179 * X25API Specific function. Disconnect listening socket from
2181 *=====================================================================*/
2183 static void wanpipe_unlink_card (struct sock
*sk
)
2185 sdla_t
*card
= (sdla_t
*)wp_sk(sk
)->card
;
2193 /*======================================================================
2196 * Ioctl function calls this function to execute user command.
2197 * Connect() sytem call also calls this function to execute
2198 * place call. This function blocks until command is executed.
2199 *=====================================================================*/
2201 static int wanpipe_exec_cmd(struct sock
*sk
, int cmd
, unsigned int flags
)
2204 wanpipe_opt
*wp
= wp_sk(sk
);
2205 mbox_cmd_t
*mbox_ptr
= (mbox_cmd_t
*)wp
->mbox
;
2208 printk(KERN_INFO
"NO MBOX PTR !!!!!\n");
2212 /* This is x25 specific area if protocol doesn't
2213 * match, return error */
2214 if (wp
->num
!= htons(X25_PROT
))
2220 case SIOC_WANPIPE_ACCEPT_CALL
:
2222 if (sk
->sk_state
!= WANSOCK_CONNECTING
) {
2227 err
= execute_command(sk
,X25_ACCEPT_CALL
,0);
2231 /* Update. Mar6 2000.
2232 * Do not set the sock lcn number here, since
2233 * it is done in wanpipe_listen_rcv().
2235 if (sk
->sk_state
== WANSOCK_CONNECTED
) {
2236 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2237 DBG_PRINTK(KERN_INFO
"\nwansock: Accept OK %i\n",
2242 DBG_PRINTK (KERN_INFO
"\nwansock: Accept Failed %i\n",
2245 err
= -ECONNREFUSED
;
2249 case SIOC_WANPIPE_CLEAR_CALL
:
2251 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2257 /* Check if data buffers are pending for transmission,
2258 * if so, check whether user wants to wait until data
2259 * is transmitted, or clear a call and drop packets */
2261 if (atomic_read(&sk
->sk_wmem_alloc
) ||
2262 check_driver_busy(sk
)) {
2263 mbox_cmd_t
*mbox
= wp
->mbox
;
2264 if (mbox
->cmd
.qdm
& 0x80){
2265 mbox
->cmd
.result
= 0x35;
2271 sk
->sk_state
= WANSOCK_DISCONNECTING
;
2273 err
= execute_command(sk
,X25_CLEAR_CALL
,0);
2277 err
= -ECONNREFUSED
;
2278 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2279 DBG_PRINTK(KERN_INFO
"\nwansock: CLEAR OK %i\n",
2286 case SIOC_WANPIPE_RESET_CALL
:
2288 if (sk
->sk_state
!= WANSOCK_CONNECTED
) {
2294 /* Check if data buffers are pending for transmission,
2295 * if so, check whether user wants to wait until data
2296 * is transmitted, or reset a call and drop packets */
2298 if (atomic_read(&sk
->sk_wmem_alloc
) ||
2299 check_driver_busy(sk
)) {
2300 mbox_cmd_t
*mbox
= wp
->mbox
;
2301 if (mbox
->cmd
.qdm
& 0x80){
2302 mbox
->cmd
.result
= 0x35;
2309 err
= execute_command(sk
, X25_RESET
,0);
2313 err
= mbox_ptr
->cmd
.result
;
2317 case X25_PLACE_CALL
:
2319 err
=execute_command(sk
,X25_PLACE_CALL
,flags
);
2323 if (sk
->sk_state
== WANSOCK_CONNECTED
) {
2325 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2327 DBG_PRINTK(KERN_INFO
"\nwansock: PLACE CALL OK %i\n",
2331 } else if (sk
->sk_state
== WANSOCK_CONNECTING
&&
2332 (flags
& O_NONBLOCK
)) {
2333 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2334 DBG_PRINTK(KERN_INFO
"\nwansock: Place Call OK: Waiting %i\n",
2340 DBG_PRINTK(KERN_INFO
"\nwansock: Place call Failed\n");
2341 err
= -ECONNREFUSED
;
2353 static int check_driver_busy (struct sock
*sk
)
2355 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
2356 wanpipe_common_t
*chan
;
2363 if ((chan
=dev
->priv
) == NULL
)
2366 return atomic_read(&chan
->driver_busy
);
2370 /*======================================================================
2373 * ACCEPT() System call. X25API Specific function.
2374 * For each incoming call, create a new socket and
2375 * return it to the user.
2376 *=====================================================================*/
2378 static int wanpipe_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
2382 struct sk_buff
*skb
;
2383 DECLARE_WAITQUEUE(wait
, current
);
2386 if (newsock
->sk
!= NULL
){
2387 wanpipe_kill_sock_accept(newsock
->sk
);
2391 if ((sk
= sock
->sk
) == NULL
)
2394 if (sk
->sk_type
!= SOCK_RAW
)
2397 if (sk
->sk_state
!= WANSOCK_LISTEN
)
2400 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2403 add_wait_queue(sk
->sk_sleep
,&wait
);
2404 current
->state
= TASK_INTERRUPTIBLE
;
2406 skb
= skb_dequeue(&sk
->sk_receive_queue
);
2411 if (signal_pending(current
)) {
2417 current
->state
= TASK_RUNNING
;
2418 remove_wait_queue(sk
->sk_sleep
,&wait
);
2423 newsk
= get_newsk_from_skb(skb
);
2428 set_bit(1,&wanpipe_tx_critical
);
2429 write_lock(&wanpipe_sklist_lock
);
2430 sk_add_node(newsk
, &wanpipe_sklist
);
2431 write_unlock(&wanpipe_sklist_lock
);
2432 clear_bit(1,&wanpipe_tx_critical
);
2434 newsk
->sk_socket
= newsock
;
2435 newsk
->sk_sleep
= &newsock
->wait
;
2437 /* Now attach up the new socket */
2438 sk
->sk_ack_backlog
--;
2439 newsock
->sk
= newsk
;
2443 DBG_PRINTK(KERN_INFO
"\nwansock: ACCEPT Got LCN %i\n",
2448 /*======================================================================
2449 * get_newsk_from_skb
2451 * Accept() uses this function to get the address of the new
2453 *=====================================================================*/
2455 struct sock
* get_newsk_from_skb (struct sk_buff
*skb
)
2457 struct net_device
*dev
= skb
->dev
;
2458 wanpipe_common_t
*chan
;
2464 if ((chan
= dev
->priv
) == NULL
){
2471 return (struct sock
*)chan
->sk
;
2474 /*======================================================================
2477 * CONNECT() System Call. X25API specific function
2478 * Check the state of the sock, and execute PLACE_CALL command.
2479 * Connect can ether block or return without waiting for connection,
2480 * if specified by user.
2481 *=====================================================================*/
2483 static int wanpipe_connect(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
, int flags
)
2485 struct sock
*sk
= sock
->sk
;
2486 struct wan_sockaddr_ll
*addr
= (struct wan_sockaddr_ll
*)uaddr
;
2487 struct net_device
*dev
;
2490 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2493 if (sk
->sk_state
== WANSOCK_CONNECTED
)
2494 return -EISCONN
; /* No reconnect on a seqpacket socket */
2496 if (sk
->sk_state
!= WAN_DISCONNECTED
) {
2497 printk(KERN_INFO
"wansock: Trying to connect on channel NON DISCONNECT\n");
2498 return -ECONNREFUSED
;
2501 sk
->sk_state
= WANSOCK_DISCONNECTED
;
2502 sock
->state
= SS_UNCONNECTED
;
2504 if (addr_len
!= sizeof(struct wan_sockaddr_ll
))
2507 if (addr
->sll_family
!= AF_WANPIPE
)
2510 if ((dev
= dev_get_by_index(sk
->sk_bound_dev_if
)) == NULL
)
2511 return -ENETUNREACH
;
2515 if (!sock_flag(sk
, SOCK_ZAPPED
)) /* Must bind first - autobinding does not work */
2518 sock
->state
= SS_CONNECTING
;
2519 sk
->sk_state
= WANSOCK_CONNECTING
;
2521 if (!wp_sk(sk
)->mbox
) {
2522 if (wp_sk (sk
)->svc
)
2526 if ((err
=set_ioctl_cmd(sk
,NULL
)) < 0)
2531 if ((err
=wanpipe_exec_cmd(sk
, X25_PLACE_CALL
,flags
)) != 0){
2532 sock
->state
= SS_UNCONNECTED
;
2533 sk
->sk_state
= WANSOCK_CONNECTED
;
2537 if (sk
->sk_state
!= WANSOCK_CONNECTED
&& (flags
& O_NONBLOCK
)) {
2541 if (sk
->sk_state
!= WANSOCK_CONNECTED
) {
2542 sock
->state
= SS_UNCONNECTED
;
2543 return -ECONNREFUSED
;
2546 sock
->state
= SS_CONNECTED
;
2550 const struct proto_ops wanpipe_ops
= {
2551 .family
= PF_WANPIPE
,
2552 .owner
= THIS_MODULE
,
2553 .release
= wanpipe_release
,
2554 .bind
= wanpipe_bind
,
2555 .connect
= wanpipe_connect
,
2556 .socketpair
= sock_no_socketpair
,
2557 .accept
= wanpipe_accept
,
2558 .getname
= wanpipe_getname
,
2559 .poll
= wanpipe_poll
,
2560 .ioctl
= wanpipe_ioctl
,
2561 .listen
= wanpipe_listen
,
2562 .shutdown
= sock_no_shutdown
,
2563 .setsockopt
= sock_no_setsockopt
,
2564 .getsockopt
= sock_no_getsockopt
,
2565 .sendmsg
= wanpipe_sendmsg
,
2566 .recvmsg
= wanpipe_recvmsg
2569 static struct net_proto_family wanpipe_family_ops
= {
2570 .family
= PF_WANPIPE
,
2571 .create
= wanpipe_create
,
2572 .owner
= THIS_MODULE
,
2575 struct notifier_block wanpipe_netdev_notifier
= {
2576 .notifier_call
= wanpipe_notifier
,
2581 void cleanup_module(void)
2583 printk(KERN_INFO
"wansock: Cleaning up \n");
2584 unregister_netdevice_notifier(&wanpipe_netdev_notifier
);
2585 sock_unregister(PF_WANPIPE
);
2586 proto_unregister(&wanpipe_proto
);
2589 int init_module(void)
2593 printk(KERN_INFO
"wansock: Registering Socket \n");
2595 rc
= proto_register(&wanpipe_proto
, 0);
2599 sock_register(&wanpipe_family_ops
);
2600 register_netdevice_notifier(&wanpipe_netdev_notifier
);
2605 MODULE_LICENSE("GPL");
2606 MODULE_ALIAS_NETPROTO(PF_WANPIPE
);