1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* PPTP constants and structs */
3 #ifndef _NF_CONNTRACK_PPTP_H
4 #define _NF_CONNTRACK_PPTP_H
5 
6 #include <linux/netfilter.h>
7 #include <linux/skbuff.h>
8 #include <linux/types.h>
9 #include <linux/netfilter/nf_conntrack_common.h>
10 #include <net/netfilter/nf_conntrack_expect.h>
11 #include <uapi/linux/netfilter/nf_conntrack_tuple_common.h>
12 
13 const char *pptp_msg_name(u_int16_t msg);
14 
15 /* state of the control session */
16 enum pptp_ctrlsess_state {
17 	PPTP_SESSION_NONE,			/* no session present */
18 	PPTP_SESSION_ERROR,			/* some session error */
19 	PPTP_SESSION_STOPREQ,			/* stop_sess request seen */
20 	PPTP_SESSION_REQUESTED,			/* start_sess request seen */
21 	PPTP_SESSION_CONFIRMED,			/* session established */
22 };
23 
24 /* state of the call inside the control session */
25 enum pptp_ctrlcall_state {
26 	PPTP_CALL_NONE,
27 	PPTP_CALL_ERROR,
28 	PPTP_CALL_OUT_REQ,
29 	PPTP_CALL_OUT_CONF,
30 	PPTP_CALL_IN_REQ,
31 	PPTP_CALL_IN_REP,
32 	PPTP_CALL_IN_CONF,
33 	PPTP_CALL_CLEAR_REQ,
34 };
35 
36 /* conntrack private data */
37 struct nf_ct_pptp_master {
38 	enum pptp_ctrlsess_state sstate;	/* session state */
39 	enum pptp_ctrlcall_state cstate;	/* call state */
40 	__be16 pac_call_id;			/* call id of PAC */
41 	__be16 pns_call_id;			/* call id of PNS */
42 
43 	/* in pre-2.6.11 this used to be per-expect. Now it is per-conntrack
44 	 * and therefore imposes a fixed limit on the number of maps */
45 	struct nf_ct_gre_keymap *keymap[IP_CT_DIR_MAX];
46 };
47 
48 struct nf_nat_pptp {
49 	__be16 pns_call_id;			/* NAT'ed PNS call id */
50 	__be16 pac_call_id;			/* NAT'ed PAC call id */
51 };
52 
53 #define PPTP_CONTROL_PORT	1723
54 
55 #define PPTP_PACKET_CONTROL	1
56 #define PPTP_PACKET_MGMT	2
57 
58 #define PPTP_MAGIC_COOKIE	0x1a2b3c4d
59 
60 struct pptp_pkt_hdr {
61 	__u16	packetLength;
62 	__be16	packetType;
63 	__be32	magicCookie;
64 };
65 
66 /* PptpControlMessageType values */
67 #define PPTP_START_SESSION_REQUEST	1
68 #define PPTP_START_SESSION_REPLY	2
69 #define PPTP_STOP_SESSION_REQUEST	3
70 #define PPTP_STOP_SESSION_REPLY		4
71 #define PPTP_ECHO_REQUEST		5
72 #define PPTP_ECHO_REPLY			6
73 #define PPTP_OUT_CALL_REQUEST		7
74 #define PPTP_OUT_CALL_REPLY		8
75 #define PPTP_IN_CALL_REQUEST		9
76 #define PPTP_IN_CALL_REPLY		10
77 #define PPTP_IN_CALL_CONNECT		11
78 #define PPTP_CALL_CLEAR_REQUEST		12
79 #define PPTP_CALL_DISCONNECT_NOTIFY	13
80 #define PPTP_WAN_ERROR_NOTIFY		14
81 #define PPTP_SET_LINK_INFO		15
82 
83 #define PPTP_MSG_MAX			15
84 
85 /* PptpGeneralError values */
86 #define PPTP_ERROR_CODE_NONE		0
87 #define PPTP_NOT_CONNECTED		1
88 #define PPTP_BAD_FORMAT			2
89 #define PPTP_BAD_VALUE			3
90 #define PPTP_NO_RESOURCE		4
91 #define PPTP_BAD_CALLID			5
92 #define PPTP_REMOVE_DEVICE_ERROR	6
93 
94 struct PptpControlHeader {
95 	__be16	messageType;
96 	__u16	reserved;
97 };
98 
99 /* FramingCapability Bitmap Values */
100 #define PPTP_FRAME_CAP_ASYNC		0x1
101 #define PPTP_FRAME_CAP_SYNC		0x2
102 
103 /* BearerCapability Bitmap Values */
104 #define PPTP_BEARER_CAP_ANALOG		0x1
105 #define PPTP_BEARER_CAP_DIGITAL		0x2
106 
107 struct PptpStartSessionRequest {
108 	__be16	protocolVersion;
109 	__u16	reserved1;
110 	__be32	framingCapability;
111 	__be32	bearerCapability;
112 	__be16	maxChannels;
113 	__be16	firmwareRevision;
114 	__u8	hostName[64];
115 	__u8	vendorString[64];
116 };
117 
118 /* PptpStartSessionResultCode Values */
119 #define PPTP_START_OK			1
120 #define PPTP_START_GENERAL_ERROR	2
121 #define PPTP_START_ALREADY_CONNECTED	3
122 #define PPTP_START_NOT_AUTHORIZED	4
123 #define PPTP_START_UNKNOWN_PROTOCOL	5
124 
125 struct PptpStartSessionReply {
126 	__be16	protocolVersion;
127 	__u8	resultCode;
128 	__u8	generalErrorCode;
129 	__be32	framingCapability;
130 	__be32	bearerCapability;
131 	__be16	maxChannels;
132 	__be16	firmwareRevision;
133 	__u8	hostName[64];
134 	__u8	vendorString[64];
135 };
136 
137 /* PptpStopReasons */
138 #define PPTP_STOP_NONE			1
139 #define PPTP_STOP_PROTOCOL		2
140 #define PPTP_STOP_LOCAL_SHUTDOWN	3
141 
142 struct PptpStopSessionRequest {
143 	__u8	reason;
144 	__u8	reserved1;
145 	__u16	reserved2;
146 };
147 
148 /* PptpStopSessionResultCode */
149 #define PPTP_STOP_OK			1
150 #define PPTP_STOP_GENERAL_ERROR		2
151 
152 struct PptpStopSessionReply {
153 	__u8	resultCode;
154 	__u8	generalErrorCode;
155 	__u16	reserved1;
156 };
157 
158 struct PptpEchoRequest {
159 	__be32 identNumber;
160 };
161 
162 /* PptpEchoReplyResultCode */
163 #define PPTP_ECHO_OK			1
164 #define PPTP_ECHO_GENERAL_ERROR		2
165 
166 struct PptpEchoReply {
167 	__be32	identNumber;
168 	__u8	resultCode;
169 	__u8	generalErrorCode;
170 	__u16	reserved;
171 };
172 
173 /* PptpFramingType */
174 #define PPTP_ASYNC_FRAMING		1
175 #define PPTP_SYNC_FRAMING		2
176 #define PPTP_DONT_CARE_FRAMING		3
177 
178 /* PptpCallBearerType */
179 #define PPTP_ANALOG_TYPE		1
180 #define PPTP_DIGITAL_TYPE		2
181 #define PPTP_DONT_CARE_BEARER_TYPE	3
182 
183 struct PptpOutCallRequest {
184 	__be16	callID;
185 	__be16	callSerialNumber;
186 	__be32	minBPS;
187 	__be32	maxBPS;
188 	__be32	bearerType;
189 	__be32	framingType;
190 	__be16	packetWindow;
191 	__be16	packetProcDelay;
192 	__be16	phoneNumberLength;
193 	__u16	reserved1;
194 	__u8	phoneNumber[64];
195 	__u8	subAddress[64];
196 };
197 
198 /* PptpCallResultCode */
199 #define PPTP_OUTCALL_CONNECT		1
200 #define PPTP_OUTCALL_GENERAL_ERROR	2
201 #define PPTP_OUTCALL_NO_CARRIER		3
202 #define PPTP_OUTCALL_BUSY		4
203 #define PPTP_OUTCALL_NO_DIAL_TONE	5
204 #define PPTP_OUTCALL_TIMEOUT		6
205 #define PPTP_OUTCALL_DONT_ACCEPT	7
206 
207 struct PptpOutCallReply {
208 	__be16	callID;
209 	__be16	peersCallID;
210 	__u8	resultCode;
211 	__u8	generalErrorCode;
212 	__be16	causeCode;
213 	__be32	connectSpeed;
214 	__be16	packetWindow;
215 	__be16	packetProcDelay;
216 	__be32	physChannelID;
217 };
218 
219 struct PptpInCallRequest {
220 	__be16	callID;
221 	__be16	callSerialNumber;
222 	__be32	callBearerType;
223 	__be32	physChannelID;
224 	__be16	dialedNumberLength;
225 	__be16	dialingNumberLength;
226 	__u8	dialedNumber[64];
227 	__u8	dialingNumber[64];
228 	__u8	subAddress[64];
229 };
230 
231 /* PptpInCallResultCode */
232 #define PPTP_INCALL_ACCEPT		1
233 #define PPTP_INCALL_GENERAL_ERROR	2
234 #define PPTP_INCALL_DONT_ACCEPT		3
235 
236 struct PptpInCallReply {
237 	__be16	callID;
238 	__be16	peersCallID;
239 	__u8	resultCode;
240 	__u8	generalErrorCode;
241 	__be16	packetWindow;
242 	__be16	packetProcDelay;
243 	__u16	reserved;
244 };
245 
246 struct PptpInCallConnected {
247 	__be16	peersCallID;
248 	__u16	reserved;
249 	__be32	connectSpeed;
250 	__be16	packetWindow;
251 	__be16	packetProcDelay;
252 	__be32	callFramingType;
253 };
254 
255 struct PptpClearCallRequest {
256 	__be16	callID;
257 	__u16	reserved;
258 };
259 
260 struct PptpCallDisconnectNotify {
261 	__be16	callID;
262 	__u8	resultCode;
263 	__u8	generalErrorCode;
264 	__be16	causeCode;
265 	__u16	reserved;
266 	__u8	callStatistics[128];
267 };
268 
269 struct PptpWanErrorNotify {
270 	__be16	peersCallID;
271 	__u16	reserved;
272 	__be32	crcErrors;
273 	__be32	framingErrors;
274 	__be32	hardwareOverRuns;
275 	__be32	bufferOverRuns;
276 	__be32	timeoutErrors;
277 	__be32	alignmentErrors;
278 };
279 
280 struct PptpSetLinkInfo {
281 	__be16	peersCallID;
282 	__u16	reserved;
283 	__be32	sendAccm;
284 	__be32	recvAccm;
285 };
286 
287 union pptp_ctrl_union {
288 	struct PptpStartSessionRequest	sreq;
289 	struct PptpStartSessionReply	srep;
290 	struct PptpStopSessionRequest	streq;
291 	struct PptpStopSessionReply	strep;
292 	struct PptpOutCallRequest	ocreq;
293 	struct PptpOutCallReply		ocack;
294 	struct PptpInCallRequest	icreq;
295 	struct PptpInCallReply		icack;
296 	struct PptpInCallConnected	iccon;
297 	struct PptpClearCallRequest	clrreq;
298 	struct PptpCallDisconnectNotify disc;
299 	struct PptpWanErrorNotify	wanerr;
300 	struct PptpSetLinkInfo		setlink;
301 };
302 
303 struct nf_nat_pptp_hook {
304 	int (*outbound)(struct sk_buff *skb,
305 			struct nf_conn *ct, enum ip_conntrack_info ctinfo,
306 			unsigned int protoff,
307 			struct PptpControlHeader *ctlh,
308 			union pptp_ctrl_union *pptpReq);
309 	int (*inbound)(struct sk_buff *skb,
310 		       struct nf_conn *ct, enum ip_conntrack_info ctinfo,
311 		       unsigned int protoff,
312 		       struct PptpControlHeader *ctlh,
313 		       union pptp_ctrl_union *pptpReq);
314 	void (*exp_gre)(struct nf_conntrack_expect *exp_orig,
315 			struct nf_conntrack_expect *exp_reply);
316 	void (*expectfn)(struct nf_conn *ct,
317 			 struct nf_conntrack_expect *exp);
318 };
319 
320 extern const struct nf_nat_pptp_hook __rcu *nf_nat_pptp_hook;
321 #endif /* _NF_CONNTRACK_PPTP_H */
322