]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/bpf-restrict-ifaces: avoid duplicate unit_get_cgroup_runtime() call
authorMike Yuan <me@yhndnzj.com>
Wed, 24 Dec 2025 18:17:57 +0000 (19:17 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 27 Dec 2025 19:14:57 +0000 (20:14 +0100)
src/core/bpf-restrict-ifaces.c

index 29df72f2b06dcb1aa68765695869367f6d10c9a1..a1bac8301be34ca7a807341f3ead0e559e613bca 100644 (file)
@@ -98,22 +98,17 @@ int bpf_restrict_ifaces_supported(void) {
         return (supported = bpf_can_link_program(obj->progs.sd_restrictif_i));
 }
 
-static int restrict_ifaces_install_impl(Unit *u) {
+static int restrict_ifaces_install_impl(Unit *u, CGroupRuntime *crt) {
         _cleanup_(bpf_link_freep) struct bpf_link *egress_link = NULL, *ingress_link = NULL;
         _cleanup_(restrict_ifaces_bpf_freep) struct restrict_ifaces_bpf *obj = NULL;
         _cleanup_free_ char *cgroup_path = NULL;
         _cleanup_close_ int cgroup_fd = -EBADF;
-        CGroupContext *cc;
-        CGroupRuntime *crt;
         int r;
 
-        cc = unit_get_cgroup_context(u);
-        if (!cc)
-                return 0;
+        assert(u);
+        assert(crt);
 
-        crt = unit_get_cgroup_runtime(u);
-        if (!crt)
-                return 0;
+        CGroupContext *cc = ASSERT_PTR(unit_get_cgroup_context(u));
 
         r = cg_get_path(crt->cgroup_path, /* suffix= */ NULL, &cgroup_path);
         if (r < 0)
@@ -159,7 +154,7 @@ int bpf_restrict_ifaces_install(Unit *u) {
         if (!crt)
                 return 0;
 
-        r = restrict_ifaces_install_impl(u);
+        r = restrict_ifaces_install_impl(u, crt);
         fdset_close(crt->initial_restrict_ifaces_link_fds, /* async= */ false);
         return r;
 }