Skip to contentSkip to conversation

netfilter: SNMP conntrack module

RFC PATCH In review Jiri Olsa 3 participants 8 messages Jan 14, 2011 – Jan 18, 2011

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

RFC PATCH 1/1 netfilter: SNMP conntrack module

hi,

attached patch adds SNMP conntrack module to the netfilter.

I refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 5 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.

The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

The patch tries to implement the "second best choice".

In case the 'second best choice' is not good enough anyway, could you please outline the first one in more detail..?

Also the patch is not adding the "help" function to the shared module, since I'm not sure where to put it. If the idea of the patch would be acceptable, could you please suggest the shared module for the 'help' function?

Also I'm not netfilter expert, the patch might have some issues..

thanks,
jirka

---
 include/linux/netfilter/nf_conntrack_snmp.h |    9 ++
 net/ipv4/netfilter/Kconfig                  |    3 +-
 net/ipv4/netfilter/nf_nat_snmp_basic.c      |    9 +-
 net/netfilter/Kconfig                       |   14 +++
 net/netfilter/Makefile                      |    1 +
 net/netfilter/nf_conntrack_snmp.c           |  141 +++++++++++++++++++++++++++
 6 files changed, 172 insertions(+), 5 deletions(-)
include/linux/netfilter/nf_conntrack_snmp.h new file +9 -0
new file mode 100644
index 0000000..064bc63
@@ -0,0 +1,9 @@
+#ifndef _NF_CONNTRACK_SNMP_H
+#define _NF_CONNTRACK_SNMP_H
+
+extern int (*nf_nat_snmp_hook)(struct sk_buff *skb,
+				unsigned int protoff,
+				struct nf_conn *ct,
+				enum ip_conntrack_info ctinfo);
+
+#endif /* _NF_CONNTRACK_SNMP_H */
net/ipv4/netfilter/Kconfig +2 -1
index babd1a2..f926a31 100644
@@ -206,8 +206,9 @@ config IP_NF_TARGET_REDIRECT
 
 config NF_NAT_SNMP_BASIC
 	tristate "Basic SNMP-ALG support"
-	depends on NF_NAT
+	depends on NF_CONNTRACK_SNMP && NF_NAT
 	depends on NETFILTER_ADVANCED
+	default NF_NAT && NF_CONNTRACK_SNMP
 	---help---
 
 	  This module implements an Application Layer Gateway (ALG) for
net/ipv4/netfilter/nf_nat_snmp_basic.c +5 -4
index ee5f419..8812a02 100644
@@ -54,6 +54,7 @@
 #include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_nat_helper.h>
+#include <linux/netfilter/nf_conntrack_snmp.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("James Morris <[email protected]>");
@@ -1310,9 +1311,9 @@ static int __init nf_nat_snmp_basic_init(void)
 {
 	int ret = 0;
 
-	ret = nf_conntrack_helper_register(&snmp_helper);
-	if (ret < 0)
-		return ret;
+	BUG_ON(nf_nat_snmp_hook != NULL);
+	rcu_assign_pointer(nf_nat_snmp_hook, help);
+
 	ret = nf_conntrack_helper_register(&snmp_trap_helper);
 	if (ret < 0) {
 		nf_conntrack_helper_unregister(&snmp_helper);
@@ -1323,7 +1324,7 @@ static int __init nf_nat_snmp_basic_init(void)
 
 static void __exit nf_nat_snmp_basic_fini(void)
 {
-	nf_conntrack_helper_unregister(&snmp_helper);
+	rcu_assign_pointer(nf_nat_snmp_hook, NULL);
 	nf_conntrack_helper_unregister(&snmp_trap_helper);
 }
 
net/netfilter/Kconfig +14 -0
index 1534f2b..955e666 100644
@@ -204,6 +204,20 @@ config NF_CONNTRACK_NETBIOS_NS
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_SNMP
+	tristate "SNMP service protocol support"
+	depends on NETFILTER_ADVANCED
+	help
+	  SNMP service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating SNMP service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config NF_CONNTRACK_PPTP
 	tristate "PPtP protocol support"
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
index 441050f..5b7df7f 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
 obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_snmp.c new file +141 -0

141 lines not on this page · raw message

#1 lore raw

net/netfilter/nf_conntrack_snmp.c line 32

Quoted 5 lines · Jiri Olsa
net/netfilter/nf_conntrack_snmp.c new file +5 -0
+
+MODULE_AUTHOR("Jiri Olsa <[email protected]>");
+MODULE_DESCRIPTION("SNMP service broadcast connection tracking helper");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("ip_conntrack_snmp");

This alias looks redundant given it's a new module, and there being no autoloading by prefix like there currently is for iptables extensions.

net/netfilter/nf_conntrack_snmp.c line 36

Quoted 2 lines
net/netfilter/nf_conntrack_snmp.c new file +2 -0
+static unsigned int timeout __read_mostly = 30;
+module_param(timeout, uint, 0400);

400 -> S_IRUSR. We have the mnemonic constants, so should make use of them.

net/netfilter/nf_conntrack_snmp.c line 121

Quoted 3 lines
net/netfilter/nf_conntrack_snmp.c new file +3 -0
+static struct nf_conntrack_helper helper __read_mostly = {
+	.name			= "snmp",
+	.tuple.src.l3num	= AF_INET,

= NFPROTO_IPV4,

net/netfilter/nf_conntrack_snmp.c line 127

Quoted 6 lines
net/netfilter/nf_conntrack_snmp.c new file +6 -0
+	.tuple.src.u.udp.port	= cpu_to_be16(SNMP_PORT),
+	.tuple.dst.protonum	= IPPROTO_UDP,
+	.me			= THIS_MODULE,
+	.help			= help,
+	.expect_policy		= &exp_policy,
+};

I think it would a good idea to give the help function a better name than "help". You know, when a stack trace comes up, it'll be much more enlightening.

#2 lore raw
In reply to Jiri Olsa

Am 14.01.2011 21:18, schrieb Jiri Olsa:

Quoted 11 lines

hi,

attached patch adds SNMP conntrack module to the netfilter.

I refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 2 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.

Quoted 7 lines
Quoted 2 lines

The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

The patch tries to implement the "second best choice".

In case the 'second best choice' is not good enough anyway, could you please outline the first one in more detail..?

Adding full broadcast tracking is non-trivial, so this is good enough for now.

Quoted 4 lines

Also the patch is not adding the "help" function to the shared module, since I'm not sure where to put it. If the idea of the patch would be acceptable, could you please suggest the shared module for the 'help' function?

How about adding a nf_conntrack_broadcast.c or something like that and keep the common code there? The help function and the expect policy (probably not really worth it) could be moved to that file.

net/netfilter/nf_conntrack_snmp.c

Quoted 2 lines
net/netfilter/nf_conntrack_snmp.c new file +0 -0

Besides Jan comments, the patch looks fine to me.

author
#3 lore raw

PATCH 1/1 netfilter: nf_conntrack snmp helper

Quoted 33 lines · Patrick McHardy

Am 14.01.2011 21:18, schrieb Jiri Olsa:

Quoted 11 lines

hi,

attached patch adds SNMP conntrack module to the netfilter.

I refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 2 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.

Quoted 7 lines
Quoted 2 lines

The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

The patch tries to implement the "second best choice".

In case the 'second best choice' is not good enough anyway, could you please outline the first one in more detail..?

Adding full broadcast tracking is non-trivial, so this is good enough for now.

Quoted 4 lines

Also the patch is not adding the "help" function to the shared module, since I'm not sure where to put it. If the idea of the patch would be acceptable, could you please suggest the shared module for the 'help' function?

How about adding a nf_conntrack_broadcast.c or something like that and keep the common code there? The help function and the expect policy (probably not really worth it) could be moved to that file.

Quoted 4 lines

net/netfilter/nf_conntrack_snmp.c

Quoted 2 lines
net/netfilter/nf_conntrack_snmp.c new file +0 -0

Besides Jan comments, the patch looks fine to me.

hi,
thanks for comments, attaching new patch

wbr,
jirka

---
adding support for SNMP broadcast connection tracking. The SNMP broadcast requests are now paired with the SNMP responses. Thus allowing using SNMP broadcasts with firewall enabled.

Please refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 4 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.
The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

This patch implements the "second best choice".

Since the netbios-ns conntrack module uses the same helper functionality as the snmp, only one helper function is added for both snmp and netbios-ns modules into the new object - nf_conntrack_broadcast.

thanks,
jirka

---
 include/linux/netfilter/nf_conntrack_snmp.h |    9 +++
 include/net/netfilter/nf_conntrack_helper.h |    6 ++
 net/ipv4/netfilter/Kconfig                  |    3 +-
 net/ipv4/netfilter/nf_nat_snmp_basic.c      |    9 ++--
 net/netfilter/Kconfig                       |   14 +++++
 net/netfilter/Makefile                      |    3 +-
 net/netfilter/nf_conntrack_broadcast.c      |   79 +++++++++++++++++++++++++++
 net/netfilter/nf_conntrack_netbios_ns.c     |   74 +++----------------------
 net/netfilter/nf_conntrack_snmp.c           |   77 ++++++++++++++++++++++++++
 9 files changed, 203 insertions(+), 71 deletions(-)
include/linux/netfilter/nf_conntrack_snmp.h new file +9 -0
new file mode 100644
index 0000000..064bc63
@@ -0,0 +1,9 @@
+#ifndef _NF_CONNTRACK_SNMP_H
+#define _NF_CONNTRACK_SNMP_H
+
+extern int (*nf_nat_snmp_hook)(struct sk_buff *skb,
+				unsigned int protoff,
+				struct nf_conn *ct,
+				enum ip_conntrack_info ctinfo);
+
+#endif /* _NF_CONNTRACK_SNMP_H */
include/net/netfilter/nf_conntrack_helper.h +6 -0
index 32c305d..f1c1311 100644
@@ -63,4 +63,10 @@ static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
 extern int nf_conntrack_helper_init(void);
 extern void nf_conntrack_helper_fini(void);
 
+extern int nf_conntrack_broadcast_help(struct sk_buff *skb,
+				       unsigned int protoff,
+				       struct nf_conn *ct,
+				       enum ip_conntrack_info ctinfo,
+				       unsigned int timeout);
+
 #endif /*_NF_CONNTRACK_HELPER_H*/
net/ipv4/netfilter/Kconfig +2 -1
index babd1a2..f926a31 100644
@@ -206,8 +206,9 @@ config IP_NF_TARGET_REDIRECT
 
 config NF_NAT_SNMP_BASIC
 	tristate "Basic SNMP-ALG support"
-	depends on NF_NAT
+	depends on NF_CONNTRACK_SNMP && NF_NAT
 	depends on NETFILTER_ADVANCED
+	default NF_NAT && NF_CONNTRACK_SNMP
 	---help---
 
 	  This module implements an Application Layer Gateway (ALG) for
net/ipv4/netfilter/nf_nat_snmp_basic.c +5 -4
index ee5f419..8812a02 100644
@@ -54,6 +54,7 @@
 #include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_nat_helper.h>
+#include <linux/netfilter/nf_conntrack_snmp.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("James Morris <[email protected]>");
@@ -1310,9 +1311,9 @@ static int __init nf_nat_snmp_basic_init(void)
 {
 	int ret = 0;
 
-	ret = nf_conntrack_helper_register(&snmp_helper);
-	if (ret < 0)
-		return ret;
+	BUG_ON(nf_nat_snmp_hook != NULL);
+	rcu_assign_pointer(nf_nat_snmp_hook, help);
+
 	ret = nf_conntrack_helper_register(&snmp_trap_helper);
 	if (ret < 0) {
 		nf_conntrack_helper_unregister(&snmp_helper);
@@ -1323,7 +1324,7 @@ static int __init nf_nat_snmp_basic_init(void)
 
 static void __exit nf_nat_snmp_basic_fini(void)
 {
-	nf_conntrack_helper_unregister(&snmp_helper);
+	rcu_assign_pointer(nf_nat_snmp_hook, NULL);
 	nf_conntrack_helper_unregister(&snmp_trap_helper);
 }
 
net/netfilter/Kconfig +14 -0
index 1534f2b..955e666 100644
@@ -204,6 +204,20 @@ config NF_CONNTRACK_NETBIOS_NS
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_SNMP
+	tristate "SNMP service protocol support"
+	depends on NETFILTER_ADVANCED
+	help
+	  SNMP service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating SNMP service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config NF_CONNTRACK_PPTP
 	tristate "PPtP protocol support"
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +2 -1
index 441050f..1087d52 100644
@@ -28,7 +28,8 @@ obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
 obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
-obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o nf_conntrack_broadcast.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o nf_conntrack_broadcast.o
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_broadcast.c new file +79 -0

79 lines not on this page · raw message

net/netfilter/nf_conntrack_netbios_ns.c +9 -65

98 lines not on this page · raw message

net/netfilter/nf_conntrack_snmp.c new file +77 -0

77 lines not on this page · raw message

#4 lore raw

Re: [PATCH] netfilter: nf_conntrack snmp helper

net/netfilter/Makefile obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o · line 32

Quoted 12 lines · Jiri Olsa

hi,
thanks for comments, attaching new patch

net/netfilter/Makefile +2 -1
@@ -28,7 +28,8 @@ obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
 obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
-obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o nf_conntrack_broadcast.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o nf_conntrack_broadcast.o

Just add an EXPORT_SYMBOL_GPL'ed function and a new Kconfig symbol for the nf_conntrack_broadcast.o file that is selected by NETBIOS_NS and SNMP.

net/netfilter/nf_conntrack_broadcast.c line 4

Quoted 13 lines
net/netfilter/Makefile +0 -0
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_broadcast.c new file +4 -0
new file mode 100644
index 0000000..fb48be1
@@ -0,0 +1,79 @@
+/*
+ *      broadcast connection tracking helper
+ *
+ *      (c) 2011 Jiri Olsa <[email protected]>

I'd also prefer if you keep my copyright statement from the netbios ns file.

Quoted 6 lines
net/netfilter/nf_conntrack_broadcast.c new file +6 -0
+ *
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ */
author
#5 lore raw

PATCH v2 1/1 netfilter: nf_conntrack snmp helper

Quoted 18 lines · Patrick McHardy

net/netfilter/Makefile obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o · line 32

Quoted 12 lines · Jiri Olsa

hi,
thanks for comments, attaching new patch

net/netfilter/Makefile +2 -1
@@ -28,7 +28,8 @@ obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
 obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
-obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o nf_conntrack_broadcast.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o nf_conntrack_broadcast.o

Just add an EXPORT_SYMBOL_GPL'ed function and a new Kconfig symbol for the nf_conntrack_broadcast.o file that is selected by NETBIOS_NS and SNMP.

Quoted 23 lines

net/netfilter/nf_conntrack_broadcast.c line 4

Quoted 13 lines
net/netfilter/Makefile +0 -0
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_broadcast.c new file +4 -0
new file mode 100644
index 0000000..fb48be1
@@ -0,0 +1,79 @@
+/*
+ *      broadcast connection tracking helper
+ *
+ *      (c) 2011 Jiri Olsa <[email protected]>

I'd also prefer if you keep my copyright statement from the netbios ns file.

Quoted 6 lines
net/netfilter/nf_conntrack_broadcast.c new file +6 -0
+ *
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ */

sending updated version

thanks,
jirka

---
Adding support for SNMP broadcast connection tracking. The SNMP broadcast requests are now paired with the SNMP responses. Thus allowing using SNMP broadcasts with firewall enabled.

Please refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 4 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.
The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

This patch implements the "second best choice".

Since the netbios-ns conntrack module uses the same helper functionality as the snmp, only one helper function is added for both snmp and netbios-ns modules into the new object - nf_conntrack_broadcast.

v2 changes:
- exporting nf_conntrack_broadcast_help via EXPORT_SYMBOL_GPL
- nf_conntrack_broadcast object now built based on new config symbol NF_CONNTRACK_BROADCAST
- changed nf_conntrack_broadcast.c copyright message

thanks,
jirka

---
 include/linux/netfilter/nf_conntrack_snmp.h |    9 +++
 include/net/netfilter/nf_conntrack_helper.h |    6 ++
 net/ipv4/netfilter/Kconfig                  |    3 +-
 net/ipv4/netfilter/nf_nat_snmp_basic.c      |    9 ++-
 net/netfilter/Kconfig                       |   21 +++++++
 net/netfilter/Makefile                      |    2 +
 net/netfilter/nf_conntrack_broadcast.c      |   80 +++++++++++++++++++++++++++
 net/netfilter/nf_conntrack_netbios_ns.c     |   74 +++----------------------
 net/netfilter/nf_conntrack_snmp.c           |   77 ++++++++++++++++++++++++++
 9 files changed, 211 insertions(+), 70 deletions(-)
include/linux/netfilter/nf_conntrack_snmp.h new file +9 -0
new file mode 100644
index 0000000..064bc63
@@ -0,0 +1,9 @@
+#ifndef _NF_CONNTRACK_SNMP_H
+#define _NF_CONNTRACK_SNMP_H
+
+extern int (*nf_nat_snmp_hook)(struct sk_buff *skb,
+				unsigned int protoff,
+				struct nf_conn *ct,
+				enum ip_conntrack_info ctinfo);
+
+#endif /* _NF_CONNTRACK_SNMP_H */
include/net/netfilter/nf_conntrack_helper.h +6 -0
index 32c305d..f1c1311 100644
@@ -63,4 +63,10 @@ static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
 extern int nf_conntrack_helper_init(void);
 extern void nf_conntrack_helper_fini(void);
 
+extern int nf_conntrack_broadcast_help(struct sk_buff *skb,
+				       unsigned int protoff,
+				       struct nf_conn *ct,
+				       enum ip_conntrack_info ctinfo,
+				       unsigned int timeout);
+
 #endif /*_NF_CONNTRACK_HELPER_H*/
net/ipv4/netfilter/Kconfig +2 -1
index babd1a2..f926a31 100644
@@ -206,8 +206,9 @@ config IP_NF_TARGET_REDIRECT
 
 config NF_NAT_SNMP_BASIC
 	tristate "Basic SNMP-ALG support"
-	depends on NF_NAT
+	depends on NF_CONNTRACK_SNMP && NF_NAT
 	depends on NETFILTER_ADVANCED
+	default NF_NAT && NF_CONNTRACK_SNMP
 	---help---
 
 	  This module implements an Application Layer Gateway (ALG) for
net/ipv4/netfilter/nf_nat_snmp_basic.c +5 -4
index ee5f419..8812a02 100644
@@ -54,6 +54,7 @@
 #include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_nat_helper.h>
+#include <linux/netfilter/nf_conntrack_snmp.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("James Morris <[email protected]>");
@@ -1310,9 +1311,9 @@ static int __init nf_nat_snmp_basic_init(void)
 {
 	int ret = 0;
 
-	ret = nf_conntrack_helper_register(&snmp_helper);
-	if (ret < 0)
-		return ret;
+	BUG_ON(nf_nat_snmp_hook != NULL);
+	rcu_assign_pointer(nf_nat_snmp_hook, help);
+
 	ret = nf_conntrack_helper_register(&snmp_trap_helper);
 	if (ret < 0) {
 		nf_conntrack_helper_unregister(&snmp_helper);
@@ -1323,7 +1324,7 @@ static int __init nf_nat_snmp_basic_init(void)
 
 static void __exit nf_nat_snmp_basic_fini(void)
 {
-	nf_conntrack_helper_unregister(&snmp_helper);
+	rcu_assign_pointer(nf_nat_snmp_hook, NULL);
 	nf_conntrack_helper_unregister(&snmp_trap_helper);
 }
 
net/netfilter/Kconfig +21 -0
index 1534f2b..f08d701 100644
@@ -185,9 +185,15 @@ config NF_CONNTRACK_IRC
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_BROADCAST
+	bool
+	help
+	  Provides helper for broadcast connection tracking.
+
 config NF_CONNTRACK_NETBIOS_NS
 	tristate "NetBIOS name service protocol support"
 	depends on NETFILTER_ADVANCED
+	select NF_CONNTRACK_BROADCAST
 	help
 	  NetBIOS name service requests are sent as broadcast messages from an
 	  unprivileged port and responded to with unicast messages to the
@@ -204,6 +210,21 @@ config NF_CONNTRACK_NETBIOS_NS
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_SNMP
+	tristate "SNMP service protocol support"
+	depends on NETFILTER_ADVANCED
+	select NF_CONNTRACK_BROADCAST
+	help
+	  SNMP service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating SNMP service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config NF_CONNTRACK_PPTP
 	tristate "PPtP protocol support"
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +2 -0
index 441050f..344b0cc 100644
@@ -28,7 +28,9 @@ obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
 obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
+obj-$(CONFIG_NF_CONNTRACK_BROADCAST) += nf_conntrack_broadcast.o
 obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_broadcast.c new file +80 -0

80 lines not on this page · raw message

net/netfilter/nf_conntrack_netbios_ns.c +9 -65

98 lines not on this page · raw message

net/netfilter/nf_conntrack_snmp.c new file +77 -0

77 lines not on this page · raw message

#6 lore raw

Re: [PATCHv2] netfilter: nf_conntrack snmp helper

Quoted 20 lines · Jiri Olsa

Adding support for SNMP broadcast connection tracking. The SNMP broadcast requests are now paired with the SNMP responses. Thus allowing using SNMP broadcasts with firewall enabled.

Please refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 4 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.
The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

This patch implements the "second best choice".

Since the netbios-ns conntrack module uses the same helper functionality as the snmp, only one helper function is added for both snmp and netbios-ns modules into the new object - nf_conntrack_broadcast.

Quoted 5 lines

v2 changes:
- exporting nf_conntrack_broadcast_help via EXPORT_SYMBOL_GPL
- nf_conntrack_broadcast object now built based on new config symbol NF_CONNTRACK_BROADCAST
- changed nf_conntrack_broadcast.c copyright message

I've applied the patch after fixeing up a few minor issues (does not build with NF_CONNTRACK=m) by adding a MODULE_LICENSE and changing the Kconfig bool to a tristate.

The final patch is attached to this email.

commit 93557f53e1fbd9e2b6574ab0a9b5852628fde9e3

Author: Jiri Olsa <[email protected]>
Date:   Tue Jan 18 18:12:24 2011 +0100

netfilter: nf_conntrack: nf_conntrack snmp helper

Adding support for SNMP broadcast connection tracking. The SNMP broadcast requests are now paired with the SNMP responses. Thus allowing using SNMP broadcasts with firewall enabled.

Please refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Patrick McHardy wrote:
> > The best solution would be to add generic broadcast tracking, the > > use of expectations for this is a bit of abuse.
> > The second best choice I guess would be to move the help() function > > to a shared module and generalize it so it can be used for both. This patch implements the "second best choice".

Since the netbios-ns conntrack module uses the same helper functionality as the snmp, only one helper function is added for both snmp and netbios-ns modules into the new object - nf_conntrack_broadcast.

include/linux/netfilter/nf_conntrack_snmp.h new file +9 -0
new file mode 100644
index 0000000..064bc63
@@ -0,0 +1,9 @@
+#ifndef _NF_CONNTRACK_SNMP_H
+#define _NF_CONNTRACK_SNMP_H
+
+extern int (*nf_nat_snmp_hook)(struct sk_buff *skb,
+				unsigned int protoff,
+				struct nf_conn *ct,
+				enum ip_conntrack_info ctinfo);
+
+#endif /* _NF_CONNTRACK_SNMP_H */
include/net/netfilter/nf_conntrack_helper.h +6 -0
index 32c305d..f1c1311 100644
@@ -63,4 +63,10 @@ static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
 extern int nf_conntrack_helper_init(void);
 extern void nf_conntrack_helper_fini(void);
 
+extern int nf_conntrack_broadcast_help(struct sk_buff *skb,
+				       unsigned int protoff,
+				       struct nf_conn *ct,
+				       enum ip_conntrack_info ctinfo,
+				       unsigned int timeout);
+
 #endif /*_NF_CONNTRACK_HELPER_H*/
net/ipv4/netfilter/Kconfig +2 -1
index babd1a2..f926a31 100644
@@ -206,8 +206,9 @@ config IP_NF_TARGET_REDIRECT
 
 config NF_NAT_SNMP_BASIC
 	tristate "Basic SNMP-ALG support"
-	depends on NF_NAT
+	depends on NF_CONNTRACK_SNMP && NF_NAT
 	depends on NETFILTER_ADVANCED
+	default NF_NAT && NF_CONNTRACK_SNMP
 	---help---
 
 	  This module implements an Application Layer Gateway (ALG) for
net/ipv4/netfilter/nf_nat_snmp_basic.c +5 -4
index ee5f419..8812a02 100644
@@ -54,6 +54,7 @@
 #include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_nat_helper.h>
+#include <linux/netfilter/nf_conntrack_snmp.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("James Morris <[email protected]>");
@@ -1310,9 +1311,9 @@ static int __init nf_nat_snmp_basic_init(void)
 {
 	int ret = 0;
 
-	ret = nf_conntrack_helper_register(&snmp_helper);
-	if (ret < 0)
-		return ret;
+	BUG_ON(nf_nat_snmp_hook != NULL);
+	rcu_assign_pointer(nf_nat_snmp_hook, help);
+
 	ret = nf_conntrack_helper_register(&snmp_trap_helper);
 	if (ret < 0) {
 		nf_conntrack_helper_unregister(&snmp_helper);
@@ -1323,7 +1324,7 @@ static int __init nf_nat_snmp_basic_init(void)
 
 static void __exit nf_nat_snmp_basic_fini(void)
 {
-	nf_conntrack_helper_unregister(&snmp_helper);
+	rcu_assign_pointer(nf_nat_snmp_hook, NULL);
 	nf_conntrack_helper_unregister(&snmp_trap_helper);
 }
 
net/netfilter/Kconfig +19 -0
index e2480bd..939b504 100644
@@ -185,9 +185,13 @@ config NF_CONNTRACK_IRC
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_BROADCAST
+	tristate
+
 config NF_CONNTRACK_NETBIOS_NS
 	tristate "NetBIOS name service protocol support"
 	depends on NETFILTER_ADVANCED
+	select NF_CONNTRACK_BROADCAST
 	help
 	  NetBIOS name service requests are sent as broadcast messages from an
 	  unprivileged port and responded to with unicast messages to the
@@ -204,6 +208,21 @@ config NF_CONNTRACK_NETBIOS_NS
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NF_CONNTRACK_SNMP
+	tristate "SNMP service protocol support"
+	depends on NETFILTER_ADVANCED
+	select NF_CONNTRACK_BROADCAST
+	help
+	  SNMP service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating SNMP service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config NF_CONNTRACK_PPTP
 	tristate "PPtP protocol support"
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +2 -0
index 401d574..2c2628d 100644
@@ -28,7 +28,9 @@ obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
 obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
 obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
 obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
+obj-$(CONFIG_NF_CONNTRACK_BROADCAST) += nf_conntrack_broadcast.o
 obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
+obj-$(CONFIG_NF_CONNTRACK_SNMP) += nf_conntrack_snmp.o
 obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
 obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
net/netfilter/nf_conntrack_broadcast.c new file +82 -0

82 lines not on this page · raw message

net/netfilter/nf_conntrack_netbios_ns.c +9 -65

98 lines not on this page · raw message

net/netfilter/nf_conntrack_snmp.c new file +77 -0

77 lines not on this page · raw message

author
#7 lore raw

Re: [PATCHv2] netfilter: nf_conntrack snmp helper

Quoted 27 lines · Patrick McHardy
Quoted 20 lines · Jiri Olsa

Adding support for SNMP broadcast connection tracking. The SNMP broadcast requests are now paired with the SNMP responses. Thus allowing using SNMP broadcasts with firewall enabled.

Please refer to the following conversation:
http://marc.info/?l=netfilter-devel&m=125992205006600&w=2

Quoted 4 lines · Patrick McHardy

The best solution would be to add generic broadcast tracking, the use of expectations for this is a bit of abuse.
The second best choice I guess would be to move the help() function to a shared module and generalize it so it can be used for both.

This patch implements the "second best choice".

Since the netbios-ns conntrack module uses the same helper functionality as the snmp, only one helper function is added for both snmp and netbios-ns modules into the new object - nf_conntrack_broadcast.

Quoted 5 lines

v2 changes:
- exporting nf_conntrack_broadcast_help via EXPORT_SYMBOL_GPL
- nf_conntrack_broadcast object now built based on new config symbol NF_CONNTRACK_BROADCAST
- changed nf_conntrack_broadcast.c copyright message

Quoted 5 lines

I've applied the patch after fixeing up a few minor issues (does not build with NF_CONNTRACK=m) by adding a MODULE_LICENSE and changing the Kconfig bool to a tristate.

The final patch is attached to this email.

cool :) thanks a lot

jirka