1 /* $NetBSD: t_basic.c,v 1.5 2011/06/26 13:13:31 christos Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_basic.c,v 1.5 2011/06/26 13:13:31 christos Exp $");
35 #include <sys/types.h>
36 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip_carp.h>
43 #include <rump/rump.h>
44 #include <rump/rump_syscalls.h>
54 #include "../config/netconfig.c"
55 #include "../../h_macros.h"
57 static bool oknow = false;
63 ATF_REQUIRE_EQ(sig, SIGCHLD);
67 atf_tc_fail("child died unexpectedly");
71 ATF_TC_HEAD(handover, tc)
74 atf_tc_set_md_var(tc, "descr", "check that carp handover works if "
78 #define THEBUS "buuuuuuus,etherbus"
83 char ifname[IFNAMSIZ];
89 /* helps reading carp debug output */
96 * Should use sysctl, bug debug is dabug.
99 //extern int rumpns_carp_opts[]; /* XXX */
100 //rumpns_carp_opts[CARPCTL_LOG] = 1;
106 memset(&ifr, 0, sizeof(ifr));
107 strlcpy(ifr.ifr_name, carpif, sizeof(ifr.ifr_name));
109 RL(s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0));
110 RL(rump_sys_ioctl(s, SIOCIFCREATE, &ifr));
112 netcfg_rump_makeshmif(THEBUS, ifname);
115 netcfg_rump_if(ifname, "10.1.1.1", "255.255.255.0");
117 netcfg_rump_if(ifname, "10.1.1.2", "255.255.255.0");
119 /* configure the carp interface */
121 RL(rump_sys_ioctl(s, SIOCGVH, &ifr));
123 strlcpy(cr.carpr_carpdev, ifname, sizeof(cr.carpr_carpdev));
126 cr.carpr_advskew = 0;
128 cr.carpr_advskew = 200;
129 cr.carpr_advbase = 1;
130 strcpy((char *)cr.carpr_key, "s3cret");
132 RL(rump_sys_ioctl(s, SIOCSVH, &ifr));
133 netcfg_rump_if(carpif, "10.1.1.100", "255.255.255.0");
135 /* tassa pause()en enka muuta voi */
139 ATF_TC_BODY(handover, tc)
141 char ifname[IFNAMSIZ];
145 signal(SIGCHLD, sighnd);
148 switch (mpid = fork()) {
150 atf_tc_fail_errno("fork failed");
162 switch (cpid = fork()) {
165 atf_tc_fail_errno("fork failed");
177 netcfg_rump_makeshmif(THEBUS, ifname);
178 netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0");
180 /* check that the primary addresses are up */
181 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true);
182 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true);
184 /* give carp a while to croak */
187 /* check that the shared IP works */
188 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true);
194 usleep(10000); /* just in case */
197 /* check that primary is now dead */
198 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false);
200 /* do it in installments. carp will cluck meanwhile */
201 for (i = 0; i < 5; i++) {
202 if (netcfg_rump_pingtest("10.1.1.100", 1000) == true)
206 atf_tc_fail("failed to failover");
208 /* to kill the child */
218 ATF_TP_ADD_TC(tp, handover);
220 return atf_no_error();