[NETD-BPF#34] Add a tag for bpf to specify the install folder
Currently, the bpf module netd.o (source system/netd/bpf_progs/netd.c) will be built to /system/etc/bpf/netd.o. In Android T, it will be moved to mainline module com.android.tethering. The expected behavior is: - In T device, it uses the netd.o in mainline module. - In pre-T devices, it uses the original netd, built from platform. However, netd.o will be double loaded if the tethering module is installed in Pre-T devices. Because: 1. bpf in apex is packed into /apex/MAINLINE_MODULE/etc/bpf/ 2. bpf in platform is packed into /system/etc/bpf/ 3. bpfloader in pre-T loads ANY bpf modules under /apex/com.android.tethering/etc/bpf/ and /system/etc/bpf/. We can't change the behavior of bpfloader in pre-T devices. We can't delete the /system/etc/bpf/netd.o from pre-T devices. Both of them are not mainline modules. So the mainlined netd.o needs to be packed into a folder other than /apex/com.android.tethering/etc/bpf/ or /system/etc/bpf/. This commit adds a tag 'sub_dir' for bpf module. The installation path of bpf modules will be: - /system/etc/bpf/SUB_DIR/ (for platform code) - /apex/MAINLINE_MODULE/etc/bpf/SUB_DIR/ (for mainline module) Bug: 202086915 Test: add test in apex_test.go and build Change-Id: Icc6619768ab006de9f86620a7df1bb2853eaba13
This commit is contained in:
committed by
Maciej Żenczykowski
parent
2a524318e4
commit
fad7f9d8b7
@@ -1574,8 +1574,8 @@ func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.R
|
|||||||
return af
|
return af
|
||||||
}
|
}
|
||||||
|
|
||||||
func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
|
func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
|
||||||
dirInApex := filepath.Join("etc", "bpf")
|
dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
|
||||||
return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
|
return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1784,8 +1784,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
case bpfTag:
|
case bpfTag:
|
||||||
if bpfProgram, ok := child.(bpf.BpfModule); ok {
|
if bpfProgram, ok := child.(bpf.BpfModule); ok {
|
||||||
filesToCopy, _ := bpfProgram.OutputFiles("")
|
filesToCopy, _ := bpfProgram.OutputFiles("")
|
||||||
|
apex_sub_dir := bpfProgram.SubDir()
|
||||||
for _, bpfFile := range filesToCopy {
|
for _, bpfFile := range filesToCopy {
|
||||||
filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
|
filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
|
ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
|
||||||
|
@@ -621,7 +621,7 @@ func TestDefaults(t *testing.T) {
|
|||||||
java_libs: ["myjar"],
|
java_libs: ["myjar"],
|
||||||
apps: ["AppFoo"],
|
apps: ["AppFoo"],
|
||||||
rros: ["rro"],
|
rros: ["rro"],
|
||||||
bpfs: ["bpf"],
|
bpfs: ["bpf", "netd_test"],
|
||||||
updatable: false,
|
updatable: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,6 +674,12 @@ func TestDefaults(t *testing.T) {
|
|||||||
srcs: ["bpf.c", "bpf2.c"],
|
srcs: ["bpf.c", "bpf2.c"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bpf {
|
||||||
|
name: "netd_test",
|
||||||
|
srcs: ["netd_test.c"],
|
||||||
|
sub_dir: "netd",
|
||||||
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
||||||
"etc/myetc",
|
"etc/myetc",
|
||||||
@@ -683,6 +689,7 @@ func TestDefaults(t *testing.T) {
|
|||||||
"overlay/blue/rro.apk",
|
"overlay/blue/rro.apk",
|
||||||
"etc/bpf/bpf.o",
|
"etc/bpf/bpf.o",
|
||||||
"etc/bpf/bpf2.o",
|
"etc/bpf/bpf2.o",
|
||||||
|
"etc/bpf/netd/netd_test.o",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
bpf/bpf.go
14
bpf/bpf.go
@@ -54,12 +54,16 @@ type BpfModule interface {
|
|||||||
android.Module
|
android.Module
|
||||||
|
|
||||||
OutputFiles(tag string) (android.Paths, error)
|
OutputFiles(tag string) (android.Paths, error)
|
||||||
|
|
||||||
|
// Returns the sub install directory if the bpf module is included by apex.
|
||||||
|
SubDir() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type BpfProperties struct {
|
type BpfProperties struct {
|
||||||
Srcs []string `android:"path"`
|
Srcs []string `android:"path"`
|
||||||
Cflags []string
|
Cflags []string
|
||||||
Include_dirs []string
|
Include_dirs []string
|
||||||
|
Sub_dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
type bpf struct {
|
type bpf struct {
|
||||||
@@ -121,6 +125,10 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w)
|
fmt.Fprintln(w)
|
||||||
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
||||||
fmt.Fprintln(w)
|
fmt.Fprintln(w)
|
||||||
|
localModulePath := "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf"
|
||||||
|
if len(bpf.properties.Sub_dir) > 0 {
|
||||||
|
localModulePath += "/" + bpf.properties.Sub_dir
|
||||||
|
}
|
||||||
for _, obj := range bpf.objs {
|
for _, obj := range bpf.objs {
|
||||||
objName := name + "_" + obj.Base()
|
objName := name + "_" + obj.Base()
|
||||||
names = append(names, objName)
|
names = append(names, objName)
|
||||||
@@ -130,7 +138,7 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
|
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
|
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
|
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf")
|
fmt.Fprintln(w, localModulePath)
|
||||||
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
|
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
|
||||||
fmt.Fprintln(w)
|
fmt.Fprintln(w)
|
||||||
}
|
}
|
||||||
@@ -154,6 +162,10 @@ func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bpf *bpf) SubDir() string {
|
||||||
|
return bpf.properties.Sub_dir
|
||||||
|
}
|
||||||
|
|
||||||
var _ android.OutputFileProducer = (*bpf)(nil)
|
var _ android.OutputFileProducer = (*bpf)(nil)
|
||||||
|
|
||||||
func BpfFactory() android.Module {
|
func BpfFactory() android.Module {
|
||||||
|
Reference in New Issue
Block a user