bpf-firewall: custom BPF programs through IP(Ingress|Egress)FilterPath=
Takes a single /sys/fs/bpf/pinned_prog string as argument, but may be specified multiple times. An empty assignment resets all previous filters. Closes https://github.com/systemd/systemd/issues/10227
This commit is contained in:
committed by
Lennart Poettering
parent
2d901d33a9
commit
fab347489f
@@ -94,6 +94,25 @@ int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path) {
|
||||
union bpf_attr attr;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (p->kernel_fd >= 0) /* don't overwrite an assembled or loaded program */
|
||||
return -EBUSY;
|
||||
|
||||
attr = (union bpf_attr) {
|
||||
.pathname = PTR_TO_UINT64(path),
|
||||
};
|
||||
|
||||
p->kernel_fd = bpf(BPF_OBJ_GET, &attr, sizeof(attr));
|
||||
if (p->kernel_fd < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags) {
|
||||
_cleanup_free_ char *copy = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
@@ -31,6 +31,7 @@ BPFProgram *bpf_program_ref(BPFProgram *p);
|
||||
|
||||
int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *insn, size_t count);
|
||||
int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size);
|
||||
int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path);
|
||||
|
||||
int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags);
|
||||
int bpf_program_cgroup_detach(BPFProgram *p);
|
||||
|
||||
@@ -758,6 +758,18 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (STR_IN_SET(field, "IPIngressFilterPath", "IPEgressFilterPath")) {
|
||||
if (isempty(eq))
|
||||
r = sd_bus_message_append(m, "(sv)", field, "as", 0);
|
||||
else
|
||||
r = sd_bus_message_append(m, "(sv)", field, "as", 1, eq);
|
||||
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user