free(p);
}
+void cgroup_context_remove_socket_bind(CGroupSocketBindItem **head) {
+ CGroupSocketBindItem *h;
+
+ assert(head);
+
+ while (*head) {
+ h = *head;
+ LIST_REMOVE(socket_bind_items, *head, h);
+ free(h);
+ }
+}
+
void cgroup_context_done(CGroupContext *c) {
assert(c);
while (c->device_allow)
cgroup_context_free_device_allow(c, c->device_allow);
+ cgroup_context_remove_socket_bind(&c->socket_bind_allow);
+ cgroup_context_remove_socket_bind(&c->socket_bind_deny);
+
c->ip_address_allow = ip_address_access_free_all(c->ip_address_allow);
c->ip_address_deny = ip_address_access_free_all(c->ip_address_deny);
CGroupBPFForeignProgram *p;
CGroupDeviceAllow *a;
CGroupContext *c;
+ CGroupSocketBindItem *bi;
IPAddressAccessItem *iaai;
char **path;
char q[FORMAT_TIMESPAN_MAX];
LIST_FOREACH(programs, p, c->bpf_foreign_programs)
fprintf(f, "%sBPFProgram: %s:%s",
prefix, bpf_cgroup_attach_type_to_string(p->attach_type), p->bpffs_path);
+
+ if (c->socket_bind_allow) {
+ fprintf(f, "%sSocketBindAllow:", prefix);
+ LIST_FOREACH(socket_bind_items, bi, c->socket_bind_allow)
+ cgroup_context_dump_socket_bind_item(bi, f);
+ fputc('\n', f);
+ }
+
+ if (c->socket_bind_deny) {
+ fprintf(f, "%sSocketBindDeny:", prefix);
+ LIST_FOREACH(socket_bind_items, bi, c->socket_bind_deny)
+ cgroup_context_dump_socket_bind_item(bi, f);
+ fputc('\n', f);
+ }
+}
+
+void cgroup_context_dump_socket_bind_item(const CGroupSocketBindItem *item, FILE *f) {
+ const char *family = item->address_family == AF_INET ? "IPv4:" :
+ item->address_family == AF_INET6 ? "IPv6:" : "";
+
+ if (item->nr_ports == 0)
+ fprintf(f, " %sany", family);
+ else if (item->nr_ports == 1)
+ fprintf(f, " %s%" PRIu16, family, item->port_min);
+ else {
+ uint16_t port_max = item->port_min + item->nr_ports - 1;
+ fprintf(f, " %s%" PRIu16 "-%" PRIu16, family, item->port_min, port_max);
+ }
}
int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode) {
typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
typedef struct CGroupBPFForeignProgram CGroupBPFForeignProgram;
+typedef struct CGroupSocketBindItem CGroupSocketBindItem;
typedef enum CGroupDevicePolicy {
/* When devices listed, will allow those, plus built-in ones, if none are listed will allow
char *bpffs_path;
};
+struct CGroupSocketBindItem {
+ LIST_FIELDS(CGroupSocketBindItem, socket_bind_items);
+ int address_family;
+ uint16_t nr_ports;
+ uint16_t port_min;
+};
+
struct CGroupContext {
bool cpu_accounting;
bool io_accounting;
CGroupDevicePolicy device_policy;
LIST_HEAD(CGroupDeviceAllow, device_allow);
+ LIST_HEAD(CGroupSocketBindItem, socket_bind_allow);
+ LIST_HEAD(CGroupSocketBindItem, socket_bind_deny);
+
/* Common */
TasksMax tasks_max;
void cgroup_context_init(CGroupContext *c);
void cgroup_context_done(CGroupContext *c);
void cgroup_context_dump(Unit *u, FILE* f, const char *prefix);
+void cgroup_context_dump_socket_bind_item(const CGroupSocketBindItem *item, FILE *f);
void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w);
void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
void cgroup_context_remove_bpf_foreign_program(CGroupContext *c, CGroupBPFForeignProgram *p);
+void cgroup_context_remove_socket_bind(CGroupSocketBindItem **head);
int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode);
int cgroup_add_bpf_foreign_program(CGroupContext *c, uint32_t attach_type, const char *path);