bgp_routemap.c 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936
  1. /* Route map function of bgpd.
  2. Copyright (C) 1998, 1999 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #include <zebra.h>
  17. #include "prefix.h"
  18. #include "filter.h"
  19. #include "routemap.h"
  20. #include "command.h"
  21. #include "linklist.h"
  22. #include "plist.h"
  23. #include "memory.h"
  24. #include "log.h"
  25. #ifdef HAVE_LIBPCREPOSIX
  26. # include <pcreposix.h>
  27. #else
  28. # ifdef HAVE_GNU_REGEX
  29. # include <regex.h>
  30. # else
  31. # include "regex-gnu.h"
  32. # endif /* HAVE_GNU_REGEX */
  33. #endif /* HAVE_LIBPCREPOSIX */
  34. #include "buffer.h"
  35. #include "sockunion.h"
  36. #include "bgpd/bgpd.h"
  37. #include "bgpd/bgp_table.h"
  38. #include "bgpd/bgp_attr.h"
  39. #include "bgpd/bgp_aspath.h"
  40. #include "bgpd/bgp_route.h"
  41. #include "bgpd/bgp_regex.h"
  42. #include "bgpd/bgp_community.h"
  43. #include "bgpd/bgp_clist.h"
  44. #include "bgpd/bgp_filter.h"
  45. #include "bgpd/bgp_mplsvpn.h"
  46. #include "bgpd/bgp_ecommunity.h"
  47. #include "bgpd/bgp_vty.h"
  48. /* Memo of route-map commands.
  49. o Cisco route-map
  50. match as-path : Done
  51. community : Done
  52. interface : Not yet
  53. ip address : Done
  54. ip next-hop : Done
  55. ip route-source : Done
  56. ip prefix-list : Done
  57. ipv6 address : Done
  58. ipv6 next-hop : Done
  59. ipv6 route-source: (This will not be implemented by bgpd)
  60. ipv6 prefix-list : Done
  61. length : (This will not be implemented by bgpd)
  62. metric : Done
  63. route-type : (This will not be implemented by bgpd)
  64. tag : (This will not be implemented by bgpd)
  65. set as-path prepend : Done
  66. as-path tag : Not yet
  67. automatic-tag : (This will not be implemented by bgpd)
  68. community : Done
  69. comm-list : Not yet
  70. dampning : Not yet
  71. default : (This will not be implemented by bgpd)
  72. interface : (This will not be implemented by bgpd)
  73. ip default : (This will not be implemented by bgpd)
  74. ip next-hop : Done
  75. ip precedence : (This will not be implemented by bgpd)
  76. ip tos : (This will not be implemented by bgpd)
  77. level : (This will not be implemented by bgpd)
  78. local-preference : Done
  79. metric : Done
  80. metric-type : Not yet
  81. origin : Done
  82. tag : (This will not be implemented by bgpd)
  83. weight : Done
  84. o Local extensions
  85. set ipv6 next-hop global: Done
  86. set ipv6 next-hop local : Done
  87. set as-path exclude : Done
  88. */
  89. /* generic as path object to be shared in multiple rules */
  90. static void *
  91. route_aspath_compile (const char *arg)
  92. {
  93. struct aspath *aspath;
  94. aspath = aspath_str2aspath (arg);
  95. if (! aspath)
  96. return NULL;
  97. return aspath;
  98. }
  99. static void
  100. route_aspath_free (void *rule)
  101. {
  102. struct aspath *aspath = rule;
  103. aspath_free (aspath);
  104. }
  105. /* 'match peer (A.B.C.D|X:X::X:X)' */
  106. /* Compares the peer specified in the 'match peer' clause with the peer
  107. received in bgp_info->peer. If it is the same, or if the peer structure
  108. received is a peer_group containing it, returns RMAP_MATCH. */
  109. static route_map_result_t
  110. route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
  111. void *object)
  112. {
  113. union sockunion *su;
  114. union sockunion su_def = { .sa.sa_family = AF_INET,
  115. .sin.sin_addr.s_addr = INADDR_ANY };
  116. struct peer_group *group;
  117. struct peer *peer;
  118. struct listnode *node, *nnode;
  119. if (type == RMAP_BGP)
  120. {
  121. su = rule;
  122. peer = ((struct bgp_info *) object)->peer;
  123. if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
  124. ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
  125. return RMAP_NOMATCH;
  126. /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
  127. REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
  128. if (sockunion_same (su, &su_def))
  129. {
  130. int ret;
  131. if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
  132. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
  133. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
  134. ret = RMAP_MATCH;
  135. else
  136. ret = RMAP_NOMATCH;
  137. return ret;
  138. }
  139. if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
  140. {
  141. if (sockunion_same (su, &peer->su))
  142. return RMAP_MATCH;
  143. return RMAP_NOMATCH;
  144. }
  145. else
  146. {
  147. group = peer->group;
  148. for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
  149. {
  150. if (sockunion_same (su, &peer->su))
  151. return RMAP_MATCH;
  152. }
  153. return RMAP_NOMATCH;
  154. }
  155. }
  156. return RMAP_NOMATCH;
  157. }
  158. static void *
  159. route_match_peer_compile (const char *arg)
  160. {
  161. union sockunion *su;
  162. int ret;
  163. su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
  164. ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su);
  165. if (ret < 0) {
  166. XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
  167. return NULL;
  168. }
  169. return su;
  170. }
  171. /* Free route map's compiled `ip address' value. */
  172. static void
  173. route_match_peer_free (void *rule)
  174. {
  175. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  176. }
  177. /* Route map commands for ip address matching. */
  178. struct route_map_rule_cmd route_match_peer_cmd =
  179. {
  180. "peer",
  181. route_match_peer,
  182. route_match_peer_compile,
  183. route_match_peer_free
  184. };
  185. /* `match ip address IP_ACCESS_LIST' */
  186. /* Match function should return 1 if match is success else return
  187. zero. */
  188. static route_map_result_t
  189. route_match_ip_address (void *rule, struct prefix *prefix,
  190. route_map_object_t type, void *object)
  191. {
  192. struct access_list *alist;
  193. /* struct prefix_ipv4 match; */
  194. if (type == RMAP_BGP)
  195. {
  196. alist = access_list_lookup (AFI_IP, (char *) rule);
  197. if (alist == NULL)
  198. return RMAP_NOMATCH;
  199. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  200. RMAP_NOMATCH : RMAP_MATCH);
  201. }
  202. return RMAP_NOMATCH;
  203. }
  204. /* Route map `ip address' match statement. `arg' should be
  205. access-list name. */
  206. static void *
  207. route_match_ip_address_compile (const char *arg)
  208. {
  209. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  210. }
  211. /* Free route map's compiled `ip address' value. */
  212. static void
  213. route_match_ip_address_free (void *rule)
  214. {
  215. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  216. }
  217. /* Route map commands for ip address matching. */
  218. struct route_map_rule_cmd route_match_ip_address_cmd =
  219. {
  220. "ip address",
  221. route_match_ip_address,
  222. route_match_ip_address_compile,
  223. route_match_ip_address_free
  224. };
  225. /* `match ip next-hop IP_ADDRESS' */
  226. /* Match function return 1 if match is success else return zero. */
  227. static route_map_result_t
  228. route_match_ip_next_hop (void *rule, struct prefix *prefix,
  229. route_map_object_t type, void *object)
  230. {
  231. struct access_list *alist;
  232. struct bgp_info *bgp_info;
  233. struct prefix_ipv4 p;
  234. if (type == RMAP_BGP)
  235. {
  236. bgp_info = object;
  237. p.family = AF_INET;
  238. p.prefix = bgp_info->attr->nexthop;
  239. p.prefixlen = IPV4_MAX_BITLEN;
  240. alist = access_list_lookup (AFI_IP, (char *) rule);
  241. if (alist == NULL)
  242. return RMAP_NOMATCH;
  243. return (access_list_apply (alist, &p) == FILTER_DENY ?
  244. RMAP_NOMATCH : RMAP_MATCH);
  245. }
  246. return RMAP_NOMATCH;
  247. }
  248. /* Route map `ip next-hop' match statement. `arg' is
  249. access-list name. */
  250. static void *
  251. route_match_ip_next_hop_compile (const char *arg)
  252. {
  253. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  254. }
  255. /* Free route map's compiled `ip address' value. */
  256. static void
  257. route_match_ip_next_hop_free (void *rule)
  258. {
  259. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  260. }
  261. /* Route map commands for ip next-hop matching. */
  262. struct route_map_rule_cmd route_match_ip_next_hop_cmd =
  263. {
  264. "ip next-hop",
  265. route_match_ip_next_hop,
  266. route_match_ip_next_hop_compile,
  267. route_match_ip_next_hop_free
  268. };
  269. /* `match ip route-source ACCESS-LIST' */
  270. /* Match function return 1 if match is success else return zero. */
  271. static route_map_result_t
  272. route_match_ip_route_source (void *rule, struct prefix *prefix,
  273. route_map_object_t type, void *object)
  274. {
  275. struct access_list *alist;
  276. struct bgp_info *bgp_info;
  277. struct peer *peer;
  278. struct prefix_ipv4 p;
  279. if (type == RMAP_BGP)
  280. {
  281. bgp_info = object;
  282. peer = bgp_info->peer;
  283. if (! peer || sockunion_family (&peer->su) != AF_INET)
  284. return RMAP_NOMATCH;
  285. p.family = AF_INET;
  286. p.prefix = peer->su.sin.sin_addr;
  287. p.prefixlen = IPV4_MAX_BITLEN;
  288. alist = access_list_lookup (AFI_IP, (char *) rule);
  289. if (alist == NULL)
  290. return RMAP_NOMATCH;
  291. return (access_list_apply (alist, &p) == FILTER_DENY ?
  292. RMAP_NOMATCH : RMAP_MATCH);
  293. }
  294. return RMAP_NOMATCH;
  295. }
  296. /* Route map `ip route-source' match statement. `arg' is
  297. access-list name. */
  298. static void *
  299. route_match_ip_route_source_compile (const char *arg)
  300. {
  301. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  302. }
  303. /* Free route map's compiled `ip address' value. */
  304. static void
  305. route_match_ip_route_source_free (void *rule)
  306. {
  307. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  308. }
  309. /* Route map commands for ip route-source matching. */
  310. struct route_map_rule_cmd route_match_ip_route_source_cmd =
  311. {
  312. "ip route-source",
  313. route_match_ip_route_source,
  314. route_match_ip_route_source_compile,
  315. route_match_ip_route_source_free
  316. };
  317. /* `match ip address prefix-list PREFIX_LIST' */
  318. static route_map_result_t
  319. route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
  320. route_map_object_t type, void *object)
  321. {
  322. struct prefix_list *plist;
  323. if (type == RMAP_BGP)
  324. {
  325. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  326. if (plist == NULL)
  327. return RMAP_NOMATCH;
  328. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  329. RMAP_NOMATCH : RMAP_MATCH);
  330. }
  331. return RMAP_NOMATCH;
  332. }
  333. static void *
  334. route_match_ip_address_prefix_list_compile (const char *arg)
  335. {
  336. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  337. }
  338. static void
  339. route_match_ip_address_prefix_list_free (void *rule)
  340. {
  341. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  342. }
  343. struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
  344. {
  345. "ip address prefix-list",
  346. route_match_ip_address_prefix_list,
  347. route_match_ip_address_prefix_list_compile,
  348. route_match_ip_address_prefix_list_free
  349. };
  350. /* `match ip next-hop prefix-list PREFIX_LIST' */
  351. static route_map_result_t
  352. route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
  353. route_map_object_t type, void *object)
  354. {
  355. struct prefix_list *plist;
  356. struct bgp_info *bgp_info;
  357. struct prefix_ipv4 p;
  358. if (type == RMAP_BGP)
  359. {
  360. bgp_info = object;
  361. p.family = AF_INET;
  362. p.prefix = bgp_info->attr->nexthop;
  363. p.prefixlen = IPV4_MAX_BITLEN;
  364. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  365. if (plist == NULL)
  366. return RMAP_NOMATCH;
  367. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  368. RMAP_NOMATCH : RMAP_MATCH);
  369. }
  370. return RMAP_NOMATCH;
  371. }
  372. static void *
  373. route_match_ip_next_hop_prefix_list_compile (const char *arg)
  374. {
  375. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  376. }
  377. static void
  378. route_match_ip_next_hop_prefix_list_free (void *rule)
  379. {
  380. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  381. }
  382. struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
  383. {
  384. "ip next-hop prefix-list",
  385. route_match_ip_next_hop_prefix_list,
  386. route_match_ip_next_hop_prefix_list_compile,
  387. route_match_ip_next_hop_prefix_list_free
  388. };
  389. /* `match ip route-source prefix-list PREFIX_LIST' */
  390. static route_map_result_t
  391. route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
  392. route_map_object_t type, void *object)
  393. {
  394. struct prefix_list *plist;
  395. struct bgp_info *bgp_info;
  396. struct peer *peer;
  397. struct prefix_ipv4 p;
  398. if (type == RMAP_BGP)
  399. {
  400. bgp_info = object;
  401. peer = bgp_info->peer;
  402. if (! peer || sockunion_family (&peer->su) != AF_INET)
  403. return RMAP_NOMATCH;
  404. p.family = AF_INET;
  405. p.prefix = peer->su.sin.sin_addr;
  406. p.prefixlen = IPV4_MAX_BITLEN;
  407. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  408. if (plist == NULL)
  409. return RMAP_NOMATCH;
  410. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  411. RMAP_NOMATCH : RMAP_MATCH);
  412. }
  413. return RMAP_NOMATCH;
  414. }
  415. static void *
  416. route_match_ip_route_source_prefix_list_compile (const char *arg)
  417. {
  418. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  419. }
  420. static void
  421. route_match_ip_route_source_prefix_list_free (void *rule)
  422. {
  423. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  424. }
  425. struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
  426. {
  427. "ip route-source prefix-list",
  428. route_match_ip_route_source_prefix_list,
  429. route_match_ip_route_source_prefix_list_compile,
  430. route_match_ip_route_source_prefix_list_free
  431. };
  432. /* `match metric METRIC' */
  433. /* Match function return 1 if match is success else return zero. */
  434. static route_map_result_t
  435. route_match_metric (void *rule, struct prefix *prefix,
  436. route_map_object_t type, void *object)
  437. {
  438. u_int32_t *med;
  439. struct bgp_info *bgp_info;
  440. if (type == RMAP_BGP)
  441. {
  442. med = rule;
  443. bgp_info = object;
  444. if (bgp_info->attr->med == *med)
  445. return RMAP_MATCH;
  446. else
  447. return RMAP_NOMATCH;
  448. }
  449. return RMAP_NOMATCH;
  450. }
  451. /* Route map `match metric' match statement. `arg' is MED value */
  452. static void *
  453. route_match_metric_compile (const char *arg)
  454. {
  455. u_int32_t *med;
  456. char *endptr = NULL;
  457. unsigned long tmpval;
  458. /* Metric value shoud be integer. */
  459. if (! all_digit (arg))
  460. return NULL;
  461. errno = 0;
  462. tmpval = strtoul (arg, &endptr, 10);
  463. if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
  464. return NULL;
  465. med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  466. if (!med)
  467. return med;
  468. *med = tmpval;
  469. return med;
  470. }
  471. /* Free route map's compiled `match metric' value. */
  472. static void
  473. route_match_metric_free (void *rule)
  474. {
  475. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  476. }
  477. /* Route map commands for metric matching. */
  478. struct route_map_rule_cmd route_match_metric_cmd =
  479. {
  480. "metric",
  481. route_match_metric,
  482. route_match_metric_compile,
  483. route_match_metric_free
  484. };
  485. /* `match as-path ASPATH' */
  486. /* Match function for as-path match. I assume given object is */
  487. static route_map_result_t
  488. route_match_aspath (void *rule, struct prefix *prefix,
  489. route_map_object_t type, void *object)
  490. {
  491. struct as_list *as_list;
  492. struct bgp_info *bgp_info;
  493. if (type == RMAP_BGP)
  494. {
  495. as_list = as_list_lookup ((char *) rule);
  496. if (as_list == NULL)
  497. return RMAP_NOMATCH;
  498. bgp_info = object;
  499. /* Perform match. */
  500. return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
  501. }
  502. return RMAP_NOMATCH;
  503. }
  504. /* Compile function for as-path match. */
  505. static void *
  506. route_match_aspath_compile (const char *arg)
  507. {
  508. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  509. }
  510. /* Compile function for as-path match. */
  511. static void
  512. route_match_aspath_free (void *rule)
  513. {
  514. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  515. }
  516. /* Route map commands for aspath matching. */
  517. struct route_map_rule_cmd route_match_aspath_cmd =
  518. {
  519. "as-path",
  520. route_match_aspath,
  521. route_match_aspath_compile,
  522. route_match_aspath_free
  523. };
  524. /* `match community COMMUNIY' */
  525. struct rmap_community
  526. {
  527. char *name;
  528. int exact;
  529. };
  530. /* Match function for community match. */
  531. static route_map_result_t
  532. route_match_community (void *rule, struct prefix *prefix,
  533. route_map_object_t type, void *object)
  534. {
  535. struct community_list *list;
  536. struct bgp_info *bgp_info;
  537. struct rmap_community *rcom;
  538. if (type == RMAP_BGP)
  539. {
  540. bgp_info = object;
  541. rcom = rule;
  542. list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
  543. if (! list)
  544. return RMAP_NOMATCH;
  545. if (rcom->exact)
  546. {
  547. if (community_list_exact_match (bgp_info->attr->community, list))
  548. return RMAP_MATCH;
  549. }
  550. else
  551. {
  552. if (community_list_match (bgp_info->attr->community, list))
  553. return RMAP_MATCH;
  554. }
  555. }
  556. return RMAP_NOMATCH;
  557. }
  558. /* Compile function for community match. */
  559. static void *
  560. route_match_community_compile (const char *arg)
  561. {
  562. struct rmap_community *rcom;
  563. int len;
  564. char *p;
  565. rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
  566. p = strchr (arg, ' ');
  567. if (p)
  568. {
  569. len = p - arg;
  570. rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
  571. memcpy (rcom->name, arg, len);
  572. rcom->exact = 1;
  573. }
  574. else
  575. {
  576. rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  577. rcom->exact = 0;
  578. }
  579. return rcom;
  580. }
  581. /* Compile function for community match. */
  582. static void
  583. route_match_community_free (void *rule)
  584. {
  585. struct rmap_community *rcom = rule;
  586. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
  587. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
  588. }
  589. /* Route map commands for community matching. */
  590. struct route_map_rule_cmd route_match_community_cmd =
  591. {
  592. "community",
  593. route_match_community,
  594. route_match_community_compile,
  595. route_match_community_free
  596. };
  597. /* Match function for extcommunity match. */
  598. static route_map_result_t
  599. route_match_ecommunity (void *rule, struct prefix *prefix,
  600. route_map_object_t type, void *object)
  601. {
  602. struct community_list *list;
  603. struct bgp_info *bgp_info;
  604. if (type == RMAP_BGP)
  605. {
  606. bgp_info = object;
  607. if (!bgp_info->attr->extra)
  608. return RMAP_NOMATCH;
  609. list = community_list_lookup (bgp_clist, (char *) rule,
  610. EXTCOMMUNITY_LIST_MASTER);
  611. if (! list)
  612. return RMAP_NOMATCH;
  613. if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
  614. return RMAP_MATCH;
  615. }
  616. return RMAP_NOMATCH;
  617. }
  618. /* Compile function for extcommunity match. */
  619. static void *
  620. route_match_ecommunity_compile (const char *arg)
  621. {
  622. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  623. }
  624. /* Compile function for extcommunity match. */
  625. static void
  626. route_match_ecommunity_free (void *rule)
  627. {
  628. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  629. }
  630. /* Route map commands for community matching. */
  631. struct route_map_rule_cmd route_match_ecommunity_cmd =
  632. {
  633. "extcommunity",
  634. route_match_ecommunity,
  635. route_match_ecommunity_compile,
  636. route_match_ecommunity_free
  637. };
  638. /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
  639. and `address-family vpnv4'. */
  640. /* `match origin' */
  641. static route_map_result_t
  642. route_match_origin (void *rule, struct prefix *prefix,
  643. route_map_object_t type, void *object)
  644. {
  645. u_char *origin;
  646. struct bgp_info *bgp_info;
  647. if (type == RMAP_BGP)
  648. {
  649. origin = rule;
  650. bgp_info = object;
  651. if (bgp_info->attr->origin == *origin)
  652. return RMAP_MATCH;
  653. }
  654. return RMAP_NOMATCH;
  655. }
  656. static void *
  657. route_match_origin_compile (const char *arg)
  658. {
  659. u_char *origin;
  660. origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
  661. if (strcmp (arg, "igp") == 0)
  662. *origin = 0;
  663. else if (strcmp (arg, "egp") == 0)
  664. *origin = 1;
  665. else
  666. *origin = 2;
  667. return origin;
  668. }
  669. /* Free route map's compiled `ip address' value. */
  670. static void
  671. route_match_origin_free (void *rule)
  672. {
  673. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  674. }
  675. /* Route map commands for origin matching. */
  676. struct route_map_rule_cmd route_match_origin_cmd =
  677. {
  678. "origin",
  679. route_match_origin,
  680. route_match_origin_compile,
  681. route_match_origin_free
  682. };
  683. /* match probability { */
  684. static route_map_result_t
  685. route_match_probability (void *rule, struct prefix *prefix,
  686. route_map_object_t type, void *object)
  687. {
  688. long r;
  689. #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
  690. r = random();
  691. #else
  692. r = (long) rand();
  693. #endif
  694. switch (*(unsigned *) rule)
  695. {
  696. case 0: break;
  697. case RAND_MAX: return RMAP_MATCH;
  698. default:
  699. if (r < *(unsigned *) rule)
  700. {
  701. return RMAP_MATCH;
  702. }
  703. }
  704. return RMAP_NOMATCH;
  705. }
  706. static void *
  707. route_match_probability_compile (const char *arg)
  708. {
  709. unsigned *lobule;
  710. unsigned perc;
  711. #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
  712. srandom (time (NULL));
  713. #else
  714. srand (time (NULL));
  715. #endif
  716. perc = atoi (arg);
  717. lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
  718. switch (perc)
  719. {
  720. case 0: *lobule = 0; break;
  721. case 100: *lobule = RAND_MAX; break;
  722. default: *lobule = RAND_MAX / 100 * perc;
  723. }
  724. return lobule;
  725. }
  726. static void
  727. route_match_probability_free (void *rule)
  728. {
  729. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  730. }
  731. struct route_map_rule_cmd route_match_probability_cmd =
  732. {
  733. "probability",
  734. route_match_probability,
  735. route_match_probability_compile,
  736. route_match_probability_free
  737. };
  738. /* } */
  739. /* `set ip next-hop IP_ADDRESS' */
  740. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  741. struct rmap_ip_nexthop_set
  742. {
  743. struct in_addr *address;
  744. int peer_address;
  745. };
  746. static route_map_result_t
  747. route_set_ip_nexthop (void *rule, struct prefix *prefix,
  748. route_map_object_t type, void *object)
  749. {
  750. struct rmap_ip_nexthop_set *rins = rule;
  751. struct bgp_info *bgp_info;
  752. struct peer *peer;
  753. if (type == RMAP_BGP)
  754. {
  755. bgp_info = object;
  756. peer = bgp_info->peer;
  757. if (rins->peer_address)
  758. {
  759. if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
  760. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
  761. && peer->su_remote
  762. && sockunion_family (peer->su_remote) == AF_INET)
  763. {
  764. bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
  765. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  766. }
  767. else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
  768. && peer->su_local
  769. && sockunion_family (peer->su_local) == AF_INET)
  770. {
  771. bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
  772. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  773. }
  774. }
  775. else
  776. {
  777. /* Set next hop value. */
  778. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  779. bgp_info->attr->nexthop = *rins->address;
  780. }
  781. }
  782. return RMAP_OKAY;
  783. }
  784. /* Route map `ip nexthop' compile function. Given string is converted
  785. to struct in_addr structure. */
  786. static void *
  787. route_set_ip_nexthop_compile (const char *arg)
  788. {
  789. struct rmap_ip_nexthop_set *rins;
  790. struct in_addr *address = NULL;
  791. int peer_address = 0;
  792. int ret;
  793. if (strcmp (arg, "peer-address") == 0)
  794. peer_address = 1;
  795. else
  796. {
  797. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  798. ret = inet_aton (arg, address);
  799. if (ret == 0)
  800. {
  801. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  802. return NULL;
  803. }
  804. }
  805. rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
  806. rins->address = address;
  807. rins->peer_address = peer_address;
  808. return rins;
  809. }
  810. /* Free route map's compiled `ip nexthop' value. */
  811. static void
  812. route_set_ip_nexthop_free (void *rule)
  813. {
  814. struct rmap_ip_nexthop_set *rins = rule;
  815. if (rins->address)
  816. XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
  817. XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
  818. }
  819. /* Route map commands for ip nexthop set. */
  820. struct route_map_rule_cmd route_set_ip_nexthop_cmd =
  821. {
  822. "ip next-hop",
  823. route_set_ip_nexthop,
  824. route_set_ip_nexthop_compile,
  825. route_set_ip_nexthop_free
  826. };
  827. /* `set local-preference LOCAL_PREF' */
  828. /* Set local preference. */
  829. static route_map_result_t
  830. route_set_local_pref (void *rule, struct prefix *prefix,
  831. route_map_object_t type, void *object)
  832. {
  833. u_int32_t *local_pref;
  834. struct bgp_info *bgp_info;
  835. if (type == RMAP_BGP)
  836. {
  837. /* Fetch routemap's rule information. */
  838. local_pref = rule;
  839. bgp_info = object;
  840. /* Set local preference value. */
  841. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
  842. bgp_info->attr->local_pref = *local_pref;
  843. }
  844. return RMAP_OKAY;
  845. }
  846. /* set local preference compilation. */
  847. static void *
  848. route_set_local_pref_compile (const char *arg)
  849. {
  850. unsigned long tmp;
  851. u_int32_t *local_pref;
  852. char *endptr = NULL;
  853. /* Local preference value shoud be integer. */
  854. if (! all_digit (arg))
  855. return NULL;
  856. errno = 0;
  857. tmp = strtoul (arg, &endptr, 10);
  858. if (*endptr != '\0' || errno || tmp > UINT32_MAX)
  859. return NULL;
  860. local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  861. if (!local_pref)
  862. return local_pref;
  863. *local_pref = tmp;
  864. return local_pref;
  865. }
  866. /* Free route map's local preference value. */
  867. static void
  868. route_set_local_pref_free (void *rule)
  869. {
  870. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  871. }
  872. /* Set local preference rule structure. */
  873. struct route_map_rule_cmd route_set_local_pref_cmd =
  874. {
  875. "local-preference",
  876. route_set_local_pref,
  877. route_set_local_pref_compile,
  878. route_set_local_pref_free,
  879. };
  880. /* `set weight WEIGHT' */
  881. /* Set weight. */
  882. static route_map_result_t
  883. route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
  884. void *object)
  885. {
  886. u_int32_t *weight;
  887. struct bgp_info *bgp_info;
  888. if (type == RMAP_BGP)
  889. {
  890. /* Fetch routemap's rule information. */
  891. weight = rule;
  892. bgp_info = object;
  893. /* Set weight value. */
  894. if (*weight)
  895. (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
  896. else if (bgp_info->attr->extra)
  897. bgp_info->attr->extra->weight = 0;
  898. }
  899. return RMAP_OKAY;
  900. }
  901. /* set local preference compilation. */
  902. static void *
  903. route_set_weight_compile (const char *arg)
  904. {
  905. unsigned long tmp;
  906. u_int32_t *weight;
  907. char *endptr = NULL;
  908. /* Local preference value shoud be integer. */
  909. if (! all_digit (arg))
  910. return NULL;
  911. errno = 0;
  912. tmp = strtoul (arg, &endptr, 10);
  913. if (*endptr != '\0' || errno || tmp > UINT32_MAX)
  914. return NULL;
  915. weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  916. if (weight == NULL)
  917. return weight;
  918. *weight = tmp;
  919. return weight;
  920. }
  921. /* Free route map's local preference value. */
  922. static void
  923. route_set_weight_free (void *rule)
  924. {
  925. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  926. }
  927. /* Set local preference rule structure. */
  928. struct route_map_rule_cmd route_set_weight_cmd =
  929. {
  930. "weight",
  931. route_set_weight,
  932. route_set_weight_compile,
  933. route_set_weight_free,
  934. };
  935. /* `set metric METRIC' */
  936. /* Set metric to attribute. */
  937. static route_map_result_t
  938. route_set_metric (void *rule, struct prefix *prefix,
  939. route_map_object_t type, void *object)
  940. {
  941. char *metric;
  942. u_int32_t metric_val;
  943. struct bgp_info *bgp_info;
  944. if (type == RMAP_BGP)
  945. {
  946. /* Fetch routemap's rule information. */
  947. metric = rule;
  948. bgp_info = object;
  949. if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
  950. bgp_info->attr->med = 0;
  951. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  952. if (all_digit (metric))
  953. {
  954. metric_val = strtoul (metric, (char **)NULL, 10);
  955. bgp_info->attr->med = metric_val;
  956. }
  957. else
  958. {
  959. metric_val = strtoul (metric+1, (char **)NULL, 10);
  960. if (strncmp (metric, "+", 1) == 0)
  961. {
  962. if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
  963. bgp_info->attr->med = BGP_MED_MAX - 1;
  964. else
  965. bgp_info->attr->med += metric_val;
  966. }
  967. else if (strncmp (metric, "-", 1) == 0)
  968. {
  969. if (bgp_info->attr->med <= metric_val)
  970. bgp_info->attr->med = 0;
  971. else
  972. bgp_info->attr->med -= metric_val;
  973. }
  974. }
  975. }
  976. return RMAP_OKAY;
  977. }
  978. /* set metric compilation. */
  979. static void *
  980. route_set_metric_compile (const char *arg)
  981. {
  982. unsigned long larg;
  983. char *endptr = NULL;
  984. if (all_digit (arg))
  985. {
  986. /* set metric value check*/
  987. errno = 0;
  988. larg = strtoul (arg, &endptr, 10);
  989. if (*endptr != '\0' || errno || larg > UINT32_MAX)
  990. return NULL;
  991. }
  992. else
  993. {
  994. /* set metric +/-value check */
  995. if ((strncmp (arg, "+", 1) != 0
  996. && strncmp (arg, "-", 1) != 0)
  997. || (! all_digit (arg+1)))
  998. return NULL;
  999. errno = 0;
  1000. larg = strtoul (arg+1, &endptr, 10);
  1001. if (*endptr != '\0' || errno || larg > UINT32_MAX)
  1002. return NULL;
  1003. }
  1004. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  1005. }
  1006. /* Free route map's compiled `set metric' value. */
  1007. static void
  1008. route_set_metric_free (void *rule)
  1009. {
  1010. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1011. }
  1012. /* Set metric rule structure. */
  1013. struct route_map_rule_cmd route_set_metric_cmd =
  1014. {
  1015. "metric",
  1016. route_set_metric,
  1017. route_set_metric_compile,
  1018. route_set_metric_free,
  1019. };
  1020. /* `set as-path prepend ASPATH' */
  1021. /* For AS path prepend mechanism. */
  1022. static route_map_result_t
  1023. route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1024. {
  1025. struct aspath *aspath;
  1026. struct aspath *new;
  1027. struct bgp_info *binfo;
  1028. if (type == RMAP_BGP)
  1029. {
  1030. aspath = rule;
  1031. binfo = object;
  1032. if (binfo->attr->aspath->refcnt)
  1033. new = aspath_dup (binfo->attr->aspath);
  1034. else
  1035. new = binfo->attr->aspath;
  1036. aspath_prepend (aspath, new);
  1037. binfo->attr->aspath = new;
  1038. }
  1039. return RMAP_OKAY;
  1040. }
  1041. /* Set as-path prepend rule structure. */
  1042. struct route_map_rule_cmd route_set_aspath_prepend_cmd =
  1043. {
  1044. "as-path prepend",
  1045. route_set_aspath_prepend,
  1046. route_aspath_compile,
  1047. route_aspath_free,
  1048. };
  1049. /* `set as-path exclude ASn' */
  1050. /* For ASN exclude mechanism.
  1051. * Iterate over ASns requested and filter them from the given AS_PATH one by one.
  1052. * Make a deep copy of existing AS_PATH, but for the first ASn only.
  1053. */
  1054. static route_map_result_t
  1055. route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
  1056. {
  1057. struct aspath * new_path, * exclude_path;
  1058. struct bgp_info *binfo;
  1059. if (type == RMAP_BGP)
  1060. {
  1061. exclude_path = rule;
  1062. binfo = object;
  1063. if (binfo->attr->aspath->refcnt)
  1064. new_path = aspath_dup (binfo->attr->aspath);
  1065. else
  1066. new_path = binfo->attr->aspath;
  1067. binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
  1068. }
  1069. return RMAP_OKAY;
  1070. }
  1071. /* Set ASn exlude rule structure. */
  1072. struct route_map_rule_cmd route_set_aspath_exclude_cmd =
  1073. {
  1074. "as-path exclude",
  1075. route_set_aspath_exclude,
  1076. route_aspath_compile,
  1077. route_aspath_free,
  1078. };
  1079. /* `set community COMMUNITY' */
  1080. struct rmap_com_set
  1081. {
  1082. struct community *com;
  1083. int additive;
  1084. int none;
  1085. };
  1086. /* For community set mechanism. */
  1087. static route_map_result_t
  1088. route_set_community (void *rule, struct prefix *prefix,
  1089. route_map_object_t type, void *object)
  1090. {
  1091. struct rmap_com_set *rcs;
  1092. struct bgp_info *binfo;
  1093. struct attr *attr;
  1094. struct community *new = NULL;
  1095. struct community *old;
  1096. struct community *merge;
  1097. if (type == RMAP_BGP)
  1098. {
  1099. rcs = rule;
  1100. binfo = object;
  1101. attr = binfo->attr;
  1102. old = attr->community;
  1103. /* "none" case. */
  1104. if (rcs->none)
  1105. {
  1106. attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
  1107. attr->community = NULL;
  1108. /* See the longer comment down below. */
  1109. if (old && old->refcnt == 0)
  1110. community_free(old);
  1111. return RMAP_OKAY;
  1112. }
  1113. /* "additive" case. */
  1114. if (rcs->additive && old)
  1115. {
  1116. merge = community_merge (community_dup (old), rcs->com);
  1117. /* HACK: if the old community is not intern'd,
  1118. * we should free it here, or all reference to it may be lost.
  1119. * Really need to cleanup attribute caching sometime.
  1120. */
  1121. if (old->refcnt == 0)
  1122. community_free (old);
  1123. new = community_uniq_sort (merge);
  1124. community_free (merge);
  1125. }
  1126. else
  1127. new = community_dup (rcs->com);
  1128. /* will be interned by caller if required */
  1129. attr->community = new;
  1130. attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1131. }
  1132. return RMAP_OKAY;
  1133. }
  1134. /* Compile function for set community. */
  1135. static void *
  1136. route_set_community_compile (const char *arg)
  1137. {
  1138. struct rmap_com_set *rcs;
  1139. struct community *com = NULL;
  1140. char *sp;
  1141. int additive = 0;
  1142. int none = 0;
  1143. if (strcmp (arg, "none") == 0)
  1144. none = 1;
  1145. else
  1146. {
  1147. sp = strstr (arg, "additive");
  1148. if (sp && sp > arg)
  1149. {
  1150. /* "additive" keyworkd is included. */
  1151. additive = 1;
  1152. *(sp - 1) = '\0';
  1153. }
  1154. com = community_str2com (arg);
  1155. if (additive)
  1156. *(sp - 1) = ' ';
  1157. if (! com)
  1158. return NULL;
  1159. }
  1160. rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
  1161. rcs->com = com;
  1162. rcs->additive = additive;
  1163. rcs->none = none;
  1164. return rcs;
  1165. }
  1166. /* Free function for set community. */
  1167. static void
  1168. route_set_community_free (void *rule)
  1169. {
  1170. struct rmap_com_set *rcs = rule;
  1171. if (rcs->com)
  1172. community_free (rcs->com);
  1173. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
  1174. }
  1175. /* Set community rule structure. */
  1176. struct route_map_rule_cmd route_set_community_cmd =
  1177. {
  1178. "community",
  1179. route_set_community,
  1180. route_set_community_compile,
  1181. route_set_community_free,
  1182. };
  1183. /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
  1184. /* For community set mechanism. */
  1185. static route_map_result_t
  1186. route_set_community_delete (void *rule, struct prefix *prefix,
  1187. route_map_object_t type, void *object)
  1188. {
  1189. struct community_list *list;
  1190. struct community *merge;
  1191. struct community *new;
  1192. struct community *old;
  1193. struct bgp_info *binfo;
  1194. if (type == RMAP_BGP)
  1195. {
  1196. if (! rule)
  1197. return RMAP_OKAY;
  1198. binfo = object;
  1199. list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
  1200. old = binfo->attr->community;
  1201. if (list && old)
  1202. {
  1203. merge = community_list_match_delete (community_dup (old), list);
  1204. new = community_uniq_sort (merge);
  1205. community_free (merge);
  1206. /* HACK: if the old community is not intern'd,
  1207. * we should free it here, or all reference to it may be lost.
  1208. * Really need to cleanup attribute caching sometime.
  1209. */
  1210. if (old->refcnt == 0)
  1211. community_free (old);
  1212. if (new->size == 0)
  1213. {
  1214. binfo->attr->community = NULL;
  1215. binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1216. community_free (new);
  1217. }
  1218. else
  1219. {
  1220. binfo->attr->community = new;
  1221. binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1222. }
  1223. }
  1224. }
  1225. return RMAP_OKAY;
  1226. }
  1227. /* Compile function for set community. */
  1228. static void *
  1229. route_set_community_delete_compile (const char *arg)
  1230. {
  1231. char *p;
  1232. char *str;
  1233. int len;
  1234. p = strchr (arg, ' ');
  1235. if (p)
  1236. {
  1237. len = p - arg;
  1238. str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
  1239. memcpy (str, arg, len);
  1240. }
  1241. else
  1242. str = NULL;
  1243. return str;
  1244. }
  1245. /* Free function for set community. */
  1246. static void
  1247. route_set_community_delete_free (void *rule)
  1248. {
  1249. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1250. }
  1251. /* Set community rule structure. */
  1252. struct route_map_rule_cmd route_set_community_delete_cmd =
  1253. {
  1254. "comm-list",
  1255. route_set_community_delete,
  1256. route_set_community_delete_compile,
  1257. route_set_community_delete_free,
  1258. };
  1259. /* `set extcommunity rt COMMUNITY' */
  1260. /* For community set mechanism. Used by _rt and _soo. */
  1261. static route_map_result_t
  1262. route_set_ecommunity (void *rule, struct prefix *prefix,
  1263. route_map_object_t type, void *object)
  1264. {
  1265. struct ecommunity *ecom;
  1266. struct ecommunity *new_ecom;
  1267. struct ecommunity *old_ecom;
  1268. struct bgp_info *bgp_info;
  1269. if (type == RMAP_BGP)
  1270. {
  1271. ecom = rule;
  1272. bgp_info = object;
  1273. if (! ecom)
  1274. return RMAP_OKAY;
  1275. /* We assume additive for Extended Community. */
  1276. old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
  1277. if (old_ecom)
  1278. {
  1279. new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
  1280. /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
  1281. * ->refcnt = 0 => set by a previous route-map statement */
  1282. if (!old_ecom->refcnt)
  1283. ecommunity_free (&old_ecom);
  1284. }
  1285. else
  1286. new_ecom = ecommunity_dup (ecom);
  1287. /* will be intern()'d or attr_flush()'d by bgp_update_main() */
  1288. bgp_info->attr->extra->ecommunity = new_ecom;
  1289. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
  1290. }
  1291. return RMAP_OKAY;
  1292. }
  1293. /* Compile function for set community. */
  1294. static void *
  1295. route_set_ecommunity_rt_compile (const char *arg)
  1296. {
  1297. struct ecommunity *ecom;
  1298. ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
  1299. if (! ecom)
  1300. return NULL;
  1301. return ecommunity_intern (ecom);
  1302. }
  1303. /* Free function for set community. Used by _rt and _soo */
  1304. static void
  1305. route_set_ecommunity_free (void *rule)
  1306. {
  1307. struct ecommunity *ecom = rule;
  1308. ecommunity_unintern (&ecom);
  1309. }
  1310. /* Set community rule structure. */
  1311. struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
  1312. {
  1313. "extcommunity rt",
  1314. route_set_ecommunity,
  1315. route_set_ecommunity_rt_compile,
  1316. route_set_ecommunity_free,
  1317. };
  1318. /* `set extcommunity soo COMMUNITY' */
  1319. /* Compile function for set community. */
  1320. static void *
  1321. route_set_ecommunity_soo_compile (const char *arg)
  1322. {
  1323. struct ecommunity *ecom;
  1324. ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
  1325. if (! ecom)
  1326. return NULL;
  1327. return ecommunity_intern (ecom);
  1328. }
  1329. /* Set community rule structure. */
  1330. struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
  1331. {
  1332. "extcommunity soo",
  1333. route_set_ecommunity,
  1334. route_set_ecommunity_soo_compile,
  1335. route_set_ecommunity_free,
  1336. };
  1337. /* `set origin ORIGIN' */
  1338. /* For origin set. */
  1339. static route_map_result_t
  1340. route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1341. {
  1342. u_char *origin;
  1343. struct bgp_info *bgp_info;
  1344. if (type == RMAP_BGP)
  1345. {
  1346. origin = rule;
  1347. bgp_info = object;
  1348. bgp_info->attr->origin = *origin;
  1349. }
  1350. return RMAP_OKAY;
  1351. }
  1352. /* Compile function for origin set. */
  1353. static void *
  1354. route_set_origin_compile (const char *arg)
  1355. {
  1356. u_char *origin;
  1357. origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
  1358. if (strcmp (arg, "igp") == 0)
  1359. *origin = 0;
  1360. else if (strcmp (arg, "egp") == 0)
  1361. *origin = 1;
  1362. else
  1363. *origin = 2;
  1364. return origin;
  1365. }
  1366. /* Compile function for origin set. */
  1367. static void
  1368. route_set_origin_free (void *rule)
  1369. {
  1370. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1371. }
  1372. /* Set origin rule structure. */
  1373. struct route_map_rule_cmd route_set_origin_cmd =
  1374. {
  1375. "origin",
  1376. route_set_origin,
  1377. route_set_origin_compile,
  1378. route_set_origin_free,
  1379. };
  1380. /* `set atomic-aggregate' */
  1381. /* For atomic aggregate set. */
  1382. static route_map_result_t
  1383. route_set_atomic_aggregate (void *rule, struct prefix *prefix,
  1384. route_map_object_t type, void *object)
  1385. {
  1386. struct bgp_info *bgp_info;
  1387. if (type == RMAP_BGP)
  1388. {
  1389. bgp_info = object;
  1390. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  1391. }
  1392. return RMAP_OKAY;
  1393. }
  1394. /* Compile function for atomic aggregate. */
  1395. static void *
  1396. route_set_atomic_aggregate_compile (const char *arg)
  1397. {
  1398. return (void *)1;
  1399. }
  1400. /* Compile function for atomic aggregate. */
  1401. static void
  1402. route_set_atomic_aggregate_free (void *rule)
  1403. {
  1404. return;
  1405. }
  1406. /* Set atomic aggregate rule structure. */
  1407. struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
  1408. {
  1409. "atomic-aggregate",
  1410. route_set_atomic_aggregate,
  1411. route_set_atomic_aggregate_compile,
  1412. route_set_atomic_aggregate_free,
  1413. };
  1414. /* `set aggregator as AS A.B.C.D' */
  1415. struct aggregator
  1416. {
  1417. as_t as;
  1418. struct in_addr address;
  1419. };
  1420. static route_map_result_t
  1421. route_set_aggregator_as (void *rule, struct prefix *prefix,
  1422. route_map_object_t type, void *object)
  1423. {
  1424. struct bgp_info *bgp_info;
  1425. struct aggregator *aggregator;
  1426. struct attr_extra *ae;
  1427. if (type == RMAP_BGP)
  1428. {
  1429. bgp_info = object;
  1430. aggregator = rule;
  1431. ae = bgp_attr_extra_get (bgp_info->attr);
  1432. ae->aggregator_as = aggregator->as;
  1433. ae->aggregator_addr = aggregator->address;
  1434. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
  1435. }
  1436. return RMAP_OKAY;
  1437. }
  1438. static void *
  1439. route_set_aggregator_as_compile (const char *arg)
  1440. {
  1441. struct aggregator *aggregator;
  1442. char as[10];
  1443. char address[20];
  1444. aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
  1445. sscanf (arg, "%s %s", as, address);
  1446. aggregator->as = strtoul (as, NULL, 10);
  1447. inet_aton (address, &aggregator->address);
  1448. return aggregator;
  1449. }
  1450. static void
  1451. route_set_aggregator_as_free (void *rule)
  1452. {
  1453. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1454. }
  1455. struct route_map_rule_cmd route_set_aggregator_as_cmd =
  1456. {
  1457. "aggregator as",
  1458. route_set_aggregator_as,
  1459. route_set_aggregator_as_compile,
  1460. route_set_aggregator_as_free,
  1461. };
  1462. #ifdef HAVE_IPV6
  1463. /* `match ipv6 address IP_ACCESS_LIST' */
  1464. static route_map_result_t
  1465. route_match_ipv6_address (void *rule, struct prefix *prefix,
  1466. route_map_object_t type, void *object)
  1467. {
  1468. struct access_list *alist;
  1469. if (type == RMAP_BGP)
  1470. {
  1471. alist = access_list_lookup (AFI_IP6, (char *) rule);
  1472. if (alist == NULL)
  1473. return RMAP_NOMATCH;
  1474. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  1475. RMAP_NOMATCH : RMAP_MATCH);
  1476. }
  1477. return RMAP_NOMATCH;
  1478. }
  1479. static void *
  1480. route_match_ipv6_address_compile (const char *arg)
  1481. {
  1482. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  1483. }
  1484. static void
  1485. route_match_ipv6_address_free (void *rule)
  1486. {
  1487. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1488. }
  1489. /* Route map commands for ip address matching. */
  1490. struct route_map_rule_cmd route_match_ipv6_address_cmd =
  1491. {
  1492. "ipv6 address",
  1493. route_match_ipv6_address,
  1494. route_match_ipv6_address_compile,
  1495. route_match_ipv6_address_free
  1496. };
  1497. /* `match ipv6 next-hop IP_ADDRESS' */
  1498. static route_map_result_t
  1499. route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
  1500. route_map_object_t type, void *object)
  1501. {
  1502. struct in6_addr *addr = rule;
  1503. struct bgp_info *bgp_info;
  1504. if (type == RMAP_BGP)
  1505. {
  1506. bgp_info = object;
  1507. if (!bgp_info->attr->extra)
  1508. return RMAP_NOMATCH;
  1509. if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, addr))
  1510. return RMAP_MATCH;
  1511. if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
  1512. IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, addr))
  1513. return RMAP_MATCH;
  1514. return RMAP_NOMATCH;
  1515. }
  1516. return RMAP_NOMATCH;
  1517. }
  1518. static void *
  1519. route_match_ipv6_next_hop_compile (const char *arg)
  1520. {
  1521. struct in6_addr *address;
  1522. int ret;
  1523. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1524. ret = inet_pton (AF_INET6, arg, address);
  1525. if (!ret)
  1526. {
  1527. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1528. return NULL;
  1529. }
  1530. return address;
  1531. }
  1532. static void
  1533. route_match_ipv6_next_hop_free (void *rule)
  1534. {
  1535. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1536. }
  1537. struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
  1538. {
  1539. "ipv6 next-hop",
  1540. route_match_ipv6_next_hop,
  1541. route_match_ipv6_next_hop_compile,
  1542. route_match_ipv6_next_hop_free
  1543. };
  1544. /* `match ipv6 address prefix-list PREFIX_LIST' */
  1545. static route_map_result_t
  1546. route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
  1547. route_map_object_t type, void *object)
  1548. {
  1549. struct prefix_list *plist;
  1550. if (type == RMAP_BGP)
  1551. {
  1552. plist = prefix_list_lookup (AFI_IP6, (char *) rule);
  1553. if (plist == NULL)
  1554. return RMAP_NOMATCH;
  1555. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  1556. RMAP_NOMATCH : RMAP_MATCH);
  1557. }
  1558. return RMAP_NOMATCH;
  1559. }
  1560. static void *
  1561. route_match_ipv6_address_prefix_list_compile (const char *arg)
  1562. {
  1563. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  1564. }
  1565. static void
  1566. route_match_ipv6_address_prefix_list_free (void *rule)
  1567. {
  1568. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1569. }
  1570. struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
  1571. {
  1572. "ipv6 address prefix-list",
  1573. route_match_ipv6_address_prefix_list,
  1574. route_match_ipv6_address_prefix_list_compile,
  1575. route_match_ipv6_address_prefix_list_free
  1576. };
  1577. /* `set ipv6 nexthop global IP_ADDRESS' */
  1578. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  1579. static route_map_result_t
  1580. route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
  1581. route_map_object_t type, void *object)
  1582. {
  1583. struct in6_addr *address;
  1584. struct bgp_info *bgp_info;
  1585. if (type == RMAP_BGP)
  1586. {
  1587. /* Fetch routemap's rule information. */
  1588. address = rule;
  1589. bgp_info = object;
  1590. /* Set next hop value. */
  1591. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
  1592. /* Set nexthop length. */
  1593. if (bgp_info->attr->extra->mp_nexthop_len == 0)
  1594. bgp_info->attr->extra->mp_nexthop_len = 16;
  1595. }
  1596. return RMAP_OKAY;
  1597. }
  1598. /* Route map `ip next-hop' compile function. Given string is converted
  1599. to struct in_addr structure. */
  1600. static void *
  1601. route_set_ipv6_nexthop_global_compile (const char *arg)
  1602. {
  1603. int ret;
  1604. struct in6_addr *address;
  1605. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1606. ret = inet_pton (AF_INET6, arg, address);
  1607. if (ret == 0)
  1608. {
  1609. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1610. return NULL;
  1611. }
  1612. return address;
  1613. }
  1614. /* Free route map's compiled `ip next-hop' value. */
  1615. static void
  1616. route_set_ipv6_nexthop_global_free (void *rule)
  1617. {
  1618. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1619. }
  1620. /* Route map commands for ip nexthop set. */
  1621. struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
  1622. {
  1623. "ipv6 next-hop global",
  1624. route_set_ipv6_nexthop_global,
  1625. route_set_ipv6_nexthop_global_compile,
  1626. route_set_ipv6_nexthop_global_free
  1627. };
  1628. /* `set ipv6 nexthop local IP_ADDRESS' */
  1629. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  1630. static route_map_result_t
  1631. route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
  1632. route_map_object_t type, void *object)
  1633. {
  1634. struct in6_addr *address;
  1635. struct bgp_info *bgp_info;
  1636. if (type == RMAP_BGP)
  1637. {
  1638. /* Fetch routemap's rule information. */
  1639. address = rule;
  1640. bgp_info = object;
  1641. /* Set next hop value. */
  1642. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
  1643. /* Set nexthop length. */
  1644. if (bgp_info->attr->extra->mp_nexthop_len != 32)
  1645. bgp_info->attr->extra->mp_nexthop_len = 32;
  1646. }
  1647. return RMAP_OKAY;
  1648. }
  1649. /* Route map `ip nexthop' compile function. Given string is converted
  1650. to struct in_addr structure. */
  1651. static void *
  1652. route_set_ipv6_nexthop_local_compile (const char *arg)
  1653. {
  1654. int ret;
  1655. struct in6_addr *address;
  1656. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1657. ret = inet_pton (AF_INET6, arg, address);
  1658. if (ret == 0)
  1659. {
  1660. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1661. return NULL;
  1662. }
  1663. return address;
  1664. }
  1665. /* Free route map's compiled `ip nexthop' value. */
  1666. static void
  1667. route_set_ipv6_nexthop_local_free (void *rule)
  1668. {
  1669. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1670. }
  1671. /* Route map commands for ip nexthop set. */
  1672. struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
  1673. {
  1674. "ipv6 next-hop local",
  1675. route_set_ipv6_nexthop_local,
  1676. route_set_ipv6_nexthop_local_compile,
  1677. route_set_ipv6_nexthop_local_free
  1678. };
  1679. #endif /* HAVE_IPV6 */
  1680. /* `set vpnv4 nexthop A.B.C.D' */
  1681. static route_map_result_t
  1682. route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
  1683. route_map_object_t type, void *object)
  1684. {
  1685. struct in_addr *address;
  1686. struct bgp_info *bgp_info;
  1687. if (type == RMAP_BGP)
  1688. {
  1689. /* Fetch routemap's rule information. */
  1690. address = rule;
  1691. bgp_info = object;
  1692. /* Set next hop value. */
  1693. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
  1694. }
  1695. return RMAP_OKAY;
  1696. }
  1697. static void *
  1698. route_set_vpnv4_nexthop_compile (const char *arg)
  1699. {
  1700. int ret;
  1701. struct in_addr *address;
  1702. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  1703. ret = inet_aton (arg, address);
  1704. if (ret == 0)
  1705. {
  1706. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1707. return NULL;
  1708. }
  1709. return address;
  1710. }
  1711. static void
  1712. route_set_vpnv4_nexthop_free (void *rule)
  1713. {
  1714. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1715. }
  1716. /* Route map commands for ip nexthop set. */
  1717. struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
  1718. {
  1719. "vpnv4 next-hop",
  1720. route_set_vpnv4_nexthop,
  1721. route_set_vpnv4_nexthop_compile,
  1722. route_set_vpnv4_nexthop_free
  1723. };
  1724. /* `set originator-id' */
  1725. /* For origin set. */
  1726. static route_map_result_t
  1727. route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1728. {
  1729. struct in_addr *address;
  1730. struct bgp_info *bgp_info;
  1731. if (type == RMAP_BGP)
  1732. {
  1733. address = rule;
  1734. bgp_info = object;
  1735. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
  1736. (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
  1737. }
  1738. return RMAP_OKAY;
  1739. }
  1740. /* Compile function for originator-id set. */
  1741. static void *
  1742. route_set_originator_id_compile (const char *arg)
  1743. {
  1744. int ret;
  1745. struct in_addr *address;
  1746. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  1747. ret = inet_aton (arg, address);
  1748. if (ret == 0)
  1749. {
  1750. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1751. return NULL;
  1752. }
  1753. return address;
  1754. }
  1755. /* Compile function for originator_id set. */
  1756. static void
  1757. route_set_originator_id_free (void *rule)
  1758. {
  1759. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1760. }
  1761. /* Set originator-id rule structure. */
  1762. struct route_map_rule_cmd route_set_originator_id_cmd =
  1763. {
  1764. "originator-id",
  1765. route_set_originator_id,
  1766. route_set_originator_id_compile,
  1767. route_set_originator_id_free,
  1768. };
  1769. /* Add bgp route map rule. */
  1770. static int
  1771. bgp_route_match_add (struct vty *vty, struct route_map_index *index,
  1772. const char *command, const char *arg)
  1773. {
  1774. int ret;
  1775. ret = route_map_add_match (index, command, arg);
  1776. if (ret)
  1777. {
  1778. switch (ret)
  1779. {
  1780. case RMAP_RULE_MISSING:
  1781. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1782. return CMD_WARNING;
  1783. case RMAP_COMPILE_ERROR:
  1784. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1785. return CMD_WARNING;
  1786. }
  1787. }
  1788. return CMD_SUCCESS;
  1789. }
  1790. /* Delete bgp route map rule. */
  1791. static int
  1792. bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
  1793. const char *command, const char *arg)
  1794. {
  1795. int ret;
  1796. ret = route_map_delete_match (index, command, arg);
  1797. if (ret)
  1798. {
  1799. switch (ret)
  1800. {
  1801. case RMAP_RULE_MISSING:
  1802. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1803. return CMD_WARNING;
  1804. case RMAP_COMPILE_ERROR:
  1805. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1806. return CMD_WARNING;
  1807. }
  1808. }
  1809. return CMD_SUCCESS;
  1810. }
  1811. /* Add bgp route map rule. */
  1812. static int
  1813. bgp_route_set_add (struct vty *vty, struct route_map_index *index,
  1814. const char *command, const char *arg)
  1815. {
  1816. int ret;
  1817. ret = route_map_add_set (index, command, arg);
  1818. if (ret)
  1819. {
  1820. switch (ret)
  1821. {
  1822. case RMAP_RULE_MISSING:
  1823. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1824. return CMD_WARNING;
  1825. case RMAP_COMPILE_ERROR:
  1826. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1827. return CMD_WARNING;
  1828. }
  1829. }
  1830. return CMD_SUCCESS;
  1831. }
  1832. /* Delete bgp route map rule. */
  1833. static int
  1834. bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
  1835. const char *command, const char *arg)
  1836. {
  1837. int ret;
  1838. ret = route_map_delete_set (index, command, arg);
  1839. if (ret)
  1840. {
  1841. switch (ret)
  1842. {
  1843. case RMAP_RULE_MISSING:
  1844. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1845. return CMD_WARNING;
  1846. case RMAP_COMPILE_ERROR:
  1847. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1848. return CMD_WARNING;
  1849. }
  1850. }
  1851. return CMD_SUCCESS;
  1852. }
  1853. /* Hook function for updating route_map assignment. */
  1854. static void
  1855. bgp_route_map_update (const char *unused)
  1856. {
  1857. int i;
  1858. afi_t afi;
  1859. safi_t safi;
  1860. int direct;
  1861. struct listnode *node, *nnode;
  1862. struct listnode *mnode, *mnnode;
  1863. struct bgp *bgp;
  1864. struct peer *peer;
  1865. struct peer_group *group;
  1866. struct bgp_filter *filter;
  1867. struct bgp_node *bn;
  1868. struct bgp_static *bgp_static;
  1869. /* For neighbor route-map updates. */
  1870. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1871. {
  1872. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1873. {
  1874. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1875. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1876. {
  1877. filter = &peer->filter[afi][safi];
  1878. for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
  1879. {
  1880. if (filter->map[direct].name)
  1881. filter->map[direct].map =
  1882. route_map_lookup_by_name (filter->map[direct].name);
  1883. else
  1884. filter->map[direct].map = NULL;
  1885. }
  1886. if (filter->usmap.name)
  1887. filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
  1888. else
  1889. filter->usmap.map = NULL;
  1890. }
  1891. }
  1892. for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
  1893. {
  1894. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1895. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1896. {
  1897. filter = &group->conf->filter[afi][safi];
  1898. for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
  1899. {
  1900. if (filter->map[direct].name)
  1901. filter->map[direct].map =
  1902. route_map_lookup_by_name (filter->map[direct].name);
  1903. else
  1904. filter->map[direct].map = NULL;
  1905. }
  1906. if (filter->usmap.name)
  1907. filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
  1908. else
  1909. filter->usmap.map = NULL;
  1910. }
  1911. }
  1912. }
  1913. /* For default-originate route-map updates. */
  1914. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1915. {
  1916. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1917. {
  1918. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1919. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1920. {
  1921. if (peer->default_rmap[afi][safi].name)
  1922. peer->default_rmap[afi][safi].map =
  1923. route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
  1924. else
  1925. peer->default_rmap[afi][safi].map = NULL;
  1926. }
  1927. }
  1928. }
  1929. /* For network route-map updates. */
  1930. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1931. {
  1932. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1933. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1934. for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
  1935. bn = bgp_route_next (bn))
  1936. if ((bgp_static = bn->info) != NULL)
  1937. {
  1938. if (bgp_static->rmap.name)
  1939. bgp_static->rmap.map =
  1940. route_map_lookup_by_name (bgp_static->rmap.name);
  1941. else
  1942. bgp_static->rmap.map = NULL;
  1943. }
  1944. }
  1945. /* For redistribute route-map updates. */
  1946. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1947. {
  1948. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  1949. {
  1950. if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
  1951. bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
  1952. route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
  1953. #ifdef HAVE_IPV6
  1954. if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
  1955. bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
  1956. route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
  1957. #endif /* HAVE_IPV6 */
  1958. }
  1959. }
  1960. }
  1961. DEFUN (match_peer,
  1962. match_peer_cmd,
  1963. "match peer (A.B.C.D|X:X::X:X)",
  1964. MATCH_STR
  1965. "Match peer address\n"
  1966. "IPv6 address of peer\n"
  1967. "IP address of peer\n")
  1968. {
  1969. return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
  1970. }
  1971. DEFUN (match_peer_local,
  1972. match_peer_local_cmd,
  1973. "match peer local",
  1974. MATCH_STR
  1975. "Match peer address\n"
  1976. "Static or Redistributed routes\n")
  1977. {
  1978. return bgp_route_match_add (vty, vty->index, "peer", "local");
  1979. }
  1980. DEFUN (no_match_peer,
  1981. no_match_peer_cmd,
  1982. "no match peer",
  1983. NO_STR
  1984. MATCH_STR
  1985. "Match peer address\n")
  1986. {
  1987. if (argc == 0)
  1988. return bgp_route_match_delete (vty, vty->index, "peer", NULL);
  1989. return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
  1990. }
  1991. ALIAS (no_match_peer,
  1992. no_match_peer_val_cmd,
  1993. "no match peer (A.B.C.D|X:X::X:X)",
  1994. NO_STR
  1995. MATCH_STR
  1996. "Match peer address\n"
  1997. "IPv6 address of peer\n"
  1998. "IP address of peer\n")
  1999. ALIAS (no_match_peer,
  2000. no_match_peer_local_cmd,
  2001. "no match peer local",
  2002. NO_STR
  2003. MATCH_STR
  2004. "Match peer address\n"
  2005. "Static or Redistributed routes\n")
  2006. DEFUN (match_ip_address,
  2007. match_ip_address_cmd,
  2008. "match ip address (<1-199>|<1300-2699>|WORD)",
  2009. MATCH_STR
  2010. IP_STR
  2011. "Match address of route\n"
  2012. "IP access-list number\n"
  2013. "IP access-list number (expanded range)\n"
  2014. "IP Access-list name\n")
  2015. {
  2016. return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
  2017. }
  2018. DEFUN (no_match_ip_address,
  2019. no_match_ip_address_cmd,
  2020. "no match ip address",
  2021. NO_STR
  2022. MATCH_STR
  2023. IP_STR
  2024. "Match address of route\n")
  2025. {
  2026. if (argc == 0)
  2027. return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
  2028. return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
  2029. }
  2030. ALIAS (no_match_ip_address,
  2031. no_match_ip_address_val_cmd,
  2032. "no match ip address (<1-199>|<1300-2699>|WORD)",
  2033. NO_STR
  2034. MATCH_STR
  2035. IP_STR
  2036. "Match address of route\n"
  2037. "IP access-list number\n"
  2038. "IP access-list number (expanded range)\n"
  2039. "IP Access-list name\n")
  2040. DEFUN (match_ip_next_hop,
  2041. match_ip_next_hop_cmd,
  2042. "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  2043. MATCH_STR
  2044. IP_STR
  2045. "Match next-hop address of route\n"
  2046. "IP access-list number\n"
  2047. "IP access-list number (expanded range)\n"
  2048. "IP Access-list name\n")
  2049. {
  2050. return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  2051. }
  2052. DEFUN (no_match_ip_next_hop,
  2053. no_match_ip_next_hop_cmd,
  2054. "no match ip next-hop",
  2055. NO_STR
  2056. MATCH_STR
  2057. IP_STR
  2058. "Match next-hop address of route\n")
  2059. {
  2060. if (argc == 0)
  2061. return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  2062. return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  2063. }
  2064. ALIAS (no_match_ip_next_hop,
  2065. no_match_ip_next_hop_val_cmd,
  2066. "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  2067. NO_STR
  2068. MATCH_STR
  2069. IP_STR
  2070. "Match next-hop address of route\n"
  2071. "IP access-list number\n"
  2072. "IP access-list number (expanded range)\n"
  2073. "IP Access-list name\n")
  2074. /* match probability { */
  2075. DEFUN (match_probability,
  2076. match_probability_cmd,
  2077. "match probability <0-100>",
  2078. MATCH_STR
  2079. "Match portion of routes defined by percentage value\n"
  2080. "Percentage of routes\n")
  2081. {
  2082. return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
  2083. }
  2084. DEFUN (no_match_probability,
  2085. no_match_probability_cmd,
  2086. "no match probability",
  2087. NO_STR
  2088. MATCH_STR
  2089. "Match portion of routes defined by percentage value\n")
  2090. {
  2091. return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
  2092. }
  2093. ALIAS (no_match_probability,
  2094. no_match_probability_val_cmd,
  2095. "no match probability <1-99>",
  2096. NO_STR
  2097. MATCH_STR
  2098. "Match portion of routes defined by percentage value\n"
  2099. "Percentage of routes\n")
  2100. /* } */
  2101. DEFUN (match_ip_route_source,
  2102. match_ip_route_source_cmd,
  2103. "match ip route-source (<1-199>|<1300-2699>|WORD)",
  2104. MATCH_STR
  2105. IP_STR
  2106. "Match advertising source address of route\n"
  2107. "IP access-list number\n"
  2108. "IP access-list number (expanded range)\n"
  2109. "IP standard access-list name\n")
  2110. {
  2111. return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
  2112. }
  2113. DEFUN (no_match_ip_route_source,
  2114. no_match_ip_route_source_cmd,
  2115. "no match ip route-source",
  2116. NO_STR
  2117. MATCH_STR
  2118. IP_STR
  2119. "Match advertising source address of route\n")
  2120. {
  2121. if (argc == 0)
  2122. return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
  2123. return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
  2124. }
  2125. ALIAS (no_match_ip_route_source,
  2126. no_match_ip_route_source_val_cmd,
  2127. "no match ip route-source (<1-199>|<1300-2699>|WORD)",
  2128. NO_STR
  2129. MATCH_STR
  2130. IP_STR
  2131. "Match advertising source address of route\n"
  2132. "IP access-list number\n"
  2133. "IP access-list number (expanded range)\n"
  2134. "IP standard access-list name\n")
  2135. DEFUN (match_ip_address_prefix_list,
  2136. match_ip_address_prefix_list_cmd,
  2137. "match ip address prefix-list WORD",
  2138. MATCH_STR
  2139. IP_STR
  2140. "Match address of route\n"
  2141. "Match entries of prefix-lists\n"
  2142. "IP prefix-list name\n")
  2143. {
  2144. return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
  2145. }
  2146. DEFUN (no_match_ip_address_prefix_list,
  2147. no_match_ip_address_prefix_list_cmd,
  2148. "no match ip address prefix-list",
  2149. NO_STR
  2150. MATCH_STR
  2151. IP_STR
  2152. "Match address of route\n"
  2153. "Match entries of prefix-lists\n")
  2154. {
  2155. if (argc == 0)
  2156. return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
  2157. return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
  2158. }
  2159. ALIAS (no_match_ip_address_prefix_list,
  2160. no_match_ip_address_prefix_list_val_cmd,
  2161. "no match ip address prefix-list WORD",
  2162. NO_STR
  2163. MATCH_STR
  2164. IP_STR
  2165. "Match address of route\n"
  2166. "Match entries of prefix-lists\n"
  2167. "IP prefix-list name\n")
  2168. DEFUN (match_ip_next_hop_prefix_list,
  2169. match_ip_next_hop_prefix_list_cmd,
  2170. "match ip next-hop prefix-list WORD",
  2171. MATCH_STR
  2172. IP_STR
  2173. "Match next-hop address of route\n"
  2174. "Match entries of prefix-lists\n"
  2175. "IP prefix-list name\n")
  2176. {
  2177. return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  2178. }
  2179. DEFUN (no_match_ip_next_hop_prefix_list,
  2180. no_match_ip_next_hop_prefix_list_cmd,
  2181. "no match ip next-hop prefix-list",
  2182. NO_STR
  2183. MATCH_STR
  2184. IP_STR
  2185. "Match next-hop address of route\n"
  2186. "Match entries of prefix-lists\n")
  2187. {
  2188. if (argc == 0)
  2189. return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
  2190. return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  2191. }
  2192. ALIAS (no_match_ip_next_hop_prefix_list,
  2193. no_match_ip_next_hop_prefix_list_val_cmd,
  2194. "no match ip next-hop prefix-list WORD",
  2195. NO_STR
  2196. MATCH_STR
  2197. IP_STR
  2198. "Match next-hop address of route\n"
  2199. "Match entries of prefix-lists\n"
  2200. "IP prefix-list name\n")
  2201. DEFUN (match_ip_route_source_prefix_list,
  2202. match_ip_route_source_prefix_list_cmd,
  2203. "match ip route-source prefix-list WORD",
  2204. MATCH_STR
  2205. IP_STR
  2206. "Match advertising source address of route\n"
  2207. "Match entries of prefix-lists\n"
  2208. "IP prefix-list name\n")
  2209. {
  2210. return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
  2211. }
  2212. DEFUN (no_match_ip_route_source_prefix_list,
  2213. no_match_ip_route_source_prefix_list_cmd,
  2214. "no match ip route-source prefix-list",
  2215. NO_STR
  2216. MATCH_STR
  2217. IP_STR
  2218. "Match advertising source address of route\n"
  2219. "Match entries of prefix-lists\n")
  2220. {
  2221. if (argc == 0)
  2222. return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
  2223. return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
  2224. }
  2225. ALIAS (no_match_ip_route_source_prefix_list,
  2226. no_match_ip_route_source_prefix_list_val_cmd,
  2227. "no match ip route-source prefix-list WORD",
  2228. NO_STR
  2229. MATCH_STR
  2230. IP_STR
  2231. "Match advertising source address of route\n"
  2232. "Match entries of prefix-lists\n"
  2233. "IP prefix-list name\n")
  2234. DEFUN (match_metric,
  2235. match_metric_cmd,
  2236. "match metric <0-4294967295>",
  2237. MATCH_STR
  2238. "Match metric of route\n"
  2239. "Metric value\n")
  2240. {
  2241. return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
  2242. }
  2243. DEFUN (no_match_metric,
  2244. no_match_metric_cmd,
  2245. "no match metric",
  2246. NO_STR
  2247. MATCH_STR
  2248. "Match metric of route\n")
  2249. {
  2250. if (argc == 0)
  2251. return bgp_route_match_delete (vty, vty->index, "metric", NULL);
  2252. return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
  2253. }
  2254. ALIAS (no_match_metric,
  2255. no_match_metric_val_cmd,
  2256. "no match metric <0-4294967295>",
  2257. NO_STR
  2258. MATCH_STR
  2259. "Match metric of route\n"
  2260. "Metric value\n")
  2261. DEFUN (match_community,
  2262. match_community_cmd,
  2263. "match community (<1-99>|<100-500>|WORD)",
  2264. MATCH_STR
  2265. "Match BGP community list\n"
  2266. "Community-list number (standard)\n"
  2267. "Community-list number (expanded)\n"
  2268. "Community-list name\n")
  2269. {
  2270. return bgp_route_match_add (vty, vty->index, "community", argv[0]);
  2271. }
  2272. DEFUN (match_community_exact,
  2273. match_community_exact_cmd,
  2274. "match community (<1-99>|<100-500>|WORD) exact-match",
  2275. MATCH_STR
  2276. "Match BGP community list\n"
  2277. "Community-list number (standard)\n"
  2278. "Community-list number (expanded)\n"
  2279. "Community-list name\n"
  2280. "Do exact matching of communities\n")
  2281. {
  2282. int ret;
  2283. char *argstr;
  2284. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  2285. strlen (argv[0]) + strlen ("exact-match") + 2);
  2286. sprintf (argstr, "%s exact-match", argv[0]);
  2287. ret = bgp_route_match_add (vty, vty->index, "community", argstr);
  2288. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  2289. return ret;
  2290. }
  2291. DEFUN (no_match_community,
  2292. no_match_community_cmd,
  2293. "no match community",
  2294. NO_STR
  2295. MATCH_STR
  2296. "Match BGP community list\n")
  2297. {
  2298. return bgp_route_match_delete (vty, vty->index, "community", NULL);
  2299. }
  2300. ALIAS (no_match_community,
  2301. no_match_community_val_cmd,
  2302. "no match community (<1-99>|<100-500>|WORD)",
  2303. NO_STR
  2304. MATCH_STR
  2305. "Match BGP community list\n"
  2306. "Community-list number (standard)\n"
  2307. "Community-list number (expanded)\n"
  2308. "Community-list name\n")
  2309. ALIAS (no_match_community,
  2310. no_match_community_exact_cmd,
  2311. "no match community (<1-99>|<100-500>|WORD) exact-match",
  2312. NO_STR
  2313. MATCH_STR
  2314. "Match BGP community list\n"
  2315. "Community-list number (standard)\n"
  2316. "Community-list number (expanded)\n"
  2317. "Community-list name\n"
  2318. "Do exact matching of communities\n")
  2319. DEFUN (match_ecommunity,
  2320. match_ecommunity_cmd,
  2321. "match extcommunity (<1-99>|<100-500>|WORD)",
  2322. MATCH_STR
  2323. "Match BGP/VPN extended community list\n"
  2324. "Extended community-list number (standard)\n"
  2325. "Extended community-list number (expanded)\n"
  2326. "Extended community-list name\n")
  2327. {
  2328. return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
  2329. }
  2330. DEFUN (no_match_ecommunity,
  2331. no_match_ecommunity_cmd,
  2332. "no match extcommunity",
  2333. NO_STR
  2334. MATCH_STR
  2335. "Match BGP/VPN extended community list\n")
  2336. {
  2337. return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
  2338. }
  2339. ALIAS (no_match_ecommunity,
  2340. no_match_ecommunity_val_cmd,
  2341. "no match extcommunity (<1-99>|<100-500>|WORD)",
  2342. NO_STR
  2343. MATCH_STR
  2344. "Match BGP/VPN extended community list\n"
  2345. "Extended community-list number (standard)\n"
  2346. "Extended community-list number (expanded)\n"
  2347. "Extended community-list name\n")
  2348. DEFUN (match_aspath,
  2349. match_aspath_cmd,
  2350. "match as-path WORD",
  2351. MATCH_STR
  2352. "Match BGP AS path list\n"
  2353. "AS path access-list name\n")
  2354. {
  2355. return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
  2356. }
  2357. DEFUN (no_match_aspath,
  2358. no_match_aspath_cmd,
  2359. "no match as-path",
  2360. NO_STR
  2361. MATCH_STR
  2362. "Match BGP AS path list\n")
  2363. {
  2364. return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
  2365. }
  2366. ALIAS (no_match_aspath,
  2367. no_match_aspath_val_cmd,
  2368. "no match as-path WORD",
  2369. NO_STR
  2370. MATCH_STR
  2371. "Match BGP AS path list\n"
  2372. "AS path access-list name\n")
  2373. DEFUN (match_origin,
  2374. match_origin_cmd,
  2375. "match origin (egp|igp|incomplete)",
  2376. MATCH_STR
  2377. "BGP origin code\n"
  2378. "remote EGP\n"
  2379. "local IGP\n"
  2380. "unknown heritage\n")
  2381. {
  2382. if (strncmp (argv[0], "igp", 2) == 0)
  2383. return bgp_route_match_add (vty, vty->index, "origin", "igp");
  2384. if (strncmp (argv[0], "egp", 1) == 0)
  2385. return bgp_route_match_add (vty, vty->index, "origin", "egp");
  2386. if (strncmp (argv[0], "incomplete", 2) == 0)
  2387. return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
  2388. return CMD_WARNING;
  2389. }
  2390. DEFUN (no_match_origin,
  2391. no_match_origin_cmd,
  2392. "no match origin",
  2393. NO_STR
  2394. MATCH_STR
  2395. "BGP origin code\n")
  2396. {
  2397. return bgp_route_match_delete (vty, vty->index, "origin", NULL);
  2398. }
  2399. ALIAS (no_match_origin,
  2400. no_match_origin_val_cmd,
  2401. "no match origin (egp|igp|incomplete)",
  2402. NO_STR
  2403. MATCH_STR
  2404. "BGP origin code\n"
  2405. "remote EGP\n"
  2406. "local IGP\n"
  2407. "unknown heritage\n")
  2408. DEFUN (set_ip_nexthop,
  2409. set_ip_nexthop_cmd,
  2410. "set ip next-hop A.B.C.D",
  2411. SET_STR
  2412. IP_STR
  2413. "Next hop address\n"
  2414. "IP address of next hop\n")
  2415. {
  2416. union sockunion su;
  2417. int ret;
  2418. ret = str2sockunion (argv[0], &su);
  2419. if (ret < 0)
  2420. {
  2421. vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
  2422. return CMD_WARNING;
  2423. }
  2424. return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
  2425. }
  2426. DEFUN (set_ip_nexthop_peer,
  2427. set_ip_nexthop_peer_cmd,
  2428. "set ip next-hop peer-address",
  2429. SET_STR
  2430. IP_STR
  2431. "Next hop address\n"
  2432. "Use peer address (for BGP only)\n")
  2433. {
  2434. return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
  2435. }
  2436. DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
  2437. no_set_ip_nexthop_peer_cmd,
  2438. "no set ip next-hop peer-address",
  2439. NO_STR
  2440. SET_STR
  2441. IP_STR
  2442. "Next hop address\n"
  2443. "Use peer address (for BGP only)\n")
  2444. {
  2445. return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  2446. }
  2447. DEFUN (no_set_ip_nexthop,
  2448. no_set_ip_nexthop_cmd,
  2449. "no set ip next-hop",
  2450. NO_STR
  2451. SET_STR
  2452. "Next hop address\n")
  2453. {
  2454. if (argc == 0)
  2455. return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  2456. return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
  2457. }
  2458. ALIAS (no_set_ip_nexthop,
  2459. no_set_ip_nexthop_val_cmd,
  2460. "no set ip next-hop A.B.C.D",
  2461. NO_STR
  2462. SET_STR
  2463. IP_STR
  2464. "Next hop address\n"
  2465. "IP address of next hop\n")
  2466. DEFUN (set_metric,
  2467. set_metric_cmd,
  2468. "set metric <0-4294967295>",
  2469. SET_STR
  2470. "Metric value for destination routing protocol\n"
  2471. "Metric value\n")
  2472. {
  2473. return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
  2474. }
  2475. ALIAS (set_metric,
  2476. set_metric_addsub_cmd,
  2477. "set metric <+/-metric>",
  2478. SET_STR
  2479. "Metric value for destination routing protocol\n"
  2480. "Add or subtract metric\n")
  2481. DEFUN (no_set_metric,
  2482. no_set_metric_cmd,
  2483. "no set metric",
  2484. NO_STR
  2485. SET_STR
  2486. "Metric value for destination routing protocol\n")
  2487. {
  2488. if (argc == 0)
  2489. return bgp_route_set_delete (vty, vty->index, "metric", NULL);
  2490. return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
  2491. }
  2492. ALIAS (no_set_metric,
  2493. no_set_metric_val_cmd,
  2494. "no set metric <0-4294967295>",
  2495. NO_STR
  2496. SET_STR
  2497. "Metric value for destination routing protocol\n"
  2498. "Metric value\n")
  2499. DEFUN (set_local_pref,
  2500. set_local_pref_cmd,
  2501. "set local-preference <0-4294967295>",
  2502. SET_STR
  2503. "BGP local preference path attribute\n"
  2504. "Preference value\n")
  2505. {
  2506. return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
  2507. }
  2508. DEFUN (no_set_local_pref,
  2509. no_set_local_pref_cmd,
  2510. "no set local-preference",
  2511. NO_STR
  2512. SET_STR
  2513. "BGP local preference path attribute\n")
  2514. {
  2515. if (argc == 0)
  2516. return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
  2517. return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
  2518. }
  2519. ALIAS (no_set_local_pref,
  2520. no_set_local_pref_val_cmd,
  2521. "no set local-preference <0-4294967295>",
  2522. NO_STR
  2523. SET_STR
  2524. "BGP local preference path attribute\n"
  2525. "Preference value\n")
  2526. DEFUN (set_weight,
  2527. set_weight_cmd,
  2528. "set weight <0-4294967295>",
  2529. SET_STR
  2530. "BGP weight for routing table\n"
  2531. "Weight value\n")
  2532. {
  2533. return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
  2534. }
  2535. DEFUN (no_set_weight,
  2536. no_set_weight_cmd,
  2537. "no set weight",
  2538. NO_STR
  2539. SET_STR
  2540. "BGP weight for routing table\n")
  2541. {
  2542. if (argc == 0)
  2543. return bgp_route_set_delete (vty, vty->index, "weight", NULL);
  2544. return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
  2545. }
  2546. ALIAS (no_set_weight,
  2547. no_set_weight_val_cmd,
  2548. "no set weight <0-4294967295>",
  2549. NO_STR
  2550. SET_STR
  2551. "BGP weight for routing table\n"
  2552. "Weight value\n")
  2553. DEFUN (set_aspath_prepend,
  2554. set_aspath_prepend_cmd,
  2555. "set as-path prepend ." CMD_AS_RANGE,
  2556. SET_STR
  2557. "Transform BGP AS_PATH attribute\n"
  2558. "Prepend to the as-path\n"
  2559. "AS number\n")
  2560. {
  2561. int ret;
  2562. char *str;
  2563. str = argv_concat (argv, argc, 0);
  2564. ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
  2565. XFREE (MTYPE_TMP, str);
  2566. return ret;
  2567. }
  2568. DEFUN (no_set_aspath_prepend,
  2569. no_set_aspath_prepend_cmd,
  2570. "no set as-path prepend",
  2571. NO_STR
  2572. SET_STR
  2573. "Transform BGP AS_PATH attribute\n"
  2574. "Prepend to the as-path\n")
  2575. {
  2576. int ret;
  2577. char *str;
  2578. if (argc == 0)
  2579. return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
  2580. str = argv_concat (argv, argc, 0);
  2581. ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
  2582. XFREE (MTYPE_TMP, str);
  2583. return ret;
  2584. }
  2585. ALIAS (no_set_aspath_prepend,
  2586. no_set_aspath_prepend_val_cmd,
  2587. "no set as-path prepend ." CMD_AS_RANGE,
  2588. NO_STR
  2589. SET_STR
  2590. "Transform BGP AS_PATH attribute\n"
  2591. "Prepend to the as-path\n"
  2592. "AS number\n")
  2593. DEFUN (set_aspath_exclude,
  2594. set_aspath_exclude_cmd,
  2595. "set as-path exclude ." CMD_AS_RANGE,
  2596. SET_STR
  2597. "Transform BGP AS-path attribute\n"
  2598. "Exclude from the as-path\n"
  2599. "AS number\n")
  2600. {
  2601. int ret;
  2602. char *str;
  2603. str = argv_concat (argv, argc, 0);
  2604. ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
  2605. XFREE (MTYPE_TMP, str);
  2606. return ret;
  2607. }
  2608. DEFUN (no_set_aspath_exclude,
  2609. no_set_aspath_exclude_cmd,
  2610. "no set as-path exclude",
  2611. NO_STR
  2612. SET_STR
  2613. "Transform BGP AS_PATH attribute\n"
  2614. "Exclude from the as-path\n")
  2615. {
  2616. int ret;
  2617. char *str;
  2618. if (argc == 0)
  2619. return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
  2620. str = argv_concat (argv, argc, 0);
  2621. ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
  2622. XFREE (MTYPE_TMP, str);
  2623. return ret;
  2624. }
  2625. ALIAS (no_set_aspath_exclude,
  2626. no_set_aspath_exclude_val_cmd,
  2627. "no set as-path exclude ." CMD_AS_RANGE,
  2628. NO_STR
  2629. SET_STR
  2630. "Transform BGP AS_PATH attribute\n"
  2631. "Exclude from the as-path\n"
  2632. "AS number\n")
  2633. DEFUN (set_community,
  2634. set_community_cmd,
  2635. "set community .AA:NN",
  2636. SET_STR
  2637. "BGP community attribute\n"
  2638. "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
  2639. {
  2640. int i;
  2641. int first = 0;
  2642. int additive = 0;
  2643. struct buffer *b;
  2644. struct community *com = NULL;
  2645. char *str;
  2646. char *argstr;
  2647. int ret;
  2648. b = buffer_new (1024);
  2649. for (i = 0; i < argc; i++)
  2650. {
  2651. if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
  2652. {
  2653. additive = 1;
  2654. continue;
  2655. }
  2656. if (first)
  2657. buffer_putc (b, ' ');
  2658. else
  2659. first = 1;
  2660. if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
  2661. {
  2662. buffer_putstr (b, "internet");
  2663. continue;
  2664. }
  2665. if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
  2666. {
  2667. buffer_putstr (b, "local-AS");
  2668. continue;
  2669. }
  2670. if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
  2671. && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
  2672. {
  2673. buffer_putstr (b, "no-advertise");
  2674. continue;
  2675. }
  2676. if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
  2677. && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
  2678. {
  2679. buffer_putstr (b, "no-export");
  2680. continue;
  2681. }
  2682. buffer_putstr (b, argv[i]);
  2683. }
  2684. buffer_putc (b, '\0');
  2685. /* Fetch result string then compile it to communities attribute. */
  2686. str = buffer_getstr (b);
  2687. buffer_free (b);
  2688. if (str)
  2689. {
  2690. com = community_str2com (str);
  2691. XFREE (MTYPE_TMP, str);
  2692. }
  2693. /* Can't compile user input into communities attribute. */
  2694. if (! com)
  2695. {
  2696. vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
  2697. return CMD_WARNING;
  2698. }
  2699. /* Set communites attribute string. */
  2700. str = community_str (com);
  2701. if (additive)
  2702. {
  2703. argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
  2704. strcpy (argstr, str);
  2705. strcpy (argstr + strlen (str), " additive");
  2706. ret = bgp_route_set_add (vty, vty->index, "community", argstr);
  2707. XFREE (MTYPE_TMP, argstr);
  2708. }
  2709. else
  2710. ret = bgp_route_set_add (vty, vty->index, "community", str);
  2711. community_free (com);
  2712. return ret;
  2713. }
  2714. DEFUN (set_community_none,
  2715. set_community_none_cmd,
  2716. "set community none",
  2717. SET_STR
  2718. "BGP community attribute\n"
  2719. "No community attribute\n")
  2720. {
  2721. return bgp_route_set_add (vty, vty->index, "community", "none");
  2722. }
  2723. DEFUN (no_set_community,
  2724. no_set_community_cmd,
  2725. "no set community",
  2726. NO_STR
  2727. SET_STR
  2728. "BGP community attribute\n")
  2729. {
  2730. return bgp_route_set_delete (vty, vty->index, "community", NULL);
  2731. }
  2732. ALIAS (no_set_community,
  2733. no_set_community_val_cmd,
  2734. "no set community .AA:NN",
  2735. NO_STR
  2736. SET_STR
  2737. "BGP community attribute\n"
  2738. "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
  2739. ALIAS (no_set_community,
  2740. no_set_community_none_cmd,
  2741. "no set community none",
  2742. NO_STR
  2743. SET_STR
  2744. "BGP community attribute\n"
  2745. "No community attribute\n")
  2746. DEFUN (set_community_delete,
  2747. set_community_delete_cmd,
  2748. "set comm-list (<1-99>|<100-500>|WORD) delete",
  2749. SET_STR
  2750. "set BGP community list (for deletion)\n"
  2751. "Community-list number (standard)\n"
  2752. "Communitly-list number (expanded)\n"
  2753. "Community-list name\n"
  2754. "Delete matching communities\n")
  2755. {
  2756. char *str;
  2757. str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
  2758. strcpy (str, argv[0]);
  2759. strcpy (str + strlen (argv[0]), " delete");
  2760. bgp_route_set_add (vty, vty->index, "comm-list", str);
  2761. XFREE (MTYPE_TMP, str);
  2762. return CMD_SUCCESS;
  2763. }
  2764. DEFUN (no_set_community_delete,
  2765. no_set_community_delete_cmd,
  2766. "no set comm-list",
  2767. NO_STR
  2768. SET_STR
  2769. "set BGP community list (for deletion)\n")
  2770. {
  2771. return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
  2772. }
  2773. ALIAS (no_set_community_delete,
  2774. no_set_community_delete_val_cmd,
  2775. "no set comm-list (<1-99>|<100-500>|WORD) delete",
  2776. NO_STR
  2777. SET_STR
  2778. "set BGP community list (for deletion)\n"
  2779. "Community-list number (standard)\n"
  2780. "Communitly-list number (expanded)\n"
  2781. "Community-list name\n"
  2782. "Delete matching communities\n")
  2783. DEFUN (set_ecommunity_rt,
  2784. set_ecommunity_rt_cmd,
  2785. "set extcommunity rt .ASN:nn_or_IP-address:nn",
  2786. SET_STR
  2787. "BGP extended community attribute\n"
  2788. "Route Target extended community\n"
  2789. "VPN extended community\n")
  2790. {
  2791. int ret;
  2792. char *str;
  2793. str = argv_concat (argv, argc, 0);
  2794. ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
  2795. XFREE (MTYPE_TMP, str);
  2796. return ret;
  2797. }
  2798. DEFUN (no_set_ecommunity_rt,
  2799. no_set_ecommunity_rt_cmd,
  2800. "no set extcommunity rt",
  2801. NO_STR
  2802. SET_STR
  2803. "BGP extended community attribute\n"
  2804. "Route Target extended community\n")
  2805. {
  2806. return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
  2807. }
  2808. ALIAS (no_set_ecommunity_rt,
  2809. no_set_ecommunity_rt_val_cmd,
  2810. "no set extcommunity rt .ASN:nn_or_IP-address:nn",
  2811. NO_STR
  2812. SET_STR
  2813. "BGP extended community attribute\n"
  2814. "Route Target extended community\n"
  2815. "VPN extended community\n")
  2816. DEFUN (set_ecommunity_soo,
  2817. set_ecommunity_soo_cmd,
  2818. "set extcommunity soo .ASN:nn_or_IP-address:nn",
  2819. SET_STR
  2820. "BGP extended community attribute\n"
  2821. "Site-of-Origin extended community\n"
  2822. "VPN extended community\n")
  2823. {
  2824. int ret;
  2825. char *str;
  2826. str = argv_concat (argv, argc, 0);
  2827. ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
  2828. XFREE (MTYPE_TMP, str);
  2829. return ret;
  2830. }
  2831. DEFUN (no_set_ecommunity_soo,
  2832. no_set_ecommunity_soo_cmd,
  2833. "no set extcommunity soo",
  2834. NO_STR
  2835. SET_STR
  2836. "BGP extended community attribute\n"
  2837. "Site-of-Origin extended community\n")
  2838. {
  2839. return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
  2840. }
  2841. ALIAS (no_set_ecommunity_soo,
  2842. no_set_ecommunity_soo_val_cmd,
  2843. "no set extcommunity soo .ASN:nn_or_IP-address:nn",
  2844. NO_STR
  2845. SET_STR
  2846. "BGP extended community attribute\n"
  2847. "Site-of-Origin extended community\n"
  2848. "VPN extended community\n")
  2849. DEFUN (set_origin,
  2850. set_origin_cmd,
  2851. "set origin (egp|igp|incomplete)",
  2852. SET_STR
  2853. "BGP origin code\n"
  2854. "remote EGP\n"
  2855. "local IGP\n"
  2856. "unknown heritage\n")
  2857. {
  2858. if (strncmp (argv[0], "igp", 2) == 0)
  2859. return bgp_route_set_add (vty, vty->index, "origin", "igp");
  2860. if (strncmp (argv[0], "egp", 1) == 0)
  2861. return bgp_route_set_add (vty, vty->index, "origin", "egp");
  2862. if (strncmp (argv[0], "incomplete", 2) == 0)
  2863. return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
  2864. return CMD_WARNING;
  2865. }
  2866. DEFUN (no_set_origin,
  2867. no_set_origin_cmd,
  2868. "no set origin",
  2869. NO_STR
  2870. SET_STR
  2871. "BGP origin code\n")
  2872. {
  2873. return bgp_route_set_delete (vty, vty->index, "origin", NULL);
  2874. }
  2875. ALIAS (no_set_origin,
  2876. no_set_origin_val_cmd,
  2877. "no set origin (egp|igp|incomplete)",
  2878. NO_STR
  2879. SET_STR
  2880. "BGP origin code\n"
  2881. "remote EGP\n"
  2882. "local IGP\n"
  2883. "unknown heritage\n")
  2884. DEFUN (set_atomic_aggregate,
  2885. set_atomic_aggregate_cmd,
  2886. "set atomic-aggregate",
  2887. SET_STR
  2888. "BGP atomic aggregate attribute\n" )
  2889. {
  2890. return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
  2891. }
  2892. DEFUN (no_set_atomic_aggregate,
  2893. no_set_atomic_aggregate_cmd,
  2894. "no set atomic-aggregate",
  2895. NO_STR
  2896. SET_STR
  2897. "BGP atomic aggregate attribute\n" )
  2898. {
  2899. return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
  2900. }
  2901. DEFUN (set_aggregator_as,
  2902. set_aggregator_as_cmd,
  2903. "set aggregator as " CMD_AS_RANGE " A.B.C.D",
  2904. SET_STR
  2905. "BGP aggregator attribute\n"
  2906. "AS number of aggregator\n"
  2907. "AS number\n"
  2908. "IP address of aggregator\n")
  2909. {
  2910. int ret;
  2911. as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
  2912. struct in_addr address;
  2913. char *argstr;
  2914. VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
  2915. ret = inet_aton (argv[1], &address);
  2916. if (ret == 0)
  2917. {
  2918. vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
  2919. return CMD_WARNING;
  2920. }
  2921. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  2922. strlen (argv[0]) + strlen (argv[1]) + 2);
  2923. sprintf (argstr, "%s %s", argv[0], argv[1]);
  2924. ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
  2925. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  2926. return ret;
  2927. }
  2928. DEFUN (no_set_aggregator_as,
  2929. no_set_aggregator_as_cmd,
  2930. "no set aggregator as",
  2931. NO_STR
  2932. SET_STR
  2933. "BGP aggregator attribute\n"
  2934. "AS number of aggregator\n")
  2935. {
  2936. int ret;
  2937. as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
  2938. struct in_addr address;
  2939. char *argstr;
  2940. if (argv == 0)
  2941. return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
  2942. VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
  2943. ret = inet_aton (argv[1], &address);
  2944. if (ret == 0)
  2945. {
  2946. vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
  2947. return CMD_WARNING;
  2948. }
  2949. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  2950. strlen (argv[0]) + strlen (argv[1]) + 2);
  2951. sprintf (argstr, "%s %s", argv[0], argv[1]);
  2952. ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
  2953. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  2954. return ret;
  2955. }
  2956. ALIAS (no_set_aggregator_as,
  2957. no_set_aggregator_as_val_cmd,
  2958. "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
  2959. NO_STR
  2960. SET_STR
  2961. "BGP aggregator attribute\n"
  2962. "AS number of aggregator\n"
  2963. "AS number\n"
  2964. "IP address of aggregator\n")
  2965. #ifdef HAVE_IPV6
  2966. DEFUN (match_ipv6_address,
  2967. match_ipv6_address_cmd,
  2968. "match ipv6 address WORD",
  2969. MATCH_STR
  2970. IPV6_STR
  2971. "Match IPv6 address of route\n"
  2972. "IPv6 access-list name\n")
  2973. {
  2974. return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
  2975. }
  2976. DEFUN (no_match_ipv6_address,
  2977. no_match_ipv6_address_cmd,
  2978. "no match ipv6 address WORD",
  2979. NO_STR
  2980. MATCH_STR
  2981. IPV6_STR
  2982. "Match IPv6 address of route\n"
  2983. "IPv6 access-list name\n")
  2984. {
  2985. return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
  2986. }
  2987. DEFUN (match_ipv6_next_hop,
  2988. match_ipv6_next_hop_cmd,
  2989. "match ipv6 next-hop X:X::X:X",
  2990. MATCH_STR
  2991. IPV6_STR
  2992. "Match IPv6 next-hop address of route\n"
  2993. "IPv6 address of next hop\n")
  2994. {
  2995. return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
  2996. }
  2997. DEFUN (no_match_ipv6_next_hop,
  2998. no_match_ipv6_next_hop_cmd,
  2999. "no match ipv6 next-hop X:X::X:X",
  3000. NO_STR
  3001. MATCH_STR
  3002. IPV6_STR
  3003. "Match IPv6 next-hop address of route\n"
  3004. "IPv6 address of next hop\n")
  3005. {
  3006. return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
  3007. }
  3008. DEFUN (match_ipv6_address_prefix_list,
  3009. match_ipv6_address_prefix_list_cmd,
  3010. "match ipv6 address prefix-list WORD",
  3011. MATCH_STR
  3012. IPV6_STR
  3013. "Match address of route\n"
  3014. "Match entries of prefix-lists\n"
  3015. "IP prefix-list name\n")
  3016. {
  3017. return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
  3018. }
  3019. DEFUN (no_match_ipv6_address_prefix_list,
  3020. no_match_ipv6_address_prefix_list_cmd,
  3021. "no match ipv6 address prefix-list WORD",
  3022. NO_STR
  3023. MATCH_STR
  3024. IPV6_STR
  3025. "Match address of route\n"
  3026. "Match entries of prefix-lists\n"
  3027. "IP prefix-list name\n")
  3028. {
  3029. return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
  3030. }
  3031. DEFUN (set_ipv6_nexthop_global,
  3032. set_ipv6_nexthop_global_cmd,
  3033. "set ipv6 next-hop global X:X::X:X",
  3034. SET_STR
  3035. IPV6_STR
  3036. "IPv6 next-hop address\n"
  3037. "IPv6 global address\n"
  3038. "IPv6 address of next hop\n")
  3039. {
  3040. return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
  3041. }
  3042. DEFUN (no_set_ipv6_nexthop_global,
  3043. no_set_ipv6_nexthop_global_cmd,
  3044. "no set ipv6 next-hop global",
  3045. NO_STR
  3046. SET_STR
  3047. IPV6_STR
  3048. "IPv6 next-hop address\n"
  3049. "IPv6 global address\n")
  3050. {
  3051. if (argc == 0)
  3052. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
  3053. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
  3054. }
  3055. ALIAS (no_set_ipv6_nexthop_global,
  3056. no_set_ipv6_nexthop_global_val_cmd,
  3057. "no set ipv6 next-hop global X:X::X:X",
  3058. NO_STR
  3059. SET_STR
  3060. IPV6_STR
  3061. "IPv6 next-hop address\n"
  3062. "IPv6 global address\n"
  3063. "IPv6 address of next hop\n")
  3064. DEFUN (set_ipv6_nexthop_local,
  3065. set_ipv6_nexthop_local_cmd,
  3066. "set ipv6 next-hop local X:X::X:X",
  3067. SET_STR
  3068. IPV6_STR
  3069. "IPv6 next-hop address\n"
  3070. "IPv6 local address\n"
  3071. "IPv6 address of next hop\n")
  3072. {
  3073. return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
  3074. }
  3075. DEFUN (no_set_ipv6_nexthop_local,
  3076. no_set_ipv6_nexthop_local_cmd,
  3077. "no set ipv6 next-hop local",
  3078. NO_STR
  3079. SET_STR
  3080. IPV6_STR
  3081. "IPv6 next-hop address\n"
  3082. "IPv6 local address\n")
  3083. {
  3084. if (argc == 0)
  3085. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
  3086. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
  3087. }
  3088. ALIAS (no_set_ipv6_nexthop_local,
  3089. no_set_ipv6_nexthop_local_val_cmd,
  3090. "no set ipv6 next-hop local X:X::X:X",
  3091. NO_STR
  3092. SET_STR
  3093. IPV6_STR
  3094. "IPv6 next-hop address\n"
  3095. "IPv6 local address\n"
  3096. "IPv6 address of next hop\n")
  3097. #endif /* HAVE_IPV6 */
  3098. DEFUN (set_vpnv4_nexthop,
  3099. set_vpnv4_nexthop_cmd,
  3100. "set vpnv4 next-hop A.B.C.D",
  3101. SET_STR
  3102. "VPNv4 information\n"
  3103. "VPNv4 next-hop address\n"
  3104. "IP address of next hop\n")
  3105. {
  3106. return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
  3107. }
  3108. DEFUN (no_set_vpnv4_nexthop,
  3109. no_set_vpnv4_nexthop_cmd,
  3110. "no set vpnv4 next-hop",
  3111. NO_STR
  3112. SET_STR
  3113. "VPNv4 information\n"
  3114. "VPNv4 next-hop address\n")
  3115. {
  3116. if (argc == 0)
  3117. return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
  3118. return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
  3119. }
  3120. ALIAS (no_set_vpnv4_nexthop,
  3121. no_set_vpnv4_nexthop_val_cmd,
  3122. "no set vpnv4 next-hop A.B.C.D",
  3123. NO_STR
  3124. SET_STR
  3125. "VPNv4 information\n"
  3126. "VPNv4 next-hop address\n"
  3127. "IP address of next hop\n")
  3128. DEFUN (set_originator_id,
  3129. set_originator_id_cmd,
  3130. "set originator-id A.B.C.D",
  3131. SET_STR
  3132. "BGP originator ID attribute\n"
  3133. "IP address of originator\n")
  3134. {
  3135. return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
  3136. }
  3137. DEFUN (no_set_originator_id,
  3138. no_set_originator_id_cmd,
  3139. "no set originator-id",
  3140. NO_STR
  3141. SET_STR
  3142. "BGP originator ID attribute\n")
  3143. {
  3144. if (argc == 0)
  3145. return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
  3146. return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
  3147. }
  3148. ALIAS (no_set_originator_id,
  3149. no_set_originator_id_val_cmd,
  3150. "no set originator-id A.B.C.D",
  3151. NO_STR
  3152. SET_STR
  3153. "BGP originator ID attribute\n"
  3154. "IP address of originator\n")
  3155. DEFUN_DEPRECATED (set_pathlimit_ttl,
  3156. set_pathlimit_ttl_cmd,
  3157. "set pathlimit ttl <1-255>",
  3158. SET_STR
  3159. "BGP AS-Pathlimit attribute\n"
  3160. "Set AS-Path Hop-count TTL\n")
  3161. {
  3162. return CMD_SUCCESS;
  3163. }
  3164. DEFUN_DEPRECATED (no_set_pathlimit_ttl,
  3165. no_set_pathlimit_ttl_cmd,
  3166. "no set pathlimit ttl",
  3167. NO_STR
  3168. SET_STR
  3169. "BGP AS-Pathlimit attribute\n"
  3170. "Set AS-Path Hop-count TTL\n")
  3171. {
  3172. return CMD_SUCCESS;
  3173. }
  3174. ALIAS (no_set_pathlimit_ttl,
  3175. no_set_pathlimit_ttl_val_cmd,
  3176. "no set pathlimit ttl <1-255>",
  3177. NO_STR
  3178. MATCH_STR
  3179. "BGP AS-Pathlimit attribute\n"
  3180. "Set AS-Path Hop-count TTL\n")
  3181. DEFUN_DEPRECATED (match_pathlimit_as,
  3182. match_pathlimit_as_cmd,
  3183. "match pathlimit as <1-65535>",
  3184. MATCH_STR
  3185. "BGP AS-Pathlimit attribute\n"
  3186. "Match Pathlimit AS number\n")
  3187. {
  3188. return CMD_SUCCESS;
  3189. }
  3190. DEFUN_DEPRECATED (no_match_pathlimit_as,
  3191. no_match_pathlimit_as_cmd,
  3192. "no match pathlimit as",
  3193. NO_STR
  3194. MATCH_STR
  3195. "BGP AS-Pathlimit attribute\n"
  3196. "Match Pathlimit AS number\n")
  3197. {
  3198. return CMD_SUCCESS;
  3199. }
  3200. ALIAS (no_match_pathlimit_as,
  3201. no_match_pathlimit_as_val_cmd,
  3202. "no match pathlimit as <1-65535>",
  3203. NO_STR
  3204. MATCH_STR
  3205. "BGP AS-Pathlimit attribute\n"
  3206. "Match Pathlimit ASN\n")
  3207. /* Initialization of route map. */
  3208. void
  3209. bgp_route_map_init (void)
  3210. {
  3211. route_map_init ();
  3212. route_map_init_vty ();
  3213. route_map_add_hook (bgp_route_map_update);
  3214. route_map_delete_hook (bgp_route_map_update);
  3215. route_map_install_match (&route_match_peer_cmd);
  3216. route_map_install_match (&route_match_ip_address_cmd);
  3217. route_map_install_match (&route_match_ip_next_hop_cmd);
  3218. route_map_install_match (&route_match_ip_route_source_cmd);
  3219. route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  3220. route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  3221. route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
  3222. route_map_install_match (&route_match_aspath_cmd);
  3223. route_map_install_match (&route_match_community_cmd);
  3224. route_map_install_match (&route_match_ecommunity_cmd);
  3225. route_map_install_match (&route_match_metric_cmd);
  3226. route_map_install_match (&route_match_origin_cmd);
  3227. route_map_install_match (&route_match_probability_cmd);
  3228. route_map_install_set (&route_set_ip_nexthop_cmd);
  3229. route_map_install_set (&route_set_local_pref_cmd);
  3230. route_map_install_set (&route_set_weight_cmd);
  3231. route_map_install_set (&route_set_metric_cmd);
  3232. route_map_install_set (&route_set_aspath_prepend_cmd);
  3233. route_map_install_set (&route_set_aspath_exclude_cmd);
  3234. route_map_install_set (&route_set_origin_cmd);
  3235. route_map_install_set (&route_set_atomic_aggregate_cmd);
  3236. route_map_install_set (&route_set_aggregator_as_cmd);
  3237. route_map_install_set (&route_set_community_cmd);
  3238. route_map_install_set (&route_set_community_delete_cmd);
  3239. route_map_install_set (&route_set_vpnv4_nexthop_cmd);
  3240. route_map_install_set (&route_set_originator_id_cmd);
  3241. route_map_install_set (&route_set_ecommunity_rt_cmd);
  3242. route_map_install_set (&route_set_ecommunity_soo_cmd);
  3243. install_element (RMAP_NODE, &match_peer_cmd);
  3244. install_element (RMAP_NODE, &match_peer_local_cmd);
  3245. install_element (RMAP_NODE, &no_match_peer_cmd);
  3246. install_element (RMAP_NODE, &no_match_peer_val_cmd);
  3247. install_element (RMAP_NODE, &no_match_peer_local_cmd);
  3248. install_element (RMAP_NODE, &match_ip_address_cmd);
  3249. install_element (RMAP_NODE, &no_match_ip_address_cmd);
  3250. install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  3251. install_element (RMAP_NODE, &match_ip_next_hop_cmd);
  3252. install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
  3253. install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
  3254. install_element (RMAP_NODE, &match_ip_route_source_cmd);
  3255. install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
  3256. install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
  3257. install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  3258. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  3259. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  3260. install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  3261. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  3262. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  3263. install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
  3264. install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
  3265. install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
  3266. install_element (RMAP_NODE, &match_aspath_cmd);
  3267. install_element (RMAP_NODE, &no_match_aspath_cmd);
  3268. install_element (RMAP_NODE, &no_match_aspath_val_cmd);
  3269. install_element (RMAP_NODE, &match_metric_cmd);
  3270. install_element (RMAP_NODE, &no_match_metric_cmd);
  3271. install_element (RMAP_NODE, &no_match_metric_val_cmd);
  3272. install_element (RMAP_NODE, &match_community_cmd);
  3273. install_element (RMAP_NODE, &match_community_exact_cmd);
  3274. install_element (RMAP_NODE, &no_match_community_cmd);
  3275. install_element (RMAP_NODE, &no_match_community_val_cmd);
  3276. install_element (RMAP_NODE, &no_match_community_exact_cmd);
  3277. install_element (RMAP_NODE, &match_ecommunity_cmd);
  3278. install_element (RMAP_NODE, &no_match_ecommunity_cmd);
  3279. install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
  3280. install_element (RMAP_NODE, &match_origin_cmd);
  3281. install_element (RMAP_NODE, &no_match_origin_cmd);
  3282. install_element (RMAP_NODE, &no_match_origin_val_cmd);
  3283. install_element (RMAP_NODE, &match_probability_cmd);
  3284. install_element (RMAP_NODE, &no_match_probability_cmd);
  3285. install_element (RMAP_NODE, &no_match_probability_val_cmd);
  3286. install_element (RMAP_NODE, &set_ip_nexthop_cmd);
  3287. install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
  3288. install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
  3289. install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
  3290. install_element (RMAP_NODE, &set_local_pref_cmd);
  3291. install_element (RMAP_NODE, &no_set_local_pref_cmd);
  3292. install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
  3293. install_element (RMAP_NODE, &set_weight_cmd);
  3294. install_element (RMAP_NODE, &no_set_weight_cmd);
  3295. install_element (RMAP_NODE, &no_set_weight_val_cmd);
  3296. install_element (RMAP_NODE, &set_metric_cmd);
  3297. install_element (RMAP_NODE, &set_metric_addsub_cmd);
  3298. install_element (RMAP_NODE, &no_set_metric_cmd);
  3299. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  3300. install_element (RMAP_NODE, &set_aspath_prepend_cmd);
  3301. install_element (RMAP_NODE, &set_aspath_exclude_cmd);
  3302. install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
  3303. install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
  3304. install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
  3305. install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
  3306. install_element (RMAP_NODE, &set_origin_cmd);
  3307. install_element (RMAP_NODE, &no_set_origin_cmd);
  3308. install_element (RMAP_NODE, &no_set_origin_val_cmd);
  3309. install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
  3310. install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
  3311. install_element (RMAP_NODE, &set_aggregator_as_cmd);
  3312. install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
  3313. install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
  3314. install_element (RMAP_NODE, &set_community_cmd);
  3315. install_element (RMAP_NODE, &set_community_none_cmd);
  3316. install_element (RMAP_NODE, &no_set_community_cmd);
  3317. install_element (RMAP_NODE, &no_set_community_val_cmd);
  3318. install_element (RMAP_NODE, &no_set_community_none_cmd);
  3319. install_element (RMAP_NODE, &set_community_delete_cmd);
  3320. install_element (RMAP_NODE, &no_set_community_delete_cmd);
  3321. install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
  3322. install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
  3323. install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
  3324. install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
  3325. install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
  3326. install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
  3327. install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
  3328. install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
  3329. install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
  3330. install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
  3331. install_element (RMAP_NODE, &set_originator_id_cmd);
  3332. install_element (RMAP_NODE, &no_set_originator_id_cmd);
  3333. install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
  3334. #ifdef HAVE_IPV6
  3335. route_map_install_match (&route_match_ipv6_address_cmd);
  3336. route_map_install_match (&route_match_ipv6_next_hop_cmd);
  3337. route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
  3338. route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
  3339. route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
  3340. install_element (RMAP_NODE, &match_ipv6_address_cmd);
  3341. install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
  3342. install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
  3343. install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
  3344. install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
  3345. install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
  3346. install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
  3347. install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
  3348. install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
  3349. install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
  3350. install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
  3351. install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
  3352. #endif /* HAVE_IPV6 */
  3353. /* AS-Pathlimit: functionality removed, commands kept for
  3354. * compatibility.
  3355. */
  3356. install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
  3357. install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
  3358. install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
  3359. install_element (RMAP_NODE, &match_pathlimit_as_cmd);
  3360. install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
  3361. install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
  3362. }