Skip to contentSkip to conversation

PPP-over-L2TP kernel support, patch for review

PATCH James Chapman 4 participants 8 messages Sep 6, 2004 – Sep 8, 2004

Subsystems (4)
lore
Share & tools
lore

James Chapman

author maintainer
#0 lore raw

Attached this time... sorry.

Attached is a PPP-over-L2TP driver for review. The patch is against vanilla 2.6.8.1. It was originally developed for 2.4 and forward- ported to 2.6 so please look for typical 2.4-to-2.6 porting bugs. The original version of this driver was written by Martijn van Oosterhout, distributed as kl2tp-0.2 last year.

Note that this code handles only the datapath of L2TP; a userland daemon runs the L2TP control protocol, setting up tunnels and sessions with its peers. OpenL2TP is a recently released L2TP client/server written specifically for Linux and includes this driver in its distribution, http://openl2tp.sourceforge.net.

I'm working towards having this driver integrated into the kernel tree. Comments?

/jc

drivers/net/Kconfig +13 -0
diff -Naur linux-2.6.8.1.orig/drivers/net/Kconfig linux-2.6.8.1/drivers/net/Kconfig
@@ -2481,6 +2481,19 @@
 	  which can lead to bad results if the ATM peer loses state and
 	  changes its encapsulation unilaterally.
 
+config PPPOL2TP
+	tristate "PPP over L2TP (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && PPPOE
+	help
+	  Support for PPP-over-L2TP socket family. L2TP is a protocol
+	  used by ISPs and enterprises to tunnel PPP traffic over UDP
+	  tunnels. L2TP is replacing PPTP for VPN uses.
+
+	  This kernel component handles only L2TP data packets: a
+	  userland daemon handles L2TP the control protocol (tunnel
+	  and session setup). One such daemon is OpenL2TP
+	  (http://openl2tp.sourceforge.net/).
+
 config SLIP
 	tristate "SLIP (serial line) support"
 	depends on NETDEVICES
drivers/net/Makefile +1 -0
diff -Naur linux-2.6.8.1.orig/drivers/net/Makefile linux-2.6.8.1/drivers/net/Makefile
@@ -101,6 +101,7 @@
 obj-$(CONFIG_PPP_DEFLATE) += ppp_deflate.o
 obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
 obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
+obj-$(CONFIG_PPPOL2TP) += pppox.o pppol2tp.o
 
 obj-$(CONFIG_SLIP) += slip.o
 ifeq ($(CONFIG_SLIP_COMPRESSED),y)
drivers/net/pppol2tp.c +2359 -0

2,359 lines not on this page · raw message

include/linux/if_pppol2tp.h +85 -0

85 lines not on this page · raw message

include/linux/if_pppox.h +4 -1
diff -Naur linux-2.6.8.1.orig/include/linux/if_pppox.h linux-2.6.8.1/include/linux/if_pppox.h
@@ -27,6 +27,7 @@
 #include <asm/semaphore.h>
 #include <linux/ppp_channel.h>
 #endif /* __KERNEL__ */
+#include <linux/if_pppol2tp.h>
 
 /* For user-space programs to pick up these definitions
  * which they wouldn't get otherwise without defining __KERNEL__
@@ -50,13 +51,15 @@
  * Protocols supported by AF_PPPOX 
  */ 
 #define PX_PROTO_OE    0 /* Currently just PPPoE */
-#define PX_MAX_PROTO   1	
+#define PX_PROTO_OL2TP 1 /* Now L2TP also */
+#define PX_MAX_PROTO   2	
  
 struct sockaddr_pppox { 
        sa_family_t     sa_family;            /* address family, AF_PPPOX */ 
        unsigned int    sa_protocol;          /* protocol identifier */ 
        union{ 
                struct pppoe_addr       pppoe; 
+               struct pppol2tp_addr    pppol2tp;
        }sa_addr; 
 }__attribute__ ((packed)); 
 
include/linux/socket.h +1 -0
diff -Naur linux-2.6.8.1.orig/include/linux/socket.h linux-2.6.8.1/include/linux/socket.h
@@ -268,6 +268,7 @@
 #define SOL_IRDA        266
 #define SOL_NETBEUI	267
 #define SOL_LLC		268
+#define SOL_PPPOL2TP	269
 
 /* IPX options */
 #define IPX_TYPE	1
maintainer
#1 lore raw
Quoted 2 lines · On Mon, 6 Sep 2004 12:59:16 +0100 James Chapman <[email protected]> wrote:

I'm working towards having this driver integrated into the kernel tree. Comments?

Only two major comments:

1) Uses own linked list implementations. Please use linux/list.h interfaces for this.

2) Does this:

struct sockaddr_pppox {

        sa_family_t     sa_family;            /* address family, AF_PPPOX */ 
        unsigned int    sa_protocol;          /* protocol identifier */ 
        union{ 
                struct pppoe_addr       pppoe; 
+               struct pppol2tp_addr    pppol2tp;
        }sa_addr; 

}__attribute__ ((packed));

Change the size of sockaddr_pppox on any platform? If so, you'll break pppox userspace with this change so we'd need find another way to do it.

Thanks.

#2 lore raw
Quoted 11 lines · David S. Miller

On Mon, 6 Sep 2004 12:59:16 +0100
James Chapman <[email protected]> wrote:
2) Does this:

struct sockaddr_pppox {

        sa_family_t     sa_family;            /* address family, AF_PPPOX */ 
        unsigned int    sa_protocol;          /* protocol identifier */ 
        union{ 
                struct pppoe_addr       pppoe; 
+               struct pppol2tp_addr    pppol2tp;
        }sa_addr; 
Quoted 5 lines

}__attribute__ ((packed));

Change the size of sockaddr_pppox on any platform? If so, you'll break pppox userspace with this change so we'd need find another way to do it.

By my calculations,

sizeof(struct pppoe_addr) = 2 + ETH_ALEN + IFNAMSIZ = 2 + 6 + 16 = 24 bytes sizeof(struct pppol2tp_addr) = sizeof(int) + sizeof(sockaddr_in) + 4 * 2

                             = 4 + 16 + 8 = 28 + possibly padding

So the answer is: I think so. However, I'm not sure why this is an issue. struct sockaddr is passed back and forth between userspace and kernelspace has many varying sizes (sockaddr_un is quite large). What could be affected? getsockname, connect and bind all take a length argument. Or are you referring to the possibility of it affecting other structures it's embedded in?

TIA,

Signature · 1 line
Martijn van Oosterhout   <[email protected]>   http://svana.org/kleptog/
Quoted 3 lines

Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a tool for doing 5% of the work and then sitting around waiting for someone else to do the other 95% so you can sue them.

#3 lore raw
Quoted 5 lines · Martijn van Oosterhout

By my calculations,

sizeof(struct pppoe_addr) = 2 + ETH_ALEN + IFNAMSIZ = 2 + 6 + 16 = 24 bytes sizeof(struct pppol2tp_addr) = sizeof(int) + sizeof(sockaddr_in) + 4 * 2

Quoted 8 lines
                            = 4 + 16 + 8 = 28 + possibly padding

So the answer is: I think so. However, I'm not sure why this is an issue. struct sockaddr is passed back and forth between userspace and kernelspace has many varying sizes (sockaddr_un is quite large). What could be affected? getsockname, connect and bind all take a length argument. Or are you referring to the possibility of it affecting other structures it's embedded in?

Any existing user-space binary that has struct sockaddr_pppox in it will be broken by your change.

Perhaps you can create a new sockaddr type?

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Martijn van Oosterhout

So the answer is: I think so. However, I'm not sure why this is an issue. struct sockaddr is passed back and forth between userspace and kernelspace has many varying sizes (sockaddr_un is quite large). What could be affected? getsockname, connect and bind all take a length argument. Or are you referring to the possibility of it affecting other structures it's embedded in?

Quoted 4 lines

Any existing user-space binary that has struct sockaddr_pppox in it will be broken by your change.

Perhaps you can create a new sockaddr type?

But within a single binary, it knows how big the structure was at the time it was compiled and has allocated the appropriate space. It also was compiled with a particular version of PX_MAX_PROTO so it should know if it's an unknown type. Any communication with the kernel includes the size so there is no possibility of buffer overruns AFAICS. The change is backward compatable in the sense that the sa_protocol field determines which union member is appropriate and hence the expected size of the structure.

However, it's possible I've not thought of a failure case. Maybe some parts of kernel or userspace ignore the length or sa_protocol argument.

It's possible to create a new sockaddr type. I didn't do that as I thought the point was to have all PPPoX sockets to use the same type. You could create a socket type sockaddr_pppox2 which is bigger than the current sockaddr_pppox but otherwise identical. Change the kernel to use this new structure (no actual code changes needed, just argument types). Worst case we get a new structure for each new type of PPPoX socket. The AF_PPPOX will be the same for all of them.

Transistion userspace to use the new pppox2 structure for everything and you're done. Again, no code changes required, only the type is changed.

I can create a patch if you want...

Signature · 1 line
Martijn van Oosterhout   <[email protected]>   http://svana.org/kleptog/
Quoted 3 lines

Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a tool for doing 5% of the work and then sitting around waiting for someone else to do the other 95% so you can sue them.

#5 lore raw
Quoted 9 lines · Martijn van Oosterhout

But within a single binary, it knows how big the structure was at the time it was compiled and has allocated the appropriate space. It also was compiled with a particular version of PX_MAX_PROTO so it should know if it's an unknown type. Any communication with the kernel includes the size so there is no possibility of buffer overruns AFAICS. The change is backward compatable in the sense that the sa_protocol field determines which union member is appropriate and hence the expected size of the structure.

It can break because people often initialise the size of the address by doing sizeof(struct sockaddr_pppox). For example, you'll see exactly this breakage in pppoe_getname in drivers/net/pppoe.c.

Now granted you can work around this in pppoe.c and repair the kernel ABI. But user space has ABIs too. Think of a library that exports this stuff to other user space applications. If it does sizeof(struct sockaddr_pppox) then you're toast.

IMHO this union was a silly idea to begin with. Let's not prolong its life any further.

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#6 lore raw
Quoted 4 lines · Herbert Xu

It can break because people often initialise the size of the address by doing sizeof(struct sockaddr_pppox). For example, you'll see exactly this breakage in pppoe_getname in drivers/net/pppoe.c.

/me looks... *BLINK* Ugh, getname takes a length argument but it's write only.

So, hypothetically, if I get passed a file descriptor through a UNIX domain socket and do a getname on it, there is no way to guarentee that it won't go past the buffer I've allocated. Who came up with this lame API?

Quoted 2 lines

IMHO this union was a silly idea to begin with. Let's not prolong its life any further.

Well, I guess I'll have to agree to that. So, lets say we create two new types, one for each version of the union, sockaddr_pppox_pppoe and sockaddr_pppox_pppol2tp. Deprecate the current sockaddr_pppox altogether (can't get rid of it now). Possibly create a new sockaddr_pppox_generic for use in the actual pppox.c file. Sprinkle some typecasts around to make the compiler happy and voila!

Then future userspace programs can use the structure appropriate for them. Does removing the union change the alignment on any architechture? Or will the dummy union have to stay in perpituity?

Seems fairly straight forward... I'll see if I have time to whip something up...

Signature · 1 line
Martijn van Oosterhout   <[email protected]>   http://svana.org/kleptog/
Quoted 3 lines

Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a tool for doing 5% of the work and then sitting around waiting for someone else to do the other 95% so you can sue them.

#7 lore raw
Quoted 5 lines · Martijn van Oosterhout

So, hypothetically, if I get passed a file descriptor through a UNIX domain socket and do a getname on it, there is no way to guarentee that it won't go past the buffer I've allocated. Who came up with this lame API?

Nope. The code in net/socket.c ensures that the buffer does not overflow.

Quoted 6 lines

Well, I guess I'll have to agree to that. So, lets say we create two new types, one for each version of the union, sockaddr_pppox_pppoe and sockaddr_pppox_pppol2tp. Deprecate the current sockaddr_pppox altogether (can't get rid of it now). Possibly create a new sockaddr_pppox_generic for use in the actual pppox.c file. Sprinkle some typecasts around to make the compiler happy and voila!

Please call them sockaddr_pppoe and sockaddr_pppol2tp.

Quoted 3 lines

Then future userspace programs can use the structure appropriate for them. Does removing the union change the alignment on any architechture? Or will the dummy union have to stay in perpituity?

The union doesn't change the size or alignemnt.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt