plist.c 75 KB

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