-
Notifications
You must be signed in to change notification settings - Fork 3
FCS detection improvements #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
630452c
Extend PCAP FCS detection
klf-gs ac09bcb
Bump version to 1.5.0
klf-gs a6b02f5
Add type in docstring
klf-gs e81c931
Undo autoformat
klf-gs f72db06
More concise conditionals
klf-gs b6b47e1
Separate ternary and boolean functions
klf-gs bcd2749
Apply suggestions from code review
klf-gs df7158f
Add back EOFError check
klf-gs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,68 @@ | ||
| const PCAP_FCS = base64decode(""" | ||
| 1MOyoQIABAAAAAAAAAAAAABAAAABAAAATHLDZMwhDABeAAAAXgAAAAEAXgByrQDXj6hWAQgARQAA | ||
| const PCAP_FILE_HEADER = "TTyyoQIABAAAAAAAAAAAAAAGAAABAAAA" | ||
|
|
||
| const PCAP_FCS = """ | ||
| THLDZMwhDABeAAAAXgAAAAEAXgByrQDXj6hWAQgARQAA | ||
| TGk3QAD9Eag2wR1YZ+AAcq1KeuaZADhwtSAAyDL/////HxIFAHRgAwAMAQAAAAAAAAzrS61s+HUX | ||
| EADJMv////9OAAAAAAAAALygjcY= | ||
| """) | ||
| """ | ||
|
|
||
| const PCAP_NOFCS = base64decode(""" | ||
| 1MOyoQIABAAAAAAAAAAAAAAABAABAAAAablkZZ4hAgBiAAAAYgAAAAABIQIgTBjATYjFhQgARQAA | ||
| const PCAP_NOFCS = """ | ||
| ablkZZ4hAgBiAAAAYgAAAAABIQIgTBjATYjFhQgARQAA | ||
| VMmzQABAAVv6CksAZQpLAAEIANTpAAIAAWm5ZGUAAAAAlCECAAAAAAAQERITFBUWFxgZGhscHR4f | ||
| ICEiIyQlJicoKSorLC0uLzAxMjM0NTY3 | ||
| """) | ||
| """ | ||
|
|
||
| const PCAP_CORRUPT_FCS = base64decode(""" | ||
| 1MOyoQIABAAAAAAAAAAAAABAAAABAAAATHLDZMwhDABeAAAAXgAAAAEAXgByrQDXj6hWAQgARQAA | ||
| const PCAP_CORRUPT_FCS = """ | ||
| THLDZMwhDABeAAAAXgAAAAEAXgByrQDXj6hWAQgARQAA | ||
| TGk3QAD9Eag2wR1YZ+AAcq1KeuaZADhwtSAAyDL/////HxIFAHRgAwAMAQAAAAAAAAzrS61s+HUX | ||
| EADJMv////9OAAAAAAAAALygjcg= | ||
| """) | ||
| """ | ||
|
|
||
| # Miniumum ethernet packet size (60 bytes without FCS) | ||
| const PCAP_SMALL = """ | ||
| Tq98Zs+xVzM8AAAAPAAAAAEAXgBynQDXj6hFQQgARQAA | ||
| HrAOQAD9EV7swR1bGOAAcp3yuObOAAr2hcD4AAAAAAAAAAAAAAAAAAAAAA== | ||
| """ | ||
|
|
||
| # Non-IPv4 packet (ARP protocol) | ||
| const PCAP_NONIP = """ | ||
| 8+/iZolNFC1AAAAAQAAAAAD2Y0DDvGQ/XwHjQwgGAAEI | ||
| AAYEAAFkP18B40Na4gKMAAAAAAAAWuICgQAAAAAAAAAAAAAAAAAAAAAAAOr6Tyw= | ||
| """ | ||
|
|
||
| check_detect_fcs(packets; confirm_checksum=true) = | ||
| pushfirst!(packets, PCAP_FILE_HEADER) |> | ||
| join |> | ||
| base64decode |> | ||
| PcapBufferReader |> | ||
| (x -> try_detect_fcs(x; confirm_checksum)) | ||
|
|
||
| @testset "pcap_has_fcs" begin | ||
| @test pcap_has_fcs(PcapBufferReader(PCAP_FCS)) | ||
| @test !pcap_has_fcs(PcapBufferReader(PCAP_NOFCS)) | ||
| @test pcap_has_fcs(PcapBufferReader(base64decode(PCAP_FILE_HEADER * PCAP_FCS))) | ||
| @test !pcap_has_fcs(PcapBufferReader(base64decode(PCAP_FILE_HEADER * PCAP_NOFCS))) | ||
| end | ||
|
|
||
| @testset "try_detect_fcs" begin | ||
| @test check_detect_fcs([PCAP_NONIP]) == FCS_UNDETERMINED | ||
| @test check_detect_fcs([PCAP_SMALL]) == FCS_UNDETERMINED | ||
| @test check_detect_fcs([""]) == FCS_UNDETERMINED # empty pcap | ||
|
|
||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_FCS]) == FCS_PRESENT | ||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_NOFCS]) == FCS_ABSENT | ||
|
|
||
| # Corrupt FCS packets will be ignored by default | ||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_CORRUPT_FCS]) == FCS_UNDETERMINED | ||
| # But corrupt FCS can be explicitly allowed | ||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_CORRUPT_FCS]; confirm_checksum = false) == FCS_PRESENT | ||
|
|
||
| # Make sure we skip corrupt frames if confirm_checksum is on | ||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_CORRUPT_FCS, PCAP_FCS]) == FCS_PRESENT | ||
| @test check_detect_fcs([PCAP_NONIP, PCAP_SMALL, PCAP_CORRUPT_FCS, PCAP_NOFCS]) == FCS_ABSENT | ||
| end | ||
|
|
||
| @testset "compute_fcs" begin | ||
| r_fcs = read(PcapBufferReader(PCAP_FCS)) | ||
| r_fcs = read(PcapBufferReader(base64decode(PCAP_FILE_HEADER * PCAP_FCS))) | ||
| @test check_fcs(r_fcs) | ||
| r_no_fcs = read(PcapBufferReader(PCAP_CORRUPT_FCS)) | ||
| r_no_fcs = read(PcapBufferReader(base64decode(PCAP_FILE_HEADER * PCAP_CORRUPT_FCS))) | ||
| @test !check_fcs(r_no_fcs) | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.