Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Alexander V. Chernikov
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#include "opt_route.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/jail.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/rmlock.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/route.h>
|
2020-06-01 20:49:42 +00:00
|
|
|
#include <net/route/route_ctl.h>
|
2020-04-28 19:14:09 +00:00
|
|
|
#include <net/route/route_var.h>
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
#include <net/route/nhop_utils.h>
|
|
|
|
#include <net/route/nhop.h>
|
|
|
|
#include <net/route/nhop_var.h>
|
2020-05-07 08:11:36 +00:00
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in_fib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/in6_fib.h>
|
|
|
|
#endif
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RIB helper functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calls @wa_f with @arg for each entry in the table specified by
|
|
|
|
* @af and @fibnum.
|
|
|
|
*
|
2020-11-22 20:21:10 +00:00
|
|
|
* @ss_t callback is called before and after the tree traversal
|
|
|
|
* while holding table lock.
|
|
|
|
*
|
|
|
|
* Table is traversed under read lock unless @wlock is set.
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-11-29 13:54:49 +00:00
|
|
|
rib_walk_ext_internal(struct rib_head *rnh, bool wlock, rib_walktree_f_t *wa_f,
|
2020-11-22 20:21:10 +00:00
|
|
|
rib_walk_hook_f_t *hook_f, void *arg)
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
{
|
|
|
|
RIB_RLOCK_TRACKER;
|
|
|
|
|
2020-11-22 20:21:10 +00:00
|
|
|
if (wlock)
|
|
|
|
RIB_WLOCK(rnh);
|
|
|
|
else
|
|
|
|
RIB_RLOCK(rnh);
|
|
|
|
if (hook_f != NULL)
|
|
|
|
hook_f(rnh, RIB_WALK_HOOK_PRE, arg);
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f, arg);
|
2020-11-22 20:21:10 +00:00
|
|
|
if (hook_f != NULL)
|
|
|
|
hook_f(rnh, RIB_WALK_HOOK_POST, arg);
|
|
|
|
if (wlock)
|
|
|
|
RIB_WUNLOCK(rnh);
|
|
|
|
else
|
|
|
|
RIB_RUNLOCK(rnh);
|
2020-11-29 13:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rib_walk_ext(uint32_t fibnum, int family, bool wlock, rib_walktree_f_t *wa_f,
|
|
|
|
rib_walk_hook_f_t *hook_f, void *arg)
|
|
|
|
{
|
|
|
|
struct rib_head *rnh;
|
|
|
|
|
|
|
|
if ((rnh = rt_tables_get_rnh(fibnum, family)) != NULL)
|
|
|
|
rib_walk_ext_internal(rnh, wlock, wa_f, hook_f, arg);
|
2020-11-22 20:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calls @wa_f with @arg for each entry in the table specified by
|
|
|
|
* @af and @fibnum.
|
|
|
|
*
|
|
|
|
* Table is traversed under read lock unless @wlock is set.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rib_walk(uint32_t fibnum, int family, bool wlock, rib_walktree_f_t *wa_f,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
rib_walk_ext(fibnum, family, wlock, wa_f, NULL, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterates over all existing fibs in system calling
|
|
|
|
* @hook_f function before/after traversing each fib.
|
|
|
|
* Calls @wa_f function for each element in current fib.
|
|
|
|
* If af is not AF_UNSPEC, iterates over fibs in particular
|
|
|
|
* address family.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rib_foreach_table_walk(int family, bool wlock, rib_walktree_f_t *wa_f,
|
|
|
|
rib_walk_hook_f_t *hook_f, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (uint32_t fibnum = 0; fibnum < rt_numfibs; fibnum++) {
|
|
|
|
/* Do we want some specific family? */
|
|
|
|
if (family != AF_UNSPEC) {
|
|
|
|
rib_walk_ext(fibnum, family, wlock, wa_f, hook_f, arg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i <= AF_MAX; i++)
|
|
|
|
rib_walk_ext(fibnum, i, wlock, wa_f, hook_f, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterates over all existing fibs in system and deletes each element
|
|
|
|
* for which @filter_f function returns non-zero value.
|
|
|
|
* If @family is not AF_UNSPEC, iterates over fibs in particular
|
|
|
|
* address family.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rib_foreach_table_walk_del(int family, rib_filter_f_t *filter_f, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (uint32_t fibnum = 0; fibnum < rt_numfibs; fibnum++) {
|
|
|
|
/* Do we want some specific family? */
|
|
|
|
if (family != AF_UNSPEC) {
|
|
|
|
rib_walk_del(fibnum, family, filter_f, arg, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i <= AF_MAX; i++)
|
|
|
|
rib_walk_del(fibnum, i, filter_f, arg, 0);
|
|
|
|
}
|
Introduce nexthop objects and new routing KPI.
This is the foundational change for the routing subsytem rearchitecture.
More details and goals are available in https://reviews.freebsd.org/D24141 .
This patch introduces concept of nexthop objects and new nexthop-based
routing KPI.
Nexthops are objects, containing all necessary information for performing
the packet output decision. Output interface, mtu, flags, gw address goes
there. For most of the cases, these objects will serve the same role as
the struct rtentry is currently serving.
Typically there will be low tens of such objects for the router even with
multiple BGP full-views, as these objects will be shared between routing
entries. This allows to store more information in the nexthop.
New KPI:
struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6,
uint32_t scopeid, uint32_t flags, uint32_t flowid);
These 2 function are intended to replace all all flavours of
<in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous
fib[46]-generation functions.
Upon successful lookup, they return nexthop object which is guaranteed to
exist within current NET_EPOCH. If longer lifetime is desired, one can
specify NHR_REF as a flag and get a referenced version of the nexthop.
Reference semantic closely resembles rtentry one, allowing sed-style conversion.
Additionally, another 2 functions are introduced to support uRPF functionality
inside variety of our firewalls. Their primary goal is to hide the multipath
implementation details inside the routing subsystem, greatly simplifying
firewalls implementation:
int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid,
uint32_t flags, const struct ifnet *src_if);
All functions have a separate scopeid argument, paving way to eliminating IPv6 scope
embedding and allowing to support IPv4 link-locals in the future.
Structure changes:
* rtentry gets new 'rt_nhop' pointer, slightly growing the overall size.
* rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz.
Old KPI:
During the transition state old and new KPI will coexists. As there are another 4-5
decent-sized conversion patches, it will probably take a couple of weeks.
To support both KPIs, fields not required by the new KPI (most of rtentry) has to be
kept, resulting in the temporary size increase.
Once conversion is finished, rtentry will notably shrink.
More details:
* architectural overview: https://reviews.freebsd.org/D24141
* list of the next changes: https://reviews.freebsd.org/D24232
Reviewed by: ae,glebius(initial version)
Differential Revision: https://reviews.freebsd.org/D24232
2020-04-12 14:30:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 20:21:10 +00:00
|
|
|
|
2020-05-07 08:11:36 +00:00
|
|
|
/*
|
|
|
|
* Wrapper for the control plane functions for performing af-agnostic
|
|
|
|
* lookups.
|
|
|
|
* @fibnum: fib to perform the lookup.
|
|
|
|
* @dst: sockaddr with family and addr filled in. IPv6 addresses needs to be in
|
|
|
|
* deembedded from.
|
|
|
|
* @flags: fib(9) flags.
|
|
|
|
* @flowid: flow id for path selection in multipath use case.
|
|
|
|
*
|
|
|
|
* Returns nhop_object or NULL.
|
|
|
|
*
|
|
|
|
* Requires NET_EPOCH.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct nhop_object *
|
|
|
|
rib_lookup(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags,
|
|
|
|
uint32_t flowid)
|
|
|
|
{
|
|
|
|
struct nhop_object *nh;
|
|
|
|
|
|
|
|
nh = NULL;
|
|
|
|
|
|
|
|
switch (dst->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
const struct sockaddr_in *a = (const struct sockaddr_in *)dst;
|
|
|
|
nh = fib4_lookup(fibnum, a->sin_addr, 0, flags, flowid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
const struct sockaddr_in6 *a = (const struct sockaddr_in6*)dst;
|
|
|
|
nh = fib6_lookup(fibnum, &a->sin6_addr, a->sin6_scope_id,
|
|
|
|
flags, flowid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nh);
|
|
|
|
}
|
2020-10-03 10:47:17 +00:00
|
|
|
|
|
|
|
#ifdef ROUTE_MPATH
|
|
|
|
static void
|
|
|
|
decompose_change_notification(struct rib_cmd_info *rc, route_notification_t *cb,
|
|
|
|
void *cbdata)
|
|
|
|
{
|
|
|
|
uint32_t num_old, num_new;
|
|
|
|
uint32_t nh_idx_old, nh_idx_new;
|
|
|
|
struct weightened_nhop *wn_old, *wn_new;
|
|
|
|
struct weightened_nhop tmp = { NULL, 0 };
|
|
|
|
uint32_t idx_old = 0, idx_new = 0;
|
|
|
|
|
|
|
|
struct rib_cmd_info rc_del = { .rc_cmd = RTM_DELETE, .rc_rt = rc->rc_rt };
|
|
|
|
struct rib_cmd_info rc_add = { .rc_cmd = RTM_ADD, .rc_rt = rc->rc_rt };
|
|
|
|
|
|
|
|
if (NH_IS_NHGRP(rc->rc_nh_old)) {
|
|
|
|
wn_old = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_old, &num_old);
|
|
|
|
} else {
|
|
|
|
tmp.nh = rc->rc_nh_old;
|
|
|
|
tmp.weight = rc->rc_nh_weight;
|
|
|
|
wn_old = &tmp;
|
|
|
|
num_old = 1;
|
|
|
|
}
|
|
|
|
if (NH_IS_NHGRP(rc->rc_nh_new)) {
|
|
|
|
wn_new = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_new, &num_new);
|
|
|
|
} else {
|
|
|
|
tmp.nh = rc->rc_nh_new;
|
|
|
|
tmp.weight = rc->rc_nh_weight;
|
|
|
|
wn_new = &tmp;
|
|
|
|
num_new = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the fact that each @wn array is sorted */
|
|
|
|
/*
|
|
|
|
* Want to convert into set of add and delete operations
|
|
|
|
* [1] -> [1, 2] = A{2}
|
|
|
|
* [2] -> [1, 2] = A{1}
|
|
|
|
* [1, 2, 4]->[1, 3, 4] = A{2}, D{3}
|
|
|
|
* [1, 2, 4]->[1, 4] = D{2}
|
|
|
|
* [1, 2, 4] -> [3, 4] = D{1}, C{2,3} OR C{1,3}, D{2} OR D{1},D{2},A{3}
|
|
|
|
* [1, 2] -> [3, 4] =
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
idx_old = 0;
|
|
|
|
while ((idx_old < num_old) && (idx_new < num_new)) {
|
|
|
|
nh_idx_old = wn_old[idx_old].nh->nh_priv->nh_idx;
|
|
|
|
nh_idx_new = wn_new[idx_new].nh->nh_priv->nh_idx;
|
|
|
|
|
|
|
|
if (nh_idx_old == nh_idx_new) {
|
|
|
|
if (wn_old[idx_old].weight != wn_new[idx_new].weight) {
|
|
|
|
/* Update weight by providing del/add notifications */
|
|
|
|
rc_del.rc_nh_old = wn_old[idx_old].nh;
|
|
|
|
rc_del.rc_nh_weight = wn_old[idx_old].weight;
|
|
|
|
cb(&rc_del, cbdata);
|
|
|
|
|
|
|
|
rc_add.rc_nh_new = wn_new[idx_new].nh;
|
|
|
|
rc_add.rc_nh_weight = wn_new[idx_new].weight;
|
|
|
|
cb(&rc_add, cbdata);
|
|
|
|
}
|
|
|
|
idx_old++;
|
|
|
|
idx_new++;
|
|
|
|
} else if (nh_idx_old < nh_idx_new) {
|
|
|
|
/*
|
|
|
|
* [1, ~2~, 4], [1, ~3~, 4]
|
|
|
|
* [1, ~2~, 5], [1, ~3~, 4]
|
|
|
|
* [1, ~2~], [1, ~3~, 4]
|
|
|
|
*/
|
|
|
|
if ((idx_old + 1 >= num_old) ||
|
|
|
|
(wn_old[idx_old + 1].nh->nh_priv->nh_idx > nh_idx_new)) {
|
|
|
|
/* Add new unless the next old item is still <= new */
|
|
|
|
rc_add.rc_nh_new = wn_new[idx_new].nh;
|
|
|
|
rc_add.rc_nh_weight = wn_new[idx_new].weight;
|
|
|
|
cb(&rc_add, cbdata);
|
|
|
|
idx_new++;
|
|
|
|
}
|
|
|
|
/* In any case, delete current old */
|
|
|
|
rc_del.rc_nh_old = wn_old[idx_old].nh;
|
|
|
|
rc_del.rc_nh_weight = wn_old[idx_old].weight;
|
|
|
|
cb(&rc_del, cbdata);
|
|
|
|
idx_old++;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* nh_idx_old > nh_idx_new
|
|
|
|
*
|
|
|
|
* [1, ~3~, 4], [1, ~2~, 4]
|
|
|
|
* [1, ~3~, 5], [1, ~2~, 4]
|
|
|
|
* [1, ~3~, 4], [1, ~2~]
|
|
|
|
*/
|
|
|
|
if ((idx_new + 1 >= num_new) ||
|
|
|
|
(wn_new[idx_new + 1].nh->nh_priv->nh_idx > nh_idx_old)) {
|
|
|
|
/* No next item or next item is > current one */
|
|
|
|
rc_add.rc_nh_new = wn_new[idx_new].nh;
|
|
|
|
rc_add.rc_nh_weight = wn_new[idx_new].weight;
|
|
|
|
cb(&rc_add, cbdata);
|
|
|
|
idx_new++;
|
|
|
|
}
|
|
|
|
/* In any case, delete current old */
|
|
|
|
rc_del.rc_nh_old = wn_old[idx_old].nh;
|
|
|
|
rc_del.rc_nh_weight = wn_old[idx_old].weight;
|
|
|
|
cb(&rc_del, cbdata);
|
|
|
|
idx_old++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (idx_old < num_old) {
|
|
|
|
rc_del.rc_nh_old = wn_old[idx_old].nh;
|
|
|
|
rc_del.rc_nh_weight = wn_old[idx_old].weight;
|
|
|
|
cb(&rc_del, cbdata);
|
|
|
|
idx_old++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (idx_new < num_new) {
|
|
|
|
rc_add.rc_nh_new = wn_new[idx_new].nh;
|
|
|
|
rc_add.rc_nh_weight = wn_new[idx_new].weight;
|
|
|
|
cb(&rc_add, cbdata);
|
|
|
|
idx_new++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decompose multipath cmd info @rc into a list of add/del/change
|
|
|
|
* single-path operations, calling @cb callback for each operation.
|
|
|
|
* Assumes at least one of the nexthops in @rc is multipath.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb,
|
|
|
|
void *cbdata)
|
|
|
|
{
|
|
|
|
struct weightened_nhop *wn;
|
|
|
|
uint32_t num_nhops;
|
|
|
|
struct rib_cmd_info rc_new;
|
|
|
|
|
|
|
|
rc_new = *rc;
|
|
|
|
DPRINTF("cb=%p cmd=%d nh_old=%p nh_new=%p",
|
|
|
|
cb, rc->cmd, rc->nh_old, rc->nh_new);
|
|
|
|
switch (rc->rc_cmd) {
|
|
|
|
case RTM_ADD:
|
|
|
|
if (!NH_IS_NHGRP(rc->rc_nh_new))
|
|
|
|
return;
|
|
|
|
wn = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_new, &num_nhops);
|
|
|
|
for (uint32_t i = 0; i < num_nhops; i++) {
|
|
|
|
rc_new.rc_nh_new = wn[i].nh;
|
|
|
|
rc_new.rc_nh_weight = wn[i].weight;
|
|
|
|
cb(&rc_new, cbdata);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RTM_DELETE:
|
|
|
|
if (!NH_IS_NHGRP(rc->rc_nh_old))
|
|
|
|
return;
|
|
|
|
wn = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_old, &num_nhops);
|
|
|
|
for (uint32_t i = 0; i < num_nhops; i++) {
|
|
|
|
rc_new.rc_nh_old = wn[i].nh;
|
|
|
|
rc_new.rc_nh_weight = wn[i].weight;
|
|
|
|
cb(&rc_new, cbdata);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RTM_CHANGE:
|
|
|
|
if (!NH_IS_NHGRP(rc->rc_nh_old) && !NH_IS_NHGRP(rc->rc_nh_new))
|
|
|
|
return;
|
|
|
|
decompose_change_notification(rc, cb, cbdata);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|