==== Config
* Parsing issue with IP lists. can't parse rules with $EXTERNAL_NET
- defined as below because or the space between ! and 10.
+ defined as below because of the space between ! and 10.
HOME_NET = [[ 10.0.17.0/24 10.0.14.0/24 10.247.0.0/16 10.246.0.0/16 ]]
EXTERNAL_NET = '! ' .. HOME_NET
* --lua can only be used in addition to, not in place of, a -c config.
Ideally, --lua could be used in lieu of -c.
-* Rule line numbers provided with syntax error messages are off by one. The first rule is
- unnumbered, the second rule is one, etc. See nhttp_inspect/detection_buffers/bad_rules/expected
- for an example.
-
==== Rules
return tmp;
}
+static void log_message(const char* type, const char* msg)
+{
+ const char* file_name;
+ unsigned file_line;
+ get_parse_location(file_name, file_line);
+
+ if ( file_line )
+ LogMessage("%s: %s:%d %s\n", type, file_name, file_line, msg);
+ else
+ LogMessage("%s: %s\n", type, msg);
+}
+
void ParseMessage(const char* format, ...)
{
char buf[STD_BUF+1];
va_end(ap);
buf[STD_BUF] = '\0';
-
- const char* file_name;
- unsigned file_line;
- get_parse_location(file_name, file_line);
-
- // FIXIT-L use same format filename/linenum as ParseWarning ( %s(%d) vs $s:%d )
- if ( file_name )
- LogMessage("%s(%d) %s\n", file_name, file_line, buf);
- else
- LogMessage("%s\n", buf);
+ log_message("INFO", buf);
}
void ParseWarning(WarningGroup wg, const char* format, ...)
va_end(ap);
buf[STD_BUF] = '\0';
-
- const char* file_name;
- unsigned file_line;
- get_parse_location(file_name, file_line);
-
- // FIXIT-L Why `file_line` here and `file_name` in ParseMessage?
- if ( file_line )
- LogMessage("WARNING: %s:%d %s\n", file_name, file_line, buf);
- else
- LogMessage("WARNING: %s\n", buf);
+ log_message("WARNING", buf);
parse_warnings++;
}
va_end(ap);
buf[STD_BUF] = '\0';
-
- const char* file_name;
- unsigned file_line;
- get_parse_location(file_name, file_line);
-
- if (file_line )
- LogMessage("ERROR: %s:%d %s\n", file_name, file_line, buf);
- else
- LogMessage("ERROR: %s\n", buf);
+ log_message("ERROR", buf);
parse_errors++;
}
unsigned file_line;
get_parse_location(file_name, file_line);
- // FIXIT-L Refer to ParseMessage above.
- if ( file_name )
- FatalError("%s(%u) %s\n", file_name, file_line, buf);
+ if ( file_line )
+ FatalError("%s:%u %s\n", file_name, file_line, buf);
else
FatalError("%s\n", buf);
}
static std::stack<Location> files;
-const char* get_parse_file()
-{
- if ( files.empty() )
- return nullptr;
-
- Location& loc = files.top();
- return loc.file.c_str();
-}
-
void get_parse_location(const char*& file, unsigned& line)
{
if ( files.empty() )
snprintf(fname, path_len, "%s%s", snort_conf_dir, arg);
}
- push_parse_location(fname, 0);
+ push_parse_location(fname);
ParseConfigFile(sc, fname);
pop_parse_location();
snort_free((char*)fname);
void parser_init();
void parser_term();
-const char* get_parse_file();
+// line > 0 implies name is non-null
void get_parse_location(const char*& name, unsigned& line);
-void push_parse_location(const char* name, unsigned line = 0);
+
+// use line = 0 for lua to suppress line numbers for errors or warnings
+void push_parse_location(const char* name, unsigned line = 1);
void pop_parse_location();
void inc_parse_position();