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