@@ -257,7 +257,7 @@ impl AclModule {
257257 if let Some ( server) = & self . inner . server {
258258 let trunks = server. data_context . trunks_snapshot ( ) ;
259259 for ( name, trunk) in trunks. iter ( ) {
260- if trunk. matches_inbound_ip ( addr) . await {
260+ if trunk. matches_inbound_source_ip ( addr) . await {
261261 return Some ( TrunkContext {
262262 id : trunk. id ,
263263 name : name. clone ( ) ,
@@ -277,7 +277,7 @@ impl AclModule {
277277 . collect ( ) ;
278278
279279 for ( name, trunk) in trunks {
280- if trunk. matches_inbound_ip ( addr) . await {
280+ if trunk. matches_inbound_source_ip ( addr) . await {
281281 return Some ( TrunkContext {
282282 id : trunk. id ,
283283 name,
@@ -498,6 +498,7 @@ fn parse_rules(rules: Vec<String>) -> Vec<AclRule> {
498498#[ cfg( test) ]
499499mod tests {
500500 use super :: * ;
501+ use crate :: proxy:: routing:: TrunkDirection ;
501502 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
502503
503504 fn create_test_config ( rules : Vec < String > ) -> Arc < ProxyConfig > {
@@ -524,6 +525,60 @@ mod tests {
524525 } )
525526 }
526527
528+ #[ tokio:: test]
529+ async fn trunk_context_ignores_outbound_dest_same_ip ( ) {
530+ let source_ip = IpAddr :: V4 ( Ipv4Addr :: new ( 43 , 198 , 217 , 33 ) ) ;
531+ let mut config = ProxyConfig :: default ( ) ;
532+
533+ config. trunks . insert (
534+ "outbound-same-ip" . to_string ( ) ,
535+ TrunkConfig {
536+ id : Some ( 147 ) ,
537+ direction : Some ( TrunkDirection :: Outbound ) ,
538+ dest : "43.198.217.33:5396" . to_string ( ) ,
539+ ..Default :: default ( )
540+ } ,
541+ ) ;
542+ config. trunks . insert (
543+ "inbound-source" . to_string ( ) ,
544+ TrunkConfig {
545+ id : Some ( 144 ) ,
546+ direction : Some ( TrunkDirection :: Inbound ) ,
547+ inbound_hosts : vec ! [ "43.198.217.33" . to_string( ) ] ,
548+ ..Default :: default ( )
549+ } ,
550+ ) ;
551+
552+ let acl = AclModule :: new ( Arc :: new ( config) ) ;
553+ let ctx = acl
554+ . is_from_trunk_context ( & source_ip)
555+ . await
556+ . expect ( "inbound trunk should match" ) ;
557+
558+ assert_eq ! ( ctx. id, Some ( 144 ) ) ;
559+ assert_eq ! ( ctx. name, "inbound-source" ) ;
560+ }
561+
562+ #[ tokio:: test]
563+ async fn trunk_context_does_not_match_inbound_dest_only ( ) {
564+ let source_ip = IpAddr :: V4 ( Ipv4Addr :: new ( 43 , 198 , 217 , 33 ) ) ;
565+ let mut config = ProxyConfig :: default ( ) ;
566+
567+ config. trunks . insert (
568+ "inbound-dest-only" . to_string ( ) ,
569+ TrunkConfig {
570+ id : Some ( 144 ) ,
571+ direction : Some ( TrunkDirection :: Inbound ) ,
572+ dest : "43.198.217.33:5060" . to_string ( ) ,
573+ ..Default :: default ( )
574+ } ,
575+ ) ;
576+
577+ let acl = AclModule :: new ( Arc :: new ( config) ) ;
578+
579+ assert ! ( acl. is_from_trunk_context( & source_ip) . await . is_none( ) ) ;
580+ }
581+
527582 #[ test]
528583 fn test_parse_network ( ) {
529584 let ( net, prefix) = parse_network ( "192.168.1.0/24" ) . unwrap ( ) ;
0 commit comments