Now that I understand the poorly written BSD routing code and what
it was trying to do, rewrite it in a clear and concise manner.
The old rtalloc1() code written by CSRG had a number of problems:
1. it was not clear which route was being returned
2. it was not clear what was being reported
3. it hid the essential radix tree lookup operation inside a series of
conditional tests and inline assignments
4. it had multiple gotos to the inside of if statements
5. it intermixed reporting code with the operational logic of lookup
and cloning
6. it assigns multiple times to key variables
7. it has unnecessary assignments to key variables
8. it overloaded the "report" argument parameter, to have two
different semantics
9. it misnamed the key route lookup function "rtalloc1", obscuring all uses
of route lookup.
In contrast to the rtalloc1 code in FreeBSD 4 or the even more convoluted
rtalloc1 code in FreeBSD 5, the DragonFlyBSD version
A. has a clear control flow that makes the common case obvious
by highlighting the core call to the radix tree look up function,
eliminating gotos into if statements,
and completely separating out the special-case cloning logic
B. makes it clear which route is being returned
by only assigning once to the key "rt" variable
and by expliciting returning "rt" or "clonedroute"
C. abstracts out the reporting code into its own reporting API
D. cleans up the semantics of the "report" argument parameter to
only indicate whether to report a miss and not whether to clone
E. introduces a simple single-argument API for caller that want to clone
and those that do not.
22 files changed: