Merge "[NFCT.TETHER.11] Test TetherOffloadRule{Add, Remove} and set limit for IPv4"
This commit is contained in:
@@ -137,6 +137,8 @@ public class BpfCoordinator {
|
||||
private final BpfTetherStatsProvider mStatsProvider;
|
||||
@NonNull
|
||||
private final BpfCoordinatorShim mBpfCoordinatorShim;
|
||||
@NonNull
|
||||
private final BpfConntrackEventConsumer mBpfConntrackEventConsumer;
|
||||
|
||||
// True if BPF offload is supported, false otherwise. The BPF offload could be disabled by
|
||||
// a runtime resource overlay package or device configuration. This flag is only initialized
|
||||
@@ -248,6 +250,11 @@ public class BpfCoordinator {
|
||||
return new ConntrackMonitor(getHandler(), getSharedLog(), consumer);
|
||||
}
|
||||
|
||||
/** Get interface information for a given interface. */
|
||||
@NonNull public InterfaceParams getInterfaceParams(String ifName) {
|
||||
return InterfaceParams.getByName(ifName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check OS Build at least S.
|
||||
*
|
||||
@@ -339,7 +346,14 @@ public class BpfCoordinator {
|
||||
mNetd = mDeps.getNetd();
|
||||
mLog = mDeps.getSharedLog().forSubComponent(TAG);
|
||||
mIsBpfEnabled = isBpfEnabled();
|
||||
mConntrackMonitor = mDeps.getConntrackMonitor(new BpfConntrackEventConsumer());
|
||||
|
||||
// The conntrack consummer needs to be initialized in BpfCoordinator constructor because it
|
||||
// have to access the data members of BpfCoordinator which is not a static class. The
|
||||
// consumer object is also needed for initializing the conntrack monitor which may be
|
||||
// mocked for testing.
|
||||
mBpfConntrackEventConsumer = new BpfConntrackEventConsumer();
|
||||
mConntrackMonitor = mDeps.getConntrackMonitor(mBpfConntrackEventConsumer);
|
||||
|
||||
BpfTetherStatsProvider provider = new BpfTetherStatsProvider();
|
||||
try {
|
||||
mDeps.getNetworkStatsManager().registerNetworkStatsProvider(
|
||||
@@ -662,7 +676,7 @@ public class BpfCoordinator {
|
||||
if (lp == null || !lp.hasIpv4Address()) return;
|
||||
|
||||
// Support raw ip upstream interface only.
|
||||
final InterfaceParams params = InterfaceParams.getByName(lp.getInterfaceName());
|
||||
final InterfaceParams params = mDeps.getInterfaceParams(lp.getInterfaceName());
|
||||
if (params == null || params.hasMacAddress) return;
|
||||
|
||||
Collection<InetAddress> addresses = lp.getAddresses();
|
||||
@@ -1148,7 +1162,8 @@ public class BpfCoordinator {
|
||||
// TODO: add ether ip support.
|
||||
// TODO: parse CTA_PROTOINFO of conntrack event in ConntrackMonitor. For TCP, only add rules
|
||||
// while TCP status is established.
|
||||
private class BpfConntrackEventConsumer implements ConntrackEventConsumer {
|
||||
@VisibleForTesting
|
||||
class BpfConntrackEventConsumer implements ConntrackEventConsumer {
|
||||
@NonNull
|
||||
private Tether4Key makeTetherUpstream4Key(
|
||||
@NonNull ConntrackEvent e, @NonNull ClientInfo c) {
|
||||
@@ -1497,5 +1512,13 @@ public class BpfCoordinator {
|
||||
return mInterfaceNames;
|
||||
}
|
||||
|
||||
// Return BPF conntrack event consumer. This is used for testing only.
|
||||
// Note that this can be only called on handler thread.
|
||||
@NonNull
|
||||
@VisibleForTesting
|
||||
final BpfConntrackEventConsumer getBpfConntrackEventConsumerForTesting() {
|
||||
return mBpfConntrackEventConsumer;
|
||||
}
|
||||
|
||||
private static native String[] getBpfCounterNames();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user