2 * ip tunnel device for MacOSX.
5 * Copyright (c) 2004, 2005, 2006, 2007 Mattias Nissler <mattias.nissler@gmx.de>
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice, this list of
11 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions and the following disclaimer in the documentation and/or other materials provided
14 * with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #define TUN_FAMILY_NAME "tun"
34 #define TUN_IF_COUNT 16 /* max number of tun interfaces */
37 #include "tun_ioctls.h"
41 errno_t
tun_inet_attach(ifnet_t ifp
, protocol_family_t proto
);
42 void tun_inet_detach(ifnet_t ifp
, protocol_family_t proto
);
43 errno_t
tun_inet6_attach(ifnet_t ifp
, protocol_family_t proto
);
44 void tun_inet6_detach(ifnet_t ifp
, protocol_family_t proto
);
49 class tun_manager
: public tuntap_manager
{
52 /* create an interface */
53 virtual tuntap_interface
*create_interface();
55 /* whether we need to call tuntap_manager::shutdown() */
59 /* special initalize */
60 virtual bool initialize(unsigned int count
, char *family
);
62 /* special shutdown */
63 virtual bool shutdown();
67 /* the tun network interface */
68 class tun_interface
: public tuntap_interface
{
71 /* maximum number of protocols that can be attached */
72 static const unsigned int MAX_ATTACHED_PROTOS
= 8;
74 /* information about attached protocols for demuxing is stored here */
76 /* whether this entry is used */
78 /* protocol family (this is equal to proto, but keep it seperated from
79 * Apple's KPI stuff...) */
81 /* protocol passed to add_proto */
82 protocol_family_t proto
;
83 } attached_protos
[MAX_ATTACHED_PROTOS
];
85 /* whether the address family field is prepended to each packet */
88 /* intializes the interface */
89 virtual bool initialize(unsigned short major
, unsigned short int unit
);
91 /* shutdown the interface */
92 virtual void shutdown();
94 /* called when the character device is opened in order to intialize the network
97 virtual int initialize_netif();
98 /* called when the character device is closed to shutdown the network interface */
99 virtual void shutdown_netif();
101 /* override interface routines */
102 virtual errno_t
if_demux(mbuf_t m
, char *header
, protocol_family_t
*proto
);
103 virtual errno_t
if_framer(mbuf_t
*m
, const struct sockaddr
*dest
,
104 const char *dest_linkaddr
, const char *frame_type
);
105 virtual errno_t
if_add_proto(protocol_family_t proto
,
106 const struct ifnet_demux_desc
*desc
, u_int32_t ndesc
);
107 virtual errno_t
if_del_proto(protocol_family_t proto
);
108 virtual errno_t
if_check_multi(const struct sockaddr
*maddr
);
110 /* helper to if_add_proto */
111 virtual errno_t
add_one_proto(protocol_family_t proto
,
112 const struct ifnet_demux_desc
&dd
);
114 /* override notify_bpf because we might need to prepend an address header */
115 virtual void notify_bpf(mbuf_t mb
, bool out
);
117 /* need to override cdev_ioctl to get our special ioctls */
118 virtual int cdev_ioctl(u_long cmd
, caddr_t data
, int fflag
, proc_t p
);
122 #endif /* __TUN_H__ */