Merge "Exclude 7681(ttyd) from port forwarding list" into main am: 6990ed9596

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Virtualization/+/3377329

Change-Id: I1b52a46a545ea183a4c096cddc77ab345e97f15e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/guest/forwarder_guest_launcher/src/main.rs b/guest/forwarder_guest_launcher/src/main.rs
index 1da37b4..f6944d6 100644
--- a/guest/forwarder_guest_launcher/src/main.rs
+++ b/guest/forwarder_guest_launcher/src/main.rs
@@ -35,6 +35,7 @@
 }
 
 const NON_PREVILEGED_PORT_RANGE_START: i32 = 1024;
+const TTYD_PORT: i32 = 7681;
 const TCPSTATES_IP_4: i8 = 4;
 const TCPSTATES_STATE_CLOSE: &str = "CLOSE";
 const TCPSTATES_STATE_LISTEN: &str = "LISTEN";
@@ -108,6 +109,10 @@
     Ok(())
 }
 
+fn is_forwardable_port(port: i32) -> bool {
+    port >= NON_PREVILEGED_PORT_RANGE_START && port != TTYD_PORT
+}
+
 async fn report_active_ports(
     mut client: DebianServiceClient<Channel>,
 ) -> Result<(), Box<dyn std::error::Error>> {
@@ -130,7 +135,7 @@
         .map(|x| x.socket)
         .filter(|x| x.is_ipv4())
         .map(|x| x.port().into())
-        .filter(|x| *x >= NON_PREVILEGED_PORT_RANGE_START) // Ignore privileged ports
+        .filter(|x| is_forwardable_port(*x))
         .collect();
     send_active_ports_report(listening_ports.clone(), &mut client).await?;
 
@@ -140,7 +145,7 @@
         if row.ip != TCPSTATES_IP_4 {
             continue;
         }
-        if row.lport < NON_PREVILEGED_PORT_RANGE_START {
+        if !is_forwardable_port(row.lport) {
             continue;
         }
         if row.rport > 0 {