Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152940218
D56322.id175155.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D56322.id175155.diff
View Options
diff --git a/sys/net/route.h b/sys/net/route.h
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -104,6 +104,8 @@
/* default route weight */
#define RT_DEFAULT_WEIGHT 1
#define RT_MAX_WEIGHT 16777215 /* 3 bytes */
+#define RT_WEIGHT_MASK 0x00FFFFFF /* first 24 bits */
+#define RT_METRIC_MASK 0xFF000000 /* last 8 bits */
/*
* Keep a generation count of routing table, incremented on route addition,
diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -135,6 +135,7 @@
* comparable.
* Assumes @wn is sorted by weight ascending and each weight is > 0.
* Returns number of slots or 0 if precise calculation failed.
+ * We also filter nexthops with lower metrics here.
*
* Some examples:
* note: (i, X) pair means (nhop=i, weight=X):
@@ -146,15 +147,25 @@
calc_min_mpath_slots_fast(struct weightened_nhop *wn, size_t num_items,
uint64_t *ptotal)
{
- uint32_t i, last, xmin;
+ uint32_t i, last, xmin, max_metric;
uint64_t total = 0;
// Get sorted array of weights in .storage field
sort_weightened_nhops_weights(wn, num_items);
+ /* find nexthop with highest metric */
+ max_metric = 0;
+ for (i = 0; i < num_items; i++)
+ if ((wn[i].weight & RT_METRIC_MASK) > max_metric)
+ max_metric = wn[i].weight & RT_METRIC_MASK;
+
last = 0;
xmin = wn[0].storage;
for (i = 0; i < num_items; i++) {
+ /* filter nexthops with lower metric */
+ if (wn[i].weight < max_metric)
+ continue;
+
total += wn[i].storage;
if ((wn[i].storage != last) &&
((wn[i].storage - last < xmin) || xmin == 0)) {
@@ -235,21 +246,35 @@
{
struct nhgrp_object *dst;
int i, slot_idx, remaining_slots;
- uint64_t remaining_sum, nh_weight, nh_slots;
+ uint64_t remaining_sum, nh_slots;
+ uint32_t highest_metric, nh_weight;
slot_idx = 0;
dst = dst_priv->nhg;
- /* Calculate sum of all weights */
+
+ /* Find highest metric */
+ highest_metric = 0;
+ for (i = 0; i < dst_priv->nhg_nh_count; i++)
+ if ((x[i].weight & RT_METRIC_MASK) > highest_metric)
+ highest_metric = x[i].weight & RT_METRIC_MASK;
+
+ /* Calculate sum of the weights with highest metric */
remaining_sum = 0;
for (i = 0; i < dst_priv->nhg_nh_count; i++)
- remaining_sum += x[i].weight;
+ if (x[i].weight >= highest_metric)
+ remaining_sum += x[i].weight;
+
remaining_slots = num_slots;
- FIB_NH_LOG(LOG_DEBUG3, x[0].nh, "sum: %lu, slots: %d",
- remaining_sum, remaining_slots);
+ FIB_NH_LOG(LOG_DEBUG3, x[0].nh, "sum: %lu, slots: %d, highest_metric: %lu",
+ remaining_sum, remaining_slots, highest_metric);
for (i = 0; i < dst_priv->nhg_nh_count; i++) {
+ /* Skip over lower metrics */
+ if (x[i].weight < highest_metric)
+ continue;
+
/* Calculate number of slots for the current nexthop */
if (remaining_sum > 0) {
- nh_weight = (uint64_t)x[i].weight;
+ nh_weight = x[i].weight;
nh_slots = (nh_weight * remaining_slots / remaining_sum);
} else
nh_slots = 0;
diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -196,11 +196,6 @@
weight = info->rti_rmx->rmx_weight;
else
weight = default_weight;
- /* Keep upper 1 byte for adm distance purposes */
- if (weight > RT_MAX_WEIGHT)
- weight = RT_MAX_WEIGHT;
- else if (weight == 0)
- weight = default_weight;
return (weight);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 19, 5:22 AM (14 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31711607
Default Alt Text
D56322.id175155.diff (3 KB)
Attached To
Mode
D56322: routing: Add support for route metric
Attached
Detach File
Event Timeline
Log In to Comment