RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / net / netfilter / nf_conntrack_pptp.c
blob7821980ceb44179de05b6a32aafd4207525e967b
1 /*
2 * Connection tracking support for PPTP (Point to Point Tunneling Protocol).
3 * PPTP is a a protocol for creating virtual private networks.
4 * It is a specification defined by Microsoft and some vendors
5 * working with Microsoft. PPTP is built on top of a modified
6 * version of the Internet Generic Routing Encapsulation Protocol.
7 * GRE is defined in RFC 1701 and RFC 1702. Documentation of
8 * PPTP can be found in RFC 2637
10 * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org>
12 * Development of this code funded by Astaro AG (http://www.astaro.com/)
14 * Limitations:
15 * - We blindly assume that control connections are always
16 * established in PNS->PAC direction. This is a violation
17 * of RFFC2673
18 * - We can only support one single call within each session
19 * TODO:
20 * - testing of incoming PPTP calls
23 #include <linux/module.h>
24 #include <linux/skbuff.h>
25 #include <linux/in.h>
26 #include <linux/tcp.h>
28 #include <net/netfilter/nf_conntrack.h>
29 #include <net/netfilter/nf_conntrack_core.h>
30 #include <net/netfilter/nf_conntrack_helper.h>
31 #include <linux/netfilter/nf_conntrack_proto_gre.h>
32 #include <linux/netfilter/nf_conntrack_pptp.h>
34 #define NF_CT_PPTP_VERSION "3.1"
36 MODULE_LICENSE("GPL");
37 MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
38 MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP");
39 MODULE_ALIAS("ip_conntrack_pptp");
41 static DEFINE_SPINLOCK(nf_pptp_lock);
43 int
44 (*nf_nat_pptp_hook_outbound)(struct sk_buff *skb,
45 struct nf_conn *ct, enum ip_conntrack_info ctinfo,
46 struct PptpControlHeader *ctlh,
47 union pptp_ctrl_union *pptpReq) __read_mostly;
48 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_outbound);
50 int
51 (*nf_nat_pptp_hook_inbound)(struct sk_buff *skb,
52 struct nf_conn *ct, enum ip_conntrack_info ctinfo,
53 struct PptpControlHeader *ctlh,
54 union pptp_ctrl_union *pptpReq) __read_mostly;
55 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_inbound);
57 void
58 (*nf_nat_pptp_hook_exp_gre)(struct nf_conntrack_expect *expect_orig,
59 struct nf_conntrack_expect *expect_reply)
60 __read_mostly;
61 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_exp_gre);
63 void
64 (*nf_nat_pptp_hook_expectfn)(struct nf_conn *ct,
65 struct nf_conntrack_expect *exp) __read_mostly;
66 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn);
68 #if 0
69 /* PptpControlMessageType names */
70 const char *pptp_msg_name[] = {
71 "UNKNOWN_MESSAGE",
72 "START_SESSION_REQUEST",
73 "START_SESSION_REPLY",
74 "STOP_SESSION_REQUEST",
75 "STOP_SESSION_REPLY",
76 "ECHO_REQUEST",
77 "ECHO_REPLY",
78 "OUT_CALL_REQUEST",
79 "OUT_CALL_REPLY",
80 "IN_CALL_REQUEST",
81 "IN_CALL_REPLY",
82 "IN_CALL_CONNECT",
83 "CALL_CLEAR_REQUEST",
84 "CALL_DISCONNECT_NOTIFY",
85 "WAN_ERROR_NOTIFY",
86 "SET_LINK_INFO"
88 EXPORT_SYMBOL(pptp_msg_name);
89 #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, __FUNCTION__, ## args)
90 #else
91 #define DEBUGP(format, args...)
92 #endif
94 #define SECS *HZ
95 #define MINS * 60 SECS
96 #define HOURS * 60 MINS
98 #define PPTP_GRE_TIMEOUT (10 MINS)
99 #define PPTP_GRE_STREAM_TIMEOUT (5 HOURS)
101 static void pptp_expectfn(struct nf_conn *ct,
102 struct nf_conntrack_expect *exp)
104 typeof(nf_nat_pptp_hook_expectfn) nf_nat_pptp_expectfn;
105 DEBUGP("increasing timeouts\n");
107 /* increase timeout of GRE data channel conntrack entry */
108 ct->proto.gre.timeout = PPTP_GRE_TIMEOUT;
109 ct->proto.gre.stream_timeout = PPTP_GRE_STREAM_TIMEOUT;
111 /* Can you see how rusty this code is, compared with the pre-2.6.11
112 * one? That's what happened to my shiny newnat of 2002 ;( -HW */
114 rcu_read_lock();
115 nf_nat_pptp_expectfn = rcu_dereference(nf_nat_pptp_hook_expectfn);
116 if (nf_nat_pptp_expectfn && ct->master->status & IPS_NAT_MASK)
117 nf_nat_pptp_expectfn(ct, exp);
118 else {
119 struct nf_conntrack_tuple inv_t;
120 struct nf_conntrack_expect *exp_other;
122 /* obviously this tuple inversion only works until you do NAT */
123 nf_ct_invert_tuplepr(&inv_t, &exp->tuple);
124 DEBUGP("trying to unexpect other dir: ");
125 NF_CT_DUMP_TUPLE(&inv_t);
127 exp_other = nf_conntrack_expect_find_get(&inv_t);
128 if (exp_other) {
129 /* delete other expectation. */
130 DEBUGP("found\n");
131 nf_conntrack_unexpect_related(exp_other);
132 nf_conntrack_expect_put(exp_other);
133 } else {
134 DEBUGP("not found\n");
137 rcu_read_unlock();
140 static int destroy_sibling_or_exp(const struct nf_conntrack_tuple *t)
142 struct nf_conntrack_tuple_hash *h;
143 struct nf_conntrack_expect *exp;
144 struct nf_conn *sibling;
146 DEBUGP("trying to timeout ct or exp for tuple ");
147 NF_CT_DUMP_TUPLE(t);
149 h = nf_conntrack_find_get(t, NULL);
150 if (h) {
151 sibling = nf_ct_tuplehash_to_ctrack(h);
152 DEBUGP("setting timeout of conntrack %p to 0\n", sibling);
153 sibling->proto.gre.timeout = 0;
154 sibling->proto.gre.stream_timeout = 0;
155 if (del_timer(&sibling->timeout))
156 sibling->timeout.function((unsigned long)sibling);
157 nf_ct_put(sibling);
158 return 1;
159 } else {
160 exp = nf_conntrack_expect_find_get(t);
161 if (exp) {
162 DEBUGP("unexpect_related of expect %p\n", exp);
163 nf_conntrack_unexpect_related(exp);
164 nf_conntrack_expect_put(exp);
165 return 1;
168 return 0;
171 /* timeout GRE data connections */
172 static void pptp_destroy_siblings(struct nf_conn *ct)
174 struct nf_conn_help *help = nfct_help(ct);
175 struct nf_conntrack_tuple t;
177 nf_ct_gre_keymap_destroy(ct);
179 /* try original (pns->pac) tuple */
180 memcpy(&t, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, sizeof(t));
181 t.dst.protonum = IPPROTO_GRE;
182 t.src.u.gre.key = help->help.ct_pptp_info.pns_call_id;
183 t.dst.u.gre.key = help->help.ct_pptp_info.pac_call_id;
184 if (!destroy_sibling_or_exp(&t))
185 DEBUGP("failed to timeout original pns->pac ct/exp\n");
187 /* try reply (pac->pns) tuple */
188 memcpy(&t, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, sizeof(t));
189 t.dst.protonum = IPPROTO_GRE;
190 t.src.u.gre.key = help->help.ct_pptp_info.pac_call_id;
191 t.dst.u.gre.key = help->help.ct_pptp_info.pns_call_id;
192 if (!destroy_sibling_or_exp(&t))
193 DEBUGP("failed to timeout reply pac->pns ct/exp\n");
196 /* expect GRE connections (PNS->PAC and PAC->PNS direction) */
197 static int exp_gre(struct nf_conn *ct, __be16 callid, __be16 peer_callid)
199 struct nf_conntrack_expect *exp_orig, *exp_reply;
200 enum ip_conntrack_dir dir;
201 int ret = 1;
202 typeof(nf_nat_pptp_hook_exp_gre) nf_nat_pptp_exp_gre;
204 exp_orig = nf_conntrack_expect_alloc(ct);
205 if (exp_orig == NULL)
206 goto out;
208 exp_reply = nf_conntrack_expect_alloc(ct);
209 if (exp_reply == NULL)
210 goto out_put_orig;
212 /* original direction, PNS->PAC */
213 dir = IP_CT_DIR_ORIGINAL;
214 nf_conntrack_expect_init(exp_orig, NF_CT_EXPECT_CLASS_DEFAULT,
215 ct->tuplehash[dir].tuple.src.l3num,
216 &ct->tuplehash[dir].tuple.src.u3,
217 &ct->tuplehash[dir].tuple.dst.u3,
218 IPPROTO_GRE, &peer_callid, &callid);
219 exp_orig->expectfn = pptp_expectfn;
221 /* reply direction, PAC->PNS */
222 dir = IP_CT_DIR_REPLY;
223 nf_conntrack_expect_init(exp_reply, NF_CT_EXPECT_CLASS_DEFAULT,
224 ct->tuplehash[dir].tuple.src.l3num,
225 &ct->tuplehash[dir].tuple.src.u3,
226 &ct->tuplehash[dir].tuple.dst.u3,
227 IPPROTO_GRE, &callid, &peer_callid);
228 exp_reply->expectfn = pptp_expectfn;
230 nf_nat_pptp_exp_gre = rcu_dereference(nf_nat_pptp_hook_exp_gre);
231 if (nf_nat_pptp_exp_gre && ct->status & IPS_NAT_MASK)
232 nf_nat_pptp_exp_gre(exp_orig, exp_reply);
233 if (nf_conntrack_expect_related(exp_orig) != 0)
234 goto out_put_both;
235 if (nf_conntrack_expect_related(exp_reply) != 0)
236 goto out_unexpect_orig;
238 /* Add GRE keymap entries */
239 if (nf_ct_gre_keymap_add(ct, IP_CT_DIR_ORIGINAL, &exp_orig->tuple) != 0)
240 goto out_unexpect_both;
241 if (nf_ct_gre_keymap_add(ct, IP_CT_DIR_REPLY, &exp_reply->tuple) != 0) {
242 nf_ct_gre_keymap_destroy(ct);
243 goto out_unexpect_both;
245 ret = 0;
247 out_put_both:
248 nf_conntrack_expect_put(exp_reply);
249 out_put_orig:
250 nf_conntrack_expect_put(exp_orig);
251 out:
252 return ret;
254 out_unexpect_both:
255 nf_conntrack_unexpect_related(exp_reply);
256 out_unexpect_orig:
257 nf_conntrack_unexpect_related(exp_orig);
258 goto out_put_both;
261 static inline int
262 pptp_inbound_pkt(struct sk_buff *skb,
263 struct PptpControlHeader *ctlh,
264 union pptp_ctrl_union *pptpReq,
265 unsigned int reqlen,
266 struct nf_conn *ct,
267 enum ip_conntrack_info ctinfo)
269 struct nf_ct_pptp_master *info = &nfct_help(ct)->help.ct_pptp_info;
270 u_int16_t msg;
271 __be16 cid = 0, pcid = 0;
272 typeof(nf_nat_pptp_hook_inbound) nf_nat_pptp_inbound;
274 msg = ntohs(ctlh->messageType);
275 DEBUGP("inbound control message %s\n", pptp_msg_name[msg]);
277 switch (msg) {
278 case PPTP_START_SESSION_REPLY:
279 /* server confirms new control session */
280 if (info->sstate < PPTP_SESSION_REQUESTED)
281 goto invalid;
282 if (pptpReq->srep.resultCode == PPTP_START_OK)
283 info->sstate = PPTP_SESSION_CONFIRMED;
284 else
285 info->sstate = PPTP_SESSION_ERROR;
286 break;
288 case PPTP_STOP_SESSION_REPLY:
289 /* server confirms end of control session */
290 if (info->sstate > PPTP_SESSION_STOPREQ)
291 goto invalid;
292 if (pptpReq->strep.resultCode == PPTP_STOP_OK)
293 info->sstate = PPTP_SESSION_NONE;
294 else
295 info->sstate = PPTP_SESSION_ERROR;
296 break;
298 case PPTP_OUT_CALL_REPLY:
299 /* server accepted call, we now expect GRE frames */
300 if (info->sstate != PPTP_SESSION_CONFIRMED)
301 goto invalid;
302 if (info->cstate != PPTP_CALL_OUT_REQ &&
303 info->cstate != PPTP_CALL_OUT_CONF)
304 goto invalid;
306 cid = pptpReq->ocack.callID;
307 pcid = pptpReq->ocack.peersCallID;
308 if (info->pns_call_id != pcid)
309 goto invalid;
310 DEBUGP("%s, CID=%X, PCID=%X\n", pptp_msg_name[msg],
311 ntohs(cid), ntohs(pcid));
313 if (pptpReq->ocack.resultCode == PPTP_OUTCALL_CONNECT) {
314 info->cstate = PPTP_CALL_OUT_CONF;
315 info->pac_call_id = cid;
316 exp_gre(ct, cid, pcid);
317 } else
318 info->cstate = PPTP_CALL_NONE;
319 break;
321 case PPTP_IN_CALL_REQUEST:
322 /* server tells us about incoming call request */
323 if (info->sstate != PPTP_SESSION_CONFIRMED)
324 goto invalid;
326 cid = pptpReq->icreq.callID;
327 DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));
328 info->cstate = PPTP_CALL_IN_REQ;
329 info->pac_call_id = cid;
330 break;
332 case PPTP_IN_CALL_CONNECT:
333 /* server tells us about incoming call established */
334 if (info->sstate != PPTP_SESSION_CONFIRMED)
335 goto invalid;
336 if (info->cstate != PPTP_CALL_IN_REP &&
337 info->cstate != PPTP_CALL_IN_CONF)
338 goto invalid;
340 pcid = pptpReq->iccon.peersCallID;
341 cid = info->pac_call_id;
343 if (info->pns_call_id != pcid)
344 goto invalid;
346 DEBUGP("%s, PCID=%X\n", pptp_msg_name[msg], ntohs(pcid));
347 info->cstate = PPTP_CALL_IN_CONF;
349 /* we expect a GRE connection from PAC to PNS */
350 exp_gre(ct, cid, pcid);
351 break;
353 case PPTP_CALL_DISCONNECT_NOTIFY:
354 /* server confirms disconnect */
355 cid = pptpReq->disc.callID;
356 DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));
357 info->cstate = PPTP_CALL_NONE;
359 /* untrack this call id, unexpect GRE packets */
360 pptp_destroy_siblings(ct);
361 break;
363 case PPTP_WAN_ERROR_NOTIFY:
364 case PPTP_ECHO_REQUEST:
365 case PPTP_ECHO_REPLY:
366 /* I don't have to explain these ;) */
367 break;
369 default:
370 goto invalid;
373 nf_nat_pptp_inbound = rcu_dereference(nf_nat_pptp_hook_inbound);
374 if (nf_nat_pptp_inbound && ct->status & IPS_NAT_MASK)
375 return nf_nat_pptp_inbound(skb, ct, ctinfo, ctlh, pptpReq);
376 return NF_ACCEPT;
378 invalid:
379 DEBUGP("invalid %s: type=%d cid=%u pcid=%u "
380 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
381 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0],
382 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,
383 ntohs(info->pns_call_id), ntohs(info->pac_call_id));
384 return NF_ACCEPT;
387 static inline int
388 pptp_outbound_pkt(struct sk_buff *skb,
389 struct PptpControlHeader *ctlh,
390 union pptp_ctrl_union *pptpReq,
391 unsigned int reqlen,
392 struct nf_conn *ct,
393 enum ip_conntrack_info ctinfo)
395 struct nf_ct_pptp_master *info = &nfct_help(ct)->help.ct_pptp_info;
396 u_int16_t msg;
397 __be16 cid = 0, pcid = 0;
398 typeof(nf_nat_pptp_hook_outbound) nf_nat_pptp_outbound;
400 msg = ntohs(ctlh->messageType);
401 DEBUGP("outbound control message %s\n", pptp_msg_name[msg]);
403 switch (msg) {
404 case PPTP_START_SESSION_REQUEST:
405 /* client requests for new control session */
406 if (info->sstate != PPTP_SESSION_NONE)
407 goto invalid;
408 info->sstate = PPTP_SESSION_REQUESTED;
409 break;
411 case PPTP_STOP_SESSION_REQUEST:
412 /* client requests end of control session */
413 info->sstate = PPTP_SESSION_STOPREQ;
414 break;
416 case PPTP_OUT_CALL_REQUEST:
417 /* client initiating connection to server */
418 if (info->sstate != PPTP_SESSION_CONFIRMED)
419 goto invalid;
420 info->cstate = PPTP_CALL_OUT_REQ;
421 /* track PNS call id */
422 cid = pptpReq->ocreq.callID;
423 DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));
424 info->pns_call_id = cid;
425 break;
427 case PPTP_IN_CALL_REPLY:
428 /* client answers incoming call */
429 if (info->cstate != PPTP_CALL_IN_REQ &&
430 info->cstate != PPTP_CALL_IN_REP)
431 goto invalid;
433 cid = pptpReq->icack.callID;
434 pcid = pptpReq->icack.peersCallID;
435 if (info->pac_call_id != pcid)
436 goto invalid;
437 DEBUGP("%s, CID=%X PCID=%X\n", pptp_msg_name[msg],
438 ntohs(cid), ntohs(pcid));
440 if (pptpReq->icack.resultCode == PPTP_INCALL_ACCEPT) {
441 /* part two of the three-way handshake */
442 info->cstate = PPTP_CALL_IN_REP;
443 info->pns_call_id = cid;
444 } else
445 info->cstate = PPTP_CALL_NONE;
446 break;
448 case PPTP_CALL_CLEAR_REQUEST:
449 /* client requests hangup of call */
450 if (info->sstate != PPTP_SESSION_CONFIRMED)
451 goto invalid;
452 /* FUTURE: iterate over all calls and check if
453 * call ID is valid. We don't do this without newnat,
454 * because we only know about last call */
455 info->cstate = PPTP_CALL_CLEAR_REQ;
456 break;
458 case PPTP_SET_LINK_INFO:
459 case PPTP_ECHO_REQUEST:
460 case PPTP_ECHO_REPLY:
461 /* I don't have to explain these ;) */
462 break;
464 default:
465 goto invalid;
468 nf_nat_pptp_outbound = rcu_dereference(nf_nat_pptp_hook_outbound);
469 if (nf_nat_pptp_outbound && ct->status & IPS_NAT_MASK)
470 return nf_nat_pptp_outbound(skb, ct, ctinfo, ctlh, pptpReq);
471 return NF_ACCEPT;
473 invalid:
474 DEBUGP("invalid %s: type=%d cid=%u pcid=%u "
475 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
476 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0],
477 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,
478 ntohs(info->pns_call_id), ntohs(info->pac_call_id));
479 return NF_ACCEPT;
482 static const unsigned int pptp_msg_size[] = {
483 [PPTP_START_SESSION_REQUEST] = sizeof(struct PptpStartSessionRequest),
484 [PPTP_START_SESSION_REPLY] = sizeof(struct PptpStartSessionReply),
485 [PPTP_STOP_SESSION_REQUEST] = sizeof(struct PptpStopSessionRequest),
486 [PPTP_STOP_SESSION_REPLY] = sizeof(struct PptpStopSessionReply),
487 [PPTP_OUT_CALL_REQUEST] = sizeof(struct PptpOutCallRequest),
488 [PPTP_OUT_CALL_REPLY] = sizeof(struct PptpOutCallReply),
489 [PPTP_IN_CALL_REQUEST] = sizeof(struct PptpInCallRequest),
490 [PPTP_IN_CALL_REPLY] = sizeof(struct PptpInCallReply),
491 [PPTP_IN_CALL_CONNECT] = sizeof(struct PptpInCallConnected),
492 [PPTP_CALL_CLEAR_REQUEST] = sizeof(struct PptpClearCallRequest),
493 [PPTP_CALL_DISCONNECT_NOTIFY] = sizeof(struct PptpCallDisconnectNotify),
494 [PPTP_WAN_ERROR_NOTIFY] = sizeof(struct PptpWanErrorNotify),
495 [PPTP_SET_LINK_INFO] = sizeof(struct PptpSetLinkInfo),
498 /* track caller id inside control connection, call expect_related */
499 static int
500 conntrack_pptp_help(struct sk_buff *skb, unsigned int protoff,
501 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
504 int dir = CTINFO2DIR(ctinfo);
505 struct nf_ct_pptp_master *info = &nfct_help(ct)->help.ct_pptp_info;
506 struct tcphdr _tcph, *tcph;
507 struct pptp_pkt_hdr _pptph, *pptph;
508 struct PptpControlHeader _ctlh, *ctlh;
509 union pptp_ctrl_union _pptpReq, *pptpReq;
510 unsigned int tcplen = skb->len - protoff;
511 unsigned int datalen, reqlen, nexthdr_off;
512 int oldsstate, oldcstate;
513 int ret;
514 u_int16_t msg;
516 /* don't do any tracking before tcp handshake complete */
517 if (ctinfo != IP_CT_ESTABLISHED &&
518 ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY)
519 return NF_ACCEPT;
521 nexthdr_off = protoff;
522 tcph = skb_header_pointer(skb, nexthdr_off, sizeof(_tcph), &_tcph);
523 BUG_ON(!tcph);
524 nexthdr_off += tcph->doff * 4;
525 datalen = tcplen - tcph->doff * 4;
527 pptph = skb_header_pointer(skb, nexthdr_off, sizeof(_pptph), &_pptph);
528 if (!pptph) {
529 DEBUGP("no full PPTP header, can't track\n");
530 return NF_ACCEPT;
532 nexthdr_off += sizeof(_pptph);
533 datalen -= sizeof(_pptph);
535 /* if it's not a control message we can't do anything with it */
536 if (ntohs(pptph->packetType) != PPTP_PACKET_CONTROL ||
537 ntohl(pptph->magicCookie) != PPTP_MAGIC_COOKIE) {
538 DEBUGP("not a control packet\n");
539 return NF_ACCEPT;
542 ctlh = skb_header_pointer(skb, nexthdr_off, sizeof(_ctlh), &_ctlh);
543 if (!ctlh)
544 return NF_ACCEPT;
545 nexthdr_off += sizeof(_ctlh);
546 datalen -= sizeof(_ctlh);
548 reqlen = datalen;
549 msg = ntohs(ctlh->messageType);
550 if (msg > 0 && msg <= PPTP_MSG_MAX && reqlen < pptp_msg_size[msg])
551 return NF_ACCEPT;
552 if (reqlen > sizeof(*pptpReq))
553 reqlen = sizeof(*pptpReq);
555 pptpReq = skb_header_pointer(skb, nexthdr_off, reqlen, &_pptpReq);
556 if (!pptpReq)
557 return NF_ACCEPT;
559 oldsstate = info->sstate;
560 oldcstate = info->cstate;
562 spin_lock_bh(&nf_pptp_lock);
564 /* FIXME: We just blindly assume that the control connection is always
565 * established from PNS->PAC. However, RFC makes no guarantee */
566 if (dir == IP_CT_DIR_ORIGINAL)
567 /* client -> server (PNS -> PAC) */
568 ret = pptp_outbound_pkt(skb, ctlh, pptpReq, reqlen, ct,
569 ctinfo);
570 else
571 /* server -> client (PAC -> PNS) */
572 ret = pptp_inbound_pkt(skb, ctlh, pptpReq, reqlen, ct,
573 ctinfo);
574 DEBUGP("sstate: %d->%d, cstate: %d->%d\n",
575 oldsstate, info->sstate, oldcstate, info->cstate);
576 spin_unlock_bh(&nf_pptp_lock);
578 return ret;
581 static const struct nf_conntrack_expect_policy pptp_exp_policy = {
582 .max_expected = 2,
583 .timeout = 5 * 60,
586 /* control protocol helper */
587 static struct nf_conntrack_helper pptp __read_mostly = {
588 .name = "pptp",
589 .me = THIS_MODULE,
590 .tuple.src.l3num = AF_INET,
591 .tuple.src.u.tcp.port = __constant_htons(PPTP_CONTROL_PORT),
592 .tuple.dst.protonum = IPPROTO_TCP,
593 .mask.src.l3num = 0xffff,
594 .mask.src.u.tcp.port = __constant_htons(0xffff),
595 .mask.dst.protonum = 0xff,
596 .help = conntrack_pptp_help,
597 .destroy = pptp_destroy_siblings,
598 .expect_policy = &pptp_exp_policy,
601 static int __init nf_conntrack_pptp_init(void)
603 return nf_conntrack_helper_register(&pptp);
606 static void __exit nf_conntrack_pptp_fini(void)
608 nf_conntrack_helper_unregister(&pptp);
609 nf_ct_gre_keymap_flush();
612 module_init(nf_conntrack_pptp_init);
613 module_exit(nf_conntrack_pptp_fini);