mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 00:51:24 +03:00
core: add bpf-foreign to fragment parser
- Parse a string for bpf attach type - Simplify bpffs path - Add foreign bpf program to cgroup context
This commit is contained in:
parent
506ea51b48
commit
0879da98dc
@ -234,7 +234,8 @@ $1.ManagedOOMSwap, config_parse_managed_oom_mode,
|
|||||||
$1.ManagedOOMMemoryPressure, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_mem_pressure)
|
$1.ManagedOOMMemoryPressure, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_mem_pressure)
|
||||||
$1.ManagedOOMMemoryPressureLimit, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context.moom_mem_pressure_limit)
|
$1.ManagedOOMMemoryPressureLimit, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context.moom_mem_pressure_limit)
|
||||||
$1.ManagedOOMPreference, config_parse_managed_oom_preference, 0, offsetof($1, cgroup_context.moom_preference)
|
$1.ManagedOOMPreference, config_parse_managed_oom_preference, 0, offsetof($1, cgroup_context.moom_preference)
|
||||||
$1.NetClass, config_parse_warn_compat, DISABLED_LEGACY, 0'
|
$1.NetClass, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||||
|
$1.BPFProgram, config_parse_bpf_foreign_program, 0, offsetof($1, cgroup_context)'
|
||||||
)m4_dnl
|
)m4_dnl
|
||||||
Unit.Description, config_parse_unit_string_printf, 0, offsetof(Unit, description)
|
Unit.Description, config_parse_unit_string_printf, 0, offsetof(Unit, description)
|
||||||
Unit.Documentation, config_parse_documentation, 0, offsetof(Unit, documentation)
|
Unit.Documentation, config_parse_documentation, 0, offsetof(Unit, documentation)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "all-units.h"
|
#include "all-units.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bpf-firewall.h"
|
#include "bpf-firewall.h"
|
||||||
|
#include "bpf-program.h"
|
||||||
#include "bus-error.h"
|
#include "bus-error.h"
|
||||||
#include "bus-internal.h"
|
#include "bus-internal.h"
|
||||||
#include "bus-util.h"
|
#include "bus-util.h"
|
||||||
@ -5581,6 +5582,64 @@ int config_parse_ip_filter_bpf_progs(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int config_parse_bpf_foreign_program(
|
||||||
|
const char *unit,
|
||||||
|
const char *filename,
|
||||||
|
unsigned line,
|
||||||
|
const char *section,
|
||||||
|
unsigned section_line,
|
||||||
|
const char *lvalue,
|
||||||
|
int ltype,
|
||||||
|
const char *rvalue,
|
||||||
|
void *data,
|
||||||
|
void *userdata) {
|
||||||
|
_cleanup_free_ char *resolved = NULL, *word = NULL;
|
||||||
|
CGroupContext *c = data;
|
||||||
|
Unit *u = userdata;
|
||||||
|
int attach_type, r;
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
assert(lvalue);
|
||||||
|
assert(rvalue);
|
||||||
|
|
||||||
|
if (isempty(rvalue)) {
|
||||||
|
while (c->bpf_foreign_programs)
|
||||||
|
cgroup_context_remove_bpf_foreign_program(c, c->bpf_foreign_programs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = extract_first_word(&rvalue, &word, ":", 0);
|
||||||
|
if (r == -ENOMEM)
|
||||||
|
return log_oom();
|
||||||
|
if (r < 0) {
|
||||||
|
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
attach_type = bpf_cgroup_attach_type_from_string(word);
|
||||||
|
if (attach_type < 0) {
|
||||||
|
log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown BPF attach type=%s, ignoring: %s", word, rvalue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = unit_full_printf(u, rvalue, &resolved);
|
||||||
|
if (r < 0) {
|
||||||
|
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
|
||||||
|
if (r < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
r = cgroup_add_bpf_foreign_program(c, attach_type, resolved);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to add foreign BPF program to cgroup context: %m");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int merge_by_names(Unit **u, Set *names, const char *id) {
|
static int merge_by_names(Unit **u, Set *names, const char *id) {
|
||||||
char *k;
|
char *k;
|
||||||
int r;
|
int r;
|
||||||
|
@ -140,6 +140,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_swap_priority);
|
|||||||
CONFIG_PARSER_PROTOTYPE(config_parse_mount_images);
|
CONFIG_PARSER_PROTOTYPE(config_parse_mount_images);
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_socket_timestamping);
|
CONFIG_PARSER_PROTOTYPE(config_parse_socket_timestamping);
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_extension_images);
|
CONFIG_PARSER_PROTOTYPE(config_parse_extension_images);
|
||||||
|
CONFIG_PARSER_PROTOTYPE(config_parse_bpf_foreign_program);
|
||||||
|
|
||||||
/* gperf prototypes */
|
/* gperf prototypes */
|
||||||
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
|
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
|
||||||
|
Loading…
Reference in New Issue
Block a user