diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2023-06-01 18:57:55 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2023-06-01 18:57:55 +0000 |
commit | 1ae9f3a754fc9e165ecd1b48c9cb1df223d1d95a (patch) | |
tree | e70c1614ee39344640eeb2eb6b483c09fda55b56 /sys/net/if_wg.c | |
parent | 83c401a3d5f28243e7a8208f366626a8ba563924 (diff) |
Add support for wireguard peer descriptions
"wgdescr[iption] foo" to label one peer (amongst many) on a wg(4) interface,
"-wgdescr[iption]" or "wgdescr ''" to remove the label, completely analogous
to existing interface discriptions.
Idea/initial diff from Mikolaj Kucharski (OK sthen)
Tests/prodded by Hrvoje Popovski
Tweaks/manual bits from me
Feedback deraadt sthen mvs claudio
OK claudio
Diffstat (limited to 'sys/net/if_wg.c')
-rw-r--r-- | sys/net/if_wg.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c index 36b9ad8ca32..951cb6f1df0 100644 --- a/sys/net/if_wg.c +++ b/sys/net/if_wg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wg.c,v 1.27 2023/05/30 08:30:01 jsg Exp $ */ +/* $OpenBSD: if_wg.c,v 1.28 2023/06/01 18:57:53 kn Exp $ */ /* * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. @@ -221,6 +221,8 @@ struct wg_peer { SLIST_ENTRY(wg_peer) p_start_list; int p_start_onlist; + + char p_description[IFDESCRSIZE]; }; struct wg_softc { @@ -407,6 +409,8 @@ wg_peer_create(struct wg_softc *sc, uint8_t public[WG_KEY_SIZE]) peer->p_counters_tx = 0; peer->p_counters_rx = 0; + strlcpy(peer->p_description, "", IFDESCRSIZE); + mtx_init(&peer->p_endpoint_mtx, IPL_NET); bzero(&peer->p_endpoint, sizeof(peer->p_endpoint)); @@ -2320,6 +2324,10 @@ wg_ioctl_set(struct wg_softc *sc, struct wg_data_io *data) } } + if (peer_o.p_flags & WG_PEER_SET_DESCRIPTION) + strlcpy(peer->p_description, peer_o.p_description, + IFDESCRSIZE); + aip_p = &peer_p->p_aips[0]; for (j = 0; j < peer_o.p_aips_count; j++) { if ((ret = copyin(aip_p, &aip_o, sizeof(aip_o))) != 0) @@ -2430,6 +2438,8 @@ wg_ioctl_get(struct wg_softc *sc, struct wg_data_io *data) } peer_o.p_aips_count = aip_count; + strlcpy(peer_o.p_description, peer->p_description, IFDESCRSIZE); + if ((ret = copyout(&peer_o, peer_p, sizeof(peer_o))) != 0) goto unlock_and_ret_size; |