-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Improve performance with nested PacketFields
#4727
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?
Changes from all commits
9db46b8
4bbaab2
9bf0c54
772459f
cc2572d
2d3c005
6e72bc3
af50227
debbbde
35877da
d6e0cde
ead2e51
e7465c8
33aeae4
0976a60
7fed967
625154c
4583af8
7f0f095
d4d6655
bf0fa0e
e32dab1
23b1628
5a1f68f
471bf40
9415f58
2fec703
9c26a32
000e16b
46f12db
d64e574
8b3eb9d
cb146b8
793fd29
2c638a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| RandInt, | ||
| RandNum, | ||
| RandNumExpo, | ||
| VolatileValue, | ||
| ) | ||
|
|
||
| from scapy.arch import get_if_hwaddr | ||
|
|
@@ -401,6 +402,15 @@ class DHCPOptionsField(StrField): | |
| islist = 1 | ||
|
|
||
| def i2repr(self, pkt, x): | ||
| # `x` may happen to be a `RandDHCPOptions` instance. | ||
| # Example: | ||
| # ```python | ||
| # pkt = fuzz(DHCP()) | ||
| # pkt.show() | ||
| # ``` | ||
| if isinstance(x, VolatileValue): | ||
| return repr(x) | ||
|
|
||
| s = [] | ||
| for v in x: | ||
| if isinstance(v, tuple) and len(v) >= 2: | ||
|
|
@@ -471,6 +481,10 @@ def m2i(self, pkt, x): | |
| return opt | ||
|
|
||
| def i2m(self, pkt, x): | ||
| # Ensure the `RandDHCPOptions` instance has been resolved before (see `Packet.self_build()`). | ||
| # | ||
| assert not isinstance(x, VolatileValue), f"Bad value {x!r}, should have been resolved before" | ||
|
|
||
|
Comment on lines
483
to
+487
|
||
| if isinstance(x, str): | ||
| return x | ||
| s = b"" | ||
|
|
||
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.
ListValuecorrectly clears caches on in-place list mutations, but it doesn't update parent/underlayer relationships forPacketelements added/replaced via list operations (append,insert,extend,__setitem__, etc.). Afterpkt.some_pkt_list.append(NewPkt()),NewPkt.parentwon’t be set to the owning packet, so subsequent edits toNewPktwon’t propagate cache invalidation upwards. Consider extending the wrappers to calladd_parent(self.pkt)(and possiblyadd_underlayer) for anyPacketitems introduced by the mutation (including slice assignments andextend/__iadd__).