@@ -531,8 +531,13 @@ impl FastPath {
531531 l3_epc_id_dst : i32 ,
532532 endpoints : EndpointData ,
533533 ) -> Arc < EndpointData > {
534- let ( key_0, key_1) =
535- self . generate_endpoints_map_key ( ip_src, ip_dst, l3_epc_id_src, l3_epc_id_dst) ;
534+ let ( key_0, key_1) = self . generate_endpoints_map_key (
535+ ip_src,
536+ ip_dst,
537+ l3_epc_id_src,
538+ l3_epc_id_dst,
539+ endpoints. src_info . l2_end ,
540+ ) ;
536541 let key = ( key_0 as u128 ) << 64 | key_1 as u128 ;
537542 let endpoints = Arc :: new ( endpoints) ;
538543 let table = self . get_endpoint_table ( table_type) ;
@@ -552,13 +557,14 @@ impl FastPath {
552557 ip_dst : IpAddr ,
553558 l3_epc_id_src : i32 ,
554559 l3_epc_id_dst : i32 ,
560+ l2_end_0 : bool ,
555561 ) -> Option < Arc < EndpointData > > {
556562 if self . flush_endpoint_table ( table_type) {
557563 return None ;
558564 }
559565
560566 let ( key_0, key_1) =
561- self . generate_endpoints_map_key ( ip_src, ip_dst, l3_epc_id_src, l3_epc_id_dst) ;
567+ self . generate_endpoints_map_key ( ip_src, ip_dst, l3_epc_id_src, l3_epc_id_dst, l2_end_0 ) ;
562568 let key = ( key_0 as u128 ) << 64 | key_1 as u128 ;
563569
564570 self . get_endpoint_table ( table_type)
@@ -572,15 +578,17 @@ impl FastPath {
572578 ip_dst : IpAddr ,
573579 l3_epc_id_src : i32 ,
574580 l3_epc_id_dst : i32 ,
581+ l2_end_0 : bool ,
575582 ) -> ( u64 , u64 ) {
576583 let netmask_table = self . netmask_table . read ( ) . unwrap ( ) ;
577584 let ( src_masked_ip, dst_masked_ip) = generate_mask_ip ( & netmask_table, ip_src, ip_dst) ;
578585 let l3_epc_id_src = l3_epc_id_src as u64 ;
579586 let l3_epc_id_dst = l3_epc_id_dst as u64 ;
587+ let ( src_flags, dst_flags) = if l2_end_0 { ( 0xffff , 0 ) } else { ( 0 , 0xffff ) } ;
580588
581589 (
582- ( src_masked_ip as u64 ) | 0xffff << 32 | l3_epc_id_src << 48 ,
583- ( dst_masked_ip as u64 ) | 0xffff << 32 | l3_epc_id_dst << 48 ,
590+ ( src_masked_ip as u64 ) | src_flags << 32 | l3_epc_id_src << 48 ,
591+ ( dst_masked_ip as u64 ) | dst_flags << 32 | l3_epc_id_dst << 48 ,
584592 )
585593 }
586594
@@ -638,7 +646,7 @@ impl FastPath {
638646}
639647
640648#[ cfg( test) ]
641- mod test {
649+ mod tests {
642650 use std:: net:: { IpAddr , Ipv4Addr } ;
643651 use std:: sync:: Arc ;
644652
@@ -895,27 +903,50 @@ mod test {
895903 let ip_src = IpAddr :: from ( "192.169.1.100" . parse :: < Ipv4Addr > ( ) . unwrap ( ) ) ;
896904 let ip_dst = IpAddr :: from ( "172.29.2.200" . parse :: < Ipv4Addr > ( ) . unwrap ( ) ) ;
897905 let mut endpoints: EndpointData = Default :: default ( ) ;
906+ endpoints. src_info . l2_end = true ;
898907 endpoints. src_info . l3_epc_id = 10 ;
899908 endpoints. dst_info . l3_epc_id = 20 ;
900909
901910 let e = table. add_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 0 , endpoints) ;
902911 assert_eq ! ( 10 , e. src_info. l3_epc_id) ;
903912 assert_eq ! ( 20 , e. dst_info. l3_epc_id) ;
904913 let e = table
905- . get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 0 )
914+ . get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 0 , true )
906915 . unwrap ( ) ;
907916 assert_eq ! ( 10 , e. src_info. l3_epc_id) ;
908917 assert_eq ! ( 20 , e. dst_info. l3_epc_id) ;
909918 let e = table
910- . get_endpoints ( EndpointTableType :: Ebpf , ip_dst, ip_src, 0 , 10 )
919+ . get_endpoints ( EndpointTableType :: Ebpf , ip_dst, ip_src, 0 , 10 , false )
911920 . unwrap ( ) ;
912921 assert_eq ! ( 20 , e. src_info. l3_epc_id) ;
913922 assert_eq ! ( 10 , e. dst_info. l3_epc_id) ;
914- let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 0 , 0 ) ;
923+ let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 0 , 0 , true ) ;
915924 assert ! ( e. is_none( ) ) ;
916- let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 0 , 10 ) ;
925+ let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 0 , 10 , false ) ;
917926 assert ! ( e. is_none( ) ) ;
918- let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 20 ) ;
927+ let e = table. get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 20 , true ) ;
919928 assert ! ( e. is_none( ) ) ;
929+
930+ let ip_src = IpAddr :: from ( "192.168.1.100" . parse :: < Ipv4Addr > ( ) . unwrap ( ) ) ;
931+ let ip_dst = IpAddr :: from ( "192.168.1.200" . parse :: < Ipv4Addr > ( ) . unwrap ( ) ) ;
932+ let mut endpoints: EndpointData = Default :: default ( ) ;
933+ endpoints. src_info . l2_end = true ;
934+ endpoints. src_info . l3_epc_id = 10 ;
935+ endpoints. dst_info . l3_epc_id = 10 ;
936+ let e = table. add_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 10 , endpoints) ;
937+ assert_eq ! ( true , e. src_info. l2_end) ;
938+ assert_eq ! ( false , e. dst_info. l2_end) ;
939+
940+ let e = table
941+ . get_endpoints ( EndpointTableType :: Ebpf , ip_src, ip_dst, 10 , 10 , true )
942+ . unwrap ( ) ;
943+ assert_eq ! ( true , e. src_info. l2_end) ;
944+ assert_eq ! ( false , e. dst_info. l2_end) ;
945+
946+ let e = table
947+ . get_endpoints ( EndpointTableType :: Ebpf , ip_dst, ip_src, 10 , 10 , false )
948+ . unwrap ( ) ;
949+ assert_eq ! ( false , e. src_info. l2_end) ;
950+ assert_eq ! ( true , e. dst_info. l2_end) ;
920951 }
921952}
0 commit comments