aboutsummaryrefslogtreecommitdiff
path: root/tests/sys/netinet
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sys/netinet')
-rwxr-xr-xtests/sys/netinet/arp.sh8
-rw-r--r--tests/sys/netinet/broadcast.c6
-rw-r--r--tests/sys/netinet/fibs_test.sh3
-rw-r--r--tests/sys/netinet/igmp.py50
-rw-r--r--tests/sys/netinet/ip_reass_test.c12
-rw-r--r--tests/sys/netinet/so_reuseport_lb_test.c10
-rw-r--r--tests/sys/netinet/socket_afinet.c3
-rw-r--r--tests/sys/netinet/tcp_implied_connect.c1
-rw-r--r--tests/sys/netinet/udp_io.c1
9 files changed, 84 insertions, 10 deletions
diff --git a/tests/sys/netinet/arp.sh b/tests/sys/netinet/arp.sh
index c7744d5de938..df5dbc50ffa1 100755
--- a/tests/sys/netinet/arp.sh
+++ b/tests/sys/netinet/arp.sh
@@ -188,7 +188,9 @@ static_body() {
ipa=198.51.100.1
ipb=198.51.100.2
+ ipb_re=$(echo ${ipb} | sed 's/\./\\./g')
max_age=$(sysctl -n net.link.ether.inet.max_age)
+ max_age="(${max_age}|$((${max_age} - 1)))"
atf_check ifconfig -j ${jname}a ${epair0}a inet ${ipa}/24
eth="$(ifconfig -j ${jname}b ${epair0}b |
@@ -197,8 +199,8 @@ static_body() {
# Expected outputs
permanent=\
"? (${ipb}) at 00:00:00:00:00:00 on ${epair0}a permanent [ethernet]\n"
- temporary=\
-"? (${ipb}) at ${eth} on ${epair0}a expires in ${max_age} seconds [ethernet]\n"
+ temporary_re=\
+"\? \(${ipb_re}\) at ${eth} on ${epair0}a expires in ${max_age} seconds \[ethernet\]"
deleted=\
"${ipb} (${ipb}) deleted\n"
@@ -217,7 +219,7 @@ static_body() {
# then check -S
atf_check -o "inline:${deleted}" jexec ${jname}a arp -nd ${ipb}
atf_check -o ignore jexec ${jname}b ping -c1 ${ipa}
- atf_check -o "inline:${temporary}" jexec ${jname}a arp -n ${ipb}
+ atf_check -o "match:${temporary_re}" jexec ${jname}a arp -n ${ipb}
# Note: this doesn't fail, tracked all the way down to FreeBSD 8
# atf_check -s not-exit:0 jexec ${jname}a arp -s ${ipb} 0:0:0:0:0:0
atf_check -o "inline:${deleted}" \
diff --git a/tests/sys/netinet/broadcast.c b/tests/sys/netinet/broadcast.c
index 32e6643a3d75..e7850d513663 100644
--- a/tests/sys/netinet/broadcast.c
+++ b/tests/sys/netinet/broadcast.c
@@ -90,7 +90,11 @@ firstbcast(struct in_addr *out)
}
/* Application sends to INADDR_BROADCAST, and this goes on the wire. */
-ATF_TC_WITHOUT_HEAD(INADDR_BROADCAST);
+ATF_TC(INADDR_BROADCAST);
+ATF_TC_HEAD(INADDR_BROADCAST, tc)
+{
+ atf_tc_set_md_var(tc, "require.config", "allow_network_access");
+}
ATF_TC_BODY(INADDR_BROADCAST, tc)
{
struct sockaddr_in sin = {
diff --git a/tests/sys/netinet/fibs_test.sh b/tests/sys/netinet/fibs_test.sh
index 5fe8f7d87641..2d0b63f8e30a 100644
--- a/tests/sys/netinet/fibs_test.sh
+++ b/tests/sys/netinet/fibs_test.sh
@@ -320,6 +320,9 @@ same_ip_multiple_ifaces_fib0_body()
# Setup the interfaces, then remove one alias. It should not panic.
setup_tap 0 inet ${ADDR} ${MASK0}
TAP0=${TAP}
+ # After commit 361a8395f0b0e6f254fd138798232529679d99f6 it became
+ # an error to assign the same interface address twice.
+ atf_expect_fail "The test results in an ifconfig error and thus spuriously fails"
setup_tap 0 inet ${ADDR} ${MASK1}
TAP1=${TAP}
ifconfig ${TAP1} -alias ${ADDR}
diff --git a/tests/sys/netinet/igmp.py b/tests/sys/netinet/igmp.py
index 5d3b38cac38f..feb9b8b571d5 100644
--- a/tests/sys/netinet/igmp.py
+++ b/tests/sys/netinet/igmp.py
@@ -62,6 +62,25 @@ def check_igmpv3(args, pkt):
return True
+def check_igmpv2(args, pkt):
+ pkt.show()
+
+ igmp = pkt.getlayer(sc.igmp.IGMP)
+ if igmp is None:
+ return False
+
+ if igmp.gaddr != args["group"]:
+ return False
+
+ if args["type"] == "join":
+ if igmp.type != 0x16:
+ return False
+ if args["type"] == "leave":
+ if igmp.type != 0x17:
+ return False
+
+ return True
+
class TestIGMP(VnetTestTemplate):
REQUIRED_MODULES = []
TOPOLOGY = {
@@ -82,7 +101,7 @@ class TestIGMP(VnetTestTemplate):
@pytest.mark.require_progs(["scapy"])
def test_igmp3_join_leave(self):
- "Test that we send the expected join/leave IGMPv2 messages"
+ "Test that we send the expected join/leave IGMPv3 messages"
if1 = self.vnet.iface_alias_map["if1"]
@@ -107,3 +126,32 @@ class TestIGMP(VnetTestTemplate):
s.close()
sniffer.join()
assert(sniffer.correctPackets > 0)
+
+ @pytest.mark.require_progs(["scapy"])
+ def test_igmp2_join_leave(self):
+ "Test that we send the expected join/leave IGMPv2 messages"
+ ToolsHelper.print_output("/sbin/sysctl net.inet.igmp.default_version=2")
+
+ if1 = self.vnet.iface_alias_map["if1"]
+
+ # Start a background sniff
+ from sniffer import Sniffer
+ expected_pkt = { "type": "join", "group": "230.0.0.1" }
+ sniffer = Sniffer(expected_pkt, check_igmpv2, if1.name, timeout=10)
+
+ # Now join a multicast group, and see if we're getting the igmp packet we expect
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
+ mreq = struct.pack("4sl", socket.inet_aton('230.0.0.1'), socket.INADDR_ANY)
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
+
+ # Wait for the sniffer to see the join packet
+ sniffer.join()
+ assert(sniffer.correctPackets > 0)
+
+ # Now leave, check for the packet
+ expected_pkt = { "type": "leave", "group": "230.0.0.1" }
+ sniffer = Sniffer(expected_pkt, check_igmpv2, if1.name)
+
+ s.close()
+ sniffer.join()
+ assert(sniffer.correctPackets > 0)
diff --git a/tests/sys/netinet/ip_reass_test.c b/tests/sys/netinet/ip_reass_test.c
index a65bfa34e1d4..538815bd7a2c 100644
--- a/tests/sys/netinet/ip_reass_test.c
+++ b/tests/sys/netinet/ip_reass_test.c
@@ -60,12 +60,16 @@ update_cksum(struct ip *ip)
{
size_t i;
uint32_t cksum;
- uint16_t *cksump;
+ uint8_t *cksump;
+ uint16_t tmp;
ip->ip_sum = 0;
- cksump = (uint16_t *)ip;
- for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(*cksump); cksump++, i++)
- cksum += ntohs(*cksump);
+ cksump = (char *)ip;
+ for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(uint16_t); i++) {
+ tmp = *cksump++;
+ tmp = tmp << 8 | *cksump++;
+ cksum += ntohs(tmp);
+ }
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum = ~(cksum + (cksum >> 16));
ip->ip_sum = htons((uint16_t)cksum);
diff --git a/tests/sys/netinet/so_reuseport_lb_test.c b/tests/sys/netinet/so_reuseport_lb_test.c
index a1b5a3f94f61..fa9d6e425884 100644
--- a/tests/sys/netinet/so_reuseport_lb_test.c
+++ b/tests/sys/netinet/so_reuseport_lb_test.c
@@ -505,6 +505,11 @@ ATF_TC_BODY(connect_not_bound, tc)
ATF_REQUIRE_MSG(rv == -1 && errno == EOPNOTSUPP,
"Expected EOPNOTSUPP on connect(2) not met. Got %d, errno %d",
rv, errno);
+ rv = sendto(s, "test", 4, 0, (struct sockaddr *)&sin,
+ sizeof(sin));
+ ATF_REQUIRE_MSG(rv == -1 && errno == EOPNOTSUPP,
+ "Expected EOPNOTSUPP on sendto(2) not met. Got %d, errno %d",
+ rv, errno);
close(p);
close(s);
@@ -536,6 +541,11 @@ ATF_TC_BODY(connect_bound, tc)
ATF_REQUIRE_MSG(rv == -1 && errno == EOPNOTSUPP,
"Expected EOPNOTSUPP on connect(2) not met. Got %d, errno %d",
rv, errno);
+ rv = sendto(s, "test", 4, 0, (struct sockaddr *)&sin,
+ sizeof(sin));
+ ATF_REQUIRE_MSG(rv == -1 && errno == EOPNOTSUPP,
+ "Expected EOPNOTSUPP on sendto(2) not met. Got %d, errno %d",
+ rv, errno);
close(p);
close(s);
diff --git a/tests/sys/netinet/socket_afinet.c b/tests/sys/netinet/socket_afinet.c
index 6fc98d982602..9c718fc5a901 100644
--- a/tests/sys/netinet/socket_afinet.c
+++ b/tests/sys/netinet/socket_afinet.c
@@ -550,7 +550,8 @@ bind_connected_port_test(const atf_tc_t *tc, int domain)
error = getsockname(sd[0], sinp, &(socklen_t){ sinp->sa_len });
ATF_REQUIRE_MSG(error == 0, "getsockname failed: %s", strerror(errno));
-
+ if (domain == PF_INET)
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
error = connect(sd[1], sinp, sinp->sa_len);
ATF_REQUIRE_MSG(error == 0, "connect failed: %s", strerror(errno));
tmp = accept(sd[0], NULL, NULL);
diff --git a/tests/sys/netinet/tcp_implied_connect.c b/tests/sys/netinet/tcp_implied_connect.c
index 6e8cb0606a0a..d03d6be4fb92 100644
--- a/tests/sys/netinet/tcp_implied_connect.c
+++ b/tests/sys/netinet/tcp_implied_connect.c
@@ -51,6 +51,7 @@ ATF_TC_BODY(tcp_implied_connect, tc)
ATF_REQUIRE(bind(s, (struct sockaddr *)&sin, sizeof(sin)) == 0);
len = sizeof(sin);
ATF_REQUIRE(getsockname(s, (struct sockaddr *)&sin, &len) == 0);
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
ATF_REQUIRE(listen(s, -1) == 0);
#if 0
/*
diff --git a/tests/sys/netinet/udp_io.c b/tests/sys/netinet/udp_io.c
index 27cd02735ed4..04f9bf56ed02 100644
--- a/tests/sys/netinet/udp_io.c
+++ b/tests/sys/netinet/udp_io.c
@@ -52,6 +52,7 @@ udp_socketpair(int *s)
ATF_REQUIRE((c = socket(PF_INET, SOCK_DGRAM, 0)) > 0);
ATF_REQUIRE(bind(b, (struct sockaddr *)&sin, sizeof(sin)) == 0);
ATF_REQUIRE(getsockname(b, (struct sockaddr *)&sin, &slen) == 0);
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
ATF_REQUIRE(connect(c, (struct sockaddr *)&sin, sizeof(sin)) == 0);
s[0] = b;