Skip to content

Commit 2fe7c32

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: pptp: attach nat extension when needed
make sure nat extension gets added if the master conntrack is subject to NAT. This will be required once the nat core stops adding it by default. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent ff45901 commit 2fe7c32

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎net/ipv4/netfilter/nf_nat_pptp.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ static void pptp_nat_expected(struct nf_conn *ct,
4949
const struct nf_ct_pptp_master *ct_pptp_info;
5050
const struct nf_nat_pptp *nat_pptp_info;
5151
struct nf_nat_range range;
52+
struct nf_conn_nat *nat;
5253

54+
nat = nf_ct_nat_ext_add(ct);
55+
if (WARN_ON_ONCE(!nat))
56+
return;
57+
58+
nat_pptp_info = &nat->help.nat_pptp_info;
5359
ct_pptp_info = nfct_help_data(master);
54-
nat_pptp_info = &nfct_nat(master)->help.nat_pptp_info;
5560

5661
/* And here goes the grand finale of corrosion... */
5762
if (exp->dir == IP_CT_DIR_ORIGINAL) {
@@ -120,13 +125,17 @@ pptp_outbound_pkt(struct sk_buff *skb,
120125

121126
{
122127
struct nf_ct_pptp_master *ct_pptp_info;
128+
struct nf_conn_nat *nat = nfct_nat(ct);
123129
struct nf_nat_pptp *nat_pptp_info;
124130
u_int16_t msg;
125131
__be16 new_callid;
126132
unsigned int cid_off;
127133

134+
if (WARN_ON_ONCE(!nat))
135+
return NF_DROP;
136+
137+
nat_pptp_info = &nat->help.nat_pptp_info;
128138
ct_pptp_info = nfct_help_data(ct);
129-
nat_pptp_info = &nfct_nat(ct)->help.nat_pptp_info;
130139

131140
new_callid = ct_pptp_info->pns_call_id;
132141

@@ -191,11 +200,15 @@ pptp_exp_gre(struct nf_conntrack_expect *expect_orig,
191200
struct nf_conntrack_expect *expect_reply)
192201
{
193202
const struct nf_conn *ct = expect_orig->master;
203+
struct nf_conn_nat *nat = nfct_nat(ct);
194204
struct nf_ct_pptp_master *ct_pptp_info;
195205
struct nf_nat_pptp *nat_pptp_info;
196206

207+
if (WARN_ON_ONCE(!nat))
208+
return;
209+
210+
nat_pptp_info = &nat->help.nat_pptp_info;
197211
ct_pptp_info = nfct_help_data(ct);
198-
nat_pptp_info = &nfct_nat(ct)->help.nat_pptp_info;
199212

200213
/* save original PAC call ID in nat_info */
201214
nat_pptp_info->pac_call_id = ct_pptp_info->pac_call_id;
@@ -223,11 +236,15 @@ pptp_inbound_pkt(struct sk_buff *skb,
223236
union pptp_ctrl_union *pptpReq)
224237
{
225238
const struct nf_nat_pptp *nat_pptp_info;
239+
struct nf_conn_nat *nat = nfct_nat(ct);
226240
u_int16_t msg;
227241
__be16 new_pcid;
228242
unsigned int pcid_off;
229243

230-
nat_pptp_info = &nfct_nat(ct)->help.nat_pptp_info;
244+
if (WARN_ON_ONCE(!nat))
245+
return NF_DROP;
246+
247+
nat_pptp_info = &nat->help.nat_pptp_info;
231248
new_pcid = nat_pptp_info->pns_call_id;
232249

233250
switch (msg = ntohs(ctlh->messageType)) {

‎net/netfilter/nf_conntrack_pptp.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int exp_gre(struct nf_conn *ct, __be16 callid, __be16 peer_callid)
263263
goto out_put_both;
264264
}
265265

266-
static inline int
266+
static int
267267
pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff,
268268
struct PptpControlHeader *ctlh,
269269
union pptp_ctrl_union *pptpReq,
@@ -391,7 +391,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff,
391391
return NF_ACCEPT;
392392
}
393393

394-
static inline int
394+
static int
395395
pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff,
396396
struct PptpControlHeader *ctlh,
397397
union pptp_ctrl_union *pptpReq,
@@ -523,6 +523,14 @@ conntrack_pptp_help(struct sk_buff *skb, unsigned int protoff,
523523
int ret;
524524
u_int16_t msg;
525525

526+
#if IS_ENABLED(CONFIG_NF_NAT)
527+
if (!nf_ct_is_confirmed(ct) && (ct->status & IPS_NAT_MASK)) {
528+
struct nf_conn_nat *nat = nf_ct_ext_find(ct, NF_CT_EXT_NAT);
529+
530+
if (!nat && !nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC))
531+
return NF_DROP;
532+
}
533+
#endif
526534
/* don't do any tracking before tcp handshake complete */
527535
if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED_REPLY)
528536
return NF_ACCEPT;

0 commit comments

Comments
 (0)