Skip to contentSkip to conversation

: Netfilter update

PATCH In review Patrick McHardy 2 participants 8 messages Apr 13, 2007

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

cover : Netfilter update

Hi Dave,

following are a few netfilter patches for 2.6.22, adding support for filtering encapsulated PPPoE and gratuitous ARP packets in bridge netfilter, compat support for ipt_ULOG (as mentioned in the other thread, 32 bit userspace can already deal with log messages sent by a 64 bit kernel, but the kernel currently does not support adding new rules from a 32 bit iptables binary), some misc netfilter logging cleanup and support for using HW checksumming for forwarded packets mangled by NAT helpers.

Please apply, thanks.

 Documentation/networking/ip-sysctl.txt   |    7 ++
 include/linux/if_pppox.h                 |    3 +
 include/linux/netfilter_bridge.h         |   11 +++-
 include/linux/netfilter_bridge/ebt_arp.h |    4 +
 include/linux/sysctl.h                   |    1 
 net/bridge/br_netfilter.c                |   77 +++++++++++++++++++++++++++++--
 net/bridge/netfilter/ebt_arp.c           |   48 ++++++++-----------
 net/bridge/netfilter/ebt_log.c           |   12 +---
 net/ipv4/netfilter/ipt_LOG.c             |   12 +---
 net/ipv4/netfilter/ipt_ULOG.c            |   40 ++++++++++++++++
 net/ipv4/netfilter/nf_nat_helper.c       |   49 ++++++++++++++-----
 net/ipv6/netfilter/ip6t_LOG.c            |   12 +---
 net/netfilter/nfnetlink_log.c            |    5 --
 13 files changed, 206 insertions(+), 75 deletions(-)

Bart De Schuymer (1):
[NETFILTER]: ebt_arp: add gratuitous arp filtering

Michael Milner (1):
[NETFILTER]: bridge-nf: filter bridged IPv4/IPv6 encapsulated in pppoe traffic

Patrick McHardy (4):
[NETFILTER]: nf_nat: use HW checksumming when possible [NETFILTER]: {eb,ip6,ip}t_LOG: remove remains of LOG target overloading [NETFILTER]: nfnetlink_log: remove fallback to group 0 [NETFILTER]: ipt_ULOG: add compat conversion functions

#1 lore raw

PATCH 1/6 : bridge-nf: filter bridged IPv4/IPv6 encapsulated in pppoe traffic

[NETFILTER]: bridge-nf: filter bridged IPv4/IPv6 encapsulated in pppoe traffic

The attached patch by Michael Milner adds support for using iptables and ip6tables on bridged traffic encapsulated in ppoe frames, similar to what's already supported for vlan.

---
commit 2b4788ea9b3c4e532f7cde3f05800c33977f32ee
tree 89fa3b01937da7bff0a6badca6e4fbe3c468d823
parent e5bc163d0150bf7d7deb49a3902d6c0a8a458ef7
author Michael Milner <[email protected]> Fri, 13 Apr 2007 04:42:56 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:42:56 +0200

 Documentation/networking/ip-sysctl.txt |    7 ++-
 include/linux/if_pppox.h               |    3 +
 include/linux/netfilter_bridge.h       |   11 ++++-
 include/linux/sysctl.h                 |    1 
 net/bridge/br_netfilter.c              |   77 ++++++++++++++++++++++++++++++--
 5 files changed, 92 insertions(+), 7 deletions(-)
Documentation/networking/ip-sysctl.txt +6 -1
index db8b4b7..ce16e6a 100644
@@ -1006,7 +1006,12 @@ bridge-nf-call-ip6tables - BOOLEAN
 	Default: 1
 
 bridge-nf-filter-vlan-tagged - BOOLEAN
-	1 : pass bridged vlan-tagged ARP/IP traffic to arptables/iptables.
+	1 : pass bridged vlan-tagged ARP/IP/IPv6 traffic to {arp,ip,ip6}tables.
+	0 : disable this.
+	Default: 1
+
+bridge-nf-filter-pppoe-tagged - BOOLEAN
+	1 : pass bridged pppoe-tagged IP/IPv6 traffic to {ip,ip6}tables.
 	0 : disable this.
 	Default: 1
 
include/linux/if_pppox.h +3 -0
index 29d6579..6f987be 100644
@@ -111,6 +111,9 @@ struct pppoe_hdr {
 	struct pppoe_tag tag[0];
 } __attribute__ ((packed));
 
+/* Length of entire PPPoE + PPP header */
+#define PPPOE_SES_HLEN	8
+
 #ifdef __KERNEL__
 #include <linux/skbuff.h>
 
include/linux/netfilter_bridge.h +9 -2
index 55689f3..1906003 100644
@@ -7,6 +7,7 @@
 #include <linux/netfilter.h>
 #include <linux/if_ether.h>
 #include <linux/if_vlan.h>
+#include <linux/if_pppox.h>
 
 /* Bridge Hooks */
 /* After promisc drops, checksum checks. */
@@ -58,8 +59,14 @@ static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)
  * enough room for the encapsulating header (if there is one). */
 static inline int nf_bridge_pad(const struct sk_buff *skb)
 {
- 	return (skb->nf_bridge && skb->protocol == htons(ETH_P_8021Q))
-		? VLAN_HLEN : 0;
+	int padding = 0;
+
+	if (skb->nf_bridge && skb->protocol == htons(ETH_P_8021Q))
+		padding = VLAN_HLEN;
+	else if (skb->nf_bridge && skb->protocol == htons(ETH_P_PPP_SES))
+		padding = PPPOE_SES_HLEN;
+
+	return padding;
 }
 
 struct bridge_skb_cb {
include/linux/sysctl.h +1 -0
index 1e8993b..867db58 100644
@@ -792,6 +792,7 @@ enum {
 	NET_BRIDGE_NF_CALL_IPTABLES = 2,
 	NET_BRIDGE_NF_CALL_IP6TABLES = 3,
 	NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
+	NET_BRIDGE_NF_FILTER_PPPOE_TAGGED = 5,
 };
 
 /* CTL_FS names: */
net/bridge/br_netfilter.c +73 -4

205 lines not on this page · raw message

#2 lore raw

PATCH 2/6 : ebt_arp: add gratuitous arp filtering

In reply to Patrick McHardy

[NETFILTER]: ebt_arp: add gratuitous arp filtering

The attached patch adds gratuitous arp filtering, more precisely: it allows checking that the IPv4 source address matches the IPv4 destination address inside the ARP header. It also adds a check for the hardware address type when matching MAC addresses (nothing critical, just for better consistency).

---
commit 801b6d278e6e78a2a58b6729eb8f799de6ed74d0
tree 2f68cb4c51af86782ba9b1ddff5735e4ccae9df5
parent 2b4788ea9b3c4e532f7cde3f05800c33977f32ee
author Bart De Schuymer <[email protected]> Fri, 13 Apr 2007 04:43:04 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:04 +0200

 include/linux/netfilter_bridge/ebt_arp.h |    4 ++-
 net/bridge/netfilter/ebt_arp.c           |   48 ++++++++++++++----------------
 2 files changed, 25 insertions(+), 27 deletions(-)
include/linux/netfilter_bridge/ebt_arp.h +3 -1
index 97e4dbd..cbf4843 100644
@@ -8,8 +8,10 @@
 #define EBT_ARP_DST_IP 0x10
 #define EBT_ARP_SRC_MAC 0x20
 #define EBT_ARP_DST_MAC 0x40
+#define EBT_ARP_GRAT 0x80
 #define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
-   EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
+   EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC | \
+   EBT_ARP_GRAT)
 #define EBT_ARP_MATCH "arp"
 
 struct ebt_arp_info
net/bridge/netfilter/ebt_arp.c +22 -26

62 lines not on this page · raw message

#3 lore raw

PATCH 3/6 : nf_nat: use HW checksumming when possible

In reply to Patrick McHardy

[NETFILTER]: nf_nat: use HW checksumming when possible

When mangling packets forwarded to a HW checksumming capable device, offload recalculation of the checksum instead of doing it in software.

---
commit 794931007064900f96c05544fbed41ef194884c8
tree c2ee02fe0ac4767e289382b008050ebaf2e1da1f
parent 801b6d278e6e78a2a58b6729eb8f799de6ed74d0
author Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:14 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:14 +0200

 net/ipv4/netfilter/nf_nat_helper.c |   49 +++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 12 deletions(-)
net/ipv4/netfilter/nf_nat_helper.c +37 -12
index 8a40fbe..15b6e5c 100644
@@ -153,6 +153,7 @@ nf_nat_mangle_tcp_packet(struct sk_buff **pskb,
 			 const char *rep_buffer,
 			 unsigned int rep_len)
 {
+	struct rtable *rt = (struct rtable *)(*pskb)->dst;
 	struct iphdr *iph;
 	struct tcphdr *tcph;
 	int oldlen, datalen;
@@ -176,11 +177,22 @@ nf_nat_mangle_tcp_packet(struct sk_buff **pskb,
 
 	datalen = (*pskb)->len - iph->ihl*4;
 	if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
-		tcph->check = 0;
-		tcph->check = tcp_v4_check(datalen,
-					   iph->saddr, iph->daddr,
-					   csum_partial((char *)tcph,
-							datalen, 0));
+		if (!(rt->rt_flags & RTCF_LOCAL) &&
+		    (*pskb)->dev->features & NETIF_F_ALL_CSUM) {
+			(*pskb)->ip_summed = CHECKSUM_PARTIAL;
+			(*pskb)->csum_start = skb_headroom(*pskb) +
+					      skb_network_offset(*pskb) +
+					      iph->ihl * 4;
+			(*pskb)->csum_offset = offsetof(struct tcphdr, check);
+			tcph->check = ~tcp_v4_check(datalen,
+						    iph->saddr, iph->daddr, 0);
+		} else {
+			tcph->check = 0;
+			tcph->check = tcp_v4_check(datalen,
+						   iph->saddr, iph->daddr,
+						   csum_partial((char *)tcph,
+								datalen, 0));
+		}
 	} else
 		nf_proto_csum_replace2(&tcph->check, *pskb,
 				       htons(oldlen), htons(datalen), 1);
@@ -217,6 +229,7 @@ nf_nat_mangle_udp_packet(struct sk_buff **pskb,
 			 const char *rep_buffer,
 			 unsigned int rep_len)
 {
+	struct rtable *rt = (struct rtable *)(*pskb)->dst;
 	struct iphdr *iph;
 	struct udphdr *udph;
 	int datalen, oldlen;
@@ -251,13 +264,25 @@ nf_nat_mangle_udp_packet(struct sk_buff **pskb,
 		return 1;
 
 	if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
-		udph->check = 0;
-		udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
-						datalen, IPPROTO_UDP,
-						csum_partial((char *)udph,
-							     datalen, 0));
-		if (!udph->check)
-			udph->check = CSUM_MANGLED_0;
+		if (!(rt->rt_flags & RTCF_LOCAL) &&
+		    (*pskb)->dev->features & NETIF_F_ALL_CSUM) {
+			(*pskb)->ip_summed = CHECKSUM_PARTIAL;
+			(*pskb)->csum_start = skb_headroom(*pskb) +
+					      skb_network_offset(*pskb) +
+					      iph->ihl * 4;
+			(*pskb)->csum_offset = offsetof(struct udphdr, check);
+			udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
+							 datalen, IPPROTO_UDP,
+							 0);
+		} else {
+			udph->check = 0;
+			udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
+							datalen, IPPROTO_UDP,
+							csum_partial((char *)udph,
+								     datalen, 0));
+			if (!udph->check)
+				udph->check = CSUM_MANGLED_0;
+		}
 	} else
 		nf_proto_csum_replace2(&udph->check, *pskb,
 				       htons(oldlen), htons(datalen), 1);
#4 lore raw

PATCH 4/6 : {eb, ip6, ip}t_LOG: remove remains of LOG target overloading

In reply to Patrick McHardy

[NETFILTER]: {eb,ip6,ip}t_LOG: remove remains of LOG target overloading

All LOG targets always use their internal logging function nowadays, so remove the incorrect error message and handle real errors (!= -EEXIST) by failing to load.

---
commit 474508878b875d838ec122f84193e48ea492f560
tree 95c52389ac63948adcb8361e20823f60461498f2
parent 794931007064900f96c05544fbed41ef194884c8
author Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:23 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:23 +0200

 net/bridge/netfilter/ebt_log.c |   12 ++++--------
 net/ipv4/netfilter/ipt_LOG.c   |   12 ++++--------
 net/ipv6/netfilter/ip6t_LOG.c  |   12 ++++--------
 3 files changed, 12 insertions(+), 24 deletions(-)
net/bridge/netfilter/ebt_log.c +4 -8
index 45712ae..031bfa4 100644
@@ -196,14 +196,10 @@ static int __init ebt_log_init(void)
 	ret = ebt_register_watcher(&log);
 	if (ret < 0)
 		return ret;
-	if (nf_log_register(PF_BRIDGE, &ebt_log_logger) < 0) {
-		printk(KERN_WARNING "ebt_log: not logging via system console "
-		       "since somebody else already registered for PF_INET\n");
-		/* we cannot make module load fail here, since otherwise
-		 * ebtables userspace would abort */
-	}
-
-	return 0;
+	ret = nf_log_register(PF_BRIDGE, &ebt_log_logger);
+	if (ret < 0 && ret != -EEXIST)
+		ebt_unregister_watcher(&log);
+	return ret;
 }
 
 static void __exit ebt_log_fini(void)
net/ipv4/netfilter/ipt_LOG.c +4 -8
index 2fa3661..a42c5cd 100644
@@ -477,14 +477,10 @@ static int __init ipt_log_init(void)
 	ret = xt_register_target(&ipt_log_reg);
 	if (ret < 0)
 		return ret;
-	if (nf_log_register(PF_INET, &ipt_log_logger) < 0) {
-		printk(KERN_WARNING "ipt_LOG: not logging via system console "
-		       "since somebody else already registered for PF_INET\n");
-		/* we cannot make module load fail here, since otherwise
-		 * iptables userspace would abort */
-	}
-
-	return 0;
+	ret = nf_log_register(PF_INET, &ipt_log_logger);
+	if (ret < 0 && ret != -EEXIST)
+		xt_unregister_target(&ipt_log_reg);
+	return ret;
 }
 
 static void __exit ipt_log_fini(void)
net/ipv6/netfilter/ip6t_LOG.c +4 -8
index b465e24..5bb9cd3 100644
@@ -490,14 +490,10 @@ static int __init ip6t_log_init(void)
 	ret = xt_register_target(&ip6t_log_reg);
 	if (ret < 0)
 		return ret;
-	if (nf_log_register(PF_INET6, &ip6t_logger) < 0) {
-		printk(KERN_WARNING "ip6t_LOG: not logging via system console "
-		       "since somebody else already registered for PF_INET6\n");
-		/* we cannot make module load fail here, since otherwise
-		 * ip6tables userspace would abort */
-	}
-
-	return 0;
+	ret = nf_log_register(PF_INET6, &ip6t_logger);
+	if (ret < 0 && ret != -EEXIST)
+		xt_unregister_target(&ip6t_log_reg);
+	return ret;
 }
 
 static void __exit ip6t_log_fini(void)
#5 lore raw

PATCH 5/6 : nfnetlink_log: remove fallback to group 0

In reply to Patrick McHardy

[NETFILTER]: nfnetlink_log: remove fallback to group 0

Don't fallback to group 0 if no instance can be found for the given group. This potentially confuses the listener and is not what the user configured. Also remove the ring buffer spamming that happens when rules are set up before the logging daemon is started.

---
commit 3f1fbdbe77db881eb7bbcf30d806fae6109cda52
tree 2aa2f32e0dc7cf256f7d17b2a81e798ede5b8bc8
parent 474508878b875d838ec122f84193e48ea492f560
author Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:31 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:31 +0200

 net/netfilter/nfnetlink_log.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
net/netfilter/nfnetlink_log.c +0 -5
index d2c6aab..e32e30e 100644
@@ -584,12 +584,7 @@ nfulnl_log_packet(unsigned int pf,
 
 	inst = instance_lookup_get(li->u.ulog.group);
 	if (!inst)
-		inst = instance_lookup_get(0);
-	if (!inst) {
-		PRINTR("nfnetlink_log: trying to log packet, "
-			"but no instance for group %u\n", li->u.ulog.group);
 		return;
-	}
 
 	plen = 0;
 	if (prefix)
#6 lore raw

PATCH 6/6 : ipt_ULOG: add compat conversion functions

In reply to Patrick McHardy

[NETFILTER]: ipt_ULOG: add compat conversion functions

---
commit e50514026143f6a528f8a13f3ede23850c5f75bf
tree bdede48e4a7ee3c693c864b9a41ff5b6ccae5e92
parent 3f1fbdbe77db881eb7bbcf30d806fae6109cda52
author Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:40 +0200 committer Patrick McHardy <[email protected]> Fri, 13 Apr 2007 04:43:40 +0200

 net/ipv4/netfilter/ipt_ULOG.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ipt_ULOG.c +40 -0
index a36bf24..60dcf86 100644
@@ -348,12 +348,52 @@ static int ipt_ulog_checkentry(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+struct compat_ipt_ulog_info {
+	compat_uint_t	nl_group;
+	compat_size_t	copy_range;
+	compat_size_t	qthreshold;
+	char		prefix[ULOG_PREFIX_LEN];
+};
+
+static void compat_from_user(void *dst, void *src)
+{
+	struct compat_ipt_ulog_info *cl = src;
+	struct ipt_ulog_info l = {
+		.nl_group	= cl->nl_group,
+		.copy_range	= cl->copy_range,
+		.qthreshold	= cl->qthreshold,
+	};
+
+	memcpy(l.prefix, cl->prefix, sizeof(l.prefix));
+	memcpy(dst, &l, sizeof(l));
+}
+
+static int compat_to_user(void __user *dst, void *src)
+{
+	struct ipt_ulog_info *l = src;
+	struct compat_ipt_ulog_info cl = {
+		.nl_group	= l->nl_group,
+		.copy_range	= l->copy_range,
+		.qthreshold	= l->qthreshold,
+	};
+
+	memcpy(cl.prefix, l->prefix, sizeof(cl.prefix));
+	return copy_to_user(dst, &cl, sizeof(cl)) ? -EFAULT : 0;
+}
+#endif /* CONFIG_COMPAT */
+
 static struct xt_target ipt_ulog_reg = {
 	.name		= "ULOG",
 	.family		= AF_INET,
 	.target		= ipt_ulog_target,
 	.targetsize	= sizeof(struct ipt_ulog_info),
 	.checkentry	= ipt_ulog_checkentry,
+#ifdef CONFIG_COMPAT
+	.compatsize	= sizeof(struct compat_ipt_ulog_info),
+	.compat_from_user = compat_from_user,
+	.compat_to_user	= compat_to_user,
+#endif
 	.me		= THIS_MODULE,
 };
 
maintainer
#7 lore raw
In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Fri, 13 Apr 2007 05:00:08 +0200 (MEST)

Quoted 11 lines

Hi Dave,

following are a few netfilter patches for 2.6.22, adding support for filtering encapsulated PPPoE and gratuitous ARP packets in bridge netfilter, compat support for ipt_ULOG (as mentioned in the other thread, 32 bit userspace can already deal with log messages sent by a 64 bit kernel, but the kernel currently does not support adding new rules from a 32 bit iptables binary), some misc netfilter logging cleanup and support for using HW checksumming for forwarded packets mangled by NAT helpers.

Please apply, thanks.

All looks good, applied, thanks Patrick.