From nobody Mon Jan 3 12:56:14 2022 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 DAB96191F794; Mon, 3 Jan 2022 12:56:17 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JSG2k75fVz3Lrj; Mon, 3 Jan 2022 12:56:14 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B4C4A25C0D; Mon, 3 Jan 2022 12:56:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 203CuENw084604; Mon, 3 Jan 2022 12:56:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 203CuE3E084603; Mon, 3 Jan 2022 12:56:14 GMT (envelope-from git) Date: Mon, 3 Jan 2022 12:56:14 GMT Message-Id: <202201031256.203CuE3E084603@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Lutz Donnerhacke Subject: git: 8925a302a31a - stable/12 - tests/libalias: Portrange 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 8925a302a31a5510d57b017cf8583b719f2ea623 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641214575; 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=Cu7BIVvMLAjBmai/Aq7eYJztUw0QWqC0aBqO43Go+3Q=; b=Ov0MpRBj+Bai6XQFaGEc3eR+zfD3BxrhvLDhFr2MS3mAUACLCnKFiTTaaPWlhSFKCAvHp/ NAwJymRmb/PVERI1WjpSzVBkxNl9Vh9gCX2Yewcdsu5zw7LGFEI7D2N+nZ6Oep8/eIP+hq w02Acb5KOXs9cy16MPP5q6Apg46lVpYPSxUkJgBm250J42q2Er+eDeYIv2ngDLC46EoeMQ LqwvobPYurpk8m6RufQ36OjIWa8GRKG9Zf8Iw87TG5M7hj56SwzM7YC+ZeZduvFhAJX8Kl SlbR5tvM4FNNet3rMn/sIiwF2gJSGFThE8byIQR+rY8A0y1qVPI9LwXk3y/f9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641214575; a=rsa-sha256; cv=none; b=BXjnZtyRiirsG8a365MjaIBHXf5sJjNmPtS2JXWVXka9Hl71gHC/xI4rOFYdMl6Ew9UQVh VlcJftH1sFbIXRPrb6rfrkDh17wKviruDOd9tGpAw0Cii06ajbejs6d4zoCToPBRMc8TlB fTXFAEM0OxmfPlfU5mfjbxCBzikZzE9vb7xc9NYOTJmdSxvQHU7Y5cC0XTEnJU6Jx/t7yP XcwlAlQC20d5/aOwL/mBnbuyGEi0Dh575nZwdVkSgr+eeET0i2MzJs1/2p1H+3rk0N/6HF 22Zj/K3My1cWKV7GpsEG4CA4XASHvKYp1V0R49e1CicaMBk4hn758FgMt7r/rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=8925a302a31a5510d57b017cf8583b719f2ea623 commit 8925a302a31a5510d57b017cf8583b719f2ea623 Author: Lutz Donnerhacke AuthorDate: 2021-07-03 22:28:20 +0000 Commit: Lutz Donnerhacke CommitDate: 2022-01-03 11:50:10 +0000 tests/libalias: Portrange Test ranges of allowed ports for aliasing. - Explicit default like ipfw(8) is doing - Regular range - Exhausting a very small range - Recovery Includes a fix of an utility macro, which was not used before. Differential Revision: https://reviews.freebsd.org/D31012 (cherry picked from commit 2c733b50c5a99cbe4f6eef437e1e3efd720ba306) --- tests/sys/netinet/libalias/2_natout.c | 55 +++++++++++++++++++++++++++++++++++ tests/sys/netinet/libalias/util.h | 4 +-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/sys/netinet/libalias/2_natout.c b/tests/sys/netinet/libalias/2_natout.c index 2b6da8f597ed..4dfffdc055e2 100644 --- a/tests/sys/netinet/libalias/2_natout.c +++ b/tests/sys/netinet/libalias/2_natout.c @@ -305,6 +305,60 @@ ATF_TC_BODY(7_stress, dummy) LibAliasUninit(la); } +ATF_TC_WITHOUT_HEAD(8_portrange); +ATF_TC_BODY(8_portrange, dummy) +{ + struct libalias *la = LibAliasInit(NULL); + struct ip *po; + struct udphdr *uo; + uint16_t sport = 0x1234; + uint16_t dport = 0x5678; + uint16_t aport; + + ATF_REQUIRE(la != NULL); + LibAliasSetAddress(la, masq); + LibAliasSetMode(la, 0, ~0); + po = ip_packet(0, 64); + + LibAliasSetAliasPortRange(la, 0, 0); /* reinit like ipfw */ + UDP_NAT_CHECK(po, uo, prv1, sport, ext, dport, masq); + aport = ntohs(uo->uh_sport); + ATF_CHECK(aport >= 0x8000); + + /* Different larger range */ + LibAliasSetAliasPortRange(la, 2000, 3000); + dport++; + UDP_NAT_CHECK(po, uo, prv1, sport, ext, dport, masq); + aport = ntohs(uo->uh_sport); + ATF_CHECK(aport >= 2000 && aport < 3000); + + /* Different small range (contains two ports) */ + LibAliasSetAliasPortRange(la, 4000, 4001); + dport++; + UDP_NAT_CHECK(po, uo, prv1, sport, ext, dport, masq); + aport = ntohs(uo->uh_sport); + ATF_CHECK(aport >= 4000 && aport <= 4001); + + sport++; + UDP_NAT_CHECK(po, uo, prv1, sport, ext, dport, masq); + aport = ntohs(uo->uh_sport); + ATF_CHECK(aport >= 4000 && aport <= 4001); + + /* Third port not available in the range */ + sport++; + UDP_NAT_FAIL(po, uo, prv1, sport, ext, dport); + + /* Back to normal */ + LibAliasSetAliasPortRange(la, 0, 0); + dport++; + UDP_NAT_CHECK(po, uo, prv1, sport, ext, dport, masq); + aport = ntohs(uo->uh_sport); + ATF_CHECK(aport >= 0x8000); + + free(po); + LibAliasUninit(la); +} + ATF_TP_ADD_TCS(natout) { /* Use "dd if=/dev/random bs=2 count=1 | od -x" to reproduce */ @@ -317,6 +371,7 @@ ATF_TP_ADD_TCS(natout) ATF_TP_ADD_TC(natout, 5_sameport); ATF_TP_ADD_TC(natout, 6_cleartable); ATF_TP_ADD_TC(natout, 7_stress); + ATF_TP_ADD_TC(natout, 8_portrange); return atf_no_error(); } diff --git a/tests/sys/netinet/libalias/util.h b/tests/sys/netinet/libalias/util.h index fcec225af658..786e48e41f37 100644 --- a/tests/sys/netinet/libalias/util.h +++ b/tests/sys/netinet/libalias/util.h @@ -80,7 +80,7 @@ rand_range(int min, int max) pip->ip_src = src; \ pip->ip_dst = dst; \ res = LibAliasOut(la, pip, len); \ - ATF_CHECK_MSG(res != PKT_ALIAS_OK), \ + ATF_CHECK_MSG(res != PKT_ALIAS_OK, \ ">%d< not met !PKT_ALIAS_OK", res); \ ATF_CHECK(addr_eq(src, pip->ip_src)); \ ATF_CHECK(addr_eq(dst, pip->ip_dst)); \ @@ -118,7 +118,7 @@ rand_range(int min, int max) #define UDP_NAT_FAIL(p, u, si, sp, di, dp) do { \ u = set_udp(p, (sp), (dp)); \ - NAT_FAIL(p, (si), (mi)); \ + NAT_FAIL(p, (si), (di)); \ } while(0) #define UDP_UNNAT_CHECK(p, u, si, sp, mi, mp, di, dp) \