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/fcntl.h>
40 #include <linux/socket.h>
42 #include <linux/inet.h>
43 #include <linux/netdevice.h>
44 #include <linux/poll.h>
45 #include <linux/wireless.h>
46 #include <linux/kmod.h>
48 #include <net/protocol.h>
49 #include <linux/skbuff.h>
51 #include <linux/errno.h>
52 #include <linux/timer.h>
53 #include <asm/system.h>
54 #include <asm/uaccess.h>
55 #include <linux/module.h>
56 #include <linux/init.h>
57 #include <linux/wanpipe.h>
58 #include <linux/if_wanpipe.h>
59 #include <linux/pkt_sched.h>
60 #include <linux/tcp_states.h>
61 #include <linux/if_wanpipe_common.h>
62 #include <linux/sdla_x25.h>
65 #include <net/inet_common.h>
68 #define SLOW_BACKOFF 0.1*HZ
69 #define FAST_BACKOFF 0.01*HZ
73 #define DBG_PRINTK(format, a...) printk(format, ## a)
75 #define DBG_PRINTK(format, a...)
79 /* SECURE SOCKET IMPLEMENTATION
83 * When the user sends a packet via send() system call
84 * the wanpipe_sendmsg() function is executed.
86 * Each packet is enqueud into sk->sk_write_queue transmit
87 * queue. When the packet is enqueued, a delayed transmit
88 * timer is triggerd which acts as a Bottom Half hander.
90 * wanpipe_delay_transmit() function (BH), dequeues packets
91 * from the sk->sk_write_queue transmit queue and sends it
92 * to the deriver via dev->hard_start_xmit(skb, dev) function.
93 * Note, this function is actual a function pointer of if_send()
94 * routine in the wanpipe driver.
96 * X25API GUARANTEED DELIVERY:
98 * In order to provide 100% guaranteed packet delivery,
99 * an atomic 'packet_sent' counter is implemented. Counter
100 * is incremented for each packet enqueued
101 * into sk->sk_write_queue. Counter is decremented each
102 * time wanpipe_delayed_transmit() function successfuly
103 * passes the packet to the driver. Before each send(), a poll
104 * routine checks the sock resources The maximum value of
105 * packet sent counter is 1, thus if one packet is queued, the
106 * application will block until that packet is passed to the
111 * Wanpipe device drivers call the socket bottom half
112 * function, wanpipe_rcv() to queue the incoming packets
113 * into an AF_WANPIPE socket queue. Based on wanpipe_rcv()
114 * return code, the driver knows whether the packet was
115 * successfully queued. If the socket queue is full,
116 * protocol flow control is used by the driver, if any,
117 * to slow down the traffic until the sock queue is free.
119 * Every time a packet arrives into a socket queue the
120 * socket wakes up processes which are waiting to receive
123 * If the socket queue is full, the driver sets a block
124 * bit which signals the socket to kick the wanpipe driver
125 * bottom half hander when the socket queue is partialy
126 * empty. wanpipe_recvmsg() function performs this action.
128 * In case of x25api, packets will never be dropped, since
129 * flow control is available.
131 * In case of streaming protocols like CHDLC, packets will
132 * be dropped but the statistics will be generated.
136 /* The code below is used to test memory leaks. It prints out
137 * a message every time kmalloc and kfree system calls get executed.
138 * If the calls match there is no leak :)
141 /***********FOR DEBUGGING PURPOSES*********************************************
142 #define KMEM_SAFETYZONE 8
144 static void * dbg_kmalloc(unsigned int size, int prio, int line) {
145 void * v = kmalloc(size,prio);
146 printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
149 static void dbg_kfree(void * v, int line) {
150 printk(KERN_INFO "line %d kfree(%p)\n",line,v);
154 #define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
155 #define kfree(x) dbg_kfree(x,__LINE__)
156 ******************************************************************************/
159 /* List of all wanpipe sockets. */
160 HLIST_HEAD(wanpipe_sklist
);
161 static DEFINE_RWLOCK(wanpipe_sklist_lock
);
163 atomic_t wanpipe_socks_nr
;
164 static unsigned long wanpipe_tx_critical
;
167 /* Private wanpipe socket structures. */
170 void *mbox
; /* Mail box */
171 void *card
; /* Card bouded to */
172 struct net_device
*dev
; /* Bounded device */
173 unsigned short lcn
; /* Binded LCN */
174 unsigned char svc
; /* 0=pvc, 1=svc */
175 unsigned char timer
; /* flag for delayed transmit*/
176 struct timer_list tx_timer
;
178 unsigned char force
; /* Used to force sock release */
179 atomic_t packet_sent
;
184 extern const struct proto_ops wanpipe_ops
;
185 static unsigned long find_free_critical
;
187 static void wanpipe_unlink_driver(struct sock
*sk
);
188 static void wanpipe_link_driver(struct net_device
*dev
, struct sock
*sk
);
189 static void wanpipe_wakeup_driver(struct sock
*sk
);
190 static int execute_command(struct sock
*, unsigned char, unsigned int);
191 static int check_dev(struct net_device
*dev
, sdla_t
*card
);
192 struct net_device
*wanpipe_find_free_dev(sdla_t
*card
);
193 static void wanpipe_unlink_card (struct sock
*);
194 static int wanpipe_link_card (struct sock
*);
195 static struct sock
*wanpipe_make_new(struct sock
*);
196 static struct sock
*wanpipe_alloc_socket(void);
197 static inline int get_atomic_device(struct net_device
*dev
);
198 static int wanpipe_exec_cmd(struct sock
*, int, unsigned int);
199 static int get_ioctl_cmd (struct sock
*, void *);
200 static int set_ioctl_cmd (struct sock
*, void *);
201 static void release_device(struct net_device
*dev
);
202 static void wanpipe_kill_sock_timer (unsigned long data
);
203 static void wanpipe_kill_sock_irq (struct sock
*);
204 static void wanpipe_kill_sock_accept (struct sock
*);
205 static int wanpipe_do_bind(struct sock
*sk
, struct net_device
*dev
,
207 struct sock
* get_newsk_from_skb (struct sk_buff
*);
208 static int wanpipe_debug (struct sock
*, void *);
209 static void wanpipe_delayed_transmit (unsigned long data
);
210 static void release_driver(struct sock
*);
211 static void start_cleanup_timer (struct sock
*);
212 static void check_write_queue(struct sock
*);
213 static int check_driver_busy (struct sock
*);
215 /*============================================================
218 * Wanpipe socket bottom half handler. This function
219 * is called by the WANPIPE device drivers to queue a
220 * incoming packet into the socket receive queue.
221 * Once the packet is queued, all processes waiting to
224 * During socket bind, this function is bounded into
225 * WANPIPE driver private.
226 *===========================================================*/
228 static int wanpipe_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
231 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)skb
->cb
;
232 wanpipe_common_t
*chan
= dev
->priv
;
234 * When we registered the protocol we saved the socket in the data
235 * field for just this event.
240 sll
->sll_family
= AF_WANPIPE
;
241 sll
->sll_hatype
= dev
->type
;
242 sll
->sll_protocol
= skb
->protocol
;
243 sll
->sll_pkttype
= skb
->pkt_type
;
244 sll
->sll_ifindex
= dev
->ifindex
;
247 if (dev
->hard_header_parse
)
248 sll
->sll_halen
= dev
->hard_header_parse(skb
, sll
->sll_addr
);
251 * WAN_PACKET_DATA : Data which should be passed up the receive queue.
252 * WAN_PACKET_ASYC : Asynchronous data like place call, which should
253 * be passed up the listening sock.
254 * WAN_PACKET_ERR : Asynchronous data like clear call or restart
255 * which should go into an error queue.
257 switch (skb
->pkt_type
){
259 case WAN_PACKET_DATA
:
260 if (sock_queue_rcv_skb(sk
,skb
)<0){
265 sk
->sk_state
= chan
->state
;
266 /* Bug fix: update Mar6.
267 * Do not set the sock lcn number here, since
268 * cmd is not guaranteed to be executed on the
269 * board, thus Lcn could be wrong */
270 sk
->sk_data_ready(sk
, skb
->len
);
274 sk
->sk_state
= chan
->state
;
275 if (sock_queue_err_skb(sk
,skb
)<0){
280 printk(KERN_INFO
"wansock: BH Illegal Packet Type Dropping\n");
285 //??????????????????????
286 // if (sk->sk_state == WANSOCK_DISCONNECTED){
287 // if (sk->sk_zapped) {
288 // //printk(KERN_INFO "wansock: Disconnected, killing early\n");
289 // wanpipe_unlink_driver(sk);
290 // sk->sk_bound_dev_if = 0;
297 /*============================================================
300 * Wanpipe LISTEN socket bottom half handler. This function
301 * is called by the WANPIPE device drivers to queue an
302 * incoming call into the socket listening queue.
303 * Once the packet is queued, the waiting accept() process
306 * During socket bind, this function is bounded into
307 * WANPIPE driver private.
310 * The accept call() is waiting for an skb packet
311 * which contains a pointer to a device structure.
313 * When we do a bind to a device structre, we
314 * bind a newly created socket into "chan->sk". Thus,
315 * when accept receives the skb packet, it will know
316 * from which dev it came form, and in turn it will know
317 * the address of the new sock.
319 * NOTE: This function gets called from driver ISR.
320 *===========================================================*/
322 static int wanpipe_listen_rcv (struct sk_buff
*skb
, struct sock
*sk
)
324 wanpipe_opt
*wp
= wp_sk(sk
), *newwp
;
325 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)skb
->cb
;
327 struct net_device
*dev
;
329 mbox_cmd_t
*mbox_ptr
;
330 wanpipe_common_t
*chan
;
332 /* Find a free device, if none found, all svc's are busy
335 card
= (sdla_t
*)wp
->card
;
337 printk(KERN_INFO
"wansock: LISTEN ERROR, No Card\n");
341 dev
= wanpipe_find_free_dev(card
);
343 printk(KERN_INFO
"wansock: LISTEN ERROR, No Free Device\n");
348 chan
->state
= WANSOCK_CONNECTING
;
350 /* Allocate a new sock, which accept will bind
351 * and pass up to the user
353 if ((newsk
= wanpipe_make_new(sk
)) == NULL
){
359 /* Initialize the new sock structure
361 newsk
->sk_bound_dev_if
= dev
->ifindex
;
362 newwp
= wp_sk(newsk
);
363 newwp
->card
= wp
->card
;
365 /* Insert the sock into the main wanpipe
368 atomic_inc(&wanpipe_socks_nr
);
370 /* Allocate and fill in the new Mail Box. Then
371 * bind the mail box to the sock. It will be
372 * used by the ioctl call to read call information
373 * and to execute commands.
375 if ((mbox_ptr
= kmalloc(sizeof(mbox_cmd_t
), GFP_ATOMIC
)) == NULL
) {
376 wanpipe_kill_sock_irq (newsk
);
380 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
381 memcpy(mbox_ptr
,skb
->data
,skb
->len
);
383 /* Register the lcn on which incoming call came
384 * from. Thus, if we have to clear it, we know
388 newwp
->lcn
= mbox_ptr
->cmd
.lcn
;
389 newwp
->mbox
= (void *)mbox_ptr
;
391 DBG_PRINTK(KERN_INFO
"NEWSOCK : Device %s, bind to lcn %i\n",
392 dev
->name
,mbox_ptr
->cmd
.lcn
);
394 chan
->lcn
= mbox_ptr
->cmd
.lcn
;
395 card
->u
.x
.svc_to_dev_map
[(chan
->lcn
%MAX_X25_LCN
)] = dev
;
397 sock_reset_flag(newsk
, SOCK_ZAPPED
);
398 newwp
->num
= htons(X25_PROT
);
400 if (wanpipe_do_bind(newsk
, dev
, newwp
->num
)) {
401 wanpipe_kill_sock_irq (newsk
);
405 newsk
->sk_state
= WANSOCK_CONNECTING
;
408 /* Fill in the standard sock address info */
410 sll
->sll_family
= AF_WANPIPE
;
411 sll
->sll_hatype
= dev
->type
;
412 sll
->sll_protocol
= skb
->protocol
;
413 sll
->sll_pkttype
= skb
->pkt_type
;
414 sll
->sll_ifindex
= dev
->ifindex
;
418 sk
->sk_ack_backlog
++;
420 /* We must do this manually, since the sock_queue_rcv_skb()
421 * function sets the skb->dev to NULL. However, we use
422 * the dev field in the accept function.*/
423 if (atomic_read(&sk
->sk_rmem_alloc
) + skb
->truesize
>=
424 (unsigned)sk
->sk_rcvbuf
) {
426 wanpipe_unlink_driver(newsk
);
427 wanpipe_kill_sock_irq (newsk
);
428 --sk
->sk_ack_backlog
;
432 skb_set_owner_r(skb
, sk
);
433 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
434 sk
->sk_data_ready(sk
, skb
->len
);
441 /*============================================================
444 * Create a new sock, and allocate a wanpipe private
445 * structure to it. Also, copy the important data
446 * from the original sock to the new sock.
448 * This function is used by wanpipe_listen_rcv() listen
449 * bottom half handler. A copy of the listening sock
450 * is created using this function.
452 *===========================================================*/
454 static struct sock
*wanpipe_make_new(struct sock
*osk
)
458 if (osk
->sk_type
!= SOCK_RAW
)
461 if ((sk
= wanpipe_alloc_socket()) == NULL
)
464 sk
->sk_type
= osk
->sk_type
;
465 sk
->sk_socket
= osk
->sk_socket
;
466 sk
->sk_priority
= osk
->sk_priority
;
467 sk
->sk_protocol
= osk
->sk_protocol
;
468 wp_sk(sk
)->num
= wp_sk(osk
)->num
;
469 sk
->sk_rcvbuf
= osk
->sk_rcvbuf
;
470 sk
->sk_sndbuf
= osk
->sk_sndbuf
;
471 sk
->sk_state
= WANSOCK_CONNECTING
;
472 sk
->sk_sleep
= osk
->sk_sleep
;
474 if (sock_flag(osk
, SOCK_DBG
))
475 sock_set_flag(sk
, SOCK_DBG
);
481 * FIXME: wanpipe_opt has to include a sock in its definition and stop using
482 * sk_protinfo, but this code is not even compilable now, so lets leave it for
485 static struct proto wanpipe_proto
= {
487 .owner
= THIS_MODULE
,
488 .obj_size
= sizeof(struct sock
),
491 /*============================================================
494 * Allocate memory for the a new sock, and sock
497 * Increment the module use count.
499 * This function is used by wanpipe_create() and
500 * wanpipe_make_new() functions.
502 *===========================================================*/
504 static struct sock
*wanpipe_alloc_socket(void)
507 struct wanpipe_opt
*wan_opt
;
509 if ((sk
= sk_alloc(PF_WANPIPE
, GFP_ATOMIC
, &wanpipe_proto
, 1)) == NULL
)
512 if ((wan_opt
= kmalloc(sizeof(struct wanpipe_opt
), GFP_ATOMIC
)) == NULL
) {
516 memset(wan_opt
, 0x00, sizeof(struct wanpipe_opt
));
520 /* Use timer to send data to the driver. This will act
521 * as a BH handler for sendmsg functions */
522 init_timer(&wan_opt
->tx_timer
);
523 wan_opt
->tx_timer
.data
= (unsigned long)sk
;
524 wan_opt
->tx_timer
.function
= wanpipe_delayed_transmit
;
526 sock_init_data(NULL
, sk
);
531 /*============================================================
534 * This function implements a sendto() system call,
535 * for AF_WANPIPE socket family.
536 * During socket bind() sk->sk_bound_dev_if is initialized
537 * to a correct network device. This number is used
538 * to find a network device to which the packet should
541 * Each packet is queued into sk->sk_write_queue and
542 * delayed transmit bottom half handler is marked for
545 * A socket must be in WANSOCK_CONNECTED state before
546 * a packet is queued into sk->sk_write_queue.
547 *===========================================================*/
549 static int wanpipe_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
550 struct msghdr
*msg
, int len
)
553 struct sock
*sk
= sock
->sk
;
554 struct wan_sockaddr_ll
*saddr
=(struct wan_sockaddr_ll
*)msg
->msg_name
;
556 struct net_device
*dev
;
557 unsigned short proto
;
559 int ifindex
, err
, reserve
= 0;
562 if (!sock_flag(sk
, SOCK_ZAPPED
))
565 if (sk
->sk_state
!= WANSOCK_CONNECTED
)
568 if (msg
->msg_flags
& ~(MSG_DONTWAIT
|MSG_CMSG_COMPAT
))
571 /* it was <=, now one can send
572 * zero length packets */
573 if (len
< sizeof(x25api_hdr_t
))
579 ifindex
= sk
->sk_bound_dev_if
;
584 if (msg
->msg_namelen
< sizeof(struct wan_sockaddr_ll
)){
588 ifindex
= sk
->sk_bound_dev_if
;
589 proto
= saddr
->sll_protocol
;
590 addr
= saddr
->sll_addr
;
593 dev
= dev_get_by_index(ifindex
);
595 printk(KERN_INFO
"wansock: Send failed, dev index: %i\n",ifindex
);
600 if (sock
->type
== SOCK_RAW
)
601 reserve
= dev
->hard_header_len
;
603 if (len
> dev
->mtu
+reserve
){
607 skb
= sock_alloc_send_skb(sk
, len
+ LL_RESERVED_SPACE(dev
),
608 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
614 skb_reserve(skb
, LL_RESERVED_SPACE(dev
));
615 skb
->nh
.raw
= skb
->data
;
617 /* Returns -EFAULT on error */
618 err
= memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
);
623 if (dev
->hard_header
) {
626 res
= dev
->hard_header(skb
, dev
, ntohs(proto
), addr
, NULL
, len
);
632 skb
->protocol
= proto
;
634 skb
->priority
= sk
->sk_priority
;
635 skb
->pkt_type
= WAN_PACKET_DATA
;
638 if (!(dev
->flags
& IFF_UP
))
641 if (atomic_read(&sk
->sk_wmem_alloc
) + skb
->truesize
>
642 (unsigned int)sk
->sk_sndbuf
){
647 skb_queue_tail(&sk
->sk_write_queue
,skb
);
648 atomic_inc(&wp
->packet_sent
);
650 if (!(test_and_set_bit(0, &wp
->timer
)))
651 mod_timer(&wp
->tx_timer
, jiffies
+ 1);
661 /*============================================================
662 * wanpipe_delayed_tarnsmit
664 * Transmit bottom half handler. It dequeues packets
665 * from sk->sk_write_queue and passes them to the
666 * driver. If the driver is busy, the packet is
669 * Packet Sent counter is decremented on successful
671 *===========================================================*/
674 static void wanpipe_delayed_transmit (unsigned long data
)
676 struct sock
*sk
=(struct sock
*)data
;
678 wanpipe_opt
*wp
= wp_sk(sk
);
679 struct net_device
*dev
= wp
->dev
;
680 sdla_t
*card
= (sdla_t
*)wp
->card
;
683 clear_bit(0, &wp
->timer
);
684 DBG_PRINTK(KERN_INFO
"wansock: Transmit delay, no dev or card\n");
688 if (sk
->sk_state
!= WANSOCK_CONNECTED
|| !sock_flag(sk
, SOCK_ZAPPED
)) {
689 clear_bit(0, &wp
->timer
);
690 DBG_PRINTK(KERN_INFO
"wansock: Tx Timer, State not CONNECTED\n");
694 /* If driver is executing command, we must offload
695 * the board by not sending data. Otherwise a
696 * pending command will never get a free buffer
698 if (atomic_read(&card
->u
.x
.command_busy
)){
699 wp
->tx_timer
.expires
= jiffies
+ SLOW_BACKOFF
;
700 add_timer(&wp
->tx_timer
);
701 DBG_PRINTK(KERN_INFO
"wansock: Tx Timer, command bys BACKOFF\n");
706 if (test_and_set_bit(0,&wanpipe_tx_critical
)){
707 printk(KERN_INFO
"WanSock: Tx timer critical %s\n",dev
->name
);
708 wp
->tx_timer
.expires
= jiffies
+ SLOW_BACKOFF
;
709 add_timer(&wp
->tx_timer
);
713 /* Check for a packet in the fifo and send */
714 if ((skb
= skb_dequeue(&sk
->sk_write_queue
)) != NULL
){
716 if (dev
->hard_start_xmit(skb
, dev
) != 0){
718 /* Driver failed to transmit, re-enqueue
719 * the packet and retry again later */
720 skb_queue_head(&sk
->sk_write_queue
,skb
);
721 clear_bit(0,&wanpipe_tx_critical
);
725 /* Packet Sent successful. Check for more packets
726 * if more packets, re-trigger the transmit routine
729 atomic_dec(&wp
->packet_sent
);
731 if (skb_peek(&sk
->sk_write_queue
) == NULL
) {
732 /* If there is nothing to send, kick
733 * the poll routine, which will trigger
734 * the application to send more data */
735 sk
->sk_data_ready(sk
, 0);
736 clear_bit(0, &wp
->timer
);
738 /* Reschedule as fast as possible */
739 wp
->tx_timer
.expires
= jiffies
+ 1;
740 add_timer(&wp
->tx_timer
);
744 clear_bit(0,&wanpipe_tx_critical
);
747 /*============================================================
750 * Execute x25api commands. The atomic variable
751 * chan->command is used to indicate to the driver that
752 * command is pending for execution. The acutal command
753 * structure is placed into a sock mbox structure
756 * The sock private structure, mbox is
757 * used as shared memory between sock and the driver.
758 * Driver uses the sock mbox to execute the command
759 * and return the result.
761 * For all command except PLACE CALL, the function
762 * waits for the result. PLACE CALL can be ether
763 * blocking or nonblocking. The user sets this option
765 *===========================================================*/
768 static int execute_command(struct sock
*sk
, unsigned char cmd
, unsigned int flags
)
770 wanpipe_opt
*wp
= wp_sk(sk
);
771 struct net_device
*dev
;
772 wanpipe_common_t
*chan
=NULL
;
774 DECLARE_WAITQUEUE(wait
, current
);
776 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
778 printk(KERN_INFO
"wansock: Exec failed no dev %i\n",
779 sk
->sk_bound_dev_if
);
784 if ((chan
=dev
->priv
) == NULL
){
785 printk(KERN_INFO
"wansock: Exec cmd failed no priv area\n");
789 if (atomic_read(&chan
->command
)){
790 printk(KERN_INFO
"wansock: ERROR: Command already running %x, %s\n",
791 atomic_read(&chan
->command
),dev
->name
);
796 printk(KERN_INFO
"wansock: In execute without MBOX\n");
800 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.command
= cmd
;
801 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
= wp
->lcn
;
802 ((mbox_cmd_t
*)wp
->mbox
)->cmd
.result
= 0x7F;
805 if (flags
& O_NONBLOCK
){
807 atomic_set(&chan
->command
, cmd
);
809 atomic_set(&chan
->command
, cmd
);
812 add_wait_queue(sk
->sk_sleep
,&wait
);
813 current
->state
= TASK_INTERRUPTIBLE
;
815 if (((mbox_cmd_t
*)wp
->mbox
)->cmd
.result
!= 0x7F) {
819 if (signal_pending(current
)) {
825 current
->state
= TASK_RUNNING
;
826 remove_wait_queue(sk
->sk_sleep
,&wait
);
831 /*============================================================
832 * wanpipe_destroy_timer
834 * Used by wanpipe_release, to delay release of
836 *===========================================================*/
838 static void wanpipe_destroy_timer(unsigned long data
)
840 struct sock
*sk
=(struct sock
*)data
;
841 wanpipe_opt
*wp
= wp_sk(sk
);
843 if ((!atomic_read(&sk
->sk_wmem_alloc
) &&
844 !atomic_read(&sk
->sk_rmem_alloc
)) ||
845 (++wp
->force
== 5)) {
847 if (atomic_read(&sk
->sk_wmem_alloc
) ||
848 atomic_read(&sk
->sk_rmem_alloc
))
849 printk(KERN_INFO
"wansock: Warning, Packet Discarded due to sock shutdown!\n");
854 if (atomic_read(&sk
->sk_refcnt
) != 1) {
855 atomic_set(&sk
->sk_refcnt
, 1);
856 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :delay.\n",
857 atomic_read(&sk
->sk_refcnt
));
860 atomic_dec(&wanpipe_socks_nr
);
864 sk
->sk_timer
.expires
= jiffies
+ 5 * HZ
;
865 add_timer(&sk
->sk_timer
);
866 printk(KERN_INFO
"wansock: packet sk destroy delayed\n");
869 /*============================================================
870 * wanpipe_unlink_driver
872 * When the socket is released, this function is
873 * used to remove links that bind the sock and the
875 *===========================================================*/
876 static void wanpipe_unlink_driver (struct sock
*sk
)
878 struct net_device
*dev
;
879 wanpipe_common_t
*chan
=NULL
;
881 sock_reset_flag(sk
, SOCK_ZAPPED
);
882 sk
->sk_state
= WANSOCK_DISCONNECTED
;
883 wp_sk(sk
)->dev
= NULL
;
885 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
887 printk(KERN_INFO
"wansock: No dev on release\n");
892 if ((chan
= dev
->priv
) == NULL
){
893 printk(KERN_INFO
"wansock: No Priv Area on release\n");
897 set_bit(0,&chan
->common_critical
);
902 clear_bit(0,&chan
->common_critical
);
908 /*============================================================
909 * wanpipe_link_driver
911 * Upon successful bind(), sock is linked to a driver
912 * by binding in the wanpipe_rcv() bottom half handler
913 * to the driver function pointer, as well as sock and
914 * sock mailbox addresses. This way driver can pass
915 * data up the socket.
916 *===========================================================*/
918 static void wanpipe_link_driver(struct net_device
*dev
, struct sock
*sk
)
920 wanpipe_opt
*wp
= wp_sk(sk
);
921 wanpipe_common_t
*chan
= dev
->priv
;
924 set_bit(0,&chan
->common_critical
);
926 chan
->func
=wanpipe_rcv
;
927 chan
->mbox
= wp
->mbox
;
928 chan
->tx_timer
= &wp
->tx_timer
;
930 sock_set_flag(sk
, SOCK_ZAPPED
);
931 clear_bit(0,&chan
->common_critical
);
935 /*============================================================
938 * During sock release, clear a critical bit, which
939 * marks the device a being taken.
940 *===========================================================*/
943 static void release_device(struct net_device
*dev
)
945 wanpipe_common_t
*chan
=dev
->priv
;
946 clear_bit(0,(void*)&chan
->rw_bind
);
949 /*============================================================
952 * Close a PACKET socket. This is fairly simple. We
953 * immediately go to 'closed' state and remove our
954 * protocol entry in the device list.
955 *===========================================================*/
957 static int wanpipe_release(struct socket
*sock
)
960 struct sock
*sk
= sock
->sk
;
966 check_write_queue(sk
);
968 /* Kill the tx timer, if we don't kill it now, the timer
969 * will run after we kill the sock. Timer code will
970 * try to access the sock which has been killed and cause
973 del_timer(&wp
->tx_timer
);
976 * Unhook packet receive handler.
979 if (wp
->num
== htons(X25_PROT
) &&
980 sk
->sk_state
!= WANSOCK_DISCONNECTED
&& sock_flag(sk
, SOCK_ZAPPED
)) {
981 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
982 wanpipe_common_t
*chan
;
985 atomic_set(&chan
->disconnect
,1);
986 DBG_PRINTK(KERN_INFO
"wansock: Sending Clear Indication %i\n",
992 set_bit(1,&wanpipe_tx_critical
);
993 write_lock(&wanpipe_sklist_lock
);
994 sk_del_node_init(sk
);
995 write_unlock(&wanpipe_sklist_lock
);
996 clear_bit(1,&wanpipe_tx_critical
);
1004 * Now the socket is dead. No more input will appear.
1007 sk
->sk_state_change(sk
); /* It is useless. Just for sanity. */
1010 sk
->sk_socket
= NULL
;
1011 sock_set_flag(sk
, SOCK_DEAD
);
1014 skb_queue_purge(&sk
->sk_receive_queue
);
1015 skb_queue_purge(&sk
->sk_write_queue
);
1016 skb_queue_purge(&sk
->sk_error_queue
);
1018 if (atomic_read(&sk
->sk_rmem_alloc
) ||
1019 atomic_read(&sk
->sk_wmem_alloc
)) {
1020 del_timer(&sk
->sk_timer
);
1021 printk(KERN_INFO
"wansock: Killing in Timer R %i , W %i\n",
1022 atomic_read(&sk
->sk_rmem_alloc
),
1023 atomic_read(&sk
->sk_wmem_alloc
));
1024 sk
->sk_timer
.data
= (unsigned long)sk
;
1025 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1026 sk
->sk_timer
.function
= wanpipe_destroy_timer
;
1027 add_timer(&sk
->sk_timer
);
1034 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1035 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i !:release.\n",
1036 atomic_read(&sk
->sk_refcnt
));
1037 atomic_set(&sk
->sk_refcnt
, 1);
1040 atomic_dec(&wanpipe_socks_nr
);
1044 /*============================================================
1047 * During sock shutdown, if the sock state is
1048 * WANSOCK_CONNECTED and there is transmit data
1049 * pending. Wait until data is released
1050 * before proceeding.
1051 *===========================================================*/
1053 static void check_write_queue(struct sock
*sk
)
1056 if (sk
->sk_state
!= WANSOCK_CONNECTED
)
1059 if (!atomic_read(&sk
->sk_wmem_alloc
))
1062 printk(KERN_INFO
"wansock: MAJOR ERROR, Data lost on sock release !!!\n");
1066 /*============================================================
1069 * This function is called during sock shutdown, to
1070 * release any resources and links that bind the sock
1071 * to the driver. It also changes the state of the
1072 * sock to WANSOCK_DISCONNECTED
1073 *===========================================================*/
1075 static void release_driver(struct sock
*sk
)
1078 struct sk_buff
*skb
=NULL
;
1079 struct sock
*deadsk
=NULL
;
1081 if (sk
->sk_state
== WANSOCK_LISTEN
||
1082 sk
->sk_state
== WANSOCK_BIND_LISTEN
) {
1083 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
)) != NULL
) {
1084 if ((deadsk
= get_newsk_from_skb(skb
))){
1085 DBG_PRINTK (KERN_INFO
"wansock: RELEASE: FOUND DEAD SOCK\n");
1086 sock_set_flag(deadsk
, SOCK_DEAD
);
1087 start_cleanup_timer(deadsk
);
1091 if (sock_flag(sk
, SOCK_ZAPPED
))
1092 wanpipe_unlink_card(sk
);
1094 if (sock_flag(sk
, SOCK_ZAPPED
))
1095 wanpipe_unlink_driver(sk
);
1097 sk
->sk_state
= WANSOCK_DISCONNECTED
;
1098 sk
->sk_bound_dev_if
= 0;
1099 sock_reset_flag(sk
, SOCK_ZAPPED
);
1108 /*============================================================
1109 * start_cleanup_timer
1111 * If new incoming call's are pending but the socket
1112 * is being released, start the timer which will
1113 * envoke the kill routines for pending socks.
1114 *===========================================================*/
1117 static void start_cleanup_timer (struct sock
*sk
)
1119 del_timer(&sk
->sk_timer
);
1120 sk
->sk_timer
.data
= (unsigned long)sk
;
1121 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1122 sk
->sk_timer
.function
= wanpipe_kill_sock_timer
;
1123 add_timer(&sk
->sk_timer
);
1127 /*============================================================
1130 * This is a function which performs actual killing
1131 * of the sock. It releases socket resources,
1132 * and unlinks the sock from the driver.
1133 *===========================================================*/
1135 static void wanpipe_kill_sock_timer (unsigned long data
)
1138 struct sock
*sk
= (struct sock
*)data
;
1144 /* This function can be called from interrupt. We must use
1145 * appropriate locks */
1147 if (test_bit(1,&wanpipe_tx_critical
)){
1148 sk
->sk_timer
.expires
= jiffies
+ 10;
1149 add_timer(&sk
->sk_timer
);
1153 write_lock(&wanpipe_sklist_lock
);
1154 sk_del_node_init(sk
);
1155 write_unlock(&wanpipe_sklist_lock
);
1158 if (wp_sk(sk
)->num
== htons(X25_PROT
) &&
1159 sk
->sk_state
!= WANSOCK_DISCONNECTED
) {
1160 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1161 wanpipe_common_t
*chan
;
1164 atomic_set(&chan
->disconnect
,1);
1171 sk
->sk_socket
= NULL
;
1174 skb_queue_purge(&sk
->sk_receive_queue
);
1175 skb_queue_purge(&sk
->sk_write_queue
);
1176 skb_queue_purge(&sk
->sk_error_queue
);
1178 if (atomic_read(&sk
->sk_rmem_alloc
) ||
1179 atomic_read(&sk
->sk_wmem_alloc
)) {
1180 del_timer(&sk
->sk_timer
);
1181 printk(KERN_INFO
"wansock: Killing SOCK in Timer\n");
1182 sk
->sk_timer
.data
= (unsigned long)sk
;
1183 sk
->sk_timer
.expires
= jiffies
+ HZ
;
1184 sk
->sk_timer
.function
= wanpipe_destroy_timer
;
1185 add_timer(&sk
->sk_timer
);
1192 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1193 atomic_set(&sk
->sk_refcnt
, 1);
1194 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :timer.\n",
1195 atomic_read(&sk
->sk_refcnt
));
1198 atomic_dec(&wanpipe_socks_nr
);
1202 static void wanpipe_kill_sock_accept (struct sock
*sk
)
1210 /* This function can be called from interrupt. We must use
1211 * appropriate locks */
1213 write_lock(&wanpipe_sklist_lock
);
1214 sk_del_node_init(sk
);
1215 write_unlock(&wanpipe_sklist_lock
);
1217 sk
->sk_socket
= NULL
;
1223 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1224 atomic_set(&sk
->sk_refcnt
, 1);
1225 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i ! :timer.\n",
1226 atomic_read(&sk
->sk_refcnt
));
1229 atomic_dec(&wanpipe_socks_nr
);
1234 static void wanpipe_kill_sock_irq (struct sock
*sk
)
1240 sk
->sk_socket
= NULL
;
1245 if (atomic_read(&sk
->sk_refcnt
) != 1) {
1246 atomic_set(&sk
->sk_refcnt
, 1);
1247 DBG_PRINTK(KERN_INFO
"wansock: Error, wrong reference count: %i !:listen.\n",
1248 atomic_read(&sk
->sk_refcnt
));
1251 atomic_dec(&wanpipe_socks_nr
);
1255 /*============================================================
1258 * Bottom half of the binding system call.
1259 * Once the wanpipe_bind() function checks the
1260 * legality of the call, this function binds the
1261 * sock to the driver.
1262 *===========================================================*/
1264 static int wanpipe_do_bind(struct sock
*sk
, struct net_device
*dev
,
1267 wanpipe_opt
*wp
= wp_sk(sk
);
1268 wanpipe_common_t
*chan
=NULL
;
1271 if (sock_flag(sk
, SOCK_ZAPPED
)) {
1273 goto bind_unlock_exit
;
1279 release_device(dev
);
1281 goto bind_unlock_exit
;
1285 if (dev
->flags
&IFF_UP
) {
1287 sk
->sk_state
= chan
->state
;
1289 if (wp
->num
== htons(X25_PROT
) &&
1290 sk
->sk_state
!= WANSOCK_DISCONNECTED
&&
1291 sk
->sk_state
!= WANSOCK_CONNECTING
) {
1292 DBG_PRINTK(KERN_INFO
1293 "wansock: Binding to Device not DISCONNECTED %i\n",
1295 release_device(dev
);
1297 goto bind_unlock_exit
;
1300 wanpipe_link_driver(dev
,sk
);
1301 sk
->sk_bound_dev_if
= dev
->ifindex
;
1303 /* X25 Specific option */
1304 if (wp
->num
== htons(X25_PROT
))
1305 wp_sk(sk
)->svc
= chan
->svc
;
1308 sk
->sk_err
= ENETDOWN
;
1309 sk
->sk_error_report(sk
);
1310 release_device(dev
);
1317 /* FIXME where is this lock */
1322 /*============================================================
1325 * BIND() System call, which is bound to the AF_WANPIPE
1326 * operations structure. It checks for correct wanpipe
1327 * card name, and cross references interface names with
1328 * the card names. Thus, interface name must belong to
1330 *===========================================================*/
1333 static int wanpipe_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
1335 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)uaddr
;
1336 struct sock
*sk
=sock
->sk
;
1337 wanpipe_opt
*wp
= wp_sk(sk
);
1338 struct net_device
*dev
= NULL
;
1346 if (addr_len
< sizeof(struct wan_sockaddr_ll
)){
1347 printk(KERN_INFO
"wansock: Address length error\n");
1350 if (sll
->sll_family
!= AF_WANPIPE
){
1351 printk(KERN_INFO
"wansock: Illegal family name specified.\n");
1355 card
= wanpipe_find_card (sll
->sll_card
);
1357 printk(KERN_INFO
"wansock: Wanpipe card not found: %s\n",sll
->sll_card
);
1360 wp_sk(sk
)->card
= (void *)card
;
1363 if (!strcmp(sll
->sll_device
,"svc_listen")){
1365 /* Bind a sock to a card structure for listening
1369 /* This is x25 specific area if protocol doesn't
1370 * match, return error */
1371 if (sll
->sll_protocol
!= htons(X25_PROT
))
1374 err
= wanpipe_link_card (sk
);
1378 if (sll
->sll_protocol
)
1379 wp
->num
= sll
->sll_protocol
;
1380 sk
->sk_state
= WANSOCK_BIND_LISTEN
;
1383 }else if (!strcmp(sll
->sll_device
,"svc_connect")){
1385 /* This is x25 specific area if protocol doesn't
1386 * match, return error */
1387 if (sll
->sll_protocol
!= htons(X25_PROT
))
1390 /* Find a free device
1392 dev
= wanpipe_find_free_dev(card
);
1394 DBG_PRINTK(KERN_INFO
"wansock: No free network devices for card %s\n",
1399 /* Bind a socket to a interface name
1400 * This is used by PVC mostly
1402 strlcpy(name
,sll
->sll_device
,sizeof(name
));
1403 dev
= dev_get_by_name(name
);
1405 printk(KERN_INFO
"wansock: Failed to get Dev from name: %s,\n",
1412 if (check_dev(dev
, card
)){
1413 printk(KERN_INFO
"wansock: Device %s, doesn't belong to card %s\n",
1414 dev
->name
, card
->devname
);
1417 if (get_atomic_device (dev
))
1421 return wanpipe_do_bind(sk
, dev
, sll
->sll_protocol
? : wp
->num
);
1424 /*============================================================
1427 * Sets a bit atomically which indicates that
1428 * the interface is taken. This avoids race conditions.
1429 *===========================================================*/
1432 static inline int get_atomic_device(struct net_device
*dev
)
1434 wanpipe_common_t
*chan
= dev
->priv
;
1435 if (!test_and_set_bit(0,(void *)&chan
->rw_bind
)){
1441 /*============================================================
1444 * Check that device name belongs to a particular card.
1445 *===========================================================*/
1447 static int check_dev(struct net_device
*dev
, sdla_t
*card
)
1449 struct net_device
* tmp_dev
;
1451 for (tmp_dev
= card
->wandev
.dev
; tmp_dev
;
1452 tmp_dev
= *((struct net_device
**)tmp_dev
->priv
)) {
1453 if (tmp_dev
->ifindex
== dev
->ifindex
){
1460 /*============================================================
1461 * wanpipe_find_free_dev
1463 * Find a free network interface. If found set atomic
1464 * bit indicating that the interface is taken.
1466 *===========================================================*/
1468 struct net_device
*wanpipe_find_free_dev(sdla_t
*card
)
1470 struct net_device
* dev
;
1471 volatile wanpipe_common_t
*chan
;
1473 if (test_and_set_bit(0,&find_free_critical
)){
1474 printk(KERN_INFO
"CRITICAL in Find Free\n");
1477 for (dev
= card
->wandev
.dev
; dev
;
1478 dev
= *((struct net_device
**)dev
->priv
)) {
1482 if (chan
->usedby
== API
&& chan
->svc
){
1483 if (!get_atomic_device (dev
)){
1484 if (chan
->state
!= WANSOCK_DISCONNECTED
){
1485 release_device(dev
);
1487 clear_bit(0,&find_free_critical
);
1493 clear_bit(0,&find_free_critical
);
1497 /*============================================================
1500 * SOCKET() System call. It allocates a sock structure
1501 * and adds the socket to the wanpipe_sk_list.
1502 * Crates AF_WANPIPE socket.
1503 *===========================================================*/
1505 static int wanpipe_create(struct socket
*sock
, int protocol
)
1509 //FIXME: This checks for root user, SECURITY ?
1510 //if (!capable(CAP_NET_RAW))
1513 if (sock
->type
!= SOCK_DGRAM
&& sock
->type
!= SOCK_RAW
)
1514 return -ESOCKTNOSUPPORT
;
1516 sock
->state
= SS_UNCONNECTED
;
1518 if ((sk
= wanpipe_alloc_socket()) == NULL
)
1522 sock
->ops
= &wanpipe_ops
;
1523 sock_init_data(sock
,sk
);
1525 sock_reset_flag(sk
, SOCK_ZAPPED
);
1526 sk
->sk_family
= PF_WANPIPE
;
1527 wp_sk(sk
)->num
= protocol
;
1528 sk
->sk_state
= WANSOCK_DISCONNECTED
;
1529 sk
->sk_ack_backlog
= 0;
1530 sk
->sk_bound_dev_if
= 0;
1532 atomic_inc(&wanpipe_socks_nr
);
1534 /* We must disable interrupts because the ISR
1535 * can also change the list */
1536 set_bit(1,&wanpipe_tx_critical
);
1537 write_lock(&wanpipe_sklist_lock
);
1538 sk_add_node(sk
, &wanpipe_sklist
);
1539 write_unlock(&wanpipe_sklist_lock
);
1540 clear_bit(1,&wanpipe_tx_critical
);
1546 /*============================================================
1549 * Pull a packet from our receive queue and hand it
1550 * to the user. If necessary we block.
1551 *===========================================================*/
1553 static int wanpipe_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1554 struct msghdr
*msg
, int len
, int flags
)
1556 struct sock
*sk
= sock
->sk
;
1557 struct sk_buff
*skb
;
1558 int copied
, err
=-ENOBUFS
;
1562 * If the address length field is there to be filled in, we fill
1566 msg
->msg_namelen
= sizeof(struct wan_sockaddr_ll
);
1569 * Call the generic datagram receiver. This handles all sorts
1570 * of horrible races and re-entrancy so we can forget about it
1571 * in the protocol layers.
1573 * Now it will return ENETDOWN, if device have just gone down,
1574 * but then it will block.
1577 if (flags
& MSG_OOB
){
1578 skb
= skb_dequeue(&sk
->sk_error_queue
);
1580 skb
=skb_recv_datagram(sk
,flags
,1,&err
);
1583 * An error occurred so return it. Because skb_recv_datagram()
1584 * handles the blocking we don't see and worry about blocking
1592 * You lose any data beyond the buffer you gave. If it worries a
1593 * user program they can ask the device for its MTU anyway.
1600 msg
->msg_flags
|=MSG_TRUNC
;
1603 wanpipe_wakeup_driver(sk
);
1605 /* We can't use skb_copy_datagram here */
1606 err
= memcpy_toiovec(msg
->msg_iov
, skb
->data
, copied
);
1610 sock_recv_timestamp(msg
, sk
, skb
);
1613 memcpy(msg
->msg_name
, skb
->cb
, msg
->msg_namelen
);
1616 * Free or return the buffer as appropriate. Again this
1617 * hides all the races and re-entrancy issues from us.
1619 err
= (flags
&MSG_TRUNC
) ? skb
->len
: copied
;
1622 skb_free_datagram(sk
, skb
);
1628 /*============================================================
1629 * wanpipe_wakeup_driver
1631 * If socket receive buffer is full and driver cannot
1632 * pass data up the sock, it sets a packet_block flag.
1633 * This function check that flag and if sock receive
1634 * queue has room it kicks the driver BH handler.
1636 * This way, driver doesn't have to poll the sock
1638 *===========================================================*/
1640 static void wanpipe_wakeup_driver(struct sock
*sk
)
1642 struct net_device
*dev
= NULL
;
1643 wanpipe_common_t
*chan
=NULL
;
1645 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1651 if ((chan
= dev
->priv
) == NULL
)
1654 if (atomic_read(&chan
->receive_block
)){
1655 if (atomic_read(&sk
->sk_rmem_alloc
) <
1656 ((unsigned)sk
->sk_rcvbuf
* 0.9)) {
1657 printk(KERN_INFO
"wansock: Queuing task for wanpipe\n");
1658 atomic_set(&chan
->receive_block
,0);
1659 wanpipe_queue_tq(&chan
->wanpipe_task
);
1665 /*============================================================
1668 * I don't know what to do with this yet.
1669 * User can use this function to get sock address
1670 * information. Not very useful for Sangoma's purposes.
1671 *===========================================================*/
1674 static int wanpipe_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
1675 int *uaddr_len
, int peer
)
1677 struct net_device
*dev
;
1678 struct sock
*sk
= sock
->sk
;
1679 struct wan_sockaddr_ll
*sll
= (struct wan_sockaddr_ll
*)uaddr
;
1681 sll
->sll_family
= AF_WANPIPE
;
1682 sll
->sll_ifindex
= sk
->sk_bound_dev_if
;
1683 sll
->sll_protocol
= wp_sk(sk
)->num
;
1684 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1686 sll
->sll_hatype
= dev
->type
;
1687 sll
->sll_halen
= dev
->addr_len
;
1688 memcpy(sll
->sll_addr
, dev
->dev_addr
, dev
->addr_len
);
1690 sll
->sll_hatype
= 0; /* Bad: we have no ARPHRD_UNSPEC */
1693 *uaddr_len
= sizeof(*sll
);
1700 /*============================================================
1703 * If driver turns off network interface, this function
1704 * will be envoked. Currently I treate it as a
1705 * call disconnect. More thought should go into this
1708 * FIXME: More thought should go into this function.
1710 *===========================================================*/
1712 static int wanpipe_notifier(struct notifier_block
*this, unsigned long msg
, void *data
)
1716 struct net_device
*dev
= (struct net_device
*)data
;
1718 sk_for_each(sk
, node
, &wanpipe_sklist
) {
1719 struct wanpipe_opt
*po
= wp_sk(sk
);
1728 case NETDEV_UNREGISTER
:
1729 if (dev
->ifindex
== sk
->sk_bound_dev_if
) {
1730 printk(KERN_INFO
"wansock: Device down %s\n",dev
->name
);
1731 if (sock_flag(sk
, SOCK_ZAPPED
)) {
1732 wanpipe_unlink_driver(sk
);
1733 sk
->sk_err
= ENETDOWN
;
1734 sk
->sk_error_report(sk
);
1737 if (msg
== NETDEV_UNREGISTER
) {
1738 printk(KERN_INFO
"wansock: Unregistering Device: %s\n",
1740 wanpipe_unlink_driver(sk
);
1741 sk
->sk_bound_dev_if
= 0;
1746 if (dev
->ifindex
== sk
->sk_bound_dev_if
&&
1747 po
->num
&& !sock_flag(sk
, SOCK_ZAPPED
)) {
1748 printk(KERN_INFO
"wansock: Registering Device: %s\n",
1750 wanpipe_link_driver(dev
,sk
);
1758 /*============================================================
1761 * Execute a user commands, and set socket options.
1763 * FIXME: More thought should go into this function.
1765 *===========================================================*/
1767 static int wanpipe_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1769 struct sock
*sk
= sock
->sk
;
1775 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
1777 case SIOC_WANPIPE_CHECK_TX
:
1779 return atomic_read(&sk
->sk_wmem_alloc
);
1781 case SIOC_WANPIPE_SOCK_STATE
:
1783 if (sk
->sk_state
== WANSOCK_CONNECTED
)
1789 case SIOC_WANPIPE_GET_CALL_DATA
:
1791 return get_ioctl_cmd (sk
,(void*)arg
);
1793 case SIOC_WANPIPE_SET_CALL_DATA
:
1795 return set_ioctl_cmd (sk
,(void*)arg
);
1797 case SIOC_WANPIPE_ACCEPT_CALL
:
1798 case SIOC_WANPIPE_CLEAR_CALL
:
1799 case SIOC_WANPIPE_RESET_CALL
:
1801 if ((err
=set_ioctl_cmd(sk
,(void*)arg
)) < 0)
1804 err
=wanpipe_exec_cmd(sk
,cmd
,0);
1805 get_ioctl_cmd(sk
,(void*)arg
);
1808 case SIOC_WANPIPE_DEBUG
:
1810 return wanpipe_debug(sk
,(void*)arg
);
1812 case SIOC_WANPIPE_SET_NONBLOCK
:
1814 if (sk
->sk_state
!= WANSOCK_DISCONNECTED
)
1817 sock
->file
->f_flags
|= O_NONBLOCK
;
1831 case SIOCGIFBRDADDR
:
1832 case SIOCSIFBRDADDR
:
1833 case SIOCGIFNETMASK
:
1834 case SIOCSIFNETMASK
:
1835 case SIOCGIFDSTADDR
:
1836 case SIOCSIFDSTADDR
:
1838 return inet_dgram_ops
.ioctl(sock
, cmd
, arg
);
1842 return -ENOIOCTLCMD
;
1847 /*============================================================
1850 * This function will pass up information about all
1853 * FIXME: More thought should go into this function.
1855 *===========================================================*/
1857 static int wanpipe_debug (struct sock
*origsk
, void *arg
)
1860 struct hlist_node
*node
;
1861 struct net_device
*dev
= NULL
;
1862 wanpipe_common_t
*chan
=NULL
;
1864 wan_debug_t
*dbg_data
= (wan_debug_t
*)arg
;
1866 sk_for_each(sk
, node
, &wanpipe_sklist
) {
1867 wanpipe_opt
*wp
= wp_sk(sk
);
1873 if ((err
=put_user(1, &dbg_data
->debug
[cnt
].free
)))
1875 if ((err
= put_user(sk
->sk_state
,
1876 &dbg_data
->debug
[cnt
].state_sk
)))
1878 if ((err
= put_user(sk
->sk_rcvbuf
,
1879 &dbg_data
->debug
[cnt
].rcvbuf
)))
1881 if ((err
= put_user(atomic_read(&sk
->sk_rmem_alloc
),
1882 &dbg_data
->debug
[cnt
].rmem
)))
1884 if ((err
= put_user(atomic_read(&sk
->sk_wmem_alloc
),
1885 &dbg_data
->debug
[cnt
].wmem
)))
1887 if ((err
= put_user(sk
->sk_sndbuf
,
1888 &dbg_data
->debug
[cnt
].sndbuf
)))
1890 if ((err
=put_user(sk_count
, &dbg_data
->debug
[cnt
].sk_count
)))
1892 if ((err
=put_user(wp
->poll_cnt
, &dbg_data
->debug
[cnt
].poll_cnt
)))
1894 if ((err
= put_user(sk
->sk_bound_dev_if
,
1895 &dbg_data
->debug
[cnt
].bound
)))
1898 if (sk
->sk_bound_dev_if
) {
1899 dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
1906 if ((err
=put_user(chan
->state
, &dbg_data
->debug
[cnt
].d_state
)))
1908 if ((err
=put_user(chan
->svc
, &dbg_data
->debug
[cnt
].svc
)))
1911 if ((err
=put_user(atomic_read(&chan
->command
),
1912 &dbg_data
->debug
[cnt
].command
)))
1917 sdla_t
*card
= (sdla_t
*)wp
->card
;
1920 if ((err
=put_user(atomic_read(&card
->u
.x
.command_busy
),
1921 &dbg_data
->debug
[cnt
].cmd_busy
)))
1925 if ((err
=put_user(wp
->lcn
,
1926 &dbg_data
->debug
[cnt
].lcn
)))
1930 if ((err
=put_user(1, &dbg_data
->debug
[cnt
].mbox
)))
1935 if ((err
=put_user(atomic_read(&chan
->receive_block
),
1936 &dbg_data
->debug
[cnt
].rblock
)))
1939 if (copy_to_user(dbg_data
->debug
[cnt
].name
, dev
->name
, strlen(dev
->name
)))
1943 if (++cnt
== MAX_NUM_DEBUG
)
1949 /*============================================================
1952 * Pass up the contents of socket MBOX to the user.
1953 *===========================================================*/
1955 static int get_ioctl_cmd (struct sock
*sk
, void *arg
)
1957 x25api_t
*usr_data
= (x25api_t
*)arg
;
1958 mbox_cmd_t
*mbox_ptr
;
1961 if (usr_data
== NULL
)
1964 if (!wp_sk(sk
)->mbox
) {
1968 mbox_ptr
= (mbox_cmd_t
*)wp_sk(sk
)->mbox
;
1970 if ((err
=put_user(mbox_ptr
->cmd
.qdm
, &usr_data
->hdr
.qdm
)))
1972 if ((err
=put_user(mbox_ptr
->cmd
.cause
, &usr_data
->hdr
.cause
)))
1974 if ((err
=put_user(mbox_ptr
->cmd
.diagn
, &usr_data
->hdr
.diagn
)))
1976 if ((err
=put_user(mbox_ptr
->cmd
.length
, &usr_data
->hdr
.length
)))
1978 if ((err
=put_user(mbox_ptr
->cmd
.result
, &usr_data
->hdr
.result
)))
1980 if ((err
=put_user(mbox_ptr
->cmd
.lcn
, &usr_data
->hdr
.lcn
)))
1983 if (mbox_ptr
->cmd
.length
> 0){
1984 if (mbox_ptr
->cmd
.length
> X25_MAX_DATA
)
1987 if (copy_to_user(usr_data
->data
, mbox_ptr
->data
, mbox_ptr
->cmd
.length
)){
1988 printk(KERN_INFO
"wansock: Copy failed !!!\n");
1995 /*============================================================
1998 * Before command can be execute, socket MBOX must
1999 * be created, and initialized with user data.
2000 *===========================================================*/
2002 static int set_ioctl_cmd (struct sock
*sk
, void *arg
)
2004 x25api_t
*usr_data
= (x25api_t
*)arg
;
2005 mbox_cmd_t
*mbox_ptr
;
2008 if (!wp_sk(sk
)->mbox
) {
2010 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
2016 if ((mbox_ptr
= kmalloc(sizeof(mbox_cmd_t
), GFP_ATOMIC
)) == NULL
)
2019 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
2020 wp_sk(sk
)->mbox
= mbox_ptr
;
2022 wanpipe_link_driver(dev
,sk
);
2025 mbox_ptr
= (mbox_cmd_t
*)wp_sk(sk
)->mbox
;
2026 memset(mbox_ptr
, 0, sizeof(mbox_cmd_t
));
2028 if (usr_data
== NULL
){
2031 if ((err
=get_user(mbox_ptr
->cmd
.qdm
, &usr_data
->hdr
.qdm
)))
2033 if ((err
=get_user(mbox_ptr
->cmd
.cause
, &usr_data
->hdr
.cause
)))
2035 if ((err
=get_user(mbox_ptr
->cmd
.diagn
, &usr_data
->hdr
.diagn
)))
2037 if ((err
=get_user(mbox_ptr
->cmd
.length
, &usr_data
->hdr
.length
)))
2039 if ((err
=get_user(mbox_ptr
->cmd
.result
, &usr_data
->hdr
.result
)))
2042 if (mbox_ptr
->cmd
.length
> 0){
2043 if (mbox_ptr
->cmd
.length
> X25_MAX_DATA
)
2046 if (copy_from_user(mbox_ptr
->data
, usr_data
->data
, mbox_ptr
->cmd
.length
)){
2047 printk(KERN_INFO
"Copy failed\n");
2055 /*======================================================================
2058 * Datagram poll: Again totally generic. This also handles
2059 * sequenced packet sockets providing the socket receive queue
2060 * is only ever holding data ready to receive.
2062 * Note: when you _don't_ use this routine for this protocol,
2063 * and you use a different write policy from sock_writeable()
2064 * then please supply your own write_space callback.
2065 *=====================================================================*/
2067 unsigned int wanpipe_poll(struct file
* file
, struct socket
*sock
, poll_table
*wait
)
2069 struct sock
*sk
= sock
->sk
;
2072 ++wp_sk(sk
)->poll_cnt
;
2074 poll_wait(file
, sk
->sk_sleep
, wait
);
2077 /* exceptional events? */
2078 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
)) {
2082 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
2086 if (!skb_queue_empty(&sk
->sk_receive_queue
)) {
2087 mask
|= POLLIN
| POLLRDNORM
;
2090 /* connection hasn't started yet */
2091 if (sk
->sk_state
== WANSOCK_CONNECTING
) {
2095 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2100 /* This check blocks the user process if there is
2101 * a packet already queued in the socket write queue.
2102 * This option is only for X25API protocol, for other
2103 * protocol like chdlc enable streaming mode,
2104 * where multiple packets can be pending in the socket
2107 if (wp_sk(sk
)->num
== htons(X25_PROT
)) {
2108 if (atomic_read(&wp_sk(sk
)->packet_sent
))
2113 if (sock_writeable(sk
)){
2114 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
2116 set_bit(SOCK_ASYNC_NOSPACE
, &sk
->sk_socket
->flags
);
2122 /*======================================================================
2125 * X25API Specific function. Set a socket into LISTENING MODE.
2126 *=====================================================================*/
2129 static int wanpipe_listen(struct socket
*sock
, int backlog
)
2131 struct sock
*sk
= sock
->sk
;
2133 /* This is x25 specific area if protocol doesn't
2134 * match, return error */
2135 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2138 if (sk
->sk_state
== WANSOCK_BIND_LISTEN
) {
2140 sk
->sk_max_ack_backlog
= backlog
;
2141 sk
->sk_state
= WANSOCK_LISTEN
;
2144 printk(KERN_INFO
"wansock: Listening sock was not binded\n");
2150 /*======================================================================
2153 * Connects the listening socket to the driver
2154 *=====================================================================*/
2156 static int wanpipe_link_card (struct sock
*sk
)
2158 sdla_t
*card
= (sdla_t
*)wp_sk(sk
)->card
;
2163 if ((card
->sk
!= NULL
) || (card
->func
!= NULL
)){
2164 printk(KERN_INFO
"wansock: Listening queue is already established\n");
2169 card
->func
=wanpipe_listen_rcv
;
2170 sock_set_flag(sk
, SOCK_ZAPPED
);
2175 /*======================================================================
2178 * X25API Specific function. Disconnect listening socket from
2180 *=====================================================================*/
2182 static void wanpipe_unlink_card (struct sock
*sk
)
2184 sdla_t
*card
= (sdla_t
*)wp_sk(sk
)->card
;
2192 /*======================================================================
2195 * Ioctl function calls this function to execute user command.
2196 * Connect() sytem call also calls this function to execute
2197 * place call. This function blocks until command is executed.
2198 *=====================================================================*/
2200 static int wanpipe_exec_cmd(struct sock
*sk
, int cmd
, unsigned int flags
)
2203 wanpipe_opt
*wp
= wp_sk(sk
);
2204 mbox_cmd_t
*mbox_ptr
= (mbox_cmd_t
*)wp
->mbox
;
2207 printk(KERN_INFO
"NO MBOX PTR !!!!!\n");
2211 /* This is x25 specific area if protocol doesn't
2212 * match, return error */
2213 if (wp
->num
!= htons(X25_PROT
))
2219 case SIOC_WANPIPE_ACCEPT_CALL
:
2221 if (sk
->sk_state
!= WANSOCK_CONNECTING
) {
2226 err
= execute_command(sk
,X25_ACCEPT_CALL
,0);
2230 /* Update. Mar6 2000.
2231 * Do not set the sock lcn number here, since
2232 * it is done in wanpipe_listen_rcv().
2234 if (sk
->sk_state
== WANSOCK_CONNECTED
) {
2235 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2236 DBG_PRINTK(KERN_INFO
"\nwansock: Accept OK %i\n",
2241 DBG_PRINTK (KERN_INFO
"\nwansock: Accept Failed %i\n",
2244 err
= -ECONNREFUSED
;
2248 case SIOC_WANPIPE_CLEAR_CALL
:
2250 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2256 /* Check if data buffers are pending for transmission,
2257 * if so, check whether user wants to wait until data
2258 * is transmitted, or clear a call and drop packets */
2260 if (atomic_read(&sk
->sk_wmem_alloc
) ||
2261 check_driver_busy(sk
)) {
2262 mbox_cmd_t
*mbox
= wp
->mbox
;
2263 if (mbox
->cmd
.qdm
& 0x80){
2264 mbox
->cmd
.result
= 0x35;
2270 sk
->sk_state
= WANSOCK_DISCONNECTING
;
2272 err
= execute_command(sk
,X25_CLEAR_CALL
,0);
2276 err
= -ECONNREFUSED
;
2277 if (sk
->sk_state
== WANSOCK_DISCONNECTED
) {
2278 DBG_PRINTK(KERN_INFO
"\nwansock: CLEAR OK %i\n",
2285 case SIOC_WANPIPE_RESET_CALL
:
2287 if (sk
->sk_state
!= WANSOCK_CONNECTED
) {
2293 /* Check if data buffers are pending for transmission,
2294 * if so, check whether user wants to wait until data
2295 * is transmitted, or reset a call and drop packets */
2297 if (atomic_read(&sk
->sk_wmem_alloc
) ||
2298 check_driver_busy(sk
)) {
2299 mbox_cmd_t
*mbox
= wp
->mbox
;
2300 if (mbox
->cmd
.qdm
& 0x80){
2301 mbox
->cmd
.result
= 0x35;
2308 err
= execute_command(sk
, X25_RESET
,0);
2312 err
= mbox_ptr
->cmd
.result
;
2316 case X25_PLACE_CALL
:
2318 err
=execute_command(sk
,X25_PLACE_CALL
,flags
);
2322 if (sk
->sk_state
== WANSOCK_CONNECTED
) {
2324 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2326 DBG_PRINTK(KERN_INFO
"\nwansock: PLACE CALL OK %i\n",
2330 } else if (sk
->sk_state
== WANSOCK_CONNECTING
&&
2331 (flags
& O_NONBLOCK
)) {
2332 wp
->lcn
= ((mbox_cmd_t
*)wp
->mbox
)->cmd
.lcn
;
2333 DBG_PRINTK(KERN_INFO
"\nwansock: Place Call OK: Waiting %i\n",
2339 DBG_PRINTK(KERN_INFO
"\nwansock: Place call Failed\n");
2340 err
= -ECONNREFUSED
;
2352 static int check_driver_busy (struct sock
*sk
)
2354 struct net_device
*dev
= dev_get_by_index(sk
->sk_bound_dev_if
);
2355 wanpipe_common_t
*chan
;
2362 if ((chan
=dev
->priv
) == NULL
)
2365 return atomic_read(&chan
->driver_busy
);
2369 /*======================================================================
2372 * ACCEPT() System call. X25API Specific function.
2373 * For each incoming call, create a new socket and
2374 * return it to the user.
2375 *=====================================================================*/
2377 static int wanpipe_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
2381 struct sk_buff
*skb
;
2382 DECLARE_WAITQUEUE(wait
, current
);
2385 if (newsock
->sk
!= NULL
){
2386 wanpipe_kill_sock_accept(newsock
->sk
);
2390 if ((sk
= sock
->sk
) == NULL
)
2393 if (sk
->sk_type
!= SOCK_RAW
)
2396 if (sk
->sk_state
!= WANSOCK_LISTEN
)
2399 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2402 add_wait_queue(sk
->sk_sleep
,&wait
);
2403 current
->state
= TASK_INTERRUPTIBLE
;
2405 skb
= skb_dequeue(&sk
->sk_receive_queue
);
2410 if (signal_pending(current
)) {
2416 current
->state
= TASK_RUNNING
;
2417 remove_wait_queue(sk
->sk_sleep
,&wait
);
2422 newsk
= get_newsk_from_skb(skb
);
2427 set_bit(1,&wanpipe_tx_critical
);
2428 write_lock(&wanpipe_sklist_lock
);
2429 sk_add_node(newsk
, &wanpipe_sklist
);
2430 write_unlock(&wanpipe_sklist_lock
);
2431 clear_bit(1,&wanpipe_tx_critical
);
2433 newsk
->sk_socket
= newsock
;
2434 newsk
->sk_sleep
= &newsock
->wait
;
2436 /* Now attach up the new socket */
2437 sk
->sk_ack_backlog
--;
2438 newsock
->sk
= newsk
;
2442 DBG_PRINTK(KERN_INFO
"\nwansock: ACCEPT Got LCN %i\n",
2447 /*======================================================================
2448 * get_newsk_from_skb
2450 * Accept() uses this function to get the address of the new
2452 *=====================================================================*/
2454 struct sock
* get_newsk_from_skb (struct sk_buff
*skb
)
2456 struct net_device
*dev
= skb
->dev
;
2457 wanpipe_common_t
*chan
;
2463 if ((chan
= dev
->priv
) == NULL
){
2470 return (struct sock
*)chan
->sk
;
2473 /*======================================================================
2476 * CONNECT() System Call. X25API specific function
2477 * Check the state of the sock, and execute PLACE_CALL command.
2478 * Connect can ether block or return without waiting for connection,
2479 * if specified by user.
2480 *=====================================================================*/
2482 static int wanpipe_connect(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
, int flags
)
2484 struct sock
*sk
= sock
->sk
;
2485 struct wan_sockaddr_ll
*addr
= (struct wan_sockaddr_ll
*)uaddr
;
2486 struct net_device
*dev
;
2489 if (wp_sk(sk
)->num
!= htons(X25_PROT
))
2492 if (sk
->sk_state
== WANSOCK_CONNECTED
)
2493 return -EISCONN
; /* No reconnect on a seqpacket socket */
2495 if (sk
->sk_state
!= WAN_DISCONNECTED
) {
2496 printk(KERN_INFO
"wansock: Trying to connect on channel NON DISCONNECT\n");
2497 return -ECONNREFUSED
;
2500 sk
->sk_state
= WANSOCK_DISCONNECTED
;
2501 sock
->state
= SS_UNCONNECTED
;
2503 if (addr_len
!= sizeof(struct wan_sockaddr_ll
))
2506 if (addr
->sll_family
!= AF_WANPIPE
)
2509 if ((dev
= dev_get_by_index(sk
->sk_bound_dev_if
)) == NULL
)
2510 return -ENETUNREACH
;
2514 if (!sock_flag(sk
, SOCK_ZAPPED
)) /* Must bind first - autobinding does not work */
2517 sock
->state
= SS_CONNECTING
;
2518 sk
->sk_state
= WANSOCK_CONNECTING
;
2520 if (!wp_sk(sk
)->mbox
) {
2521 if (wp_sk (sk
)->svc
)
2525 if ((err
=set_ioctl_cmd(sk
,NULL
)) < 0)
2530 if ((err
=wanpipe_exec_cmd(sk
, X25_PLACE_CALL
,flags
)) != 0){
2531 sock
->state
= SS_UNCONNECTED
;
2532 sk
->sk_state
= WANSOCK_CONNECTED
;
2536 if (sk
->sk_state
!= WANSOCK_CONNECTED
&& (flags
& O_NONBLOCK
)) {
2540 if (sk
->sk_state
!= WANSOCK_CONNECTED
) {
2541 sock
->state
= SS_UNCONNECTED
;
2542 return -ECONNREFUSED
;
2545 sock
->state
= SS_CONNECTED
;
2549 const struct proto_ops wanpipe_ops
= {
2550 .family
= PF_WANPIPE
,
2551 .owner
= THIS_MODULE
,
2552 .release
= wanpipe_release
,
2553 .bind
= wanpipe_bind
,
2554 .connect
= wanpipe_connect
,
2555 .socketpair
= sock_no_socketpair
,
2556 .accept
= wanpipe_accept
,
2557 .getname
= wanpipe_getname
,
2558 .poll
= wanpipe_poll
,
2559 .ioctl
= wanpipe_ioctl
,
2560 .listen
= wanpipe_listen
,
2561 .shutdown
= sock_no_shutdown
,
2562 .setsockopt
= sock_no_setsockopt
,
2563 .getsockopt
= sock_no_getsockopt
,
2564 .sendmsg
= wanpipe_sendmsg
,
2565 .recvmsg
= wanpipe_recvmsg
2568 static struct net_proto_family wanpipe_family_ops
= {
2569 .family
= PF_WANPIPE
,
2570 .create
= wanpipe_create
,
2571 .owner
= THIS_MODULE
,
2574 struct notifier_block wanpipe_netdev_notifier
= {
2575 .notifier_call
= wanpipe_notifier
,
2580 void cleanup_module(void)
2582 printk(KERN_INFO
"wansock: Cleaning up \n");
2583 unregister_netdevice_notifier(&wanpipe_netdev_notifier
);
2584 sock_unregister(PF_WANPIPE
);
2585 proto_unregister(&wanpipe_proto
);
2588 int init_module(void)
2592 printk(KERN_INFO
"wansock: Registering Socket \n");
2594 rc
= proto_register(&wanpipe_proto
, 0);
2598 sock_register(&wanpipe_family_ops
);
2599 register_netdevice_notifier(&wanpipe_netdev_notifier
);
2604 MODULE_LICENSE("GPL");
2605 MODULE_ALIAS_NETPROTO(PF_WANPIPE
);