/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The beauty of shmif is that we don't have races here.
*/
win = netcfg_rump_pingtest("1.1.1.10", 500);
win2 = netcfg_rump_pingtest("1.1.1.30", 500);
kill(cpid, SIGKILL);
if (!win)
atf_tc_fail("ping failed");
if (win2)
atf_tc_fail("non-existent host responded");
}
ATF_TC(floodping);
ATF_TC_HEAD(floodping, tc)
{
atf_tc_set_md_var(tc, "descr", "see how kernel responds to floodping");
}
/* why the hell isn't this available in userspace??? */
static uint16_t
in_cksum(void *data, size_t len)
{
uint16_t *buf = data;
unsigned sum;
for (sum = 0; len > 1; len -= 2)
sum += *buf++;
if (len)
sum += *(uint8_t *)buf;
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ~sum;
}
static int
doping(const char *target, int loops, u_int pktsize)
{
union {
char buf[IP_MAXPACKET - sizeof(struct ip)];
struct icmp i; /* ensure proper alignment */
} sndbuf;
char recvbuf[IP_MAXPACKET];
struct sockaddr_in dst, pingee;
struct icmp *icmp;
socklen_t slen;
ssize_t n;
int loop, succ;
int x, xnon, s;
switch (cpid) {
case -1:
atf_tc_fail_errno("fork failed");
case 0:
/* wait until we receive a too long IP packet */
for (loop = 0;; loop++) {
uint64_t ipstat[IP_NSTATS];
size_t arglen;
int mib[4];
if (loop == 1)
netcfg_rump_if(ifname,
"1.1.1.10", "255.255.255.0");