/* eBPF example program: * * - Loads eBPF program * * The eBPF program sets the sk_bound_dev_if index in new AF_INET{6} * sockets opened by processes in the cgroup. * * - Attaches the new program to a cgroup using BPF_PROG_ATTACH */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include "libbpf.h" char bpf_log_buf[BPF_LOG_BUF_SIZE]; static int prog_load(int idx) { struct bpf_insn prog[] = { BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_IMM(BPF_REG_3, idx), BPF_MOV64_IMM(BPF_REG_2, offsetof(struct bpf_sock, bound_dev_if)), BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_3, offsetof(struct bpf_sock, bound_dev_if)), BPF_MOV64_IMM(BPF_REG_0, 1), /* r0 = verdict */ BPF_EXIT_INSN(), }; size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn); return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, insns_cnt, "GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE); } static int usage(const char *argv0) { printf("Usage: %s cg-path device-index\n", argv0); return EXIT_FAILURE; } int main(int argc, char **argv) { int cg_fd, prog_fd, ret; unsigned int idx; if (argc < 2) return usage(argv[0]); idx = if_nametoindex(argv[2]); if (!idx) { printf("Invalid device name\n"); return EXIT_FAILURE; } cg_fd = open(argv[1], O_DIRECTORY | O_RDONLY); if (cg_fd < 0) { printf("Failed to open cgroup path: '%s'\n", strerror(errno)); return EXIT_FAILURE; } prog_fd = prog_load(idx); printf("Output from kernel verifier:\n%s\n-------\n", bpf_log_buf); if (prog_fd < 0) { printf("Failed to load prog: '%s'\n", strerror(errno)); return EXIT_FAILURE; } ret = bpf_prog_attach(prog_fd, cg_fd, BPF_CGROUP_INET_SOCK_CREATE); if (ret < 0) { printf("Failed to attach prog to cgroup: '%s'\n", strerror(errno)); return EXIT_FAILURE; } return EXIT_SUCCESS; } include/pcmcia/cistpl.h?id=99421c1cb27fb837e93b517036fab4500fe39de5'>commitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-01-15 16:09:50 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2017-01-15 16:09:50 -0800
commit99421c1cb27fb837e93b517036fab4500fe39de5 (patch)
treede5fc5bacb671223f389793ad643cebe520bc292 /include/pcmcia/cistpl.h
parentc92816275674c1491ce228ee49aa030a5fa1be04 (diff)
parent93362fa47fe98b62e4a34ab408c4a418432e7939 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull namespace fixes from Eric Biederman: "This tree contains 4 fixes. The first is a fix for a race that can causes oopses under the right circumstances, and that someone just recently encountered. Past that are several small trivial correct fixes. A real issue that was blocking development of an out of tree driver, but does not appear to have caused any actual problems for in-tree code. A potential deadlock that was reported by lockdep. And a deadlock people have experienced and took the time to track down caused by a cleanup that removed the code to drop a reference count" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: sysctl: Drop reference added by grab_header in proc_sys_readdir pid: fix lockdep deadlock warning due to ucount_lock libfs: Modify mount_pseudo_xattr to be clear it is not a userspace mount mnt: Protect the mountpoint hashtable with mount_lock
Diffstat (limited to 'include/pcmcia/cistpl.h')