2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.6 2001/07/24 19:10:18 brooks Exp $ */
29 /* $KAME: if_gif.c,v 1.47 2001/05/01 05:28:42 itojun Exp $ */
32 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the project nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * NOTICE: This file was modified by SPARTA, Inc. in 2006 to introduce
61 * support for mandatory and extensible security protections. This notice
62 * is included in support of clause 2.2 (b) of the Apple Public License,
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/malloc.h>
71 #include <sys/socket.h>
72 #include <sys/sockio.h>
73 #include <sys/errno.h>
75 #include <sys/syslog.h>
76 #include <sys/protosw.h>
77 #include <kern/cpu_number.h>
78 #include <kern/zalloc.h>
81 #include <net/if_types.h>
82 #include <net/route.h>
84 #include <net/kpi_protocol.h>
85 #include <net/kpi_interface.h>
88 #include <netinet/in.h>
89 #include <netinet/in_systm.h>
90 #include <netinet/ip.h>
92 #include <netinet/in_var.h>
93 #include <netinet/in_gif.h>
94 #include <netinet/ip_var.h>
98 #include <netinet6/in6_var.h>
99 #include <netinet/ip6.h>
100 #include <netinet6/ip6_var.h>
101 #include <netinet6/in6_gif.h>
102 #include <netinet6/ip6protosw.h>
105 #include <netinet/ip_encap.h>
106 #include <net/dlil.h>
107 #include <net/if_gif.h>
109 #include <net/net_osdep.h>
112 #include <security/mac_framework.h>
115 #define GIFNAME "gif"
116 #define GIFDEV "if_gif"
118 #define GIF_MAXUNIT IF_MAXUNIT
119 #define GIF_ZONE_MAX_ELEM MIN(IFNETS_MAX, GIF_MAXUNIT)
121 /* gif lock variables */
122 static lck_grp_t
*gif_mtx_grp
;
123 static lck_grp_attr_t
*gif_mtx_grp_attr
;
124 static lck_attr_t
*gif_mtx_attr
;
125 decl_lck_mtx_data(static, gif_mtx_data
);
126 static lck_mtx_t
*gif_mtx
= &gif_mtx_data
;
128 TAILQ_HEAD(gifhead
, gif_softc
) gifs
= TAILQ_HEAD_INITIALIZER(gifs
);
130 static int gif_encapcheck(const struct mbuf
*, int, int, void *);
131 static errno_t
gif_output(ifnet_t ifp
, mbuf_t m
);
132 static errno_t
gif_input(ifnet_t ifp
, protocol_family_t protocol_family
,
133 mbuf_t m
, char *frame_header
);
134 static errno_t
gif_ioctl(ifnet_t ifp
, u_long cmd
, void *data
);
136 static int ngif
= 0; /* number of interfaces */
139 static struct protosw in_gif_protosw
=
142 .pr_protocol
= 0, /* IPPROTO_IPV[46] */
143 .pr_flags
= PR_ATOMIC
| PR_ADDR
,
144 .pr_input
= in_gif_input
,
145 .pr_usrreqs
= &rip_usrreqs
,
146 .pr_unlock
= rip_unlock
,
150 static struct ip6protosw in6_gif_protosw
=
153 .pr_protocol
= 0, /* IPPROTO_IPV[46] */
154 .pr_flags
= PR_ATOMIC
| PR_ADDR
,
155 .pr_input
= in6_gif_input
,
156 .pr_usrreqs
= &rip6_usrreqs
,
157 .pr_unlock
= rip_unlock
,
161 static int gif_remove(struct ifnet
*);
162 static int gif_clone_create(struct if_clone
*, uint32_t, void *);
163 static int gif_clone_destroy(struct ifnet
*);
164 static void gif_delete_tunnel(struct gif_softc
*);
165 static void gif_detach(struct ifnet
*);
167 static struct if_clone gif_cloner
=
168 IF_CLONE_INITIALIZER(GIFNAME
, gif_clone_create
, gif_clone_destroy
,
169 0, GIF_MAXUNIT
, GIF_ZONE_MAX_ELEM
, sizeof(struct gif_softc
));
171 * Theory of operation: initially, one gif interface is created.
172 * Any time a gif interface is configured, if there are no other
173 * unconfigured gif interfaces, a new gif interface is created.
174 * BSD uses the clone mechanism to dynamically create more
177 * We have some extra glue to support DLIL.
180 /* GIF interface module support */
185 __unused
char *frame_header
,
186 protocol_family_t
*protocol_family
)
188 struct gif_softc
*sc
= ifnet_softc(ifp
);
191 /* Only one protocol may be attached to a gif interface. */
192 *protocol_family
= sc
->gif_proto
;
201 protocol_family_t protocol_family
,
202 __unused
const struct ifnet_demux_desc
*demux_array
,
203 __unused u_int32_t demux_count
)
205 /* Only one protocol may be attached at a time */
206 struct gif_softc
*sc
= ifnet_softc(ifp
);
209 if (sc
->gif_proto
!= 0) {
210 printf("gif_add_proto: request add_proto for gif%d\n",
214 sc
->gif_proto
= protocol_family
;
223 protocol_family_t protocol_family
)
225 struct gif_softc
*sc
= ifnet_softc(ifp
);
228 if (sc
->gif_proto
== protocol_family
) {
236 /* Glue code to attach inet to a gif interface through DLIL */
238 gif_attach_proto_family(
240 protocol_family_t protocol_family
)
242 struct ifnet_attach_proto_param reg
;
245 bzero(®
, sizeof(reg
));
246 reg
.input
= gif_input
;
248 stat
= ifnet_attach_protocol(ifp
, protocol_family
, ®
);
249 if (stat
&& stat
!= EEXIST
) {
250 printf("gif_attach_proto_family can't attach interface \
251 fam=%d\n", protocol_family
);
257 /* Function to setup the first gif interface */
263 /* Initialize the list of interfaces */
266 /* Initialize the gif global lock */
267 gif_mtx_grp_attr
= lck_grp_attr_alloc_init();
268 gif_mtx_grp
= lck_grp_alloc_init("gif", gif_mtx_grp_attr
);
269 gif_mtx_attr
= lck_attr_alloc_init();
270 lck_mtx_init(gif_mtx
, gif_mtx_grp
, gif_mtx_attr
);
272 /* Register protocol registration functions */
273 result
= proto_register_plumber(PF_INET
, APPLE_IF_FAM_GIF
,
274 gif_attach_proto_family
, NULL
);
276 printf("proto_register_plumber failed for AF_INET error=%d\n",
280 result
= proto_register_plumber(PF_INET6
, APPLE_IF_FAM_GIF
,
281 gif_attach_proto_family
, NULL
);
283 printf("proto_register_plumber failed for AF_INET6 error=%d\n",
287 result
= if_clone_attach(&gif_cloner
);
289 panic("%s: if_clone_attach() failed, error %d\n", __func__
, result
);
292 gif_clone_create(&gif_cloner
, 0, NULL
);
299 bpf_packet_func callback
)
301 struct gif_softc
*sc
= ifnet_softc(ifp
);
305 sc
->tap_callback
= callback
;
312 gif_detach(struct ifnet
*ifp
)
314 struct gif_softc
*sc
= ifp
->if_softc
;
315 lck_mtx_destroy(&sc
->gif_lock
, gif_mtx_grp
);
316 if_clone_softc_deallocate(&gif_cloner
, sc
);
317 ifp
->if_softc
= NULL
;
318 (void) ifnet_release(ifp
);
322 gif_clone_create(struct if_clone
*ifc
, uint32_t unit
, __unused
void *params
)
324 struct gif_softc
*sc
= NULL
;
325 struct ifnet_init_eparams gif_init_params
;
328 lck_mtx_lock(gif_mtx
);
330 /* Can't create more than GIF_MAXUNIT */
331 if (ngif
>= GIF_MAXUNIT
) {
336 sc
= if_clone_softc_allocate(&gif_cloner
);
338 log(LOG_ERR
, "gif_clone_create: failed to allocate gif%d\n",
344 /* use the interface name as the unique id for ifp recycle */
345 snprintf(sc
->gif_ifname
, sizeof(sc
->gif_ifname
), "%s%d",
346 ifc
->ifc_name
, unit
);
348 lck_mtx_init(&sc
->gif_lock
, gif_mtx_grp
, gif_mtx_attr
);
350 bzero(&gif_init_params
, sizeof(gif_init_params
));
351 gif_init_params
.ver
= IFNET_INIT_CURRENT_VERSION
;
352 gif_init_params
.len
= sizeof(gif_init_params
);
353 gif_init_params
.flags
= IFNET_INIT_LEGACY
;
354 gif_init_params
.uniqueid
= sc
->gif_ifname
;
355 gif_init_params
.uniqueid_len
= strlen(sc
->gif_ifname
);
356 gif_init_params
.name
= GIFNAME
;
357 gif_init_params
.unit
= unit
;
358 gif_init_params
.type
= IFT_GIF
;
359 gif_init_params
.family
= IFNET_FAMILY_GIF
;
360 gif_init_params
.output
= gif_output
;
361 gif_init_params
.demux
= gif_demux
;
362 gif_init_params
.add_proto
= gif_add_proto
;
363 gif_init_params
.del_proto
= gif_del_proto
;
364 gif_init_params
.softc
= sc
;
365 gif_init_params
.ioctl
= gif_ioctl
;
366 gif_init_params
.set_bpf_tap
= gif_set_bpf_tap
;
367 gif_init_params
.detach
= gif_detach
;
369 error
= ifnet_allocate_extended(&gif_init_params
, &sc
->gif_if
);
371 printf("gif_clone_create, ifnet_allocate failed - %d\n", error
);
372 if_clone_softc_deallocate(&gif_cloner
, sc
);
377 sc
->encap_cookie4
= sc
->encap_cookie6
= NULL
;
379 sc
->encap_cookie4
= encap_attach_func(AF_INET
, -1,
380 gif_encapcheck
, &in_gif_protosw
, sc
);
381 if (sc
->encap_cookie4
== NULL
) {
382 printf("%s: unable to attach encap4\n", if_name(sc
->gif_if
));
383 ifnet_release(sc
->gif_if
);
384 if_clone_softc_deallocate(&gif_cloner
, sc
);
390 sc
->encap_cookie6
= encap_attach_func(AF_INET6
, -1,
391 gif_encapcheck
, (struct protosw
*)&in6_gif_protosw
, sc
);
392 if (sc
->encap_cookie6
== NULL
) {
393 if (sc
->encap_cookie4
) {
394 encap_detach(sc
->encap_cookie4
);
395 sc
->encap_cookie4
= NULL
;
397 printf("%s: unable to attach encap6\n", if_name(sc
->gif_if
));
398 ifnet_release(sc
->gif_if
);
399 if_clone_softc_deallocate(&gif_cloner
, sc
);
405 ifnet_set_mtu(sc
->gif_if
, GIF_MTU
);
406 ifnet_set_flags(sc
->gif_if
, IFF_POINTOPOINT
| IFF_MULTICAST
, 0xffff);
408 /* turn off ingress filter */
409 sc
->gif_if
.if_flags
|= IFF_LINK2
;
411 sc
->gif_flags
|= IFGIF_DETACHING
;
412 error
= ifnet_attach(sc
->gif_if
, NULL
);
414 printf("gif_clone_create - ifnet_attach failed - %d\n", error
);
415 ifnet_release(sc
->gif_if
);
416 if (sc
->encap_cookie4
) {
417 encap_detach(sc
->encap_cookie4
);
418 sc
->encap_cookie4
= NULL
;
420 if (sc
->encap_cookie6
) {
421 encap_detach(sc
->encap_cookie6
);
422 sc
->encap_cookie6
= NULL
;
424 if_clone_softc_deallocate(&gif_cloner
, sc
);
428 mac_ifnet_label_init(&sc
->gif_if
);
430 bpfattach(sc
->gif_if
, DLT_NULL
, sizeof(u_int
));
431 sc
->gif_flags
&= ~IFGIF_DETACHING
;
432 TAILQ_INSERT_TAIL(&gifs
, sc
, gif_link
);
435 lck_mtx_unlock(gif_mtx
);
441 gif_remove(struct ifnet
*ifp
)
444 struct gif_softc
*sc
= NULL
;
445 const struct encaptab
*encap_cookie4
= NULL
;
446 const struct encaptab
*encap_cookie6
= NULL
;
448 lck_mtx_lock(gif_mtx
);
457 if (sc
->gif_flags
& IFGIF_DETACHING
) {
462 sc
->gif_flags
|= IFGIF_DETACHING
;
463 TAILQ_REMOVE(&gifs
, sc
, gif_link
);
466 gif_delete_tunnel(sc
);
468 encap_cookie6
= sc
->encap_cookie6
;
471 encap_cookie4
= sc
->encap_cookie4
;
477 lck_mtx_unlock(gif_mtx
);
479 if (encap_cookie6
!= NULL
) {
480 error
= encap_detach(encap_cookie6
);
481 KASSERT(error
== 0, ("gif_clone_destroy: Unexpected "
482 "error detaching encap_cookie6"));
485 if (encap_cookie4
!= NULL
) {
486 error
= encap_detach(encap_cookie4
);
487 KASSERT(error
== 0, ("gif_clone_destroy: Unexpected "
488 "error detaching encap_cookie4"));
495 gif_clone_destroy(struct ifnet
*ifp
)
499 error
= gif_remove(ifp
);
501 printf("gif_clone_destroy: gif remove failed %d\n", error
);
505 error
= ifnet_set_flags(ifp
, 0, IFF_UP
);
507 printf("gif_clone_destroy: ifnet_set_flags failed %d\n", error
);
510 error
= ifnet_detach(ifp
);
512 panic("gif_clone_destroy: ifnet_detach(%p) failed %d\n", ifp
,
520 const struct mbuf
*m
,
527 struct gif_softc
*sc
;
529 sc
= (struct gif_softc
*)arg
;
535 if ((ifnet_flags(sc
->gif_if
) & IFF_UP
) == 0) {
539 /* no physical address */
540 if (!sc
->gif_psrc
|| !sc
->gif_pdst
) {
557 mbuf_copydata((struct mbuf
*)(size_t)m
, 0, sizeof(ip
), &ip
);
562 if (sc
->gif_psrc
->sa_family
!= AF_INET
||
563 sc
->gif_pdst
->sa_family
!= AF_INET
) {
566 error
= gif_encapcheck4(m
, off
, proto
, arg
);
570 if (sc
->gif_psrc
->sa_family
!= AF_INET6
||
571 sc
->gif_pdst
->sa_family
!= AF_INET6
) {
574 error
= gif_encapcheck6(m
, off
, proto
, arg
);
589 struct gif_softc
*sc
= ifnet_softc(ifp
);
590 struct sockaddr
*gif_psrc
;
591 struct sockaddr
*gif_pdst
;
595 gif_psrc
= sc
->gif_psrc
;
596 gif_pdst
= sc
->gif_pdst
;
600 * max_gif_nesting check used to live here. It doesn't anymore
601 * because there is no guaruntee that we won't be called
602 * concurrently from more than one thread.
604 m
->m_flags
&= ~(M_BCAST
| M_MCAST
);
605 if (!(ifnet_flags(ifp
) & IFF_UP
) ||
606 gif_psrc
== NULL
|| gif_pdst
== NULL
) {
607 ifnet_touch_lastchange(ifp
);
608 m_freem(m
); /* free it here not in dlil_output */
613 bpf_tap_out(ifp
, 0, m
, &sc
->gif_proto
, sizeof(sc
->gif_proto
));
617 /* inner AF-specific encapsulation */
619 /* XXX should we check if our outer source is legal? */
621 /* dispatch to output logic based on outer AF */
622 switch (sc
->gif_psrc
->sa_family
) {
625 error
= in_gif_output(ifp
, sc
->gif_proto
, m
, NULL
);
630 error
= in6_gif_output(ifp
, sc
->gif_proto
, m
, NULL
);
641 /* the mbuf was freed either by in_gif_output or in here */
642 ifnet_stat_increment_out(ifp
, 0, 0, 1);
644 ifnet_stat_increment_out(ifp
, 1, m
->m_pkthdr
.len
, 0);
647 error
= EJUSTRETURN
; /* if no error, packet got sent already */
653 * gif_input is the input handler for IP and IPv6 attached to gif
658 protocol_family_t protocol_family
,
660 __unused
char *frame_header
)
662 struct gif_softc
*sc
= ifnet_softc(ifp
);
664 bpf_tap_in(ifp
, 0, m
, &sc
->gif_proto
, sizeof(sc
->gif_proto
));
667 * Put the packet to the network layer input queue according to the
668 * specified address family.
669 * Note: older versions of gif_input directly called network layer
670 * input functions, e.g. ip6_input, here. We changed the policy to
671 * prevent too many recursive calls of such input functions, which
672 * might cause kernel panic. But the change may introduce another
673 * problem; if the input queue is full, packets are discarded.
674 * We believed it rarely occurs and changed the policy. If we find
675 * it occurs more times than we thought, we may change the policy
678 int32_t pktlen
= m
->m_pkthdr
.len
;
679 if (proto_input(protocol_family
, m
) != 0) {
680 ifnet_stat_increment_in(ifp
, 0, 0, 1);
683 ifnet_stat_increment_in(ifp
, 1, pktlen
, 0);
689 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
696 struct gif_softc
*sc
= ifnet_softc(ifp
);
697 struct ifreq
*ifr
= (struct ifreq
*)data
;
699 struct sockaddr
*dst
= NULL
, *src
= NULL
;
702 struct gif_softc
*sc2
;
715 #ifdef SIOCSIFMTU /* xxx */
723 if (mtu
< GIF_MTU_MIN
|| mtu
> GIF_MTU_MAX
) {
726 ifnet_set_mtu(ifp
, mtu
);
729 #endif /* SIOCSIFMTU */
733 case SIOCSIFPHYADDR_IN6_32
:
734 case SIOCSIFPHYADDR_IN6_64
:
739 src
= (struct sockaddr
*)
740 &(((struct in_aliasreq
*)data
)->ifra_addr
);
741 dst
= (struct sockaddr
*)
742 &(((struct in_aliasreq
*)data
)->ifra_dstaddr
);
746 case SIOCSIFPHYADDR_IN6_32
: {
747 struct in6_aliasreq_32
*ifra_32
=
748 (struct in6_aliasreq_32
*)data
;
750 src
= (struct sockaddr
*)&ifra_32
->ifra_addr
;
751 dst
= (struct sockaddr
*)&ifra_32
->ifra_dstaddr
;
755 case SIOCSIFPHYADDR_IN6_64
: {
756 struct in6_aliasreq_64
*ifra_64
=
757 (struct in6_aliasreq_64
*)data
;
759 src
= (struct sockaddr
*)&ifra_64
->ifra_addr
;
760 dst
= (struct sockaddr
*)&ifra_64
->ifra_dstaddr
;
766 /* sa_family must be equal */
767 if (src
->sa_family
!= dst
->sa_family
) {
771 /* validate sa_len */
772 switch (src
->sa_family
) {
775 if (src
->sa_len
!= sizeof(struct sockaddr_in
)) {
782 if (src
->sa_len
!= sizeof(struct sockaddr_in6
)) {
790 switch (dst
->sa_family
) {
793 if (dst
->sa_len
!= sizeof(struct sockaddr_in
)) {
800 if (dst
->sa_len
!= sizeof(struct sockaddr_in6
)) {
809 /* check sa_family looks sane for the cmd */
812 if (src
->sa_family
== AF_INET
) {
817 case SIOCSIFPHYADDR_IN6_32
:
818 case SIOCSIFPHYADDR_IN6_64
:
819 if (src
->sa_family
== AF_INET6
) {
826 #define GIF_ORDERED_LOCK(sc, sc2) \
835 #define GIF_ORDERED_UNLOCK(sc, sc2) \
844 ifnet_head_lock_shared();
845 TAILQ_FOREACH(ifp2
, &ifnet_head
, if_link
) {
846 if (strcmp(ifnet_name(ifp2
), GIFNAME
) != 0) {
849 sc2
= ifnet_softc(ifp2
);
853 /* lock sc and sc2 in increasing order of ifnet index */
854 GIF_ORDERED_LOCK(sc
, sc2
);
855 if (!sc2
->gif_pdst
|| !sc2
->gif_psrc
) {
856 GIF_ORDERED_UNLOCK(sc
, sc2
);
859 if (sc2
->gif_pdst
->sa_family
!= dst
->sa_family
||
860 sc2
->gif_pdst
->sa_len
!= dst
->sa_len
||
861 sc2
->gif_psrc
->sa_family
!= src
->sa_family
||
862 sc2
->gif_psrc
->sa_len
!= src
->sa_len
) {
863 GIF_ORDERED_UNLOCK(sc
, sc2
);
867 /* can't configure same pair of address onto two gifs */
868 if (bcmp(sc2
->gif_pdst
, dst
, dst
->sa_len
) == 0 &&
869 bcmp(sc2
->gif_psrc
, src
, src
->sa_len
) == 0) {
870 GIF_ORDERED_UNLOCK(sc
, sc2
);
871 error
= EADDRNOTAVAIL
;
877 /* can't configure multiple multi-dest interfaces */
878 #define multidest(x) \
879 (((struct sockaddr_in *)(void *)(x))->sin_addr.s_addr == INADDR_ANY)
881 #define multidest6(x) \
882 (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) \
883 (void *)(x))->sin6_addr))
885 if (dst
->sa_family
== AF_INET
&&
886 multidest(dst
) && multidest(sc2
->gif_pdst
)) {
887 GIF_ORDERED_UNLOCK(sc
, sc2
);
888 error
= EADDRNOTAVAIL
;
893 if (dst
->sa_family
== AF_INET6
&&
894 multidest6(dst
) && multidest6(sc2
->gif_pdst
)) {
895 GIF_ORDERED_UNLOCK(sc
, sc2
);
896 error
= EADDRNOTAVAIL
;
901 GIF_ORDERED_UNLOCK(sc
, sc2
);
907 FREE(sc
->gif_psrc
, M_IFADDR
);
909 sa
= (struct sockaddr
*)_MALLOC(src
->sa_len
, M_IFADDR
,
915 bcopy((caddr_t
)src
, (caddr_t
)sa
, src
->sa_len
);
919 FREE(sc
->gif_pdst
, M_IFADDR
);
921 sa
= (struct sockaddr
*)_MALLOC(dst
->sa_len
, M_IFADDR
,
927 bcopy((caddr_t
)dst
, (caddr_t
)sa
, dst
->sa_len
);
931 ifnet_set_flags(ifp
, IFF_RUNNING
| IFF_UP
, IFF_RUNNING
|
937 #ifdef SIOCDIFPHYADDR
941 FREE(sc
->gif_psrc
, M_IFADDR
);
945 FREE(sc
->gif_pdst
, M_IFADDR
);
949 /* change the IFF_{UP, RUNNING} flag as well? */
953 case SIOCGIFPSRCADDR
:
955 case SIOCGIFPSRCADDR_IN6
:
958 if (sc
->gif_psrc
== NULL
) {
960 error
= EADDRNOTAVAIL
;
966 case SIOCGIFPSRCADDR
:
967 dst
= &ifr
->ifr_addr
;
968 size
= sizeof(ifr
->ifr_addr
);
972 case SIOCGIFPSRCADDR_IN6
:
973 dst
= (struct sockaddr
*)
974 &(((struct in6_ifreq
*)data
)->ifr_addr
);
975 size
= sizeof(((struct in6_ifreq
*)data
)->ifr_addr
);
980 error
= EADDRNOTAVAIL
;
983 if (src
->sa_len
> size
) {
987 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
991 case SIOCGIFPDSTADDR
:
993 case SIOCGIFPDSTADDR_IN6
:
996 if (sc
->gif_pdst
== NULL
) {
998 error
= EADDRNOTAVAIL
;
1004 case SIOCGIFPDSTADDR
:
1005 dst
= &ifr
->ifr_addr
;
1006 size
= sizeof(ifr
->ifr_addr
);
1010 case SIOCGIFPDSTADDR_IN6
:
1011 dst
= (struct sockaddr
*)
1012 &(((struct in6_ifreq
*)data
)->ifr_addr
);
1013 size
= sizeof(((struct in6_ifreq
*)data
)->ifr_addr
);
1017 error
= EADDRNOTAVAIL
;
1021 if (src
->sa_len
> size
) {
1025 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
1030 /* if_ioctl() takes care of it */
1042 gif_delete_tunnel(struct gif_softc
*sc
)
1044 GIF_LOCK_ASSERT(sc
);
1046 FREE(sc
->gif_psrc
, M_IFADDR
);
1047 sc
->gif_psrc
= NULL
;
1050 FREE(sc
->gif_pdst
, M_IFADDR
);
1051 sc
->gif_pdst
= NULL
;
1053 ROUTE_RELEASE(&sc
->gif_ro
);
1054 /* change the IFF_UP flag as well? */