xref: /openbsd/sys/net/if_tun.h (revision 1c386161)
1*1c386161Sdlg /*	$OpenBSD: if_tun.h,v 1.18 2024/11/17 00:25:07 dlg Exp $	*/
2df930be7Sderaadt 
3df930be7Sderaadt /*
44e428664Snate  * Copyright (c) 1988, Julian Onions <Julian.Onions@nexor.co.uk>
5df930be7Sderaadt  * Nottingham University 1987.
64e428664Snate  * All rights reserved.
7df930be7Sderaadt  *
84e428664Snate  * Redistribution and use in source and binary forms, with or without
94e428664Snate  * modification, are permitted provided that the following conditions
104e428664Snate  * are met:
114e428664Snate  * 1. Redistributions of source code must retain the above copyright
124e428664Snate  *    notice, this list of conditions and the following disclaimer.
134e428664Snate  * 2. Redistributions in binary form must reproduce the above copyright
144e428664Snate  *    notice, this list of conditions and the following disclaimer in the
154e428664Snate  *    documentation and/or other materials provided with the distribution.
16df930be7Sderaadt  *
174e428664Snate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
184e428664Snate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
194e428664Snate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
204e428664Snate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
214e428664Snate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
224e428664Snate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234e428664Snate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244e428664Snate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254e428664Snate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
264e428664Snate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274e428664Snate  */
284e428664Snate 
29df930be7Sderaadt #ifndef _NET_IF_TUN_H_
30df930be7Sderaadt #define _NET_IF_TUN_H_
31df930be7Sderaadt 
324a9bdd9fSmickey #include <sys/ioccom.h>
334a9bdd9fSmickey 
34*1c386161Sdlg /*
35*1c386161Sdlg  * tun_hdr is a multiple of 4 bytes, but is built out of uint16_t
36*1c386161Sdlg  * fields. This allows it to sit on a 2 byte boundary in front of
37*1c386161Sdlg  * either IP (and MPLS) or Ethernet packets for tun(4) and tap(4)
38*1c386161Sdlg  * interfaces respectively while maintaining the alignment of their
39*1c386161Sdlg  * payloads.
40*1c386161Sdlg  *
41*1c386161Sdlg  * Userland can request the use of the tun_hdr using the TUNSCAP
42*1c386161Sdlg  * ioctl. This ioctl also allows userland to specify which "offload"
43*1c386161Sdlg  * capabilities it is able to accept in packets it will read from the
44*1c386161Sdlg  * kernel. It is acceptable to enable tun_hdr without enabling any
45*1c386161Sdlg  * interface offload capabilities.
46*1c386161Sdlg  *
47*1c386161Sdlg  * Once the tap_hdr is enabled, userland can write packets into the
48*1c386161Sdlg  * kernel with any of the supported features. tun(4)/tap(4) reads
49*1c386161Sdlg  * will unconditionally handle any features specified on the packet,
50*1c386161Sdlg  * regardless of what capabilities were specified by the TUNSCAP
51*1c386161Sdlg  * ioctl.
52*1c386161Sdlg  *
53*1c386161Sdlg  * The tun_hdr can be read from one interface and written directly
54*1c386161Sdlg  * to another without interpretation or modification.
55*1c386161Sdlg  *
56*1c386161Sdlg  * Use of tun_hdr and the associated capabilities are reset when a
57*1c386161Sdlg  * tun(4)/tap(4) device is closed.
58*1c386161Sdlg  */
59*1c386161Sdlg 
60*1c386161Sdlg struct tun_hdr {
61*1c386161Sdlg 	uint16_t	th_flags;
62*1c386161Sdlg #define TUN_H_PRIO_MASK		0x7
63*1c386161Sdlg #define TUN_H_VTAG		(1 << 4)  /* th_vtag is set */
64*1c386161Sdlg #define TUN_H_TCP_MSS		(1 << 5)  /* Cut TCP frame up by th_mss */
65*1c386161Sdlg 
66*1c386161Sdlg #define TUN_H_IPV4_CSUM		(1 << 8)
67*1c386161Sdlg #define TUN_H_TCP_CSUM		(1 << 9)
68*1c386161Sdlg #define TUN_H_UDP_CSUM		(1 << 10)
69*1c386161Sdlg #define TUN_H_ICMP_CSUM		(1 << 11)
70*1c386161Sdlg 
71*1c386161Sdlg 	uint16_t	th_pad;
72*1c386161Sdlg 
73*1c386161Sdlg 	uint16_t	th_vtag;
74*1c386161Sdlg 	uint16_t	th_mss;
75*1c386161Sdlg };
76*1c386161Sdlg 
77df930be7Sderaadt #define	TUN_OPEN	0x0001
78df930be7Sderaadt #define	TUN_INITED	0x0002
79d7154a99Sclaudio #define	TUN_RCOLL	0x0004	/* unused */
80df930be7Sderaadt #define	TUN_IASET	0x0008
81df930be7Sderaadt #define	TUN_DSTADDR	0x0010
82df930be7Sderaadt #define	TUN_RWAIT	0x0040
83df930be7Sderaadt #define	TUN_ASYNC	0x0080
84df930be7Sderaadt #define	TUN_NBIO	0x0100
854a9bdd9fSmickey #define TUN_BRDADDR	0x0200
864a9bdd9fSmickey #define TUN_STAYUP	0x0400
87494a3c2dSclaudio #define TUN_LAYER2	0x0800
88df930be7Sderaadt 
89494a3c2dSclaudio #define	TUN_READY	(TUN_OPEN | TUN_INITED)
90df930be7Sderaadt 
91df930be7Sderaadt /* Maximum packet size */
927221e718Smickey #define	TUNMTU		3000
93df930be7Sderaadt 
94d44abe74Sbrian /* Maximum receive packet size (hard limit) */
95d44abe74Sbrian #define TUNMRU          16384
96d44abe74Sbrian 
977221e718Smickey /* iface info */
980c29d253Sderaadt struct tuninfo {
997221e718Smickey 	u_int	mtu;
1007221e718Smickey 	u_short	type;
1014a9bdd9fSmickey 	u_short	flags;
1027221e718Smickey 	u_int	baudrate;
1037221e718Smickey };
1047221e718Smickey #define TUNSIFINFO	_IOW('t', 91, struct tuninfo)
1057221e718Smickey #define TUNGIFINFO	_IOR('t', 92, struct tuninfo)
106df930be7Sderaadt 
1074be1f690Sangelos /* ioctl for changing the broadcast/point-to-point status */
1084be1f690Sangelos #define TUNSIFMODE      _IOW('t', 93, int)
1090ff72f70Smickey 
1100ff72f70Smickey /* ioctl's for get/set debug */
1110ff72f70Smickey #define	TUNSDEBUG	_IOW('t', 94, int)
1120ff72f70Smickey #define	TUNGDEBUG	_IOR('t', 95, int)
1130ff72f70Smickey 
114*1c386161Sdlg struct tun_capabilities {
115*1c386161Sdlg 	uint32_t	tun_if_capabilities; /* IFCAP_* from net/if.h */
116*1c386161Sdlg };
117*1c386161Sdlg 
118*1c386161Sdlg #define	TUNSCAP		_IOW('t', 196, struct tun_capabilities)
119*1c386161Sdlg #define	TUNGCAP		_IOR('t', 196, struct tun_capabilities)
120*1c386161Sdlg #define	TUNDCAP		_IO('t', 196)
121*1c386161Sdlg 
122e04c8cc2Sangelos #endif /* _NET_IF_TUN_H_ */
123