xref: /linux/include/uapi/linux/if_tun.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  *  Universal TUN/TAP device driver.
4607ca46eSDavid Howells  *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>
5607ca46eSDavid Howells  *
6607ca46eSDavid Howells  *  This program is free software; you can redistribute it and/or modify
7607ca46eSDavid Howells  *  it under the terms of the GNU General Public License as published by
8607ca46eSDavid Howells  *  the Free Software Foundation; either version 2 of the License, or
9607ca46eSDavid Howells  *  (at your option) any later version.
10607ca46eSDavid Howells  *
11607ca46eSDavid Howells  *  This program is distributed in the hope that it will be useful,
12607ca46eSDavid Howells  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13607ca46eSDavid Howells  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14607ca46eSDavid Howells  *  GNU General Public License for more details.
15607ca46eSDavid Howells  */
16607ca46eSDavid Howells 
17607ca46eSDavid Howells #ifndef _UAPI__IF_TUN_H
18607ca46eSDavid Howells #define _UAPI__IF_TUN_H
19607ca46eSDavid Howells 
20607ca46eSDavid Howells #include <linux/types.h>
21607ca46eSDavid Howells #include <linux/if_ether.h>
22607ca46eSDavid Howells #include <linux/filter.h>
23607ca46eSDavid Howells 
24607ca46eSDavid Howells /* Read queue size */
25607ca46eSDavid Howells #define TUN_READQ_SIZE	500
26031f5e03SMichael S. Tsirkin /* TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. */
27031f5e03SMichael S. Tsirkin #define TUN_TUN_DEV 	IFF_TUN
28031f5e03SMichael S. Tsirkin #define TUN_TAP_DEV	IFF_TAP
29607ca46eSDavid Howells #define TUN_TYPE_MASK   0x000f
30607ca46eSDavid Howells 
31607ca46eSDavid Howells /* Ioctl defines */
32607ca46eSDavid Howells #define TUNSETNOCSUM  _IOW('T', 200, int)
33607ca46eSDavid Howells #define TUNSETDEBUG   _IOW('T', 201, int)
34607ca46eSDavid Howells #define TUNSETIFF     _IOW('T', 202, int)
35607ca46eSDavid Howells #define TUNSETPERSIST _IOW('T', 203, int)
36607ca46eSDavid Howells #define TUNSETOWNER   _IOW('T', 204, int)
37607ca46eSDavid Howells #define TUNSETLINK    _IOW('T', 205, int)
38607ca46eSDavid Howells #define TUNSETGROUP   _IOW('T', 206, int)
39607ca46eSDavid Howells #define TUNGETFEATURES _IOR('T', 207, unsigned int)
40607ca46eSDavid Howells #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
41607ca46eSDavid Howells #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
42607ca46eSDavid Howells #define TUNGETIFF      _IOR('T', 210, unsigned int)
43607ca46eSDavid Howells #define TUNGETSNDBUF   _IOR('T', 211, int)
44607ca46eSDavid Howells #define TUNSETSNDBUF   _IOW('T', 212, int)
45607ca46eSDavid Howells #define TUNATTACHFILTER _IOW('T', 213, struct sock_fprog)
46607ca46eSDavid Howells #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
47607ca46eSDavid Howells #define TUNGETVNETHDRSZ _IOR('T', 215, int)
48607ca46eSDavid Howells #define TUNSETVNETHDRSZ _IOW('T', 216, int)
49cde8b15fSJason Wang #define TUNSETQUEUE  _IOW('T', 217, int)
50fb7589a1SPavel Emelyanov #define TUNSETIFINDEX	_IOW('T', 218, unsigned int)
5176975e9cSPavel Emelyanov #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
525eea84f4SMichael S. Tsirkin #define TUNSETVNETLE _IOW('T', 220, int)
535eea84f4SMichael S. Tsirkin #define TUNGETVNETLE _IOR('T', 221, int)
548b8e658bSGreg Kurz /* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on
558b8e658bSGreg Kurz  * little-endian hosts. Not all kernel configurations support them, but all
568b8e658bSGreg Kurz  * configurations that support SET also support GET.
578b8e658bSGreg Kurz  */
588b8e658bSGreg Kurz #define TUNSETVNETBE _IOW('T', 222, int)
598b8e658bSGreg Kurz #define TUNGETVNETBE _IOR('T', 223, int)
6096f84061SJason Wang #define TUNSETSTEERINGEBPF _IOR('T', 224, int)
61aff3d70aSJason Wang #define TUNSETFILTEREBPF _IOR('T', 225, int)
6226d31925SNicolas Dichtel #define TUNSETCARRIER _IOW('T', 226, int)
630c3e0e3bSKirill Tkhai #define TUNGETDEVNETNS _IO('T', 227)
64607ca46eSDavid Howells 
65607ca46eSDavid Howells /* TUNSETIFF ifr flags */
66607ca46eSDavid Howells #define IFF_TUN		0x0001
67607ca46eSDavid Howells #define IFF_TAP		0x0002
6894317099SPetar Penkov #define IFF_NAPI	0x0010
6990e33d45SPetar Penkov #define IFF_NAPI_FRAGS	0x0020
70195624d9SPatrick Rohr /* Used in TUNSETIFF to bring up tun/tap without carrier */
71195624d9SPatrick Rohr #define IFF_NO_CARRIER	0x0040
72607ca46eSDavid Howells #define IFF_NO_PI	0x1000
735d097109SMichael S. Tsirkin /* This flag has no real effect */
74607ca46eSDavid Howells #define IFF_ONE_QUEUE	0x2000
75607ca46eSDavid Howells #define IFF_VNET_HDR	0x4000
76607ca46eSDavid Howells #define IFF_TUN_EXCL	0x8000
77bbb00994SJason Wang #define IFF_MULTI_QUEUE 0x0100
78cde8b15fSJason Wang #define IFF_ATTACH_QUEUE 0x0200
79cde8b15fSJason Wang #define IFF_DETACH_QUEUE 0x0400
80274038f8SPavel Emelyanov /* read-only flag */
81274038f8SPavel Emelyanov #define IFF_PERSIST	0x0800
82849c9b6fSPavel Emelyanov #define IFF_NOFILTER	0x1000
83607ca46eSDavid Howells 
84eda29772SRichard Cochran /* Socket options */
85eda29772SRichard Cochran #define TUN_TX_TIMESTAMP 1
86eda29772SRichard Cochran 
87607ca46eSDavid Howells /* Features for GSO (TUNSETOFFLOAD). */
88607ca46eSDavid Howells #define TUN_F_CSUM	0x01	/* You can hand me unchecksummed packets. */
89607ca46eSDavid Howells #define TUN_F_TSO4	0x02	/* I can handle TSO for IPv4 packets */
90607ca46eSDavid Howells #define TUN_F_TSO6	0x04	/* I can handle TSO for IPv6 packets */
91607ca46eSDavid Howells #define TUN_F_TSO_ECN	0x08	/* I can handle TSO with ECN bits. */
92607ca46eSDavid Howells #define TUN_F_UFO	0x10	/* I can handle UFO packets */
93*b22bbdd1SAndrew Melnychenko #define TUN_F_USO4	0x20	/* I can handle USO for IPv4 packets */
94*b22bbdd1SAndrew Melnychenko #define TUN_F_USO6	0x40	/* I can handle USO for IPv6 packets */
95607ca46eSDavid Howells 
96607ca46eSDavid Howells /* Protocol info prepended to the packets (when IFF_NO_PI is not set) */
97607ca46eSDavid Howells #define TUN_PKT_STRIP	0x0001
98607ca46eSDavid Howells struct tun_pi {
99607ca46eSDavid Howells 	__u16  flags;
100607ca46eSDavid Howells 	__be16 proto;
101607ca46eSDavid Howells };
102607ca46eSDavid Howells 
103607ca46eSDavid Howells /*
104607ca46eSDavid Howells  * Filter spec (used for SETXXFILTER ioctls)
105607ca46eSDavid Howells  * This stuff is applicable only to the TAP (Ethernet) devices.
106607ca46eSDavid Howells  * If the count is zero the filter is disabled and the driver accepts
107607ca46eSDavid Howells  * all packets (promisc mode).
108607ca46eSDavid Howells  * If the filter is enabled in order to accept broadcast packets
109607ca46eSDavid Howells  * broadcast addr must be explicitly included in the addr list.
110607ca46eSDavid Howells  */
111607ca46eSDavid Howells #define TUN_FLT_ALLMULTI 0x0001 /* Accept all multicast packets */
112607ca46eSDavid Howells struct tun_filter {
113607ca46eSDavid Howells 	__u16  flags; /* TUN_FLT_ flags see above */
114607ca46eSDavid Howells 	__u16  count; /* Number of addresses */
11594dfc73eSGustavo A. R. Silva 	__u8   addr[][ETH_ALEN];
116607ca46eSDavid Howells };
117607ca46eSDavid Howells 
118607ca46eSDavid Howells #endif /* _UAPI__IF_TUN_H */
119