static int blacklist_modify(int fd, char *ip_string, unsigned int action) { unsigned int nr_cpus = bpf_num_possible_cpus(); __u64 values[nr_cpus]; __u32 key; int res; /* Update values for all possible CPUs */ memset(values, 0, sizeof(__u64) * nr_cpus); /* Convert IP-string into 32-bit network byte-order value */ if (inet_pton(AF_INET, ip_string, &key) <=0) return EXIT_FAIL_IP; if (action == ACTION_ADD) { res = bpf_map_update_elem(fd, &key, values, BPF_NOEXIST); } else if (action == ACTION_DEL) { res = bpf_map_delete_elem(fd, &key); } else { return EXIT_FAIL_OPTION; } if (res != 0) { /* 0 == success */ if (errno == 17) /* Already in blacklist */ return EXIT_OK; return EXIT_FAIL_MAP_KEY; } return EXIT_OK; }