freebsd-skq/tests/sys/net/routing
Alexander V. Chernikov 2fe5a79425 Fix dst/netmask handling in routing socket code.
Traditionally routing socket code did almost zero checks on
 the input message except for the most basic size checks.

This resulted in the unclear KPI boundary for the routing system code
 (`rtrequest*` and now `rib_action()`) w.r.t message validness.

Multiple potential problems and nuances exists:
* Host bits in RTAX_DST sockaddr. Existing applications do send prefixes
 with hostbits uncleared. Even `route(8)` does this, as they hope the kernel
 would do the job of fixing it. Code inside `rib_action()` needs to handle
 it on its own (see `rt_maskedcopy()` ugly hack).
* There are multiple way of adding the host route: it can be DST without
 netmask or DST with /32(/128) netmask. Also, RTF_HOST has to be set correspondingly.
 Currently, these 2 options create 2 DIFFERENT routes in the kernel.
* no sockaddr length/content checking for the "secondary" fields exists: nothing
 stops rtsock application to send sockaddr_in with length of 25 (instead of 16).
 Kernel will accept it, install to RIB as is and propagate to all rtsock consumers,
 potentially triggering bugs in their code. Same goes for sin_port, sin_zero, etc.

The goal of this change is to make rtsock verify all sockaddr and prefix consistency.
Said differently, `rib_action()` or internals should NOT require to change any of the
 sockaddrs supplied by `rt_addrinfo` structure due to incorrectness.

To be more specific, this change implements the following:
* sockaddr cleanup/validation check is added immediately after getting sockaddrs from rtm.
* Per-family dst/netmask checks clears host bits in dst and zeros all dst/netmask "secondary" fields.
* The same netmask checking code converts /32(/128) netmasks to "host" route case
 (NULL netmask, RTF_HOST), removing the dualism.
* Instead of allowing ANY "known" sockaddr families (0<..<AF_MAX), allow only actually
 supported ones (inet, inet6, link).
* Automatically convert `sockaddr_sdl` (AF_LINK) gateways to
  `sockaddr_sdl_short`.

Reported by:	Guy Yur <guyyur at gmail.com>
Reviewed By:	donner
Differential Revision: https://reviews.freebsd.org/D28668
MFC after:	3 days
2021-02-16 20:30:04 +00:00
..
generic_cleanup.sh Switch rtsock tests to per-test jails and epair interfaces. 2020-03-29 06:25:57 +00:00
Makefile build: provide a default WARNS for all in-tree builds 2020-09-18 17:17:46 +00:00
params.h Switch rtsock tests to per-test jails and epair interfaces. 2020-03-29 06:25:57 +00:00
rtsock_common.h Fix dst/netmask handling in routing socket code. 2021-02-16 20:30:04 +00:00
rtsock_config.h Skip routing regression tests depending on if_epair if this module isn't installed. 2020-04-17 16:31:07 +00:00
rtsock_print.h Remove trailing whitespace 2020-02-16 10:59:32 +00:00
test_rtsock_l3.c Split rtinit() into multiple functions. 2021-01-16 22:42:41 +00:00
test_rtsock_lladdr.c Add routing tests verifying basic RTM_CHANGE functionality. 2020-04-02 20:02:33 +00:00