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/notifier.h>
71 #include <linux/file.h>
72 #include <linux/proc_fs.h>
73 #include <linux/seq_file.h>
77 #include <asm/uaccess.h>
79 #define PPPOE_HASH_BITS 4
80 #define PPPOE_HASH_SIZE (1<<PPPOE_HASH_BITS)
82 static struct ppp_channel_ops pppoe_chan_ops
;
84 static int pppoe_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
);
85 static int pppoe_xmit(struct ppp_channel
*chan
, struct sk_buff
*skb
);
86 static int __pppoe_xmit(struct sock
*sk
, struct sk_buff
*skb
);
88 static const struct proto_ops pppoe_ops
;
89 static DEFINE_RWLOCK(pppoe_hash_lock
);
91 static struct ppp_channel_ops pppoe_chan_ops
;
93 static inline int cmp_2_addr(struct pppoe_addr
*a
, struct pppoe_addr
*b
)
95 return (a
->sid
== b
->sid
&&
96 (memcmp(a
->remote
, b
->remote
, ETH_ALEN
) == 0));
99 static inline int cmp_addr(struct pppoe_addr
*a
, unsigned long sid
, char *addr
)
101 return (a
->sid
== sid
&&
102 (memcmp(a
->remote
,addr
,ETH_ALEN
) == 0));
105 static int hash_item(unsigned long sid
, unsigned char *addr
)
110 for (i
= 0; i
< ETH_ALEN
; ++i
) {
111 for (j
= 0; j
< 8/PPPOE_HASH_BITS
; ++j
) {
112 hash
^= addr
[i
] >> ( j
* PPPOE_HASH_BITS
);
116 for (i
= 0; i
< (sizeof(unsigned long)*8) / PPPOE_HASH_BITS
; ++i
)
117 hash
^= sid
>> (i
*PPPOE_HASH_BITS
);
119 return hash
& ( PPPOE_HASH_SIZE
- 1 );
122 /* zeroed because its in .bss */
123 static struct pppox_sock
*item_hash_table
[PPPOE_HASH_SIZE
];
125 /**********************************************************************
127 * Set/get/delete/rehash items (internal versions)
129 **********************************************************************/
130 static struct pppox_sock
*__get_item(unsigned long sid
, unsigned char *addr
)
132 int hash
= hash_item(sid
, addr
);
133 struct pppox_sock
*ret
;
135 ret
= item_hash_table
[hash
];
137 while (ret
&& !cmp_addr(&ret
->pppoe_pa
, sid
, addr
))
143 static int __set_item(struct pppox_sock
*po
)
145 int hash
= hash_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
146 struct pppox_sock
*ret
;
148 ret
= item_hash_table
[hash
];
150 if (cmp_2_addr(&ret
->pppoe_pa
, &po
->pppoe_pa
))
157 po
->next
= item_hash_table
[hash
];
158 item_hash_table
[hash
] = po
;
164 static struct pppox_sock
*__delete_item(unsigned long sid
, char *addr
)
166 int hash
= hash_item(sid
, addr
);
167 struct pppox_sock
*ret
, **src
;
169 ret
= item_hash_table
[hash
];
170 src
= &item_hash_table
[hash
];
173 if (cmp_addr(&ret
->pppoe_pa
, sid
, addr
)) {
185 /**********************************************************************
187 * Set/get/delete/rehash items
189 **********************************************************************/
190 static inline struct pppox_sock
*get_item(unsigned long sid
,
193 struct pppox_sock
*po
;
195 read_lock_bh(&pppoe_hash_lock
);
196 po
= __get_item(sid
, addr
);
198 sock_hold(sk_pppox(po
));
199 read_unlock_bh(&pppoe_hash_lock
);
204 static inline struct pppox_sock
*get_item_by_addr(struct sockaddr_pppox
*sp
)
206 return get_item(sp
->sa_addr
.pppoe
.sid
, sp
->sa_addr
.pppoe
.remote
);
209 static inline int set_item(struct pppox_sock
*po
)
216 write_lock_bh(&pppoe_hash_lock
);
218 write_unlock_bh(&pppoe_hash_lock
);
223 static inline struct pppox_sock
*delete_item(unsigned long sid
, char *addr
)
225 struct pppox_sock
*ret
;
227 write_lock_bh(&pppoe_hash_lock
);
228 ret
= __delete_item(sid
, addr
);
229 write_unlock_bh(&pppoe_hash_lock
);
236 /***************************************************************************
238 * Handler for device events.
239 * Certain device events require that sockets be unconnected.
241 **************************************************************************/
243 static void pppoe_flush_dev(struct net_device
*dev
)
249 read_lock_bh(&pppoe_hash_lock
);
250 for (hash
= 0; hash
< PPPOE_HASH_SIZE
; hash
++) {
251 struct pppox_sock
*po
= item_hash_table
[hash
];
254 if (po
->pppoe_dev
== dev
) {
255 struct sock
*sk
= sk_pppox(po
);
258 po
->pppoe_dev
= NULL
;
260 /* We hold a reference to SK, now drop the
261 * hash table lock so that we may attempt
262 * to lock the socket (which can sleep).
264 read_unlock_bh(&pppoe_hash_lock
);
269 (PPPOX_CONNECTED
| PPPOX_BOUND
)) {
270 pppox_unbind_sock(sk
);
272 sk
->sk_state
= PPPOX_ZOMBIE
;
273 sk
->sk_state_change(sk
);
280 read_lock_bh(&pppoe_hash_lock
);
282 /* Now restart from the beginning of this
283 * hash chain. We always NULL out pppoe_dev
284 * so we are guaranteed to make forward
287 po
= item_hash_table
[hash
];
293 read_unlock_bh(&pppoe_hash_lock
);
296 static int pppoe_device_event(struct notifier_block
*this,
297 unsigned long event
, void *ptr
)
299 struct net_device
*dev
= (struct net_device
*) ptr
;
301 /* Only look at sockets that are using this specific device. */
303 case NETDEV_CHANGEMTU
:
304 /* A change in mtu is a bad thing, requiring
305 * LCP re-negotiation.
308 case NETDEV_GOING_DOWN
:
310 /* Find every socket on this device and kill it. */
311 pppoe_flush_dev(dev
);
322 static struct notifier_block pppoe_notifier
= {
323 .notifier_call
= pppoe_device_event
,
327 /************************************************************************
329 * Do the real work of receiving a PPPoE Session frame.
331 ***********************************************************************/
332 static int pppoe_rcv_core(struct sock
*sk
, struct sk_buff
*skb
)
334 struct pppox_sock
*po
= pppox_sk(sk
);
335 struct pppox_sock
*relay_po
= NULL
;
337 if (sk
->sk_state
& PPPOX_BOUND
) {
338 struct pppoe_hdr
*ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
339 int len
= ntohs(ph
->length
);
340 skb_pull_rcsum(skb
, sizeof(struct pppoe_hdr
));
341 if (pskb_trim_rcsum(skb
, len
))
344 ppp_input(&po
->chan
, skb
);
345 } else if (sk
->sk_state
& PPPOX_RELAY
) {
346 relay_po
= get_item_by_addr(&po
->pppoe_relay
);
348 if (relay_po
== NULL
)
351 if ((sk_pppox(relay_po
)->sk_state
& PPPOX_CONNECTED
) == 0)
354 skb_pull(skb
, sizeof(struct pppoe_hdr
));
355 if (!__pppoe_xmit(sk_pppox(relay_po
), skb
))
358 if (sock_queue_rcv_skb(sk
, skb
))
362 return NET_RX_SUCCESS
;
365 sock_put(sk_pppox(relay_po
));
372 /************************************************************************
374 * Receive wrapper called in BH context.
376 ***********************************************************************/
377 static int pppoe_rcv(struct sk_buff
*skb
,
378 struct net_device
*dev
,
379 struct packet_type
*pt
,
380 struct net_device
*orig_dev
)
383 struct pppoe_hdr
*ph
;
384 struct pppox_sock
*po
;
386 if (!pskb_may_pull(skb
, sizeof(struct pppoe_hdr
)))
389 if (!(skb
= skb_share_check(skb
, GFP_ATOMIC
)))
392 ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
394 po
= get_item((unsigned long) ph
->sid
, eth_hdr(skb
)->h_source
);
396 return sk_receive_skb(sk_pppox(po
), skb
, 0);
403 /************************************************************************
405 * Receive a PPPoE Discovery frame.
406 * This is solely for detection of PADT frames
408 ***********************************************************************/
409 static int pppoe_disc_rcv(struct sk_buff
*skb
,
410 struct net_device
*dev
,
411 struct packet_type
*pt
,
412 struct net_device
*orig_dev
)
415 struct pppoe_hdr
*ph
;
416 struct pppox_sock
*po
;
418 if (!pskb_may_pull(skb
, sizeof(struct pppoe_hdr
)))
421 if (!(skb
= skb_share_check(skb
, GFP_ATOMIC
)))
424 ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
425 if (ph
->code
!= PADT_CODE
)
428 po
= get_item((unsigned long) ph
->sid
, eth_hdr(skb
)->h_source
);
430 struct sock
*sk
= sk_pppox(po
);
434 /* If the user has locked the socket, just ignore
435 * the packet. With the way two rcv protocols hook into
436 * one socket family type, we cannot (easily) distinguish
437 * what kind of SKB it is during backlog rcv.
439 if (sock_owned_by_user(sk
) == 0) {
440 /* We're no longer connect at the PPPOE layer,
441 * and must wait for ppp channel to disconnect us.
443 sk
->sk_state
= PPPOX_ZOMBIE
;
453 return NET_RX_SUCCESS
; /* Lies... :-) */
456 static struct packet_type pppoes_ptype
= {
457 .type
= __constant_htons(ETH_P_PPP_SES
),
461 static struct packet_type pppoed_ptype
= {
462 .type
= __constant_htons(ETH_P_PPP_DISC
),
463 .func
= pppoe_disc_rcv
,
466 static struct proto pppoe_sk_proto
= {
468 .owner
= THIS_MODULE
,
469 .obj_size
= sizeof(struct pppox_sock
),
472 /***********************************************************************
474 * Initialize a new struct sock.
476 **********************************************************************/
477 static int pppoe_create(struct socket
*sock
)
482 sk
= sk_alloc(PF_PPPOX
, GFP_KERNEL
, &pppoe_sk_proto
, 1);
486 sock_init_data(sock
, sk
);
488 sock
->state
= SS_UNCONNECTED
;
489 sock
->ops
= &pppoe_ops
;
491 sk
->sk_backlog_rcv
= pppoe_rcv_core
;
492 sk
->sk_state
= PPPOX_NONE
;
493 sk
->sk_type
= SOCK_STREAM
;
494 sk
->sk_family
= PF_PPPOX
;
495 sk
->sk_protocol
= PX_PROTO_OE
;
501 static int pppoe_release(struct socket
*sock
)
503 struct sock
*sk
= sock
->sk
;
504 struct pppox_sock
*po
;
510 if (sock_flag(sk
, SOCK_DEAD
))
513 pppox_unbind_sock(sk
);
515 /* Signal the death of the socket. */
516 sk
->sk_state
= PPPOX_DEAD
;
519 if (po
->pppoe_pa
.sid
) {
520 delete_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
524 dev_put(po
->pppoe_dev
);
526 po
->pppoe_dev
= NULL
;
531 skb_queue_purge(&sk
->sk_receive_queue
);
538 static int pppoe_connect(struct socket
*sock
, struct sockaddr
*uservaddr
,
539 int sockaddr_len
, int flags
)
541 struct sock
*sk
= sock
->sk
;
542 struct net_device
*dev
= NULL
;
543 struct sockaddr_pppox
*sp
= (struct sockaddr_pppox
*) uservaddr
;
544 struct pppox_sock
*po
= pppox_sk(sk
);
550 if (sp
->sa_protocol
!= PX_PROTO_OE
)
553 /* Check for already bound sockets */
555 if ((sk
->sk_state
& PPPOX_CONNECTED
) && sp
->sa_addr
.pppoe
.sid
)
558 /* Check for already disconnected sockets, on attempts to disconnect */
560 if ((sk
->sk_state
& PPPOX_DEAD
) && !sp
->sa_addr
.pppoe
.sid
)
564 if (po
->pppoe_pa
.sid
) {
565 pppox_unbind_sock(sk
);
567 /* Delete the old binding */
568 delete_item(po
->pppoe_pa
.sid
,po
->pppoe_pa
.remote
);
571 dev_put(po
->pppoe_dev
);
573 memset(sk_pppox(po
) + 1, 0,
574 sizeof(struct pppox_sock
) - sizeof(struct sock
));
576 sk
->sk_state
= PPPOX_NONE
;
579 /* Don't re-bind if sid==0 */
580 if (sp
->sa_addr
.pppoe
.sid
!= 0) {
581 dev
= dev_get_by_name(sp
->sa_addr
.pppoe
.dev
);
589 if (!(dev
->flags
& IFF_UP
))
592 memcpy(&po
->pppoe_pa
,
594 sizeof(struct pppoe_addr
));
596 error
= set_item(po
);
600 po
->chan
.hdrlen
= (sizeof(struct pppoe_hdr
) +
601 dev
->hard_header_len
);
603 po
->chan
.mtu
= dev
->mtu
- sizeof(struct pppoe_hdr
);
604 po
->chan
.private = sk
;
605 po
->chan
.ops
= &pppoe_chan_ops
;
607 error
= ppp_register_channel(&po
->chan
);
611 sk
->sk_state
= PPPOX_CONNECTED
;
614 po
->num
= sp
->sa_addr
.pppoe
.sid
;
621 dev_put(po
->pppoe_dev
);
622 po
->pppoe_dev
= NULL
;
628 static int pppoe_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
629 int *usockaddr_len
, int peer
)
631 int len
= sizeof(struct sockaddr_pppox
);
632 struct sockaddr_pppox sp
;
634 sp
.sa_family
= AF_PPPOX
;
635 sp
.sa_protocol
= PX_PROTO_OE
;
636 memcpy(&sp
.sa_addr
.pppoe
, &pppox_sk(sock
->sk
)->pppoe_pa
,
637 sizeof(struct pppoe_addr
));
639 memcpy(uaddr
, &sp
, len
);
641 *usockaddr_len
= len
;
647 static int pppoe_ioctl(struct socket
*sock
, unsigned int cmd
,
650 struct sock
*sk
= sock
->sk
;
651 struct pppox_sock
*po
= pppox_sk(sk
);
659 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
663 if (put_user(po
->pppoe_dev
->mtu
-
664 sizeof(struct pppoe_hdr
) -
673 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
677 if (get_user(val
,(int __user
*) arg
))
680 if (val
< (po
->pppoe_dev
->mtu
681 - sizeof(struct pppoe_hdr
)
690 if (get_user(val
, (int __user
*) arg
))
697 struct pppox_sock
*relay_po
;
700 if (sk
->sk_state
& (PPPOX_BOUND
| PPPOX_ZOMBIE
| PPPOX_DEAD
))
704 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
707 /* PPPoE address from the user specifies an outbound
708 PPPoE address to which frames are forwarded to */
710 if (copy_from_user(&po
->pppoe_relay
,
712 sizeof(struct sockaddr_pppox
)))
716 if (po
->pppoe_relay
.sa_family
!= AF_PPPOX
||
717 po
->pppoe_relay
.sa_protocol
!= PX_PROTO_OE
)
720 /* Check that the socket referenced by the address
722 relay_po
= get_item_by_addr(&po
->pppoe_relay
);
727 sock_put(sk_pppox(relay_po
));
728 sk
->sk_state
|= PPPOX_RELAY
;
735 if (!(sk
->sk_state
& PPPOX_RELAY
))
738 sk
->sk_state
&= ~PPPOX_RELAY
;
749 static int pppoe_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
750 struct msghdr
*m
, size_t total_len
)
752 struct sk_buff
*skb
= NULL
;
753 struct sock
*sk
= sock
->sk
;
754 struct pppox_sock
*po
= pppox_sk(sk
);
756 struct pppoe_hdr hdr
;
757 struct pppoe_hdr
*ph
;
758 struct net_device
*dev
;
761 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
)) {
776 if (total_len
> (dev
->mtu
+ dev
->hard_header_len
))
780 skb
= sock_wmalloc(sk
, total_len
+ dev
->hard_header_len
+ 32,
787 /* Reserve space for headers. */
788 skb_reserve(skb
, dev
->hard_header_len
);
789 skb
->nh
.raw
= skb
->data
;
793 skb
->priority
= sk
->sk_priority
;
794 skb
->protocol
= __constant_htons(ETH_P_PPP_SES
);
796 ph
= (struct pppoe_hdr
*) skb_put(skb
, total_len
+ sizeof(struct pppoe_hdr
));
797 start
= (char *) &ph
->tag
[0];
799 error
= memcpy_fromiovec(start
, m
->msg_iov
, total_len
);
807 dev
->hard_header(skb
, dev
, ETH_P_PPP_SES
,
808 po
->pppoe_pa
.remote
, NULL
, total_len
);
810 memcpy(ph
, &hdr
, sizeof(struct pppoe_hdr
));
812 ph
->length
= htons(total_len
);
822 /************************************************************************
824 * xmit function for internal use.
826 ***********************************************************************/
827 static int __pppoe_xmit(struct sock
*sk
, struct sk_buff
*skb
)
829 struct pppox_sock
*po
= pppox_sk(sk
);
830 struct net_device
*dev
= po
->pppoe_dev
;
831 struct pppoe_hdr hdr
;
832 struct pppoe_hdr
*ph
;
833 int headroom
= skb_headroom(skb
);
834 int data_len
= skb
->len
;
835 struct sk_buff
*skb2
;
837 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
))
844 hdr
.length
= htons(skb
->len
);
849 /* Copy the skb if there is no space for the header. */
850 if (headroom
< (sizeof(struct pppoe_hdr
) + dev
->hard_header_len
)) {
851 skb2
= dev_alloc_skb(32+skb
->len
+
852 sizeof(struct pppoe_hdr
) +
853 dev
->hard_header_len
);
858 skb_reserve(skb2
, dev
->hard_header_len
+ sizeof(struct pppoe_hdr
));
859 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
861 /* Make a clone so as to not disturb the original skb,
862 * give dev_queue_xmit something it can free.
864 skb2
= skb_clone(skb
, GFP_ATOMIC
);
870 ph
= (struct pppoe_hdr
*) skb_push(skb2
, sizeof(struct pppoe_hdr
));
871 memcpy(ph
, &hdr
, sizeof(struct pppoe_hdr
));
872 skb2
->protocol
= __constant_htons(ETH_P_PPP_SES
);
874 skb2
->nh
.raw
= skb2
->data
;
878 dev
->hard_header(skb2
, dev
, ETH_P_PPP_SES
,
879 po
->pppoe_pa
.remote
, NULL
, data_len
);
881 /* We're transmitting skb2, and assuming that dev_queue_xmit
882 * will free it. The generic ppp layer however, is expecting
883 * that we give back 'skb' (not 'skb2') in case of failure,
884 * but free it in case of success.
887 if (dev_queue_xmit(skb2
) < 0)
898 /************************************************************************
900 * xmit function called by generic PPP driver
901 * sends PPP frame over PPPoE socket
903 ***********************************************************************/
904 static int pppoe_xmit(struct ppp_channel
*chan
, struct sk_buff
*skb
)
906 struct sock
*sk
= (struct sock
*) chan
->private;
907 return __pppoe_xmit(sk
, skb
);
911 static struct ppp_channel_ops pppoe_chan_ops
= {
912 .start_xmit
= pppoe_xmit
,
915 static int pppoe_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
916 struct msghdr
*m
, size_t total_len
, int flags
)
918 struct sock
*sk
= sock
->sk
;
919 struct sk_buff
*skb
= NULL
;
922 struct pppoe_hdr
*ph
= NULL
;
924 if (sk
->sk_state
& PPPOX_BOUND
) {
929 skb
= skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
,
930 flags
& MSG_DONTWAIT
, &error
);
940 ph
= (struct pppoe_hdr
*) skb
->nh
.raw
;
941 len
= ntohs(ph
->length
);
943 error
= memcpy_toiovec(m
->msg_iov
, (unsigned char *) &ph
->tag
[0], len
);
956 #ifdef CONFIG_PROC_FS
957 static int pppoe_seq_show(struct seq_file
*seq
, void *v
)
959 struct pppox_sock
*po
;
962 if (v
== SEQ_START_TOKEN
) {
963 seq_puts(seq
, "Id Address Device\n");
968 dev_name
= po
->pppoe_pa
.dev
;
970 seq_printf(seq
, "%08X %02X:%02X:%02X:%02X:%02X:%02X %8s\n",
972 po
->pppoe_pa
.remote
[0], po
->pppoe_pa
.remote
[1],
973 po
->pppoe_pa
.remote
[2], po
->pppoe_pa
.remote
[3],
974 po
->pppoe_pa
.remote
[4], po
->pppoe_pa
.remote
[5], dev_name
);
979 static __inline__
struct pppox_sock
*pppoe_get_idx(loff_t pos
)
981 struct pppox_sock
*po
= NULL
;
984 for (; i
< PPPOE_HASH_SIZE
; i
++) {
985 po
= item_hash_table
[i
];
996 static void *pppoe_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1000 read_lock_bh(&pppoe_hash_lock
);
1001 return l
? pppoe_get_idx(--l
) : SEQ_START_TOKEN
;
1004 static void *pppoe_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1006 struct pppox_sock
*po
;
1009 if (v
== SEQ_START_TOKEN
) {
1010 po
= pppoe_get_idx(0);
1017 int hash
= hash_item(po
->pppoe_pa
.sid
, po
->pppoe_pa
.remote
);
1019 while (++hash
< PPPOE_HASH_SIZE
) {
1020 po
= item_hash_table
[hash
];
1029 static void pppoe_seq_stop(struct seq_file
*seq
, void *v
)
1031 read_unlock_bh(&pppoe_hash_lock
);
1034 static struct seq_operations pppoe_seq_ops
= {
1035 .start
= pppoe_seq_start
,
1036 .next
= pppoe_seq_next
,
1037 .stop
= pppoe_seq_stop
,
1038 .show
= pppoe_seq_show
,
1041 static int pppoe_seq_open(struct inode
*inode
, struct file
*file
)
1043 return seq_open(file
, &pppoe_seq_ops
);
1046 static struct file_operations pppoe_seq_fops
= {
1047 .owner
= THIS_MODULE
,
1048 .open
= pppoe_seq_open
,
1050 .llseek
= seq_lseek
,
1051 .release
= seq_release
,
1054 static int __init
pppoe_proc_init(void)
1056 struct proc_dir_entry
*p
;
1058 p
= create_proc_entry("net/pppoe", S_IRUGO
, NULL
);
1062 p
->proc_fops
= &pppoe_seq_fops
;
1065 #else /* CONFIG_PROC_FS */
1066 static inline int pppoe_proc_init(void) { return 0; }
1067 #endif /* CONFIG_PROC_FS */
1069 static const struct proto_ops pppoe_ops
= {
1071 .owner
= THIS_MODULE
,
1072 .release
= pppoe_release
,
1073 .bind
= sock_no_bind
,
1074 .connect
= pppoe_connect
,
1075 .socketpair
= sock_no_socketpair
,
1076 .accept
= sock_no_accept
,
1077 .getname
= pppoe_getname
,
1078 .poll
= datagram_poll
,
1079 .listen
= sock_no_listen
,
1080 .shutdown
= sock_no_shutdown
,
1081 .setsockopt
= sock_no_setsockopt
,
1082 .getsockopt
= sock_no_getsockopt
,
1083 .sendmsg
= pppoe_sendmsg
,
1084 .recvmsg
= pppoe_recvmsg
,
1085 .mmap
= sock_no_mmap
,
1086 .ioctl
= pppox_ioctl
,
1089 static struct pppox_proto pppoe_proto
= {
1090 .create
= pppoe_create
,
1091 .ioctl
= pppoe_ioctl
,
1092 .owner
= THIS_MODULE
,
1096 static int __init
pppoe_init(void)
1098 int err
= proto_register(&pppoe_sk_proto
, 0);
1103 err
= register_pppox_proto(PX_PROTO_OE
, &pppoe_proto
);
1105 goto out_unregister_pppoe_proto
;
1107 err
= pppoe_proc_init();
1109 goto out_unregister_pppox_proto
;
1111 dev_add_pack(&pppoes_ptype
);
1112 dev_add_pack(&pppoed_ptype
);
1113 register_netdevice_notifier(&pppoe_notifier
);
1116 out_unregister_pppox_proto
:
1117 unregister_pppox_proto(PX_PROTO_OE
);
1118 out_unregister_pppoe_proto
:
1119 proto_unregister(&pppoe_sk_proto
);
1123 static void __exit
pppoe_exit(void)
1125 unregister_pppox_proto(PX_PROTO_OE
);
1126 dev_remove_pack(&pppoes_ptype
);
1127 dev_remove_pack(&pppoed_ptype
);
1128 unregister_netdevice_notifier(&pppoe_notifier
);
1129 remove_proc_entry("net/pppoe", NULL
);
1130 proto_unregister(&pppoe_sk_proto
);
1133 module_init(pppoe_init
);
1134 module_exit(pppoe_exit
);
1136 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
1137 MODULE_DESCRIPTION("PPP over Ethernet driver");
1138 MODULE_LICENSE("GPL");
1139 MODULE_ALIAS_NETPROTO(PF_PPPOX
);