From e7dff2f95593b012db7dc0902303183a34cfab8e Mon Sep 17 00:00:00 2001 From: Hungming Chen Date: Tue, 29 Jun 2021 16:10:54 +0800 Subject: [PATCH] Dump the unused IPv4 BPF rule age correctly Print a dash for the unused "lastUsed" of the rule. The age should not equal the bootime if the rule has never been updated the "lastUsed" field. Format: [inDstMac] iif(iface) src -> nat -> dst [outDstMac] age [00:00:00:00:00:00] 14(rmnet0) 140.112.8.116:443 -> 30(30) 10.170.56.233:43720 -> 192.168.45.236:43720 [be:34:40:28:33:5f] - Test: dumpsys tethering Change-Id: Ie771becd2f72518cf02a86e5ae228315785752a5 --- .../com/android/networkstack/tethering/BpfCoordinator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java index 9b95dac35d..56dc69cda5 100644 --- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java +++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java @@ -1069,11 +1069,12 @@ public class BpfCoordinator { throw new AssertionError("IP address array not valid IPv4 address!"); } - final long ageMs = (now - value.lastUsed) / 1_000_000; - return String.format("[%s] %d(%s) %s:%d -> %d(%s) %s:%d -> %s:%d [%s] %dms", + final String ageStr = (value.lastUsed == 0) ? "-" + : String.format("%dms", (now - value.lastUsed) / 1_000_000); + return String.format("[%s] %d(%s) %s:%d -> %d(%s) %s:%d -> %s:%d [%s] %s", key.dstMac, key.iif, getIfName(key.iif), src4, key.srcPort, value.oif, getIfName(value.oif), - public4, publicPort, dst4, value.dstPort, value.ethDstMac, ageMs); + public4, publicPort, dst4, value.dstPort, value.ethDstMac, ageStr); } private void dumpIpv4ForwardingRuleMap(long now, boolean downstream,