return rt->rt_route_iif == 0;
 }
 
+static inline __be32 rt_nexthop(const struct rtable *rt, __be32 daddr)
+{
+       if (rt->rt_gateway)
+               return rt->rt_gateway;
+       return daddr;
+}
+
 struct ip_rt_acct {
        __u32   o_bytes;
        __u32   o_packets;
 
                return 1;
        }
 
-       paddr = skb_rtable(skb)->rt_gateway;
-
+       paddr = rt_nexthop(skb_rtable(skb), ip_hdr(skb)->daddr);
        if (arp_set_predefined(inet_addr_type(dev_net(dev), paddr), haddr,
                               paddr, dev))
                return 0;
 
        rt = ip_route_output_flow(net, fl4, sk);
        if (IS_ERR(rt))
                goto no_route;
-       if (opt && opt->opt.is_strictroute && fl4->daddr != rt->rt_gateway)
+       if (opt && opt->opt.is_strictroute && rt->rt_gateway)
                goto route_err;
        return &rt->dst;
 
        rt = ip_route_output_flow(net, fl4, sk);
        if (IS_ERR(rt))
                goto no_route;
-       if (opt && opt->opt.is_strictroute && fl4->daddr != rt->rt_gateway)
+       if (opt && opt->opt.is_strictroute && rt->rt_gateway)
                goto route_err;
        return &rt->dst;
 
 
 
                if (skb->protocol == htons(ETH_P_IP)) {
                        rt = skb_rtable(skb);
-                       dst = rt->rt_gateway;
+                       dst = rt_nexthop(rt, old_iph->daddr);
                }
 #if IS_ENABLED(CONFIG_IPV6)
                else if (skb->protocol == htons(ETH_P_IPV6)) {
 
        skb_dst_set_noref(skb, &rt->dst);
 
 packet_routed:
-       if (inet_opt && inet_opt->opt.is_strictroute && fl4->daddr != rt->rt_gateway)
+       if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_gateway)
                goto no_route;
 
        /* OK, we know where to send it, allocate and build IP header. */
 
                        dev->stats.tx_fifo_errors++;
                        goto tx_error;
                }
-               dst = rt->rt_gateway;
+               dst = rt_nexthop(rt, old_iph->daddr);
        }
 
        rt = ip_route_output_ports(dev_net(dev), &fl4, NULL,
 
        struct nf_nat_ipv4_range newrange;
        const struct nf_nat_ipv4_multi_range_compat *mr;
        const struct rtable *rt;
-       __be32 newsrc;
+       __be32 newsrc, nh;
 
        NF_CT_ASSERT(par->hooknum == NF_INET_POST_ROUTING);
 
 
        mr = par->targinfo;
        rt = skb_rtable(skb);
-       newsrc = inet_select_addr(par->out, rt->rt_gateway, RT_SCOPE_UNIVERSE);
+       nh = rt_nexthop(rt, ip_hdr(skb)->daddr);
+       newsrc = inet_select_addr(par->out, nh, RT_SCOPE_UNIVERSE);
        if (!newsrc) {
                pr_info("%s ate my IP address\n", par->out->name);
                return NF_DROP;
 
                if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res) == 0)
                        src = FIB_RES_PREFSRC(dev_net(rt->dst.dev), res);
                else
-                       src = inet_select_addr(rt->dst.dev, rt->rt_gateway,
-                                       RT_SCOPE_UNIVERSE);
+                       src = inet_select_addr(rt->dst.dev,
+                                              rt_nexthop(rt, iph->daddr),
+                                              RT_SCOPE_UNIVERSE);
                rcu_read_unlock();
        }
        memcpy(addr, &src, 4);
        mtu = dst->dev->mtu;
 
        if (unlikely(dst_metric_locked(dst, RTAX_MTU))) {
-               if (rt->rt_gateway != 0 && mtu > 576)
+               if (rt->rt_gateway && mtu > 576)
                        mtu = 576;
        }
 
        rth->rt_iif     = dev->ifindex;
        rth->rt_oif     = 0;
        rth->rt_pmtu    = 0;
-       rth->rt_gateway = daddr;
+       rth->rt_gateway = 0;
        rth->fi = NULL;
        if (our) {
                rth->dst.input= ip_local_deliver;
        rth->rt_iif     = in_dev->dev->ifindex;
        rth->rt_oif     = 0;
        rth->rt_pmtu    = 0;
-       rth->rt_gateway = daddr;
+       rth->rt_gateway = 0;
        rth->fi = NULL;
 
        rth->dst.input = ip_forward;
        rth->rt_iif     = dev->ifindex;
        rth->rt_oif     = 0;
        rth->rt_pmtu    = 0;
-       rth->rt_gateway = daddr;
+       rth->rt_gateway = 0;
        rth->fi = NULL;
        if (res.type == RTN_UNREACHABLE) {
                rth->dst.input= ip_error;
        rth->rt_iif     = orig_oif ? : dev_out->ifindex;
        rth->rt_oif     = orig_oif;
        rth->rt_pmtu    = 0;
-       rth->rt_gateway = fl4->daddr;
+       rth->rt_gateway = 0;
        rth->fi = NULL;
 
        RT_CACHE_STAT_INC(out_slow_tot);
                if (nla_put_be32(skb, RTA_PREFSRC, fl4->saddr))
                        goto nla_put_failure;
        }
-       if (fl4->daddr != rt->rt_gateway &&
+       if (rt->rt_gateway &&
            nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway))
                goto nla_put_failure;