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