return;
}
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
ret = bpf_program_cgroup_detach(handler->cgroup_ops->cgroup2_devices);
if (ret < 0)
WARN("Failed to detach bpf program from cgroup");
-#endif
if (!lxc_list_empty(&handler->conf->id_map)) {
struct generic_userns_exec_data wrap = {
struct lxc_conf *conf, const char *key,
const char *val)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
struct device_item device_item = {};
int ret;
ret = bpf_list_add_device(conf, &device_item);
if (ret < 0)
return -1;
-#endif
return 0;
}
__cgfsng_ops static bool cgfsng_devices_activate(struct cgroup_ops *ops, struct lxc_handler *handler)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
__do_bpf_program_free struct bpf_program *prog = NULL;
int ret;
struct lxc_conf *conf;
prog_old = move_ptr(ops->cgroup2_devices);
ops->cgroup2_devices = move_ptr(prog);
prog = move_ptr(prog_old);
-#endif
return true;
}
#include "memory_utils.h"
#include "syscall_numbers.h"
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
-#include <linux/bpf.h>
-#include <linux/filter.h>
-#endif
-
-#ifndef BPF_F_ALLOW_OVERRIDE
-#define BPF_F_ALLOW_OVERRIDE (1U << 0)
-#endif
-
-#ifndef BPF_F_ALLOW_MULTI
-#define BPF_F_ALLOW_MULTI (1U << 1)
-#endif
-
-#ifndef BPF_F_REPLACE
-#define BPF_F_REPLACE (1U << 2)
-#endif
+#include "include/bpf.h"
+#include "include/bpf_common.h"
#ifndef HAVE_BPF
-
-union bpf_attr;
-
-static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size)
+static inline int bpf_lxc(int cmd, union bpf_attr *attr, size_t size)
{
return syscall(__NR_bpf, cmd, attr, size);
}
-
-#define bpf missing_bpf
+#define bpf bpf_lxc
#endif /* HAVE_BPF */
struct bpf_program {
__u32 prog_type;
size_t n_instructions;
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
struct bpf_insn *instructions;
-#endif /* HAVE_STRUCT_BPF_CGROUP_DEV_CTX */
int fd_cgroup;
int attached_type;
static inline bool bpf_device_add(const struct bpf_program *prog,
struct device_item *device)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
if (device->global_rule > LXC_BPF_DEVICE_CGROUP_LOCAL_RULE)
return false;
/* We're allowing all devices so skip individual allow rules. */
if (!bpf_device_block_all(prog) && device->allow)
return false;
-#endif
return true;
}
static inline void bpf_device_set_type(struct bpf_program *prog,
struct lxc_list *devices)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
struct lxc_list *it;
lxc_list_for_each (it, devices) {
if (cur->global_rule > LXC_BPF_DEVICE_CGROUP_LOCAL_RULE)
prog->device_list_type = cur->global_rule;
}
-#endif
}
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
__hidden extern struct bpf_program *bpf_program_new(__u32 prog_type);
__hidden extern int bpf_program_init(struct bpf_program *prog);
__hidden extern int bpf_program_append_device(struct bpf_program *prog, struct device_item *device);
__hidden extern int bpf_list_add_device(struct lxc_conf *conf, struct device_item *device);
-#else /* !HAVE_STRUCT_BPF_CGROUP_DEV_CTX */
-
-static inline struct bpf_program *bpf_program_new(__u32 prog_type)
-{
- return ret_set_errno(NULL, ENOSYS);
-}
-
-static inline int bpf_program_init(struct bpf_program *prog)
-{
- return ret_errno(ENOSYS);
-}
-
-static inline int bpf_program_append_device(struct bpf_program *prog, char type,
- int major, int minor,
- const char *access, int allow)
-{
- return ret_errno(ENOSYS);
-}
-
-static inline int bpf_program_finalize(struct bpf_program *prog)
-{
- return ret_errno(ENOSYS);
-}
-
-static inline int bpf_program_cgroup_attach(struct bpf_program *prog, int type,
- int fd_cgroup, int replace_bpf_fd,
- __u32 flags)
-{
- return ret_errno(ENOSYS);
-}
-
-static inline int bpf_program_cgroup_detach(struct bpf_program *prog)
-{
- return ret_errno(ENOSYS);
-}
-
-static inline void bpf_program_free(struct bpf_program *prog)
-{
-}
-
-static inline void bpf_device_program_free(struct cgroup_ops *ops)
-{
-}
-
-static inline bool bpf_devices_cgroup_supported(void)
-{
- return ret_set_errno(false, ENOSYS);
-}
-
-static inline int bpf_list_add_device(struct lxc_conf *conf,
- struct device_item *device)
-{
- return ret_errno(ENOSYS);
-}
-#endif /* !HAVE_STRUCT_BPF_CGROUP_DEV_CTX */
-
define_cleanup_function(struct bpf_program *, bpf_program_free);
#define __do_bpf_program_free call_cleaner(bpf_program_free)
int lxc_cmd_add_bpf_device_cgroup(const char *name, const char *lxcpath,
struct device_item *device)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
int stopped = 0;
struct lxc_cmd_rr cmd = {
.req = {
return log_error_errno(-1, errno, "Failed to add new bpf device cgroup rule");
return 0;
-#else
- return ret_set_errno(-1, ENOSYS);
-#endif
}
static int lxc_cmd_add_bpf_device_cgroup_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler,
struct lxc_epoll_descr *descr)
{
-#ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
__do_bpf_program_free struct bpf_program *devices = NULL;
struct lxc_cmd_rsp rsp = {0};
struct lxc_conf *conf = handler->conf;
return LXC_CMD_REAP_CLIENT_FD;
return 0;
-#else
- return ret_set_errno(-1, ENOSYS);
-#endif
}
int lxc_cmd_console_log(const char *name, const char *lxcpath,