summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadu Carpa <radu.carpa@cern.ch>2023-01-17 18:13:37 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2023-01-17 18:13:37 +0100
commit7144c9ca46f092da33a4e051bbce8f973a3bd8c4 (patch)
tree4b2d6f0b3da49d0236075cae3c05c61bb60a5579
parent928a1cb034e6f9e8edcdd1dc07264cd703e00827 (diff)
Filter: Allow setting the 'onlink' route attribute in filters
Add static route attribute to set onlink flag for route next hop. Can be used to build a dynamically routed IP-in-IP overlay network. Usage: ifname = "tunl0"; onlink = true; gw = bgp_next_hop;
-rw-r--r--doc/bird.sgml8
-rw-r--r--filter/config.Y3
-rw-r--r--filter/data.h1
-rw-r--r--filter/f-inst.c14
4 files changed, 23 insertions, 3 deletions
diff --git a/doc/bird.sgml b/doc/bird.sgml
index 50657ebf..001fcbd4 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1816,6 +1816,14 @@ Common route attributes are:
creation/removal. Zero is returned for routes with undefined outgoing
interfaces. Read-only.
+ <tag><label id="rta-onlink"><m/bool/ onlink</tag>
+ Onlink flag means that the specified nexthop is accessible on the
+ interface regardless of IP prefixes configured on the interface.
+ The attribute can be used to configure such next hops by first setting
+ <cf/onlink = true/ and <cf/ifname/, and then setting <cf/gw/. Possible
+ use case for setting this flag is to automatically build overlay IP-IP
+ networks on linux.
+
<tag><label id="rta-weight"><m/int/ weight</tag>
Multipath weight of route next hops. Valid values are 1-256. Reading
returns the weight of the first next hop, setting it sets weights of all
diff --git a/filter/config.Y b/filter/config.Y
index 1d9d9aa9..a1e5e9f1 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -305,7 +305,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
IF, THEN, ELSE, CASE,
FOR, IN, DO,
TRUE, FALSE, RT, RO, UNKNOWN, GENERIC,
- FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, WEIGHT, GW_MPLS,
+ FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, WEIGHT, GW_MPLS, ONLINK,
PREFERENCE,
ROA_CHECK, ASN, SRC, DST,
IS_V4, IS_V6,
@@ -795,6 +795,7 @@ static_attr:
| WEIGHT { $$ = f_new_static_attr(T_INT, SA_WEIGHT, 0); }
| PREFERENCE { $$ = f_new_static_attr(T_INT, SA_PREF, 0); }
| GW_MPLS { $$ = f_new_static_attr(T_INT, SA_GW_MPLS, 0); }
+ | ONLINK { $$ = f_new_static_attr(T_BOOL, SA_ONLINK, 0); }
;
term:
diff --git a/filter/data.h b/filter/data.h
index 700609e9..b3767f7b 100644
--- a/filter/data.h
+++ b/filter/data.h
@@ -102,6 +102,7 @@ enum f_sa_code {
SA_WEIGHT,
SA_PREF,
SA_GW_MPLS,
+ SA_ONLINK,
} PACKED;
/* Static attribute definition (members of struct rta) */
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 2d2a30e4..e4b47ff4 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -694,6 +694,7 @@
case SA_WEIGHT: RESULT(sa.f_type, i, rta->nh.weight + 1); break;
case SA_PREF: RESULT(sa.f_type, i, rta->pref); break;
case SA_GW_MPLS: RESULT(sa.f_type, i, rta->nh.labels ? rta->nh.label[0] : MPLS_NULL); break;
+ case SA_ONLINK: RESULT(sa.f_type, i, rta->nh.flags & RNF_ONLINK ? 1 : 0); break;
default:
bug("Invalid static attribute access (%u/%u)", sa.f_type, sa.sa_code);
@@ -720,8 +721,8 @@
case SA_GW:
{
ip_addr ip = v1.val.ip;
- struct iface *ifa = ipa_is_link_local(ip) ? rta->nh.iface : NULL;
- neighbor *n = neigh_find((*fs->rte)->src->proto, ip, ifa, 0);
+ struct iface *ifa = ipa_is_link_local(ip) || (rta->nh.flags & RNF_ONLINK) ? rta->nh.iface : NULL;
+ neighbor *n = neigh_find((*fs->rte)->src->proto, ip, ifa, (rta->nh.flags & RNF_ONLINK) ? NEF_ONLINK : 0);
if (!n || (n->scope == SCOPE_HOST))
runtime( "Invalid gw address" );
@@ -801,6 +802,15 @@
rta->pref = v1.val.i;
break;
+ case SA_ONLINK:
+ {
+ if (v1.val.i)
+ rta->nh.flags |= RNF_ONLINK;
+ else
+ rta->nh.flags &= ~RNF_ONLINK;
+ }
+ break;
+
default:
bug("Invalid static attribute access (%u/%u)", sa.f_type, sa.sa_code);
}