1 // $Id$
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 //
22 // Copyright (c) 1994 by the University of Southern California
23 // All rights reserved.
24 //
25 // Permission is hereby granted, free of charge, to any person obtaining a copy
26 // of this software and associated documentation files (the "Software"), to deal
27 // in the Software without restriction, including without limitation the rights
28 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 // copies of the Software, and to permit persons to whom the Software is
30 // furnished to do so, subject to the following conditions:
31 //
32 // The above copyright notice and this permission notice shall be included in
33 // all copies or substantial portions of the Software.
34 //
35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41 // THE SOFTWARE.
42 //
43 // Questions concerning this software should be directed to
44 // irrtoolset@cs.usc.edu.
45 //
46 // Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
47
48 #include "config.h"
49 #include <ostream>
50 #include <cstdio>
51 #include "rpsl_filter.hh"
52 #include "rpsl_attr.hh"
53 #include "regexp.hh"
54
55 using namespace std;
56
57 //// printing ////////////////////////////////////////////////////////
58
print(ostream & out) const59 ostream &Filter::print(ostream &out) const {
60 return out;
61 }
62
print(ostream & out) const63 ostream &FilterMS::print(ostream &out) const {
64 out << *f1;
65 switch (code) {
66 case 0:
67 out << "^-";
68 break;
69 case 1:
70 out << "^+";
71 break;
72 case 2:
73 if (n == m)
74 out << "^" << n;
75 else
76 out << "^" << n << "-" << m;
77 }
78 return out;
79 }
80
print(ostream & out) const81 ostream &FilterOR::print(ostream &out) const {
82 out << *f1 << " or " << *f2;
83 return out;
84 }
85
print(ostream & out) const86 ostream &FilterAND::print(ostream &out) const {
87 out << *f1 << " and " << *f2;
88 return out;
89 }
90
print(ostream & out) const91 ostream &FilterEXCEPT::print(ostream &out) const {
92 out << *f1 << " except " << *f2;
93 return out;
94 }
95
print(ostream & out) const96 ostream &FilterNOT::print(ostream &out) const {
97 out << "not " << *f1;
98 return out;
99 }
100
print(ostream & out) const101 ostream &FilterASNO::print(ostream &out) const {
102 out << "AS" << asno;
103 return out;
104 }
105
print(ostream & out) const106 ostream &FilterASNAME::print(ostream &out) const {
107 out << asname;
108 return out;
109 }
110
print(ostream & out) const111 ostream &FilterRSNAME::print(ostream &out) const {
112 out << rsname;
113 return out;
114 }
115
print(ostream & out) const116 ostream &FilterRTRSNAME::print(ostream &out) const {
117 out << rtrsname;
118 return out;
119 }
120
print(ostream & out) const121 ostream &FilterFLTRNAME::print(ostream &out) const {
122 out << fltrname;
123 return out;
124 }
125
print(ostream & out) const126 ostream &FilterANY::print(ostream &out) const {
127 out << "ANY";
128 return out;
129 }
130
print(ostream & out) const131 ostream &FilterPeerAS::print(ostream &out) const {
132 out << "peerAS";
133 return out;
134 }
135
print(ostream & out) const136 ostream &FilterASPath::print(ostream &out) const {
137 out << "<" << *re << ">";
138 return out;
139 }
140
print(ostream & out) const141 ostream &FilterPRFXList::print(ostream &out) const {
142 out << "{";
143 int i = low();
144 if (i < fence()) {
145 out << (*this)[i].get_text();
146 for (++i; i < fence(); ++i)
147 out << ", " << (*this)[i].get_text();
148 }
149 out << "}";
150
151 return out;
152 }
153
print(ostream & out) const154 ostream &FilterMPPRFXList::print(ostream &out) const {
155 MPPrefixRanges::const_iterator p;
156 out << "{";
157
158 p = begin();
159 if (p != end()) {
160 out << *p;
161 ++p;
162 for (; p != end(); ++p) {
163 out << ", ";
164 out << *p ;
165 }
166 }
167
168 out << "}";
169
170 return out;
171 }
172
get_v4()173 FilterPRFXList* FilterMPPRFXList::get_v4() {
174
175 MPPrefixRanges::const_iterator p;
176 FilterPRFXList *list_v4 = new FilterPRFXList;
177
178 for (p = begin(); p != end(); ++p) {
179 if (p->ipv4)
180 list_v4->add_high(*(p->ipv4));
181 }
182 if (list_v4->isEmpty())
183 return NULL;
184 else
185 return list_v4;
186 }
187
188
get_v6()189 FilterMPPRFXList* FilterMPPRFXList::get_v6() {
190 MPPrefixRanges::const_iterator p;
191 FilterMPPRFXList *list_v6 = new FilterMPPRFXList;
192
193 for (p = begin(); p != end(); ++p) {
194 if (p->ipv6)
195 list_v6->push_back(*p);
196 }
197 if (list_v6->begin() == list_v6->end())
198 return NULL;
199 else
200 return list_v6;
201 }
202
print(ostream & out) const203 ostream &FilterV6EXCLUDE::print(ostream &out) const {
204 MPPrefixRanges::const_iterator p;
205 out << "{";
206
207 for (p = prfxs->begin(); p != prfxs->end(); ++p) {
208 out << *p ;
209 out << ',';
210 }
211
212 out << "}";
213
214 return out;
215 }
216
print(ostream & out) const217 ostream &FilterAFI::print(ostream &out) const {
218 //out << (AddressFamily &) *afi_item;
219 for (Item *item = afi_list->head(); item; item = afi_list->next(item))
220 out << (AddressFamily &) ((ItemAFI &) *item);
221
222 out << " ";
223 out << *f;
224
225 return out;
226 }
227
print(ostream & out) const228 ostream &FilterV6HAVE_COMPONENTS::print(ostream &out) const {
229 MPPrefixRanges::const_iterator p;
230 out << "{";
231
232 for (p = prfxs->begin(); p != prfxs->end(); ++p) {
233 out << *p ;
234 out << ',';
235 }
236
237 out << "}";
238
239 return out;
240 }
241
print(ostream & out) const242 ostream &FilterRPAttribute::print(ostream &out) const {
243 out << rp_attr->name;
244 if (rp_method->isOperator)
245 out << " " << (rp_method->name + 8) << " " << *args;
246 else
247 out << "." << rp_method->name << "(" << *args << ")";
248
249 return out;
250 }
251
print(ostream & out) const252 ostream &FilterHAVE_COMPONENTS::print(ostream &out) const {
253 out << "HAVE-COMPONENTS " << *prfxs;
254 return out;
255 }
256
print(ostream & out) const257 ostream &FilterEXCLUDE::print(ostream &out) const {
258 out << "EXCLUDE " << *prfxs;
259 return out;
260 }
261
print(ostream & out) const262 ostream &FilterRouter::print(ostream &out) const {
263
264 out << ip->get_ip_text();
265
266 return out;
267 }
268
print(ostream & out) const269 ostream &FilterRouterName::print(ostream &out) const {
270 out << name;
271 return out;
272 }
273
274