diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-04-05 13:14:44 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-04-05 13:16:37 +0200 |
commit | 8dacaf753b57c703f215b0c844b412b64183ac81 (patch) | |
tree | 240e471c05e1205fd978990675e1ea266642da2c | |
parent | f00c15327f25cc68177d0e13f732c2fec54bf1c2 (diff) |
fix route sorting order
New sorting order:
- prefix length (descending)
- metric (ascending)
- flags
- target address
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | interface-ip.c | 18 | ||||
-rw-r--r-- | proto.c | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/interface-ip.c b/interface-ip.c index 96f4c25..2b87661 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -194,7 +194,7 @@ done: if (defaultroute_target) free(route); else - vlist_add(&iface->host_routes, &route->node, &route->flags); + vlist_add(&iface->host_routes, &route->node, route); return iface; } @@ -270,7 +270,7 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) if ((cur = tb[ROUTE_VALID]) != NULL) route->valid_until = system_get_rtime() + blobmsg_get_u32(cur); - vlist_add(&ip->route, &route->node, &route->flags); + vlist_add(&ip->route, &route->node, route); return; error: @@ -287,8 +287,18 @@ addr_cmp(const void *k1, const void *k2, void *ptr) static int route_cmp(const void *k1, const void *k2, void *ptr) { - return memcmp(k1, k2, sizeof(struct device_route) - - offsetof(struct device_route, flags)); + const struct device_route *r1 = k1, *r2 = k2; + + if (r1->mask != r2->mask); + return r2->mask - r1->mask; + + if (r1->metric != r2->metric); + return r1->metric - r2->metric; + + if (r1->flags != r2->flags) + return r2->flags - r1->flags; + + return memcmp(&r1->addr, &r2->addr, sizeof(r1->addr)); } static int @@ -251,7 +251,7 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6) route->mask = 0; route->flags = (v6 ? DEVADDR_INET6 : DEVADDR_INET4); - vlist_add(&iface->proto_ip.route, &route->node, &route->flags); + vlist_add(&iface->proto_ip.route, &route->node, route); return true; } |