aboutsummaryrefslogtreecommitdiff
path: root/sys/net/route
Commit message (Collapse)AuthorAgeFilesLines
* fibs: Suppress the WARNING message for setups with multiple fibsZhenlei Huang2024-08-011-5/+0
| | | | | | | | | | | | | Change 2d3982419593 switched net.add_addr_allfibs default to 0. The warning message is for potential users of the feature. Well since all supported releases have 0 as default, those potential users may have already gotten the notification, emitting this WARNING every time increasing the fib number is less useful but rather confusing to other users. So let's suppress it right now. PR: 280097 Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D45971
* route: Wrap long linesMark Johnston2024-07-141-13/+23
| | | | | | | No functional change intended. MFC after: 1 week Sponsored by: Klara, Inc.
* fib_algo(4): Lower level of algorithm switching messages to LOG_INFOMarius Strobl2024-02-051-1/+1
| | | | | | | | | | | | Otherwise, with the default flm_debug_level of LOG_NOTICE, it's rather easy to trigger debug messages such as: [fib_algo] inet.0 (bsearch4#18) rebuild_fd_flm: switching algo to radix4_lockless Also, the "severity" of these events generally only justifies LOG_INFO and not LOG_NOTICE. Reviewed by: melifaro
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-273-3/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* sys: Remove ancient SCCS tags.Warner Losh2023-11-271-2/+0
| | | | | | | | 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
* net/route: properly brace the RT_LOG() macroGleb Smirnoff2023-10-191-4/+5
|
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1611-12/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1610-20/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* ddb: Rework macros to make it easier to add new command tables.John Baldwin2023-07-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Add new DB_DEFINE_TABLE and DB_DECLARE_TABLE macros to define new command tables. DB_DECLARE_TABLE is intended for use in headers similar to MALLOC_DECLARE and SYSCTL_DECL. DB_DEFINE_TABLE takes three arguments, the name of the parent table, the command name, and the name of the table itself, e.g. DB_DEFINE_TABLE(show, foo, show_foo) defines a new "show foo" table. - DB_TABLE_COMMAND, DB_TABLE_COMMAND_FLAGS, DB_TABLE_ALIAS, and DB_ALIAS_FLAGS allow new commands and aliases to be defined. These are similar to the existing DB_COMMAND, etc. except that they take an initial argument giving the name of the parent table, e.g.: DB_TABLE_COMMAND(show_foo, bar, db_show_foo_bar) defines a new "show foo bar" command. This provides a cleaner interface than the ad-hoc use of internal macros like _DB_SET that was required previously (e.g. in cxgbe(4)). This retires DB_FUNC macro as well as the internal _DB_FUNC macro. Reviewed by: melifaro, kib, markj Differential Revision: https://reviews.freebsd.org/D40819
* routing: fix panic triggered by the 'gr_idx != 0' assert in nhg codeAlexander V. Chernikov2023-05-171-5/+2
| | | | | | | | | | | | | | | | Nexthop groups can be referenced by the external code. The reference can be released after the VNET destruction. Furthermore, nexthop groups use a single per-rib lock, which is destroyed during the VNET desctruction. To eliminate use-after-free problem, each nhg is marked as "unlinked" during the VNET destruction stage, leaving nhg_idx intact. Normally there should not be such nexthops, but if there are any, the kernel will panic on 'gr_idx != 0' when the last nhg reference is released. Address this by using the assert checks only when the nexthop group is destroyed during "valid" VNET lifetime. MFC after: 3 days
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1217-17/+17
| | | | | | | | | 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
* routing: add iterator-based nhop traversal KPI.Alexander V. Chernikov2023-04-252-0/+63
| | | | MFC after: 2 weeks
* routing: add rt_tables_get_rnh_safe() that doesn't panic when af/fib isAlexander V. Chernikov2023-04-252-0/+13
| | | | | | incorrect. MFC after: 2 weeks
* netlink: allow exact-match route lookups via RTM_GETROUTE.Alexander V. Chernikov2023-04-022-4/+16
| | | | | | | | Use already-existing RTM_F_PREFIX rtm_flag to indicate that the request assumes exact-prefix lookup instead of the longest-prefix-match. MFC after: 2 weeks
* routing: add public rt_is_exportable() version to check ifAlexander V. Chernikov2023-03-262-0/+26
| | | | | | | the route can be exported to userland when jailed. Differential Revision: https://reviews.freebsd.org/D39204 MFC after: 2 weeks
* netlink: fix NOINET6 build.Alexander V. Chernikov2023-02-241-0/+4
| | | | | | Reported by: Michael Paepcke <bugs.fbsd@paepcke.de> PR: 269787 MFC after: 3 days
* netlink: fix addition of blackhole/reject routes.Alexander V. Chernikov2023-02-231-0/+23
| | | | | | | | | | * Make nhop_set_blackhole() set all necessary properties for the nexthop * Make nexthops blackhole/reject based on the rtm_type netlink property instead of using rtflags. Reported by: Marek Zarychta <zarychtam@plan-b.pwste.edu.pl> MFC after: 3 days
* routing: always pass rtentry to add_route_flags().Alexander V. Chernikov2023-02-171-1/+13
| | | | | | | | | add_route_flags() uses `rt` prefix data to lookup the the current rtentry from the routing table. Update rib_add_route_px() to always pass rtentry regardless of the op_flags. Reported by: Stefan Grundmann <sg2342@googlemail.com> MFC after: 1 day
* fibs: restrict jail_attach(2) if process fibnum >= numfibs in the jail.Alexander V. Chernikov2023-02-121-0/+34
| | | | | | | | Reported by: olivier Tested by: olivier Reviewed by: kp, glebius Differential Revision: https://reviews.freebsd.org/D38505 MFC after: 1 week
* ifnet/API: Move struct ifnet definition to a <net/if_private.h>Justin Hibbits2023-01-246-1/+5
| | | | | | | | | | | Hide the ifnet structure definition, no user serviceable parts inside, it's a netstack implementation detail. Include it temporarily in <net/if_var.h> until all drivers are updated to use the accessors exclusively. Reviewed by: glebius Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38046
* routing: add missed RIB_WUNLOCK in the add_route_flags().Alexander V. Chernikov2022-12-301-0/+1
| | | | MFC after: 2 weeks
* routing: Use NET_EPOCH_[CALL|WAIT] macrosZhenlei Huang2022-12-217-16/+9
| | | | | | Reviewed by: melifaro, kp Approved by: kp (mentor) Differential Revision: https://reviews.freebsd.org/D37729
* netlink: add interface notification on link status / flags change.Alexander V. Chernikov2022-12-091-0/+2
| | | | | | | | | | | | | | | | * Add link-state change notifications by subscribing to ifnet_link_event. In the Linux netlink model, link state is reported in 2 places: first is the IFLA_OPERSTATE, which stores state per RFC2863. The second is an IFF_LOWER_UP interface flag. As many applications rely on the latter, reserve 1 bit from if_flags, named as IFF_NETLINK_1. This flag is mapped to IFF_LOWER_UP in the netlink headers. This is done to avoid making applications think this flag is actually supported / presented in non-netlink outputs. * Add flag change notifications, by hooking into rt_ifmsg(). In the netlink model, notification should include the bitmask for the change flags. Update rt_ifmsg() to include such bitmask. Differential Revision: https://reviews.freebsd.org/D37597
* netlink: store user-provided rtm_protocolAlexander V. Chernikov2022-12-021-0/+1
| | | | | | | | | | | | | | Store user-supplied source protocol in the nexthops and nexthop groups. Protocol specification help routing daemons like bird to quickly identify self-originated routes after the crash or restart. Example: ``` 10.2.0.0/24 via 10.0.0.2 dev vtnet0 proto bird 10.3.0.0/24 proto bird nexthop via 10.0.0.2 dev vtnet0 weight 3 nexthop via 10.0.0.3 dev vtnet0 weight 4 ```
* routing: provide dedicated function for nhgrp creation and linking.Alexander V. Chernikov2022-12-022-11/+77
| | | | | | | | | | | | | | | | | | | There is a need to store client metadata in nexthops and nexthop groups. This metadata is immutable and participate in nhop/nhg comparison. Nexthops KPI already supports its: nexthop creation pattern is ``` nhop_alloc() nhop_set_...() ... nhop_get_nhop() ``` This change provides a similar pattern for the nexthop groups. Specifically, it adds nhgrp_alloc(), nhgrp_get_nhgrp() and nhgrp_set_uidx(). MFC after: 2 weeks
* netlink: add netlink supportAlexander V. Chernikov2022-10-011-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Netlinks is a communication protocol currently used in Linux kernel to modify, read and subscribe for nearly all networking state. Interfaces, addresses, routes, firewall, fibs, vnets, etc are controlled via netlink. It is async, TLV-based protocol, providing 1-1 and 1-many communications. The current implementation supports the subset of NETLINK_ROUTE family. To be more specific, the following is supported: * Dumps: - routes - nexthops / nexthop groups - interfaces - interface addresses - neighbors (arp/ndp) * Notifications: - interface arrival/departure - interface address arrival/departure - route addition/deletion * Modifications: - adding/deleting routes - adding/deleting nexthops/nexthops groups - adding/deleting neghbors - adding/deleting interfaces (basic support only) * Rtsock interaction - route events are bridged both ways The implementation also supports the NETLINK_GENERIC family framework. Implementation notes: Netlink is implemented via loadable/unloadable kernel module, not touching many kernel parts. Each netlink socket uses dedicated taskqueue to support async operations that can sleep, such as interface creation. All message processing is performed within these taskqueues. Compatibility: Most of the Netlink data models specified above maps to FreeBSD concepts nicely. Unmodified ip(8) binary correctly works with interfaces, addresses, routes, nexthops and nexthop groups. Some software such as net/bird require header-only modifications to compile and work with FreeBSD netlink. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D36002 MFC after: 2 months
* routing: constantify nh/nhg argument in <nhop|nhgrp>_get_origin().Alexander V. Chernikov2022-09-083-5/+5
| | | | MFC after: 1 month
* routing: add abitity to set the protocol that installed route/nexthop.Alexander V. Chernikov2022-09-086-1/+38
| | | | | | | | | | | | | | | Routing daemons such as bird need to know if they install certain route so they can clean it up on startup, as a form of achieving consistent state during the crash recovery. Currently they use combination of routing flags (RTF_PROTO1) to detect these routes when interacting via route(4) rtsock protocol. Netlink protocol has a special "rtm_protocol" field that is filled and checked by the route originator. To prepare for the upcoming netlink introduction, add ability to record origing to both nexthops and nexthop groups via <nhop|nhgrp>_<get|set>_origin() KPI. The actual calls will be used in the followup commits. MFC after: 1 month
* routing: allow logging framework to be used outside of the subsystemAlexander V. Chernikov2022-09-051-3/+6
| | | | MFC after: 2 weeks
* domains: use queue(9) SLIST for linked list of domainsGleb Smirnoff2022-08-301-3/+3
|
* routing: constantify @rc in rib_decompose_notification().Alexander V. Chernikov2022-08-292-4/+4
| | | | | | Clarify the @rc immutability by explicitly marking @rc const. MFC after: 2 weeks
* Revert "routing: install prefix and loopback routes using new nhop-based KPI."Alexander V. Chernikov2022-08-292-109/+87
| | | | | | Temporarily revert the commit to unblock testing. This reverts commit a1b59379db7d879551118b921f6e9692b4bf200c.
* routing: improve multiline debugAlexander V. Chernikov2022-08-296-57/+59
| | | | | | | | Add IF_DEBUG_LEVEL() macro to ensure all debug output preparation is run only if the current debug level is sufficient. Consistently use it within routing subsystem. MFC after: 2 weeks
* routing: extend nhop(9) kpiAlexander V. Chernikov2022-08-297-42/+102
| | | | | | | | | | | | | | | | * add nhop_get_unlinked() used to prepare referenced but not linked nexthop, that can later be used as a clone source. * add nhop_check_gateway() to check for allowed address family combinations between the rib family and neighbor family (useful for 4o6 or direct routes) * add nhop_set_upper_family() to allow copying IPv6 nexthops to IPv4 rib. * add rt_get_rnd() wrapper, returning both nexthop/group and its weight attached to the rtentry. * Add CHT_SLIST_FOREACH_SAFE(), allowing to delete items during iteration. MFC after: 2 weeks
* routing: fix rib_add_route_px()Alexander V. Chernikov2022-08-291-17/+3
| | | | | | | Fix panic in newly-added rib_add_route_px() by removin unlocked prefix lookup. MFC after: 2 weeks
* routing: add ability to store opaque indentifiers in nhops/nhgsAlexander V. Chernikov2022-08-299-11/+41
| | | | | | | This is a pre-requisite for the direct nexthop/nexhop group operations via netlink. MFC after: 2 weeks
* routing: add rib_add_default_route() wrapperAlexander V. Chernikov2022-08-292-2/+58
| | | | | | | | | Multiple consumers in the kernel space want to install IPv4 or IPv6 default route. Provide convenient wrapper to simplify the code inside the customers. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D36167
* routing: install prefix and loopback routes using new nhop-based KPI.Alexander V. Chernikov2022-08-292-87/+111
| | | | | | | | | | | Construct the desired hexthops directly instead of using the "translation" layer in form of filling rt_addrinfo data. Simplify V_rt_add_addr_allfibs handling by using recently-added rib_copy_route() to propagate the routes to the non-primary address fibs. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D36166
* routing: add rib_match_gw() helperAlexander V. Chernikov2022-08-122-3/+21
| | | | | | | | | | | Finish 02e05b8faec1: * add gateway matcher function that can be used in rib_del_route_px() or any rib_walk-family functions. It will be used in the upcoming migration to the new KPI * rename gw_fulter_func to match_gw_one() to better signal the function purpose / semantic. MFC after: 1 month
* routing: fix non-debug buildMateusz Guzik2022-08-111-1/+1
| | | | Sponsored by: Rubicon Communications, LLC ("Netgate")
* routing: populate fibs with interface routes after growing net.fibs.Alexander V. Chernikov2022-08-116-3/+149
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently it is possible to extend number of fibs in runtime, but this functionality is of limited use when net.add_addrs_all_fibs is non-zero, as the routing tables are created empty. This change automatically populate newly-created fibs with the kernel-originated interface routes (filtered by RTF_PINNED flag) if net.add_addrs_all_fibs is set. ``` -> sysctl net.add_addr_allfibs=1 net.add_addr_allfibs: 0 -> 1 -> sysctl net.fibs net.fibs: 2 -> sysctl net.fibs=3 net.fibs: 2 -> 3 BEFORE: -> setfib 2 netstat -rn Routing tables (fib: 2) AFTER: -> setfib 2 netstat -rn Routing tables (fib: 2) Internet: Destination Gateway Flags Netif Expire 10.0.0.0/24 link#1 U vtnet0 10.0.0.5 link#1 UHS lo0 127.0.0.1 link#2 UH lo0 Internet6: Destination Gateway Flags Netif Expire ::1 link#2 UHS lo0 2a01:4f9:3a:fa00::/64 link#1 U vtnet0 2a01:4f9:3a:fa00:5054:ff:fe15:4a3b link#1 UHS lo0 fe80::%vtnet0/64 link#1 U vtnet0 fe80::5054:ff:fe15:4a3b%vtnet0 link#1 UHS lo0 fe80::%lo0/64 link#2 U lo0 fe80::1%lo0 link#2 UHS lo0 ``` Differential Revision: https://reviews.freebsd.org/D36075 MFC after: 1 month
* routing: fixup empty mask prefix handling after 2ce553854cbd.Alexander V. Chernikov2022-08-112-14/+29
| | | | MFC after: 1 month
* routing: fix build warning without ROUTE_MPATHAlexander V. Chernikov2022-08-111-0/+4
| | | | | Reported by: Gary Jennejohn <garyj@gmx.de> MFC after: 1 month
* routing: fix build without ROUTE_MPATHAlexander V. Chernikov2022-08-101-1/+1
| | | | MFC after: 1 month
* routing: move rtentry and subscription code out of route_ctl.cAlexander V. Chernikov2022-08-105-429/+532
| | | | | | | | | | | route_ctl.c size has grown considerably since initial introduction. Factor out non-relevant parts: * all rtentry logic, such as creation/destruction and accessors goes to net/route/route_rtentry.c * all rtable subscription logic goes to net/route/route_subscription.c Differential Revision: https://reviews.freebsd.org/D36074 MFC after: 1 month
* routing: add rib_<add|del>_route_px() functions operating with nexthops.Alexander V. Chernikov2022-08-104-215/+402
| | | | | | | | | | | | | | | | | | This change adds public KPI to work with routes using pre-created nexthops, instead of using data from addrinfo structures. These functions will be later used for adding/deleting kernel-originated routes and upcoming netlink protocol. As a part of providing this KPI, low-level route addition code has been reworked to provide more control over route creation or change. Specifically, a number of operation flags (RTM_F_<CREATE|EXCL|REPLACE|APPEND>) have been added, defining the desired behaviour the the route already exists (or not exists). This change required some changes in the multipath addition code, resulting in moving this code to route_ctl.c, rendering mpath_ctl.c empty. Differential Revision: https://reviews.freebsd.org/D36073 MFC after: 1 month
* routing: split nexthop creation and rtentry creation.Alexander V. Chernikov2022-08-101-59/+36
| | | | | | | | | This change is required for the upcoming introduction of the next nexhop-based operations KPI, as it will create rtentry and nexthops at different stages of route table modification. Differential Revision: https://reviews.freebsd.org/D36072 MFC after: 2 weeks
* routing: refactor #2Alexander V. Chernikov2022-08-105-138/+118
| | | | | | | | | | | * Use same filter func (rib_filter_f_t) for nexhtop groups to simplify callbacks. * simplify conditional route deletion & remove the need to pass rt_addrinfo to the low-level deletion functions * speedup rib_walk_del() by removing an additional per-prefix lookup Differential Revision: https://reviews.freebsd.org/D36071 MFC after: 1 month
* routing: refactor control cmds #1Alexander V. Chernikov2022-08-103-122/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This and the follow-up routing-related changes target to remove or reduce `struct rt_addrinfo` usage and use recently-landed nhop(9) KPI instead. Traditionally `rt_addrinfo` structure has been used to propagate all necessary information between the protocol/rtsock and a routing layer. Many functions inside routing subsystem uses it internally. However, using this structure became somewhat complicated, as there are too many ways of specifying a single state and verifying data consistency is hard. For example, arerouting flgs consistent with mask/gateway sockaddr pointers? Is mask really a host mask? Are sockaddr "valid" (e.g. properly zeroed, masked, have proper length)? Are they mutable? Is the suggested interface specified by the interface index embedded into the sockadd_dl gateway, or passed as RTAX_IFP parameter, or directly provided by rti_ifp or it needs to be derived from the ifa? These (and other similar) questions have to be considered every time when a function has `rt_addrinfo` pointer as an argument. The new approach is to bring more control back to the protocols and construct the desired routing objects themselves - in the end, it's the protocol/subsystem who knows the desired outcome. This specific diff changes the following: * add explicit basic low-level radix operations: add_route() (renamed from add_route_nhop()) delete_route() (factored from change_route_nhop()) change_route() (renamed from change_route_nhop) * remove "info" parameter from change_route_conditional() as a part of reducing rt_addrinfo usage in the internal KPIs * add lookup_prefix_rt() wrapper for doing re-lookups after RIB lock/unlock Differential Revision: https://reviews.freebsd.org/D36070 MFC after: 2 weeks