Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet6/in6_fib.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/if_var.h> | #include <net/if_var.h> | ||||
#include <net/if_dl.h> | #include <net/if_dl.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <net/route/route_ctl.h> | #include <net/route/route_ctl.h> | ||||
#include <net/route/route_var.h> | #include <net/route/route_var.h> | ||||
#include <net/route/route_algo.h> | |||||
#include <net/route/nhop.h> | #include <net/route/nhop.h> | ||||
#include <net/toeplitz.h> | #include <net/toeplitz.h> | ||||
#include <net/vnet.h> | #include <net/vnet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet/in_var.h> | #include <netinet/in_var.h> | ||||
#include <netinet/ip_mroute.h> | #include <netinet/ip_mroute.h> | ||||
#include <netinet/ip6.h> | #include <netinet/ip6.h> | ||||
#include <netinet6/in6_fib.h> | #include <netinet6/in6_fib.h> | ||||
#include <netinet6/in6_var.h> | #include <netinet6/in6_var.h> | ||||
#include <netinet6/nd6.h> | #include <netinet6/nd6.h> | ||||
#include <netinet6/scope6_var.h> | #include <netinet6/scope6_var.h> | ||||
#include <net/if_types.h> | #include <net/if_types.h> | ||||
#ifdef INET6 | #ifdef INET6 | ||||
CHK_STRUCT_ROUTE_COMPAT(struct route_in6, ro_dst); | CHK_STRUCT_ROUTE_COMPAT(struct route_in6, ro_dst); | ||||
#ifdef ROUTE_ALGO | |||||
VNET_DEFINE(struct fib_dp *, inet6_dp); | |||||
#endif | |||||
#ifdef ROUTE_MPATH | #ifdef ROUTE_MPATH | ||||
struct _hash_5tuple_ipv6 { | struct _hash_5tuple_ipv6 { | ||||
struct in6_addr src; | struct in6_addr src; | ||||
struct in6_addr dst; | struct in6_addr dst; | ||||
unsigned short src_port; | unsigned short src_port; | ||||
unsigned short dst_port; | unsigned short dst_port; | ||||
char proto; | char proto; | ||||
char spare[3]; | char spare[3]; | ||||
Show All 26 Lines | |||||
* Looks up path in fib @fibnum specified by @dst. | * Looks up path in fib @fibnum specified by @dst. | ||||
* Assumes scope is deembedded and provided in @scopeid. | * Assumes scope is deembedded and provided in @scopeid. | ||||
* | * | ||||
* Returns path nexthop on success. Nexthop is safe to use | * Returns path nexthop on success. Nexthop is safe to use | ||||
* within the current network epoch. If longer lifetime is required, | * within the current network epoch. If longer lifetime is required, | ||||
* one needs to pass NHR_REF as a flag. This will return referenced | * one needs to pass NHR_REF as a flag. This will return referenced | ||||
* nexthop. | * nexthop. | ||||
*/ | */ | ||||
#ifdef ROUTE_ALGO | |||||
struct nhop_object * | struct nhop_object * | ||||
fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6, | fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6, | ||||
uint32_t scopeid, uint32_t flags, uint32_t flowid) | uint32_t scopeid, uint32_t flags, uint32_t flowid) | ||||
{ | { | ||||
struct nhop_object *nh; | |||||
struct fib_dp *dp = &V_inet6_dp[fibnum]; | |||||
struct flm_lookup_key key = {.addr6 = dst6 }; | |||||
nh = dp->f(dp->arg, key, scopeid); | |||||
if (nh != NULL) { | |||||
nh = nhop_select(nh, flowid); | |||||
/* Ensure route & ifp is UP */ | |||||
if (RT_LINK_IS_UP(nh->nh_ifp)) { | |||||
if (flags & NHR_REF) | |||||
nhop_ref_object(nh); | |||||
return (nh); | |||||
} | |||||
} | |||||
RTSTAT_INC(rts_unreach); | |||||
return (NULL); | |||||
} | |||||
#else | |||||
struct nhop_object * | |||||
fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6, | |||||
uint32_t scopeid, uint32_t flags, uint32_t flowid) | |||||
{ | |||||
RIB_RLOCK_TRACKER; | RIB_RLOCK_TRACKER; | ||||
struct rib_head *rh; | struct rib_head *rh; | ||||
struct radix_node *rn; | struct radix_node *rn; | ||||
struct nhop_object *nh; | struct nhop_object *nh; | ||||
KASSERT((fibnum < rt_numfibs), ("fib6_lookup: bad fibnum")); | KASSERT((fibnum < rt_numfibs), ("fib6_lookup: bad fibnum")); | ||||
rh = rt_tables_get_rnh(fibnum, AF_INET6); | rh = rt_tables_get_rnh(fibnum, AF_INET6); | ||||
if (rh == NULL) | if (rh == NULL) | ||||
Show All 20 Lines | if (RT_LINK_IS_UP(nh->nh_ifp)) { | ||||
return (nh); | return (nh); | ||||
} | } | ||||
} | } | ||||
RIB_RUNLOCK(rh); | RIB_RUNLOCK(rh); | ||||
RTSTAT_INC(rts_unreach); | RTSTAT_INC(rts_unreach); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
#endif | |||||
inline static int | inline static int | ||||
check_urpf_nhop(const struct nhop_object *nh, uint32_t flags, | check_urpf_nhop(const struct nhop_object *nh, uint32_t flags, | ||||
const struct ifnet *src_if) | const struct ifnet *src_if) | ||||
{ | { | ||||
if (src_if != NULL && nh->nh_aifp == src_if) { | if (src_if != NULL && nh->nh_aifp == src_if) { | ||||
return (1); | return (1); | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Returns 1 if route matching conditions is found, 0 otherwise. | * Returns 1 if route matching conditions is found, 0 otherwise. | ||||
*/ | */ | ||||
int | int | ||||
fib6_check_urpf(uint32_t fibnum, const struct in6_addr *dst6, | fib6_check_urpf(uint32_t fibnum, const struct in6_addr *dst6, | ||||
uint32_t scopeid, uint32_t flags, const struct ifnet *src_if) | uint32_t scopeid, uint32_t flags, const struct ifnet *src_if) | ||||
{ | { | ||||
struct nhop_object *nh; | struct nhop_object *nh; | ||||
#ifndef ROUTE_ALGO | |||||
struct fib_dp *dp = &V_inet6_dp[fibnum]; | |||||
struct flm_lookup_key key = {.addr6 = dst6 }; | |||||
nh = dp->f(dp->arg, key, scopeid); | |||||
#else | |||||
nh = lookup_nhop(fibnum, dst6, scopeid); | nh = lookup_nhop(fibnum, dst6, scopeid); | ||||
#endif | |||||
if (nh != NULL) | if (nh != NULL) | ||||
return (check_urpf(nh, flags, src_if)); | return (check_urpf(nh, flags, src_if)); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Function returning prefix match data along with the nexthop data. | * Function returning prefix match data along with the nexthop data. | ||||
* Intended to be used by the control plane code. | * Intended to be used by the control plane code. | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |