summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2020-12-02 05:02:26 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2020-12-02 05:02:26 +0100
commit8cc5bb09e344038a1f8dff96946e05ec80607c93 (patch)
tree5c7d1f192d4d7654d40282822c639c887aaaffda /filter
parent246586771296d1c42a012c06bdc75b36a7ce0b4f (diff)
Filter: Add 'weight' route attribute
Add 'weight' route attribute that allows to get and set ECMP weight of nexthops. Similar to 'gw' attribute, it is limited to the first nexthop, but it is useful for handling BGP multipath, where an ECMP route is merged from multiple regular routes.
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y3
-rw-r--r--filter/data.h1
-rw-r--r--filter/f-inst.c15
3 files changed, 18 insertions, 1 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 557a951f..5cd52e40 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -278,7 +278,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
SET, STRING, BGPMASK, BGPPATH, CLIST, ECLIST, LCLIST,
IF, THEN, ELSE, CASE,
TRUE, FALSE, RT, RO, UNKNOWN, GENERIC,
- FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX,
+ FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, WEIGHT,
PREFERENCE,
ROA_CHECK, ASN, SRC, DST,
IS_V4, IS_V6,
@@ -750,6 +750,7 @@ static_attr:
| DEST { $$ = f_new_static_attr(T_ENUM_RTD, SA_DEST, 0); }
| IFNAME { $$ = f_new_static_attr(T_STRING, SA_IFNAME, 0); }
| IFINDEX { $$ = f_new_static_attr(T_INT, SA_IFINDEX, 1); }
+ | WEIGHT { $$ = f_new_static_attr(T_INT, SA_WEIGHT, 0); }
;
term:
diff --git a/filter/data.h b/filter/data.h
index 4ebce73b..a0ec3819 100644
--- a/filter/data.h
+++ b/filter/data.h
@@ -99,6 +99,7 @@ enum f_sa_code {
SA_DEST,
SA_IFNAME,
SA_IFINDEX,
+ SA_WEIGHT,
} PACKED;
/* Static attribute definition (members of struct rta) */
diff --git a/filter/f-inst.c b/filter/f-inst.c
index df908e26..58717d55 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -516,6 +516,7 @@
case SA_DEST: RESULT(sa.f_type, i, rta->dest); break;
case SA_IFNAME: RESULT(sa.f_type, s, rta->nh.iface ? rta->nh.iface->name : ""); break;
case SA_IFINDEX: RESULT(sa.f_type, i, rta->nh.iface ? rta->nh.iface->index : 0); break;
+ case SA_WEIGHT: RESULT(sa.f_type, i, rta->nh.weight + 1); break;
default:
bug("Invalid static attribute access (%u/%u)", sa.f_type, sa.sa_code);
@@ -586,6 +587,20 @@
}
break;
+ case SA_WEIGHT:
+ {
+ int i = v1.val.i;
+ if (i < 1 || i > 256)
+ runtime( "Setting weight value out of bounds" );
+ if (rta->dest != RTD_UNICAST)
+ runtime( "Setting weight needs regular nexthop " );
+
+ /* Set weight on all next hops */
+ for (struct nexthop *nh = &rta->nh; nh; nh = nh->next)
+ nh->weight = i - 1;
+ }
+ break;
+
default:
bug("Invalid static attribute access (%u/%u)", sa.f_type, sa.sa_code);
}