summaryrefslogtreecommitdiff
path: root/trafgen_lexer.l
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-01-26 22:25:04 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-01-28 16:15:17 +0100
commitf3c3677c5dd67d7edda5bee5b316e014be231337 (patch)
treefba2a79fc32b2e753cc0ea1b46882c0cf6507960 /trafgen_lexer.l
parent5ad97d9ef3f77a246a588f4256d92f831e542f5d (diff)
trafgen: parser: Add syntax to generate Ethernet header fields
Add function 'eth()' to support generating Ethernet header fields from the trafgen configuration language. Supported fields: da|daddr destination address, default: 00:00:00:00:00:00 sa|saddr source address, default: device MAC prot|proto protocol number, default: 0x0000 Example usage: { eth(prot=0x0800, da=11:22:33:44:55:66), fill(0xff, 60) } { eth(prot=0x0800) } { eth() } It is important that proto_init is called before fields will be filled to initialize the specified proto with header fields. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> [tk: document supported keywords in commit message] Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_lexer.l')
-rw-r--r--trafgen_lexer.l15
1 files changed, 15 insertions, 0 deletions
diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index 6c27b0c..d209116 100644
--- a/trafgen_lexer.l
+++ b/trafgen_lexer.l
@@ -19,6 +19,7 @@
#include "trafgen_parser.tab.h"
#include "xmalloc.h"
#include "built_in.h"
+#include "str.h"
extern void yyerror(const char *);
@@ -75,6 +76,9 @@ number_bin ([0]?[b][0-1]+)
number_dec (([0])|([1-9][0-9]*))
number_ascii ([a-zA-Z])
+mac_hex ([a-fA-F0-9]+)
+mac ({mac_hex}:{mac_hex}:{mac_hex}:{mac_hex}:{mac_hex}:{mac_hex})
+
%%
"cpu" { return K_CPU; }
@@ -99,6 +103,12 @@ number_ascii ([a-zA-Z])
"const32"|"c32" { return K_CONST32; }
"const64"|"c64" { return K_CONST64; }
+"daddr"|"da" { return K_DADDR; }
+"saddr"|"sa" { return K_SADDR; }
+"prot"[o]? { return K_PROT; }
+
+"eth" { return K_ETH; }
+
[ ]*"-"[ ]* { return '-'; }
[ ]*"+"[ ]* { return '+'; }
[ ]*"*"[ ]* { return '*'; }
@@ -117,6 +127,7 @@ number_ascii ([a-zA-Z])
"]" { return ']'; }
"," { return ','; }
":" { return ':'; }
+"=" { return '='; }
"\n" { yylineno++; }
@@ -146,6 +157,10 @@ number_ascii ([a-zA-Z])
{number_ascii} { yylval.number = (uint8_t) (*yytext);
return number; }
+{mac} { if (str2mac(yytext, yylval.bytes, 256))
+ panic("Failed to parse MAC address %s\n", yytext);
+ return mac; }
+
"'\\x"[a-fA-F0-9]{2}"'" { yylval.number = strtol(yytext + 3, NULL, 16);
return number; }