Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bridge: ebtables: fix reception of frames DNAT-ed to bridge device/port

When trying to redirect bridged frames to the bridge device itself or
a bridge port (brouting) via the dnat target then this currently fails:

The ethernet destination of the frame is dnat'ed to the MAC address of
the bridge device or port just fine. However, the IP code drops it in
the beginning of ip_input.c/ip_rcv() as the dnat target left
the skb->pkt_type as PACKET_OTHERHOST.

Fixing this by resetting skb->pkt_type to an appropriate type after
dnat'ing.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Linus Lüssing and committed by
Pablo Neira Ayuso
cf3cb246 6bd3d192

+20
+20
net/bridge/netfilter/ebt_dnat.c
··· 9 9 */ 10 10 #include <linux/module.h> 11 11 #include <net/sock.h> 12 + #include "../br_private.h" 12 13 #include <linux/netfilter.h> 13 14 #include <linux/netfilter/x_tables.h> 14 15 #include <linux/netfilter_bridge/ebtables.h> ··· 19 18 ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par) 20 19 { 21 20 const struct ebt_nat_info *info = par->targinfo; 21 + struct net_device *dev; 22 22 23 23 if (!skb_make_writable(skb, 0)) 24 24 return EBT_DROP; 25 25 26 26 ether_addr_copy(eth_hdr(skb)->h_dest, info->mac); 27 + 28 + if (is_multicast_ether_addr(info->mac)) { 29 + if (is_broadcast_ether_addr(info->mac)) 30 + skb->pkt_type = PACKET_BROADCAST; 31 + else 32 + skb->pkt_type = PACKET_MULTICAST; 33 + } else { 34 + if (xt_hooknum(par) != NF_BR_BROUTING) 35 + dev = br_port_get_rcu(xt_in(par))->br->dev; 36 + else 37 + dev = xt_in(par); 38 + 39 + if (ether_addr_equal(info->mac, dev->dev_addr)) 40 + skb->pkt_type = PACKET_HOST; 41 + else 42 + skb->pkt_type = PACKET_OTHERHOST; 43 + } 44 + 27 45 return info->target; 28 46 } 29 47