1 %{
2 // Copyright (c) 2001,2002                        RIPE NCC
3 //
4 // All Rights Reserved
5 //
6 // Permission to use, copy, modify, and distribute this software and its
7 // documentation for any purpose and without fee is hereby granted,
8 // provided that the above copyright notice appear in all copies and that
9 // both that copyright notice and this permission notice appear in
10 // supporting documentation, and that the name of the author not be
11 // used in advertising or publicity pertaining to distribution of the
12 // software without specific, written prior permission.
13 //
14 // THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
16 // AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
17 // DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
18 // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 //
21 //  $Id$
22 //
23 //  Copyright (c) 1994 by the University of Southern California
24 //  All rights reserved.
25 //
26 //    Permission is hereby granted, free of charge, to any person obtaining a copy
27 //    of this software and associated documentation files (the "Software"), to deal
28 //    in the Software without restriction, including without limitation the rights
29 //    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 //    copies of the Software, and to permit persons to whom the Software is
31 //    furnished to do so, subject to the following conditions:
32 //
33 //    The above copyright notice and this permission notice shall be included in
34 //    all copies or substantial portions of the Software.
35 //
36 //    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 //    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 //    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 //    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 //    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 //    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
42 //    THE SOFTWARE.
43 //
44 //  Questions concerning this software should be directed to
45 //  irrtoolset@cs.usc.edu.
46 //
47 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
48 
49 #include "config.h"
50 
51 #include <ostream>
52 #include <cstring>
53 #include <cstdlib>
54 #include <cctype>
55 #include <cstdarg>
56 #include "rtconfig.hh"
57 #include "f_cisco.hh"
58 #include "f_ciscoxr.hh"
59 #include "f_junos.hh"
60 #include "irr/irr.hh"
61 #include "irrutil/trace.hh"
62 #include "rpsl/rpsl.hh"
63 
64 extern "C" {
65 // FIXME
66 #if HAVE_MEMORY_H && 0
67 #   include <memory.h>
68 #endif
69 #ifndef HAVE_MEMCPY
70 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
71 #endif
72 }
73 
74 #define yylineno commandlineno
75 
76 extern int yyerror(const char *);
77 extern int yylex();
78 extern int yylineno;
79 
80 int xx_eof = 0;
81 
82 %}
83 
84 %union {
85    int i;
86    char *val;
87    /*IPAddr *ip;*/
88    MPPrefix *ip;
89    ASt as;
90 }
91 
92 %name-prefix "command"
93 %output "command.y.cc"
94 
95 %token <ip>  TKN_IP
96 %token <as>  TKN_ASNUM
97 %token <val> TKN_ERROR
98 %token <val> TKN_STR
99 %token <i>   TKN_INT
100 %token <val> TKN_DNSNAME
101 %token <val> TKN_FILTER
102 %token <val> TKN_WORD
103 
104 %token <val> KW_IMPORT
105 %token <val> KW_IMPORT_PEERGROUP
106 %token <val> KW_EXPORT
107 %token <val> KW_EXPORT_GROUP
108 %token <val> KW_IMPORT_GROUP
109 %token <val> KW_PRINT_PREFIXES
110 %token <val> KW_PRINT_PREFIX_RANGES
111 %token <val> KW_PRINT_SUPER_PREFIX_RANGES
112 %token <val> KW_ASPATH_ACCESS_LIST
113 %token <val> KW_ACCESS_LIST
114 %token <val> KW_CONFIGURE_ROUTER
115 %token <val> KW_STATIC2BGP
116 %token <val> KW_SET
117 %token <val> KW_CISCO_MAP_NAME
118 %token <val> KW_JUNOS_POLICY_NAME
119 %token <val> KW_CISCO_PREFIX_ACL_NO
120 %token <val> KW_CISCO_ASPATH_ACL_NO
121 %token <val> KW_CISCO_PKTFILTER_ACL_NO
122 %token <val> KW_CISCO_COMMUNITY_ACL_NO
123 %token <val> KW_COMMUNITY_SET_NO
124 %token <val> KW_CISCO_ACCESS_LIST_NO
125 %token <val> KW_SOURCE
126 %token <val> KW_PREFERENCECEILING
127 %token <val> KW_CISCO_MAX_PREFERENCE
128 %token <val> KW_NETWORKS
129 %token <val> KW_V6NETWORKS
130 %token <val> KW_DEFAULT
131 %token <val> KW_CISCO_MAP_INC
132 %token <val> KW_CISCO_MAP_START
133 %token <val> KW_INBOUND_PKT_FILTER
134 %token <val> KW_OUTBOUND_PKT_FILTER
135 
136 %%
137 input_stream: {
138 #if !(HAVE_LIBREADLINE && HAVE_LIBHISTORY)
139    if (opt_prompt)
140       std::cout << opt_prompt;
141 #endif // HAVE_LIBREADLINE && HAVE_LIBHISTORY
142 }
143 | input_stream input {
144 #if !(HAVE_LIBREADLINE && HAVE_LIBHISTORY)
145    if (opt_prompt)
146       std::cout << opt_prompt;
147 #endif // !(HAVE_LIBREADLINE && HAVE_LIBHISTORY)
148 }
149 ;
150 
151 input: input_line '\n'
152 | error '\n' {
153   yyerrok;
154 }
155 | '\n'
156 ;
157 
158 input_line: import_line
159 | importpg_line
160 | export_line
161 | export_group_line
162 | import_group_line
163 | print_prefixes_line
164 | print_prefix_ranges_line
165 | print_super_prefix_ranges_line
166 | access_list_line
167 | aspath_access_list_line
168 | default_line
169 | configure_router_line
170 | static2bgp_line
171 | networks_line
172 | v6networks_line
173 | inbound_pkt_filter_line
174 | outbound_pkt_filter_line
175 | cisco_map_name_line
176 | junos_policy_name_line
177 | cisco_map_inc_line
178 | cisco_map_start_line
179 | cisco_access_list_no_line
180 | preferenceCeiling_line
181 | source_line
182 ;
183 
184 import_line: KW_IMPORT TKN_ASNUM TKN_IP TKN_ASNUM TKN_IP {
185    /*
186    cout << "!" << endl
187         << "!LINE " << yylineno << " -- import" << endl
188         << "!" << endl;
189    */
190    rtConfig->importP($2, $3, $4, $5);
191    delete $3;
192    delete $5;
193 }
194 ;
195 
196 importpg_line: KW_IMPORT_PEERGROUP TKN_ASNUM TKN_IP TKN_ASNUM TKN_IP TKN_WORD {
197    /*
198    cout << "!" << endl
199         << "!LINE " << yylineno << " -- import" << endl
200         << "!" << endl;
201    */
202    rtConfig->importPeerGroup($2, $3, $4, $5, $6);
203    delete $3;
204    delete $5;
205 }
206 ;
207 
208 export_line: KW_EXPORT TKN_ASNUM TKN_IP TKN_ASNUM TKN_IP {
209    /*
210    cout << "!" << endl
211         << "!LINE " << yylineno << " -- export" << endl
212         << "!" << endl;
213    */
214    rtConfig->exportP($2, $3, $4, $5);
215    delete $3;
216    delete $5;
217 }
218 ;
219 
220 export_group_line: KW_EXPORT_GROUP TKN_ASNUM TKN_WORD {
221    /*
222    cout << "!" << endl
223         << "!LINE " << yylineno << " -- export" << endl
224         << "!" << endl;
225    */
226    rtConfig->exportGroup($2, $3);
227 }
228 ;
229 
230 import_group_line: KW_IMPORT_GROUP TKN_ASNUM TKN_WORD {
231    /*
232    cout << "!" << endl
233         << "!LINE " << yylineno << " -- export" << endl
234         << "!" << endl;
235    */
236    rtConfig->importGroup($2, $3);
237 }
238 ;
239 
240 print_prefixes_line: KW_PRINT_PREFIXES TKN_STR TKN_FILTER {
241    char *p = $2;
242    while ((p = strchr(p, '\\'))) {
243       if (*(p+1) == 'n') {
244 	 *p = '%';
245 	 *(p+1) = '\n';
246       }
247       if (*(p+1) == 't') {
248 	 *p = '%';
249 	 *(p+1) = '\t';
250       }
251    }
252    rtConfig->printPrefixes($3, $2);
253 };
254 
255 print_prefix_ranges_line: KW_PRINT_PREFIX_RANGES TKN_STR TKN_FILTER {
256    char *p = $2;
257    while ((p = strchr(p, '\\'))) {
258       if (*(p+1) == 'n') {
259 	 *p = '%';
260 	 *(p+1) = '\n';
261       }
262       if (*(p+1) == 't') {
263 	 *p = '%';
264 	 *(p+1) = '\t';
265       }
266    }
267    rtConfig->printPrefixRanges($3, $2);
268 };
269 
270 print_super_prefix_ranges_line: KW_PRINT_SUPER_PREFIX_RANGES TKN_STR TKN_FILTER {
271    char *p = $2;
272    while ((p = strchr(p, '\\'))) {
273       if (*(p+1) == 'n') {
274 	 *p = '%';
275 	 *(p+1) = '\n';
276       }
277       if (*(p+1) == 't') {
278 	 *p = '%';
279 	 *(p+1) = '\t';
280       }
281    }
282    rtConfig->printSuperPrefixRanges($3, $2);
283 };
284 
285 access_list_line: KW_ACCESS_LIST TKN_FILTER {
286    rtConfig->accessList($2);
287 };
288 
289 aspath_access_list_line: KW_ASPATH_ACCESS_LIST TKN_FILTER {
290    rtConfig->aspathAccessList($2);
291 };
292 
293 default_line: KW_DEFAULT TKN_ASNUM TKN_ASNUM {
294    rtConfig->deflt($2, $3);
295 }
296 ;
297 
298 configure_router_line: KW_CONFIGURE_ROUTER TKN_DNSNAME {
299    rtConfig->configureRouter($2);
300    free($2);
301 }
302 ;
303 
304 static2bgp_line: KW_STATIC2BGP TKN_ASNUM TKN_IP {
305    rtConfig->static2bgp($2, $3);
306    delete $3;
307 }
308 ;
309 
310 networks_line: KW_NETWORKS TKN_ASNUM {
311    rtConfig->networks($2);
312 }
313 ;
314 
315 v6networks_line: KW_V6NETWORKS TKN_ASNUM {
316    rtConfig->IPv6networks($2);
317 }
318 ;
319 
320 inbound_pkt_filter_line: KW_INBOUND_PKT_FILTER TKN_STR TKN_ASNUM TKN_IP TKN_ASNUM TKN_IP {
321    rtConfig->inboundPacketFilter($2, $3, $4, $5, $6);
322    delete $4;
323    delete $6;
324 }
325 ;
326 
327 outbound_pkt_filter_line: KW_OUTBOUND_PKT_FILTER TKN_STR TKN_ASNUM TKN_IP TKN_ASNUM TKN_IP {
328    rtConfig->outboundPacketFilter($2, $3, $4, $5, $6);
329    delete $4;
330    delete $6;
331 }
332 ;
333 
334 cisco_map_name_line: KW_SET KW_CISCO_MAP_NAME '=' TKN_STR {
335    strcpy(CiscoConfig::mapNameFormat, $4);
336    strcpy(CiscoXRConfig::mapNameFormat, $4);
337    Trace(TR_INPUT) << "RtConfig: cisco_map_name '"
338 		   << CiscoConfig::mapNameFormat << "'" << std::endl;
339    Trace(TR_INPUT) << "RtConfig: cisco_map_name '"
340 		   << CiscoXRConfig::mapNameFormat << "'" << std::endl;
341 }
342 ;
343 junos_policy_name_line: KW_SET KW_JUNOS_POLICY_NAME '=' TKN_STR {
344    strcpy(JunosConfig::mapNameFormat, $4);
345    Trace(TR_INPUT) << "RtConfig: junos_policy_name '"
346 		   << JunosConfig::mapNameFormat << "'" << std::endl;
347 }
348 ;
349 cisco_map_inc_line: KW_SET KW_CISCO_MAP_INC '=' TKN_INT {
350    CiscoConfig::mapIncrements = $4;
351    Trace(TR_INPUT) << "RtConfig: cisco_map_increment_by '"
352 		   << CiscoConfig::mapIncrements << "'" << std::endl;
353 }
354 ;
355 
356 cisco_map_start_line: KW_SET KW_CISCO_MAP_START '=' TKN_INT {
357    CiscoConfig::mapNumbersStartAt = $4;
358    Trace(TR_INPUT) << "RtConfig: cisco_map_first_no '"
359 		   << CiscoConfig::mapNumbersStartAt << "'" << std::endl;
360 }
361 ;
362 
363 cisco_access_list_no_line: KW_SET KW_CISCO_PREFIX_ACL_NO '=' TKN_INT {
364    if ($4 > 0)
365       prefixMgr.setNextID($4);
366    Trace(TR_INPUT) << "RtConfig: cisco_prefix_access_list_no '"
367 		   << $4 << "'" << std::endl;
368 }
369 | KW_SET KW_CISCO_ASPATH_ACL_NO '=' TKN_INT {
370    if ($4 > 0)
371       aspathMgr.setNextID($4);
372    Trace(TR_INPUT) << "RtConfig: cisco_aspath_access_list_no '"
373 		   << $4 << "'" << std::endl;
374 }
375 | KW_SET KW_CISCO_PKTFILTER_ACL_NO '=' TKN_INT {
376    if ($4 > 0)
377       pktFilterMgr.setNextID($4);
378    Trace(TR_INPUT) << "RtConfig: cisco_pktfilter_access_list_no '"
379 		   << $4 << "'" << std::endl;
380 }
381 | KW_SET KW_CISCO_COMMUNITY_ACL_NO '=' TKN_INT {
382    if ($4 > 0)
383       communityMgr.setNextID($4);
384    Trace(TR_INPUT) << "RtConfig: cisco_community_access_list_no '"
385 		   << $4 << "'" << std::endl;
386 }
387 | KW_SET KW_CISCO_ACCESS_LIST_NO '=' TKN_INT {
388    if ($4 > 0) {
389       communityMgr.setNextID($4);
390       pktFilterMgr.setNextID($4);
391       aspathMgr.setNextID($4);
392       prefixMgr.setNextID($4);
393       ipv6prefixMgr.setNextID($4);
394       ipv6pktFilterMgr.setNextID($4);
395    }
396    Trace(TR_INPUT) << "RtConfig: cisco_access_list_no '"
397 		   << $4 << "'" << std::endl;
398 }
399 | KW_SET KW_COMMUNITY_SET_NO '=' TKN_INT {
400    if ($4 > 0)
401       communitySetMgr.setNextID($4);
402    Trace(TR_INPUT) << "RtConfig: community_set_no '"
403 		   << $4 << "'" << std::endl;
404 }
405 ;
406 
407 preferenceCeiling_line: KW_SET KW_PREFERENCECEILING '=' TKN_INT {
408    if ($4 >= 0)
409       RtConfig::preferenceCeiling = $4;
410 
411    Trace(TR_INPUT) << "RtConfig: preferenceCeiling '"
412 		   << RtConfig::preferenceCeiling << "'" << std::endl;
413 }
414 ;
415 
416 source_line: KW_SET KW_SOURCE '=' TKN_STR {
417    irr->SetSources($4);
418    Trace(TR_INPUT) << "RtConfig: database order is changed to'"
419 		   << $4 << "'" << std::endl;
420 }
421 ;
422 
423 
424 %%
425 
426 int yyerror(const char *s) {
427      std::cerr << "Error in template file at line " << yylineno
428                << ": " << s
429                << std::endl;
430      return(0);
431 }
432 
433