From nobody Mon Jan 03 11:19:54 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 471941935F7D; Mon, 3 Jan 2022 11:19:55 +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 4JSCvZ6XTFz4vGK; Mon, 3 Jan 2022 11:19:54 +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 C0BD324572; Mon, 3 Jan 2022 11:19:54 +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 203BJsR5053118; Mon, 3 Jan 2022 11:19:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 203BJscu053117; Mon, 3 Jan 2022 11:19:54 GMT (envelope-from git) Date: Mon, 3 Jan 2022 11:19:54 GMT Message-Id: <202201031119.203BJscu053117@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: e5c7bbe627e6 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: e5c7bbe627e615e569d47015f16308c2ab9065bd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641208794; 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=3NEmwH34DHvXReq5xWWxATrtD2krD65BBw6ywT5kuQY=; b=Lzemh76Jz/8o7CLaHXt5YqL+unavBR7tgDS/Kl3hCRnzzu339xLHLZuq260wqQVH3tw6Bk prRs4RkdOXcOhu9R2B/FvfQRI8S9rxCAZgqqfjaJcaysGwKJjmsIxii5ItrOF1nx5CQmUT Y/b6DaxA6DAWQPwniZpdRRY560tA46/mAwMgJ5f46vJYsm9qSfy1F5pnyJV7oks0H5r3fT DLs1A3fsOrk1Sjhj2d66KTuazqKWgASkaXHVh7M0nGU7RNXUBpcIcYCMhyPOgrWar35mta nVWpDmmMW4th8n7CaK+DPWx+HtrFR9VTvQTczcbOEexIiSk+XR8O+HMfxdR9HQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641208794; a=rsa-sha256; cv=none; b=oXBRJ8eXqHP3PpXmEIJL5nK3HIl8O+uFALVIh32RAHzXymrlW3jFzZAHMjpqi06T9/nwHj FdzTTsepaPj+r1rG0U57CGeZBxJt1M/mtAdvclbTFNQXnbaA8A1VfDrZrCh8/wfn0YAYSl qTIRWMGzoKaNHPJJMZddh959W7ub4jztowuxWLKgxqopSSU/usifhMa80ud1iUFQppdFX3 g7cVyqCmtoFDXI3ez/cm0eQAdXoOrQMQwFixOdI7L63Q4/P3mvK4b14VvMusVTGvIZIP0Z swPXjn/AQMwVRVLCJpOkVtVvzFnRm0QIoGN/PLDg0S8G3NaZqqyWPexPMatE6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=e5c7bbe627e615e569d47015f16308c2ab9065bd commit e5c7bbe627e615e569d47015f16308c2ab9065bd Author: Lutz Donnerhacke AuthorDate: 2021-07-03 22:28:20 +0000 Commit: Lutz Donnerhacke CommitDate: 2022-01-03 11:18: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) \