diff options
author | brian <brian@FreeBSD.org> | 1998-05-23 22:24:50 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1998-05-23 22:24:50 +0000 |
commit | 7f9f3d4b006fb3ffffcebd44183520742fa0bf6f (patch) | |
tree | d9eda8d3412bab2407741e40c3e4b78839fe30ed /usr.sbin/ppp | |
parent | 3d5a66dff7468559eb0f226477cfed7891ba121f (diff) | |
download | FreeBSD-src-7f9f3d4b006fb3ffffcebd44183520742fa0bf6f.zip FreeBSD-src-7f9f3d4b006fb3ffffcebd44183520742fa0bf6f.tar.gz |
o Move our prompt descriptor list outside of the bundle.
It's now dealt with by the `server' object. This simplifies
things as we only have one list of prompt descriptors and
the log_ routines check prompt::logactive to determine
whether it should be used for output.
o Include the MP socket UpdateSet() result in bundle::UpdateSet().
o Don't select on the tun device unless we're in NETWORK
phase or AUTO mode.
o Stop the idle timer when we go to DEAD phase. We may
have transferred a link and not had a chance to kill
it.
o Don't fail when trying to unlink our transferred datalink
from our descriptor lists just before the transfer.
o Add our link descriptor to the write set if we got a short
write the last time (physical::out is set).
o Log the connection source address when a connection is closed.
o Remove descriptor::next field. Descriptor lists are not required
any more.
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r-- | usr.sbin/ppp/bundle.c | 147 | ||||
-rw-r--r-- | usr.sbin/ppp/bundle.h | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/chat.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/datalink.c | 5 | ||||
-rw-r--r-- | usr.sbin/ppp/descriptor.h | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/ipcp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/log.c | 97 | ||||
-rw-r--r-- | usr.sbin/ppp/log.h | 16 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 11 | ||||
-rw-r--r-- | usr.sbin/ppp/mp.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/physical.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/prompt.c | 16 | ||||
-rw-r--r-- | usr.sbin/ppp/prompt.h | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/server.c | 117 |
15 files changed, 222 insertions, 239 deletions
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 1af9b9f..a5aa1ee 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.c,v 1.2 1998/05/21 21:44:08 brian Exp $ + * $Id: bundle.c,v 1.3 1998/05/23 17:05:26 brian Exp $ */ #include <sys/types.h> @@ -112,6 +112,7 @@ bundle_NewPhase(struct bundle *bundle, u_int new) switch (new) { case PHASE_DEAD: + log_DisplayPrompts(); bundle->phase = new; break; @@ -121,7 +122,7 @@ bundle_NewPhase(struct bundle *bundle, u_int new) case PHASE_AUTHENTICATE: bundle->phase = new; - bundle_DisplayPrompt(bundle); + log_DisplayPrompts(); break; case PHASE_NETWORK: @@ -129,13 +130,13 @@ bundle_NewPhase(struct bundle *bundle, u_int new) fsm_Up(&bundle->ncp.ipcp.fsm); fsm_Open(&bundle->ncp.ipcp.fsm); bundle->phase = new; - bundle_DisplayPrompt(bundle); + log_DisplayPrompts(); break; case PHASE_TERMINATE: bundle->phase = new; mp_Down(&bundle->ncp.mp); - bundle_DisplayPrompt(bundle); + log_DisplayPrompts(); break; } } @@ -476,16 +477,12 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) { struct bundle *bundle = descriptor2bundle(d); struct datalink *dl; - struct descriptor *desc; int result, want, queued, nlinks; result = 0; for (dl = bundle->links; dl; dl = dl->next) result += descriptor_UpdateSet(&dl->desc, r, w, e, n); - for (desc = bundle->desc.next; desc; desc = desc->next) - result += descriptor_UpdateSet(desc, r, w, e, n); - /* If there are aren't many packets queued, look for some more. */ for (nlinks = 0, dl = bundle->links; dl; dl = dl->next) nlinks++; @@ -504,7 +501,8 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) bundle_StartAutoLoadTimer(bundle, 1); } - if (r) { + if (r && + (bundle->phase == PHASE_NETWORK || bundle->phys_type & PHYS_DEMAND)) { /* enough surplus so that we can tell if we're getting swamped */ want = bundle->cfg.autoload.max.packets + nlinks * 2; /* but at least 20 packets ! */ @@ -526,7 +524,7 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) * might be ``holding'' one of the datalinks (death-row) and * wants to be able to de-select() it from the descriptor set. */ - descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n); + result += descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n); return result; } @@ -536,16 +534,11 @@ bundle_IsSet(struct descriptor *d, const fd_set *fdset) { struct bundle *bundle = descriptor2bundle(d); struct datalink *dl; - struct descriptor *desc; for (dl = bundle->links; dl; dl = dl->next) if (descriptor_IsSet(&dl->desc, fdset)) return 1; - for (desc = bundle->desc.next; desc; desc = desc->next) - if (descriptor_IsSet(desc, fdset)) - return 1; - if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) return 1; @@ -557,7 +550,6 @@ bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) { struct datalink *dl; - struct descriptor *desc; if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset); @@ -566,10 +558,6 @@ bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle, if (descriptor_IsSet(&dl->desc, fdset)) descriptor_Read(&dl->desc, bundle, fdset); - for (desc = bundle->desc.next; desc; desc = desc->next) - if (descriptor_IsSet(desc, fdset)) - descriptor_Read(desc, bundle, fdset); - if (FD_ISSET(bundle->dev.fd, fdset)) { struct tun_data tun; int n, pri; @@ -653,7 +641,6 @@ bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) { struct datalink *dl; - struct descriptor *desc; /* This is not actually necessary as struct mpserver doesn't Write() */ if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) @@ -662,15 +649,11 @@ bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle, for (dl = bundle->links; dl; dl = dl->next) if (descriptor_IsSet(&dl->desc, fdset)) descriptor_Write(&dl->desc, bundle, fdset); - - for (desc = bundle->desc.next; desc; desc = desc->next) - if (descriptor_IsSet(desc, fdset)) - descriptor_Write(desc, bundle, fdset); } struct bundle * -bundle_Create(const char *prefix, struct prompt *prompt, int type) +bundle_Create(const char *prefix, int type) { int s, enoentcount, err; struct ifreq ifrq; @@ -752,7 +735,6 @@ bundle_Create(const char *prefix, struct prompt *prompt, int type) bundle.ifp.Name = NULL; return NULL; } - prompt_Printf(prompt, "Using interface: %s\n", bundle.ifp.Name); log_Printf(LogPHASE, "Using interface: %s\n", bundle.ifp.Name); bundle.ifp.Speed = 0; @@ -789,7 +771,6 @@ bundle_Create(const char *prefix, struct prompt *prompt, int type) } bundle.desc.type = BUNDLE_DESCRIPTOR; - bundle.desc.next = NULL; bundle.desc.UpdateSet = bundle_UpdateSet; bundle.desc.IsSet = bundle_IsSet; bundle.desc.Read = bundle_DescriptorRead; @@ -866,7 +847,6 @@ void bundle_Destroy(struct bundle *bundle) { struct datalink *dl; - struct descriptor *desc, *ndesc; /* * Clean up the interface. We don't need to timer_Stop()s, mp_Down(), @@ -887,18 +867,6 @@ bundle_Destroy(struct bundle *bundle) /* In case we never made PHASE_NETWORK */ bundle_Notify(bundle, EX_ERRDEAD); - /* Finally, destroy our prompts */ - desc = bundle->desc.next; - while (desc) { - ndesc = desc->next; - if (desc->type == PROMPT_DESCRIPTOR) - prompt_Destroy((struct prompt *)desc, 1); - else - log_Printf(LogERROR, "bundle_Destroy: Don't know how to delete descriptor" - " type %d\n", desc->type); - desc = ndesc; - } - bundle->desc.next = NULL; bundle->ifp.Name = NULL; } @@ -1052,7 +1020,7 @@ bundle_LinkClosed(struct bundle *bundle, struct datalink *dl) fsm_Close(&bundle->ncp.ipcp.fsm); /* ST_INITIAL please */ } bundle_NewPhase(bundle, PHASE_DEAD); - bundle_DisplayPrompt(bundle); + bundle_StopIdleTimer(bundle); bundle_StopAutoLoadTimer(bundle); bundle->autoload.running = 0; } else @@ -1263,84 +1231,6 @@ bundle_IsDead(struct bundle *bundle) return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); } -void -bundle_RegisterDescriptor(struct bundle *bundle, struct descriptor *d) -{ - d->next = bundle->desc.next; - bundle->desc.next = d; -} - -void -bundle_UnRegisterDescriptor(struct bundle *bundle, struct descriptor *d) -{ - struct descriptor **desc; - - for (desc = &bundle->desc.next; *desc; desc = &(*desc)->next) - if (*desc == d) { - *desc = d->next; - break; - } -} - -void -bundle_DelPromptDescriptors(struct bundle *bundle, struct server *s) -{ - struct descriptor **desc; - struct prompt *p; - - desc = &bundle->desc.next; - while (*desc) { - if ((*desc)->type == PROMPT_DESCRIPTOR) { - p = (struct prompt *)*desc; - if (p->owner == s) { - prompt_Destroy(p, 1); - desc = &bundle->desc.next; - continue; - } - } - desc = &(*desc)->next; - } -} - -void -bundle_DisplayPrompt(struct bundle *bundle) -{ - struct descriptor **desc; - - for (desc = &bundle->desc.next; *desc; desc = &(*desc)->next) - if ((*desc)->type == PROMPT_DESCRIPTOR) - prompt_Required((struct prompt *)*desc); -} - -void -bundle_WriteTermPrompt(struct bundle *bundle, struct datalink *dl, - const char *data, int len) -{ - struct descriptor *desc; - struct prompt *p; - - for (desc = bundle->desc.next; desc; desc = desc->next) - if (desc->type == PROMPT_DESCRIPTOR) { - p = (struct prompt *)desc; - if (prompt_IsTermMode(p, dl)) - prompt_Printf(p, "%.*s", len, data); - } -} - -void -bundle_SetTtyCommandMode(struct bundle *bundle, struct datalink *dl) -{ - struct descriptor *desc; - struct prompt *p; - - for (desc = bundle->desc.next; desc; desc = desc->next) - if (desc->type == PROMPT_DESCRIPTOR) { - p = (struct prompt *)desc; - if (prompt_IsTermMode(p, dl)) - prompt_TtyCommandMode(p); - } -} - static void bundle_LinkAdded(struct bundle *bundle, struct datalink *dl) { @@ -1369,14 +1259,13 @@ bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) { struct datalink **dlp; - if (dl->state == DATALINK_CLOSED) - for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) - if (*dlp == dl) { - *dlp = dl->next; - dl->next = NULL; - bundle_LinksRemoved(bundle); - return dl; - } + for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) + if (*dlp == dl) { + *dlp = dl->next; + dl->next = NULL; + bundle_LinksRemoved(bundle); + return dl; + } return NULL; } @@ -1534,8 +1423,8 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun) log_Printf(LogPHASE, "Transmitting datalink %s\n", dl->name); - bundle_DatalinkLinkout(dl->bundle, dl); bundle_LinkClosed(dl->bundle, dl); + bundle_DatalinkLinkout(dl->bundle, dl); /* Build our scatter/gather array */ iov[0].iov_len = strlen(Version) + 1; diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h index 52930c5..974563a 100644 --- a/usr.sbin/ppp/bundle.h +++ b/usr.sbin/ppp/bundle.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.h,v 1.1.2.42 1998/05/21 01:13:24 brian Exp $ + * $Id: bundle.h,v 1.2 1998/05/21 21:44:14 brian Exp $ */ #define PHASE_DEAD 0 /* Link is dead */ @@ -126,7 +126,7 @@ struct bundle { #define descriptor2bundle(d) \ ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) -extern struct bundle *bundle_Create(const char *, struct prompt *, int); +extern struct bundle *bundle_Create(const char *, int); extern void bundle_Destroy(struct bundle *); extern const char *bundle_PhaseName(struct bundle *); #define bundle_Phase(b) ((b)->phase) @@ -151,10 +151,6 @@ extern struct datalink *bundle2datalink(struct bundle *, const char *); extern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); extern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); -extern void bundle_DelPromptDescriptors(struct bundle *, struct server *); -extern void bundle_DisplayPrompt(struct bundle *); -extern void bundle_WriteTermPrompt(struct bundle *, struct datalink *, - const char *, int); extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); extern int bundle_DatalinkClone(struct bundle *, struct datalink *, diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 3791cba..c9e099f 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: chat.c,v 1.44.2.29 1998/05/01 19:24:11 brian Exp $ + * $Id: chat.c,v 1.45 1998/05/21 21:44:37 brian Exp $ */ #include <sys/types.h> @@ -514,7 +514,6 @@ chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf, const char *phone) { c->desc.type = CHAT_DESCRIPTOR; - c->desc.next = NULL; c->desc.UpdateSet = chat_UpdateSet; c->desc.IsSet = chat_IsSet; c->desc.Read = chat_Read; diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c index 4d4c20e..655fc0a 100644 --- a/usr.sbin/ppp/datalink.c +++ b/usr.sbin/ppp/datalink.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: datalink.c,v 1.2 1998/05/21 21:44:54 brian Exp $ + * $Id: datalink.c,v 1.3 1998/05/23 13:38:06 brian Exp $ */ #include <sys/types.h> @@ -543,7 +543,6 @@ datalink_Create(const char *name, struct bundle *bundle, int type) return dl; dl->desc.type = DATALINK_DESCRIPTOR; - dl->desc.next = NULL; dl->desc.UpdateSet = datalink_UpdateSet; dl->desc.IsSet = datalink_IsSet; dl->desc.Read = datalink_Read; @@ -612,7 +611,6 @@ datalink_Clone(struct datalink *odl, const char *name) return dl; dl->desc.type = DATALINK_DESCRIPTOR; - dl->desc.next = NULL; dl->desc.UpdateSet = datalink_UpdateSet; dl->desc.IsSet = datalink_IsSet; dl->desc.Read = datalink_Read; @@ -973,7 +971,6 @@ iov2datalink(struct bundle *bundle, struct iovec *iov, int *niov, int maxiov, (*niov)++; dl->desc.type = DATALINK_DESCRIPTOR; - dl->desc.next = NULL; dl->desc.UpdateSet = datalink_UpdateSet; dl->desc.IsSet = datalink_IsSet; dl->desc.Read = datalink_Read; diff --git a/usr.sbin/ppp/descriptor.h b/usr.sbin/ppp/descriptor.h index c0672b8..b78a1ac 100644 --- a/usr.sbin/ppp/descriptor.h +++ b/usr.sbin/ppp/descriptor.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: descriptor.h,v 1.1.2.10 1998/04/28 01:25:13 brian Exp $ + * $Id: descriptor.h,v 1.2 1998/05/21 21:45:08 brian Exp $ */ #define PHYSICAL_DESCRIPTOR (1) @@ -38,7 +38,6 @@ struct bundle; struct descriptor { int type; - struct descriptor *next; int (*UpdateSet)(struct descriptor *, fd_set *, fd_set *, fd_set *, int *); int (*IsSet)(struct descriptor *, const fd_set *); diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index 015da50..444e93c 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ipcp.c,v 1.50.2.54 1998/05/21 01:26:08 brian Exp $ + * $Id: ipcp.c,v 1.51 1998/05/21 21:45:46 brian Exp $ * * TODO: * o More RFC1772 backwoard compatibility @@ -738,7 +738,7 @@ IpcpLayerUp(struct fsm *fp) throughput_start(&ipcp->throughput, "IPCP throughput", Enabled(fp->bundle, OPT_THROUGHPUT)); - bundle_DisplayPrompt(fp->bundle); + log_DisplayPrompts(); return 1; } diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index 0522059..61a3b29 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/ppp/log.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: log.c,v 1.25.2.14 1998/05/01 22:39:35 brian Exp $ + * $Id: log.c,v 1.27 1998/05/21 21:46:25 brian Exp $ */ #include <sys/types.h> @@ -66,16 +66,28 @@ static const char *LogNames[] = { static u_long LogMask = MSK(LogPHASE); static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); static int LogTunno = -1; -static struct prompt *logprompt; /* Where to log local stuff */ +static struct prompt *promptlist; /* Where to log local stuff */ + +struct prompt * +log_PromptList() +{ + return promptlist; +} void log_RegisterPrompt(struct prompt *prompt) { - if (prompt) { - prompt->lognext = logprompt; - logprompt = prompt; - LogMaskLocal |= prompt->logmask; - } + prompt->next = promptlist; + promptlist = prompt; + prompt->active = 1; + log_DiscardAllLocal(&prompt->logmask); +} + +void +log_ActivatePrompt(struct prompt *prompt) +{ + prompt->active = 1; + LogMaskLocal |= prompt->logmask; } static void @@ -84,26 +96,80 @@ LogSetMaskLocal(void) struct prompt *p; LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); - for (p = logprompt; p; p = p->lognext) + for (p = promptlist; p; p = p->next) LogMaskLocal |= p->logmask; } void +log_DeactivatePrompt(struct prompt *prompt) +{ + if (prompt->active) { + prompt->active = 0; + LogSetMaskLocal(); + } +} + +void log_UnRegisterPrompt(struct prompt *prompt) { if (prompt) { struct prompt **p; - for (p = &logprompt; *p; p = &(*p)->lognext) + for (p = &promptlist; *p; p = &(*p)->next) if (*p == prompt) { - *p = prompt->lognext; - prompt->lognext = NULL; + *p = prompt->next; + prompt->next = NULL; break; } LogSetMaskLocal(); } } +void +log_DestroyPrompts(struct server *s) +{ + struct prompt *p, *pn; + + p = promptlist; + while (p) { + pn = p->next; + if (s && p->owner != s) { + p->next = NULL; + prompt_Destroy(p, 1); + } + p = pn; + } +} + +void +log_DisplayPrompts() +{ + struct prompt *p; + + for (p = promptlist; p; p = p->next) + prompt_Required(p); +} + +void +log_WritePrompts(struct datalink *dl, const char *data, int len) +{ + struct prompt *p; + + for (p = promptlist; p; p = p->next) + if (prompt_IsTermMode(p, dl)) + prompt_Printf(p, "%.*s", len, data); +} + +void +log_SetTtyCommandMode(struct datalink *dl) +{ + struct prompt *p; + + for (p = promptlist; p; p = p->next) + if (prompt_IsTermMode(p, dl)) + prompt_TtyCommandMode(p); +} + static int syslogLevel(int lev) { @@ -225,19 +291,20 @@ log_Printf(int lev, const char *fmt,...) if (log_IsKept(lev)) { static char nfmt[200]; - if ((log_IsKept(lev) & LOG_KEPT_LOCAL) && logprompt) { + if ((log_IsKept(lev) & LOG_KEPT_LOCAL) && promptlist) { if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s", LogTunno, log_Name(lev), fmt); else snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt); - for (prompt = logprompt; prompt; prompt = prompt->lognext) + for (prompt = promptlist; prompt; prompt = prompt->next) if (lev > LogMAXCONF || (prompt->logmask & MSK(lev))) prompt_vPrintf(prompt, nfmt, ap); } - if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) && (lev != LogWARN || !logprompt)) { + if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) && + (lev != LogWARN || !promptlist)) { if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s", LogTunno, log_Name(lev), fmt); @@ -380,7 +447,7 @@ log_ShowWho(struct cmdargs const *arg) { struct prompt *p; - for (p = logprompt; p; p = p->lognext) { + for (p = promptlist; p; p = p->next) { prompt_Printf(arg->prompt, "%s (%s)", p->src.type, p->src.from); if (p == arg->prompt) prompt_Printf(arg->prompt, " *"); diff --git a/usr.sbin/ppp/log.h b/usr.sbin/ppp/log.h index 4e34ee1..3f8969c 100644 --- a/usr.sbin/ppp/log.h +++ b/usr.sbin/ppp/log.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: log.h,v 1.18.2.8 1998/05/01 22:39:37 brian Exp $ + * $Id: log.h,v 1.19 1998/05/21 21:46:30 brian Exp $ */ #define LogMIN (1) @@ -51,6 +51,8 @@ struct mbuf; struct cmdargs; struct prompt; +struct server; +struct datalink; /* The first int arg for all of the following is one of the above values */ extern const char *log_Name(int); @@ -75,8 +77,16 @@ extern void log_Printf(int, const char *,...); #endif extern void log_DumpBp(int, const char *, const struct mbuf *); extern void log_DumpBuff(int, const char *, const u_char *, int); -extern void log_RegisterPrompt(struct prompt *); -extern void log_UnRegisterPrompt(struct prompt *); extern int log_ShowLevel(struct cmdargs const *); extern int log_SetLevel(struct cmdargs const *); extern int log_ShowWho(struct cmdargs const *); + +extern void log_RegisterPrompt(struct prompt *); +extern void log_UnRegisterPrompt(struct prompt *); +extern void log_DestroyPrompts(struct server *); +extern void log_DisplayPrompts(void); +extern void log_WritePrompts(struct datalink *, const char *, int); +extern void log_ActivatePrompt(struct prompt *); +extern void log_DeactivatePrompt(struct prompt *); +extern void log_SetTtyCommandMode(struct datalink *); +extern struct prompt *log_PromptList(void); diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 9620514..d687aa4 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.121.2.60 1998/05/15 18:21:38 brian Exp $ + * $Id: main.c,v 1.123 1998/05/21 21:46:40 brian Exp $ * * TODO: */ @@ -330,10 +330,14 @@ main(int argc, char **argv) return 1; } - if ((bundle = bundle_Create(TUN_PREFIX, prompt, mode)) == NULL) { + if ((bundle = bundle_Create(TUN_PREFIX, mode)) == NULL) { log_Printf(LogWARN, "bundle_Create: %s\n", strerror(errno)); return EX_START; } + if (prompt) { + prompt->bundle = bundle; /* couldn't do it earlier */ + prompt_Printf(prompt, "Using interface: %s\n", bundle->ifp.Name); + } SignalBundle = bundle; if (system_Select(bundle, "default", CONFFILE, prompt) < 0) @@ -474,8 +478,11 @@ DoLoop(struct bundle *bundle, struct prompt *prompt) sig_Handle(); + /* All our datalinks, the tun device and the MP socket */ descriptor_UpdateSet(&bundle->desc, &rfds, &wfds, &efds, &nfds); - descriptor_UpdateSet(&server.desc, &rfds, &wfds, &efds, &nfds); + + /* All our prompts and the diagnostic socket */ + descriptor_UpdateSet(&server.desc, &rfds, NULL, NULL, &nfds); if (bundle_IsDead(bundle)) /* Don't select - we'll be here forever */ diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index e7ce47d..6a05653 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.81 1998/05/21 21:46:56 brian Exp $ + * $Id: modem.c,v 1.82 1998/05/21 22:55:08 brian Exp $ * * TODO: */ @@ -754,7 +754,7 @@ modem_PhysicalClose(struct physical *modem) close(modem->fd); modem->fd = -1; timer_Stop(&modem->Timer); - bundle_SetTtyCommandMode(modem->dl->bundle, modem->dl); + log_SetTtyCommandMode(modem->dl); throughput_stop(&modem->link.throughput); throughput_log(&modem->link.throughput, LogPHASE, modem->link.name); } @@ -951,12 +951,12 @@ modem_DescriptorRead(struct descriptor *d, struct bundle *bundle, /* LCP packet is detected. Turn ourselves into packet mode */ if (cp != rbuff) { /* Get rid of the bit before the HDLC header */ - bundle_WriteTermPrompt(p->dl->bundle, p->dl, rbuff, cp - rbuff); - bundle_WriteTermPrompt(p->dl->bundle, p->dl, "\r\n", 2); + log_WritePrompts(p->dl, rbuff, cp - rbuff); + log_WritePrompts(p->dl, "\r\n", 2); } datalink_Up(p->dl, 0, 1); } else - bundle_WriteTermPrompt(p->dl->bundle, p->dl, rbuff, n); + log_WritePrompts(p->dl, rbuff, n); } } else if (n > 0) async_Input(bundle, rbuff, n, p); @@ -984,7 +984,6 @@ iov2modem(struct datalink *dl, struct iovec *iov, int *niov, int maxiov, int fd) p->desc.IsSet = physical_IsSet; p->desc.Read = modem_DescriptorRead; p->desc.Write = modem_DescriptorWrite; - p->desc.next = NULL; p->type = PHYS_DIRECT; p->dl = dl; len = strlen(_PATH_DEV); diff --git a/usr.sbin/ppp/mp.c b/usr.sbin/ppp/mp.c index 4532f6e..429a01a 100644 --- a/usr.sbin/ppp/mp.c +++ b/usr.sbin/ppp/mp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: mp.c,v 1.3 1998/05/23 13:38:09 brian Exp $ + * $Id: mp.c,v 1.4 1998/05/23 17:05:28 brian Exp $ */ #include <sys/types.h> @@ -850,28 +850,30 @@ mpserver_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) { struct mpserver *s = descriptor2mpserver(d); + int result; + result = 0; if (s->send.dl != NULL) { /* We've connect()ed */ if (!link_QueueLen(&s->send.dl->physical->link) && !s->send.dl->physical->out) { /* Only send if we've transmitted all our data (i.e. the ConfigAck) */ - datalink_RemoveFromSet(s->send.dl, r, w, e); + result -= datalink_RemoveFromSet(s->send.dl, r, w, e); bundle_SendDatalink(s->send.dl, s->fd, &s->socket); s->send.dl = NULL; close(s->fd); s->fd = -1; } else /* Never read from a datalink that's on death row ! */ - datalink_RemoveFromSet(s->send.dl, r, NULL, NULL); + result -= datalink_RemoveFromSet(s->send.dl, r, NULL, NULL); } else if (r && s->fd >= 0) { if (*n < s->fd + 1) *n = s->fd + 1; FD_SET(s->fd, r); log_Printf(LogTIMER, "mp: fdset(r) %d\n", s->fd); - return 1; + result++; } - return 0; + return result; } static int @@ -912,7 +914,6 @@ void mpserver_Init(struct mpserver *s) { s->desc.type = MPSERVER_DESCRIPTOR; - s->desc.next = NULL; s->desc.UpdateSet = mpserver_UpdateSet; s->desc.IsSet = mpserver_IsSet; s->desc.Read = mpserver_Read; diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 6826e06..022c563 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.34 1998/05/21 01:12:20 brian Exp $ + * $Id: physical.c,v 1.2 1998/05/21 21:47:37 brian Exp $ * */ @@ -138,7 +138,7 @@ physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, log_Printf(LogTIMER, "%s: fdset(e) %d\n", p->link.name, p->fd); sets++; } - if (w && (force || link_QueueLen(&p->link))) { + if (w && (force || link_QueueLen(&p->link) || p->out)) { FD_SET(p->fd, w); log_Printf(LogTIMER, "%s: fdset(w) %d\n", p->link.name, p->fd); sets++; diff --git a/usr.sbin/ppp/prompt.c b/usr.sbin/ppp/prompt.c index 81d927b..19c6cba 100644 --- a/usr.sbin/ppp/prompt.c +++ b/usr.sbin/ppp/prompt.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: prompt.c,v 1.1.2.30 1998/05/10 22:20:17 brian Exp $ + * $Id: prompt.c,v 1.2 1998/05/21 21:47:57 brian Exp $ */ #include <sys/param.h> @@ -185,7 +185,7 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) if (n) command_Decode(bundle, linebuff, n, p, p->src.from); } else if (n <= 0) { - log_Printf(LogPHASE, "Client connection closed.\n"); + log_Printf(LogPHASE, "%s: Client connection closed.\n", p->src.from); prompt_Destroy(p, 0); } return; @@ -279,7 +279,6 @@ prompt_Create(struct server *s, struct bundle *bundle, int fd) if (p != NULL) { p->desc.type = PROMPT_DESCRIPTOR; - p->desc.next = NULL; p->desc.UpdateSet = prompt_UpdateSet; p->desc.IsSet = prompt_IsSet; p->desc.Read = prompt_Read; @@ -306,12 +305,8 @@ prompt_Create(struct server *s, struct bundle *bundle, int fd) p->TermMode = NULL; p->nonewline = 1; p->needprompt = 1; - p->active = 1; p->bundle = bundle; - if (p->bundle) - bundle_RegisterDescriptor(p->bundle, &p->desc); log_RegisterPrompt(p); - log_DiscardAllLocal(&p->logmask); } return p; @@ -326,12 +321,11 @@ prompt_Destroy(struct prompt *p, int verbose) if (p->fd_out != p->fd_in) close(p->fd_out); if (verbose) - log_Printf(LogPHASE, "Client connection dropped.\n"); + log_Printf(LogPHASE, "%s: Client connection dropped.\n", p->src.from); } else prompt_TtyOldMode(p); log_UnRegisterPrompt(p); - bundle_UnRegisterDescriptor(p->bundle, &p->desc); free(p); } @@ -502,7 +496,7 @@ prompt_Continue(struct prompt *p) prompt_TtyCommandMode(p); p->nonewline = 1; prompt_Required(p); - p->active = 1; + log_ActivatePrompt(p); } else if (!p->owner) { bgtimer.func = prompt_TimedContinue; bgtimer.name = "prompt bg"; @@ -517,6 +511,6 @@ prompt_Suspend(struct prompt *p) { if (getpgrp() == prompt_pgrp(p)) { prompt_TtyOldMode(p); - p->active = 0; + log_DeactivatePrompt(p); } } diff --git a/usr.sbin/ppp/prompt.h b/usr.sbin/ppp/prompt.h index 53a5bfa..cda800b 100644 --- a/usr.sbin/ppp/prompt.h +++ b/usr.sbin/ppp/prompt.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: prompt.h,v 1.1.2.9 1998/05/01 19:25:44 brian Exp $ + * $Id: prompt.h,v 1.2 1998/05/21 21:48:02 brian Exp $ */ #define LOCAL_AUTH 0x01 @@ -54,7 +54,7 @@ struct prompt { char from[40]; /* Source of connection */ } src; - struct prompt *lognext; /* Maintained in log.c */ + struct prompt *next; /* Maintained in log.c */ u_long logmask; /* Maintained in log.c */ struct termios oldtio; /* Original tty mode */ diff --git a/usr.sbin/ppp/server.c b/usr.sbin/ppp/server.c index ae0ca6bb..f401674 100644 --- a/usr.sbin/ppp/server.c +++ b/usr.sbin/ppp/server.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: server.c,v 1.16.2.19 1998/05/10 22:20:20 brian Exp $ + * $Id: server.c,v 1.18 1998/05/21 21:48:15 brian Exp $ */ #include <sys/types.h> @@ -67,22 +67,38 @@ static int server_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) { struct server *s = descriptor2server(d); + struct prompt *p; + int sets; + sets = 0; if (r && s->fd >= 0) { if (*n < s->fd + 1) *n = s->fd + 1; FD_SET(s->fd, r); log_Printf(LogTIMER, "server: fdset(r) %d\n", s->fd); - return 1; + sets++; } - return 0; + + for (p = log_PromptList(); p; p = p->next) + sets += descriptor_UpdateSet(&p->desc, r, w, e, n); + + return sets; } static int server_IsSet(struct descriptor *d, const fd_set *fdset) { struct server *s = descriptor2server(d); - return s->fd >= 0 && FD_ISSET(s->fd, fdset); + struct prompt *p; + + if (s->fd >= 0 && FD_ISSET(s->fd, fdset)) + return 1; + + for (p = log_PromptList(); p; p = p->next) + if (descriptor_IsSet(&p->desc, fdset)) + return 1; + + return 0; } #define IN_SIZE sizeof(struct sockaddr_in) @@ -99,54 +115,64 @@ server_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) int ssize = ADDRSZ, wfd; struct prompt *p; - wfd = accept(s->fd, sa, &ssize); - if (wfd < 0) { - log_Printf(LogERROR, "server_Read: accept(): %s\n", strerror(errno)); - return; - } - - switch (sa->sa_family) { - case AF_LOCAL: - log_Printf(LogPHASE, "Connected to local client.\n"); - break; - - case AF_INET: - if (ntohs(in->sin_port) < 1024) { - log_Printf(LogALERT, "Rejected client connection from %s:%u" - "(invalid port number) !\n", - inet_ntoa(in->sin_addr), ntohs(in->sin_port)); - close(wfd); - return; - } - log_Printf(LogPHASE, "Connected to client from %s:%u\n", - inet_ntoa(in->sin_addr), in->sin_port); - break; + if (s->fd >= 0 && FD_ISSET(s->fd, fdset)) { + wfd = accept(s->fd, sa, &ssize); + if (wfd < 0) + log_Printf(LogERROR, "server_Read: accept(): %s\n", strerror(errno)); + } else + wfd = -1; - default: - write(wfd, "Unrecognised access !\n", 22); - close(wfd); - return; - } - - if ((p = prompt_Create(s, bundle, wfd)) == NULL) { - write(wfd, "Connection refused.\n", 20); - close(wfd); - } else { + if (wfd >= 0) switch (sa->sa_family) { case AF_LOCAL: - p->src.type = "local"; - strncpy(p->src.from, s->rm, sizeof p->src.from - 1); - p->src.from[sizeof p->src.from - 1] = '\0'; + log_Printf(LogPHASE, "Connected to local client.\n"); break; + case AF_INET: - p->src.type = "tcp"; - snprintf(p->src.from, sizeof p->src.from, "%s:%u", - inet_ntoa(in->sin_addr), in->sin_port); + if (ntohs(in->sin_port) < 1024) { + log_Printf(LogALERT, "Rejected client connection from %s:%u" + "(invalid port number) !\n", + inet_ntoa(in->sin_addr), ntohs(in->sin_port)); + close(wfd); + wfd = -1; + break; + } + log_Printf(LogPHASE, "Connected to client from %s:%u\n", + inet_ntoa(in->sin_addr), in->sin_port); + break; + + default: + write(wfd, "Unrecognised access !\n", 22); + close(wfd); + wfd = -1; break; } - prompt_TtyCommandMode(p); - prompt_Required(p); + + if (wfd >= 0) { + if ((p = prompt_Create(s, bundle, wfd)) == NULL) { + write(wfd, "Connection refused.\n", 20); + close(wfd); + } else { + switch (sa->sa_family) { + case AF_LOCAL: + p->src.type = "local"; + strncpy(p->src.from, s->rm, sizeof p->src.from - 1); + p->src.from[sizeof p->src.from - 1] = '\0'; + break; + case AF_INET: + p->src.type = "tcp"; + snprintf(p->src.from, sizeof p->src.from, "%s:%u", + inet_ntoa(in->sin_addr), in->sin_port); + break; + } + prompt_TtyCommandMode(p); + prompt_Required(p); + } } + + for (p = log_PromptList(); p; p = p->next) + if (descriptor_IsSet(&p->desc, fdset)) + descriptor_Read(&p->desc, bundle, fdset); } static void @@ -159,7 +185,6 @@ server_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) struct server server = { { SERVER_DESCRIPTOR, - NULL, server_UpdateSet, server_IsSet, server_Read, @@ -266,7 +291,7 @@ server_Close(struct bundle *bundle) server.fd = -1; server.port = 0; /* Drop associated prompts */ - bundle_DelPromptDescriptors(bundle, &server); + log_DestroyPrompts(&server); return 1; } return 0; |