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