24Q2: use mainline netbpfload from apex

(also monitor https://pitot.corp.google.com/clusters?release=public-all&comparison=target&device_view=ALL_DEVICES&duration=56&clusters.search=BpfLoaderRcUtils )

See also:
  https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2956635
  netbpfload: enable on U QPR2 (aka 24Q1)  [target May mainline]

Test: TreeHugger, atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfLoaderRcUtilsTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie9e0f90321265f33a23deb03b403fb73b6a1db05
This commit is contained in:
Maciej Żenczykowski 2024-02-07 00:43:25 +00:00
commit 13b5e1ff29
2 changed files with 24 additions and 12 deletions

View file

@ -17,7 +17,7 @@
on load_bpf_programs
exec_start bpfloader
service bpfloader /system/bin/netbpfload
service bpfloader /apex/com.android.tethering/bin/netbpfload
# netbpfload will do network bpf loading, then execute /system/bin/bpfloader
capabilities CHOWN SYS_ADMIN NET_ADMIN
# The following group memberships are a workaround for lack of DAC_OVERRIDE

View file

@ -72,6 +72,17 @@ public class BpfLoaderRcUtils {
"updatable"
);
private static final List<String> BPF_LOADER_RC_UQPR3 = List.of(
"service bpfloader /apex/com.android.tethering/bin/netbpfload",
"capabilities CHOWN SYS_ADMIN NET_ADMIN",
"group root graphics network_stack net_admin net_bw_acct net_bw_stats net_raw system",
"user root",
"rlimit memlock 1073741824 1073741824",
"oneshot",
"reboot_on_failure reboot,bpfloader-failed",
"updatable"
);
private static final String BPF_LOADER_RC_FILE_PATH = "/etc/init/bpfloader.rc";
private static final String NET_BPF_LOAD_RC_FILE_PATH = "/etc/init/netbpfload.rc";
@ -132,30 +143,31 @@ public class BpfLoaderRcUtils {
+ " exist.");
return false;
}
// Check bpf rc file in U QPR2
return compareBpfLoaderRc(bpfRcFile, BPF_LOADER_RC_UQPR2);
// Check bpf rc file in U QPR2 and U QPR3
return compareBpfLoaderRc(bpfRcFile, List.of(BPF_LOADER_RC_UQPR2, BPF_LOADER_RC_UQPR3));
}
if (SdkLevel.isAtLeastU()) {
// Check bpf rc file in U
return compareBpfLoaderRc(bpfRcFile, BPF_LOADER_RC_U);
return compareBpfLoaderRc(bpfRcFile, List.of(BPF_LOADER_RC_U));
}
// Check bpf rc file in S/T
return compareBpfLoaderRc(bpfRcFile, BPF_LOADER_RC_S_T);
return compareBpfLoaderRc(bpfRcFile, List.of(BPF_LOADER_RC_S_T));
}
private static boolean compareBpfLoaderRc(@NonNull File bpfRcFile,
@NonNull List<String> template) {
@NonNull List<List<String>> templates) {
List<String> actualContent;
try {
List<String> actualContent = loadExistingBpfRcFile(new FileInputStream(bpfRcFile));
if (!actualContent.equals(template)) {
Log.wtf(TAG, "BPF rc file is not same as the template files " + actualContent);
return false;
}
actualContent = loadExistingBpfRcFile(new FileInputStream(bpfRcFile));
} catch (FileNotFoundException e) {
Log.wtf(bpfRcFile.getPath() + " doesn't exist.", e);
return false;
}
return true;
for (List<String> template : templates) {
if (actualContent.equals(template)) return true;
}
Log.wtf(TAG, "BPF rc file is not same as the template files " + actualContent);
return false;
}
}