From 66e558ed51ff7d3d7bebb5f5d56114df5eb77e96 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 7 Nov 2015 16:55:16 +0200 Subject: 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 Signed-off-by: Tobias Klauser --- trafgen_parser.y | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'trafgen_parser.y') 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); -- cgit v1.2.3-54-g00ecf