aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2021-03-08 01:00:58 +0000
committerKyle Evans <kevans@FreeBSD.org>2021-03-09 11:16:42 +0000
commitb3dac3913dc90fbc6f909ee5c4a876097cd90791 (patch)
tree4a70da8e2cc5633fc091ce8aaa393757c2cc6e43 /sbin/ifconfig
parent172a8241c9c9a7273a78ad73a32501d3a01afd28 (diff)
downloadsrc-b3dac3913dc90fbc6f909ee5c4a876097cd90791.tar.gz
src-b3dac3913dc90fbc6f909ee5c4a876097cd90791.zip
ifconfig: allow displaying/setting persistent-keepalive
The kernel-side already accepted a persistent-keepalive-interval, so just add a verb to ifconfig(8) for it and start exporting it so that ifconfig(8) can view it. PR: 253790 MFC after: 3 days Discussed with: decke
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifwg.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sbin/ifconfig/ifwg.c b/sbin/ifconfig/ifwg.c
index 105ee7ac31d1..86bacc59f50d 100644
--- a/sbin/ifconfig/ifwg.c
+++ b/sbin/ifconfig/ifwg.c
@@ -280,6 +280,7 @@ dump_peer(const nvlist_t *nvl_peer)
char addr_buf[INET6_ADDRSTRLEN];
size_t size;
int count, port;
+ uint16_t persistent_keepalive;
printf("[Peer]\n");
if (nvlist_exists_binary(nvl_peer, "public-key")) {
@@ -292,7 +293,11 @@ dump_peer(const nvlist_t *nvl_peer)
sa_ntop(endpoint, addr_buf, &port);
printf("Endpoint = %s:%d\n", addr_buf, ntohs(port));
}
-
+ if (nvlist_exists_number(nvl_peer, "persistent-keepalive-interval")) {
+ persistent_keepalive = nvlist_get_number(nvl_peer,
+ "persistent-keepalive-interval");
+ printf("PersistentKeepalive = %d\n", persistent_keepalive);
+ }
if (!nvlist_exists_binary(nvl_peer, "allowed-ips"))
return;
aips = nvlist_get_binary(nvl_peer, "allowed-ips", &size);
@@ -476,6 +481,26 @@ DECL_CMD_FUNC(setwgpubkey, val, d)
}
static
+DECL_CMD_FUNC(setwgpersistentkeepalive, val, d)
+{
+ unsigned long persistent_keepalive;
+ char *endp;
+
+ if (!do_peer)
+ errx(1, "setting persistent keepalive only valid when adding peer");
+
+ errno = 0;
+ persistent_keepalive = strtoul(val, &endp, 0);
+ if (errno != 0 || *endp != '\0')
+ errx(1, "persistent-keepalive must be numeric (seconds)");
+ if (persistent_keepalive > USHRT_MAX)
+ errx(1, "persistent-keepalive '%lu' too large",
+ persistent_keepalive);
+ nvlist_add_number(nvl_params, "persistent-keepalive-interval",
+ persistent_keepalive);
+}
+
+static
DECL_CMD_FUNC(setallowedips, val, d)
{
char *base, *allowedip, *mask;
@@ -563,6 +588,7 @@ static struct cmd wireguard_cmds[] = {
DEF_CMD("peer-list", 0, peerlist),
DEF_CMD("peer", 0, peerstart),
DEF_CMD_ARG("public-key", setwgpubkey),
+ DEF_CMD_ARG("persistent-keepalive", setwgpersistentkeepalive),
DEF_CMD_ARG("allowed-ips", setallowedips),
DEF_CMD_ARG("endpoint", setendpoint),
};