Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/in_fib.c
Show First 20 Lines • Show All 43 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/in_fib.h> | #include <netinet/in_fib.h> | ||||
#ifdef INET | #ifdef INET | ||||
/* Verify struct route compatiblity */ | /* Verify struct route compatiblity */ | ||||
/* Assert 'struct route_in' is compatible with 'struct route' */ | /* Assert 'struct route_in' is compatible with 'struct route' */ | ||||
CHK_STRUCT_ROUTE_COMPAT(struct route_in, ro_dst4); | CHK_STRUCT_ROUTE_COMPAT(struct route_in, ro_dst4); | ||||
#ifdef ROUTE_ALGO | |||||
VNET_DEFINE(struct fib_dp *, inet_dp); | |||||
#endif | |||||
#ifdef ROUTE_MPATH | #ifdef ROUTE_MPATH | ||||
struct _hash_5tuple_ipv4 { | struct _hash_5tuple_ipv4 { | ||||
struct in_addr src; | struct in_addr src; | ||||
struct in_addr dst; | struct in_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 24 Lines | |||||
/* | /* | ||||
* Looks up path in fib @fibnum specified by @dst. | * Looks up path in fib @fibnum specified by @dst. | ||||
* 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 * | ||||
fib4_lookup(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, | fib4_lookup(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, | ||||
uint32_t flags, uint32_t flowid) | uint32_t flags, uint32_t flowid) | ||||
{ | { | ||||
struct nhop_object *nh; | |||||
struct fib_dp *dp = &V_inet_dp[fibnum]; | |||||
struct flm_lookup_key key = {.addr4 = dst }; | |||||
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 * | |||||
fib4_lookup(uint32_t fibnum, struct in_addr dst, 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), ("fib4_lookup: bad fibnum")); | KASSERT((fibnum < rt_numfibs), ("fib4_lookup: bad fibnum")); | ||||
rh = rt_tables_get_rnh(fibnum, AF_INET); | rh = rt_tables_get_rnh(fibnum, AF_INET); | ||||
if (rh == NULL) | if (rh == NULL) | ||||
Show All 19 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 All 22 Lines | wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops); | ||||
return (1); | return (1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} else | } else | ||||
#endif | #endif | ||||
return (check_urpf_nhop(nh, flags, src_if)); | return (check_urpf_nhop(nh, flags, src_if)); | ||||
} | } | ||||
#ifndef ROUTE_ALGO | |||||
static struct nhop_object * | static struct nhop_object * | ||||
lookup_nhop(uint32_t fibnum, struct in_addr dst, uint32_t scopeid) | lookup_nhop(uint32_t fibnum, struct in_addr dst, uint32_t scopeid) | ||||
{ | { | ||||
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; | ||||
Show All 12 Lines | lookup_nhop(uint32_t fibnum, struct in_addr dst, uint32_t scopeid) | ||||
RIB_RLOCK(rh); | RIB_RLOCK(rh); | ||||
rn = rh->rnh_matchaddr((void *)&sin4, &rh->head); | rn = rh->rnh_matchaddr((void *)&sin4, &rh->head); | ||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) | if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) | ||||
nh = RNTORT(rn)->rt_nhop; | nh = RNTORT(rn)->rt_nhop; | ||||
RIB_RUNLOCK(rh); | RIB_RUNLOCK(rh); | ||||
return (nh); | return (nh); | ||||
} | } | ||||
#endif | |||||
/* | /* | ||||
* Performs reverse path forwarding lookup. | * Performs reverse path forwarding lookup. | ||||
* If @src_if is non-zero, verifies that at least 1 path goes via | * If @src_if is non-zero, verifies that at least 1 path goes via | ||||
* this interface. | * this interface. | ||||
* If @src_if is zero, verifies that route exist. | * If @src_if is zero, verifies that route exist. | ||||
* if @flags contains NHR_NOTDEFAULT, do not consider default route. | * if @flags contains NHR_NOTDEFAULT, do not consider default route. | ||||
* | * | ||||
* Returns 1 if route matching conditions is found, 0 otherwise. | * Returns 1 if route matching conditions is found, 0 otherwise. | ||||
*/ | */ | ||||
int | int | ||||
fib4_check_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, | fib4_check_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, | ||||
uint32_t flags, const struct ifnet *src_if) | uint32_t flags, const struct ifnet *src_if) | ||||
{ | { | ||||
struct nhop_object *nh; | struct nhop_object *nh; | ||||
#ifdef ROUTE_ALGO | |||||
struct fib_dp *dp = &V_inet_dp[fibnum]; | |||||
struct flm_lookup_key key = {.addr4 = dst }; | |||||
nh = dp->f(dp->arg, key, scopeid); | |||||
#else | |||||
nh = lookup_nhop(fibnum, dst, scopeid); | nh = lookup_nhop(fibnum, dst, 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. | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |