Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions iptc/ip4tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions iptc/ip6tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down