/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following functions.
- yyparse
- injecterror
1 %{
2 /*
3 filename: inject.y
4
5 description:
6 Defines the grammar for an RPSL inject attribute. It was mostly
7 stolen from the IRRToolSet, simplified by removing ability to parse
8 things defined by a dictionary (we use XML for extensibility rather
9 than a dictionary).
10
11 notes:
12 Defines tokens for the associated lexer, inject.l.
13 */
14 %}
15
16 %union {
17 char *sval;
18 }
19
20 %token OP_OR OP_EQUAL OP_APPEND OP_COMPARE OP_AND
21 %token TKN_ASNO
22 %token TKN_IPV4
23 %token KEYW_ACTION
24 %token TKN_PREF TKN_MED TKN_DPA TKN_ASPATH TKN_COMMUNITY TKN_NEXT_HOP TKN_COST
25 %token TKN_COMM_NO TKN_RTRSNAME TKN_PRFXV4 TKN_PRFXV4RNG
26 %token KEYW_IGP_COST KEYW_SELF KEYW_PREPEND
27 %token KEYW_APPEND KEYW_DELETE KEYW_CONTAINS KEYW_AT KEYW_EXCEPT KEYW_UPON
28 %token KEYW_STATIC KEYW_HAVE_COMPONENTS KEYW_EXCLUDE
29 %token KEYW_INTERNET KEYW_NO_EXPORT KEYW_NO_ADVERTISE KEYW_MASKLEN
30 %token <sval> TKN_INT TKN_DNS
31 %type <sval> domain_name
32
33 %{
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <stdlib.h>
37
38 int yyerror(const char *s);
39 void syntax_error(char *fmt, ...);
40
41 %}
42
43 %%
/* [<][>][^][v][top][bottom][index][help] */
44
45 inject: opt_router_expr_with_at opt_action opt_inject_expr
46 ;
47
48 opt_router_expr_with_at:
49 | KEYW_AT router_expr
50 ;
51
52 router_expr: router_expr OP_OR router_expr_term
53 | router_expr_term
54 ;
55
56 router_expr_term: router_expr_term OP_AND router_expr_factor
57 | router_expr_term KEYW_EXCEPT router_expr_factor
58 | router_expr_factor
59 ;
60
61 router_expr_factor: '(' router_expr ')'
62 | router_expr_operand
63 ;
64
65 router_expr_operand: TKN_IPV4
66 | domain_name {
67 if (strlen($1) > 255) {
68 syntax_error("Domain name \"%s\" is longer than 255 characters", $1);
69 }
70 }
71 | TKN_RTRSNAME
72 ;
73
74 domain_name: TKN_DNS
75 | domain_name '.' TKN_DNS
76 ;
77
78 opt_action:
79 | KEYW_ACTION action
80 ;
81
82 opt_inject_expr:
83 | KEYW_UPON inject_expr
84 ;
85
86 inject_expr: inject_expr OP_OR inject_expr_term
87 | inject_expr_term
88 ;
89
90 inject_expr_term: inject_expr_term OP_AND inject_expr_factor
91 | inject_expr_factor
92 ;
93
94 inject_expr_factor: '(' inject_expr ')'
95 | inject_expr_operand
96 ;
97
98 inject_expr_operand: KEYW_STATIC
99 | KEYW_HAVE_COMPONENTS '{' opt_filter_prefix_list '}'
100 | KEYW_EXCLUDE '{' opt_filter_prefix_list '}'
101 ;
102
103 opt_filter_prefix_list:
104 | filter_prefix_list
105 ;
106
107 filter_prefix_list: filter_prefix_list_prefix
108 | filter_prefix_list ',' filter_prefix_list_prefix
109 ;
110
111 filter_prefix_list_prefix: TKN_PRFXV4
112 | TKN_PRFXV4RNG
113 ;
114
115 action: rp_attribute ';'
116 | action rp_attribute ';'
117 ;
118
119 rp_attribute: pref
120 | med
121 | dpa
122 | aspath
123 | community
124 | next_hop
125 | cost
126 ;
127
128 pref: TKN_PREF OP_EQUAL TKN_INT {
129 long int val;
130 char *s, *p;
131 p = $3;
132 val = strtol(p, &s, 10);
133 if ((val < 0) || (val > 65535)) {
134 syntax_error("pref value \"%s\" is not between 0 and 65535", p);
135 }
136 }
137 ;
138
139 med: TKN_MED OP_EQUAL TKN_INT {
140 long int val;
141 char *s, *p;
142 p = $3;
143 val = strtol(p, &s, 10);
144 if ((val < 0) || (val > 65535)) {
145 syntax_error("med value \"%s\" is not between 0 and 65535", p);
146 }
147 }
148 | TKN_MED OP_EQUAL KEYW_IGP_COST
149 ;
150
151 dpa: TKN_DPA OP_EQUAL TKN_INT {
152 long int val;
153 char *s, *p;
154 p = $3;
155 val = strtol(p, &s, 10);
156 if ((val < 0) || (val > 65535)) {
157 syntax_error("dpa value \"%s\" is not between 0 and 65535", p);
158 }
159 }
160 ;
161
162 aspath: TKN_ASPATH '.' KEYW_PREPEND '(' asno_list ')'
163 ;
164
165 asno_list: TKN_ASNO
166 | asno_list ',' TKN_ASNO
167 ;
168
169 community: TKN_COMMUNITY OP_EQUAL community_list
170 | TKN_COMMUNITY OP_APPEND community_list
171 | TKN_COMMUNITY '.' KEYW_APPEND '(' community_elm_list ')'
172 | TKN_COMMUNITY '.' KEYW_DELETE '(' community_elm_list ')'
173 | TKN_COMMUNITY '.' KEYW_CONTAINS '(' community_elm_list ')'
174 | TKN_COMMUNITY '(' community_elm_list ')'
175 | TKN_COMMUNITY OP_COMPARE community_list
176 ;
177
178 community_list: '{' community_elm_list '}'
179 ;
180
181 community_elm_list: community_elm
182 | community_elm_list ',' community_elm
183 ;
184
185 community_elm: KEYW_INTERNET
186 | KEYW_NO_EXPORT
187 | KEYW_NO_ADVERTISE
188 | TKN_INT {
189 unsigned long int val;
190 char *s, *p;
191 p = $1;
192 val = strtoul(p, &s, 10);
193 if ((val < 1) || (val > 4294967295UL) || (*s != '\0')) {
194 syntax_error("community element \"%s\" is not between 1 and 4294967295",
195 p);
196 }
197 }
198 | TKN_COMM_NO
199 ;
200
201 next_hop: TKN_NEXT_HOP OP_EQUAL TKN_IPV4
202 | TKN_NEXT_HOP OP_EQUAL KEYW_SELF
203 ;
204
205 cost: TKN_COST OP_EQUAL TKN_INT {
206 long int val;
207 char *s, *p;
208 p = $3;
209 val = strtol(p, &s, 10);
210 if ((val < 0) || (val > 65535)) {
211 syntax_error("cost value \"%s\" is not between 0 and 65535", p);
212 }
213 }
214 ;
215
216 %%
217
218 #undef injecterror
219 #undef yyerror
220
221 int
222 injecterror (const char *s)
/* [<][>][^][v][top][bottom][index][help] */
223 {
224 yyerror(s);
225 return 0;
226 }
227