diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index bb04bf5a147a..7684fc57ed80 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.139 1998/06/10 00:16:06 brian Exp $ + * $Id: command.c,v 1.140 1998/06/12 17:45:08 brian Exp $ * */ #include @@ -124,7 +124,7 @@ #define NEG_DNS 50 const char Version[] = "2.0-beta"; -const char VersionDate[] = "$Date: 1998/06/10 00:16:06 $"; +const char VersionDate[] = "$Date: 1998/06/12 17:45:08 $"; static int ShowCommand(struct cmdargs const *); static int TerminalCommand(struct cmdargs const *); @@ -138,6 +138,7 @@ static int LinkCommand(struct cmdargs const *); static int AddCommand(struct cmdargs const *); static int DeleteCommand(struct cmdargs const *); static int NegotiateCommand(struct cmdargs const *); +static int ClearCommand(struct cmdargs const *); #ifndef NOALIAS static int AliasCommand(struct cmdargs const *); static int AliasEnable(struct cmdargs const *); @@ -444,6 +445,8 @@ static struct cmdtab const Commands[] = { "Allow ppp access", "allow users|modes ...."}, {"bg", "!bg", BgShellCommand, LOCAL_AUTH, "Run a background command", "[!]bg command"}, + {"clear", NULL, ClearCommand, LOCAL_AUTH | LOCAL_CX_OPT, + "Clear throughput statistics", "clear ipcp|modem [current|overall|peak]..."}, {"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX, "Clone a link", "clone newname..."}, {"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT, @@ -2030,3 +2033,45 @@ command_ShowNegval(unsigned val) } return "disabled & denied"; } + +static int +ClearCommand(struct cmdargs const *arg) +{ + struct pppThroughput *t; + struct datalink *cx; + int i, clear_type; + + if (arg->argc < arg->argn + 1) + return -1; + + if (strcasecmp(arg->argv[arg->argn], "modem") == 0) { + cx = arg->cx; + if (!cx) + cx = bundle2datalink(arg->bundle, NULL); + if (!cx) { + log_Printf(LogWARN, "A link must be specified for ``clear modem''\n"); + return 1; + } + t = &cx->physical->link.throughput; + } else if (strcasecmp(arg->argv[arg->argn], "ipcp") == 0) + t = &arg->bundle->ncp.ipcp.throughput; + else + return -1; + + if (arg->argc > arg->argn + 1) { + clear_type = 0; + for (i = arg->argn + 1; i < arg->argc; i++) + if (strcasecmp(arg->argv[i], "overall") == 0) + clear_type |= THROUGHPUT_OVERALL; + else if (strcasecmp(arg->argv[i], "current") == 0) + clear_type |= THROUGHPUT_CURRENT; + else if (strcasecmp(arg->argv[i], "peak") == 0) + clear_type |= THROUGHPUT_PEAK; + else + return -1; + } else + clear_type = THROUGHPUT_ALL; + + throughput_clear(t, clear_type, arg->prompt); + return 0; +} diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index b6702b5e6b3b..0b26490f9a0b 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.102 1998/05/29 18:32:41 brian Exp $ +.\" $Id: ppp.8,v 1.103 1998/06/12 17:45:26 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -2297,6 +2297,17 @@ will be replaced with the appropriate values. If you wish to pause while the command executes, use the .Dv shell command instead. +.It clear modem|ipcp Op current|overall|peak... +Clear the specified throughput values at either the +.Dq modem +or +.Dq ipcp +level. If +.Dq modem +is specified, context must be given (see the +.Dq link +command below). If no second argument is given, all values are +cleared. .It clone Ar name[,name]... Clone the specified link, creating one or more new links according to the .Ar name diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index b6702b5e6b3b..0b26490f9a0b 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.102 1998/05/29 18:32:41 brian Exp $ +.\" $Id: ppp.8,v 1.103 1998/06/12 17:45:26 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -2297,6 +2297,17 @@ will be replaced with the appropriate values. If you wish to pause while the command executes, use the .Dv shell command instead. +.It clear modem|ipcp Op current|overall|peak... +Clear the specified throughput values at either the +.Dq modem +or +.Dq ipcp +level. If +.Dq modem +is specified, context must be given (see the +.Dq link +command below). If no second argument is given, all values are +cleared. .It clone Ar name[,name]... Clone the specified link, creating one or more new links according to the .Ar name diff --git a/usr.sbin/ppp/throughput.c b/usr.sbin/ppp/throughput.c index c1bc81b62e91..6773f2e63da7 100644 --- a/usr.sbin/ppp/throughput.c +++ b/usr.sbin/ppp/throughput.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: throughput.c,v 1.6 1998/06/09 18:49:08 brian Exp $ + * $Id: throughput.c,v 1.7 1998/06/12 17:45:41 brian Exp $ */ #include @@ -158,3 +158,44 @@ throughput_addout(struct pppThroughput *t, int n) { t->OctetsOut += n; } + +void +throughput_clear(struct pppThroughput *t, int clear_type, struct prompt *prompt) +{ + if (clear_type & (THROUGHPUT_OVERALL|THROUGHPUT_CURRENT)) { + int i; + + for (i = 0; i < SAMPLE_PERIOD; i++) + t->SampleOctets[i] = 0; + t->nSample = 0; + } + + if (clear_type & THROUGHPUT_OVERALL) { + int secs_up; + + secs_up = t->uptime ? time(NULL) - t->uptime : 1; + prompt_Printf(prompt, "overall cleared (was %5ld bytes/sec)\n", + (t->OctetsIn + t->OctetsOut)/secs_up); + t->OctetsIn = t->OctetsOut = 0; + t->uptime = time(NULL); + } + + if (clear_type & THROUGHPUT_CURRENT) { + prompt_Printf(prompt, "current cleared (was %5d bytes/sec)\n", + t->OctetsPerSecond); + t->OctetsPerSecond = 0; + } + + if (clear_type & THROUGHPUT_PEAK) { + char *time_buf, *last; + + time_buf = ctime(&t->BestOctetsPerSecondTime); + last = time_buf + strlen(time_buf); + if (last > time_buf && *--last == '\n') + *last = '\0'; + prompt_Printf(prompt, "peak cleared (was %5d bytes/sec on %s)\n", + t->BestOctetsPerSecond, time_buf); + t->BestOctetsPerSecond = 0; + t->BestOctetsPerSecondTime = time(NULL); + } +} diff --git a/usr.sbin/ppp/throughput.h b/usr.sbin/ppp/throughput.h index dfad6199fdb8..bdeac1e86b4f 100644 --- a/usr.sbin/ppp/throughput.h +++ b/usr.sbin/ppp/throughput.h @@ -23,11 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: throughput.h,v 1.3 1998/05/21 21:48:43 brian Exp $ + * $Id: throughput.h,v 1.4 1998/06/09 18:49:10 brian Exp $ */ #define SAMPLE_PERIOD 5 +#define THROUGHPUT_OVERALL 0x0001 +#define THROUGHPUT_CURRENT 0x0002 +#define THROUGHPUT_PEAK 0x0004 +#define THROUGHPUT_ALL THROUGHPUT_OVERALL | THROUGHPUT_CURRENT \ + | THROUGHPUT_PEAK + struct pppThroughput { time_t uptime; u_long OctetsIn; @@ -48,3 +54,4 @@ extern void throughput_start(struct pppThroughput *, const char *, int); extern void throughput_stop(struct pppThroughput *); extern void throughput_addin(struct pppThroughput *, int); extern void throughput_addout(struct pppThroughput *, int); +extern void throughput_clear(struct pppThroughput *, int, struct prompt *);