From bf228e53274c0573e11345d7aea2f2e8f7fcdc19 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 12:03:56 +0000 Subject: [PATCH] Add tests for IP packet fragmentation flags Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com> --- pydivert/tests/test_packet.py | 51 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/pydivert/tests/test_packet.py b/pydivert/tests/test_packet.py index 7f56e65..3840672 100644 --- a/pydivert/tests/test_packet.py +++ b/pydivert/tests/test_packet.py @@ -139,12 +139,59 @@ def test_ipv4_fields(): ip = p.ipv4 ip.ttl = 64 assert ip.ttl == 64 - ip.df = True - assert ip.df ip.ident = 0x1234 assert ip.ident == 0x1234 +def test_ipv4_fragmentation_flags(): + p = create_base_ipv4_tcp() + ip = p.ipv4 + + # Reset all flags + ip.rf = False + ip.df = False + ip.mf = False + + # Check initial state + assert not ip.rf + assert not ip.df + assert not ip.mf + assert not ip.reserved + + # Test rf (and reserved alias) + ip.rf = True + assert ip.rf + assert ip.reserved + assert not ip.df + assert not ip.mf + ip.reserved = False + assert not ip.rf + assert not ip.reserved + + # Test df + ip.df = True + assert ip.df + assert not ip.rf + assert not ip.mf + ip.df = False + assert not ip.df + + # Test mf + ip.mf = True + assert ip.mf + assert not ip.rf + assert not ip.df + ip.mf = False + assert not ip.mf + + # Set combinations + ip.rf = True + ip.df = True + assert ip.rf + assert ip.df + assert not ip.mf + + # --- TCP Fields ---