Skip to content

Commit d0a24d8

Browse files
committed
fix windows route
1 parent 39f13d0 commit d0a24d8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

agent/crates/public/src/utils/net/windows.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
140140
);
141141

142142
if result != 111 {
143+
println!("{} {} GetAdaptersAddresses {}", file!(), line!(), result);
143144
return Err(Error::Windows(format!(
144145
"Get buffer len by GetAdaptersAddresses failed error code {}",
145146
result
@@ -159,6 +160,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
159160
&mut buffer_len,
160161
);
161162
if result != 0 {
163+
println!("{} {} GetAdaptersAddresses {}", file!(), line!(), result);
162164
return Err(Error::Windows(format!(
163165
"Get adapter addresses by GetAdaptersAddresses failed error code {}",
164166
result
@@ -170,6 +172,7 @@ pub fn get_interface_by_index_from_win32(if_index: u32) -> Result<Link> {
170172
while !current_adapter.is_null() {
171173
let mac_address = unsafe {
172174
let adapter_ref = &*current_adapter;
175+
println!("{} {} adapter ifindex {}", file!(), line!(), adapter_ref.Anonymous1.Anonymous.IfIndex);
173176
if if_index != adapter_ref.Anonymous1.Anonymous.IfIndex {
174177
current_adapter = adapter_ref.Next;
175178
continue;
@@ -326,6 +329,7 @@ pub fn route_get(dest_addr: IpAddr) -> Result<Route> {
326329
"failed to run GetBestInterfaceEx function with destination address={} because of win32 error code({}),\n{}",
327330
dest_addr, ret_code, WIN_ERROR_CODE_STR
328331
);
332+
println!("{} {} {}", file!(), line!(), err_msg);
329333
return Err(Error::Windows(err_msg));
330334
}
331335

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

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

385391
Ok(Route {
386392
pref_src: Some(src_addr),

agent/src/utils/environment.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,22 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
385385
"failed getting control ip and mac from {}, because: {:?}, wait 1 second",
386386
dest, tuple,
387387
);
388+
println!(
389+
"failed getting control ip and mac from {}, because: {:?}, wait 1 second",
390+
dest, tuple,
391+
);
388392
thread::sleep(Duration::from_secs(1));
389393
continue;
390394
}
391395
let (ip, mac) = tuple.unwrap();
396+
println!("{} {} get_route_src_ip_and_mac return {} {}", file!(), line!(), ip, mac);
392397
let links = link_list();
393398
if links.is_err() {
394399
warn!(
395400
"failed getting local interfaces, because: {:?}, wait 1 second",
396401
links
397402
);
403+
println!("{} {}", file!(), line!());
398404
thread::sleep(Duration::from_secs(1));
399405
continue;
400406
}
@@ -403,7 +409,9 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
403409
// interface of the default route.
404410
for link in links.unwrap().iter() {
405411
if link.mac_addr == mac {
412+
println!("{} {} ", file!(), line!());
406413
if !link.flags.contains(LinkFlags::UP) {
414+
println!("{} {} {:?}", file!(), line!(), link);
407415
let dest = if dest.is_ipv4() {
408416
DNS_HOST_IPV4
409417
} else {
@@ -412,13 +420,15 @@ pub fn get_ctrl_ip_and_mac(dest: &IpAddr) -> Result<(IpAddr, MacAddr)> {
412420
let tuple = get_route_src_ip_and_mac(&dest);
413421
if tuple.is_err() {
414422
warn!("failed getting control ip and mac from {}, because: {:?}, wait 1 second", dest, tuple);
423+
println!("failed getting control ip and mac from {}, because: {:?}, wait 1 second", dest, tuple);
415424
thread::sleep(Duration::from_secs(1));
416425
// There are scenarios where multiple network cards use the same MAC address, so it is necessary to
417426
// continue checking the other network cards.
418427
continue;
419428
}
420429
return Ok(tuple.unwrap());
421430
}
431+
println!("{} {} ", file!(), line!());
422432
break;
423433
}
424434
}

0 commit comments

Comments
 (0)