netifd: Assign interface metric to route metric when route is created
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 10 Mar 2014 15:27:52 +0000 (16:27 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 11 Mar 2014 09:23:36 +0000 (10:23 +0100)
Interface metric needs to be assigned to the route metric parameter at route creation time. Otherwise if the interface metric is different from 0 route_cmp will wrongly conclude the routes are different.
In this case the route will be added/deleted and could end up with the route missing in the kernel depending on the add/delete order.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
interface-ip.c

index b1abbc60de4557edf5017f4f202077a78058b9d9..d5a3832bd4d4980155a9818f81ca14f7c5d948ce 100644 (file)
@@ -322,7 +322,8 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
        if ((cur = tb[ROUTE_METRIC]) != NULL) {
                route->metric = blobmsg_get_u32(cur);
                route->flags |= DEVROUTE_METRIC;
-       }
+       } else
+               route->metric = iface->metric;
 
        if ((cur = tb[ROUTE_MTU]) != NULL) {
                route->mtu = blobmsg_get_u32(cur);
@@ -588,9 +589,6 @@ interface_update_proto_route(struct vlist_tree *tree,
        if (node_new) {
                bool _enabled = enable_route(ip, route_new);
 
-               if (!(route_new->flags & DEVROUTE_METRIC))
-                       route_new->metric = iface->metric;
-
                if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep && _enabled)
                        if (system_add_route(dev, route_new))
                                route_new->failed = true;