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

Bug fix #6238 and AF_XDP program loading #9315

Closed
wants to merge 2 commits into from

Conversation

joser12345678
Copy link
Contributor

fixed bug by adding program loading support and program unloading after suricata stops. This is done by adding support for adding and removing AF_XDP programs.

Make sure these boxes are signed before submitting your Pull Request -- thank you.

Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/6238

Describe changes:
fixed bug by adding program loading support and program unloading after suricata stops. This is done by adding support for adding and removing AF_XDP programs. Added RunModeAFXDPRemoveProg() and RunModeLoadAFXDPProg() in runmode-af-xdp.c. Also added flag in the AFXDPIfaceConfig struct called inhibit_prog_load which if true will set a libxdp flag that prevents the default AF_XDP program from being loaded; this is needed if the user wants to load their own AF_XDP program. source-af-xdp.c was also changed to act on this flag being set. The user can now add the "xdp-program" item in the suricata.yaml file to point to a xdp-program the user wishes to load. Finally, added check in suricata.c to unload xdp-programs before the threads are shutdown, which fixes the race condition described in the ticket.

Provide values to any of the below to override the defaults.

To use a pull request use a branch name like pr/N where N is the
pull request number.

Alternatively, SV_BRANCH may also be a link to an
OISF/suricata-verify pull-request.

SV_REPO=
SV_BRANCH=
SU_REPO=
SU_BRANCH=
LIBHTP_REPO=
LIBHTP_BRANCH=

fixed bug by adding program loading support and program unloading after suricata stops
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

NOTE: This PR may contain new authors:

joser12345678 <joser17@vt.edu>

fixed bug by adding program loading support and program unloading after suricata stops
@jufajardini
Copy link
Contributor

Hi there @joser12345678, did you close this on purpose?

@joser12345678
Copy link
Contributor Author

Yes sir, I was under the impression that since my commit commit failed the tests here it was going to be closed and I would have to open a new one anyway. I take it this was an incorrect assumption on my part. I apologize as this is my first time contributing to suricata let alone an open source project

@jufajardini
Copy link
Contributor

jufajardini commented Aug 1, 2023

Yes sir, I was under the impression that since my commit commit failed the tests here it was going to be closed and I would have to open a new one anyway. I take it this was an incorrect assumption on my part. I apologize as this is my first time contributing to suricata let alone an open source project

No problems! Welcome to our community, and thanks for your interest in contributing to Suricata! I hope you'll have a good open source experience with us ^^
Your assumption was partially correct: when there are failures introduced by the PR, we don't usually close the PR right away, but we do ask the author to submit a new one, fixing said failures. I asked because I was in the process of reviewing it. Since you'll open a new PR soon, I'll leave a few general comments regarding our contribution guidelines here, so you can incorporate those on your next one! :)

@jufajardini
Copy link
Contributor

Commits segmentation : if the new additions are necessary to fix the bug, then I think it's ok
Commit messages : please see separate comment
Git ID set : please use First and Last name for commit author
CLA : to confirm
code: please see inline comments. I don't have the expertise to review these changes in full, and to be honest I'm not sure I understand the need to load another program to fix the bug - nor how safe this option would be. If this isn't a requirement, I think it might be best to keep the two changes separate, if possible. As for the security aspect, I think that @catenacyber or Victor would be better judges, when we have a new version of the PR :)
Doc update : will probably be necessary, as this would introduce a new config option
Redmine ticket : ok
Rustfmt : to see with next PR
Tests : is it possible to create some suricata-verify test for this? that would be ideal
Dependencies added: don't think so

Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

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

I've left a few comments for you to consider for your next PR :)

On top of those, for your next commit message, please follow our guideline of:

module: brief describe changes (<50 chars)

Add more descriptive message.

Bug #6238

If anything from my comments isn't clear, please, ask away!

Comment on lines +590 to +591
* ADDED function to add a socket to the XDP map
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ADDED a left over that should be replaced by \brief?

Comment on lines +481 to +483
SCLogInfo("unable to find af-xdp config for "
"interface \"%s\" or \"default\", using default values",
live_dev);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is related to configuration, it would probably be better to use SCLogConfig here and in other similar output messages, instead.

// get the path to the xdp-program
const char *program_path = NULL;
const char *confstr = NULL;
if (ConfGetChildValueWithDefault(if_root, if_default, "xdp-program", &confstr) == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'm missing something. Shouldn't xdp-program be added to our suricata.yaml.in if you want to use that config value?


int ret = xdp_program__detach(prog, ifindex, XDP_MODE_NATIVE, 0);
if (ret) {
printf("ERROR: can't detatch\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

We use our own SCLog API for logging messages with adequate log levels. If these are debug messages, I think SCLogDebug would work better, if not, maybe SCLogNotice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, even if this is an unrecoverable error, some other option would be best.


struct xdp_multiprog *progs = xdp_multiprog__get_from_ifindex(ptv->ifindex);
if (progs == NULL) {
printf("cannot get multiprog");
Copy link
Contributor

Choose a reason for hiding this comment

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

The same comment about log API applies here :)

@joser12345678
Copy link
Contributor Author

Ok, for my next version of this commit I will separate the adding of an AF_XDP program. The bug is detailed in the bug ticket. If more info is needed:
https://bugzilla.kernel.org/show_bug.cgi?id=217712

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants