Skip to content

Commit fb73a4e

Browse files
committed
af-packet: clean up IPS config check
Don't emmit generic error statements on things that are not errors. Instead, for cases where (part of) the config is missing, use the defaults and log only a more detailed explanation at the 'config' level. Minor code cleanups.
1 parent 078c646 commit fb73a4e

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/runmode-af-packet.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,33 @@ const char *RunModeAFPGetDefaultMode(void)
6666
return "workers";
6767
}
6868

69-
static int AFPRunModeIsIPS(void)
69+
static bool AFPRunModeIsIPS(void)
7070
{
7171
int nlive = LiveGetDeviceCount();
72-
int ldev;
73-
ConfNode *if_root;
74-
ConfNode *if_default = NULL;
75-
ConfNode *af_packet_node;
76-
int has_ips = 0;
77-
int has_ids = 0;
72+
bool has_ips = false;
73+
bool has_ids = false;
7874

79-
/* Find initial node */
80-
af_packet_node = ConfGetNode("af-packet");
75+
ConfNode *af_packet_node = ConfGetNode("af-packet");
8176
if (af_packet_node == NULL) {
82-
return 0;
77+
SCLogConfig("no 'af-packet' section in the yaml, default to IDS");
78+
return false;
8379
}
8480

85-
if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
81+
ConfNode *if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
8682

87-
for (ldev = 0; ldev < nlive; ldev++) {
83+
for (int ldev = 0; ldev < nlive; ldev++) {
8884
const char *live_dev = LiveGetDeviceName(ldev);
8985
if (live_dev == NULL) {
90-
SCLogError("Problem with config file");
91-
return -1;
86+
SCLogConfig("no 'af-packet' section for '%s' in the yaml, default to IDS", live_dev);
87+
return false;
9288
}
93-
if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
94-
89+
ConfNode *if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
9590
if (if_root == NULL) {
9691
if (if_default == NULL) {
97-
SCLogError("Problem with config file");
98-
return -1;
92+
SCLogConfig(
93+
"no 'af-packet' section for '%s' or 'default' in the yaml, default to IDS",
94+
live_dev);
95+
return false;
9996
}
10097
if_root = if_default;
10198
}
@@ -105,28 +102,28 @@ static int AFPRunModeIsIPS(void)
105102
if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1 &&
106103
ConfGetChildValue(if_root, "copy-iface", &copyifacestr) == 1) {
107104
if (strcmp(copymodestr, "ips") == 0) {
108-
has_ips = 1;
105+
has_ips = true;
109106
} else {
110-
has_ids = 1;
107+
has_ids = true;
111108
}
112109
} else {
113-
has_ids = 1;
110+
has_ids = true;
114111
}
115112
}
116113

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

123120
return has_ips;
124121
}
125122

126123
static int AFPRunModeEnableIPS(void)
127124
{
128-
int r = AFPRunModeIsIPS();
129-
if (r == 1) {
125+
bool r = AFPRunModeIsIPS();
126+
if (r) {
130127
SCLogInfo("Setting IPS mode");
131128
EngineModeSetIPS();
132129
}

0 commit comments

Comments
 (0)