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
3897aaf7
Commit
3897aaf7
authored
1 year ago
by
Maciej Żenczykowski
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "[Refactor] Make uid owner match comparison logic into a function" into main
parents
462572b2
f7d23e1a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bpf_progs/netd.c
+1
-11
1 addition, 11 deletions
bpf_progs/netd.c
bpf_progs/netd.h
+14
-0
14 additions, 0 deletions
bpf_progs/netd.h
with
15 additions
and
11 deletions
bpf_progs/netd.c
+
1
−
11
View file @
3897aaf7
...
...
@@ -401,11 +401,6 @@ static __always_inline inline bool ingress_should_discard(struct __sk_buff* skb,
return
true
;
// disallowed interface
}
// DROP_IF_SET is set of rules that DROP if rule is globally enabled, and per-uid bit is set
#define DROP_IF_SET (STANDBY_MATCH | OEM_DENY_1_MATCH | OEM_DENY_2_MATCH | OEM_DENY_3_MATCH)
// DROP_IF_UNSET is set of rules that should DROP if globally enabled, and per-uid bit is NOT set
#define DROP_IF_UNSET (DOZABLE_MATCH | POWERSAVE_MATCH | RESTRICTED_MATCH | LOW_POWER_STANDBY_MATCH)
static
__always_inline
inline
int
bpf_owner_match
(
struct
__sk_buff
*
skb
,
uint32_t
uid
,
bool
egress
,
const
unsigned
kver
)
{
if
(
is_system_uid
(
uid
))
return
PASS
;
...
...
@@ -418,12 +413,7 @@ static __always_inline inline int bpf_owner_match(struct __sk_buff* skb, uint32_
uint32_t
uidRules
=
uidEntry
?
uidEntry
->
rule
:
0
;
uint32_t
allowed_iif
=
uidEntry
?
uidEntry
->
iif
:
0
;
// Warning: funky bit-wise arithmetic: in parallel, for all DROP_IF_SET/UNSET rules
// check whether the rules are globally enabled, and if so whether the rules are
// set/unset for the specific uid. DROP if that is the case for ANY of the rules.
// We achieve this by masking out only the bits/rules we're interested in checking,
// and negating (via bit-wise xor) the bits/rules that should drop if unset.
if
(
enabledRules
&
(
DROP_IF_SET
|
DROP_IF_UNSET
)
&
(
uidRules
^
DROP_IF_UNSET
))
return
DROP
;
if
(
isBlockedByUidRules
(
enabledRules
,
uidRules
))
return
DROP
;
if
(
!
egress
&&
skb
->
ifindex
!=
1
)
{
if
(
ingress_should_discard
(
skb
,
kver
))
return
DROP
;
...
...
This diff is collapsed.
Click to expand it.
bpf_progs/netd.h
+
14
−
0
View file @
3897aaf7
...
...
@@ -235,3 +235,17 @@ STRUCT_SIZE(IngressDiscardValue, 2 * 4); // 8
#define CURRENT_STATS_MAP_CONFIGURATION_KEY 1
#undef STRUCT_SIZE
// DROP_IF_SET is set of rules that DROP if rule is globally enabled, and per-uid bit is set
#define DROP_IF_SET (STANDBY_MATCH | OEM_DENY_1_MATCH | OEM_DENY_2_MATCH | OEM_DENY_3_MATCH)
// DROP_IF_UNSET is set of rules that should DROP if globally enabled, and per-uid bit is NOT set
#define DROP_IF_UNSET (DOZABLE_MATCH | POWERSAVE_MATCH | RESTRICTED_MATCH | LOW_POWER_STANDBY_MATCH)
// Warning: funky bit-wise arithmetic: in parallel, for all DROP_IF_SET/UNSET rules
// check whether the rules are globally enabled, and if so whether the rules are
// set/unset for the specific uid. DROP if that is the case for ANY of the rules.
// We achieve this by masking out only the bits/rules we're interested in checking,
// and negating (via bit-wise xor) the bits/rules that should drop if unset.
static
inline
bool
isBlockedByUidRules
(
BpfConfig
enabledRules
,
uint32_t
uidRules
)
{
return
enabledRules
&
(
DROP_IF_SET
|
DROP_IF_UNSET
)
&
(
uidRules
^
DROP_IF_UNSET
);
}
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