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.
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)
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)