-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Sendrecv overhaul: async sniffing & major cleanup #1999
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1999 +/- ##
==========================================
+ Coverage 86.86% 87.14% +0.27%
==========================================
Files 197 197
Lines 44505 44512 +7
==========================================
+ Hits 38661 38791 +130
+ Misses 5844 5721 -123
|
aa62755
to
6a36830
Compare
a4dba5b
to
eab7908
Compare
6bb9e76
to
5ee6640
Compare
@polybassa I finally managed to fix BSD*. The last commit fails because of The PR nearly is in its final state, the only thing left is to fix that. It works all right if I disable those. Also, note that this PR will probably allow to rewrite |
@gpotter2 |
@polybassa You were very right ! Thanks a lot, I had missed the I've updated it using the new mechanic in be21a50, and it appears to have solved the issue ! |
It is an alternative fix for secdev#1199
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.
I need to take more time to review the changes in sendrecv.py but I like the idea of refactoring the code!
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.
This is brilliant. Thanks (and congrats) @gpotter2!
This PR:
REQUIRES Fix FlagsField & dissection improvements #2035sent_time
in__iter__
rather than requiring extra memory space to store the timestamps. This brings a small performance boost, see below.AsyncSniff
, removes tons of duplications, and allow us to useSessions
everywheresniff
usesAsyncSniff
sndrcv
usesAsyncSniff
sndrcvflood
usessndrcv
.Event
usage: not required anymore if we use a class.process
from sndrcv: no one uses it, and it's extremly messy. (My bad). We could reimplement it much easily now that we useAsyncSniffer
withinsndrcv
scapy/automaton.py
AsyncSniffer
None
are ignored on all platforms (previously only Windows/BPF), instead of closing the socket (and using the very unclearTimeoutElapsed
).EOFError
will now be the default exception to close a socket (this behavior is only used in*PcapReader
)conf.use_bpf
would always enable itself even ifconf.use_pcap
was True. (Missing parenthesis)scapy.arch.bpf.supersocket
sockets to use therecv_raw
mechanicIt's a bit harder to implement than it looks, because it must be able to get out of a frozen
select()
, on sockets that don't get any more packets.Perfs:
Using the benchmarking of #1259
Note: the following stats should only be read relatively speaking. The test is performed using a short packet (
Ether()/IP()
) on loopback. It isn't intended to match a real usage by any mean.Notes:
async_select_unrequired=False
means that theselect
function is blocking, therefore a control socket (fake) should be passed. It should be set toTrue
otherwise (Windows/OSX/Pcapdnet)... We could potentially rename itis_blocking_socket=False
if it's clearer (but I only thought of that later 😄)Hopes for the future:
Thanks to the use of *sniff within the sndrcv suite, we have less code to maintain + it will allow us to enable:
Sessions
insndrcv*
: match a chunked HTTP response to its answer ?multiprocessing.dummy
and try to paralellize packet dissections in pools). Edit: to anyone still reading this, note AsyncSniffer does NOT improve performances (or barely). Splitting the work load in multiple threads is useless. We could try to split it across processes, but that makes it much harder to implement. Eventually, the best option to optimize your code is to disable dissection of packets you don't use. We should make an util to make that easier somedayRelated:
fixes #1523
fixes #1505
fixes #1937