Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/route_helpers.c
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
#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_var.h> | #include <net/route/route_var.h> | ||||
#include <net/route/nhop_utils.h> | #include <net/route/nhop_utils.h> | ||||
#include <net/route/nhop.h> | #include <net/route/nhop.h> | ||||
#include <net/route/nhop_var.h> | #include <net/route/nhop_var.h> | ||||
#include <net/route/shared.h> | #include <net/route/shared.h> | ||||
#ifdef INET | |||||
#include <netinet/in_fib.h> | |||||
#endif | |||||
#ifdef INET6 | |||||
#include <netinet6/in6_fib.h> | |||||
#endif | |||||
#include <net/vnet.h> | #include <net/vnet.h> | ||||
/* | /* | ||||
* RIB helper functions. | * RIB helper functions. | ||||
*/ | */ | ||||
/* | /* | ||||
* Calls @wa_f with @arg for each entry in the table specified by | * Calls @wa_f with @arg for each entry in the table specified by | ||||
* @af and @fibnum. | * @af and @fibnum. | ||||
* | * | ||||
* Table is traversed under read lock. | * Table is traversed under read lock. | ||||
*/ | */ | ||||
void | void | ||||
rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, void *arg) | rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, void *arg) | ||||
{ | { | ||||
RIB_RLOCK_TRACKER; | RIB_RLOCK_TRACKER; | ||||
struct rib_head *rnh; | struct rib_head *rnh; | ||||
if ((rnh = rt_tables_get_rnh(fibnum, af)) == NULL) | if ((rnh = rt_tables_get_rnh(fibnum, af)) == NULL) | ||||
return; | return; | ||||
RIB_RLOCK(rnh); | RIB_RLOCK(rnh); | ||||
rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f, arg); | rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f, arg); | ||||
RIB_RUNLOCK(rnh); | RIB_RUNLOCK(rnh); | ||||
} | |||||
/* | |||||
* 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 | |||||
ae: We usually don't use tab after #ifdef, only after #define. | |||||
case AF_INET: | |||||
{ | |||||
const struct sockaddr_in *a = (const struct sockaddr_in *)&dst; | |||||
aeUnsubmitted Done Inline ActionsIt seems & is not needed here. ae: It seems & is not needed here. | |||||
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; | |||||
aeUnsubmitted Done Inline ActionsThe same. ae: The same. | |||||
nh = fib6_lookup(fibnum, &a->sin6_addr, a->sin6_scope_id, | |||||
flags, flowid); | |||||
break; | |||||
} | |||||
#endif | |||||
} | |||||
return (nh); | |||||
} | } | ||||
We usually don't use tab after #ifdef, only after #define.