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

Add ability to produce WireShark-compatible PCAP packet logging. #38

Open
wants to merge 1 commit into
base: helium/hotspot
Choose a base branch
from

Conversation

ke6jjj
Copy link

@ke6jjj ke6jjj commented Jun 30, 2023

Summary

This PR adds the ability to log received LoRa packets to "PCAP" file in a format that has been standardized by the WireShark network analysis project.

Usage

PCAP logging can be enabled via the JSON configuration file. When enabled, PCAP logging can be reset via SIGHUP to allow for log rotation without restarting the packet forwarder.

JSON path Value
gateway_conf.pcap_dump_path Pathname of the PCAP file to create (or append to) when logging packets

Example config

With this patch, PCAP logging is disabled by default, but it can be enabled by adding a pcap_dump_path item to gateway_conf item the global JSON configuration. For example:

{
    ...
    "gateway_conf": {
        ...
        "pcap_dump_path": "/var/tmp/lora.pcap"
    }
}

To rotate the PCAP file (for example, once a day), move the current PCAP output to a new location (say, /var/tmp/lora-YYYY-MM-DD.pcap) then deliver a SIGHUP (signal 1) signal to the packet forwarder. It will open and initialize a new /var/tmp/lora.pcap file on receipt.

@ke6jjj ke6jjj requested a review from JayKickliter June 30, 2023 22:32
@@ -129,6 +130,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* signal handling variables */
volatile bool exit_sig = false; /* 1 -> application terminates cleanly (shut down hardware, close open files, etc) */
volatile bool quit_sig = false; /* 1 -> application terminates without shutting down the hardware */
volatile bool reload_sig = false; /* 1 -> application re-opens logs/PCAP output */

Choose a reason for hiding this comment

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

I’m guessing you’re just following the existing code, but these should all be atomics. Somehow I forgot it never noticed the (incorrect) use of volatile here

Comment on lines +6 to +10
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif

Choose a reason for hiding this comment

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

This pattern is something I've accepted in C source, but never understood. Or at least can't remember


/*
* The PCAP file header. Using clever runtime checking of the
* magic number field, this structure can be written to disk

Choose a reason for hiding this comment

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

I see a write method for this struct, but no 'read'. Is that done elsewhere? Sorry if dump question, I don't know a whole lot about pcap

uint16_t tag; /* !MISALIGNED */
};
static size_t kLoRaTapHeaderSize = 35;

Choose a reason for hiding this comment

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

I like that you use a literal for the size above (I dislike having to do math when reading code), but I always like to add a static assert in these situations:

Suggested change
__Static_assert(sizeof(struct pcap_lora_tap_header) == kLoRaTapHeaderSize, "check LoRa header size");

Choose a reason for hiding this comment

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

I add the static assert suggestion from memory, so please double check syntax/usage before using if you chose to do so.

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.

2 participants