Beispiel #1
0
	def testDiffClassSameIp(self):
		"""For multiple connections from the same IP address with different classes, we should count correctly."""
		self._start(1)
		conntrack.up(2, '127.0.0.1', ('ALL', 'foo'))
		self.assertEqual(conntrack.classcount('ALL'), 2)
		self.assertEqual(conntrack.classcount('foo'), 1)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('ALL'), 1)
		self.assertEqual(conntrack.classcount('foo'), 1)
Beispiel #2
0
	def testManyClasses(self):
		"""We should correctly add to each class for multi-class connections."""
		conntrack._clearmaps()
		conntrack.up(1, '127.0.0.1', ('foo', 'bar'))
		self.assertEqual(conntrack.classcount('foo'), 1)
		self.assertEqual(conntrack.classcount('bar'), 1)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('foo'), 0)
		self.assertEqual(conntrack.classcount('bar'), 0)
		self.assertEqual(len(conntrack.activeclasses()), 0)
Beispiel #3
0
	def testMultiClassConnects(self):
		"""We should correctly count how many times a given class is active, even with differnet IPs."""
		self._start(1)
		conntrack.up(2, '127.0.0.2', ('ALL',))
		self.assertEqual(conntrack.classcount('ALL'), 2)
		conntrack.up(3, '127.0.0.3', ('ALL',))
		self.assertEqual(conntrack.classcount('ALL'), 3)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('ALL'), 2)
		conntrack.down(3)
		self.assertEqual(conntrack.classcount('ALL'), 1)
Beispiel #4
0
	def testMultiIPConnects(self):
		"""We should correctly count how many times the same IP is connected, even with different classes."""
		self._start(1)
		conntrack.up(2, '127.0.0.1', ('foo',))
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 2)
		conntrack.up(3, '127.0.0.1', ('bar',))
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 3)
		conntrack.down(1)
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 2)
		conntrack.down(3)
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 1)
Beispiel #5
0
	def testHasPid(self):
		"Test that we accurately report whether we are tracking a PID."
		conntrack._clearmaps()
		self.assertEqual(conntrack.havepid(1), 0)
		self._up(1)
		self.assertEqual(conntrack.havepid(1), 1)
		self.assertEqual(conntrack.havepid(2), 0)
		self._up(2)
		self.assertEqual(conntrack.havepid(2), 1)
		conntrack.down(1)
		self.assertEqual(conntrack.havepid(2), 1)
		self.assertEqual(conntrack.havepid(1), 0)
		conntrack.down(2)
		self.assertEqual(conntrack.havepid(2), 0)
Beispiel #6
0
	def testNoClassesLeft(self):
		"""There should be no active classes left listed after up/down."""
		self._start(1)
		conntrack.down(1)
		self.assertEqual(len(conntrack.activeclasses()), 0)
Beispiel #7
0
	def testRemoveMissing(self):
		"Removing a nonexistent PID succeeds."
		conntrack._clearmaps()
		conntrack.down(1)
Beispiel #8
0
	def testInsertRemove(self):
		"""If we insert then remove, the result should be null."""
		self._start(1)
		conntrack.down(1)
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 0)
		self.assertEqual(conntrack.classcount('ALL'), 0)
Beispiel #9
0
def reaper(pid):
	log.debug(4, "reaped PID %d" % (pid,))
	conntrack.down(pid)