Contributed by phessler on from the thats-it? dept.
Almost exclusively, they told me "filter performance."
Many IXP operators made a point to tell me that they liked the syntax and use of OpenBGPd. They were very concerned that there was apparently only a single piece of software that was now being used for Route Servers, and even some of them used multiple versions of it to "satisfy" their desire for divergent implementations. (insert 'eek' here)
So, I decided to look into why the filters were so slow.
Turns out, we were being very naive with the filters and checking every filter against every rule, even when we couldn't match. This is very common in the first implementation of a filter and even showed up in the initial version of PF. Obviously, filter performance in PF is rather critical to having a performant firewall so I looked at its implemetation. Turns out, it was rather simple and straight-forward.
PF's filter performance is known as "skip steps", which exploit the fact that some rules will never match. As an example, if you write a rule like "allow from AS 65111", this can never match if a peer has AS 65333. In such a case, we need to skip all of those rules.
There are two parts to skip-steps. First is when you parse and load the filters, you need to calculate where to skip to, if a group doesn't apply. This happens at load time. The second part is when we are iterating through the filters, is to detect when we get to a rule that can't apply, and skip to the next group. That happens while applying the rules.
Andy from LONAP (the 15th largest IX in the world, according to wikipedia), gave me the last configuration they used with OpenBGPd. This had 314 peers configured, and about 35,000 prefix filters. For additional torture, I added the IRR ruleset for a friend's network, which brought the total prefix rules up to around 600,000 prefixes filters. To this configuration, I sent 65,000 routes.
In OpenBSD 5.8, processing these routes would take approx 35 minutes on my laptop. With the change I committed today (Nov 6), the same processing takes only 30 seconds.
reposted from http://bad.network/openbgpd-and-route-filters.html with permission
CVSROOT: /cvs Module name: src Changes by: phessler@cvs.openbsd.org 2015/11/06 09:23:26 Modified files: usr.sbin/bgpd : bgpd.h rde.c rde.h rde_filter.c Log message: Radically improve the performance of bgpd filters. Based on PF's skip steps (and uses much of the same code). In a torture test of ~600k prefix filters and 65k prefixes, convergance time goes from 35 minutes to 30 seconds. Many thanks to LONAP for providing a base configuration for torture testing. many discussions with claudio@, benno@, sthen@ and the rest of the bgpd crowd OK sthen@ benno@
(Comments are closed)
By Anonymous Coward (179.219.207.238) on
By Salim Shaw (eshaw) salimshaw@vfemail.net on
By Anonymous Coward (81.82.229.158) on
Comments
By phessler (phessler) on http://www.openbsdfoundation.org/donations.html
Thanks! I'll have to look for this presentation and contact them.
By gregbo (198.144.201.12) gds@gds.best.vwh.net on http://gregbo.livejournal.com/
By Stuart Henderson (82.68.199.130) on https://dmtx.uk/
Since skip-steps come from PF, we can look in that direction for guidance about performance. An old Undeadly article about PF rule optimization talks about this ("Ordering rulesets to maximize skip steps") and the principles are the same here. You want to group the rules together to reduce the number of evaluations done.
Take these rules, for example:
And here are the skip-step groupings used in the code:
You can probably make a good guess at the meanings. So the rules above are not optimal - a simple reordering as below would put all of the "from" rules together and allow half of the lines to be skipped in one go. (Fewer than half of the *rules*, because the prefix lists are expanded to multiple rules, but hey there needs to be some room for borrowing something else from PF for future improvement ;-)
Nowadays PF has a ruleset optimizer that is aware of skip-steps and will reorder rules to take advantage of them automatically. (In fact, in some cases with PF it can still be better to disable the optimizer and do this by hand; you might know something about your traffic that pfctl doesn't). In the case of IXP route-server BGP filters, they're likely to be much larger than any PF ruleset you're ever going to see, so a ruleset optimizer would be relatively slow and take a lot of memory. Fortunately with BGP filters, they're already going to be machine-generated from routing registries or local databases, so it's a lot easier to order them correctly from the start.
By Blake (2a01:e34:ec06:8f90:cabc:c8ff:fedb:4d83) on 2112.net
https://github.com/job
http://irrexplorer.nlnog.net/search/AS22512
Comments
By phessler (phessler) on http://www.openbsdfoundation.org/donations.html
> https://github.com/job
> http://irrexplorer.nlnog.net/search/AS22512
>
>
Thanks! Yes, I have been in contact with Job already, we talked about some features he would like to see in the future.
By Ilyas Bakirov (82.200.241.50) on
Would be nice if all latest updates of OpenBSD's OpenBGPD got by others.
Comments
By phessler (phessler) on http://www.openbsdfoundation.org/donations.html
>
> Would be nice if all latest updates of OpenBSD's OpenBGPD got by others.
The last release of OpenBGPd portable was done from 4.6, 6 years ago. I plan on updating that in the near-future, but it will take some time.
Comments
By Ilyas Bakirov (147.30.27.64) on
Yeah, I know.
Good news. Thanks. Public code like GitHub are welcome for -p(portable) version and porting will faster by many contributions and donations...