Пример #1
0
class BasicSetup(object):
    def setup(self):

        # run server / client
        self.env = {}
        self.ct = Conntrack()
        self.nfct = NFCTSocket()
        if self.ct.count() == 0:
            self.ct.close()
            self.nfct.close()
            raise SkipTest('conntrack modules are not supported')
        self.server = threading.Thread(target=server,
                                       args=('127.0.0.1', 5591, self.env))
        self.server.start()
        e = None
        for x in range(5):
            try:
                self.client = Client('127.0.0.1', 5591)
                time.sleep(1)
                break
            except Exception as exc:
                e = exc
        else:
            raise e

    def teardown(self):
        self.nfct.close()
        self.ct.close()
        self.client.stop()
        self.server.join()
        self.env = {}
Пример #2
0
class BasicSetup(object):

    def setup(self):

        # run server / client
        self.env = {}
        self.ct = Conntrack()
        self.nfct = NFCTSocket()
        if self.ct.count() == 0:
            self.ct.close()
            self.nfct.close()
            raise SkipTest('conntrack modules are not supported')
        self.server = threading.Thread(target=server,
                                       args=('127.0.0.1', 5591, self.env))
        self.server.start()
        e = None
        for x in range(5):
            try:
                self.client = Client('127.0.0.1', 5591)
                time.sleep(1)
                break
            except Exception as exc:
                e = exc
        else:
            raise e

    def teardown(self):
        self.nfct.close()
        self.ct.close()
        self.client.stop()
        self.server.join()
        self.env = {}
Пример #3
0
    def setup(self):
        require_user('root')
        self.tuples = []
        self.COUNT_CT = 20
        self.ct = Conntrack()

        for sport in range(20000, 20000 + self.COUNT_CT):
            tuple_orig = self.add_tuple(
                saddr='192.168.122.1', daddr='192.168.122.67',
                proto=socket.IPPROTO_TCP, sport=sport, dport=5599)
            self.ct.entry('add', timeout=60,
                          tuple_orig=tuple_orig,
                          tuple_reply=tuple_orig.reverse())
Пример #4
0
    def setup(self):
        require_user('root')

        # run server / client
        self.env = {}
        self.ct = Conntrack()
        self.nfct = NFCTSocket()
        if self.ct.count() == 0:
            self.ct.close()
            self.nfct.close()
            raise SkipTest('conntrack modules are not supported')
        self.server = threading.Thread(target=server,
                                       args=('127.0.0.1', 5591, self.env))
        self.server.start()
        e = None
        for x in range(5):
            try:
                self.client = Client('127.0.0.1', 5591)
                time.sleep(1)
                break
            except Exception as exc:
                e = exc
        else:
            raise e
Пример #5
0
class TestDumpEntries(object):
    def add_tuple(self, saddr, daddr, proto, sport, dport):
        tuple_orig = NFCTAttrTuple(saddr=saddr,
                                   daddr=daddr,
                                   proto=proto,
                                   sport=sport,
                                   dport=dport)
        self.tuples.append(tuple_orig)
        return tuple_orig

    def setup(self):
        require_user('root')
        self.tuples = []
        self.COUNT_CT = 20
        self.ct = Conntrack()

        for sport in range(20000, 20000 + self.COUNT_CT):
            tuple_orig = self.add_tuple(saddr='192.168.122.1',
                                        daddr='192.168.122.67',
                                        proto=socket.IPPROTO_TCP,
                                        sport=sport,
                                        dport=5599)
            self.ct.entry('add',
                          timeout=60,
                          tuple_orig=tuple_orig,
                          tuple_reply=tuple_orig.reverse())

    def test_dump(self):
        tuple_match = NFCTAttrTuple(saddr='192.168.122.1',
                                    daddr='192.168.122.67')

        count_found = 0
        tuple_filter = tuple_match
        for entry in self.ct.dump_entries(tuple_orig=tuple_match):
            count_found += 1
        assert count_found == self.COUNT_CT

        count_found = 0
        tuple_filter = NFCTAttrTuple(proto=socket.IPPROTO_TCP)
        for entry in self.ct.dump_entries(tuple_orig=tuple_filter):
            if tuple_match == entry.tuple_orig:
                count_found += 1

        assert count_found == self.COUNT_CT

    def teardown(self):
        for tuple_orig in self.tuples:
            self.ct.entry('del', tuple_orig=tuple_orig)