On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000
See system/netd/include/Fwmark.h which reserves the bottom 21 bits of skb->mark for netid, etc... so out of necessity these have to be in the top 11 bits. In practice the only values that really make sense are either: mark == mask == 0 (disabled) or (mark == mask) being one of the top 11 available bits, for example: mark == mask == 0x80000000 (enabled, using top-most bit) (only a single bit makes sense, as this is really just a boolean signal, and only the topmost is known to be used on any real devices) Let's just force the use of 0x80000000 for ecosystem consistency. Bug: 284334830 Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I199e9b00de845b3747940426ea6644426ab72e87
This commit is contained in:
@@ -317,6 +317,7 @@ import java.io.IOException;
|
|||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.lang.IllegalArgumentException;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@@ -441,6 +442,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ConnectivityResources mResources;
|
private final ConnectivityResources mResources;
|
||||||
|
private final int mWakeUpMark;
|
||||||
|
private final int mWakeUpMask;
|
||||||
// The Context is created for UserHandle.ALL.
|
// The Context is created for UserHandle.ALL.
|
||||||
private final Context mUserAllContext;
|
private final Context mUserAllContext;
|
||||||
private final Dependencies mDeps;
|
private final Dependencies mDeps;
|
||||||
@@ -1610,6 +1613,29 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mCellularRadioTimesharingCapable =
|
mCellularRadioTimesharingCapable =
|
||||||
mResources.get().getBoolean(R.bool.config_cellular_radio_timesharing_capable);
|
mResources.get().getBoolean(R.bool.config_cellular_radio_timesharing_capable);
|
||||||
|
|
||||||
|
int mark = mResources.get().getInteger(R.integer.config_networkWakeupPacketMark);
|
||||||
|
int mask = mResources.get().getInteger(R.integer.config_networkWakeupPacketMask);
|
||||||
|
|
||||||
|
if (SdkLevel.isAtLeastU()) {
|
||||||
|
// U+ default value of both mark & mask, this is the top bit of the skb->mark,
|
||||||
|
// see //system/netd/include/FwMark.h union Fwmark, field ingress_cpu_wakeup
|
||||||
|
final int defaultUMarkMask = 0x80000000; // u32
|
||||||
|
|
||||||
|
if ((mark == 0) || (mask == 0)) {
|
||||||
|
// simply treat unset/disabled as the default U value
|
||||||
|
mark = defaultUMarkMask;
|
||||||
|
mask = defaultUMarkMask;
|
||||||
|
}
|
||||||
|
if ((mark != defaultUMarkMask) || (mask != defaultUMarkMask)) {
|
||||||
|
// invalid device overlay settings
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Bad config_networkWakeupPacketMark/Mask " + mark + "/" + mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mWakeUpMark = mark;
|
||||||
|
mWakeUpMask = mask;
|
||||||
|
|
||||||
mNetd = netd;
|
mNetd = netd;
|
||||||
mBpfNetMaps = mDeps.getBpfNetMaps(mContext, netd);
|
mBpfNetMaps = mDeps.getBpfNetMaps(mContext, netd);
|
||||||
mHandlerThread = mDeps.makeHandlerThread();
|
mHandlerThread = mDeps.makeHandlerThread();
|
||||||
@@ -8088,21 +8114,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mark = mResources.get().getInteger(R.integer.config_networkWakeupPacketMark);
|
|
||||||
int mask = mResources.get().getInteger(R.integer.config_networkWakeupPacketMask);
|
|
||||||
|
|
||||||
// Mask/mark of zero will not detect anything interesting.
|
// Mask/mark of zero will not detect anything interesting.
|
||||||
// Don't install rules unless both values are nonzero.
|
// Don't install rules unless both values are nonzero.
|
||||||
if (mark == 0 || mask == 0) {
|
if (mWakeUpMark == 0 || mWakeUpMask == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String prefix = makeNflogPrefix(iface, nai.network.getNetworkHandle());
|
final String prefix = makeNflogPrefix(iface, nai.network.getNetworkHandle());
|
||||||
try {
|
try {
|
||||||
if (add) {
|
if (add) {
|
||||||
mNetd.wakeupAddInterface(iface, prefix, mark, mask);
|
mNetd.wakeupAddInterface(iface, prefix, mWakeUpMark, mWakeUpMask);
|
||||||
} else {
|
} else {
|
||||||
mNetd.wakeupDelInterface(iface, prefix, mark, mask);
|
mNetd.wakeupDelInterface(iface, prefix, mWakeUpMark, mWakeUpMask);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
loge("Exception modifying wakeup packet monitoring: " + e);
|
loge("Exception modifying wakeup packet monitoring: " + e);
|
||||||
|
|||||||
@@ -541,8 +541,7 @@ public class ConnectivityServiceTest {
|
|||||||
private static final int TEST_PACKAGE_UID2 = 321;
|
private static final int TEST_PACKAGE_UID2 = 321;
|
||||||
private static final int TEST_PACKAGE_UID3 = 456;
|
private static final int TEST_PACKAGE_UID3 = 456;
|
||||||
|
|
||||||
private static final int PACKET_WAKEUP_MASK = 0xffff0000;
|
private static final int PACKET_WAKEUP_MARK_MASK = 0x80000000;
|
||||||
private static final int PACKET_WAKEUP_MARK = 0x88880000;
|
|
||||||
|
|
||||||
private static final String ALWAYS_ON_PACKAGE = "com.android.test.alwaysonvpn";
|
private static final String ALWAYS_ON_PACKAGE = "com.android.test.alwaysonvpn";
|
||||||
|
|
||||||
@@ -1924,9 +1923,9 @@ public class ConnectivityServiceTest {
|
|||||||
doReturn(0).when(mResources).getInteger(R.integer.config_activelyPreferBadWifi);
|
doReturn(0).when(mResources).getInteger(R.integer.config_activelyPreferBadWifi);
|
||||||
doReturn(true).when(mResources)
|
doReturn(true).when(mResources)
|
||||||
.getBoolean(R.bool.config_cellular_radio_timesharing_capable);
|
.getBoolean(R.bool.config_cellular_radio_timesharing_capable);
|
||||||
doReturn(PACKET_WAKEUP_MASK).when(mResources).getInteger(
|
doReturn(PACKET_WAKEUP_MARK_MASK).when(mResources).getInteger(
|
||||||
R.integer.config_networkWakeupPacketMask);
|
R.integer.config_networkWakeupPacketMask);
|
||||||
doReturn(PACKET_WAKEUP_MARK).when(mResources).getInteger(
|
doReturn(PACKET_WAKEUP_MARK_MASK).when(mResources).getInteger(
|
||||||
R.integer.config_networkWakeupPacketMark);
|
R.integer.config_networkWakeupPacketMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18224,8 +18223,8 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
final String expectedPrefix = makeNflogPrefix(WIFI_IFNAME,
|
final String expectedPrefix = makeNflogPrefix(WIFI_IFNAME,
|
||||||
mWiFiAgent.getNetwork().getNetworkHandle());
|
mWiFiAgent.getNetwork().getNetworkHandle());
|
||||||
verify(mMockNetd).wakeupAddInterface(WIFI_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK,
|
verify(mMockNetd).wakeupAddInterface(WIFI_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK_MASK,
|
||||||
PACKET_WAKEUP_MASK);
|
PACKET_WAKEUP_MARK_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -18238,8 +18237,8 @@ public class ConnectivityServiceTest {
|
|||||||
if (mDeps.isAtLeastU()) {
|
if (mDeps.isAtLeastU()) {
|
||||||
final String expectedPrefix = makeNflogPrefix(MOBILE_IFNAME,
|
final String expectedPrefix = makeNflogPrefix(MOBILE_IFNAME,
|
||||||
mCellAgent.getNetwork().getNetworkHandle());
|
mCellAgent.getNetwork().getNetworkHandle());
|
||||||
verify(mMockNetd).wakeupAddInterface(MOBILE_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK,
|
verify(mMockNetd).wakeupAddInterface(MOBILE_IFNAME, expectedPrefix,
|
||||||
PACKET_WAKEUP_MASK);
|
PACKET_WAKEUP_MARK_MASK, PACKET_WAKEUP_MARK_MASK);
|
||||||
} else {
|
} else {
|
||||||
verify(mMockNetd, never()).wakeupAddInterface(eq(MOBILE_IFNAME), anyString(), anyInt(),
|
verify(mMockNetd, never()).wakeupAddInterface(eq(MOBILE_IFNAME), anyString(), anyInt(),
|
||||||
anyInt());
|
anyInt());
|
||||||
|
|||||||
Reference in New Issue
Block a user