From nobody Thu Jun 26 02:59:07 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bSNgb49Gwz5yvV8; Thu, 26 Jun 2025 02:59:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bSNgb2vYFz3Lmr; Thu, 26 Jun 2025 02:59:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750906747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ye652pCu52ejSdc1m1GL7PL89bMdQS1TX5swmIol6g0=; b=Cu1zgS93R4TqzQSWGnOL8xq0BuIXL3S8UpvhDm7JUjvSIdo2DXddRARv0AgtL4JmVBGPF3 pS5oSYu8NCAYi/95FhbKFY5t5Q9f+e9ceo10oqBuIVQkBA5i4MS3OGhtrBC/rmWNcwO2xs FLvcBGfaXlNC5j2UMe5Ew1ETKX0gdIkRDDGMa1aX5U8DCCBMzDuPvZQgqG6tKruDtOZYbR mBYNdc+sakB05ZuX07ko/P72oujOxgkFgVkYPcKY1yFq44aVrNeCZ6yTzVJcFk9E4XsceL xzoeRRasAffYMx3HIb4NmcI928PGBqA/rYyfNA5d3266beB+M+316xLRyMyWkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750906747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ye652pCu52ejSdc1m1GL7PL89bMdQS1TX5swmIol6g0=; b=Wn12XDKSQSphD6vWrNC1Jf0jFIBGs8T0BcKLgGcyfAYYbb73PkD968k7K+cCYy/Gto3LtI Z8BcvfV7d8ymNzxotDP1ZtEl+HHBpV8s8LrTJGEKpdOqHaGoOtnp9wN9gScYHjHDTQTnBx hxPjaGRMuU8QwPE4Snqu9KvOwYDfnfDOBOB0YTCFn3uUpioX9GzB+96BNBxe786QouWz8n e9UTeMSp/fJbHUnOCF+0H//48i087LQxzDaxSZ8kihrGDzPaLwkeV+yjO591FW4MD6r7QC z9t26oeFB7+Oc3y71PCdCAx9vFofAI9v3qYiQYMG7agqpEnSn3YgNWk794wAVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750906747; a=rsa-sha256; cv=none; b=K+nP89sftGNiKuFxzN3ffKOcHQ9YekpgWAFcy5nZU+MnH4PqqXKlWZ6H4s4aeQEq7iqQ6+ 7JqbrlnSB+JhXLq2k4BHsnXG/A+FYEG8/JF8t/lOE0FU92IlGMGmsXmwhfucytD+/sMVj7 /sf9pzvr2jY8Wx5Sig4GdAOxufBzKl5zZ4tjFBU3TI3k06LwcjAnvtun1f5pihQlWV96bq 2zubQJV20EnGaaCFKk/jPMQkWDrvMgHcm+upinz1gu7ZxPjg4CAIl9gbwvxudLk2sD2/Vr TeUDJKNoxLdANgW9t5YOUzycONUp8XceSbC5QerN7VeBByOAjArdcmWeJUlTVQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bSNgb1z4bzl08; Thu, 26 Jun 2025 02:59:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55Q2x7S5052921; Thu, 26 Jun 2025 02:59:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55Q2x7Rd052916; Thu, 26 Jun 2025 02:59:07 GMT (envelope-from git) Date: Thu, 26 Jun 2025 02:59:07 GMT Message-Id: <202506260259.55Q2x7Rd052916@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: ba2607ae7dff - main - kern: wg: refactor out some repetitive bits in allowed-ip config List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ba2607ae7dff17957d9e62ccd567ba716c168e77 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=ba2607ae7dff17957d9e62ccd567ba716c168e77 commit ba2607ae7dff17957d9e62ccd567ba716c168e77 Author: Kyle Evans AuthorDate: 2025-06-26 02:57:02 +0000 Commit: Kyle Evans CommitDate: 2025-06-26 02:57:02 +0000 kern: wg: refactor out some repetitive bits in allowed-ip config The only difference in the wg_aip_add() call after IP validation is the address family. Just pull that out into a variable and avoid the two different callsites for wg_aip_add(). A future change will add a new call for each case to remove an address from the peer, so it's nice to avoid needing to repeat the logic for two different branches. Reviewed by: Aaron LI, Jason A. Donenfeld, ivy, jhb, markj Differential Revision: https://reviews.freebsd.org/D50446 --- sys/dev/wg/if_wg.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c index 5a3b60e45b7a..ce12d623be6f 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -2461,8 +2461,12 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl) aipl = nvlist_get_nvlist_array(nvl, "allowed-ips", &allowedip_count); for (size_t idx = 0; idx < allowedip_count; idx++) { + sa_family_t ipaf; + if (!nvlist_exists_number(aipl[idx], "cidr")) continue; + + ipaf = AF_UNSPEC; cidr = nvlist_get_number(aipl[idx], "cidr"); if (nvlist_exists_binary(aipl[idx], "ipv4")) { addr = nvlist_get_binary(aipl[idx], "ipv4", &size); @@ -2470,19 +2474,23 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl) err = EINVAL; goto out; } - if ((err = wg_aip_add(sc, peer, AF_INET, addr, cidr)) != 0) - goto out; + + ipaf = AF_INET; } else if (nvlist_exists_binary(aipl[idx], "ipv6")) { addr = nvlist_get_binary(aipl[idx], "ipv6", &size); if (addr == NULL || cidr > 128 || size != sizeof(struct in6_addr)) { err = EINVAL; goto out; } - if ((err = wg_aip_add(sc, peer, AF_INET6, addr, cidr)) != 0) - goto out; + + ipaf = AF_INET6; } else { continue; } + + MPASS(ipaf != AF_UNSPEC); + if ((err = wg_aip_add(sc, peer, ipaf, addr, cidr)) != 0) + goto out; } } if (remote != NULL)