Writing filters that change output depending on peer

Maria Matejka maria.matejka at nic.cz
Sun Sep 14 13:01:03 CEST 2025


Good … now already afternoon, Nico!

On Sun, Sep 14, 2025 at 11:23:05AM +0200, Nico Schottelius wrote:

> you have a very valid point I haven't though about yet. You are right
> that currently filters and functions can just be used in the CLI w/o a
> "context".
> 
> And maybe that is also the answer as to how bird should behave: if no
> "context" (or peer or whatever it will be named in the end) is supplied,
> I think bird should behave the same as before.

Yes, not only regular route filtering, there is multiple usage of the
same filter engine where the context is different.

> And we can even formalise this a bit and update the previous
> description:
> 
> 
>     string proto_to_or_destination_or_better_name
> 
>            The name of the protocol in which the filter or function is being
>            called in. Allows to match on the destination.
> 
>            Might contain the empty string, if the evaluated outside a
>            protocol context.

Empty string or undefined?

> > * CLI: show route export bar
> 
> proto_to_or_destination_or_better_name is unset -> false

Well, this call is intended as "how do routes export to bar" check so
here the name would be probably better set as the filter should imho run
in the protocol context.

Otherwise you get different results than what gets exported, and the
users get confused.

> > * CLI: show route where foo()
> 
> proto_to_or_destination_or_better_name is unset -> false

The question here is whether the filter engine should just silently
treat the parameter as empty, or complain. I'm a little inclined for
complaining because people may forget that they have target-specific
behavior, try this while debugging, and get confused.

> > * CLI: eval foo
> 
> proto_to_or_destination_or_better_name is unset -> false

The same as above. Please note that if you ask for `eval net`, you get a
runtime error because there is no route at all.

> Now comes a however: however it might be helpful then to add a context
> alike syntax:
> 
> show route where foo() context proto bar
> 
> --> true
> 
> show route where foo() context proto foo
> 
> --> no routes

This looks viable, even though maybe a little bit clumsy.

> > * Conf: protocol bgp yay { require graceful restart ( foo() ); }
> 
> proto_to_or_destination_or_better_name is = yay -> false

Indeed.

> > * Conf: template bgp yippie { require graceful restart ( foo() ); }
> 
> proto_to_or_destination_or_better_name is = yippie -> false

But then the template is used to create the protocol `bar` and one may
expect there that we would evaluate the expression in the protocol
context …

> > * Conf: ipv6 table bastu { sorted ( foo() ); };
> 
> I'm not familiar with the sorted function, so no clue

It's just a table parameter. I would say that the function may make use
of some similar context but regarding the table involved instead.

> > * Conf: function meow() { if foo() then return 1; else return 2; } router id ( meow() );
> 
> Same as above, depends on where meow() is called.

In toplevel config, no block.

Basically these config uses are rudimentary uses of the filter engine to
evaluate some config values. And the question is how to make this work
the right way.

> I think in the end, the actual value of
> proto_to_or_destination_or_better_name should be handled similar to how
> "net" is passed down:
> 
> - set inside a protocol ...{} context
> - empty/unset outside of that context

Ha, you got to the same conclusion as myself above.

> > Thank you for opening this topic!
> 
> Thank you for being open and continuing to provide a great software!

We try our best. With open-source, one can actually quite openly discus
what is going on and how things are going to be implemented. In the end,
we need to collect the feature requirements early enough to not waste
time implementing things wrongly.

Enjoy your sunny day!  
Maria

-- 
Maria Matejka (she/her) | BIRD Team Leader | CZ.NIC, z.s.p.o.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20250914/4278e950/attachment.htm>


More information about the Bird-users mailing list