bpf-firewall: give a name to maps used
Running systemd with IP accounting enabled generates many bpf maps (two
per unit for accounting, another two if IPAddressAllow/Deny are used).
Systemd itself knows which maps belong to what unit and commands like
`systemctl status <unit>` can be used to query what service has which
map, but monitoring these values all the time costs 4 dbus requests
(calling the .IP{E,I}gress{Bytes,Packets} method for each unit) and
makes services like the prometheus systemd_exporter[1] somewhat slow
when doing that for every units, while less precise information could
quickly be obtained by looking directly at the maps.
Unfortunately, bpf map names are rather limited:
- only 15 characters in length (16, but last byte must be 0)
- only allows isalnum(), _ and . characters
If it wasn't for the length limit we could use the normal unit escape
functions but I've opted to just make any forbidden character into
underscores for maximum brievty -- the map prefix is also rather short:
This isn't meant as a precise mapping, but as a hint for admins who want
to look at these.
(Note there is no problem if multiple maps have the same name)
Link: https://github.com/povilasv/systemd_exporter [1]
This commit is contained in:
committed by
Yu Watanabe
parent
38cdd08b22
commit
25d9c6cdaf
@@ -451,7 +451,9 @@ static int bpf_firewall_prepare_access_maps(
|
||||
}
|
||||
|
||||
if (n_ipv4 > 0) {
|
||||
char *name = strjoina("4_", u->id);
|
||||
ipv4_map_fd = bpf_map_new(
|
||||
name,
|
||||
BPF_MAP_TYPE_LPM_TRIE,
|
||||
offsetof(struct bpf_lpm_trie_key, data) + sizeof(uint32_t),
|
||||
sizeof(uint64_t),
|
||||
@@ -462,7 +464,9 @@ static int bpf_firewall_prepare_access_maps(
|
||||
}
|
||||
|
||||
if (n_ipv6 > 0) {
|
||||
char *name = strjoina("6_", u->id);
|
||||
ipv6_map_fd = bpf_map_new(
|
||||
name,
|
||||
BPF_MAP_TYPE_LPM_TRIE,
|
||||
offsetof(struct bpf_lpm_trie_key, data) + sizeof(uint32_t)*4,
|
||||
sizeof(uint64_t),
|
||||
@@ -500,7 +504,8 @@ static int bpf_firewall_prepare_accounting_maps(Unit *u, bool enabled, int *fd_i
|
||||
|
||||
if (enabled) {
|
||||
if (*fd_ingress < 0) {
|
||||
r = bpf_map_new(BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(uint64_t), 2, 0);
|
||||
char *name = strjoina("I_", u->id);
|
||||
r = bpf_map_new(name, BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(uint64_t), 2, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -508,8 +513,8 @@ static int bpf_firewall_prepare_accounting_maps(Unit *u, bool enabled, int *fd_i
|
||||
}
|
||||
|
||||
if (*fd_egress < 0) {
|
||||
|
||||
r = bpf_map_new(BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(uint64_t), 2, 0);
|
||||
char *name = strjoina("E_", u->id);
|
||||
r = bpf_map_new(name, BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(uint64_t), 2, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user