From 8e950ea70924467a81ecb8411d5fc5932ccc2f23 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sat, 15 Apr 2000 10:10:25 +0000 Subject: [PATCH] fixes for demand mode and multilink --- pppd/main.c | 8 +++++--- pppd/multilink.c | 25 ++++++++++++++++++------- pppd/pppd.h | 3 ++- pppd/sys-linux.c | 37 +++++++++++++++++++++++++------------ 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index ad7c90d..4686382 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -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 #include @@ -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(); + } } /* diff --git a/pppd/multilink.c b/pppd/multilink.c index 546fcae..81528bb 100644 --- a/pppd/multilink.c +++ b/pppd/multilink.c @@ -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; } diff --git a/pppd/pppd.h b/pppd/pppd.h index a19659c..24909fb 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -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 */ diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index 88ab9dd..9208fdc 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -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; } -- 2.39.2