1 /** -*- linux-c -*- ***********************************************************
2 * Linux PPP over Ethernet (PPPoX/PPPoE) Sockets
4 * PPPoX --- Generic PPP encapsulation socket family
5 * PPPoE --- PPP over Ethernet (RFC 2516)
10 * 220102 : Fix module use count on failure in pppoe_create, pppox_sk -acme
11 * 030700 : Fixed connect logic to allow for disconnect.
12 * 270700 : Fixed potential SMP problems; we must protect against
13 * simultaneous invocation of ppp_input
14 * and ppp_unregister_channel.
15 * 040800 : Respect reference count mechanisms on net-devices.
16 * 200800 : fix kfree(skb) in pppoe_rcv (acme)
17 * Module reference count is decremented in the right spot now,
18 * guards against sock_put not actually freeing the sk
20 * 051000 : Initialization cleanup.
21 * 111100 : Fix recvmsg.
22 * 050101 : Fix PADT procesing.
23 * 140501 : Use pppoe_rcv_core to handle all backlog. (Alexey)
24 * 170701 : Do not lock_sock with rwlock held. (DaveM)
25 * Ignore discovery frames if user has socket
27 * Ignore return value of dev_queue_xmit in __pppoe_xmit
28 * or else we may kfree an SKB twice. (DaveM)
29 * 190701 : When doing copies of skb's in __pppoe_xmit, always delete
30 * the original skb that was passed in on success, never on
31 * failure. Delete the copy of the skb on failure to avoid
33 * 081001 : Misc. cleanup (licence string, non-blocking, prevent
34 * reference of device on close).
35 * 121301 : New ppp channels interface; cannot unregister a channel
36 * from interrupts. Thus, we mark the socket as a ZOMBIE
37 * and do the unregistration later.
38 * 081002 : seq_file support for proc stuff -acme
39 * 111602 : Merge all 2.4 fixes into 2.5/2.6 tree. Label 2.5/2.6
40 * as version 0.7. Spacing cleanup.
41 * Author: Michal Ostrowski <mostrows@speakeasy.net>
43 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
44 * David S. Miller (davem@redhat.com)
47 * This program is free software; you can redistribute it and/or
48 * modify it under the terms of the GNU General Public License
49 * as published by the Free Software Foundation; either version
50 * 2 of the License, or (at your option) any later version.
54 #include <linux/string.h>
55 #include <linux/module.h>
56 #include <linux/kernel.h>
57 #include <linux/slab.h>
58 #include <linux/errno.h>
59 #include <linux/netdevice.h>
60 #include <linux/net.h>
61 #include <linux/inetdevice.h>
62 #include <linux/etherdevice.h>
63 #include <linux/skbuff.h>
64 #include <linux/init.h>
65 #include <linux/if_ether.h>
66 #include <linux/if_pppox.h>
67 #include <linux/ppp_channel.h>
68 #include <linux/ppp_defs.h>
69 #include <linux/if_ppp.h>
70 #include <linux/if_pppvar.h>
71 #include <linux/notifier.h>
72 #include <linux/file.h>
73 #include <linux/proc_fs.h>
74 #include <linux/seq_file.h>
78 #include <asm/uaccess.h>
80 static int __attribute__((unused
)) pppoe_debug
= 7;
81 #define PPPOE_HASH_BITS 4
82 #define PPPOE_HASH_SIZE (1<<PPPOE_HASH_BITS)
84 int pppoe_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
);
85 int pppoe_xmit(struct ppp_channel
*chan
, struct sk_buff
*skb
);
86 int __pppoe_xmit(struct sock
*sk
, struct sk_buff
*skb
);
88 struct proto_ops pppoe_ops
;
92 #define CHECKPTR(x,y) do { if (!(x) && pppoe_debug &7 ){ printk(KERN_CRIT "PPPoE Invalid pointer : %s , %p\n",#x,(x)); error=-EINVAL; goto y; }} while (0)
93 #define DEBUG(s,args...) do { if( pppoe_debug & (s) ) printk(KERN_CRIT args ); } while (0)
95 #define CHECKPTR(x,y) do { } while (0)
96 #define DEBUG(s,args...) do { } while (0)
101 static rwlock_t pppoe_hash_lock
= RW_LOCK_UNLOCKED
;
104 static inline int cmp_2_addr(struct pppoe_addr
*a
, struct pppoe_addr
*b
)
106 return (a
->sid
== b
->sid
&&
107 (memcmp(a
->remote
, b
->remote
, ETH_ALEN
) == 0));
110 static inline int cmp_addr(struct pppoe_addr
*a
, unsigned long sid
, char *addr
)
112 return (a
->sid
== sid
&&
113 (memcmp(a
->remote
,addr
,ETH_ALEN
) == 0));
116 static int hash_item(unsigned long sid
, unsigned char *addr
)
121 for (i
= 0; i
< ETH_ALEN
; ++i
) {
122 for (j
= 0; j
< 8/PPPOE_HASH_BITS
; ++j
) {
123 hash
^= addr
[i
] >> ( j
* PPPOE_HASH_BITS
);
127 for (i
= 0; i
< (sizeof(unsigned long)*8) / PPPOE_HASH_BITS
; ++i
)
128 hash
^= sid
>> (i
*PPPOE_HASH_BITS
);
130 return hash
& ( PPPOE_HASH_SIZE
- 1 );
133 /* zeroed because its in .bss */
134 static struct pppox_opt
*item_hash_table
[PPPOE_HASH_SIZE
];
136 /**********************************************************************
138 * Set/get/delete/rehash items (internal versions)
140 **********************************************************************/
141 static struct pppox_opt
*__get_item(unsigned long sid
, unsigned char *addr
)
143 int hash
= hash_item(sid
, addr
);
144 struct pppox_opt
*ret
;
146 ret
= item_hash_table
[hash
];
148 while (ret
&& !cmp_addr(&ret
->pppoe_pa
, sid
, addr
))
154 static int __set_item(struct pppox_opt
*po
)
156 int hash
= hash_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
157 struct pppox_opt
*ret
;
159 ret
= item_hash_table
[hash
];
161 if (cmp_2_addr(&ret
->pppoe_pa
, &po
->pppoe_pa
))
168 po
->next
= item_hash_table
[hash
];
169 item_hash_table
[hash
] = po
;
175 static struct pppox_opt
*__delete_item(unsigned long sid
, char *addr
)
177 int hash
= hash_item(sid
, addr
);
178 struct pppox_opt
*ret
, **src
;
180 ret
= item_hash_table
[hash
];
181 src
= &item_hash_table
[hash
];
184 if (cmp_addr(&ret
->pppoe_pa
, sid
, addr
)) {
196 /**********************************************************************
198 * Set/get/delete/rehash items
200 **********************************************************************/
201 static inline struct pppox_opt
*get_item(unsigned long sid
,
204 struct pppox_opt
*po
;
206 read_lock_bh(&pppoe_hash_lock
);
207 po
= __get_item(sid
, addr
);
210 read_unlock_bh(&pppoe_hash_lock
);
215 static inline struct pppox_opt
*get_item_by_addr(struct sockaddr_pppox
*sp
)
217 return get_item(sp
->sa_addr
.pppoe
.sid
, sp
->sa_addr
.pppoe
.remote
);
220 static inline int set_item(struct pppox_opt
*po
)
227 write_lock_bh(&pppoe_hash_lock
);
229 write_unlock_bh(&pppoe_hash_lock
);
234 static inline struct pppox_opt
*delete_item(unsigned long sid
, char *addr
)
236 struct pppox_opt
*ret
;
238 write_lock_bh(&pppoe_hash_lock
);
239 ret
= __delete_item(sid
, addr
);
240 write_unlock_bh(&pppoe_hash_lock
);
247 /***************************************************************************
249 * Handler for device events.
250 * Certain device events require that sockets be unconnected.
252 **************************************************************************/
254 static void pppoe_flush_dev(struct net_device
*dev
)
261 read_lock_bh(&pppoe_hash_lock
);
262 for (hash
= 0; hash
< PPPOE_HASH_SIZE
; hash
++) {
263 struct pppox_opt
*po
= item_hash_table
[hash
];
266 if (po
->pppoe_dev
== dev
) {
267 struct sock
*sk
= po
->sk
;
270 po
->pppoe_dev
= NULL
;
272 /* We hold a reference to SK, now drop the
273 * hash table lock so that we may attempt
274 * to lock the socket (which can sleep).
276 read_unlock_bh(&pppoe_hash_lock
);
281 (PPPOX_CONNECTED
| PPPOX_BOUND
)) {
282 pppox_unbind_sock(sk
);
284 sk
->sk_state
= PPPOX_ZOMBIE
;
285 sk
->sk_state_change(sk
);
292 read_lock_bh(&pppoe_hash_lock
);
294 /* Now restart from the beginning of this
295 * hash chain. We always NULL out pppoe_dev
296 * so we are guaranteed to make forward
299 po
= item_hash_table
[hash
];
305 read_unlock_bh(&pppoe_hash_lock
);
308 static int pppoe_device_event(struct notifier_block
*this,
309 unsigned long event
, void *ptr
)
311 struct net_device
*dev
= (struct net_device
*) ptr
;
313 /* Only look at sockets that are using this specific device. */
315 case NETDEV_CHANGEMTU
:
316 /* A change in mtu is a bad thing, requiring
317 * LCP re-negotiation.
320 case NETDEV_GOING_DOWN
:
322 /* Find every socket on this device and kill it. */
323 pppoe_flush_dev(dev
);
334 static struct notifier_block pppoe_notifier
= {
335 .notifier_call
= pppoe_device_event
,
341 /************************************************************************
343 * Do the real work of receiving a PPPoE Session frame.
345 ***********************************************************************/
346 int pppoe_rcv_core(struct sock
*sk
, struct sk_buff
*skb
)
348 struct pppox_opt
*po
= pppox_sk(sk
);
349 struct pppox_opt
*relay_po
= NULL
;
351 if (sk
->sk_state
& PPPOX_BOUND
) {
352 skb_pull(skb
, sizeof(struct pppoe_hdr
));
353 ppp_input(&po
->chan
, skb
);
354 } else if (sk
->sk_state
& PPPOX_RELAY
) {
355 relay_po
= get_item_by_addr(&po
->pppoe_relay
);
357 if (relay_po
== NULL
)
360 if ((relay_po
->sk
->sk_state
& PPPOX_CONNECTED
) == 0)
363 skb_pull(skb
, sizeof(struct pppoe_hdr
));
364 if (!__pppoe_xmit( relay_po
->sk
, skb
))
367 sock_queue_rcv_skb(sk
, skb
);
370 return NET_RX_SUCCESS
;
373 sock_put(relay_po
->sk
);
380 /************************************************************************
382 * Receive wrapper called in BH context.
384 ***********************************************************************/
385 static int pppoe_rcv(struct sk_buff
*skb
,
386 struct net_device
*dev
,
387 struct packet_type
*pt
)
390 struct pppoe_hdr
*ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
391 struct pppox_opt
*po
;
395 po
= get_item((unsigned long) ph
->sid
, skb
->mac
.ethernet
->h_source
);
405 /* Socket state is unknown, must put skb into backlog. */
406 if (sock_owned_by_user(sk
) != 0) {
407 sk_add_backlog(sk
, skb
);
408 ret
= NET_RX_SUCCESS
;
410 ret
= pppoe_rcv_core(sk
, skb
);
419 /************************************************************************
421 * Receive a PPPoE Discovery frame.
422 * This is solely for detection of PADT frames
424 ***********************************************************************/
425 static int pppoe_disc_rcv(struct sk_buff
*skb
,
426 struct net_device
*dev
,
427 struct packet_type
*pt
)
430 struct pppoe_hdr
*ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
431 struct pppox_opt
*po
;
433 if (ph
->code
!= PADT_CODE
)
436 po
= get_item((unsigned long) ph
->sid
, skb
->mac
.ethernet
->h_source
);
438 struct sock
*sk
= po
->sk
;
442 /* If the user has locked the socket, just ignore
443 * the packet. With the way two rcv protocols hook into
444 * one socket family type, we cannot (easily) distinguish
445 * what kind of SKB it is during backlog rcv.
447 if (sock_owned_by_user(sk
) == 0) {
448 /* We're no longer connect at the PPPOE layer,
449 * and must wait for ppp channel to disconnect us.
451 sk
->sk_state
= PPPOX_ZOMBIE
;
460 return NET_RX_SUCCESS
; /* Lies... :-) */
463 struct packet_type pppoes_ptype
= {
464 .type
= __constant_htons(ETH_P_PPP_SES
),
468 struct packet_type pppoed_ptype
= {
469 .type
= __constant_htons(ETH_P_PPP_DISC
),
470 .func
= pppoe_disc_rcv
,
473 /***********************************************************************
475 * Really kill the socket. (Called from pppox_sk_free if refcnt == 0.)
477 **********************************************************************/
478 static void pppoe_sk_free(struct sock
*sk
)
480 struct pppox_opt
*po
= pppox_sk(sk
);
487 /***********************************************************************
489 * Initialize a new struct sock.
491 **********************************************************************/
492 static int pppoe_create(struct socket
*sock
)
496 struct pppox_opt
*po
;
498 sk
= sk_alloc(PF_PPPOX
, GFP_KERNEL
, 1, NULL
);
502 sock_init_data(sock
, sk
);
503 sk_set_owner(sk
, THIS_MODULE
);
504 sock
->state
= SS_UNCONNECTED
;
505 sock
->ops
= &pppoe_ops
;
507 sk
->sk_backlog_rcv
= pppoe_rcv_core
;
508 sk
->sk_state
= PPPOX_NONE
;
509 sk
->sk_type
= SOCK_STREAM
;
510 sk
->sk_family
= PF_PPPOX
;
511 sk
->sk_protocol
= PX_PROTO_OE
;
512 sk
->sk_destruct
= pppoe_sk_free
;
514 po
= pppox_sk(sk
) = kmalloc(sizeof(*po
), GFP_KERNEL
);
517 memset(po
, 0, sizeof(*po
));
525 int pppoe_release(struct socket
*sock
)
527 struct sock
*sk
= sock
->sk
;
528 struct pppox_opt
*po
;
534 if (sock_flag(sk
, SOCK_DEAD
))
537 pppox_unbind_sock(sk
);
539 /* Signal the death of the socket. */
540 sk
->sk_state
= PPPOX_DEAD
;
543 if (po
->pppoe_pa
.sid
) {
544 delete_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
548 dev_put(po
->pppoe_dev
);
550 po
->pppoe_dev
= NULL
;
555 skb_queue_purge(&sk
->sk_receive_queue
);
562 int pppoe_connect(struct socket
*sock
, struct sockaddr
*uservaddr
,
563 int sockaddr_len
, int flags
)
565 struct sock
*sk
= sock
->sk
;
566 struct net_device
*dev
= NULL
;
567 struct sockaddr_pppox
*sp
= (struct sockaddr_pppox
*) uservaddr
;
568 struct pppox_opt
*po
= pppox_sk(sk
);
574 if (sp
->sa_protocol
!= PX_PROTO_OE
)
577 /* Check for already bound sockets */
579 if ((sk
->sk_state
& PPPOX_CONNECTED
) && sp
->sa_addr
.pppoe
.sid
)
582 /* Check for already disconnected sockets, on attempts to disconnect */
584 if ((sk
->sk_state
& PPPOX_DEAD
) && !sp
->sa_addr
.pppoe
.sid
)
588 if (po
->pppoe_pa
.sid
) {
589 pppox_unbind_sock(sk
);
591 /* Delete the old binding */
592 delete_item(po
->pppoe_pa
.sid
,po
->pppoe_pa
.remote
);
595 dev_put(po
->pppoe_dev
);
597 memset(po
, 0, sizeof(struct pppox_opt
));
600 sk
->sk_state
= PPPOX_NONE
;
603 /* Don't re-bind if sid==0 */
604 if (sp
->sa_addr
.pppoe
.sid
!= 0) {
605 dev
= dev_get_by_name(sp
->sa_addr
.pppoe
.dev
);
613 if (!(dev
->flags
& IFF_UP
))
616 memcpy(&po
->pppoe_pa
,
618 sizeof(struct pppoe_addr
));
620 error
= set_item(po
);
624 po
->chan
.hdrlen
= (sizeof(struct pppoe_hdr
) +
625 dev
->hard_header_len
);
627 po
->chan
.private = sk
;
628 po
->chan
.ops
= &pppoe_chan_ops
;
630 error
= ppp_register_channel(&po
->chan
);
634 sk
->sk_state
= PPPOX_CONNECTED
;
637 po
->num
= sp
->sa_addr
.pppoe
.sid
;
644 dev_put(po
->pppoe_dev
);
645 po
->pppoe_dev
= NULL
;
651 int pppoe_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
652 int *usockaddr_len
, int peer
)
654 int len
= sizeof(struct sockaddr_pppox
);
655 struct sockaddr_pppox sp
;
657 sp
.sa_family
= AF_PPPOX
;
658 sp
.sa_protocol
= PX_PROTO_OE
;
659 memcpy(&sp
.sa_addr
.pppoe
, &pppox_sk(sock
->sk
)->pppoe_pa
,
660 sizeof(struct pppoe_addr
));
662 memcpy(uaddr
, &sp
, len
);
664 *usockaddr_len
= len
;
670 int pppoe_ioctl(struct socket
*sock
, unsigned int cmd
,
673 struct sock
*sk
= sock
->sk
;
674 struct pppox_opt
*po
= pppox_sk(sk
);
682 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
686 if (put_user(po
->pppoe_dev
->mtu
-
687 sizeof(struct pppoe_hdr
) -
696 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
700 if (get_user(val
,(int *) arg
))
703 if (val
< (po
->pppoe_dev
->mtu
704 - sizeof(struct pppoe_hdr
)
713 if (get_user(val
, (int *) arg
))
720 struct pppox_opt
*relay_po
;
723 if (sk
->sk_state
& (PPPOX_BOUND
| PPPOX_ZOMBIE
| PPPOX_DEAD
))
727 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
730 /* PPPoE address from the user specifies an outbound
731 PPPoE address to which frames are forwarded to */
733 if (copy_from_user(&po
->pppoe_relay
,
735 sizeof(struct sockaddr_pppox
)))
739 if (po
->pppoe_relay
.sa_family
!= AF_PPPOX
||
740 po
->pppoe_relay
.sa_protocol
!= PX_PROTO_OE
)
743 /* Check that the socket referenced by the address
745 relay_po
= get_item_by_addr(&po
->pppoe_relay
);
750 sock_put(relay_po
->sk
);
751 sk
->sk_state
|= PPPOX_RELAY
;
758 if (!(sk
->sk_state
& PPPOX_RELAY
))
761 sk
->sk_state
&= ~PPPOX_RELAY
;
772 int pppoe_sendmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*m
,
775 struct sk_buff
*skb
= NULL
;
776 struct sock
*sk
= sock
->sk
;
777 struct pppox_opt
*po
= pppox_sk(sk
);
779 struct pppoe_hdr hdr
;
780 struct pppoe_hdr
*ph
;
781 struct net_device
*dev
;
784 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
)) {
799 if (total_len
> (dev
->mtu
+ dev
->hard_header_len
))
803 skb
= sock_wmalloc(sk
, total_len
+ dev
->hard_header_len
+ 32,
810 /* Reserve space for headers. */
811 skb_reserve(skb
, dev
->hard_header_len
);
812 skb
->nh
.raw
= skb
->data
;
816 skb
->priority
= sk
->sk_priority
;
817 skb
->protocol
= __constant_htons(ETH_P_PPP_SES
);
819 ph
= (struct pppoe_hdr
*) skb_put(skb
, total_len
+ sizeof(struct pppoe_hdr
));
820 start
= (char *) &ph
->tag
[0];
822 error
= memcpy_fromiovec(start
, m
->msg_iov
, total_len
);
830 dev
->hard_header(skb
, dev
, ETH_P_PPP_SES
,
831 po
->pppoe_pa
.remote
, NULL
, total_len
);
833 memcpy(ph
, &hdr
, sizeof(struct pppoe_hdr
));
835 ph
->length
= htons(total_len
);
845 /************************************************************************
847 * xmit function for internal use.
849 ***********************************************************************/
850 int __pppoe_xmit(struct sock
*sk
, struct sk_buff
*skb
)
852 struct pppox_opt
*po
= pppox_sk(sk
);
853 struct net_device
*dev
= po
->pppoe_dev
;
854 struct pppoe_hdr hdr
;
855 struct pppoe_hdr
*ph
;
856 int headroom
= skb_headroom(skb
);
857 int data_len
= skb
->len
;
858 struct sk_buff
*skb2
;
860 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
))
867 hdr
.length
= htons(skb
->len
);
872 /* Copy the skb if there is no space for the header. */
873 if (headroom
< (sizeof(struct pppoe_hdr
) + dev
->hard_header_len
)) {
874 skb2
= dev_alloc_skb(32+skb
->len
+
875 sizeof(struct pppoe_hdr
) +
876 dev
->hard_header_len
);
881 skb_reserve(skb2
, dev
->hard_header_len
+ sizeof(struct pppoe_hdr
));
882 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
884 /* Make a clone so as to not disturb the original skb,
885 * give dev_queue_xmit something it can free.
887 skb2
= skb_clone(skb
, GFP_ATOMIC
);
890 ph
= (struct pppoe_hdr
*) skb_push(skb2
, sizeof(struct pppoe_hdr
));
891 memcpy(ph
, &hdr
, sizeof(struct pppoe_hdr
));
892 skb2
->protocol
= __constant_htons(ETH_P_PPP_SES
);
894 skb2
->nh
.raw
= skb2
->data
;
898 dev
->hard_header(skb2
, dev
, ETH_P_PPP_SES
,
899 po
->pppoe_pa
.remote
, NULL
, data_len
);
901 /* We're transmitting skb2, and assuming that dev_queue_xmit
902 * will free it. The generic ppp layer however, is expecting
903 * that we give back 'skb' (not 'skb2') in case of failure,
904 * but free it in case of success.
907 if (dev_queue_xmit(skb2
) < 0)
918 /************************************************************************
920 * xmit function called by generic PPP driver
921 * sends PPP frame over PPPoE socket
923 ***********************************************************************/
924 int pppoe_xmit(struct ppp_channel
*chan
, struct sk_buff
*skb
)
926 struct sock
*sk
= (struct sock
*) chan
->private;
927 return __pppoe_xmit(sk
, skb
);
931 struct ppp_channel_ops pppoe_chan_ops
= { pppoe_xmit
, NULL
};
933 int pppoe_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
934 struct msghdr
*m
, int total_len
, int flags
)
936 struct sock
*sk
= sock
->sk
;
937 struct sk_buff
*skb
= NULL
;
940 struct pppoe_hdr
*ph
= NULL
;
942 if (sk
->sk_state
& PPPOX_BOUND
) {
947 skb
= skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
,
948 flags
& MSG_DONTWAIT
, &error
);
958 ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
959 len
= ntohs(ph
->length
);
961 error
= memcpy_toiovec(m
->msg_iov
, (unsigned char *) &ph
->tag
[0], len
);
974 #ifdef CONFIG_PROC_FS
975 static int pppoe_seq_show(struct seq_file
*seq
, void *v
)
977 struct pppox_opt
*po
;
980 if (v
== (void *)1) {
981 seq_puts(seq
, "Id Address Device\n");
986 dev_name
= po
->pppoe_pa
.dev
;
988 seq_printf(seq
, "%08X %02X:%02X:%02X:%02X:%02X:%02X %8s\n",
990 po
->pppoe_pa
.remote
[0], po
->pppoe_pa
.remote
[1],
991 po
->pppoe_pa
.remote
[2], po
->pppoe_pa
.remote
[3],
992 po
->pppoe_pa
.remote
[4], po
->pppoe_pa
.remote
[5], dev_name
);
997 static __inline__
struct pppox_opt
*pppoe_get_idx(loff_t pos
)
999 struct pppox_opt
*po
= NULL
;
1002 for (; i
< PPPOE_HASH_SIZE
; i
++) {
1003 po
= item_hash_table
[i
];
1014 static void *pppoe_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1018 read_lock_bh(&pppoe_hash_lock
);
1019 return l
? pppoe_get_idx(--l
) : (void *)1;
1022 static void *pppoe_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1024 struct pppox_opt
*po
;
1027 if (v
== (void *)1) {
1028 po
= pppoe_get_idx(0);
1034 int hash
= hash_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
1036 while (++hash
< PPPOE_HASH_SIZE
) {
1037 po
= item_hash_table
[hash
];
1046 static void pppoe_seq_stop(struct seq_file
*seq
, void *v
)
1048 read_unlock_bh(&pppoe_hash_lock
);
1051 struct seq_operations pppoe_seq_ops
= {
1052 .start
= pppoe_seq_start
,
1053 .next
= pppoe_seq_next
,
1054 .stop
= pppoe_seq_stop
,
1055 .show
= pppoe_seq_show
,
1058 static int pppoe_seq_open(struct inode
*inode
, struct file
*file
)
1060 return seq_open(file
, &pppoe_seq_ops
);
1063 static struct file_operations pppoe_seq_fops
= {
1064 .owner
= THIS_MODULE
,
1065 .open
= pppoe_seq_open
,
1067 .llseek
= seq_lseek
,
1068 .release
= seq_release
,
1070 #endif /* CONFIG_PROC_FS */
1072 /* ->ioctl are set at pppox_create */
1074 struct proto_ops pppoe_ops
= {
1076 .owner
= THIS_MODULE
,
1077 .release
= pppoe_release
,
1078 .bind
= sock_no_bind
,
1079 .connect
= pppoe_connect
,
1080 .socketpair
= sock_no_socketpair
,
1081 .accept
= sock_no_accept
,
1082 .getname
= pppoe_getname
,
1083 .poll
= datagram_poll
,
1084 .listen
= sock_no_listen
,
1085 .shutdown
= sock_no_shutdown
,
1086 .setsockopt
= sock_no_setsockopt
,
1087 .getsockopt
= sock_no_getsockopt
,
1088 .sendmsg
= pppoe_sendmsg
,
1089 .recvmsg
= pppoe_recvmsg
,
1090 .mmap
= sock_no_mmap
1093 struct pppox_proto pppoe_proto
= {
1094 .create
= pppoe_create
,
1095 .ioctl
= pppoe_ioctl
,
1096 .owner
= THIS_MODULE
,
1100 int __init
pppoe_init(void)
1102 int err
= register_pppox_proto(PX_PROTO_OE
, &pppoe_proto
);
1106 #ifdef CONFIG_PROC_FS
1108 struct proc_dir_entry
*p
= create_proc_entry("pppoe", S_IRUGO
,
1112 goto out_unregister
;
1114 p
->proc_fops
= &pppoe_seq_fops
;
1117 #endif /* CONFIG_PROC_FS */
1118 dev_add_pack(&pppoes_ptype
);
1119 dev_add_pack(&pppoed_ptype
);
1120 register_netdevice_notifier(&pppoe_notifier
);
1124 unregister_pppox_proto(PX_PROTO_OE
);
1128 void __exit
pppoe_exit(void)
1130 unregister_pppox_proto(PX_PROTO_OE
);
1131 dev_remove_pack(&pppoes_ptype
);
1132 dev_remove_pack(&pppoed_ptype
);
1133 unregister_netdevice_notifier(&pppoe_notifier
);
1134 #ifdef CONFIG_PROC_FS
1135 remove_proc_entry("pppoe", proc_net
);
1139 module_init(pppoe_init
);
1140 module_exit(pppoe_exit
);
1142 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
1143 MODULE_DESCRIPTION("PPP over Ethernet driver");
1144 MODULE_LICENSE("GPL");