/* -*-c-*-
*
- * $Id: admin.c,v 1.4 2001/02/06 09:34:53 mdw Exp $
+ * $Id: admin.c,v 1.5 2001/02/16 21:22:51 mdw Exp $
*
* Admin interface for configuration
*
/*----- Revision history --------------------------------------------------*
*
* $Log: admin.c,v $
+ * Revision 1.5 2001/02/16 21:22:51 mdw
+ * Support for displaying statistics. Make client connections blocking, so
+ * that things don't get dropped. (This might change again if I add
+ * buffering.)
+ *
* Revision 1.4 2001/02/06 09:34:53 mdw
* Change ERR response to FAIL for consistency with other programs.
*
}
}
+static void acmd_stats(admin *a, unsigned ac, char *av[])
+{
+ peer *p;
+ stats *st;
+
+ if ((p = p_find(av[0])) == 0)
+ a_write(a, "FAIL peer `%s' not found\n", av[0]);
+ else {
+ st = p_stats(p);
+ a_write(a, "INFO start-time=%s\n", timestr(st->t_start));
+ a_write(a, "INFO last-packet-time=%s\n", timestr(st->t_last));
+ a_write(a, "INFO packets-in=%lu bytes-in=%lu\n", st->n_in, st->sz_in);
+ a_write(a, "INFO packets-out=%lu bytes-out=%lu\n",
+ st->n_out, st->sz_out);
+ a_write(a, "INFO keyexch-packets-in=%lu keyexch-bytes-in=%lu\n",
+ st->n_kxin, st->sz_kxin);
+ a_write(a, "INFO keyexch-packets-out=%lu keyexch-bytes-out=%lu\n",
+ st->n_kxout, st->sz_kxout);
+ a_write(a, "INFO ip-packets-in=%lu ip-bytes-in=%lu\n",
+ st->n_ipin, st->sz_ipin);
+ a_write(a, "INFO ip-packets-out=%lu ip-bytes-out=%lu\n",
+ st->n_ipout, st->sz_ipout);
+ a_write(a, "INFO rejected-packets=%lu\n", st->n_reject);
+ a_write(a, "OK\n");
+ }
+}
+
static void acmd_kill(admin *a, unsigned ac, char *av[])
{
peer *p;
{ "list", "LIST", 0, 0, acmd_list },
{ "ifname", "IFNAME peer", 1, 1, acmd_ifname },
{ "addr", "ADDR peer", 1, 1, acmd_addr },
+ { "stats", "STATS peer", 1, 1, acmd_stats },
{ "kill", "KILL peer", 1, 1, acmd_kill },
{ "add", "ADD peer addr port", 3, 3, acmd_add },
{ "quit", "QUIT", 0, 0, acmd_quit },
a->pname = 0;
if (fd_in == STDIN_FILENO)
a_stdin = a;
- fdflags(fd_in, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
+ fdflags(fd_in, O_NONBLOCK, 0, FD_CLOEXEC, FD_CLOEXEC);
if (fd_out != fd_in)
- fdflags(fd_out, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
+ fdflags(fd_out, O_NONBLOCK, 0, FD_CLOEXEC, FD_CLOEXEC);
a->fd = fd_out;
selbuf_init(&a->b, &sel, fd_in, a_line, a);
a->next = admins;
}
if (!S_ISSOCK(st.st_mode))
die(EXIT_FAILURE, "object `%s' isn't a socket", sun.sun_path);
- T( trace(T_ADMIN, "stale socket found; removing it"); )
+ T( trace(T_ADMIN, "admin: stale socket found; removing it"); )
unlink(sun.sun_path);
close(fd);
goto again;