Skip to content

Commit 3c7066b

Browse files
committed
correct route matching, dispatch, and purge logic
1 parent 2271ffa commit 3c7066b

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/addr_families.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ WOLFSENTRY_LOCAL wolfsentry_errcode_t wolfsentry_addr_family_clone(
324324
if ((*new_bynumber = (struct wolfsentry_addr_family_bynumber *)WOLFSENTRY_MALLOC_1(dest_context->hpi.allocator, sizeof **new_bynumber)) == NULL)
325325
WOLFSENTRY_ERROR_RETURN(SYS_RESOURCE_FAILED);
326326
if ((*new_byname = (struct wolfsentry_addr_family_byname *)WOLFSENTRY_MALLOC_1(dest_context->hpi.allocator, byname_size)) == NULL) {
327-
(void)WOLFSENTRY_FREE_1(dest_context->hpi.allocator, (void *)new_byname);
327+
(void)WOLFSENTRY_FREE_1(dest_context->hpi.allocator, (void *)*new_bynumber);
328328
WOLFSENTRY_ERROR_RETURN(SYS_RESOURCE_FAILED);
329329
}
330330
memcpy(*new_bynumber, src_bynumber, sizeof **new_bynumber);

src/routes.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static int compare_match_exactness(const struct wolfsentry_route *target, const
520520
} else
521521
#endif
522522
{
523-
right_match_score = addr_prefix_match_size(WOLFSENTRY_ROUTE_LOCAL_ADDR(target), WOLFSENTRY_ROUTE_LOCAL_ADDR_BITS(target), WOLFSENTRY_ROUTE_LOCAL_ADDR(right), WOLFSENTRY_ROUTE_LOCAL_ADDR_BITS(right));
523+
right_match_score = addr_prefix_match_size(WOLFSENTRY_ROUTE_REMOTE_ADDR(target), WOLFSENTRY_ROUTE_REMOTE_ADDR_BITS(target), WOLFSENTRY_ROUTE_REMOTE_ADDR(right), WOLFSENTRY_ROUTE_REMOTE_ADDR_BITS(right));
524524
}
525525
}
526526

@@ -2562,9 +2562,11 @@ static wolfsentry_errcode_t wolfsentry_route_event_dispatch_0(
25622562
(WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
25632563
>= config->config.derogatory_threshold_for_penaltybox)
25642564
:
2565-
(WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
2566-
- WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.commendable_count)
2567-
>= (int)config->config.derogatory_threshold_for_penaltybox)))
2565+
((WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
2566+
>= WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.commendable_count))
2567+
&& ((wolfsentry_hitcount_t)(WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
2568+
- WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.commendable_count))
2569+
>= config->config.derogatory_threshold_for_penaltybox))))
25682570
{
25692571
wolfsentry_route_flags_t flags_before;
25702572
WOLFSENTRY_WARN_ON_FAILURE(
@@ -2961,6 +2963,10 @@ static wolfsentry_errcode_t wolfsentry_route_event_dispatch_by_route_1(
29612963
WOLFSENTRY_ERROR_UNLOCK_AND_RERETURN(ret);
29622964
}
29632965

2966+
if (route->header.parent_table == NULL) {
2967+
ret = WOLFSENTRY_ERROR_ENCODE(INTERNAL_CHECK_FATAL);
2968+
goto out;
2969+
}
29642970
if (route->header.parent_table->ent_type != WOLFSENTRY_OBJECT_TYPE_ROUTE) {
29652971
ret = WOLFSENTRY_ERROR_ENCODE(WRONG_OBJECT);
29662972
goto out;
@@ -3095,7 +3101,7 @@ static wolfsentry_errcode_t wolfsentry_route_stale_purge_1(
30953101
(! (route->flags & WOLFSENTRY_ROUTE_FLAG_PENDING_DELETE)) &&
30963102
((table->max_purgeable_idle_time == 0) || (now - route->meta.last_hit_time > table->max_purgeable_idle_time)))
30973103
{
3098-
continue;
3104+
break;
30993105
}
31003106
}
31013107
#ifdef WOLFSENTRY_THREADSAFE

0 commit comments

Comments
 (0)