diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py index f1ecc210c06..d1d2ee73948 100644 --- a/scapy/layers/inet6.py +++ b/scapy/layers/inet6.py @@ -481,7 +481,20 @@ def answers(self, other): elif other.nh == 43 and isinstance(other.payload, IPv6ExtHdrSegmentRouting): # noqa: E501 return self.payload.answers(other.payload.payload) # Buggy if self.payload is a IPv6ExtHdrRouting # noqa: E501 elif other.nh == 60 and isinstance(other.payload, IPv6ExtHdrDestOpt): - return self.payload.answers(other.payload.payload) + # Extension Headers can show weird behavious. + # Linux's sk_buff considers the IPv6 Payload + # to be either TCP, UDP or ICMP. It does not + # consider Extension Headers to be the payload. + # Following similar architecture, This small + # modification let's packet flow with Destination + # Option on both, request and response packets + # be captured as well. + if UDP in self and UDP in other: + return self[UDP].answers(other[UDP]) + elif TCP in self and TCP in other: + return self[TCP].answers(other[TCP]) + else: + return self.payload.answers(other.payload.payload) # Previous Implementation elif self.nh == 60 and isinstance(self.payload, IPv6ExtHdrDestOpt): # BU in reply to BRR, for instance # noqa: E501 return self.payload.payload.answers(other.payload) else: