1 // SPDX-License-Identifier: GPL-2.0-only
3 * Connection tracking support for PPTP (Point to Point Tunneling Protocol).
4 * PPTP is a protocol for creating virtual private networks.
5 * It is a specification defined by Microsoft and some vendors
6 * working with Microsoft. PPTP is built on top of a modified
7 * version of the Internet Generic Routing Encapsulation Protocol.
8 * GRE is defined in RFC 1701 and RFC 1702. Documentation of
9 * PPTP can be found in RFC 2637
11 * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org>
13 * Development of this code funded by Astaro AG (http://www.astaro.com/)
15 * (C) 2006-2012 Patrick McHardy <kaber@trash.net>
18 * - We blindly assume that control connections are always
19 * established in PNS->PAC direction. This is a violation
21 * - We can only support one single call within each session
23 * - testing of incoming PPTP calls
26 #include <linux/module.h>
27 #include <linux/skbuff.h>
29 #include <linux/tcp.h>
31 #include <net/netfilter/nf_conntrack.h>
32 #include <net/netfilter/nf_conntrack_core.h>
33 #include <net/netfilter/nf_conntrack_helper.h>
34 #include <net/netfilter/nf_conntrack_zones.h>
35 #include <linux/netfilter/nf_conntrack_proto_gre.h>
36 #include <linux/netfilter/nf_conntrack_pptp.h>
38 #define NF_CT_PPTP_VERSION "3.1"
40 MODULE_LICENSE("GPL");
41 MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
42 MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP");
43 MODULE_ALIAS("ip_conntrack_pptp");
44 MODULE_ALIAS_NFCT_HELPER("pptp");
46 static DEFINE_SPINLOCK(nf_pptp_lock
);
49 (*nf_nat_pptp_hook_outbound
)(struct sk_buff
*skb
,
50 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
,
51 unsigned int protoff
, struct PptpControlHeader
*ctlh
,
52 union pptp_ctrl_union
*pptpReq
) __read_mostly
;
53 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_outbound
);
56 (*nf_nat_pptp_hook_inbound
)(struct sk_buff
*skb
,
57 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
,
58 unsigned int protoff
, struct PptpControlHeader
*ctlh
,
59 union pptp_ctrl_union
*pptpReq
) __read_mostly
;
60 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_inbound
);
63 (*nf_nat_pptp_hook_exp_gre
)(struct nf_conntrack_expect
*expect_orig
,
64 struct nf_conntrack_expect
*expect_reply
)
66 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_exp_gre
);
69 (*nf_nat_pptp_hook_expectfn
)(struct nf_conn
*ct
,
70 struct nf_conntrack_expect
*exp
) __read_mostly
;
71 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn
);
73 #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
74 /* PptpControlMessageType names */
75 static const char *const pptp_msg_name_array
[PPTP_MSG_MAX
+ 1] = {
76 [0] = "UNKNOWN_MESSAGE",
77 [PPTP_START_SESSION_REQUEST
] = "START_SESSION_REQUEST",
78 [PPTP_START_SESSION_REPLY
] = "START_SESSION_REPLY",
79 [PPTP_STOP_SESSION_REQUEST
] = "STOP_SESSION_REQUEST",
80 [PPTP_STOP_SESSION_REPLY
] = "STOP_SESSION_REPLY",
81 [PPTP_ECHO_REQUEST
] = "ECHO_REQUEST",
82 [PPTP_ECHO_REPLY
] = "ECHO_REPLY",
83 [PPTP_OUT_CALL_REQUEST
] = "OUT_CALL_REQUEST",
84 [PPTP_OUT_CALL_REPLY
] = "OUT_CALL_REPLY",
85 [PPTP_IN_CALL_REQUEST
] = "IN_CALL_REQUEST",
86 [PPTP_IN_CALL_REPLY
] = "IN_CALL_REPLY",
87 [PPTP_IN_CALL_CONNECT
] = "IN_CALL_CONNECT",
88 [PPTP_CALL_CLEAR_REQUEST
] = "CALL_CLEAR_REQUEST",
89 [PPTP_CALL_DISCONNECT_NOTIFY
] = "CALL_DISCONNECT_NOTIFY",
90 [PPTP_WAN_ERROR_NOTIFY
] = "WAN_ERROR_NOTIFY",
91 [PPTP_SET_LINK_INFO
] = "SET_LINK_INFO"
94 const char *pptp_msg_name(u_int16_t msg
)
96 if (msg
> PPTP_MSG_MAX
)
97 return pptp_msg_name_array
[0];
99 return pptp_msg_name_array
[msg
];
101 EXPORT_SYMBOL(pptp_msg_name
);
105 #define MINS * 60 SECS
106 #define HOURS * 60 MINS
108 #define PPTP_GRE_TIMEOUT (10 MINS)
109 #define PPTP_GRE_STREAM_TIMEOUT (5 HOURS)
111 static void pptp_expectfn(struct nf_conn
*ct
,
112 struct nf_conntrack_expect
*exp
)
114 struct net
*net
= nf_ct_net(ct
);
115 typeof(nf_nat_pptp_hook_expectfn
) nf_nat_pptp_expectfn
;
116 pr_debug("increasing timeouts\n");
118 /* increase timeout of GRE data channel conntrack entry */
119 ct
->proto
.gre
.timeout
= PPTP_GRE_TIMEOUT
;
120 ct
->proto
.gre
.stream_timeout
= PPTP_GRE_STREAM_TIMEOUT
;
122 /* Can you see how rusty this code is, compared with the pre-2.6.11
123 * one? That's what happened to my shiny newnat of 2002 ;( -HW */
125 nf_nat_pptp_expectfn
= rcu_dereference(nf_nat_pptp_hook_expectfn
);
126 if (nf_nat_pptp_expectfn
&& ct
->master
->status
& IPS_NAT_MASK
)
127 nf_nat_pptp_expectfn(ct
, exp
);
129 struct nf_conntrack_tuple inv_t
;
130 struct nf_conntrack_expect
*exp_other
;
132 /* obviously this tuple inversion only works until you do NAT */
133 nf_ct_invert_tuple(&inv_t
, &exp
->tuple
);
134 pr_debug("trying to unexpect other dir: ");
135 nf_ct_dump_tuple(&inv_t
);
137 exp_other
= nf_ct_expect_find_get(net
, nf_ct_zone(ct
), &inv_t
);
139 /* delete other expectation. */
141 nf_ct_unexpect_related(exp_other
);
142 nf_ct_expect_put(exp_other
);
144 pr_debug("not found\n");
149 static int destroy_sibling_or_exp(struct net
*net
, struct nf_conn
*ct
,
150 const struct nf_conntrack_tuple
*t
)
152 const struct nf_conntrack_tuple_hash
*h
;
153 const struct nf_conntrack_zone
*zone
;
154 struct nf_conntrack_expect
*exp
;
155 struct nf_conn
*sibling
;
157 pr_debug("trying to timeout ct or exp for tuple ");
160 zone
= nf_ct_zone(ct
);
161 h
= nf_conntrack_find_get(net
, zone
, t
);
163 sibling
= nf_ct_tuplehash_to_ctrack(h
);
164 pr_debug("setting timeout of conntrack %p to 0\n", sibling
);
165 sibling
->proto
.gre
.timeout
= 0;
166 sibling
->proto
.gre
.stream_timeout
= 0;
171 exp
= nf_ct_expect_find_get(net
, zone
, t
);
173 pr_debug("unexpect_related of expect %p\n", exp
);
174 nf_ct_unexpect_related(exp
);
175 nf_ct_expect_put(exp
);
182 /* timeout GRE data connections */
183 static void pptp_destroy_siblings(struct nf_conn
*ct
)
185 struct net
*net
= nf_ct_net(ct
);
186 const struct nf_ct_pptp_master
*ct_pptp_info
= nfct_help_data(ct
);
187 struct nf_conntrack_tuple t
;
189 nf_ct_gre_keymap_destroy(ct
);
191 /* try original (pns->pac) tuple */
192 memcpy(&t
, &ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
, sizeof(t
));
193 t
.dst
.protonum
= IPPROTO_GRE
;
194 t
.src
.u
.gre
.key
= ct_pptp_info
->pns_call_id
;
195 t
.dst
.u
.gre
.key
= ct_pptp_info
->pac_call_id
;
196 if (!destroy_sibling_or_exp(net
, ct
, &t
))
197 pr_debug("failed to timeout original pns->pac ct/exp\n");
199 /* try reply (pac->pns) tuple */
200 memcpy(&t
, &ct
->tuplehash
[IP_CT_DIR_REPLY
].tuple
, sizeof(t
));
201 t
.dst
.protonum
= IPPROTO_GRE
;
202 t
.src
.u
.gre
.key
= ct_pptp_info
->pac_call_id
;
203 t
.dst
.u
.gre
.key
= ct_pptp_info
->pns_call_id
;
204 if (!destroy_sibling_or_exp(net
, ct
, &t
))
205 pr_debug("failed to timeout reply pac->pns ct/exp\n");
208 /* expect GRE connections (PNS->PAC and PAC->PNS direction) */
209 static int exp_gre(struct nf_conn
*ct
, __be16 callid
, __be16 peer_callid
)
211 struct nf_conntrack_expect
*exp_orig
, *exp_reply
;
212 enum ip_conntrack_dir dir
;
214 typeof(nf_nat_pptp_hook_exp_gre
) nf_nat_pptp_exp_gre
;
216 exp_orig
= nf_ct_expect_alloc(ct
);
217 if (exp_orig
== NULL
)
220 exp_reply
= nf_ct_expect_alloc(ct
);
221 if (exp_reply
== NULL
)
224 /* original direction, PNS->PAC */
225 dir
= IP_CT_DIR_ORIGINAL
;
226 nf_ct_expect_init(exp_orig
, NF_CT_EXPECT_CLASS_DEFAULT
,
228 &ct
->tuplehash
[dir
].tuple
.src
.u3
,
229 &ct
->tuplehash
[dir
].tuple
.dst
.u3
,
230 IPPROTO_GRE
, &peer_callid
, &callid
);
231 exp_orig
->expectfn
= pptp_expectfn
;
233 /* reply direction, PAC->PNS */
234 dir
= IP_CT_DIR_REPLY
;
235 nf_ct_expect_init(exp_reply
, NF_CT_EXPECT_CLASS_DEFAULT
,
237 &ct
->tuplehash
[dir
].tuple
.src
.u3
,
238 &ct
->tuplehash
[dir
].tuple
.dst
.u3
,
239 IPPROTO_GRE
, &callid
, &peer_callid
);
240 exp_reply
->expectfn
= pptp_expectfn
;
242 nf_nat_pptp_exp_gre
= rcu_dereference(nf_nat_pptp_hook_exp_gre
);
243 if (nf_nat_pptp_exp_gre
&& ct
->status
& IPS_NAT_MASK
)
244 nf_nat_pptp_exp_gre(exp_orig
, exp_reply
);
245 if (nf_ct_expect_related(exp_orig
, 0) != 0)
247 if (nf_ct_expect_related(exp_reply
, 0) != 0)
248 goto out_unexpect_orig
;
250 /* Add GRE keymap entries */
251 if (nf_ct_gre_keymap_add(ct
, IP_CT_DIR_ORIGINAL
, &exp_orig
->tuple
) != 0)
252 goto out_unexpect_both
;
253 if (nf_ct_gre_keymap_add(ct
, IP_CT_DIR_REPLY
, &exp_reply
->tuple
) != 0) {
254 nf_ct_gre_keymap_destroy(ct
);
255 goto out_unexpect_both
;
260 nf_ct_expect_put(exp_reply
);
262 nf_ct_expect_put(exp_orig
);
267 nf_ct_unexpect_related(exp_reply
);
269 nf_ct_unexpect_related(exp_orig
);
274 pptp_inbound_pkt(struct sk_buff
*skb
, unsigned int protoff
,
275 struct PptpControlHeader
*ctlh
,
276 union pptp_ctrl_union
*pptpReq
,
279 enum ip_conntrack_info ctinfo
)
281 struct nf_ct_pptp_master
*info
= nfct_help_data(ct
);
283 __be16 cid
= 0, pcid
= 0;
284 typeof(nf_nat_pptp_hook_inbound
) nf_nat_pptp_inbound
;
286 msg
= ntohs(ctlh
->messageType
);
287 pr_debug("inbound control message %s\n", pptp_msg_name(msg
));
290 case PPTP_START_SESSION_REPLY
:
291 /* server confirms new control session */
292 if (info
->sstate
< PPTP_SESSION_REQUESTED
)
294 if (pptpReq
->srep
.resultCode
== PPTP_START_OK
)
295 info
->sstate
= PPTP_SESSION_CONFIRMED
;
297 info
->sstate
= PPTP_SESSION_ERROR
;
300 case PPTP_STOP_SESSION_REPLY
:
301 /* server confirms end of control session */
302 if (info
->sstate
> PPTP_SESSION_STOPREQ
)
304 if (pptpReq
->strep
.resultCode
== PPTP_STOP_OK
)
305 info
->sstate
= PPTP_SESSION_NONE
;
307 info
->sstate
= PPTP_SESSION_ERROR
;
310 case PPTP_OUT_CALL_REPLY
:
311 /* server accepted call, we now expect GRE frames */
312 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
)
314 if (info
->cstate
!= PPTP_CALL_OUT_REQ
&&
315 info
->cstate
!= PPTP_CALL_OUT_CONF
)
318 cid
= pptpReq
->ocack
.callID
;
319 pcid
= pptpReq
->ocack
.peersCallID
;
320 if (info
->pns_call_id
!= pcid
)
322 pr_debug("%s, CID=%X, PCID=%X\n", pptp_msg_name(msg
),
323 ntohs(cid
), ntohs(pcid
));
325 if (pptpReq
->ocack
.resultCode
== PPTP_OUTCALL_CONNECT
) {
326 info
->cstate
= PPTP_CALL_OUT_CONF
;
327 info
->pac_call_id
= cid
;
328 exp_gre(ct
, cid
, pcid
);
330 info
->cstate
= PPTP_CALL_NONE
;
333 case PPTP_IN_CALL_REQUEST
:
334 /* server tells us about incoming call request */
335 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
)
338 cid
= pptpReq
->icreq
.callID
;
339 pr_debug("%s, CID=%X\n", pptp_msg_name(msg
), ntohs(cid
));
340 info
->cstate
= PPTP_CALL_IN_REQ
;
341 info
->pac_call_id
= cid
;
344 case PPTP_IN_CALL_CONNECT
:
345 /* server tells us about incoming call established */
346 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
)
348 if (info
->cstate
!= PPTP_CALL_IN_REP
&&
349 info
->cstate
!= PPTP_CALL_IN_CONF
)
352 pcid
= pptpReq
->iccon
.peersCallID
;
353 cid
= info
->pac_call_id
;
355 if (info
->pns_call_id
!= pcid
)
358 pr_debug("%s, PCID=%X\n", pptp_msg_name(msg
), ntohs(pcid
));
359 info
->cstate
= PPTP_CALL_IN_CONF
;
361 /* we expect a GRE connection from PAC to PNS */
362 exp_gre(ct
, cid
, pcid
);
365 case PPTP_CALL_DISCONNECT_NOTIFY
:
366 /* server confirms disconnect */
367 cid
= pptpReq
->disc
.callID
;
368 pr_debug("%s, CID=%X\n", pptp_msg_name(msg
), ntohs(cid
));
369 info
->cstate
= PPTP_CALL_NONE
;
371 /* untrack this call id, unexpect GRE packets */
372 pptp_destroy_siblings(ct
);
375 case PPTP_WAN_ERROR_NOTIFY
:
376 case PPTP_SET_LINK_INFO
:
377 case PPTP_ECHO_REQUEST
:
378 case PPTP_ECHO_REPLY
:
379 /* I don't have to explain these ;) */
386 nf_nat_pptp_inbound
= rcu_dereference(nf_nat_pptp_hook_inbound
);
387 if (nf_nat_pptp_inbound
&& ct
->status
& IPS_NAT_MASK
)
388 return nf_nat_pptp_inbound(skb
, ct
, ctinfo
,
389 protoff
, ctlh
, pptpReq
);
393 pr_debug("invalid %s: type=%d cid=%u pcid=%u "
394 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
396 msg
, ntohs(cid
), ntohs(pcid
), info
->cstate
, info
->sstate
,
397 ntohs(info
->pns_call_id
), ntohs(info
->pac_call_id
));
402 pptp_outbound_pkt(struct sk_buff
*skb
, unsigned int protoff
,
403 struct PptpControlHeader
*ctlh
,
404 union pptp_ctrl_union
*pptpReq
,
407 enum ip_conntrack_info ctinfo
)
409 struct nf_ct_pptp_master
*info
= nfct_help_data(ct
);
411 __be16 cid
= 0, pcid
= 0;
412 typeof(nf_nat_pptp_hook_outbound
) nf_nat_pptp_outbound
;
414 msg
= ntohs(ctlh
->messageType
);
415 pr_debug("outbound control message %s\n", pptp_msg_name(msg
));
418 case PPTP_START_SESSION_REQUEST
:
419 /* client requests for new control session */
420 if (info
->sstate
!= PPTP_SESSION_NONE
)
422 info
->sstate
= PPTP_SESSION_REQUESTED
;
425 case PPTP_STOP_SESSION_REQUEST
:
426 /* client requests end of control session */
427 info
->sstate
= PPTP_SESSION_STOPREQ
;
430 case PPTP_OUT_CALL_REQUEST
:
431 /* client initiating connection to server */
432 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
)
434 info
->cstate
= PPTP_CALL_OUT_REQ
;
435 /* track PNS call id */
436 cid
= pptpReq
->ocreq
.callID
;
437 pr_debug("%s, CID=%X\n", pptp_msg_name(msg
), ntohs(cid
));
438 info
->pns_call_id
= cid
;
441 case PPTP_IN_CALL_REPLY
:
442 /* client answers incoming call */
443 if (info
->cstate
!= PPTP_CALL_IN_REQ
&&
444 info
->cstate
!= PPTP_CALL_IN_REP
)
447 cid
= pptpReq
->icack
.callID
;
448 pcid
= pptpReq
->icack
.peersCallID
;
449 if (info
->pac_call_id
!= pcid
)
451 pr_debug("%s, CID=%X PCID=%X\n", pptp_msg_name(msg
),
452 ntohs(cid
), ntohs(pcid
));
454 if (pptpReq
->icack
.resultCode
== PPTP_INCALL_ACCEPT
) {
455 /* part two of the three-way handshake */
456 info
->cstate
= PPTP_CALL_IN_REP
;
457 info
->pns_call_id
= cid
;
459 info
->cstate
= PPTP_CALL_NONE
;
462 case PPTP_CALL_CLEAR_REQUEST
:
463 /* client requests hangup of call */
464 if (info
->sstate
!= PPTP_SESSION_CONFIRMED
)
466 /* FUTURE: iterate over all calls and check if
467 * call ID is valid. We don't do this without newnat,
468 * because we only know about last call */
469 info
->cstate
= PPTP_CALL_CLEAR_REQ
;
472 case PPTP_SET_LINK_INFO
:
473 case PPTP_ECHO_REQUEST
:
474 case PPTP_ECHO_REPLY
:
475 /* I don't have to explain these ;) */
482 nf_nat_pptp_outbound
= rcu_dereference(nf_nat_pptp_hook_outbound
);
483 if (nf_nat_pptp_outbound
&& ct
->status
& IPS_NAT_MASK
)
484 return nf_nat_pptp_outbound(skb
, ct
, ctinfo
,
485 protoff
, ctlh
, pptpReq
);
489 pr_debug("invalid %s: type=%d cid=%u pcid=%u "
490 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
492 msg
, ntohs(cid
), ntohs(pcid
), info
->cstate
, info
->sstate
,
493 ntohs(info
->pns_call_id
), ntohs(info
->pac_call_id
));
497 static const unsigned int pptp_msg_size
[] = {
498 [PPTP_START_SESSION_REQUEST
] = sizeof(struct PptpStartSessionRequest
),
499 [PPTP_START_SESSION_REPLY
] = sizeof(struct PptpStartSessionReply
),
500 [PPTP_STOP_SESSION_REQUEST
] = sizeof(struct PptpStopSessionRequest
),
501 [PPTP_STOP_SESSION_REPLY
] = sizeof(struct PptpStopSessionReply
),
502 [PPTP_OUT_CALL_REQUEST
] = sizeof(struct PptpOutCallRequest
),
503 [PPTP_OUT_CALL_REPLY
] = sizeof(struct PptpOutCallReply
),
504 [PPTP_IN_CALL_REQUEST
] = sizeof(struct PptpInCallRequest
),
505 [PPTP_IN_CALL_REPLY
] = sizeof(struct PptpInCallReply
),
506 [PPTP_IN_CALL_CONNECT
] = sizeof(struct PptpInCallConnected
),
507 [PPTP_CALL_CLEAR_REQUEST
] = sizeof(struct PptpClearCallRequest
),
508 [PPTP_CALL_DISCONNECT_NOTIFY
] = sizeof(struct PptpCallDisconnectNotify
),
509 [PPTP_WAN_ERROR_NOTIFY
] = sizeof(struct PptpWanErrorNotify
),
510 [PPTP_SET_LINK_INFO
] = sizeof(struct PptpSetLinkInfo
),
513 /* track caller id inside control connection, call expect_related */
515 conntrack_pptp_help(struct sk_buff
*skb
, unsigned int protoff
,
516 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
519 int dir
= CTINFO2DIR(ctinfo
);
520 const struct nf_ct_pptp_master
*info
= nfct_help_data(ct
);
521 const struct tcphdr
*tcph
;
523 const struct pptp_pkt_hdr
*pptph
;
524 struct pptp_pkt_hdr _pptph
;
525 struct PptpControlHeader _ctlh
, *ctlh
;
526 union pptp_ctrl_union _pptpReq
, *pptpReq
;
527 unsigned int tcplen
= skb
->len
- protoff
;
528 unsigned int datalen
, reqlen
, nexthdr_off
;
529 int oldsstate
, oldcstate
;
533 #if IS_ENABLED(CONFIG_NF_NAT)
534 if (!nf_ct_is_confirmed(ct
) && (ct
->status
& IPS_NAT_MASK
)) {
535 struct nf_conn_nat
*nat
= nf_ct_ext_find(ct
, NF_CT_EXT_NAT
);
537 if (!nat
&& !nf_ct_ext_add(ct
, NF_CT_EXT_NAT
, GFP_ATOMIC
))
541 /* don't do any tracking before tcp handshake complete */
542 if (ctinfo
!= IP_CT_ESTABLISHED
&& ctinfo
!= IP_CT_ESTABLISHED_REPLY
)
545 nexthdr_off
= protoff
;
546 tcph
= skb_header_pointer(skb
, nexthdr_off
, sizeof(_tcph
), &_tcph
);
548 nexthdr_off
+= tcph
->doff
* 4;
549 datalen
= tcplen
- tcph
->doff
* 4;
551 pptph
= skb_header_pointer(skb
, nexthdr_off
, sizeof(_pptph
), &_pptph
);
553 pr_debug("no full PPTP header, can't track\n");
556 nexthdr_off
+= sizeof(_pptph
);
557 datalen
-= sizeof(_pptph
);
559 /* if it's not a control message we can't do anything with it */
560 if (ntohs(pptph
->packetType
) != PPTP_PACKET_CONTROL
||
561 ntohl(pptph
->magicCookie
) != PPTP_MAGIC_COOKIE
) {
562 pr_debug("not a control packet\n");
566 ctlh
= skb_header_pointer(skb
, nexthdr_off
, sizeof(_ctlh
), &_ctlh
);
569 nexthdr_off
+= sizeof(_ctlh
);
570 datalen
-= sizeof(_ctlh
);
573 msg
= ntohs(ctlh
->messageType
);
574 if (msg
> 0 && msg
<= PPTP_MSG_MAX
&& reqlen
< pptp_msg_size
[msg
])
576 if (reqlen
> sizeof(*pptpReq
))
577 reqlen
= sizeof(*pptpReq
);
579 pptpReq
= skb_header_pointer(skb
, nexthdr_off
, reqlen
, &_pptpReq
);
583 oldsstate
= info
->sstate
;
584 oldcstate
= info
->cstate
;
586 spin_lock_bh(&nf_pptp_lock
);
588 /* FIXME: We just blindly assume that the control connection is always
589 * established from PNS->PAC. However, RFC makes no guarantee */
590 if (dir
== IP_CT_DIR_ORIGINAL
)
591 /* client -> server (PNS -> PAC) */
592 ret
= pptp_outbound_pkt(skb
, protoff
, ctlh
, pptpReq
, reqlen
, ct
,
595 /* server -> client (PAC -> PNS) */
596 ret
= pptp_inbound_pkt(skb
, protoff
, ctlh
, pptpReq
, reqlen
, ct
,
598 pr_debug("sstate: %d->%d, cstate: %d->%d\n",
599 oldsstate
, info
->sstate
, oldcstate
, info
->cstate
);
600 spin_unlock_bh(&nf_pptp_lock
);
605 static const struct nf_conntrack_expect_policy pptp_exp_policy
= {
610 /* control protocol helper */
611 static struct nf_conntrack_helper pptp __read_mostly
= {
614 .tuple
.src
.l3num
= AF_INET
,
615 .tuple
.src
.u
.tcp
.port
= cpu_to_be16(PPTP_CONTROL_PORT
),
616 .tuple
.dst
.protonum
= IPPROTO_TCP
,
617 .help
= conntrack_pptp_help
,
618 .destroy
= pptp_destroy_siblings
,
619 .expect_policy
= &pptp_exp_policy
,
622 static int __init
nf_conntrack_pptp_init(void)
624 NF_CT_HELPER_BUILD_BUG_ON(sizeof(struct nf_ct_pptp_master
));
626 return nf_conntrack_helper_register(&pptp
);
629 static void __exit
nf_conntrack_pptp_fini(void)
631 nf_conntrack_helper_unregister(&pptp
);
634 module_init(nf_conntrack_pptp_init
);
635 module_exit(nf_conntrack_pptp_fini
);