]> granicus.if.org Git - libnl/commitdiff
Represent default route with destination address length zero
authorThomas Graf <tgr@deb.localdomain>
Wed, 19 Dec 2007 18:41:01 +0000 (19:41 +0100)
committerThomas Graf <tgr@deb.localdomain>
Wed, 19 Dec 2007 18:41:01 +0000 (19:41 +0100)
So far the destination address for default routes was NULL
which complicated the handling of routes in general. By
assigning a address of length zero they can be compared
to each other.

This allows the cache manager to properly handle default
routes.

lib/route/route.c
lib/route/route_obj.c

index 2fc25f730f0c43647dff20dead65862c398bb798..0644bd7530788853825e3de0375bd5b285a9d5d4 100644 (file)
@@ -91,15 +91,18 @@ static int route_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
                dst = nla_get_addr(tb[RTA_DST], rtm->rtm_family);
                if (dst == NULL)
                        goto errout_errno;
-       } else if (rtm->rtm_dst_len)
+       } else {
                dst = nl_addr_alloc(0);
-
-       if (dst) {
-               nl_addr_set_prefixlen(dst, rtm->rtm_dst_len);
-               rtnl_route_set_dst(route, dst);
-               nl_addr_put(dst);
+               nl_addr_set_family(dst, rtm->rtm_family);
        }
 
+       nl_addr_set_prefixlen(dst, rtm->rtm_dst_len);
+       err = rtnl_route_set_dst(route, dst);
+       if (err < 0)
+               goto errout;
+
+       nl_addr_put(dst);
+
        if (tb[RTA_SRC]) {
                src = nla_get_addr(tb[RTA_SRC], rtm->rtm_family);
                if (src == NULL)
index 7d954fcb5c48ac07875b398bf4b5edd1a57732a3..78e7712ced9f3a130c819a8b99814f18f4a1f3fd 100644 (file)
@@ -136,10 +136,11 @@ static int route_dump_brief(struct nl_object *a, struct nl_dump_params *p)
 
        link_cache = nl_cache_mngt_require("route/link");
 
-       if (r->ce_mask & ROUTE_ATTR_DST)
-               dp_dump(p, "%s ", nl_addr2str(r->rt_dst, buf, sizeof(buf)));
-       else
+       if (!(r->ce_mask & ROUTE_ATTR_DST) ||
+           nl_addr_get_len(r->rt_dst) == 0)
                dp_dump(p, "default ");
+       else
+               dp_dump(p, "%s ", nl_addr2str(r->rt_dst, buf, sizeof(buf)));
 
        if (r->ce_mask & ROUTE_ATTR_OIF) {
                if (link_cache)