bgp_routemap.c 99 KB

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