diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-10-14 14:58:31 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-10-14 14:58:31 -0400 |
commit | e6a7d3c04f8fe49099521e6dc9a46b0272381f2f (patch) | |
tree | 4717fcfe05549d39c9281b3b23310b775ad38d16 /net/ipv4 | |
parent | 129404a1f117c35c6224e020444fc27eb4479817 (diff) |
netfilter: ctnetlink: remove bogus module dependency between ctnetlink and nf_nat
This patch removes the module dependency between ctnetlink and
nf_nat by means of an indirect call that is initialized when
nf_nat is loaded. Now, nf_conntrack_netlink only requires
nf_conntrack and nfnetlink.
This patch puts nfnetlink_parse_nat_setup_hook into the
nf_conntrack_core to avoid dependencies between ctnetlink,
nf_conntrack_ipv4 and nf_conntrack_ipv6.
This patch also introduces the function ctnetlink_change_nat
that is only invoked from the creation path. Actually, the
nat handling cannot be invoked from the update path since
this is not allowed. By introducing this function, we remove
the useless nat handling in the update path and we avoid
deadlock-prone code.
This patch also adds the required EAGAIN logic for nfnetlink.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/netfilter/nf_nat_core.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c index 2ac9eaf1a8c9..a65cf692359f 100644 --- a/net/ipv4/netfilter/nf_nat_core.c +++ b/net/ipv4/netfilter/nf_nat_core.c | |||
@@ -584,6 +584,98 @@ static struct nf_ct_ext_type nat_extend __read_mostly = { | |||
584 | .flags = NF_CT_EXT_F_PREALLOC, | 584 | .flags = NF_CT_EXT_F_PREALLOC, |
585 | }; | 585 | }; |
586 | 586 | ||
587 | #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) | ||
588 | |||
589 | #include <linux/netfilter/nfnetlink.h> | ||
590 | #include <linux/netfilter/nfnetlink_conntrack.h> | ||
591 | |||
592 | static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = { | ||
593 | [CTA_PROTONAT_PORT_MIN] = { .type = NLA_U16 }, | ||
594 | [CTA_PROTONAT_PORT_MAX] = { .type = NLA_U16 }, | ||
595 | }; | ||
596 | |||
597 | static int nfnetlink_parse_nat_proto(struct nlattr *attr, | ||
598 | const struct nf_conn *ct, | ||
599 | struct nf_nat_range *range) | ||
600 | { | ||
601 | struct nlattr *tb[CTA_PROTONAT_MAX+1]; | ||
602 | const struct nf_nat_protocol *npt; | ||
603 | int err; | ||
604 | |||
605 | err = nla_parse_nested(tb, CTA_PROTONAT_MAX, attr, protonat_nla_policy); | ||
606 | if (err < 0) | ||
607 | return err; | ||
608 | |||
609 | npt = nf_nat_proto_find_get(nf_ct_protonum(ct)); | ||
610 | if (npt->nlattr_to_range) | ||
611 | err = npt->nlattr_to_range(tb, range); | ||
612 | nf_nat_proto_put(npt); | ||
613 | return err; | ||
614 | } | ||
615 | |||
616 | static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = { | ||
617 | [CTA_NAT_MINIP] = { .type = NLA_U32 }, | ||
618 | [CTA_NAT_MAXIP] = { .type = NLA_U32 }, | ||
619 | }; | ||
620 | |||
621 | static int | ||
622 | nfnetlink_parse_nat(struct nlattr *nat, | ||
623 | const struct nf_conn *ct, struct nf_nat_range *range) | ||
624 | { | ||
625 | struct nlattr *tb[CTA_NAT_MAX+1]; | ||
626 | int err; | ||
627 | |||
628 | memset(range, 0, sizeof(*range)); | ||
629 | |||
630 | err = nla_parse_nested(tb, CTA_NAT_MAX, nat, nat_nla_policy); | ||
631 | if (err < 0) | ||
632 | return err; | ||
633 | |||
634 | if (tb[CTA_NAT_MINIP]) | ||
635 | range->min_ip = nla_get_be32(tb[CTA_NAT_MINIP]); | ||
636 | |||
637 | if (!tb[CTA_NAT_MAXIP]) | ||
638 | range->max_ip = range->min_ip; | ||
639 | else | ||
640 | range->max_ip = nla_get_be32(tb[CTA_NAT_MAXIP]); | ||
641 | |||
642 | if (range->min_ip) | ||
643 | range->flags |= IP_NAT_RANGE_MAP_IPS; | ||
644 | |||
645 | if (!tb[CTA_NAT_PROTO]) | ||
646 | return 0; | ||
647 | |||
648 | err = nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO], ct, range); | ||
649 | if (err < 0) | ||
650 | return err; | ||
651 | |||
652 | return 0; | ||
653 | } | ||
654 | |||
655 | static int | ||
656 | nfnetlink_parse_nat_setup(struct nf_conn *ct, | ||
657 | enum nf_nat_manip_type manip, | ||
658 | struct nlattr *attr) | ||
659 | { | ||
660 | struct nf_nat_range range; | ||
661 | |||
662 | if (nfnetlink_parse_nat(attr, ct, &range) < 0) | ||
663 | return -EINVAL; | ||
664 | if (nf_nat_initialized(ct, manip)) | ||
665 | return -EEXIST; | ||
666 | |||
667 | return nf_nat_setup_info(ct, &range, manip); | ||
668 | } | ||
669 | #else | ||
670 | static int | ||
671 | nfnetlink_parse_nat_setup(struct nf_conn *ct, | ||
672 | enum nf_nat_manip_type manip, | ||
673 | struct nlattr *attr) | ||
674 | { | ||
675 | return -EOPNOTSUPP; | ||
676 | } | ||
677 | #endif | ||
678 | |||
587 | static int __net_init nf_nat_net_init(struct net *net) | 679 | static int __net_init nf_nat_net_init(struct net *net) |
588 | { | 680 | { |
589 | net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&nf_nat_htable_size, | 681 | net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&nf_nat_htable_size, |
@@ -654,6 +746,9 @@ static int __init nf_nat_init(void) | |||
654 | 746 | ||
655 | BUG_ON(nf_nat_seq_adjust_hook != NULL); | 747 | BUG_ON(nf_nat_seq_adjust_hook != NULL); |
656 | rcu_assign_pointer(nf_nat_seq_adjust_hook, nf_nat_seq_adjust); | 748 | rcu_assign_pointer(nf_nat_seq_adjust_hook, nf_nat_seq_adjust); |
749 | BUG_ON(nfnetlink_parse_nat_setup_hook != NULL); | ||
750 | rcu_assign_pointer(nfnetlink_parse_nat_setup_hook, | ||
751 | nfnetlink_parse_nat_setup); | ||
657 | return 0; | 752 | return 0; |
658 | 753 | ||
659 | cleanup_extend: | 754 | cleanup_extend: |
@@ -667,10 +762,12 @@ static void __exit nf_nat_cleanup(void) | |||
667 | nf_ct_l3proto_put(l3proto); | 762 | nf_ct_l3proto_put(l3proto); |
668 | nf_ct_extend_unregister(&nat_extend); | 763 | nf_ct_extend_unregister(&nat_extend); |
669 | rcu_assign_pointer(nf_nat_seq_adjust_hook, NULL); | 764 | rcu_assign_pointer(nf_nat_seq_adjust_hook, NULL); |
765 | rcu_assign_pointer(nfnetlink_parse_nat_setup_hook, NULL); | ||
670 | synchronize_net(); | 766 | synchronize_net(); |
671 | } | 767 | } |
672 | 768 | ||
673 | MODULE_LICENSE("GPL"); | 769 | MODULE_LICENSE("GPL"); |
770 | MODULE_ALIAS("nf-nat-ipv4"); | ||
674 | 771 | ||
675 | module_init(nf_nat_init); | 772 | module_init(nf_nat_init); |
676 | module_exit(nf_nat_cleanup); | 773 | module_exit(nf_nat_cleanup); |