snmp: keep printing results after an ICMP answer - #5128
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5128 +/- ##
==========================================
+ Coverage 80.63% 80.64% +0.01%
==========================================
Files 390 390
Lines 96936 96936
==========================================
+ Hits 78168 78178 +10
+ Misses 18768 18758 -10
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
snmpget()can query several targets in one call and prints what each returns. Some answers arenot SNMP at all: Scapy matches an ICMP error to the probe that provoked it, so an unreachable host
or router appears in the answered set.
The result loop at
scapy/layers/snmp.py:290-317prints that error and then returns from the function rather than moving to the next answer.
Everything before the ICMP answer in the iteration has already printed; everything after it is
discarded. The results were collected — they are simply never shown.
The change continues instead of returning:
if ICMP in r.answer: print("%s: %s" % (r.answer.src, r.answer.sprintf("%ICMP.type%"))) - return + continueThe diagnostic still prints, so nothing about the error case is lost.
The added regression builds a multi-target result set with an ICMP answer ahead of a valid SNMP
answer and asserts both appear in the output. Restoring the
returnmakes it fail.Performance was measured on one computer, before and after the fix: a representative call took
113.5 µs before and 114.3 µs after. Repeat runs moved by about 2%, so that difference is smaller
than the test can distinguish.