Skip to content

Commit df556c7

Browse files
committed
feat (layer + test): fixed code health checks and Copilot's comments
AI-Assisted: yes (OpenAI Codex)
1 parent 3285a55 commit df556c7

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

scapy/layers/hsrp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _is_hsrpv2(pkt):
6262
tlvtype = orb(pkt[0:1])
6363
tlvlength = orb(pkt[1:2])
6464

65-
if tlvtype not in _HSRP_V2_TLV_TYPES:
65+
if tlvtype == 0:
6666
return False
6767

6868
if len(pkt) < 2 + tlvlength:
@@ -299,10 +299,10 @@ def post_build(self, p, pay):
299299
bind_layers(UDP, HSRP, dport=1985, sport=1985)
300300

301301
DestIPField.bind_addr(UDP, "224.0.0.2", dport=1985)
302-
"""
303-
since port 1954 (UDP) would be shared by both hsrpv1 and hsprv2 (ipv4),
304-
users building hsrpv2 (ipv4) packets should set IP(dst="224.0.0.102") explicitly to avoid using wrong multicast destination
305-
"""
302+
# UDP port 1985 is shared by HSRPv1 and HSRPv2 for IPv4
303+
# To avoid using the HSRPv1 multicast destination, explicitly set
304+
# IP(dst="224.0.0.102") when building HSRPv2 packets.
305+
# Otherwise, consider below for binding.
306306
# DestIPField.bind_addr(UDP, "224.0.0.102", dport=1985)
307307

308308
if conf.ipv6_enabled:

test/scapy/layers/hsrp.uts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ assert pkt[HSRPv2UnknownTLV].type == 99
106106
assert pkt[HSRPv2UnknownTLV].len == 4
107107
assert pkt[HSRPv2UnknownTLV].value == b"abcd"
108108

109+
= HSRPv2 - Unknown first TLV UDP dispatch
110+
pkt = IP(raw(
111+
IP(dst="224.0.0.102") /
112+
UDP(dport=1985, sport=1985) /
113+
HSRPv2UnknownTLV(type=99, value=b"abcd")
114+
))
115+
assert HSRPv2 in pkt and HSRPv2UnknownTLV in pkt and HSRP not in pkt
116+
assert pkt[HSRPv2UnknownTLV].type == 99
117+
assert pkt[HSRPv2UnknownTLV].len == 4
118+
assert pkt[HSRPv2UnknownTLV].value == b"abcd"
119+
109120
= HSRPv2 - MD5 Auth TLV build & dissection
110121
digest = b"\x11" * 16
111122
pkt = HSRPv2(raw(

0 commit comments

Comments
 (0)