@@ -1129,7 +1129,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
11291129 mtu = dst -> dev -> mtu ;
11301130
11311131 if (unlikely (dst_metric_locked (dst , RTAX_MTU ))) {
1132- if (rt -> rt_gateway && mtu > 576 )
1132+ if (rt -> rt_uses_gateway && mtu > 576 )
11331133 mtu = 576 ;
11341134 }
11351135
@@ -1180,7 +1180,9 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
11801180 if (fnhe -> fnhe_gw ) {
11811181 rt -> rt_flags |= RTCF_REDIRECTED ;
11821182 rt -> rt_gateway = fnhe -> fnhe_gw ;
1183- }
1183+ rt -> rt_uses_gateway = 1 ;
1184+ } else if (!rt -> rt_gateway )
1185+ rt -> rt_gateway = daddr ;
11841186
11851187 orig = rcu_dereference (fnhe -> fnhe_rth );
11861188 rcu_assign_pointer (fnhe -> fnhe_rth , rt );
@@ -1189,13 +1191,6 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
11891191
11901192 fnhe -> fnhe_stamp = jiffies ;
11911193 ret = true;
1192- } else {
1193- /* Routes we intend to cache in nexthop exception have
1194- * the DST_NOCACHE bit clear. However, if we are
1195- * unsuccessful at storing this route into the cache
1196- * we really need to set it.
1197- */
1198- rt -> dst .flags |= DST_NOCACHE ;
11991194 }
12001195 spin_unlock_bh (& fnhe_lock );
12011196
@@ -1218,15 +1213,8 @@ static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt)
12181213 if (prev == orig ) {
12191214 if (orig )
12201215 rt_free (orig );
1221- } else {
1222- /* Routes we intend to cache in the FIB nexthop have
1223- * the DST_NOCACHE bit clear. However, if we are
1224- * unsuccessful at storing this route into the cache
1225- * we really need to set it.
1226- */
1227- rt -> dst .flags |= DST_NOCACHE ;
1216+ } else
12281217 ret = false;
1229- }
12301218
12311219 return ret ;
12321220}
@@ -1287,8 +1275,10 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
12871275 if (fi ) {
12881276 struct fib_nh * nh = & FIB_RES_NH (* res );
12891277
1290- if (nh -> nh_gw && nh -> nh_scope == RT_SCOPE_LINK )
1278+ if (nh -> nh_gw && nh -> nh_scope == RT_SCOPE_LINK ) {
12911279 rt -> rt_gateway = nh -> nh_gw ;
1280+ rt -> rt_uses_gateway = 1 ;
1281+ }
12921282 dst_init_metrics (& rt -> dst , fi -> fib_metrics , true);
12931283#ifdef CONFIG_IP_ROUTE_CLASSID
12941284 rt -> dst .tclassid = nh -> nh_tclassid ;
@@ -1297,8 +1287,18 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
12971287 cached = rt_bind_exception (rt , fnhe , daddr );
12981288 else if (!(rt -> dst .flags & DST_NOCACHE ))
12991289 cached = rt_cache_route (nh , rt );
1300- }
1301- if (unlikely (!cached ))
1290+ if (unlikely (!cached )) {
1291+ /* Routes we intend to cache in nexthop exception or
1292+ * FIB nexthop have the DST_NOCACHE bit clear.
1293+ * However, if we are unsuccessful at storing this
1294+ * route into the cache we really need to set it.
1295+ */
1296+ rt -> dst .flags |= DST_NOCACHE ;
1297+ if (!rt -> rt_gateway )
1298+ rt -> rt_gateway = daddr ;
1299+ rt_add_uncached_list (rt );
1300+ }
1301+ } else
13021302 rt_add_uncached_list (rt );
13031303
13041304#ifdef CONFIG_IP_ROUTE_CLASSID
@@ -1366,6 +1366,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
13661366 rth -> rt_iif = 0 ;
13671367 rth -> rt_pmtu = 0 ;
13681368 rth -> rt_gateway = 0 ;
1369+ rth -> rt_uses_gateway = 0 ;
13691370 INIT_LIST_HEAD (& rth -> rt_uncached );
13701371 if (our ) {
13711372 rth -> dst .input = ip_local_deliver ;
@@ -1435,7 +1436,6 @@ static int __mkroute_input(struct sk_buff *skb,
14351436 return - EINVAL ;
14361437 }
14371438
1438-
14391439 err = fib_validate_source (skb , saddr , daddr , tos , FIB_RES_OIF (* res ),
14401440 in_dev -> dev , in_dev , & itag );
14411441 if (err < 0 ) {
@@ -1491,6 +1491,7 @@ static int __mkroute_input(struct sk_buff *skb,
14911491 rth -> rt_iif = 0 ;
14921492 rth -> rt_pmtu = 0 ;
14931493 rth -> rt_gateway = 0 ;
1494+ rth -> rt_uses_gateway = 0 ;
14941495 INIT_LIST_HEAD (& rth -> rt_uncached );
14951496
14961497 rth -> dst .input = ip_forward ;
@@ -1658,6 +1659,7 @@ out: return err;
16581659 rth -> rt_iif = 0 ;
16591660 rth -> rt_pmtu = 0 ;
16601661 rth -> rt_gateway = 0 ;
1662+ rth -> rt_uses_gateway = 0 ;
16611663 INIT_LIST_HEAD (& rth -> rt_uncached );
16621664 if (res .type == RTN_UNREACHABLE ) {
16631665 rth -> dst .input = ip_error ;
@@ -1826,6 +1828,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
18261828 rth -> rt_iif = orig_oif ? : 0 ;
18271829 rth -> rt_pmtu = 0 ;
18281830 rth -> rt_gateway = 0 ;
1831+ rth -> rt_uses_gateway = 0 ;
18291832 INIT_LIST_HEAD (& rth -> rt_uncached );
18301833
18311834 RT_CACHE_STAT_INC (out_slow_tot );
@@ -2104,6 +2107,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
21042107 rt -> rt_flags = ort -> rt_flags ;
21052108 rt -> rt_type = ort -> rt_type ;
21062109 rt -> rt_gateway = ort -> rt_gateway ;
2110+ rt -> rt_uses_gateway = ort -> rt_uses_gateway ;
21072111
21082112 INIT_LIST_HEAD (& rt -> rt_uncached );
21092113
@@ -2182,7 +2186,7 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
21822186 if (nla_put_be32 (skb , RTA_PREFSRC , fl4 -> saddr ))
21832187 goto nla_put_failure ;
21842188 }
2185- if (rt -> rt_gateway &&
2189+ if (rt -> rt_uses_gateway &&
21862190 nla_put_be32 (skb , RTA_GATEWAY , rt -> rt_gateway ))
21872191 goto nla_put_failure ;
21882192
0 commit comments