blob: 998e86795728bf78ff473e5cb78727030f0914f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* 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; }
[tT][eE][xX][tT] { yylval->i = TCF_EM_TEXT; return EMATCH_TEXT; }
"(" return KW_OPEN;
")" return KW_CLOSE;
[mM][aA][sS][kK] return KW_MASK;
[aA][tT] return KW_AT;
"+" return KW_PLUS;
[fF][rR][oO][mM] return KW_FROM;
[tT][oO] return KW_TO;
[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;
}
|