if_gif.c revision 1.3 1 1.3 itojun /* $NetBSD: if_gif.c,v 1.3 1999/12/02 07:18:44 itojun Exp $ */
2 1.3 itojun
3 1.2 itojun /*
4 1.2 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 1.2 itojun * All rights reserved.
6 1.2 itojun *
7 1.2 itojun * Redistribution and use in source and binary forms, with or without
8 1.2 itojun * modification, are permitted provided that the following conditions
9 1.2 itojun * are met:
10 1.2 itojun * 1. Redistributions of source code must retain the above copyright
11 1.2 itojun * notice, this list of conditions and the following disclaimer.
12 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 itojun * notice, this list of conditions and the following disclaimer in the
14 1.2 itojun * documentation and/or other materials provided with the distribution.
15 1.2 itojun * 3. Neither the name of the project nor the names of its contributors
16 1.2 itojun * may be used to endorse or promote products derived from this software
17 1.2 itojun * without specific prior written permission.
18 1.2 itojun *
19 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2 itojun * SUCH DAMAGE.
30 1.2 itojun */
31 1.2 itojun
32 1.2 itojun /*
33 1.2 itojun * gif.c
34 1.2 itojun */
35 1.2 itojun
36 1.2 itojun #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
37 1.2 itojun #include "opt_inet.h"
38 1.2 itojun #endif
39 1.2 itojun
40 1.2 itojun #include <sys/param.h>
41 1.2 itojun #include <sys/systm.h>
42 1.2 itojun #include <sys/kernel.h>
43 1.2 itojun #include <sys/mbuf.h>
44 1.2 itojun #include <sys/socket.h>
45 1.2 itojun #include <sys/sockio.h>
46 1.2 itojun #include <sys/errno.h>
47 1.2 itojun #if !defined(__FreeBSD__) || __FreeBSD__ < 3
48 1.2 itojun #include <sys/ioctl.h>
49 1.2 itojun #endif
50 1.2 itojun #include <sys/time.h>
51 1.2 itojun #include <sys/syslog.h>
52 1.2 itojun #include <machine/cpu.h>
53 1.2 itojun
54 1.2 itojun #include <net/if.h>
55 1.2 itojun #include <net/if_types.h>
56 1.2 itojun #include <net/netisr.h>
57 1.2 itojun #include <net/route.h>
58 1.2 itojun #include <net/bpf.h>
59 1.2 itojun
60 1.2 itojun #ifdef INET
61 1.2 itojun #include <netinet/in.h>
62 1.2 itojun #include <netinet/in_systm.h>
63 1.2 itojun #include <netinet/in_var.h>
64 1.2 itojun #include <netinet/ip.h>
65 1.2 itojun #include <netinet/in_gif.h>
66 1.2 itojun #endif /* INET */
67 1.2 itojun
68 1.2 itojun #ifdef INET6
69 1.2 itojun #ifndef INET
70 1.2 itojun #include <netinet/in.h>
71 1.2 itojun #endif
72 1.2 itojun #include <netinet6/in6_var.h>
73 1.2 itojun #include <netinet/ip6.h>
74 1.2 itojun #include <netinet6/ip6_var.h>
75 1.2 itojun #include <netinet6/in6_gif.h>
76 1.2 itojun #include <netinet6/in6_ifattach.h>
77 1.2 itojun #endif /* INET6 */
78 1.2 itojun
79 1.2 itojun #include <net/if_gif.h>
80 1.2 itojun
81 1.2 itojun #include "gif.h"
82 1.2 itojun #include "bpfilter.h"
83 1.2 itojun
84 1.2 itojun #if NGIF > 0
85 1.2 itojun
86 1.2 itojun void gifattach __P((void *));
87 1.2 itojun
88 1.2 itojun /*
89 1.2 itojun * gif global variable definitions
90 1.2 itojun */
91 1.2 itojun int ngif = NGIF; /* number of interfaces */
92 1.2 itojun struct gif_softc *gif = 0;
93 1.2 itojun
94 1.2 itojun void
95 1.2 itojun gifattach(dummy)
96 1.2 itojun void *dummy;
97 1.2 itojun {
98 1.2 itojun register struct gif_softc *sc;
99 1.2 itojun register int i;
100 1.2 itojun
101 1.2 itojun gif = sc = malloc (ngif * sizeof(struct gif_softc), M_DEVBUF, M_WAIT);
102 1.2 itojun bzero(sc, ngif * sizeof(struct gif_softc));
103 1.2 itojun for (i = 0; i < ngif; sc++, i++) {
104 1.2 itojun sprintf(sc->gif_if.if_xname, "gif%d", i);
105 1.2 itojun sc->gif_if.if_mtu = GIF_MTU;
106 1.2 itojun sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
107 1.2 itojun sc->gif_if.if_ioctl = gif_ioctl;
108 1.2 itojun sc->gif_if.if_output = gif_output;
109 1.2 itojun sc->gif_if.if_type = IFT_GIF;
110 1.2 itojun if_attach(&sc->gif_if);
111 1.2 itojun #if NBPFILTER > 0
112 1.2 itojun bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, sizeof(u_int));
113 1.2 itojun #endif
114 1.2 itojun }
115 1.2 itojun }
116 1.2 itojun
117 1.2 itojun #ifdef __FreeBSD__
118 1.2 itojun PSEUDO_SET(gifattach, if_gif);
119 1.2 itojun #endif
120 1.2 itojun
121 1.2 itojun int
122 1.2 itojun gif_output(ifp, m, dst, rt)
123 1.2 itojun struct ifnet *ifp;
124 1.2 itojun struct mbuf *m;
125 1.2 itojun struct sockaddr *dst;
126 1.2 itojun struct rtentry *rt; /* added in net2 */
127 1.2 itojun {
128 1.2 itojun register struct gif_softc *sc = (struct gif_softc*)ifp;
129 1.2 itojun int error = 0;
130 1.2 itojun static int called = 0; /* XXX: MUTEX */
131 1.2 itojun int calllimit = 10; /* XXX: adhoc */
132 1.2 itojun
133 1.2 itojun /*
134 1.2 itojun * gif may cause infinite recursion calls when misconfigured.
135 1.2 itojun * We'll prevent this by introducing upper limit.
136 1.2 itojun * XXX: this mechanism may introduce another problem about
137 1.2 itojun * mutual exclusion of the variable CALLED, especially if we
138 1.2 itojun * use kernel thread.
139 1.2 itojun */
140 1.2 itojun if (++called >= calllimit) {
141 1.2 itojun log(LOG_NOTICE,
142 1.2 itojun "gif_output: recursively called too many times(%d)\n",
143 1.2 itojun called);
144 1.2 itojun m_freem(m);
145 1.2 itojun error = EIO; /* is there better errno? */
146 1.2 itojun goto end;
147 1.2 itojun }
148 1.2 itojun
149 1.2 itojun ifp->if_lastchange = time;
150 1.2 itojun m->m_flags &= ~(M_BCAST|M_MCAST);
151 1.2 itojun if (!(ifp->if_flags & IFF_UP) ||
152 1.2 itojun #if 0
153 1.2 itojun sc->gif_flags & GIFF_INUSE ||
154 1.2 itojun #endif
155 1.2 itojun sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
156 1.2 itojun m_freem(m);
157 1.2 itojun error = ENETDOWN;
158 1.2 itojun goto end;
159 1.2 itojun }
160 1.2 itojun
161 1.2 itojun #if NBPFILTER > 0
162 1.2 itojun if (ifp->if_bpf) {
163 1.2 itojun /*
164 1.2 itojun * We need to prepend the address family as
165 1.2 itojun * a four byte field. Cons up a dummy header
166 1.2 itojun * to pacify bpf. This is safe because bpf
167 1.2 itojun * will only read from the mbuf (i.e., it won't
168 1.2 itojun * try to free it or keep a pointer a to it).
169 1.2 itojun */
170 1.2 itojun struct mbuf m0;
171 1.2 itojun u_int af = dst->sa_family;
172 1.2 itojun
173 1.2 itojun m0.m_next = m;
174 1.2 itojun m0.m_len = 4;
175 1.2 itojun m0.m_data = (char *)⁡
176 1.2 itojun
177 1.2 itojun bpf_mtap(ifp->if_bpf, &m0);
178 1.2 itojun }
179 1.2 itojun #endif
180 1.2 itojun ifp->if_opackets++;
181 1.2 itojun ifp->if_obytes += m->m_pkthdr.len;
182 1.2 itojun #if 0
183 1.2 itojun s = splnet();
184 1.2 itojun sc->gif_flags |= GIFF_INUSE;
185 1.2 itojun #endif
186 1.2 itojun
187 1.2 itojun switch (sc->gif_psrc->sa_family) {
188 1.2 itojun #ifdef INET
189 1.2 itojun case AF_INET:
190 1.2 itojun error = in_gif_output(ifp, dst->sa_family, m, rt);
191 1.2 itojun break;
192 1.2 itojun #endif
193 1.2 itojun #ifdef INET6
194 1.2 itojun case AF_INET6:
195 1.2 itojun error = in6_gif_output(ifp, dst->sa_family, m, rt);
196 1.2 itojun break;
197 1.2 itojun #endif
198 1.2 itojun default:
199 1.2 itojun m_freem(m);
200 1.2 itojun error = ENETDOWN;
201 1.2 itojun }
202 1.2 itojun #if 0
203 1.2 itojun sc->gif_flags &= ~GIFF_INUSE;
204 1.2 itojun splx(s);
205 1.2 itojun #endif
206 1.2 itojun
207 1.2 itojun end:
208 1.2 itojun called = 0; /* reset recursion counter */
209 1.2 itojun if (error) ifp->if_oerrors++;
210 1.2 itojun return error;
211 1.2 itojun }
212 1.2 itojun
213 1.2 itojun void
214 1.2 itojun gif_input(m, af, gifp)
215 1.2 itojun struct mbuf *m;
216 1.2 itojun int af;
217 1.2 itojun struct ifnet *gifp;
218 1.2 itojun {
219 1.2 itojun int s, isr;
220 1.2 itojun register struct ifqueue *ifq = 0;
221 1.2 itojun
222 1.2 itojun if (gifp == NULL) {
223 1.2 itojun /* just in case */
224 1.2 itojun m_freem(m);
225 1.2 itojun return;
226 1.2 itojun }
227 1.2 itojun
228 1.2 itojun if (m->m_pkthdr.rcvif)
229 1.2 itojun m->m_pkthdr.rcvif = gifp;
230 1.2 itojun
231 1.2 itojun #if NBPFILTER > 0
232 1.2 itojun if (gifp->if_bpf) {
233 1.2 itojun /*
234 1.2 itojun * We need to prepend the address family as
235 1.2 itojun * a four byte field. Cons up a dummy header
236 1.2 itojun * to pacify bpf. This is safe because bpf
237 1.2 itojun * will only read from the mbuf (i.e., it won't
238 1.2 itojun * try to free it or keep a pointer a to it).
239 1.2 itojun */
240 1.2 itojun struct mbuf m0;
241 1.2 itojun u_int af = AF_INET6;
242 1.2 itojun
243 1.2 itojun m0.m_next = m;
244 1.2 itojun m0.m_len = 4;
245 1.2 itojun m0.m_data = (char *)⁡
246 1.2 itojun
247 1.2 itojun bpf_mtap(gifp->if_bpf, &m0);
248 1.2 itojun }
249 1.2 itojun #endif /*NBPFILTER > 0*/
250 1.2 itojun
251 1.2 itojun /*
252 1.2 itojun * Put the packet to the network layer input queue according to the
253 1.2 itojun * specified address family.
254 1.2 itojun * Note: older versions of gif_input directly called network layer
255 1.2 itojun * input functions, e.g. ip6_input, here. We changed the policy to
256 1.2 itojun * prevent too many recursive calls of such input functions, which
257 1.2 itojun * might cause kernel panic. But the change may introduce another
258 1.2 itojun * problem; if the input queue is full, packets are discarded.
259 1.2 itojun * We believed it rarely occurs and changed the policy. If we find
260 1.2 itojun * it occurs more times than we thought, we may change the policy
261 1.2 itojun * again.
262 1.2 itojun */
263 1.2 itojun switch (af) {
264 1.2 itojun #ifdef INET
265 1.2 itojun case AF_INET:
266 1.2 itojun ifq = &ipintrq;
267 1.2 itojun isr = NETISR_IP;
268 1.2 itojun break;
269 1.2 itojun #endif
270 1.2 itojun #ifdef INET6
271 1.2 itojun case AF_INET6:
272 1.2 itojun ifq = &ip6intrq;
273 1.2 itojun isr = NETISR_IPV6;
274 1.2 itojun break;
275 1.2 itojun #endif
276 1.2 itojun default:
277 1.2 itojun m_freem(m);
278 1.2 itojun return;
279 1.2 itojun }
280 1.2 itojun
281 1.2 itojun s = splimp();
282 1.2 itojun if (IF_QFULL(ifq)) {
283 1.2 itojun IF_DROP(ifq); /* update statistics */
284 1.2 itojun m_freem(m);
285 1.2 itojun splx(s);
286 1.2 itojun return;
287 1.2 itojun }
288 1.2 itojun IF_ENQUEUE(ifq, m);
289 1.2 itojun /* we need schednetisr since the address family may change */
290 1.2 itojun schednetisr(isr);
291 1.2 itojun gifp->if_ipackets++;
292 1.2 itojun gifp->if_ibytes += m->m_pkthdr.len;
293 1.2 itojun splx(s);
294 1.2 itojun
295 1.2 itojun return;
296 1.2 itojun }
297 1.2 itojun
298 1.2 itojun
299 1.2 itojun int
300 1.2 itojun gif_ioctl(ifp, cmd, data)
301 1.2 itojun struct ifnet *ifp;
302 1.2 itojun u_long cmd;
303 1.2 itojun caddr_t data;
304 1.2 itojun {
305 1.2 itojun struct gif_softc *sc = (struct gif_softc*)ifp;
306 1.2 itojun struct ifreq *ifr = (struct ifreq*)data;
307 1.2 itojun int error = 0, size;
308 1.2 itojun struct sockaddr *sa, *dst, *src;
309 1.2 itojun
310 1.2 itojun switch (cmd) {
311 1.2 itojun case SIOCSIFADDR:
312 1.2 itojun break;
313 1.2 itojun
314 1.2 itojun case SIOCSIFDSTADDR:
315 1.2 itojun break;
316 1.2 itojun
317 1.2 itojun case SIOCADDMULTI:
318 1.2 itojun case SIOCDELMULTI:
319 1.2 itojun switch (ifr->ifr_addr.sa_family) {
320 1.2 itojun #ifdef INET
321 1.2 itojun case AF_INET: /* IP supports Multicast */
322 1.2 itojun break;
323 1.2 itojun #endif /* INET */
324 1.2 itojun #ifdef INET6
325 1.2 itojun case AF_INET6: /* IP6 supports Multicast */
326 1.2 itojun break;
327 1.2 itojun #endif /* INET6 */
328 1.2 itojun default: /* Other protocols doesn't support Multicast */
329 1.2 itojun error = EAFNOSUPPORT;
330 1.2 itojun break;
331 1.2 itojun }
332 1.2 itojun break;
333 1.2 itojun
334 1.2 itojun #ifdef SIOCSIFMTU /* xxx */
335 1.2 itojun case SIOCGIFMTU:
336 1.2 itojun break;
337 1.2 itojun case SIOCSIFMTU:
338 1.2 itojun {
339 1.2 itojun #ifdef __bsdi__
340 1.2 itojun short mtu;
341 1.2 itojun mtu = *(short *)ifr->ifr_data;
342 1.2 itojun #else
343 1.2 itojun u_long mtu;
344 1.2 itojun mtu = ifr->ifr_mtu;
345 1.2 itojun #endif
346 1.2 itojun if (mtu < GIF_MTU_MIN || mtu > GIF_MTU_MAX) {
347 1.2 itojun return (EINVAL);
348 1.2 itojun }
349 1.2 itojun ifp->if_mtu = mtu;
350 1.2 itojun }
351 1.2 itojun break;
352 1.2 itojun #endif /* SIOCSIFMTU */
353 1.2 itojun
354 1.2 itojun case SIOCSIFPHYADDR:
355 1.2 itojun #ifdef INET6
356 1.2 itojun case SIOCSIFPHYADDR_IN6:
357 1.2 itojun #endif /* INET6 */
358 1.2 itojun #ifdef INET6
359 1.2 itojun if (found_first_ifid)
360 1.2 itojun in6_ifattach(ifp, IN6_IFT_P2P, NULL, 1);
361 1.2 itojun else {
362 1.2 itojun error = ENXIO; /* xxx */
363 1.2 itojun goto bad;
364 1.2 itojun }
365 1.2 itojun #endif /* INET6 */
366 1.2 itojun
367 1.2 itojun switch (ifr->ifr_addr.sa_family) {
368 1.2 itojun #ifdef INET
369 1.2 itojun case AF_INET:
370 1.2 itojun src = (struct sockaddr *)
371 1.2 itojun &(((struct in_aliasreq *)data)->ifra_addr);
372 1.2 itojun dst = (struct sockaddr *)
373 1.2 itojun &(((struct in_aliasreq *)data)->ifra_dstaddr);
374 1.2 itojun
375 1.2 itojun /* only one gif can have dst = INADDR_ANY */
376 1.2 itojun #define satosaddr(sa) (((struct sockaddr_in *)(sa))->sin_addr.s_addr)
377 1.2 itojun
378 1.2 itojun if (satosaddr(dst) == INADDR_ANY) {
379 1.2 itojun int i;
380 1.2 itojun struct gif_softc *sc2;
381 1.2 itojun
382 1.2 itojun for (i = 0, sc2 = gif; i < ngif; i++, sc2++) {
383 1.2 itojun if (sc2 == sc) continue;
384 1.2 itojun if (sc2->gif_pdst &&
385 1.2 itojun satosaddr(sc2->gif_pdst)
386 1.2 itojun == INADDR_ANY) {
387 1.2 itojun error = EADDRNOTAVAIL;
388 1.2 itojun goto bad;
389 1.2 itojun }
390 1.2 itojun }
391 1.2 itojun }
392 1.2 itojun size = sizeof(struct sockaddr_in);
393 1.2 itojun break;
394 1.2 itojun #endif /* INET */
395 1.2 itojun #ifdef INET6
396 1.2 itojun case AF_INET6:
397 1.2 itojun src = (struct sockaddr *)
398 1.2 itojun &(((struct in6_aliasreq *)data)->ifra_addr);
399 1.2 itojun dst = (struct sockaddr *)
400 1.2 itojun &(((struct in6_aliasreq *)data)->ifra_dstaddr);
401 1.2 itojun
402 1.2 itojun /* only one gif can have dst = in6addr_any */
403 1.2 itojun #define satoin6(sa) (&((struct sockaddr_in6 *)(sa))->sin6_addr)
404 1.2 itojun
405 1.2 itojun if (IN6_IS_ADDR_UNSPECIFIED(satoin6(dst))) {
406 1.2 itojun int i;
407 1.2 itojun struct gif_softc *sc2;
408 1.2 itojun
409 1.2 itojun for (i = 0, sc2 = gif; i < ngif; i++, sc2++) {
410 1.2 itojun if (sc2 == sc) continue;
411 1.2 itojun if (sc2->gif_pdst &&
412 1.2 itojun IN6_IS_ADDR_UNSPECIFIED(
413 1.2 itojun satoin6(sc2->gif_pdst)
414 1.2 itojun )) {
415 1.2 itojun error = EADDRNOTAVAIL;
416 1.2 itojun goto bad;
417 1.2 itojun }
418 1.2 itojun }
419 1.2 itojun }
420 1.2 itojun size = sizeof(struct sockaddr_in6);
421 1.2 itojun break;
422 1.2 itojun #endif /* INET6 */
423 1.2 itojun default:
424 1.2 itojun error = EPROTOTYPE;
425 1.2 itojun goto bad;
426 1.2 itojun break;
427 1.2 itojun }
428 1.2 itojun if (sc->gif_psrc != NULL)
429 1.2 itojun free((caddr_t)sc->gif_psrc, M_IFADDR);
430 1.2 itojun if (sc->gif_pdst != NULL)
431 1.2 itojun free((caddr_t)sc->gif_pdst, M_IFADDR);
432 1.2 itojun
433 1.2 itojun sa = (struct sockaddr *)malloc(size, M_IFADDR, M_WAITOK);
434 1.2 itojun bzero((caddr_t)sa, size);
435 1.2 itojun bcopy((caddr_t)src, (caddr_t)sa, size);
436 1.2 itojun sc->gif_psrc = sa;
437 1.2 itojun
438 1.2 itojun sa = (struct sockaddr *)malloc(size, M_IFADDR, M_WAITOK);
439 1.2 itojun bzero((caddr_t)sa, size);
440 1.2 itojun bcopy((caddr_t)dst, (caddr_t)sa, size);
441 1.2 itojun sc->gif_pdst = sa;
442 1.2 itojun
443 1.2 itojun ifp->if_flags |= (IFF_UP|IFF_RUNNING);
444 1.2 itojun if_up(ifp); /* send up RTM_IFINFO */
445 1.2 itojun
446 1.2 itojun break;
447 1.2 itojun
448 1.2 itojun case SIOCGIFPSRCADDR:
449 1.2 itojun #ifdef INET6
450 1.2 itojun case SIOCGIFPSRCADDR_IN6:
451 1.2 itojun #endif /* INET6 */
452 1.2 itojun if (sc->gif_psrc == NULL) {
453 1.2 itojun error = EADDRNOTAVAIL;
454 1.2 itojun goto bad;
455 1.2 itojun }
456 1.2 itojun src = sc->gif_psrc;
457 1.2 itojun switch (sc->gif_psrc->sa_family) {
458 1.2 itojun #ifdef INET
459 1.2 itojun case AF_INET:
460 1.2 itojun dst = &ifr->ifr_addr;
461 1.2 itojun size = sizeof(struct sockaddr_in);
462 1.2 itojun break;
463 1.2 itojun #endif /* INET */
464 1.2 itojun #ifdef INET6
465 1.2 itojun case AF_INET6:
466 1.2 itojun dst = (struct sockaddr *)
467 1.2 itojun &(((struct in6_ifreq *)data)->ifr_addr);
468 1.2 itojun size = sizeof(struct sockaddr_in6);
469 1.2 itojun break;
470 1.2 itojun #endif /* INET6 */
471 1.2 itojun default:
472 1.2 itojun error = EADDRNOTAVAIL;
473 1.2 itojun goto bad;
474 1.2 itojun }
475 1.2 itojun bcopy((caddr_t)src, (caddr_t)dst, size);
476 1.2 itojun break;
477 1.2 itojun
478 1.2 itojun case SIOCGIFPDSTADDR:
479 1.2 itojun #ifdef INET6
480 1.2 itojun case SIOCGIFPDSTADDR_IN6:
481 1.2 itojun #endif /* INET6 */
482 1.2 itojun if (sc->gif_pdst == NULL) {
483 1.2 itojun error = EADDRNOTAVAIL;
484 1.2 itojun goto bad;
485 1.2 itojun }
486 1.2 itojun src = sc->gif_pdst;
487 1.2 itojun switch (sc->gif_pdst->sa_family) {
488 1.2 itojun #ifdef INET
489 1.2 itojun case AF_INET:
490 1.2 itojun dst = &ifr->ifr_addr;
491 1.2 itojun size = sizeof(struct sockaddr_in);
492 1.2 itojun break;
493 1.2 itojun #endif /* INET */
494 1.2 itojun #ifdef INET6
495 1.2 itojun case AF_INET6:
496 1.2 itojun dst = (struct sockaddr *)
497 1.2 itojun &(((struct in6_ifreq *)data)->ifr_addr);
498 1.2 itojun size = sizeof(struct sockaddr_in6);
499 1.2 itojun break;
500 1.2 itojun #endif /* INET6 */
501 1.2 itojun default:
502 1.2 itojun error = EADDRNOTAVAIL;
503 1.2 itojun goto bad;
504 1.2 itojun }
505 1.2 itojun bcopy((caddr_t)src, (caddr_t)dst, size);
506 1.2 itojun break;
507 1.2 itojun
508 1.2 itojun case SIOCSIFFLAGS:
509 1.2 itojun break;
510 1.2 itojun
511 1.2 itojun default:
512 1.2 itojun error = EINVAL;
513 1.2 itojun break;
514 1.2 itojun }
515 1.2 itojun bad:
516 1.2 itojun return error;
517 1.2 itojun }
518 1.2 itojun #endif /*NGIF > 0*/
519