summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-11-07 16:55:16 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-11-09 13:41:24 +0100
commit66e558ed51ff7d3d7bebb5f5d56114df5eb77e96 (patch)
tree4740acd0e3e239e415008a93f572b15085e316fe /trafgen_parser.y
parentc6aeff438d452be679cc3ba0a600db1d204b49a6 (diff)
trafgen: Allow to build packet from command line
Craft packet directly from command line with same syntax as for conf file. It might be as first step to extend current syntax with specific proto fields. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y25
1 files changed, 25 insertions, 0 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 88daf7a..1718f3d 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -34,6 +34,8 @@
extern FILE *yyin;
extern int yylex(void);
+extern void yy_scan_string(char *);
+extern void yylex_destroy();
extern void yyerror(const char *);
extern int yylineno;
extern char *yytext;
@@ -641,6 +643,29 @@ err:
die();
}
+void compile_packets_str(char *str, bool verbose, unsigned int cpu)
+{
+ int ret = 1;
+
+ our_cpu = cpu;
+ realloc_packet();
+
+ yy_scan_string(str);
+ if (yyparse() != 0)
+ goto err;
+
+ finalize_packet();
+ if (our_cpu == 0 && verbose)
+ dump_conf();
+
+ ret = 0;
+err:
+ yylex_destroy();
+
+ if (ret)
+ die();
+}
+
void yyerror(const char *err)
{
fprintf(stderr, "Syntax error at line %d, char '%s': %s\n", yylineno, yytext, err);