Now that I understand the poorly written BSD routing code and what
authorJeffrey Hsu <hsu@dragonflybsd.org>
Thu, 6 Jan 2005 17:59:32 +0000 (17:59 +0000)
committerJeffrey Hsu <hsu@dragonflybsd.org>
Thu, 6 Jan 2005 17:59:32 +0000 (17:59 +0000)
commitf3ed2586bd034c9a75914e4e28354af8bfe2aabc
tree72ceb6a01375af7e881ea347730b10c6c18265e8
parente2d5dced98f327a1f53b46e291618223b237a803
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:
sys/net/faith/if_faith.c
sys/net/hostcache.c
sys/net/if_atm.h
sys/net/if_fddisubr.c
sys/net/route.c
sys/net/route.h
sys/net/rtsock.c
sys/netinet/if_ether.c
sys/netinet/in_gif.c
sys/netinet/in_hostcache.c
sys/netinet/in_rmx.c
sys/netinet/ip_icmp.c
sys/netinet6/icmp6.c
sys/netinet6/in6.c
sys/netinet6/in6_gif.c
sys/netinet6/in6_ifattach.c
sys/netinet6/in6_pcb.c
sys/netinet6/in6_rmx.c
sys/netinet6/in6_src.c
sys/netinet6/ip6_output.c
sys/netinet6/nd6.c
sys/netinet6/nd6_nbr.c