Commit c748a223 authored by Florent Fourcot's avatar Florent Fourcot

conntrack: enable nlm_generator by default

And fix some functions to be compatible with both modes.
This reduce a lot memory consumption of dump_entries(), already coded as
a generator
parent 9f355f53
......@@ -86,6 +86,8 @@ class Conntrack(NFCTSocket):
High level conntrack functions
def __init__(self, nlm_generator=True, **kwargs):
super(Conntrack, self).__init__(nlm_generator=nlm_generator, **kwargs)
def stat(self):
""" Return current statistics per CPU
......@@ -107,16 +109,16 @@ class Conntrack(NFCTSocket):
Same result than /proc/sys/net/netfilter/nf_conntrack_count file
or conntrack -C command
ndmsg = super(Conntrack, self).count()
return ndmsg[0].get_attr('CTA_STATS_GLOBAL_ENTRIES')
for ndmsg in super(Conntrack, self).count():
return ndmsg.get_attr('CTA_STATS_GLOBAL_ENTRIES')
def conntrack_max_size(self):
Return the max size of connection tracking table
ndmsg = super(Conntrack, self).conntrack_max_size()
return ndmsg[0].get_attr('CTA_STATS_GLOBAL_MAX_ENTRIES')
for ndmsg in super(Conntrack, self).conntrack_max_size():
return ndmsg.get_attr('CTA_STATS_GLOBAL_MAX_ENTRIES')
def delete(self, entry):
if isinstance(entry, ConntrackEntry):
......@@ -125,7 +127,12 @@ class Conntrack(NFCTSocket):
tuple_orig = entry
raise NotImplementedError()
self.entry('del', tuple_orig=tuple_orig)
for ndmsg in self.entry('del', tuple_orig=tuple_orig):
return ndmsg
def entry(self, cmd, **kwargs):
for res in super(Conntrack, self).entry(cmd, **kwargs):
return res
def dump_entries(self, mark=None, mark_mask=0xffffffff, tuple_orig=None,
......@@ -86,7 +86,7 @@ class TestConntrack(BasicSetup):
# These values should be pretty the same, but the call is not atomic
# so some sessions may end or begin that time. Thus the difference
# may occur, but should not be significant.
assert abs(len(self.ct.dump()) - self.ct.count()) < 3
assert abs(len(list(self.ct.dump())) - self.ct.count()) < 3
class TestNFCTSocket(BasicSetup):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment