Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/route_fib.h
- This file was added.
/*- | |||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
* | |||||
* Copyright (c) 2023 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. | |||||
* | |||||
* $FreeBSD$ | |||||
*/ | |||||
/* | |||||
* This header file contains public functions and structures used for | |||||
* the datapath. | |||||
*/ | |||||
#ifndef _NET_ROUTE_ROUTE_FIB_H_ | |||||
#define _NET_ROUTE_ROUTE_FIB_H_ | |||||
#ifdef _KERNEL | |||||
#include <net/vnet.h> | |||||
/* | |||||
* Keep a generation count of routing table, incremented on route addition, | |||||
* so we can invalidate caches. This is accessed without a lock, as precision | |||||
* is not required. | |||||
*/ | |||||
typedef volatile u_int rt_gen_t; /* tree generation (for adds) */ | |||||
#define RT_GEN(fibnum, af) rt_tables_get_gen(fibnum, af) | |||||
/* | |||||
* Struct route consiste of a destination address, | |||||
* a route entry pointer, link-layer prepend data pointer along | |||||
* with its length. | |||||
*/ | |||||
struct route { | |||||
struct nhop_object *ro_nh; | |||||
struct llentry *ro_lle; | |||||
/* | |||||
* ro_prepend and ro_plen are only used for bpf to pass in a | |||||
* preformed header. They are not cacheable. | |||||
*/ | |||||
char *ro_prepend; | |||||
uint16_t ro_plen; | |||||
uint16_t ro_flags; | |||||
uint16_t ro_mtu; /* saved ro_rt mtu */ | |||||
uint16_t spare; | |||||
struct sockaddr ro_dst; | |||||
}; | |||||
#define RT_L2_ME_BIT 2 /* dst L2 addr is our address */ | |||||
#define RT_MAY_LOOP_BIT 3 /* dst may require loop copy */ | |||||
#define RT_HAS_HEADER_BIT 4 /* mbuf already have its header prepended */ | |||||
#define RT_L2_ME (1 << RT_L2_ME_BIT) /* 0x0004 */ | |||||
#define RT_MAY_LOOP (1 << RT_MAY_LOOP_BIT) /* 0x0008 */ | |||||
#define RT_HAS_HEADER (1 << RT_HAS_HEADER_BIT) /* 0x0010 */ | |||||
#define RT_REJECT 0x0020 /* Destination is reject */ | |||||
#define RT_BLACKHOLE 0x0040 /* Destination is blackhole */ | |||||
#define RT_HAS_GW 0x0080 /* Destination has GW */ | |||||
#define RT_LLE_CACHE 0x0100 /* Cache link layer */ | |||||
/* Calculate flowid for locally-originated packets */ | |||||
#define V_fib_hash_outbound VNET(fib_hash_outbound) | |||||
VNET_DECLARE(u_int, fib_hash_outbound); | |||||
/* Outbound flowid generation rules */ | |||||
#ifdef RSS | |||||
#define fib4_calc_packet_hash xps_proto_software_hash_v4 | |||||
#define fib6_calc_packet_hash xps_proto_software_hash_v6 | |||||
#define CALC_FLOWID_OUTBOUND_SENDTO true | |||||
#ifdef ROUTE_MPATH | |||||
#define CALC_FLOWID_OUTBOUND V_fib_hash_outbound | |||||
#else | |||||
#define CALC_FLOWID_OUTBOUND false | |||||
#endif | |||||
#else /* !RSS */ | |||||
#define fib4_calc_packet_hash fib4_calc_software_hash | |||||
#define fib6_calc_packet_hash fib6_calc_software_hash | |||||
#ifdef ROUTE_MPATH | |||||
#define CALC_FLOWID_OUTBOUND_SENDTO V_fib_hash_outbound | |||||
#define CALC_FLOWID_OUTBOUND V_fib_hash_outbound | |||||
#else | |||||
#define CALC_FLOWID_OUTBOUND_SENDTO false | |||||
#define CALC_FLOWID_OUTBOUND false | |||||
#endif | |||||
#endif /* RSS */ | |||||
#endif /* _KERNEL */ | |||||
#define RT_LINK_IS_UP(ifp) (!((ifp)->if_capabilities & IFCAP_LINKSTATE) \ | |||||
|| (ifp)->if_link_state == LINK_STATE_UP) | |||||
#define RO_NHFREE(_ro) do { \ | |||||
if ((_ro)->ro_nh) { \ | |||||
NH_FREE((_ro)->ro_nh); \ | |||||
(_ro)->ro_nh = NULL; \ | |||||
} \ | |||||
} while (0) | |||||
#define RO_INVALIDATE_CACHE(ro) do { \ | |||||
if ((ro)->ro_lle != NULL) { \ | |||||
LLE_FREE((ro)->ro_lle); \ | |||||
(ro)->ro_lle = NULL; \ | |||||
} \ | |||||
if ((ro)->ro_nh != NULL) { \ | |||||
NH_FREE((ro)->ro_nh); \ | |||||
(ro)->ro_nh = NULL; \ | |||||
} \ | |||||
} while (0) | |||||
#define RO_GET_FAMILY(ro, dst) ((ro) != NULL && \ | |||||
(ro)->ro_flags & RT_HAS_GW \ | |||||
? (ro)->ro_dst.sa_family : (dst)->sa_family) | |||||
/* | |||||
* Validate a cached route based on a supplied cookie. If there is an | |||||
* out-of-date cache, simply free it. Update the generation number | |||||
* for the new allocation | |||||
*/ | |||||
#define NH_VALIDATE(ro, cookiep, fibnum) do { \ | |||||
rt_gen_t cookie = RT_GEN(fibnum, (ro)->ro_dst.sa_family); \ | |||||
if (*(cookiep) != cookie) { \ | |||||
RO_INVALIDATE_CACHE(ro); \ | |||||
*(cookiep) = cookie; \ | |||||
} \ | |||||
} while (0) | |||||
VNET_DECLARE(uint32_t, _rt_numfibs); /* number of existing route tables */ | |||||
#define V_rt_numfibs VNET(_rt_numfibs) | |||||
/* temporary compat arg */ | |||||
#define rt_numfibs V_rt_numfibs | |||||
#endif |