Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up code for arm architecture when creating new rules #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions iptc/ip4tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@
xtables(NFPROTO_IPV4)


exist_table_names = dict() # Dictionary to check faster if table is available

def is_table_available(name):
global exist_table_names
try:
if name in exist_table_names:
return exist_table_names[name]
Table(name)
exist_table_names[name] = True
return True
except IPTCError:
pass
exist_table_names[name] = False
return False


Expand Down Expand Up @@ -669,6 +676,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 +796,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
7 changes: 7 additions & 0 deletions iptc/ip6tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
_IFNAMSIZ = 16


exist_table6_names = dict() # Dictionary to check faster if table is available

def is_table6_available(name):
global exist_table6_names
try:
if name in exist_table6_names:
return exist_table6_names[name]
Table6(name)
exist_table6_names[name] = True
return True
except IPTCError:
pass
exist_table6_names[name] = False
return False


Expand Down