1 // $Id: f_cisco.hh 319 2010-03-19 22:19:39Z nick $ 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 #ifndef F_CISCOXR_H 49 #define F_CISCOXR_H 50 51 52 #include "f_cisco.hh" 53 #include "config.h" 54 #include "rpsl/List.hh" 55 #include "normalform/FilterOfASPath.hh" 56 #include "irr/irr.hh" 57 #include "irr/autnum.hh" 58 59 #include <sstream> 60 61 class FilterOfCommunity; 62 class RangeList; 63 class regexp; 64 class PolicyAction; 65 class PolicyActionList; 66 class PTree; 67 class ItemList; 68 class NormalExpression; 69 class SetOfPrefix; 70 class SetOfIPv6Prefix; 71 class regexp_nf; 72 73 //class ListNodeOf2Ints : public ListNode { 74 //public: 75 // int start; 76 // int end; 77 // int flag; // flag is used for exact community matching 78 // 79 // ListNodeOf2Ints() {} 80 // ListNodeOf2Ints(int s, int e, int f) : start(s), end(e), flag(f) {} 81 // ListNodeOf2Ints(const ListNodeOf2Ints& b) : 82 // start(b.start), end(b.end), flag(b.flag) {} 83 //}; 84 // 85 //class ListOf2Ints : public List<ListNodeOf2Ints> { 86 //public: 87 // ListOf2Ints(int flag) : List<ListNodeOf2Ints>() { 88 // // create a list whose end is less than its start 89 // // so it wont print anything! 90 // add(2,1); 91 // } 92 // ListOf2Ints() : List<ListNodeOf2Ints>() {} 93 // void add(int s, int e, int flag = 0) { 94 // append((new ListNodeOf2Ints(s, e, flag))); 95 // } 96 //}; 97 98 class CiscoXRConfig : public RtConfig { 99 public: CiscoXRConfig()100 CiscoXRConfig() : RtConfig() { 101 lastMapName[0] = 0; 102 routeMapGenerated = false; 103 prefixListGenerated = false; 104 distributeListNo = -1; 105 routeMapID = 1; 106 } 107 // REIMPLEMENTED 108 void importP(ASt as, MPPrefix* addr, ASt peerAS, MPPrefix* peerAddr); 109 void exportP(ASt as, MPPrefix* addr, ASt peerAS, MPPrefix* peerAddr); 110 void exportGroup(ASt as, char *pset); 111 void importGroup(ASt as, char *pset); 112 void deflt(ASt as, ASt peerAS); 113 void static2bgp(ASt as, MPPrefix* addr); 114 void networks(ASt as); 115 void IPv6networks(ASt as); 116 void inboundPacketFilter(char *ifname, ASt as, MPPrefix* addr, ASt peerAS, MPPrefix* peerAddr); 117 void outboundPacketFilter(char *ifname, ASt as, MPPrefix* addr, ASt peerAS, MPPrefix* peerAddr); 118 119 public: 120 // options 121 static char mapName[80]; 122 static char mapNameFormat[80]; 123 static bool forcedInboundMatchIP; 124 static bool useAclCaches; 125 static bool printRouteMap; 126 static bool compressAcls; 127 static bool usePrefixLists; 128 static bool eliminateDupMapParts; 129 static bool forceTilda; 130 static bool emptyLists; 131 static int mapIncrements; 132 static int mapNumbersStartAt; 133 static int mapCount; 134 135 private: 136 char lastMapName[80]; 137 bool routeMapGenerated; 138 bool prefixListGenerated; 139 int distributeListNo; 140 int routeMapID; 141 bool reSplittable; 142 bool hasTilda; 143 bool inTilda; 144 145 private: 146 static bool firstCommunityList; 147 const char *returnPermitOrDeny(bool); 148 ListOf2Ints *printRoutes(SetOfPrefix& nets); 149 ListOf2Ints *printRoutes(SetOfIPv6Prefix& nets); 150 ListOf2Ints *printPrefixList(SetOfPrefix& nets); 151 ListOf2Ints *printPrefixList(SetOfIPv6Prefix& nets); 152 ListOf2Ints *printCommunities(FilterOfCommunity& cm); 153 ListOf2Ints *printASPaths(regexp_nf& path); 154 void printREASno(std::ostream& out, const RangeList &no); 155 int printRE_(std::ostream& os, const regexp& r); 156 void printRE(std::ostream& os, const regexp& r, int aclID, bool permit); 157 158 int printPacketFilter(SetOfPrefix &set); 159 int printPacketFilter(SetOfIPv6Prefix &set); 160 inline void printCommunity(std::ostream &os, unsigned int i); 161 void printCommunityList(std::ostream &os, ItemList *args); 162 int printCommunitySetList(std::ostream &os, ItemList *args); 163 void printActions(std::ostream &os, PolicyActionList *action, ItemAFI *afi); 164 int print(NormalExpression *ne, PolicyActionList *actn, int import_flag, ItemAFI *afi); 165 bool printNeighbor(int import, ASt asno, ASt peerAS, char *neighbor, bool peerGroup, ItemAFI *peer_afi, ItemAFI *filter_afi); printAccessList(SetOfPrefix & nets)166 void printAccessList(SetOfPrefix& nets) { 167 bool save = useAclCaches; 168 useAclCaches = false; 169 printRoutes(nets); 170 useAclCaches = save; 171 } printAccessList(SetOfIPv6Prefix & nets)172 void printAccessList(SetOfIPv6Prefix& nets) { 173 bool save = useAclCaches; 174 useAclCaches = false; 175 printRoutes(nets); 176 useAclCaches = save; 177 } printAspathAccessList(FilterOfASPath & path)178 void printAspathAccessList(FilterOfASPath& path) { 179 bool save = useAclCaches; 180 useAclCaches = false; 181 printASPaths(path); 182 useAclCaches = save; 183 } 184 }; 185 186 //template <class T> 187 //class AccessListManager { 188 //private : 189 // class Node : public ListNode { 190 // public: 191 // Node() : data(), lof2i() {} 192 // Node(const Node &b) : data(b.data), lof2i(b.lof2i) {} 193 // Node(T& _data) : data(_data), lof2i() {} 194 // 195 // public: 196 // T data; 197 // ListOf2Ints lof2i; 198 // }; 199 // 200 // List<Node> cache; 201 // int next_id; 202 // 203 //public: 204 // AccessListManager() : cache(), next_id(1) { 205 // } 206 // 207 // AccessListManager(int firstID) : cache(), next_id(firstID) { 208 // } 209 // 210 // ListOf2Ints* search(T& _data) { 211 // for (Node *p = cache.head(); p; p = cache.next(p)) 212 // if (p->data == _data) 213 // return &(p->lof2i); 214 // return NULL; 215 // } 216 // 217 // ListOf2Ints* add(T& _data) { 218 // Node *p = new Node(_data); 219 // cache.append(p); 220 // return &(p->lof2i); 221 // } 222 // 223 // void setNextID(int id) { 224 // next_id = id; 225 // } 226 // 227 // int newID() { 228 // return next_id++; 229 // } 230 // int lastID() { 231 // return next_id - 1; 232 // } 233 //}; 234 235 extern AccessListManager<regexp_nf> aspathMgr; 236 extern AccessListManager<SetOfPrefix> prefixMgr; 237 extern AccessListManager<SetOfIPv6Prefix> ipv6prefixMgr; 238 extern AccessListManager<SetOfPrefix> pktFilterMgr; 239 extern AccessListManager<SetOfIPv6Prefix> ipv6pktFilterMgr; 240 extern AccessListManager<FilterOfCommunity> communityMgr; 241 242 243 #endif // F_CISCOXR_H 244