aboutsummaryrefslogtreecommitdiff
path: root/sys/net/route
Commit message (Collapse)AuthorAgeFilesLines
* net: routing table attach never failsGleb Smirnoff2025-12-041-5/+1
|
* net: Use proper prototype for SYSINIT functionsZhenlei Huang2025-10-131-1/+1
| | | | MFC after: 1 week
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-111-2/+1
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* route: fix rtentry double freeKristof Provost2025-06-051-2/+1
| | | | | | | | | add_route_flags() frees the rtentry on error when called with the RTM_F_CREATE flag. Don't free the rtentry a second time. Reviewed by: ae Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D50665
* routing: do not allow PINNED routes to be overridenAndrey V. Elsukov2025-03-021-1/+1
| | | | | | | | First configured PINNED routes should have higher priority. Fixes: 1da4954c92ea MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D48650
* routing: set net.route.multipath=0 when kernel doesn't have ROUTE_MPATHAndrey V. Elsukov2025-02-281-1/+2
| | | | MFC after: 1 week
* routing: Use NULL for VNET_SYS[UN]INIT's last arg, which is a pointer typeZhenlei Huang2024-12-091-2/+2
| | | | MFC after: 3 days
* Fix failure to add an interface prefix route when route with the sameAlexander V. Chernikov2024-11-122-10/+13
| | | | | | | | | | | prefix is already presented in the routing table. PR: 277125 Reported by: Oleksandr Ignatyev <alex@i.org.ua> Reviewed by: ae, jlduran Tested by: jlduran Differential Revision: https://reviews.freebsd.org/D47534 MFC after: 2 weeks
* 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