1 %{
2 #include <netlink-local.h>
3 #include <netlink-tc.h>
4 #include <netlink/netlink.h>
5 #include <netlink/utils.h>
6 #include <netlink/route/pktloc.h>
7 %}
8
9 %locations
10 %error-verbose
11 %define api.pure
12 %name-prefix "pktloc_"
13
14 %parse-param {void *scanner}
15 %lex-param {void *scanner}
16
17 %union {
18 struct rtnl_pktloc *l;
19 uint32_t i;
20 char *s;
21 }
22
23 %{
24 extern int pktloc_lex(YYSTYPE *, YYLTYPE *, void *);
25 extern void rtnl_pktloc_add(struct rtnl_pktloc *);
26
yyerror(YYLTYPE * locp,void * scanner,const char * msg)27 static void yyerror(YYLTYPE *locp, void *scanner, const char *msg)
28 {
29 /* FIXME */
30 }
31 %}
32
33 %token <i> ERROR NUMBER LAYER
34 %token <s> NAME
35
36 %type <i> mask layer
37 %type <l> location
38
39 %destructor { free($$); } NAME
40
41 %start input
42
43 %%
44
45 input:
46 def
47 { }
48 ;
49
50 def:
51 /* empty */
52 { }
53 | location def
54 { }
55 ;
56
57 location:
58 NAME NAME layer NUMBER mask
59 {
60 struct rtnl_pktloc *loc;
61
62 if (!(loc = calloc(1, sizeof(*loc)))) {
63 /* FIXME */
64 }
65
66 if (!strcasecmp($2, "u8"))
67 loc->align = TCF_EM_ALIGN_U8;
68 else if (!strcasecmp($2, "h8")) {
69 loc->align = TCF_EM_ALIGN_U8;
70 loc->flags = TCF_EM_CMP_TRANS;
71 } else if (!strcasecmp($2, "u16"))
72 loc->align = TCF_EM_ALIGN_U16;
73 else if (!strcasecmp($2, "h16")) {
74 loc->align = TCF_EM_ALIGN_U16;
75 loc->flags = TCF_EM_CMP_TRANS;
76 } else if (!strcasecmp($2, "u32"))
77 loc->align = TCF_EM_ALIGN_U32;
78 else if (!strcasecmp($2, "h32")) {
79 loc->align = TCF_EM_ALIGN_U32;
80 loc->flags = TCF_EM_CMP_TRANS;
81 }
82
83 free($2);
84
85 loc->name = $1;
86 loc->layer = $3;
87 loc->offset = $4;
88 loc->mask = $5;
89
90 rtnl_pktloc_add(loc);
91
92 $$ = loc;
93 }
94 ;
95
96 layer:
97 /* empty */
98 { $$ = TCF_LAYER_NETWORK; }
99 | LAYER '+'
100 { $$ = $1; }
101 ;
102
103 mask:
104 /* empty */
105 { $$ = 0; }
106 | NUMBER
107 { $$ = $1; }
108 ;
109