1 /* $NetBSD: t_forward.c,v 1.8 2012/03/18 09:46:50 jruoho 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_forward.c,v 1.8 2012/03/18 09:46:50 jruoho Exp $");
35 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <sys/sysctl.h>
41 #include <arpa/inet.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/ip_icmp.h>
47 #include <netinet/icmp_var.h>
48 #include <net/route.h>
50 #include <rump/rump.h>
51 #include <rump/rump_syscalls.h>
60 #include "../../h_macros.h"
61 #include "../config/netconfig.c"
64 * Since our maxttl is in our private namespace, we don't need raw packet
65 * construction like traceroute(8) -- we can just use the global maxttl.
70 struct sockaddr_in sin
;
72 char ifname
[IFNAMSIZ
];
73 int mib
[4] = { CTL_NET
, PF_INET
, IPPROTO_IP
, IPCTL_DEFTTL
};
77 netcfg_rump_makeshmif("bus1", ifname
);
78 netcfg_rump_if(ifname
, "1.0.0.1", "255.255.255.0");
79 netcfg_rump_route("0.0.0.0", "0.0.0.0", "1.0.0.2"); /* default router */
81 /* set global ttl to 1 */
83 if (rump_sys___sysctl(mib
, 4, NULL
, NULL
, &nv
, sizeof(nv
)) == -1)
84 atf_tc_fail_errno("set ttl");
86 s
= rump_sys_socket(PF_INET
, SOCK_DGRAM
, 0);
88 atf_tc_fail_errno("create send socket");
90 memset(&sin
, 0, sizeof(sin
));
91 sin
.sin_len
= sizeof(sin
);
92 sin
.sin_family
= AF_INET
;
93 sin
.sin_port
= htons(33434);
94 sin
.sin_addr
.s_addr
= inet_addr("9.9.9.9");
96 /* send udp datagram with ttl == 1 */
97 if (rump_sys_sendto(s
, payload
, sizeof(payload
), 0,
98 (struct sockaddr
*)&sin
, sizeof(sin
)) == -1)
99 atf_tc_fail_errno("sendto");
105 int mib
[4] = { CTL_NET
, PF_INET
, IPPROTO_ICMP
,
106 ICMPCTL_RETURNDATABYTES
};
107 char ifname
[IFNAMSIZ
];
110 /* set returndatabytes to 200 */
112 if (rump_sys___sysctl(mib
, 4, NULL
, NULL
, &nv
, sizeof(nv
)) == -1)
113 atf_tc_fail_errno("sysctl returndatabytes");
115 netcfg_rump_makeshmif("bus1", ifname
);
116 netcfg_rump_if(ifname
, "1.0.0.2", "255.255.255.0");
119 * Wait for parent to send us the data and for us to have
120 * a chance to process it.
126 ATF_TC(returndatabytes
);
127 ATF_TC_HEAD(returndatabytes
, tc
)
130 atf_tc_set_md_var(tc
, "descr", "icmp.returndatabytes with certain "
131 "packets can cause kernel panic (PR kern/43548)");
132 atf_tc_set_md_var(tc
, "timeout", "4"); /* just in case */
135 ATF_TC_BODY(returndatabytes
, tc
)
145 atf_tc_fail_errno("fork failed");
151 if (wait(&status
) == -1)
152 atf_tc_fail_errno("wait");
153 if (WIFEXITED(status
)) {
154 if (WEXITSTATUS(status
))
155 atf_tc_fail("child exited with status %d",
156 WEXITSTATUS(status
));
158 atf_tc_fail("child died");
166 ATF_TP_ADD_TC(tp
, returndatabytes
);
168 return atf_no_error();