Import 2.4.0-test6pre4
[davej-history.git] / drivers / net / pppoe.c
blob84dc28025bfd5660bad7b8a46ace07600da69bb9
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)
8 * Version: 0.6.0
10 * 030700 : Fixed connect logic to allow for disconnect.
11 * 270700 : Fixed potential SMP problems; we must protect against
12 * simultaneous invocation of ppp_input
13 * and ppp_unregister_channel.
15 * Module reference count is decremented in the right spot now,
16 * guards against sock_put not actually freeing the sk
17 * in pppoe_release.
19 * Author: Michal Ostrowski <mostrows@styx.uwaterloo.ca>
21 * License:
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version
25 * 2 of the License, or (at your option) any later version.
29 #include <linux/string.h>
30 #include <linux/module.h>
32 #include <asm/uaccess.h>
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/malloc.h>
37 #include <linux/errno.h>
39 #include <linux/netdevice.h>
40 #include <linux/net.h>
41 #include <linux/inetdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/init.h>
45 #include <linux/if_ether.h>
46 #include <linux/if_pppox.h>
47 #include <net/sock.h>
48 #include <linux/ppp_channel.h>
49 #include <linux/ppp_defs.h>
50 #include <linux/if_ppp.h>
51 #include <linux/if_pppvar.h>
52 #include <linux/notifier.h>
53 #include <linux/file.h>
54 #include <linux/proc_fs.h>
58 static int __attribute__((unused)) pppoe_debug = 7;
59 #define PPPOE_HASH_BITS 4
60 #define PPPOE_HASH_SIZE (1<<PPPOE_HASH_BITS)
62 int pppoe_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
63 int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb);
64 int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
66 struct proto_ops pppoe_ops;
69 #if 0
70 #define CHECKPTR(x,y) { if (!(x) && pppoe_debug &7 ){ printk(KERN_CRIT "PPPoE Invalid pointer : %s , %p\n",#x,(x)); error=-EINVAL; goto y; }}
71 #define DEBUG(s,args...) if( pppoe_debug & (s) ) printk(KERN_CRIT args );
72 #else
73 #define CHECKPTR(x,y) do {} while (0);
74 #define DEBUG(s,args...) do { } while (0);
75 #endif
79 static rwlock_t pppoe_hash_lock = RW_LOCK_UNLOCKED;
82 static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
84 return (a->sid == b->sid &&
85 (memcmp(a->remote, b->remote, ETH_ALEN) == 0));
88 static inline int cmp_addr(struct pppoe_addr *a, unsigned long sid, char *addr)
90 return (a->sid == sid &&
91 (memcmp(a->remote,addr,ETH_ALEN) == 0));
94 static int hash_item(unsigned long sid, unsigned char *addr)
96 char hash=0;
97 int i,j;
98 for (i = 0; i < ETH_ALEN ; ++i){
99 for (j = 0; j < 8/PPPOE_HASH_BITS ; ++j){
100 hash ^= addr[i] >> ( j * PPPOE_HASH_BITS );
104 for (i = 0; i < (sizeof(unsigned long)*8) / PPPOE_HASH_BITS ; ++i)
105 hash ^= sid >> (i*PPPOE_HASH_BITS);
107 return hash & ( PPPOE_HASH_SIZE - 1 );
110 static struct pppox_opt *item_hash_table[PPPOE_HASH_SIZE] = { 0, };
112 /**********************************************************************
114 * Set/get/delete/rehash items (internal versions)
116 **********************************************************************/
117 static struct pppox_opt *__get_item(unsigned long sid, unsigned char *addr)
119 int hash = hash_item(sid, addr);
120 struct pppox_opt *ret;
122 ret = item_hash_table[hash];
124 while (ret && !cmp_addr(&ret->pppoe_pa, sid, addr))
125 ret = ret->next;
127 return ret;
130 static int __set_item(struct pppox_opt *po)
132 int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
133 struct pppox_opt *ret;
135 ret = item_hash_table[hash];
136 while (ret) {
137 if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa))
138 return -EALREADY;
140 ret = ret->next;
143 if (!ret) {
144 po->next = item_hash_table[hash];
145 item_hash_table[hash] = po;
148 return 0;
151 static struct pppox_opt *__delete_item(unsigned long sid, char *addr)
153 int hash = hash_item(sid, addr);
154 struct pppox_opt *ret, **src;
156 ret = item_hash_table[hash];
157 src = &item_hash_table[hash];
159 while (ret) {
160 if (cmp_addr(&ret->pppoe_pa, sid, addr)) {
161 *src = ret->next;
162 break;
165 src = &ret->next;
166 ret = ret->next;
169 return ret;
172 static struct pppox_opt *__find_on_dev(struct net_device *dev,
173 struct pppox_opt *start)
175 struct pppox_opt *po;
176 int hash;
178 if (start != NULL) {
179 hash = hash_item(start->pppoe_pa.sid, start->pppoe_pa.remote);
180 po = start;
181 } else {
182 hash = 0;
183 po = NULL;
185 while (!po && ++hash < PPPOE_HASH_SIZE)
186 po = item_hash_table[hash];
189 while (po && (po->pppoe_dev != dev)){
190 if (po->next) {
191 po = po->next;
192 } else {
193 po = NULL;
194 while (!po && ++hash < PPPOE_HASH_SIZE)
195 po = item_hash_table[hash];
199 return po;
202 /**********************************************************************
204 * Set/get/delete/rehash items
206 **********************************************************************/
207 static inline struct pppox_opt *get_item(unsigned long sid,
208 unsigned char *addr)
210 struct pppox_opt *po;
212 read_lock_bh(&pppoe_hash_lock);
213 po = __get_item(sid, addr);
214 if(po)
215 sock_hold(po->sk);
216 read_unlock_bh(&pppoe_hash_lock);
218 return po;
221 static inline struct pppox_opt *get_item_by_addr(struct sockaddr_pppox *sp)
223 return get_item(sp->sa_addr.pppoe.sid, sp->sa_addr.pppoe.remote);
226 static inline int set_item(struct pppox_opt *po)
228 int i;
230 if (!po)
231 return -EINVAL;
233 write_lock_bh(&pppoe_hash_lock);
234 i = __set_item(po);
235 write_unlock_bh(&pppoe_hash_lock);
237 return i;
240 static inline struct pppox_opt *delete_item(unsigned long sid, char *addr)
242 struct pppox_opt *ret;
244 write_lock_bh(&pppoe_hash_lock);
245 ret = __delete_item(sid, addr);
246 write_unlock_bh(&pppoe_hash_lock);
248 return ret;
251 static struct pppox_opt *find_on_dev(struct net_device *dev,
252 struct pppox_opt *start)
254 struct pppox_opt *po;
255 read_lock_bh(&pppoe_hash_lock);
256 po = __find_on_dev(dev,start);
257 if(po)
258 sock_hold(po->sk);
259 read_unlock_bh(&pppoe_hash_lock);
260 return po;
263 /***************************************************************************
265 * Handler for device events.
266 * Certain device events require that sockets be unconnected.
268 **************************************************************************/
269 static int pppoe_device_event(struct notifier_block *this,
270 unsigned long event, void *ptr)
272 int error = NOTIFY_DONE;
273 struct net_device *dev = (struct net_device *) ptr;
274 struct pppox_opt *po = NULL;
276 /* Only look at sockets that are using this specific device. */
277 switch (event) {
278 case NETDEV_CHANGEMTU:
279 /* A change in mtu is a bad thing, requiring
280 * LCP re-negotiation.
282 case NETDEV_GOING_DOWN:
283 case NETDEV_DOWN:
284 do {
285 po = find_on_dev(dev, po);
286 if(!po)
287 break;
289 lock_sock(po->sk);
290 if (po->sk->state & PPPOX_CONNECTED)
291 pppox_unbind_sock(po->sk);
293 release_sock(po->sk);
294 sock_put(po->sk);
296 } while (1);
298 break;
299 default:
300 break;
303 return error;
307 static struct notifier_block pppoe_notifier = {
308 pppoe_device_event,
309 NULL,
316 /************************************************************************
318 * Do the real work of receiving a PPPoE Session frame.
320 ***********************************************************************/
321 int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb){
322 struct pppox_opt *po=sk->protinfo.pppox;
324 if (sk->state & PPPOX_BOUND) {
325 skb_pull(skb, sizeof(struct pppoe_hdr));
327 ppp_input(&po->chan, skb);
328 } else if( sk->state & PPPOX_RELAY ){
329 struct pppox_opt *relay_po;
331 relay_po = get_item_by_addr( &po->pppoe_relay );
333 if( relay_po == NULL ||
334 !( relay_po->sk->state & PPPOX_CONNECTED ) ){
335 sock_put(relay_po->sk);
336 goto abort;
339 skb_pull(skb, sizeof(struct pppoe_hdr));
340 if( !__pppoe_xmit( relay_po->sk , skb) ){
341 sock_put(relay_po->sk);
342 goto abort;
345 } else {
346 sock_queue_rcv_skb(sk, skb);
348 return 1;
349 abort:
350 sock_put(sk);
351 return 0;
358 /************************************************************************
360 * Receive wrapper called in BH context.
362 ***********************************************************************/
363 static int pppoe_rcv(struct sk_buff *skb,
364 struct net_device *dev,
365 struct packet_type *pt)
368 struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw;
369 struct pppox_opt *po;
370 struct sock *sk ;
371 int ret;
373 po = get_item((unsigned long) ph->sid, skb->mac.ethernet->h_source);
375 if(!po){
376 kfree(skb);
377 return 0;
380 sk = po->sk;
381 bh_lock_sock(sk);
383 /* Socket state is unknown, must put skb into backlog. */
384 if( sk->lock.users != 0 ){
385 sk_add_backlog( sk, skb);
386 ret = 1;
387 }else{
388 ret = pppoe_rcv_core(sk, skb);
391 bh_unlock_sock(sk);
392 sock_put(sk);
393 return ret;
397 /************************************************************************
399 * Receive wrapper called in process context.
401 ***********************************************************************/
402 int pppoe_backlog_rcv(struct sock *sk, struct sk_buff *skb)
404 lock_sock(sk);
405 pppoe_rcv_core(sk, skb);
406 release_sock(sk);
407 return 0;
412 /************************************************************************
414 * Receive a PPPoE Discovery frame.
415 * This is solely for detection of PADT frames
417 ***********************************************************************/
418 static int pppoe_disc_rcv(struct sk_buff *skb,
419 struct net_device *dev,
420 struct packet_type *pt)
423 struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw;
424 struct pppox_opt *po;
425 struct sock *sk = NULL;
427 if (ph->code != PADT_CODE)
428 goto abort;
430 po = get_item((unsigned long) ph->sid, skb->mac.ethernet->h_source);
432 if (!po)
433 goto abort_put;
435 sk = po->sk;
437 pppox_unbind_sock(sk);
439 abort_put:
440 sock_put(sk);
441 abort:
442 kfree_skb(skb);
443 return 0;
449 struct packet_type pppoes_ptype = {
450 __constant_htons(ETH_P_PPP_SES),
451 NULL,
452 pppoe_rcv,
453 NULL,
454 NULL
457 struct packet_type pppoed_ptype = {
458 __constant_htons(ETH_P_PPP_DISC),
459 NULL,
460 pppoe_disc_rcv,
461 NULL,
462 NULL
465 /**********************************************************************
467 * The destruct hook --- this can be trashed if there is no need for
468 * the sock to clear its receive queue?
470 *********************************************************************/
471 void sock_pppoe_destruct(struct sock *sk)
473 if (sk->protinfo.destruct_hook)
474 kfree(sk->protinfo.destruct_hook);
476 MOD_DEC_USE_COUNT;
479 /***********************************************************************
481 * Initialize a new struct sock.
483 **********************************************************************/
484 static int pppoe_create(struct socket *sock)
486 int error = 0;
487 struct sock *sk;
489 MOD_INC_USE_COUNT;
491 sk = sk_alloc(PF_PPPOX, GFP_KERNEL, 1);
492 if (!sk)
493 return -ENOMEM;
495 sock_init_data(sock, sk);
497 sock->state = SS_UNCONNECTED;
498 sock->ops = &pppoe_ops;
500 sk->protocol = PX_PROTO_OE;
501 sk->family = PF_PPPOX;
503 sk->backlog_rcv = pppoe_backlog_rcv;
504 sk->next = NULL;
505 sk->pprev = NULL;
506 sk->state = PPPOX_NONE;
507 sk->type = SOCK_STREAM;
509 sk->protinfo.pppox = kmalloc(sizeof(struct pppox_opt), GFP_KERNEL);
510 if (!sk->protinfo.pppox) {
511 error = -ENOMEM;
512 goto free_sk;
515 memset((void *) sk->protinfo.pppox, 0, sizeof(struct pppox_opt));
516 sk->protinfo.pppox->sk = sk;
518 /* Delete the protinfo when it is time to do so. */
519 sk->protinfo.destruct_hook = sk->protinfo.pppox;
520 sock->sk = sk;
522 return 0;
524 free_sk:
525 sk_free(sk);
526 return error;
529 int pppoe_release(struct socket *sock)
531 struct sock *sk = sock->sk;
532 struct pppox_opt *po;
533 int error = 0;
535 if (!sk)
536 return 0;
538 if (sk->dead != 0)
539 return -EBADF;
541 pppox_unbind_sock(sk);
543 /* Signal the death of the socket. */
544 sk->state = PPPOX_DEAD;
546 po = sk->protinfo.pppox;
547 if (po->pppoe_pa.sid)
548 delete_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
550 /* Should also do a queue purge here */
552 sock_orphan(sk);
553 sock->sk = NULL;
555 skb_queue_purge(&sk->receive_queue);
557 sock_put(sk);
558 MOD_DEC_USE_COUNT;
560 return error;
564 int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
565 int sockaddr_len, int flags)
567 struct sock *sk = sock->sk;
568 struct net_device *dev = NULL;
569 struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
570 struct pppox_opt *po=sk->protinfo.pppox;
571 int error;
573 lock_sock(sk);
575 error = -EINVAL;
576 if (sp->sa_protocol != PX_PROTO_OE)
577 goto end;
579 error = -EBUSY;
580 if ((sk->state & PPPOX_CONNECTED) && sp->sa_addr.pppoe.sid)
581 goto end;
583 dev = dev_get_by_name(sp->sa_addr.pppoe.dev);
585 error = -ENODEV;
586 if (!dev)
587 goto end;
589 error = 0;
590 if (po->pppoe_pa.sid) {
591 pppox_unbind_sock(sk);
593 /* Delete the old binding */
594 delete_item(po->pppoe_pa.sid,po->pppoe_pa.remote);
596 memset(po, 0, sizeof(struct pppox_opt));
597 po->sk = sk;
599 sk->state = PPPOX_NONE;
602 /* Don't re-bind if sid==0 */
603 if (sp->sa_addr.pppoe.sid != 0) {
604 memcpy(&po->pppoe_pa,
605 &sp->sa_addr.pppoe,
606 sizeof(struct pppoe_addr));
608 error = set_item(po);
609 if (error < 0)
610 goto end;
612 po->pppoe_dev = dev;
614 po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
615 dev->hard_header_len);
617 po->chan.private = sk;
618 po->chan.ops = &pppoe_chan_ops;
620 error = ppp_register_channel(&po->chan);
622 sk->state = PPPOX_CONNECTED;
625 sk->num = sp->sa_addr.pppoe.sid;
627 end:
628 release_sock(sk);
629 return error;
633 int pppoe_getname(struct socket *sock, struct sockaddr *uaddr,
634 int *usockaddr_len, int peer)
636 int len = sizeof(struct sockaddr_pppox);
637 struct sockaddr_pppox sp;
639 sp.sa_family = AF_PPPOX;
640 sp.sa_protocol = PX_PROTO_OE;
641 memcpy(&sp.sa_addr.pppoe, &sock->sk->protinfo.pppox->pppoe_pa,
642 sizeof(struct pppoe_addr));
644 memcpy(uaddr, &sp, len);
646 *usockaddr_len = len;
648 return 0;
652 int pppoe_ioctl(struct socket *sock, unsigned int cmd,
653 unsigned long arg)
655 struct sock *sk = sock->sk;
656 struct pppox_opt *po;
657 int val = 0;
658 int err = 0;
660 po = sk->protinfo.pppox;
661 switch (cmd) {
662 case PPPIOCGMRU:
663 err = -ENXIO;
665 if (!(sk->state & PPPOX_CONNECTED))
666 break;
668 err = -EFAULT;
669 if (put_user(po->pppoe_dev->mtu -
670 sizeof(struct pppoe_hdr) -
671 PPP_HDRLEN,
672 (int *) arg))
673 break;
674 err = 0;
675 break;
677 case PPPIOCSMRU:
678 err = -ENXIO;
679 if (!(sk->state & PPPOX_CONNECTED))
680 break;
682 err = -EFAULT;
683 if (get_user(val,(int *) arg))
684 break;
686 if (val < (po->pppoe_dev->mtu
687 - sizeof(struct pppoe_hdr)
688 - PPP_HDRLEN))
689 err = 0;
690 else
691 err = -EINVAL;
692 break;
694 case PPPIOCSFLAGS:
695 err = -EFAULT;
696 if (get_user(val, (int *) arg))
697 break;
698 err = 0;
699 break;
701 case PPPOEIOCSFWD:
703 struct pppox_opt *relay_po;
705 err = -EBUSY;
706 if (sk->state & PPPOX_BOUND)
707 break;
709 err = -ENOTCONN;
710 if (!(sk->state & PPPOX_CONNECTED))
711 break;
713 /* PPPoE address from the user specifies an outbound
714 PPPoE address to which frames are forwarded to */
715 err = -EFAULT;
716 if( copy_from_user(&po->pppoe_relay,
717 (void*)arg,
718 sizeof(struct sockaddr_pppox)))
719 break;
721 err = -EINVAL;
722 if (po->pppoe_relay.sa_family != AF_PPPOX ||
723 po->pppoe_relay.sa_protocol!= PX_PROTO_OE)
724 break;
726 /* Check that the socket referenced by the address
727 actually exists. */
728 relay_po = get_item_by_addr(&po->pppoe_relay);
730 if (!relay_po)
731 break;
733 sk->state |= PPPOX_RELAY;
734 err = 0;
735 break;
738 case PPPOEIOCDFWD:
739 err = -EALREADY;
740 if (!(sk->state & PPPOX_RELAY))
741 break;
743 sk->state &= ~PPPOX_RELAY;
744 err = 0;
745 break;
747 default:
750 return err;
754 int pppoe_sendmsg(struct socket *sock, struct msghdr *m,
755 int total_len, struct scm_cookie *scm)
757 struct sk_buff *skb = NULL;
758 struct sock *sk = sock->sk;
759 int error = 0;
760 struct pppoe_hdr hdr;
761 struct pppoe_hdr *ph;
762 struct net_device *dev;
763 char *start;
764 int copied = 0;
766 if (sk->dead || !(sk->state & PPPOX_CONNECTED)) {
767 error = -ENOTCONN;
768 goto end;
771 hdr.ver = 1;
772 hdr.type = 1;
773 hdr.code = 0;
774 hdr.sid = sk->num;
776 dev = sk->protinfo.pppox->pppoe_dev;
778 skb = sock_wmalloc(sk, total_len + dev->hard_header_len + 32,
779 0, GFP_KERNEL);
780 if (!skb) {
781 error = -ENOMEM;
782 goto end;
785 /* Reserve space for headers. */
786 skb_reserve(skb, dev->hard_header_len);
787 skb->nh.raw = skb->data;
788 skb->dev = dev;
789 skb->priority = sk->priority;
790 skb->protocol = __constant_htons(ETH_P_PPP_SES);
792 ph = (struct pppoe_hdr *) skb_put(skb, total_len + sizeof(struct pppoe_hdr));
793 start = (char *) &ph->tag[0];
795 copied = memcpy_fromiovec( start, m->msg_iov, m->msg_iovlen);
797 dev->hard_header(skb, dev, ETH_P_PPP_SES,
798 sk->protinfo.pppox->pppoe_pa.remote,
799 NULL, copied);
801 memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
803 ph->length = htons(copied);
805 dev_queue_xmit(skb);
806 return copied;
808 end:
809 return error;
812 /************************************************************************
814 * xmit function for internal use.
816 ***********************************************************************/
817 int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
819 struct net_device *dev = sk->protinfo.pppox->pppoe_dev;
820 struct pppoe_hdr hdr;
821 struct pppoe_hdr *ph;
822 int headroom = skb_headroom(skb);
823 int data_len = skb->len;
825 if (sk->dead || !(sk->state & PPPOX_CONNECTED)) {
826 goto abort;
829 hdr.ver = 1;
830 hdr.type = 1;
831 hdr.code = 0;
832 hdr.sid = sk->num;
833 hdr.length = htons(skb->len);
835 if (!dev) {
836 goto abort;
839 /* Copy the skb if there is no space for the header. */
840 if (headroom < (sizeof(struct pppoe_hdr) + dev->hard_header_len)) {
841 struct sk_buff *skb2;
843 skb2 = dev_alloc_skb(32+skb->len +
844 sizeof(struct pppoe_hdr) +
845 dev->hard_header_len);
847 if (skb2 == NULL)
848 goto abort;
850 skb_reserve(skb2, dev->hard_header_len + sizeof(struct pppoe_hdr));
851 memcpy(skb_put(skb2, skb->len), skb->data, skb->len);
853 skb_unlink(skb);
854 kfree_skb(skb);
855 skb = skb2;
858 ph = (struct pppoe_hdr *) skb_push(skb, sizeof(struct pppoe_hdr));
859 memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
860 skb->protocol = __constant_htons(ETH_P_PPP_SES);
862 skb->nh.raw = skb->data;
863 skb->dev = dev;
865 dev->hard_header(skb, dev, ETH_P_PPP_SES,
866 sk->protinfo.pppox->pppoe_pa.remote,
867 NULL, data_len);
869 if (dev_queue_xmit(skb) < 0)
870 goto abort;
872 return 1;
873 abort:
874 return 0;
878 /************************************************************************
880 * xmit function called by generic PPP driver
881 * sends PPP frame over PPPoE socket
883 ***********************************************************************/
884 int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
886 struct sock *sk = (struct sock *) chan->private;
887 return __pppoe_xmit(sk, skb);
891 struct ppp_channel_ops pppoe_chan_ops = { pppoe_xmit , NULL };
893 int pppoe_rcvmsg(struct socket *sock, struct msghdr *m, int total_len, int flags, struct scm_cookie *scm)
895 struct sock *sk = sock->sk;
896 struct sk_buff *skb = NULL;
897 int error = 0;
898 int len;
899 struct pppoe_hdr *ph = NULL;
901 if (sk->state & PPPOX_BOUND) {
902 error = -EIO;
903 goto end;
906 skb = skb_recv_datagram(sk, flags, 0, &error);
908 if (error < 0) {
909 goto end;
912 m->msg_namelen = 0;
914 if (skb) {
915 error = 0;
916 ph = (struct pppoe_hdr *) skb->nh.raw;
917 len = ntohs(ph->length);
919 error = memcpy_toiovec(m->msg_iov, (unsigned char *) &ph->tag[0], len);
920 if (error < 0)
921 goto do_skb_free;
922 error = len;
925 do_skb_free:
926 if (skb)
927 kfree_skb(skb);
928 end:
929 return error;
932 int pppoe_proc_info(char *buffer, char **start, off_t offset, int length)
934 struct pppox_opt *po;
935 int len = 0;
936 off_t pos = 0;
937 off_t begin = 0;
938 int size;
939 int i;
941 len += sprintf(buffer,
942 "Id Address Device\n");
943 pos = len;
945 write_lock_bh(&pppoe_hash_lock);
947 for (i = 0; i < PPPOE_HASH_SIZE; i++) {
948 po = item_hash_table[i];
949 while (po) {
950 char *dev = po->pppoe_pa.dev;
952 size = sprintf(buffer + len,
953 "%08X %02X:%02X:%02X:%02X:%02X:%02X %8s\n",
954 po->pppoe_pa.sid,
955 po->pppoe_pa.remote[0],
956 po->pppoe_pa.remote[1],
957 po->pppoe_pa.remote[2],
958 po->pppoe_pa.remote[3],
959 po->pppoe_pa.remote[4],
960 po->pppoe_pa.remote[5],
961 dev);
962 len += size;
963 pos += size;
964 if (pos < offset) {
965 len = 0;
966 begin = pos;
969 if (pos > offset + length)
970 break;
972 po = po->next;
975 if (po)
976 break;
978 write_unlock_bh(&pppoe_hash_lock);
980 *start = buffer + (offset - begin);
981 len -= (offset - begin);
982 if (len > length)
983 len = length;
984 if (len < 0)
985 len = 0;
986 return len;
990 struct proto_ops pppoe_ops = {
991 family: AF_PPPOX,
992 release: pppoe_release,
993 bind: sock_no_bind,
994 connect: pppoe_connect,
995 socketpair: sock_no_socketpair,
996 accept: sock_no_accept,
997 getname: pppoe_getname,
998 poll: datagram_poll,
999 ioctl: pppoe_ioctl,
1000 listen: sock_no_listen,
1001 shutdown: sock_no_shutdown,
1002 setsockopt: sock_no_setsockopt,
1003 getsockopt: sock_no_getsockopt,
1004 sendmsg: pppoe_sendmsg,
1005 recvmsg: pppoe_rcvmsg,
1006 mmap: sock_no_mmap
1009 struct pppox_proto pppoe_proto = {
1010 create: pppoe_create,
1011 ioctl: pppoe_ioctl
1015 int __init pppoe_init(void)
1017 int err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);
1019 if (err == 0) {
1020 printk(KERN_INFO "Registered PPPoE v0.5\n");
1022 dev_add_pack(&pppoes_ptype);
1023 register_netdevice_notifier(&pppoe_notifier);
1024 proc_net_create("pppoe", 0, pppoe_proc_info);
1026 return err;
1030 #ifdef MODULE
1031 MODULE_PARM(debug, "i");
1032 int init_module(void)
1034 return pppoe_init();
1037 void cleanup_module(void)
1039 unregister_pppox_proto(PX_PROTO_OE);
1040 dev_remove_pack(&pppoes_ptype);
1041 unregister_netdevice_notifier(&pppoe_notifier);
1042 proc_net_remove("pppoe");
1045 #else
1047 int pppoe_proto_init(struct net_proto *np)
1049 return pppoe_init();
1052 #endif