Handle disconnected interfaces (and periodically attempt to re-connect)#191
Handle disconnected interfaces (and periodically attempt to re-connect)#191imsnif merged 4 commits intoimsnif:mainfrom thepacketgeek:iface-disconnect
Conversation
Sniffer::next() now returns an io::Result so the thread in main can determine between no packets & a sniffing error - Matching on EtherType to remove duplicate code determining IP Version Added Sniffer::reset_channel to allow main to poll a previously connected interface
|
Hey @thepacketgeek, this looks like a good direction.
I think this would work well, seeing as it will only sleep if the network interface becomes unavailable. I think this is a relatively rare occurrence all-in-all.
I think handling it silently is fine. Maybe in the future we can develop a warning box, interface status line or some such, but right now I feel this is out-of-scope information for the tool. As for the PR itself: |
|
Thanks for the feedback @imsnif! I changed The thread is parked prior to returning None. This works as the thread will call Err(err) => match err.kind() {
std::io::ErrorKind::TimedOut => {
park_timeout(PACKET_WAIT_TIMEOUT);
return None;
}
_ => {
park_timeout(CHANNEL_RESET_DELAY);
self.reset_channel().ok();
return None;
}
}, |
|
@thepacketgeek - I saw your fixes, my apologies for not getting to them yet. I'm going to take a look tomorrow. |
imsnif
left a comment
There was a problem hiding this comment.
Hey, so thanks with bearing with my slightly hectic week. :)
This change looks great. I left one small nitpick (I'd have removed it myself but wanted to make sure with you it wasn't something I'm missing). Once we address that, I'll merge this.
|
Thanks for the review @imsnif! |
|
Awesome, thanks for this @thepacketgeek! |
Addresses #150, which I was able to repro on a Mac by disconnecting an Ethernet dongle during sniffing. The timeout suggestion fix works and I'd like some guidance around the following:
Timeout selection
Currently, there's no timeout so
Sniffer.next()is called in rapid succession. I used a timeout of 10 ms here as it's a good middle ground for keeping sniffing real-time and not spinning too much on a quiet interface.Interface disconnects handled silently
There's no more CPU spike @ 100% after an interface is disconnected. The thread will silently continue to re-establish the channel for that interface. Should this be handled silently and should bandwhich periodically attempt to reconnect (currently at the same 1 second interval of display updates)