Changeset 917:711cf86b0af4
- Timestamp:
- 09/12/08 17:57:20 (4 months ago)
- Files:
-
- scapy/layers/inet6.py (modified) (84 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
scapy/layers/inet6.py
r916 r917 44 44 45 45 if OPENBSD or FREEBSD or NETBSD or DARWIN: 46 loname = "lo0"46 loname = "lo0" 47 47 else: 48 loname = "lo"48 loname = "lo" 49 49 50 50 # From net/ipv6.h on Linux (+ Additions) … … 84 84 cset = [] 85 85 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) 87 87 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) 89 89 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) 91 91 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) 100 100 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) 102 102 cset = map(lambda x: x[0], cset) 103 103 return cset … … 116 116 117 117 if len(candidate_set) == 0: 118 # Should not happen119 return None118 # Should not happen 119 return None 120 120 121 121 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] 125 125 126 126 return candidate_set[0] … … 143 143 # if any. Change that ... 144 144 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") 148 148 149 149 def __repr__(self): … … 151 151 152 152 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))) 154 154 155 155 colwidth = map(lambda x: max(map(lambda y: len(y), x)), apply(zip, rtlst)) … … 393 393 """ 394 394 ret = [] 395 try:396 f = open("/proc/net/if_inet6","r")397 except IOError, err:398 return ret399 l = f.readlines()400 for i in l:401 # addr, index, plen, scope, flags, ifname402 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 ret395 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 407 407 408 408 def read_routes6(): 409 try:410 f = open("/proc/net/ipv6_route","r")411 except IOError, err:412 return []413 # 1. destination network414 # 2. destination prefix length415 # 3. source network displayed416 # 4. source prefix length409 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 417 417 # 5. next hop 418 # 6. metric419 # 7. reference counter (?!?)420 # 8. use counter (?!?)421 # 9. flags422 # 10. device name418 # 6. metric 419 # 7. reference counter (?!?) 420 # 8. use counter (?!?) 421 # 9. flags 422 # 10. device name 423 423 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) 428 428 429 lifaddr = in6_getifaddr()429 lifaddr = in6_getifaddr() 430 430 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() 432 432 fl = int(fl, 16) 433 433 … … 437 437 continue 438 438 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) 442 442 443 443 cset = [] # candidate set (possible source addresses) 444 if dev == loname:445 if d == '::':446 continue447 cset = ['::1']448 else:444 if dev == loname: 445 if d == '::': 446 continue 447 cset = ['::1'] 448 else: 449 449 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 452 452 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 456 456 457 457 elif WINDOWS: … … 496 496 497 497 ret = [] 498 i = dnet.intf()498 i = dnet.intf() 499 499 for int in i: 500 ifname = int['name']500 ifname = int['name'] 501 501 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 continue507 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)) 514 514 return ret 515 515 … … 526 526 ok = l.find('Destination') 527 527 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 DARWIN528 # gv 12/12/06: under debugging 529 if NETBSD or OPENBSD: 530 d,nh,fl,_,_,_,dev = l.split()[:7] 531 else: # FREEBSD or DARWIN 532 532 d,nh,fl,dev = l.split()[:4] 533 if filter(lambda x: x[2] == dev, lifaddr) == []:534 continue533 if filter(lambda x: x[2] == dev, lifaddr) == []: 534 continue 535 535 if 'L' in fl: # drop MAC addresses 536 536 continue 537 537 538 538 if 'link' in nh: 539 nh = '::'540 541 cset = [] # candidate set (possible source addresses)542 dp = 128543 if d == 'default':544 d = '::'545 dp = 0546 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 = '::' 556 556 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) 559 559 560 560 if len(cset) != 0: 561 routes.append((d, dp, nh, dev, cset))561 routes.append((d, dp, nh, dev, cset)) 562 562 563 563 f.close() … … 741 741 742 742 netmask = int(tmp[1]) 743 self.net = inet_pton(socket.AF_INET6, tmp[0])743 self.net = inet_pton(socket.AF_INET6, tmp[0]) 744 744 self.mask = in6_cidr2mask(netmask) 745 self.plen = netmask745 self.plen = netmask 746 746 747 747 def __iter__(self): 748 748 def m8(i): 749 if i % 8 == 0:749 if i % 8 == 0: 750 750 return i 751 751 tuple = filter(lambda x: m8(x), xrange(8, 129)) … … 761 761 762 762 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: 766 766 sep = '' 767 767 if n == 16: 768 return l768 return l 769 769 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) 775 775 776 776 return iter(rec(0, [''])) … … 818 818 819 819 if dstAddrType == IPV6_ADDR_UNSPECIFIED: # Shouldn't happen as dst addr 820 return None820 return None 821 821 822 822 if dstAddrType == IPV6_ADDR_LOOPBACK: 823 return None823 return None 824 824 825 825 tmp = [[]] + map(lambda (x,y,z): (in6_getAddrType(x), x, y, z), laddr) 826 826 def filterSameScope(l, t): 827 if (t[0] & dstAddrType & IPV6_ADDR_SCOPE_MASK) == 0:828 l.append(t)829 return l827 if (t[0] & dstAddrType & IPV6_ADDR_SCOPE_MASK) == 0: 828 l.append(t) 829 return l 830 830 sameScope = reduce(filterSameScope, tmp) 831 831 832 832 l = len(sameScope) 833 833 if l == 1: # Only one address for our scope 834 return sameScope[0][1]834 return sameScope[0][1] 835 835 836 836 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 6to4841 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 any846 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] 849 849 else: 850 return None850 return None 851 851 852 852 … … 1171 1171 s = '::fdff:ffff:ffff:ff80' 1172 1172 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)) 1174 1174 return x == inet_pton(socket.AF_INET6, s) 1175 1175 else: 1176 # not EUI-641177 #| 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 | 1182 1182 warning('in6_isanycast(): TODO not EUI-64') 1183 1183 return 0 … … 1189 1189 lambda x,y: x & y, 1190 1190 lambda x,y: x ^ y 1191 ]1191 ] 1192 1192 ret = map(fop[operator%len(fop)], a1, a2) 1193 1193 t = ''.join(map(lambda x: struct.pack('I', x), ret)) … … 1384 1384 """ 1385 1385 if in6_isgladdr(addr): 1386 scope = IPV6_ADDR_GLOBAL1386 scope = IPV6_ADDR_GLOBAL 1387 1387 elif in6_islladdr(addr): 1388 scope = IPV6_ADDR_LINKLOCAL1388 scope = IPV6_ADDR_LINKLOCAL 1389 1389 elif in6_issladdr(addr): 1390 scope = IPV6_ADDR_SITELOCAL1390 scope = IPV6_ADDR_SITELOCAL 1391 1391 elif in6_ismaddr(addr): 1392 scope = IPV6_ADDR_MULTICAST1392 scope = IPV6_ADDR_MULTICAST 1393 1393 elif addr == '::1': 1394 scope = IPV6_ADDR_LOOPBACK1394 scope = IPV6_ADDR_LOOPBACK 1395 1395 else: 1396 scope = -11396 scope = -1 1397 1397 return scope 1398 1398 … … 1409 1409 if type(x) is str: 1410 1410 try: 1411 x = in6_ptop(x)1411 x = in6_ptop(x) 1412 1412 except socket.error: 1413 1413 x = Net6(x) … … 1423 1423 def i2repr(self, pkt, x): 1424 1424 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 info1428 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 address1425 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 1431 1431 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 return1432 return "%s [6to4 GW: %s]" % (self.i2h(pkt, x), vaddr) 1433 return self.i2h(pkt, x) # No specific information to return 1434 1434 1435 1435 class SourceIP6Field(IP6Field): … … 1454 1454 return None 1455 1455 else: 1456 iff,x,nh = conf.route6.route(dst)1456 iff,x,nh = conf.route6.route(dst) 1457 1457 return IP6Field.i2h(self, pkt, x) 1458 1458 … … 1480 1480 #50: "IPv6ExtHrESP", 1481 1481 #51: "IPv6ExtHdrAH", 1482 58: "ICMPv6Unknown",1482 58: "ICMPv6Unknown", 1483 1483 59: "Raw", 1484 1484 60: "IPv6ExtHdrDestOpt" } … … 1524 1524 1525 1525 def i2m(self, pkt, x): 1526 s = ''1526 s = '' 1527 1527 for y in x: 1528 1528 try: … … 1532 1532 y = inet_pton(socket.AF_INET6, y) 1533 1533 s += y 1534 return s1534 return s 1535 1535 1536 1536 def i2repr(self,pkt,x): 1537 1537 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) 1542 1542 return "[ %s ]" % (", ".join(s)) 1543 1544 class _IPv6GuessPayload: 1543 1544 class _IPv6GuessPayload: 1545 1545 name = "Dummy class that implements guess_payload_class() for IPv6" 1546 1546 def default_payload_class(self,p): … … 1552 1552 elif self.nh == 135 and len(p) > 3: 1553 1553 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") 1556 1556 1557 1557 class IPv6(_IPv6GuessPayload, Packet, IPTools): … … 1559 1559 fields_desc = [ BitField("version" , 6 , 4), 1560 1560 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), 1563 1563 ByteEnumField("nh", 59, ipv6nh), 1564 1564 ByteField("hlim", 64), … … 1569 1569 1570 1570 def post_build(self, p, pay): 1571 p += pay1571 p += pay 1572 1572 if self.plen is None: 1573 1573 l = len(p) - 40 … … 1586 1586 return struct.pack("B", self.nh)+self.payload.hashret() 1587 1587 1588 nh = self.nh1589 sd = self.dst1590 ss = self.src1588 nh = self.nh 1589 sd = self.dst 1590 ss = self.src 1591 1591 if self.nh == 43 and isinstance(self.payload, IPv6ExtHdrRouting): 1592 # With routing header, the destination is the last1593 # address of the IPv6 list if segleft > 01594 nh = self.payload.nh1595 try:1596 sd = self.addresses[-1]1597 except IndexError:1598 sd = '::1'1599 # TODO: big bug with ICMPv6 error messages as the destination of IPerror61600 # 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) 1607 1607 1608 1608 if self.nh == 44 and isinstance(self.payload, IPv6ExtHdrFragment): … … 1636 1636 os = inet_pton(socket.AF_INET6, other.src) 1637 1637 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) 1639 1639 # Check reply destination addr matches request source addr (i.e 1640 1640 # sd == os) except when reply is multicasted too … … 1682 1682 if not isinstance(other, IPv6): 1683 1683 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 sent1690 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: 1691 1691 1692 1692 # find upper layer for self (possible citation) … … 1703 1703 otherup = otherup.payload 1704 1704 1705 if ((ss == os and sd == od) or # <- Basic case1705 if ((ss == os and sd == od) or # <- Basic case 1706 1706 (ss == os and request_has_rh)): # <- Request has a RH : 1707 1707 # don't check dst address … … 1765 1765 fields_desc = [ IP6Field("src", "::"), 1766 1766 IP6Field("dst", "::"), 1767 ShortField("uplen", None),1767 ShortField("uplen", None), 1768 1768 BitField("zero", 0, 24), 1769 1769 ByteField("nh", 0) ] … … 1797 1797 final_dest_addr_found = 0 1798 1798 while u != None and not isinstance(u, IPv6): 1799 if (isinstance(u, IPv6ExtHdrRouting) and1800 u.segleft != 0 and len(u.addresses) != 0 and1799 if (isinstance(u, IPv6ExtHdrRouting) and 1800 u.segleft != 0 and len(u.addresses) != 0 and 1801 1801 final_dest_addr_found == 0): 1802 rthdr = u.addresses[-1]1802 rthdr = u.addresses[-1] 1803 1803 final_dest_addr_found = 1 1804 elif (isinstance(u, IPv6ExtHdrDestOpt) and (len(u.options) == 1) and1804 elif (isinstance(u, IPv6ExtHdrDestOpt) and (len(u.options) == 1) and 1805 1805 isinstance(u.options[0], HAO)): 1806 1806 hahdr = u.options[0].hoa 1807 u = u.underlayer1807 u = u.underlayer 1808 1808 if u is None: 1809 warning("No IPv6 underlayer to compute checksum. Leaving null.")1810 return 01811 if hahdr: 1812 ph6.src = hahdr1809 warning("No IPv6 underlayer to compute checksum. Leaving null.") 1810 return 0 1811 if hahdr: 1812 ph6.src = hahdr 1813 1813 else: 1814 1814 ph6.src = u.src 1815 1815 if rthdr: 1816 ph6.dst = rthdr1816 ph6.dst = rthdr 1817 1817 else: 1818 ph6.dst = u.dst1818 ph6.dst = u.dst 1819 1819 ph6.uplen = len(p) 1820 1820 ph6s = str(ph6) … … 2053 2053 adjust = lambda pkt,x: (x+2+7)/8 - 1), 2054 2054 _PhantomAutoPadField("autopad", 1), # autopad activated by default 2055 _HopByHopOptionsField("options", [], HBHOptUnknown, 2,2055 _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 2056 2056 length_from = lambda pkt: (8*(pkt.len+1))-2) ] 2057 2057 overload_fields = {IPv6: { "nh": 0 }} … … 2066 2066 adjust = lambda pkt,x: (x+2+7)/8 - 1), 2067 2067 _PhantomAutoPadField("autopad", 1), # autopad activated by default 2068 _HopByHopOptionsField("options", [], HBHOptUnknown, 2,2068 _HopByHopOptionsField("options", [], HBHOptUnknown, 2, 2069 2069 length_from = lambda pkt: (8*(pkt.len+1))-2) ] 2070 2070 overload_fields = {IPv6: { "nh": 60 }} … … 2081 2081 ByteField("segleft", None), 2082 2082 BitField("reserved", 0, 32), # There is meaning in this field ... 2083 IP6ListField("addresses", [],2083 IP6ListField("addresses", [], 2084 2084 length_from = lambda pkt: 8*pkt.len)] 2085 2085 overload_fields = {IPv6: { "nh": 43 }} … … 2092 2092 ########################### Fragmentation Header ############################ 2093 2093 2094 class IPv6ExtHdrFragment(_IPv6ExtHdr): 2094 class IPv6ExtHdrFragment(_IPv6ExtHdr): 2095 2095 name = "IPv6 Extension Header - Fragmentation header" 2096 2096 fields_desc = [ ByteEnumField("nh", 59, ipv6nh), 2097 2097 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) ] 2102 2102 overload_fields = {IPv6: { "nh": 44 }} 2103 2103 … … 2308 2308 142: "ICMPv6ND_INDAdv", 2309 2309 #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", 2314 2314 #148: Do Me - SEND related - RFC 3971 2315 2315 #149: Do Me - SEND related - RFC 3971 … … 2317 2317 152: "ICMPv6MRD_Solicitation", 2318 2318 153: "ICMPv6MRD_Termination", 2319 }2319 } 2320 2320 2321 2321 icmp6types = { 1 : "Destination unreachable", 2322 2322 2 : "Packet too big", 2323 3 : "Time exceeded",2323 3 : "Time exceeded", 2324 2324 4 : "Parameter problem", 2325 2325 100 : "Private Experimentation", … … 2328 2328 129 : "Echo Reply", 2329 2329 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", 2349 2349 151 : "Multicast Router Advertisement", 2350 2350 152 : "Multicast Router Solicitation", … … 2358 2358 overload_fields = {IPv6: {"nh": 58}} 2359 2359 def post_build(self, p, pay): 2360 p += pay2360 p += pay 2361 2361 if self.cksum == None: 2362 chksum = in6_chksum(58, self.underlayer, p)2363 p = p[:2]+struct.pack("!H", chksum)+p[4:]2364 return p2362 chksum = in6_chksum(58, self.underlayer, p) 2363 p = p[:2]+struct.pack("!H", chksum)+p[4:] 2364 return p 2365 2365 2366 2366 def hashret(self): … … 2369 2369 def answers(self, other): 2370 2370 # isinstance(self.underlayer, _IPv6ExtHdr) may introduce a bug ... 2371 if (isinstance(self.underlayer, IPerror6) or2371 if (isinstance(self.underlayer, IPerror6) or 2372 2372 isinstance(self.underlayer, _IPv6ExtHdr) and 2373 2373 isinstance(other, _ICMPv6)): 2374 if not ((self.type == other.type) and2375 (self.code == other.code)):2376 return 02377 return 12378 return 02374 if not ((self.type == other.type) and 2375 (self.code == other.code)): 2376 return 0 2377 return 1 2378 return 0 2379 2379 2380 2380 … … 2382 2382 name = "ICMPv6 errors dummy class" 2383 2383 def guess_payload_class(self,p): 2384 return IPerror62384 return IPerror6 2385 2385 2386 2386 class ICMPv6Unknown(_ICMPv6): … … 2645 2645 ByteField("len", 1), 2646 2646 MACField("lladdr", ETHER_ANY) ] 2647 def mysummary(self): 2647 def mysummary(self): 2648 2648 return self.sprintf("%name% %lladdr%") 2649 2649 … … 2666 2666 XIntField("res2",0x00000000), 2667 2667 IP6Field("prefix","::") ] 2668 def mysummary(self): 2668 def mysummary(self): 2669 2669 return self.sprintf("%name% %prefix%") 2670 2670 … … 2733 2733 ShortField("res", 0), 2734 2734 IntField("advint", 0) ] 2735 def mysummary(self): 2735 def mysummary(self): 2736 2736 return self.sprintf("%name% %advint% milliseconds") 2737 2737 2738 class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet): 2738 class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet): 2739 2739 name = "ICMPv6 Neighbor Discovery - Home Agent Information" 2740 2740 fields_desc = [ ByteField("type",8), … … 2743 2743 ShortField("pref", 0), 2744 2744 ShortField("lifetime", 1)] 2745 def mysummary(self): 2745 def mysummary(self): 2746 2746 return self.sprintf("%name% %pref% %lifetime% seconds") 2747 2747 … … 2750 2750 # type 10 : See ICMPv6NDOptTgtAddrList class below in IND (RFC 3122) support 2751 2751 2752 class ICMPv6NDOptIPAddr(_ICMPv6NDGuessPayload, Packet): # RFC 40682752 class ICMPv6NDOptIPAddr(_ICMPv6NDGuessPayload, Packet): # RFC 4068 2753 2753 name = "ICMPv6 Neighbor Discovery - IP Address Option (FH for MIPv6)" 2754 2754 fields_desc = [ ByteField("type",17), … … 2779 2779 7: "No fast handovers support for AP identified by the LLA" } 2780 2780 2781 class ICMPv6NDOptLLA(_ICMPv6NDGuessPayload, Packet): # RFC 40682781 class ICMPv6NDOptLLA(_ICMPv6NDGuessPayload, Packet): # RFC 4068 2782 2782 name = "ICMPv6 Neighbor Discovery - Link-Layer Address (LLA) Option (FH for MIPv6)" 2783 2783 fields_desc = [ ByteField("type", 19), … … 2786 2786 MACField("lla", ETHER_ANY) ] # We only support ethernet 2787 2787 2788 class ICMPv6NDOptMAP(_ICMPv6NDGuessPayload, Packet): # RFC 41402788 class ICMPv6NDOptMAP(_ICMPv6NDGuessPayload, Packet): # RFC 4140 2789 2789 name = "ICMPv6 Neighbor Discovery - MAP Option" 2790 2790 fields_desc = [ ByteField("type", 23), … … 2921 2921 2922 2922 def answers(self, other): 2923 return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt2923 return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt 2924 2924 2925 2925 # associated possible options : target link-layer option, Redirected header … … 3269 3269 3270 3270 #_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", 3272 3272 # 32: "Global addresses" } 3273
![[SCAPY]](/scapydoc-com/chrome/common/trac_banner.png)