From nobody Mon Jul 21 02:13:56 2025 X-Original-To: dev-commits-src-branches@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 4blkTw6sPZz61xrW; Mon, 21 Jul 2025 02:13:56 +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 4blkTw4Vfjz3Nf6; Mon, 21 Jul 2025 02:13:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753064036; 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=MxmpwUPmAXaCIzjChleCuxUsABb4WqoxXZehr5MNMU4=; b=sCOT6TrNgZPPcgMkKC7Ct5isolQTrbV6MtIPsEXlZh75MYzFxrkyvy0QKS2Iy04YqTXbHi rns+aePcVI6oVM6DrzOOzT5ZrndgbKyh1oba3NsMa6ssa/VQoax0Q+gHJKqgJDypGdOYUu bwJbY7LLqSZoCXUHdaPWG+P6YNokKf3cEoJ1Ei151Y925LqtUzm5QKSbnP30sraAdNZF/8 SXCh1eAg5GQCCND5SY1EDK1SZN7eK04wxyxHQfw2D0+KhYi0j/BhALTIkrmodt8wHfdsOb 0U7RxVpGAwJuVEilFWDddwCatiBkMUCeo6sf92s3oqAUgjlNkQQDcbx27iBBVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753064036; 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=MxmpwUPmAXaCIzjChleCuxUsABb4WqoxXZehr5MNMU4=; b=sLU8kj3mCy1ZVLZp8N27F4wmxyCj8hnLDzieyFglxV+oY8QC343ichPgWuFpBxbsLbwww+ sG01t0jcTSiyO5DWExgxJUJkdjcCObBtI7O6GrnGM8hmsGvfMnfJC8r/GJN1ANiQ7NfYc/ 7q/sD+ZcibBXffSHO8h7fKHoNO0WH+y7BFlV3GaZacYIFppwPJrPwAhz2UAvq53QRlOS2K owZdOVV4UJM2KDfx9u/COGLAuOzOEnzRWlP/uB6m0IK81r7g8G5EejmWgBO8frQKBbZQHb uP3P3HBgr0ETPDz+3uhwZJnAIMEBudue37uJsHTsprYQ2KKwvacUzqQ9LxOQ4A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753064036; a=rsa-sha256; cv=none; b=ByY9Lqz+yDcYjl+xENRwTHL4XuhlCIyiT2vSCInZv95lAhb9+tEjBrAMNE9b/1AF3FZh/3 zKPQVIDD8C24Z2bGpgxByeU90Jd+AnpHQcMc1030p9q5NLRlkNuPb1KwP5t3pLHymbLw/H s6tkxKUGugMSsgvL4FR+k2BVNKM5w51PkiDYEkatI59+XNEmoZgvpJjnIRftL/zheyV2xd Jow/u1IH0k3TFiwyq5wm8U0N7INZELIqEARBrPr/rmeo5yqg0FquqEVwDwXaqjDlyUGtJI 1n73hhgY4ZynAFcqZuvp5Xtzg3h/9k6xlESvnux8t6Q/5ZGkAABNE9wkS91O1Q== 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 4blkTw44j2zfDS; Mon, 21 Jul 2025 02:13:56 +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 56L2Dui1013873; Mon, 21 Jul 2025 02:13:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56L2Du3n013870; Mon, 21 Jul 2025 02:13:56 GMT (envelope-from git) Date: Mon, 21 Jul 2025 02:13:56 GMT Message-Id: <202507210213.56L2Du3n013870@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 1cacf672e3ee - stable/14 - kern: wg: refactor out some repetitive bits in allowed-ip config List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 1cacf672e3ee3719b72534347cf7d5ce69cf716f Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=1cacf672e3ee3719b72534347cf7d5ce69cf716f commit 1cacf672e3ee3719b72534347cf7d5ce69cf716f Author: Kyle Evans AuthorDate: 2025-06-26 02:57:02 +0000 Commit: Kyle Evans CommitDate: 2025-07-21 02:12:28 +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 (cherry picked from commit ba2607ae7dff17957d9e62ccd567ba716c168e77) --- 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 2534929a1e37..9e86e1074ef5 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -2459,8 +2459,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); @@ -2468,19 +2472,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)