1 /* $NetBSD: t_pr.c,v 1.7 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_pr.c,v 1.7 2012/03/18 09:46:50 jruoho Exp $");
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/sysctl.h>
39 #include <netinet/in.h>
40 #include <net/route.h>
42 #include <rump/rump.h>
43 #include <rump/rump_syscalls.h>
52 #include "../config/netconfig.c"
53 #include "../../h_macros.h"
56 * Prepare rump, configure interface and route to cause fragmentation
61 char ifname
[IFNAMSIZ
];
63 struct rt_msghdr m_rtm
;
64 struct sockaddr_in m_sin
;
66 #define rtm m_rtmsg.m_rtm
67 #define rsin m_rtmsg.m_sin
73 /* first, config lo0 & route */
74 strcpy(ifname
, "lo0");
75 netcfg_rump_if(ifname
, "127.0.0.1", "255.0.0.0");
76 netcfg_rump_route("127.0.0.1", "255.0.0.0", "127.0.0.1");
78 if ((s
= rump_sys_socket(PF_ROUTE
, SOCK_RAW
, 0)) == -1)
79 atf_tc_fail_errno("routing socket");
82 * set MTU for interface so that route MTU doesn't
83 * get overridden by it.
85 memset(&ifr
, 0, sizeof(ifr
));
86 strcpy(ifr
.ifr_name
, "lo0");
88 if (rump_sys_ioctl(s
, SIOCSIFMTU
, &ifr
) == -1)
89 atf_tc_fail_errno("set mtu");
91 /* change route MTU to 100 */
92 memset(&m_rtmsg
, 0, sizeof(m_rtmsg
));
93 rtm
.rtm_type
= RTM_CHANGE
;
94 rtm
.rtm_flags
= RTF_STATIC
;
95 rtm
.rtm_version
= RTM_VERSION
;
97 rtm
.rtm_inits
= RTV_MTU
;
98 rtm
.rtm_addrs
= RTA_DST
;
99 rtm
.rtm_rmx
.rmx_mtu
= 100;
100 rtm
.rtm_msglen
= sizeof(m_rtmsg
);
102 memset(&rsin
, 0, sizeof(rsin
));
103 rsin
.sin_family
= AF_INET
;
104 rsin
.sin_len
= sizeof(rsin
);
105 rsin
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
107 if (rump_sys_write(s
, &m_rtmsg
, sizeof(m_rtmsg
)) != sizeof(m_rtmsg
))
108 atf_tc_fail_errno("set route mtu");
113 * Turn on checksums on loopback interfaces
118 struct sysctlnode q
, ans
[256];
129 memset(&q
, 0, sizeof(q
));
130 q
.sysctl_flags
= SYSCTL_VERSION
;
132 if (rump_sys___sysctl(mib
, 4, ans
, &alen
, &q
, sizeof(q
)) == -1)
135 for (i
= 0; i
< __arraycount(ans
); i
++)
136 if (strcmp("do_loopback_cksum", ans
[i
].sysctl_name
) == 0)
138 if (i
== __arraycount(ans
)) {
143 mib
[3] = ans
[i
].sysctl_num
;
146 if (rump_sys___sysctl(mib
, 4, NULL
, NULL
, &enable
,
147 sizeof(enable
)) == -1)
154 ATF_TC_HEAD(loopmtu
, tc
)
157 atf_tc_set_md_var(tc
, "descr",
158 "test lo0 fragmentation (PR kern/43664)");
161 ATF_TC_BODY(loopmtu
, tc
)
163 struct sockaddr_in sin
;
169 /* open raw socket */
170 s
= rump_sys_socket(PF_INET
, SOCK_RAW
, 0);
172 atf_tc_fail_errno("raw socket");
174 /* then, send data */
175 memset(&sin
, 0, sizeof(sin
));
176 sin
.sin_family
= AF_INET
;
177 sin
.sin_len
= sizeof(sin
);
178 sin
.sin_port
= htons(12345);
179 sin
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
181 if (rump_sys_sendto(s
, data
, sizeof(data
), 0,
182 (struct sockaddr
*)&sin
, sizeof(sin
)) == -1)
183 atf_tc_fail_errno("sendto failed");
186 ATF_TC(loopmtu_csum
);
187 ATF_TC_HEAD(loopmtu_csum
, tc
)
190 atf_tc_set_md_var(tc
, "descr",
191 "test lo0 fragmentation with checksums (PR kern/43664)");
194 ATF_TC_BODY(loopmtu_csum
, tc
)
196 struct sockaddr_in sin
;
202 ATF_CHECK(enable_locsums() == 0);
204 /* open raw socket */
205 s
= rump_sys_socket(PF_INET
, SOCK_RAW
, 0);
207 atf_tc_fail_errno("raw socket");
209 /* then, send data */
210 memset(&sin
, 0, sizeof(sin
));
211 sin
.sin_family
= AF_INET
;
212 sin
.sin_len
= sizeof(sin
);
213 sin
.sin_port
= htons(12345);
214 sin
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
216 if (rump_sys_sendto(s
, data
, sizeof(data
), 0,
217 (struct sockaddr
*)&sin
, sizeof(sin
)) == -1)
218 atf_tc_fail_errno("sendto failed");
224 ATF_TP_ADD_TC(tp
, loopmtu
);
225 ATF_TP_ADD_TC(tp
, loopmtu_csum
);
227 return atf_no_error();