Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/nhgrp_ctl.c
Show First 20 Lines • Show All 611 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Creates new nexthop group based on @src group without the nexthops | * Creates new nexthop group based on @src group without the nexthops | ||||
* chosen by @flt_func. | * chosen by @flt_func. | ||||
* Returns 0 on success, storring the reference nhop group/object in @rnd. | * Returns 0 on success, storring the reference nhop group/object in @rnd. | ||||
*/ | */ | ||||
int | int | ||||
nhgrp_get_filtered_group(struct rib_head *rh, const struct nhgrp_object *src, | nhgrp_get_filtered_group(struct rib_head *rh, const struct rtentry *rt, | ||||
nhgrp_filter_cb_t flt_func, void *flt_data, struct route_nhop_data *rnd) | const struct nhgrp_object *src, rib_filter_f_t flt_func, void *flt_data, | ||||
struct route_nhop_data *rnd) | |||||
{ | { | ||||
char storage[64]; | char storage[64]; | ||||
struct nh_control *ctl = rh->nh_control; | struct nh_control *ctl = rh->nh_control; | ||||
struct weightened_nhop *pnhops; | struct weightened_nhop *pnhops; | ||||
const struct nhgrp_priv *mp_priv, *src_priv; | const struct nhgrp_priv *mp_priv, *src_priv; | ||||
size_t sz; | size_t sz; | ||||
int error, i, num_nhops; | int error, i, num_nhops; | ||||
src_priv = NHGRP_PRIV_CONST(src); | src_priv = NHGRP_PRIV_CONST(src); | ||||
sz = src_priv->nhg_nh_count * (sizeof(struct weightened_nhop)); | sz = src_priv->nhg_nh_count * (sizeof(struct weightened_nhop)); | ||||
/* optimize for <= 4 paths, each path=16 bytes */ | /* optimize for <= 4 paths, each path=16 bytes */ | ||||
if (sz <= sizeof(storage)) | if (sz <= sizeof(storage)) | ||||
pnhops = (struct weightened_nhop *)&storage[0]; | pnhops = (struct weightened_nhop *)&storage[0]; | ||||
else { | else { | ||||
if ((pnhops = malloc(sz, M_TEMP, M_NOWAIT)) == NULL) | if ((pnhops = malloc(sz, M_TEMP, M_NOWAIT)) == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
/* Filter nexthops */ | /* Filter nexthops */ | ||||
error = 0; | error = 0; | ||||
num_nhops = 0; | num_nhops = 0; | ||||
for (i = 0; i < src_priv->nhg_nh_count; i++) { | for (i = 0; i < src_priv->nhg_nh_count; i++) { | ||||
if (flt_func(src_priv->nhg_nh_weights[i].nh, flt_data)) | if (flt_func(rt, src_priv->nhg_nh_weights[i].nh, flt_data)) | ||||
continue; | continue; | ||||
memcpy(&pnhops[num_nhops++], &src_priv->nhg_nh_weights[i], | memcpy(&pnhops[num_nhops++], &src_priv->nhg_nh_weights[i], | ||||
sizeof(struct weightened_nhop)); | sizeof(struct weightened_nhop)); | ||||
} | } | ||||
if (num_nhops == 0) { | if (num_nhops == 0) { | ||||
rnd->rnd_nhgrp = NULL; | rnd->rnd_nhgrp = NULL; | ||||
rnd->rnd_weight = 0; | rnd->rnd_weight = 0; | ||||
▲ Show 20 Lines • Show All 238 Lines • Show Last 20 Lines |