Merge "Improve dumping IPv4 map entries."
This commit is contained in:
@@ -48,6 +48,7 @@ import android.net.util.InterfaceParams;
|
||||
import android.net.util.SharedLog;
|
||||
import android.net.util.TetheringUtils.ForwardedStats;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.system.ErrnoException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -871,7 +872,7 @@ public class BpfCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
private String ipv4RuleToString(Tether4Key key, Tether4Value value) {
|
||||
private String ipv4RuleToString(long now, Tether4Key key, Tether4Value value) {
|
||||
final String private4, public4, dst4;
|
||||
try {
|
||||
private4 = InetAddress.getByAddress(key.src4).getHostAddress();
|
||||
@@ -880,29 +881,43 @@ public class BpfCoordinator {
|
||||
} catch (UnknownHostException impossible) {
|
||||
throw new AssertionError("4-byte array not valid IPv4 address!");
|
||||
}
|
||||
return String.format("[%s] %d(%s) %s:%d -> %d(%s) %s:%d -> %s:%d",
|
||||
long ageMs = (now - value.lastUsed) / 1_000_000;
|
||||
return String.format("[%s] %d(%s) %s:%d -> %d(%s) %s:%d -> %s:%d %dms",
|
||||
key.dstMac, key.iif, getIfName(key.iif), private4, key.srcPort,
|
||||
value.oif, getIfName(value.oif),
|
||||
public4, value.srcPort, dst4, key.dstPort);
|
||||
public4, value.srcPort, dst4, key.dstPort, ageMs);
|
||||
}
|
||||
|
||||
private void dumpIpv4ForwardingRuleMap(long now, BpfMap<Tether4Key, Tether4Value> map,
|
||||
IndentingPrintWriter pw) throws ErrnoException {
|
||||
if (map == null) {
|
||||
pw.println("No IPv4 support");
|
||||
return;
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
pw.println("No rules");
|
||||
return;
|
||||
}
|
||||
map.forEach((k, v) -> pw.println(ipv4RuleToString(now, k, v)));
|
||||
}
|
||||
|
||||
private void dumpIpv4ForwardingRules(IndentingPrintWriter pw) {
|
||||
try (BpfMap<Tether4Key, Tether4Value> map = mDeps.getBpfUpstream4Map()) {
|
||||
if (map == null) {
|
||||
pw.println("No IPv4 support");
|
||||
return;
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
pw.println("No IPv4 rules");
|
||||
return;
|
||||
}
|
||||
pw.println("IPv4: [inDstMac] iif(iface) src -> nat -> dst");
|
||||
final long now = SystemClock.elapsedRealtimeNanos();
|
||||
|
||||
try (BpfMap<Tether4Key, Tether4Value> upstreamMap = mDeps.getBpfUpstream4Map();
|
||||
BpfMap<Tether4Key, Tether4Value> downstreamMap = mDeps.getBpfDownstream4Map()) {
|
||||
pw.println("IPv4 Upstream: [inDstMac] iif(iface) src -> nat -> dst");
|
||||
pw.increaseIndent();
|
||||
map.forEach((k, v) -> pw.println(ipv4RuleToString(k, v)));
|
||||
dumpIpv4ForwardingRuleMap(now, upstreamMap, pw);
|
||||
pw.decreaseIndent();
|
||||
|
||||
pw.println("IPv4 Downstream: [inDstMac] iif(iface) src -> nat -> dst");
|
||||
pw.increaseIndent();
|
||||
dumpIpv4ForwardingRuleMap(now, downstreamMap, pw);
|
||||
pw.decreaseIndent();
|
||||
} catch (ErrnoException e) {
|
||||
pw.println("Error dumping IPv4 map: " + e);
|
||||
}
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user