* 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>
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();
+ }
}
/*
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);
}
}
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 */
set_ifunit(1);
script_setenv("BUNDLE", bundle_id + 7, 1);
tdb_writeunlock(pppdb);
+ info("New bundle %s created", ifname);
return 0;
}
* 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 $
*/
/*
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 */
warn("Couldn't set /dev/ppp (channel) to nonblock: %m");
set_ppp_fd(fd);
- ifunit = -1;
if (!looped && !multilink) {
/*
* Create a new 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)
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)
{
set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_MULTILINK);
ifunit = ifnum;
- dbglog("bundle_attach succeeded");
return 1;
}