Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/route_temporal.c
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Callback returning 1 for the expired routes. | * Callback returning 1 for the expired routes. | ||||
* Updates time of the next nearest route expiration as a side effect. | * Updates time of the next nearest route expiration as a side effect. | ||||
*/ | */ | ||||
static int | static int | ||||
expire_route(const struct rtentry *rt, const struct nhop_object *nh, void *arg) | expire_route(const struct rtentry *rt, const struct nhop_object *nh, void *arg) | ||||
{ | { | ||||
uint32_t nh_expire = nhop_get_expire(nh); | |||||
time_t *next_callout; | time_t *next_callout; | ||||
if (rt->rt_expire == 0) | if (nh_expire == 0) | ||||
return (0); | return (0); | ||||
if (rt->rt_expire <= time_uptime) | if (nh_expire <= time_uptime) | ||||
return (1); | return (1); | ||||
next_callout = (time_t *)arg; | next_callout = (time_t *)arg; | ||||
/* | /* | ||||
* Update next_callout to determine the next ts to | * Update next_callout to determine the next ts to | ||||
* run the callback at. | * run the callback at. | ||||
*/ | */ | ||||
if (*next_callout == 0 || *next_callout > rt->rt_expire) | if (*next_callout == 0 || *next_callout > nh_expire) | ||||
*next_callout = rt->rt_expire; | *next_callout = nh_expire; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Per-rnh callout function traversing the tree and deleting | * Per-rnh callout function traversing the tree and deleting | ||||
* expired routes. Calculates next callout run by looking at | * expired routes. Calculates next callout run by looking at | ||||
* the rt_expire time for the remaining temporal routes. | * the nh_expire time for the remaining temporal routes. | ||||
*/ | */ | ||||
static void | static void | ||||
expire_callout(void *arg) | expire_callout(void *arg) | ||||
{ | { | ||||
struct rib_head *rnh; | struct rib_head *rnh; | ||||
time_t next_expire; | time_t next_expire; | ||||
int seconds; | int seconds; | ||||
Show All 28 Lines | |||||
/* | /* | ||||
* Function responsible for updating the time of the next calllout | * Function responsible for updating the time of the next calllout | ||||
* w.r.t. new temporal routes insertion. | * w.r.t. new temporal routes insertion. | ||||
* | * | ||||
* Called by the routing code upon adding new temporal route | * Called by the routing code upon adding new temporal route | ||||
* to the tree. RIB_WLOCK must be held. | * to the tree. RIB_WLOCK must be held. | ||||
*/ | */ | ||||
void | void | ||||
tmproutes_update(struct rib_head *rnh, struct rtentry *rt) | tmproutes_update(struct rib_head *rnh, struct rtentry *rt, struct nhop_object *nh) | ||||
{ | { | ||||
int seconds; | int seconds; | ||||
uint32_t nh_expire = nhop_get_expire(nh); | |||||
RIB_WLOCK_ASSERT(rnh); | RIB_WLOCK_ASSERT(rnh); | ||||
if (rnh->next_expire == 0 || rnh->next_expire > rt->rt_expire) { | if (rnh->next_expire == 0 || rnh->next_expire > nh_expire) { | ||||
/* | /* | ||||
* Callback is not scheduled, is executing, | * Callback is not scheduled, is executing, | ||||
* or is scheduled for a later time than we need. | * or is scheduled for a later time than we need. | ||||
* | * | ||||
* Schedule the one for the current @rt expiration time. | * Schedule the one for the current @rt expiration time. | ||||
*/ | */ | ||||
seconds = (rt->rt_expire - time_uptime); | seconds = (nh_expire - time_uptime); | ||||
if (seconds < 0) | if (seconds < 0) | ||||
seconds = 0; | seconds = 0; | ||||
callout_reset_sbt(&rnh->expire_callout, SBT_1S * seconds, | callout_reset_sbt(&rnh->expire_callout, SBT_1S * seconds, | ||||
SBT_1MS * 500, expire_callout, rnh, 0); | SBT_1MS * 500, expire_callout, rnh, 0); | ||||
rnh->next_expire = rt->rt_expire; | rnh->next_expire = nh_expire; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
tmproutes_init(struct rib_head *rh) | tmproutes_init(struct rib_head *rh) | ||||
{ | { | ||||
callout_init(&rh->expire_callout, 1); | callout_init(&rh->expire_callout, 1); | ||||
} | } | ||||
void | void | ||||
tmproutes_destroy(struct rib_head *rh) | tmproutes_destroy(struct rib_head *rh) | ||||
{ | { | ||||
callout_drain(&rh->expire_callout); | callout_drain(&rh->expire_callout); | ||||
} | } |