Skip to content

Commit 73d11d3

Browse files
committed
fix: incorrect l2end
1 parent c7aed39 commit 73d11d3

4 files changed

Lines changed: 60 additions & 14 deletions

File tree

agent/benches/labeler.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@ fn bench_policy(c: &mut Criterion) {
262262
b.iter_custom(|iters| {
263263
let start = Instant::now();
264264
for _ in 0..iters {
265-
first.endpoint_fast_get(EndpointTableType::Ebpf, key.src_ip, key.dst_ip, 2, 0);
265+
first.endpoint_fast_get(
266+
EndpointTableType::Ebpf,
267+
key.src_ip,
268+
key.dst_ip,
269+
2,
270+
0,
271+
true,
272+
);
266273
}
267274
start.elapsed()
268275
})

agent/src/policy/fast_path.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

agent/src/policy/first_path.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,20 @@ impl FirstPath {
735735
ip_dst: IpAddr,
736736
l3_epc_id_src: i32,
737737
l3_epc_id_dst: i32,
738+
l2_end_0: bool,
738739
) -> Option<Arc<EndpointData>> {
739740
if self.fast_disable {
740741
return None;
741742
}
742743

743-
self.fast
744-
.get_endpoints(table_type, ip_src, ip_dst, l3_epc_id_src, l3_epc_id_dst)
744+
self.fast.get_endpoints(
745+
table_type,
746+
ip_src,
747+
ip_dst,
748+
l3_epc_id_src,
749+
l3_epc_id_dst,
750+
l2_end_0,
751+
)
745752
}
746753

747754
pub fn endpoint_fast_add(

agent/src/policy/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl Policy {
408408
key.dst_ip,
409409
l3_epc_id_0,
410410
l3_epc_id_1,
411+
key.l2_end_0,
411412
) {
412413
let entry = self.lookup_gpid_entry(key, &endpoints);
413414
self.send_ebpf(

0 commit comments

Comments
 (0)