Page MenuHomeFreeBSD

D56323.id175156.diff
No OneTemporary

D56323.id175156.diff

diff --git a/sys/net/route.h b/sys/net/route.h
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -106,6 +106,7 @@
#define RT_MAX_WEIGHT 16777215 /* 3 bytes */
#define RT_WEIGHT_MASK 0x00FFFFFF /* first 24 bits */
#define RT_METRIC_MASK 0xFF000000 /* last 8 bits */
+#define RT_WEIGHT_TO_METRIC(x) (x >> 24) /* return metric from weight */
/*
* Keep a generation count of routing table, incremented on route addition,
diff --git a/sys/netlink/netlink_snl_route_parsers.h b/sys/netlink/netlink_snl_route_parsers.h
--- a/sys/netlink/netlink_snl_route_parsers.h
+++ b/sys/netlink/netlink_snl_route_parsers.h
@@ -50,10 +50,11 @@
struct sockaddr *gw;
uint32_t ifindex;
uint8_t rtnh_flags;
- uint8_t rtnh_weight;
+ uint8_t rtnh_metric;
uint32_t rtax_mtu;
uint32_t rta_rtflags;
uint32_t rta_expire;
+ uint32_t rtnh_weight;
};
#define _IN(_field) offsetof(struct rtnexthop, _field)
@@ -66,6 +67,7 @@
static const struct snl_attr_parser _nla_p_mp_nh[] = {
{ .type = NL_RTA_GATEWAY, .off = _OUT(gw), .cb = snl_attr_get_ip },
{ .type = NL_RTA_METRICS, .arg = &_metrics_mp_nh_parser, .cb = snl_attr_get_nested },
+ { .type = NL_RTA_WEIGHT, .off = _OUT(rtnh_weight), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_RTFLAGS, .off = _OUT(rta_rtflags), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_VIA, .off = _OUT(gw), .cb = snl_attr_get_ipvia },
{ .type = NL_RTA_EXPIRES, .off = _OUT(rta_expire), .cb = snl_attr_get_uint32 },
@@ -73,7 +75,7 @@
static const struct snl_field_parser _fp_p_mp_nh[] = {
{ .off_in = _IN(rtnh_flags), .off_out = _OUT(rtnh_flags), .cb = snl_field_get_uint8 },
- { .off_in = _IN(rtnh_hops), .off_out = _OUT(rtnh_weight), .cb = snl_field_get_uint8 },
+ { .off_in = _IN(rtnh_hops), .off_out = _OUT(rtnh_metric), .cb = snl_field_get_uint8 },
{ .off_in = _IN(rtnh_ifindex), .off_out = _OUT(ifindex), .cb = snl_field_get_uint32 },
};
diff --git a/sys/netlink/route/route.h b/sys/netlink/route/route.h
--- a/sys/netlink/route/route.h
+++ b/sys/netlink/route/route.h
@@ -333,7 +333,7 @@
struct rtnexthop {
unsigned short rtnh_len;
unsigned char rtnh_flags;
- unsigned char rtnh_hops; /* nexthop weight */
+ unsigned char rtnh_hops; /* nexthop metric */
int rtnh_ifindex;
};
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -216,13 +216,14 @@
return;
rtnh->rtnh_flags = 0;
rtnh->rtnh_ifindex = if_getindex(wn[i].nh->nh_ifp);
- rtnh->rtnh_hops = wn[i].weight;
+ rtnh->rtnh_hops = RT_WEIGHT_TO_METRIC(wn[i].weight);
dump_rc_nhop_gw(nw, wn[i].nh);
uint32_t rtflags = nhop_get_rtflags(wn[i].nh);
if (rtflags != base_rtflags)
nlattr_add_u32(nw, NL_RTA_RTFLAGS, rtflags);
if (rtflags & RTF_FIXEDMTU)
dump_rc_nhop_mtu(nw, wn[i].nh);
+ nlattr_add_u32(nw, NL_RTA_WEIGHT, wn[i].weight);
nh_expire = nhop_get_expire(wn[i].nh);
if (nh_expire > 0)
nlattr_add_u32(nw, NL_RTA_EXPIRES, nh_expire - time_uptime);
@@ -424,18 +425,20 @@
struct sockaddr *gw;
struct ifnet *ifp;
uint8_t rtnh_flags;
- uint8_t rtnh_weight;
+ uint8_t rtnh_metric;
+ uint32_t rtnh_weight;
};
#define _IN(_field) offsetof(struct rtnexthop, _field)
#define _OUT(_field) offsetof(struct rta_mpath_nh, _field)
const static struct nlattr_parser nla_p_rtnh[] = {
{ .type = NL_RTA_GATEWAY, .off = _OUT(gw), .cb = nlattr_get_ip },
+ { .type = NL_RTA_WEIGHT, .off = _OUT(gw), .cb = nlattr_get_uint32 },
{ .type = NL_RTA_VIA, .off = _OUT(gw), .cb = nlattr_get_ipvia },
};
const static struct nlfield_parser nlf_p_rtnh[] = {
{ .off_in = _IN(rtnh_flags), .off_out = _OUT(rtnh_flags), .cb = nlf_get_u8 },
- { .off_in = _IN(rtnh_hops), .off_out = _OUT(rtnh_weight), .cb = nlf_get_u8 },
+ { .off_in = _IN(rtnh_hops), .off_out = _OUT(rtnh_metric), .cb = nlf_get_u8 },
{ .off_in = _IN(rtnh_ifindex), .off_out = _OUT(ifp), .cb = nlf_get_ifpz },
};
#undef _IN
@@ -892,7 +895,9 @@
nhop_free(wn[j].nh);
break;
}
- wn[i].weight = mpnh->rtnh_weight > 0 ? mpnh->rtnh_weight : 1;
+ wn[i].weight = mpnh->rtnh_weight > 0 ? mpnh->rtnh_weight : RT_DEFAULT_WEIGHT;
+ if (mpnh->rtnh_metric > 0 && mpnh->rtnh_weight <= RT_MAX_WEIGHT)
+ wn[i].weight += (uint32_t)(mpnh->rtnh_metric << 24);
}
if (error == 0) {
struct rib_head *rh = nhop_get_rh(wn[0].nh);

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 19, 3:11 PM (8 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31759576
Default Alt Text
D56323.id175156.diff (4 KB)

Event Timeline