Skip to contentSkip to conversation

netfilter: add IPComp extension match support

PATCH In review Fan Du 2 participants 4 messages Nov 28, 2013 – Dec 7, 2013

Subsystems (3)
lore
Share & tools
lore

Fan Du

author
#0 lore raw

PATCH 1/1 netfilter: add IPComp extension match support

With this plugin, user could specify IPComp tagged with certain CPI that host not interested will be DROPped or any other action.

For example:
iptables -A INPUT -p 108 -m ipcomp --ipcompspi 0x87 -j DROP

Then input IPComp packet with CPI equates 0x87 will not reach upper layer anymore.

---
 include/uapi/linux/netfilter_ipv4/ipt_comp.h |   17 +++++
 net/ipv4/netfilter/Kconfig                   |    9 +++
 net/ipv4/netfilter/Makefile                  |    1 +
 net/ipv4/netfilter/ipt_comp.c                |  101 ++++++++++++++++++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 include/uapi/linux/netfilter_ipv4/ipt_comp.h
 create mode 100644 net/ipv4/netfilter/ipt_comp.c
include/uapi/linux/netfilter_ipv4/ipt_comp.h new file +17 -0
new file mode 100644
index 0000000..d072202
@@ -0,0 +1,17 @@
+#ifndef _IPT_COMP_H
+#define _IPT_COMP_H
+
+#include <linux/types.h>
+
+struct ipt_comp {
+	__u32 spis[2];			/* Security Parameter Index */
+	__u8  invflags;			/* Inverse flags */
+};
+
+
+
+/* Values for "invflags" field in struct ipt_comp. */
+#define IPT_IPCOMP_INV_SPI		0x01	/* Invert the sense of spi. */
+#define IPT_IPCOMP_INV_MASK	0x01	/* All possible flags. */
+
+#endif /*_IPT_COMP_H*/
net/ipv4/netfilter/Kconfig +9 -0
index 40d5607..f71cf7b 100644
@@ -81,6 +81,15 @@ config IP_NF_MATCH_AH
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config IP_NF_MATCH_IPCOMP
+	tristate '"ipcomp" match support'
+	depends on NETFILTER_ADVANCED
+	help
+	  This match extension allows you to match a range of SPIs (Actually it's
+	  Compression Parameter Index(CPI) inside IPComp header of IPSec packets.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config IP_NF_MATCH_ECN
 	tristate '"ecn" match support'
 	depends on NETFILTER_ADVANCED
net/ipv4/netfilter/Makefile +1 -0
index 19df72b..b67ecb8 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_IP_NF_SECURITY) += iptable_security.o
 
 # matches
 obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
+obj-$(CONFIG_IP_NF_MATCH_IPCOMP) += ipt_comp.o
 obj-$(CONFIG_IP_NF_MATCH_RPFILTER) += ipt_rpfilter.o
 
 # targets
net/ipv4/netfilter/ipt_comp.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

Hi,

Quoted 8 lines · Fan Du

With this plugin, user could specify IPComp tagged with certain CPI that host not interested will be DROPped or any other action.

For example:
iptables -A INPUT -p 108 -m ipcomp --ipcompspi 0x87 -j DROP

Then input IPComp packet with CPI equates 0x87 will not reach upper layer anymore.

I think that, with a little bit more work, you can add support for IPv6 as well. From RFC 3173:

"In the IPv6 context, IPComp is viewed as an end-to-end payload, and MUST NOT apply to hop-by-hop, routing, and fragmentation extension headers.

You can perform that IPv6-specific handling to skip these extension headers and reach the IPComp header by means of the ipv6_find_hdr() helper function.

BTW, please post the iptables userspace part as well.

author
#2 lore raw
Quoted 19 lines · Pablo Neira Ayuso

Hi,

Quoted 8 lines · Fan Du

With this plugin, user could specify IPComp tagged with certain CPI that host not interested will be DROPped or any other action.

For example:
iptables -A INPUT -p 108 -m ipcomp --ipcompspi 0x87 -j DROP

Then input IPComp packet with CPI equates 0x87 will not reach upper layer anymore.

I think that, with a little bit more work, you can add support for IPv6 as well. From RFC 3173:

"In the IPv6 context, IPComp is viewed as an end-to-end payload, and MUST NOT apply to hop-by-hop, routing, and fragmentation extension headers.

Quoted 5 lines

You can perform that IPv6-specific handling to skip these extension headers and reach the IPComp header by means of the ipv6_find_hdr() helper function.

BTW, please post the iptables userspace part as well.

Thanks for your attention, Pablo.
I will try to finish your request this weekend, hopefully post the whole patch set in early next week.

Signature · 7 lines
浮沉随浪只记今朝笑

--fan fan
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 18 lines · Fan Du
Quoted 15 lines · Pablo Neira Ayuso

Hi,

Quoted 8 lines · Fan Du

With this plugin, user could specify IPComp tagged with certain CPI that host not interested will be DROPped or any other action.

For example:
iptables -A INPUT -p 108 -m ipcomp --ipcompspi 0x87 -j DROP

Then input IPComp packet with CPI equates 0x87 will not reach upper layer anymore.

I think that, with a little bit more work, you can add support for IPv6 as well. From RFC 3173:

Quoted 7 lines
Quoted 7 lines

"In the IPv6 context, IPComp is viewed as an end-to-end payload, and MUST NOT apply to hop-by-hop, routing, and fragmentation extension headers.

You can perform that IPv6-specific handling to skip these extension headers and reach the IPComp header by means of the ipv6_find_hdr() helper function.

I just noted that you always have to use -p 108 to get this match working, in that case the ip6_tables already sets par->thoff that you can use to reach the transport header, so you can skip calling ipv6_find_hdr(). So adding IPv6 support is even easier to make. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html