Skip to content

Commit 3eca692

Browse files
committed
linux: print a better message for "out of memory" errors for kernel filters.
If attempting to set a kernel filter gets ENOMEM, print a message suggesting that they increase the value of the net.core.optmem_max sysctl. See GitHub issue #1089 for an example of a complicated but not too complicated filter that exceeds the default "other/option memory per socket" maximum.
1 parent 9d928eb commit 3eca692

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pcap-linux.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,7 +4410,18 @@ pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
44104410
* the filter for a reason other than "this kernel
44114411
* isn't configured to support socket filters.
44124412
*/
4413-
if (errno != ENOPROTOOPT && errno != EOPNOTSUPP) {
4413+
if (errno == ENOMEM) {
4414+
/*
4415+
* Either a kernel memory allocation
4416+
* failure occurred, or there's too
4417+
* much "other/option memory" allocated
4418+
* for this socket. Suggest that they
4419+
* increase the "other/option memory"
4420+
* limit.
4421+
*/
4422+
fprintf(stderr,
4423+
"Warning: Couldn't allocate kernel memory for filter: try increasing net.core.optmem_max with sysctl\n");
4424+
} else if (errno != ENOPROTOOPT && errno != EOPNOTSUPP) {
44144425
fprintf(stderr,
44154426
"Warning: Kernel filter failed: %s\n",
44164427
pcap_strerror(errno));

0 commit comments

Comments
 (0)