: Small netfilter update
Subsystems (3)
cover : Small netfilter update
Hi Dave,
following is a small netfilter update for 2.6.19. The first three patches are fixes (Kconfig dependency fix and Horms' LVS routing fix), one patch to remove the duplicated route_me_harder code from ipt_REJECT and Bart's ebt_mark patch. I know I'm a little late, but I hope its they're still fine since they're quite small.
Please apply, thanks.
include/linux/netfilter_bridge/ebt_mark_t.h | 12 +++ include/linux/netfilter_ipv4.h | 2 net/bridge/netfilter/ebt_mark.c | 21 ++++-- net/ipv4/ipvs/ip_vs_core.c | 10 ++ net/ipv4/netfilter.c | 9 +- net/ipv4/netfilter/ip_nat_standalone.c | 3 net/ipv4/netfilter/ipt_REJECT.c | 97 +++++----------------------- net/ipv4/netfilter/iptable_mangle.c | 3 net/netfilter/Kconfig | 2 9 files changed, 70 insertions(+), 89 deletions(-)
Bart De Schuymer:
[NETFILTER]: ebt_mark: add or/and/xor action support to mark target
Patrick McHardy:
[NETFILTER]: Kconfig: fix xt_physdev dependencies [NETFILTER]: ipt_REJECT: remove largely duplicate route_reverse function
Simon Horman:
[NETFILTER]: add type parameter to ip_route_me_harder [NETFILTER]: Honour source routing for LVS-NAT
PATCH 1/5 : Kconfig: fix xt_physdev dependencies
[NETFILTER]: Kconfig: fix xt_physdev dependencies
xt_physdev depends on bridge netfilter, which is a boolean, but can still be built modular because of special handling in the bridge makefile. Add a dependency on BRIDGE to prevent XT_MATCH_PHYSDEV=y, BRIDGE=m.
---
commit 2f253e95a172eaec7de29e3f0951d3a20d3f904c
tree fa38b574cf9b05743058ef38a3fa38bf28a1a399
parent 6656e3c4c8e0c80f2d2bfece574876d269f64861
author Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:35 +0200 committer Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:35 +0200
net/netfilter/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/Kconfig +1 -1
@@ -365,7 +365,7 @@ config NETFILTER_XT_MATCH_MULTIPORT config NETFILTER_XT_MATCH_PHYSDEV tristate '"physdev" match support' - depends on NETFILTER_XTABLES && BRIDGE_NETFILTER + depends on NETFILTER_XTABLES && BRIDGE && BRIDGE_NETFILTER help Physdev packet matching matches against the physical bridge ports the IP packet arrived on or will leave by.
PATCH 2/5 : add type parameter to ip_route_me_harder
In reply to Patrick McHardy[NETFILTER]: add type parameter to ip_route_me_harder
By adding a type parameter to ip_route_me_harder() the expensive call to inet_addr_type() can be avoided in some cases. A followup patch where ip_route_me_harder() is called from within ip_vs_out() is one such example.
---
commit fa2cba7f2f3ce89d34fdb903f7d80494439e6b59
tree 06e54f9b5988869066c28fdedb438f4ce7a42702
parent 2f253e95a172eaec7de29e3f0951d3a20d3f904c
author Simon Horman <[email protected]> Mon, 02 Oct 2006 17:39:40 +0200 committer Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:40 +0200
include/linux/netfilter_ipv4.h | 2 +- net/ipv4/netfilter.c | 9 ++++++--- net/ipv4/netfilter/ip_nat_standalone.c | 3 ++- net/ipv4/netfilter/iptable_mangle.c | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-)
include/linux/netfilter_ipv4.h +1 -1
@@ -77,7 +77,7 @@ enum nf_ip_hook_priorities {#define SO_ORIGINAL_DST 80#ifdef __KERNEL__ -extern int ip_route_me_harder (struct sk_buff **pskb); +extern int ip_route_me_harder (struct sk_buff **pskb,unsigned addr_type);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);
net/ipv4/netfilter.c +6 -3
@@ -8,7 +8,7 @@ #include <net/xfrm.h>#include <net/ip.h> /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ -int ip_route_me_harder (struct sk_buff **pskb) +int ip_route_me_harder (struct sk_buff **pskb,unsigned addr_type) {struct iphdr *iph = (*pskb)->nh.iph;struct rtable *rt;
@@ -16,10 +16,13 @@ int ip_route_me_harder(struct sk_buff **struct dst_entry *odst;unsigned int hh_len; +if (addr_type ==RTN_UNSPEC ) + addr_type =inet_addr_type (iph->saddr); +/* some non-standard hacks like ipt_REJECT.c:send_reset() can cause * packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook. */ -if (inet_addr_type (iph->saddr) ==RTN_LOCAL ) { +if (addr_type ==RTN_LOCAL ) { fl.nl_u.ip4_u.daddr = iph->daddr; fl.nl_u.ip4_u.saddr = iph->saddr; fl.nl_u.ip4_u.tos =RT_TOS (iph->tos);
@@ -156,7 +159,7 @@ static int nf_ip_reroute(struct sk_buffif (!(iph->tos == rt_info->tos && iph->daddr == rt_info->daddr && iph->saddr == rt_info->saddr)) -return ip_route_me_harder (pskb); +return ip_route_me_harder (pskb,RTN_UNSPEC ); }return 0 ; }
net/ipv4/netfilter/ip_nat_standalone.c +2 -1
@@ -265,7 +265,8 @@ #ifdef CONFIG_XFRM ct->tuplehash[!dir].tuple.src.u.all #endif ) - return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP; +if (ip_route_me_harder (pskb,RTN_UNSPEC )) + ret = NF_DROP; }return ret; }
net/ipv4/netfilter/iptable_mangle.c +2 -1
@@ -157,7 +157,8 @@ #ifdef CONFIG_IP_ROUTE_FWMARK || (*pskb)->nfmark != nfmark #endif || (*pskb)->nh.iph->tos != tos)) -return ip_route_me_harder (pskb) ==0 ? ret :NF_DROP ; +if (ip_route_me_harder (pskb,RTN_UNSPEC )) + ret =NF_DROP ; return ret; }
PATCH 3/5 : Honour source routing for LVS-NAT
In reply to Patrick McHardy[NETFILTER]: Honour source routing for LVS-NAT
For policy routing, packets originating from this machine itself may be routed differently to packets passing through. We want this packet to be routed as if it came from this machine itself. So re-compute the routing information using ip_route_me_harder().
This patch is derived from work by Ken Brownfield
---
commit 1bc8aeeaf12d73774421e408d7f6461a20cebc5e
tree 273fb8d8604554aecf263bef82a43f781a019333
parent fa2cba7f2f3ce89d34fdb903f7d80494439e6b59
author Simon Horman <[email protected]> Mon, 02 Oct 2006 17:39:45 +0200 committer Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:45 +0200
net/ipv4/ipvs/ip_vs_core.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
net/ipv4/ipvs/ip_vs_core.c +10 -0
@@ -813,6 +813,16 @@ ip_vs_out(unsigned int hooknum, struct s skb->nh.iph->saddr = cp->vaddr;ip_send_check (skb->nh.iph); +/* For policy routing, packets originating from this +* machine itself may be routed differently to packets +* passing through. We want this packet to be routed as +* if it came from this machine itself. So re-compute +* the routing information. +*/ +if (ip_route_me_harder (pskb,RTN_LOCAL ) !=0 ) + goto drop; + skb = *pskb; +IP_VS_DBG_PKT (10 , pp, skb,0 ,"After SNAT" );ip_vs_out_stats (cp, skb);
PATCH 4/5 : ipt_REJECT: remove largely duplicate route_reverse function
In reply to Patrick McHardy[NETFILTER]: ipt_REJECT: remove largely duplicate route_reverse function
Use ip_route_me_harder instead, which now allows to specify how we wish the packet to be routed.
Based on patch by Simon Horman <[email protected]>.
---
commit 606add40816396611545a6239c1029a473448d9f
tree 6a1e6e137c44132154b94a60ae10733f174f4ec2
parent 1bc8aeeaf12d73774421e408d7f6461a20cebc5e
author Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:49 +0200 committer Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:49 +0200
net/ipv4/netfilter/ipt_REJECT.c | 97 ++++++++------------------------------- 1 files changed, 19 insertions(+), 78 deletions(-)
net/ipv4/netfilter/ipt_REJECT.c +19 -78
@@ -38,76 +38,16 @@ #else #define DEBUGP(format, args...)#endif -static inline struct rtable *route_reverse (struct sk_buff *skb, -struct tcphdr *tcph,int hook) -{ -struct iphdr *iph = skb->nh.iph; -struct dst_entry *odst; -struct flowi fl = {}; -struct rtable *rt; - -/* We don't require ip forwarding to be enabled to be able to -* send a RST reply for bridged traffic. */ -if (hook !=NF_IP_FORWARD -#ifdef CONFIG_BRIDGE_NETFILTER - || (skb->nf_bridge && skb->nf_bridge->mask &BRNF_BRIDGED ) -#endif - ) { - fl.nl_u.ip4_u.daddr = iph->saddr; -if (hook ==NF_IP_LOCAL_IN ) - fl.nl_u.ip4_u.saddr = iph->daddr; - fl.nl_u.ip4_u.tos =RT_TOS (iph->tos); - -if (ip_route_output_key (&rt, &fl) !=0 ) -return NULL ; - }else { -/* non-local src, find valid iif to satisfy -* rp-filter when calling ip_route_input. */ - fl.nl_u.ip4_u.daddr = iph->daddr; -if (ip_route_output_key (&rt, &fl) !=0 ) -return NULL ; - - odst = skb->dst; -if (ip_route_input (skb, iph->saddr, iph->daddr, -RT_TOS (iph->tos), rt->u.dst.dev) !=0 ) { -dst_release (&rt->u.dst); -return NULL ; - } -dst_release (&rt->u.dst); - rt = (struct rtable *)skb->dst; - skb->dst = odst; - - fl.nl_u.ip4_u.daddr = iph->saddr; - fl.nl_u.ip4_u.saddr = iph->daddr; - fl.nl_u.ip4_u.tos =RT_TOS (iph->tos); - } - -if (rt->u.dst.error) { -dst_release (&rt->u.dst); -return NULL ; - } - - fl.proto =IPPROTO_TCP ; - fl.fl_ip_sport = tcph->dest; - fl.fl_ip_dport = tcph->source; -security_skb_classify_flow (skb, &fl); - -xfrm_lookup ((struct dst_entry **)&rt, &fl,NULL ,0 ); - -return rt; -} -/* Send RST reply */ static void send_reset (struct sk_buff *oldskb,int hook) {struct sk_buff *nskb;struct iphdr *iph = oldskb->nh.iph;struct tcphdr _otcph, *oth, *tcph; -struct rtable *rt;__be16 tmp_port;__be32 tmp_addr;int needs_ack; -int hh_len; +unsigned int addr_type;/* IP header checks: fragment. */ if (oldskb->nh.iph->frag_off &htons (IP_OFFSET ))
@@ -126,23 +66,13 @@ static void send_reset(struct sk_buff *oif (nf_ip_checksum (oldskb, hook, iph->ihl *4 ,IPPROTO_TCP ))return ; -if ((rt =route_reverse (oldskb, oth, hook)) ==NULL ) -return ; - - hh_len =LL_RESERVED_SPACE (rt->u.dst.dev); -/* We need a linear, writeable skb. We also need to expand headroom in case hh_len of incoming interface < hh_len of outgoing interface */ - nskb =skb_copy_expand (oldskb, hh_len,skb_tailroom (oldskb), + nskb =skb_copy_expand (oldskb,LL_MAX_HEADER ,skb_tailroom (oldskb),GFP_ATOMIC ); -if (!nskb) { -dst_release (&rt->u.dst); +if (!nskb)return ; - } - -dst_release (nskb->dst); - nskb->dst = &rt->u.dst;/* This packet will not be the same as the other: clear nf fields */ nf_reset (nskb);
@@ -184,6 +114,21 @@ static void send_reset(struct sk_buff *o tcph->window =0 ; tcph->urg_ptr =0 ; +/* Set DF, id = 0 */ + nskb->nh.iph->frag_off =htons (IP_DF ); + nskb->nh.iph->id =0 ; + + addr_type =RTN_UNSPEC ; +if (hook !=NF_IP_FORWARD +#ifdef CONFIG_BRIDGE_NETFILTER + || (nskb->nf_bridge && nskb->nf_bridge->mask &BRNF_BRIDGED ) +#endif + ) + addr_type =RTN_LOCAL ; + +if (ip_route_me_harder (&nskb, addr_type)) + goto free_nskb; +/* Adjust TCP checksum */ nskb->ip_summed =CHECKSUM_NONE ; tcph->check =0 ;
@@ -192,12 +137,8 @@ static void send_reset(struct sk_buff *o nskb->nh.iph->daddr,csum_partial ((char *)tcph, sizeof(struct tcphdr), 0)); - -/* Adjust IP TTL, DF */ +/* Adjust IP TTL */ nskb->nh.iph->ttl =dst_metric (nskb->dst,RTAX_HOPLIMIT ); -/* Set DF, id = 0 */ - nskb->nh.iph->frag_off =htons (IP_DF ); - nskb->nh.iph->id =0 ;/* Adjust IP checksum */ nskb->nh.iph->check =0 ;
PATCH 5/5 : ebt_mark: add or/and/xor action support to mark target
In reply to Patrick McHardy[NETFILTER]: ebt_mark: add or/and/xor action support to mark target
The following patch adds or/and/xor functionality for the mark target, while staying backwards compatible.
---
commit 9a2c1735d4cf9c120d67d9bf82bb4455804f2041
tree 9049c23fafecd717254cbe066c1f9e310e5227a8
parent 606add40816396611545a6239c1029a473448d9f
author Bart De Schuymer <[email protected]> Mon, 02 Oct 2006 17:39:55 +0200 committer Patrick McHardy <[email protected]> Mon, 02 Oct 2006 17:39:55 +0200
include/linux/netfilter_bridge/ebt_mark_t.h | 12 ++++++++++++ net/bridge/netfilter/ebt_mark.c | 21 +++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-)
include/linux/netfilter_bridge/ebt_mark_t.h +12 -0
@@ -1,6 +1,18 @@ #ifndef __LINUX_BRIDGE_EBT_MARK_T_H #define __LINUX_BRIDGE_EBT_MARK_T_H +/* The target member is reused for adding new actions, the + * value of the real target is -1 to -NUM_STANDARD_TARGETS. + * For backward compatibility, the 4 lsb (2 would be enough, + * but let's play it safe) are kept to designate this target. + * The remaining bits designate the action. By making the set + * action 0xfffffff0, the result will look ok for older + * versions. [September 2006] */ +#define MARK_SET_VALUE (0xfffffff0) +#define MARK_OR_VALUE (0xffffffe0) +#define MARK_AND_VALUE (0xffffffd0) +#define MARK_XOR_VALUE (0xffffffc0) + struct ebt_mark_t_info { unsigned long mark;
net/bridge/netfilter/ebt_mark.c +17 -4
@@ -22,24 +22,37 @@ static int ebt_target_mark(struct sk_buf const void *data, unsigned int datalen) {struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data; +int action = info->target &-16 ; -if ((*pskb)->nfmark != info->mark) +if (action ==MARK_SET_VALUE ) (*pskb)->nfmark = info->mark; +else if (action ==MARK_OR_VALUE ) + (*pskb)->nfmark |= info->mark; +else if (action ==MARK_AND_VALUE ) + (*pskb)->nfmark &= info->mark; +else + (*pskb)->nfmark ^= info->mark; -return info->target; +return info->target |-16 ; }static int ebt_target_mark_check (const char *tablename,unsigned int hookmask,const struct ebt_entry *e,void *data,unsigned int datalen) {struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data; +int tmp;if (datalen !=EBT_ALIGN (sizeof (struct ebt_mark_t_info )))return -EINVAL ; -if (BASE_CHAIN && info->target ==EBT_RETURN ) + tmp = info->target |-16 ; +if (BASE_CHAIN && tmp ==EBT_RETURN )return -EINVAL ;CLEAR_BASE_CHAIN_BIT ; -if (INVALID_TARGET ) +if (tmp < -NUM_STANDARD_TARGETS || tmp >=0 ) +return -EINVAL ; + tmp = info->target &-16 ; +if (tmp !=MARK_SET_VALUE && tmp !=MARK_OR_VALUE && + tmp !=MARK_AND_VALUE && tmp !=MARK_XOR_VALUE )return -EINVAL ;return 0 ; }
From: Patrick McHardy <[email protected]>
Date: Mon, 2 Oct 2006 17:46:03 +0200 (MEST)
Quoted 7 lines
following is a small netfilter update for 2.6.19. The first three patches are fixes (
Kconfigdependency fix and Horms' LVS routing fix), one patch to remove the duplicatedroute_me_hardercode fromipt_REJECTand Bart'sebt_markpatch. I know I'm a little late, but I hope its they're still fine since they're quite small.Please apply, thanks.
Applied.
Please submit the bug fixes as you see fit to -stable, in particular I'd like to see the Kconfig dependency fix go to 2.6.18-stable. You can use this signoff line for any of those patches when submitting to -stable, thanks:
Quoted 6 lines · David Miller
Please submit the bug fixes as you see fit to -stable, in particular I'd like to see the
Kconfigdependency fix go to 2.6.18-stable. You can use this signoff line for any of those patches when submitting to -stable, thanks:Signed-off-by David S. Miller <[email protected]>
Thanks, I'll push the first three patches today or tomorrow along with a few backports from my last patchset.