diff --git a/scapy/layers/lltd.py b/scapy/layers/lltd.py index e7cdf685593bd251722f6520016e8508f1538a30..e28dd0f9c38a556db088249e384934aa4d3182e2 100644 --- a/scapy/layers/lltd.py +++ b/scapy/layers/lltd.py @@ -25,6 +25,12 @@ from scapy.data import ETHER_ANY class LLTD(Packet): name = "LLTD" + answer_hashret = { + # (tos, function) tuple mapping (answer -> query), used by + # .hashret() + (1, 1): (0, 0), + (0, 12): (0, 11), + } fields_desc = [ ByteField("version", 1), ByteEnumField("tos", 0, { @@ -96,6 +102,38 @@ class LLTD(Packet): else: return self.sprintf('LLTD %tos% - %function%') + def hashret(self): + tos, function = self.tos, self.function + return "%c%c" % self.answer_hashret.get((tos, function), + (tos, function)) + + def answers(self, other): + if not isinstance(other, LLTD): + return False + if self.tos == 0: + if self.function == 0 and isinstance(self.payload, LLTDDiscover) \ + and len(self[LLTDDiscover].stations_list) == 1: + # "Topology discovery - Discover" with one MAC address + # discovered answers a "Quick discovery - Hello" + return other.tos == 1 and \ + other.function == 1 and \ + LLTDAttributeHostID in other and \ + other[LLTDAttributeHostID].mac == \ + self[LLTDDiscover].stations_list[0] + elif self.function == 12: + # "Topology discovery - QueryLargeTlvResp" answers + # "Topology discovery - QueryLargeTlv" with same .seq + # value + return other.tos == 0 and other.function == 11 \ + and other.seq == self.seq + elif self.tos == 1: + if self.function == 1 and isinstance(self.payload, LLTDHello): + # "Quick discovery - Hello" answers a "Topology + # discovery - Discover" + return other.tos == 0 and other.function == 0 and \ + other.real_src == self.current_mapper_address + return False + class LLTDHello(Packet): name = "LLTD - Hello"