Skip to content

Commit

Permalink
Fix FiveTuple printing to print actual contents of dataclass instead …
Browse files Browse the repository at this point in the history
…of class type
  • Loading branch information
Jauler committed Dec 17, 2024
1 parent 07f2d21 commit 37f1712
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Empty file.
9 changes: 6 additions & 3 deletions nat-lab/tests/utils/connection_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __hash__(self):
(self.protocol, self.src_ip, self.dst_ip, self.src_port, self.dst_port)
)

def __str__(self) -> str:
return f"{self.protocol} {self.src_ip}:{self.src_port} -> {self.dst_ip}:{self.dst_port}"


class EventType(Enum):
"""Event type reported by conntrack"""
Expand Down Expand Up @@ -147,7 +150,7 @@ def __init__(
):
if max_limit is not None and min_limit is not None and max_limit < min_limit:
raise ValueError(
f"Max limit {max_limit} is smaller then min limit {min_limit}"
f"Max limit {max_limit} is smaller than min limit {min_limit}"
)

self.key = key
Expand All @@ -172,12 +175,12 @@ def find_conntracker_violations(
if self.max_limit is not None and count > self.max_limit:
return ConnTrackerViolation(
recoverable=False,
reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is more then max limit of {self.max_limit}",
reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is more than max limit of {self.max_limit}",
)
if self.min_limit is not None and count < self.min_limit:
return ConnTrackerViolation(
recoverable=True,
reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is less then min limit of {self.min_limit}",
reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is less than min limit of {self.min_limit}",
)

return None
Expand Down

0 comments on commit 37f1712

Please sign in to comment.