util-ebpf: only unlink pinned maps in eBPF filter

pull/3952/head
Eric Leblond 6 years ago committed by Victor Julien
parent 4cf531008e
commit 96f1454ebf

@ -66,6 +66,7 @@ struct bpf_map_item {
char iface[IFNAMSIZ]; char iface[IFNAMSIZ];
char * name; char * name;
int fd; int fd;
uint8_t unlink;
}; };
struct bpf_maps_info { struct bpf_maps_info {
@ -86,13 +87,15 @@ static void BpfMapsInfoFree(void *bpf)
int i; int i;
for (i = 0; i < bpfinfo->last; i ++) { for (i = 0; i < bpfinfo->last; i ++) {
if (bpfinfo->array[i].name) { if (bpfinfo->array[i].name) {
char pinnedpath[1024]; if (bpfinfo->array[i].unlink) {
snprintf(pinnedpath, sizeof(pinnedpath), char pinnedpath[1024];
"/sys/fs/bpf/suricata-%s-%s", snprintf(pinnedpath, sizeof(pinnedpath),
bpfinfo->array[i].iface, "/sys/fs/bpf/suricata-%s-%s",
bpfinfo->array[i].name); bpfinfo->array[i].iface,
/* Unlink the pinned entry */ bpfinfo->array[i].name);
unlink(pinnedpath); /* Unlink the pinned entry */
unlink(pinnedpath);
}
SCFree(bpfinfo->array[i].name); SCFree(bpfinfo->array[i].name);
} }
} }
@ -275,6 +278,7 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section,
BpfMapsInfoFree(bpf_map_data); BpfMapsInfoFree(bpf_map_data);
return -1; return -1;
} }
bpf_map_data->array[bpf_map_data->last].unlink = 0;
if (flags & EBPF_PINNED_MAPS) { if (flags & EBPF_PINNED_MAPS) {
SCLogNotice("Pinning: %d to %s", bpf_map_data->array[bpf_map_data->last].fd, SCLogNotice("Pinning: %d to %s", bpf_map_data->array[bpf_map_data->last].fd,
bpf_map_data->array[bpf_map_data->last].name); bpf_map_data->array[bpf_map_data->last].name);
@ -285,6 +289,12 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section,
if (ret != 0) { if (ret != 0) {
SCLogError(SC_ERR_AFP_CREATE, "Can not pin: %s", strerror(errno)); SCLogError(SC_ERR_AFP_CREATE, "Can not pin: %s", strerror(errno));
} }
/* Don't unlink pinned maps in XDP mode to avoid a state reset */
if (flags & EBPF_XDP_CODE) {
bpf_map_data->array[bpf_map_data->last].unlink = 0;
} else {
bpf_map_data->array[bpf_map_data->last].unlink = 1;
}
} }
bpf_map_data->last++; bpf_map_data->last++;
} }

Loading…
Cancel
Save