@@ -583,10 +583,10 @@ static void wolfsentry_route_update_flags_1(
583583
584584static void wolfsentry_route_free_1 (
585585 WOLFSENTRY_CONTEXT_ARGS_IN ,
586- struct wolfsentry_eventconfig_internal * config ,
586+ size_t route_private_data_alignment ,
587587 struct wolfsentry_route * route )
588588{
589- if (config -> config . route_private_data_alignment == 0 )
589+ if (route_private_data_alignment == 0 )
590590 WOLFSENTRY_FREE (route );
591591 else
592592 WOLFSENTRY_FREE_ALIGNED (route );
@@ -599,6 +599,10 @@ static wolfsentry_errcode_t wolfsentry_route_drop_reference_1(
599599 wolfsentry_action_res_t * action_results )
600600{
601601 struct wolfsentry_eventconfig_internal * config = (route -> parent_event && route -> parent_event -> config ) ? route -> parent_event -> config : & wolfsentry -> config ;
602+ /* snapshot the alignment before dropping the event reference, since the
603+ * event (and its config) may be freed by the drop.
604+ */
605+ size_t route_private_data_alignment = config -> config .route_private_data_alignment ;
602606 wolfsentry_errcode_t ret ;
603607 wolfsentry_refcount_t refs_left ;
604608 if (route -> header .refcount == 0 )
@@ -612,7 +616,7 @@ static wolfsentry_errcode_t wolfsentry_route_drop_reference_1(
612616 WOLFSENTRY_RETURN_OK ;
613617 if (route -> parent_event )
614618 WOLFSENTRY_WARN_ON_FAILURE (wolfsentry_event_drop_reference (WOLFSENTRY_CONTEXT_ARGS_OUT , route -> parent_event , NULL /* action_results */ ));
615- wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , config , route );
619+ wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , route_private_data_alignment , route );
616620 if (action_results )
617621 WOLFSENTRY_SET_BITS (* action_results , WOLFSENTRY_ACTION_RES_DEALLOCATED );
618622 WOLFSENTRY_RETURN_OK ;
@@ -995,7 +999,7 @@ static wolfsentry_errcode_t wolfsentry_route_new(
995999 WOLFSENTRY_ERROR_RETURN (SYS_RESOURCE_FAILED );
9961000 ret = wolfsentry_route_init (parent_event , remote , local , flags , (int )config -> config .route_private_data_size , new_size , * new );
9971001 if (ret < 0 ) {
998- wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , config , * new );
1002+ wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , config -> config . route_private_data_alignment , * new );
9991003 * new = NULL ;
10001004 } else {
10011005 if (parent_event != NULL ) {
@@ -1054,7 +1058,7 @@ static wolfsentry_errcode_t wolfsentry_route_new_by_exports(
10541058 WOLFSENTRY_ERROR_RETURN (SYS_RESOURCE_FAILED );
10551059 ret = wolfsentry_route_init_by_exports (parent_event , route_exports , config -> config .route_private_data_size , new_size , * new );
10561060 if (ret < 0 ) {
1057- wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , config , * new );
1061+ wolfsentry_route_free_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , config -> config . route_private_data_alignment , * new );
10581062 * new = NULL ;
10591063 } else {
10601064 if (parent_event != NULL ) {
@@ -1174,7 +1178,7 @@ WOLFSENTRY_LOCAL wolfsentry_errcode_t wolfsentry_route_clone(
11741178#ifdef WOLFSENTRY_THREADSAFE
11751179 thread ,
11761180#endif
1177- config , * new_route );
1181+ config -> config . route_private_data_alignment , * new_route );
11781182 WOLFSENTRY_ERROR_RERETURN (ret );
11791183 }
11801184 WOLFSENTRY_REFCOUNT_INCREMENT ((* new_route )-> parent_event -> header .refcount , ret );
@@ -1330,7 +1334,7 @@ static wolfsentry_errcode_t wolfsentry_route_insert_1(
13301334
13311335 if (route_to_insert -> flags & WOLFSENTRY_ROUTE_FLAG_SA_FAMILY_WILDCARD ) {
13321336 if ((route_table -> last_af_wildcard_route == NULL ) ||
1333- (wolfsentry_route_key_cmp_1 (route_to_insert , route_table -> last_af_wildcard_route , 0 /* match_wildcards_p */ , NULL /* inexact_matches */ ) < 0 ))
1337+ (wolfsentry_route_key_cmp_1 (route_to_insert , route_table -> last_af_wildcard_route , 0 /* match_wildcards_p */ , NULL /* inexact_matches */ ) > 0 ))
13341338 {
13351339 route_table -> last_af_wildcard_route = route_to_insert ;
13361340 }
@@ -1987,6 +1991,9 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_table_default_policy_set(
19871991{
19881992 if (WOLFSENTRY_MASKOUT_BITS (default_policy , WOLFSENTRY_ROUTE_DEFAULT_POLICY_MASK ) != WOLFSENTRY_ACTION_RES_NONE )
19891993 WOLFSENTRY_ERROR_RETURN (INVALID_ARG );
1994+ if ((default_policy != WOLFSENTRY_ACTION_RES_NONE ) &&
1995+ (! WOLFSENTRY_MASKIN_BITS (default_policy , WOLFSENTRY_ACTION_RES_ACCEPT | WOLFSENTRY_ACTION_RES_REJECT )))
1996+ WOLFSENTRY_ERROR_RETURN (INVALID_ARG );
19901997 WOLFSENTRY_MUTEX_OR_RETURN ();
19911998 table -> default_policy = default_policy ;
19921999 if (table == wolfsentry -> routes )
@@ -2162,10 +2169,19 @@ static wolfsentry_errcode_t wolfsentry_route_delete_0(
21622169 wolfsentry_route_update_flags_1 (route , WOLFSENTRY_ROUTE_FLAG_NONE , WOLFSENTRY_ROUTE_FLAG_IN_TABLE , & flags_before , & flags_after );
21632170 }
21642171
2165- if ((ret = wolfsentry_table_ent_delete_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , & route -> header )) < 0 ) {
2166- wolfsentry_route_flags_t flags_before , flags_after ;
2167- wolfsentry_route_update_flags_1 (route , WOLFSENTRY_ROUTE_FLAG_IN_TABLE , WOLFSENTRY_ROUTE_FLAG_NONE , & flags_before , & flags_after );
2168- WOLFSENTRY_ERROR_RERETURN (ret );
2172+ /* snapshot linked-list neighbor before delete_1 nullifies prev/next. */
2173+ {
2174+ struct wolfsentry_route * prev_route = (struct wolfsentry_route * )route -> header .prev ;
2175+ if ((ret = wolfsentry_table_ent_delete_1 (WOLFSENTRY_CONTEXT_ARGS_OUT , & route -> header )) < 0 ) {
2176+ wolfsentry_route_flags_t flags_before , flags_after ;
2177+ wolfsentry_route_update_flags_1 (route , WOLFSENTRY_ROUTE_FLAG_IN_TABLE , WOLFSENTRY_ROUTE_FLAG_NONE , & flags_before , & flags_after );
2178+ WOLFSENTRY_ERROR_RERETURN (ret );
2179+ }
2180+ if (route_table -> last_af_wildcard_route == route ) {
2181+ while (prev_route && ! (prev_route -> flags & WOLFSENTRY_ROUTE_FLAG_SA_FAMILY_WILDCARD ))
2182+ prev_route = (struct wolfsentry_route * )prev_route -> header .prev ;
2183+ route_table -> last_af_wildcard_route = prev_route ;
2184+ }
21692185 }
21702186
21712187#ifdef WOLFSENTRY_ADDR_BITMASK_MATCHING
@@ -2191,9 +2207,6 @@ static wolfsentry_errcode_t wolfsentry_route_delete_0(
21912207 WOLFSENTRY_WARN ("wolfsentry_action_list_dispatch for wolfsentry_route_delete_0 returned " WOLFSENTRY_ERROR_FMT "\n" , WOLFSENTRY_ERROR_FMT_ARGS (ret ));
21922208 }
21932209
2194- if (route_table -> last_af_wildcard_route == route )
2195- route_table -> last_af_wildcard_route = (struct wolfsentry_route * )route -> header .prev ;
2196-
21972210 {
21982211 wolfsentry_priority_t effective_priority = route -> parent_event ? route -> parent_event -> priority : 0 ;
21992212 if (effective_priority == route_table -> highest_priority_route_in_table ) {
@@ -2490,7 +2503,9 @@ static wolfsentry_errcode_t wolfsentry_route_event_dispatch_0(
24902503 (void )ret ;
24912504 }
24922505
2493- if (! (current_rule_route_flags & WOLFSENTRY_ROUTE_FLAG_DONT_COUNT_CURRENT_CONNECTIONS )) {
2506+ if ((! (current_rule_route_flags & WOLFSENTRY_ROUTE_FLAG_DONT_COUNT_CURRENT_CONNECTIONS )) &&
2507+ (config -> config .max_connection_count > 0 ))
2508+ {
24942509 if (* action_results & WOLFSENTRY_ACTION_RES_CONNECT ) {
24952510 if (rule_route -> meta .connection_count >= config -> config .max_connection_count ) {
24962511 * action_results |= WOLFSENTRY_ACTION_RES_REJECT ;
@@ -3904,7 +3919,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_format_address(
39043919 WOLFSENTRY_RETURN_OK ;
39053920 }
39063921
3907- if (sa_family == WOLFSENTRY_AF_LINK ) {
3922+ if (sa_family == WOLFSENTRY_AF_LINK || sa_family == WOLFSENTRY_AF_LINK64 ) {
39083923 unsigned int i ;
39093924 if ((addr_bits >> 3 ) * 3 > (size_t )* buflen )
39103925 WOLFSENTRY_ERROR_RETURN (BUFFER_TOO_SMALL );
@@ -4431,7 +4446,7 @@ static wolfsentry_errcode_t wolfsentry_route_render_address(WOLFSENTRY_CONTEXT_A
44314446 WOLFSENTRY_RETURN_OK ;
44324447 }
44334448
4434- if (sa_family == WOLFSENTRY_AF_LINK ) {
4449+ if (sa_family == WOLFSENTRY_AF_LINK || sa_family == WOLFSENTRY_AF_LINK64 ) {
44354450 unsigned int i ;
44364451 for (i = 0 ; i < (addr_bits >> 3 ); ++ i ) {
44374452 if (fprintf (f , "%s%02x" , i ? ":" : "" , (unsigned int )addr [i ]) < 0 )
0 commit comments