diff options
author | Gao feng <gaofeng@cn.fujitsu.com> | 2012-06-21 00:36:43 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-06-27 13:05:05 -0400 |
commit | efa758fe2c2543f70b4dbda4421c8a352703e68e (patch) | |
tree | 8951a9d5453c97c0b57e589824daeb22dc6362c1 /net/netfilter | |
parent | 12c26df35eae52f14cf573a1adb85cedaa273d2b (diff) |
netfilter: nf_ct_tcp: merge tcpv[4,6]_net_init into tcp_net_init
Merge tcpv4_net_init and tcpv6_net_init into tcp_net_init to
remove redundant code now that we have the u_int16_t proto
parameter.
And use nf_proto_net.users to identify if it's the first time
we use the nf_proto_net, in that case, we initialize it.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/nf_conntrack_proto_tcp.c | 71 |
1 files changed, 21 insertions, 50 deletions
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index 6db9d3c44820..44f0da830156 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c | |||
@@ -1533,11 +1533,10 @@ static struct ctl_table tcp_compat_sysctl_table[] = { | |||
1533 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ | 1533 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ |
1534 | #endif /* CONFIG_SYSCTL */ | 1534 | #endif /* CONFIG_SYSCTL */ |
1535 | 1535 | ||
1536 | static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn) | 1536 | static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn, |
1537 | struct nf_tcp_net *tn) | ||
1537 | { | 1538 | { |
1538 | #ifdef CONFIG_SYSCTL | 1539 | #ifdef CONFIG_SYSCTL |
1539 | struct nf_tcp_net *tn = (struct nf_tcp_net *)pn; | ||
1540 | |||
1541 | if (pn->ctl_table) | 1540 | if (pn->ctl_table) |
1542 | return 0; | 1541 | return 0; |
1543 | 1542 | ||
@@ -1564,11 +1563,11 @@ static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn) | |||
1564 | return 0; | 1563 | return 0; |
1565 | } | 1564 | } |
1566 | 1565 | ||
1567 | static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) | 1566 | static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn, |
1567 | struct nf_tcp_net *tn) | ||
1568 | { | 1568 | { |
1569 | #ifdef CONFIG_SYSCTL | 1569 | #ifdef CONFIG_SYSCTL |
1570 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT | 1570 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT |
1571 | struct nf_tcp_net *tn = (struct nf_tcp_net *)pn; | ||
1572 | pn->ctl_compat_table = kmemdup(tcp_compat_sysctl_table, | 1571 | pn->ctl_compat_table = kmemdup(tcp_compat_sysctl_table, |
1573 | sizeof(tcp_compat_sysctl_table), | 1572 | sizeof(tcp_compat_sysctl_table), |
1574 | GFP_KERNEL); | 1573 | GFP_KERNEL); |
@@ -1593,18 +1592,15 @@ static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) | |||
1593 | return 0; | 1592 | return 0; |
1594 | } | 1593 | } |
1595 | 1594 | ||
1596 | static int tcpv4_init_net(struct net *net, u_int16_t proto) | 1595 | static int tcp_init_net(struct net *net, u_int16_t proto) |
1597 | { | 1596 | { |
1598 | int i; | 1597 | int ret; |
1599 | int ret = 0; | ||
1600 | struct nf_tcp_net *tn = tcp_pernet(net); | 1598 | struct nf_tcp_net *tn = tcp_pernet(net); |
1601 | struct nf_proto_net *pn = (struct nf_proto_net *)tn; | 1599 | struct nf_proto_net *pn = &tn->pn; |
1600 | |||
1601 | if (!pn->users) { | ||
1602 | int i; | ||
1602 | 1603 | ||
1603 | #ifdef CONFIG_SYSCTL | ||
1604 | if (!pn->ctl_table) { | ||
1605 | #else | ||
1606 | if (!pn->users++) { | ||
1607 | #endif | ||
1608 | for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++) | 1604 | for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++) |
1609 | tn->timeouts[i] = tcp_timeouts[i]; | 1605 | tn->timeouts[i] = tcp_timeouts[i]; |
1610 | 1606 | ||
@@ -1613,45 +1609,20 @@ static int tcpv4_init_net(struct net *net, u_int16_t proto) | |||
1613 | tn->tcp_max_retrans = nf_ct_tcp_max_retrans; | 1609 | tn->tcp_max_retrans = nf_ct_tcp_max_retrans; |
1614 | } | 1610 | } |
1615 | 1611 | ||
1616 | ret = tcp_kmemdup_compat_sysctl_table(pn); | 1612 | if (proto == AF_INET) { |
1617 | 1613 | ret = tcp_kmemdup_compat_sysctl_table(pn, tn); | |
1618 | if (ret < 0) | 1614 | if (ret < 0) |
1619 | return ret; | 1615 | return ret; |
1620 | 1616 | ||
1621 | ret = tcp_kmemdup_sysctl_table(pn); | 1617 | ret = tcp_kmemdup_sysctl_table(pn, tn); |
1618 | if (ret < 0) | ||
1619 | nf_ct_kfree_compat_sysctl_table(pn); | ||
1620 | } else | ||
1621 | ret = tcp_kmemdup_sysctl_table(pn, tn); | ||
1622 | 1622 | ||
1623 | #ifdef CONFIG_SYSCTL | ||
1624 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT | ||
1625 | if (ret < 0) { | ||
1626 | kfree(pn->ctl_compat_table); | ||
1627 | pn->ctl_compat_table = NULL; | ||
1628 | } | ||
1629 | #endif | ||
1630 | #endif | ||
1631 | return ret; | 1623 | return ret; |
1632 | } | 1624 | } |
1633 | 1625 | ||
1634 | static int tcpv6_init_net(struct net *net, u_int16_t proto) | ||
1635 | { | ||
1636 | int i; | ||
1637 | struct nf_tcp_net *tn = tcp_pernet(net); | ||
1638 | struct nf_proto_net *pn = (struct nf_proto_net *)tn; | ||
1639 | |||
1640 | #ifdef CONFIG_SYSCTL | ||
1641 | if (!pn->ctl_table) { | ||
1642 | #else | ||
1643 | if (!pn->users++) { | ||
1644 | #endif | ||
1645 | for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++) | ||
1646 | tn->timeouts[i] = tcp_timeouts[i]; | ||
1647 | tn->tcp_loose = nf_ct_tcp_loose; | ||
1648 | tn->tcp_be_liberal = nf_ct_tcp_be_liberal; | ||
1649 | tn->tcp_max_retrans = nf_ct_tcp_max_retrans; | ||
1650 | } | ||
1651 | |||
1652 | return tcp_kmemdup_sysctl_table(pn); | ||
1653 | } | ||
1654 | |||
1655 | struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = | 1626 | struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = |
1656 | { | 1627 | { |
1657 | .l3proto = PF_INET, | 1628 | .l3proto = PF_INET, |
@@ -1684,7 +1655,7 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = | |||
1684 | .nla_policy = tcp_timeout_nla_policy, | 1655 | .nla_policy = tcp_timeout_nla_policy, |
1685 | }, | 1656 | }, |
1686 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | 1657 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
1687 | .init_net = tcpv4_init_net, | 1658 | .init_net = tcp_init_net, |
1688 | }; | 1659 | }; |
1689 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4); | 1660 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4); |
1690 | 1661 | ||
@@ -1720,6 +1691,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = | |||
1720 | .nla_policy = tcp_timeout_nla_policy, | 1691 | .nla_policy = tcp_timeout_nla_policy, |
1721 | }, | 1692 | }, |
1722 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | 1693 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
1723 | .init_net = tcpv6_init_net, | 1694 | .init_net = tcp_init_net, |
1724 | }; | 1695 | }; |
1725 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6); | 1696 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6); |