if_43.c revision 1.2 1 1.2 dyoung /* $NetBSD: if_43.c,v 1.2 2009/03/17 00:08:10 dyoung Exp $ */
2 1.1 ad
3 1.1 ad /*
4 1.1 ad * Copyright (c) 1982, 1986, 1989, 1990, 1993
5 1.1 ad * The Regents of the University of California. All rights reserved.
6 1.1 ad *
7 1.1 ad * Redistribution and use in source and binary forms, with or without
8 1.1 ad * modification, are permitted provided that the following conditions
9 1.1 ad * are met:
10 1.1 ad * 1. Redistributions of source code must retain the above copyright
11 1.1 ad * notice, this list of conditions and the following disclaimer.
12 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ad * notice, this list of conditions and the following disclaimer in the
14 1.1 ad * documentation and/or other materials provided with the distribution.
15 1.1 ad * 3. Neither the name of the University nor the names of its contributors
16 1.1 ad * may be used to endorse or promote products derived from this software
17 1.1 ad * without specific prior written permission.
18 1.1 ad *
19 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 ad * SUCH DAMAGE.
30 1.1 ad *
31 1.1 ad * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
32 1.1 ad */
33 1.1 ad
34 1.1 ad #include <sys/cdefs.h>
35 1.2 dyoung __KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.2 2009/03/17 00:08:10 dyoung Exp $");
36 1.2 dyoung
37 1.2 dyoung #if defined(_KERNEL_OPT)
38 1.2 dyoung #include "opt_compat_netbsd.h"
39 1.2 dyoung #endif
40 1.1 ad
41 1.1 ad #include <sys/param.h>
42 1.1 ad #include <sys/systm.h>
43 1.1 ad #include <sys/filedesc.h>
44 1.1 ad #include <sys/kernel.h>
45 1.1 ad #include <sys/proc.h>
46 1.1 ad #include <sys/file.h>
47 1.1 ad #include <sys/socket.h>
48 1.1 ad #include <sys/socketvar.h>
49 1.1 ad #include <sys/stat.h>
50 1.1 ad #include <sys/ioctl.h>
51 1.1 ad #include <sys/fcntl.h>
52 1.1 ad #include <sys/malloc.h>
53 1.1 ad #include <sys/syslog.h>
54 1.1 ad #include <sys/unistd.h>
55 1.1 ad #include <sys/resourcevar.h>
56 1.1 ad #include <sys/mbuf.h> /* for MLEN */
57 1.1 ad #include <sys/protosw.h>
58 1.1 ad
59 1.1 ad #include <sys/mount.h>
60 1.1 ad #include <sys/syscallargs.h>
61 1.1 ad
62 1.1 ad #include <net/if.h>
63 1.1 ad #include <net/bpf.h>
64 1.1 ad #include <net/route.h>
65 1.1 ad #include <netinet/in.h>
66 1.1 ad #include <netinet/in_systm.h>
67 1.1 ad #include <netinet/ip.h>
68 1.1 ad #include <net/if_gre.h>
69 1.1 ad #include <net/if_atm.h>
70 1.1 ad #include <net/if_tap.h>
71 1.1 ad #include <net80211/ieee80211_ioctl.h>
72 1.1 ad #include <netinet6/in6_var.h>
73 1.1 ad #include <netinet6/nd6.h>
74 1.1 ad #include <compat/sys/socket.h>
75 1.1 ad #include <compat/sys/sockio.h>
76 1.1 ad
77 1.1 ad #include <compat/common/compat_util.h>
78 1.1 ad
79 1.1 ad #include <uvm/uvm_extern.h>
80 1.1 ad
81 1.1 ad u_long
82 1.1 ad compat_cvtcmd(u_long cmd)
83 1.1 ad {
84 1.1 ad u_long ncmd;
85 1.1 ad
86 1.1 ad if (IOCPARM_LEN(cmd) != sizeof(struct oifreq))
87 1.1 ad return cmd;
88 1.1 ad
89 1.1 ad ncmd = ((cmd) & ~(IOCPARM_MASK << IOCPARM_SHIFT)) |
90 1.1 ad (sizeof(struct ifreq) << IOCPARM_SHIFT);
91 1.1 ad
92 1.1 ad switch (ncmd) {
93 1.1 ad case BIOCGETIF:
94 1.1 ad case BIOCSETIF:
95 1.1 ad case GREDSOCK:
96 1.1 ad case GREGADDRD:
97 1.1 ad case GREGADDRS:
98 1.1 ad case GREGPROTO:
99 1.1 ad case GRESADDRD:
100 1.1 ad case GRESADDRS:
101 1.1 ad case GRESPROTO:
102 1.1 ad case GRESSOCK:
103 1.1 ad #ifdef COMPAT_20
104 1.1 ad case OSIOCG80211STATS:
105 1.1 ad case OSIOCG80211ZSTATS:
106 1.1 ad #endif /* COMPAT_20 */
107 1.1 ad case SIOCADDMULTI:
108 1.1 ad case SIOCDELMULTI:
109 1.1 ad case SIOCDIFADDR:
110 1.1 ad case SIOCDIFADDR_IN6:
111 1.1 ad case SIOCDIFPHYADDR:
112 1.1 ad case SIOCGDEFIFACE_IN6:
113 1.1 ad case SIOCG80211NWID:
114 1.1 ad case SIOCG80211STATS:
115 1.1 ad case SIOCG80211ZSTATS:
116 1.1 ad case SIOCGIFADDR:
117 1.1 ad case SIOCGIFADDR_IN6:
118 1.1 ad case SIOCGIFAFLAG_IN6:
119 1.1 ad case SIOCGIFALIFETIME_IN6:
120 1.1 ad case SIOCGIFBRDADDR:
121 1.1 ad case SIOCGIFDLT:
122 1.1 ad case SIOCGIFDSTADDR:
123 1.1 ad case SIOCGIFDSTADDR_IN6:
124 1.1 ad case SIOCGIFFLAGS:
125 1.1 ad case SIOCGIFGENERIC:
126 1.1 ad case SIOCGIFMETRIC:
127 1.1 ad case SIOCGIFMTU:
128 1.1 ad case SIOCGIFNETMASK:
129 1.1 ad case SIOCGIFNETMASK_IN6:
130 1.1 ad case SIOCGIFPDSTADDR:
131 1.1 ad case SIOCGIFPDSTADDR_IN6:
132 1.1 ad case SIOCGIFPSRCADDR:
133 1.1 ad case SIOCGIFPSRCADDR_IN6:
134 1.1 ad case SIOCGIFSTAT_ICMP6:
135 1.1 ad case SIOCGIFSTAT_IN6:
136 1.1 ad case SIOCGPVCSIF:
137 1.1 ad case SIOCGVH:
138 1.1 ad case SIOCIFCREATE:
139 1.1 ad case SIOCIFDESTROY:
140 1.1 ad case SIOCS80211NWID:
141 1.1 ad case SIOCSDEFIFACE_IN6:
142 1.1 ad case SIOCSIFADDR:
143 1.1 ad case SIOCSIFADDR_IN6:
144 1.1 ad case SIOCSIFBRDADDR:
145 1.1 ad case SIOCSIFDSTADDR:
146 1.1 ad case SIOCSIFDSTADDR_IN6:
147 1.1 ad case SIOCSIFFLAGS:
148 1.1 ad case SIOCSIFGENERIC:
149 1.1 ad case SIOCSIFMEDIA:
150 1.1 ad case SIOCSIFMETRIC:
151 1.1 ad case SIOCSIFMTU:
152 1.1 ad case SIOCSIFNETMASK:
153 1.1 ad case SIOCSIFNETMASK_IN6:
154 1.1 ad case SIOCSNDFLUSH_IN6:
155 1.1 ad case SIOCSPFXFLUSH_IN6:
156 1.1 ad case SIOCSPVCSIF:
157 1.1 ad case SIOCSRTRFLUSH_IN6:
158 1.1 ad case SIOCSVH:
159 1.1 ad case TAPGIFNAME:
160 1.1 ad return ncmd;
161 1.1 ad }
162 1.1 ad return cmd;
163 1.1 ad }
164 1.1 ad
165 1.1 ad int
166 1.1 ad compat_ifioctl(struct socket *so, u_long ocmd, u_long cmd, void *data,
167 1.1 ad struct lwp *l)
168 1.1 ad {
169 1.1 ad int error;
170 1.1 ad struct ifreq *ifr = data;
171 1.1 ad struct ifnet *ifp = ifunit(ifr->ifr_name);
172 1.1 ad struct sockaddr *sa;
173 1.1 ad
174 1.1 ad if (ifp == NULL)
175 1.1 ad return ENXIO;
176 1.1 ad
177 1.1 ad switch (ocmd) {
178 1.1 ad case OSIOCSIFADDR:
179 1.1 ad case OSIOCSIFDSTADDR:
180 1.1 ad case OSIOCSIFBRDADDR:
181 1.1 ad case OSIOCSIFNETMASK:
182 1.1 ad sa = &ifr->ifr_addr;
183 1.1 ad #if BYTE_ORDER != BIG_ENDIAN
184 1.1 ad if (sa->sa_family == 0 && sa->sa_len < 16) {
185 1.1 ad sa->sa_family = sa->sa_len;
186 1.1 ad sa->sa_len = 16;
187 1.1 ad }
188 1.1 ad #else
189 1.1 ad if (sa->sa_len == 0)
190 1.1 ad sa->sa_len = 16;
191 1.1 ad #endif
192 1.1 ad break;
193 1.1 ad
194 1.1 ad case OOSIOCGIFADDR:
195 1.1 ad cmd = SIOCGIFADDR;
196 1.1 ad break;
197 1.1 ad
198 1.1 ad case OOSIOCGIFDSTADDR:
199 1.1 ad cmd = SIOCGIFDSTADDR;
200 1.1 ad break;
201 1.1 ad
202 1.1 ad case OOSIOCGIFBRDADDR:
203 1.1 ad cmd = SIOCGIFBRDADDR;
204 1.1 ad break;
205 1.1 ad
206 1.1 ad case OOSIOCGIFNETMASK:
207 1.1 ad cmd = SIOCGIFNETMASK;
208 1.1 ad }
209 1.1 ad
210 1.1 ad error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
211 1.1 ad (struct mbuf *)cmd, (struct mbuf *)ifr, (struct mbuf *)ifp, l);
212 1.1 ad
213 1.1 ad switch (ocmd) {
214 1.1 ad case OOSIOCGIFADDR:
215 1.1 ad case OOSIOCGIFDSTADDR:
216 1.1 ad case OOSIOCGIFBRDADDR:
217 1.1 ad case OOSIOCGIFNETMASK:
218 1.1 ad *(u_int16_t *)&ifr->ifr_addr =
219 1.1 ad ((struct sockaddr *)&ifr->ifr_addr)->sa_family;
220 1.1 ad }
221 1.1 ad return error;
222 1.1 ad }
223