diff --git a/iptc/ip4tc.py b/iptc/ip4tc.py index 4ddd2dc..90f5ee7 100644 --- a/iptc/ip4tc.py +++ b/iptc/ip4tc.py @@ -42,10 +42,14 @@ def is_table_available(name): try: + if name in Table.existing_table_names: + return Table.existing_table_names[name] Table(name) + Table.existing_table_names[name] = True return True except IPTCError: pass + Table.existing_table_names[name] = False return False @@ -669,6 +673,11 @@ class Target(IPTCModule): does not take any value in the iptables extension, an empty string i.e. "" should be used. """ + + STANDARD_TARGETS = ["", "ACCEPT", "DROP", "REJECT", "RETURN", "REDIRECT", "SNAT", "DNAT", \ + "MASQUERADE", "MIRROR", "TOS", "MARK", "QUEUE", "LOG"] + """This is the constant for all standard targets.""" + def __init__(self, rule, name=None, target=None, revision=None, goto=None): """ *rule* is the Rule object this match belongs to; it can be changed @@ -784,6 +793,8 @@ def _create_buffer(self, target): self.reset() def _is_standard_target(self): + if self._name in Target.STANDARD_TARGETS: + return False for t in self._rule.tables: if t.is_chain(self._name): return True @@ -1572,6 +1583,8 @@ class Table(object): """This is the constant for all tables.""" _cache = dict() + existing_table_names = dict() + """Dictionary to check faster if a table is available.""" def __new__(cls, name, autocommit=None): obj = Table._cache.get(name, None) diff --git a/iptc/ip6tc.py b/iptc/ip6tc.py index ea4a1d7..e0d8787 100644 --- a/iptc/ip6tc.py +++ b/iptc/ip6tc.py @@ -19,10 +19,14 @@ def is_table6_available(name): try: + if name in Table6.existing_table_names: + return Table6.existing_table_names[name] Table6(name) + Table6.existing_table_names[name] = True return True except IPTCError: pass + Table6.existing_table_names[name] = False return False @@ -572,6 +576,8 @@ class Table6(Table): """This is the constant for all tables.""" _cache = dict() + existing_table_names = dict() + """Dictionary to check faster if a table is available.""" def __new__(cls, name, autocommit=None): obj = Table6._cache.get(name, None)