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

af-packet: clean up IPS config check #12397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions src/runmode-af-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,33 @@ const char *RunModeAFPGetDefaultMode(void)
return "workers";
}

static int AFPRunModeIsIPS(void)
static bool AFPRunModeIsIPS(void)
{
int nlive = LiveGetDeviceCount();
int ldev;
ConfNode *if_root;
ConfNode *if_default = NULL;
ConfNode *af_packet_node;
int has_ips = 0;
int has_ids = 0;
bool has_ips = false;
bool has_ids = false;

/* Find initial node */
af_packet_node = ConfGetNode("af-packet");
ConfNode *af_packet_node = ConfGetNode("af-packet");
if (af_packet_node == NULL) {
return 0;
SCLogConfig("no 'af-packet' section in the yaml, default to IDS");
return false;
}

if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
ConfNode *if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");

for (ldev = 0; ldev < nlive; ldev++) {
for (int ldev = 0; ldev < nlive; ldev++) {
const char *live_dev = LiveGetDeviceName(ldev);
if (live_dev == NULL) {
SCLogError("Problem with config file");
return -1;
SCLogConfig("no 'af-packet' section for '%s' in the yaml, default to IDS", live_dev);
return false;
}
if_root = ConfFindDeviceConfig(af_packet_node, live_dev);

ConfNode *if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
if (if_root == NULL) {
if (if_default == NULL) {
SCLogError("Problem with config file");
return -1;
SCLogConfig(
"no 'af-packet' section for '%s' or 'default' in the yaml, default to IDS",
live_dev);
return false;
}
if_root = if_default;
}
Expand All @@ -105,28 +102,28 @@ static int AFPRunModeIsIPS(void)
if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1 &&
ConfGetChildValue(if_root, "copy-iface", &copyifacestr) == 1) {
if (strcmp(copymodestr, "ips") == 0) {
has_ips = 1;
has_ips = true;
} else {
has_ids = 1;
has_ids = true;
}
} else {
has_ids = 1;
has_ids = true;
}
}

if (has_ids && has_ips) {
SCLogError("using both IPS and TAP/IDS mode is not allowed due to undefined behavior. See "
"ticket #5588.");
return -1;
return false;
}

return has_ips;
}

static int AFPRunModeEnableIPS(void)
{
int r = AFPRunModeIsIPS();
if (r == 1) {
bool r = AFPRunModeIsIPS();
if (r) {
SCLogInfo("Setting IPS mode");
EngineModeSetIPS();
}
Expand Down
Loading