1 /* $NetBSD: t_pr.c,v 1.2 2010/07/26 14:07:04 pooka Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 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. 28 */ 29 30 #include <sys/cdefs.h> 31 #ifndef lint 32 __RCSID("$NetBSD: t_pr.c,v 1.2 2010/07/26 14:07:04 pooka Exp $"); 33 #endif /* not lint */ 34 35 #include <sys/types.h> 36 #include <sys/socket.h> 37 38 #include <netinet/in.h> 39 #include <net/route.h> 40 41 #include <rump/rump.h> 42 #include <rump/rump_syscalls.h> 43 44 #include <atf-c.h> 45 #include <errno.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <string.h> 49 #include <unistd.h> 50 51 #include "../config/netconfig.c" 52 #include "../../h_macros.h" 53 54 ATF_TC(loopmtu); 55 ATF_TC_HEAD(loopmtu, tc) 56 { 57 58 atf_tc_set_md_var(tc, "descr", "test lo0 fragmentation"); 59 /* PR kern/43664 */ 60 } 61 62 ATF_TC_BODY(loopmtu, tc) 63 { 64 char ifname[IFNAMSIZ]; 65 size_t len; 66 struct { 67 struct rt_msghdr m_rtm; 68 struct sockaddr_in m_sin; 69 } m_rtmsg; 70 #define rtm m_rtmsg.m_rtm 71 #define rsin m_rtmsg.m_sin 72 struct sockaddr_in sin; 73 struct ifreq ifr; 74 char data[2000]; 75 int s; 76 77 strcpy(ifname, "lo0"); 78 rump_init(); 79 80 /* first, config lo0 & route */ 81 netcfg_rump_if(ifname, "127.0.0.1", "255.0.0.0"); 82 netcfg_rump_route("127.0.0.1", "255.0.0.0", "127.0.0.1"); 83 84 if ((s = rump_sys_socket(PF_ROUTE, SOCK_RAW, 0)) == -1) 85 atf_tc_fail_errno("routing socket"); 86 87 /* 88 * set MTU for interface so that route MTU doesn't 89 * get overridden by it. 90 */ 91 memset(&ifr, 0, sizeof(ifr)); 92 strcpy(ifr.ifr_name, "lo0"); 93 ifr.ifr_mtu = 1300; 94 if (rump_sys_ioctl(s, SIOCSIFMTU, &ifr) == -1) 95 atf_tc_fail_errno("set mtu"); 96 97 /* change route MTU to 100 */ 98 memset(&m_rtmsg, 0, sizeof(m_rtmsg)); 99 rtm.rtm_type = RTM_CHANGE; 100 rtm.rtm_flags = RTF_STATIC; 101 rtm.rtm_version = RTM_VERSION; 102 rtm.rtm_seq = 3; 103 rtm.rtm_inits = RTV_MTU; 104 rtm.rtm_addrs = RTA_DST; 105 rtm.rtm_rmx.rmx_mtu = 100; 106 rtm.rtm_msglen = sizeof(m_rtmsg); 107 108 memset(&rsin, 0, sizeof(rsin)); 109 rsin.sin_family = AF_INET; 110 rsin.sin_len = sizeof(rsin); 111 rsin.sin_addr.s_addr = inet_addr("127.0.0.1"); 112 113 if (rump_sys_write(s, &m_rtmsg, sizeof(m_rtmsg)) != sizeof(m_rtmsg)) 114 atf_tc_fail_errno("set route mtu"); 115 rump_sys_close(s); 116 117 /* open raw socket */ 118 s = rump_sys_socket(PF_INET, SOCK_RAW, 0); 119 if (s == -1) 120 atf_tc_fail_errno("raw socket"); 121 122 /* then, send data */ 123 memset(&sin, 0, sizeof(sin)); 124 sin.sin_family = AF_INET; 125 sin.sin_len = sizeof(sin); 126 sin.sin_port = htons(12345); 127 sin.sin_addr.s_addr = inet_addr("127.0.0.1"); 128 129 atf_tc_expect_signal(SIGABRT, "PR kern/43664"); 130 if (rump_sys_sendto(s, data, sizeof(data), 0, 131 (struct sockaddr *)&sin, sizeof(sin)) == -1) 132 atf_tc_fail_errno("sendto failed"); 133 } 134 135 ATF_TP_ADD_TCS(tp) 136 { 137 138 ATF_TP_ADD_TC(tp, loopmtu); 139 140 return atf_no_error(); 141 } 142