Merge changes Iaac422d7,Ia7638b31 am: 0913a7a415
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1560403 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I747667f004d2b13fe25789beaf9d6c9101c39692
This commit is contained in:
@@ -71,10 +71,8 @@ import com.android.networkstack.tethering.BpfCoordinator.ClientInfo;
|
|||||||
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
|
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
|
||||||
import com.android.networkstack.tethering.PrivateAddressCoordinator;
|
import com.android.networkstack.tethering.PrivateAddressCoordinator;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -187,16 +185,6 @@ public class IpServer extends StateMachine {
|
|||||||
return InterfaceParams.getByName(ifName);
|
return InterfaceParams.getByName(ifName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get |ifName|'s interface index. */
|
|
||||||
public int getIfindex(String ifName) {
|
|
||||||
try {
|
|
||||||
return NetworkInterface.getByName(ifName).getIndex();
|
|
||||||
} catch (IOException | NullPointerException e) {
|
|
||||||
Log.e(TAG, "Can't determine interface index for interface " + ifName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a DhcpServer instance to be used by IpServer. */
|
/** Create a DhcpServer instance to be used by IpServer. */
|
||||||
public abstract void makeDhcpServer(String ifName, DhcpServingParamsParcel params,
|
public abstract void makeDhcpServer(String ifName, DhcpServingParamsParcel params,
|
||||||
DhcpServerCallbacks cb);
|
DhcpServerCallbacks cb);
|
||||||
|
|||||||
@@ -245,8 +245,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get downstream4 BPF map. */
|
/** Get downstream4 BPF map. */
|
||||||
@Nullable public BpfMap<Tether4Key, Tether4Value>
|
@Nullable public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
||||||
getBpfDownstream4Map() {
|
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_DOWNSTREAM4_MAP_PATH,
|
return new BpfMap<>(TETHER_DOWNSTREAM4_MAP_PATH,
|
||||||
BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
|
BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
|
||||||
@@ -257,20 +256,18 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get upstream4 BPF map. */
|
/** Get upstream4 BPF map. */
|
||||||
@Nullable public BpfMap<Tether4Key, Tether4Value>
|
@Nullable public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
||||||
getBpfUpstream4Map() {
|
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_UPSTREAM4_MAP_PATH,
|
return new BpfMap<>(TETHER_UPSTREAM4_MAP_PATH,
|
||||||
BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
|
BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
Log.e(TAG, "Cannot create upstream4 map: " + e);
|
Log.e(TAG, "Cannot create upstream4 map: " + e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get downstream6 BPF map. */
|
/** Get downstream6 BPF map. */
|
||||||
@Nullable public BpfMap<TetherDownstream6Key, Tether6Value>
|
@Nullable public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
||||||
getBpfDownstream6Map() {
|
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
|
return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
|
||||||
BpfMap.BPF_F_RDWR, TetherDownstream6Key.class, Tether6Value.class);
|
BpfMap.BPF_F_RDWR, TetherDownstream6Key.class, Tether6Value.class);
|
||||||
@@ -958,7 +955,7 @@ public class BpfCoordinator {
|
|||||||
// TODO: add ether ip support.
|
// TODO: add ether ip support.
|
||||||
private class BpfConntrackEventConsumer implements ConntrackEventConsumer {
|
private class BpfConntrackEventConsumer implements ConntrackEventConsumer {
|
||||||
@NonNull
|
@NonNull
|
||||||
private Tether4Key makeTether4Key(
|
private Tether4Key makeTetherUpstream4Key(
|
||||||
@NonNull ConntrackEvent e, @NonNull ClientInfo c) {
|
@NonNull ConntrackEvent e, @NonNull ClientInfo c) {
|
||||||
return new Tether4Key(c.downstreamIfindex, c.downstreamMac,
|
return new Tether4Key(c.downstreamIfindex, c.downstreamMac,
|
||||||
e.tupleOrig.protoNum, e.tupleOrig.srcIp.getAddress(),
|
e.tupleOrig.protoNum, e.tupleOrig.srcIp.getAddress(),
|
||||||
@@ -966,7 +963,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Tether4Key makeTether4Key(
|
private Tether4Key makeTetherDownstream4Key(
|
||||||
@NonNull ConntrackEvent e, @NonNull ClientInfo c, int upstreamIndex) {
|
@NonNull ConntrackEvent e, @NonNull ClientInfo c, int upstreamIndex) {
|
||||||
return new Tether4Key(upstreamIndex, NULL_MAC_ADDRESS /* dstMac (rawip) */,
|
return new Tether4Key(upstreamIndex, NULL_MAC_ADDRESS /* dstMac (rawip) */,
|
||||||
e.tupleReply.protoNum, e.tupleReply.srcIp.getAddress(),
|
e.tupleReply.protoNum, e.tupleReply.srcIp.getAddress(),
|
||||||
@@ -974,7 +971,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Tether4Value makeTether4Value(@NonNull ConntrackEvent e,
|
private Tether4Value makeTetherUpstream4Value(@NonNull ConntrackEvent e,
|
||||||
int upstreamIndex) {
|
int upstreamIndex) {
|
||||||
return new Tether4Value(upstreamIndex,
|
return new Tether4Value(upstreamIndex,
|
||||||
NULL_MAC_ADDRESS /* ethDstMac (rawip) */,
|
NULL_MAC_ADDRESS /* ethDstMac (rawip) */,
|
||||||
@@ -985,11 +982,12 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Tether4Value makeTether4Value(@NonNull ConntrackEvent e,
|
private Tether4Value makeTetherDownstream4Value(@NonNull ConntrackEvent e,
|
||||||
@NonNull ClientInfo c, int upstreamIndex) {
|
@NonNull ClientInfo c, int upstreamIndex) {
|
||||||
return new Tether4Value(c.downstreamIfindex,
|
return new Tether4Value(c.downstreamIfindex,
|
||||||
c.clientMac, c.downstreamMac, ETH_P_IP, NetworkStackConstants.ETHER_MTU,
|
c.clientMac, c.downstreamMac, ETH_P_IP, NetworkStackConstants.ETHER_MTU,
|
||||||
e.tupleOrig.dstIp.getAddress(), e.tupleOrig.srcIp.getAddress(),
|
toIpv4MappedAddressBytes(e.tupleOrig.dstIp),
|
||||||
|
toIpv4MappedAddressBytes(e.tupleOrig.srcIp),
|
||||||
e.tupleOrig.dstPort, e.tupleOrig.srcPort,
|
e.tupleOrig.dstPort, e.tupleOrig.srcPort,
|
||||||
0 /* lastUsed, filled by bpf prog only */);
|
0 /* lastUsed, filled by bpf prog only */);
|
||||||
}
|
}
|
||||||
@@ -1014,9 +1012,9 @@ public class BpfCoordinator {
|
|||||||
final Integer upstreamIndex = mIpv4UpstreamIndices.get(e.tupleReply.dstIp);
|
final Integer upstreamIndex = mIpv4UpstreamIndices.get(e.tupleReply.dstIp);
|
||||||
if (upstreamIndex == null) return;
|
if (upstreamIndex == null) return;
|
||||||
|
|
||||||
final Tether4Key upstream4Key = makeTether4Key(e, tetherClient);
|
final Tether4Key upstream4Key = makeTetherUpstream4Key(e, tetherClient);
|
||||||
final Tether4Key downstream4Key = makeTether4Key(e,
|
final Tether4Key downstream4Key = makeTetherDownstream4Key(e, tetherClient,
|
||||||
tetherClient, upstreamIndex);
|
upstreamIndex);
|
||||||
|
|
||||||
if (e.msgType == (NetlinkConstants.NFNL_SUBSYS_CTNETLINK << 8
|
if (e.msgType == (NetlinkConstants.NFNL_SUBSYS_CTNETLINK << 8
|
||||||
| NetlinkConstants.IPCTNL_MSG_CT_DELETE)) {
|
| NetlinkConstants.IPCTNL_MSG_CT_DELETE)) {
|
||||||
@@ -1025,10 +1023,9 @@ public class BpfCoordinator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Tether4Value upstream4Value = makeTether4Value(e,
|
final Tether4Value upstream4Value = makeTetherUpstream4Value(e, upstreamIndex);
|
||||||
|
final Tether4Value downstream4Value = makeTetherDownstream4Value(e, tetherClient,
|
||||||
upstreamIndex);
|
upstreamIndex);
|
||||||
final Tether4Value downstream4Value = makeTether4Value(e,
|
|
||||||
tetherClient, upstreamIndex);
|
|
||||||
|
|
||||||
mBpfCoordinatorShim.tetherOffloadRuleAdd(false, upstream4Key, upstream4Value);
|
mBpfCoordinatorShim.tetherOffloadRuleAdd(false, upstream4Key, upstream4Value);
|
||||||
mBpfCoordinatorShim.tetherOffloadRuleAdd(true, downstream4Key, downstream4Value);
|
mBpfCoordinatorShim.tetherOffloadRuleAdd(true, downstream4Key, downstream4Value);
|
||||||
|
|||||||
@@ -206,9 +206,6 @@ public class IpServerTest {
|
|||||||
when(mDependencies.getInterfaceParams(UPSTREAM_IFACE)).thenReturn(UPSTREAM_IFACE_PARAMS);
|
when(mDependencies.getInterfaceParams(UPSTREAM_IFACE)).thenReturn(UPSTREAM_IFACE_PARAMS);
|
||||||
when(mDependencies.getInterfaceParams(UPSTREAM_IFACE2)).thenReturn(UPSTREAM_IFACE_PARAMS2);
|
when(mDependencies.getInterfaceParams(UPSTREAM_IFACE2)).thenReturn(UPSTREAM_IFACE_PARAMS2);
|
||||||
|
|
||||||
when(mDependencies.getIfindex(eq(UPSTREAM_IFACE))).thenReturn(UPSTREAM_IFINDEX);
|
|
||||||
when(mDependencies.getIfindex(eq(UPSTREAM_IFACE2))).thenReturn(UPSTREAM_IFINDEX2);
|
|
||||||
|
|
||||||
mInterfaceConfiguration = new InterfaceConfigurationParcel();
|
mInterfaceConfiguration = new InterfaceConfigurationParcel();
|
||||||
mInterfaceConfiguration.flags = new String[0];
|
mInterfaceConfiguration.flags = new String[0];
|
||||||
if (interfaceType == TETHERING_BLUETOOTH) {
|
if (interfaceType == TETHERING_BLUETOOTH) {
|
||||||
@@ -309,26 +306,22 @@ public class IpServerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value>
|
public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
||||||
getBpfDownstream4Map() {
|
|
||||||
return mBpfDownstream4Map;
|
return mBpfDownstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value>
|
public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
||||||
getBpfUpstream4Map() {
|
|
||||||
return mBpfUpstream4Map;
|
return mBpfUpstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherDownstream6Key, Tether6Value>
|
public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
||||||
getBpfDownstream6Map() {
|
|
||||||
return mBpfDownstream6Map;
|
return mBpfDownstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherUpstream6Key, Tether6Value>
|
public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
||||||
getBpfUpstream6Map() {
|
|
||||||
return mBpfUpstream6Map;
|
return mBpfUpstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,26 +206,22 @@ public class BpfCoordinatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value>
|
public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
||||||
getBpfDownstream4Map() {
|
|
||||||
return mBpfDownstream4Map;
|
return mBpfDownstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value>
|
public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
||||||
getBpfUpstream4Map() {
|
|
||||||
return mBpfUpstream4Map;
|
return mBpfUpstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherDownstream6Key, Tether6Value>
|
public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
||||||
getBpfDownstream6Map() {
|
|
||||||
return mBpfDownstream6Map;
|
return mBpfDownstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherUpstream6Key, Tether6Value>
|
public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
||||||
getBpfUpstream6Map() {
|
|
||||||
return mBpfUpstream6Map;
|
return mBpfUpstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user