add netfilter TTL module
[openwrt.git] / openwrt / package / linux / kernel-patches / 308-netfilter-nat-pptp
1 diff -urN linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack.h
2 --- linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack.h 2005-04-02 19:04:11.000000000 +0200
3 +++ linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack.h 2005-04-02 19:41:05.000000000 +0200
4 @@ -50,16 +50,19 @@
5
6 #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
7 #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
8 +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
9
10 /* per conntrack: protocol private data */
11 union ip_conntrack_proto {
12 /* insert conntrack proto private data here */
13 struct ip_ct_tcp tcp;
14 struct ip_ct_icmp icmp;
15 + struct ip_ct_gre gre;
16 };
17
18 union ip_conntrack_expect_proto {
19 /* insert expect proto private data here */
20 + struct ip_ct_gre_expect gre;
21 };
22
23 /* Add protocol helper include file here */
24 @@ -67,6 +70,7 @@
25
26 #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
27 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
28 +#include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
29
30 /* per expectation: application helper private data */
31 union ip_conntrack_expect_help {
32 @@ -74,6 +78,7 @@
33 struct ip_ct_amanda_expect exp_amanda_info;
34 struct ip_ct_ftp_expect exp_ftp_info;
35 struct ip_ct_irc_expect exp_irc_info;
36 + struct ip_ct_pptp_expect exp_pptp_info;
37
38 #ifdef CONFIG_IP_NF_NAT_NEEDED
39 union {
40 @@ -87,14 +92,17 @@
41 /* insert conntrack helper private data (master) here */
42 struct ip_ct_ftp_master ct_ftp_info;
43 struct ip_ct_irc_master ct_irc_info;
44 + struct ip_ct_pptp_master ct_pptp_info;
45 };
46
47 #ifdef CONFIG_IP_NF_NAT_NEEDED
48 #include <linux/netfilter_ipv4/ip_nat.h>
49 +#include <linux/netfilter_ipv4/ip_nat_pptp.h>
50
51 /* per conntrack: nat application helper private data */
52 union ip_conntrack_nat_help {
53 /* insert nat helper private data here */
54 + struct ip_nat_pptp nat_pptp_info;
55 };
56 #endif
57
58 diff -urN linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_pptp.h linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_pptp.h
59 --- linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_pptp.h 1970-01-01 01:00:00.000000000 +0100
60 +++ linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_pptp.h 2005-04-02 19:09:07.000000000 +0200
61 @@ -0,0 +1,313 @@
62 +/* PPTP constants and structs */
63 +#ifndef _CONNTRACK_PPTP_H
64 +#define _CONNTRACK_PPTP_H
65 +
66 +/* state of the control session */
67 +enum pptp_ctrlsess_state {
68 + PPTP_SESSION_NONE, /* no session present */
69 + PPTP_SESSION_ERROR, /* some session error */
70 + PPTP_SESSION_STOPREQ, /* stop_sess request seen */
71 + PPTP_SESSION_REQUESTED, /* start_sess request seen */
72 + PPTP_SESSION_CONFIRMED, /* session established */
73 +};
74 +
75 +/* state of the call inside the control session */
76 +enum pptp_ctrlcall_state {
77 + PPTP_CALL_NONE,
78 + PPTP_CALL_ERROR,
79 + PPTP_CALL_OUT_REQ,
80 + PPTP_CALL_OUT_CONF,
81 + PPTP_CALL_IN_REQ,
82 + PPTP_CALL_IN_REP,
83 + PPTP_CALL_IN_CONF,
84 + PPTP_CALL_CLEAR_REQ,
85 +};
86 +
87 +
88 +/* conntrack private data */
89 +struct ip_ct_pptp_master {
90 + enum pptp_ctrlsess_state sstate; /* session state */
91 +
92 + /* everything below is going to be per-expectation in newnat,
93 + * since there could be more than one call within one session */
94 + enum pptp_ctrlcall_state cstate; /* call state */
95 + u_int16_t pac_call_id; /* call id of PAC, host byte order */
96 + u_int16_t pns_call_id; /* call id of PNS, host byte order */
97 +};
98 +
99 +/* conntrack_expect private member */
100 +struct ip_ct_pptp_expect {
101 + enum pptp_ctrlcall_state cstate; /* call state */
102 + u_int16_t pac_call_id; /* call id of PAC */
103 + u_int16_t pns_call_id; /* call id of PNS */
104 +};
105 +
106 +
107 +#ifdef __KERNEL__
108 +
109 +#include <linux/netfilter_ipv4/lockhelp.h>
110 +DECLARE_LOCK_EXTERN(ip_pptp_lock);
111 +
112 +#define IP_CONNTR_PPTP PPTP_CONTROL_PORT
113 +
114 +union pptp_ctrl_union {
115 + void *rawreq;
116 + struct PptpStartSessionRequest *sreq;
117 + struct PptpStartSessionReply *srep;
118 + struct PptpStopSessionRequest *streq;
119 + struct PptpStopSessionReply *strep;
120 + struct PptpOutCallRequest *ocreq;
121 + struct PptpOutCallReply *ocack;
122 + struct PptpInCallRequest *icreq;
123 + struct PptpInCallReply *icack;
124 + struct PptpInCallConnected *iccon;
125 + struct PptpClearCallRequest *clrreq;
126 + struct PptpCallDisconnectNotify *disc;
127 + struct PptpWanErrorNotify *wanerr;
128 + struct PptpSetLinkInfo *setlink;
129 +};
130 +
131 +
132 +
133 +#define PPTP_CONTROL_PORT 1723
134 +
135 +#define PPTP_PACKET_CONTROL 1
136 +#define PPTP_PACKET_MGMT 2
137 +
138 +#define PPTP_MAGIC_COOKIE 0x1a2b3c4d
139 +
140 +struct pptp_pkt_hdr {
141 + __u16 packetLength;
142 + __u16 packetType;
143 + __u32 magicCookie;
144 +};
145 +
146 +/* PptpControlMessageType values */
147 +#define PPTP_START_SESSION_REQUEST 1
148 +#define PPTP_START_SESSION_REPLY 2
149 +#define PPTP_STOP_SESSION_REQUEST 3
150 +#define PPTP_STOP_SESSION_REPLY 4
151 +#define PPTP_ECHO_REQUEST 5
152 +#define PPTP_ECHO_REPLY 6
153 +#define PPTP_OUT_CALL_REQUEST 7
154 +#define PPTP_OUT_CALL_REPLY 8
155 +#define PPTP_IN_CALL_REQUEST 9
156 +#define PPTP_IN_CALL_REPLY 10
157 +#define PPTP_IN_CALL_CONNECT 11
158 +#define PPTP_CALL_CLEAR_REQUEST 12
159 +#define PPTP_CALL_DISCONNECT_NOTIFY 13
160 +#define PPTP_WAN_ERROR_NOTIFY 14
161 +#define PPTP_SET_LINK_INFO 15
162 +
163 +#define PPTP_MSG_MAX 15
164 +
165 +/* PptpGeneralError values */
166 +#define PPTP_ERROR_CODE_NONE 0
167 +#define PPTP_NOT_CONNECTED 1
168 +#define PPTP_BAD_FORMAT 2
169 +#define PPTP_BAD_VALUE 3
170 +#define PPTP_NO_RESOURCE 4
171 +#define PPTP_BAD_CALLID 5
172 +#define PPTP_REMOVE_DEVICE_ERROR 6
173 +
174 +struct PptpControlHeader {
175 + __u16 messageType;
176 + __u16 reserved;
177 +};
178 +
179 +/* FramingCapability Bitmap Values */
180 +#define PPTP_FRAME_CAP_ASYNC 0x1
181 +#define PPTP_FRAME_CAP_SYNC 0x2
182 +
183 +/* BearerCapability Bitmap Values */
184 +#define PPTP_BEARER_CAP_ANALOG 0x1
185 +#define PPTP_BEARER_CAP_DIGITAL 0x2
186 +
187 +struct PptpStartSessionRequest {
188 + __u16 protocolVersion;
189 + __u8 reserved1;
190 + __u8 reserved2;
191 + __u32 framingCapability;
192 + __u32 bearerCapability;
193 + __u16 maxChannels;
194 + __u16 firmwareRevision;
195 + __u8 hostName[64];
196 + __u8 vendorString[64];
197 +};
198 +
199 +/* PptpStartSessionResultCode Values */
200 +#define PPTP_START_OK 1
201 +#define PPTP_START_GENERAL_ERROR 2
202 +#define PPTP_START_ALREADY_CONNECTED 3
203 +#define PPTP_START_NOT_AUTHORIZED 4
204 +#define PPTP_START_UNKNOWN_PROTOCOL 5
205 +
206 +struct PptpStartSessionReply {
207 + __u16 protocolVersion;
208 + __u8 resultCode;
209 + __u8 generalErrorCode;
210 + __u32 framingCapability;
211 + __u32 bearerCapability;
212 + __u16 maxChannels;
213 + __u16 firmwareRevision;
214 + __u8 hostName[64];
215 + __u8 vendorString[64];
216 +};
217 +
218 +/* PptpStopReasons */
219 +#define PPTP_STOP_NONE 1
220 +#define PPTP_STOP_PROTOCOL 2
221 +#define PPTP_STOP_LOCAL_SHUTDOWN 3
222 +
223 +struct PptpStopSessionRequest {
224 + __u8 reason;
225 +};
226 +
227 +/* PptpStopSessionResultCode */
228 +#define PPTP_STOP_OK 1
229 +#define PPTP_STOP_GENERAL_ERROR 2
230 +
231 +struct PptpStopSessionReply {
232 + __u8 resultCode;
233 + __u8 generalErrorCode;
234 +};
235 +
236 +struct PptpEchoRequest {
237 + __u32 identNumber;
238 +};
239 +
240 +/* PptpEchoReplyResultCode */
241 +#define PPTP_ECHO_OK 1
242 +#define PPTP_ECHO_GENERAL_ERROR 2
243 +
244 +struct PptpEchoReply {
245 + __u32 identNumber;
246 + __u8 resultCode;
247 + __u8 generalErrorCode;
248 + __u16 reserved;
249 +};
250 +
251 +/* PptpFramingType */
252 +#define PPTP_ASYNC_FRAMING 1
253 +#define PPTP_SYNC_FRAMING 2
254 +#define PPTP_DONT_CARE_FRAMING 3
255 +
256 +/* PptpCallBearerType */
257 +#define PPTP_ANALOG_TYPE 1
258 +#define PPTP_DIGITAL_TYPE 2
259 +#define PPTP_DONT_CARE_BEARER_TYPE 3
260 +
261 +struct PptpOutCallRequest {
262 + __u16 callID;
263 + __u16 callSerialNumber;
264 + __u32 minBPS;
265 + __u32 maxBPS;
266 + __u32 bearerType;
267 + __u32 framingType;
268 + __u16 packetWindow;
269 + __u16 packetProcDelay;
270 + __u16 reserved1;
271 + __u16 phoneNumberLength;
272 + __u16 reserved2;
273 + __u8 phoneNumber[64];
274 + __u8 subAddress[64];
275 +};
276 +
277 +/* PptpCallResultCode */
278 +#define PPTP_OUTCALL_CONNECT 1
279 +#define PPTP_OUTCALL_GENERAL_ERROR 2
280 +#define PPTP_OUTCALL_NO_CARRIER 3
281 +#define PPTP_OUTCALL_BUSY 4
282 +#define PPTP_OUTCALL_NO_DIAL_TONE 5
283 +#define PPTP_OUTCALL_TIMEOUT 6
284 +#define PPTP_OUTCALL_DONT_ACCEPT 7
285 +
286 +struct PptpOutCallReply {
287 + __u16 callID;
288 + __u16 peersCallID;
289 + __u8 resultCode;
290 + __u8 generalErrorCode;
291 + __u16 causeCode;
292 + __u32 connectSpeed;
293 + __u16 packetWindow;
294 + __u16 packetProcDelay;
295 + __u32 physChannelID;
296 +};
297 +
298 +struct PptpInCallRequest {
299 + __u16 callID;
300 + __u16 callSerialNumber;
301 + __u32 callBearerType;
302 + __u32 physChannelID;
303 + __u16 dialedNumberLength;
304 + __u16 dialingNumberLength;
305 + __u8 dialedNumber[64];
306 + __u8 dialingNumber[64];
307 + __u8 subAddress[64];
308 +};
309 +
310 +/* PptpInCallResultCode */
311 +#define PPTP_INCALL_ACCEPT 1
312 +#define PPTP_INCALL_GENERAL_ERROR 2
313 +#define PPTP_INCALL_DONT_ACCEPT 3
314 +
315 +struct PptpInCallReply {
316 + __u16 callID;
317 + __u16 peersCallID;
318 + __u8 resultCode;
319 + __u8 generalErrorCode;
320 + __u16 packetWindow;
321 + __u16 packetProcDelay;
322 + __u16 reserved;
323 +};
324 +
325 +struct PptpInCallConnected {
326 + __u16 peersCallID;
327 + __u16 reserved;
328 + __u32 connectSpeed;
329 + __u16 packetWindow;
330 + __u16 packetProcDelay;
331 + __u32 callFramingType;
332 +};
333 +
334 +struct PptpClearCallRequest {
335 + __u16 callID;
336 + __u16 reserved;
337 +};
338 +
339 +struct PptpCallDisconnectNotify {
340 + __u16 callID;
341 + __u8 resultCode;
342 + __u8 generalErrorCode;
343 + __u16 causeCode;
344 + __u16 reserved;
345 + __u8 callStatistics[128];
346 +};
347 +
348 +struct PptpWanErrorNotify {
349 + __u16 peersCallID;
350 + __u16 reserved;
351 + __u32 crcErrors;
352 + __u32 framingErrors;
353 + __u32 hardwareOverRuns;
354 + __u32 bufferOverRuns;
355 + __u32 timeoutErrors;
356 + __u32 alignmentErrors;
357 +};
358 +
359 +struct PptpSetLinkInfo {
360 + __u16 peersCallID;
361 + __u16 reserved;
362 + __u32 sendAccm;
363 + __u32 recvAccm;
364 +};
365 +
366 +
367 +struct pptp_priv_data {
368 + __u16 call_id;
369 + __u16 mcall_id;
370 + __u16 pcall_id;
371 +};
372 +
373 +#endif /* __KERNEL__ */
374 +#endif /* _CONNTRACK_PPTP_H */
375 diff -urN linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h
376 --- linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h 1970-01-01 01:00:00.000000000 +0100
377 +++ linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h 2005-04-02 19:10:45.000000000 +0200
378 @@ -0,0 +1,123 @@
379 +#ifndef _CONNTRACK_PROTO_GRE_H
380 +#define _CONNTRACK_PROTO_GRE_H
381 +#include <asm/byteorder.h>
382 +
383 +/* GRE PROTOCOL HEADER */
384 +
385 +/* GRE Version field */
386 +#define GRE_VERSION_1701 0x0
387 +#define GRE_VERSION_PPTP 0x1
388 +
389 +/* GRE Protocol field */
390 +#define GRE_PROTOCOL_PPTP 0x880B
391 +
392 +/* GRE Flags */
393 +#define GRE_FLAG_C 0x80
394 +#define GRE_FLAG_R 0x40
395 +#define GRE_FLAG_K 0x20
396 +#define GRE_FLAG_S 0x10
397 +#define GRE_FLAG_A 0x80
398 +
399 +#define GRE_IS_C(f) ((f)&GRE_FLAG_C)
400 +#define GRE_IS_R(f) ((f)&GRE_FLAG_R)
401 +#define GRE_IS_K(f) ((f)&GRE_FLAG_K)
402 +#define GRE_IS_S(f) ((f)&GRE_FLAG_S)
403 +#define GRE_IS_A(f) ((f)&GRE_FLAG_A)
404 +
405 +/* GRE is a mess: Four different standards */
406 +struct gre_hdr {
407 +#if defined(__LITTLE_ENDIAN_BITFIELD)
408 + __u16 rec:3,
409 + srr:1,
410 + seq:1,
411 + key:1,
412 + routing:1,
413 + csum:1,
414 + version:3,
415 + reserved:4,
416 + ack:1;
417 +#elif defined(__BIG_ENDIAN_BITFIELD)
418 + __u16 csum:1,
419 + routing:1,
420 + key:1,
421 + seq:1,
422 + srr:1,
423 + rec:3,
424 + ack:1,
425 + reserved:4,
426 + version:3;
427 +#else
428 +#error "Adjust your <asm/byteorder.h> defines"
429 +#endif
430 + __u16 protocol;
431 +};
432 +
433 +/* modified GRE header for PPTP */
434 +struct gre_hdr_pptp {
435 + __u8 flags; /* bitfield */
436 + __u8 version; /* should be GRE_VERSION_PPTP */
437 + __u16 protocol; /* should be GRE_PROTOCOL_PPTP */
438 + __u16 payload_len; /* size of ppp payload, not inc. gre header */
439 + __u16 call_id; /* peer's call_id for this session */
440 + __u32 seq; /* sequence number. Present if S==1 */
441 + __u32 ack; /* seq number of highest packet recieved by */
442 + /* sender in this session */
443 +};
444 +
445 +
446 +/* this is part of ip_conntrack */
447 +struct ip_ct_gre {
448 + unsigned int stream_timeout;
449 + unsigned int timeout;
450 +};
451 +
452 +/* this is part of ip_conntrack_expect */
453 +struct ip_ct_gre_expect {
454 + struct ip_ct_gre_keymap *keymap_orig, *keymap_reply;
455 +};
456 +
457 +#ifdef __KERNEL__
458 +struct ip_conntrack_expect;
459 +
460 +/* structure for original <-> reply keymap */
461 +struct ip_ct_gre_keymap {
462 + struct list_head list;
463 +
464 + struct ip_conntrack_tuple tuple;
465 +};
466 +
467 +
468 +/* add new tuple->key_reply pair to keymap */
469 +int ip_ct_gre_keymap_add(struct ip_conntrack_expect *exp,
470 + struct ip_conntrack_tuple *t,
471 + int reply);
472 +
473 +/* change an existing keymap entry */
474 +void ip_ct_gre_keymap_change(struct ip_ct_gre_keymap *km,
475 + struct ip_conntrack_tuple *t);
476 +
477 +/* delete keymap entries */
478 +void ip_ct_gre_keymap_destroy(struct ip_conntrack_expect *exp);
479 +
480 +
481 +/* get pointer to gre key, if present */
482 +static inline u_int32_t *gre_key(struct gre_hdr *greh)
483 +{
484 + if (!greh->key)
485 + return NULL;
486 + if (greh->csum || greh->routing)
487 + return (u_int32_t *) (greh+sizeof(*greh)+4);
488 + return (u_int32_t *) (greh+sizeof(*greh));
489 +}
490 +
491 +/* get pointer ot gre csum, if present */
492 +static inline u_int16_t *gre_csum(struct gre_hdr *greh)
493 +{
494 + if (!greh->csum)
495 + return NULL;
496 + return (u_int16_t *) (greh+sizeof(*greh));
497 +}
498 +
499 +#endif /* __KERNEL__ */
500 +
501 +#endif /* _CONNTRACK_PROTO_GRE_H */
502 diff -urN linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
503 --- linux-2.4.29-old/include/linux/netfilter_ipv4/ip_conntrack_tuple.h 2003-11-28 19:26:21.000000000 +0100
504 +++ linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_conntrack_tuple.h 2005-04-02 19:07:18.000000000 +0200
505 @@ -14,7 +14,7 @@
506 union ip_conntrack_manip_proto
507 {
508 /* Add other protocols here. */
509 - u_int16_t all;
510 + u_int32_t all;
511
512 struct {
513 u_int16_t port;
514 @@ -25,6 +25,9 @@
515 struct {
516 u_int16_t id;
517 } icmp;
518 + struct {
519 + u_int32_t key;
520 + } gre;
521 };
522
523 /* The manipulable part of the tuple. */
524 @@ -44,7 +47,7 @@
525 u_int32_t ip;
526 union {
527 /* Add other protocols here. */
528 - u_int16_t all;
529 + u_int32_t all;
530
531 struct {
532 u_int16_t port;
533 @@ -55,6 +58,9 @@
534 struct {
535 u_int8_t type, code;
536 } icmp;
537 + struct {
538 + u_int32_t key;
539 + } gre;
540 } u;
541
542 /* The protocol. */
543 @@ -80,10 +86,16 @@
544 #ifdef __KERNEL__
545
546 #define DUMP_TUPLE(tp) \
547 -DEBUGP("tuple %p: %u %u.%u.%u.%u:%hu -> %u.%u.%u.%u:%hu\n", \
548 +DEBUGP("tuple %p: %u %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", \
549 (tp), (tp)->dst.protonum, \
550 - NIPQUAD((tp)->src.ip), ntohs((tp)->src.u.all), \
551 - NIPQUAD((tp)->dst.ip), ntohs((tp)->dst.u.all))
552 + NIPQUAD((tp)->src.ip), ntohl((tp)->src.u.all), \
553 + NIPQUAD((tp)->dst.ip), ntohl((tp)->dst.u.all))
554 +
555 +#define DUMP_TUPLE_RAW(x) \
556 + DEBUGP("tuple %p: %u %u.%u.%u.%u:0x%08x -> %u.%u.%u.%u:0x%08x\n",\
557 + (x), (x)->dst.protonum, \
558 + NIPQUAD((x)->src.ip), ntohl((x)->src.u.all), \
559 + NIPQUAD((x)->dst.ip), ntohl((x)->dst.u.all))
560
561 #define CTINFO2DIR(ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)
562
563 diff -urN linux-2.4.29-old/include/linux/netfilter_ipv4/ip_nat_pptp.h linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_nat_pptp.h
564 --- linux-2.4.29-old/include/linux/netfilter_ipv4/ip_nat_pptp.h 1970-01-01 01:00:00.000000000 +0100
565 +++ linux-2.4.29-dev/include/linux/netfilter_ipv4/ip_nat_pptp.h 2005-04-02 19:07:18.000000000 +0200
566 @@ -0,0 +1,11 @@
567 +/* PPTP constants and structs */
568 +#ifndef _NAT_PPTP_H
569 +#define _NAT_PPTP_H
570 +
571 +/* conntrack private data */
572 +struct ip_nat_pptp {
573 + u_int16_t pns_call_id; /* NAT'ed PNS call id */
574 + u_int16_t pac_call_id; /* NAT'ed PAC call id */
575 +};
576 +
577 +#endif /* _NAT_PPTP_H */
578 diff -urN linux-2.4.29-old/net/ipv4/netfilter/Config.in linux-2.4.29-dev/net/ipv4/netfilter/Config.in
579 --- linux-2.4.29-old/net/ipv4/netfilter/Config.in 2005-04-02 19:04:11.000000000 +0200
580 +++ linux-2.4.29-dev/net/ipv4/netfilter/Config.in 2005-04-02 19:07:18.000000000 +0200
581 @@ -10,6 +10,8 @@
582 dep_tristate ' Amanda protocol support' CONFIG_IP_NF_AMANDA $CONFIG_IP_NF_CONNTRACK
583 dep_tristate ' TFTP protocol support' CONFIG_IP_NF_TFTP $CONFIG_IP_NF_CONNTRACK
584 dep_tristate ' IRC protocol support' CONFIG_IP_NF_IRC $CONFIG_IP_NF_CONNTRACK
585 + dep_tristate ' GRE protocol support' CONFIG_IP_NF_CT_PROTO_GRE $CONFIG_IP_NF_CONNTRACK
586 + dep_tristate ' PPTP protocol support' CONFIG_IP_NF_PPTP $CONFIG_IP_NF_CT_PROTO_GRE
587 fi
588
589 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
590 @@ -67,6 +69,20 @@
591 define_bool CONFIG_IP_NF_NAT_NEEDED y
592 dep_tristate ' MASQUERADE target support' CONFIG_IP_NF_TARGET_MASQUERADE $CONFIG_IP_NF_NAT
593 dep_tristate ' REDIRECT target support' CONFIG_IP_NF_TARGET_REDIRECT $CONFIG_IP_NF_NAT
594 + if [ "$CONFIG_IP_NF_PPTP" = "m" ]; then
595 + define_tristate CONFIG_IP_NF_NAT_PPTP m
596 + else
597 + if [ "$CONFIG_IP_NF_PPTP" = "y" ]; then
598 + define_tristate CONFIG_IP_NF_NAT_PPTP $CONFIG_IP_NF_NAT
599 + fi
600 + fi
601 + if [ "$CONFIG_IP_NF_CT_PROTO_GRE" = "m" ]; then
602 + define_tristate CONFIG_IP_NF_NAT_PROTO_GRE m
603 + else
604 + if [ "$CONFIG_IP_NF_CT_PROTO_GRE" = "y" ]; then
605 + define_tristate CONFIG_IP_NF_NAT_PROTO_GRE $CONFIG_IP_NF_NAT
606 + fi
607 + fi
608 if [ "$CONFIG_IP_NF_AMANDA" = "m" ]; then
609 define_tristate CONFIG_IP_NF_NAT_AMANDA m
610 else
611 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_core.c linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_core.c
612 --- linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_core.c 2005-04-02 19:04:11.000000000 +0200
613 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_core.c 2005-04-02 19:07:18.000000000 +0200
614 @@ -142,6 +142,8 @@
615 tuple->dst.ip = iph->daddr;
616 tuple->dst.protonum = iph->protocol;
617
618 + tuple->src.u.all = tuple->dst.u.all = 0;
619 +
620 ret = protocol->pkt_to_tuple((u_int32_t *)iph + iph->ihl,
621 len - 4*iph->ihl,
622 tuple);
623 @@ -157,6 +159,8 @@
624 inverse->dst.ip = orig->src.ip;
625 inverse->dst.protonum = orig->dst.protonum;
626
627 + inverse->src.u.all = inverse->dst.u.all = 0;
628 +
629 return protocol->invert_tuple(inverse, orig);
630 }
631
632 @@ -954,8 +958,8 @@
633 * so there is no need to use the tuple lock too */
634
635 DEBUGP("ip_conntrack_expect_related %p\n", related_to);
636 - DEBUGP("tuple: "); DUMP_TUPLE(&expect->tuple);
637 - DEBUGP("mask: "); DUMP_TUPLE(&expect->mask);
638 + DEBUGP("tuple: "); DUMP_TUPLE_RAW(&expect->tuple);
639 + DEBUGP("mask: "); DUMP_TUPLE_RAW(&expect->mask);
640
641 old = LIST_FIND(&ip_conntrack_expect_list, resent_expect,
642 struct ip_conntrack_expect *, &expect->tuple,
643 @@ -1072,15 +1076,14 @@
644
645 MUST_BE_READ_LOCKED(&ip_conntrack_lock);
646 WRITE_LOCK(&ip_conntrack_expect_tuple_lock);
647 -
648 DEBUGP("change_expect:\n");
649 - DEBUGP("exp tuple: "); DUMP_TUPLE(&expect->tuple);
650 - DEBUGP("exp mask: "); DUMP_TUPLE(&expect->mask);
651 - DEBUGP("newtuple: "); DUMP_TUPLE(newtuple);
652 + DEBUGP("exp tuple: "); DUMP_TUPLE_RAW(&expect->tuple);
653 + DEBUGP("exp mask: "); DUMP_TUPLE_RAW(&expect->mask);
654 + DEBUGP("newtuple: "); DUMP_TUPLE_RAW(newtuple);
655 if (expect->ct_tuple.dst.protonum == 0) {
656 /* Never seen before */
657 DEBUGP("change expect: never seen before\n");
658 - if (!ip_ct_tuple_equal(&expect->tuple, newtuple)
659 + if (!ip_ct_tuple_mask_cmp(&expect->tuple, newtuple, &expect->mask)
660 && LIST_FIND(&ip_conntrack_expect_list, expect_clash,
661 struct ip_conntrack_expect *, newtuple, &expect->mask)) {
662 /* Force NAT to find an unused tuple */
663 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_pptp.c linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_pptp.c
664 --- linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_pptp.c 1970-01-01 01:00:00.000000000 +0100
665 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_pptp.c 2005-04-02 19:13:21.000000000 +0200
666 @@ -0,0 +1,633 @@
667 +/*
668 + * ip_conntrack_pptp.c - Version 1.9
669 + *
670 + * Connection tracking support for PPTP (Point to Point Tunneling Protocol).
671 + * PPTP is a a protocol for creating virtual private networks.
672 + * It is a specification defined by Microsoft and some vendors
673 + * working with Microsoft. PPTP is built on top of a modified
674 + * version of the Internet Generic Routing Encapsulation Protocol.
675 + * GRE is defined in RFC 1701 and RFC 1702. Documentation of
676 + * PPTP can be found in RFC 2637
677 + *
678 + * (C) 2000-2003 by Harald Welte <laforge@gnumonks.org>
679 + *
680 + * Development of this code funded by Astaro AG (http://www.astaro.com/)
681 + *
682 + * Limitations:
683 + * - We blindly assume that control connections are always
684 + * established in PNS->PAC direction. This is a violation
685 + * of RFFC2673
686 + *
687 + * TODO: - finish support for multiple calls within one session
688 + * (needs expect reservations in newnat)
689 + * - testing of incoming PPTP calls
690 + *
691 + * Changes:
692 + * 2002-02-05 - Version 1.3
693 + * - Call ip_conntrack_unexpect_related() from
694 + * pptp_timeout_related() to destroy expectations in case
695 + * CALL_DISCONNECT_NOTIFY or tcp fin packet was seen
696 + * (Philip Craig <philipc@snapgear.com>)
697 + * - Add Version information at module loadtime
698 + * 2002-02-10 - Version 1.6
699 + * - move to C99 style initializers
700 + * - remove second expectation if first arrives
701 + *
702 + */
703 +
704 +#include <linux/config.h>
705 +#include <linux/module.h>
706 +#include <linux/netfilter.h>
707 +#include <linux/ip.h>
708 +#include <net/checksum.h>
709 +#include <net/tcp.h>
710 +
711 +#include <linux/netfilter_ipv4/lockhelp.h>
712 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
713 +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
714 +#include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
715 +
716 +#define IP_CT_PPTP_VERSION "1.9"
717 +
718 +MODULE_LICENSE("GPL");
719 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
720 +MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP");
721 +
722 +DECLARE_LOCK(ip_pptp_lock);
723 +
724 +#if 0
725 +#include "ip_conntrack_pptp_priv.h"
726 +#define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
727 + ": " format, ## args)
728 +#else
729 +#define DEBUGP(format, args...)
730 +#endif
731 +
732 +#define SECS *HZ
733 +#define MINS * 60 SECS
734 +#define HOURS * 60 MINS
735 +#define DAYS * 24 HOURS
736 +
737 +#define PPTP_GRE_TIMEOUT (10 MINS)
738 +#define PPTP_GRE_STREAM_TIMEOUT (5 DAYS)
739 +
740 +static int pptp_expectfn(struct ip_conntrack *ct)
741 +{
742 + struct ip_conntrack *master;
743 + struct ip_conntrack_expect *exp;
744 +
745 + DEBUGP("increasing timeouts\n");
746 + /* increase timeout of GRE data channel conntrack entry */
747 + ct->proto.gre.timeout = PPTP_GRE_TIMEOUT;
748 + ct->proto.gre.stream_timeout = PPTP_GRE_STREAM_TIMEOUT;
749 +
750 + master = master_ct(ct);
751 + if (!master) {
752 + DEBUGP(" no master!!!\n");
753 + return 0;
754 + }
755 +
756 + exp = ct->master;
757 + if (!exp) {
758 + DEBUGP("no expectation!!\n");
759 + return 0;
760 + }
761 +
762 + DEBUGP("completing tuples with ct info\n");
763 + /* we can do this, since we're unconfirmed */
764 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.gre.key ==
765 + htonl(master->help.ct_pptp_info.pac_call_id)) {
766 + /* assume PNS->PAC */
767 + ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.gre.key =
768 + htonl(master->help.ct_pptp_info.pns_call_id);
769 + ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.gre.key =
770 + htonl(master->help.ct_pptp_info.pns_call_id);
771 + } else {
772 + /* assume PAC->PNS */
773 + ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.gre.key =
774 + htonl(master->help.ct_pptp_info.pac_call_id);
775 + ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.gre.key =
776 + htonl(master->help.ct_pptp_info.pac_call_id);
777 + }
778 +
779 + /* delete other expectation */
780 + if (exp->expected_list.next != &exp->expected_list) {
781 + struct ip_conntrack_expect *other_exp;
782 + struct list_head *cur_item, *next;
783 +
784 + for (cur_item = master->sibling_list.next;
785 + cur_item != &master->sibling_list; cur_item = next) {
786 + next = cur_item->next;
787 + other_exp = list_entry(cur_item,
788 + struct ip_conntrack_expect,
789 + expected_list);
790 + /* remove only if occurred at same sequence number */
791 + if (other_exp != exp && other_exp->seq == exp->seq) {
792 + DEBUGP("unexpecting other direction\n");
793 + ip_ct_gre_keymap_destroy(other_exp);
794 + ip_conntrack_unexpect_related(other_exp);
795 + }
796 + }
797 + }
798 +
799 + return 0;
800 +}
801 +
802 +/* timeout GRE data connections */
803 +static int pptp_timeout_related(struct ip_conntrack *ct)
804 +{
805 + struct list_head *cur_item, *next;
806 + struct ip_conntrack_expect *exp;
807 +
808 + /* FIXME: do we have to lock something ? */
809 + for (cur_item = ct->sibling_list.next;
810 + cur_item != &ct->sibling_list; cur_item = next) {
811 + next = cur_item->next;
812 + exp = list_entry(cur_item, struct ip_conntrack_expect,
813 + expected_list);
814 +
815 + ip_ct_gre_keymap_destroy(exp);
816 + if (!exp->sibling) {
817 + ip_conntrack_unexpect_related(exp);
818 + continue;
819 + }
820 +
821 + DEBUGP("setting timeout of conntrack %p to 0\n",
822 + exp->sibling);
823 + exp->sibling->proto.gre.timeout = 0;
824 + exp->sibling->proto.gre.stream_timeout = 0;
825 + ip_ct_refresh(exp->sibling, 0);
826 + }
827 +
828 + return 0;
829 +}
830 +
831 +/* expect GRE connections (PNS->PAC and PAC->PNS direction) */
832 +static inline int
833 +exp_gre(struct ip_conntrack *master,
834 + u_int32_t seq,
835 + u_int16_t callid,
836 + u_int16_t peer_callid)
837 +{
838 + struct ip_conntrack_expect exp;
839 + struct ip_conntrack_tuple inv_tuple;
840 +
841 + memset(&exp, 0, sizeof(exp));
842 + /* tuple in original direction, PNS->PAC */
843 + exp.tuple.src.ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
844 + exp.tuple.src.u.gre.key = htonl(ntohs(peer_callid));
845 + exp.tuple.dst.ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
846 + exp.tuple.dst.u.gre.key = htonl(ntohs(callid));
847 + exp.tuple.dst.protonum = IPPROTO_GRE;
848 +
849 + exp.mask.src.ip = 0xffffffff;
850 + exp.mask.src.u.all = 0;
851 + exp.mask.dst.u.all = 0;
852 + exp.mask.dst.u.gre.key = 0xffffffff;
853 + exp.mask.dst.ip = 0xffffffff;
854 + exp.mask.dst.protonum = 0xffff;
855 +
856 + exp.seq = seq;
857 + exp.expectfn = pptp_expectfn;
858 +
859 + exp.help.exp_pptp_info.pac_call_id = ntohs(callid);
860 + exp.help.exp_pptp_info.pns_call_id = ntohs(peer_callid);
861 +
862 + DEBUGP("calling expect_related ");
863 + DUMP_TUPLE_RAW(&exp.tuple);
864 +
865 + /* Add GRE keymap entries */
866 + if (ip_ct_gre_keymap_add(&exp, &exp.tuple, 0) != 0)
867 + return 1;
868 +
869 + invert_tuplepr(&inv_tuple, &exp.tuple);
870 + if (ip_ct_gre_keymap_add(&exp, &inv_tuple, 1) != 0) {
871 + ip_ct_gre_keymap_destroy(&exp);
872 + return 1;
873 + }
874 +
875 + if (ip_conntrack_expect_related(master, &exp) != 0) {
876 + ip_ct_gre_keymap_destroy(&exp);
877 + DEBUGP("cannot expect_related()\n");
878 + return 1;
879 + }
880 +
881 + /* tuple in reply direction, PAC->PNS */
882 + exp.tuple.src.ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
883 + exp.tuple.src.u.gre.key = htonl(ntohs(callid));
884 + exp.tuple.dst.ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
885 + exp.tuple.dst.u.gre.key = htonl(ntohs(peer_callid));
886 +
887 + DEBUGP("calling expect_related ");
888 + DUMP_TUPLE_RAW(&exp.tuple);
889 +
890 + /* Add GRE keymap entries */
891 + ip_ct_gre_keymap_add(&exp, &exp.tuple, 0);
892 + invert_tuplepr(&inv_tuple, &exp.tuple);
893 + ip_ct_gre_keymap_add(&exp, &inv_tuple, 1);
894 + /* FIXME: cannot handle error correctly, since we need to free
895 + * the above keymap :( */
896 +
897 + if (ip_conntrack_expect_related(master, &exp) != 0) {
898 + /* free the second pair of keypmaps */
899 + ip_ct_gre_keymap_destroy(&exp);
900 + DEBUGP("cannot expect_related():\n");
901 + return 1;
902 + }
903 +
904 + return 0;
905 +}
906 +
907 +static inline int
908 +pptp_inbound_pkt(struct tcphdr *tcph,
909 + struct pptp_pkt_hdr *pptph,
910 + size_t datalen,
911 + struct ip_conntrack *ct,
912 + enum ip_conntrack_info ctinfo)
913 +{
914 + struct PptpControlHeader *ctlh;
915 + union pptp_ctrl_union pptpReq;
916 +
917 + struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;
918 + u_int16_t msg, *cid, *pcid;
919 + u_int32_t seq;
920 +
921 + ctlh = (struct PptpControlHeader *)
922 + ((char *) pptph + sizeof(struct pptp_pkt_hdr));
923 + pptpReq.rawreq = (void *)
924 + ((char *) ctlh + sizeof(struct PptpControlHeader));
925 +
926 + msg = ntohs(ctlh->messageType);
927 + DEBUGP("inbound control message %s\n", strMName[msg]);
928 +
929 + switch (msg) {
930 + case PPTP_START_SESSION_REPLY:
931 + /* server confirms new control session */
932 + if (info->sstate < PPTP_SESSION_REQUESTED) {
933 + DEBUGP("%s without START_SESS_REQUEST\n",
934 + strMName[msg]);
935 + break;
936 + }
937 + if (pptpReq.srep->resultCode == PPTP_START_OK)
938 + info->sstate = PPTP_SESSION_CONFIRMED;
939 + else
940 + info->sstate = PPTP_SESSION_ERROR;
941 + break;
942 +
943 + case PPTP_STOP_SESSION_REPLY:
944 + /* server confirms end of control session */
945 + if (info->sstate > PPTP_SESSION_STOPREQ) {
946 + DEBUGP("%s without STOP_SESS_REQUEST\n",
947 + strMName[msg]);
948 + break;
949 + }
950 + if (pptpReq.strep->resultCode == PPTP_STOP_OK)
951 + info->sstate = PPTP_SESSION_NONE;
952 + else
953 + info->sstate = PPTP_SESSION_ERROR;
954 + break;
955 +
956 + case PPTP_OUT_CALL_REPLY:
957 + /* server accepted call, we now expect GRE frames */
958 + if (info->sstate != PPTP_SESSION_CONFIRMED) {
959 + DEBUGP("%s but no session\n", strMName[msg]);
960 + break;
961 + }
962 + if (info->cstate != PPTP_CALL_OUT_REQ &&
963 + info->cstate != PPTP_CALL_OUT_CONF) {
964 + DEBUGP("%s without OUTCALL_REQ\n", strMName[msg]);
965 + break;
966 + }
967 + if (pptpReq.ocack->resultCode != PPTP_OUTCALL_CONNECT) {
968 + info->cstate = PPTP_CALL_NONE;
969 + break;
970 + }
971 +
972 + cid = &pptpReq.ocack->callID;
973 + pcid = &pptpReq.ocack->peersCallID;
974 +
975 + info->pac_call_id = ntohs(*cid);
976 +
977 + if (htons(info->pns_call_id) != *pcid) {
978 + DEBUGP("%s for unknown callid %u\n",
979 + strMName[msg], ntohs(*pcid));
980 + break;
981 + }
982 +
983 + DEBUGP("%s, CID=%X, PCID=%X\n", strMName[msg],
984 + ntohs(*cid), ntohs(*pcid));
985 +
986 + info->cstate = PPTP_CALL_OUT_CONF;
987 +
988 + seq = ntohl(tcph->seq) + ((void *)pcid - (void *)pptph);
989 + if (exp_gre(ct, seq, *cid, *pcid) != 0)
990 + printk("ip_conntrack_pptp: error during exp_gre\n");
991 + break;
992 +
993 + case PPTP_IN_CALL_REQUEST:
994 + /* server tells us about incoming call request */
995 + if (info->sstate != PPTP_SESSION_CONFIRMED) {
996 + DEBUGP("%s but no session\n", strMName[msg]);
997 + break;
998 + }
999 + pcid = &pptpReq.icack->peersCallID;
1000 + DEBUGP("%s, PCID=%X\n", strMName[msg], ntohs(*pcid));
1001 + info->cstate = PPTP_CALL_IN_REQ;
1002 + info->pac_call_id= ntohs(*pcid);
1003 + break;
1004 +
1005 + case PPTP_IN_CALL_CONNECT:
1006 + /* server tells us about incoming call established */
1007 + if (info->sstate != PPTP_SESSION_CONFIRMED) {
1008 + DEBUGP("%s but no session\n", strMName[msg]);
1009 + break;
1010 + }
1011 + if (info->sstate != PPTP_CALL_IN_REP
1012 + && info->sstate != PPTP_CALL_IN_CONF) {
1013 + DEBUGP("%s but never sent IN_CALL_REPLY\n",
1014 + strMName[msg]);
1015 + break;
1016 + }
1017 +
1018 + pcid = &pptpReq.iccon->peersCallID;
1019 + cid = &info->pac_call_id;
1020 +
1021 + if (info->pns_call_id != ntohs(*pcid)) {
1022 + DEBUGP("%s for unknown CallID %u\n",
1023 + strMName[msg], ntohs(*cid));
1024 + break;
1025 + }
1026 +
1027 + DEBUGP("%s, PCID=%X\n", strMName[msg], ntohs(*pcid));
1028 + info->cstate = PPTP_CALL_IN_CONF;
1029 +
1030 + /* we expect a GRE connection from PAC to PNS */
1031 + seq = ntohl(tcph->seq) + ((void *)pcid - (void *)pptph);
1032 + if (exp_gre(ct, seq, *cid, *pcid) != 0)
1033 + printk("ip_conntrack_pptp: error during exp_gre\n");
1034 +
1035 + break;
1036 +
1037 + case PPTP_CALL_DISCONNECT_NOTIFY:
1038 + /* server confirms disconnect */
1039 + cid = &pptpReq.disc->callID;
1040 + DEBUGP("%s, CID=%X\n", strMName[msg], ntohs(*cid));
1041 + info->cstate = PPTP_CALL_NONE;
1042 +
1043 + /* untrack this call id, unexpect GRE packets */
1044 + pptp_timeout_related(ct);
1045 + break;
1046 +
1047 + case PPTP_WAN_ERROR_NOTIFY:
1048 + break;
1049 +
1050 + case PPTP_ECHO_REQUEST:
1051 + case PPTP_ECHO_REPLY:
1052 + /* I don't have to explain these ;) */
1053 + break;
1054 + default:
1055 + DEBUGP("invalid %s (TY=%d)\n", (msg <= PPTP_MSG_MAX)
1056 + ? strMName[msg]:strMName[0], msg);
1057 + break;
1058 + }
1059 +
1060 + return NF_ACCEPT;
1061 +
1062 +}
1063 +
1064 +static inline int
1065 +pptp_outbound_pkt(struct tcphdr *tcph,
1066 + struct pptp_pkt_hdr *pptph,
1067 + size_t datalen,
1068 + struct ip_conntrack *ct,
1069 + enum ip_conntrack_info ctinfo)
1070 +{
1071 + struct PptpControlHeader *ctlh;
1072 + union pptp_ctrl_union pptpReq;
1073 + struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;
1074 + u_int16_t msg, *cid, *pcid;
1075 +
1076 + ctlh = (struct PptpControlHeader *) ((void *) pptph + sizeof(*pptph));
1077 + pptpReq.rawreq = (void *) ((void *) ctlh + sizeof(*ctlh));
1078 +
1079 + msg = ntohs(ctlh->messageType);
1080 + DEBUGP("outbound control message %s\n", strMName[msg]);
1081 +
1082 + switch (msg) {
1083 + case PPTP_START_SESSION_REQUEST:
1084 + /* client requests for new control session */
1085 + if (info->sstate != PPTP_SESSION_NONE) {
1086 + DEBUGP("%s but we already have one",
1087 + strMName[msg]);
1088 + }
1089 + info->sstate = PPTP_SESSION_REQUESTED;
1090 + break;
1091 + case PPTP_STOP_SESSION_REQUEST:
1092 + /* client requests end of control session */
1093 + info->sstate = PPTP_SESSION_STOPREQ;
1094 + break;
1095 +
1096 + case PPTP_OUT_CALL_REQUEST:
1097 + /* client initiating connection to server */
1098 + if (info->sstate != PPTP_SESSION_CONFIRMED) {
1099 + DEBUGP("%s but no session\n",
1100 + strMName[msg]);
1101 + break;
1102 + }
1103 + info->cstate = PPTP_CALL_OUT_REQ;
1104 + /* track PNS call id */
1105 + cid = &pptpReq.ocreq->callID;
1106 + DEBUGP("%s, CID=%X\n", strMName[msg], ntohs(*cid));
1107 + info->pns_call_id = ntohs(*cid);
1108 + break;
1109 + case PPTP_IN_CALL_REPLY:
1110 + /* client answers incoming call */
1111 + if (info->cstate != PPTP_CALL_IN_REQ
1112 + && info->cstate != PPTP_CALL_IN_REP) {
1113 + DEBUGP("%s without incall_req\n",
1114 + strMName[msg]);
1115 + break;
1116 + }
1117 + if (pptpReq.icack->resultCode != PPTP_INCALL_ACCEPT) {
1118 + info->cstate = PPTP_CALL_NONE;
1119 + break;
1120 + }
1121 + pcid = &pptpReq.icack->peersCallID;
1122 + if (info->pac_call_id != ntohs(*pcid)) {
1123 + DEBUGP("%s for unknown call %u\n",
1124 + strMName[msg], ntohs(*pcid));
1125 + break;
1126 + }
1127 + DEBUGP("%s, CID=%X\n", strMName[msg], ntohs(*pcid));
1128 + /* part two of the three-way handshake */
1129 + info->cstate = PPTP_CALL_IN_REP;
1130 + info->pns_call_id = ntohs(pptpReq.icack->callID);
1131 + break;
1132 +
1133 + case PPTP_CALL_CLEAR_REQUEST:
1134 + /* client requests hangup of call */
1135 + if (info->sstate != PPTP_SESSION_CONFIRMED) {
1136 + DEBUGP("CLEAR_CALL but no session\n");
1137 + break;
1138 + }
1139 + /* FUTURE: iterate over all calls and check if
1140 + * call ID is valid. We don't do this without newnat,
1141 + * because we only know about last call */
1142 + info->cstate = PPTP_CALL_CLEAR_REQ;
1143 + break;
1144 + case PPTP_SET_LINK_INFO:
1145 + break;
1146 + case PPTP_ECHO_REQUEST:
1147 + case PPTP_ECHO_REPLY:
1148 + /* I don't have to explain these ;) */
1149 + break;
1150 + default:
1151 + DEBUGP("invalid %s (TY=%d)\n", (msg <= PPTP_MSG_MAX)?
1152 + strMName[msg]:strMName[0], msg);
1153 + /* unknown: no need to create GRE masq table entry */
1154 + break;
1155 + }
1156 +
1157 + return NF_ACCEPT;
1158 +}
1159 +
1160 +
1161 +/* track caller id inside control connection, call expect_related */
1162 +static int
1163 +conntrack_pptp_help(const struct iphdr *iph, size_t len,
1164 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
1165 +
1166 +{
1167 + struct pptp_pkt_hdr *pptph;
1168 +
1169 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
1170 + u_int32_t tcplen = len - iph->ihl * 4;
1171 + u_int32_t datalen = tcplen - tcph->doff * 4;
1172 + void *datalimit;
1173 + int dir = CTINFO2DIR(ctinfo);
1174 + struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;
1175 +
1176 + int oldsstate, oldcstate;
1177 + int ret;
1178 +
1179 + /* don't do any tracking before tcp handshake complete */
1180 + if (ctinfo != IP_CT_ESTABLISHED
1181 + && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) {
1182 + DEBUGP("ctinfo = %u, skipping\n", ctinfo);
1183 + return NF_ACCEPT;
1184 + }
1185 +
1186 + /* not a complete TCP header? */
1187 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
1188 + DEBUGP("tcplen = %u\n", tcplen);
1189 + return NF_ACCEPT;
1190 + }
1191 +
1192 + /* checksum invalid? */
1193 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
1194 + csum_partial((char *) tcph, tcplen, 0))) {
1195 + printk(KERN_NOTICE __FILE__ ": bad csum\n");
1196 + /* W2K PPTP server sends TCP packets with wrong checksum :(( */
1197 + //return NF_ACCEPT;
1198 + }
1199 +
1200 + if (tcph->fin || tcph->rst) {
1201 + DEBUGP("RST/FIN received, timeouting GRE\n");
1202 + /* can't do this after real newnat */
1203 + info->cstate = PPTP_CALL_NONE;
1204 +
1205 + /* untrack this call id, unexpect GRE packets */
1206 + pptp_timeout_related(ct);
1207 + }
1208 +
1209 +
1210 + pptph = (struct pptp_pkt_hdr *) ((void *) tcph + tcph->doff * 4);
1211 + datalimit = (void *) pptph + datalen;
1212 +
1213 + /* not a full pptp packet header? */
1214 + if ((void *) pptph+sizeof(*pptph) >= datalimit) {
1215 + DEBUGP("no full PPTP header, can't track\n");
1216 + return NF_ACCEPT;
1217 + }
1218 +
1219 + /* if it's not a control message we can't do anything with it */
1220 + if (ntohs(pptph->packetType) != PPTP_PACKET_CONTROL ||
1221 + ntohl(pptph->magicCookie) != PPTP_MAGIC_COOKIE) {
1222 + DEBUGP("not a control packet\n");
1223 + return NF_ACCEPT;
1224 + }
1225 +
1226 + oldsstate = info->sstate;
1227 + oldcstate = info->cstate;
1228 +
1229 + LOCK_BH(&ip_pptp_lock);
1230 +
1231 + /* FIXME: We just blindly assume that the control connection is always
1232 + * established from PNS->PAC. However, RFC makes no guarantee */
1233 + if (dir == IP_CT_DIR_ORIGINAL)
1234 + /* client -> server (PNS -> PAC) */
1235 + ret = pptp_outbound_pkt(tcph, pptph, datalen, ct, ctinfo);
1236 + else
1237 + /* server -> client (PAC -> PNS) */
1238 + ret = pptp_inbound_pkt(tcph, pptph, datalen, ct, ctinfo);
1239 + DEBUGP("sstate: %d->%d, cstate: %d->%d\n",
1240 + oldsstate, info->sstate, oldcstate, info->cstate);
1241 + UNLOCK_BH(&ip_pptp_lock);
1242 +
1243 + return ret;
1244 +}
1245 +
1246 +/* control protocol helper */
1247 +static struct ip_conntrack_helper pptp = {
1248 + .list = { NULL, NULL },
1249 + .name = "pptp",
1250 + .flags = IP_CT_HELPER_F_REUSE_EXPECT,
1251 + .me = THIS_MODULE,
1252 + .max_expected = 2,
1253 + .timeout = 0,
1254 + .tuple = { .src = { .ip = 0,
1255 + .u = { .tcp = { .port =
1256 + __constant_htons(PPTP_CONTROL_PORT) } }
1257 + },
1258 + .dst = { .ip = 0,
1259 + .u = { .all = 0 },
1260 + .protonum = IPPROTO_TCP
1261 + }
1262 + },
1263 + .mask = { .src = { .ip = 0,
1264 + .u = { .tcp = { .port = 0xffff } }
1265 + },
1266 + .dst = { .ip = 0,
1267 + .u = { .all = 0 },
1268 + .protonum = 0xffff
1269 + }
1270 + },
1271 + .help = conntrack_pptp_help
1272 +};
1273 +
1274 +/* ip_conntrack_pptp initialization */
1275 +static int __init init(void)
1276 +{
1277 + int retcode;
1278 +
1279 + DEBUGP(__FILE__ ": registering helper\n");
1280 + if ((retcode = ip_conntrack_helper_register(&pptp))) {
1281 + printk(KERN_ERR "Unable to register conntrack application "
1282 + "helper for pptp: %d\n", retcode);
1283 + return -EIO;
1284 + }
1285 +
1286 + printk("ip_conntrack_pptp version %s loaded\n", IP_CT_PPTP_VERSION);
1287 + return 0;
1288 +}
1289 +
1290 +static void __exit fini(void)
1291 +{
1292 + ip_conntrack_helper_unregister(&pptp);
1293 + printk("ip_conntrack_pptp version %s unloaded\n", IP_CT_PPTP_VERSION);
1294 +}
1295 +
1296 +module_init(init);
1297 +module_exit(fini);
1298 +
1299 +EXPORT_SYMBOL(ip_pptp_lock);
1300 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_pptp_priv.h linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_pptp_priv.h
1301 --- linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_pptp_priv.h 1970-01-01 01:00:00.000000000 +0100
1302 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_pptp_priv.h 2005-04-02 19:14:10.000000000 +0200
1303 @@ -0,0 +1,24 @@
1304 +#ifndef _IP_CT_PPTP_PRIV_H
1305 +#define _IP_CT_PPTP_PRIV_H
1306 +
1307 +/* PptpControlMessageType names */
1308 +static const char *strMName[] = {
1309 + "UNKNOWN_MESSAGE",
1310 + "START_SESSION_REQUEST",
1311 + "START_SESSION_REPLY",
1312 + "STOP_SESSION_REQUEST",
1313 + "STOP_SESSION_REPLY",
1314 + "ECHO_REQUEST",
1315 + "ECHO_REPLY",
1316 + "OUT_CALL_REQUEST",
1317 + "OUT_CALL_REPLY",
1318 + "IN_CALL_REQUEST",
1319 + "IN_CALL_REPLY",
1320 + "IN_CALL_CONNECT",
1321 + "CALL_CLEAR_REQUEST",
1322 + "CALL_DISCONNECT_NOTIFY",
1323 + "WAN_ERROR_NOTIFY",
1324 + "SET_LINK_INFO"
1325 +};
1326 +
1327 +#endif
1328 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_proto_gre.c linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_proto_gre.c
1329 --- linux-2.4.29-old/net/ipv4/netfilter/ip_conntrack_proto_gre.c 1970-01-01 01:00:00.000000000 +0100
1330 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_conntrack_proto_gre.c 2005-04-02 19:14:31.000000000 +0200
1331 @@ -0,0 +1,333 @@
1332 +/*
1333 + * ip_conntrack_proto_gre.c - Version 1.2
1334 + *
1335 + * Connection tracking protocol helper module for GRE.
1336 + *
1337 + * GRE is a generic encapsulation protocol, which is generally not very
1338 + * suited for NAT, as it has no protocol-specific part as port numbers.
1339 + *
1340 + * It has an optional key field, which may help us distinguishing two
1341 + * connections between the same two hosts.
1342 + *
1343 + * GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784
1344 + *
1345 + * PPTP is built on top of a modified version of GRE, and has a mandatory
1346 + * field called "CallID", which serves us for the same purpose as the key
1347 + * field in plain GRE.
1348 + *
1349 + * Documentation about PPTP can be found in RFC 2637
1350 + *
1351 + * (C) 2000-2003 by Harald Welte <laforge@gnumonks.org>
1352 + *
1353 + * Development of this code funded by Astaro AG (http://www.astaro.com/)
1354 + *
1355 + */
1356 +
1357 +#include <linux/config.h>
1358 +#include <linux/module.h>
1359 +#include <linux/types.h>
1360 +#include <linux/timer.h>
1361 +#include <linux/netfilter.h>
1362 +#include <linux/ip.h>
1363 +#include <linux/in.h>
1364 +#include <linux/list.h>
1365 +
1366 +#include <linux/netfilter_ipv4/lockhelp.h>
1367 +
1368 +DECLARE_RWLOCK(ip_ct_gre_lock);
1369 +#define ASSERT_READ_LOCK(x) MUST_BE_READ_LOCKED(&ip_ct_gre_lock)
1370 +#define ASSERT_WRITE_LOCK(x) MUST_BE_WRITE_LOCKED(&ip_ct_gre_lock)
1371 +
1372 +#include <linux/netfilter_ipv4/listhelp.h>
1373 +#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
1374 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
1375 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
1376 +
1377 +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
1378 +#include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
1379 +
1380 +MODULE_LICENSE("GPL");
1381 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
1382 +MODULE_DESCRIPTION("netfilter connection tracking protocol helper for GRE");
1383 +
1384 +/* shamelessly stolen from ip_conntrack_proto_udp.c */
1385 +#define GRE_TIMEOUT (30*HZ)
1386 +#define GRE_STREAM_TIMEOUT (180*HZ)
1387 +
1388 +#if 0
1389 +#define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
1390 + ": " format, ## args)
1391 +#define DUMP_TUPLE_GRE(x) printk("%u.%u.%u.%u:0x%x -> %u.%u.%u.%u:0x%x:%u:0x%x\n", \
1392 + NIPQUAD((x)->src.ip), ntohl((x)->src.u.gre.key), \
1393 + NIPQUAD((x)->dst.ip), ntohl((x)->dst.u.gre.key))
1394 +#else
1395 +#define DEBUGP(x, args...)
1396 +#define DUMP_TUPLE_GRE(x)
1397 +#endif
1398 +
1399 +/* GRE KEYMAP HANDLING FUNCTIONS */
1400 +static LIST_HEAD(gre_keymap_list);
1401 +
1402 +static inline int gre_key_cmpfn(const struct ip_ct_gre_keymap *km,
1403 + const struct ip_conntrack_tuple *t)
1404 +{
1405 + return ((km->tuple.src.ip == t->src.ip) &&
1406 + (km->tuple.dst.ip == t->dst.ip) &&
1407 + (km->tuple.dst.protonum == t->dst.protonum) &&
1408 + (km->tuple.dst.u.all == t->dst.u.all));
1409 +}
1410 +
1411 +/* look up the source key for a given tuple */
1412 +static u_int32_t gre_keymap_lookup(struct ip_conntrack_tuple *t)
1413 +{
1414 + struct ip_ct_gre_keymap *km;
1415 + u_int32_t key;
1416 +
1417 + READ_LOCK(&ip_ct_gre_lock);
1418 + km = LIST_FIND(&gre_keymap_list, gre_key_cmpfn,
1419 + struct ip_ct_gre_keymap *, t);
1420 + if (!km) {
1421 + READ_UNLOCK(&ip_ct_gre_lock);
1422 + return 0;
1423 + }
1424 +
1425 + key = km->tuple.src.u.gre.key;
1426 + READ_UNLOCK(&ip_ct_gre_lock);
1427 +
1428 + return key;
1429 +}
1430 +
1431 +/* add a single keymap entry, associate with specified expect */
1432 +int ip_ct_gre_keymap_add(struct ip_conntrack_expect *exp,
1433 + struct ip_conntrack_tuple *t, int reply)
1434 +{
1435 + struct ip_ct_gre_keymap *km;
1436 +
1437 + km = kmalloc(sizeof(*km), GFP_ATOMIC);
1438 + if (!km)
1439 + return -1;
1440 +
1441 + /* initializing list head should be sufficient */
1442 + memset(km, 0, sizeof(*km));
1443 +
1444 + memcpy(&km->tuple, t, sizeof(*t));
1445 +
1446 + if (!reply)
1447 + exp->proto.gre.keymap_orig = km;
1448 + else
1449 + exp->proto.gre.keymap_reply = km;
1450 +
1451 + DEBUGP("adding new entry %p: ", km);
1452 + DUMP_TUPLE_GRE(&km->tuple);
1453 +
1454 + WRITE_LOCK(&ip_ct_gre_lock);
1455 + list_append(&gre_keymap_list, km);
1456 + WRITE_UNLOCK(&ip_ct_gre_lock);
1457 +
1458 + return 0;
1459 +}
1460 +
1461 +/* change the tuple of a keymap entry (used by nat helper) */
1462 +void ip_ct_gre_keymap_change(struct ip_ct_gre_keymap *km,
1463 + struct ip_conntrack_tuple *t)
1464 +{
1465 + DEBUGP("changing entry %p to: ", km);
1466 + DUMP_TUPLE_GRE(t);
1467 +
1468 + WRITE_LOCK(&ip_ct_gre_lock);
1469 + memcpy(&km->tuple, t, sizeof(km->tuple));
1470 + WRITE_UNLOCK(&ip_ct_gre_lock);
1471 +}
1472 +
1473 +/* destroy the keymap entries associated with specified expect */
1474 +void ip_ct_gre_keymap_destroy(struct ip_conntrack_expect *exp)
1475 +{
1476 + DEBUGP("entering for exp %p\n", exp);
1477 + WRITE_LOCK(&ip_ct_gre_lock);
1478 + if (exp->proto.gre.keymap_orig) {
1479 + DEBUGP("removing %p from list\n", exp->proto.gre.keymap_orig);
1480 + list_del(&exp->proto.gre.keymap_orig->list);
1481 + kfree(exp->proto.gre.keymap_orig);
1482 + exp->proto.gre.keymap_orig = NULL;
1483 + }
1484 + if (exp->proto.gre.keymap_reply) {
1485 + DEBUGP("removing %p from list\n", exp->proto.gre.keymap_reply);
1486 + list_del(&exp->proto.gre.keymap_reply->list);
1487 + kfree(exp->proto.gre.keymap_reply);
1488 + exp->proto.gre.keymap_reply = NULL;
1489 + }
1490 + WRITE_UNLOCK(&ip_ct_gre_lock);
1491 +}
1492 +
1493 +
1494 +/* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */
1495 +
1496 +/* invert gre part of tuple */
1497 +static int gre_invert_tuple(struct ip_conntrack_tuple *tuple,
1498 + const struct ip_conntrack_tuple *orig)
1499 +{
1500 + tuple->dst.u.gre.key = orig->src.u.gre.key;
1501 + tuple->src.u.gre.key = orig->dst.u.gre.key;
1502 +
1503 + return 1;
1504 +}
1505 +
1506 +/* gre hdr info to tuple */
1507 +static int gre_pkt_to_tuple(const void *datah, size_t datalen,
1508 + struct ip_conntrack_tuple *tuple)
1509 +{
1510 + struct gre_hdr *grehdr = (struct gre_hdr *) datah;
1511 + struct gre_hdr_pptp *pgrehdr = (struct gre_hdr_pptp *) datah;
1512 + u_int32_t srckey;
1513 +
1514 + /* core guarantees 8 protocol bytes, no need for size check */
1515 +
1516 + switch (grehdr->version) {
1517 + case GRE_VERSION_1701:
1518 + if (!grehdr->key) {
1519 + DEBUGP("Can't track GRE without key\n");
1520 + return 0;
1521 + }
1522 + tuple->dst.u.gre.key = *(gre_key(grehdr));
1523 + break;
1524 +
1525 + case GRE_VERSION_PPTP:
1526 + if (ntohs(grehdr->protocol) != GRE_PROTOCOL_PPTP) {
1527 + DEBUGP("GRE_VERSION_PPTP but unknown proto\n");
1528 + return 0;
1529 + }
1530 + tuple->dst.u.gre.key = htonl(ntohs(pgrehdr->call_id));
1531 + break;
1532 +
1533 + default:
1534 + printk(KERN_WARNING "unknown GRE version %hu\n",
1535 + grehdr->version);
1536 + return 0;
1537 + }
1538 +
1539 + srckey = gre_keymap_lookup(tuple);
1540 +
1541 +#if 0
1542 + DEBUGP("found src key %x for tuple ", ntohl(srckey));
1543 + DUMP_TUPLE_GRE(tuple);
1544 +#endif
1545 + tuple->src.u.gre.key = srckey;
1546 +
1547 + return 1;
1548 +}
1549 +
1550 +/* print gre part of tuple */
1551 +static unsigned int gre_print_tuple(char *buffer,
1552 + const struct ip_conntrack_tuple *tuple)
1553 +{
1554 + return sprintf(buffer, "srckey=0x%x dstkey=0x%x ",
1555 + ntohl(tuple->src.u.gre.key),
1556 + ntohl(tuple->dst.u.gre.key));
1557 +}
1558 +
1559 +/* print private data for conntrack */
1560 +static unsigned int gre_print_conntrack(char *buffer,
1561 + const struct ip_conntrack *ct)
1562 +{
1563 + return sprintf(buffer, "timeout=%u, stream_timeout=%u ",
1564 + (ct->proto.gre.timeout / HZ),
1565 + (ct->proto.gre.stream_timeout / HZ));
1566 +}
1567 +
1568 +/* Returns verdict for packet, and may modify conntrack */
1569 +static int gre_packet(struct ip_conntrack *ct,
1570 + struct iphdr *iph, size_t len,
1571 + enum ip_conntrack_info conntrackinfo)
1572 +{
1573 + /* If we've seen traffic both ways, this is a GRE connection.
1574 + * Extend timeout. */
1575 + if (ct->status & IPS_SEEN_REPLY) {
1576 + ip_ct_refresh(ct, ct->proto.gre.stream_timeout);
1577 + /* Also, more likely to be important, and not a probe. */
1578 + set_bit(IPS_ASSURED_BIT, &ct->status);
1579 + } else
1580 + ip_ct_refresh(ct, ct->proto.gre.timeout);
1581 +
1582 + return NF_ACCEPT;
1583 +}
1584 +
1585 +/* Called when a new connection for this protocol found. */
1586 +static int gre_new(struct ip_conntrack *ct,
1587 + struct iphdr *iph, size_t len)
1588 +{
1589 + DEBUGP(": ");
1590 + DUMP_TUPLE_GRE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
1591 +
1592 + /* initialize to sane value. Ideally a conntrack helper
1593 + * (e.g. in case of pptp) is increasing them */
1594 + ct->proto.gre.stream_timeout = GRE_STREAM_TIMEOUT;
1595 + ct->proto.gre.timeout = GRE_TIMEOUT;
1596 +
1597 + return 1;
1598 +}
1599 +
1600 +/* Called when a conntrack entry has already been removed from the hashes
1601 + * and is about to be deleted from memory */
1602 +static void gre_destroy(struct ip_conntrack *ct)
1603 +{
1604 + struct ip_conntrack_expect *master = ct->master;
1605 +
1606 + DEBUGP(" entering\n");
1607 +
1608 + if (!master) {
1609 + DEBUGP("no master exp for ct %p\n", ct);
1610 + return;
1611 + }
1612 +
1613 + ip_ct_gre_keymap_destroy(master);
1614 +}
1615 +
1616 +/* protocol helper struct */
1617 +static struct ip_conntrack_protocol gre = { { NULL, NULL }, IPPROTO_GRE,
1618 + "gre",
1619 + gre_pkt_to_tuple,
1620 + gre_invert_tuple,
1621 + gre_print_tuple,
1622 + gre_print_conntrack,
1623 + gre_packet,
1624 + gre_new,
1625 + gre_destroy,
1626 + NULL,
1627 + THIS_MODULE };
1628 +
1629 +/* ip_conntrack_proto_gre initialization */
1630 +static int __init init(void)
1631 +{
1632 + int retcode;
1633 +
1634 + if ((retcode = ip_conntrack_protocol_register(&gre))) {
1635 + printk(KERN_ERR "Unable to register conntrack protocol "
1636 + "helper for gre: %d\n", retcode);
1637 + return -EIO;
1638 + }
1639 +
1640 + return 0;
1641 +}
1642 +
1643 +static void __exit fini(void)
1644 +{
1645 + struct list_head *pos, *n;
1646 +
1647 + /* delete all keymap entries */
1648 + WRITE_LOCK(&ip_ct_gre_lock);
1649 + list_for_each_safe(pos, n, &gre_keymap_list) {
1650 + DEBUGP("deleting keymap %p at module unload time\n", pos);
1651 + list_del(pos);
1652 + kfree(pos);
1653 + }
1654 + WRITE_UNLOCK(&ip_ct_gre_lock);
1655 +
1656 + ip_conntrack_protocol_unregister(&gre);
1657 +}
1658 +
1659 +EXPORT_SYMBOL(ip_ct_gre_keymap_add);
1660 +EXPORT_SYMBOL(ip_ct_gre_keymap_change);
1661 +EXPORT_SYMBOL(ip_ct_gre_keymap_destroy);
1662 +
1663 +module_init(init);
1664 +module_exit(fini);
1665 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_nat_core.c linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_core.c
1666 --- linux-2.4.29-old/net/ipv4/netfilter/ip_nat_core.c 2005-01-19 15:10:13.000000000 +0100
1667 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_core.c 2005-04-02 19:07:18.000000000 +0200
1668 @@ -424,7 +424,7 @@
1669 *tuple = *orig_tuple;
1670 while ((rptr = find_best_ips_proto_fast(tuple, mr, conntrack, hooknum))
1671 != NULL) {
1672 - DEBUGP("Found best for "); DUMP_TUPLE(tuple);
1673 + DEBUGP("Found best for "); DUMP_TUPLE_RAW(tuple);
1674 /* 3) The per-protocol part of the manip is made to
1675 map into the range to make a unique tuple. */
1676
1677 @@ -564,9 +564,9 @@
1678 HOOK2MANIP(hooknum)==IP_NAT_MANIP_SRC ? "SRC" : "DST",
1679 conntrack);
1680 DEBUGP("Original: ");
1681 - DUMP_TUPLE(&orig_tp);
1682 + DUMP_TUPLE_RAW(&orig_tp);
1683 DEBUGP("New: ");
1684 - DUMP_TUPLE(&new_tuple);
1685 + DUMP_TUPLE_RAW(&new_tuple);
1686 #endif
1687
1688 /* We now have two tuples (SRCIP/SRCPT/DSTIP/DSTPT):
1689 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_nat_pptp.c linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_pptp.c
1690 --- linux-2.4.29-old/net/ipv4/netfilter/ip_nat_pptp.c 1970-01-01 01:00:00.000000000 +0100
1691 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_pptp.c 2005-04-02 19:14:52.000000000 +0200
1692 @@ -0,0 +1,475 @@
1693 +/*
1694 + * ip_nat_pptp.c - Version 1.5
1695 + *
1696 + * NAT support for PPTP (Point to Point Tunneling Protocol).
1697 + * PPTP is a a protocol for creating virtual private networks.
1698 + * It is a specification defined by Microsoft and some vendors
1699 + * working with Microsoft. PPTP is built on top of a modified
1700 + * version of the Internet Generic Routing Encapsulation Protocol.
1701 + * GRE is defined in RFC 1701 and RFC 1702. Documentation of
1702 + * PPTP can be found in RFC 2637
1703 + *
1704 + * (C) 2000-2003 by Harald Welte <laforge@gnumonks.org>
1705 + *
1706 + * Development of this code funded by Astaro AG (http://www.astaro.com/)
1707 + *
1708 + * TODO: - Support for multiple calls within one session
1709 + * (needs netfilter newnat code)
1710 + * - NAT to a unique tuple, not to TCP source port
1711 + * (needs netfilter tuple reservation)
1712 + *
1713 + * Changes:
1714 + * 2002-02-10 - Version 1.3
1715 + * - Use ip_nat_mangle_tcp_packet() because of cloned skb's
1716 + * in local connections (Philip Craig <philipc@snapgear.com>)
1717 + * - add checks for magicCookie and pptp version
1718 + * - make argument list of pptp_{out,in}bound_packet() shorter
1719 + * - move to C99 style initializers
1720 + * - print version number at module loadtime
1721 + * 2003-09-22 - Version 1.5
1722 + * - use SNATed tcp sourceport as callid, since we get called before
1723 + * TCP header is mangled (Philip Craig <philipc@snapgear.com>)
1724 + *
1725 + */
1726 +
1727 +#include <linux/config.h>
1728 +#include <linux/module.h>
1729 +#include <linux/ip.h>
1730 +#include <linux/tcp.h>
1731 +#include <net/tcp.h>
1732 +#include <linux/netfilter_ipv4/ip_nat.h>
1733 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
1734 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
1735 +#include <linux/netfilter_ipv4/ip_nat_pptp.h>
1736 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
1737 +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
1738 +#include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
1739 +
1740 +#define IP_NAT_PPTP_VERSION "1.5"
1741 +
1742 +MODULE_LICENSE("GPL");
1743 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
1744 +MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP");
1745 +
1746 +
1747 +#if 0
1748 +#include "ip_conntrack_pptp_priv.h"
1749 +#define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
1750 + ": " format, ## args)
1751 +#else
1752 +#define DEBUGP(format, args...)
1753 +#endif
1754 +
1755 +static unsigned int
1756 +pptp_nat_expected(struct sk_buff **pskb,
1757 + unsigned int hooknum,
1758 + struct ip_conntrack *ct,
1759 + struct ip_nat_info *info)
1760 +{
1761 + struct ip_conntrack *master = master_ct(ct);
1762 + struct ip_nat_multi_range mr;
1763 + struct ip_ct_pptp_master *ct_pptp_info;
1764 + struct ip_nat_pptp *nat_pptp_info;
1765 + u_int32_t newip, newcid;
1766 + int ret;
1767 +
1768 + IP_NF_ASSERT(info);
1769 + IP_NF_ASSERT(master);
1770 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
1771 +
1772 + DEBUGP("we have a connection!\n");
1773 +
1774 + LOCK_BH(&ip_pptp_lock);
1775 + ct_pptp_info = &master->help.ct_pptp_info;
1776 + nat_pptp_info = &master->nat.help.nat_pptp_info;
1777 +
1778 + /* need to alter GRE tuple because conntrack expectfn() used 'wrong'
1779 + * (unmanipulated) values */
1780 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
1781 + DEBUGP("completing tuples with NAT info \n");
1782 + /* we can do this, since we're unconfirmed */
1783 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.gre.key ==
1784 + htonl(ct_pptp_info->pac_call_id)) {
1785 + /* assume PNS->PAC */
1786 + ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.gre.key =
1787 + htonl(nat_pptp_info->pns_call_id);
1788 + ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.gre.key =
1789 + htonl(nat_pptp_info->pns_call_id);
1790 + newip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
1791 + newcid = htonl(nat_pptp_info->pac_call_id);
1792 + } else {
1793 + /* assume PAC->PNS */
1794 + ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.gre.key =
1795 + htonl(nat_pptp_info->pac_call_id);
1796 + ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.gre.key =
1797 + htonl(nat_pptp_info->pac_call_id);
1798 + newip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
1799 + newcid = htonl(nat_pptp_info->pns_call_id);
1800 + }
1801 + } else {
1802 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.gre.key ==
1803 + htonl(ct_pptp_info->pac_call_id)) {
1804 + /* assume PNS->PAC */
1805 + newip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
1806 + newcid = htonl(ct_pptp_info->pns_call_id);
1807 + }
1808 + else {
1809 + /* assume PAC->PNS */
1810 + newip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
1811 + newcid = htonl(ct_pptp_info->pac_call_id);
1812 + }
1813 + }
1814 +
1815 + mr.rangesize = 1;
1816 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED;
1817 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
1818 + mr.range[0].min = mr.range[0].max =
1819 + ((union ip_conntrack_manip_proto ) { newcid });
1820 + DEBUGP("change ip to %u.%u.%u.%u\n",
1821 + NIPQUAD(newip));
1822 + DEBUGP("change key to 0x%x\n", ntohl(newcid));
1823 + ret = ip_nat_setup_info(ct, &mr, hooknum);
1824 +
1825 + UNLOCK_BH(&ip_pptp_lock);
1826 +
1827 + return ret;
1828 +
1829 +}
1830 +
1831 +/* outbound packets == from PNS to PAC */
1832 +static inline unsigned int
1833 +pptp_outbound_pkt(struct sk_buff **pskb,
1834 + struct ip_conntrack *ct,
1835 + enum ip_conntrack_info ctinfo,
1836 + struct ip_conntrack_expect *exp)
1837 +
1838 +{
1839 + struct iphdr *iph = (*pskb)->nh.iph;
1840 + struct tcphdr *tcph = (void *) iph + iph->ihl*4;
1841 + struct pptp_pkt_hdr *pptph = (struct pptp_pkt_hdr *)
1842 + ((void *)tcph + tcph->doff*4);
1843 +
1844 + struct PptpControlHeader *ctlh;
1845 + union pptp_ctrl_union pptpReq;
1846 + struct ip_ct_pptp_master *ct_pptp_info = &ct->help.ct_pptp_info;
1847 + struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info;
1848 +
1849 + u_int16_t msg, *cid = NULL, new_callid;
1850 +
1851 + /* FIXME: size checks !!! */
1852 + ctlh = (struct PptpControlHeader *) ((void *) pptph + sizeof(*pptph));
1853 + pptpReq.rawreq = (void *) ((void *) ctlh + sizeof(*ctlh));
1854 +
1855 + new_callid = htons(ct_pptp_info->pns_call_id);
1856 +
1857 + switch (msg = ntohs(ctlh->messageType)) {
1858 + case PPTP_OUT_CALL_REQUEST:
1859 + cid = &pptpReq.ocreq->callID;
1860 + /* FIXME: ideally we would want to reserve a call ID
1861 + * here. current netfilter NAT core is not able to do
1862 + * this :( For now we use TCP source port. This breaks
1863 + * multiple calls within one control session */
1864 +
1865 + /* save original call ID in nat_info */
1866 + nat_pptp_info->pns_call_id = ct_pptp_info->pns_call_id;
1867 +
1868 + /* don't use tcph->source since we are at a DSTmanip
1869 + * hook (e.g. PREROUTING) and pkt is not mangled yet */
1870 + new_callid = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.tcp.port;
1871 +
1872 + /* save new call ID in ct info */
1873 + ct_pptp_info->pns_call_id = ntohs(new_callid);
1874 + break;
1875 + case PPTP_IN_CALL_REPLY:
1876 + cid = &pptpReq.icreq->callID;
1877 + break;
1878 + case PPTP_CALL_CLEAR_REQUEST:
1879 + cid = &pptpReq.clrreq->callID;
1880 + break;
1881 + default:
1882 + DEBUGP("unknown outbound packet 0x%04x:%s\n", msg,
1883 + (msg <= PPTP_MSG_MAX)? strMName[msg]:strMName[0]);
1884 + /* fall through */
1885 +
1886 + case PPTP_SET_LINK_INFO:
1887 + /* only need to NAT in case PAC is behind NAT box */
1888 + case PPTP_START_SESSION_REQUEST:
1889 + case PPTP_START_SESSION_REPLY:
1890 + case PPTP_STOP_SESSION_REQUEST:
1891 + case PPTP_STOP_SESSION_REPLY:
1892 + case PPTP_ECHO_REQUEST:
1893 + case PPTP_ECHO_REPLY:
1894 + /* no need to alter packet */
1895 + return NF_ACCEPT;
1896 + }
1897 +
1898 + IP_NF_ASSERT(cid);
1899 +
1900 + DEBUGP("altering call id from 0x%04x to 0x%04x\n",
1901 + ntohs(*cid), ntohs(new_callid));
1902 +
1903 + /* mangle packet */
1904 + ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, (void *)cid - (void *)pptph,
1905 + sizeof(new_callid), (char *)&new_callid,
1906 + sizeof(new_callid));
1907 +
1908 + return NF_ACCEPT;
1909 +}
1910 +
1911 +/* inbound packets == from PAC to PNS */
1912 +static inline unsigned int
1913 +pptp_inbound_pkt(struct sk_buff **pskb,
1914 + struct ip_conntrack *ct,
1915 + enum ip_conntrack_info ctinfo,
1916 + struct ip_conntrack_expect *oldexp)
1917 +{
1918 + struct iphdr *iph = (*pskb)->nh.iph;
1919 + struct tcphdr *tcph = (void *) iph + iph->ihl*4;
1920 + struct pptp_pkt_hdr *pptph = (struct pptp_pkt_hdr *)
1921 + ((void *)tcph + tcph->doff*4);
1922 +
1923 + struct PptpControlHeader *ctlh;
1924 + union pptp_ctrl_union pptpReq;
1925 + struct ip_ct_pptp_master *ct_pptp_info = &ct->help.ct_pptp_info;
1926 + struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info;
1927 +
1928 + u_int16_t msg, new_cid = 0, new_pcid, *pcid = NULL, *cid = NULL;
1929 + u_int32_t old_dst_ip;
1930 +
1931 + struct ip_conntrack_tuple t, inv_t;
1932 + struct ip_conntrack_tuple *orig_t, *reply_t;
1933 +
1934 + /* FIXME: size checks !!! */
1935 + ctlh = (struct PptpControlHeader *) ((void *) pptph + sizeof(*pptph));
1936 + pptpReq.rawreq = (void *) ((void *) ctlh + sizeof(*ctlh));
1937 +
1938 + new_pcid = htons(nat_pptp_info->pns_call_id);
1939 +
1940 + switch (msg = ntohs(ctlh->messageType)) {
1941 + case PPTP_OUT_CALL_REPLY:
1942 + pcid = &pptpReq.ocack->peersCallID;
1943 + cid = &pptpReq.ocack->callID;
1944 + if (!oldexp) {
1945 + DEBUGP("outcall but no expectation\n");
1946 + break;
1947 + }
1948 + old_dst_ip = oldexp->tuple.dst.ip;
1949 + t = oldexp->tuple;
1950 + invert_tuplepr(&inv_t, &t);
1951 +
1952 + /* save original PAC call ID in nat_info */
1953 + nat_pptp_info->pac_call_id = ct_pptp_info->pac_call_id;
1954 +
1955 + /* alter expectation */
1956 + orig_t = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple;
1957 + reply_t = &ct->tuplehash[IP_CT_DIR_REPLY].tuple;
1958 + if (t.src.ip == orig_t->src.ip && t.dst.ip == orig_t->dst.ip) {
1959 + /* expectation for PNS->PAC direction */
1960 + t.src.u.gre.key = htonl(nat_pptp_info->pns_call_id);
1961 + t.dst.u.gre.key = htonl(ct_pptp_info->pac_call_id);
1962 + inv_t.src.ip = reply_t->src.ip;
1963 + inv_t.dst.ip = reply_t->dst.ip;
1964 + inv_t.src.u.gre.key = htonl(nat_pptp_info->pac_call_id);
1965 + inv_t.dst.u.gre.key = htonl(ct_pptp_info->pns_call_id);
1966 + } else {
1967 + /* expectation for PAC->PNS direction */
1968 + t.src.u.gre.key = htonl(nat_pptp_info->pac_call_id);
1969 + t.dst.u.gre.key = htonl(ct_pptp_info->pns_call_id);
1970 + inv_t.src.ip = orig_t->src.ip;
1971 + inv_t.dst.ip = orig_t->dst.ip;
1972 + inv_t.src.u.gre.key = htonl(nat_pptp_info->pns_call_id);
1973 + inv_t.dst.u.gre.key = htonl(ct_pptp_info->pac_call_id);
1974 + }
1975 +
1976 + if (!ip_conntrack_change_expect(oldexp, &t)) {
1977 + DEBUGP("successfully changed expect\n");
1978 + } else {
1979 + DEBUGP("can't change expect\n");
1980 + }
1981 + ip_ct_gre_keymap_change(oldexp->proto.gre.keymap_orig, &t);
1982 + ip_ct_gre_keymap_change(oldexp->proto.gre.keymap_reply, &inv_t);
1983 + break;
1984 + case PPTP_IN_CALL_CONNECT:
1985 + pcid = &pptpReq.iccon->peersCallID;
1986 + if (!oldexp)
1987 + break;
1988 + old_dst_ip = oldexp->tuple.dst.ip;
1989 + t = oldexp->tuple;
1990 +
1991 + /* alter expectation, no need for callID */
1992 + if (t.dst.ip == ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip) {
1993 + /* expectation for PNS->PAC direction */
1994 + t.src.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
1995 + } else {
1996 + /* expectation for PAC->PNS direction */
1997 + t.dst.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
1998 + }
1999 +
2000 + if (!ip_conntrack_change_expect(oldexp, &t)) {
2001 + DEBUGP("successfully changed expect\n");
2002 + } else {
2003 + DEBUGP("can't change expect\n");
2004 + }
2005 + break;
2006 + case PPTP_IN_CALL_REQUEST:
2007 + /* only need to nat in case PAC is behind NAT box */
2008 + break;
2009 + case PPTP_WAN_ERROR_NOTIFY:
2010 + pcid = &pptpReq.wanerr->peersCallID;
2011 + break;
2012 + case PPTP_CALL_DISCONNECT_NOTIFY:
2013 + pcid = &pptpReq.disc->callID;
2014 + break;
2015 +
2016 + default:
2017 + DEBUGP("unknown inbound packet %s\n",
2018 + (msg <= PPTP_MSG_MAX)? strMName[msg]:strMName[0]);
2019 + /* fall through */
2020 +
2021 + case PPTP_START_SESSION_REQUEST:
2022 + case PPTP_START_SESSION_REPLY:
2023 + case PPTP_STOP_SESSION_REQUEST:
2024 + case PPTP_STOP_SESSION_REPLY:
2025 + case PPTP_ECHO_REQUEST:
2026 + case PPTP_ECHO_REPLY:
2027 + /* no need to alter packet */
2028 + return NF_ACCEPT;
2029 + }
2030 +
2031 + /* mangle packet */
2032 + IP_NF_ASSERT(pcid);
2033 + DEBUGP("altering peer call id from 0x%04x to 0x%04x\n",
2034 + ntohs(*pcid), ntohs(new_pcid));
2035 + ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, (void *)pcid - (void *)pptph,
2036 + sizeof(new_pcid), (char *)&new_pcid,
2037 + sizeof(new_pcid));
2038 +
2039 + if (new_cid) {
2040 + IP_NF_ASSERT(cid);
2041 + DEBUGP("altering call id from 0x%04x to 0x%04x\n",
2042 + ntohs(*cid), ntohs(new_cid));
2043 + ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
2044 + (void *)cid - (void *)pptph,
2045 + sizeof(new_cid), (char *)&new_cid,
2046 + sizeof(new_cid));
2047 + }
2048 +
2049 + /* great, at least we don't need to resize packets */
2050 + return NF_ACCEPT;
2051 +}
2052 +
2053 +
2054 +static unsigned int tcp_help(struct ip_conntrack *ct,
2055 + struct ip_conntrack_expect *exp,
2056 + struct ip_nat_info *info,
2057 + enum ip_conntrack_info ctinfo,
2058 + unsigned int hooknum, struct sk_buff **pskb)
2059 +{
2060 + struct iphdr *iph = (*pskb)->nh.iph;
2061 + struct tcphdr *tcph = (void *) iph + iph->ihl*4;
2062 + unsigned int datalen = (*pskb)->len - iph->ihl*4 - tcph->doff*4;
2063 + struct pptp_pkt_hdr *pptph;
2064 +
2065 + int dir;
2066 +
2067 + DEBUGP("entering\n");
2068 +
2069 + /* Only mangle things once: DST for original direction
2070 + and SRC for reply direction. */
2071 + dir = CTINFO2DIR(ctinfo);
2072 + if (!((HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC
2073 + && dir == IP_CT_DIR_ORIGINAL)
2074 + || (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST
2075 + && dir == IP_CT_DIR_REPLY))) {
2076 + DEBUGP("Not touching dir %s at hook %s\n",
2077 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
2078 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
2079 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
2080 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT"
2081 + : hooknum == NF_IP_LOCAL_IN ? "INPUT" : "???");
2082 + return NF_ACCEPT;
2083 + }
2084 +
2085 + /* if packet is too small, just skip it */
2086 + if (datalen < sizeof(struct pptp_pkt_hdr)+
2087 + sizeof(struct PptpControlHeader)) {
2088 + DEBUGP("pptp packet too short\n");
2089 + return NF_ACCEPT;
2090 + }
2091 +
2092 + pptph = (struct pptp_pkt_hdr *) ((void *)tcph + tcph->doff*4);
2093 +
2094 + /* if it's not a control message, we can't handle it */
2095 + if (ntohs(pptph->packetType) != PPTP_PACKET_CONTROL ||
2096 + ntohl(pptph->magicCookie) != PPTP_MAGIC_COOKIE) {
2097 + DEBUGP("not a pptp control packet\n");
2098 + return NF_ACCEPT;
2099 + }
2100 +
2101 + LOCK_BH(&ip_pptp_lock);
2102 +
2103 + if (dir == IP_CT_DIR_ORIGINAL) {
2104 + /* reuqests sent by client to server (PNS->PAC) */
2105 + pptp_outbound_pkt(pskb, ct, ctinfo, exp);
2106 + } else {
2107 + /* response from the server to the client (PAC->PNS) */
2108 + pptp_inbound_pkt(pskb, ct, ctinfo, exp);
2109 + }
2110 +
2111 + UNLOCK_BH(&ip_pptp_lock);
2112 +
2113 + return NF_ACCEPT;
2114 +}
2115 +
2116 +/* nat helper struct for control connection */
2117 +static struct ip_nat_helper pptp_tcp_helper = {
2118 + .list = { NULL, NULL },
2119 + .name = "pptp",
2120 + .flags = IP_NAT_HELPER_F_ALWAYS,
2121 + .me = THIS_MODULE,
2122 + .tuple = { .src = { .ip = 0,
2123 + .u = { .tcp = { .port =
2124 + __constant_htons(PPTP_CONTROL_PORT) }
2125 + }
2126 + },
2127 + .dst = { .ip = 0,
2128 + .u = { .all = 0 },
2129 + .protonum = IPPROTO_TCP
2130 + }
2131 + },
2132 +
2133 + .mask = { .src = { .ip = 0,
2134 + .u = { .tcp = { .port = 0xFFFF } }
2135 + },
2136 + .dst = { .ip = 0,
2137 + .u = { .all = 0 },
2138 + .protonum = 0xFFFF
2139 + }
2140 + },
2141 + .help = tcp_help,
2142 + .expect = pptp_nat_expected
2143 +};
2144 +
2145 +
2146 +static int __init init(void)
2147 +{
2148 + DEBUGP("%s: registering NAT helper\n", __FILE__);
2149 + if (ip_nat_helper_register(&pptp_tcp_helper)) {
2150 + printk(KERN_ERR "Unable to register NAT application helper "
2151 + "for pptp\n");
2152 + return -EIO;
2153 + }
2154 +
2155 + printk("ip_nat_pptp version %s loaded\n", IP_NAT_PPTP_VERSION);
2156 + return 0;
2157 +}
2158 +
2159 +static void __exit fini(void)
2160 +{
2161 + DEBUGP("cleanup_module\n" );
2162 + ip_nat_helper_unregister(&pptp_tcp_helper);
2163 + printk("ip_nat_pptp version %s unloaded\n", IP_NAT_PPTP_VERSION);
2164 +}
2165 +
2166 +module_init(init);
2167 +module_exit(fini);
2168 Binary files linux-2.4.29-old/net/ipv4/netfilter/.ip_nat_pptp.c.swp and linux-2.4.29-dev/net/ipv4/netfilter/.ip_nat_pptp.c.swp differ
2169 diff -urN linux-2.4.29-old/net/ipv4/netfilter/ip_nat_proto_gre.c linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_proto_gre.c
2170 --- linux-2.4.29-old/net/ipv4/netfilter/ip_nat_proto_gre.c 1970-01-01 01:00:00.000000000 +0100
2171 +++ linux-2.4.29-dev/net/ipv4/netfilter/ip_nat_proto_gre.c 2005-04-02 19:15:10.000000000 +0200
2172 @@ -0,0 +1,202 @@
2173 +/*
2174 + * ip_nat_proto_gre.c - Version 1.2
2175 + *
2176 + * NAT protocol helper module for GRE.
2177 + *
2178 + * GRE is a generic encapsulation protocol, which is generally not very
2179 + * suited for NAT, as it has no protocol-specific part as port numbers.
2180 + *
2181 + * It has an optional key field, which may help us distinguishing two
2182 + * connections between the same two hosts.
2183 + *
2184 + * GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784
2185 + *
2186 + * PPTP is built on top of a modified version of GRE, and has a mandatory
2187 + * field called "CallID", which serves us for the same purpose as the key
2188 + * field in plain GRE.
2189 + *
2190 + * Documentation about PPTP can be found in RFC 2637
2191 + *
2192 + * (C) 2000-2003 by Harald Welte <laforge@gnumonks.org>
2193 + *
2194 + * Development of this code funded by Astaro AG (http://www.astaro.com/)
2195 + *
2196 + */
2197 +
2198 +#include <linux/config.h>
2199 +#include <linux/module.h>
2200 +#include <linux/ip.h>
2201 +#include <linux/netfilter_ipv4/ip_nat.h>
2202 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
2203 +#include <linux/netfilter_ipv4/ip_nat_protocol.h>
2204 +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
2205 +
2206 +MODULE_LICENSE("GPL");
2207 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
2208 +MODULE_DESCRIPTION("Netfilter NAT protocol helper module for GRE");
2209 +
2210 +#if 0
2211 +#define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
2212 + ": " format, ## args)
2213 +#else
2214 +#define DEBUGP(x, args...)
2215 +#endif
2216 +
2217 +/* is key in given range between min and max */
2218 +static int
2219 +gre_in_range(const struct ip_conntrack_tuple *tuple,
2220 + enum ip_nat_manip_type maniptype,
2221 + const union ip_conntrack_manip_proto *min,
2222 + const union ip_conntrack_manip_proto *max)
2223 +{
2224 + u_int32_t key;
2225 +
2226 + if (maniptype == IP_NAT_MANIP_SRC)
2227 + key = tuple->src.u.gre.key;
2228 + else
2229 + key = tuple->dst.u.gre.key;
2230 +
2231 + return ntohl(key) >= ntohl(min->gre.key)
2232 + && ntohl(key) <= ntohl(max->gre.key);
2233 +}
2234 +
2235 +/* generate unique tuple ... */
2236 +static int
2237 +gre_unique_tuple(struct ip_conntrack_tuple *tuple,
2238 + const struct ip_nat_range *range,
2239 + enum ip_nat_manip_type maniptype,
2240 + const struct ip_conntrack *conntrack)
2241 +{
2242 + u_int32_t min, i, range_size;
2243 + u_int32_t key = 0, *keyptr;
2244 +
2245 + if (maniptype == IP_NAT_MANIP_SRC)
2246 + keyptr = &tuple->src.u.gre.key;
2247 + else
2248 + keyptr = &tuple->dst.u.gre.key;
2249 +
2250 + if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)) {
2251 +
2252 + DEBUGP("%p: NATing GRE PPTP\n", conntrack);
2253 + min = 1;
2254 + range_size = 0xffff;
2255 +
2256 + } else {
2257 + min = ntohl(range->min.gre.key);
2258 + range_size = ntohl(range->max.gre.key) - min + 1;
2259 + }
2260 +
2261 + DEBUGP("min = %u, range_size = %u\n", min, range_size);
2262 +
2263 + for (i = 0; i < range_size; i++, key++) {
2264 + *keyptr = htonl(min + key % range_size);
2265 + if (!ip_nat_used_tuple(tuple, conntrack))
2266 + return 1;
2267 + }
2268 +
2269 + DEBUGP("%p: no NAT mapping\n", conntrack);
2270 +
2271 + return 0;
2272 +}
2273 +
2274 +/* manipulate a GRE packet according to maniptype */
2275 +static void
2276 +gre_manip_pkt(struct iphdr *iph, size_t len,
2277 + const struct ip_conntrack_manip *manip,
2278 + enum ip_nat_manip_type maniptype)
2279 +{
2280 + struct gre_hdr *greh = (struct gre_hdr *)((u_int32_t *)iph+iph->ihl);
2281 + struct gre_hdr_pptp *pgreh = (struct gre_hdr_pptp *) greh;
2282 +
2283 + /* we only have destination manip of a packet, since 'source key'
2284 + * is not present in the packet itself */
2285 + if (maniptype == IP_NAT_MANIP_DST) {
2286 + /* key manipulation is always dest */
2287 + switch (greh->version) {
2288 + case 0:
2289 + if (!greh->key) {
2290 + DEBUGP("can't nat GRE w/o key\n");
2291 + break;
2292 + }
2293 + if (greh->csum) {
2294 + /* FIXME: Never tested this code... */
2295 + *(gre_csum(greh)) =
2296 + ip_nat_cheat_check(~*(gre_key(greh)),
2297 + manip->u.gre.key,
2298 + *(gre_csum(greh)));
2299 + }
2300 + *(gre_key(greh)) = manip->u.gre.key;
2301 + break;
2302 + case GRE_VERSION_PPTP:
2303 + DEBUGP("call_id -> 0x%04x\n",
2304 + ntohl(manip->u.gre.key));
2305 + pgreh->call_id = htons(ntohl(manip->u.gre.key));
2306 + break;
2307 + default:
2308 + DEBUGP("can't nat unknown GRE version\n");
2309 + break;
2310 + }
2311 + }
2312 +}
2313 +
2314 +/* print out a nat tuple */
2315 +static unsigned int
2316 +gre_print(char *buffer,
2317 + const struct ip_conntrack_tuple *match,
2318 + const struct ip_conntrack_tuple *mask)
2319 +{
2320 + unsigned int len = 0;
2321 +
2322 + if (mask->src.u.gre.key)
2323 + len += sprintf(buffer + len, "srckey=0x%x ",
2324 + ntohl(match->src.u.gre.key));
2325 +
2326 + if (mask->dst.u.gre.key)
2327 + len += sprintf(buffer + len, "dstkey=0x%x ",
2328 + ntohl(match->src.u.gre.key));
2329 +
2330 + return len;
2331 +}
2332 +
2333 +/* print a range of keys */
2334 +static unsigned int
2335 +gre_print_range(char *buffer, const struct ip_nat_range *range)
2336 +{
2337 + if (range->min.gre.key != 0
2338 + || range->max.gre.key != 0xFFFF) {
2339 + if (range->min.gre.key == range->max.gre.key)
2340 + return sprintf(buffer, "key 0x%x ",
2341 + ntohl(range->min.gre.key));
2342 + else
2343 + return sprintf(buffer, "keys 0x%u-0x%u ",
2344 + ntohl(range->min.gre.key),
2345 + ntohl(range->max.gre.key));
2346 + } else
2347 + return 0;
2348 +}
2349 +
2350 +/* nat helper struct */
2351 +static struct ip_nat_protocol gre =
2352 + { { NULL, NULL }, "GRE", IPPROTO_GRE,
2353 + gre_manip_pkt,
2354 + gre_in_range,
2355 + gre_unique_tuple,
2356 + gre_print,
2357 + gre_print_range
2358 + };
2359 +
2360 +static int __init init(void)
2361 +{
2362 + if (ip_nat_protocol_register(&gre))
2363 + return -EIO;
2364 +
2365 + return 0;
2366 +}
2367 +
2368 +static void __exit fini(void)
2369 +{
2370 + ip_nat_protocol_unregister(&gre);
2371 +}
2372 +
2373 +module_init(init);
2374 +module_exit(fini);
2375 diff -urN linux-2.4.29-old/net/ipv4/netfilter/Makefile linux-2.4.29-dev/net/ipv4/netfilter/Makefile
2376 --- linux-2.4.29-old/net/ipv4/netfilter/Makefile 2005-04-02 19:04:11.000000000 +0200
2377 +++ linux-2.4.29-dev/net/ipv4/netfilter/Makefile 2005-04-02 19:07:18.000000000 +0200
2378 @@ -36,23 +36,32 @@
2379 ifdef CONFIG_IP_NF_AMANDA
2380 export-objs += ip_conntrack_amanda.o
2381 endif
2382 -
2383 obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
2384 obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
2385 ifdef CONFIG_IP_NF_FTP
2386 export-objs += ip_conntrack_ftp.o
2387 endif
2388 -
2389 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
2390 ifdef CONFIG_IP_NF_IRC
2391 export-objs += ip_conntrack_irc.o
2392 endif
2393 +obj-$(CONFIG_IP_NF_CT_PROTO_GRE) += ip_conntrack_proto_gre.o
2394 +ifdef CONFIG_IP_NF_CT_PROTO_GRE
2395 + export-objs += ip_conntrack_proto_gre.o
2396 +endif
2397 +obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o
2398 +ifdef CONFIG_IP_NF_NAT_PPTP
2399 + export-objs += ip_conntrack_pptp.o
2400 +endif
2401 +
2402
2403 # NAT helpers
2404 obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o
2405 obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
2406 obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
2407 obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
2408 +obj-$(CONFIG_IP_NF_NAT_PROTO_GRE) += ip_nat_proto_gre.o
2409 +obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o
2410
2411 # generic IP tables
2412 obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
This page took 0.136344 seconds and 5 git commands to generate.