Skip to content

Commit 20ff320

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: pptp: use single option structure
Instead of exposing the four hooks individually use a sinle hook ops structure. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 1015c3d commit 20ff320

File tree

3 files changed

+45
-77
lines changed

3 files changed

+45
-77
lines changed

include/linux/netfilter/nf_conntrack_pptp.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,26 +300,22 @@ union pptp_ctrl_union {
300300
struct PptpSetLinkInfo setlink;
301301
};
302302

303-
extern int
304-
(*nf_nat_pptp_hook_outbound)(struct sk_buff *skb,
305-
struct nf_conn *ct, enum ip_conntrack_info ctinfo,
306-
unsigned int protoff,
307-
struct PptpControlHeader *ctlh,
308-
union pptp_ctrl_union *pptpReq);
309-
310-
extern int
311-
(*nf_nat_pptp_hook_inbound)(struct sk_buff *skb,
312-
struct nf_conn *ct, enum ip_conntrack_info ctinfo,
313-
unsigned int protoff,
314-
struct PptpControlHeader *ctlh,
315-
union pptp_ctrl_union *pptpReq);
316-
317-
extern void
318-
(*nf_nat_pptp_hook_exp_gre)(struct nf_conntrack_expect *exp_orig,
319-
struct nf_conntrack_expect *exp_reply);
320-
321-
extern void
322-
(*nf_nat_pptp_hook_expectfn)(struct nf_conn *ct,
323-
struct nf_conntrack_expect *exp);
303+
struct nf_nat_pptp_hook {
304+
int (*outbound)(struct sk_buff *skb,
305+
struct nf_conn *ct, enum ip_conntrack_info ctinfo,
306+
unsigned int protoff,
307+
struct PptpControlHeader *ctlh,
308+
union pptp_ctrl_union *pptpReq);
309+
int (*inbound)(struct sk_buff *skb,
310+
struct nf_conn *ct, enum ip_conntrack_info ctinfo,
311+
unsigned int protoff,
312+
struct PptpControlHeader *ctlh,
313+
union pptp_ctrl_union *pptpReq);
314+
void (*exp_gre)(struct nf_conntrack_expect *exp_orig,
315+
struct nf_conntrack_expect *exp_reply);
316+
void (*expectfn)(struct nf_conn *ct,
317+
struct nf_conntrack_expect *exp);
318+
};
324319

320+
extern const struct nf_nat_pptp_hook __rcu *nf_nat_pptp_hook;
325321
#endif /* _NF_CONNTRACK_PPTP_H */

net/ipv4/netfilter/nf_nat_pptp.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,28 +295,24 @@ pptp_inbound_pkt(struct sk_buff *skb,
295295
return NF_ACCEPT;
296296
}
297297

298+
static const struct nf_nat_pptp_hook pptp_hooks = {
299+
.outbound = pptp_outbound_pkt,
300+
.inbound = pptp_inbound_pkt,
301+
.exp_gre = pptp_exp_gre,
302+
.expectfn = pptp_nat_expected,
303+
};
304+
298305
static int __init nf_nat_helper_pptp_init(void)
299306
{
300-
BUG_ON(nf_nat_pptp_hook_outbound != NULL);
301-
RCU_INIT_POINTER(nf_nat_pptp_hook_outbound, pptp_outbound_pkt);
302-
303-
BUG_ON(nf_nat_pptp_hook_inbound != NULL);
304-
RCU_INIT_POINTER(nf_nat_pptp_hook_inbound, pptp_inbound_pkt);
305-
306-
BUG_ON(nf_nat_pptp_hook_exp_gre != NULL);
307-
RCU_INIT_POINTER(nf_nat_pptp_hook_exp_gre, pptp_exp_gre);
307+
WARN_ON(nf_nat_pptp_hook != NULL);
308+
RCU_INIT_POINTER(nf_nat_pptp_hook, &pptp_hooks);
308309

309-
BUG_ON(nf_nat_pptp_hook_expectfn != NULL);
310-
RCU_INIT_POINTER(nf_nat_pptp_hook_expectfn, pptp_nat_expected);
311310
return 0;
312311
}
313312

314313
static void __exit nf_nat_helper_pptp_fini(void)
315314
{
316-
RCU_INIT_POINTER(nf_nat_pptp_hook_expectfn, NULL);
317-
RCU_INIT_POINTER(nf_nat_pptp_hook_exp_gre, NULL);
318-
RCU_INIT_POINTER(nf_nat_pptp_hook_inbound, NULL);
319-
RCU_INIT_POINTER(nf_nat_pptp_hook_outbound, NULL);
315+
RCU_INIT_POINTER(nf_nat_pptp_hook, NULL);
320316
synchronize_rcu();
321317
}
322318

net/netfilter/nf_conntrack_pptp.c

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,8 @@ MODULE_ALIAS_NFCT_HELPER("pptp");
4545

4646
static DEFINE_SPINLOCK(nf_pptp_lock);
4747

48-
int
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);
54-
55-
int
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);
61-
62-
void
63-
(*nf_nat_pptp_hook_exp_gre)(struct nf_conntrack_expect *expect_orig,
64-
struct nf_conntrack_expect *expect_reply)
65-
__read_mostly;
66-
EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_exp_gre);
67-
68-
void
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);
48+
const struct nf_nat_pptp_hook *nf_nat_pptp_hook;
49+
EXPORT_SYMBOL_GPL(nf_nat_pptp_hook);
7250

7351
#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
7452
/* PptpControlMessageType names */
@@ -111,8 +89,8 @@ EXPORT_SYMBOL(pptp_msg_name);
11189
static void pptp_expectfn(struct nf_conn *ct,
11290
struct nf_conntrack_expect *exp)
11391
{
92+
const struct nf_nat_pptp_hook *hook;
11493
struct net *net = nf_ct_net(ct);
115-
typeof(nf_nat_pptp_hook_expectfn) nf_nat_pptp_expectfn;
11694
pr_debug("increasing timeouts\n");
11795

11896
/* increase timeout of GRE data channel conntrack entry */
@@ -122,9 +100,9 @@ static void pptp_expectfn(struct nf_conn *ct,
122100
/* Can you see how rusty this code is, compared with the pre-2.6.11
123101
* one? That's what happened to my shiny newnat of 2002 ;( -HW */
124102

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);
103+
hook = rcu_dereference(nf_nat_pptp_hook);
104+
if (hook && ct->master->status & IPS_NAT_MASK)
105+
hook->expectfn(ct, exp);
128106
else {
129107
struct nf_conntrack_tuple inv_t;
130108
struct nf_conntrack_expect *exp_other;
@@ -209,9 +187,9 @@ static void pptp_destroy_siblings(struct nf_conn *ct)
209187
static int exp_gre(struct nf_conn *ct, __be16 callid, __be16 peer_callid)
210188
{
211189
struct nf_conntrack_expect *exp_orig, *exp_reply;
190+
const struct nf_nat_pptp_hook *hook;
212191
enum ip_conntrack_dir dir;
213192
int ret = 1;
214-
typeof(nf_nat_pptp_hook_exp_gre) nf_nat_pptp_exp_gre;
215193

216194
exp_orig = nf_ct_expect_alloc(ct);
217195
if (exp_orig == NULL)
@@ -239,9 +217,9 @@ static int exp_gre(struct nf_conn *ct, __be16 callid, __be16 peer_callid)
239217
IPPROTO_GRE, &callid, &peer_callid);
240218
exp_reply->expectfn = pptp_expectfn;
241219

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);
220+
hook = rcu_dereference(nf_nat_pptp_hook);
221+
if (hook && ct->status & IPS_NAT_MASK)
222+
hook->exp_gre(exp_orig, exp_reply);
245223
if (nf_ct_expect_related(exp_orig, 0) != 0)
246224
goto out_put_both;
247225
if (nf_ct_expect_related(exp_reply, 0) != 0)
@@ -279,9 +257,9 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff,
279257
enum ip_conntrack_info ctinfo)
280258
{
281259
struct nf_ct_pptp_master *info = nfct_help_data(ct);
260+
const struct nf_nat_pptp_hook *hook;
282261
u_int16_t msg;
283262
__be16 cid = 0, pcid = 0;
284-
typeof(nf_nat_pptp_hook_inbound) nf_nat_pptp_inbound;
285263

286264
msg = ntohs(ctlh->messageType);
287265
pr_debug("inbound control message %s\n", pptp_msg_name(msg));
@@ -383,10 +361,9 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff,
383361
goto invalid;
384362
}
385363

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);
364+
hook = rcu_dereference(nf_nat_pptp_hook);
365+
if (hook && ct->status & IPS_NAT_MASK)
366+
return hook->inbound(skb, ct, ctinfo, protoff, ctlh, pptpReq);
390367
return NF_ACCEPT;
391368

392369
invalid:
@@ -407,9 +384,9 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff,
407384
enum ip_conntrack_info ctinfo)
408385
{
409386
struct nf_ct_pptp_master *info = nfct_help_data(ct);
387+
const struct nf_nat_pptp_hook *hook;
410388
u_int16_t msg;
411389
__be16 cid = 0, pcid = 0;
412-
typeof(nf_nat_pptp_hook_outbound) nf_nat_pptp_outbound;
413390

414391
msg = ntohs(ctlh->messageType);
415392
pr_debug("outbound control message %s\n", pptp_msg_name(msg));
@@ -479,10 +456,9 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff,
479456
goto invalid;
480457
}
481458

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);
459+
hook = rcu_dereference(nf_nat_pptp_hook);
460+
if (hook && ct->status & IPS_NAT_MASK)
461+
return hook->outbound(skb, ct, ctinfo, protoff, ctlh, pptpReq);
486462
return NF_ACCEPT;
487463

488464
invalid:

0 commit comments

Comments
 (0)