summaryrefslogtreecommitdiffstats
path: root/lib/route/cls/ematch_grammar.l
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-28 22:20:42 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-10-28 22:20:42 (GMT)
commitd7a561a1372f819efc8cede30dc550d8e3afcc28 (patch)
treeda9fefa62f5ffdca82fa374ebe0b207202719410 /lib/route/cls/ematch_grammar.l
parente1eacd6b16b014eb42bcf6683ebe2334c3a35c68 (diff)
downloadlibnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.zip
libnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.tar.gz
libnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.tar.bz2
Tons of ematch work
- Fixes a bunch of bugs related to ematches - Adds support for the nbyte ematch - Adds a bison/flex parser for ematch expressions, expressions may look like this: ip.length > 256 && pattern(ip6.src = 3ffe::/16) documenation on syntax follows - adds ematch support to the basic classifier (--ematch EXPR)
Diffstat (limited to 'lib/route/cls/ematch_grammar.l')
-rw-r--r--lib/route/cls/ematch_grammar.l105
1 files changed, 105 insertions, 0 deletions
diff --git a/lib/route/cls/ematch_grammar.l b/lib/route/cls/ematch_grammar.l
new file mode 100644
index 0000000..e345181
--- /dev/null
+++ b/lib/route/cls/ematch_grammar.l
@@ -0,0 +1,105 @@
+/*
+ * lib/route/cls/ematch_grammar.l ematch expression grammar
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
+ */
+
+%{
+ #include <netlink-local.h>
+ #include <netlink-tc.h>
+ #include <netlink/netlink.h>
+ #include <netlink/route/cls/ematch.h>
+ #include <netlink/route/cls/ematch/cmp.h>
+ #include "ematch_syntax.h"
+%}
+
+%option 8bit
+%option reentrant
+%option warn
+%option noyywrap
+%option noinput
+%option nounput
+%option bison-bridge
+%option prefix="ematch_"
+
+%x QUOTE
+
+%%
+
+[ \t\r\n]+
+
+\" {
+ NL_DBG(4, "Beginning of quote\n");
+ yylval->q.len = 32;
+ if (!(yylval->q.data = calloc(1, yylval->q.len)))
+ return ERROR;
+
+ yylval->q.index = 0;
+ BEGIN(QUOTE);
+ }
+
+<QUOTE>[^\\\n\"]+ {
+ memcpy(yylval->q.data + yylval->q.index, yytext,
+ strlen(yytext));
+ yylval->q.index += strlen(yytext);
+ }
+
+<QUOTE>\" {
+ BEGIN(0);
+ return QUOTED;
+ }
+
+
+[[:digit:]]+ |
+0[xX][[:xdigit:]]+ {
+ yylval->i = strtoul(yytext, NULL, 0);
+ return NUMBER;
+ }
+
+eq |
+"=" return KW_EQ;
+gt |
+">" return KW_GT;
+lt |
+"<" return KW_LT;
+
+[aA][nN][dD] |
+"&&" { yylval->i = TCF_EM_REL_AND; return LOGIC; }
+[oO][rR] |
+"||" { yylval->i = TCF_EM_REL_OR; return LOGIC; }
+[nN][oO][tT] |
+"!" return NOT;
+
+[cC][mM][pP] { yylval->i = TCF_EM_CMP; return EMATCH_CMP; }
+[pP][aA][tT][tT][eE][rR][nN] { yylval->i = TCF_EM_NBYTE; return EMATCH_NBYTE; }
+
+"(" return KW_OPEN;
+")" return KW_CLOSE;
+[mM][aA][sS][kK] return KW_MASK;
+[aA][tT] return KW_AT;
+"+" return KW_PLUS;
+
+[uU]8 { yylval->i = TCF_EM_ALIGN_U8; return ALIGN; }
+[uU]16 { yylval->i = TCF_EM_ALIGN_U16; return ALIGN; }
+[uU]32 { yylval->i = TCF_EM_ALIGN_U32; return ALIGN; }
+
+[lL][iI][nN][kK] |
+[eE][tT][hH] { yylval->i = TCF_LAYER_LINK; return LAYER; }
+[nN][eE][tT] |
+[iI][pP]6 |
+[iI][pP] { yylval->i = TCF_LAYER_NETWORK; return LAYER; }
+[tT][rR][aA][nN][sS][pP][oO][rR][tT] |
+[tT][cC][pP] { yylval->i = TCF_LAYER_TRANSPORT; return LAYER; }
+
+[^ \t\r\n+()=<>&|\"]+ {
+ yylval->s = strdup(yytext);
+ if (yylval->s == NULL)
+ return ERROR;
+ NL_DBG(4, "lex STR=%s\n", yylval->s);
+ return STR;
+ }