Merge "Set default value to bpf maps with Java Bpf Map"

This commit is contained in:
Motomu Utsumi
2022-08-03 07:41:52 +00:00
committed by Gerrit Code Review
2 changed files with 25 additions and 7 deletions

View File

@@ -173,13 +173,8 @@ Status TrafficController::initMaps() {
RETURN_IF_NOT_OK(mIfaceStatsMap.init(IFACE_STATS_MAP_PATH)); RETURN_IF_NOT_OK(mIfaceStatsMap.init(IFACE_STATS_MAP_PATH));
RETURN_IF_NOT_OK(mConfigurationMap.init(CONFIGURATION_MAP_PATH)); RETURN_IF_NOT_OK(mConfigurationMap.init(CONFIGURATION_MAP_PATH));
RETURN_IF_NOT_OK(
mConfigurationMap.writeValue(UID_RULES_CONFIGURATION_KEY, DEFAULT_CONFIG, BPF_ANY));
RETURN_IF_NOT_OK(mConfigurationMap.writeValue(CURRENT_STATS_MAP_CONFIGURATION_KEY, SELECT_MAP_A,
BPF_ANY));
RETURN_IF_NOT_OK(mUidOwnerMap.init(UID_OWNER_MAP_PATH)); RETURN_IF_NOT_OK(mUidOwnerMap.init(UID_OWNER_MAP_PATH));
RETURN_IF_NOT_OK(mUidOwnerMap.clear());
RETURN_IF_NOT_OK(mUidPermissionMap.init(UID_PERMISSION_MAP_PATH)); RETURN_IF_NOT_OK(mUidPermissionMap.init(UID_PERMISSION_MAP_PATH));
ALOGI("%s successfully", __func__); ALOGI("%s successfully", __func__);

View File

@@ -87,6 +87,11 @@ public class BpfNetMaps {
private static final String UID_OWNER_MAP_PATH = private static final String UID_OWNER_MAP_PATH =
"/sys/fs/bpf/netd_shared/map_netd_uid_owner_map"; "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map";
private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0); private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0);
private static final U32 CURRENT_STATS_MAP_CONFIGURATION_KEY = new U32(1);
private static final long UID_RULES_DEFAULT_CONFIGURATION = 0;
private static final long STATS_SELECT_MAP_A = 0;
private static final long STATS_SELECT_MAP_B = 1;
private static BpfMap<U32, U32> sConfigurationMap = null; private static BpfMap<U32, U32> sConfigurationMap = null;
// BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others. // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null; private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
@@ -149,13 +154,31 @@ public class BpfNetMaps {
} }
} }
private static void setBpfMaps() { private static void initBpfMaps() {
if (sConfigurationMap == null) { if (sConfigurationMap == null) {
sConfigurationMap = getConfigurationMap(); sConfigurationMap = getConfigurationMap();
} }
try {
sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY,
new U32(UID_RULES_DEFAULT_CONFIGURATION));
} catch (ErrnoException e) {
throw new IllegalStateException("Failed to initialize uid rules configuration", e);
}
try {
sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
new U32(STATS_SELECT_MAP_A));
} catch (ErrnoException e) {
throw new IllegalStateException("Failed to initialize current stats configuration", e);
}
if (sUidOwnerMap == null) { if (sUidOwnerMap == null) {
sUidOwnerMap = getUidOwnerMap(); sUidOwnerMap = getUidOwnerMap();
} }
try {
sUidOwnerMap.clear();
} catch (ErrnoException e) {
throw new IllegalStateException("Failed to initialize uid owner map", e);
}
} }
/** /**
@@ -171,7 +194,7 @@ public class BpfNetMaps {
} }
Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap); Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap);
setBpfMaps(); initBpfMaps();
native_init(); native_init();
sInitialized = true; sInitialized = true;
} }