xref: /linux/include/linux/netfilter/nf_conntrack_pptp.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
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_PACKET_CONTROL	1
54 #define PPTP_PACKET_MGMT	2
55 
56 #define PPTP_MAGIC_COOKIE	0x1a2b3c4d
57 
58 struct pptp_pkt_hdr {
59 	__u16	packetLength;
60 	__be16	packetType;
61 	__be32	magicCookie;
62 };
63 
64 /* PptpControlMessageType values */
65 #define PPTP_START_SESSION_REQUEST	1
66 #define PPTP_START_SESSION_REPLY	2
67 #define PPTP_STOP_SESSION_REQUEST	3
68 #define PPTP_STOP_SESSION_REPLY		4
69 #define PPTP_ECHO_REQUEST		5
70 #define PPTP_ECHO_REPLY			6
71 #define PPTP_OUT_CALL_REQUEST		7
72 #define PPTP_OUT_CALL_REPLY		8
73 #define PPTP_IN_CALL_REQUEST		9
74 #define PPTP_IN_CALL_REPLY		10
75 #define PPTP_IN_CALL_CONNECT		11
76 #define PPTP_CALL_CLEAR_REQUEST		12
77 #define PPTP_CALL_DISCONNECT_NOTIFY	13
78 #define PPTP_WAN_ERROR_NOTIFY		14
79 #define PPTP_SET_LINK_INFO		15
80 
81 #define PPTP_MSG_MAX			15
82 
83 /* PptpGeneralError values */
84 #define PPTP_ERROR_CODE_NONE		0
85 #define PPTP_NOT_CONNECTED		1
86 #define PPTP_BAD_FORMAT			2
87 #define PPTP_BAD_VALUE			3
88 #define PPTP_NO_RESOURCE		4
89 #define PPTP_BAD_CALLID			5
90 #define PPTP_REMOVE_DEVICE_ERROR	6
91 
92 struct PptpControlHeader {
93 	__be16	messageType;
94 	__u16	reserved;
95 };
96 
97 /* FramingCapability Bitmap Values */
98 #define PPTP_FRAME_CAP_ASYNC		0x1
99 #define PPTP_FRAME_CAP_SYNC		0x2
100 
101 /* BearerCapability Bitmap Values */
102 #define PPTP_BEARER_CAP_ANALOG		0x1
103 #define PPTP_BEARER_CAP_DIGITAL		0x2
104 
105 struct PptpStartSessionRequest {
106 	__be16	protocolVersion;
107 	__u16	reserved1;
108 	__be32	framingCapability;
109 	__be32	bearerCapability;
110 	__be16	maxChannels;
111 	__be16	firmwareRevision;
112 	__u8	hostName[64];
113 	__u8	vendorString[64];
114 };
115 
116 /* PptpStartSessionResultCode Values */
117 #define PPTP_START_OK			1
118 #define PPTP_START_GENERAL_ERROR	2
119 #define PPTP_START_ALREADY_CONNECTED	3
120 #define PPTP_START_NOT_AUTHORIZED	4
121 #define PPTP_START_UNKNOWN_PROTOCOL	5
122 
123 struct PptpStartSessionReply {
124 	__be16	protocolVersion;
125 	__u8	resultCode;
126 	__u8	generalErrorCode;
127 	__be32	framingCapability;
128 	__be32	bearerCapability;
129 	__be16	maxChannels;
130 	__be16	firmwareRevision;
131 	__u8	hostName[64];
132 	__u8	vendorString[64];
133 };
134 
135 /* PptpStopReasons */
136 #define PPTP_STOP_NONE			1
137 #define PPTP_STOP_PROTOCOL		2
138 #define PPTP_STOP_LOCAL_SHUTDOWN	3
139 
140 struct PptpStopSessionRequest {
141 	__u8	reason;
142 	__u8	reserved1;
143 	__u16	reserved2;
144 };
145 
146 /* PptpStopSessionResultCode */
147 #define PPTP_STOP_OK			1
148 #define PPTP_STOP_GENERAL_ERROR		2
149 
150 struct PptpStopSessionReply {
151 	__u8	resultCode;
152 	__u8	generalErrorCode;
153 	__u16	reserved1;
154 };
155 
156 struct PptpEchoRequest {
157 	__be32 identNumber;
158 };
159 
160 /* PptpEchoReplyResultCode */
161 #define PPTP_ECHO_OK			1
162 #define PPTP_ECHO_GENERAL_ERROR		2
163 
164 struct PptpEchoReply {
165 	__be32	identNumber;
166 	__u8	resultCode;
167 	__u8	generalErrorCode;
168 	__u16	reserved;
169 };
170 
171 /* PptpFramingType */
172 #define PPTP_ASYNC_FRAMING		1
173 #define PPTP_SYNC_FRAMING		2
174 #define PPTP_DONT_CARE_FRAMING		3
175 
176 /* PptpCallBearerType */
177 #define PPTP_ANALOG_TYPE		1
178 #define PPTP_DIGITAL_TYPE		2
179 #define PPTP_DONT_CARE_BEARER_TYPE	3
180 
181 struct PptpOutCallRequest {
182 	__be16	callID;
183 	__be16	callSerialNumber;
184 	__be32	minBPS;
185 	__be32	maxBPS;
186 	__be32	bearerType;
187 	__be32	framingType;
188 	__be16	packetWindow;
189 	__be16	packetProcDelay;
190 	__be16	phoneNumberLength;
191 	__u16	reserved1;
192 	__u8	phoneNumber[64];
193 	__u8	subAddress[64];
194 };
195 
196 /* PptpCallResultCode */
197 #define PPTP_OUTCALL_CONNECT		1
198 #define PPTP_OUTCALL_GENERAL_ERROR	2
199 #define PPTP_OUTCALL_NO_CARRIER		3
200 #define PPTP_OUTCALL_BUSY		4
201 #define PPTP_OUTCALL_NO_DIAL_TONE	5
202 #define PPTP_OUTCALL_TIMEOUT		6
203 #define PPTP_OUTCALL_DONT_ACCEPT	7
204 
205 struct PptpOutCallReply {
206 	__be16	callID;
207 	__be16	peersCallID;
208 	__u8	resultCode;
209 	__u8	generalErrorCode;
210 	__be16	causeCode;
211 	__be32	connectSpeed;
212 	__be16	packetWindow;
213 	__be16	packetProcDelay;
214 	__be32	physChannelID;
215 };
216 
217 struct PptpInCallRequest {
218 	__be16	callID;
219 	__be16	callSerialNumber;
220 	__be32	callBearerType;
221 	__be32	physChannelID;
222 	__be16	dialedNumberLength;
223 	__be16	dialingNumberLength;
224 	__u8	dialedNumber[64];
225 	__u8	dialingNumber[64];
226 	__u8	subAddress[64];
227 };
228 
229 /* PptpInCallResultCode */
230 #define PPTP_INCALL_ACCEPT		1
231 #define PPTP_INCALL_GENERAL_ERROR	2
232 #define PPTP_INCALL_DONT_ACCEPT		3
233 
234 struct PptpInCallReply {
235 	__be16	callID;
236 	__be16	peersCallID;
237 	__u8	resultCode;
238 	__u8	generalErrorCode;
239 	__be16	packetWindow;
240 	__be16	packetProcDelay;
241 	__u16	reserved;
242 };
243 
244 struct PptpInCallConnected {
245 	__be16	peersCallID;
246 	__u16	reserved;
247 	__be32	connectSpeed;
248 	__be16	packetWindow;
249 	__be16	packetProcDelay;
250 	__be32	callFramingType;
251 };
252 
253 struct PptpClearCallRequest {
254 	__be16	callID;
255 	__u16	reserved;
256 };
257 
258 struct PptpCallDisconnectNotify {
259 	__be16	callID;
260 	__u8	resultCode;
261 	__u8	generalErrorCode;
262 	__be16	causeCode;
263 	__u16	reserved;
264 	__u8	callStatistics[128];
265 };
266 
267 struct PptpWanErrorNotify {
268 	__be16	peersCallID;
269 	__u16	reserved;
270 	__be32	crcErrors;
271 	__be32	framingErrors;
272 	__be32	hardwareOverRuns;
273 	__be32	bufferOverRuns;
274 	__be32	timeoutErrors;
275 	__be32	alignmentErrors;
276 };
277 
278 struct PptpSetLinkInfo {
279 	__be16	peersCallID;
280 	__u16	reserved;
281 	__be32	sendAccm;
282 	__be32	recvAccm;
283 };
284 
285 union pptp_ctrl_union {
286 	struct PptpStartSessionRequest	sreq;
287 	struct PptpStartSessionReply	srep;
288 	struct PptpStopSessionRequest	streq;
289 	struct PptpStopSessionReply	strep;
290 	struct PptpOutCallRequest	ocreq;
291 	struct PptpOutCallReply		ocack;
292 	struct PptpInCallRequest	icreq;
293 	struct PptpInCallReply		icack;
294 	struct PptpInCallConnected	iccon;
295 	struct PptpClearCallRequest	clrreq;
296 	struct PptpCallDisconnectNotify disc;
297 	struct PptpWanErrorNotify	wanerr;
298 	struct PptpSetLinkInfo		setlink;
299 };
300 
301 struct nf_nat_pptp_hook {
302 	int (*outbound)(struct sk_buff *skb,
303 			struct nf_conn *ct, enum ip_conntrack_info ctinfo,
304 			unsigned int protoff,
305 			struct PptpControlHeader *ctlh,
306 			union pptp_ctrl_union *pptpReq);
307 	int (*inbound)(struct sk_buff *skb,
308 		       struct nf_conn *ct, enum ip_conntrack_info ctinfo,
309 		       unsigned int protoff,
310 		       struct PptpControlHeader *ctlh,
311 		       union pptp_ctrl_union *pptpReq);
312 	void (*exp_gre)(struct nf_conntrack_expect *exp_orig,
313 			struct nf_conntrack_expect *exp_reply);
314 	void (*expectfn)(struct nf_conn *ct,
315 			 struct nf_conntrack_expect *exp);
316 };
317 
318 extern const struct nf_nat_pptp_hook __rcu *nf_nat_pptp_hook;
319 #endif /* _NF_CONNTRACK_PPTP_H */
320