diff options
author | 2020-11-06 21:24:47 +0000 | |
---|---|---|
committer | 2020-11-06 21:24:47 +0000 | |
commit | 3da3dc9d473ac516bbbff0384cb00f9170254ca5 (patch) | |
tree | 3235a3382f2214b6b9d67285580e13f3420e10e2 | |
parent | Add some debug output showing the exact network configuration (diff) | |
download | wireguard-openbsd-3da3dc9d473ac516bbbff0384cb00f9170254ca5.tar.xz wireguard-openbsd-3da3dc9d473ac516bbbff0384cb00f9170254ca5.zip |
Keep track of allowed ips pointer correctly
Someone reported wg(4) not working on macppc; fix ifconfig(8)'s "wgaip" to
interate over data structures in the same way as the kernel does.
Analysis and fiff from Jason A. Donenfeld
Tested on macppc, sparc64 and amd64 by me
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 2ccbac6f4ce..3799cc3a8e9 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.429 2020/10/07 14:38:54 denis Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.430 2020/11/06 21:24:47 kn Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -5696,11 +5696,10 @@ ensurewginterface(void) err(1, "calloc"); } -void * +void growwgdata(size_t by) { ptrdiff_t peer_offset, aip_offset; - void *ret; if (wg_interface == NULL) wgdata.wgd_size = sizeof(*wg_interface); @@ -5721,16 +5720,18 @@ growwgdata(size_t by) if (wg_aip != NULL) wg_aip = (void *)wg_interface + aip_offset; - ret = (void *)wg_interface + wgdata.wgd_size - by; - bzero(ret, by); - - return ret; + bzero((char *)wg_interface + wgdata.wgd_size - by, by); } void setwgpeer(const char *peerkey_b64, int param) { - wg_peer = growwgdata(sizeof(*wg_peer)); + growwgdata(sizeof(*wg_peer)); + if (wg_aip) + wg_peer = (struct wg_peer_io *)wg_aip; + else + wg_peer = &wg_interface->i_peers[0]; + wg_aip = &wg_peer->p_aips[0]; wg_peer->p_flags |= WG_PEER_HAS_PUBLIC; WG_LOAD_KEY(wg_peer->p_public, peerkey_b64, "wgpeer"); wg_interface->i_peers_count++; @@ -5743,7 +5744,7 @@ setwgpeeraip(const char *aip, int param) if (wg_peer == NULL) errx(1, "wgaip: wgpeer not set"); - wg_aip = growwgdata(sizeof(*wg_aip)); + growwgdata(sizeof(*wg_aip)); if ((res = inet_net_pton(AF_INET, aip, &wg_aip->a_ipv4, sizeof(wg_aip->a_ipv4))) != -1) { @@ -5759,6 +5760,8 @@ setwgpeeraip(const char *aip, int param) wg_peer->p_flags |= WG_PEER_REPLACE_AIPS; wg_peer->p_aips_count++; + + wg_aip++; } void |