vrrp.py 1019 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """Virtual Router Redundancy Protocol."""
  2. from pypacker import pypacker, checksum
  3. class VRRP(pypacker.Packet):
  4. __hdr__ = (
  5. ("vtype", "B", 0x21),
  6. ("vrid", "B", 0),
  7. ("priority", "B", 0),
  8. ("count", "B", 0),
  9. ("atype", "B", 0),
  10. ("advtime", "B", 0),
  11. ("sum", "H", 0),
  12. )
  13. def __get_v(self):
  14. return self.vtype >> 4
  15. def __set_v(self, v):
  16. self.vtype = (self.vtype & ~0xf) | (v << 4)
  17. v = property(__get_v, __set_v)
  18. def __get_type(self):
  19. return self.vtype & 0xf
  20. def __set_type(self, v):
  21. self.vtype = (self.vtype & ~0xf0) | (v & 0xf)
  22. type = property(__get_type, __set_type)
  23. def bin(self, update_auto_fields=True):
  24. if update_auto_fields:
  25. if self._changed():
  26. # logger.debug(">>> IP: calculating sum")
  27. # reset checksum for recalculation, mark as changed / clear cache
  28. self.sum = 0
  29. # logger.debug(">>> IP: bytes for sum: %s" % self.header_bytes)
  30. self.sum = checksum.in_cksum(pypacker.Packet.bin())
  31. return pypacker.Packet.bin(self, update_auto_fields=update_auto_fields)