cgroup: add socket-bind to cgroup context
This commit is contained in:
@@ -200,6 +200,18 @@ void cgroup_context_remove_bpf_foreign_program(CGroupContext *c, CGroupBPFForeig
|
||||
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);
|
||||
|
||||
@@ -221,6 +233,9 @@ void cgroup_context_done(CGroupContext *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);
|
||||
|
||||
@@ -376,6 +391,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
|
||||
CGroupBPFForeignProgram *p;
|
||||
CGroupDeviceAllow *a;
|
||||
CGroupContext *c;
|
||||
CGroupSocketBindItem *bi;
|
||||
IPAddressAccessItem *iaai;
|
||||
char **path;
|
||||
char q[FORMAT_TIMESPAN_MAX];
|
||||
@@ -562,6 +578,34 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
|
||||
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) {
|
||||
|
||||
@@ -32,6 +32,7 @@ typedef struct CGroupIODeviceLatency CGroupIODeviceLatency;
|
||||
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
|
||||
@@ -101,6 +102,13 @@ struct CGroupBPFForeignProgram {
|
||||
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;
|
||||
@@ -165,6 +173,9 @@ struct CGroupContext {
|
||||
CGroupDevicePolicy device_policy;
|
||||
LIST_HEAD(CGroupDeviceAllow, device_allow);
|
||||
|
||||
LIST_HEAD(CGroupSocketBindItem, socket_bind_allow);
|
||||
LIST_HEAD(CGroupSocketBindItem, socket_bind_deny);
|
||||
|
||||
/* Common */
|
||||
TasksMax tasks_max;
|
||||
|
||||
@@ -203,6 +214,7 @@ usec_t cgroup_cpu_adjust_period(usec_t period, usec_t quota, usec_t resolution,
|
||||
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);
|
||||
@@ -211,6 +223,7 @@ void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLaten
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user