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

Extended rule counters capabilities #289

Merged
merged 3 commits into from
Oct 28, 2019
Merged

Extended rule counters capabilities #289

merged 3 commits into from
Oct 28, 2019

Conversation

jllorente
Copy link
Collaborator

  • Extend ip4tc.py with set_counters() function and make counters a property of Rule()
  • Extend iptc.easy rule definition with a counters field, available on creation/representation: rule_d = {'counters': (100, 100), 'dst': '1.1.1.1', 'protocol': 'icmp', 'target': ''}
  • Counter update available via rule replacement: iptc.easy.replace_rule(table, chain, rule_d, rule_d)
  • Update documentation

@ldx
Copy link
Owner

ldx commented Oct 26, 2019

Probably easy to fix, a few tests are now failing:

======================================================================
FAIL: test_rule_to_dict (tests.test_iptc.TestRule)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ldx/python-iptables/tests/test_iptc.py", line 942, in test_rule_to_dict
    self.assertEqual(rule_d, {"protocol": "tcp", "src": "127.0.0.1/32", "target": "ACCEPT"})
AssertionError: {'src': '127.0.0.1/32', 'protocol': 'tcp', 'target': 'ACCEPT', 'counters': (0L,  [truncated]... != {'src': '127.0.0.1/32', 'protocol': 'tcp', 'target': 'ACCEPT'}
+ {'protocol': 'tcp', 'src': '127.0.0.1/32', 'target': 'ACCEPT'}
- {'counters': (0L, 0L),
-  'protocol': 'tcp',
-  'src': '127.0.0.1/32',
-  'target': 'ACCEPT'}

======================================================================
FAIL: test_rule_to_dict (tests.test_iptc.TestRule6)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ldx/python-iptables/tests/test_iptc.py", line 584, in test_rule_to_dict
    self.assertEqual(rule_d, {"protocol": "tcp", "src": "::1/128", "target": "ACCEPT"})
AssertionError: {'src': '::1/128', 'protocol': 'tcp', 'target': 'ACCEPT', 'counters': (0L, 0L)} != {'src': '::1/128', 'protocol': 'tcp', 'target': 'ACCEPT'}
- {'counters': (0L, 0L), 'protocol': 'tcp', 'src': '::1/128', 'target': 'ACCEPT'}
?  ----------------------
+ {'protocol': 'tcp', 'src': '::1/128', 'target': 'ACCEPT'}

======================================================================
FAIL: test_recent (tests.test_matches.TestRecentMatch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ldx/python-iptables/tests/test_matches.py", line 502, in test_recent
    self.assertEqual(rule_d, rule2_d)
AssertionError: {'protocol': 'udp', 'target': {'REJECT': {'reject-with': 'icmp-port-unreachable' [truncated]... != {'counters': (0L, 0L), 'protocol': 'udp', 'target': {u'REJECT': {'reject-with':  [truncated]...
+ {'counters': (0L, 0L),
- {'protocol': 'udp',
? ^
+  'protocol': 'udp',
? ^
-  'recent': {'mask': '255.255.255.255',
+  u'recent': {'mask': '255.255.255.255',
?  +
-             'name': 'UDP-PORTSCAN',
+              'name': 'UDP-PORTSCAN',
? +
-             'rsource': '',
+              'rsource': '',
? +
-             'seconds': '60',
+              'seconds': '60',
? +
-             'update': ''},
+              'update': ''},
? +
-  'target': {'REJECT': {'reject-with': 'icmp-port-unreachable'}}}
+  'target': {u'REJECT': {'reject-with': 'icmp-port-unreachable'}}}
?             +

@coveralls
Copy link

coveralls commented Oct 26, 2019

Coverage Status

Coverage increased (+0.01%) to 58.553% when pulling a1c3669 on issue288 into d46b145 on master.

@jllorente
Copy link
Collaborator Author

I thought that removing the "counters" from the assertion in the dictionary representation of the rule was the cleanest way to go about it.

@jllorente jllorente requested a review from ldx October 27, 2019 10:47
Copy link
Owner

@ldx ldx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ldx
Copy link
Owner

ldx commented Oct 28, 2019

Thanks, feel free to merge 👍

@jllorente jllorente merged commit 7fe9a99 into master Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants