From 3bf710a4bacbaa768b2fab10be5348e41dfbab0e Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Fri, 6 Mar 1998 00:34:47 +0000 Subject: [PATCH] o Move all device names into struct physical. o Use the correct device name in -direct mode. o Use a default list of "cuaa1, cuaa0" rather than just cuaa1 and allow embedded spaces as separators. --- usr.sbin/ppp/chap.c | 7 +-- usr.sbin/ppp/command.c | 4 +- usr.sbin/ppp/defs.h | 15 ++---- usr.sbin/ppp/modem.c | 104 +++++++++++++++++++++------------------- usr.sbin/ppp/modem.h | 3 +- usr.sbin/ppp/pap.c | 7 +-- usr.sbin/ppp/physical.c | 14 +++--- usr.sbin/ppp/physical.h | 10 +++- usr.sbin/ppp/vars.c | 7 ++- usr.sbin/ppp/vars.h | 8 +--- 10 files changed, 89 insertions(+), 90 deletions(-) diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index aad6639a0121..2ddf2372247d 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: chap.c,v 1.28.2.10 1998/02/19 02:08:42 brian Exp $ + * $Id: chap.c,v 1.28.2.11 1998/03/01 01:07:40 brian Exp $ * * TODO: */ @@ -238,14 +238,15 @@ RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp, if ((mode & MODE_DIRECT) && Physical_IsATTY(physical) && Enabled(ConfUtmp)) if (Utmp) + /* XXX: one entry per line please ! */ LogPrintf(LogERROR, "Oops, already logged in on %s\n", - VarBaseDevice); + physical->name.base); else { struct utmp ut; memset(&ut, 0, sizeof ut); time(&ut.ut_time); strncpy(ut.ut_name, name, sizeof ut.ut_name); - strncpy(ut.ut_line, VarBaseDevice, sizeof ut.ut_line - 1); + strncpy(ut.ut_line, physical->name.base, sizeof ut.ut_line - 1); ID0login(&ut); Utmp = 1; } diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index c67065deee9e..e6b7929968f5 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.131.2.29 1998/02/23 00:38:25 brian Exp $ + * $Id: command.c,v 1.131.2.30 1998/03/01 01:07:42 brian Exp $ * */ #include @@ -1330,7 +1330,7 @@ SetVariable(struct cmdargs const *arg) } break; case VAR_DEVICE: - modem_SetDeviceName(cx->physical, argp); + Physical_SetDeviceList(cx->physical, argp); break; case VAR_ACCMAP: sscanf(argp, "%lx", &map); diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index bacb701234aa..f030cd1de802 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -15,24 +15,19 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: defs.h,v 1.29.2.2 1998/02/16 19:10:38 brian Exp $ + * $Id: defs.h,v 1.29.2.3 1998/02/16 19:11:06 brian Exp $ * * TODO: */ -/* - * Check following definitions for your machine environment - */ +/* Check the following definitions for your machine environment */ #ifdef __FreeBSD__ -# define MODEM_DEV "/dev/cuaa1" /* name of tty device */ -# define BASE_MODEM_DEV "cuaa1" /* name of base tty device */ +# define MODEM_LIST "/dev/cuaa1,/dev/cuaa0" /* name of tty device */ #else # ifdef __OpenBSD__ -# define MODEM_DEV "/dev/cua01" /* name of tty device */ -# define BASE_MODEM_DEV "cua01" /* name of base tty device */ +# define MODEM_LIST "/dev/cua01,/dev/cua00" /* name of tty device */ # else -# define MODEM_DEV "/dev/tty01" /* name of tty device */ -# define BASE_MODEM_DEV "tty01" /* name of base tty device */ +# define MODEM_LIST "/dev/tty01,/dev/tty00" /* name of tty device */ # endif #endif diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index 2d4a55d5abf2..4709790cf4e8 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.c,v 1.77.2.26 1998/02/27 21:46:00 brian Exp $ + * $Id: modem.c,v 1.77.2.27 1998/03/01 01:07:47 brian Exp $ * * TODO: */ @@ -124,11 +124,16 @@ modem_Create(const char *name) p->out = NULL; p->connect_count = 0; + *p->name.full = '\0'; + p->name.base = p->name.full; + p->cfg.is_direct = 0; /* not yet used */ p->cfg.is_dedicated = 0; /* not yet used */ p->cfg.rts_cts = MODEM_CTSRTS; p->cfg.speed = MODEM_SPEED; p->cfg.parity = CS8; + strncpy(p->cfg.devlist, MODEM_LIST, sizeof p->cfg.devlist - 1); + p->cfg.devlist[sizeof p->cfg.devlist - 1] = '\0'; return p; } @@ -246,6 +251,15 @@ IntToSpeed(int nspeed) return B0; } +static void +modem_SetDevice(struct physical *physical, const char *name) +{ + strncpy(physical->name.full, name, sizeof physical->name.full - 1); + physical->name.full[sizeof physical->name.full - 1] = '\0'; + physical->name.base = strncmp(physical->name.full, "/dev/", 5) ? + physical->name.full : physical->name.full + 5; +} + struct timeoutArg { struct bundle *bundle; struct physical *modem; @@ -413,7 +427,7 @@ modem_lock(struct physical *modem, int tunno) FILE *lockfile; char fn[MAXPATHLEN]; - if (*VarDevice != '/') + if (*modem->name.full != '/') return 0; if ( @@ -422,16 +436,16 @@ modem_lock(struct physical *modem, int tunno) #else !(mode & MODE_DIRECT) && #endif - (res = ID0uu_lock(VarBaseDevice)) != UU_LOCK_OK) { + (res = ID0uu_lock(modem->name.base)) != UU_LOCK_OK) { if (res == UU_LOCK_INUSE) - LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice); + LogPrintf(LogPHASE, "Modem %s is in use\n", modem->name.full); else LogPrintf(LogPHASE, "Modem %s is in use: uu_lock: %s\n", - VarDevice, uu_lockerr(res)); + modem->name.full, uu_lockerr(res)); return (-1); } - snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, VarBaseDevice); + snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, modem->name.base); lockfile = ID0fopen(fn, "w"); if (lockfile != NULL) { fprintf(lockfile, "tun%d\n", tunno); @@ -450,10 +464,10 @@ modem_Unlock(struct physical *modem) { char fn[MAXPATHLEN]; - if (*VarDevice != '/') + if (*modem->name.full != '/') return; - snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, VarBaseDevice); + snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, modem->name.base); #ifndef RELEASE_CRUNCH if (ID0unlink(fn) == -1) LogPrintf(LogALERT, "Warning: Can't remove %s: %s\n", fn, strerror(errno)); @@ -467,7 +481,7 @@ modem_Unlock(struct physical *modem) #else !(mode & MODE_DIRECT) && #endif - ID0uu_unlock(VarBaseDevice) == -1) + ID0uu_unlock(modem->name.base) == -1) LogPrintf(LogALERT, "Warning: Can't uu_unlock %s\n", fn); } @@ -479,20 +493,6 @@ modem_Found(struct physical *modem) LogPrintf(LogPHASE, "Connected!\n"); } -void -modem_SetDeviceName(struct physical *modem, const char *name) -{ - if (name == NULL) - name = ""; - - if (link_IsActive(&modem->link)) - LogPrintf(LogWARN, - "Cannot change device to \"%s\" when \"%s\" is open\n", - name, Physical_GetDevice(modem)); - else - Physical_SetDevice(modem, name); -} - int modem_Open(struct physical *modem, struct bundle *bundle) { @@ -500,7 +500,7 @@ modem_Open(struct physical *modem, struct bundle *bundle) int oldflag; char *host, *port; char *cp; - char tmpDeviceList[sizeof VarDeviceList]; + char tmpDeviceList[sizeof modem->cfg.devlist]; char *tmpDevice; if (modem->fd >= 0) @@ -515,7 +515,7 @@ modem_Open(struct physical *modem, struct bundle *bundle) ) { if (isatty(STDIN_FILENO)) { LogPrintf(LogDEBUG, "modem_Open(direct): Modem is a tty\n"); - modem_SetDeviceName(modem, ttyname(STDIN_FILENO)); + modem_SetDevice(modem, ttyname(STDIN_FILENO)); if (modem_lock(modem, bundle->unit) == -1) { close(STDIN_FILENO); return -1; @@ -524,62 +524,63 @@ modem_Open(struct physical *modem, struct bundle *bundle) modem_Found(modem); } else { LogPrintf(LogDEBUG, "modem_Open(direct): Modem is not a tty\n"); - modem_SetDeviceName(modem, NULL); + modem_SetDevice(modem, ""); /* We don't call modem_Timeout() with this type of connection */ modem_Found(modem); return modem->fd = STDIN_FILENO; } } else { - strncpy(tmpDeviceList, VarDeviceList, sizeof tmpDeviceList - 1); + strncpy(tmpDeviceList, modem->cfg.devlist, sizeof tmpDeviceList - 1); tmpDeviceList[sizeof tmpDeviceList - 1] = '\0'; - for(tmpDevice=strtok(tmpDeviceList, ","); tmpDevice && (modem->fd < 0); - tmpDevice=strtok(NULL,",")) { - strncpy(VarDevice, tmpDevice, sizeof VarDevice - 1); - VarDevice[sizeof VarDevice - 1]= '\0'; - VarBaseDevice = strrchr(VarDevice, '/'); - VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : ""; + for(tmpDevice=strtok(tmpDeviceList, ", "); tmpDevice && (modem->fd < 0); + tmpDevice=strtok(NULL,", ")) { + modem_SetDevice(modem, tmpDevice); - if (strncmp(VarDevice, "/dev/", 5) == 0) { - if (modem_lock(modem, bundle->unit) == -1) { + if (*modem->name.full == '/') { + if (modem_lock(modem, bundle->unit) == -1) modem->fd = -1; - } else { - modem->fd = ID0open(VarDevice, O_RDWR | O_NONBLOCK); + modem->fd = ID0open(modem->name.full, O_RDWR | O_NONBLOCK); if (modem->fd < 0) { - LogPrintf(LogERROR, "modem_Open failed: %s: %s\n", VarDevice, + LogPrintf(LogERROR, "modem_Open failed: %s: %s\n", modem->name.full, strerror(errno)); modem_Unlock(modem); modem->fd = -1; } else { modem_Found(modem); - LogPrintf(LogDEBUG, "modem_Open: Modem is %s\n", VarDevice); + LogPrintf(LogDEBUG, "modem_Open: Modem is %s\n", modem->name.full); } } } else { /* PPP over TCP */ - cp = strchr(VarDevice, ':'); + /* + * XXX: Fix me - this should be another sort of link (similar to a + * physical + */ + cp = strchr(modem->name.full, ':'); if (cp) { *cp = '\0'; - host = VarDevice; + host = modem->name.full; port = cp + 1; if (*host && *port) { modem->fd = OpenConnection(host, port); - *cp = ':'; /* Don't destroy VarDevice */ + *cp = ':'; /* Don't destroy name.full */ if (modem->fd < 0) return (-1); modem_Found(modem); - LogPrintf(LogDEBUG, "modem_Open: Modem is socket %s\n", VarDevice); + LogPrintf(LogDEBUG, "modem_Open: Modem is socket %s\n", + modem->name.full); } else { - *cp = ':'; /* Don't destroy VarDevice */ - LogPrintf(LogERROR, "Invalid host:port: \"%s\"\n", VarDevice); + *cp = ':'; /* Don't destroy name.full */ + LogPrintf(LogERROR, "Invalid host:port: \"%s\"\n", + modem->name.full); return (-1); } } else { - LogPrintf(LogERROR, - "Device (%s) must be in /dev or be a host:port pair\n", - VarDevice); + LogPrintf(LogERROR, "Device (%s) must begin with a '/' or be a" + " host:port pair\n", modem->name.full); return (-1); } } @@ -847,7 +848,7 @@ modem_LogicalClose(struct physical *modem) LogPrintf(LogDEBUG, "modem_LogicalClose\n"); if (modem->fd >= 0) { if (Utmp) { - ID0logout(VarBaseDevice); + ID0logout(modem->name.base); Utmp = 0; } modem_PhysicalClose(modem); @@ -906,8 +907,11 @@ modem_ShowStatus(struct cmdargs const *arg) int nb; #endif - dev = *VarDevice ? VarDevice : "network"; + dev = *arg->cx->physical->name.full ? + arg->cx->physical->name.full : "stdin"; + prompt_Printf(&prompt, "device configuration: %s\n", + arg->cx->physical->cfg.devlist); prompt_Printf(&prompt, "device: %s speed: ", dev); if (Physical_IsSync(arg->cx->physical)) prompt_Printf(&prompt, "sync\n"); diff --git a/usr.sbin/ppp/modem.h b/usr.sbin/ppp/modem.h index cde978391d5b..9b6c1ebc9f77 100644 --- a/usr.sbin/ppp/modem.h +++ b/usr.sbin/ppp/modem.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.h,v 1.16.2.9 1998/02/21 01:45:23 brian Exp $ + * $Id: modem.h,v 1.16.2.10 1998/02/23 00:38:38 brian Exp $ * * TODO: */ @@ -32,4 +32,3 @@ extern int modem_SetParity(struct physical *, const char *); extern int modem_ShowStatus(struct cmdargs const *); extern void modem_Close(struct physical *); extern void modem_Offline(struct physical *); -extern void modem_SetDeviceName(struct physical *, const char *); diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 96272878d742..b2b50b253cfe 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -18,7 +18,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pap.c,v 1.20.2.10 1998/02/19 02:08:53 brian Exp $ + * $Id: pap.c,v 1.20.2.11 1998/03/01 01:07:48 brian Exp $ * * TODO: */ @@ -175,14 +175,15 @@ PapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical) if ((mode & MODE_DIRECT) && Physical_IsATTY(physical) && Enabled(ConfUtmp)) if (Utmp) + /* XXX: one entry per line please ! */ LogPrintf(LogERROR, "Oops, already logged in on %s\n", - VarBaseDevice); + physical->name.base); else { struct utmp ut; memset(&ut, 0, sizeof ut); time(&ut.ut_time); strncpy(ut.ut_name, cp+1, sizeof ut.ut_name); - strncpy(ut.ut_line, VarBaseDevice, sizeof ut.ut_line - 1); + strncpy(ut.ut_line, physical->name.base, sizeof ut.ut_line - 1); ID0login(&ut); Utmp = 1; } diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 57cb4d3377f4..e0da3d8e20e8 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.c,v 1.1.2.11 1998/02/18 19:35:53 brian Exp $ + * $Id: physical.c,v 1.1.2.12 1998/02/23 00:38:39 brian Exp $ * */ @@ -87,16 +87,16 @@ Physical_FD_SET(struct physical *phys, fd_set *set) { } -/* XXX-ML - must be moved into the physical struct */ -const char *Physical_GetDevice(struct physical *phys) { - return VarDevice; +const char *Physical_GetDevice(struct physical *phys) +{ + return phys->name.full; } /* XXX-ML - must be moved into the physical struct */ void -Physical_SetDevice(struct physical *phys, const char *new_device_list) { - strncpy(VarDeviceList, new_device_list, sizeof VarDeviceList - 1); - VarDeviceList[sizeof VarDeviceList - 1] = '\0'; +Physical_SetDeviceList(struct physical *phys, const char *new_device_list) { + strncpy(phys->cfg.devlist, new_device_list, sizeof phys->cfg.devlist - 1); + phys->cfg.devlist[sizeof phys->cfg.devlist - 1] = '\0'; } diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h index bc12ed6b6274..cbc7b208170e 100644 --- a/usr.sbin/ppp/physical.h +++ b/usr.sbin/ppp/physical.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.h,v 1.1.2.11 1998/02/21 01:45:24 brian Exp $ + * $Id: physical.h,v 1.1.2.12 1998/02/23 00:38:39 brian Exp $ * */ @@ -36,6 +36,11 @@ struct physical { struct mbuf *out; int connect_count; + struct { + char full[40]; + char *base; + } name; + /* XXX-ML Most of the below is device specific, and probably do not belong in the generic physical struct. It comes from modem.c. */ @@ -45,6 +50,7 @@ struct physical { unsigned rts_cts : 1; /* Is rts/cts enabled? */ unsigned int parity; /* What parity is enabled? (TTY flags) */ unsigned int speed; /* Modem speed */ + char devlist[LINE_LEN]; /* Comma-separated list of devices */ } cfg; struct termios ios; /* To be able to reset from raw mode */ @@ -69,7 +75,7 @@ int Physical_IsDirect(struct physical *phys); const char *Physical_GetDevice(struct physical *); -void Physical_SetDevice(struct physical *phys, const char *new_device_list); +void Physical_SetDeviceList(struct physical *, const char *); int /* Was this speed OK? */ Physical_SetSpeed(struct physical *phys, int speed); diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index cc94db817484..11db32fd51f5 100644 --- a/usr.sbin/ppp/vars.c +++ b/usr.sbin/ppp/vars.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vars.c,v 1.45.2.10 1998/02/16 19:11:08 brian Exp $ + * $Id: vars.c,v 1.45.2.11 1998/02/17 01:05:20 brian Exp $ * */ #include @@ -46,7 +46,7 @@ #include "prompt.h" char VarVersion[] = "PPP Version 2.0-beta"; -char VarLocalVersion[] = "$Date: 1998/02/16 19:11:08 $"; +char VarLocalVersion[] = "$Date: 1998/02/17 01:05:20 $"; int Utmp = 0; int ipKeepAlive = 0; @@ -72,8 +72,7 @@ struct confdesc pppConfs[] = { }; struct pppvars pppVars = { - DEF_MRU, DEF_MTU, 0, 180, 30, 3, - 1, MODEM_DEV, "", BASE_MODEM_DEV, 1, LOCAL_NO_AUTH + DEF_MRU, DEF_MTU, 0, 180, 30, 3, 1, 1, LOCAL_NO_AUTH }; int diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h index f3dd2555533e..9dc560a2981b 100644 --- a/usr.sbin/ppp/vars.h +++ b/usr.sbin/ppp/vars.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vars.h,v 1.42.2.8 1998/02/17 01:05:22 brian Exp $ + * $Id: vars.h,v 1.42.2.9 1998/02/17 19:28:01 brian Exp $ * * TODO: */ @@ -62,9 +62,6 @@ struct pppvars { int lqr_timeout; /* LQR timeout value */ int retry_timeout; /* Retry timeout value */ int loopback; /* Turn around packets addressed to me */ - char modem_devlist[LINE_LEN]; /* Comma-separated list of devices */ - char modem_dev[40]; /* Name of device / host:port */ - const char *base_modem_dev; /* Pointer to base of modem_dev */ int open_mode; /* Delay before first LCP REQ (-1 = passive) */ #define LOCAL_AUTH 0x01 #define LOCAL_NO_AUTH 0x02 @@ -94,9 +91,6 @@ struct pppvars { #define VarAccmap pppVars.var_accmap #define VarMRU pppVars.var_mru #define VarPrefMTU pppVars.pref_mtu -#define VarDevice pppVars.modem_dev -#define VarDeviceList pppVars.modem_devlist -#define VarBaseDevice pppVars.base_modem_dev #define VarOpenMode pppVars.open_mode #define VarLocalAuth pppVars.lauth #define VarIdleTimeout pppVars.idle_timeout