2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.6 2001/07/24 19:10:18 brooks Exp $ */
23 /* $KAME: if_gif.c,v 1.47 2001/05/01 05:28:42 itojun Exp $ */
26 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. Neither the name of the project nor the names of its contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/kernel.h>
57 #include <sys/malloc.h>
59 #include <sys/socket.h>
60 #include <sys/sockio.h>
61 #include <sys/errno.h>
63 #include <sys/syslog.h>
64 #include <sys/protosw.h>
65 #include <kern/cpu_number.h>
68 #include <net/if_types.h>
69 #include <net/netisr.h>
70 #include <net/route.h>
73 #include <netinet/in.h>
74 #include <netinet/in_systm.h>
75 #include <netinet/ip.h>
77 #include <netinet/in_var.h>
78 #include <netinet/in_gif.h>
79 #include <netinet/ip_var.h>
83 #include <netinet6/in6_var.h>
84 #include <netinet/ip6.h>
85 #include <netinet6/ip6_var.h>
86 #include <netinet6/in6_gif.h>
87 #include <netinet6/ip6protosw.h>
90 #include <netinet/ip_encap.h>
92 #include <net/if_gif.h>
94 #include <net/net_osdep.h>
97 #define GIFDEV "if_gif"
98 #define GIF_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */
101 static MALLOC_DEFINE(M_GIF
, "gif", "Generic Tunnel Interface");
104 TAILQ_HEAD(gifhead
, gif_softc
) gifs
= TAILQ_HEAD_INITIALIZER(gifs
);
107 void gifattach
__P((void));
108 int gif_pre_output
__P((struct ifnet
*, register struct mbuf
**, struct sockaddr
*,
109 caddr_t
, char *, char *, u_long
));
110 static void gif_create_dev(void);
111 static int gif_encapcheck(const struct mbuf
*, int, int, void*);
114 int ngif
= 0; /* number of interfaces */
118 struct protosw in_gif_protosw
=
119 { SOCK_RAW
, 0, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC
|PR_ADDR
,
120 in_gif_input
, 0, 0, 0,
128 struct ip6protosw in6_gif_protosw
=
129 { SOCK_RAW
, 0, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC
|PR_ADDR
,
141 * This macro controls the upper limitation on nesting of gif tunnels.
142 * Since, setting a large value to this macro with a careless configuration
143 * may introduce system crash, we don't allow any nestings by default.
144 * If you need to configure nested gif tunnels, you can define this macro
145 * in your kernel configuration file. However, if you do so, please be
146 * careful to configure the tunnels so that it won't make a loop.
148 #define MAX_GIF_NEST 1
150 static int max_gif_nesting
= MAX_GIF_NEST
;
156 * Theory of operation: initially, one gif interface is created.
157 * Any time a gif interface is configured, if there are no other
158 * unconfigured gif interfaces, a new gif interface is created.
159 * BSD uses the clone mechanism to dynamically create more
162 * We have some extra glue to support DLIL.
165 /* GIF interface module support */
166 int gif_demux(ifp
, m
, frame_header
, proto
)
170 struct if_proto
**proto
;
172 struct gif_softc
* gif
= (struct gif_softc
*)ifp
->if_softc
;
174 /* Only one protocol may be attached to a gif interface. */
175 *proto
= gif
->gif_proto
;
181 int gif_add_if(struct ifnet
*ifp
)
183 ifp
->if_demux
= gif_demux
;
189 int gif_del_if(struct ifnet
*ifp
)
195 int gif_add_proto(struct ddesc_head_str
*desc_head
, struct if_proto
*proto
, u_long dl_tag
)
197 /* Only one protocol may be attached at a time */
198 struct gif_softc
* gif
= (struct gif_softc
*)proto
->ifp
;
200 if (gif
->gif_proto
!= NULL
)
201 printf("gif_add_proto: request add_proto for gif%d\n", gif
->gif_if
.if_unit
);
203 gif
->gif_proto
= proto
;
209 int gif_del_proto(struct if_proto
*proto
, u_long dl_tag
)
211 if (((struct gif_softc
*)proto
->ifp
)->gif_proto
== proto
)
212 ((struct gif_softc
*)proto
->ifp
)->gif_proto
= NULL
;
224 void gif_reg_if_mods()
226 struct dlil_ifmod_reg_str gif_ifmod
;
228 bzero(&gif_ifmod
, sizeof(gif_ifmod
));
229 gif_ifmod
.add_if
= gif_add_if
;
230 gif_ifmod
.del_if
= gif_del_if
;
231 gif_ifmod
.add_proto
= gif_add_proto
;
232 gif_ifmod
.del_proto
= gif_del_proto
;
233 gif_ifmod
.ifmod_ioctl
= 0;
234 gif_ifmod
.shutdown
= gif_shutdown
;
236 if (dlil_reg_if_modules(APPLE_IF_FAM_GIF
, &gif_ifmod
))
237 panic("Couldn't register gif modules\n");
241 /* Glue code to attach inet to a gif interface through DLIL */
243 u_long
gif_attach_proto_family(struct ifnet
*ifp
, int af
)
245 struct dlil_proto_reg_str reg
;
246 struct dlil_demux_desc desc
;
251 /* Check if we're already attached */
252 stat
= dlil_find_dltag(ifp
->if_family
, ifp
->if_unit
, af
, &dl_tag
);
256 TAILQ_INIT(®
.demux_desc_head
);
257 desc
.type
= DLIL_DESC_RAW
;
258 desc
.variants
.bitmask
.proto_id_length
= 0;
259 desc
.variants
.bitmask
.proto_id
= 0;
260 desc
.variants
.bitmask
.proto_id_mask
= 0;
261 desc
.native_type
= (char *) &native
;
262 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
263 reg
.interface_family
= ifp
->if_family
;
264 reg
.unit_number
= ifp
->if_unit
;
265 reg
.input
= gif_input
;
266 reg
.pre_output
= gif_pre_output
;
270 reg
.default_proto
= 0;
271 reg
.protocol_family
= af
;
273 stat
= dlil_attach_protocol(®
, &dl_tag
);
275 panic("gif_attach_proto_family can't attach interface fam=%d\n", af
);
281 u_long
gif_detach_proto_family(struct ifnet
*ifp
, int af
)
283 u_long ip_dl_tag
= 0;
286 stat
= dlil_find_dltag(ifp
->if_family
, ifp
->if_unit
, af
, &ip_dl_tag
);
288 stat
= dlil_detach_protocol(ip_dl_tag
);
290 printf("WARNING: gif_detach can't detach IP fam=%d from interface\n", af
);
296 int gif_attach_inet(struct ifnet
*ifp
, u_long
*dl_tag
) {
297 *dl_tag
= gif_attach_proto_family(ifp
, AF_INET
);
301 int gif_detach_inet(struct ifnet
*ifp
, u_long dl_tag
) {
302 gif_detach_proto_family(ifp
, AF_INET
);
306 int gif_attach_inet6(struct ifnet
*ifp
, u_long
*dl_tag
) {
307 *dl_tag
= gif_attach_proto_family(ifp
, AF_INET6
);
311 int gif_detach_inet6(struct ifnet
*ifp
, u_long dl_tag
) {
312 gif_detach_proto_family(ifp
, AF_INET6
);
317 /* Function to setup the first gif interface */
321 struct dlil_protomod_reg_str gif_protoreg
;
324 /* Init the list of interfaces */
327 gif_reg_if_mods(); /* DLIL modules */
329 /* Register protocol registration functions */
331 bzero(&gif_protoreg
, sizeof(gif_protoreg
));
332 gif_protoreg
.attach_proto
= gif_attach_inet
;
333 gif_protoreg
.detach_proto
= gif_detach_inet
;
335 if ( error
= dlil_reg_proto_module(AF_INET
, APPLE_IF_FAM_GIF
, &gif_protoreg
) != 0)
336 printf("dlil_reg_proto_module failed for AF_INET error=%d\n", error
);
338 gif_protoreg
.attach_proto
= gif_attach_inet6
;
339 gif_protoreg
.detach_proto
= gif_detach_inet6
;
341 if ( error
= dlil_reg_proto_module(AF_INET6
, APPLE_IF_FAM_GIF
, &gif_protoreg
) != 0)
342 printf("dlil_reg_proto_module failed for AF_INET6 error=%d\n", error
);
345 /* Create first device */
349 /* Creates another gif device if there are none free */
353 struct gif_softc
*sc
;
356 /* Can't create more than GIF_MAXUNIT */
357 if (ngif
>= GIF_MAXUNIT
)
360 /* Check for unused gif interface */
361 TAILQ_FOREACH(sc
, &gifs
, gif_link
) {
362 /* If unused, return, no need to create a new interface */
363 if ((sc
->gif_if
.if_flags
& IFF_RUNNING
) == 0)
367 sc
= _MALLOC(sizeof(struct gif_softc
), M_DEVBUF
, M_WAITOK
);
369 log(LOG_ERR
, "gifattach: failed to allocate gif%d\n", ngif
);
373 bzero(sc
, sizeof(struct gif_softc
));
374 sc
->gif_if
.if_softc
= sc
;
375 sc
->gif_if
.if_name
= GIFNAME
;
376 sc
->gif_if
.if_unit
= ngif
;
378 sc
->encap_cookie4
= sc
->encap_cookie6
= NULL
;
380 sc
->encap_cookie4
= encap_attach_func(AF_INET
, -1,
381 gif_encapcheck
, &in_gif_protosw
, sc
);
382 if (sc
->encap_cookie4
== NULL
) {
383 printf("%s: unable to attach encap4\n", if_name(&sc
->gif_if
));
389 sc
->encap_cookie6
= encap_attach_func(AF_INET6
, -1,
390 gif_encapcheck
, (struct protosw
*)&in6_gif_protosw
, sc
);
391 if (sc
->encap_cookie6
== NULL
) {
392 if (sc
->encap_cookie4
) {
393 encap_detach(sc
->encap_cookie4
);
394 sc
->encap_cookie4
= NULL
;
396 printf("%s: unable to attach encap6\n", if_name(&sc
->gif_if
));
402 sc
->gif_if
.if_family
= APPLE_IF_FAM_GIF
;
403 sc
->gif_if
.if_mtu
= GIF_MTU
;
404 sc
->gif_if
.if_flags
= IFF_POINTOPOINT
| IFF_MULTICAST
;
406 /* turn off ingress filter */
407 sc
->gif_if
.if_flags
|= IFF_LINK2
;
409 sc
->gif_if
.if_ioctl
= gif_ioctl
;
410 sc
->gif_if
.if_output
= NULL
; /* pre_output returns error or EJUSTRETURN */
411 sc
->gif_if
.if_type
= IFT_GIF
;
412 dlil_if_attach(&sc
->gif_if
);
413 bpfattach(&sc
->gif_if
, DLT_NULL
, sizeof(u_int
));
414 TAILQ_INSERT_TAIL(&gifs
, sc
, gif_link
);
419 gif_encapcheck(m
, off
, proto
, arg
)
420 const struct mbuf
*m
;
426 struct gif_softc
*sc
;
428 sc
= (struct gif_softc
*)arg
;
432 if ((sc
->gif_if
.if_flags
& IFF_UP
) == 0)
435 /* no physical address */
436 if (!sc
->gif_psrc
|| !sc
->gif_pdst
)
452 /* LINTED const cast */
453 m_copydata((struct mbuf
*)m
, 0, sizeof(ip
), (caddr_t
)&ip
);
458 if (sc
->gif_psrc
->sa_family
!= AF_INET
||
459 sc
->gif_pdst
->sa_family
!= AF_INET
)
461 return gif_encapcheck4(m
, off
, proto
, arg
);
465 if (sc
->gif_psrc
->sa_family
!= AF_INET6
||
466 sc
->gif_pdst
->sa_family
!= AF_INET6
)
468 return gif_encapcheck6(m
, off
, proto
, arg
);
476 gif_pre_output(ifp
, m0
, dst
, rt
, frame
, address
, dl_tag
)
479 struct sockaddr
*dst
;
485 struct gif_softc
*sc
= (struct gif_softc
*)ifp
;
486 register struct mbuf
* m
= *m0
;
488 static int called
= 0; /* XXX: MUTEX */
491 * gif may cause infinite recursion calls when misconfigured.
492 * We'll prevent this by introducing upper limit.
493 * XXX: this mechanism may introduce another problem about
494 * mutual exclusion of the variable CALLED, especially if we
497 if (++called
> max_gif_nesting
) {
499 "gif_output: recursively called too many times(%d)\n",
501 m_freem(m
); /* free it here not in dlil_output*/
502 error
= EIO
; /* is there better errno? */
506 getmicrotime(&ifp
->if_lastchange
);
507 m
->m_flags
&= ~(M_BCAST
|M_MCAST
);
508 if (!(ifp
->if_flags
& IFF_UP
) ||
509 sc
->gif_psrc
== NULL
|| sc
->gif_pdst
== NULL
) {
510 m_freem(m
); /* free it here not in dlil_output */
517 * We need to prepend the address family as
518 * a four byte field. Cons up a dummy header
519 * to pacify bpf. This is safe because bpf
520 * will only read from the mbuf (i.e., it won't
521 * try to free it or keep a pointer a to it).
524 u_int32_t af
= dst
->sa_family
;
528 m0
.m_data
= (char *)&af
;
533 ifp
->if_obytes
+= m
->m_pkthdr
.len
;
535 /* inner AF-specific encapsulation */
537 /* XXX should we check if our outer source is legal? */
539 /* dispatch to output logic based on outer AF */
540 switch (sc
->gif_psrc
->sa_family
) {
543 error
= in_gif_output(ifp
, dst
->sa_family
, m
, (struct rtentry
*)rt
);
548 error
= in6_gif_output(ifp
, dst
->sa_family
, m
, (struct rtentry
*)rt
);
557 called
= 0; /* reset recursion counter */
559 /* the mbuf was freed either by in_gif_output or in here */
560 *m0
= NULL
; /* avoid getting dlil_output freeing it */
564 error
= EJUSTRETURN
; /* if no error, packet got sent already */
569 gif_input(m
, frame_header
, gifp
, dl_tag
, sync_ok
)
577 struct ifqueue
*ifq
= 0;
586 /* Assume packet is of type of protocol attached to this interface */
587 af
= ((struct gif_softc
*)(gifp
->if_softc
))->gif_proto
->protocol_family
;
589 if (m
->m_pkthdr
.rcvif
)
590 m
->m_pkthdr
.rcvif
= gifp
;
594 * We need to prepend the address family as
595 * a four byte field. Cons up a dummy header
596 * to pacify bpf. This is safe because bpf
597 * will only read from the mbuf (i.e., it won't
598 * try to free it or keep a pointer a to it).
605 m0
.m_data
= (char *)&af1
;
611 * Put the packet to the network layer input queue according to the
612 * specified address family.
613 * Note: older versions of gif_input directly called network layer
614 * input functions, e.g. ip6_input, here. We changed the policy to
615 * prevent too many recursive calls of such input functions, which
616 * might cause kernel panic. But the change may introduce another
617 * problem; if the input queue is full, packets are discarded.
618 * We believed it rarely occurs and changed the policy. If we find
619 * it occurs more times than we thought, we may change the policy
637 return (EJUSTRETURN
);
642 IF_DROP(ifq
); /* update statistics */
645 return (EJUSTRETURN
);
648 /* we need schednetisr since the address family may change */
651 gifp
->if_ibytes
+= m
->m_pkthdr
.len
;
657 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
659 gif_ioctl(ifp
, cmd
, data
)
664 struct gif_softc
*sc
= (struct gif_softc
*)ifp
;
665 struct ifreq
*ifr
= (struct ifreq
*)data
;
667 struct sockaddr
*dst
, *src
;
671 struct gif_softc
*sc2
;
684 #ifdef SIOCSIFMTU /* xxx */
692 if (mtu
< GIF_MTU_MIN
|| mtu
> GIF_MTU_MAX
) {
698 #endif /* SIOCSIFMTU */
702 case SIOCSIFPHYADDR_IN6
:
704 case SIOCSLIFPHYADDR
:
708 src
= (struct sockaddr
*)
709 &(((struct in_aliasreq
*)data
)->ifra_addr
);
710 dst
= (struct sockaddr
*)
711 &(((struct in_aliasreq
*)data
)->ifra_dstaddr
);
715 case SIOCSIFPHYADDR_IN6
:
716 src
= (struct sockaddr
*)
717 &(((struct in6_aliasreq
*)data
)->ifra_addr
);
718 dst
= (struct sockaddr
*)
719 &(((struct in6_aliasreq
*)data
)->ifra_dstaddr
);
722 case SIOCSLIFPHYADDR
:
723 src
= (struct sockaddr
*)
724 &(((struct if_laddrreq
*)data
)->addr
);
725 dst
= (struct sockaddr
*)
726 &(((struct if_laddrreq
*)data
)->dstaddr
);
729 /* sa_family must be equal */
730 if (src
->sa_family
!= dst
->sa_family
)
733 /* validate sa_len */
734 switch (src
->sa_family
) {
737 if (src
->sa_len
!= sizeof(struct sockaddr_in
))
743 if (src
->sa_len
!= sizeof(struct sockaddr_in6
))
750 switch (dst
->sa_family
) {
753 if (dst
->sa_len
!= sizeof(struct sockaddr_in
))
759 if (dst
->sa_len
!= sizeof(struct sockaddr_in6
))
767 /* check sa_family looks sane for the cmd */
770 if (src
->sa_family
== AF_INET
)
774 case SIOCSIFPHYADDR_IN6
:
775 if (src
->sa_family
== AF_INET6
)
779 case SIOCSLIFPHYADDR
:
780 /* checks done in the above */
784 TAILQ_FOREACH(ifp2
, &ifnet
, if_link
) {
785 if (strcmp(ifp2
->if_name
, GIFNAME
) != 0)
787 sc2
= ifp2
->if_softc
;
790 if (!sc2
->gif_pdst
|| !sc2
->gif_psrc
)
792 if (sc2
->gif_pdst
->sa_family
!= dst
->sa_family
||
793 sc2
->gif_pdst
->sa_len
!= dst
->sa_len
||
794 sc2
->gif_psrc
->sa_family
!= src
->sa_family
||
795 sc2
->gif_psrc
->sa_len
!= src
->sa_len
)
798 /* can't configure same pair of address onto two gifs */
799 if (bcmp(sc2
->gif_pdst
, dst
, dst
->sa_len
) == 0 &&
800 bcmp(sc2
->gif_psrc
, src
, src
->sa_len
) == 0) {
801 error
= EADDRNOTAVAIL
;
806 /* can't configure multiple multi-dest interfaces */
807 #define multidest(x) \
808 (((struct sockaddr_in *)(x))->sin_addr.s_addr == INADDR_ANY)
810 #define multidest6(x) \
811 (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)(x))->sin6_addr))
813 if (dst
->sa_family
== AF_INET
&&
814 multidest(dst
) && multidest(sc2
->gif_pdst
)) {
815 error
= EADDRNOTAVAIL
;
819 if (dst
->sa_family
== AF_INET6
&&
820 multidest6(dst
) && multidest6(sc2
->gif_pdst
)) {
821 error
= EADDRNOTAVAIL
;
828 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
829 sa
= (struct sockaddr
*)_MALLOC(src
->sa_len
, M_IFADDR
, M_WAITOK
);
830 bcopy((caddr_t
)src
, (caddr_t
)sa
, src
->sa_len
);
834 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
835 sa
= (struct sockaddr
*)_MALLOC(dst
->sa_len
, M_IFADDR
, M_WAITOK
);
836 bcopy((caddr_t
)dst
, (caddr_t
)sa
, dst
->sa_len
);
839 ifp
->if_flags
|= IFF_RUNNING
;
841 gif_attach_proto_family(ifp
, src
->sa_family
);
844 if_up(ifp
); /* mark interface UP and send up RTM_IFINFO */
846 /* Make sure at least one unused device is still available */
854 #ifdef SIOCDIFPHYADDR
857 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
861 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
864 /* change the IFF_{UP, RUNNING} flag as well? */
868 case SIOCGIFPSRCADDR
:
870 case SIOCGIFPSRCADDR_IN6
:
872 if (sc
->gif_psrc
== NULL
) {
873 error
= EADDRNOTAVAIL
;
879 case SIOCGIFPSRCADDR
:
880 dst
= &ifr
->ifr_addr
;
881 size
= sizeof(ifr
->ifr_addr
);
885 case SIOCGIFPSRCADDR_IN6
:
886 dst
= (struct sockaddr
*)
887 &(((struct in6_ifreq
*)data
)->ifr_addr
);
888 size
= sizeof(((struct in6_ifreq
*)data
)->ifr_addr
);
892 error
= EADDRNOTAVAIL
;
895 if (src
->sa_len
> size
)
897 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
900 case SIOCGIFPDSTADDR
:
902 case SIOCGIFPDSTADDR_IN6
:
904 if (sc
->gif_pdst
== NULL
) {
905 error
= EADDRNOTAVAIL
;
911 case SIOCGIFPDSTADDR
:
912 dst
= &ifr
->ifr_addr
;
913 size
= sizeof(ifr
->ifr_addr
);
917 case SIOCGIFPDSTADDR_IN6
:
918 dst
= (struct sockaddr
*)
919 &(((struct in6_ifreq
*)data
)->ifr_addr
);
920 size
= sizeof(((struct in6_ifreq
*)data
)->ifr_addr
);
924 error
= EADDRNOTAVAIL
;
927 if (src
->sa_len
> size
)
929 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
932 case SIOCGLIFPHYADDR
:
933 if (sc
->gif_psrc
== NULL
|| sc
->gif_pdst
== NULL
) {
934 error
= EADDRNOTAVAIL
;
940 dst
= (struct sockaddr
*)
941 &(((struct if_laddrreq
*)data
)->addr
);
942 size
= sizeof(((struct if_laddrreq
*)data
)->addr
);
943 if (src
->sa_len
> size
)
945 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
949 dst
= (struct sockaddr
*)
950 &(((struct if_laddrreq
*)data
)->dstaddr
);
951 size
= sizeof(((struct if_laddrreq
*)data
)->dstaddr
);
952 if (src
->sa_len
> size
)
954 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
958 /* if_ioctl() takes care of it */
970 gif_delete_tunnel(sc
)
971 struct gif_softc
*sc
;
973 /* XXX: NetBSD protects this function with splsoftnet() */
976 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
980 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
983 /* change the IFF_UP flag as well? */