Skip to content

Commit 3fd1144

Browse files
committed
nflog: only increment packets_nobufs when recv() returns an error
Errno should only be valid when recv() returns a `-1`, indicating an error. I believe the intended behavior here is for packets_nobufs to be a counter that reports back how many times recv() returns an ENOBUFS during a packet capture. Because of the existing logic however, packets_nobufs begins incrementing for every recv() call once the first ENOBUFS error is seen, since errno is not reset when there are no errors returned from recv(). Before (counter deviates from strace): # tcpdump output 38069 packets captured 38069 packets received by filter 38061 packets dropped by kernel # strace output % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 26.47 0.282728 7 38067 3 recvfrom After (counter matches strace): # tcpdump output 38095 packets captured 38095 packets received by filter 7 packets dropped by kernel # strace output % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 27.11 0.258596 6 38096 7 recvfrom
1 parent 5079d5e commit 3fd1144

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pcap-netfilter-linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
123123
handle->break_loop = 0;
124124
return PCAP_ERROR_BREAK;
125125
}
126-
if (errno == ENOBUFS)
126+
if (len == -1 && errno == ENOBUFS)
127127
handlep->packets_nobufs++;
128128
} while ((len == -1) && (errno == EINTR || errno == ENOBUFS));
129129

0 commit comments

Comments
 (0)