Using as set a list of routes to advertise

William bird at is.unlawful.id.au
Wed May 31 07:25:52 CEST 2023


Hi all,
For the record, I've written a little bash tidbit that works for the 
moment, just means a lot of route statements in the static protocol in 
worst cases:

NEWGW="172.24.16.2"; grep "define site_subnets" bird.conf | sed -e 
's/^.*\[ /  route /' -e "s/ \].*$/ via $NEWGW;\r/" -e "s/, / via 
$NEWGW;\r  route /g"

It includes a little indentation too, adjust for your nesting spacing 
scheme.  It picks up on the set named "site_subnets", breaks it apart 
and creates unix-terminated (CR, no LF) lines for each prefix listed.  
Hasn't been tested on IPv6 prefixes though, but I suspect it will Just 
Work(tm).

Regards,
William

On 13/05/2023 21:51, William wrote:

> On 13/05/2023 4:12 pm, Ross Tajvar wrote:
> 
>> What are you using the prefix set for in the first place?
> In this particular case it is used to filter inbound and restrict
> outbound advertisements with upstream BGP routers to ensure that site
> doesn't receive its own routes back, but also protect the rest of the
> network from accidentally advertising the wrong routes (like default
> route).
> 
> In some situations the routes may be directly connected (and so fed
> into the route tables by direct protocol entries), others via
> downstream hosts like I mentioned and that point we need to add the
> routes one-by-one into the tables.
> 
> On Thu, May 11, 2023, 2:34 AM William <bird at is.unlawful.id.au>
> wrote:
> 
> On 10/05/2023 19:46, Maria Matejka via Bird-users wrote: Hello!
> Thanks for replying.
> 
> On 5/10/23 11:13, William wrote: Hi All,
> I've been digging around trying to find a nice way of doing it
  but

>> can't seem to find a valid answer.
>> 
>> Is there a way to use a prefix set to create static routes?
> 
> No, this is not possible and implementing this would be
  surprisingly

> difficult as the prefix sets are implemented as a compressed
  trie

> optimized for fast lookup and not enumeration.
> 
> Also imagine this:
> 
> define my_route_set = [ 2001:db8/32+ ]; # note the plus sign
> protocol static { ipv6; route my_route_set via
  2001:db8::dead:beef; }

> This short code would generate approx. 7.9e28 routes.

Yeah, that could hurt.

> If you could elaborate more precisely what you are trying to
  achieve

> as a whole result, we may try to help you find how to do it in
  the way

> BIRD is designed.

We have a number of remote sites where there are non-dynamically
routed
downstream subnets that we need to add as static routes (anything
from 1
to 20+ per site) but also advertise upstream back into the WAN.

Instead of specifying each prefix as an individual static route I
was
hoping to be able to use the existing prefix set to act as a list
of
routes to add.  If there was a way to iterate over the set in a
loop
fashion then that would suffice.  In our instance there aren't
modifiers
on the masks (no -'s, +'s or {minlen, maxlen}) hence the idea of
being
able to use the set as "just a list" - this could be a condition
of
using it for that function.

For example (twist on my original):

define my_route_set = [ 10.1.2.3/24 [1], 172.20.4.2/24 [2],
10.200.0.0/23 [3] ];

protocol static route_set {
ipv4 {
table Some_Routes;
}
for ThisRoute in my_route_set {
route ThisRoute via 192.168.55.2;    # downstream static
gateway
}
route 5.6.7.8/32 [4] via 192.168.55.1;
}

Resulting in:
bird> sh route table Some_Routes
Table Some_Routes:
10.1.2.3/24 [1]            unicast [route_set 2023-05-10] * (200)
via 192.168.55.2 on ens256
10.20.4.2/24 [5]           unicast [route_set 2023-05-10] * (200)
via 192.168.55.2 on ens256
10.200.0.0/23 [3]          unicast [route_set 2023-05-10] * (200)
via 192.168.55.2 on ens256
5.6.7.8/32 [4]             unicast [route_set 2023-05-10] * (200)
via 192.168.55.1 on ens256
192.168.55.0/24 [6]        unicast [Local_Ints 2023-05-10] * (240)
dev ens256
bird>

Hope that explains better what I'm hoping to achieve.  I couldn't
see a
way of doing it with if..then..else or case statements.  The only
other
option would be to have a script scrape the set out of the config
and
prepare an include file *shudder*.

Regards,
William


More information about the Bird-users mailing list