bgp_routemap.c 101 KB

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