--- v2.4.19/linux/include/net/ip_fib.h Tue Nov 13 01:24:05 2001 +++ linux/include/net/ip_fib.h Sat May 4 13:24:04 2002 @@ -275,5 +275,6 @@ #endif } +extern rwlock_t fib_nhflags_lock; #endif /* _NET_FIB_H */ --- v2.4.19/linux/net/ipv4/fib_semantics.c Sat May 4 11:29:08 2002 +++ linux/net/ipv4/fib_semantics.c Sat May 4 13:26:07 2002 @@ -48,6 +48,7 @@ static struct fib_info *fib_info_list; static rwlock_t fib_info_lock = RW_LOCK_UNLOCKED; int fib_info_cnt; +rwlock_t fib_nhflags_lock = RW_LOCK_UNLOCKED; #define for_fib_info() { struct fib_info *fi; \ for (fi = fib_info_list; fi; fi = fi->fib_next) @@ -365,8 +366,11 @@ return -EINVAL; if ((dev = __dev_get_by_index(nh->nh_oif)) == NULL) return -ENODEV; - if (!(dev->flags&IFF_UP)) - return -ENETDOWN; + if (!(dev->flags&IFF_UP)) { + if (fi->fib_protocol != RTPROT_STATIC) + return -ENETDOWN; + nh->nh_flags |= RTNH_F_DEAD; + } nh->nh_dev = dev; atomic_inc(&dev->refcnt); nh->nh_scope = RT_SCOPE_LINK; @@ -380,23 +384,48 @@ /* It is not necessary, but requires a bit of thinking */ if (key.scope < RT_SCOPE_LINK) key.scope = RT_SCOPE_LINK; - if ((err = fib_lookup(&key, &res)) != 0) - return err; - err = -EINVAL; - if (res.type != RTN_UNICAST && res.type != RTN_LOCAL) - goto out; - nh->nh_scope = res.scope; - nh->nh_oif = FIB_RES_OIF(res); - if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL) - goto out; - atomic_inc(&nh->nh_dev->refcnt); - err = -ENETDOWN; - if (!(nh->nh_dev->flags & IFF_UP)) - goto out; - err = 0; + + err = fib_lookup(&key, &res); + if (err) { + struct in_device *in_dev; + + if (err != -ENETUNREACH || + fi->fib_protocol != RTPROT_STATIC) + return err; + + in_dev = inetdev_by_index(nh->nh_oif); + if (in_dev == NULL || + in_dev->dev->flags & IFF_UP) { + if (in_dev) + in_dev_put(in_dev); + return err; + } + nh->nh_flags |= RTNH_F_DEAD; + nh->nh_scope = RT_SCOPE_LINK; + nh->nh_dev = in_dev->dev; + atomic_inc(&nh->nh_dev->refcnt); + in_dev_put(in_dev); + } else { + err = -EINVAL; + if (res.type != RTN_UNICAST && res.type != RTN_LOCAL) + goto out; + nh->nh_scope = res.scope; + nh->nh_oif = FIB_RES_OIF(res); + if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL) + goto out; + atomic_inc(&nh->nh_dev->refcnt); + if (!(nh->nh_dev->flags & IFF_UP)) { + if (fi->fib_protocol != RTPROT_STATIC) { + err = -ENETDOWN; + goto out; + } + nh->nh_flags |= RTNH_F_DEAD; + } + err = 0; out: - fib_res_put(&res); - return err; + fib_res_put(&res); + return err; + } } else { struct in_device *in_dev; @@ -407,8 +436,11 @@ if (in_dev == NULL) return -ENODEV; if (!(in_dev->dev->flags&IFF_UP)) { - in_dev_put(in_dev); - return -ENETDOWN; + if (fi->fib_protocol != RTPROT_STATIC) { + in_dev_put(in_dev); + return -ENETDOWN; + } + nh->nh_flags |= RTNH_F_DEAD; } nh->nh_dev = in_dev->dev; atomic_inc(&nh->nh_dev->refcnt); @@ -870,22 +902,35 @@ if (local && fi->fib_prefsrc == local) { fi->fib_flags |= RTNH_F_DEAD; ret++; - } else if (dev && fi->fib_nhs) { + } else if (fi->fib_nhs) { int dead = 0; change_nexthops(fi) { - if (nh->nh_flags&RTNH_F_DEAD) - dead++; - else if (nh->nh_dev == dev && - nh->nh_scope != scope) { - nh->nh_flags |= RTNH_F_DEAD; + if (nh->nh_flags&RTNH_F_DEAD) { + if (fi->fib_protocol!=RTPROT_STATIC || + nh->nh_dev == NULL || + !__in_dev_get(nh->nh_dev) || + nh->nh_dev->flags&IFF_UP) + dead++; + } else if ((nh->nh_dev == dev && dev && + nh->nh_scope != scope) || + (local == nh->nh_gw && local && + nh->nh_oif)) { + write_lock_bh(&fib_nhflags_lock); #ifdef CONFIG_IP_ROUTE_MULTIPATH - spin_lock_bh(&fib_multipath_lock); + spin_lock(&fib_multipath_lock); + nh->nh_flags |= RTNH_F_DEAD; fi->fib_power -= nh->nh_power; nh->nh_power = 0; - spin_unlock_bh(&fib_multipath_lock); + spin_unlock(&fib_multipath_lock); +#else + nh->nh_flags |= RTNH_F_DEAD; #endif - dead++; + write_unlock_bh(&fib_nhflags_lock); + if (fi->fib_protocol!=RTPROT_STATIC || + force || + (dev && __in_dev_get(dev) == NULL)) + dead++; } #ifdef CONFIG_IP_ROUTE_MULTIPATH if (force > 1 && nh->nh_dev == dev) { @@ -903,37 +948,55 @@ return ret; } -#ifdef CONFIG_IP_ROUTE_MULTIPATH - /* - Dead device goes up. We wake up dead nexthops. - It takes sense only on multipath routes. + Dead device goes up or new address is added. We wake up dead nexthops. */ int fib_sync_up(struct net_device *dev) { - int ret = 0; + struct rt_key key; + struct fib_result res; + int ret, rep; +repeat: if (!(dev->flags&IFF_UP)) return 0; + ret = 0; + rep = 0; for_fib_info() { int alive = 0; change_nexthops(fi) { - if (!(nh->nh_flags&RTNH_F_DEAD)) { - alive++; + if (!(nh->nh_flags&RTNH_F_DEAD)) continue; - } if (nh->nh_dev == NULL || !(nh->nh_dev->flags&IFF_UP)) continue; if (nh->nh_dev != dev || __in_dev_get(dev) == NULL) continue; + if (nh->nh_gw && fi->fib_protocol == RTPROT_STATIC) { + memset(&key, 0, sizeof(key)); + key.dst = nh->nh_gw; + key.oif = nh->nh_oif; + key.scope = nh->nh_scope; + if (fib_lookup(&key, &res) != 0) + continue; + if (res.type != RTN_UNICAST && + res.type != RTN_LOCAL) { + fib_res_put(&res); + continue; + } + nh->nh_scope = res.scope; + fib_res_put(&res); + rep = 1; + } alive++; +#ifdef CONFIG_IP_ROUTE_MULTIPATH spin_lock_bh(&fib_multipath_lock); nh->nh_power = 0; nh->nh_flags &= ~RTNH_F_DEAD; spin_unlock_bh(&fib_multipath_lock); +#endif } endfor_nexthops(fi) if (alive > 0) { @@ -941,8 +1004,12 @@ ret++; } } endfor_fib_info(); + if (rep) + goto repeat; return ret; } + +#ifdef CONFIG_IP_ROUTE_MULTIPATH /* The algorithm is suboptimal, but it provides really --- v2.4.19/linux/net/ipv4/fib_frontend.c Sat May 4 11:29:08 2002 +++ linux/net/ipv4/fib_frontend.c Sat May 4 13:24:04 2002 @@ -579,9 +579,7 @@ switch (event) { case NETDEV_UP: fib_add_ifaddr(ifa); -#ifdef CONFIG_IP_ROUTE_MULTIPATH fib_sync_up(ifa->ifa_dev->dev); -#endif rt_cache_flush(-1); break; case NETDEV_DOWN: @@ -617,9 +615,7 @@ for_ifa(in_dev) { fib_add_ifaddr(ifa); } endfor_ifa(in_dev); -#ifdef CONFIG_IP_ROUTE_MULTIPATH fib_sync_up(dev); -#endif rt_cache_flush(-1); break; case NETDEV_DOWN: