aboutsummaryrefslogtreecommitdiff
path: root/sys/netlink/route/rt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/netlink/route/rt.c')
-rw-r--r--sys/netlink/route/rt.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index 8159409c9f67..39ecb537d365 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -217,7 +217,7 @@ dump_rc_nhg(struct nl_writer *nw, const struct route_nhop_data *rnd, struct rtms
return;
rtnh->rtnh_flags = 0;
rtnh->rtnh_ifindex = if_getindex(wn[i].nh->nh_ifp);
- rtnh->rtnh_hops = wn[i].weight;
+ rtnh->rtnh_hops = MIN(wn[i].weight, UINT8_MAX);
dump_rc_nhop_gw(nw, wn[i].nh);
uint32_t rtflags = nhop_get_rtflags(wn[i].nh);
if (rtflags != base_rtflags)
@@ -242,7 +242,8 @@ dump_rc_nhg(struct nl_writer *nw, const struct route_nhop_data *rnd, struct rtms
}
nlattr_set_len(nw, off);
nlattr_add_u32(nw, NL_RTA_PRIORITY, nhop_metric);
- nlattr_add_u32(nw, NL_RTA_WEIGHT, nhop_weight);
+ if (nhop_weight != RT_DEFAULT_WEIGHT)
+ nlattr_add_u32(nw, NL_RTA_WEIGHT, nhop_weight);
}
static void
@@ -726,7 +727,7 @@ handle_rtm_dump(struct nlpcb *nlp, uint32_t fibnum, int family,
if (fibnum == RT_TABLE_UNSPEC) {
for (int i = 0; i < V_rt_numfibs; i++) {
- dump_rtable_fib(&wa, fibnum, family);
+ dump_rtable_fib(&wa, i, family);
if (wa.error != 0)
break;
}
@@ -977,6 +978,14 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
return (nh);
}
+/* pre-2.6.19 Linux API compatibility: prefer RTA_TABLE, fall back to rtm_table */
+static inline void
+old_linux_compat(struct nl_parsed_route *attrs)
+{
+ if (attrs->rtm_table > 0 && attrs->rta_table == 0)
+ attrs->rta_table = attrs->rtm_table;
+}
+
static int
rtnl_handle_newroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
struct nl_pstate *npt)
@@ -996,9 +1005,7 @@ rtnl_handle_newroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
return (EINVAL);
}
- /* pre-2.6.19 Linux API compatibility */
- if (attrs.rtm_table > 0 && attrs.rta_table == 0)
- attrs.rta_table = attrs.rtm_table;
+ old_linux_compat(&attrs);
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
return (EINVAL);
@@ -1065,6 +1072,7 @@ rtnl_handle_delroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
return (ESRCH);
}
+ old_linux_compat(&attrs);
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
return (EINVAL);
@@ -1088,6 +1096,7 @@ rtnl_handle_getroute(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *
if (error != 0)
return (error);
+ old_linux_compat(&attrs);
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
return (EINVAL);