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

debug: option to print using mnl format #219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

aojea
Copy link

@aojea aojea commented Jan 4, 2025

nftables uses the libmnl library that has a particular debugging format. This format is also used for nftables --debug=all. google/nftables golang library to interact with nftables uses this library to interface with netlink directly.
Since the netlink libraries and implementations are not well documented, is common to have to dump the netlink bits to compare.

This commit implements an option to choose the same format used in nftables by adding a new option to the NLDEBUG environmental variable and using the format=mnt key value.

Output of nft --debug=all

image

Output of a nftables dump using google/nftables and setting the environment variable
https://gist.github.com/aojea/8a811e11a060fa638aa2dd8165960d5a

NLDEBUG=format=mnl go run main.go cni-kindnet prerouting

image

cc: @stapelberg

Copy link
Contributor

@stapelberg stapelberg left a comment

Choose a reason for hiding this comment

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

Thanks for your PR!

debug.go Outdated Show resolved Hide resolved
doc.go Outdated Show resolved Hide resolved
Copy link
Owner

@mdlayher mdlayher left a comment

Choose a reason for hiding this comment

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

This is awesome, I would be fine making this the default debugging format given that the existing one is probably not very useful for most circumstances.

I do think that the printer is complex enough to probably at least merit a unit test that dumps a fixed output and verifies that it does not drift.

aojea added 2 commits January 6, 2025 14:48
Change-Id: I0d067261c1c30c0dc25fbc92f162b0a3746158ef
nftables uses the libmnl library that has a particular debugging format.
This format is also used for nftables --debug=all.
google/nftables golang library to interact with nftables uses this
library to interface with netlink directly.
Since these libraries are not well documented, is common to have to dump
the netlink bits to compare.

This commit implements an option to choose the same format used in
nftables by adding a new option to the NLDEBUG environmenta variable and
using the format=mnl key value.

For Linux systems mnl is the default format.

Change-Id: I5f63753b3ada4d25565fe0bddac35e010510a34f
@aojea
Copy link
Author

aojea commented Jan 6, 2025

This is awesome, I would be fine making this the default debugging format given that the existing one is probably not very useful for most circumstances.

I do think that the printer is complex enough to probably at least merit a unit test that dumps a fixed output and verifies that it does not drift.

@mdlayher added a commit to bump github actions and golang versions and defaulted the logger to mnl

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.

3 participants