diff -urp v4.3-before-nf_reroute/linux/include/net/flow.h linux/include/net/flow.h
--- v4.3-before-nf_reroute/linux/include/net/flow.h	2015-11-04 10:00:12.000000000 +0200
+++ linux/include/net/flow.h	2015-11-07 18:22:42.051244643 +0200
@@ -88,6 +88,7 @@ struct flowi4 {
 #define fl4_ipsec_spi		uli.spi
 #define fl4_mh_type		uli.mht.type
 #define fl4_gre_key		uli.gre_key
+	__be32			fl4_gw;
 } __attribute__((__aligned__(BITS_PER_LONG/8)));
 
 static inline void flowi4_init_output(struct flowi4 *fl4, int oif,
@@ -109,6 +110,7 @@ static inline void flowi4_init_output(st
 	fl4->saddr = saddr;
 	fl4->fl4_dport = dport;
 	fl4->fl4_sport = sport;
+	fl4->fl4_gw = 0;
 }
 
 /* Reset some input parameters after previous lookup */
diff -urp v4.3-before-nf_reroute/linux/include/net/netfilter/nf_nat.h linux/include/net/netfilter/nf_nat.h
--- v4.3-before-nf_reroute/linux/include/net/netfilter/nf_nat.h	2014-12-12 01:02:26.000000000 +0200
+++ linux/include/net/netfilter/nf_nat.h	2015-11-07 18:22:42.051244643 +0200
@@ -38,6 +38,11 @@ struct nf_conn_nat {
 #endif
 };
 
+/* Call input routing for SNAT-ed traffic */
+unsigned int ip_nat_route_input(const struct nf_hook_ops *ops,
+				struct sk_buff *skb,
+				const struct nf_hook_state *state);
+
 /* Set up the info structure to map into this range. */
 unsigned int nf_nat_setup_info(struct nf_conn *ct,
 			       const struct nf_nat_range *range,
diff -urp v4.3-before-nf_reroute/linux/include/net/route.h linux/include/net/route.h
--- v4.3-before-nf_reroute/linux/include/net/route.h	2015-11-04 10:00:12.000000000 +0200
+++ linux/include/net/route.h	2015-11-07 18:22:42.052244629 +0200
@@ -197,6 +197,8 @@ unsigned int inet_addr_type_dev_table(st
 void ip_rt_multicast_event(struct in_device *);
 int ip_rt_ioctl(struct net *, unsigned int cmd, void __user *arg);
 void ip_rt_get_source(u8 *src, struct sk_buff *skb, struct rtable *rt);
+int ip_route_input_lookup(struct sk_buff*, __be32 dst, __be32 src, u8 tos,
+			  struct net_device *devin, __be32 lsrc);
 
 struct in_ifaddr;
 void fib_add_ifaddr(struct in_ifaddr *);
diff -urp v4.3-before-nf_reroute/linux/net/bridge/br_netfilter_hooks.c linux/net/bridge/br_netfilter_hooks.c
--- v4.3-before-nf_reroute/linux/net/bridge/br_netfilter_hooks.c	2015-11-04 10:00:13.000000000 +0200
+++ linux/net/bridge/br_netfilter_hooks.c	2015-11-07 18:22:42.052244629 +0200
@@ -352,6 +352,9 @@ static int br_nf_pre_routing_finish(stru
 
 	nf_bridge->frag_max_size = IPCB(skb)->frag_max_size;
 
+	/* Old skb->dst is not expected, it is lost in all cases */
+	skb_dst_drop(skb);
+
 	if (nf_bridge->pkt_otherhost) {
 		skb->pkt_type = PACKET_OTHERHOST;
 		nf_bridge->pkt_otherhost = false;
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/fib_frontend.c linux/net/ipv4/fib_frontend.c
--- v4.3-before-nf_reroute/linux/net/ipv4/fib_frontend.c	2015-11-07 18:22:19.491561723 +0200
+++ linux/net/ipv4/fib_frontend.c	2015-11-07 18:24:11.490987551 +0200
@@ -308,6 +308,7 @@ __be32 fib_compute_spec_dst(struct sk_bu
 		fl4.flowi4_scope = scope;
 		fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
 		fl4.flowi4_tun_key.tun_id = 0;
+		fl4.fl4_gw = 0;
 		if (!fib_lookup(net, &fl4, &res, 0))
 			return FIB_RES_PREFSRC(net, res);
 	} else {
@@ -348,6 +349,7 @@ static int __fib_validate_source(struct
 	fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
 	fl4.flowi4_tun_key.tun_id = 0;
 	fl4.flowi4_flags = 0;
+	fl4.fl4_gw = 0;
 
 	no_addr = idev->ifa_list == NULL;
 
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/fib_semantics.c linux/net/ipv4/fib_semantics.c
--- v4.3-before-nf_reroute/linux/net/ipv4/fib_semantics.c	2015-11-07 18:22:19.492561709 +0200
+++ linux/net/ipv4/fib_semantics.c	2015-11-07 18:22:42.054244601 +0200
@@ -444,6 +444,9 @@ static int fib_detect_death(struct fib_i
 	for (nhsel = 0, nh = fi->fib_nh; nhsel < fi->fib_nhs; nh++, nhsel++) {
 		if (flp->flowi4_oif && flp->flowi4_oif != nh->nh_oif)
 			continue;
+		if (flp->fl4_gw && flp->fl4_gw != nh->nh_gw && nh->nh_gw &&
+		    nh->nh_scope == RT_SCOPE_LINK)
+			continue;
 		if (nh->nh_flags & RTNH_F_DEAD)
 			continue;
 
@@ -1620,6 +1623,10 @@ void fib_select_multipath(const struct f
 		change_nexthops(fi) {
 			if (flp->flowi4_oif != nexthop_nh->nh_oif)
 				continue;
+			if (flp->fl4_gw && flp->fl4_gw != nexthop_nh->nh_gw &&
+			    nexthop_nh->nh_gw &&
+			    nexthop_nh->nh_scope == RT_SCOPE_LINK)
+				continue;
 			in_dev = __in_dev_get_rcu(nexthop_nh->nh_dev);
 			down = in_dev &&
 			       IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
@@ -1691,6 +1698,9 @@ last_resort:
 		if (!(nh->nh_flags & RTNH_F_DEAD)) {
 			if (flp->flowi4_oif && flp->flowi4_oif != nh->nh_oif)
 				continue;
+			if (flp->fl4_gw && flp->fl4_gw != nh->nh_gw &&
+			    nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK)
+				continue;
 			spin_unlock_bh(&fib_multipath_lock);
 			res->nh_sel = nhsel;
 			return;
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/fib_trie.c linux/net/ipv4/fib_trie.c
--- v4.3-before-nf_reroute/linux/net/ipv4/fib_trie.c	2015-11-04 10:00:13.000000000 +0200
+++ linux/net/ipv4/fib_trie.c	2015-11-07 18:26:34.959971067 +0200
@@ -1430,6 +1430,9 @@ found:
 				if (flp->flowi4_oif &&
 				    flp->flowi4_oif != nh->nh_oif)
 					continue;
+				if (flp->fl4_gw && flp->fl4_gw != nh->nh_gw &&
+				    nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK)
+					continue;
 			}
 
 			if (!(fib_flags & FIB_LOOKUP_NOREF))
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/netfilter/iptable_nat.c linux/net/ipv4/netfilter/iptable_nat.c
--- v4.3-before-nf_reroute/linux/net/ipv4/netfilter/iptable_nat.c	2015-06-27 10:24:23.000000000 +0300
+++ linux/net/ipv4/netfilter/iptable_nat.c	2015-11-07 18:22:42.055244587 +0200
@@ -91,6 +91,14 @@ static struct nf_hook_ops nf_nat_ipv4_op
 		.hooknum	= NF_INET_LOCAL_OUT,
 		.priority	= NF_IP_PRI_NAT_DST,
 	},
+	/* Before routing, route before mangling */
+	{
+		.hook		= ip_nat_route_input,
+		.owner		= THIS_MODULE,
+		.pf		= NFPROTO_IPV4,
+		.hooknum	= NF_INET_PRE_ROUTING,
+		.priority	= NF_IP_PRI_LAST-1,
+	},
 	/* After packet filtering, change source */
 	{
 		.hook		= iptable_nat_ipv4_fn,
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c linux/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c
--- v4.3-before-nf_reroute/linux/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c	2014-12-12 01:02:27.000000000 +0200
+++ linux/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c	2015-11-07 18:22:42.055244587 +0200
@@ -31,8 +31,8 @@ nf_nat_masquerade_ipv4(struct sk_buff *s
 	struct nf_conn_nat *nat;
 	enum ip_conntrack_info ctinfo;
 	struct nf_nat_range newrange;
-	const struct rtable *rt;
-	__be32 newsrc, nh;
+	struct rtable *rt;
+	__be32 newsrc;
 
 	NF_CT_ASSERT(hooknum == NF_INET_POST_ROUTING);
 
@@ -48,12 +48,23 @@ nf_nat_masquerade_ipv4(struct sk_buff *s
 	if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip == 0)
 		return NF_ACCEPT;
 
-	rt = skb_rtable(skb);
-	nh = rt_nexthop(rt, ip_hdr(skb)->daddr);
-	newsrc = inet_select_addr(out, nh, RT_SCOPE_UNIVERSE);
-	if (!newsrc) {
-		pr_info("%s ate my IP address\n", out->name);
-		return NF_DROP;
+	{
+		struct flowi4 fl4 = { .flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
+				      .flowi4_mark = skb->mark,
+				      .flowi4_oif = out->ifindex,
+				      .daddr = ip_hdr(skb)->daddr,
+				      .fl4_gw = skb_rtable(skb)->rt_gateway };
+		rt = ip_route_output_key(dev_net(out), &fl4);
+		if (IS_ERR(rt)) {
+			/* Funky routing can do this. */
+			if (net_ratelimit())
+				pr_info("%s:"
+				       " No route: Rusty's brain broke!\n",
+				       out->name);
+			return NF_DROP;
+		}
+		newsrc = fl4.saddr;
+		ip_rt_put(rt);
 	}
 
 	nat->masq_index = out->ifindex;
diff -urp v4.3-before-nf_reroute/linux/net/ipv4/route.c linux/net/ipv4/route.c
--- v4.3-before-nf_reroute/linux/net/ipv4/route.c	2015-11-07 18:22:19.493561695 +0200
+++ linux/net/ipv4/route.c	2015-11-07 18:25:47.900632495 +0200
@@ -1548,7 +1548,7 @@ static void ip_handle_martian_source(str
 static int __mkroute_input(struct sk_buff *skb,
 			   const struct fib_result *res,
 			   struct in_device *in_dev,
-			   __be32 daddr, __be32 saddr, u32 tos)
+			   __be32 daddr, __be32 saddr, u32 tos, __be32 lsrc)
 {
 	struct fib_nh_exception *fnhe;
 	struct rtable *rth;
@@ -1575,7 +1575,7 @@ static int __mkroute_input(struct sk_buf
 
 	do_cache = res->fi && !itag;
 	if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
-	    skb->protocol == htons(ETH_P_IP) &&
+	    skb->protocol == htons(ETH_P_IP) && !lsrc &&
 	    (IN_DEV_SHARED_MEDIA(out_dev) ||
 	     inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
 		IPCB(skb)->flags |= IPSKB_DOREDIRECT;
@@ -1651,7 +1651,7 @@ static int ip_mkroute_input(struct sk_bu
 			    struct net *net,
 			    const struct flowi4 *fl4,
 			    struct in_device *in_dev,
-			    __be32 daddr, __be32 saddr, u32 tos)
+			    __be32 daddr, __be32 saddr, u32 tos, __be32 lsrc)
 {
 	fib_select_default(fl4, res);
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -1660,7 +1660,7 @@ static int ip_mkroute_input(struct sk_bu
 #endif
 
 	/* create a routing cache entry */
-	return __mkroute_input(skb, res, in_dev, daddr, saddr, tos);
+	return __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc);
 }
 
 /*
@@ -1675,7 +1675,7 @@ static int ip_mkroute_input(struct sk_bu
  */
 
 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-			       u8 tos, struct net_device *dev)
+			       u8 tos, struct net_device *dev, __be32 lsrc)
 {
 	struct fib_result res;
 	struct in_device *in_dev = __in_dev_get_rcu(dev);
@@ -1731,18 +1731,28 @@ static int ip_route_input_slow(struct sk
 			goto martian_source;
 	}
 
+	if (lsrc) {
+		if (ipv4_is_multicast(lsrc) || ipv4_is_lbcast(lsrc) ||
+		    ipv4_is_zeronet(lsrc) || ipv4_is_loopback(lsrc))
+			goto martian_source;
+	}
+
 	/*
 	 *	Now we are ready to route packet.
 	 */
 	fl4.flowi4_oif = 0;
-	fl4.flowi4_iif = vrf_master_ifindex_rcu(dev) ? : dev->ifindex;
+	fl4.flowi4_iif = lsrc ? LOOPBACK_IFINDEX :
+			 (vrf_master_ifindex_rcu(dev) ? : dev->ifindex);
 	fl4.flowi4_mark = skb->mark;
 	fl4.flowi4_tos = tos;
 	fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
 	fl4.flowi4_flags = 0;
 	fl4.daddr = daddr;
-	fl4.saddr = saddr;
+	fl4.saddr = lsrc? : saddr;
+	fl4.fl4_gw = 0;
 	err = fib_lookup(net, &fl4, &res, 0);
+	fl4.flowi4_iif = vrf_master_ifindex_rcu(dev) ? : dev->ifindex;
+	fl4.saddr = saddr;
 	if (err != 0) {
 		if (!IN_DEV_FORWARD(in_dev))
 			err = -EHOSTUNREACH;
@@ -1767,12 +1777,15 @@ static int ip_route_input_slow(struct sk
 	if (res.type != RTN_UNICAST)
 		goto martian_destination;
 
-	err = ip_mkroute_input(skb, &res, net, &fl4, in_dev, daddr, saddr, tos);
+	err = ip_mkroute_input(skb, &res, net, &fl4, in_dev, daddr, saddr,
+		tos, lsrc);
 out:	return err;
 
 brd_input:
 	if (skb->protocol != htons(ETH_P_IP))
 		goto e_inval;
+	if (lsrc)
+		goto e_inval;
 
 	if (!ipv4_is_zeronet(saddr)) {
 		err = fib_validate_source(skb, saddr, 0, tos, 0, dev,
@@ -1867,8 +1880,9 @@ martian_source_keep_err:
 	goto out;
 }
 
-int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-			 u8 tos, struct net_device *dev)
+int ip_route_input_noref_common(struct sk_buff *skb, __be32 daddr,
+				__be32 saddr, u8 tos, struct net_device *dev,
+				__be32 lsrc)
 {
 	int res;
 
@@ -1907,12 +1921,25 @@ int ip_route_input_noref(struct sk_buff
 		rcu_read_unlock();
 		return -EINVAL;
 	}
-	res = ip_route_input_slow(skb, daddr, saddr, tos, dev);
+	res = ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
 	rcu_read_unlock();
 	return res;
 }
+
+int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
+			 u8 tos, struct net_device *dev)
+{
+	return ip_route_input_noref_common(skb, daddr, saddr, tos, dev, 0);
+}
 EXPORT_SYMBOL(ip_route_input_noref);
 
+int ip_route_input_lookup(struct sk_buff *skb, __be32 daddr, __be32 saddr,
+			  u8 tos, struct net_device *dev, __be32 lsrc)
+{
+	return ip_route_input_noref_common(skb, daddr, saddr, tos, dev, lsrc);
+}
+EXPORT_SYMBOL(ip_route_input_lookup);
+
 /* called with rcu_read_lock() */
 static struct rtable *__mkroute_output(const struct fib_result *res,
 				       const struct flowi4 *fl4, int orig_oif,
@@ -2152,6 +2179,7 @@ struct rtable *__ip_route_output_key(str
 			fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK);
 		dev_out = net->loopback_dev;
 		fl4->flowi4_oif = LOOPBACK_IFINDEX;
+		fl4->fl4_gw = 0;
 		res.type = RTN_LOCAL;
 		flags |= RTCF_LOCAL;
 		goto make_route;
@@ -2199,6 +2227,7 @@ struct rtable *__ip_route_output_key(str
 		}
 		dev_out = net->loopback_dev;
 		fl4->flowi4_oif = dev_out->ifindex;
+		fl4->fl4_gw = 0;
 		flags |= RTCF_LOCAL;
 		goto make_route;
 	}
diff -urp v4.3-before-nf_reroute/linux/net/netfilter/nf_nat_core.c linux/net/netfilter/nf_nat_core.c
--- v4.3-before-nf_reroute/linux/net/netfilter/nf_nat_core.c	2015-11-04 10:00:13.000000000 +0200
+++ linux/net/netfilter/nf_nat_core.c	2015-11-07 18:22:42.057244559 +0200
@@ -848,6 +848,49 @@ static struct nf_ct_helper_expectfn foll
 	.expectfn	= nf_nat_follow_master,
 };
 
+unsigned int ip_nat_route_input(const struct nf_hook_ops *ops,
+				struct sk_buff *skb,
+				const struct nf_hook_state *state)
+{
+	struct iphdr *iph;
+	struct nf_conn *conn;
+	enum ip_conntrack_info ctinfo;
+	enum ip_conntrack_dir dir;
+	unsigned long statusbit;
+	__be32 saddr;
+
+	if (!(conn = nf_ct_get(skb, &ctinfo)))
+		return NF_ACCEPT;
+
+	if (!(conn->status & IPS_NAT_DONE_MASK))
+		return NF_ACCEPT;
+	dir = CTINFO2DIR(ctinfo);
+	statusbit = IPS_SRC_NAT;
+	if (dir == IP_CT_DIR_REPLY)
+		statusbit ^= IPS_NAT_MASK;
+	if (!(conn->status & statusbit))
+		return NF_ACCEPT;
+
+	if (skb_dst(skb))
+		return NF_ACCEPT;
+
+	if (skb->len < sizeof(struct iphdr))
+		return NF_ACCEPT;
+
+	/* use daddr in other direction as masquerade address (lsrc) */
+	iph = ip_hdr(skb);
+	saddr = conn->tuplehash[!dir].tuple.dst.u3.ip;
+	if (saddr == iph->saddr)
+		return NF_ACCEPT;
+
+	if (ip_route_input_lookup(skb, iph->daddr, iph->saddr, iph->tos,
+	    skb->dev, saddr))
+		return NF_DROP;
+
+	return NF_ACCEPT;
+}
+EXPORT_SYMBOL_GPL(ip_nat_route_input);
+
 static int __init nf_nat_init(void)
 {
 	int ret;
