1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_IF_TUNNEL_H_
3 #define _UAPI_IF_TUNNEL_H_
4 
5 #include <linux/types.h>
6 #include <linux/if.h>
7 #include <linux/ip.h>
8 #include <linux/in6.h>
9 #include <asm/byteorder.h>
10 
11 
12 #define SIOCGETTUNNEL   (SIOCDEVPRIVATE + 0)
13 #define SIOCADDTUNNEL   (SIOCDEVPRIVATE + 1)
14 #define SIOCDELTUNNEL   (SIOCDEVPRIVATE + 2)
15 #define SIOCCHGTUNNEL   (SIOCDEVPRIVATE + 3)
16 #define SIOCGETPRL      (SIOCDEVPRIVATE + 4)
17 #define SIOCADDPRL      (SIOCDEVPRIVATE + 5)
18 #define SIOCDELPRL      (SIOCDEVPRIVATE + 6)
19 #define SIOCCHGPRL      (SIOCDEVPRIVATE + 7)
20 #define SIOCGET6RD      (SIOCDEVPRIVATE + 8)
21 #define SIOCADD6RD      (SIOCDEVPRIVATE + 9)
22 #define SIOCDEL6RD      (SIOCDEVPRIVATE + 10)
23 #define SIOCCHG6RD      (SIOCDEVPRIVATE + 11)
24 
25 #define GRE_CSUM	__cpu_to_be16(0x8000)
26 #define GRE_ROUTING	__cpu_to_be16(0x4000)
27 #define GRE_KEY		__cpu_to_be16(0x2000)
28 #define GRE_SEQ		__cpu_to_be16(0x1000)
29 #define GRE_STRICT	__cpu_to_be16(0x0800)
30 #define GRE_REC		__cpu_to_be16(0x0700)
31 #define GRE_ACK		__cpu_to_be16(0x0080)
32 #define GRE_FLAGS	__cpu_to_be16(0x0078)
33 #define GRE_VERSION	__cpu_to_be16(0x0007)
34 
35 #define GRE_IS_CSUM(f)		((f) & GRE_CSUM)
36 #define GRE_IS_ROUTING(f)	((f) & GRE_ROUTING)
37 #define GRE_IS_KEY(f)		((f) & GRE_KEY)
38 #define GRE_IS_SEQ(f)		((f) & GRE_SEQ)
39 #define GRE_IS_STRICT(f)	((f) & GRE_STRICT)
40 #define GRE_IS_REC(f)		((f) & GRE_REC)
41 #define GRE_IS_ACK(f)		((f) & GRE_ACK)
42 
43 #define GRE_VERSION_0		__cpu_to_be16(0x0000)
44 #define GRE_VERSION_1		__cpu_to_be16(0x0001)
45 #define GRE_PROTO_PPP		__cpu_to_be16(0x880b)
46 #define GRE_PPTP_KEY_MASK	__cpu_to_be32(0xffff)
47 
48 struct ip_tunnel_parm {
49 	char			name[IFNAMSIZ];
50 	int			link;
51 	__be16			i_flags;
52 	__be16			o_flags;
53 	__be32			i_key;
54 	__be32			o_key;
55 	struct iphdr		iph;
56 };
57 
58 enum {
59 	IFLA_IPTUN_UNSPEC,
60 	IFLA_IPTUN_LINK,
61 	IFLA_IPTUN_LOCAL,
62 	IFLA_IPTUN_REMOTE,
63 	IFLA_IPTUN_TTL,
64 	IFLA_IPTUN_TOS,
65 	IFLA_IPTUN_ENCAP_LIMIT,
66 	IFLA_IPTUN_FLOWINFO,
67 	IFLA_IPTUN_FLAGS,
68 	IFLA_IPTUN_PROTO,
69 	IFLA_IPTUN_PMTUDISC,
70 	IFLA_IPTUN_6RD_PREFIX,
71 	IFLA_IPTUN_6RD_RELAY_PREFIX,
72 	IFLA_IPTUN_6RD_PREFIXLEN,
73 	IFLA_IPTUN_6RD_RELAY_PREFIXLEN,
74 	IFLA_IPTUN_ENCAP_TYPE,
75 	IFLA_IPTUN_ENCAP_FLAGS,
76 	IFLA_IPTUN_ENCAP_SPORT,
77 	IFLA_IPTUN_ENCAP_DPORT,
78 	IFLA_IPTUN_COLLECT_METADATA,
79 	IFLA_IPTUN_FWMARK,
80 	__IFLA_IPTUN_MAX,
81 };
82 #define IFLA_IPTUN_MAX	(__IFLA_IPTUN_MAX - 1)
83 
84 enum tunnel_encap_types {
85 	TUNNEL_ENCAP_NONE,
86 	TUNNEL_ENCAP_FOU,
87 	TUNNEL_ENCAP_GUE,
88 	TUNNEL_ENCAP_MPLS,
89 };
90 
91 #define TUNNEL_ENCAP_FLAG_CSUM		(1<<0)
92 #define TUNNEL_ENCAP_FLAG_CSUM6		(1<<1)
93 #define TUNNEL_ENCAP_FLAG_REMCSUM	(1<<2)
94 
95 /* SIT-mode i_flags */
96 #define	SIT_ISATAP	0x0001
97 
98 struct ip_tunnel_prl {
99 	__be32			addr;
100 	__u16			flags;
101 	__u16			__reserved;
102 	__u32			datalen;
103 	__u32			__reserved2;
104 	/* data follows */
105 };
106 
107 /* PRL flags */
108 #define	PRL_DEFAULT		0x0001
109 
110 struct ip_tunnel_6rd {
111 	struct in6_addr		prefix;
112 	__be32			relay_prefix;
113 	__u16			prefixlen;
114 	__u16			relay_prefixlen;
115 };
116 
117 enum {
118 	IFLA_GRE_UNSPEC,
119 	IFLA_GRE_LINK,
120 	IFLA_GRE_IFLAGS,
121 	IFLA_GRE_OFLAGS,
122 	IFLA_GRE_IKEY,
123 	IFLA_GRE_OKEY,
124 	IFLA_GRE_LOCAL,
125 	IFLA_GRE_REMOTE,
126 	IFLA_GRE_TTL,
127 	IFLA_GRE_TOS,
128 	IFLA_GRE_PMTUDISC,
129 	IFLA_GRE_ENCAP_LIMIT,
130 	IFLA_GRE_FLOWINFO,
131 	IFLA_GRE_FLAGS,
132 	IFLA_GRE_ENCAP_TYPE,
133 	IFLA_GRE_ENCAP_FLAGS,
134 	IFLA_GRE_ENCAP_SPORT,
135 	IFLA_GRE_ENCAP_DPORT,
136 	IFLA_GRE_COLLECT_METADATA,
137 	IFLA_GRE_IGNORE_DF,
138 	IFLA_GRE_FWMARK,
139 	IFLA_GRE_ERSPAN_INDEX,
140 	IFLA_GRE_ERSPAN_VER,
141 	IFLA_GRE_ERSPAN_DIR,
142 	IFLA_GRE_ERSPAN_HWID,
143 	__IFLA_GRE_MAX,
144 };
145 
146 #define IFLA_GRE_MAX	(__IFLA_GRE_MAX - 1)
147 
148 /* VTI-mode i_flags */
149 #define VTI_ISVTI ((__force __be16)0x0001)
150 
151 enum {
152 	IFLA_VTI_UNSPEC,
153 	IFLA_VTI_LINK,
154 	IFLA_VTI_IKEY,
155 	IFLA_VTI_OKEY,
156 	IFLA_VTI_LOCAL,
157 	IFLA_VTI_REMOTE,
158 	IFLA_VTI_FWMARK,
159 	__IFLA_VTI_MAX,
160 };
161 
162 #define IFLA_VTI_MAX	(__IFLA_VTI_MAX - 1)
163 
164 #ifndef __KERNEL__
165 /* Historically, tunnel flags have been defined as __be16 and now there are
166  * no free bits left. It is strongly advised to switch the already existing
167  * userspace code to the new *_BIT definitions from down below, as __be16
168  * can't be simply cast to a wider type on LE systems. All new flags and
169  * code must use *_BIT only.
170  */
171 
172 #define TUNNEL_CSUM		__cpu_to_be16(0x01)
173 #define TUNNEL_ROUTING		__cpu_to_be16(0x02)
174 #define TUNNEL_KEY		__cpu_to_be16(0x04)
175 #define TUNNEL_SEQ		__cpu_to_be16(0x08)
176 #define TUNNEL_STRICT		__cpu_to_be16(0x10)
177 #define TUNNEL_REC		__cpu_to_be16(0x20)
178 #define TUNNEL_VERSION		__cpu_to_be16(0x40)
179 #define TUNNEL_NO_KEY		__cpu_to_be16(0x80)
180 #define TUNNEL_DONT_FRAGMENT    __cpu_to_be16(0x0100)
181 #define TUNNEL_OAM		__cpu_to_be16(0x0200)
182 #define TUNNEL_CRIT_OPT		__cpu_to_be16(0x0400)
183 #define TUNNEL_GENEVE_OPT	__cpu_to_be16(0x0800)
184 #define TUNNEL_VXLAN_OPT	__cpu_to_be16(0x1000)
185 #define TUNNEL_NOCACHE		__cpu_to_be16(0x2000)
186 #define TUNNEL_ERSPAN_OPT	__cpu_to_be16(0x4000)
187 #define TUNNEL_GTP_OPT		__cpu_to_be16(0x8000)
188 
189 #define TUNNEL_OPTIONS_PRESENT \
190 		(TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT | TUNNEL_ERSPAN_OPT | \
191 		TUNNEL_GTP_OPT)
192 #endif
193 
194 enum {
195 	IP_TUNNEL_CSUM_BIT		= 0U,
196 	IP_TUNNEL_ROUTING_BIT,
197 	IP_TUNNEL_KEY_BIT,
198 	IP_TUNNEL_SEQ_BIT,
199 	IP_TUNNEL_STRICT_BIT,
200 	IP_TUNNEL_REC_BIT,
201 	IP_TUNNEL_VERSION_BIT,
202 	IP_TUNNEL_NO_KEY_BIT,
203 	IP_TUNNEL_DONT_FRAGMENT_BIT,
204 	IP_TUNNEL_OAM_BIT,
205 	IP_TUNNEL_CRIT_OPT_BIT,
206 	IP_TUNNEL_GENEVE_OPT_BIT,	/* OPTIONS_PRESENT */
207 	IP_TUNNEL_VXLAN_OPT_BIT,	/* OPTIONS_PRESENT */
208 	IP_TUNNEL_NOCACHE_BIT,
209 	IP_TUNNEL_ERSPAN_OPT_BIT,	/* OPTIONS_PRESENT */
210 	IP_TUNNEL_GTP_OPT_BIT,		/* OPTIONS_PRESENT */
211 
212 	IP_TUNNEL_VTI_BIT,
213 	IP_TUNNEL_SIT_ISATAP_BIT	= IP_TUNNEL_VTI_BIT,
214 
215 	/* Flags starting from here are not available via the old UAPI */
216 	IP_TUNNEL_PFCP_OPT_BIT,		/* OPTIONS_PRESENT */
217 
218 	__IP_TUNNEL_FLAG_NUM,
219 };
220 
221 #endif /* _UAPI_IF_TUNNEL_H_ */
222