fix REJECT for bridged traffic
Subsystems (3)
PATCH 1/1 fix REJECT for bridged traffic
Hi,
The attached patch does the following:
1. fix a bug introduced in commit 9d02002d2dc2c7423e5891b97727fde4d667adf1 (2/10/2006) which made ipt_REJECT stop work for bridged traffic (use of nskb instead of oldskb)
2. use the correct source MAC address for the response (bug reported in bug 531 of netfilter's bugzilla)
Tested for plain IP traffic and IP traffic encapsulated inside a VLAN header (should also work for PPPoE encapsulated IP traffic).
cheers,
Bart
Signature · 2 lines
Bart De Schuymer www.artinalgorithms.be
include/linux/netfilter_bridge.h renamed from include/linux/netfilter_bridge.h.ori +10 -0
@@ -44,6 +44,7 @@ enum nf_br_hook_priorities {#define BRNF_DONT_TAKE_PARENT 0x04#define BRNF_BRIDGED 0x08#define BRNF_NF_BRIDGE_PREROUTING 0x10 +#define BRNF_COPY_MAC_SADDR 0x20/* Only used in br_forward.c */
@@ -77,6 +78,15 @@ static inline unsigned int nf_bridge_padreturn 0 ; } +static inline struct nf_bridge_info *nf_bridge_alloc (struct sk_buff *skb) +{ + skb->nf_bridge =kzalloc (sizeof (struct nf_bridge_info ),GFP_ATOMIC ); +if (likely (skb->nf_bridge)) +atomic_set (&(skb->nf_bridge->use),1 ); + +return skb->nf_bridge; +} + struct bridge_skb_cb { union { __be32 ipv4;
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +7 -9
@@ -145,15 +145,6 @@ static inline struct net_device *bridge_return port ? port->br->dev :NULL ; } -static inline struct nf_bridge_info *nf_bridge_alloc (struct sk_buff *skb) -{ - skb->nf_bridge =kzalloc (sizeof (struct nf_bridge_info ),GFP_ATOMIC ); -if (likely (skb->nf_bridge)) -atomic_set (&(skb->nf_bridge->use),1 ); - -return skb->nf_bridge; -} -static inline struct nf_bridge_info *nf_bridge_unshare (struct sk_buff *skb) {struct nf_bridge_info *nf_bridge = skb->nf_bridge;
@@ -775,6 +766,13 @@ static unsigned int br_nf_local_out(unsireturn NF_DROP ; nf_bridge = skb->nf_bridge; +/* Enable complete transparency for e.g. ipt_REJECT */ +if (nf_bridge->mask &BRNF_COPY_MAC_SADDR ) { +skb_copy_to_linear_data_offset (skb,-8 , nf_bridge->data,6 ); +nf_bridge_put (nf_bridge); + skb->nf_bridge =NULL ; +return NF_ACCEPT ; + }if (!(nf_bridge->mask &BRNF_BRIDGED_DNAT ))return NF_ACCEPT ;
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +11 -3
@@ -100,11 +100,19 @@ static void send_reset(struct sk_buff *o sizeof(struct tcphdr), 0)); addr_type =RTN_UNSPEC ; -if (hook !=NF_INET_FORWARD #ifdef CONFIG_BRIDGE_NETFILTER - || (nskb->nf_bridge && nskb->nf_bridge->mask &BRNF_BRIDGED ) +if (oldskb->nf_bridge && oldskb->nf_bridge->mask &BRNF_BRIDGED ) { +int daddr_offset =-14 -nf_bridge_encap_header_len (oldskb); + + addr_type =RTN_LOCAL ; +if (!nf_bridge_alloc (nskb)) + goto free_nskb; + nskb->nf_bridge->mask |=BRNF_COPY_MAC_SADDR ; +skb_copy_from_linear_data_offset (oldskb, daddr_offset, + nskb->nf_bridge->data,6 ); + } else#endif - ) +if (hook !=NF_INET_FORWARD ) addr_type =RTN_LOCAL ;/* ip_route_me_harder expects skb->dst to be set */
Quoted 16 lines · Bart De Schuymer
Hi,
The attached patch does the following:
1. fix a bug introduced in commit9d02002d2dc2c7423e5891b97727fde4d667adf1(2/10/2006) which madeipt_REJECTstop work for bridged traffic (use of nskb instead of oldskb)
2. use the correct source MAC address for the response (bug reported in bug 531 of netfilter's bugzilla)Tested for plain IP traffic and IP traffic encapsulated inside a VLAN header (should also work for PPPoE encapsulated IP traffic).
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsi · line 771
Quoted 6 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +3
-0@@ -775,6 +766,13 @@ static unsigned int br_nf_local_out(unsireturn NF_DROP ; nf_bridge = skb->nf_bridge; +/* Enable complete transparency for e.g. ipt_REJECT */ +if (nf_bridge->mask &BRNF_COPY_MAC_SADDR ) { +skb_copy_to_linear_data_offset (skb,-8 , nf_bridge->data,6 );
Please use the proper ETH_*LEN values. I guess that would be skb_copy_to_linear_data_offset(skb, -(ETH_HLEN - ETH_ALEN),
nf_bridge->data, ETH_ALEN)
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsi · line 774
Quoted 3 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +3
-0+nf_bridge_put (nf_bridge); + skb->nf_bridge =NULL ; +return NF_ACCEPT ;
Shouldn't packets with BRNF_BRIDGED_DNAT continue through NF_BR_FORWARD like they used to?
Quoted 12 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +1
-0+ }if (!(nf_bridge->mask &BRNF_BRIDGED_DNAT ))return NF_ACCEPT ;net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +0
-1@@ -100,11 +100,19 @@ static void send_reset(struct sk_buff *o sizeof(struct tcphdr), 0)); addr_type =RTN_UNSPEC ; - if (hook != NF_INET_FORWARD#ifdef CONFIG_BRIDGE_NETFILTER
net/ipv4/netfilter/ipt_REJECT.c static void send_reset(struct sk_buff *o · line 112
Quoted 10 lines
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +9
-1- || (nskb->nf_bridge && nskb->nf_bridge->mask & BRNF_BRIDGED) +if (oldskb->nf_bridge && oldskb->nf_bridge->mask &BRNF_BRIDGED ) { +int daddr_offset =-14 -nf_bridge_encap_header_len (oldskb); + + addr_type =RTN_LOCAL ; +if (!nf_bridge_alloc (nskb)) + goto free_nskb; + nskb->nf_bridge->mask |=BRNF_COPY_MAC_SADDR ; +skb_copy_from_linear_data_offset (oldskb, daddr_offset, + nskb->nf_bridge->data,6 );
Also proper ETH_* values please. But I'm wondering, we already save the entire header in br_nf_post_routing(). Can't that be done earlier so the upper layers don't have to care about this stuff and can simply attach the original nf_bridge reference?
I'm also wondering - how are ICMP rejects handled?
net/ipv4/netfilter/ipt_REJECT.c static void send_reset(struct sk_buff *o · line 116
Quoted 5 lines
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +2
-1+ } else#endif - ) +if (hook !=NF_INET_FORWARD ) addr_type =RTN_LOCAL ;
We used to route all bridged packets as RTN_LOCAL for some reason which I'm not sure of. This is not necessary anymore?
Patrick McHardy schreef:
Quoted 28 lines
Quoted 16 lines · Bart De Schuymer
Hi,
The attached patch does the following:
1. fix a bug introduced in commit9d02002d2dc2c7423e5891b97727fde4d667adf1(2/10/2006) which madeipt_REJECTstop work for bridged traffic (use of nskb instead of oldskb)
2. use the correct source MAC address for the response (bug reported in bug 531 of netfilter's bugzilla)Tested for plain IP traffic and IP traffic encapsulated inside a VLAN header (should also work for PPPoE encapsulated IP traffic).
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsi · line 772
Quoted 7 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +3
-0@@ -775,6 +766,13 @@ static unsigned int br_nf_local_out(unsireturn NF_DROP ; nf_bridge = skb->nf_bridge; +/* Enable complete transparency for e.g. ipt_REJECT */ +if (nf_bridge->mask &BRNF_COPY_MAC_SADDR ) { +skb_copy_to_linear_data_offset (skb,-8 , nf_bridge->data,6 );Please use the proper ETH_*LEN values. I guess that would be skb_copy_to_linear_data_offset(skb, -(ETH_HLEN -
ETH_ALEN),
Quoted 3 lines
nf_bridge->data, ETH_ALEN)
Done, see attached patch.
Quoted 9 lines
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsi · line 776
Quoted 4 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +3
-0+nf_bridge_put (nf_bridge); + skb->nf_bridge =NULL ; +return NF_ACCEPT ;Shouldn't packets with
BRNF_BRIDGED_DNATcontinue throughNF_BR_FORWARDlike they used to?
Yes. It is impossible for an skbuff to have both flags set.
Quoted 20 lines
Quoted 20 lines
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +1
-0+ }if (!(nf_bridge->mask &BRNF_BRIDGED_DNAT ))net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +0
-0return NF_ACCEPT ;net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +7
-2@@ -100,11 +100,19 @@ static void send_reset(struct sk_buff *o sizeof(struct tcphdr), 0)); addr_type =RTN_UNSPEC ; -if (hook !=NF_INET_FORWARD #ifdef CONFIG_BRIDGE_NETFILTER - || (nskb->nf_bridge && nskb->nf_bridge->mask & BRNF_BRIDGED) +if (oldskb->nf_bridge && oldskb->nf_bridge->mask &BRNF_BRIDGED ) { +int daddr_offset =-14 -nf_bridge_encap_header_len (oldskb); + + addr_type =RTN_LOCAL ; +if (!nf_bridge_alloc (nskb)) + goto free_nskb; + nskb->nf_bridge->mask |=BRNF_COPY_MAC_SADDR ;
Quoted 10 lines
net/ipv4/netfilter/ipt_REJECT.c static void send_reset(struct sk_buff *o · line 113
Quoted 3 lines
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +2
-0+skb_copy_from_linear_data_offset (oldskb, daddr_offset, + nskb->nf_bridge->data,6 );Also proper ETH_* values please. But I'm wondering, we already save the entire header in
br_nf_post_routing(). Can't that be done earlier so the upper layers don't have to care about this stuff and can simply attach the originalnf_bridgereference?
If you don't save the correct MAC address for the newly created skbuff in ipt_REJECT, there is no way to get it back later. Furthermore, if you save the header too early, MAC SNAT and DNAT might have changed the header and you have to resave the header anyway.
Quoted 3 lines
I'm also wondering - how are ICMP rejects handled?
Good question :-)
ICMP packets currently get sent with a source IP and MAC address of the bridge. If the bridge doesn't have an IP address but does have a suitable route, the source address is 0.0.0.0. I'll look into fixing this.
Quoted 11 lines
net/ipv4/netfilter/ipt_REJECT.c static void send_reset(struct sk_buff *o · line 118
Quoted 6 lines
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +2
-1+ } else#endif - ) +if (hook !=NF_INET_FORWARD ) addr_type =RTN_LOCAL ;We used to route all bridged packets as
RTN_LOCALfor some reason which I'm not sure of. This is not necessary anymore?
Yes it is still necessary and it's in the patch. There used to be special code for bridge-netfilter in send_reset because we didn't want to enforce ip_forward to be enabled to be able to send the reset answers (there used to be a comment about that in ipt_REJECT). However, the commit I mentioned above rewrote the send_reset function and enabling ip_forward isn't enough anymore: it doesn't work without RTN_LOCAL.
cheers,
Bart
Signature · 2 lines
Bart De Schuymer www.artinalgorithms.be
include/linux/netfilter_bridge.h renamed from include/linux/netfilter_bridge.h.ori +10 -0
@@ -44,6 +44,7 @@ enum nf_br_hook_priorities {#define BRNF_DONT_TAKE_PARENT 0x04#define BRNF_BRIDGED 0x08#define BRNF_NF_BRIDGE_PREROUTING 0x10 +#define BRNF_COPY_MAC_SADDR 0x20/* Only used in br_forward.c */
@@ -77,6 +78,15 @@ static inline unsigned int nf_bridge_padreturn 0 ; } +static inline struct nf_bridge_info *nf_bridge_alloc (struct sk_buff *skb) +{ + skb->nf_bridge =kzalloc (sizeof (struct nf_bridge_info ),GFP_ATOMIC ); +if (likely (skb->nf_bridge)) +atomic_set (&(skb->nf_bridge->use),1 ); + +return skb->nf_bridge; +} + struct bridge_skb_cb { union { __be32 ipv4;
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.fixed +8 -9
@@ -145,15 +145,6 @@ static inline struct net_device *bridge_return port ? port->br->dev :NULL ; } -static inline struct nf_bridge_info *nf_bridge_alloc (struct sk_buff *skb) -{ - skb->nf_bridge =kzalloc (sizeof (struct nf_bridge_info ),GFP_ATOMIC ); -if (likely (skb->nf_bridge)) -atomic_set (&(skb->nf_bridge->use),1 ); - -return skb->nf_bridge; -} -static inline struct nf_bridge_info *nf_bridge_unshare (struct sk_buff *skb) {struct nf_bridge_info *nf_bridge = skb->nf_bridge;
@@ -775,6 +766,14 @@ static unsigned int br_nf_local_out(unsireturn NF_DROP ; nf_bridge = skb->nf_bridge; +/* Enable complete transparency for e.g. ipt_REJECT */ +if (nf_bridge->mask &BRNF_COPY_MAC_SADDR ) { +skb_copy_to_linear_data_offset (skb, -(ETH_HLEN -ETH_ALEN ), + nf_bridge->data,ETH_ALEN ); +nf_bridge_put (nf_bridge); + skb->nf_bridge =NULL ; +return NF_ACCEPT ; + }if (!(nf_bridge->mask &BRNF_BRIDGED_DNAT ))return NF_ACCEPT ;
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.ori +11 -3
@@ -100,11 +100,19 @@ static void send_reset(struct sk_buff *o sizeof(struct tcphdr), 0)); addr_type =RTN_UNSPEC ; -if (hook !=NF_INET_FORWARD #ifdef CONFIG_BRIDGE_NETFILTER - || (nskb->nf_bridge && nskb->nf_bridge->mask &BRNF_BRIDGED ) +if (oldskb->nf_bridge && oldskb->nf_bridge->mask &BRNF_BRIDGED ) { +int daddr_offset = -ETH_HLEN -nf_bridge_encap_header_len (oldskb); + + addr_type =RTN_LOCAL ; +if (!nf_bridge_alloc (nskb)) + goto free_nskb; + nskb->nf_bridge->mask |=BRNF_COPY_MAC_SADDR ; +skb_copy_from_linear_data_offset (oldskb, daddr_offset, + nskb->nf_bridge->data,ETH_ALEN ); + } else#endif - ) +if (hook !=NF_INET_FORWARD ) addr_type =RTN_LOCAL ;/* ip_route_me_harder expects skb->dst to be set */
Quoted 11 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 6 lines
Also proper ETH_* values please. But I'm wondering, we already save the entire header in
br_nf_post_routing(). Can't that be done earlier so the upper layers don't have to care about this stuff and can simply attach the originalnf_bridgereference?If you don't save the correct MAC address for the newly created skbuff in
ipt_REJECT, there is no way to get it back later. Furthermore, if you save the header too early, MAC SNAT and DNAT might have changed the header and you have to resave the header anyway.
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
nskb->nf_bridge = nf_bridge_get(oskb->nf_bridge)
in ipt_REJECT and probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.
Quoted 7 lines
Quoted 3 lines
I'm also wondering - how are ICMP rejects handled?
Good question :-)
ICMP packets currently get sent with a source IP and MAC address of the bridge. If the bridge doesn't have an IP address but does have a suitable route, the source address is 0.0.0.0. I'll look into fixing this.
Patrick McHardy schreef:
Quoted 17 lines
Quoted 9 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 7 lines
Also proper ETH_* values please. But I'm wondering, we already save the entire header in
br_nf_post_routing(). Can't that be done earlier so the upper layers don't have to care about this stuff and can simply attach the originalnf_bridgereference?Quoted 5 lines
If you don't save the correct MAC address for the newly created skbuff in
ipt_REJECT, there is no way to get it back later. Furthermore, if you save the header too early, MAC SNAT and DNAT might have changed the header and you have to resave the header anyway.
Quoted 9 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.
Patrick,
The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time. How will you know in PREROUTING what SMAC to use if you didn't save it when you created the skbuf?
cheers,
Bart
Signature · 2 lines
Bart De Schuymer www.artinalgorithms.be
Quoted 4 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 3 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
Quoted 8 lines
Quoted 6 lines
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time.
That's what I'm doing above.
Quoted 3 lines
How will you know in
PREROUTING what SMAC to use if you didn't save it when you created the skbuf?
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the nf_bridge data from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.
Quoted 20 lines · Patrick McHardy
Quoted 4 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 3 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
Quoted 8 lines
Quoted 6 lines
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time.
That's what I'm doing above.
Quoted 3 lines
How will you know in
PREROUTING what SMAC to use if you didn't save it when you created the skbuf?
Quoted 6 lines
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the
nf_bridgedata from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.
This patchTo demonstrate the idea
Quoted 19 lines · Patrick McHardy
Quoted 18 lines · Patrick McHardy
Quoted 4 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 3 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
Quoted 8 lines
Quoted 6 lines
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time.
That's what I'm doing above.
Quoted 3 lines
How will you know in
PREROUTING what SMAC to use if you didn't save it when you created the skbuf?
Quoted 8 lines
Quoted 6 lines
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the
nf_bridgedata from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.This patchTo demonstrate the idea
Please ignore, hit the wrong key :)
Quoted 20 lines · Patrick McHardy
Quoted 4 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 3 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
Quoted 8 lines
Quoted 6 lines
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time.
That's what I'm doing above.
Quoted 3 lines
How will you know in
PREROUTING what SMAC to use if you didn't save it when you created the skbuf?
Quoted 6 lines
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the
nf_bridgedata from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.
This patch demonstrates the idea. Its not compile tested and incomplete, just to make more clear what I'm suggesting.
include/linux/skbuff.h +2 -1
@@ -1952,10 +1952,11 @@ static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)if (nf_bridge &&atomic_dec_and_test (&nf_bridge->use)) kfree(nf_bridge); } -static inline void nf_bridge_get (struct nf_bridge_info *nf_bridge) +static inline struct nf_bridge_info *nf_bridge_get (struct nf_bridge_info *nf_bridge) {if (nf_bridge)atomic_inc (&nf_bridge->use); +return nf_bridge; }#endif /* CONFIG_BRIDGE_NETFILTER */ static inline void nf_reset (struct sk_buff *skb)
net/bridge/br_netfilter.c +3 -1
@@ -567,6 +567,8 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,return NF_ACCEPT ;#endif nf_bridge_pull_encap_header_rcsum (skb); +nf_bridge_save_header (skb); +return br_nf_pre_routing_ipv6 (hook, skb, in, out, okfn); }#ifdef CONFIG_SYSCTL
@@ -579,6 +581,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,return NF_ACCEPT ;nf_bridge_pull_encap_header_rcsum (skb); +nf_bridge_save_header (skb);if (!pskb_may_pull (skb,sizeof (struct iphdr ))) goto inhdr_error;
@@ -863,7 +866,6 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb, }nf_bridge_pull_encap_header (skb); -nf_bridge_save_header (skb);NF_HOOK (pf,NF_INET_POST_ROUTING , skb,NULL , realoutdev, br_nf_dev_queue_xmit);
net/bridge/netfilter/ebt_dnat.c +1 -0
@@ -23,6 +23,7 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_target_param *par)return EBT_DROP ;memcpy (eth_hdr (skb)->h_dest, info->mac,ETH_ALEN ); +/* update nf_bridge info */ return info->target; }
net/bridge/netfilter/ebt_snat.c +1 -0
@@ -25,6 +25,7 @@ ebt_snat_tg(struct sk_buff *skb, const struct xt_target_param *par)return EBT_DROP ;memcpy (eth_hdr (skb)->h_source, info->mac,ETH_ALEN ); +/* update nf_bridge info */ if (!(info->target &NAT_ARP_BIT ) &ð_hdr (skb)->h_proto ==htons (ETH_P_ARP )) {const struct arphdr *ap;
net/ipv4/netfilter/ipt_REJECT.c +2 -0
@@ -107,6 +107,8 @@ static void send_reset(struct sk_buff *oldskb, int hook) ) addr_type =RTN_LOCAL ; + nskb->nf_bridge =nf_bridge_get (oldskb->nf_bridge); +/* ip_route_me_harder expects skb->dst to be set */ skb_dst_set (nskb,dst_clone (skb_dst (oldskb)));
Patrick McHardy schreef:
Quoted 34 lines
Quoted 24 lines · Patrick McHardy
Quoted 7 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 5 lines
Yes, we need to save it at some point. My idea was that we might be able to save it in PREROUTING instead of POSTROUTING and only do
nskb->nf_bridge=nf_bridge_get(oskb->nf_bridge)Quoted 8 lines
Quoted 5 lines
in
ipt_REJECTand probably also the ICMP code. MAC NAT could be handled by updating the bridge info simultaneously.The code creates a new skbuf and the correct source MAC address is lost if you don't attach it to the skbuf at that time.
That's what I'm doing above.
Quoted 4 lines
How will you know in
PREROUTING what SMAC to use if you didn't save it when you created the skbuf?Quoted 7 lines
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the
nf_bridgedata from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.
Quoted 3 lines
This patch demonstrates the idea. Its not compile tested and incomplete, just to make more clear what I'm suggesting.
OK, that sounds good. Much cleaner. Sorry for misunderstanding you, it's Friday evening... I'll look into it.
cheers,
Bart
Signature · 2 lines
Bart De Schuymer www.artinalgorithms.be
Quoted 8 lines · Bart De Schuymer
Patrick McHardy schreef:
Quoted 4 lines
This patch demonstrates the idea. Its not compile tested and incomplete, just to make more clear what I'm suggesting.
OK, that sounds good. Much cleaner. Sorry for misunderstanding you, it's Friday evening...
I'll look into it.
Great, thanks.
Quoted 11 lines · Patrick McHardy
Quoted 7 lines
I'm not sure I understand what you're getting at. The above line of code would do exactly that, attach the
nf_bridgedata from the original packet to the newly created one. But for this to work we need to make sure its valid in all hooks, hence my suggestion to save it in PREROUTING instead of POSTROUTING.This patch demonstrates the idea. Its not compile tested and incomplete, just to make more clear what I'm suggesting.
[patch in non-inlined form]
For a final one you also want to modify ip6t_REJECT.