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