2 * ip_conntrack_pptp.c - Version 3.0
4 * Connection tracking support for PPTP (Point to Point Tunneling Protocol).
5 * PPTP is a a protocol for creating virtual private networks.
6 * It is a specification defined by Microsoft and some vendors
7 * working with Microsoft. PPTP is built on top of a modified
8 * version of the Internet Generic Routing Encapsulation Protocol.
9 * GRE is defined in RFC 1701 and RFC 1702. Documentation of
10 * PPTP can be found in RFC 2637
12 * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org>
14 * Development of this code funded by Astaro AG (http://www.astaro.com/)
17 * - We blindly assume that control connections are always
18 * established in PNS->PAC direction. This is a violation
20 * - We can only support one single call within each session
23 * - testing of incoming PPTP calls
26 * 2002-02-05 - Version 1.3
27 * - Call ip_conntrack_unexpect_related() from
28 * pptp_destroy_siblings() to destroy expectations in case
29 * CALL_DISCONNECT_NOTIFY or tcp fin packet was seen
30 * (Philip Craig <philipc@snapgear.com>)
31 * - Add Version information at module loadtime
32 * 2002-02-10 - Version 1.6
33 * - move to C99 style initializers
34 * - remove second expectation if first arrives
35 * 2004-10-22 - Version 2.0
36 * - merge Mandrake's 2.6.x port with recent 2.6.x API changes
37 * - fix lots of linear skb assumptions from Mandrake's port
38 * 2005-06-10 - Version 2.1
39 * - use ip_conntrack_expect_free() instead of kfree() on the
40 * expect's (which are from the slab for quite some time)
41 * 2005-06-10 - Version 3.0
42 * - port helper to post-2.6.11 API changes,
43 * funded by Oxcoda NetBox Blue (http://www.netboxblue.com/)
44 * 2005-07-30 - Version 3.1
45 * - port helper to 2.6.13 API changes
49 #include <linux/module.h>
50 #include <linux/netfilter.h>
52 #include <net/checksum.h>
55 #include <linux/netfilter_ipv4/ip_conntrack.h>
56 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
57 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
58 #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
59 #include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
61 #define IP_CT_PPTP_VERSION "3.1"
63 MODULE_LICENSE("GPL");
64 MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
65 MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP");
67 static DEFINE_SPINLOCK(ip_pptp_lock
);
70 (*ip_nat_pptp_hook_outbound
)(struct sk_buff
**pskb
,
71 struct ip_conntrack
*ct
,
72 enum ip_conntrack_info ctinfo
,
73 struct PptpControlHeader
*ctlh
,
74 union pptp_ctrl_union
*pptpReq
);
77 (*ip_nat_pptp_hook_inbound
)(struct sk_buff
**pskb
,
78 struct ip_conntrack
*ct
,
79 enum ip_conntrack_info ctinfo
,
80 struct PptpControlHeader
*ctlh
,
81 union pptp_ctrl_union
*pptpReq
);
84 (*ip_nat_pptp_hook_exp_gre
)(struct ip_conntrack_expect
*expect_orig
,
85 struct ip_conntrack_expect
*expect_reply
);
88 (*ip_nat_pptp_hook_expectfn
)(struct ip_conntrack
*ct
,
89 struct ip_conntrack_expect
*exp
);
92 /* PptpControlMessageType names */
93 const char *pptp_msg_name
[] = {
95 "START_SESSION_REQUEST",
96 "START_SESSION_REPLY",
97 "STOP_SESSION_REQUEST",
106 "CALL_CLEAR_REQUEST",
107 "CALL_DISCONNECT_NOTIFY",
111 EXPORT_SYMBOL(pptp_msg_name
);
112 #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, __FUNCTION__, ## args)
114 #define DEBUGP(format, args...)
118 #define MINS * 60 SECS
119 #define HOURS * 60 MINS
121 #define PPTP_GRE_TIMEOUT (10 MINS)
122 #define PPTP_GRE_STREAM_TIMEOUT (5 HOURS)
124 static void pptp_expectfn(struct ip_conntrack
*ct
,
125 struct ip_conntrack_expect
*exp
)
127 DEBUGP("increasing timeouts\n");
129 /* increase timeout of GRE data channel conntrack entry */
130 ct
->proto
.gre
.timeout
= PPTP_GRE_TIMEOUT
;
131 ct
->proto
.gre
.stream_timeout
= PPTP_GRE_STREAM_TIMEOUT
;
133 /* Can you see how rusty this code is, compared with the pre-2.6.11
134 * one? That's what happened to my shiny newnat of 2002 ;( -HW */
136 if (!ip_nat_pptp_hook_expectfn
) {
137 struct ip_conntrack_tuple inv_t
;
138 struct ip_conntrack_expect
*exp_other
;
140 /* obviously this tuple inversion only works until you do NAT */
141 invert_tuplepr(&inv_t
, &exp
->tuple
);
142 DEBUGP("trying to unexpect other dir: ");
145 exp_other
= ip_conntrack_expect_find(&inv_t
);
147 /* delete other expectation. */
149 ip_conntrack_unexpect_related(exp_other
);
150 ip_conntrack_expect_put(exp_other
);
152 DEBUGP("not found\n");
155 /* we need more than simple inversion */
156 ip_nat_pptp_hook_expectfn(ct
, exp
);
160 static int destroy_sibling_or_exp(const struct ip_conntrack_tuple
*t
)
162 struct ip_conntrack_tuple_hash
*h
;
163 struct ip_conntrack_expect
*exp
;
165 DEBUGP("trying to timeout ct or exp for tuple ");
168 h
= ip_conntrack_find_get(t
, NULL
);
170 struct ip_conntrack
*sibling
= tuplehash_to_ctrack(h
);
171 DEBUGP("setting timeout of conntrack %p to 0\n", sibling
);
172 sibling
->proto
.gre
.timeout
= 0;
173 sibling
->proto
.gre
.stream_timeout
= 0;
174 if (del_timer(&sibling
->timeout
))
175 sibling
->timeout
.function((unsigned long)sibling
);
176 ip_conntrack_put(sibling
);
179 exp
= ip_conntrack_expect_find(t
);
181 DEBUGP("unexpect_related of expect %p\n", exp
);
182 ip_conntrack_unexpect_related(exp
);
183 ip_conntrack_expect_put(exp
);
192 /* timeout GRE data connections */
193 static void pptp_destroy_siblings(struct ip_conntrack
*ct
)
195 struct ip_conntrack_tuple t
;
197 /* Since ct->sibling_list has literally rusted away in 2.6.11,
198 * we now need another way to find out about our sibling
199 * contrack and expects... -HW */
201 /* try original (pns->pac) tuple */
202 memcpy(&t
, &ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
, sizeof(t
));
203 t
.dst
.protonum
= IPPROTO_GRE
;
204 t
.src
.u
.gre
.key
= ct
->help
.ct_pptp_info
.pns_call_id
;
205 t
.dst
.u
.gre
.key
= ct
->help
.ct_pptp_info
.pac_call_id
;
207 if (!destroy_sibling_or_exp(&t
))
208 DEBUGP("failed to timeout original pns->pac ct/exp\n");
210 /* try reply (pac->pns) tuple */
211 memcpy(&t
, &ct
->tuplehash
[IP_CT_DIR_REPLY
].tuple
, sizeof(t
));
212 t
.dst
.protonum
= IPPROTO_GRE
;
213 t
.src
.u
.gre
.key
= ct
->help
.ct_pptp_info
.pac_call_id
;
214 t
.dst
.u
.gre
.key
= ct
->help
.ct_pptp_info
.pns_call_id
;
216 if (!destroy_sibling_or_exp(&t
))
217 DEBUGP("failed to timeout reply pac->pns ct/exp\n");
220 /* expect GRE connections (PNS->PAC and PAC->PNS direction) */
222 exp_gre(struct ip_conntrack
*master
,
226 struct ip_conntrack_tuple inv_tuple
;
227 struct ip_conntrack_tuple exp_tuples
[] = {
228 /* tuple in original direction, PNS->PAC */
229 { .src
= { .ip
= master
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.src
.ip
,
230 .u
= { .gre
= { .key
= peer_callid
} }
232 .dst
= { .ip
= master
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.ip
,
233 .u
= { .gre
= { .key
= callid
} },
234 .protonum
= IPPROTO_GRE
237 /* tuple in reply direction, PAC->PNS */
238 { .src
= { .ip
= master
->tuplehash
[IP_CT_DIR_REPLY
].tuple
.src
.ip
,
239 .u
= { .gre
= { .key
= callid
} }
241 .dst
= { .ip
= master
->tuplehash
[IP_CT_DIR_REPLY
].tuple
.dst
.ip
,
242 .u
= { .gre
= { .key
= peer_callid
} },
243 .protonum
= IPPROTO_GRE
247 struct ip_conntrack_expect
*exp_orig
, *exp_reply
;
250 exp_orig
= ip_conntrack_expect_alloc(master
);
251 if (exp_orig
== NULL
)
254 exp_reply
= ip_conntrack_expect_alloc(master
);
255 if (exp_reply
== NULL
)
258 memcpy(&exp_orig
->tuple
, &exp_tuples
[0], sizeof(exp_orig
->tuple
));
260 exp_orig
->mask
.src
.ip
= 0xffffffff;
261 exp_orig
->mask
.src
.u
.all
= 0;
262 exp_orig
->mask
.dst
.u
.all
= 0;
263 exp_orig
->mask
.dst
.u
.gre
.key
= htons(0xffff);
264 exp_orig
->mask
.dst
.ip
= 0xffffffff;
265 exp_orig
->mask
.dst
.protonum
= 0xff;
267 exp_orig
->master
= master
;
268 exp_orig
->expectfn
= pptp_expectfn
;
271 /* both expectations are identical apart from tuple */
272 memcpy(exp_reply
, exp_orig
, sizeof(*exp_reply
));
273 memcpy(&exp_reply
->tuple
, &exp_tuples
[1], sizeof(exp_reply
->tuple
));
275 if (ip_nat_pptp_hook_exp_gre
)
276 ret
= ip_nat_pptp_hook_exp_gre(exp_orig
, exp_reply
);
279 DEBUGP("calling expect_related PNS->PAC");
280 DUMP_TUPLE(&exp_orig
->tuple
);
282 if (ip_conntrack_expect_related(exp_orig
) != 0) {
283 DEBUGP("cannot expect_related()\n");
287 DEBUGP("calling expect_related PAC->PNS");
288 DUMP_TUPLE(&exp_reply
->tuple
);
290 if (ip_conntrack_expect_related(exp_reply
) != 0) {
291 DEBUGP("cannot expect_related()\n");
292 goto out_unexpect_orig
;
295 /* Add GRE keymap entries */
296 if (ip_ct_gre_keymap_add(master
, &exp_reply
->tuple
, 0) != 0) {
297 DEBUGP("cannot keymap_add() exp\n");
298 goto out_unexpect_both
;
301 invert_tuplepr(&inv_tuple
, &exp_reply
->tuple
);
302 if (ip_ct_gre_keymap_add(master
, &inv_tuple
, 1) != 0) {
303 ip_ct_gre_keymap_destroy(master
);
304 DEBUGP("cannot keymap_add() exp_inv\n");
305 goto out_unexpect_both
;
311 ip_conntrack_expect_put(exp_reply
);
313 ip_conntrack_expect_put(exp_orig
);
318 ip_conntrack_unexpect_related(exp_reply
);
320 ip_conntrack_unexpect_related(exp_orig
);
325 pptp_inbound_pkt(struct sk_buff
**pskb
,
327 unsigned int nexthdr_off
,
328 unsigned int datalen
,
329 struct ip_conntrack
*ct
,
330 enum ip_conntrack_info ctinfo
)
332 struct PptpControlHeader _ctlh
, *ctlh
;
334 union pptp_ctrl_union _pptpReq
, *pptpReq
;
335 struct ip_ct_pptp_master
*info
= &ct
->help
.ct_pptp_info
;
339 ctlh
= skb_header_pointer(*pskb
, nexthdr_off
, sizeof(_ctlh
), &_ctlh
);
341 DEBUGP("error during skb_header_pointer\n");
344 nexthdr_off
+= sizeof(_ctlh
);
345 datalen
-= sizeof(_ctlh
);
348 if (reqlen
> sizeof(*pptpReq
))
349 reqlen
= sizeof(*pptpReq
);
350 pptpReq
= skb_header_pointer(*pskb
, nexthdr_off
, reqlen
, &_pptpReq
);
352 DEBUGP("error during skb_header_pointer\n");
356 msg
= ntohs(ctlh
->messageType
);
357 DEBUGP("inbound control message %s\n", pptp_msg_name
[msg
]);
360 case PPTP_START_SESSION_REPLY
:
361 if (reqlen
< sizeof(_pptpReq
.srep
)) {
362 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
366 /* server confirms new control session */
367 if (info
->sstate
< PPTP_SESSION_REQUESTED
) {
368 DEBUGP("%s without START_SESS_REQUEST\n",
372 if (pptpReq
->srep
.resultCode
== PPTP_START_OK
)
373 info
->sstate
= PPTP_SESSION_CONFIRMED
;
375 info
->sstate
= PPTP_SESSION_ERROR
;
378 case PPTP_STOP_SESSION_REPLY
:
379 if (reqlen
< sizeof(_pptpReq
.strep
)) {
380 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
384 /* server confirms end of control session */
385 if (info
->sstate
> PPTP_SESSION_STOPREQ
) {
386 DEBUGP("%s without STOP_SESS_REQUEST\n",
390 if (pptpReq
->strep
.resultCode
== PPTP_STOP_OK
)
391 info
->sstate
= PPTP_SESSION_NONE
;
393 info
->sstate
= PPTP_SESSION_ERROR
;
396 case PPTP_OUT_CALL_REPLY
:
397 if (reqlen
< sizeof(_pptpReq
.ocack
)) {
398 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
402 /* server accepted call, we now expect GRE frames */
403 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
) {
404 DEBUGP("%s but no session\n", pptp_msg_name
[msg
]);
407 if (info
->cstate
!= PPTP_CALL_OUT_REQ
&&
408 info
->cstate
!= PPTP_CALL_OUT_CONF
) {
409 DEBUGP("%s without OUTCALL_REQ\n", pptp_msg_name
[msg
]);
412 if (pptpReq
->ocack
.resultCode
!= PPTP_OUTCALL_CONNECT
) {
413 info
->cstate
= PPTP_CALL_NONE
;
417 cid
= &pptpReq
->ocack
.callID
;
418 pcid
= &pptpReq
->ocack
.peersCallID
;
420 info
->pac_call_id
= *cid
;
422 if (info
->pns_call_id
!= *pcid
) {
423 DEBUGP("%s for unknown callid %u\n",
424 pptp_msg_name
[msg
], ntohs(*pcid
));
428 DEBUGP("%s, CID=%X, PCID=%X\n", pptp_msg_name
[msg
],
429 ntohs(*cid
), ntohs(*pcid
));
431 info
->cstate
= PPTP_CALL_OUT_CONF
;
433 exp_gre(ct
, *cid
, *pcid
);
436 case PPTP_IN_CALL_REQUEST
:
437 if (reqlen
< sizeof(_pptpReq
.icack
)) {
438 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
442 /* server tells us about incoming call request */
443 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
) {
444 DEBUGP("%s but no session\n", pptp_msg_name
[msg
]);
447 pcid
= &pptpReq
->icack
.peersCallID
;
448 DEBUGP("%s, PCID=%X\n", pptp_msg_name
[msg
], ntohs(*pcid
));
449 info
->cstate
= PPTP_CALL_IN_REQ
;
450 info
->pac_call_id
= *pcid
;
453 case PPTP_IN_CALL_CONNECT
:
454 if (reqlen
< sizeof(_pptpReq
.iccon
)) {
455 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
459 /* server tells us about incoming call established */
460 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
) {
461 DEBUGP("%s but no session\n", pptp_msg_name
[msg
]);
464 if (info
->cstate
!= PPTP_CALL_IN_REP
465 && info
->cstate
!= PPTP_CALL_IN_CONF
) {
466 DEBUGP("%s but never sent IN_CALL_REPLY\n",
471 pcid
= &pptpReq
->iccon
.peersCallID
;
472 cid
= &info
->pac_call_id
;
474 if (info
->pns_call_id
!= *pcid
) {
475 DEBUGP("%s for unknown CallID %u\n",
476 pptp_msg_name
[msg
], ntohs(*pcid
));
480 DEBUGP("%s, PCID=%X\n", pptp_msg_name
[msg
], ntohs(*pcid
));
481 info
->cstate
= PPTP_CALL_IN_CONF
;
483 /* we expect a GRE connection from PAC to PNS */
484 exp_gre(ct
, *cid
, *pcid
);
487 case PPTP_CALL_DISCONNECT_NOTIFY
:
488 if (reqlen
< sizeof(_pptpReq
.disc
)) {
489 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
493 /* server confirms disconnect */
494 cid
= &pptpReq
->disc
.callID
;
495 DEBUGP("%s, CID=%X\n", pptp_msg_name
[msg
], ntohs(*cid
));
496 info
->cstate
= PPTP_CALL_NONE
;
498 /* untrack this call id, unexpect GRE packets */
499 pptp_destroy_siblings(ct
);
502 case PPTP_WAN_ERROR_NOTIFY
:
505 case PPTP_ECHO_REQUEST
:
506 case PPTP_ECHO_REPLY
:
507 /* I don't have to explain these ;) */
510 DEBUGP("invalid %s (TY=%d)\n", (msg
<= PPTP_MSG_MAX
)
511 ? pptp_msg_name
[msg
]:pptp_msg_name
[0], msg
);
516 if (ip_nat_pptp_hook_inbound
)
517 return ip_nat_pptp_hook_inbound(pskb
, ct
, ctinfo
, ctlh
,
525 pptp_outbound_pkt(struct sk_buff
**pskb
,
527 unsigned int nexthdr_off
,
528 unsigned int datalen
,
529 struct ip_conntrack
*ct
,
530 enum ip_conntrack_info ctinfo
)
532 struct PptpControlHeader _ctlh
, *ctlh
;
534 union pptp_ctrl_union _pptpReq
, *pptpReq
;
535 struct ip_ct_pptp_master
*info
= &ct
->help
.ct_pptp_info
;
539 ctlh
= skb_header_pointer(*pskb
, nexthdr_off
, sizeof(_ctlh
), &_ctlh
);
542 nexthdr_off
+= sizeof(_ctlh
);
543 datalen
-= sizeof(_ctlh
);
546 if (reqlen
> sizeof(*pptpReq
))
547 reqlen
= sizeof(*pptpReq
);
548 pptpReq
= skb_header_pointer(*pskb
, nexthdr_off
, reqlen
, &_pptpReq
);
552 msg
= ntohs(ctlh
->messageType
);
553 DEBUGP("outbound control message %s\n", pptp_msg_name
[msg
]);
556 case PPTP_START_SESSION_REQUEST
:
557 /* client requests for new control session */
558 if (info
->sstate
!= PPTP_SESSION_NONE
) {
559 DEBUGP("%s but we already have one",
562 info
->sstate
= PPTP_SESSION_REQUESTED
;
564 case PPTP_STOP_SESSION_REQUEST
:
565 /* client requests end of control session */
566 info
->sstate
= PPTP_SESSION_STOPREQ
;
569 case PPTP_OUT_CALL_REQUEST
:
570 if (reqlen
< sizeof(_pptpReq
.ocreq
)) {
571 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
575 /* client initiating connection to server */
576 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
) {
577 DEBUGP("%s but no session\n",
581 info
->cstate
= PPTP_CALL_OUT_REQ
;
582 /* track PNS call id */
583 cid
= &pptpReq
->ocreq
.callID
;
584 DEBUGP("%s, CID=%X\n", pptp_msg_name
[msg
], ntohs(*cid
));
585 info
->pns_call_id
= *cid
;
587 case PPTP_IN_CALL_REPLY
:
588 if (reqlen
< sizeof(_pptpReq
.icack
)) {
589 DEBUGP("%s: short packet\n", pptp_msg_name
[msg
]);
593 /* client answers incoming call */
594 if (info
->cstate
!= PPTP_CALL_IN_REQ
595 && info
->cstate
!= PPTP_CALL_IN_REP
) {
596 DEBUGP("%s without incall_req\n",
600 if (pptpReq
->icack
.resultCode
!= PPTP_INCALL_ACCEPT
) {
601 info
->cstate
= PPTP_CALL_NONE
;
604 pcid
= &pptpReq
->icack
.peersCallID
;
605 if (info
->pac_call_id
!= *pcid
) {
606 DEBUGP("%s for unknown call %u\n",
607 pptp_msg_name
[msg
], ntohs(*pcid
));
610 DEBUGP("%s, CID=%X\n", pptp_msg_name
[msg
], ntohs(*pcid
));
611 /* part two of the three-way handshake */
612 info
->cstate
= PPTP_CALL_IN_REP
;
613 info
->pns_call_id
= pptpReq
->icack
.callID
;
616 case PPTP_CALL_CLEAR_REQUEST
:
617 /* client requests hangup of call */
618 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
) {
619 DEBUGP("CLEAR_CALL but no session\n");
622 /* FUTURE: iterate over all calls and check if
623 * call ID is valid. We don't do this without newnat,
624 * because we only know about last call */
625 info
->cstate
= PPTP_CALL_CLEAR_REQ
;
627 case PPTP_SET_LINK_INFO
:
629 case PPTP_ECHO_REQUEST
:
630 case PPTP_ECHO_REPLY
:
631 /* I don't have to explain these ;) */
634 DEBUGP("invalid %s (TY=%d)\n", (msg
<= PPTP_MSG_MAX
)?
635 pptp_msg_name
[msg
]:pptp_msg_name
[0], msg
);
636 /* unknown: no need to create GRE masq table entry */
640 if (ip_nat_pptp_hook_outbound
)
641 return ip_nat_pptp_hook_outbound(pskb
, ct
, ctinfo
, ctlh
,
648 /* track caller id inside control connection, call expect_related */
650 conntrack_pptp_help(struct sk_buff
**pskb
,
651 struct ip_conntrack
*ct
, enum ip_conntrack_info ctinfo
)
654 struct pptp_pkt_hdr _pptph
, *pptph
;
655 struct tcphdr _tcph
, *tcph
;
656 u_int32_t tcplen
= (*pskb
)->len
- (*pskb
)->nh
.iph
->ihl
* 4;
658 int dir
= CTINFO2DIR(ctinfo
);
659 struct ip_ct_pptp_master
*info
= &ct
->help
.ct_pptp_info
;
660 unsigned int nexthdr_off
;
662 int oldsstate
, oldcstate
;
665 /* don't do any tracking before tcp handshake complete */
666 if (ctinfo
!= IP_CT_ESTABLISHED
667 && ctinfo
!= IP_CT_ESTABLISHED
+IP_CT_IS_REPLY
) {
668 DEBUGP("ctinfo = %u, skipping\n", ctinfo
);
672 nexthdr_off
= (*pskb
)->nh
.iph
->ihl
*4;
673 tcph
= skb_header_pointer(*pskb
, nexthdr_off
, sizeof(_tcph
), &_tcph
);
675 nexthdr_off
+= tcph
->doff
* 4;
676 datalen
= tcplen
- tcph
->doff
* 4;
678 if (tcph
->fin
|| tcph
->rst
) {
679 DEBUGP("RST/FIN received, timeouting GRE\n");
680 /* can't do this after real newnat */
681 info
->cstate
= PPTP_CALL_NONE
;
683 /* untrack this call id, unexpect GRE packets */
684 pptp_destroy_siblings(ct
);
687 pptph
= skb_header_pointer(*pskb
, nexthdr_off
, sizeof(_pptph
), &_pptph
);
689 DEBUGP("no full PPTP header, can't track\n");
692 nexthdr_off
+= sizeof(_pptph
);
693 datalen
-= sizeof(_pptph
);
695 /* if it's not a control message we can't do anything with it */
696 if (ntohs(pptph
->packetType
) != PPTP_PACKET_CONTROL
||
697 ntohl(pptph
->magicCookie
) != PPTP_MAGIC_COOKIE
) {
698 DEBUGP("not a control packet\n");
702 oldsstate
= info
->sstate
;
703 oldcstate
= info
->cstate
;
705 spin_lock_bh(&ip_pptp_lock
);
707 /* FIXME: We just blindly assume that the control connection is always
708 * established from PNS->PAC. However, RFC makes no guarantee */
709 if (dir
== IP_CT_DIR_ORIGINAL
)
710 /* client -> server (PNS -> PAC) */
711 ret
= pptp_outbound_pkt(pskb
, tcph
, nexthdr_off
, datalen
, ct
,
714 /* server -> client (PAC -> PNS) */
715 ret
= pptp_inbound_pkt(pskb
, tcph
, nexthdr_off
, datalen
, ct
,
717 DEBUGP("sstate: %d->%d, cstate: %d->%d\n",
718 oldsstate
, info
->sstate
, oldcstate
, info
->cstate
);
719 spin_unlock_bh(&ip_pptp_lock
);
724 /* control protocol helper */
725 static struct ip_conntrack_helper pptp
= {
726 .list
= { NULL
, NULL
},
731 .tuple
= { .src
= { .ip
= 0,
732 .u
= { .tcp
= { .port
=
733 __constant_htons(PPTP_CONTROL_PORT
) } }
737 .protonum
= IPPROTO_TCP
740 .mask
= { .src
= { .ip
= 0,
741 .u
= { .tcp
= { .port
= __constant_htons(0xffff) } }
748 .help
= conntrack_pptp_help
751 extern void ip_ct_proto_gre_fini(void);
752 extern int __init
ip_ct_proto_gre_init(void);
754 /* ip_conntrack_pptp initialization */
755 static int __init
ip_conntrack_helper_pptp_init(void)
759 retcode
= ip_ct_proto_gre_init();
763 DEBUGP(" registering helper\n");
764 if ((retcode
= ip_conntrack_helper_register(&pptp
))) {
765 printk(KERN_ERR
"Unable to register conntrack application "
766 "helper for pptp: %d\n", retcode
);
767 ip_ct_proto_gre_fini();
771 printk("ip_conntrack_pptp version %s loaded\n", IP_CT_PPTP_VERSION
);
775 static void __exit
ip_conntrack_helper_pptp_fini(void)
777 ip_conntrack_helper_unregister(&pptp
);
778 ip_ct_proto_gre_fini();
779 printk("ip_conntrack_pptp version %s unloaded\n", IP_CT_PPTP_VERSION
);
782 module_init(ip_conntrack_helper_pptp_init
);
783 module_exit(ip_conntrack_helper_pptp_fini
);
785 EXPORT_SYMBOL(ip_nat_pptp_hook_outbound
);
786 EXPORT_SYMBOL(ip_nat_pptp_hook_inbound
);
787 EXPORT_SYMBOL(ip_nat_pptp_hook_exp_gre
);
788 EXPORT_SYMBOL(ip_nat_pptp_hook_expectfn
);