From 6695b89afb63d30f9a8c2e424ba64765e5d699e5 Mon Sep 17 00:00:00 2001 From: Guillaume Valadon <guillaume@valadon.net> Date: Thu, 1 Aug 2013 17:51:25 +0200 Subject: [PATCH] Issues #884 & #915: IPv6 NA is not a NS & Error in class ICMPv6ND_NS(_ICMPv6NDGuessPayload, _ICMPv6, Packet): --- scapy/layers/inet6.py | 25 +++++++++++++++++-------- test/regression.uts | 6 +++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py index a4c787ef..a131f7a9 100644 --- a/scapy/layers/inet6.py +++ b/scapy/layers/inet6.py @@ -1687,10 +1687,7 @@ class ICMPv6ND_NS(_ICMPv6NDGuessPayload, _ICMPv6, Packet): fields_desc = [ ByteEnumField("type",135, icmp6types), ByteField("code",0), XShortField("cksum", None), - BitField("R",0,1), - BitField("S",0,1), - BitField("O",0,1), - XBitField("res",0,29), + IntField("res", 0), IP6Field("tgt","::") ] overload_fields = {IPv6: { "nh": 58, "dst": "ff02::1", "hlim": 255 }} @@ -1700,11 +1697,23 @@ class ICMPv6ND_NS(_ICMPv6NDGuessPayload, _ICMPv6, Packet): def hashret(self): return self.tgt+self.payload.hashret() -class ICMPv6ND_NA(ICMPv6ND_NS): +class ICMPv6ND_NA(_ICMPv6NDGuessPayload, _ICMPv6, Packet): name = "ICMPv6 Neighbor Discovery - Neighbor Advertisement" - type = 136 - R = 1 - O = 1 + fields_desc = [ ByteEnumField("type",136, icmp6types), + ByteField("code",0), + XShortField("cksum", None), + BitField("R",1,1), + BitField("S",0,1), + BitField("O",1,1), + XBitField("res",0,29), + IP6Field("tgt","::") ] + overload_fields = {IPv6: { "nh": 58, "dst": "ff02::1", "hlim": 255 }} + + def mysummary(self): + return self.sprintf("%name% (tgt: %tgt%)") + + def hashret(self): + return self.tgt+self.payload.hashret() def answers(self, other): return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt diff --git a/test/regression.uts b/test/regression.uts index d97e377b..916afdc4 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -1741,15 +1741,15 @@ isinstance(a, IPv6) and a.nh == 58 and a.hlim == 255 and isinstance(a.payload, I str(ICMPv6ND_NS()) == '\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' = ICMPv6ND_NS - Instantiation with specific values -str(ICMPv6ND_NS(code=0x11, R=1, S=1, O=1, res=1, tgt="ffff::1111")) == '\x87\x11\x00\x00\xe0\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11' +str(ICMPv6ND_NS(code=0x11, res=3758096385, tgt="ffff::1111")) == '\x87\x11\x00\x00\xe0\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11' = ICMPv6ND_NS - Basic Dissection a=ICMPv6ND_NS('\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -a.code==0 and a.R==0 and a.S==0 and a.O==0 and a.res==0 and a.tgt=="::" +a.code==0 and a.res==0 and a.tgt=="::" = ICMPv6ND_NS - Dissection with specific values a=ICMPv6ND_NS('\x87\x11\x00\x00\xe0\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11') -a.code==0x11 and a.R==1 and a.S==1 and a.O==1 and a.res==1 and a.tgt=="ffff::1111" +a.code==0x11 and a.res==3758096385 and a.tgt=="ffff::1111" = ICMPv6ND_NS - IPv6 layer fields overloading a=IPv6(str(IPv6()/ICMPv6ND_NS())) -- GitLab