@@ -399,7 +399,7 @@ UrlRewrite::ReverseMap(HTTPHdr *response_header)
399399void
400400UrlRewrite::PerformACLFiltering (HttpTransact::State *s, url_mapping *map)
401401{
402- if (unlikely (!s || s->acl_filtering_performed || !s->client_connection_enabled )) {
402+ if (unlikely (!s || s->acl_filtering_performed || !s->client_connection_allowed )) {
403403 return ;
404404 }
405405
@@ -411,43 +411,50 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, url_mapping *map)
411411
412412 ink_release_assert (ats_is_ip (&s->client_info .src_addr ));
413413
414- s->client_connection_enabled = true ; // Default is that we allow things unless some filter matches
414+ s->client_connection_allowed = true ; // Default is that we allow things unless some filter matches
415415
416- for (acl_filter_rule *rp = map->filter ; rp; rp = rp->next ) {
417- bool match = true ;
416+ int rule_index = 0 ;
417+ for (acl_filter_rule *rp = map->filter ; rp; rp = rp->next , ++rule_index) {
418+ bool method_matches = true ;
418419
419420 if (rp->method_restriction_enabled ) {
420421 if (method_wksidx >= 0 && method_wksidx < HTTP_WKSIDX_METHODS_CNT) {
421- match = rp->standard_method_lookup [method_wksidx];
422+ method_matches = rp->standard_method_lookup [method_wksidx];
422423 } else if (!rp->nonstandard_methods .empty ()) {
423- match = false ;
424+ method_matches = false ;
424425 } else {
425426 int method_str_len;
426427 const char *method_str = s->hdr_info .client_request .method_get (&method_str_len);
427- match = rp->nonstandard_methods .count (std::string (method_str, method_str_len));
428+ method_matches = rp->nonstandard_methods .count (std::string (method_str, method_str_len));
428429 }
430+ } else {
431+ // No method specified, therefore all match.
432+ method_matches = true ;
429433 }
430434
431- if (match && rp->src_ip_valid ) {
432- match = false ;
433- for (int j = 0 ; j < rp->src_ip_cnt && !match; j++) {
435+ // Is there a @src_ip specified? If so, check it.
436+ bool ip_matches = false ;
437+ if (rp->src_ip_valid ) {
438+ ip_matches = false ;
439+ for (int j = 0 ; j < rp->src_ip_cnt && !ip_matches; j++) {
434440 bool in_range = rp->src_ip_array [j].contains (s->client_info .src_addr );
435441 if (rp->src_ip_array [j].invert ) {
436442 if (!in_range) {
437- match = true ;
443+ ip_matches = true ;
438444 }
439445 } else {
440446 if (in_range) {
441- match = true ;
447+ ip_matches = true ;
442448 }
443449 }
444450 }
445451 }
446452
447- if (match && rp->in_ip_valid ) {
448- Debug (" url_rewrite" , " match was true and we have specified a in_ip field" );
449- match = false ;
450- for (int j = 0 ; j < rp->in_ip_cnt && !match; j++) {
453+ // Is there an @in_ip specified? If so, check it.
454+ if (ip_matches && rp->in_ip_valid ) {
455+ Debug (" url_rewrite" , " src_ip match was true, checking the specified in_ip range." );
456+ ip_matches = false ;
457+ for (int j = 0 ; j < rp->in_ip_cnt && !ip_matches; j++) {
451458 IpEndpoint incoming_addr;
452459 incoming_addr.assign (s->state_machine ->get_ua_txn ()->get_netvc ()->get_local_addr ());
453460 if (is_debug_tag_set (" url_rewrite" )) {
@@ -460,28 +467,36 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, url_mapping *map)
460467 bool in_range = rp->in_ip_array [j].contains (incoming_addr);
461468 if (rp->in_ip_array [j].invert ) {
462469 if (!in_range) {
463- match = true ;
470+ ip_matches = true ;
464471 }
465472 } else {
466473 if (in_range) {
467- match = true ;
474+ ip_matches = true ;
468475 }
469476 }
470477 }
471478 }
472479
473480 if (rp->internal ) {
474- match = s->state_machine ->get_ua_txn ()->get_netvc ()->get_is_internal_request ();
475- Debug (" url_rewrite" , " %s an internal request" , match ? " matched" : " didn't match" );
481+ ip_matches = s->state_machine ->get_ua_txn ()->get_netvc ()->get_is_internal_request ();
482+ Debug (" url_rewrite" , " %s an internal request" , ip_matches ? " matched" : " didn't match" );
476483 }
477484
478- if (match) {
479- // We have a match, stop evaluating filters
480- Debug (" url_rewrite" , " matched ACL filter rule, %s request" , rp->allow_flag ? " allowing" : " denying" );
481- s->client_connection_enabled = rp->allow_flag ;
485+ Debug (" url_rewrite" , " %d: ACL filter %s rule matches by ip: %s, by method: %s" , rule_index,
486+ (rp->allow_flag ? " allow" : " deny" ), (ip_matches ? " true" : " false" ), (method_matches ? " true" : " false" ));
487+
488+ if (ip_matches) {
489+ // The rule matches. Handle the method according to the rule.
490+ if (method_matches) {
491+ // Did they specify allowing the listed methods, or denying them?
492+ Debug (" url_rewrite" , " matched ACL filter rule, %s request" , rp->allow_flag ? " allowing" : " denying" );
493+ s->client_connection_allowed = rp->allow_flag ;
494+ } else {
495+ Debug (" url_rewrite" , " ACL rule matched on IP but not on method, action: %s, %s the request" ,
496+ (rp->allow_flag ? " allow" : " deny" ), (rp->allow_flag ? " denying" : " allowing" ));
497+ s->client_connection_allowed = !rp->allow_flag ;
498+ }
482499 break ;
483- } else {
484- Debug (" url_rewrite" , " did NOT match ACL filter rule, %s request" , rp->allow_flag ? " denying" : " allowing" );
485500 }
486501 }
487502 } /* end of for(rp = map->filter;rp;rp = rp->next) */
0 commit comments