Ticket #21: scapy_gre.diff

File scapy_gre.diff, 2.9 kB (added by zer0@droids-corp.org, 2 years ago)

Add a patch that extend scapy GRE protocol to RFC 1701

  • scapy.py

    old new  
    71967196    def mysummary(self): 
    71977197        return self.sprintf("NTP v%ir,NTP.version%, %NTP.mode%") 
    71987198 
     7199class GRErouting(Packet): 
     7200    name = "GRE routing informations" 
     7201    fields_desc = [ ShortField("address_family",0), 
     7202                    ByteField("SRE_offset", 0), 
     7203                    FieldLenField("SRE_len", None, "routing_info", "B"), 
     7204                    StrLenField("routing_info", "", "SRE_len"), 
     7205                    ] 
     7206 
    71997207 
    72007208class GRE(Packet): 
    72017209    name = "GRE" 
    7202     fields_desc = [ BitField("chksumpresent",0,1), 
    7203                     BitField("reserved0",0,12), 
     7210    fields_desc = [ BitField("chksum_present",0,1), 
     7211                    BitField("routing_present",0,1), 
     7212                    BitField("key_present",0,1), 
     7213                    BitField("seqnum_present",0,1), 
     7214                    BitField("strict_route_source",0,1), 
     7215                    BitField("recursion control",0,3), 
     7216                    BitField("flags",0,5), 
    72047217                    BitField("version",0,3), 
    72057218                    XShortEnumField("proto", 0x0000, ETHER_TYPES), 
    7206                     ConditionalField(XShortField("chksum",None),"chksumpresent",lambda x:x==1), 
    7207                     ConditionalField(XShortField("reserved1",None),"chksumpresent",lambda x:x==1), 
     7219                    ConditionalField(XShortField("chksum",None),["chksum_present","routing_present"],lambda x:x!=[0,0]), 
     7220                    ConditionalField(XShortField("offset",None),["chksum_present","routing_present"],lambda x:x!=[0,0]), 
     7221                    ConditionalField(XIntField("key",None),"key_present",lambda x:x==1), 
     7222                    ConditionalField(XIntField("seqence_number",None),"seqnum_present",lambda x:x==1), 
    72087223                    ] 
    72097224    def post_build(self, p, pay): 
    72107225        p += pay 
    7211         if self.chksumpresent and self.chksum is None: 
     7226        if self.chksum_present and self.chksum is None: 
    72127227            c = checksum(p) 
    72137228            p = p[:4]+chr((c>>8)&0xff)+chr(c&0xff)+p[6:] 
    72147229        return p 
     
    85708585                ( GRE,    ARP,      { "proto" : 0x0806 } ), 
    85718586                ( GRE,    IP,       { "proto" : 0x0800 } ), 
    85728587                ( GRE,    EAPOL,    { "proto" : 0x888e } ), 
     8588                ( GRE,           GRErouting,      { "routing_present" : 1 } ), 
     8589                ( GRErouting,    Raw,             { "address_family" : 0, 
     8590                                                    "SRE_len" : 0 } ), 
     8591                ( GRErouting,    GRErouting,      { } ), 
    85738592                ( PPPoE,  PPP,      { "code" : 0x00 } ), 
    85748593                ( EAPOL,  EAP,      { "type" : EAPOL.EAP_PACKET } ), 
    85758594                ( LLC,    STP,      { "dsap" : 0x42 , "ssap" : 0x42, "ctrl":3 } ),