Changeset 917:711cf86b0af4

Show
Ignore:
Timestamp:
09/12/08 17:57:20 (4 months ago)
Author:
Phil <phil@secdev.org>
Message:

Removed tabs/space mixup in layers/inet6.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scapy/layers/inet6.py

    r916 r917  
    4444 
    4545if OPENBSD or FREEBSD or NETBSD or DARWIN: 
    46        loname = "lo0" 
     46        loname = "lo0" 
    4747else: 
    48        loname = "lo" 
     48        loname = "lo" 
    4949 
    5050# From net/ipv6.h on Linux (+ Additions) 
     
    8484    cset = [] 
    8585    if in6_isgladdr(addr): 
    86        cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
     86        cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
    8787    elif in6_islladdr(addr): 
    88        cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr) 
     88        cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr) 
    8989    elif in6_issladdr(addr): 
    90        cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr) 
     90        cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr) 
    9191    elif in6_ismaddr(addr): 
    92        if in6_ismnladdr(addr): 
    93            cset = [('::1', 16, loname)] 
    94        elif in6_ismgladdr(addr): 
    95            cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
    96        elif in6_ismlladdr(addr): 
    97            cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr) 
    98        elif in6_ismsladdr(addr): 
    99            cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr) 
     92        if in6_ismnladdr(addr): 
     93            cset = [('::1', 16, loname)] 
     94        elif in6_ismgladdr(addr): 
     95            cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
     96        elif in6_ismlladdr(addr): 
     97            cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr) 
     98        elif in6_ismsladdr(addr): 
     99            cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr) 
    100100    elif addr == '::' and plen == 0: 
    101        cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
     101        cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
    102102    cset = map(lambda x: x[0], cset) 
    103103    return cset             
     
    116116     
    117117    if len(candidate_set) == 0: 
    118        # Should not happen 
    119        return None 
     118        # Should not happen 
     119        return None 
    120120     
    121121    if in6_isaddr6to4(dst): 
    122        tmp = filter(lambda x: in6_isaddr6to4(x), candidate_set) 
    123        if len(tmp) != 0: 
    124            return tmp[0] 
     122        tmp = filter(lambda x: in6_isaddr6to4(x), candidate_set) 
     123        if len(tmp) != 0: 
     124            return tmp[0] 
    125125 
    126126    return candidate_set[0] 
     
    143143        #        if any. Change that ... 
    144144        self.invalidate_cache() 
    145        self.routes = read_routes6() 
    146        if self.routes == []: 
    147             log_loading.info("No IPv6 support in kernel") 
     145        self.routes = read_routes6() 
     146        if self.routes == []: 
     147             log_loading.info("No IPv6 support in kernel") 
    148148         
    149149    def __repr__(self): 
     
    151151 
    152152        for net,msk,gw,iface,cset in self.routes: 
    153            rtlst.append(('%s/%i'% (net,msk), gw, iface, ", ".join(cset))) 
     153            rtlst.append(('%s/%i'% (net,msk), gw, iface, ", ".join(cset))) 
    154154 
    155155        colwidth = map(lambda x: max(map(lambda y: len(y), x)), apply(zip, rtlst)) 
     
    393393        """ 
    394394        ret = [] 
    395        try: 
    396            f = open("/proc/net/if_inet6","r") 
    397        except IOError, err:     
    398            return ret 
    399        l = f.readlines() 
    400        for i in l: 
    401            # addr, index, plen, scope, flags, ifname 
    402            tmp = i.split() 
    403            addr = struct.unpack('4s4s4s4s4s4s4s4s', tmp[0]) 
    404            addr = in6_ptop(':'.join(addr)) 
    405            ret.append((addr, int(tmp[3], 16), tmp[5])) # (addr, scope, iface) 
    406                return ret 
     395        try: 
     396            f = open("/proc/net/if_inet6","r") 
     397        except IOError, err:     
     398            return ret 
     399        l = f.readlines() 
     400        for i in l: 
     401            # addr, index, plen, scope, flags, ifname 
     402            tmp = i.split() 
     403            addr = struct.unpack('4s4s4s4s4s4s4s4s', tmp[0]) 
     404            addr = in6_ptop(':'.join(addr)) 
     405            ret.append((addr, int(tmp[3], 16), tmp[5])) # (addr, scope, iface) 
     406        return ret 
    407407 
    408408    def read_routes6(): 
    409        try: 
    410            f = open("/proc/net/ipv6_route","r") 
    411        except IOError, err: 
    412            return [] 
    413        # 1. destination network 
    414        # 2. destination prefix length 
    415        # 3. source network displayed 
    416        # 4. source prefix length 
     409        try: 
     410            f = open("/proc/net/ipv6_route","r") 
     411        except IOError, err: 
     412            return [] 
     413        # 1. destination network 
     414        # 2. destination prefix length 
     415        # 3. source network displayed 
     416        # 4. source prefix length 
    417417        # 5. next hop 
    418        # 6. metric 
    419        # 7. reference counter (?!?) 
    420        # 8. use counter (?!?) 
    421        # 9. flags 
    422        # 10. device name 
     418        # 6. metric 
     419        # 7. reference counter (?!?) 
     420        # 8. use counter (?!?) 
     421        # 9. flags 
     422        # 10. device name 
    423423        routes = [] 
    424        def proc2r(p): 
    425            ret = struct.unpack('4s4s4s4s4s4s4s4s', p) 
    426            ret = ':'.join(ret) 
    427            return in6_ptop(ret) 
     424        def proc2r(p): 
     425            ret = struct.unpack('4s4s4s4s4s4s4s4s', p) 
     426            ret = ':'.join(ret) 
     427            return in6_ptop(ret) 
    428428         
    429        lifaddr = in6_getifaddr()  
     429        lifaddr = in6_getifaddr()  
    430430        for l in f.readlines(): 
    431            d,dp,s,sp,nh,m,rc,us,fl,dev = l.split() 
     431            d,dp,s,sp,nh,m,rc,us,fl,dev = l.split() 
    432432            fl = int(fl, 16) 
    433433 
     
    437437                continue 
    438438 
    439            d = proc2r(d) ; dp = int(dp, 16) 
    440            s = proc2r(s) ; sp = int(sp, 16) 
    441            nh = proc2r(nh) 
     439            d = proc2r(d) ; dp = int(dp, 16) 
     440            s = proc2r(s) ; sp = int(sp, 16) 
     441            nh = proc2r(nh) 
    442442 
    443443            cset = [] # candidate set (possible source addresses) 
    444            if dev == loname: 
    445                if d == '::': 
    446                    continue 
    447                cset = ['::1'] 
    448            else: 
     444            if dev == loname: 
     445                if d == '::': 
     446                    continue 
     447                cset = ['::1'] 
     448            else: 
    449449                devaddrs = filter(lambda x: x[2] == dev, lifaddr) 
    450                cset = construct_source_candidate_set(d, dp, devaddrs) 
    451             
     450                cset = construct_source_candidate_set(d, dp, devaddrs) 
     451             
    452452            if len(cset) != 0: 
    453                routes.append((d, dp, nh, dev, cset)) 
    454        f.close() 
    455         return routes    
     453                routes.append((d, dp, nh, dev, cset)) 
     454        f.close() 
     455        return routes    
    456456 
    457457elif WINDOWS: 
     
    496496 
    497497        ret = [] 
    498        i = dnet.intf() 
     498        i = dnet.intf() 
    499499        for int in i: 
    500            ifname = int['name'] 
     500            ifname = int['name'] 
    501501            v6 = [] 
    502            if int.has_key('alias_addrs'): 
    503                v6 = int['alias_addrs'] 
    504            for a in v6: 
    505                if a.type != dnet.ADDR_TYPE_IP6: 
    506                    continue 
    507  
    508                xx = str(a).split('/')[0] 
    509                addr = in6_ptop(xx) 
    510  
    511                scope = in6_getscope(addr) 
    512  
    513                ret.append((xx, scope, ifname)) 
     502            if int.has_key('alias_addrs'): 
     503                v6 = int['alias_addrs'] 
     504            for a in v6: 
     505                if a.type != dnet.ADDR_TYPE_IP6: 
     506                    continue 
     507 
     508                xx = str(a).split('/')[0] 
     509                addr = in6_ptop(xx) 
     510 
     511                scope = in6_getscope(addr) 
     512 
     513                ret.append((xx, scope, ifname)) 
    514514        return ret 
    515515 
     
    526526                ok = l.find('Destination') 
    527527                continue 
    528             # gv 12/12/06: under debugging      
    529            if NETBSD or OPENBSD: 
    530                d,nh,fl,_,_,_,dev = l.split()[:7] 
    531            else:       # FREEBSD or DARWIN  
     528            # gv 12/12/06: under debugging       
     529            if NETBSD or OPENBSD: 
     530                d,nh,fl,_,_,_,dev = l.split()[:7] 
     531            else:       # FREEBSD or DARWIN  
    532532                d,nh,fl,dev = l.split()[:4] 
    533            if filter(lambda x: x[2] == dev, lifaddr) == []: 
    534                continue 
     533            if filter(lambda x: x[2] == dev, lifaddr) == []: 
     534                continue 
    535535            if 'L' in fl: # drop MAC addresses 
    536536                continue 
    537537 
    538538            if 'link' in nh: 
    539                nh = '::' 
    540  
    541            cset = [] # candidate set (possible source addresses) 
    542            dp = 128 
    543            if d == 'default': 
    544                d = '::' 
    545                dp = 0 
    546            if '/' in d: 
    547                d,dp = d.split("/") 
    548                dp = int(dp) 
    549            if '%' in d: 
    550                d,dev = d.split('%') 
    551            if '%' in nh: 
    552                nh,dev = nh.split('%') 
    553            if loname in dev: 
    554                cset = ['::1'] 
    555                nh = '::' 
     539                nh = '::' 
     540 
     541            cset = [] # candidate set (possible source addresses) 
     542            dp = 128 
     543            if d == 'default': 
     544                d = '::' 
     545                dp = 0 
     546            if '/' in d: 
     547                d,dp = d.split("/") 
     548                dp = int(dp) 
     549            if '%' in d: 
     550                d,dev = d.split('%') 
     551            if '%' in nh: 
     552                nh,dev = nh.split('%') 
     553            if loname in dev: 
     554                cset = ['::1'] 
     555                nh = '::' 
    556556            else: 
    557                devaddrs = filter(lambda x: x[2] == dev, lifaddr) 
    558                cset = construct_source_candidate_set(d, dp, devaddrs) 
     557                devaddrs = filter(lambda x: x[2] == dev, lifaddr) 
     558                cset = construct_source_candidate_set(d, dp, devaddrs) 
    559559 
    560560            if len(cset) != 0: 
    561                routes.append((d, dp, nh, dev, cset)) 
     561                routes.append((d, dp, nh, dev, cset)) 
    562562 
    563563        f.close() 
     
    741741 
    742742        netmask = int(tmp[1]) 
    743        self.net = inet_pton(socket.AF_INET6, tmp[0]) 
     743        self.net = inet_pton(socket.AF_INET6, tmp[0]) 
    744744        self.mask = in6_cidr2mask(netmask) 
    745        self.plen = netmask 
     745        self.plen = netmask 
    746746 
    747747    def __iter__(self): 
    748748        def m8(i): 
    749            if i % 8 == 0: 
     749            if i % 8 == 0: 
    750750                return i 
    751751        tuple = filter(lambda x: m8(x), xrange(8, 129)) 
     
    761761 
    762762        def rec(n, l):  
    763            if n and  n % 2 == 0: 
    764                sep = ':' 
    765             else:        
     763            if n and  n % 2 == 0: 
     764                sep = ':' 
     765            else:        
    766766                sep = '' 
    767767            if n == 16: 
    768                return l 
     768                return l 
    769769            else: 
    770                ll = [] 
    771                for i in xrange(*self.parsed[n]): 
    772                    for y in l: 
    773                        ll += [y+sep+'%.2x'%i] 
    774                return rec(n+1, ll) 
     770                ll = [] 
     771                for i in xrange(*self.parsed[n]): 
     772                    for y in l: 
     773                        ll += [y+sep+'%.2x'%i] 
     774                return rec(n+1, ll) 
    775775 
    776776        return iter(rec(0, [''])) 
     
    818818     
    819819    if dstAddrType == IPV6_ADDR_UNSPECIFIED: # Shouldn't happen as dst addr 
    820        return None 
     820        return None 
    821821 
    822822    if dstAddrType == IPV6_ADDR_LOOPBACK:  
    823        return None 
     823        return None 
    824824 
    825825    tmp = [[]] + map(lambda (x,y,z): (in6_getAddrType(x), x, y, z), laddr) 
    826826    def filterSameScope(l, t): 
    827        if (t[0] & dstAddrType & IPV6_ADDR_SCOPE_MASK) == 0: 
    828            l.append(t) 
    829        return l 
     827        if (t[0] & dstAddrType & IPV6_ADDR_SCOPE_MASK) == 0: 
     828            l.append(t) 
     829        return l 
    830830    sameScope = reduce(filterSameScope, tmp) 
    831831     
    832832    l =  len(sameScope)  
    833833    if l == 1:  # Only one address for our scope 
    834        return sameScope[0][1] 
     834        return sameScope[0][1] 
    835835 
    836836    elif l > 1: # Muliple addresses for our scope 
    837        stfAddr = filter(lambda x: x[0] & IPV6_ADDR_6TO4, sameScope) 
    838        nativeAddr = filter(lambda x: not (x[0] & IPV6_ADDR_6TO4), sameScope) 
    839  
    840        if not (dstAddrType & IPV6_ADDR_6TO4): # destination is not 6to4 
    841           if len(nativeAddr) != 0: 
    842               return nativeAddr[0][1] 
    843           return stfAddr[0][1] 
    844  
    845        else:  # Destination is 6to4, try to use source 6to4 addr if any 
    846            if len(stfAddr) != 0: 
    847                return stfAddr[0][1] 
    848            return nativeAddr[0][1] 
     837        stfAddr = filter(lambda x: x[0] & IPV6_ADDR_6TO4, sameScope) 
     838        nativeAddr = filter(lambda x: not (x[0] & IPV6_ADDR_6TO4), sameScope) 
     839 
     840        if not (dstAddrType & IPV6_ADDR_6TO4): # destination is not 6to4 
     841           if len(nativeAddr) != 0: 
     842               return nativeAddr[0][1] 
     843           return stfAddr[0][1] 
     844 
     845        else:  # Destination is 6to4, try to use source 6to4 addr if any 
     846            if len(stfAddr) != 0: 
     847                return stfAddr[0][1] 
     848            return nativeAddr[0][1] 
    849849    else: 
    850        return None 
     850        return None 
    851851 
    852852 
     
    11711171        s = '::fdff:ffff:ffff:ff80' 
    11721172        x = in6_and(x, inet_pton(socket.AF_INET6, '::ffff:ffff:ffff:ff80')) 
    1173        x = in6_and(x, inet_pton(socket.AF_INET6, s))  
     1173        x = in6_and(x, inet_pton(socket.AF_INET6, s))  
    11741174        return x == inet_pton(socket.AF_INET6, s) 
    11751175    else: 
    1176        # not EUI-64  
    1177        #|              n bits             |    121-n bits    |   7 bits   | 
    1178        #+---------------------------------+------------------+------------+ 
    1179        #|           subnet prefix         | 1111111...111111 | anycast ID | 
    1180        #+---------------------------------+------------------+------------+ 
    1181        #                                  |   interface identifier field  | 
     1176        # not EUI-64  
     1177        #|              n bits             |    121-n bits    |   7 bits   | 
     1178        #+---------------------------------+------------------+------------+ 
     1179        #|           subnet prefix         | 1111111...111111 | anycast ID | 
     1180        #+---------------------------------+------------------+------------+ 
     1181        #                                  |   interface identifier field  | 
    11821182        warning('in6_isanycast(): TODO not EUI-64') 
    11831183        return 0 
     
    11891189            lambda x,y: x & y, 
    11901190            lambda x,y: x ^ y 
    1191          ]   
     1191          ]   
    11921192    ret = map(fop[operator%len(fop)], a1, a2) 
    11931193    t = ''.join(map(lambda x: struct.pack('I', x), ret)) 
     
    13841384    """ 
    13851385    if in6_isgladdr(addr): 
    1386        scope = IPV6_ADDR_GLOBAL 
     1386        scope = IPV6_ADDR_GLOBAL 
    13871387    elif in6_islladdr(addr): 
    1388        scope = IPV6_ADDR_LINKLOCAL 
     1388        scope = IPV6_ADDR_LINKLOCAL 
    13891389    elif in6_issladdr(addr): 
    1390        scope = IPV6_ADDR_SITELOCAL 
     1390        scope = IPV6_ADDR_SITELOCAL 
    13911391    elif in6_ismaddr(addr): 
    1392        scope = IPV6_ADDR_MULTICAST 
     1392        scope = IPV6_ADDR_MULTICAST 
    13931393    elif addr == '::1': 
    1394        scope = IPV6_ADDR_LOOPBACK 
     1394        scope = IPV6_ADDR_LOOPBACK 
    13951395    else: 
    1396        scope = -1 
     1396        scope = -1 
    13971397    return scope 
    13981398 
     
    14091409        if type(x) is str: 
    14101410            try: 
    1411                x = in6_ptop(x) 
     1411                x = in6_ptop(x) 
    14121412            except socket.error: 
    14131413                x = Net6(x) 
     
    14231423    def i2repr(self, pkt, x): 
    14241424        if x is None: 
    1425            return self.i2h(pkt,x) 
    1426        elif not isinstance(x, Net6) and not type(x) is list: 
    1427            if in6_isaddrTeredo(x):   # print Teredo info 
    1428                server, flag, maddr, mport = teredoAddrExtractInfo(x)      
    1429                return "%s [Teredo srv: %s cli: %s:%s]" % (self.i2h(pkt, x), server, maddr,mport) 
    1430            elif in6_isaddr6to4(x):   # print encapsulated address 
     1425            return self.i2h(pkt,x) 
     1426        elif not isinstance(x, Net6) and not type(x) is list: 
     1427            if in6_isaddrTeredo(x):   # print Teredo info 
     1428                server, flag, maddr, mport = teredoAddrExtractInfo(x)      
     1429                return "%s [Teredo srv: %s cli: %s:%s]" % (self.i2h(pkt, x), server, maddr,mport) 
     1430            elif in6_isaddr6to4(x):   # print encapsulated address 
    14311431                vaddr = in6_6to4ExtractAddr(x) 
    1432                return "%s [6to4 GW: %s]" % (self.i2h(pkt, x), vaddr) 
    1433        return self.i2h(pkt, x)       # No specific information to return 
     1432                return "%s [6to4 GW: %s]" % (self.i2h(pkt, x), vaddr) 
     1433        return self.i2h(pkt, x)       # No specific information to return 
    14341434 
    14351435class SourceIP6Field(IP6Field): 
     
    14541454                    return None 
    14551455            else: 
    1456                iff,x,nh = conf.route6.route(dst) 
     1456                iff,x,nh = conf.route6.route(dst) 
    14571457        return IP6Field.i2h(self, pkt, x) 
    14581458 
     
    14801480              #50: "IPv6ExtHrESP", 
    14811481              #51: "IPv6ExtHdrAH", 
    1482               58: "ICMPv6Unknown",  
     1482               58: "ICMPv6Unknown",  
    14831483               59: "Raw", 
    14841484               60: "IPv6ExtHdrDestOpt" } 
     
    15241524 
    15251525    def i2m(self, pkt, x): 
    1526        s = '' 
     1526        s = '' 
    15271527        for y in x: 
    15281528            try: 
     
    15321532                y = inet_pton(socket.AF_INET6, y) 
    15331533            s += y 
    1534        return s 
     1534        return s 
    15351535 
    15361536    def i2repr(self,pkt,x): 
    15371537        s = [] 
    1538        if x == None: 
    1539            return "[]" 
    1540        for y in x: 
    1541            s.append('%s' % y) 
     1538        if x == None: 
     1539            return "[]" 
     1540        for y in x: 
     1541            s.append('%s' % y) 
    15421542        return "[ %s ]" % (", ".join(s)) 
    1543          
    1544 class _IPv6GuessPayload:        
     1543         
     1544class _IPv6GuessPayload:         
    15451545    name = "Dummy class that implements guess_payload_class() for IPv6" 
    15461546    def default_payload_class(self,p): 
     
    15521552        elif self.nh == 135 and len(p) > 3: 
    15531553            return _mip6_mhtype2cls.get(ord(p[2]), MIP6MH_Generic) 
    1554        else: 
    1555            return get_cls(ipv6nhcls.get(self.nh,"Raw"), "Raw") 
     1554        else: 
     1555            return get_cls(ipv6nhcls.get(self.nh,"Raw"), "Raw") 
    15561556 
    15571557class IPv6(_IPv6GuessPayload, Packet, IPTools): 
     
    15591559    fields_desc = [ BitField("version" , 6 , 4), 
    15601560                    BitField("tc", 0, 8), #TODO: IPv6, ByteField ? 
    1561                    BitField("fl", 0, 20), 
    1562                    ShortField("plen", None), 
     1561                    BitField("fl", 0, 20), 
     1562                    ShortField("plen", None), 
    15631563                    ByteEnumField("nh", 59, ipv6nh), 
    15641564                    ByteField("hlim", 64), 
     
    15691569 
    15701570    def post_build(self, p, pay): 
    1571        p += pay 
     1571        p += pay 
    15721572        if self.plen is None: 
    15731573            l = len(p) - 40 
     
    15861586                return struct.pack("B", self.nh)+self.payload.hashret() 
    15871587 
    1588        nh = self.nh 
    1589        sd = self.dst 
    1590        ss = self.src 
     1588        nh = self.nh 
     1589        sd = self.dst 
     1590        ss = self.src 
    15911591        if self.nh == 43 and isinstance(self.payload, IPv6ExtHdrRouting): 
    1592            # With routing header, the destination is the last  
    1593            # address of the IPv6 list if segleft > 0  
    1594            nh = self.payload.nh 
    1595            try: 
    1596                sd = self.addresses[-1] 
    1597            except IndexError: 
    1598                sd = '::1' 
    1599            # TODO: big bug with ICMPv6 error messages as the destination of IPerror6 
    1600            #       could be anything from the original list ... 
    1601            if 1: 
    1602                sd = inet_pton(socket.AF_INET6, sd) 
    1603                for a in self.addresses: 
    1604                    a = inet_pton(socket.AF_INET6, a) 
    1605                    sd = strxor(sd, a) 
    1606                sd = inet_ntop(socket.AF_INET6, sd) 
     1592            # With routing header, the destination is the last  
     1593            # address of the IPv6 list if segleft > 0  
     1594            nh = self.payload.nh 
     1595            try: 
     1596                sd = self.addresses[-1] 
     1597            except IndexError: 
     1598                sd = '::1' 
     1599            # TODO: big bug with ICMPv6 error messages as the destination of IPerror6 
     1600            #       could be anything from the original list ... 
     1601            if 1: 
     1602                sd = inet_pton(socket.AF_INET6, sd) 
     1603                for a in self.addresses: 
     1604                    a = inet_pton(socket.AF_INET6, a) 
     1605                    sd = strxor(sd, a) 
     1606                sd = inet_ntop(socket.AF_INET6, sd) 
    16071607 
    16081608        if self.nh == 44 and isinstance(self.payload, IPv6ExtHdrFragment): 
     
    16361636            os = inet_pton(socket.AF_INET6, other.src) 
    16371637            od = inet_pton(socket.AF_INET6, other.dst) 
    1638            # request was sent to a multicast address (other.dst) 
     1638            # request was sent to a multicast address (other.dst) 
    16391639            # Check reply destination addr matches request source addr (i.e  
    16401640            # sd == os) except when reply is multicasted too 
     
    16821682        if not isinstance(other, IPv6): 
    16831683            return False 
    1684        sd = inet_pton(socket.AF_INET6, self.dst) 
    1685        ss = inet_pton(socket.AF_INET6, self.src) 
    1686        od = inet_pton(socket.AF_INET6, other.dst) 
    1687        os = inet_pton(socket.AF_INET6, other.src) 
    1688  
    1689        # Make sure that the ICMPv6 error is related to the packet scapy sent 
    1690        if isinstance(self.underlayer, _ICMPv6) and self.underlayer.type < 128: 
     1684        sd = inet_pton(socket.AF_INET6, self.dst) 
     1685        ss = inet_pton(socket.AF_INET6, self.src) 
     1686        od = inet_pton(socket.AF_INET6, other.dst) 
     1687        os = inet_pton(socket.AF_INET6, other.src) 
     1688 
     1689        # Make sure that the ICMPv6 error is related to the packet scapy sent 
     1690        if isinstance(self.underlayer, _ICMPv6) and self.underlayer.type < 128: 
    16911691             
    16921692            # find upper layer for self (possible citation) 
     
    17031703                otherup = otherup.payload 
    17041704 
    1705            if ((ss == os and sd == od) or      # <- Basic case  
     1705            if ((ss == os and sd == od) or      # <- Basic case  
    17061706                (ss == os and request_has_rh)): # <- Request has a RH :  
    17071707                                                #    don't check dst address 
     
    17651765    fields_desc = [ IP6Field("src", "::"), 
    17661766                    IP6Field("dst", "::"), 
    1767                    ShortField("uplen", None), 
     1767                    ShortField("uplen", None), 
    17681768                    BitField("zero", 0, 24), 
    17691769                    ByteField("nh", 0) ]   
     
    17971797    final_dest_addr_found = 0 
    17981798    while u != None and not isinstance(u, IPv6): 
    1799        if (isinstance(u, IPv6ExtHdrRouting) and 
    1800            u.segleft != 0 and len(u.addresses) != 0 and 
     1799        if (isinstance(u, IPv6ExtHdrRouting) and 
     1800            u.segleft != 0 and len(u.addresses) != 0 and 
    18011801            final_dest_addr_found == 0): 
    1802            rthdr = u.addresses[-1] 
     1802            rthdr = u.addresses[-1] 
    18031803            final_dest_addr_found = 1 
    1804        elif (isinstance(u, IPv6ExtHdrDestOpt) and (len(u.options) == 1) and 
     1804        elif (isinstance(u, IPv6ExtHdrDestOpt) and (len(u.options) == 1) and 
    18051805             isinstance(u.options[0], HAO)): 
    18061806             hahdr  = u.options[0].hoa 
    1807        u = u.underlayer 
     1807        u = u.underlayer 
    18081808    if u is None:   
    1809        warning("No IPv6 underlayer to compute checksum. Leaving null.") 
    1810        return 0 
    1811     if hahdr:   
    1812        ph6.src = hahdr 
     1809        warning("No IPv6 underlayer to compute checksum. Leaving null.") 
     1810        return 0 
     1811    if hahdr:    
     1812        ph6.src = hahdr 
    18131813    else: 
    18141814        ph6.src = u.src 
    18151815    if rthdr: 
    1816        ph6.dst = rthdr 
     1816        ph6.dst = rthdr 
    18171817    else: 
    1818        ph6.dst = u.dst 
     1818        ph6.dst = u.dst 
    18191819    ph6.uplen = len(p) 
    18201820    ph6s = str(ph6) 
     
    20532053                                  adjust = lambda pkt,x: (x+2+7)/8 - 1),  
    20542054                    _PhantomAutoPadField("autopad", 1), # autopad activated by default 
    2055                    _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 
     2055                    _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 
    20562056                                          length_from = lambda pkt: (8*(pkt.len+1))-2) ] 
    20572057    overload_fields = {IPv6: { "nh": 0 }} 
     
    20662066                                  adjust = lambda pkt,x: (x+2+7)/8 - 1),  
    20672067                    _PhantomAutoPadField("autopad", 1), # autopad activated by default 
    2068                    _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 
     2068                    _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 
    20692069                                          length_from = lambda pkt: (8*(pkt.len+1))-2) ] 
    20702070    overload_fields = {IPv6: { "nh": 60 }} 
     
    20812081                    ByteField("segleft", None), 
    20822082                    BitField("reserved", 0, 32), # There is meaning in this field ... 
    2083                    IP6ListField("addresses", [], 
     2083                    IP6ListField("addresses", [], 
    20842084                                 length_from = lambda pkt: 8*pkt.len)] 
    20852085    overload_fields = {IPv6: { "nh": 43 }} 
     
    20922092########################### Fragmentation Header ############################ 
    20932093 
    2094 class IPv6ExtHdrFragment(_IPv6ExtHdr):            
     2094class IPv6ExtHdrFragment(_IPv6ExtHdr):             
    20952095    name = "IPv6 Extension Header - Fragmentation header" 
    20962096    fields_desc = [ ByteEnumField("nh", 59, ipv6nh), 
    20972097                    BitField("res1", 0, 8), 
    2098                    BitField("offset", 0, 13), 
    2099                    BitField("res2", 0, 2), 
    2100                    BitField("m", 0, 1), 
    2101                    IntField("id", None) ] 
     2098                    BitField("offset", 0, 13), 
     2099                    BitField("res2", 0, 2), 
     2100                    BitField("m", 0, 1), 
     2101                    IntField("id", None) ] 
    21022102    overload_fields = {IPv6: { "nh": 44 }} 
    21032103 
     
    23082308                   142: "ICMPv6ND_INDAdv", 
    23092309                  #143: Do Me - RFC 3810 
    2310                   144: "ICMPv6HAADRequest",  
    2311                   145: "ICMPv6HAADReply", 
    2312                   146: "ICMPv6MPSol", 
    2313                   147: "ICMPv6MPAdv", 
     2310                   144: "ICMPv6HAADRequest",  
     2311                   145: "ICMPv6HAADReply", 
     2312                   146: "ICMPv6MPSol", 
     2313                   147: "ICMPv6MPAdv", 
    23142314                  #148: Do Me - SEND related - RFC 3971 
    23152315                  #149: Do Me - SEND related - RFC 3971 
     
    23172317                   152: "ICMPv6MRD_Solicitation", 
    23182318                   153: "ICMPv6MRD_Termination", 
    2319                   } 
     2319                   } 
    23202320 
    23212321icmp6types = { 1 : "Destination unreachable",   
    23222322               2 : "Packet too big",  
    2323               3 : "Time exceeded", 
     2323               3 : "Time exceeded", 
    23242324               4 : "Parameter problem", 
    23252325             100 : "Private Experimentation", 
     
    23282328             129 : "Echo Reply", 
    23292329             130 : "MLD Query", 
    2330             131 : "MLD Report", 
    2331             132 : "MLD Done", 
    2332             133 : "Router Solicitation", 
    2333             134 : "Router Advertisement", 
    2334             135 : "Neighbor Solicitation", 
    2335             136 : "Neighbor Advertisement", 
    2336             137 : "Redirect Message", 
    2337             138 : "Router Renumbering", 
    2338             139 : "ICMP Node Information Query",         
    2339             140 : "ICMP Node Information Response",     
    2340             141 : "Inverse Neighbor Discovery Solicitation Message", 
    2341             142 : "Inverse Neighbor Discovery Advertisement Message", 
    2342             143 : "Version 2 Multicast Listener Report", 
    2343             144 : "Home Agent Address Discovery Request Message", 
    2344             145 : "Home Agent Address Discovery Reply Message", 
    2345             146 : "Mobile Prefix Solicitation", 
    2346             147 : "Mobile Prefix Advertisement", 
    2347             148 : "Certification Path Solicitation", 
    2348             149 : "Certification Path Advertisement", 
     2330             131 : "MLD Report", 
     2331             132 : "MLD Done", 
     2332             133 : "Router Solicitation", 
     2333             134 : "Router Advertisement", 
     2334             135 : "Neighbor Solicitation", 
     2335             136 : "Neighbor Advertisement", 
     2336             137 : "Redirect Message", 
     2337             138 : "Router Renumbering", 
     2338             139 : "ICMP Node Information Query",         
     2339             140 : "ICMP Node Information Response",     
     2340             141 : "Inverse Neighbor Discovery Solicitation Message", 
     2341             142 : "Inverse Neighbor Discovery Advertisement Message", 
     2342             143 : "Version 2 Multicast Listener Report", 
     2343             144 : "Home Agent Address Discovery Request Message", 
     2344             145 : "Home Agent Address Discovery Reply Message", 
     2345             146 : "Mobile Prefix Solicitation", 
     2346             147 : "Mobile Prefix Advertisement", 
     2347             148 : "Certification Path Solicitation", 
     2348             149 : "Certification Path Advertisement", 
    23492349             151 : "Multicast Router Advertisement", 
    23502350             152 : "Multicast Router Solicitation", 
     
    23582358    overload_fields = {IPv6: {"nh": 58}} 
    23592359    def post_build(self, p, pay): 
    2360        p += pay 
     2360        p += pay 
    23612361        if self.cksum == None:  
    2362            chksum = in6_chksum(58, self.underlayer, p) 
    2363            p = p[:2]+struct.pack("!H", chksum)+p[4:] 
    2364        return p 
     2362            chksum = in6_chksum(58, self.underlayer, p) 
     2363            p = p[:2]+struct.pack("!H", chksum)+p[4:] 
     2364        return p 
    23652365 
    23662366    def hashret(self): 
     
    23692369    def answers(self, other): 
    23702370        # isinstance(self.underlayer, _IPv6ExtHdr) may introduce a bug ... 
    2371        if (isinstance(self.underlayer, IPerror6) or 
     2371        if (isinstance(self.underlayer, IPerror6) or 
    23722372            isinstance(self.underlayer, _IPv6ExtHdr) and 
    23732373            isinstance(other, _ICMPv6)): 
    2374            if not ((self.type == other.type) and 
    2375                    (self.code == other.code)): 
    2376                return 0 
    2377            return 1 
    2378        return 0 
     2374            if not ((self.type == other.type) and 
     2375                    (self.code == other.code)): 
     2376                return 0 
     2377            return 1 
     2378        return 0 
    23792379 
    23802380 
     
    23822382    name = "ICMPv6 errors dummy class" 
    23832383    def guess_payload_class(self,p): 
    2384        return IPerror6 
     2384        return IPerror6 
    23852385 
    23862386class ICMPv6Unknown(_ICMPv6): 
     
    26452645                    ByteField("len", 1), 
    26462646                    MACField("lladdr", ETHER_ANY) ] 
    2647     def mysummary(self):                        
     2647    def mysummary(self):                         
    26482648        return self.sprintf("%name% %lladdr%") 
    26492649 
     
    26662666                    XIntField("res2",0x00000000), 
    26672667                    IP6Field("prefix","::") ] 
    2668     def mysummary(self):                        
     2668    def mysummary(self):                         
    26692669        return self.sprintf("%name% %prefix%") 
    26702670 
     
    27332733                    ShortField("res", 0), 
    27342734                    IntField("advint", 0) ] 
    2735     def mysummary(self):                        
     2735    def mysummary(self):                         
    27362736        return self.sprintf("%name% %advint% milliseconds") 
    27372737 
    2738 class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet):         
     2738class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet):  
    27392739    name = "ICMPv6 Neighbor Discovery - Home Agent Information" 
    27402740    fields_desc = [ ByteField("type",8), 
     
    27432743                    ShortField("pref", 0), 
    27442744                    ShortField("lifetime", 1)] 
    2745     def mysummary(self):                        
     2745    def mysummary(self):                         
    27462746        return self.sprintf("%name% %pref% %lifetime% seconds") 
    27472747 
     
    27502750# type 10 : See ICMPv6NDOptTgtAddrList class below in IND (RFC 3122) support 
    27512751 
    2752 class ICMPv6NDOptIPAddr(_ICMPv6NDGuessPayload, Packet):        # RFC 4068 
     2752class ICMPv6NDOptIPAddr(_ICMPv6NDGuessPayload, Packet): # RFC 4068 
    27532753    name = "ICMPv6 Neighbor Discovery - IP Address Option (FH for MIPv6)" 
    27542754    fields_desc = [ ByteField("type",17), 
     
    27792779                        7: "No fast handovers support for AP identified by the LLA" } 
    27802780 
    2781 class ICMPv6NDOptLLA(_ICMPv6NDGuessPayload, Packet):    # RFC 4068 
     2781class ICMPv6NDOptLLA(_ICMPv6NDGuessPayload, Packet):    # RFC 4068 
    27822782    name = "ICMPv6 Neighbor Discovery - Link-Layer Address (LLA) Option (FH for MIPv6)" 
    27832783    fields_desc = [ ByteField("type", 19), 
     
    27862786                    MACField("lla", ETHER_ANY) ] # We only support ethernet 
    27872787 
    2788 class ICMPv6NDOptMAP(_ICMPv6NDGuessPayload, Packet):    # RFC 4140 
     2788class ICMPv6NDOptMAP(_ICMPv6NDGuessPayload, Packet):    # RFC 4140 
    27892789    name = "ICMPv6 Neighbor Discovery - MAP Option" 
    27902790    fields_desc = [ ByteField("type", 23), 
     
    29212921 
    29222922    def answers(self, other): 
    2923        return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt 
     2923        return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt 
    29242924 
    29252925# associated possible options : target link-layer option, Redirected header 
     
    32693269 
    32703270#_niquery_flags = {  2: "All unicast addresses", 4: "IPv4 addresses", 
    3271                  8: "Link-local addresses", 16: "Site-local addresses",  
     3271                  8: "Link-local addresses", 16: "Site-local addresses",  
    32723272#                   32: "Global addresses" } 
    3273