OpenWrt Forum Archive

Topic: [patch] Making l2tpd work with CONFIG_UNIX98_PTYS

The content of this topic has been archived on 1 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

l2tpd doesn't work because the kernel is compiled with CONFIG_UNIX98_PTYS enabled. The following patch (needs to go in openwrt/package/l2tpd/patches) makes it work without having to compile a custom kernel, I adapted it from  http://www.jacco2.dds.nl/networking/fre … onfigLinux.

--- l2tpd-0.70-pre20031121.orig/l2tpd.c    2005-09-25 14:54:09.000000000 +0200
+++ l2tpd-0.70-pre20031121/l2tpd.c    2005-09-25 15:02:31.000000000 +0200
@@ -14,6 +14,7 @@
  */
 
 #include <stdlib.h>
+#include <sys/types.h>
 #include <sys/utsname.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
@@ -259,8 +260,8 @@ void death_handler (int signal)
 
 int start_pppd (struct call *c, struct ppp_opts *opts)
 {
-    char a, b;
-    char tty[80];
+    /* char a, b; */
+    char *tty;
     char *stropt[80];
     struct ppp_opts *p;
 #ifdef USE_KERNEL
@@ -309,12 +310,45 @@ int start_pppd (struct call *c, struct p
     else
     {
 #endif
-        if ((c->fd = getPtyMaster (&a, &b)) < 0)
+    c->fd = open("/dev/ptmx", O_RDWR | O_NONBLOCK);
+    if (c->fd == -1)
+    {
+        log (LOG_WARN, "%s: unable to open /dev/ptmx to allocate pty\n",
+                __FUNCTION__);
+        return -EINVAL;
+    } else
+    {
+        if (grantpt(c->fd))
+        {
+        log (LOG_WARN, "%s: unable to grantpt() on pty\n",
+                __FUNCTION__);
+        close(c->fd);
+        return -EINVAL;
+        }
+        if (unlockpt(c->fd))
+        {
+        log (LOG_WARN, "%s: unable to unlockpt() on pty\n",
+            __FUNCTION__);
+        close(c->fd);
+        return -EINVAL;
+        }
+        tty = ptsname(c->fd);
+        if (tty == NULL)
+        {
+        log (LOG_WARN, "%s: unable to obtain name of slave tty\n",
+            __FUNCTION__);
+        close(c->fd);
+        return -EINVAL;
+        }
+    }
+    
+    
+ /*    if ((c->fd = getPtyMaster (&a, &b)) < 0)
         {
             log (LOG_WARN, "%s: unable to allocate pty, abandoning!\n",
                  __FUNCTION__);
             return -EINVAL;
-        }
+        } */
 
         /* set fd opened above to not echo so we don't see read our own packets
            back of the file descriptor that we just wrote them to */
@@ -323,8 +357,8 @@ int start_pppd (struct call *c, struct p
         ptyconf.c_cflag &= ~(ICANON | ECHO);
         tcsetattr (c->fd, TCSANOW, &ptyconf);
 
-        snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b);
+/*        snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b); */
         fd2 = open (tty, O_RDWR);
         if(!fd2)
             log(LOG_WARN, "unable to open tty %s", tty);

I don't get a clean patch into the original file:

$ patch -p0 < l2tpd.patch
patching file l2tpd-0.70-pre20031121.orig/l2tpd.c
Hunk #1 succeeded at 16 (offset 2 lines).
Hunk #2 succeeded at 272 (offset 12 lines).
Hunk #3 succeeded at 322 (offset 12 lines).
Hunk #4 FAILED at 369.
1 out of 4 hunks FAILED -- saving rejects to file l2tpd-0.70-pre20031121.orig/l2tpd.c.rej

Here's the .rej file:

***************
*** 335,342 ****
          ptyconf.c_cflag &= ~(ICANON | ECHO);
          tcsetattr (c->fd, TCSANOW, &ptyconf);

-         snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b);
          fd2 = open (tty, O_RDWR);
          if(!fd2)
              log(LOG_WARN, "unable to open tty %s", tty);

--- 369,376 ----
          ptyconf.c_cflag &= ~(ICANON | ECHO);
          tcsetattr (c->fd, TCSANOW, &ptyconf);

+ /*        snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b); */
          fd2 = open (tty, O_RDWR);
          if(!fd2)
              log(LOG_WARN, "unable to open tty %s", tty);

The discussion might have continued from here.