Skip to content

Commit

Permalink
Fix setup_input_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
radupotop committed Apr 5, 2024
1 parent 1a021f3 commit 02ff5b2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/iptables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup_whitelist_chain(self):
log.info('Creating the whitelist chain: %s', self.config.chain)
self.chain = self.filter_table.create_chain(self.config.chain)

def setup_input_chain(self):
def setup_input_chain(self, set_policy_drop=False):
"""
Append a rule to the INPUT chain to jump to the whitelist chain for
all the packets matching the destination ports & protocols.
Expand All @@ -40,7 +40,7 @@ def setup_input_chain(self):
input_chain.append_rule(input_rule)
log.info('Added INPUT chain rule for %s:%s', port, protocol)

if self.config.set_input_policy_drop:
if set_policy_drop:
log.warning('Setting the INPUT chain Policy to DROP')
input_chain.set_policy(iptc.Policy.DROP)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_iptables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup_class(self):

def test_setup_chain(self):
self.ipt.setup_whitelist_chain()
self.ipt.setup_input_chain()
self.ipt.setup_input_chain(set_policy_drop=True)

def test_initial_chain_added(self):
chain_names = [c.name for c in self.filter_table.chains]
Expand Down
2 changes: 1 addition & 1 deletion utils/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_chains():
cfg = ConfigReader()
ipt = IPTables(cfg)
ipt.setup_whitelist_chain()
ipt.setup_input_chain()
ipt.setup_input_chain(set_policy_drop=cfg.set_input_policy_drop)


if __name__ == '__main__':
Expand Down

0 comments on commit 02ff5b2

Please sign in to comment.