Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/netinet/libalias/2_natout.c
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <alias.h> | #include <alias.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "util.h" | #include "util.h" | ||||
/* common ip ranges */ | |||||
static struct in_addr masq = { htonl(0x01020304) }; | |||||
static struct in_addr pub = { htonl(0x0102dead) }; | |||||
static struct in_addr prv1 = { htonl(0x0a00dead) }; | |||||
static struct in_addr prv2 = { htonl(0xac10dead) }; | |||||
static struct in_addr prv3 = { htonl(0xc0a8dead) }; | |||||
static struct in_addr cgn = { htonl(0x6440dead) }; | |||||
static struct in_addr ext = { htonl(0x12345678) }; | |||||
#define NAT_CHECK(pip, src, msq) do { \ | |||||
int res; \ | |||||
int len = ntohs(pip->ip_len); \ | |||||
struct in_addr dst = pip->ip_dst; \ | |||||
pip->ip_src = src; \ | |||||
res = LibAliasOut(la, pip, len); \ | |||||
ATF_CHECK_MSG(res == PKT_ALIAS_OK, \ | |||||
">%d< not met PKT_ALIAS_OK", res); \ | |||||
ATF_CHECK(addr_eq(msq, pip->ip_src)); \ | |||||
ATF_CHECK(addr_eq(dst, pip->ip_dst)); \ | |||||
} while(0) | |||||
#define NAT_FAIL(pip, src, dst) do { \ | |||||
int res; \ | |||||
int len = ntohs(pip->ip_len); \ | |||||
pip->ip_src = src; \ | |||||
pip->ip_dst = dst; \ | |||||
res = LibAliasOut(la, pip, len); \ | |||||
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)); \ | |||||
} while(0) | |||||
#define UNNAT_CHECK(pip, src, dst, rel) do { \ | |||||
int res; \ | |||||
int len = ntohs(pip->ip_len); \ | |||||
pip->ip_src = src; \ | |||||
pip->ip_dst = dst; \ | |||||
res = LibAliasIn(la, pip, len); \ | |||||
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(rel, pip->ip_dst)); \ | |||||
} while(0) | |||||
#define UNNAT_FAIL(pip, src, dst) do { \ | |||||
int res; \ | |||||
int len = ntohs(pip->ip_len); \ | |||||
pip->ip_src = src; \ | |||||
pip->ip_dst = dst; \ | |||||
res = LibAliasIn(la, pip, len); \ | |||||
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)); \ | |||||
} while(0) | |||||
ATF_TC_WITHOUT_HEAD(1_simplemasq); | ATF_TC_WITHOUT_HEAD(1_simplemasq); | ||||
ATF_TC_BODY(1_simplemasq, dummy) | ATF_TC_BODY(1_simplemasq, dummy) | ||||
{ | { | ||||
struct libalias *la = LibAliasInit(NULL); | struct libalias *la = LibAliasInit(NULL); | ||||
struct ip *pip; | struct ip *pip; | ||||
ATF_REQUIRE(la != NULL); | ATF_REQUIRE(la != NULL); | ||||
LibAliasSetAddress(la, masq); | LibAliasSetAddress(la, masq); | ||||
▲ Show 20 Lines • Show All 309 Lines • Show Last 20 Lines |