Skip to content

Commit 2c205dd

Browse files
committed
netfilter: add struct nf_nat_hook and use it
Move decode_session() and parse_nat_setup_hook() indirections to struct nf_nat_hook structure. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 1f4b243 commit 2c205dd

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

include/linux/netfilter.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,29 @@ int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
320320
int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry);
321321

322322
#include <net/flow.h>
323-
extern void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *);
323+
324+
struct nf_conn;
325+
enum nf_nat_manip_type;
326+
struct nlattr;
327+
328+
struct nf_nat_hook {
329+
int (*parse_nat_setup)(struct nf_conn *ct, enum nf_nat_manip_type manip,
330+
const struct nlattr *attr);
331+
void (*decode_session)(struct sk_buff *skb, struct flowi *fl);
332+
};
333+
334+
extern struct nf_nat_hook __rcu *nf_nat_hook;
324335

325336
static inline void
326337
nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
327338
{
328339
#ifdef CONFIG_NF_NAT_NEEDED
329-
void (*decodefn)(struct sk_buff *, struct flowi *);
340+
struct nf_nat_hook *nat_hook;
330341

331342
rcu_read_lock();
332-
decodefn = rcu_dereference(nf_nat_decode_session_hook);
333-
if (decodefn)
334-
decodefn(skb, fl);
343+
nat_hook = rcu_dereference(nf_nat_hook);
344+
if (nat_hook->decode_session)
345+
nat_hook->decode_session(skb, fl);
335346
rcu_read_unlock();
336347
#endif
337348
}

include/net/netfilter/nf_nat_core.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,4 @@ static inline int nf_nat_initialized(struct nf_conn *ct,
2626
return ct->status & IPS_DST_NAT_DONE;
2727
}
2828

29-
struct nlattr;
30-
31-
extern int
32-
(*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct,
33-
enum nf_nat_manip_type manip,
34-
const struct nlattr *attr);
35-
3629
#endif /* _NF_NAT_CORE_H */

net/netfilter/core.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *)
574574
__rcu __read_mostly;
575575
EXPORT_SYMBOL(ip_ct_attach);
576576

577+
struct nf_nat_hook __rcu *nf_nat_hook __read_mostly;
578+
EXPORT_SYMBOL_GPL(nf_nat_hook);
579+
577580
void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb)
578581
{
579582
void (*attach)(struct sk_buff *, const struct sk_buff *);
@@ -608,11 +611,6 @@ const struct nf_conntrack_zone nf_ct_zone_dflt = {
608611
EXPORT_SYMBOL_GPL(nf_ct_zone_dflt);
609612
#endif /* CONFIG_NF_CONNTRACK */
610613

611-
#ifdef CONFIG_NF_NAT_NEEDED
612-
void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *);
613-
EXPORT_SYMBOL(nf_nat_decode_session_hook);
614-
#endif
615-
616614
static void __net_init __netfilter_net_init(struct nf_hook_entries **e, int max)
617615
{
618616
int h;

net/netfilter/nf_conntrack_core.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@
5858

5959
#include "nf_internals.h"
6060

61-
int (*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct,
62-
enum nf_nat_manip_type manip,
63-
const struct nlattr *attr) __read_mostly;
64-
EXPORT_SYMBOL_GPL(nfnetlink_parse_nat_setup_hook);
65-
6661
__cacheline_aligned_in_smp spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];
6762
EXPORT_SYMBOL_GPL(nf_conntrack_locks);
6863

net/netfilter/nf_conntrack_netlink.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,11 +1431,11 @@ ctnetlink_parse_nat_setup(struct nf_conn *ct,
14311431
enum nf_nat_manip_type manip,
14321432
const struct nlattr *attr)
14331433
{
1434-
typeof(nfnetlink_parse_nat_setup_hook) parse_nat_setup;
1434+
struct nf_nat_hook *nat_hook;
14351435
int err;
14361436

1437-
parse_nat_setup = rcu_dereference(nfnetlink_parse_nat_setup_hook);
1438-
if (!parse_nat_setup) {
1437+
nat_hook = rcu_dereference(nf_nat_hook);
1438+
if (!nat_hook) {
14391439
#ifdef CONFIG_MODULES
14401440
rcu_read_unlock();
14411441
nfnl_unlock(NFNL_SUBSYS_CTNETLINK);
@@ -1446,13 +1446,13 @@ ctnetlink_parse_nat_setup(struct nf_conn *ct,
14461446
}
14471447
nfnl_lock(NFNL_SUBSYS_CTNETLINK);
14481448
rcu_read_lock();
1449-
if (nfnetlink_parse_nat_setup_hook)
1449+
if (nat_hook->parse_nat_setup)
14501450
return -EAGAIN;
14511451
#endif
14521452
return -EOPNOTSUPP;
14531453
}
14541454

1455-
err = parse_nat_setup(ct, manip, attr);
1455+
err = nat_hook->parse_nat_setup(ct, manip, attr);
14561456
if (err == -EAGAIN) {
14571457
#ifdef CONFIG_MODULES
14581458
rcu_read_unlock();

net/netfilter/nf_nat_core.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,13 @@ static struct pernet_operations nat_net_ops = {
10261026
.size = sizeof(struct nat_net),
10271027
};
10281028

1029+
struct nf_nat_hook nat_hook = {
1030+
.parse_nat_setup = nfnetlink_parse_nat_setup,
1031+
#ifdef CONFIG_XFRM
1032+
.decode_session = __nf_nat_decode_session,
1033+
#endif
1034+
};
1035+
10291036
static int __init nf_nat_init(void)
10301037
{
10311038
int ret, i;
@@ -1057,13 +1064,9 @@ static int __init nf_nat_init(void)
10571064

10581065
nf_ct_helper_expectfn_register(&follow_master_nat);
10591066

1060-
BUG_ON(nfnetlink_parse_nat_setup_hook != NULL);
1061-
RCU_INIT_POINTER(nfnetlink_parse_nat_setup_hook,
1062-
nfnetlink_parse_nat_setup);
1063-
#ifdef CONFIG_XFRM
1064-
BUG_ON(nf_nat_decode_session_hook != NULL);
1065-
RCU_INIT_POINTER(nf_nat_decode_session_hook, __nf_nat_decode_session);
1066-
#endif
1067+
WARN_ON(nf_nat_hook != NULL);
1068+
RCU_INIT_POINTER(nf_nat_hook, &nat_hook);
1069+
10671070
return 0;
10681071
}
10691072

@@ -1076,10 +1079,8 @@ static void __exit nf_nat_cleanup(void)
10761079

10771080
nf_ct_extend_unregister(&nat_extend);
10781081
nf_ct_helper_expectfn_unregister(&follow_master_nat);
1079-
RCU_INIT_POINTER(nfnetlink_parse_nat_setup_hook, NULL);
1080-
#ifdef CONFIG_XFRM
1081-
RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL);
1082-
#endif
1082+
RCU_INIT_POINTER(nf_nat_hook, NULL);
1083+
10831084
synchronize_rcu();
10841085

10851086
for (i = 0; i < NFPROTO_NUMPROTO; i++)

0 commit comments

Comments
 (0)