pppoe.py 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """PPP-over-Ethernet."""
  2. from pypacker import pypacker
  3. from pypacker.layer12.ppp import PPP
  4. import struct
  5. # RFC 2516 codes
  6. PPPoE_PADI = 0x09
  7. PPPoE_PADO = 0x07
  8. PPPoE_PADR = 0x19
  9. PPPoE_PADS = 0x65
  10. PPPoE_PADT = 0xA7
  11. PPPoE_SESSION = 0x00
  12. class PPPoE(pypacker.Packet):
  13. __hdr__ = (
  14. ("v_type", "B", 0x11),
  15. ("code", "B", 0),
  16. ("session", "H", 0),
  17. ("len", "H", 0) # payload length
  18. )
  19. def __get_v(self):
  20. return self.v_type >> 4
  21. def __set_v(self, v):
  22. self.v_type = (v << 4) | (self.v_type & 0xf)
  23. v = property(__get_v, __set_v)
  24. def __get_type(self):
  25. return self.v_type & 0xf
  26. def __set_type(self, t):
  27. self.v_type = (self.v_type & 0xf0) | t
  28. type = property(__get_type, __set_type)
  29. def _dissect(self, buf):
  30. code = buf[1]
  31. if code == PPPoE_SESSION:
  32. try:
  33. self._set_bodyhandler(PPP(buf[6:]))
  34. except (KeyError, struct.error, pypacker.UnpackError):
  35. pass
  36. else:
  37. pass
  38. return 6
  39. # XXX - TODO TLVs, etc.