2 * Copyright (c) 2000-2013 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>
80 #include <net/if_types.h>
81 #include <net/route.h>
83 #include <net/kpi_protocol.h>
84 #include <net/kpi_interface.h>
87 #include <netinet/in.h>
88 #include <netinet/in_systm.h>
89 #include <netinet/ip.h>
91 #include <netinet/in_var.h>
92 #include <netinet/in_gif.h>
93 #include <netinet/ip_var.h>
97 #include <netinet6/in6_var.h>
98 #include <netinet/ip6.h>
99 #include <netinet6/ip6_var.h>
100 #include <netinet6/in6_gif.h>
101 #include <netinet6/ip6protosw.h>
104 #include <netinet/ip_encap.h>
105 #include <net/dlil.h>
106 #include <net/if_gif.h>
108 #include <net/net_osdep.h>
111 #include <security/mac_framework.h>
114 #define GIFNAME "gif"
115 #define GIFDEV "if_gif"
116 #define GIF_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */
118 /* gif lock variables */
119 static lck_grp_t
*gif_mtx_grp
;
120 static lck_grp_attr_t
*gif_mtx_grp_attr
;
121 static lck_attr_t
*gif_mtx_attr
;
122 decl_lck_mtx_data(static, gif_mtx_data
);
123 static lck_mtx_t
*gif_mtx
= &gif_mtx_data
;
125 TAILQ_HEAD(gifhead
, gif_softc
) gifs
= TAILQ_HEAD_INITIALIZER(gifs
);
127 static int gif_encapcheck(const struct mbuf
*, int, int, void *);
128 static errno_t
gif_output(ifnet_t ifp
, mbuf_t m
);
129 static errno_t
gif_input(ifnet_t ifp
, protocol_family_t protocol_family
,
130 mbuf_t m
, char *frame_header
);
131 static errno_t
gif_ioctl(ifnet_t ifp
, u_long cmd
, void *data
);
133 static int ngif
= 0; /* number of interfaces */
136 static struct protosw in_gif_protosw
=
139 .pr_protocol
= 0, /* IPPROTO_IPV[46] */
140 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
141 .pr_input
= in_gif_input
,
142 .pr_usrreqs
= &rip_usrreqs
,
143 .pr_unlock
= rip_unlock
,
147 static struct ip6protosw in6_gif_protosw
=
150 .pr_protocol
= 0, /* IPPROTO_IPV[46] */
151 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
152 .pr_input
= in6_gif_input
,
153 .pr_usrreqs
= &rip6_usrreqs
,
154 .pr_unlock
= rip_unlock
,
158 static if_clone_t gif_cloner
= NULL
;
159 static int gif_clone_create(struct if_clone
*, uint32_t, void *);
160 static int gif_clone_destroy(struct ifnet
*);
161 static void gif_delete_tunnel(struct gif_softc
*);
162 static void gif_detach(struct ifnet
*);
165 * Theory of operation: initially, one gif interface is created.
166 * Any time a gif interface is configured, if there are no other
167 * unconfigured gif interfaces, a new gif interface is created.
168 * BSD uses the clone mechanism to dynamically create more
171 * We have some extra glue to support DLIL.
174 /* GIF interface module support */
179 __unused
char *frame_header
,
180 protocol_family_t
*protocol_family
)
182 struct gif_softc
*sc
= ifnet_softc(ifp
);
185 /* Only one protocol may be attached to a gif interface. */
186 *protocol_family
= sc
->gif_proto
;
195 protocol_family_t protocol_family
,
196 __unused
const struct ifnet_demux_desc
*demux_array
,
197 __unused u_int32_t demux_count
)
199 /* Only one protocol may be attached at a time */
200 struct gif_softc
*sc
= ifnet_softc(ifp
);
203 if (sc
->gif_proto
!= 0)
204 printf("gif_add_proto: request add_proto for gif%d\n",
207 sc
->gif_proto
= protocol_family
;
216 protocol_family_t protocol_family
)
218 struct gif_softc
*sc
= ifnet_softc(ifp
);
221 if (sc
->gif_proto
== protocol_family
)
228 /* Glue code to attach inet to a gif interface through DLIL */
230 gif_attach_proto_family(
232 protocol_family_t protocol_family
)
234 struct ifnet_attach_proto_param reg
;
237 bzero(®
, sizeof (reg
));
238 reg
.input
= gif_input
;
240 stat
= ifnet_attach_protocol(ifp
, protocol_family
, ®
);
241 if (stat
&& stat
!= EEXIST
) {
242 printf("gif_attach_proto_family can't attach interface \
243 fam=%d\n", protocol_family
);
249 /* Function to setup the first gif interface */
254 struct ifnet_clone_params ifnet_clone_params
;
255 struct if_clone
*ifc
= NULL
;
257 /* Initialize the list of interfaces */
260 /* Initialize the gif global lock */
261 gif_mtx_grp_attr
= lck_grp_attr_alloc_init();
262 gif_mtx_grp
= lck_grp_alloc_init("gif", gif_mtx_grp_attr
);
263 gif_mtx_attr
= lck_attr_alloc_init();
264 lck_mtx_init(gif_mtx
, gif_mtx_grp
, gif_mtx_attr
);
266 /* Register protocol registration functions */
267 result
= proto_register_plumber(PF_INET
, APPLE_IF_FAM_GIF
,
268 gif_attach_proto_family
, NULL
);
270 printf("proto_register_plumber failed for AF_INET error=%d\n",
273 result
= proto_register_plumber(PF_INET6
, APPLE_IF_FAM_GIF
,
274 gif_attach_proto_family
, NULL
);
276 printf("proto_register_plumber failed for AF_INET6 error=%d\n",
279 ifnet_clone_params
.ifc_name
= "gif";
280 ifnet_clone_params
.ifc_create
= gif_clone_create
;
281 ifnet_clone_params
.ifc_destroy
= gif_clone_destroy
;
283 result
= ifnet_clone_attach(&ifnet_clone_params
, &gif_cloner
);
285 printf("gifattach: ifnet_clone_attach failed %d\n", result
);
287 /* Create first device */
288 ifc
= if_clone_lookup("gif", NULL
);
289 gif_clone_create(ifc
, 0, NULL
);
296 bpf_packet_func callback
)
298 struct gif_softc
*sc
= ifnet_softc(ifp
);
302 sc
->tap_callback
= callback
;
309 gif_detach(struct ifnet
*ifp
)
311 struct gif_softc
*sc
= ifp
->if_softc
;
312 lck_mtx_destroy(&sc
->gif_lock
, gif_mtx_grp
);
313 _FREE(ifp
->if_softc
, M_DEVBUF
);
314 ifp
->if_softc
= NULL
;
315 (void) ifnet_release(ifp
);
319 gif_clone_create(struct if_clone
*ifc
, uint32_t unit
, __unused
void *params
)
321 struct gif_softc
*sc
= NULL
;
322 struct ifnet_init_params gif_init_params
;
325 lck_mtx_lock(gif_mtx
);
327 /* Can't create more than GIF_MAXUNIT */
328 if (ngif
>= GIF_MAXUNIT
) {
333 sc
= _MALLOC(sizeof (struct gif_softc
), M_DEVBUF
, M_WAITOK
);
335 log(LOG_ERR
, "gif_clone_create: failed to allocate gif%d\n",
340 bzero(sc
, sizeof (struct gif_softc
));
342 /* use the interface name as the unique id for ifp recycle */
343 snprintf(sc
->gif_ifname
, sizeof (sc
->gif_ifname
), "%s%d",
344 ifc
->ifc_name
, unit
);
346 lck_mtx_init(&sc
->gif_lock
, gif_mtx_grp
, gif_mtx_attr
);
348 bzero(&gif_init_params
, sizeof (gif_init_params
));
349 gif_init_params
.uniqueid
= sc
->gif_ifname
;
350 gif_init_params
.uniqueid_len
= strlen(sc
->gif_ifname
);
351 gif_init_params
.name
= GIFNAME
;
352 gif_init_params
.unit
= unit
;
353 gif_init_params
.type
= IFT_GIF
;
354 gif_init_params
.family
= IFNET_FAMILY_GIF
;
355 gif_init_params
.output
= gif_output
;
356 gif_init_params
.demux
= gif_demux
;
357 gif_init_params
.add_proto
= gif_add_proto
;
358 gif_init_params
.del_proto
= gif_del_proto
;
359 gif_init_params
.softc
= sc
;
360 gif_init_params
.ioctl
= gif_ioctl
;
361 gif_init_params
.set_bpf_tap
= gif_set_bpf_tap
;
362 gif_init_params
.detach
= gif_detach
;
364 error
= ifnet_allocate(&gif_init_params
, &sc
->gif_if
);
366 printf("gif_clone_create, ifnet_allocate failed - %d\n", error
);
372 sc
->encap_cookie4
= sc
->encap_cookie6
= NULL
;
374 sc
->encap_cookie4
= encap_attach_func(AF_INET
, -1,
375 gif_encapcheck
, &in_gif_protosw
, sc
);
376 if (sc
->encap_cookie4
== NULL
) {
377 printf("%s: unable to attach encap4\n", if_name(sc
->gif_if
));
378 ifnet_release(sc
->gif_if
);
385 sc
->encap_cookie6
= encap_attach_func(AF_INET6
, -1,
386 gif_encapcheck
, (struct protosw
*)&in6_gif_protosw
, sc
);
387 if (sc
->encap_cookie6
== NULL
) {
388 if (sc
->encap_cookie4
) {
389 encap_detach(sc
->encap_cookie4
);
390 sc
->encap_cookie4
= NULL
;
392 printf("%s: unable to attach encap6\n", if_name(sc
->gif_if
));
393 ifnet_release(sc
->gif_if
);
400 ifnet_set_mtu(sc
->gif_if
, GIF_MTU
);
401 ifnet_set_flags(sc
->gif_if
, IFF_POINTOPOINT
| IFF_MULTICAST
, 0xffff);
403 /* turn off ingress filter */
404 sc
->gif_if
.if_flags
|= IFF_LINK2
;
406 error
= ifnet_attach(sc
->gif_if
, NULL
);
408 printf("gif_clone_create - ifnet_attach failed - %d\n", error
);
409 ifnet_release(sc
->gif_if
);
410 if (sc
->encap_cookie4
) {
411 encap_detach(sc
->encap_cookie4
);
412 sc
->encap_cookie4
= NULL
;
414 if (sc
->encap_cookie6
) {
415 encap_detach(sc
->encap_cookie6
);
416 sc
->encap_cookie6
= NULL
;
422 mac_ifnet_label_init(&sc
->gif_if
);
424 bpfattach(sc
->gif_if
, DLT_NULL
, sizeof (u_int
));
425 TAILQ_INSERT_TAIL(&gifs
, sc
, gif_link
);
428 lck_mtx_unlock(gif_mtx
);
434 gif_clone_destroy(struct ifnet
*ifp
)
436 #if defined(INET) || defined(INET6)
439 struct gif_softc
*sc
= ifp
->if_softc
;
441 lck_mtx_lock(gif_mtx
);
442 TAILQ_REMOVE(&gifs
, sc
, gif_link
);
446 gif_delete_tunnel(sc
);
448 if (sc
->encap_cookie6
!= NULL
) {
449 error
= encap_detach(sc
->encap_cookie6
);
450 KASSERT(error
== 0, ("gif_clone_destroy: Unexpected \
451 error detaching encap_cookie6"));
455 if (sc
->encap_cookie4
!= NULL
) {
456 error
= encap_detach(sc
->encap_cookie4
);
457 KASSERT(error
== 0, ("gif_clone_destroy: Unexpected \
458 error detaching encap_cookie4"));
461 error
= ifnet_set_flags(ifp
, 0, IFF_UP
);
463 printf("gif_clone_destroy: ifnet_set_flags failed %d\n", error
);
466 error
= ifnet_detach(ifp
);
468 panic("gif_clone_destroy: ifnet_detach(%p) failed %d\n", ifp
,
472 lck_mtx_unlock(gif_mtx
);
479 const struct mbuf
*m
,
486 struct gif_softc
*sc
;
488 sc
= (struct gif_softc
*)arg
;
493 if ((ifnet_flags(sc
->gif_if
) & IFF_UP
) == 0)
496 /* no physical address */
497 if (!sc
->gif_psrc
|| !sc
->gif_pdst
)
513 mbuf_copydata((struct mbuf
*)(size_t)m
, 0, sizeof (ip
), &ip
);
518 if (sc
->gif_psrc
->sa_family
!= AF_INET
||
519 sc
->gif_pdst
->sa_family
!= AF_INET
)
521 error
= gif_encapcheck4(m
, off
, proto
, arg
);
525 if (sc
->gif_psrc
->sa_family
!= AF_INET6
||
526 sc
->gif_pdst
->sa_family
!= AF_INET6
)
528 error
= gif_encapcheck6(m
, off
, proto
, arg
);
543 struct gif_softc
*sc
= ifnet_softc(ifp
);
544 struct sockaddr
*gif_psrc
;
545 struct sockaddr
*gif_pdst
;
549 gif_psrc
= sc
->gif_psrc
;
550 gif_pdst
= sc
->gif_pdst
;
554 * max_gif_nesting check used to live here. It doesn't anymore
555 * because there is no guaruntee that we won't be called
556 * concurrently from more than one thread.
558 m
->m_flags
&= ~(M_BCAST
|M_MCAST
);
559 if (!(ifnet_flags(ifp
) & IFF_UP
) ||
560 gif_psrc
== NULL
|| gif_pdst
== NULL
) {
561 ifnet_touch_lastchange(ifp
);
562 m_freem(m
); /* free it here not in dlil_output */
567 bpf_tap_out(ifp
, 0, m
, &sc
->gif_proto
, sizeof (sc
->gif_proto
));
571 /* inner AF-specific encapsulation */
573 /* XXX should we check if our outer source is legal? */
575 /* dispatch to output logic based on outer AF */
576 switch (sc
->gif_psrc
->sa_family
) {
579 error
= in_gif_output(ifp
, sc
->gif_proto
, m
, NULL
);
584 error
= in6_gif_output(ifp
, sc
->gif_proto
, m
, NULL
);
595 /* the mbuf was freed either by in_gif_output or in here */
596 ifnet_stat_increment_out(ifp
, 0, 0, 1);
598 ifnet_stat_increment_out(ifp
, 1, m
->m_pkthdr
.len
, 0);
601 error
= EJUSTRETURN
; /* if no error, packet got sent already */
606 * gif_input is the input handler for IP and IPv6 attached to gif
611 protocol_family_t protocol_family
,
613 __unused
char *frame_header
)
615 struct gif_softc
*sc
= ifnet_softc(ifp
);
617 bpf_tap_in(ifp
, 0, m
, &sc
->gif_proto
, sizeof (sc
->gif_proto
));
620 * Put the packet to the network layer input queue according to the
621 * specified address family.
622 * Note: older versions of gif_input directly called network layer
623 * input functions, e.g. ip6_input, here. We changed the policy to
624 * prevent too many recursive calls of such input functions, which
625 * might cause kernel panic. But the change may introduce another
626 * problem; if the input queue is full, packets are discarded.
627 * We believed it rarely occurs and changed the policy. If we find
628 * it occurs more times than we thought, we may change the policy
631 if (proto_input(protocol_family
, m
) != 0) {
632 ifnet_stat_increment_in(ifp
, 0, 0, 1);
635 ifnet_stat_increment_in(ifp
, 1, m
->m_pkthdr
.len
, 0);
640 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
647 struct gif_softc
*sc
= ifnet_softc(ifp
);
648 struct ifreq
*ifr
= (struct ifreq
*)data
;
650 struct sockaddr
*dst
= NULL
, *src
= NULL
;
653 struct gif_softc
*sc2
;
666 #ifdef SIOCSIFMTU /* xxx */
674 if (mtu
< GIF_MTU_MIN
|| mtu
> GIF_MTU_MAX
) {
677 ifnet_set_mtu(ifp
, mtu
);
680 #endif /* SIOCSIFMTU */
684 case SIOCSIFPHYADDR_IN6_32
:
685 case SIOCSIFPHYADDR_IN6_64
:
690 src
= (struct sockaddr
*)
691 &(((struct in_aliasreq
*)data
)->ifra_addr
);
692 dst
= (struct sockaddr
*)
693 &(((struct in_aliasreq
*)data
)->ifra_dstaddr
);
697 case SIOCSIFPHYADDR_IN6_32
: {
698 struct in6_aliasreq_32
*ifra_32
=
699 (struct in6_aliasreq_32
*)data
;
701 src
= (struct sockaddr
*)&ifra_32
->ifra_addr
;
702 dst
= (struct sockaddr
*)&ifra_32
->ifra_dstaddr
;
706 case SIOCSIFPHYADDR_IN6_64
: {
707 struct in6_aliasreq_64
*ifra_64
=
708 (struct in6_aliasreq_64
*)data
;
710 src
= (struct sockaddr
*)&ifra_64
->ifra_addr
;
711 dst
= (struct sockaddr
*)&ifra_64
->ifra_dstaddr
;
717 /* sa_family must be equal */
718 if (src
->sa_family
!= dst
->sa_family
)
721 /* validate sa_len */
722 switch (src
->sa_family
) {
725 if (src
->sa_len
!= sizeof (struct sockaddr_in
))
731 if (src
->sa_len
!= sizeof (struct sockaddr_in6
))
736 return (EAFNOSUPPORT
);
738 switch (dst
->sa_family
) {
741 if (dst
->sa_len
!= sizeof (struct sockaddr_in
))
747 if (dst
->sa_len
!= sizeof (struct sockaddr_in6
))
752 return (EAFNOSUPPORT
);
755 /* check sa_family looks sane for the cmd */
758 if (src
->sa_family
== AF_INET
)
760 return (EAFNOSUPPORT
);
762 case SIOCSIFPHYADDR_IN6_32
:
763 case SIOCSIFPHYADDR_IN6_64
:
764 if (src
->sa_family
== AF_INET6
)
766 return (EAFNOSUPPORT
);
770 #define GIF_ORDERED_LOCK(sc, sc2) \
779 #define GIF_ORDERED_UNLOCK(sc, sc2) \
788 ifnet_head_lock_shared();
789 TAILQ_FOREACH(ifp2
, &ifnet_head
, if_link
) {
790 if (strcmp(ifnet_name(ifp2
), GIFNAME
) != 0)
792 sc2
= ifnet_softc(ifp2
);
795 /* lock sc and sc2 in increasing order of ifnet index */
796 GIF_ORDERED_LOCK(sc
, sc2
);
797 if (!sc2
->gif_pdst
|| !sc2
->gif_psrc
) {
798 GIF_ORDERED_UNLOCK(sc
, sc2
);
801 if (sc2
->gif_pdst
->sa_family
!= dst
->sa_family
||
802 sc2
->gif_pdst
->sa_len
!= dst
->sa_len
||
803 sc2
->gif_psrc
->sa_family
!= src
->sa_family
||
804 sc2
->gif_psrc
->sa_len
!= src
->sa_len
) {
805 GIF_ORDERED_UNLOCK(sc
, sc2
);
809 /* can't configure same pair of address onto two gifs */
810 if (bcmp(sc2
->gif_pdst
, dst
, dst
->sa_len
) == 0 &&
811 bcmp(sc2
->gif_psrc
, src
, src
->sa_len
) == 0) {
812 GIF_ORDERED_UNLOCK(sc
, sc2
);
813 error
= EADDRNOTAVAIL
;
819 /* can't configure multiple multi-dest interfaces */
820 #define multidest(x) \
821 (((struct sockaddr_in *)(void *)(x))->sin_addr.s_addr == INADDR_ANY)
823 #define multidest6(x) \
824 (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) \
825 (void *)(x))->sin6_addr))
827 if (dst
->sa_family
== AF_INET
&&
828 multidest(dst
) && multidest(sc2
->gif_pdst
)) {
829 GIF_ORDERED_UNLOCK(sc
, sc2
);
830 error
= EADDRNOTAVAIL
;
835 if (dst
->sa_family
== AF_INET6
&&
836 multidest6(dst
) && multidest6(sc2
->gif_pdst
)) {
837 GIF_ORDERED_UNLOCK(sc
, sc2
);
838 error
= EADDRNOTAVAIL
;
843 GIF_ORDERED_UNLOCK(sc
, sc2
);
849 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
850 sa
= (struct sockaddr
*)_MALLOC(src
->sa_len
, M_IFADDR
,
856 bcopy((caddr_t
)src
, (caddr_t
)sa
, src
->sa_len
);
860 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
861 sa
= (struct sockaddr
*)_MALLOC(dst
->sa_len
, M_IFADDR
,
867 bcopy((caddr_t
)dst
, (caddr_t
)sa
, dst
->sa_len
);
871 ifnet_set_flags(ifp
, IFF_RUNNING
| IFF_UP
, IFF_RUNNING
|
877 #ifdef SIOCDIFPHYADDR
881 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
885 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
889 /* change the IFF_{UP, RUNNING} flag as well? */
893 case SIOCGIFPSRCADDR
:
895 case SIOCGIFPSRCADDR_IN6
:
898 if (sc
->gif_psrc
== NULL
) {
900 error
= EADDRNOTAVAIL
;
906 case SIOCGIFPSRCADDR
:
907 dst
= &ifr
->ifr_addr
;
908 size
= sizeof (ifr
->ifr_addr
);
912 case SIOCGIFPSRCADDR_IN6
:
913 dst
= (struct sockaddr
*)
914 &(((struct in6_ifreq
*)data
)->ifr_addr
);
915 size
= sizeof (((struct in6_ifreq
*)data
)->ifr_addr
);
920 error
= EADDRNOTAVAIL
;
923 if (src
->sa_len
> size
) {
927 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
931 case SIOCGIFPDSTADDR
:
933 case SIOCGIFPDSTADDR_IN6
:
936 if (sc
->gif_pdst
== NULL
) {
938 error
= EADDRNOTAVAIL
;
944 case SIOCGIFPDSTADDR
:
945 dst
= &ifr
->ifr_addr
;
946 size
= sizeof (ifr
->ifr_addr
);
950 case SIOCGIFPDSTADDR_IN6
:
951 dst
= (struct sockaddr
*)
952 &(((struct in6_ifreq
*)data
)->ifr_addr
);
953 size
= sizeof (((struct in6_ifreq
*)data
)->ifr_addr
);
957 error
= EADDRNOTAVAIL
;
961 if (src
->sa_len
> size
) {
965 bcopy((caddr_t
)src
, (caddr_t
)dst
, src
->sa_len
);
970 /* if_ioctl() takes care of it */
982 gif_delete_tunnel(struct gif_softc
*sc
)
986 FREE((caddr_t
)sc
->gif_psrc
, M_IFADDR
);
990 FREE((caddr_t
)sc
->gif_pdst
, M_IFADDR
);
993 ROUTE_RELEASE(&sc
->gif_ro
);
994 /* change the IFF_UP flag as well? */