Skip to content

Commit b7c071a

Browse files
committed
speed up code for arm architecture when creating new rules
1 parent 794aace commit b7c071a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

iptc/ip4tc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@
4040
xtables(NFPROTO_IPV4)
4141

4242

43+
exist_table_names = dict() # Dictionary to check faster if table is available
44+
4345
def is_table_available(name):
46+
global exist_table_names
4447
try:
48+
if name in exist_table_names:
49+
return exist_table_names[name]
4550
Table(name)
51+
exist_table_names[name] = True
4652
return True
4753
except IPTCError:
4854
pass
55+
exist_table_names[name] = False
4956
return False
5057

5158

@@ -669,6 +676,11 @@ class Target(IPTCModule):
669676
does not take any value in the iptables extension, an empty string i.e. ""
670677
should be used.
671678
"""
679+
680+
STANDARD_TARGETS = ["", "ACCEPT", "DROP", "REJECT", "RETURN", "REDIRECT", "SNAT", "DNAT", \
681+
"MASQUERADE", "MIRROR", "TOS", "MARK", "QUEUE", "LOG"]
682+
"""This is the constant for all standard targets."""
683+
672684
def __init__(self, rule, name=None, target=None, revision=None, goto=None):
673685
"""
674686
*rule* is the Rule object this match belongs to; it can be changed
@@ -784,6 +796,8 @@ def _create_buffer(self, target):
784796
self.reset()
785797

786798
def _is_standard_target(self):
799+
if self._name in Target.STANDARD_TARGETS:
800+
return False
787801
for t in self._rule.tables:
788802
if t.is_chain(self._name):
789803
return True

iptc/ip6tc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717
_IFNAMSIZ = 16
1818

1919

20+
exist_table6_names = dict() # Dictionary to check faster if table is available
21+
2022
def is_table6_available(name):
23+
global exist_table6_names
2124
try:
25+
if name in exist_table6_names:
26+
return exist_table6_names[name]
2227
Table6(name)
28+
exist_table6_names[name] = True
2329
return True
2430
except IPTCError:
2531
pass
32+
exist_table6_names[name] = False
2633
return False
2734

2835

0 commit comments

Comments
 (0)