Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.
This commit is contained in:
ozaki-r 2017-06-16 04:40:16 +00:00
parent 67721744d0
commit a49d9c85a4
2 changed files with 35 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: route.8,v 1.56 2016/04/04 07:37:07 ozaki-r Exp $
.\" $NetBSD: route.8,v 1.57 2017/06/16 04:40:16 ozaki-r Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)route.8 8.4 (Berkeley) 6/1/94
.\"
.Dd March 30, 2016
.Dd June 16, 2017
.Dt ROUTE 8
.Os
.Sh NAME
@ -139,8 +139,17 @@ The monitor command has the syntax
.Nm
.Op Fl n
.Cm monitor
.Op Fl c Ar count
.Ed
.Pp
If
.Ar count
is specified,
.Nm
exits after receiving
.Ar count
routing messages.
.Pp
The flush command has the syntax
.Pp
.Bd -filled -offset indent -compact

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.155 2017/03/17 16:13:44 roy Exp $ */
/* $NetBSD: route.c,v 1.156 2017/06/16 04:40:16 ozaki-r Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: route.c,v 1.155 2017/03/17 16:13:44 roy Exp $");
__RCSID("$NetBSD: route.c,v 1.156 2017/06/16 04:40:16 ozaki-r Exp $");
#endif
#endif /* not lint */
@ -108,7 +108,7 @@ static char *netmask_string(const struct sockaddr *, int, int);
static int prefixlen(const char *, struct sou *);
#ifndef SMALL
static void interfaces(void);
__dead static void monitor(void);
static void monitor(int, char * const *);
static int print_getmsg(struct rt_msghdr *, int, struct sou *);
static const char *linkstate(struct if_msghdr *);
static sup readtag(sup, const char *);
@ -236,7 +236,7 @@ main(int argc, char * const *argv)
#ifndef SMALL
case K_MONITOR:
monitor();
monitor(argc, argv);
return 0;
#endif /* SMALL */
@ -1105,20 +1105,37 @@ interfaces(void)
}
static void
monitor(void)
monitor(int argc, char * const *argv)
{
int n;
int i, n;
union {
char msg[2048];
struct rt_msghdr hdr;
} u;
int count = 0;
/* usage: route monitor [-c <count>] */
/* eat "monitor" */
argc -= 1;
argv += 1;
/* parse [-c <count>] */
if (argc > 0) {
if (argc != 2)
usage(argv[0]);
if (strcmp(argv[0], "-c") != 0)
usage(argv[0]);
count = atoi(argv[1]);
}
verbose = 1;
if (debugonly) {
interfaces();
exit(0);
}
for(;;) {
for(i = 0; count == 0 || i < count; i++) {
time_t now;
n = prog_read(sock, &u, sizeof(u));
now = time(NULL);