]> git.ozlabs.org Git - ppp.git/commitdiff
fixes for demand mode and multilink
authorPaul Mackerras <paulus@samba.org>
Sat, 15 Apr 2000 10:10:25 +0000 (10:10 +0000)
committerPaul Mackerras <paulus@samba.org>
Sat, 15 Apr 2000 10:10:25 +0000 (10:10 +0000)
pppd/main.c
pppd/multilink.c
pppd/pppd.h
pppd/sys-linux.c

index ad7c90d0910bd0b5831c01cf0ae87fa64106c3c0..46863829fdb4bb2a2b874e41ba72e1eecc0d1465 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: main.c,v 1.94 2000/04/15 01:27:13 masputra Exp $"
+#define RCSID  "$Id: main.c,v 1.95 2000/04/15 10:10:24 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -1017,8 +1017,10 @@ set_ifunit(iskey)
     info("Using interface ppp%d", ifunit);
     slprintf(ifname, sizeof(ifname), "ppp%d", ifunit);
     script_setenv("IFNAME", ifname, iskey);
-    create_pidfile();  /* write pid to file */
-    create_linkpidfile();
+    if (iskey) {
+       create_pidfile();       /* write pid to file */
+       create_linkpidfile();
+    }
 }
 
 /*
index 546fcaea64004d0d2df991705975de6d90a4761d..81528bb23a1a069f6965e7ca528a4168f0f35637 100644 (file)
@@ -127,24 +127,34 @@ mp_join_bundle()
                p += slprintf(p, bundle_id+l-p, "/%v", bundle_name);
        dbglog("bundle_id = %s", bundle_id+7);
 
+       /*
+        * For demand mode, we only need to configure the bundle
+        * and attach the link.
+        */
+       if (demand) {
+               cfg_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf);
+               script_setenv("BUNDLE", bundle_id + 7, 1);
+               return 0;
+       }
+
        /*
         * Check if the bundle ID is already in the database.
         */
        unit = -1;
-       pppd_pid = -1;
+       tdb_writelock(pppdb);
        key.dptr = bundle_id;
        key.dsize = p - bundle_id;
-       tdb_writelock(pppdb);
        pid = tdb_fetch(pppdb, key);
        if (pid.dptr != NULL) {
-               /* bundle ID exists, see if the pppd record still exists */
+               /* bundle ID exists, see if the pppd record exists */
                rec = tdb_fetch(pppdb, pid);
                if (rec.dptr != NULL) {
                        /* it is, parse the interface number */
                        parse_num(rec.dptr, "IFNAME=ppp", &unit);
                        /* check the pid value */
-                       parse_num(rec.dptr, "PPPD_PID=", &pppd_pid);
-                       if (!process_exists(pppd_pid) || !owns_unit(pid, unit))
+                       if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid)
+                           || !process_exists(pppd_pid)
+                           || !owns_unit(pid, unit))
                                unit = -1;
                        free(rec.dptr);
                }
@@ -152,12 +162,12 @@ mp_join_bundle()
        }
 
        if (unit >= 0) {
-               /* attach to existing unit, if the pid still exists */
+               /* attach to existing unit */
                if (bundle_attach(unit)) {
-                       dbglog("attached link to interface %d", ifunit);
                        set_ifunit(0);
                        script_setenv("BUNDLE", bundle_id + 7, 0);
                        tdb_writeunlock(pppdb);
+                       info("Link attached to %s", ifname);
                        return 1;
                }
                /* attach failed because bundle doesn't exist */
@@ -168,6 +178,7 @@ mp_join_bundle()
        set_ifunit(1);
        script_setenv("BUNDLE", bundle_id + 7, 1);
        tdb_writeunlock(pppdb);
+       info("New bundle %s created", ifname);
        return 0;
 }
 
index a19659ce2c9467e22b6ed735dfd0dc02f2a8912f..24909fb44d005e5d72273a79f2c7dc7a03208b87 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: pppd.h,v 1.53 2000/04/13 12:05:15 paulus Exp $
+ * $Id: pppd.h,v 1.54 2000/04/15 10:10:25 paulus Exp $
  */
 
 /*
@@ -407,6 +407,7 @@ void restore_loop __P((void));      /* Transfer ppp unit back to loopback */
 void disestablish_ppp __P((int)); /* Restore port to normal operation */
 void make_new_bundle __P((int, int, int, int)); /* Create new bundle */
 int  bundle_attach __P((int)); /* Attach link to existing bundle */
+void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */
 void clean_check __P((void));  /* Check if line was 8-bit clean */
 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
 void restore_tty __P((int));   /* Restore port's original parameters */
index 88ab9ddba54b50a0bd2e31175844611e299f87f6..9208fdc6cf556dd1b4edcf06ad759b1ed25d1991 100644 (file)
@@ -415,7 +415,6 @@ int establish_ppp (int tty_fd)
            warn("Couldn't set /dev/ppp (channel) to nonblock: %m");
        set_ppp_fd(fd);
 
-       ifunit = -1;
        if (!looped && !multilink) {
            /*
             * Create a new PPP unit.
@@ -550,22 +549,16 @@ static int make_ppp_unit()
 }
 
 /*
- * make_new_bundle - create a new PPP unit (i.e. a bundle)
- * and connect our channel to it.  This should only get called
- * if `multilink' was set at the time establish_ppp was called.
+ * cfg_bundle - configure the existing bundle.
+ * Used in demand mode.
  */
-void make_new_bundle(int mrru, int mtru, int rssn, int tssn)
+void cfg_bundle(int mrru, int mtru, int rssn, int tssn)
 {
        int flags;
        struct ifreq ifr;
 
-       if (looped || !new_style_driver)
+       if (!new_style_driver)
                return;
-       dbglog("make_new_bundle(%d,%d,%d,%d)", mrru, mtru, rssn, tssn);
-
-       /* make us a ppp unit */
-       if (make_ppp_unit() < 0)
-               die(1);
 
        /* set the mrru, mtu and flags */
        if (ioctl(ppp_dev_fd, PPPIOCSMRRU, &mrru) < 0)
@@ -591,8 +584,29 @@ void make_new_bundle(int mrru, int mtru, int rssn, int tssn)
        add_fd(ppp_dev_fd);
 }
 
+/*
+ * make_new_bundle - create a new PPP unit (i.e. a bundle)
+ * and connect our channel to it.  This should only get called
+ * if `multilink' was set at the time establish_ppp was called.
+ * In demand mode this uses our existing bundle instead of making
+ * a new one.
+ */
+void make_new_bundle(int mrru, int mtru, int rssn, int tssn)
+{
+       if (!new_style_driver)
+               return;
+
+       /* make us a ppp unit */
+       if (make_ppp_unit() < 0)
+               die(1);
+
+       /* set the mrru, mtu and flags */
+       cfg_bundle(mrru, mtru, rssn, tssn);
+}
+
 /*
  * bundle_attach - attach our link to a given PPP unit.
+ * We assume the unit is controlled by another pppd.
  */
 int bundle_attach(int ifnum)
 {
@@ -609,7 +623,6 @@ int bundle_attach(int ifnum)
        set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_MULTILINK);
 
        ifunit = ifnum;
-       dbglog("bundle_attach succeeded");
        return 1;
 }