예제 #1
0
    def setUpClass(cls):
        # This is per-class setup instead of per-testcase setup because shelling out
        # to ip and iptables is slow, and because routing configuration doesn't
        # change during the test.
        cls.iproute = iproute.IPRoute()
        cls.tuns = {}
        cls.ifindices = {}
        if HAVE_AUTOCONF_TABLE:
            cls.SetSysctl(AUTOCONF_TABLE_SYSCTL, -1000)
            cls.AUTOCONF_TABLE_OFFSET = -1000
        else:
            cls.AUTOCONF_TABLE_OFFSET = None

        # Disable ICMP rate limits. These will be restored by _RestoreSysctls.
        for version in [4, 6]:
            cls._SetICMPRatelimit(version, 0)

        for netid in cls.NETIDS:
            cls.tuns[netid] = cls.CreateTunInterface(netid)
            iface = cls.GetInterfaceName(netid)
            cls.ifindices[netid] = net_test.GetInterfaceIndex(iface)

            cls.SendRA(netid)
            cls._RunSetupCommands(netid, True)

        for version in [4, 6]:
            cls.iproute.UnreachableRule(version, True, 1000)
예제 #2
0
    def setUpClass(cls):
        # This is per-class setup instead of per-testcase setup because shelling out
        # to ip and iptables is slow, and because routing configuration doesn't
        # change during the test.
        cls.iproute = iproute.IPRoute()
        cls.tuns = {}
        cls.ifindices = {}
        if HAVE_AUTOCONF_TABLE:
            cls.SetSysctl(AUTOCONF_TABLE_SYSCTL, -1000)
            cls.AUTOCONF_TABLE_OFFSET = -1000
        else:
            cls.AUTOCONF_TABLE_OFFSET = None

        # Disable ICMP rate limits. These will be restored by _RestoreSysctls.
        for version in [4, 6]:
            cls._SetICMPRatelimit(version, 0)

        for version in [4, 6]:
            cls.iproute.UnreachableRule(version, True,
                                        cls.PRIORITY_UNREACHABLE)

        for netid in cls.NETIDS:
            cls.tuns[netid] = cls.CreateTunInterface(netid)
            iface = cls.GetInterfaceName(netid)
            cls.ifindices[netid] = net_test.GetInterfaceIndex(iface)

            cls.SendRA(netid)
            cls._RunSetupCommands(netid, True)

        # Don't print lots of "device foo entered promiscuous mode" warnings.
        cls.loglevel = cls.GetConsoleLogLevel()
        cls.SetConsoleLogLevel(net_test.KERN_INFO)

        # When running on device, don't send connections through FwmarkServer.
        os.environ["ANDROID_NO_USE_FWMARK_CLIENT"] = "1"
예제 #3
0
def HaveUidRouting():
    """Checks whether the kernel supports UID routing."""
    # Create a rule with the UID range selector. If the kernel doesn't understand
    # the selector, it will create a rule with no selectors.
    try:
        iproute.IPRoute().UidRangeRule(6, True, 1000, 2000, 100, 10000)
    except IOError:
        return False

    # Dump all the rules. If we find a rule using the UID range selector, then the
    # kernel supports UID range routing.
    rules = iproute.IPRoute().DumpRules(6)
    result = any("FRA_UID_START" in attrs for rule, attrs in rules)

    # Delete the rule.
    iproute.IPRoute().UidRangeRule(6, False, 1000, 2000, 100, 10000)
    return result
예제 #4
0
def HaveXfrmInterfaces():
    try:
        i = iproute.IPRoute()
        i.CreateXfrmInterface(_TEST_XFRM_IFNAME, _TEST_XFRM_IF_ID,
                              _LOOPBACK_IFINDEX)
        i.DeleteLink(_TEST_XFRM_IFNAME)
        try:
            i.GetIfIndex(_TEST_XFRM_IFNAME)
            assert "Deleted interface %s still exists!" % _TEST_XFRM_IFNAME
        except IOError:
            pass
        return True
    except IOError:
        return False
예제 #5
0
    def __init__(self, iface, netid, underlying_netid, local, remote, version):
        self.iface = iface
        self.netid = netid
        self.underlying_netid = underlying_netid
        self.local, self.remote = local, remote

        # XFRM interfaces technically do not have a version. This keeps track of
        # the IP version of the local and remote addresses.
        self.version = version
        self.rx = self.tx = 0
        self.addrs = {}

        self.iproute = iproute.IPRoute()
        self.xfrm = xfrm.Xfrm()
예제 #6
0
    def __init__(self, iface, netid, underlying_netid, local, remote):
        self.iface = iface
        self.netid = netid
        self.underlying_netid = underlying_netid
        self.local, self.remote = local, remote
        self.rx = self.tx = 0
        self.ikey = _TEST_IKEY + netid
        self.okey = _TEST_OKEY + netid
        self.out_spi = self.in_spi = random.randint(0, 0x7fffffff)

        self.iproute = iproute.IPRoute()
        self.xfrm = xfrm.Xfrm()

        self.SetupInterface()
        self.SetupXfrm()
        self.addrs = {}
예제 #7
0
 def setUp(self):
   self.iproute = iproute.IPRoute()
   for version in [4, 6]:
     self.iproute.DeleteRulesAtPriority(version, self.RULE_PRIORITY)
예제 #8
0
 def setUp(self):
     multinetwork_base.MultiNetworkBaseTest.setUp(self)
     self.iproute = iproute.IPRoute()