Exemplo n.º 1
0
    def testSendToOnlinkDestination(self):
        # [3]  Get an IPv6 address back, in optimistic DAD start-up.
        self.SetDAD(self.test_ifname, 1)  # Enable DAD
        self.SetOptimisticDAD(self.test_ifname, 1)
        self.SetUseOptimistic(self.test_ifname, 1)
        # Send a RA to start SLAAC and subsequent DAD.
        self.SendRA(self.test_netid, 0)
        # Prove optimism and usability.
        self.assertAddressHasExpectedAttributes(self.test_ip,
                                                self.test_ifindex,
                                                iproute.IFA_F_OPTIMISTIC)
        self.assertAddressUsable(self.test_ip, self.test_netid)
        self.assertAddressSelected(self.test_ip, self.test_netid)

        # [4]  Send to an on-link destination and observe a Neighbor Solicitation
        # packet with a source address that is NOT the optimistic address.
        # In this setup, the only usable address is the link-local address.
        onlink_dest = self.GetRandomDestination(
            self.IPv6Prefix(self.test_netid))
        self.SendWithSourceAddress(self.test_ip, self.test_netid, onlink_dest)

        if net_test.LinuxVersion() >= (3, 18, 0):
            # Older versions will actually choose the optimistic address to
            # originate Neighbor Solications (RFC violation).
            expected_ns = packets.NS(self.test_lladdr, onlink_dest,
                                     self.MyMacAddress(self.test_netid))[1]
            self.ExpectPacketOn(self.test_netid, "link-local NS", expected_ns)
Exemplo n.º 2
0
    def testOnlinkCommunication(self):
        """Checks that on-link communication goes direct and not through routers."""
        for netid in self.tuns:
            # Send a UDP packet to a random on-link destination.
            s = net_test.UDPSocket(AF_INET6)
            iface = self.GetInterfaceName(netid)
            self.BindToDevice(s, iface)
            # dstaddr can never be our address because GetRandomDestination only fills
            # in the lower 32 bits, but our address has 0xff in the byte before that
            # (since it's constructed from the EUI-64 and so has ff:fe in the middle).
            dstaddr = self.GetRandomDestination(self.IPv6Prefix(netid))
            s.sendto(UDP_PAYLOAD, (dstaddr, 53))

            # Expect an NS for that destination on the interface.
            myaddr = self.MyAddress(6, netid)
            mymac = self.MyMacAddress(netid)
            desc, expected = packets.NS(myaddr, dstaddr, mymac)
            msg = "Sending UDP packet to on-link destination: expecting %s" % desc
            time.sleep(
                0.0001)  # Required to make the test work on kernel 3.1(!)
            self.ExpectPacketOn(netid, msg, expected)

            # Send an NA.
            tgtmac = "02:00:00:00:%02x:99" % netid
            _, reply = packets.NA(dstaddr, myaddr, tgtmac)
            # Don't use ReceivePacketOn, since that uses the router's MAC address as
            # the source. Instead, construct our own Ethernet header with source
            # MAC of tgtmac.
            reply = scapy.Ether(src=tgtmac, dst=mymac) / reply
            self.ReceiveEtherPacketOn(netid, reply)

            # Expect the kernel to send the original UDP packet now that the ND cache
            # entry has been populated.
            sport = s.getsockname()[1]
            desc, expected = packets.UDP(6, myaddr, dstaddr, sport=sport)
            msg = "After NA response, expecting %s" % desc
            self.ExpectPacketOn(netid, msg, expected)