Merge "Fix monitoring active port logic in forwarder_guest_launcher" into main
diff --git a/guest/forwarder_guest_launcher/src/main.rs b/guest/forwarder_guest_launcher/src/main.rs
index 0bb3b4d..1da37b4 100644
--- a/guest/forwarder_guest_launcher/src/main.rs
+++ b/guest/forwarder_guest_launcher/src/main.rs
@@ -36,6 +36,7 @@
const NON_PREVILEGED_PORT_RANGE_START: i32 = 1024;
const TCPSTATES_IP_4: i8 = 4;
+const TCPSTATES_STATE_CLOSE: &str = "CLOSE";
const TCPSTATES_STATE_LISTEN: &str = "LISTEN";
#[derive(Debug, Deserialize)]
@@ -43,7 +44,7 @@
struct TcpStateRow {
ip: i8,
lport: i32,
- oldstate: String,
+ rport: i32,
newstate: String,
}
@@ -142,14 +143,17 @@
if row.lport < NON_PREVILEGED_PORT_RANGE_START {
continue;
}
- match (row.oldstate.as_str(), row.newstate.as_str()) {
- (_, TCPSTATES_STATE_LISTEN) => {
+ if row.rport > 0 {
+ continue;
+ }
+ match row.newstate.as_str() {
+ TCPSTATES_STATE_LISTEN => {
listening_ports.insert(row.lport);
}
- (TCPSTATES_STATE_LISTEN, _) => {
+ TCPSTATES_STATE_CLOSE => {
listening_ports.remove(&row.lport);
}
- (_, _) => continue,
+ _ => continue,
}
send_active_ports_report(listening_ports.clone(), &mut client).await?;
}