opnsense-src/tests/sys
Alexander V. Chernikov e1bdecd9f6 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

(cherry picked from commit 2fe5a79425)
2021-03-10 21:48:06 +00:00
..
acl Drop "All rights reserved" from all my stuff. This includes 2020-10-28 13:46:11 +00:00
aio lio_listio: validate aio_lio_opcode 2021-01-11 19:53:01 -07:00
audit tests/sys/audit: force PIE off 2021-03-05 12:46:11 -05:00
auditpipe Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
capsicum Temporarily skip failing test cases in CI: 2020-10-07 09:53:24 +00:00
cddl build: provide a default WARNS for all in-tree builds 2020-09-18 17:17:46 +00:00
common Add tests verifying IPv4/IPv6 output for TCP/UDP/raw paths. 2020-03-23 12:21:32 +00:00
devrandom Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
fifo Avoid hard-coding pipe buffer sizes in the pipe and fifo kqueue tests. 2020-05-20 17:48:18 +00:00
file close_range/closefrom: fix regression from close_range introduction 2020-04-13 17:55:31 +00:00
fs fusefs: implement FUSE_COPY_FILE_RANGE. 2021-01-01 10:18:23 -07:00
geom build: provide a default WARNS for all in-tree builds 2020-09-18 17:17:46 +00:00
kern fdgrowtable_test.c: appease gcc 2020-12-11 22:52:16 +00:00
kqueue Enable timer tests in sys.kqueue.libkqueue.kqueue_test.main on i386 2020-04-22 09:53:41 +00:00
mac Resolve conflict between the fusefs(5) and mac_bsdextended(4) tests 2020-05-02 20:14:59 +00:00
mqueue Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
net Fix dst/netmask handling in routing socket code. 2021-03-10 21:48:06 +00:00
netgraph New Netgraph module ng_macfilter: 2020-12-08 15:09:42 +00:00
netinet ping: fix some man pages and tests after r368045 2020-11-26 04:55:02 +00:00
netinet6 ping: fix some man pages and tests after r368045 2020-11-26 04:55:02 +00:00
netipsec ping: fix some man pages and tests after r368045 2020-11-26 04:55:02 +00:00
netmap Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
netpfil pf tests: Explicitly ask for python3 2021-02-24 09:04:19 +01:00
opencrypto Remove __NO_TLS. 2021-03-02 02:49:42 +02:00
pjdfstest Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
posixshm posixshm_test.c: remove tautological checks 2020-12-11 22:52:20 +00:00
sys Revert r357246 2020-01-29 22:37:01 +00:00
vfs vfs_lookup: Allow PATH_MAX-1 symlinks 2017-11-17 19:25:39 +00:00
vm [tests] Fix unused variable warning in gcc 2020-11-13 18:50:24 +00:00
Makefile New Netgraph module ng_macfilter: 2020-12-08 15:09:42 +00:00
Makefile.depend DIRDEPS_BUILD: Connect MK_TESTS. 2016-03-09 22:46:01 +00:00
Makefile.inc Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00