From 2664ff88021d6bb732944ae3ce13329c970bc3b2 Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Fri, 20 Jan 2017 08:34:21 +0100
Subject: [PATCH] Use SourceIPField in HSRPmd5

---
 scapy/layers/hsrp.py |  2 +-
 test/regression.uts  | 27 +++++++++++++--------------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/scapy/layers/hsrp.py b/scapy/layers/hsrp.py
index 3558bbf9..9fa09c1d 100644
--- a/scapy/layers/hsrp.py
+++ b/scapy/layers/hsrp.py
@@ -67,7 +67,7 @@ class HSRPmd5(Packet):
         ByteEnumField("algo", 0, {1: "MD5"}),
         ByteField("padding", 0x00),
         XShortField("flags", 0x00),
-        IPField("sourceip", "127.0.0.1"),
+        SourceIPField("sourceip", None),
         XIntField("keyid", 0x00),
         StrFixedLenField("authdigest", "\00" * 16, 16)]
 
diff --git a/test/regression.uts b/test/regression.uts
index f8bec41e..a2cd5a5b 100644
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -281,16 +281,16 @@ assert( _ == "FOO\x01\x02\x03\x04" )
 
 = SourceIPField
 ~ core field
-defgw = conf.route.route('0.0.0.0')[1]
+defaddr = conf.route.route('0.0.0.0')[1]
 class Test(Packet): fields_desc = [SourceIPField("sourceip", None)]
 
-assert Test().sourceip == defgw
-assert Test(str(Test())).sourceip == defgw
+assert Test().sourceip == defaddr
+assert Test(str(Test())).sourceip == defaddr
 
-assert IP(dst="0.0.0.0").src == defgw
-assert IP(str(IP(dst="0.0.0.0"))).src == defgw
-assert IP(dst="0.0.0.0/31").src == defgw
-assert IP(str(IP(dst="0.0.0.0/31"))).src == defgw
+assert IP(dst="0.0.0.0").src == defaddr
+assert IP(str(IP(dst="0.0.0.0"))).src == defaddr
+assert IP(dst="0.0.0.0/31").src == defaddr
+assert IP(str(IP(dst="0.0.0.0/31"))).src == defaddr
 
 
 #= ByteField
@@ -7185,13 +7185,12 @@ L2TP in p and p[L2TP].len == 14 and p.tunnel_id == 0 and p[UDP].chksum == 0xf465
 
 + HSRP tests
 
-= HSRP - build
-s = str(IP(src="127.0.0.1")/UDP(dport=1985, sport=1985)/HSRP()/HSRPmd5())
-s == 'E\x00\x00N\x00\x01\x00\x00@\x11\x1b\x9b\x7f\x00\x00\x01\xe0\x00\x00\x02\x07\xc1\x07\xc1\x00:\xeb\x00\x00\x00\x10\x03\nx\x01\x00cisco\x00\x00\x00\xc0\xa8\x01\x01\x04\x00\x00\x00\x00\x00\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
-
-= HSRP - dissection
-p = IP(s)
-p[IP].dst == "224.0.0.2" and HSRPmd5 in p and p[HSRPmd5].sourceip == "127.0.0.1"
+= HSRP - build & dissection
+defaddr = conf.route.route('0.0.0.0')[1]
+pkt = IP(str(IP()/UDP(dport=1985, sport=1985)/HSRP()/HSRPmd5()))
+assert pkt[IP].dst == "224.0.0.2" and pkt[UDP].sport == pkt[UDP].dport == 1985
+assert pkt[HSRP].opcode == 0 and pkt[HSRP].state == 16
+assert pkt[HSRPmd5].type == 4 and pkt[HSRPmd5].sourceip == defaddr
 
 
 ############
-- 
GitLab