Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_packages_modules_Connectivity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LMODroid
platform_packages_modules_Connectivity
Commits
ed353e90
Commit
ed353e90
authored
1 year ago
by
Ken Chen
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "Return error Status from BpfHandler::initPrograms()" into main
parents
9a966eab
d6ea75ac
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
netd/BpfHandler.cpp
+11
-29
11 additions, 29 deletions
netd/BpfHandler.cpp
netd/NetdUpdatable.cpp
+1
-1
1 addition, 1 deletion
netd/NetdUpdatable.cpp
staticlibs/netd/libnetdutils/include/netdutils/Status.h
+3
-0
3 additions, 0 deletions
staticlibs/netd/libnetdutils/include/netdutils/Status.h
with
15 additions
and
30 deletions
netd/BpfHandler.cpp
+
11
−
29
View file @
ed353e90
...
...
@@ -53,14 +53,10 @@ static Status attachProgramToCgroup(const char* programPath, const unique_fd& cg
bpf_attach_type
type
)
{
unique_fd
cgroupProg
(
retrieveProgram
(
programPath
));
if
(
!
cgroupProg
.
ok
())
{
const
int
err
=
errno
;
ALOGE
(
"Failed to get program from %s: %s"
,
programPath
,
strerror
(
err
));
return
statusFromErrno
(
err
,
"cgroup program get failed"
);
return
statusFromErrno
(
errno
,
fmt
::
format
(
"Failed to get program from {}"
,
programPath
));
}
if
(
android
::
bpf
::
attachProgram
(
type
,
cgroupProg
,
cgroupFd
))
{
const
int
err
=
errno
;
ALOGE
(
"Program from %s attach failed: %s"
,
programPath
,
strerror
(
err
));
return
statusFromErrno
(
err
,
"program attach failed"
);
return
statusFromErrno
(
errno
,
fmt
::
format
(
"Program {} attach failed"
,
programPath
));
}
return
netdutils
::
status
::
ok
;
}
...
...
@@ -68,50 +64,38 @@ static Status attachProgramToCgroup(const char* programPath, const unique_fd& cg
static
Status
checkProgramAccessible
(
const
char
*
programPath
)
{
unique_fd
prog
(
retrieveProgram
(
programPath
));
if
(
!
prog
.
ok
())
{
const
int
err
=
errno
;
ALOGE
(
"Failed to get program from %s: %s"
,
programPath
,
strerror
(
err
));
return
statusFromErrno
(
err
,
"program retrieve failed"
);
return
statusFromErrno
(
errno
,
fmt
::
format
(
"Failed to get program from {}"
,
programPath
));
}
return
netdutils
::
status
::
ok
;
}
static
Status
initPrograms
(
const
char
*
cg2_path
)
{
if
(
!
cg2_path
)
{
ALOGE
(
"cg2_path is NULL"
);
return
statusFromErrno
(
EINVAL
,
"cg2_path is NULL"
);
}
if
(
!
cg2_path
)
return
Status
(
"cg2_path is NULL"
);
// This code was mainlined in T, so this should be trivially satisfied.
if
(
!
modules
::
sdklevel
::
IsAtLeastT
())
{
ALOGE
(
"S- platform is unsupported"
);
abort
();
}
if
(
!
modules
::
sdklevel
::
IsAtLeastT
())
return
Status
(
"S- platform is unsupported"
);
// S requires eBPF support which was only added in 4.9, so this should be satisfied.
if
(
!
bpf
::
isAtLeastKernelVersion
(
4
,
9
,
0
))
{
ALOGE
(
"kernel version < 4.9.0 is unsupported"
);
abort
();
return
Status
(
"kernel version < 4.9.0 is unsupported"
);
}
// U bumps the kernel requirement up to 4.14
if
(
modules
::
sdklevel
::
IsAtLeastU
()
&&
!
bpf
::
isAtLeastKernelVersion
(
4
,
14
,
0
))
{
ALOGE
(
"U+ platform with kernel version < 4.14.0 is unsupported"
);
abort
();
return
Status
(
"U+ platform with kernel version < 4.14.0 is unsupported"
);
}
if
(
modules
::
sdklevel
::
IsAtLeastV
())
{
// V bumps the kernel requirement up to 4.19
// see also: //system/netd/tests/kernel_test.cpp TestKernel419
if
(
!
bpf
::
isAtLeastKernelVersion
(
4
,
19
,
0
))
{
ALOGE
(
"V+ platform with kernel version < 4.19.0 is unsupported"
);
abort
();
return
Status
(
"V+ platform with kernel version < 4.19.0 is unsupported"
);
}
// Technically already required by U, but only enforce on V+
// see also: //system/netd/tests/kernel_test.cpp TestKernel64Bit
if
(
bpf
::
isKernel32Bit
()
&&
bpf
::
isAtLeastKernelVersion
(
5
,
16
,
0
))
{
ALOGE
(
"V+ platform with 32 bit kernel, version >= 5.16.0 is unsupported"
);
abort
();
return
Status
(
"V+ platform with 32 bit kernel, version >= 5.16.0 is unsupported"
);
}
}
...
...
@@ -123,14 +107,12 @@ static Status initPrograms(const char* cg2_path) {
// problems are AFAIK limited to various CAP_NET_ADMIN protected interfaces.
// see also: //system/bpf/bpfloader/BpfLoader.cpp main()
if
(
bpf
::
isUserspace32bit
()
&&
bpf
::
isAtLeastKernelVersion
(
6
,
2
,
0
))
{
ALOGE
(
"32 bit userspace with Kernel version >= 6.2.0 is unsupported"
);
abort
();
return
Status
(
"32 bit userspace with Kernel version >= 6.2.0 is unsupported"
);
}
// U mandates this mount point (though it should also be the case on T)
if
(
modules
::
sdklevel
::
IsAtLeastU
()
&&
!!
strcmp
(
cg2_path
,
"/sys/fs/cgroup"
))
{
ALOGE
(
"U+ platform with cg2_path != /sys/fs/cgroup is unsupported"
);
abort
();
return
Status
(
"U+ platform with cg2_path != /sys/fs/cgroup is unsupported"
);
}
unique_fd
cg_fd
(
open
(
cg2_path
,
O_DIRECTORY
|
O_RDONLY
|
O_CLOEXEC
));
...
...
This diff is collapsed.
Click to expand it.
netd/NetdUpdatable.cpp
+
1
−
1
View file @
ed353e90
...
...
@@ -31,7 +31,7 @@ int libnetd_updatable_init(const char* cg2_path) {
android
::
netdutils
::
Status
ret
=
sBpfHandler
.
init
(
cg2_path
);
if
(
!
android
::
netdutils
::
isOk
(
ret
))
{
LOG
(
ERROR
)
<<
__func__
<<
":
BPF handler init failed"
;
LOG
(
ERROR
)
<<
__func__
<<
":
Failed. "
<<
ret
.
code
()
<<
" "
<<
ret
.
msg
()
;
return
-
ret
.
code
();
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
staticlibs/netd/libnetdutils/include/netdutils/Status.h
+
3
−
0
View file @
ed353e90
...
...
@@ -41,6 +41,9 @@ class [[nodiscard]] Status {
// Constructs an error Status, |code| must be non-zero.
Status
(
int
code
,
std
::
string
msg
)
:
mCode
(
code
),
mMsg
(
std
::
move
(
msg
))
{
assert
(
!
ok
());
}
// Constructs an error Status with message. Error |code| is unspecified.
explicit
Status
(
std
::
string
msg
)
:
Status
(
std
::
numeric_limits
<
int
>::
max
(),
std
::
move
(
msg
))
{}
Status
(
android
::
base
::
Result
<
void
>
result
)
:
mCode
(
result
.
ok
()
?
0
:
static_cast
<
int
>
(
result
.
error
().
code
())),
mMsg
(
result
.
ok
()
?
""
:
result
.
error
().
message
())
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment