-
Notifications
You must be signed in to change notification settings - Fork 904
open a non-existent interface should always return 'no such interface' #1560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
open a non-existent interface should always return 'no such interface' #1560
Conversation
2848591
to
b6e51a7
Compare
Thank you for preparing this change. The comments that clarify the problem and the solution should be in the commit message. |
* There's nothing more to say, so clear the | ||
* error message. | ||
*/ | ||
handle->tstamp_type_list = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why tstamp_type_list
no longer needs to be set here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing these changes
because current code ignoring the ENODEV error and treating it as a success case, assumes the user will discover the real problem later during activation
case ENODEV:
..
handle->tstamp_type_list = NULL;
return 0; // SUCCESS, continue execution
This is problematic because it allows execution to continue with a non existent interface, leading to confusing error messages later
The new code immediately fails when it detects ENODEV:
case ENODEV:
...
ebuf[0] = '\0';
return PCAP_ERROR_NO_SUCH_DEVICE; // MMEDIATE FAILURE
after returning PCAP_ERROR_NO_SUCH_DEVICE, the calling function (pcapint_create_interface
) do:
if (iface_get_ts_types(device, handle, ebuf) == -1) {
pcap_close(handle); // Cleans up the handle
return NULL; // Function exits immediately
}
Since the function exits immediately and calls pcap_close(handle)
, there's no point in setting tstamp_type_list
On Linux the only proposed change is to
It looks like the two proposed changes are not related and should be two different commits, each stating and solving a separate problem. Also, since This requires a bit more work before it is ready. |
d5797aa
to
8b097c7
Compare
When attempting to open a non-existent network interface on Linux, libpcap would return PCAP_ERROR_PERM_DENIED instead of the correct PCAP_ERROR_NO_SUCH_DEVICE. This occurred because the privileged socket(PF_PACKET, SOCK_RAW, 0) call in setup_socket() would fail with permission errors before interface validation could occur. This fix adds an interface existence check using an unprivileged AF_INET socket and SIOCGIFINDEX ioctl before attempting to create the privileged packet socket. Non-existent interfaces now correctly return PCAP_ERROR_NO_SUCH_DEVICE. This resolves the issue where applications like tcpdump would report "Permission denied" instead of "No such device exists" for non-existent interfaces, breaking their fallback logic from interface names to indices. Note: BSD/macOS platforms have the same underlying issue where BPF device access fails with permission errors before interface validation. This should be addressed in a separate commit. Fixes: libpcap issue the-tcpdump-group#1538 Related: tcpdump issue the-tcpdump-group#1334 Signed-off-by: Afshin Paydar <afshin.paydar@deriv.com>
02956d2
to
ffb13dc
Compare
Fix interface existence check on Linux before privileged operations
When attempting to open a non-existent network interface on Linux,
libpcap would return PCAP_ERROR_PERM_DENIED instead of the correct
PCAP_ERROR_NO_SUCH_DEVICE. This occurred because the privileged
socket(PF_PACKET, SOCK_RAW, 0) call in setup_socket() would fail
with permission errors before interface validation could occur.
This fix adds an interface existence check using an unprivileged
AF_INET socket and SIOCGIFINDEX ioctl before attempting to create
the privileged packet socket. Non-existent interfaces now correctly
return PCAP_ERROR_NO_SUCH_DEVICE.
This resolves the issue where applications like tcpdump would report
"Permission denied" instead of "No such device exists" for non-existent
interfaces, breaking their fallback logic from interface names to indices.
Note: BSD/macOS platforms have the same underlying issue where BPF device
access fails with permission errors before interface validation. This
should be addressed in a separate commit.
Fixes: libpcap issue #1538
Related: tcpdump issue #1334