Skip to content

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

Open
ke6jjj wants to merge 1 commit intohelium/hotspotfrom
jsc/lora-tap-pcap
Open

Add ability to produce WireShark-compatible PCAP packet logging.#38
ke6jjj wants to merge 1 commit intohelium/hotspotfrom
jsc/lora-tap-pcap

Conversation

@ke6jjj
Copy link
Copy Markdown

@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
/* 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 */
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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;

Copy link
Copy Markdown

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");

Copy link
Copy Markdown

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