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