plist.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860
  1. /* Prefix list functions.
  2. * Copyright (C) 1999 Kunihiro Ishiguro
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation; either version 2, or (at your
  9. * option) any later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "prefix.h"
  23. #include "command.h"
  24. #include "memory.h"
  25. #include "plist.h"
  26. #include "sockunion.h"
  27. #include "buffer.h"
  28. #include "stream.h"
  29. #include "log.h"
  30. /* Each prefix-list's entry. */
  31. struct prefix_list_entry
  32. {
  33. int seq;
  34. int le;
  35. int ge;
  36. enum prefix_list_type type;
  37. int any;
  38. struct prefix prefix;
  39. unsigned long refcnt;
  40. unsigned long hitcnt;
  41. struct prefix_list_entry *next;
  42. struct prefix_list_entry *prev;
  43. };
  44. /* List of struct prefix_list. */
  45. struct prefix_list_list
  46. {
  47. struct prefix_list *head;
  48. struct prefix_list *tail;
  49. };
  50. /* Master structure of prefix_list. */
  51. struct prefix_master
  52. {
  53. /* List of prefix_list which name is number. */
  54. struct prefix_list_list num;
  55. /* List of prefix_list which name is string. */
  56. struct prefix_list_list str;
  57. /* Whether sequential number is used. */
  58. int seqnum;
  59. /* The latest update. */
  60. struct prefix_list *recent;
  61. /* Hook function which is executed when new prefix_list is added. */
  62. void (*add_hook) (struct prefix_list *);
  63. /* Hook function which is executed when prefix_list is deleted. */
  64. void (*delete_hook) (struct prefix_list *);
  65. };
  66. /* Static structure of IPv4 prefix_list's master. */
  67. static struct prefix_master prefix_master_ipv4 =
  68. {
  69. {NULL, NULL},
  70. {NULL, NULL},
  71. 1,
  72. NULL,
  73. NULL,
  74. };
  75. #ifdef HAVE_IPV6
  76. /* Static structure of IPv6 prefix-list's master. */
  77. static struct prefix_master prefix_master_ipv6 =
  78. {
  79. {NULL, NULL},
  80. {NULL, NULL},
  81. 1,
  82. NULL,
  83. NULL,
  84. };
  85. #endif /* HAVE_IPV6*/
  86. /* Static structure of BGP ORF prefix_list's master. */
  87. static struct prefix_master prefix_master_orf =
  88. {
  89. {NULL, NULL},
  90. {NULL, NULL},
  91. 1,
  92. NULL,
  93. NULL,
  94. };
  95. static struct prefix_master *
  96. prefix_master_get (afi_t afi)
  97. {
  98. if (afi == AFI_IP)
  99. return &prefix_master_ipv4;
  100. #ifdef HAVE_IPV6
  101. else if (afi == AFI_IP6)
  102. return &prefix_master_ipv6;
  103. #endif /* HAVE_IPV6 */
  104. else if (afi == AFI_ORF_PREFIX)
  105. return &prefix_master_orf;
  106. return NULL;
  107. }
  108. /* Lookup prefix_list from list of prefix_list by name. */
  109. struct prefix_list *
  110. prefix_list_lookup (afi_t afi, const char *name)
  111. {
  112. struct prefix_list *plist;
  113. struct prefix_master *master;
  114. if (name == NULL)
  115. return NULL;
  116. master = prefix_master_get (afi);
  117. if (master == NULL)
  118. return NULL;
  119. for (plist = master->num.head; plist; plist = plist->next)
  120. if (strcmp (plist->name, name) == 0)
  121. return plist;
  122. for (plist = master->str.head; plist; plist = plist->next)
  123. if (strcmp (plist->name, name) == 0)
  124. return plist;
  125. return NULL;
  126. }
  127. static struct prefix_list *
  128. prefix_list_new (void)
  129. {
  130. struct prefix_list *new;
  131. new = XCALLOC (MTYPE_PREFIX_LIST, sizeof (struct prefix_list));
  132. return new;
  133. }
  134. static void
  135. prefix_list_free (struct prefix_list *plist)
  136. {
  137. XFREE (MTYPE_PREFIX_LIST, plist);
  138. }
  139. static struct prefix_list_entry *
  140. prefix_list_entry_new (void)
  141. {
  142. struct prefix_list_entry *new;
  143. new = XCALLOC (MTYPE_PREFIX_LIST_ENTRY, sizeof (struct prefix_list_entry));
  144. return new;
  145. }
  146. static void
  147. prefix_list_entry_free (struct prefix_list_entry *pentry)
  148. {
  149. XFREE (MTYPE_PREFIX_LIST_ENTRY, pentry);
  150. }
  151. /* Insert new prefix list to list of prefix_list. Each prefix_list
  152. is sorted by the name. */
  153. static struct prefix_list *
  154. prefix_list_insert (afi_t afi, const char *name)
  155. {
  156. unsigned int i;
  157. long number;
  158. struct prefix_list *plist;
  159. struct prefix_list *point;
  160. struct prefix_list_list *list;
  161. struct prefix_master *master;
  162. master = prefix_master_get (afi);
  163. if (master == NULL)
  164. return NULL;
  165. /* Allocate new prefix_list and copy given name. */
  166. plist = prefix_list_new ();
  167. plist->name = XSTRDUP (MTYPE_PREFIX_LIST_STR, name);
  168. plist->master = master;
  169. /* If name is made by all digit character. We treat it as
  170. number. */
  171. for (number = 0, i = 0; i < strlen (name); i++)
  172. {
  173. if (isdigit ((int) name[i]))
  174. number = (number * 10) + (name[i] - '0');
  175. else
  176. break;
  177. }
  178. /* In case of name is all digit character */
  179. if (i == strlen (name))
  180. {
  181. plist->type = PREFIX_TYPE_NUMBER;
  182. /* Set prefix_list to number list. */
  183. list = &master->num;
  184. for (point = list->head; point; point = point->next)
  185. if (atol (point->name) >= number)
  186. break;
  187. }
  188. else
  189. {
  190. plist->type = PREFIX_TYPE_STRING;
  191. /* Set prefix_list to string list. */
  192. list = &master->str;
  193. /* Set point to insertion point. */
  194. for (point = list->head; point; point = point->next)
  195. if (strcmp (point->name, name) >= 0)
  196. break;
  197. }
  198. /* In case of this is the first element of master. */
  199. if (list->head == NULL)
  200. {
  201. list->head = list->tail = plist;
  202. return plist;
  203. }
  204. /* In case of insertion is made at the tail of access_list. */
  205. if (point == NULL)
  206. {
  207. plist->prev = list->tail;
  208. list->tail->next = plist;
  209. list->tail = plist;
  210. return plist;
  211. }
  212. /* In case of insertion is made at the head of access_list. */
  213. if (point == list->head)
  214. {
  215. plist->next = list->head;
  216. list->head->prev = plist;
  217. list->head = plist;
  218. return plist;
  219. }
  220. /* Insertion is made at middle of the access_list. */
  221. plist->next = point;
  222. plist->prev = point->prev;
  223. if (point->prev)
  224. point->prev->next = plist;
  225. point->prev = plist;
  226. return plist;
  227. }
  228. static struct prefix_list *
  229. prefix_list_get (afi_t afi, const char *name)
  230. {
  231. struct prefix_list *plist;
  232. plist = prefix_list_lookup (afi, name);
  233. if (plist == NULL)
  234. plist = prefix_list_insert (afi, name);
  235. return plist;
  236. }
  237. /* Delete prefix-list from prefix_list_master and free it. */
  238. static void
  239. prefix_list_delete (struct prefix_list *plist)
  240. {
  241. struct prefix_list_list *list;
  242. struct prefix_master *master;
  243. struct prefix_list_entry *pentry;
  244. struct prefix_list_entry *next;
  245. /* If prefix-list contain prefix_list_entry free all of it. */
  246. for (pentry = plist->head; pentry; pentry = next)
  247. {
  248. next = pentry->next;
  249. prefix_list_entry_free (pentry);
  250. plist->count--;
  251. }
  252. master = plist->master;
  253. if (plist->type == PREFIX_TYPE_NUMBER)
  254. list = &master->num;
  255. else
  256. list = &master->str;
  257. if (plist->next)
  258. plist->next->prev = plist->prev;
  259. else
  260. list->tail = plist->prev;
  261. if (plist->prev)
  262. plist->prev->next = plist->next;
  263. else
  264. list->head = plist->next;
  265. if (plist->desc)
  266. XFREE (MTYPE_TMP, plist->desc);
  267. /* Make sure master's recent changed prefix-list information is
  268. cleared. */
  269. master->recent = NULL;
  270. if (plist->name)
  271. XFREE (MTYPE_PREFIX_LIST_STR, plist->name);
  272. prefix_list_free (plist);
  273. if (master->delete_hook)
  274. (*master->delete_hook) (NULL);
  275. }
  276. static struct prefix_list_entry *
  277. prefix_list_entry_make (struct prefix *prefix, enum prefix_list_type type,
  278. int seq, int le, int ge, int any)
  279. {
  280. struct prefix_list_entry *pentry;
  281. pentry = prefix_list_entry_new ();
  282. if (any)
  283. pentry->any = 1;
  284. prefix_copy (&pentry->prefix, prefix);
  285. pentry->type = type;
  286. pentry->seq = seq;
  287. pentry->le = le;
  288. pentry->ge = ge;
  289. return pentry;
  290. }
  291. /* Add hook function. */
  292. void
  293. prefix_list_add_hook (void (*func) (struct prefix_list *plist))
  294. {
  295. prefix_master_ipv4.add_hook = func;
  296. #ifdef HAVE_IPV6
  297. prefix_master_ipv6.add_hook = func;
  298. #endif /* HAVE_IPV6 */
  299. }
  300. /* Delete hook function. */
  301. void
  302. prefix_list_delete_hook (void (*func) (struct prefix_list *plist))
  303. {
  304. prefix_master_ipv4.delete_hook = func;
  305. #ifdef HAVE_IPV6
  306. prefix_master_ipv6.delete_hook = func;
  307. #endif /* HAVE_IPVt6 */
  308. }
  309. /* Calculate new sequential number. */
  310. static int
  311. prefix_new_seq_get (struct prefix_list *plist)
  312. {
  313. int maxseq;
  314. int newseq;
  315. struct prefix_list_entry *pentry;
  316. maxseq = newseq = 0;
  317. for (pentry = plist->head; pentry; pentry = pentry->next)
  318. {
  319. if (maxseq < pentry->seq)
  320. maxseq = pentry->seq;
  321. }
  322. newseq = ((maxseq / 5) * 5) + 5;
  323. return newseq;
  324. }
  325. /* Return prefix list entry which has same seq number. */
  326. static struct prefix_list_entry *
  327. prefix_seq_check (struct prefix_list *plist, int seq)
  328. {
  329. struct prefix_list_entry *pentry;
  330. for (pentry = plist->head; pentry; pentry = pentry->next)
  331. if (pentry->seq == seq)
  332. return pentry;
  333. return NULL;
  334. }
  335. static struct prefix_list_entry *
  336. prefix_list_entry_lookup (struct prefix_list *plist, struct prefix *prefix,
  337. enum prefix_list_type type, int seq, int le, int ge)
  338. {
  339. struct prefix_list_entry *pentry;
  340. for (pentry = plist->head; pentry; pentry = pentry->next)
  341. if (prefix_same (&pentry->prefix, prefix) && pentry->type == type)
  342. {
  343. if (seq >= 0 && pentry->seq != seq)
  344. continue;
  345. if (pentry->le != le)
  346. continue;
  347. if (pentry->ge != ge)
  348. continue;
  349. return pentry;
  350. }
  351. return NULL;
  352. }
  353. static void
  354. prefix_list_entry_delete (struct prefix_list *plist,
  355. struct prefix_list_entry *pentry,
  356. int update_list)
  357. {
  358. if (plist == NULL || pentry == NULL)
  359. return;
  360. if (pentry->prev)
  361. pentry->prev->next = pentry->next;
  362. else
  363. plist->head = pentry->next;
  364. if (pentry->next)
  365. pentry->next->prev = pentry->prev;
  366. else
  367. plist->tail = pentry->prev;
  368. prefix_list_entry_free (pentry);
  369. plist->count--;
  370. if (update_list)
  371. {
  372. if (plist->master->delete_hook)
  373. (*plist->master->delete_hook) (plist);
  374. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  375. prefix_list_delete (plist);
  376. else
  377. plist->master->recent = plist;
  378. }
  379. }
  380. static void
  381. prefix_list_entry_add (struct prefix_list *plist,
  382. struct prefix_list_entry *pentry)
  383. {
  384. struct prefix_list_entry *replace;
  385. struct prefix_list_entry *point;
  386. /* Automatic asignment of seq no. */
  387. if (pentry->seq == -1)
  388. pentry->seq = prefix_new_seq_get (plist);
  389. /* Is there any same seq prefix list entry? */
  390. replace = prefix_seq_check (plist, pentry->seq);
  391. if (replace)
  392. prefix_list_entry_delete (plist, replace, 0);
  393. /* Check insert point. */
  394. for (point = plist->head; point; point = point->next)
  395. if (point->seq >= pentry->seq)
  396. break;
  397. /* In case of this is the first element of the list. */
  398. pentry->next = point;
  399. if (point)
  400. {
  401. if (point->prev)
  402. point->prev->next = pentry;
  403. else
  404. plist->head = pentry;
  405. pentry->prev = point->prev;
  406. point->prev = pentry;
  407. }
  408. else
  409. {
  410. if (plist->tail)
  411. plist->tail->next = pentry;
  412. else
  413. plist->head = pentry;
  414. pentry->prev = plist->tail;
  415. plist->tail = pentry;
  416. }
  417. /* Increment count. */
  418. plist->count++;
  419. /* Run hook function. */
  420. if (plist->master->add_hook)
  421. (*plist->master->add_hook) (plist);
  422. plist->master->recent = plist;
  423. }
  424. /* Return string of prefix_list_type. */
  425. static const char *
  426. prefix_list_type_str (struct prefix_list_entry *pentry)
  427. {
  428. switch (pentry->type)
  429. {
  430. case PREFIX_PERMIT:
  431. return "permit";
  432. case PREFIX_DENY:
  433. return "deny";
  434. default:
  435. return "";
  436. }
  437. }
  438. static int
  439. prefix_list_entry_match (struct prefix_list_entry *pentry, struct prefix *p)
  440. {
  441. int ret;
  442. ret = prefix_match (&pentry->prefix, p);
  443. if (! ret)
  444. return 0;
  445. /* In case of le nor ge is specified, exact match is performed. */
  446. if (! pentry->le && ! pentry->ge)
  447. {
  448. if (pentry->prefix.prefixlen != p->prefixlen)
  449. return 0;
  450. }
  451. else
  452. {
  453. if (pentry->le)
  454. if (p->prefixlen > pentry->le)
  455. return 0;
  456. if (pentry->ge)
  457. if (p->prefixlen < pentry->ge)
  458. return 0;
  459. }
  460. return 1;
  461. }
  462. enum prefix_list_type
  463. prefix_list_apply (struct prefix_list *plist, void *object)
  464. {
  465. struct prefix_list_entry *pentry;
  466. struct prefix *p;
  467. p = (struct prefix *) object;
  468. if (plist == NULL)
  469. return PREFIX_DENY;
  470. if (plist->count == 0)
  471. return PREFIX_PERMIT;
  472. for (pentry = plist->head; pentry; pentry = pentry->next)
  473. {
  474. pentry->refcnt++;
  475. if (prefix_list_entry_match (pentry, p))
  476. {
  477. pentry->hitcnt++;
  478. return pentry->type;
  479. }
  480. }
  481. return PREFIX_DENY;
  482. }
  483. static void __attribute__ ((unused))
  484. prefix_list_print (struct prefix_list *plist)
  485. {
  486. struct prefix_list_entry *pentry;
  487. if (plist == NULL)
  488. return;
  489. printf ("ip prefix-list %s: %d entries\n", plist->name, plist->count);
  490. for (pentry = plist->head; pentry; pentry = pentry->next)
  491. {
  492. if (pentry->any)
  493. printf ("any %s\n", prefix_list_type_str (pentry));
  494. else
  495. {
  496. struct prefix *p;
  497. char buf[BUFSIZ];
  498. p = &pentry->prefix;
  499. printf (" seq %d %s %s/%d",
  500. pentry->seq,
  501. prefix_list_type_str (pentry),
  502. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  503. p->prefixlen);
  504. if (pentry->ge)
  505. printf (" ge %d", pentry->ge);
  506. if (pentry->le)
  507. printf (" le %d", pentry->le);
  508. printf ("\n");
  509. }
  510. }
  511. }
  512. /* Retrun 1 when plist already include pentry policy. */
  513. static struct prefix_list_entry *
  514. prefix_entry_dup_check (struct prefix_list *plist,
  515. struct prefix_list_entry *new)
  516. {
  517. struct prefix_list_entry *pentry;
  518. int seq = 0;
  519. if (new->seq == -1)
  520. seq = prefix_new_seq_get (plist);
  521. else
  522. seq = new->seq;
  523. for (pentry = plist->head; pentry; pentry = pentry->next)
  524. {
  525. if (prefix_same (&pentry->prefix, &new->prefix)
  526. && pentry->type == new->type
  527. && pentry->le == new->le
  528. && pentry->ge == new->ge
  529. && pentry->seq != seq)
  530. return pentry;
  531. }
  532. return NULL;
  533. }
  534. static int
  535. vty_invalid_prefix_range (struct vty *vty, const char *prefix)
  536. {
  537. vty_out (vty, "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value%s",
  538. prefix, VTY_NEWLINE);
  539. return CMD_WARNING;
  540. }
  541. static int
  542. vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
  543. const char *seq, const char *typestr,
  544. const char *prefix, const char *ge, const char *le)
  545. {
  546. int ret;
  547. enum prefix_list_type type;
  548. struct prefix_list *plist;
  549. struct prefix_list_entry *pentry;
  550. struct prefix_list_entry *dup;
  551. struct prefix p;
  552. int any = 0;
  553. int seqnum = -1;
  554. int lenum = 0;
  555. int genum = 0;
  556. /* Sequential number. */
  557. if (seq)
  558. seqnum = atoi (seq);
  559. /* ge and le number */
  560. if (ge)
  561. genum = atoi (ge);
  562. if (le)
  563. lenum = atoi (le);
  564. /* Check filter type. */
  565. if (strncmp ("permit", typestr, 1) == 0)
  566. type = PREFIX_PERMIT;
  567. else if (strncmp ("deny", typestr, 1) == 0)
  568. type = PREFIX_DENY;
  569. else
  570. {
  571. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  572. return CMD_WARNING;
  573. }
  574. /* "any" is special token for matching any IPv4 addresses. */
  575. if (afi == AFI_IP)
  576. {
  577. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  578. {
  579. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  580. genum = 0;
  581. lenum = IPV4_MAX_BITLEN;
  582. any = 1;
  583. }
  584. else
  585. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  586. if (ret <= 0)
  587. {
  588. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  589. return CMD_WARNING;
  590. }
  591. }
  592. #ifdef HAVE_IPV6
  593. else if (afi == AFI_IP6)
  594. {
  595. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  596. {
  597. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  598. genum = 0;
  599. lenum = IPV6_MAX_BITLEN;
  600. any = 1;
  601. }
  602. else
  603. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  604. if (ret <= 0)
  605. {
  606. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  607. return CMD_WARNING;
  608. }
  609. }
  610. #endif /* HAVE_IPV6 */
  611. /* ge and le check. */
  612. if (genum && genum <= p.prefixlen)
  613. return vty_invalid_prefix_range (vty, prefix);
  614. if (lenum && lenum <= p.prefixlen)
  615. return vty_invalid_prefix_range (vty, prefix);
  616. if (lenum && genum > lenum)
  617. return vty_invalid_prefix_range (vty, prefix);
  618. if (genum && lenum == (afi == AFI_IP ? 32 : 128))
  619. lenum = 0;
  620. /* Get prefix_list with name. */
  621. plist = prefix_list_get (afi, name);
  622. /* Make prefix entry. */
  623. pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
  624. /* Check same policy. */
  625. dup = prefix_entry_dup_check (plist, pentry);
  626. if (dup)
  627. {
  628. prefix_list_entry_free (pentry);
  629. vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
  630. VTY_NEWLINE);
  631. vty_out (vty, " seq %d %s %s", dup->seq, typestr, prefix);
  632. if (! any && genum)
  633. vty_out (vty, " ge %d", genum);
  634. if (! any && lenum)
  635. vty_out (vty, " le %d", lenum);
  636. vty_out (vty, "%s", VTY_NEWLINE);
  637. return CMD_WARNING;
  638. }
  639. /* Install new filter to the access_list. */
  640. prefix_list_entry_add (plist, pentry);
  641. return CMD_SUCCESS;
  642. }
  643. static int
  644. vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
  645. const char *seq, const char *typestr,
  646. const char *prefix, const char *ge, const char *le)
  647. {
  648. int ret;
  649. enum prefix_list_type type;
  650. struct prefix_list *plist;
  651. struct prefix_list_entry *pentry;
  652. struct prefix p;
  653. int seqnum = -1;
  654. int lenum = 0;
  655. int genum = 0;
  656. /* Check prefix list name. */
  657. plist = prefix_list_lookup (afi, name);
  658. if (! plist)
  659. {
  660. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  661. return CMD_WARNING;
  662. }
  663. /* Only prefix-list name specified, delete the entire prefix-list. */
  664. if (seq == NULL && typestr == NULL && prefix == NULL &&
  665. ge == NULL && le == NULL)
  666. {
  667. prefix_list_delete (plist);
  668. return CMD_SUCCESS;
  669. }
  670. /* We must have, at a minimum, both the type and prefix here */
  671. if ((typestr == NULL) || (prefix == NULL))
  672. {
  673. vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
  674. return CMD_WARNING;
  675. }
  676. /* Check sequence number. */
  677. if (seq)
  678. seqnum = atoi (seq);
  679. /* ge and le number */
  680. if (ge)
  681. genum = atoi (ge);
  682. if (le)
  683. lenum = atoi (le);
  684. /* Check of filter type. */
  685. if (strncmp ("permit", typestr, 1) == 0)
  686. type = PREFIX_PERMIT;
  687. else if (strncmp ("deny", typestr, 1) == 0)
  688. type = PREFIX_DENY;
  689. else
  690. {
  691. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  692. return CMD_WARNING;
  693. }
  694. /* "any" is special token for matching any IPv4 addresses. */
  695. if (afi == AFI_IP)
  696. {
  697. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  698. {
  699. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  700. genum = 0;
  701. lenum = IPV4_MAX_BITLEN;
  702. }
  703. else
  704. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  705. if (ret <= 0)
  706. {
  707. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  708. return CMD_WARNING;
  709. }
  710. }
  711. #ifdef HAVE_IPV6
  712. else if (afi == AFI_IP6)
  713. {
  714. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  715. {
  716. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  717. genum = 0;
  718. lenum = IPV6_MAX_BITLEN;
  719. }
  720. else
  721. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  722. if (ret <= 0)
  723. {
  724. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  725. return CMD_WARNING;
  726. }
  727. }
  728. #endif /* HAVE_IPV6 */
  729. /* Lookup prefix entry. */
  730. pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
  731. if (pentry == NULL)
  732. {
  733. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  734. return CMD_WARNING;
  735. }
  736. /* Install new filter to the access_list. */
  737. prefix_list_entry_delete (plist, pentry, 1);
  738. return CMD_SUCCESS;
  739. }
  740. static int
  741. vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
  742. {
  743. struct prefix_list *plist;
  744. plist = prefix_list_lookup (afi, name);
  745. if (! plist)
  746. {
  747. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  748. return CMD_WARNING;
  749. }
  750. if (plist->desc)
  751. {
  752. XFREE (MTYPE_TMP, plist->desc);
  753. plist->desc = NULL;
  754. }
  755. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  756. prefix_list_delete (plist);
  757. return CMD_SUCCESS;
  758. }
  759. enum display_type
  760. {
  761. normal_display,
  762. summary_display,
  763. detail_display,
  764. sequential_display,
  765. longer_display,
  766. first_match_display
  767. };
  768. static void
  769. vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
  770. struct prefix_master *master, enum display_type dtype,
  771. int seqnum)
  772. {
  773. struct prefix_list_entry *pentry;
  774. /* Print the name of the protocol */
  775. if (zlog_default)
  776. vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
  777. if (dtype == normal_display)
  778. {
  779. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  780. afi == AFI_IP ? "" : "v6",
  781. plist->name, plist->count, VTY_NEWLINE);
  782. if (plist->desc)
  783. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  784. }
  785. else if (dtype == summary_display || dtype == detail_display)
  786. {
  787. vty_out (vty, "ip%s prefix-list %s:%s",
  788. afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
  789. if (plist->desc)
  790. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  791. vty_out (vty, " count: %d, range entries: %d, sequences: %d - %d%s",
  792. plist->count, plist->rangecount,
  793. plist->head ? plist->head->seq : 0,
  794. plist->tail ? plist->tail->seq : 0,
  795. VTY_NEWLINE);
  796. }
  797. if (dtype != summary_display)
  798. {
  799. for (pentry = plist->head; pentry; pentry = pentry->next)
  800. {
  801. if (dtype == sequential_display && pentry->seq != seqnum)
  802. continue;
  803. vty_out (vty, " ");
  804. if (master->seqnum)
  805. vty_out (vty, "seq %d ", pentry->seq);
  806. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  807. if (pentry->any)
  808. vty_out (vty, "any");
  809. else
  810. {
  811. struct prefix *p = &pentry->prefix;
  812. char buf[BUFSIZ];
  813. vty_out (vty, "%s/%d",
  814. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  815. p->prefixlen);
  816. if (pentry->ge)
  817. vty_out (vty, " ge %d", pentry->ge);
  818. if (pentry->le)
  819. vty_out (vty, " le %d", pentry->le);
  820. }
  821. if (dtype == detail_display || dtype == sequential_display)
  822. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  823. pentry->hitcnt, pentry->refcnt);
  824. vty_out (vty, "%s", VTY_NEWLINE);
  825. }
  826. }
  827. }
  828. static int
  829. vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
  830. const char *seq, enum display_type dtype)
  831. {
  832. struct prefix_list *plist;
  833. struct prefix_master *master;
  834. int seqnum = 0;
  835. master = prefix_master_get (afi);
  836. if (master == NULL)
  837. return CMD_WARNING;
  838. if (seq)
  839. seqnum = atoi (seq);
  840. if (name)
  841. {
  842. plist = prefix_list_lookup (afi, name);
  843. if (! plist)
  844. {
  845. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  846. return CMD_WARNING;
  847. }
  848. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  849. }
  850. else
  851. {
  852. if (dtype == detail_display || dtype == summary_display)
  853. {
  854. if (master->recent)
  855. vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
  856. master->recent->name, VTY_NEWLINE);
  857. }
  858. for (plist = master->num.head; plist; plist = plist->next)
  859. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  860. for (plist = master->str.head; plist; plist = plist->next)
  861. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  862. }
  863. return CMD_SUCCESS;
  864. }
  865. static int
  866. vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
  867. const char *prefix, enum display_type type)
  868. {
  869. struct prefix_list *plist;
  870. struct prefix_list_entry *pentry;
  871. struct prefix p;
  872. int ret;
  873. int match;
  874. plist = prefix_list_lookup (afi, name);
  875. if (! plist)
  876. {
  877. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  878. return CMD_WARNING;
  879. }
  880. ret = str2prefix (prefix, &p);
  881. if (ret <= 0)
  882. {
  883. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  884. return CMD_WARNING;
  885. }
  886. for (pentry = plist->head; pentry; pentry = pentry->next)
  887. {
  888. match = 0;
  889. if (type == normal_display || type == first_match_display)
  890. if (prefix_same (&p, &pentry->prefix))
  891. match = 1;
  892. if (type == longer_display)
  893. if (prefix_match (&p, &pentry->prefix))
  894. match = 1;
  895. if (match)
  896. {
  897. vty_out (vty, " seq %d %s ",
  898. pentry->seq,
  899. prefix_list_type_str (pentry));
  900. if (pentry->any)
  901. vty_out (vty, "any");
  902. else
  903. {
  904. struct prefix *p = &pentry->prefix;
  905. char buf[BUFSIZ];
  906. vty_out (vty, "%s/%d",
  907. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  908. p->prefixlen);
  909. if (pentry->ge)
  910. vty_out (vty, " ge %d", pentry->ge);
  911. if (pentry->le)
  912. vty_out (vty, " le %d", pentry->le);
  913. }
  914. if (type == normal_display || type == first_match_display)
  915. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  916. pentry->hitcnt, pentry->refcnt);
  917. vty_out (vty, "%s", VTY_NEWLINE);
  918. if (type == first_match_display)
  919. return CMD_SUCCESS;
  920. }
  921. }
  922. return CMD_SUCCESS;
  923. }
  924. static int
  925. vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
  926. const char *prefix)
  927. {
  928. struct prefix_master *master;
  929. struct prefix_list *plist;
  930. struct prefix_list_entry *pentry;
  931. int ret;
  932. struct prefix p;
  933. master = prefix_master_get (afi);
  934. if (master == NULL)
  935. return CMD_WARNING;
  936. if (name == NULL && prefix == NULL)
  937. {
  938. for (plist = master->num.head; plist; plist = plist->next)
  939. for (pentry = plist->head; pentry; pentry = pentry->next)
  940. pentry->hitcnt = 0;
  941. for (plist = master->str.head; plist; plist = plist->next)
  942. for (pentry = plist->head; pentry; pentry = pentry->next)
  943. pentry->hitcnt = 0;
  944. }
  945. else
  946. {
  947. plist = prefix_list_lookup (afi, name);
  948. if (! plist)
  949. {
  950. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  951. return CMD_WARNING;
  952. }
  953. if (prefix)
  954. {
  955. ret = str2prefix (prefix, &p);
  956. if (ret <= 0)
  957. {
  958. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  959. return CMD_WARNING;
  960. }
  961. }
  962. for (pentry = plist->head; pentry; pentry = pentry->next)
  963. {
  964. if (prefix)
  965. {
  966. if (prefix_match (&pentry->prefix, &p))
  967. pentry->hitcnt = 0;
  968. }
  969. else
  970. pentry->hitcnt = 0;
  971. }
  972. }
  973. return CMD_SUCCESS;
  974. }
  975. DEFUN (ip_prefix_list,
  976. ip_prefix_list_cmd,
  977. "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  978. IP_STR
  979. PREFIX_LIST_STR
  980. "Name of a prefix list\n"
  981. "Specify packets to reject\n"
  982. "Specify packets to forward\n"
  983. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  984. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  985. {
  986. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
  987. argv[1], argv[2], NULL, NULL);
  988. }
  989. DEFUN (ip_prefix_list_ge,
  990. ip_prefix_list_ge_cmd,
  991. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  992. IP_STR
  993. PREFIX_LIST_STR
  994. "Name of a prefix list\n"
  995. "Specify packets to reject\n"
  996. "Specify packets to forward\n"
  997. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  998. "Minimum prefix length to be matched\n"
  999. "Minimum prefix length\n")
  1000. {
  1001. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1002. argv[2], argv[3], NULL);
  1003. }
  1004. DEFUN (ip_prefix_list_ge_le,
  1005. ip_prefix_list_ge_le_cmd,
  1006. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1007. IP_STR
  1008. PREFIX_LIST_STR
  1009. "Name of a prefix list\n"
  1010. "Specify packets to reject\n"
  1011. "Specify packets to forward\n"
  1012. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1013. "Minimum prefix length to be matched\n"
  1014. "Minimum prefix length\n"
  1015. "Maximum prefix length to be matched\n"
  1016. "Maximum prefix length\n")
  1017. {
  1018. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1019. argv[2], argv[3], argv[4]);
  1020. }
  1021. DEFUN (ip_prefix_list_le,
  1022. ip_prefix_list_le_cmd,
  1023. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1024. IP_STR
  1025. PREFIX_LIST_STR
  1026. "Name of a prefix list\n"
  1027. "Specify packets to reject\n"
  1028. "Specify packets to forward\n"
  1029. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1030. "Maximum prefix length to be matched\n"
  1031. "Maximum prefix length\n")
  1032. {
  1033. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1034. argv[2], NULL, argv[3]);
  1035. }
  1036. DEFUN (ip_prefix_list_le_ge,
  1037. ip_prefix_list_le_ge_cmd,
  1038. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1039. IP_STR
  1040. PREFIX_LIST_STR
  1041. "Name of a prefix list\n"
  1042. "Specify packets to reject\n"
  1043. "Specify packets to forward\n"
  1044. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1045. "Maximum prefix length to be matched\n"
  1046. "Maximum prefix length\n"
  1047. "Minimum prefix length to be matched\n"
  1048. "Minimum prefix length\n")
  1049. {
  1050. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1051. argv[2], argv[4], argv[3]);
  1052. }
  1053. DEFUN (ip_prefix_list_seq,
  1054. ip_prefix_list_seq_cmd,
  1055. "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1056. IP_STR
  1057. PREFIX_LIST_STR
  1058. "Name of a prefix list\n"
  1059. "sequence number of an entry\n"
  1060. "Sequence number\n"
  1061. "Specify packets to reject\n"
  1062. "Specify packets to forward\n"
  1063. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1064. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1065. {
  1066. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1067. argv[3], NULL, NULL);
  1068. }
  1069. DEFUN (ip_prefix_list_seq_ge,
  1070. ip_prefix_list_seq_ge_cmd,
  1071. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1072. IP_STR
  1073. PREFIX_LIST_STR
  1074. "Name of a prefix list\n"
  1075. "sequence number of an entry\n"
  1076. "Sequence number\n"
  1077. "Specify packets to reject\n"
  1078. "Specify packets to forward\n"
  1079. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1080. "Minimum prefix length to be matched\n"
  1081. "Minimum prefix length\n")
  1082. {
  1083. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1084. argv[3], argv[4], NULL);
  1085. }
  1086. DEFUN (ip_prefix_list_seq_ge_le,
  1087. ip_prefix_list_seq_ge_le_cmd,
  1088. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1089. IP_STR
  1090. PREFIX_LIST_STR
  1091. "Name of a prefix list\n"
  1092. "sequence number of an entry\n"
  1093. "Sequence number\n"
  1094. "Specify packets to reject\n"
  1095. "Specify packets to forward\n"
  1096. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1097. "Minimum prefix length to be matched\n"
  1098. "Minimum prefix length\n"
  1099. "Maximum prefix length to be matched\n"
  1100. "Maximum prefix length\n")
  1101. {
  1102. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1103. argv[3], argv[4], argv[5]);
  1104. }
  1105. DEFUN (ip_prefix_list_seq_le,
  1106. ip_prefix_list_seq_le_cmd,
  1107. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1108. IP_STR
  1109. PREFIX_LIST_STR
  1110. "Name of a prefix list\n"
  1111. "sequence number of an entry\n"
  1112. "Sequence number\n"
  1113. "Specify packets to reject\n"
  1114. "Specify packets to forward\n"
  1115. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1116. "Maximum prefix length to be matched\n"
  1117. "Maximum prefix length\n")
  1118. {
  1119. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1120. argv[3], NULL, argv[4]);
  1121. }
  1122. DEFUN (ip_prefix_list_seq_le_ge,
  1123. ip_prefix_list_seq_le_ge_cmd,
  1124. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1125. IP_STR
  1126. PREFIX_LIST_STR
  1127. "Name of a prefix list\n"
  1128. "sequence number of an entry\n"
  1129. "Sequence number\n"
  1130. "Specify packets to reject\n"
  1131. "Specify packets to forward\n"
  1132. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1133. "Maximum prefix length to be matched\n"
  1134. "Maximum prefix length\n"
  1135. "Minimum prefix length to be matched\n"
  1136. "Minimum prefix length\n")
  1137. {
  1138. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1139. argv[3], argv[5], argv[4]);
  1140. }
  1141. DEFUN (no_ip_prefix_list,
  1142. no_ip_prefix_list_cmd,
  1143. "no ip prefix-list WORD",
  1144. NO_STR
  1145. IP_STR
  1146. PREFIX_LIST_STR
  1147. "Name of a prefix list\n")
  1148. {
  1149. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
  1150. NULL, NULL, NULL);
  1151. }
  1152. DEFUN (no_ip_prefix_list_prefix,
  1153. no_ip_prefix_list_prefix_cmd,
  1154. "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  1155. NO_STR
  1156. IP_STR
  1157. PREFIX_LIST_STR
  1158. "Name of a prefix list\n"
  1159. "Specify packets to reject\n"
  1160. "Specify packets to forward\n"
  1161. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1162. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1163. {
  1164. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1165. argv[2], NULL, NULL);
  1166. }
  1167. DEFUN (no_ip_prefix_list_ge,
  1168. no_ip_prefix_list_ge_cmd,
  1169. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  1170. NO_STR
  1171. IP_STR
  1172. PREFIX_LIST_STR
  1173. "Name of a prefix list\n"
  1174. "Specify packets to reject\n"
  1175. "Specify packets to forward\n"
  1176. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1177. "Minimum prefix length to be matched\n"
  1178. "Minimum prefix length\n")
  1179. {
  1180. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1181. argv[2], argv[3], NULL);
  1182. }
  1183. DEFUN (no_ip_prefix_list_ge_le,
  1184. no_ip_prefix_list_ge_le_cmd,
  1185. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1186. NO_STR
  1187. IP_STR
  1188. PREFIX_LIST_STR
  1189. "Name of a prefix list\n"
  1190. "Specify packets to reject\n"
  1191. "Specify packets to forward\n"
  1192. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1193. "Minimum prefix length to be matched\n"
  1194. "Minimum prefix length\n"
  1195. "Maximum prefix length to be matched\n"
  1196. "Maximum prefix length\n")
  1197. {
  1198. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1199. argv[2], argv[3], argv[4]);
  1200. }
  1201. DEFUN (no_ip_prefix_list_le,
  1202. no_ip_prefix_list_le_cmd,
  1203. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1204. NO_STR
  1205. IP_STR
  1206. PREFIX_LIST_STR
  1207. "Name of a prefix list\n"
  1208. "Specify packets to reject\n"
  1209. "Specify packets to forward\n"
  1210. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1211. "Maximum prefix length to be matched\n"
  1212. "Maximum prefix length\n")
  1213. {
  1214. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1215. argv[2], NULL, argv[3]);
  1216. }
  1217. DEFUN (no_ip_prefix_list_le_ge,
  1218. no_ip_prefix_list_le_ge_cmd,
  1219. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1220. NO_STR
  1221. IP_STR
  1222. PREFIX_LIST_STR
  1223. "Name of a prefix list\n"
  1224. "Specify packets to reject\n"
  1225. "Specify packets to forward\n"
  1226. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1227. "Maximum prefix length to be matched\n"
  1228. "Maximum prefix length\n"
  1229. "Minimum prefix length to be matched\n"
  1230. "Minimum prefix length\n")
  1231. {
  1232. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1233. argv[2], argv[4], argv[3]);
  1234. }
  1235. DEFUN (no_ip_prefix_list_seq,
  1236. no_ip_prefix_list_seq_cmd,
  1237. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1238. NO_STR
  1239. IP_STR
  1240. PREFIX_LIST_STR
  1241. "Name of a prefix list\n"
  1242. "sequence number of an entry\n"
  1243. "Sequence number\n"
  1244. "Specify packets to reject\n"
  1245. "Specify packets to forward\n"
  1246. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1247. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1248. {
  1249. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1250. argv[3], NULL, NULL);
  1251. }
  1252. DEFUN (no_ip_prefix_list_seq_ge,
  1253. no_ip_prefix_list_seq_ge_cmd,
  1254. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1255. NO_STR
  1256. IP_STR
  1257. PREFIX_LIST_STR
  1258. "Name of a prefix list\n"
  1259. "sequence number of an entry\n"
  1260. "Sequence number\n"
  1261. "Specify packets to reject\n"
  1262. "Specify packets to forward\n"
  1263. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1264. "Minimum prefix length to be matched\n"
  1265. "Minimum prefix length\n")
  1266. {
  1267. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1268. argv[3], argv[4], NULL);
  1269. }
  1270. DEFUN (no_ip_prefix_list_seq_ge_le,
  1271. no_ip_prefix_list_seq_ge_le_cmd,
  1272. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1273. NO_STR
  1274. IP_STR
  1275. PREFIX_LIST_STR
  1276. "Name of a prefix list\n"
  1277. "sequence number of an entry\n"
  1278. "Sequence number\n"
  1279. "Specify packets to reject\n"
  1280. "Specify packets to forward\n"
  1281. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1282. "Minimum prefix length to be matched\n"
  1283. "Minimum prefix length\n"
  1284. "Maximum prefix length to be matched\n"
  1285. "Maximum prefix length\n")
  1286. {
  1287. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1288. argv[3], argv[4], argv[5]);
  1289. }
  1290. DEFUN (no_ip_prefix_list_seq_le,
  1291. no_ip_prefix_list_seq_le_cmd,
  1292. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1293. NO_STR
  1294. IP_STR
  1295. PREFIX_LIST_STR
  1296. "Name of a prefix list\n"
  1297. "sequence number of an entry\n"
  1298. "Sequence number\n"
  1299. "Specify packets to reject\n"
  1300. "Specify packets to forward\n"
  1301. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1302. "Maximum prefix length to be matched\n"
  1303. "Maximum prefix length\n")
  1304. {
  1305. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1306. argv[3], NULL, argv[4]);
  1307. }
  1308. DEFUN (no_ip_prefix_list_seq_le_ge,
  1309. no_ip_prefix_list_seq_le_ge_cmd,
  1310. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1311. NO_STR
  1312. IP_STR
  1313. PREFIX_LIST_STR
  1314. "Name of a prefix list\n"
  1315. "sequence number of an entry\n"
  1316. "Sequence number\n"
  1317. "Specify packets to reject\n"
  1318. "Specify packets to forward\n"
  1319. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1320. "Maximum prefix length to be matched\n"
  1321. "Maximum prefix length\n"
  1322. "Minimum prefix length to be matched\n"
  1323. "Minimum prefix length\n")
  1324. {
  1325. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1326. argv[3], argv[5], argv[4]);
  1327. }
  1328. DEFUN (ip_prefix_list_sequence_number,
  1329. ip_prefix_list_sequence_number_cmd,
  1330. "ip prefix-list sequence-number",
  1331. IP_STR
  1332. PREFIX_LIST_STR
  1333. "Include/exclude sequence numbers in NVGEN\n")
  1334. {
  1335. prefix_master_ipv4.seqnum = 1;
  1336. return CMD_SUCCESS;
  1337. }
  1338. DEFUN (no_ip_prefix_list_sequence_number,
  1339. no_ip_prefix_list_sequence_number_cmd,
  1340. "no ip prefix-list sequence-number",
  1341. NO_STR
  1342. IP_STR
  1343. PREFIX_LIST_STR
  1344. "Include/exclude sequence numbers in NVGEN\n")
  1345. {
  1346. prefix_master_ipv4.seqnum = 0;
  1347. return CMD_SUCCESS;
  1348. }
  1349. DEFUN (ip_prefix_list_description,
  1350. ip_prefix_list_description_cmd,
  1351. "ip prefix-list WORD description .LINE",
  1352. IP_STR
  1353. PREFIX_LIST_STR
  1354. "Name of a prefix list\n"
  1355. "Prefix-list specific description\n"
  1356. "Up to 80 characters describing this prefix-list\n")
  1357. {
  1358. struct prefix_list *plist;
  1359. plist = prefix_list_get (AFI_IP, argv[0]);
  1360. if (plist->desc)
  1361. {
  1362. XFREE (MTYPE_TMP, plist->desc);
  1363. plist->desc = NULL;
  1364. }
  1365. plist->desc = argv_concat(argv, argc, 1);
  1366. return CMD_SUCCESS;
  1367. }
  1368. DEFUN (no_ip_prefix_list_description,
  1369. no_ip_prefix_list_description_cmd,
  1370. "no ip prefix-list WORD description",
  1371. NO_STR
  1372. IP_STR
  1373. PREFIX_LIST_STR
  1374. "Name of a prefix list\n"
  1375. "Prefix-list specific description\n")
  1376. {
  1377. return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
  1378. }
  1379. ALIAS (no_ip_prefix_list_description,
  1380. no_ip_prefix_list_description_arg_cmd,
  1381. "no ip prefix-list WORD description .LINE",
  1382. NO_STR
  1383. IP_STR
  1384. PREFIX_LIST_STR
  1385. "Name of a prefix list\n"
  1386. "Prefix-list specific description\n"
  1387. "Up to 80 characters describing this prefix-list\n")
  1388. DEFUN (show_ip_prefix_list,
  1389. show_ip_prefix_list_cmd,
  1390. "show ip prefix-list",
  1391. SHOW_STR
  1392. IP_STR
  1393. PREFIX_LIST_STR)
  1394. {
  1395. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
  1396. }
  1397. DEFUN (show_ip_prefix_list_name,
  1398. show_ip_prefix_list_name_cmd,
  1399. "show ip prefix-list WORD",
  1400. SHOW_STR
  1401. IP_STR
  1402. PREFIX_LIST_STR
  1403. "Name of a prefix list\n")
  1404. {
  1405. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
  1406. }
  1407. DEFUN (show_ip_prefix_list_name_seq,
  1408. show_ip_prefix_list_name_seq_cmd,
  1409. "show ip prefix-list WORD seq <1-4294967295>",
  1410. SHOW_STR
  1411. IP_STR
  1412. PREFIX_LIST_STR
  1413. "Name of a prefix list\n"
  1414. "sequence number of an entry\n"
  1415. "Sequence number\n")
  1416. {
  1417. return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
  1418. }
  1419. DEFUN (show_ip_prefix_list_prefix,
  1420. show_ip_prefix_list_prefix_cmd,
  1421. "show ip prefix-list WORD A.B.C.D/M",
  1422. SHOW_STR
  1423. IP_STR
  1424. PREFIX_LIST_STR
  1425. "Name of a prefix list\n"
  1426. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1427. {
  1428. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
  1429. }
  1430. DEFUN (show_ip_prefix_list_prefix_longer,
  1431. show_ip_prefix_list_prefix_longer_cmd,
  1432. "show ip prefix-list WORD A.B.C.D/M longer",
  1433. SHOW_STR
  1434. IP_STR
  1435. PREFIX_LIST_STR
  1436. "Name of a prefix list\n"
  1437. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1438. "Lookup longer prefix\n")
  1439. {
  1440. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
  1441. }
  1442. DEFUN (show_ip_prefix_list_prefix_first_match,
  1443. show_ip_prefix_list_prefix_first_match_cmd,
  1444. "show ip prefix-list WORD A.B.C.D/M first-match",
  1445. SHOW_STR
  1446. IP_STR
  1447. PREFIX_LIST_STR
  1448. "Name of a prefix list\n"
  1449. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1450. "First matched prefix\n")
  1451. {
  1452. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
  1453. }
  1454. DEFUN (show_ip_prefix_list_summary,
  1455. show_ip_prefix_list_summary_cmd,
  1456. "show ip prefix-list summary",
  1457. SHOW_STR
  1458. IP_STR
  1459. PREFIX_LIST_STR
  1460. "Summary of prefix lists\n")
  1461. {
  1462. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
  1463. }
  1464. DEFUN (show_ip_prefix_list_summary_name,
  1465. show_ip_prefix_list_summary_name_cmd,
  1466. "show ip prefix-list summary WORD",
  1467. SHOW_STR
  1468. IP_STR
  1469. PREFIX_LIST_STR
  1470. "Summary of prefix lists\n"
  1471. "Name of a prefix list\n")
  1472. {
  1473. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
  1474. }
  1475. DEFUN (show_ip_prefix_list_detail,
  1476. show_ip_prefix_list_detail_cmd,
  1477. "show ip prefix-list detail",
  1478. SHOW_STR
  1479. IP_STR
  1480. PREFIX_LIST_STR
  1481. "Detail of prefix lists\n")
  1482. {
  1483. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
  1484. }
  1485. DEFUN (show_ip_prefix_list_detail_name,
  1486. show_ip_prefix_list_detail_name_cmd,
  1487. "show ip prefix-list detail WORD",
  1488. SHOW_STR
  1489. IP_STR
  1490. PREFIX_LIST_STR
  1491. "Detail of prefix lists\n"
  1492. "Name of a prefix list\n")
  1493. {
  1494. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
  1495. }
  1496. DEFUN (clear_ip_prefix_list,
  1497. clear_ip_prefix_list_cmd,
  1498. "clear ip prefix-list",
  1499. CLEAR_STR
  1500. IP_STR
  1501. PREFIX_LIST_STR)
  1502. {
  1503. return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
  1504. }
  1505. DEFUN (clear_ip_prefix_list_name,
  1506. clear_ip_prefix_list_name_cmd,
  1507. "clear ip prefix-list WORD",
  1508. CLEAR_STR
  1509. IP_STR
  1510. PREFIX_LIST_STR
  1511. "Name of a prefix list\n")
  1512. {
  1513. return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
  1514. }
  1515. DEFUN (clear_ip_prefix_list_name_prefix,
  1516. clear_ip_prefix_list_name_prefix_cmd,
  1517. "clear ip prefix-list WORD A.B.C.D/M",
  1518. CLEAR_STR
  1519. IP_STR
  1520. PREFIX_LIST_STR
  1521. "Name of a prefix list\n"
  1522. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1523. {
  1524. return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
  1525. }
  1526. #ifdef HAVE_IPV6
  1527. DEFUN (ipv6_prefix_list,
  1528. ipv6_prefix_list_cmd,
  1529. "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1530. IPV6_STR
  1531. PREFIX_LIST_STR
  1532. "Name of a prefix list\n"
  1533. "Specify packets to reject\n"
  1534. "Specify packets to forward\n"
  1535. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1536. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1537. {
  1538. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
  1539. argv[1], argv[2], NULL, NULL);
  1540. }
  1541. DEFUN (ipv6_prefix_list_ge,
  1542. ipv6_prefix_list_ge_cmd,
  1543. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1544. IPV6_STR
  1545. PREFIX_LIST_STR
  1546. "Name of a prefix list\n"
  1547. "Specify packets to reject\n"
  1548. "Specify packets to forward\n"
  1549. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1550. "Minimum prefix length to be matched\n"
  1551. "Minimum prefix length\n")
  1552. {
  1553. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1554. argv[2], argv[3], NULL);
  1555. }
  1556. DEFUN (ipv6_prefix_list_ge_le,
  1557. ipv6_prefix_list_ge_le_cmd,
  1558. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1559. IPV6_STR
  1560. PREFIX_LIST_STR
  1561. "Name of a prefix list\n"
  1562. "Specify packets to reject\n"
  1563. "Specify packets to forward\n"
  1564. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1565. "Minimum prefix length to be matched\n"
  1566. "Minimum prefix length\n"
  1567. "Maximum prefix length to be matched\n"
  1568. "Maximum prefix length\n")
  1569. {
  1570. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1571. argv[2], argv[3], argv[4]);
  1572. }
  1573. DEFUN (ipv6_prefix_list_le,
  1574. ipv6_prefix_list_le_cmd,
  1575. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1576. IPV6_STR
  1577. PREFIX_LIST_STR
  1578. "Name of a prefix list\n"
  1579. "Specify packets to reject\n"
  1580. "Specify packets to forward\n"
  1581. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1582. "Maximum prefix length to be matched\n"
  1583. "Maximum prefix length\n")
  1584. {
  1585. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1586. argv[2], NULL, argv[3]);
  1587. }
  1588. DEFUN (ipv6_prefix_list_le_ge,
  1589. ipv6_prefix_list_le_ge_cmd,
  1590. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1591. IPV6_STR
  1592. PREFIX_LIST_STR
  1593. "Name of a prefix list\n"
  1594. "Specify packets to reject\n"
  1595. "Specify packets to forward\n"
  1596. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1597. "Maximum prefix length to be matched\n"
  1598. "Maximum prefix length\n"
  1599. "Minimum prefix length to be matched\n"
  1600. "Minimum prefix length\n")
  1601. {
  1602. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1603. argv[2], argv[4], argv[3]);
  1604. }
  1605. DEFUN (ipv6_prefix_list_seq,
  1606. ipv6_prefix_list_seq_cmd,
  1607. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1608. IPV6_STR
  1609. PREFIX_LIST_STR
  1610. "Name of a prefix list\n"
  1611. "sequence number of an entry\n"
  1612. "Sequence number\n"
  1613. "Specify packets to reject\n"
  1614. "Specify packets to forward\n"
  1615. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1616. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1617. {
  1618. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1619. argv[3], NULL, NULL);
  1620. }
  1621. DEFUN (ipv6_prefix_list_seq_ge,
  1622. ipv6_prefix_list_seq_ge_cmd,
  1623. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1624. IPV6_STR
  1625. PREFIX_LIST_STR
  1626. "Name of a prefix list\n"
  1627. "sequence number of an entry\n"
  1628. "Sequence number\n"
  1629. "Specify packets to reject\n"
  1630. "Specify packets to forward\n"
  1631. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1632. "Minimum prefix length to be matched\n"
  1633. "Minimum prefix length\n")
  1634. {
  1635. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1636. argv[3], argv[4], NULL);
  1637. }
  1638. DEFUN (ipv6_prefix_list_seq_ge_le,
  1639. ipv6_prefix_list_seq_ge_le_cmd,
  1640. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1641. IPV6_STR
  1642. PREFIX_LIST_STR
  1643. "Name of a prefix list\n"
  1644. "sequence number of an entry\n"
  1645. "Sequence number\n"
  1646. "Specify packets to reject\n"
  1647. "Specify packets to forward\n"
  1648. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1649. "Minimum prefix length to be matched\n"
  1650. "Minimum prefix length\n"
  1651. "Maximum prefix length to be matched\n"
  1652. "Maximum prefix length\n")
  1653. {
  1654. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1655. argv[3], argv[4], argv[5]);
  1656. }
  1657. DEFUN (ipv6_prefix_list_seq_le,
  1658. ipv6_prefix_list_seq_le_cmd,
  1659. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1660. IPV6_STR
  1661. PREFIX_LIST_STR
  1662. "Name of a prefix list\n"
  1663. "sequence number of an entry\n"
  1664. "Sequence number\n"
  1665. "Specify packets to reject\n"
  1666. "Specify packets to forward\n"
  1667. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1668. "Maximum prefix length to be matched\n"
  1669. "Maximum prefix length\n")
  1670. {
  1671. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1672. argv[3], NULL, argv[4]);
  1673. }
  1674. DEFUN (ipv6_prefix_list_seq_le_ge,
  1675. ipv6_prefix_list_seq_le_ge_cmd,
  1676. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1677. IPV6_STR
  1678. PREFIX_LIST_STR
  1679. "Name of a prefix list\n"
  1680. "sequence number of an entry\n"
  1681. "Sequence number\n"
  1682. "Specify packets to reject\n"
  1683. "Specify packets to forward\n"
  1684. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1685. "Maximum prefix length to be matched\n"
  1686. "Maximum prefix length\n"
  1687. "Minimum prefix length to be matched\n"
  1688. "Minimum prefix length\n")
  1689. {
  1690. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1691. argv[3], argv[5], argv[4]);
  1692. }
  1693. DEFUN (no_ipv6_prefix_list,
  1694. no_ipv6_prefix_list_cmd,
  1695. "no ipv6 prefix-list WORD",
  1696. NO_STR
  1697. IPV6_STR
  1698. PREFIX_LIST_STR
  1699. "Name of a prefix list\n")
  1700. {
  1701. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
  1702. NULL, NULL, NULL);
  1703. }
  1704. DEFUN (no_ipv6_prefix_list_prefix,
  1705. no_ipv6_prefix_list_prefix_cmd,
  1706. "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1707. NO_STR
  1708. IPV6_STR
  1709. PREFIX_LIST_STR
  1710. "Name of a prefix list\n"
  1711. "Specify packets to reject\n"
  1712. "Specify packets to forward\n"
  1713. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1714. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1715. {
  1716. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1717. argv[2], NULL, NULL);
  1718. }
  1719. DEFUN (no_ipv6_prefix_list_ge,
  1720. no_ipv6_prefix_list_ge_cmd,
  1721. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1722. NO_STR
  1723. IPV6_STR
  1724. PREFIX_LIST_STR
  1725. "Name of a prefix list\n"
  1726. "Specify packets to reject\n"
  1727. "Specify packets to forward\n"
  1728. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1729. "Minimum prefix length to be matched\n"
  1730. "Minimum prefix length\n")
  1731. {
  1732. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1733. argv[2], argv[3], NULL);
  1734. }
  1735. DEFUN (no_ipv6_prefix_list_ge_le,
  1736. no_ipv6_prefix_list_ge_le_cmd,
  1737. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1738. NO_STR
  1739. IPV6_STR
  1740. PREFIX_LIST_STR
  1741. "Name of a prefix list\n"
  1742. "Specify packets to reject\n"
  1743. "Specify packets to forward\n"
  1744. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1745. "Minimum prefix length to be matched\n"
  1746. "Minimum prefix length\n"
  1747. "Maximum prefix length to be matched\n"
  1748. "Maximum prefix length\n")
  1749. {
  1750. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1751. argv[2], argv[3], argv[4]);
  1752. }
  1753. DEFUN (no_ipv6_prefix_list_le,
  1754. no_ipv6_prefix_list_le_cmd,
  1755. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1756. NO_STR
  1757. IPV6_STR
  1758. PREFIX_LIST_STR
  1759. "Name of a prefix list\n"
  1760. "Specify packets to reject\n"
  1761. "Specify packets to forward\n"
  1762. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1763. "Maximum prefix length to be matched\n"
  1764. "Maximum prefix length\n")
  1765. {
  1766. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1767. argv[2], NULL, argv[3]);
  1768. }
  1769. DEFUN (no_ipv6_prefix_list_le_ge,
  1770. no_ipv6_prefix_list_le_ge_cmd,
  1771. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1772. NO_STR
  1773. IPV6_STR
  1774. PREFIX_LIST_STR
  1775. "Name of a prefix list\n"
  1776. "Specify packets to reject\n"
  1777. "Specify packets to forward\n"
  1778. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1779. "Maximum prefix length to be matched\n"
  1780. "Maximum prefix length\n"
  1781. "Minimum prefix length to be matched\n"
  1782. "Minimum prefix length\n")
  1783. {
  1784. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1785. argv[2], argv[4], argv[3]);
  1786. }
  1787. DEFUN (no_ipv6_prefix_list_seq,
  1788. no_ipv6_prefix_list_seq_cmd,
  1789. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1790. NO_STR
  1791. IPV6_STR
  1792. PREFIX_LIST_STR
  1793. "Name of a prefix list\n"
  1794. "sequence number of an entry\n"
  1795. "Sequence number\n"
  1796. "Specify packets to reject\n"
  1797. "Specify packets to forward\n"
  1798. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1799. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1800. {
  1801. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1802. argv[3], NULL, NULL);
  1803. }
  1804. DEFUN (no_ipv6_prefix_list_seq_ge,
  1805. no_ipv6_prefix_list_seq_ge_cmd,
  1806. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1807. NO_STR
  1808. IPV6_STR
  1809. PREFIX_LIST_STR
  1810. "Name of a prefix list\n"
  1811. "sequence number of an entry\n"
  1812. "Sequence number\n"
  1813. "Specify packets to reject\n"
  1814. "Specify packets to forward\n"
  1815. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1816. "Minimum prefix length to be matched\n"
  1817. "Minimum prefix length\n")
  1818. {
  1819. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1820. argv[3], argv[4], NULL);
  1821. }
  1822. DEFUN (no_ipv6_prefix_list_seq_ge_le,
  1823. no_ipv6_prefix_list_seq_ge_le_cmd,
  1824. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1825. NO_STR
  1826. IPV6_STR
  1827. PREFIX_LIST_STR
  1828. "Name of a prefix list\n"
  1829. "sequence number of an entry\n"
  1830. "Sequence number\n"
  1831. "Specify packets to reject\n"
  1832. "Specify packets to forward\n"
  1833. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1834. "Minimum prefix length to be matched\n"
  1835. "Minimum prefix length\n"
  1836. "Maximum prefix length to be matched\n"
  1837. "Maximum prefix length\n")
  1838. {
  1839. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1840. argv[3], argv[4], argv[5]);
  1841. }
  1842. DEFUN (no_ipv6_prefix_list_seq_le,
  1843. no_ipv6_prefix_list_seq_le_cmd,
  1844. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1845. NO_STR
  1846. IPV6_STR
  1847. PREFIX_LIST_STR
  1848. "Name of a prefix list\n"
  1849. "sequence number of an entry\n"
  1850. "Sequence number\n"
  1851. "Specify packets to reject\n"
  1852. "Specify packets to forward\n"
  1853. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1854. "Maximum prefix length to be matched\n"
  1855. "Maximum prefix length\n")
  1856. {
  1857. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1858. argv[3], NULL, argv[4]);
  1859. }
  1860. DEFUN (no_ipv6_prefix_list_seq_le_ge,
  1861. no_ipv6_prefix_list_seq_le_ge_cmd,
  1862. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1863. NO_STR
  1864. IPV6_STR
  1865. PREFIX_LIST_STR
  1866. "Name of a prefix list\n"
  1867. "sequence number of an entry\n"
  1868. "Sequence number\n"
  1869. "Specify packets to reject\n"
  1870. "Specify packets to forward\n"
  1871. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1872. "Maximum prefix length to be matched\n"
  1873. "Maximum prefix length\n"
  1874. "Minimum prefix length to be matched\n"
  1875. "Minimum prefix length\n")
  1876. {
  1877. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1878. argv[3], argv[5], argv[4]);
  1879. }
  1880. DEFUN (ipv6_prefix_list_sequence_number,
  1881. ipv6_prefix_list_sequence_number_cmd,
  1882. "ipv6 prefix-list sequence-number",
  1883. IPV6_STR
  1884. PREFIX_LIST_STR
  1885. "Include/exclude sequence numbers in NVGEN\n")
  1886. {
  1887. prefix_master_ipv6.seqnum = 1;
  1888. return CMD_SUCCESS;
  1889. }
  1890. DEFUN (no_ipv6_prefix_list_sequence_number,
  1891. no_ipv6_prefix_list_sequence_number_cmd,
  1892. "no ipv6 prefix-list sequence-number",
  1893. NO_STR
  1894. IPV6_STR
  1895. PREFIX_LIST_STR
  1896. "Include/exclude sequence numbers in NVGEN\n")
  1897. {
  1898. prefix_master_ipv6.seqnum = 0;
  1899. return CMD_SUCCESS;
  1900. }
  1901. DEFUN (ipv6_prefix_list_description,
  1902. ipv6_prefix_list_description_cmd,
  1903. "ipv6 prefix-list WORD description .LINE",
  1904. IPV6_STR
  1905. PREFIX_LIST_STR
  1906. "Name of a prefix list\n"
  1907. "Prefix-list specific description\n"
  1908. "Up to 80 characters describing this prefix-list\n")
  1909. {
  1910. struct prefix_list *plist;
  1911. plist = prefix_list_get (AFI_IP6, argv[0]);
  1912. if (plist->desc)
  1913. {
  1914. XFREE (MTYPE_TMP, plist->desc);
  1915. plist->desc = NULL;
  1916. }
  1917. plist->desc = argv_concat(argv, argc, 1);
  1918. return CMD_SUCCESS;
  1919. }
  1920. DEFUN (no_ipv6_prefix_list_description,
  1921. no_ipv6_prefix_list_description_cmd,
  1922. "no ipv6 prefix-list WORD description",
  1923. NO_STR
  1924. IPV6_STR
  1925. PREFIX_LIST_STR
  1926. "Name of a prefix list\n"
  1927. "Prefix-list specific description\n")
  1928. {
  1929. return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
  1930. }
  1931. ALIAS (no_ipv6_prefix_list_description,
  1932. no_ipv6_prefix_list_description_arg_cmd,
  1933. "no ipv6 prefix-list WORD description .LINE",
  1934. NO_STR
  1935. IPV6_STR
  1936. PREFIX_LIST_STR
  1937. "Name of a prefix list\n"
  1938. "Prefix-list specific description\n"
  1939. "Up to 80 characters describing this prefix-list\n")
  1940. DEFUN (show_ipv6_prefix_list,
  1941. show_ipv6_prefix_list_cmd,
  1942. "show ipv6 prefix-list",
  1943. SHOW_STR
  1944. IPV6_STR
  1945. PREFIX_LIST_STR)
  1946. {
  1947. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
  1948. }
  1949. DEFUN (show_ipv6_prefix_list_name,
  1950. show_ipv6_prefix_list_name_cmd,
  1951. "show ipv6 prefix-list WORD",
  1952. SHOW_STR
  1953. IPV6_STR
  1954. PREFIX_LIST_STR
  1955. "Name of a prefix list\n")
  1956. {
  1957. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
  1958. }
  1959. DEFUN (show_ipv6_prefix_list_name_seq,
  1960. show_ipv6_prefix_list_name_seq_cmd,
  1961. "show ipv6 prefix-list WORD seq <1-4294967295>",
  1962. SHOW_STR
  1963. IPV6_STR
  1964. PREFIX_LIST_STR
  1965. "Name of a prefix list\n"
  1966. "sequence number of an entry\n"
  1967. "Sequence number\n")
  1968. {
  1969. return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
  1970. }
  1971. DEFUN (show_ipv6_prefix_list_prefix,
  1972. show_ipv6_prefix_list_prefix_cmd,
  1973. "show ipv6 prefix-list WORD X:X::X:X/M",
  1974. SHOW_STR
  1975. IPV6_STR
  1976. PREFIX_LIST_STR
  1977. "Name of a prefix list\n"
  1978. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  1979. {
  1980. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
  1981. }
  1982. DEFUN (show_ipv6_prefix_list_prefix_longer,
  1983. show_ipv6_prefix_list_prefix_longer_cmd,
  1984. "show ipv6 prefix-list WORD X:X::X:X/M longer",
  1985. SHOW_STR
  1986. IPV6_STR
  1987. PREFIX_LIST_STR
  1988. "Name of a prefix list\n"
  1989. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1990. "Lookup longer prefix\n")
  1991. {
  1992. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
  1993. }
  1994. DEFUN (show_ipv6_prefix_list_prefix_first_match,
  1995. show_ipv6_prefix_list_prefix_first_match_cmd,
  1996. "show ipv6 prefix-list WORD X:X::X:X/M first-match",
  1997. SHOW_STR
  1998. IPV6_STR
  1999. PREFIX_LIST_STR
  2000. "Name of a prefix list\n"
  2001. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  2002. "First matched prefix\n")
  2003. {
  2004. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
  2005. }
  2006. DEFUN (show_ipv6_prefix_list_summary,
  2007. show_ipv6_prefix_list_summary_cmd,
  2008. "show ipv6 prefix-list summary",
  2009. SHOW_STR
  2010. IPV6_STR
  2011. PREFIX_LIST_STR
  2012. "Summary of prefix lists\n")
  2013. {
  2014. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
  2015. }
  2016. DEFUN (show_ipv6_prefix_list_summary_name,
  2017. show_ipv6_prefix_list_summary_name_cmd,
  2018. "show ipv6 prefix-list summary WORD",
  2019. SHOW_STR
  2020. IPV6_STR
  2021. PREFIX_LIST_STR
  2022. "Summary of prefix lists\n"
  2023. "Name of a prefix list\n")
  2024. {
  2025. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
  2026. }
  2027. DEFUN (show_ipv6_prefix_list_detail,
  2028. show_ipv6_prefix_list_detail_cmd,
  2029. "show ipv6 prefix-list detail",
  2030. SHOW_STR
  2031. IPV6_STR
  2032. PREFIX_LIST_STR
  2033. "Detail of prefix lists\n")
  2034. {
  2035. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
  2036. }
  2037. DEFUN (show_ipv6_prefix_list_detail_name,
  2038. show_ipv6_prefix_list_detail_name_cmd,
  2039. "show ipv6 prefix-list detail WORD",
  2040. SHOW_STR
  2041. IPV6_STR
  2042. PREFIX_LIST_STR
  2043. "Detail of prefix lists\n"
  2044. "Name of a prefix list\n")
  2045. {
  2046. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
  2047. }
  2048. DEFUN (clear_ipv6_prefix_list,
  2049. clear_ipv6_prefix_list_cmd,
  2050. "clear ipv6 prefix-list",
  2051. CLEAR_STR
  2052. IPV6_STR
  2053. PREFIX_LIST_STR)
  2054. {
  2055. return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
  2056. }
  2057. DEFUN (clear_ipv6_prefix_list_name,
  2058. clear_ipv6_prefix_list_name_cmd,
  2059. "clear ipv6 prefix-list WORD",
  2060. CLEAR_STR
  2061. IPV6_STR
  2062. PREFIX_LIST_STR
  2063. "Name of a prefix list\n")
  2064. {
  2065. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
  2066. }
  2067. DEFUN (clear_ipv6_prefix_list_name_prefix,
  2068. clear_ipv6_prefix_list_name_prefix_cmd,
  2069. "clear ipv6 prefix-list WORD X:X::X:X/M",
  2070. CLEAR_STR
  2071. IPV6_STR
  2072. PREFIX_LIST_STR
  2073. "Name of a prefix list\n"
  2074. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  2075. {
  2076. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
  2077. }
  2078. #endif /* HAVE_IPV6 */
  2079. /* Configuration write function. */
  2080. static int
  2081. config_write_prefix_afi (afi_t afi, struct vty *vty)
  2082. {
  2083. struct prefix_list *plist;
  2084. struct prefix_list_entry *pentry;
  2085. struct prefix_master *master;
  2086. int write = 0;
  2087. master = prefix_master_get (afi);
  2088. if (master == NULL)
  2089. return 0;
  2090. if (! master->seqnum)
  2091. {
  2092. vty_out (vty, "no ip%s prefix-list sequence-number%s",
  2093. afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
  2094. vty_out (vty, "!%s", VTY_NEWLINE);
  2095. }
  2096. for (plist = master->num.head; plist; plist = plist->next)
  2097. {
  2098. if (plist->desc)
  2099. {
  2100. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2101. afi == AFI_IP ? "" : "v6",
  2102. plist->name, plist->desc, VTY_NEWLINE);
  2103. write++;
  2104. }
  2105. for (pentry = plist->head; pentry; pentry = pentry->next)
  2106. {
  2107. vty_out (vty, "ip%s prefix-list %s ",
  2108. afi == AFI_IP ? "" : "v6",
  2109. plist->name);
  2110. if (master->seqnum)
  2111. vty_out (vty, "seq %d ", pentry->seq);
  2112. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  2113. if (pentry->any)
  2114. vty_out (vty, "any");
  2115. else
  2116. {
  2117. struct prefix *p = &pentry->prefix;
  2118. char buf[BUFSIZ];
  2119. vty_out (vty, "%s/%d",
  2120. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2121. p->prefixlen);
  2122. if (pentry->ge)
  2123. vty_out (vty, " ge %d", pentry->ge);
  2124. if (pentry->le)
  2125. vty_out (vty, " le %d", pentry->le);
  2126. }
  2127. vty_out (vty, "%s", VTY_NEWLINE);
  2128. write++;
  2129. }
  2130. /* vty_out (vty, "!%s", VTY_NEWLINE); */
  2131. }
  2132. for (plist = master->str.head; plist; plist = plist->next)
  2133. {
  2134. if (plist->desc)
  2135. {
  2136. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2137. afi == AFI_IP ? "" : "v6",
  2138. plist->name, plist->desc, VTY_NEWLINE);
  2139. write++;
  2140. }
  2141. for (pentry = plist->head; pentry; pentry = pentry->next)
  2142. {
  2143. vty_out (vty, "ip%s prefix-list %s ",
  2144. afi == AFI_IP ? "" : "v6",
  2145. plist->name);
  2146. if (master->seqnum)
  2147. vty_out (vty, "seq %d ", pentry->seq);
  2148. vty_out (vty, "%s", prefix_list_type_str (pentry));
  2149. if (pentry->any)
  2150. vty_out (vty, " any");
  2151. else
  2152. {
  2153. struct prefix *p = &pentry->prefix;
  2154. char buf[BUFSIZ];
  2155. vty_out (vty, " %s/%d",
  2156. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2157. p->prefixlen);
  2158. if (pentry->ge)
  2159. vty_out (vty, " ge %d", pentry->ge);
  2160. if (pentry->le)
  2161. vty_out (vty, " le %d", pentry->le);
  2162. }
  2163. vty_out (vty, "%s", VTY_NEWLINE);
  2164. write++;
  2165. }
  2166. }
  2167. return write;
  2168. }
  2169. struct stream *
  2170. prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
  2171. u_char init_flag, u_char permit_flag, u_char deny_flag)
  2172. {
  2173. struct prefix_list_entry *pentry;
  2174. if (! plist)
  2175. return s;
  2176. for (pentry = plist->head; pentry; pentry = pentry->next)
  2177. {
  2178. u_char flag = init_flag;
  2179. struct prefix *p = &pentry->prefix;
  2180. flag |= (pentry->type == PREFIX_PERMIT ?
  2181. permit_flag : deny_flag);
  2182. stream_putc (s, flag);
  2183. stream_putl (s, (u_int32_t)pentry->seq);
  2184. stream_putc (s, (u_char)pentry->ge);
  2185. stream_putc (s, (u_char)pentry->le);
  2186. stream_put_prefix (s, p);
  2187. }
  2188. return s;
  2189. }
  2190. int
  2191. prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
  2192. int permit, int set)
  2193. {
  2194. struct prefix_list *plist;
  2195. struct prefix_list_entry *pentry;
  2196. /* ge and le value check */
  2197. if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
  2198. return CMD_WARNING;
  2199. if (orfp->le && orfp->le <= orfp->p.prefixlen)
  2200. return CMD_WARNING;
  2201. if (orfp->le && orfp->ge > orfp->le)
  2202. return CMD_WARNING;
  2203. if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
  2204. orfp->le = 0;
  2205. plist = prefix_list_get (AFI_ORF_PREFIX, name);
  2206. if (! plist)
  2207. return CMD_WARNING;
  2208. if (set)
  2209. {
  2210. pentry = prefix_list_entry_make (&orfp->p,
  2211. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2212. orfp->seq, orfp->le, orfp->ge, 0);
  2213. if (prefix_entry_dup_check (plist, pentry))
  2214. {
  2215. prefix_list_entry_free (pentry);
  2216. return CMD_WARNING;
  2217. }
  2218. prefix_list_entry_add (plist, pentry);
  2219. }
  2220. else
  2221. {
  2222. pentry = prefix_list_entry_lookup (plist, &orfp->p,
  2223. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2224. orfp->seq, orfp->le, orfp->ge);
  2225. if (! pentry)
  2226. return CMD_WARNING;
  2227. prefix_list_entry_delete (plist, pentry, 1);
  2228. }
  2229. return CMD_SUCCESS;
  2230. }
  2231. void
  2232. prefix_bgp_orf_remove_all (char *name)
  2233. {
  2234. struct prefix_list *plist;
  2235. plist = prefix_list_lookup (AFI_ORF_PREFIX, name);
  2236. if (plist)
  2237. prefix_list_delete (plist);
  2238. }
  2239. /* return prefix count */
  2240. int
  2241. prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name)
  2242. {
  2243. struct prefix_list *plist;
  2244. struct prefix_list_entry *pentry;
  2245. plist = prefix_list_lookup (AFI_ORF_PREFIX, name);
  2246. if (! plist)
  2247. return 0;
  2248. if (! vty)
  2249. return plist->count;
  2250. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  2251. afi == AFI_IP ? "" : "v6",
  2252. plist->name, plist->count, VTY_NEWLINE);
  2253. for (pentry = plist->head; pentry; pentry = pentry->next)
  2254. {
  2255. struct prefix *p = &pentry->prefix;
  2256. char buf[BUFSIZ];
  2257. vty_out (vty, " seq %d %s %s/%d", pentry->seq,
  2258. prefix_list_type_str (pentry),
  2259. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2260. p->prefixlen);
  2261. if (pentry->ge)
  2262. vty_out (vty, " ge %d", pentry->ge);
  2263. if (pentry->le)
  2264. vty_out (vty, " le %d", pentry->le);
  2265. vty_out (vty, "%s", VTY_NEWLINE);
  2266. }
  2267. return plist->count;
  2268. }
  2269. static void
  2270. prefix_list_reset_orf (void)
  2271. {
  2272. struct prefix_list *plist;
  2273. struct prefix_list *next;
  2274. struct prefix_master *master;
  2275. master = prefix_master_get (AFI_ORF_PREFIX);
  2276. if (master == NULL)
  2277. return;
  2278. for (plist = master->num.head; plist; plist = next)
  2279. {
  2280. next = plist->next;
  2281. prefix_list_delete (plist);
  2282. }
  2283. for (plist = master->str.head; plist; plist = next)
  2284. {
  2285. next = plist->next;
  2286. prefix_list_delete (plist);
  2287. }
  2288. assert (master->num.head == NULL);
  2289. assert (master->num.tail == NULL);
  2290. assert (master->str.head == NULL);
  2291. assert (master->str.tail == NULL);
  2292. master->seqnum = 1;
  2293. master->recent = NULL;
  2294. }
  2295. /* Prefix-list node. */
  2296. static struct cmd_node prefix_node =
  2297. {
  2298. PREFIX_NODE,
  2299. "", /* Prefix list has no interface. */
  2300. 1
  2301. };
  2302. static int
  2303. config_write_prefix_ipv4 (struct vty *vty)
  2304. {
  2305. return config_write_prefix_afi (AFI_IP, vty);
  2306. }
  2307. static void
  2308. prefix_list_reset_ipv4 (void)
  2309. {
  2310. struct prefix_list *plist;
  2311. struct prefix_list *next;
  2312. struct prefix_master *master;
  2313. master = prefix_master_get (AFI_IP);
  2314. if (master == NULL)
  2315. return;
  2316. for (plist = master->num.head; plist; plist = next)
  2317. {
  2318. next = plist->next;
  2319. prefix_list_delete (plist);
  2320. }
  2321. for (plist = master->str.head; plist; plist = next)
  2322. {
  2323. next = plist->next;
  2324. prefix_list_delete (plist);
  2325. }
  2326. assert (master->num.head == NULL);
  2327. assert (master->num.tail == NULL);
  2328. assert (master->str.head == NULL);
  2329. assert (master->str.tail == NULL);
  2330. master->seqnum = 1;
  2331. master->recent = NULL;
  2332. }
  2333. static void
  2334. prefix_list_init_ipv4 (void)
  2335. {
  2336. install_node (&prefix_node, config_write_prefix_ipv4);
  2337. install_element (CONFIG_NODE, &ip_prefix_list_cmd);
  2338. install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
  2339. install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
  2340. install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
  2341. install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
  2342. install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
  2343. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
  2344. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
  2345. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
  2346. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
  2347. install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
  2348. install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
  2349. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
  2350. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
  2351. install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
  2352. install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
  2353. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
  2354. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
  2355. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
  2356. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
  2357. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
  2358. install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
  2359. install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
  2360. install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
  2361. install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
  2362. install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
  2363. install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
  2364. install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
  2365. install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
  2366. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
  2367. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2368. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2369. install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
  2370. install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
  2371. install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
  2372. install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
  2373. install_element (ENABLE_NODE, &show_ip_prefix_list_cmd);
  2374. install_element (ENABLE_NODE, &show_ip_prefix_list_name_cmd);
  2375. install_element (ENABLE_NODE, &show_ip_prefix_list_name_seq_cmd);
  2376. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_cmd);
  2377. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2378. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2379. install_element (ENABLE_NODE, &show_ip_prefix_list_summary_cmd);
  2380. install_element (ENABLE_NODE, &show_ip_prefix_list_summary_name_cmd);
  2381. install_element (ENABLE_NODE, &show_ip_prefix_list_detail_cmd);
  2382. install_element (ENABLE_NODE, &show_ip_prefix_list_detail_name_cmd);
  2383. install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
  2384. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
  2385. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
  2386. }
  2387. #ifdef HAVE_IPV6
  2388. /* Prefix-list node. */
  2389. static struct cmd_node prefix_ipv6_node =
  2390. {
  2391. PREFIX_IPV6_NODE,
  2392. "", /* Prefix list has no interface. */
  2393. 1
  2394. };
  2395. static int
  2396. config_write_prefix_ipv6 (struct vty *vty)
  2397. {
  2398. return config_write_prefix_afi (AFI_IP6, vty);
  2399. }
  2400. static void
  2401. prefix_list_reset_ipv6 (void)
  2402. {
  2403. struct prefix_list *plist;
  2404. struct prefix_list *next;
  2405. struct prefix_master *master;
  2406. master = prefix_master_get (AFI_IP6);
  2407. if (master == NULL)
  2408. return;
  2409. for (plist = master->num.head; plist; plist = next)
  2410. {
  2411. next = plist->next;
  2412. prefix_list_delete (plist);
  2413. }
  2414. for (plist = master->str.head; plist; plist = next)
  2415. {
  2416. next = plist->next;
  2417. prefix_list_delete (plist);
  2418. }
  2419. assert (master->num.head == NULL);
  2420. assert (master->num.tail == NULL);
  2421. assert (master->str.head == NULL);
  2422. assert (master->str.tail == NULL);
  2423. master->seqnum = 1;
  2424. master->recent = NULL;
  2425. }
  2426. static void
  2427. prefix_list_init_ipv6 (void)
  2428. {
  2429. install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
  2430. install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
  2431. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
  2432. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
  2433. install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
  2434. install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
  2435. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
  2436. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
  2437. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
  2438. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
  2439. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
  2440. install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
  2441. install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
  2442. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
  2443. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
  2444. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
  2445. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
  2446. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
  2447. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
  2448. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
  2449. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
  2450. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
  2451. install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
  2452. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
  2453. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
  2454. install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
  2455. install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
  2456. install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
  2457. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
  2458. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2459. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2460. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2461. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2462. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
  2463. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2464. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
  2465. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2466. install_element (ENABLE_NODE, &show_ipv6_prefix_list_cmd);
  2467. install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_cmd);
  2468. install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2469. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2470. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2471. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2472. install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd);
  2473. install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2474. install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd);
  2475. install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2476. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
  2477. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
  2478. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
  2479. }
  2480. #endif /* HAVE_IPV6 */
  2481. void
  2482. prefix_list_init ()
  2483. {
  2484. prefix_list_init_ipv4 ();
  2485. #ifdef HAVE_IPV6
  2486. prefix_list_init_ipv6 ();
  2487. #endif /* HAVE_IPV6 */
  2488. }
  2489. void
  2490. prefix_list_reset ()
  2491. {
  2492. prefix_list_reset_ipv4 ();
  2493. #ifdef HAVE_IPV6
  2494. prefix_list_reset_ipv6 ();
  2495. #endif /* HAVE_IPV6 */
  2496. prefix_list_reset_orf ();
  2497. }