Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions agent/crates/public/src/utils/net/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
);

if result != 111 {
println!("{} {} GetAdaptersAddresses {}", file!(), line!(), result);
return Err(Error::Windows(format!(
"Get buffer len by GetAdaptersAddresses failed error code {}",
result
Expand All @@ -159,6 +160,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
&mut buffer_len,
);
if result != 0 {
println!("{} {} GetAdaptersAddresses {}", file!(), line!(), result);
return Err(Error::Windows(format!(
"Get adapter addresses by GetAdaptersAddresses failed error code {}",
result
Expand All @@ -170,6 +172,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
while !current_adapter.is_null() {
let mac_address = unsafe {
let adapter_ref = &*current_adapter;
println!("{} {} adapter ifindex {}", file!(), line!(), adapter_ref.Anonymous1.Anonymous.IfIndex);
if if_index != adapter_ref.Anonymous1.Anonymous.IfIndex {
current_adapter = adapter_ref.Next;
continue;
Expand Down Expand Up @@ -326,6 +329,7 @@ pub fn route_get(dest_addr: IpAddr) -> Result<Route> {
"failed to run GetBestInterfaceEx function with destination address={} because of win32 error code({}),\n{}",
dest_addr, ret_code, WIN_ERROR_CODE_STR
);
println!("{} {} {}", file!(), line!(), err_msg);
return Err(Error::Windows(err_msg));
}

Expand All @@ -351,6 +355,7 @@ pub fn route_get(dest_addr: IpAddr) -> Result<Route> {
"failed to run GetBestRoute2 function with destination address={} error: {}",
dest_addr, err
);
println!("{} {} {}", file!(), line!(), err_msg);
return Err(Error::Windows(err_msg));
}

Expand Down Expand Up @@ -381,6 +386,7 @@ pub fn route_get(dest_addr: IpAddr) -> Result<Route> {
(src_addr, gateway)
}
};
println!("{} {} route_get({}) return {} {}", file!(), line!(), dest_addr, src_addr, best_if_index);

Ok(Route {
pref_src: Some(src_addr),
Expand Down
10 changes: 10 additions & 0 deletions agent/src/utils/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,22 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
"failed getting control ip and mac from {}, because: {:?}, wait 1 second",
dest, tuple,
);
println!(
"failed getting control ip and mac from {}, because: {:?}, wait 1 second",
dest, tuple,
);
thread::sleep(Duration::from_secs(1));
continue;
}
let (ip, mac) = tuple.unwrap();
println!("{} {} get_route_src_ip_and_mac return {} {}", file!(), line!(), ip, mac);
let links = link_list();
if links.is_err() {
warn!(
"failed getting local interfaces, because: {:?}, wait 1 second",
links
);
println!("{} {}", file!(), line!());
thread::sleep(Duration::from_secs(1));
continue;
}
Expand All @@ -403,7 +409,9 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
// interface of the default route.
for link in links.unwrap().iter() {
if link.mac_addr == mac {
println!("{} {} ", file!(), line!());
if !link.flags.contains(LinkFlags::UP) {
println!("{} {} {:?}", file!(), line!(), link);
let dest = if dest.is_ipv4() {
DNS_HOST_IPV4
} else {
Expand All @@ -412,13 +420,15 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
let tuple = get_route_src_ip_and_mac(&dest);
if tuple.is_err() {
warn!("failed getting control ip and mac from {}, because: {:?}, wait 1 second", dest, tuple);
println!("failed getting control ip and mac from {}, because: {:?}, wait 1 second", dest, tuple);
thread::sleep(Duration::from_secs(1));
// There are scenarios where multiple network cards use the same MAC address, so it is necessary to
// continue checking the other network cards.
continue;
}
return Ok(tuple.unwrap());
}
println!("{} {} ", file!(), line!());
break;
}
}
Expand Down
Loading