: Netfilter update
Subsystems (3)
cover : Netfilter update
Hi Dave,
these patches include Herbert's SIP fix, the GRE memory corruption fix, a change to the DNAT target to accept the port randomization option and some small bridge netfilter cleanup.
Please apply, thanks.
include/linux/netfilter/nf_conntrack_proto_gre.h | 18 --- include/linux/netfilter_bridge.h | 25 ++-- net/bridge/br_netfilter.c | 138 ++++++----------------- net/ipv4/netfilter/nf_nat_proto_gre.c | 20 +-- net/ipv4/netfilter/nf_nat_rule.c | 4 net/ipv4/netfilter/nf_nat_sip.c | 26 ++++ 6 files changed, 89 insertions(+), 142 deletions(-)
Herbert Xu (1):
[NETFILTER]: sip: Fix RTP address NAT
Jorge Boncompte (1):
[NETFILTER]: nf_nat_proto_gre: do not modify/corrupt GREv0 packets through NAT
Patrick McHardy (2):
[NETFILTER]: ipt_DNAT: accept port randomization option [NETFILTER]: bridge netfilter: consolidate header pushing/pulling code
PATCH 1/4 : ipt_DNAT: accept port randomization option
[NETFILTER]: ipt_DNAT: accept port randomization option
Also accept the --random option for DNAT to allow randomly selecting a destination port from the given range.
---
commit 316258f1e782f387bcd01fd81d673aaeec24b8dc
tree 99e75850f1927d958ee195cb9294f8b6b15302f9
parent dc87c3985e9b442c60994308a96f887579addc39
author Patrick McHardy <[email protected]> Wed, 02 May 2007 16:17:22 +0200 committer Patrick McHardy <[email protected]> Wed, 02 May 2007 16:17:22 +0200
net/ipv4/netfilter/nf_nat_rule.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
net/ipv4/netfilter/nf_nat_rule.c +0 -4
@@ -226,10 +226,6 @@ static int ipt_dnat_checkentry(const char *tablename,printk ("DNAT: multiple ranges no longer supported\n" );return 0 ; } -if (mr->range[0 ].flags &IP_NAT_RANGE_PROTO_RANDOM ) { -printk ("DNAT: port randomization not supported\n" ); -return 0 ; - }return 1 ; }
Re: [NETFILTER 01/04]: ipt_DNAT: accept port randomization option
From: Patrick McHardy <[email protected]>
Date: Thu, 3 May 2007 03:25:57 +0200 (MEST)
Quoted 6 lines
[NETFILTER]:
ipt_DNAT: accept port randomization optionAlso accept the --random option for DNAT to allow randomly selecting a destination port from the given range.
Signed-off-by Patrick McHardy <[email protected]>
Applied.
PATCH 2/4 : nf_nat_proto_gre: do not modify/corrupt GREv0 packets through NAT
In reply to Patrick McHardy[NETFILTER]: nf_nat_proto_gre: do not modify/corrupt GREv0 packets through NAT
While porting some changes of the 2.6.21-rc7 pptp/proto_gre conntrack and nat modules to a 2.4.32 kernel I noticed that the gre_key function returns a wrong pointer to the GRE key of a version 0 packet thus corrupting the packet payload.
The intended behaviour for GREv0 packets is to act like nf_conntrack_proto_generic/nf_nat_proto_unknown so I have ripped the offending functions (not used anymore) and modified the nf_nat_proto_gre modules to not touch version 0 (non PPTP) packets.
---
commit 08130cb0faa275f6a8290a39942e58c18cec3533
tree 01dab60a8b7759c68701292b636000bc063492d3
parent 316258f1e782f387bcd01fd81d673aaeec24b8dc
author Jorge Boncompte <[email protected]> Wed, 02 May 2007 16:17:31 +0200 committer Patrick McHardy <[email protected]> Thu, 03 May 2007 02:51:46 +0200
include/linux/netfilter/nf_conntrack_proto_gre.h | 18 ------------------ net/ipv4/netfilter/nf_nat_proto_gre.c | 20 ++++++++------------ 2 files changed, 8 insertions(+), 30 deletions(-)
include/linux/netfilter/nf_conntrack_proto_gre.h +0 -18
@@ -87,24 +87,6 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir,/* delete keymap entries */ void nf_ct_gre_keymap_destroy (struct nf_conn *ct); -/* get pointer to gre key, if present */ -static inline __be32 *gre_key (struct gre_hdr *greh) -{ -if (!greh->key) -return NULL ; -if (greh->csum || greh->routing) -return (__be32 *)(greh+sizeof (*greh)+4 ); -return (__be32 *)(greh+sizeof (*greh)); -} - -/* get pointer ot gre csum, if present */ -static inline __sum16 *gre_csum (struct gre_hdr *greh) -{ -if (!greh->csum) -return NULL ; -return (__sum16 *)(greh+sizeof (*greh)); -} -extern void nf_ct_gre_keymap_flush (void );extern void nf_nat_need_gre (void );
net/ipv4/netfilter/nf_nat_proto_gre.c +8 -12
@@ -72,6 +72,11 @@ gre_unique_tuple(struct nf_conntrack_tuple *tuple,__be16 *keyptr;unsigned int min, i, range_size; +/* If there is no master conntrack we are not PPTP, +do not change tuples */ +if (!conntrack->master) +return 0 ; +if (maniptype ==IP_NAT_MANIP_SRC ) keyptr = &tuple->src.u.gre.key;else
@@ -122,18 +127,9 @@ gre_manip_pkt(struct sk_buff **pskb, unsigned int iphdroff,if (maniptype !=IP_NAT_MANIP_DST )return 1 ;switch (greh->version) { -case 0 : -if (!greh->key) { -DEBUGP ("can't nat GRE w/o key\n" ); -break ; - } -if (greh->csum) { -/* FIXME: Never tested this code... */ -nf_proto_csum_replace4 (gre_csum (greh), *pskb, - *(gre_key (greh)), - tuple->dst.u.gre.key,0 ); - } - *(gre_key (greh)) = tuple->dst.u.gre.key; +case GRE_VERSION_1701 : +/* We do not currently NAT any GREv0 packets. +* Try to behave like "nf_nat_proto_unknown" */ break ;case GRE_VERSION_PPTP :DEBUGP ("call_id -> 0x%04x\n" ,ntohs (tuple->dst.u.gre.key));
Re: [NETFILTER 02/04]: nf_nat_proto_gre: do not modify/corrupt GREv0 packets through NAT
From: Patrick McHardy <[email protected]>
Date: Thu, 3 May 2007 03:25:59 +0200 (MEST)
Quoted 7 lines
[NETFILTER]:
nf_nat_proto_gre: do not modify/corrupt GREv0 packets through NATWhile porting some changes of the 2.6.21-rc7 pptp/proto_gre conntrack and nat modules to a 2.4.32 kernel I noticed that the
gre_keyfunction returns a wrong pointer to the GRE key of a version 0 packet thus corrupting the packet payload.
Quoted 7 lines
The intended behaviour for GREv0 packets is to act like nf_conntrack_proto_generic/nf_nat_proto_unknown so I have ripped the offending functions (not used anymore) and modified the
nf_nat_proto_gremodules to not touch version 0 (non PPTP) packets.Signed-off-by Jorge Boncompte <[email protected]>Signed-off-by Patrick McHardy <[email protected]>
Applied.
PATCH 3/4 : sip: Fix RTP address NAT
In reply to Patrick McHardy[NETFILTER]: sip: Fix RTP address NAT
I needed to use this recently to talk to a Cisco server. In my case I only did SNAT while the Cisco server used a different address for RTP traffic than the one for SIP. I discovered that nf_nat_sip NATed the RTP address to the SIP one which was unnecessary but OK. However, in doing so it did not DNAT the destination address on the RTP traffic to the Cisco back to the original RTP address.
This patch corrects this by noting down the RTP address and using it when the expectation fires.
---
commit 63ce4c4edbf300cf7c5b1d219feca1e687bdbc4b
tree 105983a8043f83a79b0149eb8acc2c189217288d
parent 08130cb0faa275f6a8290a39942e58c18cec3533
author Herbert Xu <[email protected]> Wed, 02 May 2007 16:17:39 +0200 committer Patrick McHardy <[email protected]> Thu, 03 May 2007 02:51:50 +0200
net/ipv4/netfilter/nf_nat_sip.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-)
net/ipv4/netfilter/nf_nat_sip.c +25 -1
@@ -222,6 +222,29 @@ static unsigned int mangle_sdp(struct sk_buff **pskb,return mangle_content_len (pskb, ctinfo, ct, dptr); } +static void ip_nat_sdp_expect (struct nf_conn *ct, +struct nf_conntrack_expect *exp) +{ +struct nf_nat_range range; + +/* This must be a fresh one. */ +BUG_ON (ct->status &IPS_NAT_DONE_MASK ); + +/* Change src to where master sends to */ + range.flags =IP_NAT_RANGE_MAP_IPS ; + range.min_ip = range.max_ip + = ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip; +/* hook doesn't matter, but it has to do source manip */ +nf_nat_setup_info (ct, &range,NF_IP_POST_ROUTING ); + +/* For DST manip, map port here to where it's expected. */ + range.flags = (IP_NAT_RANGE_MAP_IPS |IP_NAT_RANGE_PROTO_SPECIFIED ); + range.min = range.max = exp->saved_proto; + range.min_ip = range.max_ip = exp->saved_ip; +/* hook doesn't matter, but it has to do destination manip */ +nf_nat_setup_info (ct, &range,NF_IP_PRE_ROUTING ); +} +/* So, this packet has hit the connection tracking matching code. Mangle it, and change the expectation to match the new version. */ static unsigned int ip_nat_sdp(struct sk_buff **pskb,
@@ -239,13 +262,14 @@ static unsigned int ip_nat_sdp(struct sk_buff **pskb,/* Connection will come from reply */ newip = ct->tuplehash[!dir].tuple.dst.u3.ip; + exp->saved_ip = exp->tuple.dst.u3.ip; exp->tuple.dst.u3.ip = newip; exp->saved_proto.udp.port = exp->tuple.dst.u.udp.port; exp->dir = !dir;/* When you see the packet, we need to NAT it the same as the this one. */ - exp->expectfn = nf_nat_follow_master; + exp->expectfn = ip_nat_sdp_expect;/* Try to get same port: if not, try to change it. */ for (port =ntohs (exp->saved_proto.udp.port); port !=0 ; port++) {
Re: [NETFILTER 03/04]: sip: Fix RTP address NAT
From: Patrick McHardy <[email protected]>
Date: Thu, 3 May 2007 03:26:00 +0200 (MEST)
Quoted 9 lines
[NETFILTER]: sip: Fix RTP address NAT
I needed to use this recently to talk to a Cisco server. In my case I only did SNAT while the Cisco server used a different address for RTP traffic than the one for SIP. I discovered that
nf_nat_sipNATed the RTP address to the SIP one which was unnecessary but OK. However, in doing so it did not DNAT the destination address on the RTP traffic to the Cisco back to the original RTP address.
Quoted 5 lines
This patch corrects this by noting down the RTP address and using it when the expectation fires.
Signed-off-by Herbert Xu <[email protected]>Signed-off-by Patrick McHardy <[email protected]>
Applied.
PATCH 4/4 : bridge netfilter: consolidate header pushing/pulling code
In reply to Patrick McHardy[NETFILTER]: bridge netfilter: consolidate header pushing/pulling code
Consolidate the common push/pull sequences into a few helper functions.
---
commit e439550c01bb8fa2eff00a2dfb4cfd26a966e8ce
tree 43331213cbcf138328638dce0075cbedb20e5ba3
parent 63ce4c4edbf300cf7c5b1d219feca1e687bdbc4b
author Patrick McHardy <[email protected]> Wed, 02 May 2007 16:17:51 +0200 committer Patrick McHardy <[email protected]> Thu, 03 May 2007 02:51:50 +0200
include/linux/netfilter_bridge.h | 25 ++++--- net/bridge/br_netfilter.c | 138 +++++++++++--------------------------- 2 files changed, 56 insertions(+), 107 deletions(-)
include/linux/netfilter_bridge.h +16 -9
@@ -55,18 +55,25 @@ static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)return 0 ; } +static inline unsigned int nf_bridge_encap_header_len (const struct sk_buff *skb) +{ +switch (skb->protocol) { +case __constant_htons (ETH_P_8021Q ): +return VLAN_HLEN ; +case __constant_htons (ETH_P_PPP_SES ): +return PPPOE_SES_HLEN ; +default : +return 0 ; + } +} +/* This is called by the IP fragmenting code and it ensures there is * enough room for the encapsulating header (if there is one). */ -static inline int nf_bridge_pad (const struct sk_buff *skb) +static inline unsigned int nf_bridge_pad (const struct sk_buff *skb) { -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; +if (skb->nf_bridge) +return nf_bridge_encap_header_len (skb); +return 0 ; }struct bridge_skb_cb {
net/bridge/br_netfilter.c +40 -98
227 lines not on this page · raw message
David Miller
maintainerRe: [NETFILTER 04/04]: bridge netfilter: consolidate header pushing/pulling code
From: Patrick McHardy <[email protected]>
Date: Thu, 3 May 2007 03:26:01 +0200 (MEST)
Quoted 5 lines
[NETFILTER]: bridge netfilter: consolidate header pushing/pulling code
Consolidate the common push/pull sequences into a few helper functions.
Signed-off-by Patrick McHardy <[email protected]>
Also applied, thanks.