plist.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775
  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. /* Sequential number. */
  563. if (seq)
  564. seqnum = atoi (seq);
  565. /* ge and le number */
  566. if (ge)
  567. genum = atoi (ge);
  568. if (le)
  569. lenum = atoi (le);
  570. /* Check filter type. */
  571. if (strncmp ("permit", typestr, 1) == 0)
  572. type = PREFIX_PERMIT;
  573. else if (strncmp ("deny", typestr, 1) == 0)
  574. type = PREFIX_DENY;
  575. else
  576. {
  577. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  578. return CMD_WARNING;
  579. }
  580. /* "any" is special token for matching any IPv4 addresses. */
  581. switch (afi)
  582. {
  583. case AFI_IP:
  584. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  585. {
  586. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  587. genum = 0;
  588. lenum = IPV4_MAX_BITLEN;
  589. any = 1;
  590. }
  591. else
  592. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  593. if (ret <= 0)
  594. {
  595. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  596. return CMD_WARNING;
  597. }
  598. break;
  599. case AFI_IP6:
  600. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  601. {
  602. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  603. genum = 0;
  604. lenum = IPV6_MAX_BITLEN;
  605. any = 1;
  606. }
  607. else
  608. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  609. if (ret <= 0)
  610. {
  611. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  612. return CMD_WARNING;
  613. }
  614. break;
  615. }
  616. /* ge and le check. */
  617. if (genum && (genum <= p.prefixlen))
  618. return vty_invalid_prefix_range (vty, prefix);
  619. if (lenum && (lenum <= p.prefixlen))
  620. return vty_invalid_prefix_range (vty, prefix);
  621. if (lenum && (genum > lenum))
  622. return vty_invalid_prefix_range (vty, prefix);
  623. if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
  624. lenum = 0;
  625. /* Get prefix_list with name. */
  626. plist = prefix_list_get (afi, 0, name);
  627. /* Make prefix entry. */
  628. pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
  629. /* Check same policy. */
  630. dup = prefix_entry_dup_check (plist, pentry);
  631. if (dup)
  632. {
  633. prefix_list_entry_free (pentry);
  634. vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
  635. VTY_NEWLINE);
  636. vty_out (vty, " seq %d %s %s", dup->seq, typestr, prefix);
  637. if (! any && genum)
  638. vty_out (vty, " ge %d", genum);
  639. if (! any && lenum)
  640. vty_out (vty, " le %d", lenum);
  641. vty_out (vty, "%s", VTY_NEWLINE);
  642. return CMD_WARNING;
  643. }
  644. /* Install new filter to the access_list. */
  645. prefix_list_entry_add (plist, pentry);
  646. return CMD_SUCCESS;
  647. }
  648. static int
  649. vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
  650. const char *seq, const char *typestr,
  651. const char *prefix, const char *ge, const char *le)
  652. {
  653. int ret;
  654. enum prefix_list_type type;
  655. struct prefix_list *plist;
  656. struct prefix_list_entry *pentry;
  657. struct prefix p;
  658. int seqnum = -1;
  659. int lenum = 0;
  660. int genum = 0;
  661. /* Check prefix list name. */
  662. plist = prefix_list_lookup (afi, name);
  663. if (! plist)
  664. {
  665. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  666. return CMD_WARNING;
  667. }
  668. /* Only prefix-list name specified, delete the entire prefix-list. */
  669. if (seq == NULL && typestr == NULL && prefix == NULL &&
  670. ge == NULL && le == NULL)
  671. {
  672. prefix_list_delete (plist);
  673. return CMD_SUCCESS;
  674. }
  675. /* We must have, at a minimum, both the type and prefix here */
  676. if ((typestr == NULL) || (prefix == NULL))
  677. {
  678. vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
  679. return CMD_WARNING;
  680. }
  681. /* Check sequence number. */
  682. if (seq)
  683. seqnum = atoi (seq);
  684. /* ge and le number */
  685. if (ge)
  686. genum = atoi (ge);
  687. if (le)
  688. lenum = atoi (le);
  689. /* Check of filter type. */
  690. if (strncmp ("permit", typestr, 1) == 0)
  691. type = PREFIX_PERMIT;
  692. else if (strncmp ("deny", typestr, 1) == 0)
  693. type = PREFIX_DENY;
  694. else
  695. {
  696. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  697. return CMD_WARNING;
  698. }
  699. /* "any" is special token for matching any IPv4 addresses. */
  700. if (afi == AFI_IP)
  701. {
  702. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  703. {
  704. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  705. genum = 0;
  706. lenum = IPV4_MAX_BITLEN;
  707. }
  708. else
  709. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  710. if (ret <= 0)
  711. {
  712. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  713. return CMD_WARNING;
  714. }
  715. }
  716. #ifdef HAVE_IPV6
  717. else if (afi == AFI_IP6)
  718. {
  719. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  720. {
  721. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  722. genum = 0;
  723. lenum = IPV6_MAX_BITLEN;
  724. }
  725. else
  726. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  727. if (ret <= 0)
  728. {
  729. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  730. return CMD_WARNING;
  731. }
  732. }
  733. #endif /* HAVE_IPV6 */
  734. /* Lookup prefix entry. */
  735. pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
  736. if (pentry == NULL)
  737. {
  738. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  739. return CMD_WARNING;
  740. }
  741. /* Install new filter to the access_list. */
  742. prefix_list_entry_delete (plist, pentry, 1);
  743. return CMD_SUCCESS;
  744. }
  745. static int
  746. vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
  747. {
  748. struct prefix_list *plist;
  749. plist = prefix_list_lookup (afi, name);
  750. if (! plist)
  751. {
  752. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  753. return CMD_WARNING;
  754. }
  755. if (plist->desc)
  756. {
  757. XFREE (MTYPE_TMP, plist->desc);
  758. plist->desc = NULL;
  759. }
  760. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  761. prefix_list_delete (plist);
  762. return CMD_SUCCESS;
  763. }
  764. enum display_type
  765. {
  766. normal_display,
  767. summary_display,
  768. detail_display,
  769. sequential_display,
  770. longer_display,
  771. first_match_display
  772. };
  773. static void
  774. vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
  775. struct prefix_master *master, enum display_type dtype,
  776. int seqnum)
  777. {
  778. struct prefix_list_entry *pentry;
  779. /* Print the name of the protocol */
  780. if (zlog_default)
  781. vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
  782. if (dtype == normal_display)
  783. {
  784. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  785. afi == AFI_IP ? "" : "v6",
  786. plist->name, plist->count, VTY_NEWLINE);
  787. if (plist->desc)
  788. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  789. }
  790. else if (dtype == summary_display || dtype == detail_display)
  791. {
  792. vty_out (vty, "ip%s prefix-list %s:%s",
  793. afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
  794. if (plist->desc)
  795. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  796. vty_out (vty, " count: %d, range entries: %d, sequences: %d - %d%s",
  797. plist->count, plist->rangecount,
  798. plist->head ? plist->head->seq : 0,
  799. plist->tail ? plist->tail->seq : 0,
  800. VTY_NEWLINE);
  801. }
  802. if (dtype != summary_display)
  803. {
  804. for (pentry = plist->head; pentry; pentry = pentry->next)
  805. {
  806. if (dtype == sequential_display && pentry->seq != seqnum)
  807. continue;
  808. vty_out (vty, " ");
  809. if (master->seqnum)
  810. vty_out (vty, "seq %d ", pentry->seq);
  811. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  812. if (pentry->any)
  813. vty_out (vty, "any");
  814. else
  815. {
  816. struct prefix *p = &pentry->prefix;
  817. char buf[BUFSIZ];
  818. vty_out (vty, "%s/%d",
  819. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  820. p->prefixlen);
  821. if (pentry->ge)
  822. vty_out (vty, " ge %d", pentry->ge);
  823. if (pentry->le)
  824. vty_out (vty, " le %d", pentry->le);
  825. }
  826. if (dtype == detail_display || dtype == sequential_display)
  827. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  828. pentry->hitcnt, pentry->refcnt);
  829. vty_out (vty, "%s", VTY_NEWLINE);
  830. }
  831. }
  832. }
  833. static int
  834. vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
  835. const char *seq, enum display_type dtype)
  836. {
  837. struct prefix_list *plist;
  838. struct prefix_master *master;
  839. int seqnum = 0;
  840. master = prefix_master_get (afi, 0);
  841. if (master == NULL)
  842. return CMD_WARNING;
  843. if (seq)
  844. seqnum = atoi (seq);
  845. if (name)
  846. {
  847. plist = prefix_list_lookup (afi, name);
  848. if (! plist)
  849. {
  850. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  851. return CMD_WARNING;
  852. }
  853. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  854. }
  855. else
  856. {
  857. if (dtype == detail_display || dtype == summary_display)
  858. {
  859. if (master->recent)
  860. vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
  861. master->recent->name, VTY_NEWLINE);
  862. }
  863. for (plist = master->num.head; plist; plist = plist->next)
  864. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  865. for (plist = master->str.head; plist; plist = plist->next)
  866. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  867. }
  868. return CMD_SUCCESS;
  869. }
  870. static int
  871. vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
  872. const char *prefix, enum display_type type)
  873. {
  874. struct prefix_list *plist;
  875. struct prefix_list_entry *pentry;
  876. struct prefix p;
  877. int ret;
  878. int match;
  879. plist = prefix_list_lookup (afi, name);
  880. if (! plist)
  881. {
  882. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  883. return CMD_WARNING;
  884. }
  885. ret = str2prefix (prefix, &p);
  886. if (ret <= 0)
  887. {
  888. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  889. return CMD_WARNING;
  890. }
  891. for (pentry = plist->head; pentry; pentry = pentry->next)
  892. {
  893. match = 0;
  894. if (type == normal_display || type == first_match_display)
  895. if (prefix_same (&p, &pentry->prefix))
  896. match = 1;
  897. if (type == longer_display)
  898. if (prefix_match (&p, &pentry->prefix))
  899. match = 1;
  900. if (match)
  901. {
  902. vty_out (vty, " seq %d %s ",
  903. pentry->seq,
  904. prefix_list_type_str (pentry));
  905. if (pentry->any)
  906. vty_out (vty, "any");
  907. else
  908. {
  909. struct prefix *p = &pentry->prefix;
  910. char buf[BUFSIZ];
  911. vty_out (vty, "%s/%d",
  912. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  913. p->prefixlen);
  914. if (pentry->ge)
  915. vty_out (vty, " ge %d", pentry->ge);
  916. if (pentry->le)
  917. vty_out (vty, " le %d", pentry->le);
  918. }
  919. if (type == normal_display || type == first_match_display)
  920. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  921. pentry->hitcnt, pentry->refcnt);
  922. vty_out (vty, "%s", VTY_NEWLINE);
  923. if (type == first_match_display)
  924. return CMD_SUCCESS;
  925. }
  926. }
  927. return CMD_SUCCESS;
  928. }
  929. static int
  930. vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
  931. const char *prefix)
  932. {
  933. struct prefix_master *master;
  934. struct prefix_list *plist;
  935. struct prefix_list_entry *pentry;
  936. int ret;
  937. struct prefix p;
  938. master = prefix_master_get (afi, 0);
  939. if (master == NULL)
  940. return CMD_WARNING;
  941. if (name == NULL && prefix == NULL)
  942. {
  943. for (plist = master->num.head; plist; plist = plist->next)
  944. for (pentry = plist->head; pentry; pentry = pentry->next)
  945. pentry->hitcnt = 0;
  946. for (plist = master->str.head; plist; plist = plist->next)
  947. for (pentry = plist->head; pentry; pentry = pentry->next)
  948. pentry->hitcnt = 0;
  949. }
  950. else
  951. {
  952. plist = prefix_list_lookup (afi, name);
  953. if (! plist)
  954. {
  955. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  956. return CMD_WARNING;
  957. }
  958. if (prefix)
  959. {
  960. ret = str2prefix (prefix, &p);
  961. if (ret <= 0)
  962. {
  963. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  964. return CMD_WARNING;
  965. }
  966. }
  967. for (pentry = plist->head; pentry; pentry = pentry->next)
  968. {
  969. if (prefix)
  970. {
  971. if (prefix_match (&pentry->prefix, &p))
  972. pentry->hitcnt = 0;
  973. }
  974. else
  975. pentry->hitcnt = 0;
  976. }
  977. }
  978. return CMD_SUCCESS;
  979. }
  980. DEFUN (ip_prefix_list,
  981. ip_prefix_list_cmd,
  982. "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  983. IP_STR
  984. PREFIX_LIST_STR
  985. "Name of a prefix list\n"
  986. "Specify packets to reject\n"
  987. "Specify packets to forward\n"
  988. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  989. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  990. {
  991. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
  992. argv[1], argv[2], NULL, NULL);
  993. }
  994. DEFUN (ip_prefix_list_ge,
  995. ip_prefix_list_ge_cmd,
  996. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  997. IP_STR
  998. PREFIX_LIST_STR
  999. "Name of a prefix list\n"
  1000. "Specify packets to reject\n"
  1001. "Specify packets to forward\n"
  1002. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1003. "Minimum prefix length to be matched\n"
  1004. "Minimum prefix length\n")
  1005. {
  1006. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1007. argv[2], argv[3], NULL);
  1008. }
  1009. DEFUN (ip_prefix_list_ge_le,
  1010. ip_prefix_list_ge_le_cmd,
  1011. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1012. IP_STR
  1013. PREFIX_LIST_STR
  1014. "Name of a prefix list\n"
  1015. "Specify packets to reject\n"
  1016. "Specify packets to forward\n"
  1017. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1018. "Minimum prefix length to be matched\n"
  1019. "Minimum prefix length\n"
  1020. "Maximum prefix length to be matched\n"
  1021. "Maximum prefix length\n")
  1022. {
  1023. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1024. argv[2], argv[3], argv[4]);
  1025. }
  1026. DEFUN (ip_prefix_list_le,
  1027. ip_prefix_list_le_cmd,
  1028. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1029. IP_STR
  1030. PREFIX_LIST_STR
  1031. "Name of a prefix list\n"
  1032. "Specify packets to reject\n"
  1033. "Specify packets to forward\n"
  1034. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1035. "Maximum prefix length to be matched\n"
  1036. "Maximum prefix length\n")
  1037. {
  1038. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1039. argv[2], NULL, argv[3]);
  1040. }
  1041. DEFUN (ip_prefix_list_le_ge,
  1042. ip_prefix_list_le_ge_cmd,
  1043. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1044. IP_STR
  1045. PREFIX_LIST_STR
  1046. "Name of a prefix list\n"
  1047. "Specify packets to reject\n"
  1048. "Specify packets to forward\n"
  1049. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1050. "Maximum prefix length to be matched\n"
  1051. "Maximum prefix length\n"
  1052. "Minimum prefix length to be matched\n"
  1053. "Minimum prefix length\n")
  1054. {
  1055. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1056. argv[2], argv[4], argv[3]);
  1057. }
  1058. DEFUN (ip_prefix_list_seq,
  1059. ip_prefix_list_seq_cmd,
  1060. "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1061. IP_STR
  1062. PREFIX_LIST_STR
  1063. "Name of a prefix list\n"
  1064. "sequence number of an entry\n"
  1065. "Sequence number\n"
  1066. "Specify packets to reject\n"
  1067. "Specify packets to forward\n"
  1068. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1069. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1070. {
  1071. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1072. argv[3], NULL, NULL);
  1073. }
  1074. DEFUN (ip_prefix_list_seq_ge,
  1075. ip_prefix_list_seq_ge_cmd,
  1076. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1077. IP_STR
  1078. PREFIX_LIST_STR
  1079. "Name of a prefix list\n"
  1080. "sequence number of an entry\n"
  1081. "Sequence number\n"
  1082. "Specify packets to reject\n"
  1083. "Specify packets to forward\n"
  1084. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1085. "Minimum prefix length to be matched\n"
  1086. "Minimum prefix length\n")
  1087. {
  1088. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1089. argv[3], argv[4], NULL);
  1090. }
  1091. DEFUN (ip_prefix_list_seq_ge_le,
  1092. ip_prefix_list_seq_ge_le_cmd,
  1093. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1094. IP_STR
  1095. PREFIX_LIST_STR
  1096. "Name of a prefix list\n"
  1097. "sequence number of an entry\n"
  1098. "Sequence number\n"
  1099. "Specify packets to reject\n"
  1100. "Specify packets to forward\n"
  1101. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1102. "Minimum prefix length to be matched\n"
  1103. "Minimum prefix length\n"
  1104. "Maximum prefix length to be matched\n"
  1105. "Maximum prefix length\n")
  1106. {
  1107. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1108. argv[3], argv[4], argv[5]);
  1109. }
  1110. DEFUN (ip_prefix_list_seq_le,
  1111. ip_prefix_list_seq_le_cmd,
  1112. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1113. IP_STR
  1114. PREFIX_LIST_STR
  1115. "Name of a prefix list\n"
  1116. "sequence number of an entry\n"
  1117. "Sequence number\n"
  1118. "Specify packets to reject\n"
  1119. "Specify packets to forward\n"
  1120. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1121. "Maximum prefix length to be matched\n"
  1122. "Maximum prefix length\n")
  1123. {
  1124. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1125. argv[3], NULL, argv[4]);
  1126. }
  1127. DEFUN (ip_prefix_list_seq_le_ge,
  1128. ip_prefix_list_seq_le_ge_cmd,
  1129. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1130. IP_STR
  1131. PREFIX_LIST_STR
  1132. "Name of a prefix list\n"
  1133. "sequence number of an entry\n"
  1134. "Sequence number\n"
  1135. "Specify packets to reject\n"
  1136. "Specify packets to forward\n"
  1137. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1138. "Maximum prefix length to be matched\n"
  1139. "Maximum prefix length\n"
  1140. "Minimum prefix length to be matched\n"
  1141. "Minimum prefix length\n")
  1142. {
  1143. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1144. argv[3], argv[5], argv[4]);
  1145. }
  1146. DEFUN (no_ip_prefix_list,
  1147. no_ip_prefix_list_cmd,
  1148. "no ip prefix-list WORD",
  1149. NO_STR
  1150. IP_STR
  1151. PREFIX_LIST_STR
  1152. "Name of a prefix list\n")
  1153. {
  1154. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
  1155. NULL, NULL, NULL);
  1156. }
  1157. DEFUN (no_ip_prefix_list_prefix,
  1158. no_ip_prefix_list_prefix_cmd,
  1159. "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  1160. NO_STR
  1161. IP_STR
  1162. PREFIX_LIST_STR
  1163. "Name of a prefix list\n"
  1164. "Specify packets to reject\n"
  1165. "Specify packets to forward\n"
  1166. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1167. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1168. {
  1169. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1170. argv[2], NULL, NULL);
  1171. }
  1172. DEFUN (no_ip_prefix_list_ge,
  1173. no_ip_prefix_list_ge_cmd,
  1174. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  1175. NO_STR
  1176. IP_STR
  1177. PREFIX_LIST_STR
  1178. "Name of a prefix list\n"
  1179. "Specify packets to reject\n"
  1180. "Specify packets to forward\n"
  1181. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1182. "Minimum prefix length to be matched\n"
  1183. "Minimum prefix length\n")
  1184. {
  1185. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1186. argv[2], argv[3], NULL);
  1187. }
  1188. DEFUN (no_ip_prefix_list_ge_le,
  1189. no_ip_prefix_list_ge_le_cmd,
  1190. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1191. NO_STR
  1192. IP_STR
  1193. PREFIX_LIST_STR
  1194. "Name of a prefix list\n"
  1195. "Specify packets to reject\n"
  1196. "Specify packets to forward\n"
  1197. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1198. "Minimum prefix length to be matched\n"
  1199. "Minimum prefix length\n"
  1200. "Maximum prefix length to be matched\n"
  1201. "Maximum prefix length\n")
  1202. {
  1203. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1204. argv[2], argv[3], argv[4]);
  1205. }
  1206. DEFUN (no_ip_prefix_list_le,
  1207. no_ip_prefix_list_le_cmd,
  1208. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1209. NO_STR
  1210. IP_STR
  1211. PREFIX_LIST_STR
  1212. "Name of a prefix list\n"
  1213. "Specify packets to reject\n"
  1214. "Specify packets to forward\n"
  1215. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1216. "Maximum prefix length to be matched\n"
  1217. "Maximum prefix length\n")
  1218. {
  1219. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1220. argv[2], NULL, argv[3]);
  1221. }
  1222. DEFUN (no_ip_prefix_list_le_ge,
  1223. no_ip_prefix_list_le_ge_cmd,
  1224. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1225. NO_STR
  1226. IP_STR
  1227. PREFIX_LIST_STR
  1228. "Name of a prefix list\n"
  1229. "Specify packets to reject\n"
  1230. "Specify packets to forward\n"
  1231. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1232. "Maximum prefix length to be matched\n"
  1233. "Maximum prefix length\n"
  1234. "Minimum prefix length to be matched\n"
  1235. "Minimum prefix length\n")
  1236. {
  1237. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1238. argv[2], argv[4], argv[3]);
  1239. }
  1240. DEFUN (no_ip_prefix_list_seq,
  1241. no_ip_prefix_list_seq_cmd,
  1242. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1243. NO_STR
  1244. IP_STR
  1245. PREFIX_LIST_STR
  1246. "Name of a prefix list\n"
  1247. "sequence number of an entry\n"
  1248. "Sequence number\n"
  1249. "Specify packets to reject\n"
  1250. "Specify packets to forward\n"
  1251. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1252. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1253. {
  1254. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1255. argv[3], NULL, NULL);
  1256. }
  1257. DEFUN (no_ip_prefix_list_seq_ge,
  1258. no_ip_prefix_list_seq_ge_cmd,
  1259. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1260. NO_STR
  1261. IP_STR
  1262. PREFIX_LIST_STR
  1263. "Name of a prefix list\n"
  1264. "sequence number of an entry\n"
  1265. "Sequence number\n"
  1266. "Specify packets to reject\n"
  1267. "Specify packets to forward\n"
  1268. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1269. "Minimum prefix length to be matched\n"
  1270. "Minimum prefix length\n")
  1271. {
  1272. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1273. argv[3], argv[4], NULL);
  1274. }
  1275. DEFUN (no_ip_prefix_list_seq_ge_le,
  1276. no_ip_prefix_list_seq_ge_le_cmd,
  1277. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1278. NO_STR
  1279. IP_STR
  1280. PREFIX_LIST_STR
  1281. "Name of a prefix list\n"
  1282. "sequence number of an entry\n"
  1283. "Sequence number\n"
  1284. "Specify packets to reject\n"
  1285. "Specify packets to forward\n"
  1286. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1287. "Minimum prefix length to be matched\n"
  1288. "Minimum prefix length\n"
  1289. "Maximum prefix length to be matched\n"
  1290. "Maximum prefix length\n")
  1291. {
  1292. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1293. argv[3], argv[4], argv[5]);
  1294. }
  1295. DEFUN (no_ip_prefix_list_seq_le,
  1296. no_ip_prefix_list_seq_le_cmd,
  1297. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1298. NO_STR
  1299. IP_STR
  1300. PREFIX_LIST_STR
  1301. "Name of a prefix list\n"
  1302. "sequence number of an entry\n"
  1303. "Sequence number\n"
  1304. "Specify packets to reject\n"
  1305. "Specify packets to forward\n"
  1306. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1307. "Maximum prefix length to be matched\n"
  1308. "Maximum prefix length\n")
  1309. {
  1310. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1311. argv[3], NULL, argv[4]);
  1312. }
  1313. DEFUN (no_ip_prefix_list_seq_le_ge,
  1314. no_ip_prefix_list_seq_le_ge_cmd,
  1315. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1316. NO_STR
  1317. IP_STR
  1318. PREFIX_LIST_STR
  1319. "Name of a prefix list\n"
  1320. "sequence number of an entry\n"
  1321. "Sequence number\n"
  1322. "Specify packets to reject\n"
  1323. "Specify packets to forward\n"
  1324. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1325. "Maximum prefix length to be matched\n"
  1326. "Maximum prefix length\n"
  1327. "Minimum prefix length to be matched\n"
  1328. "Minimum prefix length\n")
  1329. {
  1330. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1331. argv[3], argv[5], argv[4]);
  1332. }
  1333. DEFUN (ip_prefix_list_sequence_number,
  1334. ip_prefix_list_sequence_number_cmd,
  1335. "ip prefix-list sequence-number",
  1336. IP_STR
  1337. PREFIX_LIST_STR
  1338. "Include/exclude sequence numbers in NVGEN\n")
  1339. {
  1340. prefix_master_ipv4.seqnum = 1;
  1341. return CMD_SUCCESS;
  1342. }
  1343. DEFUN (no_ip_prefix_list_sequence_number,
  1344. no_ip_prefix_list_sequence_number_cmd,
  1345. "no ip prefix-list sequence-number",
  1346. NO_STR
  1347. IP_STR
  1348. PREFIX_LIST_STR
  1349. "Include/exclude sequence numbers in NVGEN\n")
  1350. {
  1351. prefix_master_ipv4.seqnum = 0;
  1352. return CMD_SUCCESS;
  1353. }
  1354. DEFUN (ip_prefix_list_description,
  1355. ip_prefix_list_description_cmd,
  1356. "ip prefix-list WORD description .LINE",
  1357. IP_STR
  1358. PREFIX_LIST_STR
  1359. "Name of a prefix list\n"
  1360. "Prefix-list specific description\n"
  1361. "Up to 80 characters describing this prefix-list\n")
  1362. {
  1363. struct prefix_list *plist;
  1364. plist = prefix_list_get (AFI_IP, 0, argv[0]);
  1365. if (plist->desc)
  1366. {
  1367. XFREE (MTYPE_TMP, plist->desc);
  1368. plist->desc = NULL;
  1369. }
  1370. plist->desc = argv_concat(argv, argc, 1);
  1371. return CMD_SUCCESS;
  1372. }
  1373. DEFUN (no_ip_prefix_list_description,
  1374. no_ip_prefix_list_description_cmd,
  1375. "no ip prefix-list WORD description",
  1376. NO_STR
  1377. IP_STR
  1378. PREFIX_LIST_STR
  1379. "Name of a prefix list\n"
  1380. "Prefix-list specific description\n")
  1381. {
  1382. return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
  1383. }
  1384. ALIAS (no_ip_prefix_list_description,
  1385. no_ip_prefix_list_description_arg_cmd,
  1386. "no ip prefix-list WORD description .LINE",
  1387. NO_STR
  1388. IP_STR
  1389. PREFIX_LIST_STR
  1390. "Name of a prefix list\n"
  1391. "Prefix-list specific description\n"
  1392. "Up to 80 characters describing this prefix-list\n")
  1393. DEFUN (show_ip_prefix_list,
  1394. show_ip_prefix_list_cmd,
  1395. "show ip prefix-list",
  1396. SHOW_STR
  1397. IP_STR
  1398. PREFIX_LIST_STR)
  1399. {
  1400. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
  1401. }
  1402. DEFUN (show_ip_prefix_list_name,
  1403. show_ip_prefix_list_name_cmd,
  1404. "show ip prefix-list WORD",
  1405. SHOW_STR
  1406. IP_STR
  1407. PREFIX_LIST_STR
  1408. "Name of a prefix list\n")
  1409. {
  1410. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
  1411. }
  1412. DEFUN (show_ip_prefix_list_name_seq,
  1413. show_ip_prefix_list_name_seq_cmd,
  1414. "show ip prefix-list WORD seq <1-4294967295>",
  1415. SHOW_STR
  1416. IP_STR
  1417. PREFIX_LIST_STR
  1418. "Name of a prefix list\n"
  1419. "sequence number of an entry\n"
  1420. "Sequence number\n")
  1421. {
  1422. return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
  1423. }
  1424. DEFUN (show_ip_prefix_list_prefix,
  1425. show_ip_prefix_list_prefix_cmd,
  1426. "show ip prefix-list WORD A.B.C.D/M",
  1427. SHOW_STR
  1428. IP_STR
  1429. PREFIX_LIST_STR
  1430. "Name of a prefix list\n"
  1431. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1432. {
  1433. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
  1434. }
  1435. DEFUN (show_ip_prefix_list_prefix_longer,
  1436. show_ip_prefix_list_prefix_longer_cmd,
  1437. "show ip prefix-list WORD A.B.C.D/M longer",
  1438. SHOW_STR
  1439. IP_STR
  1440. PREFIX_LIST_STR
  1441. "Name of a prefix list\n"
  1442. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1443. "Lookup longer prefix\n")
  1444. {
  1445. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
  1446. }
  1447. DEFUN (show_ip_prefix_list_prefix_first_match,
  1448. show_ip_prefix_list_prefix_first_match_cmd,
  1449. "show ip prefix-list WORD A.B.C.D/M first-match",
  1450. SHOW_STR
  1451. IP_STR
  1452. PREFIX_LIST_STR
  1453. "Name of a prefix list\n"
  1454. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1455. "First matched prefix\n")
  1456. {
  1457. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
  1458. }
  1459. DEFUN (show_ip_prefix_list_summary,
  1460. show_ip_prefix_list_summary_cmd,
  1461. "show ip prefix-list summary",
  1462. SHOW_STR
  1463. IP_STR
  1464. PREFIX_LIST_STR
  1465. "Summary of prefix lists\n")
  1466. {
  1467. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
  1468. }
  1469. DEFUN (show_ip_prefix_list_summary_name,
  1470. show_ip_prefix_list_summary_name_cmd,
  1471. "show ip prefix-list summary WORD",
  1472. SHOW_STR
  1473. IP_STR
  1474. PREFIX_LIST_STR
  1475. "Summary of prefix lists\n"
  1476. "Name of a prefix list\n")
  1477. {
  1478. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
  1479. }
  1480. DEFUN (show_ip_prefix_list_detail,
  1481. show_ip_prefix_list_detail_cmd,
  1482. "show ip prefix-list detail",
  1483. SHOW_STR
  1484. IP_STR
  1485. PREFIX_LIST_STR
  1486. "Detail of prefix lists\n")
  1487. {
  1488. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
  1489. }
  1490. DEFUN (show_ip_prefix_list_detail_name,
  1491. show_ip_prefix_list_detail_name_cmd,
  1492. "show ip prefix-list detail WORD",
  1493. SHOW_STR
  1494. IP_STR
  1495. PREFIX_LIST_STR
  1496. "Detail of prefix lists\n"
  1497. "Name of a prefix list\n")
  1498. {
  1499. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
  1500. }
  1501. DEFUN (clear_ip_prefix_list,
  1502. clear_ip_prefix_list_cmd,
  1503. "clear ip prefix-list",
  1504. CLEAR_STR
  1505. IP_STR
  1506. PREFIX_LIST_STR)
  1507. {
  1508. return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
  1509. }
  1510. DEFUN (clear_ip_prefix_list_name,
  1511. clear_ip_prefix_list_name_cmd,
  1512. "clear ip prefix-list WORD",
  1513. CLEAR_STR
  1514. IP_STR
  1515. PREFIX_LIST_STR
  1516. "Name of a prefix list\n")
  1517. {
  1518. return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
  1519. }
  1520. DEFUN (clear_ip_prefix_list_name_prefix,
  1521. clear_ip_prefix_list_name_prefix_cmd,
  1522. "clear ip prefix-list WORD A.B.C.D/M",
  1523. CLEAR_STR
  1524. IP_STR
  1525. PREFIX_LIST_STR
  1526. "Name of a prefix list\n"
  1527. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1528. {
  1529. return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
  1530. }
  1531. #ifdef HAVE_IPV6
  1532. DEFUN (ipv6_prefix_list,
  1533. ipv6_prefix_list_cmd,
  1534. "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1535. IPV6_STR
  1536. PREFIX_LIST_STR
  1537. "Name of a prefix list\n"
  1538. "Specify packets to reject\n"
  1539. "Specify packets to forward\n"
  1540. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1541. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1542. {
  1543. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
  1544. argv[1], argv[2], NULL, NULL);
  1545. }
  1546. DEFUN (ipv6_prefix_list_ge,
  1547. ipv6_prefix_list_ge_cmd,
  1548. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1549. IPV6_STR
  1550. PREFIX_LIST_STR
  1551. "Name of a prefix list\n"
  1552. "Specify packets to reject\n"
  1553. "Specify packets to forward\n"
  1554. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1555. "Minimum prefix length to be matched\n"
  1556. "Minimum prefix length\n")
  1557. {
  1558. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1559. argv[2], argv[3], NULL);
  1560. }
  1561. DEFUN (ipv6_prefix_list_ge_le,
  1562. ipv6_prefix_list_ge_le_cmd,
  1563. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1564. IPV6_STR
  1565. PREFIX_LIST_STR
  1566. "Name of a prefix list\n"
  1567. "Specify packets to reject\n"
  1568. "Specify packets to forward\n"
  1569. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1570. "Minimum prefix length to be matched\n"
  1571. "Minimum prefix length\n"
  1572. "Maximum prefix length to be matched\n"
  1573. "Maximum prefix length\n")
  1574. {
  1575. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1576. argv[2], argv[3], argv[4]);
  1577. }
  1578. DEFUN (ipv6_prefix_list_le,
  1579. ipv6_prefix_list_le_cmd,
  1580. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1581. IPV6_STR
  1582. PREFIX_LIST_STR
  1583. "Name of a prefix list\n"
  1584. "Specify packets to reject\n"
  1585. "Specify packets to forward\n"
  1586. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1587. "Maximum prefix length to be matched\n"
  1588. "Maximum prefix length\n")
  1589. {
  1590. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1591. argv[2], NULL, argv[3]);
  1592. }
  1593. DEFUN (ipv6_prefix_list_le_ge,
  1594. ipv6_prefix_list_le_ge_cmd,
  1595. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1596. IPV6_STR
  1597. PREFIX_LIST_STR
  1598. "Name of a prefix list\n"
  1599. "Specify packets to reject\n"
  1600. "Specify packets to forward\n"
  1601. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1602. "Maximum prefix length to be matched\n"
  1603. "Maximum prefix length\n"
  1604. "Minimum prefix length to be matched\n"
  1605. "Minimum prefix length\n")
  1606. {
  1607. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1608. argv[2], argv[4], argv[3]);
  1609. }
  1610. DEFUN (ipv6_prefix_list_seq,
  1611. ipv6_prefix_list_seq_cmd,
  1612. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1613. IPV6_STR
  1614. PREFIX_LIST_STR
  1615. "Name of a prefix list\n"
  1616. "sequence number of an entry\n"
  1617. "Sequence number\n"
  1618. "Specify packets to reject\n"
  1619. "Specify packets to forward\n"
  1620. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1621. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1622. {
  1623. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1624. argv[3], NULL, NULL);
  1625. }
  1626. DEFUN (ipv6_prefix_list_seq_ge,
  1627. ipv6_prefix_list_seq_ge_cmd,
  1628. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1629. IPV6_STR
  1630. PREFIX_LIST_STR
  1631. "Name of a prefix list\n"
  1632. "sequence number of an entry\n"
  1633. "Sequence number\n"
  1634. "Specify packets to reject\n"
  1635. "Specify packets to forward\n"
  1636. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1637. "Minimum prefix length to be matched\n"
  1638. "Minimum prefix length\n")
  1639. {
  1640. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1641. argv[3], argv[4], NULL);
  1642. }
  1643. DEFUN (ipv6_prefix_list_seq_ge_le,
  1644. ipv6_prefix_list_seq_ge_le_cmd,
  1645. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1646. IPV6_STR
  1647. PREFIX_LIST_STR
  1648. "Name of a prefix list\n"
  1649. "sequence number of an entry\n"
  1650. "Sequence number\n"
  1651. "Specify packets to reject\n"
  1652. "Specify packets to forward\n"
  1653. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1654. "Minimum prefix length to be matched\n"
  1655. "Minimum prefix length\n"
  1656. "Maximum prefix length to be matched\n"
  1657. "Maximum prefix length\n")
  1658. {
  1659. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1660. argv[3], argv[4], argv[5]);
  1661. }
  1662. DEFUN (ipv6_prefix_list_seq_le,
  1663. ipv6_prefix_list_seq_le_cmd,
  1664. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1665. IPV6_STR
  1666. PREFIX_LIST_STR
  1667. "Name of a prefix list\n"
  1668. "sequence number of an entry\n"
  1669. "Sequence number\n"
  1670. "Specify packets to reject\n"
  1671. "Specify packets to forward\n"
  1672. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1673. "Maximum prefix length to be matched\n"
  1674. "Maximum prefix length\n")
  1675. {
  1676. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1677. argv[3], NULL, argv[4]);
  1678. }
  1679. DEFUN (ipv6_prefix_list_seq_le_ge,
  1680. ipv6_prefix_list_seq_le_ge_cmd,
  1681. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1682. IPV6_STR
  1683. PREFIX_LIST_STR
  1684. "Name of a prefix list\n"
  1685. "sequence number of an entry\n"
  1686. "Sequence number\n"
  1687. "Specify packets to reject\n"
  1688. "Specify packets to forward\n"
  1689. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1690. "Maximum prefix length to be matched\n"
  1691. "Maximum prefix length\n"
  1692. "Minimum prefix length to be matched\n"
  1693. "Minimum prefix length\n")
  1694. {
  1695. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1696. argv[3], argv[5], argv[4]);
  1697. }
  1698. DEFUN (no_ipv6_prefix_list,
  1699. no_ipv6_prefix_list_cmd,
  1700. "no ipv6 prefix-list WORD",
  1701. NO_STR
  1702. IPV6_STR
  1703. PREFIX_LIST_STR
  1704. "Name of a prefix list\n")
  1705. {
  1706. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
  1707. NULL, NULL, NULL);
  1708. }
  1709. DEFUN (no_ipv6_prefix_list_prefix,
  1710. no_ipv6_prefix_list_prefix_cmd,
  1711. "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1712. NO_STR
  1713. IPV6_STR
  1714. PREFIX_LIST_STR
  1715. "Name of a prefix list\n"
  1716. "Specify packets to reject\n"
  1717. "Specify packets to forward\n"
  1718. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1719. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1720. {
  1721. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1722. argv[2], NULL, NULL);
  1723. }
  1724. DEFUN (no_ipv6_prefix_list_ge,
  1725. no_ipv6_prefix_list_ge_cmd,
  1726. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1727. NO_STR
  1728. IPV6_STR
  1729. PREFIX_LIST_STR
  1730. "Name of a prefix list\n"
  1731. "Specify packets to reject\n"
  1732. "Specify packets to forward\n"
  1733. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1734. "Minimum prefix length to be matched\n"
  1735. "Minimum prefix length\n")
  1736. {
  1737. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1738. argv[2], argv[3], NULL);
  1739. }
  1740. DEFUN (no_ipv6_prefix_list_ge_le,
  1741. no_ipv6_prefix_list_ge_le_cmd,
  1742. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1743. NO_STR
  1744. IPV6_STR
  1745. PREFIX_LIST_STR
  1746. "Name of a prefix list\n"
  1747. "Specify packets to reject\n"
  1748. "Specify packets to forward\n"
  1749. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1750. "Minimum prefix length to be matched\n"
  1751. "Minimum prefix length\n"
  1752. "Maximum prefix length to be matched\n"
  1753. "Maximum prefix length\n")
  1754. {
  1755. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1756. argv[2], argv[3], argv[4]);
  1757. }
  1758. DEFUN (no_ipv6_prefix_list_le,
  1759. no_ipv6_prefix_list_le_cmd,
  1760. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1761. NO_STR
  1762. IPV6_STR
  1763. PREFIX_LIST_STR
  1764. "Name of a prefix list\n"
  1765. "Specify packets to reject\n"
  1766. "Specify packets to forward\n"
  1767. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1768. "Maximum prefix length to be matched\n"
  1769. "Maximum prefix length\n")
  1770. {
  1771. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1772. argv[2], NULL, argv[3]);
  1773. }
  1774. DEFUN (no_ipv6_prefix_list_le_ge,
  1775. no_ipv6_prefix_list_le_ge_cmd,
  1776. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1777. NO_STR
  1778. IPV6_STR
  1779. PREFIX_LIST_STR
  1780. "Name of a prefix list\n"
  1781. "Specify packets to reject\n"
  1782. "Specify packets to forward\n"
  1783. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1784. "Maximum prefix length to be matched\n"
  1785. "Maximum prefix length\n"
  1786. "Minimum prefix length to be matched\n"
  1787. "Minimum prefix length\n")
  1788. {
  1789. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1790. argv[2], argv[4], argv[3]);
  1791. }
  1792. DEFUN (no_ipv6_prefix_list_seq,
  1793. no_ipv6_prefix_list_seq_cmd,
  1794. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1795. NO_STR
  1796. IPV6_STR
  1797. PREFIX_LIST_STR
  1798. "Name of a prefix list\n"
  1799. "sequence number of an entry\n"
  1800. "Sequence number\n"
  1801. "Specify packets to reject\n"
  1802. "Specify packets to forward\n"
  1803. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1804. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1805. {
  1806. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1807. argv[3], NULL, NULL);
  1808. }
  1809. DEFUN (no_ipv6_prefix_list_seq_ge,
  1810. no_ipv6_prefix_list_seq_ge_cmd,
  1811. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1812. NO_STR
  1813. IPV6_STR
  1814. PREFIX_LIST_STR
  1815. "Name of a prefix list\n"
  1816. "sequence number of an entry\n"
  1817. "Sequence number\n"
  1818. "Specify packets to reject\n"
  1819. "Specify packets to forward\n"
  1820. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1821. "Minimum prefix length to be matched\n"
  1822. "Minimum prefix length\n")
  1823. {
  1824. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1825. argv[3], argv[4], NULL);
  1826. }
  1827. DEFUN (no_ipv6_prefix_list_seq_ge_le,
  1828. no_ipv6_prefix_list_seq_ge_le_cmd,
  1829. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1830. NO_STR
  1831. IPV6_STR
  1832. PREFIX_LIST_STR
  1833. "Name of a prefix list\n"
  1834. "sequence number of an entry\n"
  1835. "Sequence number\n"
  1836. "Specify packets to reject\n"
  1837. "Specify packets to forward\n"
  1838. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1839. "Minimum prefix length to be matched\n"
  1840. "Minimum prefix length\n"
  1841. "Maximum prefix length to be matched\n"
  1842. "Maximum prefix length\n")
  1843. {
  1844. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1845. argv[3], argv[4], argv[5]);
  1846. }
  1847. DEFUN (no_ipv6_prefix_list_seq_le,
  1848. no_ipv6_prefix_list_seq_le_cmd,
  1849. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1850. NO_STR
  1851. IPV6_STR
  1852. PREFIX_LIST_STR
  1853. "Name of a prefix list\n"
  1854. "sequence number of an entry\n"
  1855. "Sequence number\n"
  1856. "Specify packets to reject\n"
  1857. "Specify packets to forward\n"
  1858. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1859. "Maximum prefix length to be matched\n"
  1860. "Maximum prefix length\n")
  1861. {
  1862. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1863. argv[3], NULL, argv[4]);
  1864. }
  1865. DEFUN (no_ipv6_prefix_list_seq_le_ge,
  1866. no_ipv6_prefix_list_seq_le_ge_cmd,
  1867. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1868. NO_STR
  1869. IPV6_STR
  1870. PREFIX_LIST_STR
  1871. "Name of a prefix list\n"
  1872. "sequence number of an entry\n"
  1873. "Sequence number\n"
  1874. "Specify packets to reject\n"
  1875. "Specify packets to forward\n"
  1876. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1877. "Maximum prefix length to be matched\n"
  1878. "Maximum prefix length\n"
  1879. "Minimum prefix length to be matched\n"
  1880. "Minimum prefix length\n")
  1881. {
  1882. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1883. argv[3], argv[5], argv[4]);
  1884. }
  1885. DEFUN (ipv6_prefix_list_sequence_number,
  1886. ipv6_prefix_list_sequence_number_cmd,
  1887. "ipv6 prefix-list sequence-number",
  1888. IPV6_STR
  1889. PREFIX_LIST_STR
  1890. "Include/exclude sequence numbers in NVGEN\n")
  1891. {
  1892. prefix_master_ipv6.seqnum = 1;
  1893. return CMD_SUCCESS;
  1894. }
  1895. DEFUN (no_ipv6_prefix_list_sequence_number,
  1896. no_ipv6_prefix_list_sequence_number_cmd,
  1897. "no ipv6 prefix-list sequence-number",
  1898. NO_STR
  1899. IPV6_STR
  1900. PREFIX_LIST_STR
  1901. "Include/exclude sequence numbers in NVGEN\n")
  1902. {
  1903. prefix_master_ipv6.seqnum = 0;
  1904. return CMD_SUCCESS;
  1905. }
  1906. DEFUN (ipv6_prefix_list_description,
  1907. ipv6_prefix_list_description_cmd,
  1908. "ipv6 prefix-list WORD description .LINE",
  1909. IPV6_STR
  1910. PREFIX_LIST_STR
  1911. "Name of a prefix list\n"
  1912. "Prefix-list specific description\n"
  1913. "Up to 80 characters describing this prefix-list\n")
  1914. {
  1915. struct prefix_list *plist;
  1916. plist = prefix_list_get (AFI_IP6, 0, argv[0]);
  1917. if (plist->desc)
  1918. {
  1919. XFREE (MTYPE_TMP, plist->desc);
  1920. plist->desc = NULL;
  1921. }
  1922. plist->desc = argv_concat(argv, argc, 1);
  1923. return CMD_SUCCESS;
  1924. }
  1925. DEFUN (no_ipv6_prefix_list_description,
  1926. no_ipv6_prefix_list_description_cmd,
  1927. "no ipv6 prefix-list WORD description",
  1928. NO_STR
  1929. IPV6_STR
  1930. PREFIX_LIST_STR
  1931. "Name of a prefix list\n"
  1932. "Prefix-list specific description\n")
  1933. {
  1934. return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
  1935. }
  1936. ALIAS (no_ipv6_prefix_list_description,
  1937. no_ipv6_prefix_list_description_arg_cmd,
  1938. "no ipv6 prefix-list WORD description .LINE",
  1939. NO_STR
  1940. IPV6_STR
  1941. PREFIX_LIST_STR
  1942. "Name of a prefix list\n"
  1943. "Prefix-list specific description\n"
  1944. "Up to 80 characters describing this prefix-list\n")
  1945. DEFUN (show_ipv6_prefix_list,
  1946. show_ipv6_prefix_list_cmd,
  1947. "show ipv6 prefix-list",
  1948. SHOW_STR
  1949. IPV6_STR
  1950. PREFIX_LIST_STR)
  1951. {
  1952. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
  1953. }
  1954. DEFUN (show_ipv6_prefix_list_name,
  1955. show_ipv6_prefix_list_name_cmd,
  1956. "show ipv6 prefix-list WORD",
  1957. SHOW_STR
  1958. IPV6_STR
  1959. PREFIX_LIST_STR
  1960. "Name of a prefix list\n")
  1961. {
  1962. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
  1963. }
  1964. DEFUN (show_ipv6_prefix_list_name_seq,
  1965. show_ipv6_prefix_list_name_seq_cmd,
  1966. "show ipv6 prefix-list WORD seq <1-4294967295>",
  1967. SHOW_STR
  1968. IPV6_STR
  1969. PREFIX_LIST_STR
  1970. "Name of a prefix list\n"
  1971. "sequence number of an entry\n"
  1972. "Sequence number\n")
  1973. {
  1974. return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
  1975. }
  1976. DEFUN (show_ipv6_prefix_list_prefix,
  1977. show_ipv6_prefix_list_prefix_cmd,
  1978. "show ipv6 prefix-list WORD X:X::X:X/M",
  1979. SHOW_STR
  1980. IPV6_STR
  1981. PREFIX_LIST_STR
  1982. "Name of a prefix list\n"
  1983. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  1984. {
  1985. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
  1986. }
  1987. DEFUN (show_ipv6_prefix_list_prefix_longer,
  1988. show_ipv6_prefix_list_prefix_longer_cmd,
  1989. "show ipv6 prefix-list WORD X:X::X:X/M longer",
  1990. SHOW_STR
  1991. IPV6_STR
  1992. PREFIX_LIST_STR
  1993. "Name of a prefix list\n"
  1994. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1995. "Lookup longer prefix\n")
  1996. {
  1997. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
  1998. }
  1999. DEFUN (show_ipv6_prefix_list_prefix_first_match,
  2000. show_ipv6_prefix_list_prefix_first_match_cmd,
  2001. "show ipv6 prefix-list WORD X:X::X:X/M first-match",
  2002. SHOW_STR
  2003. IPV6_STR
  2004. PREFIX_LIST_STR
  2005. "Name of a prefix list\n"
  2006. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  2007. "First matched prefix\n")
  2008. {
  2009. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
  2010. }
  2011. DEFUN (show_ipv6_prefix_list_summary,
  2012. show_ipv6_prefix_list_summary_cmd,
  2013. "show ipv6 prefix-list summary",
  2014. SHOW_STR
  2015. IPV6_STR
  2016. PREFIX_LIST_STR
  2017. "Summary of prefix lists\n")
  2018. {
  2019. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
  2020. }
  2021. DEFUN (show_ipv6_prefix_list_summary_name,
  2022. show_ipv6_prefix_list_summary_name_cmd,
  2023. "show ipv6 prefix-list summary WORD",
  2024. SHOW_STR
  2025. IPV6_STR
  2026. PREFIX_LIST_STR
  2027. "Summary of prefix lists\n"
  2028. "Name of a prefix list\n")
  2029. {
  2030. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
  2031. }
  2032. DEFUN (show_ipv6_prefix_list_detail,
  2033. show_ipv6_prefix_list_detail_cmd,
  2034. "show ipv6 prefix-list detail",
  2035. SHOW_STR
  2036. IPV6_STR
  2037. PREFIX_LIST_STR
  2038. "Detail of prefix lists\n")
  2039. {
  2040. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
  2041. }
  2042. DEFUN (show_ipv6_prefix_list_detail_name,
  2043. show_ipv6_prefix_list_detail_name_cmd,
  2044. "show ipv6 prefix-list detail WORD",
  2045. SHOW_STR
  2046. IPV6_STR
  2047. PREFIX_LIST_STR
  2048. "Detail of prefix lists\n"
  2049. "Name of a prefix list\n")
  2050. {
  2051. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
  2052. }
  2053. DEFUN (clear_ipv6_prefix_list,
  2054. clear_ipv6_prefix_list_cmd,
  2055. "clear ipv6 prefix-list",
  2056. CLEAR_STR
  2057. IPV6_STR
  2058. PREFIX_LIST_STR)
  2059. {
  2060. return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
  2061. }
  2062. DEFUN (clear_ipv6_prefix_list_name,
  2063. clear_ipv6_prefix_list_name_cmd,
  2064. "clear ipv6 prefix-list WORD",
  2065. CLEAR_STR
  2066. IPV6_STR
  2067. PREFIX_LIST_STR
  2068. "Name of a prefix list\n")
  2069. {
  2070. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
  2071. }
  2072. DEFUN (clear_ipv6_prefix_list_name_prefix,
  2073. clear_ipv6_prefix_list_name_prefix_cmd,
  2074. "clear ipv6 prefix-list WORD X:X::X:X/M",
  2075. CLEAR_STR
  2076. IPV6_STR
  2077. PREFIX_LIST_STR
  2078. "Name of a prefix list\n"
  2079. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  2080. {
  2081. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
  2082. }
  2083. #endif /* HAVE_IPV6 */
  2084. /* Configuration write function. */
  2085. static int
  2086. config_write_prefix_afi (afi_t afi, struct vty *vty)
  2087. {
  2088. struct prefix_list *plist;
  2089. struct prefix_list_entry *pentry;
  2090. struct prefix_master *master;
  2091. int write = 0;
  2092. master = prefix_master_get (afi, 0);
  2093. if (master == NULL)
  2094. return 0;
  2095. if (! master->seqnum)
  2096. {
  2097. vty_out (vty, "no ip%s prefix-list sequence-number%s",
  2098. afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
  2099. vty_out (vty, "!%s", VTY_NEWLINE);
  2100. }
  2101. for (plist = master->num.head; plist; plist = plist->next)
  2102. {
  2103. if (plist->desc)
  2104. {
  2105. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2106. afi == AFI_IP ? "" : "v6",
  2107. plist->name, plist->desc, VTY_NEWLINE);
  2108. write++;
  2109. }
  2110. for (pentry = plist->head; pentry; pentry = pentry->next)
  2111. {
  2112. vty_out (vty, "ip%s prefix-list %s ",
  2113. afi == AFI_IP ? "" : "v6",
  2114. plist->name);
  2115. if (master->seqnum)
  2116. vty_out (vty, "seq %d ", pentry->seq);
  2117. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  2118. if (pentry->any)
  2119. vty_out (vty, "any");
  2120. else
  2121. {
  2122. struct prefix *p = &pentry->prefix;
  2123. char buf[BUFSIZ];
  2124. vty_out (vty, "%s/%d",
  2125. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2126. p->prefixlen);
  2127. if (pentry->ge)
  2128. vty_out (vty, " ge %d", pentry->ge);
  2129. if (pentry->le)
  2130. vty_out (vty, " le %d", pentry->le);
  2131. }
  2132. vty_out (vty, "%s", VTY_NEWLINE);
  2133. write++;
  2134. }
  2135. /* vty_out (vty, "!%s", VTY_NEWLINE); */
  2136. }
  2137. for (plist = master->str.head; plist; plist = plist->next)
  2138. {
  2139. if (plist->desc)
  2140. {
  2141. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2142. afi == AFI_IP ? "" : "v6",
  2143. plist->name, plist->desc, VTY_NEWLINE);
  2144. write++;
  2145. }
  2146. for (pentry = plist->head; pentry; pentry = pentry->next)
  2147. {
  2148. vty_out (vty, "ip%s prefix-list %s ",
  2149. afi == AFI_IP ? "" : "v6",
  2150. plist->name);
  2151. if (master->seqnum)
  2152. vty_out (vty, "seq %d ", pentry->seq);
  2153. vty_out (vty, "%s", prefix_list_type_str (pentry));
  2154. if (pentry->any)
  2155. vty_out (vty, " any");
  2156. else
  2157. {
  2158. struct prefix *p = &pentry->prefix;
  2159. char buf[BUFSIZ];
  2160. vty_out (vty, " %s/%d",
  2161. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2162. p->prefixlen);
  2163. if (pentry->ge)
  2164. vty_out (vty, " ge %d", pentry->ge);
  2165. if (pentry->le)
  2166. vty_out (vty, " le %d", pentry->le);
  2167. }
  2168. vty_out (vty, "%s", VTY_NEWLINE);
  2169. write++;
  2170. }
  2171. }
  2172. return write;
  2173. }
  2174. struct stream *
  2175. prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
  2176. u_char init_flag, u_char permit_flag, u_char deny_flag)
  2177. {
  2178. struct prefix_list_entry *pentry;
  2179. if (! plist)
  2180. return s;
  2181. for (pentry = plist->head; pentry; pentry = pentry->next)
  2182. {
  2183. u_char flag = init_flag;
  2184. struct prefix *p = &pentry->prefix;
  2185. flag |= (pentry->type == PREFIX_PERMIT ?
  2186. permit_flag : deny_flag);
  2187. stream_putc (s, flag);
  2188. stream_putl (s, (u_int32_t)pentry->seq);
  2189. stream_putc (s, (u_char)pentry->ge);
  2190. stream_putc (s, (u_char)pentry->le);
  2191. stream_put_prefix (s, p);
  2192. }
  2193. return s;
  2194. }
  2195. int
  2196. prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
  2197. int permit, int set)
  2198. {
  2199. struct prefix_list *plist;
  2200. struct prefix_list_entry *pentry;
  2201. /* ge and le value check */
  2202. if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
  2203. return CMD_WARNING;
  2204. if (orfp->le && orfp->le <= orfp->p.prefixlen)
  2205. return CMD_WARNING;
  2206. if (orfp->le && orfp->ge > orfp->le)
  2207. return CMD_WARNING;
  2208. if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
  2209. orfp->le = 0;
  2210. plist = prefix_list_get (afi, 1, name);
  2211. if (! plist)
  2212. return CMD_WARNING;
  2213. if (set)
  2214. {
  2215. pentry = prefix_list_entry_make (&orfp->p,
  2216. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2217. orfp->seq, orfp->le, orfp->ge, 0);
  2218. if (prefix_entry_dup_check (plist, pentry))
  2219. {
  2220. prefix_list_entry_free (pentry);
  2221. return CMD_WARNING;
  2222. }
  2223. prefix_list_entry_add (plist, pentry);
  2224. }
  2225. else
  2226. {
  2227. pentry = prefix_list_entry_lookup (plist, &orfp->p,
  2228. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2229. orfp->seq, orfp->le, orfp->ge);
  2230. if (! pentry)
  2231. return CMD_WARNING;
  2232. prefix_list_entry_delete (plist, pentry, 1);
  2233. }
  2234. return CMD_SUCCESS;
  2235. }
  2236. void
  2237. prefix_bgp_orf_remove_all (afi_t afi, char *name)
  2238. {
  2239. struct prefix_list *plist;
  2240. plist = prefix_bgp_orf_lookup (afi, name);
  2241. if (plist)
  2242. prefix_list_delete (plist);
  2243. }
  2244. /* return prefix count */
  2245. int
  2246. prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name)
  2247. {
  2248. struct prefix_list *plist;
  2249. struct prefix_list_entry *pentry;
  2250. plist = prefix_bgp_orf_lookup (afi, name);
  2251. if (! plist)
  2252. return 0;
  2253. if (! vty)
  2254. return plist->count;
  2255. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  2256. afi == AFI_IP ? "" : "v6",
  2257. plist->name, plist->count, VTY_NEWLINE);
  2258. for (pentry = plist->head; pentry; pentry = pentry->next)
  2259. {
  2260. struct prefix *p = &pentry->prefix;
  2261. char buf[BUFSIZ];
  2262. vty_out (vty, " seq %d %s %s/%d", pentry->seq,
  2263. prefix_list_type_str (pentry),
  2264. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2265. p->prefixlen);
  2266. if (pentry->ge)
  2267. vty_out (vty, " ge %d", pentry->ge);
  2268. if (pentry->le)
  2269. vty_out (vty, " le %d", pentry->le);
  2270. vty_out (vty, "%s", VTY_NEWLINE);
  2271. }
  2272. return plist->count;
  2273. }
  2274. static void
  2275. prefix_list_reset_afi (afi_t afi, int orf)
  2276. {
  2277. struct prefix_list *plist;
  2278. struct prefix_list *next;
  2279. struct prefix_master *master;
  2280. master = prefix_master_get (afi, orf);
  2281. if (master == NULL)
  2282. return;
  2283. for (plist = master->num.head; plist; plist = next)
  2284. {
  2285. next = plist->next;
  2286. prefix_list_delete (plist);
  2287. }
  2288. for (plist = master->str.head; plist; plist = next)
  2289. {
  2290. next = plist->next;
  2291. prefix_list_delete (plist);
  2292. }
  2293. assert (master->num.head == NULL);
  2294. assert (master->num.tail == NULL);
  2295. assert (master->str.head == NULL);
  2296. assert (master->str.tail == NULL);
  2297. master->seqnum = 1;
  2298. master->recent = NULL;
  2299. }
  2300. /* Prefix-list node. */
  2301. static struct cmd_node prefix_node =
  2302. {
  2303. PREFIX_NODE,
  2304. "", /* Prefix list has no interface. */
  2305. 1
  2306. };
  2307. static int
  2308. config_write_prefix_ipv4 (struct vty *vty)
  2309. {
  2310. return config_write_prefix_afi (AFI_IP, vty);
  2311. }
  2312. static void
  2313. prefix_list_init_ipv4 (void)
  2314. {
  2315. install_node (&prefix_node, config_write_prefix_ipv4);
  2316. install_element (CONFIG_NODE, &ip_prefix_list_cmd);
  2317. install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
  2318. install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
  2319. install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
  2320. install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
  2321. install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
  2322. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
  2323. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
  2324. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
  2325. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
  2326. install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
  2327. install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
  2328. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
  2329. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
  2330. install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
  2331. install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
  2332. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
  2333. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
  2334. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
  2335. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
  2336. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
  2337. install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
  2338. install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
  2339. install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
  2340. install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
  2341. install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
  2342. install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
  2343. install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
  2344. install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
  2345. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
  2346. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2347. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2348. install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
  2349. install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
  2350. install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
  2351. install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
  2352. install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
  2353. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
  2354. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
  2355. }
  2356. /* Prefix-list node. */
  2357. static struct cmd_node prefix_ipv6_node =
  2358. {
  2359. PREFIX_IPV6_NODE,
  2360. "", /* Prefix list has no interface. */
  2361. 1
  2362. };
  2363. static int
  2364. config_write_prefix_ipv6 (struct vty *vty)
  2365. {
  2366. return config_write_prefix_afi (AFI_IP6, vty);
  2367. }
  2368. static void
  2369. prefix_list_init_ipv6 (void)
  2370. {
  2371. install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
  2372. install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
  2373. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
  2374. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
  2375. install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
  2376. install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
  2377. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
  2378. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
  2379. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
  2380. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
  2381. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
  2382. install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
  2383. install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
  2384. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
  2385. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
  2386. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
  2387. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
  2388. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
  2389. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
  2390. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
  2391. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
  2392. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
  2393. install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
  2394. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
  2395. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
  2396. install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
  2397. install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
  2398. install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
  2399. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
  2400. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2401. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2402. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2403. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2404. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
  2405. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2406. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
  2407. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2408. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
  2409. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
  2410. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
  2411. }
  2412. void
  2413. prefix_list_init ()
  2414. {
  2415. prefix_list_init_ipv4 ();
  2416. #ifdef HAVE_IPV6
  2417. prefix_list_init_ipv6 ();
  2418. #endif /* HAVE_IPV6 */
  2419. }
  2420. void
  2421. prefix_list_reset ()
  2422. {
  2423. prefix_list_reset_afi (AFI_IP, 0);
  2424. prefix_list_reset_afi (AFI_IP6, 0);
  2425. prefix_list_reset_afi (AFI_IP, 1);
  2426. prefix_list_reset_afi (AFI_IP6, 1);
  2427. }