Page MenuHomeFreeBSD

D30335.id89415.diff
No OneTemporary

D30335.id89415.diff

Index: tests/sys/netinet/libalias/2_natout.c
===================================================================
--- /dev/null
+++ tests/sys/netinet/libalias/2_natout.c
@@ -0,0 +1,79 @@
+#include <atf-c.h>
+#include <alias.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <netinet/ip.h>
+
+static struct ip *
+ip_packet(struct in_addr src, struct in_addr dst, u_char protocol, size_t len) {
+ struct ip * p;
+
+ ATF_REQUIRE(len >= 64 && len <= IP_MAXPACKET);
+
+ p = malloc(len);
+ ATF_REQUIRE(p != NULL);
+
+ p->ip_v = IPVERSION;
+ p->ip_hl = sizeof(*p)/4;
+ p->ip_len = htons(len);
+ p->ip_ttl = IPDEFTTL;
+ p->ip_src = src;
+ p->ip_dst = dst;
+ p->ip_p = protocol;
+ ATF_REQUIRE(p->ip_hl == 5);
+
+ return (p);
+}
+
+static inline bool
+addr_eq(struct in_addr a, struct in_addr b) {
+ return a.s_addr == b.s_addr;
+}
+
+static inline uint32_t
+a2h(struct in_addr a) {
+ return ntohl(a.s_addr);
+}
+
+ATF_TC_WITHOUT_HEAD(1_simplemasq);
+ATF_TC_BODY(1_simplemasq, dummy)
+{
+ struct libalias *la = LibAliasInit(NULL);
+ struct in_addr masq = { htonl(0x01020304) };
+ struct in_addr src = { htonl(0x0a010203) };
+ struct in_addr dst = { htonl(0x12345678) };
+ struct ip * pkt;
+ int res;
+
+ ATF_REQUIRE(la != NULL);
+ LibAliasSetAddress(la, masq);
+
+ pkt = ip_packet(src, dst, 254, 64);
+ res = LibAliasOut(la, pkt, 64);
+
+ ATF_CHECK_MSG(res == PKT_ALIAS_OK,
+ "Aliasing returned %d instead of %d.",
+ res, PKT_ALIAS_OK);
+ ATF_CHECK_MSG(addr_eq(masq, pkt->ip_src),
+ "Packet from %04x to %04x not aliased to %04x",
+ a2h(pkt->ip_src), a2h(pkt->ip_dst), a2h(masq));
+ ATF_CHECK_MSG(addr_eq(dst, pkt->ip_dst),
+ "Packet from %04x to %04x not going to %04x",
+ a2h(pkt->ip_src), a2h(pkt->ip_dst), a2h(dst));
+
+ /* Cleanup */
+ free(pkt);
+ LibAliasUninit(la);
+}
+
+ATF_TP_ADD_TCS(natout)
+{
+ /* Use "dd if=/dev/random bs=2 count=1 | od -x" to reproduce */
+ srand(0x0b61);
+
+ ATF_TP_ADD_TC(natout, 1_simplemasq);
+
+ return atf_no_error();
+}
Index: tests/sys/netinet/libalias/Makefile
===================================================================
--- tests/sys/netinet/libalias/Makefile
+++ tests/sys/netinet/libalias/Makefile
@@ -7,7 +7,8 @@
TESTSDIR= ${TESTSBASE}/sys/netinet/libalias
BINDIR= ${TESTSDIR}
-ATF_TESTS_C+= 1_instance
+ATF_TESTS_C+= 1_instance \
+ 2_natout \
LIBADD+= alias

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 16, 1:00 PM (17 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31605032
Default Alt Text
D30335.id89415.diff (2 KB)

Event Timeline