Skip to contentSkip to conversation

: Netfilter Update

PATCH Applied Patrick McHardy 3 participants 29 messages Apr 6, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover : Netfilter Update

Hi Dave,

following are a couple of netfilter fixes and enhancements: a couple of patches to fix the section mismatch warnings and clean up the netfilter hook registration, checksumming consolidation with better HW checksum error handling and some cleanup patches for the H.323 helper. The diffstat is a bit misleading, there is a lot of noise from the renaming of two large H.323 header files and a lot of reindentation of netfilter structures, its not as bad as it looks :) If you think its too large for -rc1 I can hold on to the checksumming patches, the others should go in as they actually fix stuff. Thanks.

 include/linux/netfilter.h                                     |   42 
 include/linux/netfilter_ipv4.h                                |    2 
 include/linux/netfilter_ipv4/ip_conntrack_h323.h              |   52 
 include/linux/netfilter_ipv4/ip_conntrack_helper_h323_asn1.h  |   98 +
 include/linux/netfilter_ipv4/ip_conntrack_helper_h323_types.h |  938 ++++++++++
 include/linux/netfilter_ipv6.h                                |    3 
 net/ipv4/netfilter.c                                          |   50 
 net/ipv4/netfilter/Kconfig                                    |    1 
 net/ipv4/netfilter/arptable_filter.c                          |   19 
 net/ipv4/netfilter/ip_conntrack_helper_h323.c                 |   50 
 net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c            |    2 
 net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h            |   98 -
 net/ipv4/netfilter/ip_conntrack_helper_h323_types.h           |  938 ----------
 net/ipv4/netfilter/ip_conntrack_proto_icmp.c                  |   23 
 net/ipv4/netfilter/ip_conntrack_proto_tcp.c                   |    7 
 net/ipv4/netfilter/ip_conntrack_proto_udp.c                   |    7 
 net/ipv4/netfilter/ip_conntrack_standalone.c                  |  270 +-
 net/ipv4/netfilter/ip_nat_helper_h323.c                       |   58 
 net/ipv4/netfilter/ip_nat_standalone.c                        |  161 -
 net/ipv4/netfilter/ip_queue.c                                 |   31 
 net/ipv4/netfilter/ipt_CLUSTERIP.c                            |   40 
 net/ipv4/netfilter/ipt_REJECT.c                               |    9 
 net/ipv4/netfilter/iptable_filter.c                           |   21 
 net/ipv4/netfilter/iptable_mangle.c                           |   33 
 net/ipv4/netfilter/iptable_raw.c                              |   35 
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c                |  227 --
 net/ipv4/netfilter/nf_conntrack_proto_icmp.c                  |   20 
 net/ipv6/netfilter.c                                          |   51 
 net/ipv6/netfilter/ip6_queue.c                                |   31 
 net/ipv6/netfilter/ip6table_filter.c                          |   21 
 net/ipv6/netfilter/ip6table_mangle.c                          |   33 
 net/ipv6/netfilter/ip6table_raw.c                             |   15 
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c                |  181 -
 net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c                |   12 
 net/netfilter/core.c                                          |   51 
 net/netfilter/nf_conntrack_proto_tcp.c                        |   50 
 net/netfilter/nf_conntrack_proto_udp.c                        |   50 
 net/netfilter/nf_conntrack_standalone.c                       |  115 -
 net/netfilter/nf_queue.c                                      |   49 
 net/netfilter/nfnetlink_log.c                                 |   25 
 net/netfilter/nfnetlink_queue.c                               |   27 
 41 files changed, 1799 insertions(+), 2147 deletions(-)

Jing Min Zhao:
[NETFILTER]: H.323 helper: move some function prototypes to ip_conntrack_h323.h [NETFILTER]: H.323 helper: change EXPORT_SYMBOL to EXPORT_SYMBOL_GPL [NETFILTER]: H.323 helper: make get_h245_addr() static [NETFILTER]: H.323 helper: add parameter 'default_rrq_ttl' [NETFILTER]: H.323 helper: update Changelog

Patrick McHardy:
[NETFILTER]: Add helper functions for mass hook registration/unregistration [NETFILTER]: Clean up hook registration
[NETFILTER]: Fix section mismatch warnings
[NETFILTER]: Fix IP_NF_CONNTRACK_NETLINK dependency [NETFILTER]: Introduce infrastructure for address family specific operations [NETFILTER]: Add address family specific checksum helpers [NETFILTER]: Convert conntrack/ipt_REJECT to new checksumming functions

#1 lore raw

PATCH 1/12 : Add helper functions for mass hook registration/unregistration

[NETFILTER]: Add helper functions for mass hook registration/unregistration

---
commit 3bf0d209e539917efcc5286b8f1cab2856ebdd49
tree 4c5840cf32ee69cc6138534d24c4d43a23fad557
parent 32a976a8703b098e898a9a13f9ddcabbf654e7d8
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:32:05 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:32:05 +0200

 include/linux/netfilter.h |    2 ++
 net/netfilter/core.c      |   28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
include/linux/netfilter.h +2 -0
index 412e52c..5aa9316 100644
@@ -110,6 +110,8 @@ struct nf_info
 /* Function to register/unregister hook points. */
 int nf_register_hook(struct nf_hook_ops *reg);
 void nf_unregister_hook(struct nf_hook_ops *reg);
+int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
+void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
 
 /* Functions to register get/setsockopt ranges (non-inclusive).  You
    need to check permissions yourself! */
net/netfilter/core.c +28 -0
index 1ceb1a6..5c7143e 100644
@@ -63,6 +63,34 @@ void nf_unregister_hook(struct nf_hook_o
 }
 EXPORT_SYMBOL(nf_unregister_hook);
 
+int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+	unsigned int i;
+	int err = 0;
+
+	for (i = 0; i < n; i++) {
+		err = nf_register_hook(&reg[i]);
+		if (err)
+			goto err;
+	}
+	return err;
+
+err:
+	if (i > 0)
+		nf_unregister_hooks(reg, i - i);
+	return err;
+}
+EXPORT_SYMBOL(nf_register_hooks);
+
+void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+	unsigned int i;
+
+	for (i = 0; i < n; i++)
+		nf_unregister_hook(&reg[i]);
+}
+EXPORT_SYMBOL(nf_unregister_hooks);
+
 unsigned int nf_iterate(struct list_head *head,
 			struct sk_buff **skb,
 			int hook,
#5 lore raw

PATCH 2/12 : Clean up hook registration

In reply to Patrick McHardy

[NETFILTER]: Clean up hook registration

Clean up hook registration by makeing use of the new mass registration and unregistration helpers.

---
commit 2f8e62d3a554aee067771c5146a1e29feecd2758
tree ea5cdb8d6c319c334007c87c1e859ae0ed41f3f5
parent 3bf0d209e539917efcc5286b8f1cab2856ebdd49
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:34:13 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:34:13 +0200

 net/ipv4/netfilter/arptable_filter.c           |   19 +-
 net/ipv4/netfilter/ip_conntrack_standalone.c   |  180 ++++++++---------------
 net/ipv4/netfilter/ip_nat_standalone.c         |  143 +++++++-----------
 net/ipv4/netfilter/iptable_filter.c            |   21 ---
 net/ipv4/netfilter/iptable_mangle.c            |   33 ----
 net/ipv4/netfilter/iptable_raw.c               |   35 ++--
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |  189 ++++++++----------------
 net/ipv6/netfilter/ip6table_filter.c           |   21 ---
 net/ipv6/netfilter/ip6table_mangle.c           |   33 ----
 net/ipv6/netfilter/ip6table_raw.c              |   15 --
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c |  143 ++++++------------
 11 files changed, 253 insertions(+), 579 deletions(-)
net/ipv4/netfilter/arptable_filter.c +6 -13
index d0d379c..d7c472f 100644
@@ -181,33 +181,26 @@ static struct nf_hook_ops arpt_ops[] = {
 
 static int __init arptable_filter_init(void)
 {
-	int ret, i;
+	int ret;
 
 	/* Register table */
 	ret = arpt_register_table(&packet_filter, &initial_table.repl);
 	if (ret < 0)
 		return ret;
 
-	for (i = 0; i < ARRAY_SIZE(arpt_ops); i++)
-		if ((ret = nf_register_hook(&arpt_ops[i])) < 0)
-			goto cleanup_hooks;
+	ret = nf_register_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
+	if (ret < 0)
+		goto cleanup_table;
 	return ret;
 
-cleanup_hooks:
-	while (--i >= 0)
-		nf_unregister_hook(&arpt_ops[i]);
-
+cleanup_table:
 	arpt_unregister_table(&packet_filter);
 	return ret;
 }
 
 static void __exit arptable_filter_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(arpt_ops); i++)
-		nf_unregister_hook(&arpt_ops[i]);
-
+	nf_unregister_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
 	arpt_unregister_table(&packet_filter);
 }
 
net/ipv4/netfilter/ip_conntrack_standalone.c +62 -118

207 lines not on this page · raw message

net/ipv4/netfilter/ip_nat_standalone.c +52 -91

163 lines not on this page · raw message

net/ipv4/netfilter/iptable_filter.c +2 -19
index 3d80aef..7f41748 100644
@@ -157,37 +157,20 @@ static int __init iptable_filter_init(vo
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ipt_ops[0]);
+	ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ipt_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
-	ret = nf_register_hook(&ipt_ops[2]);
-	if (ret < 0)
-		goto cleanup_hook1;
-
 	return ret;
 
- cleanup_hook1:
-	nf_unregister_hook(&ipt_ops[1]);
- cleanup_hook0:
-	nf_unregister_hook(&ipt_ops[0]);
  cleanup_table:
 	ipt_unregister_table(&packet_filter);
-
 	return ret;
 }
 
 static void __exit iptable_filter_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ipt_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ipt_ops[i]);
-
+	nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	ipt_unregister_table(&packet_filter);
 }
 
net/ipv4/netfilter/iptable_mangle.c +2 -31
index 412fc96..397b95c 100644
@@ -211,49 +211,20 @@ static int __init iptable_mangle_init(vo
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ipt_ops[0]);
+	ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ipt_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
-	ret = nf_register_hook(&ipt_ops[2]);
-	if (ret < 0)
-		goto cleanup_hook1;
-
-	ret = nf_register_hook(&ipt_ops[3]);
-	if (ret < 0)
-		goto cleanup_hook2;
-
-	ret = nf_register_hook(&ipt_ops[4]);
-	if (ret < 0)
-		goto cleanup_hook3;
-
 	return ret;
 
- cleanup_hook3:
-        nf_unregister_hook(&ipt_ops[3]);
- cleanup_hook2:
-        nf_unregister_hook(&ipt_ops[2]);
- cleanup_hook1:
-	nf_unregister_hook(&ipt_ops[1]);
- cleanup_hook0:
-	nf_unregister_hook(&ipt_ops[0]);
  cleanup_table:
 	ipt_unregister_table(&packet_mangler);
-
 	return ret;
 }
 
 static void __exit iptable_mangle_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ipt_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ipt_ops[i]);
-
+	nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	ipt_unregister_table(&packet_mangler);
 }
 
net/ipv4/netfilter/iptable_raw.c +12 -23
index 03cc79a..be43dfb 100644
@@ -101,18 +101,18 @@ ipt_hook(unsigned int hook,
 /* 'raw' is the very first table. */
 static struct nf_hook_ops ipt_ops[] = {
 	{
-	  .hook = ipt_hook, 
-	  .pf = PF_INET, 
-	  .hooknum = NF_IP_PRE_ROUTING, 
-	  .priority = NF_IP_PRI_RAW,
-	  .owner = THIS_MODULE,
+		.hook = ipt_hook,
+		.pf = PF_INET,
+		.hooknum = NF_IP_PRE_ROUTING,
+		.priority = NF_IP_PRI_RAW,
+		.owner = THIS_MODULE,
 	},
 	{
-	  .hook = ipt_hook, 
-	  .pf = PF_INET, 
-	  .hooknum = NF_IP_LOCAL_OUT, 
-	  .priority = NF_IP_PRI_RAW,
-	  .owner = THIS_MODULE,
+		.hook = ipt_hook,
+		.pf = PF_INET,
+		.hooknum = NF_IP_LOCAL_OUT,
+		.priority = NF_IP_PRI_RAW,
+		.owner = THIS_MODULE,
 	},
 };
 
@@ -126,31 +126,20 @@ static int __init iptable_raw_init(void)
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ipt_ops[0]);
+	ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ipt_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
 	return ret;
 
- cleanup_hook0:
-	nf_unregister_hook(&ipt_ops[0]);
  cleanup_table:
 	ipt_unregister_table(&packet_raw);
-
 	return ret;
 }
 
 static void __exit iptable_raw_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ipt_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ipt_ops[i]);
-
+	nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
 	ipt_unregister_table(&packet_raw);
 }
 
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +63 -126

216 lines not on this page · raw message

net/ipv6/netfilter/ip6table_filter.c +2 -19
index e5e724d..60976c0 100644
@@ -177,37 +177,20 @@ static int __init ip6table_filter_init(v
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ip6t_ops[0]);
+	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ip6t_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
-	ret = nf_register_hook(&ip6t_ops[2]);
-	if (ret < 0)
-		goto cleanup_hook1;
-
 	return ret;
 
- cleanup_hook1:
-	nf_unregister_hook(&ip6t_ops[1]);
- cleanup_hook0:
-	nf_unregister_hook(&ip6t_ops[0]);
  cleanup_table:
 	ip6t_unregister_table(&packet_filter);
-
 	return ret;
 }
 
 static void __exit ip6table_filter_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ip6t_ops[i]);
-
+	nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	ip6t_unregister_table(&packet_filter);
 }
 
net/ipv6/netfilter/ip6table_mangle.c +2 -31
index e1f0f6a..03a13ea 100644
@@ -238,49 +238,20 @@ static int __init ip6table_mangle_init(v
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ip6t_ops[0]);
+	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ip6t_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
-	ret = nf_register_hook(&ip6t_ops[2]);
-	if (ret < 0)
-		goto cleanup_hook1;
-
-	ret = nf_register_hook(&ip6t_ops[3]);
-	if (ret < 0)
-		goto cleanup_hook2;
-
-	ret = nf_register_hook(&ip6t_ops[4]);
-	if (ret < 0)
-		goto cleanup_hook3;
-
 	return ret;
 
- cleanup_hook3:
-        nf_unregister_hook(&ip6t_ops[3]);
- cleanup_hook2:
-	nf_unregister_hook(&ip6t_ops[2]);
- cleanup_hook1:
-	nf_unregister_hook(&ip6t_ops[1]);
- cleanup_hook0:
-	nf_unregister_hook(&ip6t_ops[0]);
  cleanup_table:
 	ip6t_unregister_table(&packet_mangler);
-
 	return ret;
 }
 
 static void __exit ip6table_mangle_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ip6t_ops[i]);
-
+	nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	ip6t_unregister_table(&packet_mangler);
 }
 
net/ipv6/netfilter/ip6table_raw.c +2 -13
index 54d1fff..61a7c58 100644
@@ -152,31 +152,20 @@ static int __init ip6table_raw_init(void
 		return ret;
 
 	/* Register hooks */
-	ret = nf_register_hook(&ip6t_ops[0]);
+	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	if (ret < 0)
 		goto cleanup_table;
 
-	ret = nf_register_hook(&ip6t_ops[1]);
-	if (ret < 0)
-		goto cleanup_hook0;
-
 	return ret;
 
- cleanup_hook0:
-	nf_unregister_hook(&ip6t_ops[0]);
  cleanup_table:
 	ip6t_unregister_table(&packet_raw);
-
 	return ret;
 }
 
 static void __exit ip6table_raw_fini(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
-		nf_unregister_hook(&ip6t_ops[i]);
-
+	nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
 	ip6t_unregister_table(&packet_raw);
 }
 
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +48 -95

172 lines not on this page · raw message

#7 lore raw

PATCH 3/12 : Fix section mismatch warnings

In reply to Patrick McHardy

[NETFILTER]: Fix section mismatch warnings

Fix section mismatch warnings caused by netfilter's init_or_cleanup functions used in many places by splitting the init from the cleanup parts.

---
commit 7e7dcfedeec88f2da01af1261c4ecc5a27a9686f
tree 19c9844dce001903774a04a943c61c967a4a9a5f
parent 2f8e62d3a554aee067771c5146a1e29feecd2758
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:35:58 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:35:58 +0200

 net/ipv4/netfilter/ip_conntrack_standalone.c   |   90 +++++++++----------
 net/ipv4/netfilter/ip_nat_standalone.c         |   18 +---
 net/ipv4/netfilter/ip_queue.c                  |   31 +++---
 net/ipv4/netfilter/ipt_CLUSTERIP.c             |   40 +++-----
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |   38 ++++----
 net/ipv6/netfilter/ip6_queue.c                 |   31 +++---
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c |   38 ++++----
 net/netfilter/nf_conntrack_standalone.c        |  115 ++++++++++++------------
 net/netfilter/nfnetlink_log.c                  |   25 ++---
 net/netfilter/nfnetlink_queue.c                |   27 ++----
 10 files changed, 204 insertions(+), 249 deletions(-)
net/ipv4/netfilter/ip_conntrack_standalone.c +44 -46
index adc1a0f..f785529 100644
@@ -776,18 +776,46 @@ static ctl_table ip_ct_net_table[] = {
 EXPORT_SYMBOL(ip_ct_log_invalid);
 #endif /* CONFIG_SYSCTL */
 
-static int init_or_cleanup(int init)
+/* FIXME: Allow NULL functions and sub in pointers to generic for
+   them. --RR */
+int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
+{
+	int ret = 0;
+
+	write_lock_bh(&ip_conntrack_lock);
+	if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
+		ret = -EBUSY;
+		goto out;
+	}
+	ip_ct_protos[proto->proto] = proto;
+ out:
+	write_unlock_bh(&ip_conntrack_lock);
+	return ret;
+}
+
+void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
+{
+	write_lock_bh(&ip_conntrack_lock);
+	ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
+	write_unlock_bh(&ip_conntrack_lock);
+	
+	/* Somebody could be still looking at the proto in bh. */
+	synchronize_net();
+
+	/* Remove all contrack entries for this protocol */
+	ip_ct_iterate_cleanup(kill_proto, &proto->proto);
+}
+
+static int __init ip_conntrack_standalone_init(void)
 {
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry *proc, *proc_exp, *proc_stat;
 #endif
 	int ret = 0;
 
-	if (!init) goto cleanup;
-
 	ret = ip_conntrack_init();
 	if (ret < 0)
-		goto cleanup_nothing;
+		return ret;
 
 #ifdef CONFIG_PROC_FS
 	ret = -ENOMEM;
@@ -819,16 +847,12 @@ static int init_or_cleanup(int init)
 		goto cleanup_hooks;
 	}
 #endif
-
 	return ret;
 
- cleanup:
-	synchronize_net();
 #ifdef CONFIG_SYSCTL
- 	unregister_sysctl_table(ip_ct_sysctl_header);
  cleanup_hooks:
-#endif
 	nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
+#endif
  cleanup_proc_stat:
 #ifdef CONFIG_PROC_FS
 	remove_proc_entry("ip_conntrack", proc_net_stat);
@@ -839,48 +863,22 @@ static int init_or_cleanup(int init)
  cleanup_init:
 #endif /* CONFIG_PROC_FS */
 	ip_conntrack_cleanup();
- cleanup_nothing:
-	return ret;
-}
-
-/* FIXME: Allow NULL functions and sub in pointers to generic for
-   them. --RR */
-int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
-{
-	int ret = 0;
-
-	write_lock_bh(&ip_conntrack_lock);
-	if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
-		ret = -EBUSY;
-		goto out;
-	}
-	ip_ct_protos[proto->proto] = proto;
- out:
-	write_unlock_bh(&ip_conntrack_lock);
 	return ret;
 }
 
-void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
-{
-	write_lock_bh(&ip_conntrack_lock);
-	ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
-	write_unlock_bh(&ip_conntrack_lock);
-	
-	/* Somebody could be still looking at the proto in bh. */
-	synchronize_net();
-
-	/* Remove all contrack entries for this protocol */
-	ip_ct_iterate_cleanup(kill_proto, &proto->proto);
-}
-
-static int __init ip_conntrack_standalone_init(void)
-{
-	return init_or_cleanup(1);
-}
-
 static void __exit ip_conntrack_standalone_fini(void)
 {
-	init_or_cleanup(0);
+	synchronize_net();
+#ifdef CONFIG_SYSCTL
+	unregister_sysctl_table(ip_ct_sysctl_header);
+#endif
+	nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry("ip_conntrack", proc_net_stat);
+	proc_net_remove("ip_conntrack_expect");
+	proc_net_remove("ip_conntrack");
+#endif /* CONFIG_PROC_FS */
+	ip_conntrack_cleanup();
 }
 
 module_init(ip_conntrack_standalone_init);
net/ipv4/netfilter/ip_nat_standalone.c +7 -11
index 5f02f43..8f760b2 100644
@@ -350,14 +350,12 @@ static struct nf_hook_ops ip_nat_ops[] =
 	},
 };
 
-static int init_or_cleanup(int init)
+static int __init ip_nat_standalone_init(void)
 {
 	int ret = 0;
 
 	need_conntrack();
 
-	if (!init) goto cleanup;
-
 #ifdef CONFIG_XFRM
 	BUG_ON(ip_nat_decode_session != NULL);
 	ip_nat_decode_session = nat_decode_session;
@@ -374,8 +372,6 @@ static int init_or_cleanup(int init)
 	}
 	return ret;
 
- cleanup:
-	nf_unregister_hooks(ip_nat_ops, ARRAY_SIZE(ip_nat_ops));
  cleanup_rule_init:
 	ip_nat_rule_cleanup();
  cleanup_decode_session:
@@ -386,14 +382,14 @@ static int init_or_cleanup(int init)
 	return ret;
 }
 
-static int __init ip_nat_standalone_init(void)
-{
-	return init_or_cleanup(1);
-}
-
 static void __exit ip_nat_standalone_fini(void)
 {
-	init_or_cleanup(0);
+	nf_unregister_hooks(ip_nat_ops, ARRAY_SIZE(ip_nat_ops));
+	ip_nat_rule_cleanup();
+#ifdef CONFIG_XFRM
+	ip_nat_decode_session = NULL;
+	synchronize_net();
+#endif
 }
 
 module_init(ip_nat_standalone_init);
net/ipv4/netfilter/ip_queue.c +14 -17
index 896a244..4bcc842 100644
@@ -662,15 +662,11 @@ static struct nf_queue_handler nfqh = {
 	.outfn	= &ipq_enqueue_packet,
 };
 
-static int
-init_or_cleanup(int init)
+static int __init ip_queue_init(void)
 {
 	int status = -ENOMEM;
 	struct proc_dir_entry *proc;
 	
-	if (!init)
-		goto cleanup;
-
 	netlink_register_notifier(&ipq_nl_notifier);
 	ipqnl = netlink_kernel_create(NETLINK_FIREWALL, 0, ipq_rcv_sk,
 				      THIS_MODULE);
@@ -697,11 +693,6 @@ init_or_cleanup(int init)
 	}
 	return status;
 
-cleanup:
-	nf_unregister_queue_handlers(&nfqh);
-	synchronize_net();
-	ipq_flush(NF_DROP);
-	
 cleanup_sysctl:
 	unregister_sysctl_table(ipq_sysctl_header);
 	unregister_netdevice_notifier(&ipq_dev_notifier);
@@ -717,15 +708,21 @@ cleanup_netlink_notifier:
 	return status;
 }
 
-static int __init ip_queue_init(void)
-{
-	
-	return init_or_cleanup(1);
-}
-
 static void __exit ip_queue_fini(void)
 {
-	init_or_cleanup(0);
+	nf_unregister_queue_handlers(&nfqh);
+	synchronize_net();
+	ipq_flush(NF_DROP);
+	
+	unregister_sysctl_table(ipq_sysctl_header);
+	unregister_netdevice_notifier(&ipq_dev_notifier);
+	proc_net_remove(IPQ_PROC_FS_NAME);
+	
+	sock_release(ipqnl->sk_socket);
+	mutex_lock(&ipqnl_mutex);
+	mutex_unlock(&ipqnl_mutex);
+	
+	netlink_unregister_notifier(&ipq_nl_notifier);
 }
 
 MODULE_DESCRIPTION("IPv4 packet queue handler");
net/ipv4/netfilter/ipt_CLUSTERIP.c +14 -26
index e4768a3..aad9d28 100644
@@ -725,22 +725,17 @@ static struct file_operations clusterip_
 
 #endif /* CONFIG_PROC_FS */
 
-static int init_or_cleanup(int fini)
+static int __init ipt_clusterip_init(void)
 {
 	int ret;
 
-	if (fini)
-		goto cleanup;
-
-	if (ipt_register_target(&clusterip_tgt)) {
-		ret = -EINVAL;
-		goto cleanup_none;
-	}
+	ret = ipt_register_target(&clusterip_tgt);
+	if (ret < 0)
+		return ret;
 
-	if (nf_register_hook(&cip_arp_ops) < 0) {
-		ret = -EINVAL;
+	ret = nf_register_hook(&cip_arp_ops);
+	if (ret < 0)
 		goto cleanup_target;
-	}
 
 #ifdef CONFIG_PROC_FS
 	clusterip_procdir = proc_mkdir("ipt_CLUSTERIP", proc_net);
@@ -753,31 +748,24 @@ static int init_or_cleanup(int fini)
 
 	printk(KERN_NOTICE "ClusterIP Version %s loaded successfully\n",
 		CLUSTERIP_VERSION);
-
 	return 0;
 
-cleanup:
-	printk(KERN_NOTICE "ClusterIP Version %s unloading\n",
-		CLUSTERIP_VERSION);
-#ifdef CONFIG_PROC_FS
-	remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
-#endif
 cleanup_hook:
 	nf_unregister_hook(&cip_arp_ops);
 cleanup_target:
 	ipt_unregister_target(&clusterip_tgt);
-cleanup_none:
-	return -EINVAL;
-}
-
-static int __init ipt_clusterip_init(void)
-{
-	return init_or_cleanup(0);
+	return ret;
 }
 
 static void __exit ipt_clusterip_fini(void)
 {
-	init_or_cleanup(1);
+	printk(KERN_NOTICE "ClusterIP Version %s unloading\n",
+		CLUSTERIP_VERSION);
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
+#endif
+	nf_unregister_hook(&cip_arp_ops);
+	ipt_unregister_target(&clusterip_tgt);
 }
 
 module_init(ipt_clusterip_init);
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +19 -19
index 3fadacc..15ebdb6 100644
@@ -432,16 +432,20 @@ struct nf_conntrack_l3proto nf_conntrack
 extern struct nf_conntrack_protocol nf_conntrack_protocol_tcp4;
 extern struct nf_conntrack_protocol nf_conntrack_protocol_udp4;
 extern struct nf_conntrack_protocol nf_conntrack_protocol_icmp;
-static int init_or_cleanup(int init)
+
+MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET));
+MODULE_LICENSE("GPL");
+
+static int __init nf_conntrack_l3proto_ipv4_init(void)
 {
 	int ret = 0;
-
-	if (!init) goto cleanup;
+	
+	need_conntrack();
 
 	ret = nf_register_sockopt(&so_getorigdst);
 	if (ret < 0) {
 		printk(KERN_ERR "Unable to register netfilter socket option\n");
-		goto cleanup_nothing;
+		return ret;
 	}
 
 	ret = nf_conntrack_protocol_register(&nf_conntrack_protocol_tcp4);
@@ -484,13 +488,10 @@ static int init_or_cleanup(int init)
 #endif
 	return ret;
 
- cleanup:
-	synchronize_net();
 #ifdef CONFIG_SYSCTL
- 	unregister_sysctl_table(nf_ct_ipv4_sysctl_header);
  cleanup_hooks:
-#endif
 	nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
+#endif
  cleanup_ipv4:
 	nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
  cleanup_icmp:
@@ -501,22 +502,21 @@ static int init_or_cleanup(int init)
 	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp4);
  cleanup_sockopt:
 	nf_unregister_sockopt(&so_getorigdst);
- cleanup_nothing:
 	return ret;
 }
 
-MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET));
-MODULE_LICENSE("GPL");
-
-static int __init nf_conntrack_l3proto_ipv4_init(void)
-{
-	need_conntrack();
-	return init_or_cleanup(1);
-}
-
 static void __exit nf_conntrack_l3proto_ipv4_fini(void)
 {
-	init_or_cleanup(0);
+	synchronize_net();
+#ifdef CONFIG_SYSCTL
+ 	unregister_sysctl_table(nf_ct_ipv4_sysctl_header);
+#endif
+	nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
+	nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_icmp);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_udp4);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp4);
+	nf_unregister_sockopt(&so_getorigdst);
 }
 
 module_init(nf_conntrack_l3proto_ipv4_init);
net/ipv6/netfilter/ip6_queue.c +14 -17
index e81c6a9..fa23ffe 100644
@@ -658,15 +658,11 @@ static struct nf_queue_handler nfqh = {
 	.outfn	= &ipq_enqueue_packet,
 };
 
-static int
-init_or_cleanup(int init)
+static int __init ip6_queue_init(void)
 {
 	int status = -ENOMEM;
 	struct proc_dir_entry *proc;
 	
-	if (!init)
-		goto cleanup;
-
 	netlink_register_notifier(&ipq_nl_notifier);
 	ipqnl = netlink_kernel_create(NETLINK_IP6_FW, 0, ipq_rcv_sk,
 	                              THIS_MODULE);
@@ -693,11 +689,6 @@ init_or_cleanup(int init)
 	}
 	return status;
 
-cleanup:
-	nf_unregister_queue_handlers(&nfqh);
-	synchronize_net();
-	ipq_flush(NF_DROP);
-	
 cleanup_sysctl:
 	unregister_sysctl_table(ipq_sysctl_header);
 	unregister_netdevice_notifier(&ipq_dev_notifier);
@@ -713,15 +704,21 @@ cleanup_netlink_notifier:
 	return status;
 }
 
-static int __init ip6_queue_init(void)
-{
-	
-	return init_or_cleanup(1);
-}
-
 static void __exit ip6_queue_fini(void)
 {
-	init_or_cleanup(0);
+	nf_unregister_queue_handlers(&nfqh);
+	synchronize_net();
+	ipq_flush(NF_DROP);
+	
+	unregister_sysctl_table(ipq_sysctl_header);
+	unregister_netdevice_notifier(&ipq_dev_notifier);
+	proc_net_remove(IPQ_PROC_FS_NAME);
+	
+	sock_release(ipqnl->sk_socket);
+	mutex_lock(&ipqnl_mutex);
+	mutex_unlock(&ipqnl_mutex);
+	
+	netlink_unregister_notifier(&ipq_nl_notifier);
 }
 
 MODULE_DESCRIPTION("IPv6 packet queue handler");
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +19 -19
index 0426ed0..93bae36 100644
@@ -464,16 +464,21 @@ extern struct nf_conntrack_protocol nf_c
 extern struct nf_conntrack_protocol nf_conntrack_protocol_icmpv6;
 extern int nf_ct_frag6_init(void);
 extern void nf_ct_frag6_cleanup(void);
-static int init_or_cleanup(int init)
+
+MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6));
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Yasuyuki KOZAKAI @USAGI <[email protected]>");
+
+static int __init nf_conntrack_l3proto_ipv6_init(void)
 {
 	int ret = 0;
 
-	if (!init) goto cleanup;
+	need_conntrack();
 
 	ret = nf_ct_frag6_init();
 	if (ret < 0) {
 		printk("nf_conntrack_ipv6: can't initialize frag6.\n");
-		goto cleanup_nothing;
+		return ret;
 	}
 	ret = nf_conntrack_protocol_register(&nf_conntrack_protocol_tcp6);
 	if (ret < 0) {
@@ -516,13 +521,10 @@ static int init_or_cleanup(int init)
 #endif
 	return ret;
 
- cleanup:
-	synchronize_net();
 #ifdef CONFIG_SYSCTL
- 	unregister_sysctl_table(nf_ct_ipv6_sysctl_header);
  cleanup_hooks:
-#endif
 	nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops));
+#endif
  cleanup_ipv6:
 	nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv6);
  cleanup_icmpv6:
@@ -533,23 +535,21 @@ static int init_or_cleanup(int init)
 	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp6);
  cleanup_frag6:
 	nf_ct_frag6_cleanup();
- cleanup_nothing:
 	return ret;
 }
 
-MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6));
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Yasuyuki KOZAKAI @USAGI <[email protected]>");
-
-static int __init nf_conntrack_l3proto_ipv6_init(void)
-{
-	need_conntrack();
-	return init_or_cleanup(1);
-}
-
 static void __exit nf_conntrack_l3proto_ipv6_fini(void)
 {
-	init_or_cleanup(0);
+	synchronize_net();
+#ifdef CONFIG_SYSCTL
+ 	unregister_sysctl_table(nf_ct_ipv6_sysctl_header);
+#endif
+	nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops));
+	nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv6);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_icmpv6);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_udp6);
+	nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp6);
+	nf_ct_frag6_cleanup();
 }
 
 module_init(nf_conntrack_l3proto_ipv6_init);
net/netfilter/nf_conntrack_standalone.c +56 -59

131 lines not on this page · raw message

net/netfilter/nfnetlink_log.c +8 -17
index 3e3f544..c60273c 100644
@@ -1033,17 +1033,13 @@ static struct file_operations nful_file_
 
 #endif /* PROC_FS */
 
-static int
-init_or_cleanup(int init)
+static int __init nfnetlink_log_init(void)
 {
 	int i, status = -ENOMEM;
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry *proc_nful;
 #endif
 	
-	if (!init)
-		goto cleanup;
-
 	for (i = 0; i < INSTANCE_BUCKETS; i++)
 		INIT_HLIST_HEAD(&instance_table[i]);
 	
@@ -1066,30 +1062,25 @@ init_or_cleanup(int init)
 		goto cleanup_subsys;
 	proc_nful->proc_fops = &nful_file_ops;
 #endif
-
 	return status;
 
-cleanup:
-	nf_log_unregister_logger(&nfulnl_logger);
 #ifdef CONFIG_PROC_FS
-	remove_proc_entry("nfnetlink_log", proc_net_netfilter);
 cleanup_subsys:
-#endif
 	nfnetlink_subsys_unregister(&nfulnl_subsys);
+#endif
 cleanup_netlink_notifier:
 	netlink_unregister_notifier(&nfulnl_rtnl_notifier);
 	return status;
 }
 
-static int __init nfnetlink_log_init(void)
-{
-	
-	return init_or_cleanup(1);
-}
-
 static void __exit nfnetlink_log_fini(void)
 {
-	init_or_cleanup(0);
+	nf_log_unregister_logger(&nfulnl_logger);
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry("nfnetlink_log", proc_net_netfilter);
+#endif
+	nfnetlink_subsys_unregister(&nfulnl_subsys);
+	netlink_unregister_notifier(&nfulnl_rtnl_notifier);
 }
 
 MODULE_DESCRIPTION("netfilter userspace logging");
net/netfilter/nfnetlink_queue.c +9 -18
index d0e62f6..b93bcd3 100644
@@ -1071,17 +1071,13 @@ static struct file_operations nfqnl_file
 
 #endif /* PROC_FS */
 
-static int
-init_or_cleanup(int init)
+static int __init nfnetlink_queue_init(void)
 {
 	int i, status = -ENOMEM;
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry *proc_nfqueue;
 #endif
 	
-	if (!init)
-		goto cleanup;
-
 	for (i = 0; i < INSTANCE_BUCKETS; i++)
 		INIT_HLIST_HEAD(&instance_table[i]);
 
@@ -1101,31 +1097,26 @@ init_or_cleanup(int init)
 #endif
 
 	register_netdevice_notifier(&nfqnl_dev_notifier);
-
 	return status;
 
-cleanup:
-	nf_unregister_queue_handlers(&nfqh);
-	unregister_netdevice_notifier(&nfqnl_dev_notifier);
 #ifdef CONFIG_PROC_FS
-	remove_proc_entry("nfnetlink_queue", proc_net_netfilter);
 cleanup_subsys:
-#endif	
 	nfnetlink_subsys_unregister(&nfqnl_subsys);
+#endif	
 cleanup_netlink_notifier:
 	netlink_unregister_notifier(&nfqnl_rtnl_notifier);
 	return status;
 }
 
-static int __init nfnetlink_queue_init(void)
-{
-	
-	return init_or_cleanup(1);
-}
-
 static void __exit nfnetlink_queue_fini(void)
 {
-	init_or_cleanup(0);
+	nf_unregister_queue_handlers(&nfqh);
+	unregister_netdevice_notifier(&nfqnl_dev_notifier);
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry("nfnetlink_queue", proc_net_netfilter);
+#endif	
+	nfnetlink_subsys_unregister(&nfqnl_subsys);
+	netlink_unregister_notifier(&nfqnl_rtnl_notifier);
 }
 
 MODULE_DESCRIPTION("netfilter packet queue handler");
#10 lore raw

PATCH 4/12 : H.323 helper: move some function prototypes to ip_conntrack_h323.h

In reply to Patrick McHardy

[NETFILTER]: H.323 helper: move some function prototypes to ip_conntrack_h323.h

Move prototypes of NAT callbacks to ip_conntrack_h323.h. Because the use of typedefs as arguments, some header files need to be moved as well.

---
commit 02fe897a46c3da14bab9fafeaa99692da6ae7fc1
tree 962f387c169fb4fbb96ab7f78cabfcde4258b810
parent 7e7dcfedeec88f2da01af1261c4ecc5a27a9686f
author Jing Min Zhao <[email protected]> Thu, 06 Apr 2006 11:40:43 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:40:43 +0200

 include/linux/netfilter_ipv4/ip_conntrack_h323.h   |   52 +
 .../netfilter_ipv4/ip_conntrack_helper_h323_asn1.h |   98 ++
 .../ip_conntrack_helper_h323_types.h               |  938 +++++++++++++++++++++++
 net/ipv4/netfilter/ip_conntrack_helper_h323.c      |    2 
 net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c |    2 
 net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h |   98 --
 .../netfilter/ip_conntrack_helper_h323_types.h     |  938 -----------------------
 net/ipv4/netfilter/ip_nat_helper_h323.c            |   53 -
 8 files changed, 1089 insertions(+), 1092 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_h323.h +52 -0
index 0987cea..eace86b 100644
@@ -3,6 +3,8 @@
 
 #ifdef __KERNEL__
 
+#include <linux/netfilter_ipv4/ip_conntrack_helper_h323_asn1.h>
+
 #define RAS_PORT 1719
 #define Q931_PORT 1720
 #define H323_RTP_CHANNEL_MAX 4	/* Audio, video, FAX and other */
@@ -25,6 +27,56 @@ struct ip_ct_h323_master {
 	};
 };
 
+struct ip_conntrack_expect;
+
+extern int get_h225_addr(unsigned char *data, TransportAddress * addr,
+			 u_int32_t * ip, u_int16_t * port);
+extern void ip_conntrack_h245_expect(struct ip_conntrack *new,
+				     struct ip_conntrack_expect *this);
+extern void ip_conntrack_q931_expect(struct ip_conntrack *new,
+				     struct ip_conntrack_expect *this);
+extern int (*set_h245_addr_hook) (struct sk_buff ** pskb,
+				  unsigned char **data, int dataoff,
+				  H245_TransportAddress * addr,
+				  u_int32_t ip, u_int16_t port);
+extern int (*set_h225_addr_hook) (struct sk_buff ** pskb,
+				  unsigned char **data, int dataoff,
+				  TransportAddress * addr,
+				  u_int32_t ip, u_int16_t port);
+extern int (*set_sig_addr_hook) (struct sk_buff ** pskb,
+				 struct ip_conntrack * ct,
+				 enum ip_conntrack_info ctinfo,
+				 unsigned char **data,
+				 TransportAddress * addr, int count);
+extern int (*set_ras_addr_hook) (struct sk_buff ** pskb,
+				 struct ip_conntrack * ct,
+				 enum ip_conntrack_info ctinfo,
+				 unsigned char **data,
+				 TransportAddress * addr, int count);
+extern int (*nat_rtp_rtcp_hook) (struct sk_buff ** pskb,
+				 struct ip_conntrack * ct,
+				 enum ip_conntrack_info ctinfo,
+				 unsigned char **data, int dataoff,
+				 H245_TransportAddress * addr,
+				 u_int16_t port, u_int16_t rtp_port,
+				 struct ip_conntrack_expect * rtp_exp,
+				 struct ip_conntrack_expect * rtcp_exp);
+extern int (*nat_t120_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
+			     enum ip_conntrack_info ctinfo,
+			     unsigned char **data, int dataoff,
+			     H245_TransportAddress * addr, u_int16_t port,
+			     struct ip_conntrack_expect * exp);
+extern int (*nat_h245_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
+			     enum ip_conntrack_info ctinfo,
+			     unsigned char **data, int dataoff,
+			     TransportAddress * addr, u_int16_t port,
+			     struct ip_conntrack_expect * exp);
+extern int (*nat_q931_hook) (struct sk_buff ** pskb, struct ip_conntrack * ct,
+			     enum ip_conntrack_info ctinfo,
+			     unsigned char **data, TransportAddress * addr,
+			     int idx, u_int16_t port,
+			     struct ip_conntrack_expect * exp);
+
 #endif
 
 #endif
include/linux/netfilter_ipv4/ip_conntrack_helper_h323_asn1.h new file +98 -0

98 lines not on this page · raw message

include/linux/netfilter_ipv4/ip_conntrack_helper_h323_types.h new file +938 -0

938 lines not on this page · raw message

net/ipv4/netfilter/ip_conntrack_helper_h323.c +0 -2
index daeb139..fc817fd 100644
@@ -54,8 +54,6 @@
 #include <linux/netfilter_ipv4/ip_conntrack_h323.h>
 #include <linux/moduleparam.h>
 
-#include "ip_conntrack_helper_h323_asn1.h"
-
 #if 0
 #define DEBUGP printk
 #else
net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c +1 -1
index afa5251..4807800 100644
@@ -15,7 +15,7 @@
 #else
 #include <stdio.h>
 #endif
-#include "ip_conntrack_helper_h323_asn1.h"
+#include <linux/netfilter_ipv4/ip_conntrack_helper_h323_asn1.h>
 
 /* Trace Flag */
 #ifndef H323_TRACE
net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.h deleted +0 -98

98 lines not on this page · raw message

net/ipv4/netfilter/ip_conntrack_helper_h323_types.h deleted +0 -938

938 lines not on this page · raw message

net/ipv4/netfilter/ip_nat_helper_h323.c +0 -53

65 lines not on this page · raw message

#12 lore raw

PATCH 5/12 : H.323 helper: change EXPORT_SYMBOL to EXPORT_SYMBOL_GPL

In reply to Patrick McHardy

[NETFILTER]: H.323 helper: change EXPORT_SYMBOL to EXPORT_SYMBOL_GPL

---
commit 3c1284349cc00613a738dbd582e6096236c4a44e
tree d62e9e0c5af6c4efa448c7650642182cbb5a6418
parent 02fe897a46c3da14bab9fafeaa99692da6ae7fc1
author Jing Min Zhao <[email protected]> Thu, 06 Apr 2006 11:41:27 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:41:27 +0200

 net/ipv4/netfilter/ip_conntrack_helper_h323.c |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_h323.c +11 -12
index fc817fd..83140d2 100644
@@ -1711,18 +1711,17 @@ static int __init init(void)
 module_init(init);
 module_exit(fini);
 
-EXPORT_SYMBOL(get_h245_addr);
-EXPORT_SYMBOL(get_h225_addr);
-EXPORT_SYMBOL(ip_conntrack_h245_expect);
-EXPORT_SYMBOL(ip_conntrack_q931_expect);
-EXPORT_SYMBOL(set_h245_addr_hook);
-EXPORT_SYMBOL(set_h225_addr_hook);
-EXPORT_SYMBOL(set_sig_addr_hook);
-EXPORT_SYMBOL(set_ras_addr_hook);
-EXPORT_SYMBOL(nat_rtp_rtcp_hook);
-EXPORT_SYMBOL(nat_t120_hook);
-EXPORT_SYMBOL(nat_h245_hook);
-EXPORT_SYMBOL(nat_q931_hook);
+EXPORT_SYMBOL_GPL(get_h225_addr);
+EXPORT_SYMBOL_GPL(ip_conntrack_h245_expect);
+EXPORT_SYMBOL_GPL(ip_conntrack_q931_expect);
+EXPORT_SYMBOL_GPL(set_h245_addr_hook);
+EXPORT_SYMBOL_GPL(set_h225_addr_hook);
+EXPORT_SYMBOL_GPL(set_sig_addr_hook);
+EXPORT_SYMBOL_GPL(set_ras_addr_hook);
+EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook);
+EXPORT_SYMBOL_GPL(nat_t120_hook);
+EXPORT_SYMBOL_GPL(nat_h245_hook);
+EXPORT_SYMBOL_GPL(nat_q931_hook);
 
 MODULE_AUTHOR("Jing Min Zhao <[email protected]>");
 MODULE_DESCRIPTION("H.323 connection tracking helper");
#14 lore raw

PATCH 6/12 : H.323 helper: make get_h245_addr() static

In reply to Patrick McHardy

[NETFILTER]: H.323 helper: make get_h245_addr() static

---
commit a429b7ed024240e1334b78447e208f71959add62
tree d63e6e4658079356856f7b4bfd6a38529e39ac8e
parent 3c1284349cc00613a738dbd582e6096236c4a44e
author Jing Min Zhao <[email protected]> Thu, 06 Apr 2006 11:42:04 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:42:04 +0200

 net/ipv4/netfilter/ip_conntrack_helper_h323.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_h323.c +2 -2
index 83140d2..11c652f 100644
@@ -220,8 +220,8 @@ static int get_tpkt_data(struct sk_buff 
 }
 
 /****************************************************************************/
-int get_h245_addr(unsigned char *data, H245_TransportAddress * addr,
-		  u_int32_t * ip, u_int16_t * port)
+static int get_h245_addr(unsigned char *data, H245_TransportAddress * addr,
+			 u_int32_t * ip, u_int16_t * port)
 {
 	unsigned char *p;
 
#16 lore raw

PATCH 7/12 : H.323 helper: add parameter 'default_rrq_ttl'

In reply to Patrick McHardy

[NETFILTER]: H.323 helper: add parameter 'default_rrq_ttl'

default_rrq_ttl is used when no TTL is included in the RRQ.

---
commit 58e6febec3e259470b331d97cfe085242d2421c5
tree a4d5bd9755e4cfbe35cadac9ade4246a857be278
parent a429b7ed024240e1334b78447e208f71959add62
author Jing Min Zhao <[email protected]> Thu, 06 Apr 2006 11:43:00 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:00 +0200

 net/ipv4/netfilter/ip_conntrack_helper_h323.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_h323.c +5 -1
index 11c652f..dccc6c3 100644
@@ -61,6 +61,10 @@
 #endif
 
 /* Parameters */
+static unsigned int default_rrq_ttl = 300;
+module_param(default_rrq_ttl, uint, 0600);
+MODULE_PARM_DESC(default_rrq_ttl, "use this TTL if it's missing in RRQ");
+
 static int gkrouted_only = 1;
 module_param(gkrouted_only, int, 0600);
 MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper");
@@ -1300,7 +1304,7 @@ static int process_rrq(struct sk_buff **
 		DEBUGP("ip_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive);
 		info->timeout = rrq->timeToLive;
 	} else
-		info->timeout = 0;
+		info->timeout = default_rrq_ttl;
 
 	return 0;
 }
#18 lore raw

PATCH 8/12 : H.323 helper: update Changelog

In reply to Patrick McHardy

[NETFILTER]: H.323 helper: update Changelog

---
commit 4c164120eecc4d67e0eb6392bbb9f81351c18387
tree 9e710e2bce7e141f181daf1a61be3a989f57f653
parent 58e6febec3e259470b331d97cfe085242d2421c5
author Jing Min Zhao <[email protected]> Thu, 06 Apr 2006 11:43:21 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:21 +0200

 net/ipv4/netfilter/ip_conntrack_helper_h323.c |   15 +++++++++++++++
 net/ipv4/netfilter/ip_nat_helper_h323.c       |    5 +++++
 2 files changed, 20 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_h323.c +15 -0
index dccc6c3..5221685 100644
@@ -40,6 +40,21 @@
  * 	  4. Sort ASN.1 data to avoid forwarding declarations (suggested by
  * 	     Patrick McHardy)
  * 	  5. Reset next TPKT data length in get_tpkt_data()
+ *
+ * 	2006-03-20 - version 0.5
+ * 	  1. Change gkrouted_only default to 1 (Patrick McHardy)
+ * 	  2. Remove #ifndef offsetof in ASN.1 parser (Patrick McHardy)
+ * 	  3. Initialize datalen to 0 in ras_help to silence an incorrect gcc
+ * 	     warning (Patrick McHardy)
+ *
+ * 	2006-03-22 - version 0.6
+ * 	  1. get_h225_addr incorrectly defined as 'static' (found by
+ * 	     Andrew Morton)
+ *
+ * 	2006-03-25 - version 0.7
+ * 	  1. Added new parameter 'default_rrq_ttl'.
+ * 	  2. Made get_h245_addr static (suggested by Adrian Bunk)
+ * 	  3. Changed to use EXPORT_SYMBOL_GPL (suggested by Adrian Bunk)
  */
 
 #include <linux/config.h>
net/ipv4/netfilter/ip_nat_helper_h323.c +5 -0
index 6f19c20..c96f15f 100644
@@ -25,6 +25,11 @@
  * 	2006-03-15 - version 0.4
  * 	  1. Added support for T.120 channels
  * 	  2. Added parameter gkrouted_only (suggested by Patrick McHardy)
+ *
+ * 	2006-03-25 - version 0.7
+ * 	  1. Made get_h245_addr static (suggested by Adrian Bunk)
+ * 	  2. Move some extern function prototypes to ip_conntrack_h323.h
+ * 	     (suggested by Adrian Bunk)
  */
 
 #include <linux/module.h>
#21 lore raw

PATCH 9/12 : Fix IP_NF_CONNTRACK_NETLINK dependency

In reply to Patrick McHardy

[NETFILTER]: Fix IP_NF_CONNTRACK_NETLINK dependency

When NAT is built as a module, ip_conntrack_netlink can not be linked statically.

---
commit c9cb4249431b37ed45e69f20a5faa2735933feeb
tree 7321ed9625f9163b6b8a3dd921510197c89681fe
parent 4c164120eecc4d67e0eb6392bbb9f81351c18387
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:35 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:35 +0200

 net/ipv4/netfilter/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/ipv4/netfilter/Kconfig +1 -0
index 77855cc..c60fd5c 100644
@@ -69,6 +69,7 @@ config IP_NF_CONNTRACK_NETLINK
 	tristate 'Connection tracking netlink interface (EXPERIMENTAL)'
 	depends on EXPERIMENTAL && IP_NF_CONNTRACK && NETFILTER_NETLINK
 	depends on IP_NF_CONNTRACK!=y || NETFILTER_NETLINK!=m
+	depends on IP_NF_NAT=n || IP_NF_NAT
 	help
 	  This option enables support for a netlink-based userspace interface
 
#23 lore raw

PATCH 10/12 : Introduce infrastructure for address family specific operations

In reply to Patrick McHardy

[NETFILTER]: Introduce infrastructure for address family specific operations

Change the queue rerouter intrastructure to a generic usable infrastructure for address family specific operations as a base for some cleanups.

---
commit 6a870bcf3e2ee0394ee23cb1ca32de2195edf86d
tree a5e7a46f323f8b9e24c52d546b9d7fcc69f8273c
parent c9cb4249431b37ed45e69f20a5faa2735933feeb
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:48 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:48 +0200

 include/linux/netfilter.h |   23 +++++++++++++++------
 net/ipv4/netfilter.c      |   17 ++++++++--------
 net/ipv6/netfilter.c      |   17 ++++++++--------
 net/netfilter/core.c      |   23 +++++++++++++++++++++
 net/netfilter/nf_queue.c  |   49 ++++++++++++---------------------------------
 5 files changed, 70 insertions(+), 59 deletions(-)
include/linux/netfilter.h +16 -7
index 5aa9316..6ee168c 100644
@@ -283,16 +283,25 @@ extern void nf_invalidate_cache(int pf);
    Returns true or false. */
 extern int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len);
 
-struct nf_queue_rerouter {
-	void (*save)(const struct sk_buff *skb, struct nf_info *info);
-	int (*reroute)(struct sk_buff **skb, const struct nf_info *info);
-	int rer_size;
+struct nf_afinfo {
+	unsigned short	family;
+	void		(*saveroute)(const struct sk_buff *skb,
+				     struct nf_info *info);
+	int		(*reroute)(struct sk_buff **skb,
+				   const struct nf_info *info);
+	int		route_key_size;
 };
 
-#define nf_info_reroute(x) ((void *)x + sizeof(struct nf_info))
+extern struct nf_afinfo *nf_afinfo[];
+static inline struct nf_afinfo *nf_get_afinfo(unsigned short family)
+{
+	return rcu_dereference(nf_afinfo[family]);
+}
 
-extern int nf_register_queue_rerouter(int pf, struct nf_queue_rerouter *rer);
-extern int nf_unregister_queue_rerouter(int pf);
+extern int nf_register_afinfo(struct nf_afinfo *afinfo);
+extern void nf_unregister_afinfo(struct nf_afinfo *afinfo);
+
+#define nf_info_reroute(x) ((void *)x + sizeof(struct nf_info))
 
 #include <net/flow.h>
 extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *);
net/ipv4/netfilter.c +9 -8
index b5ad9ac..b25339c 100644
@@ -133,7 +133,7 @@ struct ip_rt_info {
 	u_int8_t tos;
 };
 
-static void queue_save(const struct sk_buff *skb, struct nf_info *info)
+static void nf_ip_saveroute(const struct sk_buff *skb, struct nf_info *info)
 {
 	struct ip_rt_info *rt_info = nf_info_reroute(info);
 
@@ -146,7 +146,7 @@ static void queue_save(const struct sk_b
 	}
 }
 
-static int queue_reroute(struct sk_buff **pskb, const struct nf_info *info)
+static int nf_ip_reroute(struct sk_buff **pskb, const struct nf_info *info)
 {
 	const struct ip_rt_info *rt_info = nf_info_reroute(info);
 
@@ -161,20 +161,21 @@ static int queue_reroute(struct sk_buff 
 	return 0;
 }
 
-static struct nf_queue_rerouter ip_reroute = {
-	.rer_size	= sizeof(struct ip_rt_info),
-	.save		= queue_save,
-	.reroute	= queue_reroute,
+static struct nf_afinfo nf_ip_afinfo = {
+	.family		= AF_INET,
+	.saveroute	= nf_ip_saveroute,
+	.reroute	= nf_ip_reroute,
+	.route_key_size	= sizeof(struct ip_rt_info),
 };
 
 static int ipv4_netfilter_init(void)
 {
-	return nf_register_queue_rerouter(PF_INET, &ip_reroute);
+	return nf_register_afinfo(&nf_ip_afinfo);
 }
 
 static void ipv4_netfilter_fini(void)
 {
-	nf_unregister_queue_rerouter(PF_INET);
+	nf_unregister_afinfo(&nf_ip_afinfo);
 }
 
 module_init(ipv4_netfilter_init);
net/ipv6/netfilter.c +9 -8
index d750cfc..f514a01 100644
@@ -54,7 +54,7 @@ struct ip6_rt_info {
 	struct in6_addr saddr;
 };
 
-static void save(const struct sk_buff *skb, struct nf_info *info)
+static void nf_ip6_saveroute(const struct sk_buff *skb, struct nf_info *info)
 {
 	struct ip6_rt_info *rt_info = nf_info_reroute(info);
 
@@ -66,7 +66,7 @@ static void save(const struct sk_buff *s
 	}
 }
 
-static int reroute(struct sk_buff **pskb, const struct nf_info *info)
+static int nf_ip6_reroute(struct sk_buff **pskb, const struct nf_info *info)
 {
 	struct ip6_rt_info *rt_info = nf_info_reroute(info);
 
@@ -79,15 +79,16 @@ static int reroute(struct sk_buff **pskb
 	return 0;
 }
 
-static struct nf_queue_rerouter ip6_reroute = {
-	.rer_size	= sizeof(struct ip6_rt_info),
-	.save 		= &save,
-	.reroute	= &reroute,
+static struct nf_afinfo nf_ip6_afinfo = {
+	.family		= AF_INET6,
+	.saveroute	= nf_ip6_saveroute,
+	.reroute	= nf_ip6_reroute,
+	.route_key_size	= sizeof(struct ip6_rt_info),
 };
 
 int __init ipv6_netfilter_init(void)
 {
-	return nf_register_queue_rerouter(PF_INET6, &ip6_reroute);
+	return nf_register_afinfo(&nf_ip6_afinfo);
 }
 
 /* This can be called from inet6_init() on errors, so it cannot
@@ -95,5 +96,5 @@ int __init ipv6_netfilter_init(void)
  */
 void ipv6_netfilter_fini(void)
 {
-	nf_unregister_queue_rerouter(PF_INET6);
+	nf_unregister_afinfo(&nf_ip6_afinfo);
 }
net/netfilter/core.c +23 -0
index 5c7143e..dceed88 100644
@@ -27,6 +27,29 @@
 
 #include "nf_internals.h"
 
+static DEFINE_SPINLOCK(afinfo_lock);
+
+struct nf_afinfo *nf_afinfo[NPROTO];
+EXPORT_SYMBOL(nf_afinfo);
+
+int nf_register_afinfo(struct nf_afinfo *afinfo)
+{
+	spin_lock(&afinfo_lock);
+	rcu_assign_pointer(nf_afinfo[afinfo->family], afinfo);
+	spin_unlock(&afinfo_lock);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nf_register_afinfo);
+
+void nf_unregister_afinfo(struct nf_afinfo *afinfo)
+{
+	spin_lock(&afinfo_lock);
+	rcu_assign_pointer(nf_afinfo[afinfo->family], NULL);
+	spin_unlock(&afinfo_lock);
+	synchronize_rcu();
+}
+EXPORT_SYMBOL_GPL(nf_unregister_afinfo);
+
 /* In this code, we can be waiting indefinitely for userspace to
  * service a packet if a hook returns NF_QUEUE.  We could keep a count
  * of skbuffs queued for userspace, and not deregister a hook unless
net/netfilter/nf_queue.c +13 -36

91 lines not on this page · raw message

#25 lore raw

PATCH 11/12 : Add address family specific checksum helpers

In reply to Patrick McHardy

[NETFILTER]: Add address family specific checksum helpers

Add checksum operation which takes care of verifying the checksum and dealing with HW checksum errors and avoids multiple checksum operations by setting ip_summed to CHECKSUM_UNNECESSARY after successful verification.

---
commit b204de98f3e9d2f9d47141c6a1036a2a27729329
tree baf5ff3876cccf6b875f2c5d794d6fe9becd17b3
parent 6a870bcf3e2ee0394ee23cb1ca32de2195edf86d
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:58 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:43:58 +0200

 include/linux/netfilter.h      |   17 +++++++++++++++++
 include/linux/netfilter_ipv4.h |    2 ++
 include/linux/netfilter_ipv6.h |    3 +++
 net/ipv4/netfilter.c           |   33 +++++++++++++++++++++++++++++++++
 net/ipv6/netfilter.c           |   34 ++++++++++++++++++++++++++++++++++
 5 files changed, 89 insertions(+), 0 deletions(-)
include/linux/netfilter.h +17 -0
index 6ee168c..b31a9bc 100644
@@ -285,6 +285,8 @@ extern int skb_make_writable(struct sk_b
 
 struct nf_afinfo {
 	unsigned short	family;
+	unsigned int	(*checksum)(struct sk_buff *skb, unsigned int hook,
+				    unsigned int dataoff, u_int8_t protocol);
 	void		(*saveroute)(const struct sk_buff *skb,
 				     struct nf_info *info);
 	int		(*reroute)(struct sk_buff **skb,
@@ -298,6 +300,21 @@ static inline struct nf_afinfo *nf_get_a
 	return rcu_dereference(nf_afinfo[family]);
 }
 
+static inline unsigned int
+nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff,
+	    u_int8_t protocol, unsigned short family)
+{
+	struct nf_afinfo *afinfo;
+	unsigned int csum = 0;
+
+	rcu_read_lock();
+	afinfo = nf_get_afinfo(family);
+	if (afinfo)
+		csum = afinfo->checksum(skb, hook, dataoff, protocol);
+	rcu_read_unlock();
+	return csum;
+}
+
 extern int nf_register_afinfo(struct nf_afinfo *afinfo);
 extern void nf_unregister_afinfo(struct nf_afinfo *afinfo);
 
include/linux/netfilter_ipv4.h +2 -0
index 43c09d7..85301c5 100644
@@ -80,6 +80,8 @@ enum nf_ip_hook_priorities {
 #ifdef __KERNEL__
 extern int ip_route_me_harder(struct sk_buff **pskb);
 extern int ip_xfrm_me_harder(struct sk_buff **pskb);
+extern unsigned int nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
+				   unsigned int dataoff, u_int8_t protocol);
 #endif /*__KERNEL__*/
 
 #endif /*__LINUX_IP_NETFILTER_H*/
include/linux/netfilter_ipv6.h +3 -0
index 14f2bd0..52a7b9e 100644
@@ -73,6 +73,9 @@ enum nf_ip6_hook_priorities {
 };
 
 #ifdef CONFIG_NETFILTER
+extern unsigned int nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
+				    unsigned int dataoff, u_int8_t protocol);
+
 extern int ipv6_netfilter_init(void);
 extern void ipv6_netfilter_fini(void);
 #else /* CONFIG_NETFILTER */
net/ipv4/netfilter.c +33 -0
index b25339c..6a9e34b 100644
@@ -161,8 +161,41 @@ static int nf_ip_reroute(struct sk_buff 
 	return 0;
 }
 
+unsigned int nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
+			    unsigned int dataoff, u_int8_t protocol)
+{
+	struct iphdr *iph = skb->nh.iph;
+	unsigned int csum = 0;
+
+	switch (skb->ip_summed) {
+	case CHECKSUM_HW:
+		if (hook != NF_IP_PRE_ROUTING && hook != NF_IP_LOCAL_IN)
+			break;
+		if ((protocol == 0 && !(u16)csum_fold(skb->csum)) ||
+		    !csum_tcpudp_magic(iph->saddr, iph->daddr,
+			    	       skb->len - dataoff, protocol,
+				       skb->csum)) {
+			skb->ip_summed = CHECKSUM_UNNECESSARY;
+			break;
+		}
+		/* fall through */
+	case CHECKSUM_NONE:
+		if (protocol == 0)
+			skb->csum = 0;
+		else
+			skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
+						       skb->len - dataoff,
+						       protocol, 0);
+		csum = __skb_checksum_complete(skb);
+	}
+	return csum;
+}
+
+EXPORT_SYMBOL(nf_ip_checksum);
+
 static struct nf_afinfo nf_ip_afinfo = {
 	.family		= AF_INET,
+	.checksum	= nf_ip_checksum,
 	.saveroute	= nf_ip_saveroute,
 	.reroute	= nf_ip_reroute,
 	.route_key_size	= sizeof(struct ip_rt_info),
net/ipv6/netfilter.c +34 -0
index f514a01..3e9ecfa 100644
@@ -79,8 +79,42 @@ static int nf_ip6_reroute(struct sk_buff
 	return 0;
 }
 
+unsigned int nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
+			     unsigned int dataoff, u_int8_t protocol)
+{
+	struct ipv6hdr *ip6h = skb->nh.ipv6h;
+	unsigned int csum = 0;
+
+	switch (skb->ip_summed) {
+	case CHECKSUM_HW:
+		if (hook != NF_IP6_PRE_ROUTING && hook != NF_IP6_LOCAL_IN)
+			break;
+		if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
+			    	     skb->len - dataoff, protocol,
+				     csum_sub(skb->csum,
+					      skb_checksum(skb, 0,
+							   dataoff, 0)))) {
+			skb->ip_summed = CHECKSUM_UNNECESSARY;
+			break;
+		}
+		/* fall through */
+	case CHECKSUM_NONE:
+		skb->csum = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
+					     skb->len - dataoff,
+					     protocol,
+					     csum_sub(0,
+						      skb_checksum(skb, 0,
+							           dataoff, 0)));
+		csum = __skb_checksum_complete(skb);
+	}
+	return csum;
+}
+
+EXPORT_SYMBOL(nf_ip6_checksum);
+
 static struct nf_afinfo nf_ip6_afinfo = {
 	.family		= AF_INET6,
+	.checksum	= nf_ip6_checksum,
 	.saveroute	= nf_ip6_saveroute,
 	.reroute	= nf_ip6_reroute,
 	.route_key_size	= sizeof(struct ip6_rt_info),
#27 lore raw

PATCH 12/12 : Convert conntrack/ipt_REJECT to new checksumming functions

In reply to Patrick McHardy

[NETFILTER]: Convert conntrack/ipt_REJECT to new checksumming functions

Besides removing lots of duplicate code, all converted users benefit from improved HW checksum error handling. Tested with and without HW checksums in almost all combinations.

---
commit 841bf618050f12d9230c6fee4186c632b3bf786a
tree 6af5e18f6f57ee30e011a59d689df94008775660
parent b204de98f3e9d2f9d47141c6a1036a2a27729329
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:44:05 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:44:05 +0200

 net/ipv4/netfilter/ip_conntrack_proto_icmp.c   |   23 +++--------
 net/ipv4/netfilter/ip_conntrack_proto_tcp.c    |    7 +--
 net/ipv4/netfilter/ip_conntrack_proto_udp.c    |    7 +--
 net/ipv4/netfilter/ipt_REJECT.c                |    9 ----
 net/ipv4/netfilter/nf_conntrack_proto_icmp.c   |   20 +---------
 net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c |   12 +-----
 net/netfilter/nf_conntrack_proto_tcp.c         |   50 ++----------------------
 net/netfilter/nf_conntrack_proto_udp.c         |   50 ++----------------------
 8 files changed, 25 insertions(+), 153 deletions(-)
net/ipv4/netfilter/ip_conntrack_proto_icmp.c +6 -17
index 3021af0..d8b14a9 100644
@@ -224,25 +224,14 @@ icmp_error(struct sk_buff *skb, enum ip_
 	}
 
 	/* See ip_conntrack_proto_tcp.c */
-	if (hooknum != NF_IP_PRE_ROUTING)
-		goto checksum_skipped;
-
-	switch (skb->ip_summed) {
-	case CHECKSUM_HW:
-		if (!(u16)csum_fold(skb->csum)) 
-			break;
-		/* fall through */
-	case CHECKSUM_NONE:
-		skb->csum = 0;
-		if (__skb_checksum_complete(skb)) {
-			if (LOG_INVALID(IPPROTO_ICMP))
-				nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
-					      "ip_ct_icmp: bad ICMP checksum ");
-			return -NF_ACCEPT;
-		}
+	if (hooknum == NF_IP_PRE_ROUTING &&
+	    nf_ip_checksum(skb, hooknum, skb->nh.iph->ihl * 4, 0)) {
+		if (LOG_INVALID(IPPROTO_ICMP))
+			nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
+				      "ip_ct_icmp: bad ICMP checksum ");
+		return -NF_ACCEPT;
 	}
 
-checksum_skipped:
 	/*
 	 *	18 is the highest 'known' ICMP type. Anything else is a mystery
 	 *
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +2 -5
index e0dc370..062b252 100644
@@ -870,11 +870,8 @@ static int tcp_error(struct sk_buff *skb
 	 * and moreover root might send raw packets.
 	 */
 	/* FIXME: Source route IP option packets --RR */
-	if (hooknum == NF_IP_PRE_ROUTING
-	    && skb->ip_summed != CHECKSUM_UNNECESSARY
-	    && csum_tcpudp_magic(iph->saddr, iph->daddr, tcplen, IPPROTO_TCP,
-			         skb->ip_summed == CHECKSUM_HW ? skb->csum
-			      	 : skb_checksum(skb, iph->ihl*4, tcplen, 0))) {
+	if (hooknum == NF_IP_PRE_ROUTING &&
+	    nf_ip_checksum(skb, hooknum, iph->ihl * 4, IPPROTO_TCP)) {
 		if (LOG_INVALID(IPPROTO_TCP))
 			nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
 				  "ip_ct_tcp: bad TCP checksum ");
net/ipv4/netfilter/ip_conntrack_proto_udp.c +2 -5
index 55b7d32..7089986 100644
@@ -120,11 +120,8 @@ static int udp_error(struct sk_buff *skb
 	 * because the semantic of CHECKSUM_HW is different there 
 	 * and moreover root might send raw packets.
 	 * FIXME: Source route IP option packets --RR */
-	if (hooknum == NF_IP_PRE_ROUTING
-	    && skb->ip_summed != CHECKSUM_UNNECESSARY
-	    && csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
-			         skb->ip_summed == CHECKSUM_HW ? skb->csum
-			      	 : skb_checksum(skb, iph->ihl*4, udplen, 0))) {
+	if (hooknum == NF_IP_PRE_ROUTING &&
+	    nf_ip_checksum(skb, hooknum, iph->ihl * 4, IPPROTO_UDP)) {
 		if (LOG_INVALID(IPPROTO_UDP))
 			nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
 				  "ip_ct_udp: bad UDP checksum ");
net/ipv4/netfilter/ipt_REJECT.c +1 -8
index 4269a54..0bba3c2 100644
@@ -106,7 +106,6 @@ static void send_reset(struct sk_buff *o
 	struct rtable *rt;
 	u_int16_t tmp_port;
 	u_int32_t tmp_addr;
-	unsigned int tcplen;
 	int needs_ack;
 	int hh_len;
 
@@ -124,13 +123,7 @@ static void send_reset(struct sk_buff *o
 		return;
 
 	/* Check checksum */
-	tcplen = oldskb->len - iph->ihl * 4;
-	if (((hook != NF_IP_LOCAL_IN && oldskb->ip_summed != CHECKSUM_HW) ||
-	     (hook == NF_IP_LOCAL_IN &&
-	      oldskb->ip_summed != CHECKSUM_UNNECESSARY)) &&
-	    csum_tcpudp_magic(iph->saddr, iph->daddr, tcplen, IPPROTO_TCP,
-	                      oldskb->ip_summed == CHECKSUM_HW ? oldskb->csum :
-	                      skb_checksum(oldskb, iph->ihl * 4, tcplen, 0)))
+	if (nf_ip_checksum(oldskb, hook, iph->ihl * 4, IPPROTO_TCP))
 		return;
 
 	if ((rt = route_reverse(oldskb, oth, hook)) == NULL)
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +2 -18
index 52dc175..4b0d361 100644
@@ -235,30 +235,14 @@ icmp_error(struct sk_buff *skb, unsigned
 	}
 
 	/* See ip_conntrack_proto_tcp.c */
-	if (hooknum != NF_IP_PRE_ROUTING)
-		goto checksum_skipped;
-
-	switch (skb->ip_summed) {
-	case CHECKSUM_HW:
-		if (!(u16)csum_fold(skb->csum))
-			break;
+	if (hooknum == NF_IP_PRE_ROUTING &&
+	    nf_ip_checksum(skb, hooknum, dataoff, 0)) {
 		if (LOG_INVALID(IPPROTO_ICMP))
 			nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
 				      "nf_ct_icmp: bad HW ICMP checksum ");
 		return -NF_ACCEPT;
-	case CHECKSUM_NONE:
-		if ((u16)csum_fold(skb_checksum(skb, 0, skb->len, 0))) {
-			if (LOG_INVALID(IPPROTO_ICMP))
-				nf_log_packet(PF_INET, 0, skb, NULL, NULL,
-					      NULL,
-					      "nf_ct_icmp: bad ICMP checksum ");
-			return -NF_ACCEPT;
-		}
-	default:
-		break;
 	}
 
-checksum_skipped:
 	/*
 	 *	18 is the highest 'known' ICMP type. Anything else is a mystery
 	 *
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +2 -10
index 09945c3..86c6703 100644
@@ -233,21 +233,13 @@ icmpv6_error(struct sk_buff *skb, unsign
 		return -NF_ACCEPT;
 	}
 
-	if (hooknum != NF_IP6_PRE_ROUTING)
-		goto skipped;
-
-	/* Ignore it if the checksum's bogus. */
-	if (csum_ipv6_magic(&skb->nh.ipv6h->saddr, &skb->nh.ipv6h->daddr,
-			    skb->len - dataoff, IPPROTO_ICMPV6,
-			    skb_checksum(skb, dataoff,
-					 skb->len - dataoff, 0))) {
+	if (hooknum == NF_IP6_PRE_ROUTING &&
+	    nf_ip6_checksum(skb, hooknum, dataoff, IPPROTO_ICMPV6)) {
 		nf_log_packet(PF_INET6, 0, skb, NULL, NULL, NULL,
 			      "nf_ct_icmpv6: ICMPv6 checksum failed\n");
 		return -NF_ACCEPT;
 	}
 
-skipped:
-
 	/* is not error message ? */
 	if (icmp6h->icmp6_type >= 128)
 		return NF_ACCEPT;
net/netfilter/nf_conntrack_proto_tcp.c +5 -45

80 lines not on this page · raw message

net/netfilter/nf_conntrack_proto_udp.c +5 -45

80 lines not on this page · raw message

#2 lore raw

Re: [NETFILTER 01/12]: Add helper functions for mass hook registration/unregistration

In reply to Patrick McHardy

net/netfilter/core.c void nf_unregister_hook(struct nf_hook_o · line 80

Quoted 3 lines
net/netfilter/core.c +3 -0
+err:
+	if (i > 0)
+		nf_unregister_hooks(reg, i - i);
                                         ^^^^^

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return err;
+}

That should make it a nice noop. :-)
Change the line to:
+ nf_unregister_hooks(reg, i);

/Jones

#3 lore raw

Re: [NETFILTER 01/12]: Add helper functions for mass hook registration/unregistration

Review

Quoted 13 lines · Jones Desougi

Review

Quoted 3 lines
(quoted diff) +3 -0
+err:
+	if (i > 0)
+		nf_unregister_hooks(reg, i - i);
                                         ^^^^^

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return err;
+}

That should make it a nice noop. :-)
Change the line to:

(quoted diff) +1 -0
+		nf_unregister_hooks(reg, i);

One typo and one thinko, good catch. I wonder why it didn't crash in my tests, I did try unloading and reloading.

Corrected patch attached.

[NETFILTER]: Add helper functions for mass hook registration/unregistration

---
commit 3bf0d209e539917efcc5286b8f1cab2856ebdd49
tree 4c5840cf32ee69cc6138534d24c4d43a23fad557
parent 32a976a8703b098e898a9a13f9ddcabbf654e7d8
author Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:32:05 +0200 committer Patrick McHardy <[email protected]> Thu, 06 Apr 2006 11:32:05 +0200

 include/linux/netfilter.h |    2 ++
 net/netfilter/core.c      |   28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
include/linux/netfilter.h +2 -0
index 412e52c..5aa9316 100644
@@ -110,6 +110,8 @@ struct nf_info
 /* Function to register/unregister hook points. */
 int nf_register_hook(struct nf_hook_ops *reg);
 void nf_unregister_hook(struct nf_hook_ops *reg);
+int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
+void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
 
 /* Functions to register get/setsockopt ranges (non-inclusive).  You
    need to check permissions yourself! */
net/netfilter/core.c +28 -0
index 1ceb1a6..5c7143e 100644
@@ -63,6 +63,34 @@ void nf_unregister_hook(struct nf_hook_o
 }
 EXPORT_SYMBOL(nf_unregister_hook);
 
+int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+	unsigned int i;
+	int err = 0;
+
+	for (i = 0; i < n; i++) {
+		err = nf_register_hook(&reg[i]);
+		if (err)
+			goto err;
+	}
+	return err;
+
+err:
+	if (i > 0)
+		nf_unregister_hooks(reg, i);
+	return err;
+}
+EXPORT_SYMBOL(nf_register_hooks);
+
+void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+	unsigned int i;
+
+	for (i = 0; i < n; i++)
+		nf_unregister_hook(&reg[i]);
+}
+EXPORT_SYMBOL(nf_unregister_hooks);
+
 unsigned int nf_iterate(struct list_head *head,
 			struct sk_buff **skb,
 			int hook,
maintainer Applied
#4 lore raw

Re: [NETFILTER 01/12]: Add helper functions for mass hook registration/unregistration

From: Patrick McHardy <[email protected]>
Date: Thu, 06 Apr 2006 18:10:02 +0200

Quoted 1 line

Corrected patch attached.

Applied, thanks.

maintainer Applied
#8 lore raw

Re: [NETFILTER 03/12]: Fix section mismatch warnings

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:04:56 +0200 (MEST)

Quoted 7 lines

[NETFILTER]: Fix section mismatch warnings

Fix section mismatch warnings caused by netfilter's init_or_cleanup functions used in many places by splitting the init from the cleanup parts.

Applied, but lots of trailing whitespace I had to clean up before applying. Please test your patches with:

   git apply --check --whitespace=error-all $1

Thanks.

maintainer Applied
#11 lore raw

Re: [NETFILTER 04/12]: H.323 helper: move some function prototypes to ip_conntrack_h323.h

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:04:58 +0200 (MEST)

Quoted 7 lines

[NETFILTER]: H.323 helper: move some function prototypes to ip_conntrack_h323.h

Move prototypes of NAT callbacks to ip_conntrack_h323.h. Because the use of typedefs as arguments, some header files need to be moved as well.

Applied, thanks.

maintainer
#19 lore raw

Re: [NETFILTER 08/12]: H.323 helper: update Changelog

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:05:04 +0200 (MEST)

Quoted 4 lines

[NETFILTER]: H.323 helper: update Changelog

This doesn't make any sense. We have source revision control for keeping this kind of information around, so adding it to the source file is unnecessary duplication.

I'm not applying this, sorry.

maintainer Applied
#24 lore raw

Re: [NETFILTER 10/12]: Introduce infrastructure for address family specific operations

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:05:07 +0200 (MEST)

Quoted 6 lines

[NETFILTER]: Introduce infrastructure for address family specific operations

Change the queue rerouter intrastructure to a generic usable infrastructure for address family specific operations as a base for some cleanups.

Applied, thanks.

maintainer Applied
#26 lore raw

Re: [NETFILTER 11/12]: Add address family specific checksum helpers

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:05:08 +0200 (MEST)

Quoted 7 lines

[NETFILTER]: Add address family specific checksum helpers

Add checksum operation which takes care of verifying the checksum and dealing with HW checksum errors and avoids multiple checksum operations by setting ip_summed to CHECKSUM_UNNECESSARY after successful verification.

Applied, thanks.

maintainer
#28 lore raw

Re: [NETFILTER 12/12]: Convert conntrack/ipt_REJECT to new checksumming functions

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:05:09 +0200 (MEST)

Quoted 7 lines

[NETFILTER]: Convert conntrack/ipt_REJECT to new checksumming functions

Besides removing lots of duplicate code, all converted users benefit from improved HW checksum error handling. Tested with and without HW checksums in almost all combinations.

Also applied, thanks a lot Patrick.

#20 lore raw

Re: [NETFILTER 08/12]: H.323 helper: update Changelog

In reply to David S. Miller
Quoted 10 lines · David S. Miller

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:05:04 +0200 (MEST)

Quoted 4 lines

[NETFILTER]: H.323 helper: update Changelog

Quoted 5 lines

This doesn't make any sense. We have source revision control for keeping this kind of information around, so adding it to the source file is unnecessary duplication.

I'm not applying this, sorry.

Fine with me, I already suggested to Jing Min to remove the changelogs. Just tried to be polite by letting the decision up to him :)

#9 lore raw

Re: [NETFILTER 03/12]: Fix section mismatch warnings

In reply to David S. Miller
Quoted 10 lines · David S. Miller

From: Patrick McHardy <[email protected]>
Date: Thu, 6 Apr 2006 12:04:56 +0200 (MEST)

Quoted 6 lines

[NETFILTER]: Fix section mismatch warnings

Fix section mismatch warnings caused by netfilter's init_or_cleanup functions used in many places by splitting the init from the cleanup parts.

Quoted 7 lines
Quoted 1 line

Applied, but lots of trailing whitespace I had to clean up before applying. Please test your patches with:

   git apply --check --whitespace=error-all $1

Sorry, I know you already mentioned this. I already had the feeling something is wrong with my whitespace-stripping regexes recently, but didn't investigate. Most of my scripts need a rework anyway, I'll make sure to fix this before submitting the next batch.