mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-18 02:19:39 +00:00
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 2c733b50c5
)
This commit is contained in:
parent
2de6637133
commit
e5c7bbe627
@ -305,6 +305,60 @@ ATF_TC_BODY(7_stress, dummy)
|
|||||||
LibAliasUninit(la);
|
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)
|
ATF_TP_ADD_TCS(natout)
|
||||||
{
|
{
|
||||||
/* Use "dd if=/dev/random bs=2 count=1 | od -x" to reproduce */
|
/* 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, 5_sameport);
|
||||||
ATF_TP_ADD_TC(natout, 6_cleartable);
|
ATF_TP_ADD_TC(natout, 6_cleartable);
|
||||||
ATF_TP_ADD_TC(natout, 7_stress);
|
ATF_TP_ADD_TC(natout, 7_stress);
|
||||||
|
ATF_TP_ADD_TC(natout, 8_portrange);
|
||||||
|
|
||||||
return atf_no_error();
|
return atf_no_error();
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ rand_range(int min, int max)
|
|||||||
pip->ip_src = src; \
|
pip->ip_src = src; \
|
||||||
pip->ip_dst = dst; \
|
pip->ip_dst = dst; \
|
||||||
res = LibAliasOut(la, pip, len); \
|
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); \
|
">%d< not met !PKT_ALIAS_OK", res); \
|
||||||
ATF_CHECK(addr_eq(src, pip->ip_src)); \
|
ATF_CHECK(addr_eq(src, pip->ip_src)); \
|
||||||
ATF_CHECK(addr_eq(dst, pip->ip_dst)); \
|
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 { \
|
#define UDP_NAT_FAIL(p, u, si, sp, di, dp) do { \
|
||||||
u = set_udp(p, (sp), (dp)); \
|
u = set_udp(p, (sp), (dp)); \
|
||||||
NAT_FAIL(p, (si), (mi)); \
|
NAT_FAIL(p, (si), (di)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define UDP_UNNAT_CHECK(p, u, si, sp, mi, mp, di, dp) \
|
#define UDP_UNNAT_CHECK(p, u, si, sp, mi, mp, di, dp) \
|
||||||
|
Loading…
Reference in New Issue
Block a user