[NFCT.TETHER.7] Prepare the downstream information for IPv4 offload rule

Add and remove downstream client information to BpfCoordinator

Required for building IPv4 forwarding rule when a conntrack event is
received. The IpServer provides the following elements of a rule which
is not included in conntrack event:
- Downstream interface index
- Downstream Mac address
- Client IP address to Client Mac address

Test: atest TetheringCoverageTests
Change-Id: I84db13acc047ace5730d17f0d3dd99544f516084
This commit is contained in:
Hungming Chen
2020-12-21 19:39:49 +08:00
parent 168a96643d
commit d71c06ec71
2 changed files with 117 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ import com.android.internal.util.MessageUtils;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.networkstack.tethering.BpfCoordinator;
import com.android.networkstack.tethering.BpfCoordinator.ClientInfo;
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
import com.android.networkstack.tethering.PrivateAddressCoordinator;
@@ -941,11 +942,38 @@ public class IpServer extends StateMachine {
}
}
// TODO: consider moving into BpfCoordinator.
private void updateClientInfoIpv4(NeighborEvent e) {
// TODO: Perhaps remove this protection check.
// See the related comment in #addIpv6ForwardingRule.
if (!mUsingBpfOffload) return;
if (e == null) return;
if (!(e.ip instanceof Inet4Address) || e.ip.isMulticastAddress()
|| e.ip.isLoopbackAddress() || e.ip.isLinkLocalAddress()) {
return;
}
// When deleting clients, IpServer still need to pass a non-null MAC, even though it's
// ignored. Do this here instead of in the ClientInfo constructor to ensure that
// IpServer never add clients with a null MAC, only delete them.
final MacAddress clientMac = e.isValid() ? e.macAddr : NULL_MAC_ADDRESS;
final ClientInfo clientInfo = new ClientInfo(mInterfaceParams.index,
mInterfaceParams.macAddr, (Inet4Address) e.ip, clientMac);
if (e.isValid()) {
mBpfCoordinator.tetherOffloadClientAdd(this, clientInfo);
} else {
// TODO: Delete all related offload rules which are using this client.
mBpfCoordinator.tetherOffloadClientRemove(this, clientInfo);
}
}
private void handleNeighborEvent(NeighborEvent e) {
if (mInterfaceParams != null
&& mInterfaceParams.index == e.ifindex
&& mInterfaceParams.hasMacAddress) {
updateIpv6ForwardingRules(mLastIPv6UpstreamIfindex, mLastIPv6UpstreamIfindex, e);
updateClientInfoIpv4(e);
}
}