aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/show.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-02-22 21:53:55 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-02-23 07:09:49 +0100
commitbda4b8c60b030727c49e291ca575cf6067c720d7 (patch)
tree8e839d9984e5588843b0721235339cba0d177ef2 /src/show.c
parentwg: give "off" value for fwmark (diff)
downloadwireguard-tools-bda4b8c60b030727c49e291ca575cf6067c720d7.tar.xz
wireguard-tools-bda4b8c60b030727c49e291ca575cf6067c720d7.zip
wg: add wg show [interface] dump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/show.c')
-rw-r--r--src/show.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/show.c b/src/show.c
index 6cf2b23..7b057cf 100644
--- a/src/show.c
+++ b/src/show.c
@@ -203,7 +203,7 @@ static char *bytes(uint64_t b)
static const char *COMMAND_NAME = NULL;
static void show_usage(void)
{
- fprintf(stderr, "Usage: %s %s { <interface> | all | interfaces } [public-key | private-key | preshared-key | listen-port | fwmark | peers | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive]\n", PROG_NAME, COMMAND_NAME);
+ fprintf(stderr, "Usage: %s %s { <interface> | all | interfaces } [public-key | private-key | preshared-key | listen-port | fwmark | peers | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump]\n", PROG_NAME, COMMAND_NAME);
}
static void pretty_print(struct wgdevice *device)
@@ -252,6 +252,44 @@ static void pretty_print(struct wgdevice *device)
}
}
+static void dump_print(struct wgdevice *device, bool with_interface)
+{
+ size_t i, j;
+ struct wgpeer *peer;
+ struct wgipmask *ipmask;
+
+ if (with_interface)
+ printf("%s\t", device->interface);
+ printf("%s\t", key(device->private_key));
+ printf("%s\t", key(device->public_key));
+ printf("%s\t", key(device->preshared_key));
+ printf("%u\t", device->port);
+ if (device->fwmark)
+ printf("0x%x\n", device->fwmark);
+ else
+ printf("off\n");
+ for_each_wgpeer(device, peer, i) {
+ if (with_interface)
+ printf("%s\t", device->interface);
+ printf("%s\t", key(peer->public_key));
+ if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
+ printf("%s\t", endpoint(&peer->endpoint.addr));
+ else
+ printf("(none)\t");
+ if (peer->num_ipmasks) {
+ for_each_wgipmask(peer, ipmask, j)
+ printf("%s/%u%c", ip(ipmask), ipmask->cidr, j == (size_t)peer->num_ipmasks - 1 ? '\t' : ',');
+ } else
+ printf("(none)\t");
+ printf("%llu\t", (unsigned long long)peer->last_handshake_time.tv_sec);
+ printf("%" PRIu64 "\t%" PRIu64 "\t", (uint64_t)peer->rx_bytes, (uint64_t)peer->tx_bytes);
+ if (peer->persistent_keepalive_interval)
+ printf("%u\n", peer->persistent_keepalive_interval);
+ else
+ printf("off\n");
+ }
+}
+
static bool ugly_print(struct wgdevice *device, const char *param, bool with_interface)
{
size_t i, j;
@@ -328,7 +366,9 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
printf("%s\t", device->interface);
printf("%s\n", key(peer->public_key));
}
- } else {
+ } else if (!strcmp(param, "dump"))
+ dump_print(device, with_interface);
+ else {
fprintf(stderr, "Invalid parameter: `%s`\n", param);
show_usage();
return false;