Projectname large_stringclasses 15
values | Filepath large_stringlengths 4 106 ⌀ | Function large_stringlengths 11 3.45k | Label list |
|---|---|---|---|
Linux Kernel | samples/bpf/sock_example.c |
int main(void) {
FILE *f;
f = popen("ping -4 -c5 localhost", "r");
(void)f;
return test_sock();
} | [
0,
0
] |
Linux Kernel | samples/bpf/syscall_tp_kern.c | int trace_enter_exit(struct syscalls_exit_open_args *ctx) {
count(&exit_open_map);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/syscall_tp_user.c |
static void verify_map(int map_id) {
__u32 key = 0;
__u32 val;
if (bpf_map_lookup_elem(map_id, &key, &val) != 0) {
fprintf(stderr, "map_lookup failed: %s\n", strerror(errno));
return;
}
if (val == 0) {
fprintf(stderr, "failed: map #%d returns value 0\n", map_id);
return;
}
printf("verif... | [
0,
0
] |
Linux Kernel | samples/bpf/task_fd_query_user.c |
static __u64 ptr_to_u64(void *ptr) { return (__u64)(unsigned long)ptr; } | [
0,
0
] |
Linux Kernel | samples/bpf/task_fd_query_user.c | static int bpf_find_probe_type(const char *event_type) {
char buf[256];
int fd, ret;
ret = snprintf(buf, sizeof(buf), PMU_TYPE_FILE, event_type);
CHECK_PERROR_RET(ret < 0 || ret >= sizeof(buf));
fd = open(buf, O_RDONLY);
CHECK_PERROR_RET(fd < 0);
ret = read(fd, buf, sizeof(buf));
close(fd);
CHECK_P... | [
1,
0
] |
Linux Kernel | samples/bpf/tcbpf1_kern.c | static inline void set_tcp_dest_port(struct __sk_buff *skb, __u16 new_port) {
__u16 old_port = htons(load_half(skb, TCP_DPORT_OFF));
bpf_l4_csum_replace(skb, TCP_CSUM_OFF, old_port, new_port, sizeof(new_port));
bpf_skb_store_bytes(skb, TCP_DPORT_OFF, &new_port, sizeof(new_port), 0);
} | [
1,
0
] |
Linux Kernel | samples/bpf/tcp_iw_kern.c | int bpf_iw(struct bpf_sock_ops *skops) {
int bufsize = 1500000;
int rwnd_init = 40;
int iw = 40;
int rv = 0;
int op;
if (bpf_ntohl(skops->remote_port) != 55601 && skops->local_port != 55601) {
skops->reply = -1;
return 1;
}
op = (int)skops->op;
#ifdef DEBUG
bpf_printk("BPF command: %d\n", o... | [
1,
0
] |
Linux Kernel | samples/bpf/tc_l2_redirect_kern.c | int _l2_to_iptun_ingress_forward(struct __sk_buff *skb) {
struct bpf_tunnel_key tkey = {};
void *data = (void *)(long)skb->data;
struct eth_hdr *eth = data;
void *data_end = (void *)(long)skb->data_end;
int key = 0, *ifindex;
int ret;
if (data + sizeof(*eth) > data_end)
return TC_ACT_OK;
ifindex ... | [
1,
0
] |
Linux Kernel | samples/bpf/tc_l2_redirect_kern.c | int _l2_to_iptun_ingress_redirect(struct __sk_buff *skb) {
struct bpf_tunnel_key tkey = {};
void *data = (void *)(long)skb->data;
struct eth_hdr *eth = data;
void *data_end = (void *)(long)skb->data_end;
int key = 0, *ifindex;
int ret;
if (data + sizeof(*eth) > data_end)
return TC_ACT_OK;
ifindex... | [
1,
0
] |
Linux Kernel | samples/bpf/test_cgrp2_sock.c |
static int get_bind_to_device(int sd, char *name, size_t len) {
socklen_t optlen = len;
int rc;
name[0] = '\0';
rc = getsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, name, &optlen);
if (rc < 0)
perror("setsockopt(SO_BINDTODEVICE)");
return rc;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_cgrp2_sock2.c |
static int usage(const char *argv0) {
printf("Usage: %s cg-path filter-path [filter-id]\n", argv0);
return EXIT_FAILURE;
} | [
1,
0
] |
Linux Kernel | samples/bpf/test_current_task_under_cgroup_kern.c | int bpf_prog1(struct pt_regs *ctx) {
u64 pid = bpf_get_current_pid_tgid();
int idx = 0;
if (!bpf_current_task_under_cgroup(&cgroup_map, 0))
return 0;
bpf_map_update_elem(&perf_map, &idx, &pid, BPF_ANY);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_lru_dist.c |
static inline void INIT_LIST_HEAD(struct list_head *list) {
list->next = list;
list->prev = list;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_lru_dist.c |
static int create_map(int map_type, int map_flags, unsigned int size) {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = map_flags, );
int map_fd;
map_fd = bpf_map_create(map_type, NULL, sizeof(unsigned long long),
sizeof(unsigned long long), size, &opts);
if (map_fd == -1)
p... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lru_dist.c |
static int sched_next_online(int pid, int next_to_try) {
cpu_set_t cpuset;
if (next_to_try == nr_cpus)
return -1;
while (next_to_try < nr_cpus) {
CPU_ZERO(&cpuset);
CPU_SET(next_to_try++, &cpuset);
if (!sched_setaffinity(pid, sizeof(cpuset), &cpuset))
break;
}
return next_to_try;
} | [
1,
0
] |
Linux Kernel | samples/bpf/test_lru_dist.c |
static void test_parallel_lru_dist(int map_type, int map_flags, int nr_tasks,
unsigned int lru_size) {
int child_data[2];
int lru_map_fd;
printf("%s (map_type:%d map_flags:0x%X):\n", __func__, map_type, map_flags);
if (map_flags & BPF_F_NO_COMMON_LRU)
lru_map_fd = creat... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lru_dist.c | static void test_parallel_lru_loss(int map_type, int map_flags, int nr_tasks) {
int map_fd;
printf("%s (map_type:%d map_flags:0x%X):\n", __func__, map_type, map_flags);
if (map_flags & BPF_F_NO_COMMON_LRU)
map_fd = create_map(map_type, map_flags, nr_cpus * (1000 + 200));
else
map_fd = create_map(map_t... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_nop(struct __sk_buff *skb) { return BPF_OK; } | [
0,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_test_ctx(struct __sk_buff *skb) {
skb->cb[0] = CB_MAGIC;
printk("len %d hash %d protocol %d\n", skb->len, skb->hash, skb->protocol);
printk("cb %d ingress_ifindex %d ifindex %d\n", skb->cb[0],
skb->ingress_ifindex, skb->ifindex);
return BPF_OK;
} | [
1,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_test_data(struct __sk_buff *skb) {
void *data = (void *)(long)skb->data;
void *data_end = (void *)(long)skb->data_end;
struct iphdr *iph = data;
if (data + sizeof(*iph) > data_end) {
printk("packet truncated\n");
return BPF_DROP;
}
printk("src: %x dst: %x\n", iph->saddr, iph->daddr);
ret... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_test_rewrite(struct __sk_buff *skb) {
uint32_t old_ip, new_ip = 0x3fea8c0;
int ret;
ret = bpf_skb_load_bytes(skb, IP_DST_OFF, &old_ip, 4);
if (ret < 0) {
printk("bpf_skb_load_bytes failed: %d\n", ret);
return BPF_DROP;
}
if (old_ip == 0x2fea8c0) {
printk("out: rewriting from %x to %x\n"... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c |
static inline int __do_push_ll_and_redirect(struct __sk_buff *skb) {
uint64_t smac = SRC_MAC, dmac = DST_MAC;
int ret, ifindex = DST_IFINDEX;
struct ethhdr ehdr;
ret = bpf_skb_change_head(skb, 14, 0);
if (ret < 0) {
printk("skb_change_head() failed: %d\n", ret);
}
ehdr.h_proto = __constant_htons(ET... | [
1,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_push_ll_and_redirect_silent(struct __sk_buff *skb) {
return __do_push_ll_and_redirect(skb);
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_lwt_bpf.c | int do_fill_garbage_and_redirect(struct __sk_buff *skb) {
int ifindex = DST_IFINDEX;
__fill_garbage(skb);
printk("redirected to %d\n", ifindex);
return bpf_redirect(ifindex, 0);
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_map_in_map_kern.c |
static __always_inline int do_reg_lookup(void *inner_map, u32 port) {
int *result;
result = bpf_map_lookup_elem(inner_map, &port);
return result ? *result : -ENOENT;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_map_in_map_kern.c |
static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port) {
int *result;
if (inner_map != &port_h)
return -EINVAL;
result = bpf_map_lookup_elem(&port_h, &port);
return result ? *result : -ENOENT;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_map_in_map_user.c |
static void check_map_id(int inner_map_fd, int map_in_map_fd, uint32_t key) {
struct bpf_map_info info = {};
uint32_t info_len = sizeof(info);
int ret, id;
ret = bpf_obj_get_info_by_fd(inner_map_fd, &info, &info_len);
assert(!ret);
ret = bpf_map_lookup_elem(map_in_map_fd, &key, &id);
assert(!ret);
as... | [
1,
0
] |
Linux Kernel | samples/bpf/test_overhead_kprobe_kern.c | int prog(struct pt_regs *ctx) {
struct signal_struct *signal;
struct task_struct *tsk;
char oldcomm[TASK_COMM_LEN] = {};
char newcomm[TASK_COMM_LEN] = {};
u16 oom_score_adj;
u32 pid;
tsk = (void *)PT_REGS_PARM1(ctx);
pid = _(tsk->pid);
bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm);... | [
1,
0
] |
Linux Kernel | samples/bpf/test_overhead_user.c |
static __u64 time_get_ns(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000ull + ts.tv_nsec;
} | [
0,
0
] |
Linux Kernel | samples/bpf/test_overhead_user.c |
static void test_task_rename(int cpu) {
__u64 start_time;
char buf[] = "test\n";
int i, fd;
fd = open("/proc/self/comm", O_WRONLY | O_TRUNC);
if (fd < 0) {
printf("couldn't open /proc\n");
exit(1);
}
start_time = time_get_ns();
for (i = 0; i < MAX_CNT; i++) {
if (write(fd, buf, sizeof(buf)... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex1_user.c | int main(int ac, char **argv) {
struct bpf_link *link = NULL;
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
FILE *f;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
fprintf(stderr, "ERROR: ... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex2_kern.c |
static unsigned int log2l(unsigned long v) {
unsigned int hi = v >> 32;
if (hi)
return log2(hi) + 32;
else
return log2(v);
} | [
1,
0
] |
Linux Kernel | samples/bpf/tracex2_kern.c | int bpf_prog3(struct pt_regs *ctx) {
long write_size = PT_REGS_PARM3(ctx);
long init_val = 1;
long *value;
struct hist_key key;
key.index = log2l(write_size);
key.pid_tgid = bpf_get_current_pid_tgid();
key.uid_gid = bpf_get_current_uid_gid();
bpf_get_current_comm(&key.comm, sizeof(key.comm));
value ... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex2_user.c |
static void stars(char *str, long val, long max, int width) {
int i;
for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++)
str[i] = '*';
if (val > max)
str[i - 1] = '+';
str[i] = '\0';
} | [
1,
0
] |
Linux Kernel | samples/bpf/tracex2_user.c |
static void print_hist_for_pid(int fd, void *task) {
unsigned int nr_cpus = bpf_num_possible_cpus();
struct hist_key key = {}, next_key;
long values[nr_cpus];
char starstr[MAX_STARS];
long value;
long data[MAX_INDEX] = {};
int max_ind = -1;
long max_value = 0;
int i, ind;
while (bpf_map_get_next_k... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex3_kern.c |
static unsigned int log2l(unsigned long long n) {
#define S(k) \
if (n >= (1ull << k)) { \
i += k; \
n >>= k; ... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex3_user.c |
static void clear_stats(int fd) {
unsigned int nr_cpus = bpf_num_possible_cpus();
__u64 values[nr_cpus];
__u32 key;
memset(values, 0, sizeof(values));
for (key = 0; key < SLOTS; key++)
bpf_map_update_elem(fd, &key, values, BPF_ANY);
} | [
1,
0
] |
Linux Kernel | samples/bpf/tracex4_kern.c | int bpf_prog2(struct pt_regs *ctx) {
long ptr = PT_REGS_RC(ctx);
long ip = 0;
BPF_KRETPROBE_READ_RET_IP(ip, ctx);
struct pair v = {
.val = bpf_ktime_get_ns(),
.ip = ip,
};
bpf_map_update_elem(&my_map, &ptr, &v, BPF_ANY);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/tracex4_user.c | int main(int ac, char **argv) {
struct bpf_link *links[2];
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
int map_fd, i, j = 0;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
fprintf(stderr... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex5_kern.c | PROG(SYS__NR_write)(struct pt_regs *ctx) {
struct seccomp_data sd;
bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
if (sd.args[2] == 512) {
char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
bpf_trace_printk(fmt, sizeof(fmt), sd.args[0], sd.args[1], sd.args[2]);
}
return 0;
} | [
1,
0
] |
Linux Kernel | samples/bpf/tracex5_user.c | int main(int ac, char **argv) {
struct bpf_link *link = NULL;
struct bpf_program *prog;
struct bpf_object *obj;
int key, fd, progs_fd;
const char *section;
char filename[256];
FILE *f;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbp... | [
1,
0
] |
Linux Kernel | samples/bpf/tracex7_kern.c | int bpf_prog1(struct pt_regs *ctx) {
unsigned long rc = -12;
bpf_override_return(ctx, rc);
return 0;
} | [
1,
0
] |
Linux Kernel | samples/bpf/trace_event_user.c |
static void print_stack(struct key_t *key, __u64 count) {
__u64 ip[PERF_MAX_STACK_DEPTH] = {};
static bool warned;
int i;
printf("%3lld %s;", count, key->comm);
if (bpf_map_lookup_elem(map_fd[1], &key->kernstack, ip) != 0) {
printf("---;");
} else {
for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--)
... | [
1,
0
] |
Linux Kernel | samples/bpf/trace_event_user.c |
static void err_exit(int err) {
kill(pid, SIGKILL);
exit(err);
} | [
0,
0
] |
Linux Kernel | samples/bpf/trace_event_user.c |
static inline int generate_load(void) {
if (system("dd if=/dev/zero of=/dev/null count=5000k status=none") < 0) {
printf("failed to generate some load with dd: %s\n", strerror(errno));
return -1;
}
return 0;
} | [
1,
0
] |
Linux Kernel | samples/bpf/xdp1_kern.c |
static int parse_ipv4(void *data, u64 nh_off, void *data_end) {
struct iphdr *iph = data + nh_off;
if (iph + 1 > data_end)
return 0;
return iph->protocol;
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp2skb_meta_kern.c | int _tc_mark(struct __sk_buff *ctx) {
void *data = (void *)(unsigned long)ctx->data;
void *data_end = (void *)(unsigned long)ctx->data_end;
void *data_meta = (void *)(unsigned long)ctx->data_meta;
struct meta_info *meta = data_meta;
if (meta + 1 > data) {
ctx->mark = 41;
/* Skip "accept" if no data_m... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp2_kern.c |
static void swap_src_dst_mac(void *data) {
unsigned short *p = data;
unsigned short dst[3];
dst[0] = p[0];
dst[1] = p[1];
dst[2] = p[2];
p[0] = p[3];
p[1] = p[4];
p[2] = p[5];
p[3] = dst[0];
p[4] = dst[1];
p[5] = dst[2];
} | [
1,
0
] |
Linux Kernel | samples/bpf/xdp2_kern.c | int xdp_prog1(struct xdp_md *ctx) {
__u8 pkt[XDPBUFSIZE] = {};
void *data_end = &pkt[XDPBUFSIZE - 1];
void *data = pkt;
struct ethhdr *eth = data;
int rc = XDP_DROP;
long *value;
u16 h_proto;
u64 nh_off;
u32 ipproto;
if (bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt)))
return rc;
nh_off = sizeo... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_adjust_tail_kern.c |
static __always_inline void swap_mac(void *data, struct ethhdr *orig_eth) {
struct ethhdr *eth;
eth = data;
memcpy(eth->h_source, orig_eth->h_dest, ETH_ALEN);
memcpy(eth->h_dest, orig_eth->h_source, ETH_ALEN);
eth->h_proto = orig_eth->h_proto;
} | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_adjust_tail_kern.c | int _xdp_icmp(struct xdp_md *xdp) {
void *data_end = (void *)(long)xdp->data_end;
void *data = (void *)(long)xdp->data;
struct ethhdr *eth = data;
__u16 h_proto;
if (eth + 1 > data_end)
return XDP_DROP;
h_proto = eth->h_proto;
if (h_proto == htons(ETH_P_IP))
return handle_ipv4(xdp);
else
... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_adjust_tail_user.c |
static void int_exit(int sig) {
__u32 curr_prog_id = 0;
if (ifindex > -1) {
if (bpf_xdp_query_id(ifindex, xdp_flags, &curr_prog_id)) {
printf("bpf_xdp_query_id failed\n");
exit(1);
}
if (prog_id == curr_prog_id)
bpf_xdp_detach(ifindex, xdp_flags, NULL);
else if (!curr_prog_id)
... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_fwd_user.c | static int do_detach(int ifindex, const char *ifname, const char *app_name) {
LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
struct bpf_prog_info prog_info = {};
char prog_name[BPF_OBJ_NAME_LEN];
__u32 info_len, curr_prog_id;
int prog_fd;
int err = 1;
if (bpf_xdp_query_id(ifindex, xdp_flags, &curr_prog_id)) {
... | [
1,
1
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu.bpf.c | static __always_inline bool parse_eth(struct ethhdr *eth, void *data_end,
u16 *eth_proto, u64 *l3_offset) {
u16 eth_type;
u64 offset;
offset = sizeof(*eth);
if ((void *)eth + offset > data_end)
return false;
eth_type = eth->h_proto;
if (__builtin_expect(bpf_ntohs... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu.bpf.c | int xdp_prognum0_no_touch(struct xdp_md *ctx) {
u32 key = bpf_get_smp_processor_id();
struct datarec *rec;
u32 *cpu_selected;
u32 cpu_dest = 0;
u32 key0 = 0;
cpu_selected = bpf_map_lookup_elem(&cpus_available, &key0);
if (!cpu_selected)
return XDP_ABORTED;
cpu_dest = *cpu_selected;
rec = bpf_map... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu.bpf.c | int xdp_prognum3_proto_separate(struct xdp_md *ctx) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
u32 key = bpf_get_smp_processor_id();
struct ethhdr *eth = data;
u8 ip_proto = IPPROTO_UDP;
struct datarec *rec;
u16 eth_proto = 0;
u64 l3_offset = 0;
u32 cpu_dest ... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu.bpf.c |
static __always_inline u32 get_ipv4_hash_ip_pair(struct xdp_md *ctx,
u64 nh_off) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
struct iphdr *iph = data + nh_off;
u32 cpu_hash;
if (iph + 1 > data_end)
return 0;
cp... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu.bpf.c | int xdp_redirect_cpu_pass(struct xdp_md *ctx) { return XDP_PASS; } | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_cpu_user.c | static int mark_cpus_unavailable(void) {
int ret, i, n_cpus = libbpf_num_possible_cpus();
__u32 invalid_cpu = n_cpus;
for (i = 0; i < n_cpus; i++) {
ret = bpf_map_update_elem(avail_fd, &i, &invalid_cpu, 0);
if (ret < 0) {
fprintf(stderr, "Failed marking CPU unavailable: %s\n", strerror(errno));
... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_map.bpf.c |
static __always_inline int xdp_redirect_map(struct xdp_md *ctx,
void *redirect_map) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
u32 key = bpf_get_smp_processor_id();
struct ethhdr *eth = data;
struct datarec *rec;
u64 nh_... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_map.bpf.c | int xdp_redirect_map_native(struct xdp_md *ctx) {
return xdp_redirect_map(ctx, &tx_port_native);
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_redirect_map.bpf.c | int xdp_redirect_map_egress(struct xdp_md *ctx) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
u8 *mac_addr = (u8 *)tx_mac_addr;
struct ethhdr *eth = data;
u64 nh_off;
nh_off = sizeof(*eth);
if (data + nh_off > data_end)
return XDP_DROP;
barrier_var(mac_addr)... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_rxq_info_user.c |
static double calc_period(struct record *r, struct record *p) {
double period_ = 0;
__u64 period = 0;
period = r->timestamp - p->timestamp;
if (period > 0)
period_ = ((double)period / NANOSEC_PER_SEC);
return period_;
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample.bpf.c |
static __always_inline __u32 xdp_get_err_key(int err) {
switch (err) {
case 0:
return 0;
case -EINVAL:
return 2;
case -ENETDOWN:
return 3;
case -EMSGSIZE:
return 4;
case -EOPNOTSUPP:
return 5;
case -ENOSPC:
return 6;
default:
return 1;
}
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample.bpf.c | int BPF_PROG(tp_xdp_redirect_map_err, const struct net_device *dev,
const struct bpf_prog *xdp, const void *tgt, int err,
const struct bpf_map *map, u32 index) {
return xdp_redirect_collect_stat(dev->ifindex, err);
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample.bpf.c | int BPF_PROG(tp_xdp_cpumap_enqueue, int map_id, unsigned int processed,
unsigned int drops, int to_cpu) {
u32 cpu = bpf_get_smp_processor_id();
struct datarec *rec;
u32 idx;
if (cpumap_map_id && cpumap_map_id != map_id)
return 0;
idx = to_cpu * nr_cpus + cpu;
rec = bpf_map_lookup_elem(&cp... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample.bpf.c | int BPF_PROG(tp_xdp_devmap_xmit, const struct net_device *from_dev,
const struct net_device *to_dev, int sent, int drops, int err) {
struct datarec *rec;
int idx_in, idx_out;
u32 cpu;
idx_in = from_dev->ifindex;
idx_out = to_dev->ifindex;
if (!IN_SET(from_match, idx_in))
return 0;
if (!... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample.bpf.h | static __always_inline void __write_once_size(volatile void *p, void *res,
int size) {
switch (size) {
case 1:
*(volatile __u8_alias_t *)p = *(__u8_alias_t *)res;
break;
case 2:
*(volatile __u16_alias_t *)p = *(__u16_alias_t *)res;
break;
case 4:
... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_pkts_kern.c | int xdp_sample_prog(struct xdp_md *ctx) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
struct S {
u16 cookie;
u16 pkt_len;
} __packed metadata;
if (data < data_end) {
/* The XDP perf_event_output handler will use the upper 32 bits
* of the flags argume... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static const char *action2str(int action) {
if (action < XDP_ACTION_MAX)
return xdp_action_names[action];
return NULL;
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
void sample_usage(char *argv[], const struct option *long_options,
const char *doc, int mask, bool error) {
int i;
if (!error)
sample_print_help(mask);
printf("\n%s\nOption for %s:\n", doc, argv[0]);
for (i = 0; long_options[i].name != 0; i++) {
printf(" --%-15s", long_options[i].na... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c | static void map_collect_percpu(struct datarec *values, struct record *rec) {
unsigned int nr_cpus = libbpf_num_possible_cpus();
__u64 sum_xdp_redirect = 0;
__u64 sum_processed = 0;
__u64 sum_xdp_pass = 0;
__u64 sum_xdp_drop = 0;
__u64 sum_dropped = 0;
__u64 sum_issue = 0;
int i;
/* Get time as close... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static double calc_period(struct record *r, struct record *p) {
double period_ = 0;
__u64 period = 0;
period = r->timestamp - p->timestamp;
if (period > 0)
period_ = ((double)period / NANOSEC_PER_SEC);
return period_;
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static void calc_xdp_pps(struct datarec *r, struct datarec *p, double *xdp_pass,
double *xdp_drop, double *xdp_redirect,
double period_) {
*xdp_pass = 0, *xdp_drop = 0, *xdp_redirect = 0;
if (period_ > 0) {
*xdp_redirect = (r->xdp_redirect - p->xdp_redirect) / ... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static void stats_get_rx_cnt(struct stats_record *stats_rec,
struct stats_record *stats_prev,
unsigned int nr_cpus, struct sample_output *out) {
struct record *rec, *prev;
double t, pps, drop, err;
int i;
rec = &stats_rec->rx_cnt;
prev = &stats_prev-... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c | static void stats_get_cpumap_enqueue(struct stats_record *stats_rec,
struct stats_record *stats_prev,
unsigned int nr_cpus) {
struct record *rec, *prev;
double t, pps, drop, err;
int i, to_cpu;
for (to_cpu = 0; to_cpu < sample_n_cpus; to... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static void stats_get_redirect_cnt(struct stats_record *stats_rec,
struct stats_record *stats_prev,
unsigned int nr_cpus,
struct sample_output *out) {
struct record *rec, *prev;
double t, pps;
int i;
rec =... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
void sample_switch_mode(void) { sample_log_level ^= LL_DEBUG - 1; } | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c | static void swap(struct stats_record **a, struct stats_record **b) {
struct stats_record *tmp;
tmp = *a;
*a = *b;
*b = tmp;
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
static int sample_timer_cb(int timerfd, struct stats_record **rec,
struct stats_record **prev) {
char line[64] = "Summary";
int ret;
__u64 t;
ret = read(timerfd, &t, sizeof(t));
if (ret < 0)
return -errno;
swap(prev, rec);
ret = sample_stats_collect(*rec);
if (ret < 0)
... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c | int sample_run(int interval, void (*post_cb)(void *), void *ctx) {
struct timespec ts = {interval, 0};
struct itimerspec its = {ts, ts};
struct stats_record *rec, *prev;
struct pollfd pfd[2] = {};
int timerfd, ret;
if (!interval) {
fprintf(stderr, "Incorrect interval 0\n");
return -EINVAL;
}
sa... | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c |
int get_mac_addr(int ifindex, void *mac_addr) {
char ifname[IF_NAMESIZE];
struct ifreq ifr = {};
int fd, r;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
return -errno;
if (!if_indextoname(ifindex, ifname)) {
r = -errno;
goto end;
}
safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_na... | [
1,
0
] |
Linux Kernel | samples/bpf/xdp_sample_user.c | static void sample_ctor(void) {
if (libbpf_set_strict_mode(LIBBPF_STRICT_ALL) < 0) {
fprintf(stderr, "Failed to set libbpf strict mode: %s\n", strerror(errno));
exit(EXIT_FAIL_BPF);
}
} | [
0,
0
] |
Linux Kernel | samples/bpf/xdp_tx_iptunnel_user.c | static void poll_stats(unsigned int kill_after_s) {
const unsigned int nr_protos = 256;
unsigned int nr_cpus = bpf_num_possible_cpus();
time_t started_at = time(NULL);
__u64 values[nr_cpus], prev[nr_protos][nr_cpus];
__u32 proto;
int i;
memset(prev, 0, sizeof(prev));
while (!kill_after_s || time(NULL)... | [
1,
0
] |
Linux Kernel | samples/configfs/configfs_sample.c |
static inline struct simple_child *to_simple_child(struct config_item *item) {
return container_of(item, struct simple_child, item);
} | [
0,
0
] |
Linux Kernel | samples/configfs/configfs_sample.c |
static void __exit configfs_example_exit(void) {
int i;
for (i = 0; example_subsys[i]; i++)
configfs_unregister_subsystem(example_subsys[i]);
} | [
0,
0
] |
Linux Kernel | samples/connector/cn_test.c |
static int cn_test_init(void) {
int err;
err = cn_add_callback(&cn_test_id, cn_test_name, cn_test_callback);
if (err)
goto err_out;
cn_test_id.val++;
err = cn_add_callback(&cn_test_id, cn_test_name, cn_test_callback);
if (err) {
cn_del_callback(&cn_test_id);
goto err_out;
}
timer_setup(&c... | [
1,
0
] |
Linux Kernel | samples/connector/ucon.c |
static int netlink_send(int s, struct cn_msg *msg) {
struct nlmsghdr *nlh;
unsigned int size;
int err;
char buf[128];
struct cn_msg *m;
size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
nlh = (struct nlmsghdr *)buf;
nlh->nlmsg_seq = seq++;
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = NLMSG_DO... | [
1,
0
] |
Linux Kernel | samples/connector/ucon.c |
static void usage(void) {
printf("Usage: ucon [options] [output file]\n"
"\n"
"\t-h\tthis help screen\n"
"\t-s\tsend buffers to the test module\n"
"\n"
"The default behavior of ucon is to subscribe to the test module\n"
"and wait for state messages. Any ones rec... | [
0,
0
] |
Linux Kernel | samples/coresight/coresight-cfg-sample.c | static int __init cscfg_sample_init(void) {
return cscfg_load_config_sets(sample_cfgs, sample_feats, &mod_owner);
} | [
0,
0
] |
Linux Kernel | samples/coresight/coresight-cfg-sample.c |
static void __exit cscfg_sample_exit(void) {
cscfg_unload_config_sets(&mod_owner);
} | [
0,
0
] |
Linux Kernel | samples/fanotify/fs-monitor.c |
static void handle_notifications(char *buffer, int len) {
struct fanotify_event_metadata *event =
(struct fanotify_event_metadata *)buffer;
struct fanotify_event_info_header *info;
struct fanotify_event_info_error *err;
struct fanotify_event_info_fid *fid;
int off;
for (; FAN_EVENT_OK(event, len); e... | [
1,
0
] |
Linux Kernel | samples/fprobe/fprobe_example.c |
static void show_backtrace(void) {
unsigned long stacks[BACKTRACE_DEPTH];
unsigned int len;
len = stack_trace_save(stacks, BACKTRACE_DEPTH, 2);
stack_trace_print(stacks, len, 24);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/ftrace-direct-multi-modify.c |
void my_direct_func2(unsigned long ip) {
trace_printk("my direct func2 ip %lx\n", ip);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/ftrace-direct-multi.c |
static void __exit ftrace_direct_multi_exit(void) {
unregister_ftrace_direct_multi(&direct, (unsigned long)my_tramp);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/ftrace-direct-too.c |
void my_direct_func(struct vm_area_struct *vma, unsigned long address,
unsigned int flags) {
trace_printk("handle mm fault vma=%p address=%lx flags=%x\n", vma, address,
flags);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/ftrace-direct-too.c |
static int __init ftrace_direct_init(void) {
return register_ftrace_direct((unsigned long)handle_mm_fault,
(unsigned long)my_tramp);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/ftrace-direct.c |
void my_direct_func(struct task_struct *p) {
trace_printk("waking up %s-%d\n", p->comm, p->pid);
} | [
1,
0
] |
Linux Kernel | samples/ftrace/sample-trace-array.c |
static void mytimer_handler(struct timer_list *unused) {
schedule_work(&trace_work);
} | [
0,
0
] |
Linux Kernel | samples/ftrace/sample-trace-array.c | static void simple_thread_func(int count) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
trace_array_printk(tr, _THIS_IP_, "trace_array_printk: count=%d\n", count);
/*
* Tracepoint for event "sample_event". This will print the
* current value of count and current jiffies.
*/
trace_sa... | [
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.