Commit Graph

258 Commits

Author SHA1 Message Date
Mark Johnston
2e55256de3 route tests: Serialize
These tests reuse jail names and so cannot run in parallel.

MFC after:	1 week
2024-01-27 13:51:14 -05:00
Mike Karels
b9e8ae1d8a route: error on IPv4 network routes with incorrect destination
Route destinations like 10/8 are most likely intended as a shorthand
for 10.0.0.0/8, but instead it means 0.0.0.10/8, which includes
only bits in the host part of the mask, and hence adds a route to
0.0.0.0/8.  In 12.x, there was code to "do what I mean", which was
removed as part of a cleanup of old network class remnants.  Given
that we have gone this long without that code, do not restore that
behavior.  Instead, detect the issue and produce an error.
Specifically, if there are no dots in a numeric IPv4 address, the
mask is specified with CIDR notation (using a slash), and there are
bits set in the host part, produce an error like this for 10/8:

    route: malformed address, bits set after mask; 10 means 0.0.0.10

PR:		258874
MFC after:	1 week
Reviewed by:	melifaro, emaste
Differential Revision:	https://reviews.freebsd.org/D43384
2024-01-15 15:14:54 -06:00
R. Christian McDonald
ca7edd0d2c
route: introduce add interface route test cases
As a followup to D41330 and D41436, this patch introduces two new tests
for sbin/route: interface_route_v[46].

These tests fail without D41330.

Reviewed by:	kp
Approved by:	kp (mentor)
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-11-28 16:16:25 -05:00
Warner Losh
0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh
51e16cb8fc sbin: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:29 -07:00
Kristof Provost
4f8f43b06e netlink: cope with growing requests
If a request ends up growing beyong the initially allocated space the
netlink functions (such as snl_add_msg_attr_u32()) will allocate a
new buffer. This invalidates the header pointer we can have received
from snl_create_msg_request(). Always use the hdr returned by
snl_finalize_msg().

Reviewed by:	melifaro
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42223
2023-10-17 08:47:52 +02:00
R. Christian McDonald
2a78083fc2 route(8): fix route not found exit code and warn with netlink
Fix route(8) incorrectly returning a zero exit code even when unable to
find the specified route with route -n get <route>.

Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D41882
2023-09-19 19:34:02 +02:00
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Marko Zec
32b28e3ae2 route.8: mention DXR in FIB_ALGO section
While here, add a sentence describing DPDK DIR24-8 principle of
operation.

MFC after:	2 weeks.
2023-06-15 07:21:51 +02:00
Yan Ka, Chiu
ab4d1b73cb route(8): teach route to attach to jails
Add -j <jail> flag to route(8) to allow route to perform actions in
a Jail.

Differential Revision: https://reviews.freebsd.org/D40377
MFC after:	2 weeks
2023-06-13 06:06:27 +00:00
Alexander V. Chernikov
656a39c1a0 netlink: use newly-added snl(3) array parsing for handling multipath
routes.

MFC after:	2 weeks
2023-05-27 11:13:14 +00:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Alexander V. Chernikov
30d7e724db route: show originator PID in netlink monitor
Replacing rtsock with netlink also means providing similar tracing facilities,
rtsock provides `route -n monitor` interface, where each message can be traced
to the originating PID.
This diff closes the feature gap between rtsock and netlink in that regard.

Netlink works slightly differently from rtsock, as it is a generic message
"broker". It calls some kernel KPIs and returns the result to the caller.
Other Netlink consumers gets notified on the changed kernel state using the
relevant subsystem callbacks. Typically, it is close to impossible to pass
some data through these KPIs to enhance the notification.

This diff approaches the problem by using osd(9) to assign the relevant
socket pointer (`'nlp`) to the per-socket taskqueue execution thread.
This change allows to recover the pointer in the aforementioned notification
callbacks and extract some additional data.
Using `osd(9)` (and adding additional metadata) to the notification receiver
comes with some additional cost attached, so this interface needs to be
enabled explicitly by using a newly-created `NETLINK_MSG_INFO` `SOL_NETLINK`
socket option.

The actual medatadata (which includes the originator PID) is provided via
control messages. To enable extensibility, the control message data is
encoded in the standard netlink(TLV-based) fashion. The list of the
currently-provided properties can be found in `nlmsginfo_attrs`.
snl(3) is extended to enable decoding of netlink messages with metadata
(`snl_read_message_dbg()` stores the parsed structure in the provided buffer).

Differential Revision: https://reviews.freebsd.org/D39391
2023-04-28 13:54:54 +00:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Alexander V. Chernikov
351e4592f6 route: remove always-true expression 2023-04-09 10:04:56 +00:00
Alexander V. Chernikov
091fec1188 route: switch transport protocol to Netlink.
All known bugs have been fixed, try to enable Netlink once again.
2023-04-08 18:02:57 +00:00
Alexander V. Chernikov
ee8f5c2a31 route: fix netlink route operations with link-local gw / dst.
Extract ifindex from either gw or dst sockaddr and add it as a
 dedicated RTA_OIF attribute.
2023-04-08 11:38:05 +00:00
Alexander V. Chernikov
f262b06a57 route: fix route get netlink translation.
route.c uses newroute() to handle the "route get" command. The logic
 inside newroute() adds RTF_GATEWAY flag if "-interface" flag is not
 specified. That results in the inconsistent RTM_GET message with
 RTF_GATEWAY set but no RTAX_GATEWAY provided. Address this in the
 translation code by checking if the gateway is actually provided.
2023-04-04 08:42:33 +00:00
Alexander V. Chernikov
68f9e13563 route: add support for exact-prefix-match via netlink. 2023-04-02 13:50:05 +00:00
Alexander V. Chernikov
140ddeba08 route: try to autoload netlink(4) module if not present in the kernel.
Differential Revision: https://reviews.freebsd.org/D39324
2023-03-30 09:53:06 +00:00
Alexander V. Chernikov
bd9d75e49f route: revert transport to rtsock
Temporary switch route(8) back to using rtsock to address
 the discovered issues.
2023-03-28 08:56:18 +00:00
Alexander V. Chernikov
3a151e31ac route: fix RTF_HOST & non-empty mask handling in netlink translation. 2023-03-26 18:07:23 +00:00
Alexander V. Chernikov
c597432e22 route(8): convert to netlink
This change converts all kernel rtsock interactions in route(8)
 to Netlink.

Based on the WITHOUT_NETLINK_SUPPORT src.conf(5) variable, route(8)
 now fully operates either via Netlink or via rtsock/sysctl.
The default (compile-time) is Netlink.

The output for route delete/add/get/flush is targeted to be exactly
 the same (apart from some error handling cases).
The output for the route monitor has been changed to improve
 readability and support netlink models.

Other behaviour changes:
* exact prefix lookup (route -n get a.b.c.d/e) is not yet supported.
* route monitor does not show the change originator yet.

Differential Revision:	https://reviews.freebsd.org/D39007
2023-03-26 11:06:56 +00:00
Gordon Bergling
21f2681828 route.8: Don't reference an external command in EXAMPLES
It is better to mention the externel command for showing
the routing table as using an explicit command.

PR:	231579
Suggested by:	karels
Reviewed by:	karles, gbe
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D39075
2023-03-14 14:55:28 +01:00
Gordon Bergling
6dbfbe6e11 route.8: Fix mandoc warnings
- skipping end of block that is not open: Oc
- no blank before trailing delimiter
- remove useless TN macros
- remove commented out reference for esis(4)

MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D38783
2023-02-26 14:33:58 +01:00
Gordon Bergling
b06338167d route.8: Add information about ROUTE_MPATH and FIB_ALGO
Since the kernel options ROUTE_MPATH and FIB_ALGO are enabled
per default for a while, it's good to have some user facing
documetation about the general functionality of multipath
routing and fib lookup algorithms.

Reviewed by:	pauamma, Jose Luis Duran <jlduran at gmail dot com>
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D38783
2023-02-26 14:15:34 +01:00
Ed Maste
f567fcb2ff route: remove write-only struct hostent from getaddr()
Under some INET/INET6 src.conf configurations sbin/route previously
failed to build due to an unused variable warning.  It was functionally
write-only anyway, so just remove it.

Reported by:	melifaro
Reviewed by:	melifaro
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33717
2022-01-06 10:45:44 -05:00
Ed Maste
c217390359 route: use NULL for null ptr in getaddr call, not 0
Style(9) prefers NULL.

Sponsored by:	The FreeBSD Foundation
2022-01-01 12:02:17 -05:00
Warner Losh
c6b2efb64e route(8): Remove obsolete information
xns and osi are no longer relevant (or supported) so remove their
vestiges.

Noticed by:	phk
Sponsored by:	Netflix
2021-12-15 16:07:35 -07:00
Roy Marples
7045b1603b socket: Implement SO_RERROR
SO_RERROR indicates that receive buffer overflows should be handled as
errors. Historically receive buffer overflows have been ignored and
programs could not tell if they missed messages or messages had been
truncated because of overflows. Since programs historically do not
expect to get receive overflow errors, this behavior is not the
default.

This is really really important for programs that use route(4) to keep
in sync with the system. If we loose a message then we need to reload
the full system state, otherwise the behaviour from that point is
undefined and can lead to chasing bogus bug reports.

Reviewed by:	philip (network), kbowling (transport), gbe (manpages)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26652
2021-07-28 09:35:09 -07:00
Gordon Bergling
bc54f5f1cd route(8): Add an example how to print the routing tables
The manual page currently doesn't show an example how to print
the routing table, so add one and .Xr netstat while here.

PR:		231579
Reported by:	Pekka Järvinen <pekka dot jarvinen at gmail dot com>
Reviewed by:	debdrup
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D29702
2021-04-13 06:45:22 +02:00
Alexander V. Chernikov
924d1c9a05 Revert "SO_RERROR indicates that receive buffer overflows should be handled as errors."
Wrong version of the change was pushed inadvertenly.

This reverts commit 4a01b854ca.
2021-02-08 22:32:32 +00:00
Alexander V. Chernikov
4a01b854ca SO_RERROR indicates that receive buffer overflows should be handled as errors.
Historically receive buffer overflows have been ignored and programs
could not tell if they missed messages or messages had been truncated
because of overflows. Since programs historically do not expect to get
receive overflow errors, this behavior is not the default.

This is really really important for programs that use route(4) to keep in sync
with the system. If we loose a message then we need to reload the full system
state, otherwise the behaviour from that point is undefined and can lead
to chasing bogus bug reports.
2021-02-08 21:42:20 +00:00
Alexander V. Chernikov
d28210b2c2 Remove remnants of classful behavior in route(8).
Curently route(8) treats some addresses as network addresses:

 RTA_DST: inet 10.0.0.0; RTA_NETMASK: inet 255.0.0.0; RTA_IFP: link ;
 RTM_GET: Report Metrics: len 240, pid: 0, seq 1, errno 0, flags:<UP,GATEWAY,STATIC>
 locks:  inits:
 sockaddrs: <DST,NETMASK,IFP>
   10.0.0.0 255.0.0.0 link#0

Note added `RTA_NETMASK` in the request.

Host address from the same network is ok:

route -nv get 10.0.0.1
 RTA_DST: inet 10.0.0.1
 RTA_IFP: link
 RTM_GET: Report Metrics: len 224, pid: 0, seq 1, errno 0, flags:<UP,GATEWAY,HOST,STATIC>
...
   route to: 10.0.0.1
destination: 10.0.0.0
       mask: 255.255.255.0

This change eliminates network auto-guessing part AND reading network from /etc/networks.

Reviewed By: rgrimes

Differential Revision: https://reviews.freebsd.org/D24401
2021-01-16 23:45:30 +00:00
Olivier Cochard
784d8d8db0 Skip sbin/route tests if jail not installed (WITHOUT_JAIL).
Approved by:	kp
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D25935
2020-08-04 21:34:13 +00:00
Tom Jones
3b01bf881c Add tests for "add", "change" and "delete" functionality of /sbin/route.
Add tests to cover "add", "change" and "delete" functionality of /sbin/route
for ipv4 and ipv6. These tests for the existing route tool are the first step
towards creating libroute.

Submitted by:   Ahsan Barkati
Sponsored by:   Google, Inc. (GSoC 2020)
Reviewed by:    kp, thj
Approved by:    bz (mentor)
MFC after:      1 month
Differential Revision:  https://reviews.freebsd.org/D25220
2020-07-22 13:49:54 +00:00
Enji Cooper
8b5fede0ac route(8): clarify -prefixlen description
Try to reword -prefixlen section to more clearly and accurately describe how
the -prefixlen modifier works.

While here, fix a word that igor considered a typo: aggregatable addresses is a
valid technical term per RFC-2374, however, it was superseded by the term
"aggregator" in RFC-3587.

MFC after:	1 week
Reviewed by:	0mp, crees
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D10087
2019-01-10 00:10:12 +00:00
Eugene Grosbein
2814116849 route(8): correctly return exit status when "-q" flag is used.
Previously, route returned 1 in case of error  properly signalling failure
but "route -q" it returned 0 for same case. Fix it.

PR:		186333
MFC after:	1 month
2018-10-27 07:59:19 +00:00
Alexander V. Chernikov
2d5832444f Fix memory leaks in route(8).
Submitted by:	Tom Rix (trix_juniper.net)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D9676
2018-03-31 15:06:14 +00:00
Eugene Grosbein
0d41f9c9f0 route(8): make it possible to manually delete pinned route
Reported by:	Andreas Longwitz <longwitz@incore.de>
Approved by:	avg (mentor)
MFC after:	1 week
2018-02-24 21:25:56 +00:00
Ryan Stone
9ec35e3cb4 Fix route manpage to show correct flush syntax
The current route(8) manpage shows that "flush" is an argument to
the optional -n flag, rather than a separate subcommand.  Correct
this to properly show flush as a route subcommand.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Reviewed by: rgrimes
Differential Revision: https://reviews.freebsd.org/D14401
2018-02-21 19:13:27 +00:00
Ryan Stone
b3b6ff23e7 Allow route change requests to not specify the gateway.
Only require a gateway to be specified on a route add request.  On
a route change request that does not specify the gateway, the
gateway will remain the same.  This allows changing other route
parameters without having to re-specifying the gateway, like in
"route change 10.0.0.0/8 -mtu 9000".

Update the route(8) manpage to explicitly call out this usage
as being supported.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Reviewed By: eugen (rtsock.c change), rgrimes
Differential Revision: https://reviews.freebsd.org/D14291
2018-02-21 19:13:23 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Konstantin Belousov
24328efbb4 Typo, the '-6' option selects inet6.
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2017-08-15 19:29:10 +00:00
Patrick Kelsey
2f8c6c0a58 Fix userland tools that don't check the format of routing socket
messages before accessing message fields that may not be present,
removing dead/duplicate/misleading code along the way.

Document the message format for each routing socket message in
route.h.

Fix a bug in usr.bin/netstat introduced in r287351 that resulted in
pointer computation with essentially random 16-bit offsets and
dereferencing of the results.

Reviewed by:	ae
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D10330
2017-04-16 19:17:10 +00:00
Enji Cooper
c9f1eca5c4 Delete trailing whitespace (no functional change)
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-03-21 22:00:52 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00