Page MenuHomeFreeBSD

D56323.id177261.diff
No OneTemporary

D56323.id177261.diff

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
@@ -52,6 +52,7 @@
uint8_t rtnh_flags;
uint8_t rtnh_weight;
uint32_t rtax_mtu;
+ uint32_t rta_metric;
uint32_t rta_rtflags;
uint32_t rta_expire;
};
@@ -65,6 +66,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_PRIORITY, .off = _OUT(rta_metric), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_METRICS, .arg = &_metrics_mp_nh_parser, .cb = snl_attr_get_nested },
{ .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 },
@@ -121,6 +123,7 @@
uint32_t rta_rtflags;
uint32_t rtax_mtu;
uint32_t rtax_weight;
+ uint32_t rta_metric;
uint8_t rtm_family;
uint8_t rtm_type;
uint8_t rtm_protocol;
@@ -138,6 +141,7 @@
{ .type = NL_RTA_DST, .off = _OUT(rta_dst), .cb = snl_attr_get_ip },
{ .type = NL_RTA_OIF, .off = _OUT(rta_oif), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_GATEWAY, .off = _OUT(rta_gw), .cb = snl_attr_get_ip },
+ { .type = NL_RTA_PRIORITY, .off = _OUT(rta_metric), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_METRICS, .arg = &_metrics_parser, .cb = snl_attr_get_nested },
{ .type = NL_RTA_MULTIPATH, .off = _OUT(rta_multipath), .cb = nlattr_get_multipath },
{ .type = NL_RTA_KNH_ID, .off = _OUT(rta_knh_id), .cb = snl_attr_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
@@ -149,7 +149,7 @@
NL_RTA_IIF = 3, /* not supported */
NL_RTA_OIF = 4, /* u32, transmit ifindex */
NL_RTA_GATEWAY = 5, /* binary: IPv4/IPv6 gateway */
- NL_RTA_PRIORITY = 6, /* not supported */
+ NL_RTA_PRIORITY = 6, /* u32, path metric */
NL_RTA_PREFSRC = 7, /* not supported */
NL_RTA_METRICS = 8, /* nested, list of NL_RTAX* attrs */
NL_RTA_MULTIPATH = 9, /* binary, array of struct rtnexthop */
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
@@ -181,7 +181,7 @@
const struct weightened_nhop *wn;
struct nhop_object *nh;
uint32_t uidx, num_nhops, nh_expire;
- uint32_t base_rtflags, rtflags, nhop_weight;
+ uint32_t base_rtflags, rtflags, nhop_weight, nhop_metric;
MPASS((NH_IS_NHGRP(rnd->rnd_nhop)));
@@ -223,13 +223,16 @@
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_PRIORITY, nhop_get_metric(wn[i].nh));
nh_expire = nhop_get_expire(wn[i].nh);
if (nh_expire > 0)
nlattr_add_u32(nw, NL_RTA_EXPIRES, nh_expire - time_uptime);
rtnh = nlattr_restore_offset(nw, nh_off, struct rtnexthop);
- if (nh == wn[i].nh)
+ if (nh == wn[i].nh) {
nhop_weight = wn[i].weight;
+ nhop_metric = nhop_get_metric(wn[i].nh);
+ }
/*
* nlattr_add() allocates 4-byte aligned storage, no need to aligh
* length here
@@ -237,6 +240,7 @@
rtnh->rtnh_len = nlattr_save_offset(nw) - nh_off;
}
nlattr_set_len(nw, off);
+ nlattr_add_u32(nw, NL_RTA_PRIORITY, nhop_metric);
nlattr_add_u32(nw, NL_RTA_WEIGHT, nhop_weight);
}
@@ -278,8 +282,10 @@
/* In any case, fill outgoing interface */
nlattr_add_u32(nw, NL_RTA_OIF, if_getindex(nh->nh_ifp));
- if (rnd->rnd_weight != RT_DEFAULT_WEIGHT)
+ if (rnd->rnd_weight != RT_DEFAULT_WEIGHT) {
+ nlattr_add_u32(nw, NL_RTA_PRIORITY, nhop_get_metric(nh));
nlattr_add_u32(nw, NL_RTA_WEIGHT, rnd->rnd_weight);
+ }
}
/*
@@ -425,12 +431,14 @@
struct ifnet *ifp;
uint8_t rtnh_flags;
uint8_t rtnh_weight;
+ uint32_t rtnh_metric;
};
#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_PRIORITY, .off = _OUT(rtnh_metric), .cb = nlattr_get_uint32 },
{ .type = NL_RTA_VIA, .off = _OUT(gw), .cb = nlattr_get_ipvia },
};
const static struct nlfield_parser nlf_p_rtnh[] = {
@@ -512,6 +520,7 @@
uint32_t rta_table;
uint32_t rta_rtflags;
uint32_t rta_nh_id;
+ uint32_t rta_metric;
uint32_t rta_weight;
uint32_t rta_expire;
uint32_t rtax_mtu;
@@ -534,6 +543,7 @@
{ .type = NL_RTA_DST, .off = _OUT(rta_dst), .cb = nlattr_get_ip },
{ .type = NL_RTA_OIF, .off = _OUT(rta_oif), .cb = nlattr_get_ifp },
{ .type = NL_RTA_GATEWAY, .off = _OUT(rta_gw), .cb = nlattr_get_ip },
+ { .type = NL_RTA_PRIORITY, .off = _OUT(rta_metric), .cb = nlattr_get_uint32 },
{ .type = NL_RTA_METRICS, .arg = &metrics_parser, .cb = nlattr_get_nested },
{ .type = NL_RTA_MULTIPATH, .off = _OUT(rta_multipath), .cb = nlattr_get_multipath },
{ .type = NL_RTA_WEIGHT, .off = _OUT(rta_weight), .cb = nlattr_get_uint32 },
@@ -862,6 +872,12 @@
nhop_set_transmit_ifp(nh, mpnh->ifp);
nhop_set_pxtype_flag(nh, get_pxflag(attrs));
nhop_set_rtflags(nh, attrs->rta_rtflags);
+ /* if metric is specified per nexthop, use it */
+ if (mpnh->rtnh_metric != 0)
+ nhop_set_metric(nh, mpnh->rtnh_metric);
+ /* otherwise, use the route metric if specified */
+ else if (attrs->rta_metric != 0)
+ nhop_set_metric(nh, attrs->rta_metric);
if (attrs->rtm_protocol > RTPROT_STATIC)
nhop_set_origin(nh, attrs->rtm_protocol);
@@ -937,6 +953,8 @@
nhop_set_broadcast(nh, true);
if (attrs->rtm_protocol > RTPROT_STATIC)
nhop_set_origin(nh, attrs->rtm_protocol);
+ if (attrs->rta_metric != 0)
+ nhop_set_metric(nh, attrs->rta_metric);
nhop_set_pxtype_flag(nh, get_pxflag(attrs));
nhop_set_rtflags(nh, attrs->rta_rtflags);

File Metadata

Mime Type
text/plain
Expires
Sun, Jun 14, 1:29 AM (8 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33938161
Default Alt Text
D56323.id177261.diff (5 KB)

Event Timeline