bgp_routemap.c 99 KB

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