@@ -460,6 +460,26 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, const url_mapping *const
460460 int method_wksidx = (method != -1 ) ? (method - HTTP_WKSIDX_CONNECT) : -1 ;
461461
462462 ink_release_assert (ats_is_ip (&s->client_info .src_addr ));
463+ const IpEndpoint *src_addr = nullptr ;
464+ const IpEndpoint *local_addr = nullptr ;
465+ const ProxyProtocol &pp_info = s->state_machine ->get_ua_txn ()->get_netvc ()->get_proxy_protocol_info ();
466+ for (int i = 0 ; i < IpAllow::Subject::MAX_SUBJECTS; ++i) {
467+ if (IpAllow::Subject::PEER == IpAllow::subjects[i]) {
468+ src_addr = &s->client_info .src_addr ;
469+ local_addr = &s->client_info .dst_addr ;
470+ break ;
471+ } else if (IpAllow::Subject::PROXY == IpAllow::subjects[i] && pp_info.version != ProxyProtocolVersion::UNDEFINED) {
472+ src_addr = &pp_info.src_addr ;
473+ local_addr = &pp_info.dst_addr ;
474+ break ;
475+ }
476+ }
477+
478+ if (src_addr == nullptr ) {
479+ // Use addresses from peer if none of the configured sources are avaialable
480+ src_addr = &s->client_info .src_addr ;
481+ local_addr = &s->client_info .dst_addr ;
482+ }
463483
464484 s->client_connection_allowed = true ; // Default is that we allow things unless some filter matches
465485
@@ -487,7 +507,7 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, const url_mapping *const
487507 if (rp->src_ip_valid ) {
488508 bool src_ip_matches = false ;
489509 for (int j = 0 ; j < rp->src_ip_cnt && !src_ip_matches; j++) {
490- bool in_range = rp->src_ip_array [j].contains (s-> client_info . src_addr );
510+ bool in_range = rp->src_ip_array [j].contains (* src_addr);
491511 if (rp->src_ip_array [j].invert ) {
492512 if (!in_range) {
493513 src_ip_matches = true ;
@@ -506,7 +526,7 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, const url_mapping *const
506526 if (ip_matches && rp->src_ip_category_valid ) {
507527 bool category_ip_matches = false ;
508528 for (int j = 0 ; j < rp->src_ip_category_cnt && !category_ip_matches; j++) {
509- bool in_category = rp->src_ip_category_array [j].contains (s-> client_info . src_addr );
529+ bool in_category = rp->src_ip_category_array [j].contains (* src_addr);
510530 if (rp->src_ip_category_array [j].invert ) {
511531 if (!in_category) {
512532 category_ip_matches = true ;
@@ -525,16 +545,14 @@ UrlRewrite::PerformACLFiltering(HttpTransact::State *s, const url_mapping *const
525545 if (ip_matches && rp->in_ip_valid ) {
526546 bool in_ip_matches = false ;
527547 for (int j = 0 ; j < rp->in_ip_cnt && !in_ip_matches; j++) {
528- IpEndpoint incoming_addr;
529- incoming_addr.assign (s->state_machine ->get_ua_txn ()->get_netvc ()->get_local_addr ());
530548 if (dbg_ctl_url_rewrite.on ()) {
531549 char buf1[128 ], buf2[128 ], buf3[128 ];
532- ats_ip_ntop (incoming_addr , buf1, sizeof (buf1));
550+ ats_ip_ntop (local_addr , buf1, sizeof (buf1));
533551 rp->in_ip_array [j].start .toString (buf2, sizeof (buf2));
534552 rp->in_ip_array [j].end .toString (buf3, sizeof (buf3));
535553 Dbg (dbg_ctl_url_rewrite, " Trying to match incoming address %s in range %s - %s." , buf1, buf2, buf3);
536554 }
537- bool in_range = rp->in_ip_array [j].contains (incoming_addr );
555+ bool in_range = rp->in_ip_array [j].contains (*local_addr );
538556 if (rp->in_ip_array [j].invert ) {
539557 if (!in_range) {
540558 in_ip_matches = true ;
0 commit comments