t_compat.c revision 1.2 1 1.2 pgoyette /* $NetBSD: t_compat.c,v 1.2 2016/11/07 02:59:29 pgoyette Exp $ */
2 1.1 pooka
3 1.1 pooka #include <sys/socket.h>
4 1.1 pooka #include <sys/ioctl.h>
5 1.1 pooka #include <net/if.h>
6 1.1 pooka #include <netinet/in.h>
7 1.1 pooka
8 1.1 pooka #include <string.h>
9 1.1 pooka #include <stdio.h>
10 1.1 pooka #include <stdlib.h>
11 1.1 pooka
12 1.1 pooka #include <rump/rump.h>
13 1.1 pooka #include <rump/rump_syscalls.h>
14 1.1 pooka
15 1.1 pooka #include "../config/netconfig.c"
16 1.1 pooka
17 1.1 pooka /*
18 1.1 pooka * Test for stack smashing in compat ioctl handling. Adapted as an
19 1.1 pooka * atf test from code provided by Onno van der Linden in PR kern/44054
20 1.1 pooka */
21 1.1 pooka
22 1.1 pooka struct oifreq {
23 1.1 pooka char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
24 1.1 pooka union {
25 1.1 pooka struct sockaddr ifru_addr;
26 1.1 pooka struct sockaddr ifru_dstaddr;
27 1.1 pooka struct sockaddr ifru_broadaddr;
28 1.1 pooka short ifru_flags;
29 1.1 pooka int ifru_metric;
30 1.1 pooka int ifru_mtu;
31 1.1 pooka int ifru_dlt;
32 1.1 pooka u_int ifru_value;
33 1.1 pooka void * ifru_data;
34 1.1 pooka struct {
35 1.1 pooka uint32_t b_buflen;
36 1.1 pooka void *b_buf;
37 1.1 pooka } ifru_b;
38 1.1 pooka } ifr_ifru;
39 1.1 pooka };
40 1.1 pooka #define OOSIOCGIFBRDADDR _IOWR('i', 18, struct oifreq)
41 1.1 pooka
42 1.1 pooka ATF_TC(OOSIOCGIFBRDADDR);
43 1.1 pooka ATF_TC_HEAD(OOSIOCGIFBRDADDR, tc)
44 1.1 pooka {
45 1.1 pooka
46 1.1 pooka atf_tc_set_md_var(tc, "descr", "Checks that OOSIOCGIFBRDADDR works "
47 1.1 pooka "(PR kern/44054)");
48 1.1 pooka }
49 1.1 pooka
50 1.1 pooka ATF_TC_BODY(OOSIOCGIFBRDADDR, tc)
51 1.1 pooka {
52 1.1 pooka int fd, ifnum;
53 1.1 pooka struct oifreq ifreq;
54 1.1 pooka struct sockaddr_in *sin;
55 1.1 pooka int rv;
56 1.1 pooka
57 1.1 pooka memset(&ifreq,'\0',sizeof ifreq);
58 1.1 pooka
59 1.1 pooka rump_init();
60 1.1 pooka
61 1.1 pooka /* create an interface and give it netmask 0xffff0000 */
62 1.1 pooka rv = rump_pub_shmif_create("bus", &ifnum);
63 1.1 pooka if (rv)
64 1.1 pooka atf_tc_fail("failed to create shmif: %s", strerror(rv));
65 1.1 pooka sprintf(ifreq.ifr_name, "shmif%d", ifnum);
66 1.1 pooka netcfg_rump_if(ifreq.ifr_name, "1.7.64.10", "255.255.0.0");
67 1.1 pooka
68 1.2 pgoyette atf_tc_expect_fail("rump does not include COMPAT_43");
69 1.2 pgoyette
70 1.1 pooka /* query kernel for iface bcast */
71 1.1 pooka RL(fd = rump_sys_socket(AF_INET, SOCK_DGRAM, 0));
72 1.1 pooka RL(rump_sys_ioctl(fd, OOSIOCGIFBRDADDR, &ifreq));
73 1.1 pooka
74 1.1 pooka /* make sure we got what we deserve */
75 1.1 pooka sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
76 1.1 pooka ATF_REQUIRE_EQ(sin->sin_addr.s_addr, htonl(0x0107ffff));
77 1.1 pooka rump_sys_close(fd);
78 1.1 pooka }
79 1.1 pooka
80 1.1 pooka ATF_TP_ADD_TCS(tp)
81 1.1 pooka {
82 1.1 pooka
83 1.1 pooka ATF_TP_ADD_TC(tp, OOSIOCGIFBRDADDR);
84 1.1 pooka return atf_no_error();
85 1.1 pooka }
86