interface.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685
  1. /*
  2. * Interface function.
  3. * Copyright (C) 1997, 1999 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "if.h"
  24. #include "vty.h"
  25. #include "sockunion.h"
  26. #include "prefix.h"
  27. #include "command.h"
  28. #include "memory.h"
  29. #include "ioctl.h"
  30. #include "connected.h"
  31. #include "log.h"
  32. #include "zclient.h"
  33. #include "vrf.h"
  34. #include "command.h"
  35. #include "zebra/interface.h"
  36. #include "zebra/rtadv.h"
  37. #include "zebra/rib.h"
  38. #include "zebra/zserv.h"
  39. #include "zebra/redistribute.h"
  40. #include "zebra/debug.h"
  41. #include "zebra/irdp.h"
  42. #if defined (HAVE_RTADV)
  43. /* Order is intentional. Matches RFC4191. This array is also used for
  44. command matching, so only modify with care. */
  45. const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 };
  46. #endif /* HAVE_RTADV */
  47. /* Called when new interface is added. */
  48. static int
  49. if_zebra_new_hook (struct interface *ifp)
  50. {
  51. struct zebra_if *zebra_if;
  52. zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if));
  53. zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
  54. zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
  55. #if defined (HAVE_RTADV)
  56. {
  57. /* Set default router advertise values. */
  58. struct rtadvconf *rtadv;
  59. rtadv = &zebra_if->rtadv;
  60. rtadv->AdvSendAdvertisements = 0;
  61. rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
  62. rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
  63. rtadv->AdvIntervalTimer = 0;
  64. rtadv->AdvManagedFlag = 0;
  65. rtadv->AdvOtherConfigFlag = 0;
  66. rtadv->AdvHomeAgentFlag = 0;
  67. rtadv->AdvLinkMTU = 0;
  68. rtadv->AdvReachableTime = 0;
  69. rtadv->AdvRetransTimer = 0;
  70. rtadv->AdvCurHopLimit = 0;
  71. rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */
  72. rtadv->HomeAgentPreference = 0;
  73. rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */
  74. rtadv->AdvIntervalOption = 0;
  75. rtadv->DefaultPreference = RTADV_PREF_MEDIUM;
  76. rtadv->AdvPrefixList = list_new ();
  77. }
  78. #endif /* HAVE_RTADV */
  79. /* Initialize installed address chains tree. */
  80. zebra_if->ipv4_subnets = route_table_init ();
  81. ifp->info = zebra_if;
  82. return 0;
  83. }
  84. /* Called when interface is deleted. */
  85. static int
  86. if_zebra_delete_hook (struct interface *ifp)
  87. {
  88. struct zebra_if *zebra_if;
  89. if (ifp->info)
  90. {
  91. zebra_if = ifp->info;
  92. /* Free installed address chains tree. */
  93. if (zebra_if->ipv4_subnets)
  94. route_table_finish (zebra_if->ipv4_subnets);
  95. XFREE (MTYPE_TMP, zebra_if);
  96. }
  97. return 0;
  98. }
  99. /* Tie an interface address to its derived subnet list of addresses. */
  100. int
  101. if_subnet_add (struct interface *ifp, struct connected *ifc)
  102. {
  103. struct route_node *rn;
  104. struct zebra_if *zebra_if;
  105. struct prefix cp;
  106. struct list *addr_list;
  107. assert (ifp && ifp->info && ifc);
  108. zebra_if = ifp->info;
  109. /* Get address derived subnet node and associated address list, while marking
  110. address secondary attribute appropriately. */
  111. cp = *ifc->address;
  112. apply_mask (&cp);
  113. rn = route_node_get (zebra_if->ipv4_subnets, &cp);
  114. if ((addr_list = rn->info))
  115. SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
  116. else
  117. {
  118. UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
  119. rn->info = addr_list = list_new ();
  120. route_lock_node (rn);
  121. }
  122. /* Tie address at the tail of address list. */
  123. listnode_add (addr_list, ifc);
  124. /* Return list element count. */
  125. return (addr_list->count);
  126. }
  127. /* Untie an interface address from its derived subnet list of addresses. */
  128. int
  129. if_subnet_delete (struct interface *ifp, struct connected *ifc)
  130. {
  131. struct route_node *rn;
  132. struct zebra_if *zebra_if;
  133. struct list *addr_list;
  134. assert (ifp && ifp->info && ifc);
  135. zebra_if = ifp->info;
  136. /* Get address derived subnet node. */
  137. rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address);
  138. if (! (rn && rn->info))
  139. {
  140. zlog_warn("Trying to remove an address from an unknown subnet."
  141. " (please report this bug)");
  142. return -1;
  143. }
  144. route_unlock_node (rn);
  145. /* Untie address from subnet's address list. */
  146. addr_list = rn->info;
  147. /* Deleting an address that is not registered is a bug.
  148. * In any case, we shouldn't decrement the lock counter if the address
  149. * is unknown. */
  150. if (!listnode_lookup(addr_list, ifc))
  151. {
  152. zlog_warn("Trying to remove an address from a subnet where it is not"
  153. " currently registered. (please report this bug)");
  154. return -1;
  155. }
  156. listnode_delete (addr_list, ifc);
  157. route_unlock_node (rn);
  158. /* Return list element count, if not empty. */
  159. if (addr_list->count)
  160. {
  161. /* If deleted address is primary, mark subsequent one as such and distribute. */
  162. if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
  163. {
  164. ifc = listgetdata ((struct listnode *)listhead (addr_list));
  165. zebra_interface_address_delete_update (ifp, ifc);
  166. UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
  167. /* XXX: Linux kernel removes all the secondary addresses when the primary
  168. * address is removed. We could try to work around that, though this is
  169. * non-trivial. */
  170. zebra_interface_address_add_update (ifp, ifc);
  171. }
  172. return addr_list->count;
  173. }
  174. /* Otherwise, free list and route node. */
  175. list_free (addr_list);
  176. rn->info = NULL;
  177. route_unlock_node (rn);
  178. return 0;
  179. }
  180. /* if_flags_mangle: A place for hacks that require mangling
  181. * or tweaking the interface flags.
  182. *
  183. * ******************** Solaris flags hacks **************************
  184. *
  185. * Solaris IFF_UP flag reflects only the primary interface as the
  186. * routing socket only sends IFINFO for the primary interface. Hence
  187. * ~IFF_UP does not per se imply all the logical interfaces are also
  188. * down - which we only know of as addresses. Instead we must determine
  189. * whether the interface really is up or not according to how many
  190. * addresses are still attached. (Solaris always sends RTM_DELADDR if
  191. * an interface, logical or not, goes ~IFF_UP).
  192. *
  193. * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
  194. * are addresses left in struct connected, not just the actual underlying
  195. * IFF_UP flag.
  196. *
  197. * We must hence remember the real state of IFF_UP, which we do in
  198. * struct zebra_if.primary_state.
  199. *
  200. * Setting IFF_UP within zebra to administratively shutdown the
  201. * interface will affect only the primary interface/address on Solaris.
  202. ************************End Solaris flags hacks ***********************
  203. */
  204. static void
  205. if_flags_mangle (struct interface *ifp, uint64_t *newflags)
  206. {
  207. #ifdef SUNOS_5
  208. struct zebra_if *zif = ifp->info;
  209. zif->primary_state = *newflags & (IFF_UP & 0xff);
  210. if (CHECK_FLAG (zif->primary_state, IFF_UP)
  211. || listcount(ifp->connected) > 0)
  212. SET_FLAG (*newflags, IFF_UP);
  213. else
  214. UNSET_FLAG (*newflags, IFF_UP);
  215. #endif /* SUNOS_5 */
  216. }
  217. /* Update the flags field of the ifp with the new flag set provided.
  218. * Take whatever actions are required for any changes in flags we care
  219. * about.
  220. *
  221. * newflags should be the raw value, as obtained from the OS.
  222. */
  223. void
  224. if_flags_update (struct interface *ifp, uint64_t newflags)
  225. {
  226. if_flags_mangle (ifp, &newflags);
  227. if (if_is_operative (ifp))
  228. {
  229. /* operative -> inoperative? */
  230. ifp->flags = newflags;
  231. if (!if_is_operative (ifp))
  232. if_down (ifp);
  233. }
  234. else
  235. {
  236. /* inoperative -> operative? */
  237. ifp->flags = newflags;
  238. if (if_is_operative (ifp))
  239. if_up (ifp);
  240. }
  241. }
  242. /* Wake up configured address if it is not in current kernel
  243. address. */
  244. static void
  245. if_addr_wakeup (struct interface *ifp)
  246. {
  247. struct listnode *node, *nnode;
  248. struct connected *ifc;
  249. struct prefix *p;
  250. int ret;
  251. for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc))
  252. {
  253. p = ifc->address;
  254. if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)
  255. && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED))
  256. {
  257. /* Address check. */
  258. if (p->family == AF_INET)
  259. {
  260. if (! if_is_up (ifp))
  261. {
  262. /* Assume zebra is configured like following:
  263. *
  264. * interface gre0
  265. * ip addr 192.0.2.1/24
  266. * !
  267. *
  268. * As soon as zebra becomes first aware that gre0 exists in the
  269. * kernel, it will set gre0 up and configure its addresses.
  270. *
  271. * (This may happen at startup when the interface already exists
  272. * or during runtime when the interface is added to the kernel)
  273. *
  274. * XXX: IRDP code is calling here via if_add_update - this seems
  275. * somewhat weird.
  276. * XXX: RUNNING is not a settable flag on any system
  277. * I (paulj) am aware of.
  278. */
  279. if_set_flags (ifp, IFF_UP | IFF_RUNNING);
  280. if_refresh (ifp);
  281. }
  282. ret = if_set_prefix (ifp, ifc);
  283. if (ret < 0)
  284. {
  285. zlog_warn ("Can't set interface's address: %s",
  286. safe_strerror(errno));
  287. continue;
  288. }
  289. SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  290. /* The address will be advertised to zebra clients when the notification
  291. * from the kernel has been received.
  292. * It will also be added to the interface's subnet list then. */
  293. }
  294. #ifdef HAVE_IPV6
  295. if (p->family == AF_INET6)
  296. {
  297. if (! if_is_up (ifp))
  298. {
  299. /* See long comment above */
  300. if_set_flags (ifp, IFF_UP | IFF_RUNNING);
  301. if_refresh (ifp);
  302. }
  303. ret = if_prefix_add_ipv6 (ifp, ifc);
  304. if (ret < 0)
  305. {
  306. zlog_warn ("Can't set interface's address: %s",
  307. safe_strerror(errno));
  308. continue;
  309. }
  310. SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  311. /* The address will be advertised to zebra clients when the notification
  312. * from the kernel has been received. */
  313. }
  314. #endif /* HAVE_IPV6 */
  315. }
  316. }
  317. }
  318. static void if_count_up(struct zebra_if *zif)
  319. {
  320. event_counter_inc(&zif->up_events);
  321. }
  322. static void if_count_down(struct zebra_if *zif)
  323. {
  324. event_counter_inc(&zif->down_events);
  325. }
  326. void
  327. if_startup_count_up (void)
  328. {
  329. vrf_iter_t iter;
  330. struct interface *ifp;
  331. struct zebra_if *zif;
  332. struct listnode *node;
  333. for (iter = vrf_first(); iter != VRF_ITER_INVALID; iter = vrf_next(iter))
  334. {
  335. for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist(iter), node, ifp))
  336. {
  337. zif = ifp->info;
  338. if (!zif->up_events.count && if_is_operative(ifp))
  339. if_count_up(zif);
  340. }
  341. }
  342. }
  343. /* Handle interface addition */
  344. void
  345. if_add_update (struct interface *ifp)
  346. {
  347. struct zebra_if *if_data;
  348. if_data = ifp->info;
  349. assert(if_data);
  350. if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
  351. if_set_flags (ifp, IFF_MULTICAST);
  352. else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF)
  353. if_unset_flags (ifp, IFF_MULTICAST);
  354. zebra_interface_add_update (ifp);
  355. if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  356. {
  357. SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
  358. if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
  359. {
  360. if (IS_ZEBRA_DEBUG_KERNEL)
  361. zlog_debug ("interface %s vrf %u index %d is shutdown. "
  362. "Won't wake it up.",
  363. ifp->name, ifp->vrf_id, ifp->ifindex);
  364. return;
  365. }
  366. if_addr_wakeup (ifp);
  367. if (IS_ZEBRA_DEBUG_KERNEL)
  368. zlog_debug ("interface %s vrf %u index %d becomes active.",
  369. ifp->name, ifp->vrf_id, ifp->ifindex);
  370. }
  371. else
  372. {
  373. if (IS_ZEBRA_DEBUG_KERNEL)
  374. zlog_debug ("interface %s vrf %u index %d is added.",
  375. ifp->name, ifp->vrf_id, ifp->ifindex);
  376. }
  377. if (host_config_get())
  378. {
  379. /* If configuration and therefore link-detect have already been
  380. * loaded, count an initial up event when new interfaces are added
  381. * in up state.
  382. * If configuration has not been loaded yet, this is handled by
  383. * if_startup_count_up which is called after reading the config. */
  384. if (!if_data->up_events.count && if_is_operative(ifp))
  385. if_count_up(if_data);
  386. }
  387. }
  388. /* Handle an interface delete event */
  389. void
  390. if_delete_update (struct interface *ifp)
  391. {
  392. struct connected *ifc;
  393. struct prefix *p;
  394. struct route_node *rn;
  395. struct zebra_if *zebra_if;
  396. zebra_if = ifp->info;
  397. if (if_is_up(ifp))
  398. {
  399. zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
  400. ifp->name, ifp->vrf_id, ifp->ifindex);
  401. return;
  402. }
  403. /* Mark interface as inactive */
  404. UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
  405. if (IS_ZEBRA_DEBUG_KERNEL)
  406. zlog_debug ("interface %s vrf %u index %d is now inactive.",
  407. ifp->name, ifp->vrf_id, ifp->ifindex);
  408. /* Delete connected routes from the kernel. */
  409. if (ifp->connected)
  410. {
  411. struct listnode *node;
  412. struct listnode *last = NULL;
  413. while ((node = (last ? last->next : listhead (ifp->connected))))
  414. {
  415. ifc = listgetdata (node);
  416. p = ifc->address;
  417. if (p->family == AF_INET
  418. && (rn = route_node_lookup (zebra_if->ipv4_subnets, p)))
  419. {
  420. struct listnode *anode;
  421. struct listnode *next;
  422. struct listnode *first;
  423. struct list *addr_list;
  424. route_unlock_node (rn);
  425. addr_list = (struct list *) rn->info;
  426. /* Remove addresses, secondaries first. */
  427. first = listhead (addr_list);
  428. for (anode = first->next; anode || first; anode = next)
  429. {
  430. if (!anode)
  431. {
  432. anode = first;
  433. first = NULL;
  434. }
  435. next = anode->next;
  436. ifc = listgetdata (anode);
  437. p = ifc->address;
  438. connected_down_ipv4 (ifp, ifc);
  439. /* XXX: We have to send notifications here explicitly, because we destroy
  440. * the ifc before receiving the notification about the address being deleted.
  441. */
  442. zebra_interface_address_delete_update (ifp, ifc);
  443. UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
  444. UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  445. /* Remove from subnet chain. */
  446. list_delete_node (addr_list, anode);
  447. route_unlock_node (rn);
  448. /* Remove from interface address list (unconditionally). */
  449. if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  450. {
  451. listnode_delete (ifp->connected, ifc);
  452. connected_free (ifc);
  453. }
  454. else
  455. last = node;
  456. }
  457. /* Free chain list and respective route node. */
  458. list_delete (addr_list);
  459. rn->info = NULL;
  460. route_unlock_node (rn);
  461. }
  462. #ifdef HAVE_IPV6
  463. else if (p->family == AF_INET6)
  464. {
  465. connected_down_ipv6 (ifp, ifc);
  466. zebra_interface_address_delete_update (ifp, ifc);
  467. UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
  468. UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  469. if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  470. last = node;
  471. else
  472. {
  473. listnode_delete (ifp->connected, ifc);
  474. connected_free (ifc);
  475. }
  476. }
  477. #endif /* HAVE_IPV6 */
  478. else
  479. {
  480. last = node;
  481. }
  482. }
  483. }
  484. zebra_interface_delete_update (ifp);
  485. /* Update ifindex after distributing the delete message. This is in
  486. case any client needs to have the old value of ifindex available
  487. while processing the deletion. Each client daemon is responsible
  488. for setting ifindex to IFINDEX_INTERNAL after processing the
  489. interface deletion message. */
  490. ifp->ifindex = IFINDEX_INTERNAL;
  491. }
  492. /* Interface is up. */
  493. void
  494. if_up (struct interface *ifp)
  495. {
  496. struct listnode *node;
  497. struct listnode *next;
  498. struct connected *ifc;
  499. struct prefix *p;
  500. if_count_up(ifp->info);
  501. /* Notify the protocol daemons. */
  502. zebra_interface_up_update (ifp);
  503. /* Install connected routes to the kernel. */
  504. if (ifp->connected)
  505. {
  506. for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
  507. {
  508. p = ifc->address;
  509. if (p->family == AF_INET)
  510. connected_up_ipv4 (ifp, ifc);
  511. #ifdef HAVE_IPV6
  512. else if (p->family == AF_INET6)
  513. connected_up_ipv6 (ifp, ifc);
  514. #endif /* HAVE_IPV6 */
  515. }
  516. }
  517. /* Examine all static routes. */
  518. rib_update (ifp->vrf_id);
  519. }
  520. /* Interface goes down. We have to manage different behavior of based
  521. OS. */
  522. void
  523. if_down (struct interface *ifp)
  524. {
  525. struct listnode *node;
  526. struct listnode *next;
  527. struct connected *ifc;
  528. struct prefix *p;
  529. struct zebra_if *zif;
  530. zif = ifp->info;
  531. if (zif->up_events.count)
  532. if_count_down(zif);
  533. /* Notify to the protocol daemons. */
  534. zebra_interface_down_update (ifp);
  535. /* Delete connected routes from the kernel. */
  536. if (ifp->connected)
  537. {
  538. for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
  539. {
  540. p = ifc->address;
  541. if (p->family == AF_INET)
  542. connected_down_ipv4 (ifp, ifc);
  543. #ifdef HAVE_IPV6
  544. else if (p->family == AF_INET6)
  545. connected_down_ipv6 (ifp, ifc);
  546. #endif /* HAVE_IPV6 */
  547. }
  548. }
  549. /* Examine all static routes which direct to the interface. */
  550. rib_update (ifp->vrf_id);
  551. }
  552. void
  553. if_refresh (struct interface *ifp)
  554. {
  555. if_get_flags (ifp);
  556. }
  557. /* Output prefix string to vty. */
  558. static int
  559. prefix_vty_out (struct vty *vty, struct prefix *p)
  560. {
  561. char str[INET6_ADDRSTRLEN];
  562. inet_ntop (p->family, &p->u.prefix, str, sizeof (str));
  563. vty_out (vty, "%s", str);
  564. return strlen (str);
  565. }
  566. /* Dump if address information to vty. */
  567. static void
  568. connected_dump_vty (struct vty *vty, struct connected *connected)
  569. {
  570. struct prefix *p;
  571. /* Print interface address. */
  572. p = connected->address;
  573. vty_out (vty, " %s ", prefix_family_str (p));
  574. prefix_vty_out (vty, p);
  575. vty_out (vty, "/%d", p->prefixlen);
  576. /* If there is destination address, print it. */
  577. if (connected->destination)
  578. {
  579. vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
  580. prefix_vty_out (vty, connected->destination);
  581. }
  582. if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
  583. vty_out (vty, " secondary");
  584. if (connected->label)
  585. vty_out (vty, " %s", connected->label);
  586. vty_out (vty, "%s", VTY_NEWLINE);
  587. }
  588. #if defined (HAVE_RTADV)
  589. /* Dump interface ND information to vty. */
  590. static void
  591. nd_dump_vty (struct vty *vty, struct interface *ifp)
  592. {
  593. struct zebra_if *zif;
  594. struct rtadvconf *rtadv;
  595. int interval;
  596. zif = (struct zebra_if *) ifp->info;
  597. rtadv = &zif->rtadv;
  598. if (rtadv->AdvSendAdvertisements)
  599. {
  600. vty_out (vty, " ND advertised reachable time is %d milliseconds%s",
  601. rtadv->AdvReachableTime, VTY_NEWLINE);
  602. vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s",
  603. rtadv->AdvRetransTimer, VTY_NEWLINE);
  604. interval = rtadv->MaxRtrAdvInterval;
  605. if (interval % 1000)
  606. vty_out (vty, " ND router advertisements are sent every "
  607. "%d milliseconds%s", interval,
  608. VTY_NEWLINE);
  609. else
  610. vty_out (vty, " ND router advertisements are sent every "
  611. "%d seconds%s", interval / 1000,
  612. VTY_NEWLINE);
  613. if (rtadv->AdvDefaultLifetime != -1)
  614. vty_out (vty, " ND router advertisements live for %d seconds%s",
  615. rtadv->AdvDefaultLifetime, VTY_NEWLINE);
  616. else
  617. vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s",
  618. VTY_NEWLINE);
  619. vty_out (vty, " ND router advertisement default router preference is "
  620. "%s%s", rtadv_pref_strs[rtadv->DefaultPreference],
  621. VTY_NEWLINE);
  622. if (rtadv->AdvManagedFlag)
  623. vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s",
  624. VTY_NEWLINE);
  625. else
  626. vty_out (vty, " Hosts use stateless autoconfig for addresses.%s",
  627. VTY_NEWLINE);
  628. if (rtadv->AdvHomeAgentFlag)
  629. {
  630. vty_out (vty, " ND router advertisements with "
  631. "Home Agent flag bit set.%s",
  632. VTY_NEWLINE);
  633. if (rtadv->HomeAgentLifetime != -1)
  634. vty_out (vty, " Home Agent lifetime is %u seconds%s",
  635. rtadv->HomeAgentLifetime, VTY_NEWLINE);
  636. else
  637. vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s",
  638. VTY_NEWLINE);
  639. vty_out (vty, " Home Agent preference is %u%s",
  640. rtadv->HomeAgentPreference, VTY_NEWLINE);
  641. }
  642. if (rtadv->AdvIntervalOption)
  643. vty_out (vty, " ND router advertisements with Adv. Interval option.%s",
  644. VTY_NEWLINE);
  645. }
  646. }
  647. #endif /* HAVE_RTADV */
  648. /* Interface's information print out to vty interface. */
  649. static void
  650. if_dump_vty (struct vty *vty, struct interface *ifp)
  651. {
  652. struct connected *connected;
  653. struct listnode *node;
  654. struct route_node *rn;
  655. struct zebra_if *zebra_if;
  656. zebra_if = ifp->info;
  657. vty_out (vty, "Interface %s is ", ifp->name);
  658. if (if_is_up(ifp)) {
  659. vty_out (vty, "up, line protocol ");
  660. if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
  661. if (if_is_running(ifp))
  662. vty_out (vty, "is up%s", VTY_NEWLINE);
  663. else
  664. vty_out (vty, "is down%s", VTY_NEWLINE);
  665. } else {
  666. vty_out (vty, "detection is disabled%s", VTY_NEWLINE);
  667. }
  668. } else {
  669. vty_out (vty, "down%s", VTY_NEWLINE);
  670. }
  671. vty_out (vty, " Link ups: %s%s",
  672. event_counter_format(&zebra_if->up_events), VTY_NEWLINE);
  673. vty_out (vty, " Link downs: %s%s",
  674. event_counter_format(&zebra_if->down_events), VTY_NEWLINE);
  675. vty_out (vty, " vrf: %u%s", ifp->vrf_id, VTY_NEWLINE);
  676. if (ifp->desc)
  677. vty_out (vty, " Description: %s%s", ifp->desc,
  678. VTY_NEWLINE);
  679. if (ifp->ifindex == IFINDEX_INTERNAL)
  680. {
  681. vty_out(vty, " pseudo interface%s", VTY_NEWLINE);
  682. return;
  683. }
  684. else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  685. {
  686. vty_out(vty, " index %d inactive interface%s",
  687. ifp->ifindex,
  688. VTY_NEWLINE);
  689. return;
  690. }
  691. vty_out (vty, " index %d metric %d mtu %d ",
  692. ifp->ifindex, ifp->metric, ifp->mtu);
  693. #ifdef HAVE_IPV6
  694. if (ifp->mtu6 != ifp->mtu)
  695. vty_out (vty, "mtu6 %d ", ifp->mtu6);
  696. #endif
  697. vty_out (vty, "%s flags: %s%s", VTY_NEWLINE,
  698. if_flag_dump (ifp->flags), VTY_NEWLINE);
  699. /* Hardware address. */
  700. vty_out (vty, " Type: %s%s", if_link_type_str (ifp->ll_type), VTY_NEWLINE);
  701. if (ifp->hw_addr_len != 0)
  702. {
  703. int i;
  704. vty_out (vty, " HWaddr: ");
  705. for (i = 0; i < ifp->hw_addr_len; i++)
  706. vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);
  707. vty_out (vty, "%s", VTY_NEWLINE);
  708. }
  709. /* Bandwidth in kbps */
  710. if (ifp->bandwidth != 0)
  711. {
  712. vty_out(vty, " bandwidth %u kbps", ifp->bandwidth);
  713. vty_out(vty, "%s", VTY_NEWLINE);
  714. }
  715. for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn))
  716. {
  717. if (! rn->info)
  718. continue;
  719. for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected))
  720. connected_dump_vty (vty, connected);
  721. }
  722. for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
  723. {
  724. if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) &&
  725. (connected->address->family == AF_INET6))
  726. connected_dump_vty (vty, connected);
  727. }
  728. if (HAS_LINK_PARAMS(ifp))
  729. {
  730. int i;
  731. struct if_link_params *iflp = ifp->link_params;
  732. vty_out(vty, " Traffic Engineering Link Parameters:%s", VTY_NEWLINE);
  733. if (IS_PARAM_SET(iflp, LP_TE))
  734. vty_out(vty, " TE metric %u%s",iflp->te_metric, VTY_NEWLINE);
  735. if (IS_PARAM_SET(iflp, LP_MAX_BW))
  736. vty_out(vty, " Maximum Bandwidth %g (Byte/s)%s", iflp->max_bw, VTY_NEWLINE);
  737. if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
  738. vty_out(vty, " Maximum Reservable Bandwidth %g (Byte/s)%s", iflp->max_rsv_bw, VTY_NEWLINE);
  739. if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
  740. vty_out(vty, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE);
  741. for (i = 0; i < MAX_CLASS_TYPE; i+=2)
  742. vty_out(vty, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
  743. i, iflp->unrsv_bw[i], i+1, iflp->unrsv_bw[i+1], VTY_NEWLINE);
  744. }
  745. if (IS_PARAM_SET(iflp, LP_ADM_GRP))
  746. vty_out(vty, " Administrative Group:%u%s", iflp->admin_grp, VTY_NEWLINE);
  747. if (IS_PARAM_SET(iflp, LP_DELAY))
  748. {
  749. vty_out(vty, " Link Delay Average: %u (micro-sec.)", iflp->av_delay);
  750. if (IS_PARAM_SET(iflp, LP_MM_DELAY))
  751. {
  752. vty_out(vty, " Min: %u (micro-sec.)", iflp->min_delay);
  753. vty_out(vty, " Max: %u (micro-sec.)", iflp->max_delay);
  754. }
  755. vty_out(vty, "%s", VTY_NEWLINE);
  756. }
  757. if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
  758. vty_out(vty, " Link Delay Variation %u (micro-sec.)%s", iflp->delay_var, VTY_NEWLINE);
  759. if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
  760. vty_out(vty, " Link Packet Loss %g (in %%)%s", iflp->pkt_loss, VTY_NEWLINE);
  761. if (IS_PARAM_SET(iflp, LP_AVA_BW))
  762. vty_out(vty, " Available Bandwidth %g (Byte/s)%s", iflp->ava_bw, VTY_NEWLINE);
  763. if (IS_PARAM_SET(iflp, LP_RES_BW))
  764. vty_out(vty, " Residual Bandwidth %g (Byte/s)%s", iflp->res_bw, VTY_NEWLINE);
  765. if (IS_PARAM_SET(iflp, LP_USE_BW))
  766. vty_out(vty, " Utilized Bandwidth %g (Byte/s)%s", iflp->use_bw, VTY_NEWLINE);
  767. if (IS_PARAM_SET(iflp, LP_RMT_AS))
  768. vty_out(vty, " Neighbor ASBR IP: %s AS: %u %s", inet_ntoa(iflp->rmt_ip), iflp->rmt_as, VTY_NEWLINE);
  769. }
  770. #ifdef RTADV
  771. nd_dump_vty (vty, ifp);
  772. #endif /* RTADV */
  773. #if defined (HAVE_RTADV)
  774. nd_dump_vty (vty, ifp);
  775. #endif /* HAVE_RTADV */
  776. #ifdef HAVE_PROC_NET_DEV
  777. /* Statistics print out using proc file system. */
  778. vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, "
  779. "%lu dropped%s",
  780. ifp->stats.rx_packets, ifp->stats.rx_multicast,
  781. ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE);
  782. vty_out (vty, " %lu input errors, %lu length, %lu overrun,"
  783. " %lu CRC, %lu frame%s",
  784. ifp->stats.rx_errors, ifp->stats.rx_length_errors,
  785. ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
  786. ifp->stats.rx_frame_errors, VTY_NEWLINE);
  787. vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors,
  788. ifp->stats.rx_missed_errors, VTY_NEWLINE);
  789. vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s",
  790. ifp->stats.tx_packets, ifp->stats.tx_bytes,
  791. ifp->stats.tx_dropped, VTY_NEWLINE);
  792. vty_out (vty, " %lu output errors, %lu aborted, %lu carrier,"
  793. " %lu fifo, %lu heartbeat%s",
  794. ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
  795. ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
  796. ifp->stats.tx_heartbeat_errors, VTY_NEWLINE);
  797. vty_out (vty, " %lu window, %lu collisions%s",
  798. ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE);
  799. #endif /* HAVE_PROC_NET_DEV */
  800. #ifdef HAVE_NET_RT_IFLIST
  801. #if defined (__bsdi__) || defined (__NetBSD__)
  802. /* Statistics print out using sysctl (). */
  803. vty_out (vty, " input packets %llu, bytes %llu, dropped %llu,"
  804. " multicast packets %llu%s",
  805. (unsigned long long)ifp->stats.ifi_ipackets,
  806. (unsigned long long)ifp->stats.ifi_ibytes,
  807. (unsigned long long)ifp->stats.ifi_iqdrops,
  808. (unsigned long long)ifp->stats.ifi_imcasts,
  809. VTY_NEWLINE);
  810. vty_out (vty, " input errors %llu%s",
  811. (unsigned long long)ifp->stats.ifi_ierrors, VTY_NEWLINE);
  812. vty_out (vty, " output packets %llu, bytes %llu,"
  813. " multicast packets %llu%s",
  814. (unsigned long long)ifp->stats.ifi_opackets,
  815. (unsigned long long)ifp->stats.ifi_obytes,
  816. (unsigned long long)ifp->stats.ifi_omcasts,
  817. VTY_NEWLINE);
  818. vty_out (vty, " output errors %llu%s",
  819. (unsigned long long)ifp->stats.ifi_oerrors, VTY_NEWLINE);
  820. vty_out (vty, " collisions %llu%s",
  821. (unsigned long long)ifp->stats.ifi_collisions, VTY_NEWLINE);
  822. #else
  823. /* Statistics print out using sysctl (). */
  824. vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
  825. " multicast packets %lu%s",
  826. ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
  827. ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
  828. VTY_NEWLINE);
  829. vty_out (vty, " input errors %lu%s",
  830. ifp->stats.ifi_ierrors, VTY_NEWLINE);
  831. vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s",
  832. ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
  833. ifp->stats.ifi_omcasts, VTY_NEWLINE);
  834. vty_out (vty, " output errors %lu%s",
  835. ifp->stats.ifi_oerrors, VTY_NEWLINE);
  836. vty_out (vty, " collisions %lu%s",
  837. ifp->stats.ifi_collisions, VTY_NEWLINE);
  838. #endif /* __bsdi__ || __NetBSD__ */
  839. #endif /* HAVE_NET_RT_IFLIST */
  840. }
  841. /* Wrapper hook point for zebra daemon so that ifindex can be set
  842. * DEFUN macro not used as extract.pl HAS to ignore this
  843. * See also interface_cmd in lib/if.c
  844. */
  845. DEFUN_NOSH (zebra_interface,
  846. zebra_interface_cmd,
  847. "interface IFNAME",
  848. "Select an interface to configure\n"
  849. "Interface's name\n")
  850. {
  851. int ret;
  852. struct interface *ifp;
  853. /* Call lib interface() */
  854. if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
  855. return ret;
  856. ifp = vty->index;
  857. if (ifp->ifindex == IFINDEX_INTERNAL)
  858. /* Is this really necessary? Shouldn't status be initialized to 0
  859. in that case? */
  860. UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
  861. return ret;
  862. }
  863. ALIAS (zebra_interface,
  864. zebra_interface_vrf_cmd,
  865. "interface IFNAME " VRF_CMD_STR,
  866. "Select an interface to configure\n"
  867. "Interface's name\n"
  868. VRF_CMD_HELP_STR)
  869. struct cmd_node interface_node =
  870. {
  871. INTERFACE_NODE,
  872. "%s(config-if)# ",
  873. 1
  874. };
  875. /* Show all interfaces to vty. */
  876. DEFUN (show_interface, show_interface_cmd,
  877. "show interface",
  878. SHOW_STR
  879. "Interface status and configuration\n")
  880. {
  881. struct listnode *node;
  882. struct interface *ifp;
  883. vrf_id_t vrf_id = VRF_DEFAULT;
  884. #ifdef HAVE_PROC_NET_DEV
  885. /* If system has interface statistics via proc file system, update
  886. statistics. */
  887. ifstat_update_proc ();
  888. #endif /* HAVE_PROC_NET_DEV */
  889. #ifdef HAVE_NET_RT_IFLIST
  890. ifstat_update_sysctl ();
  891. #endif /* HAVE_NET_RT_IFLIST */
  892. if (argc > 0)
  893. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  894. /* All interface print. */
  895. for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
  896. if_dump_vty (vty, ifp);
  897. return CMD_SUCCESS;
  898. }
  899. ALIAS (show_interface,
  900. show_interface_vrf_cmd,
  901. "show interface " VRF_CMD_STR,
  902. SHOW_STR
  903. "Interface status and configuration\n"
  904. VRF_CMD_HELP_STR)
  905. /* Show all interfaces to vty. */
  906. DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd,
  907. "show interface " VRF_ALL_CMD_STR,
  908. SHOW_STR
  909. "Interface status and configuration\n"
  910. VRF_ALL_CMD_HELP_STR)
  911. {
  912. struct listnode *node;
  913. struct interface *ifp;
  914. vrf_iter_t iter;
  915. #ifdef HAVE_PROC_NET_DEV
  916. /* If system has interface statistics via proc file system, update
  917. statistics. */
  918. ifstat_update_proc ();
  919. #endif /* HAVE_PROC_NET_DEV */
  920. #ifdef HAVE_NET_RT_IFLIST
  921. ifstat_update_sysctl ();
  922. #endif /* HAVE_NET_RT_IFLIST */
  923. /* All interface print. */
  924. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  925. for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
  926. if_dump_vty (vty, ifp);
  927. return CMD_SUCCESS;
  928. }
  929. /* Show specified interface to vty. */
  930. DEFUN (show_interface_name, show_interface_name_cmd,
  931. "show interface IFNAME",
  932. SHOW_STR
  933. "Interface status and configuration\n"
  934. "Inteface name\n")
  935. {
  936. struct interface *ifp;
  937. vrf_id_t vrf_id = VRF_DEFAULT;
  938. #ifdef HAVE_PROC_NET_DEV
  939. /* If system has interface statistics via proc file system, update
  940. statistics. */
  941. ifstat_update_proc ();
  942. #endif /* HAVE_PROC_NET_DEV */
  943. #ifdef HAVE_NET_RT_IFLIST
  944. ifstat_update_sysctl ();
  945. #endif /* HAVE_NET_RT_IFLIST */
  946. if (argc > 1)
  947. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  948. /* Specified interface print. */
  949. ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
  950. if (ifp == NULL)
  951. {
  952. vty_out (vty, "%% Can't find interface %s%s", argv[0],
  953. VTY_NEWLINE);
  954. return CMD_WARNING;
  955. }
  956. if_dump_vty (vty, ifp);
  957. return CMD_SUCCESS;
  958. }
  959. ALIAS (show_interface_name,
  960. show_interface_name_vrf_cmd,
  961. "show interface IFNAME " VRF_CMD_STR,
  962. SHOW_STR
  963. "Interface status and configuration\n"
  964. "Inteface name\n"
  965. VRF_CMD_HELP_STR)
  966. /* Show specified interface to vty. */
  967. DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd,
  968. "show interface IFNAME " VRF_ALL_CMD_STR,
  969. SHOW_STR
  970. "Interface status and configuration\n"
  971. "Inteface name\n"
  972. VRF_ALL_CMD_HELP_STR)
  973. {
  974. struct interface *ifp;
  975. vrf_iter_t iter;
  976. int found = 0;
  977. #ifdef HAVE_PROC_NET_DEV
  978. /* If system has interface statistics via proc file system, update
  979. statistics. */
  980. ifstat_update_proc ();
  981. #endif /* HAVE_PROC_NET_DEV */
  982. #ifdef HAVE_NET_RT_IFLIST
  983. ifstat_update_sysctl ();
  984. #endif /* HAVE_NET_RT_IFLIST */
  985. /* All interface print. */
  986. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  987. {
  988. /* Specified interface print. */
  989. ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter));
  990. if (ifp)
  991. {
  992. if_dump_vty (vty, ifp);
  993. found++;
  994. }
  995. }
  996. if (!found)
  997. {
  998. vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE);
  999. return CMD_WARNING;
  1000. }
  1001. return CMD_SUCCESS;
  1002. }
  1003. static void
  1004. if_show_description (struct vty *vty, vrf_id_t vrf_id)
  1005. {
  1006. struct listnode *node;
  1007. struct interface *ifp;
  1008. vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE);
  1009. for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
  1010. {
  1011. int len;
  1012. len = vty_out (vty, "%s", ifp->name);
  1013. vty_out (vty, "%*s", (16 - len), " ");
  1014. if (if_is_up(ifp))
  1015. {
  1016. vty_out (vty, "up ");
  1017. if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
  1018. {
  1019. if (if_is_running(ifp))
  1020. vty_out (vty, "up ");
  1021. else
  1022. vty_out (vty, "down ");
  1023. }
  1024. else
  1025. {
  1026. vty_out (vty, "unknown ");
  1027. }
  1028. }
  1029. else
  1030. {
  1031. vty_out (vty, "down down ");
  1032. }
  1033. if (ifp->desc)
  1034. vty_out (vty, "%s", ifp->desc);
  1035. vty_out (vty, "%s", VTY_NEWLINE);
  1036. }
  1037. }
  1038. DEFUN (show_interface_desc,
  1039. show_interface_desc_cmd,
  1040. "show interface description",
  1041. SHOW_STR
  1042. "Interface status and configuration\n"
  1043. "Interface description\n")
  1044. {
  1045. vrf_id_t vrf_id = VRF_DEFAULT;
  1046. if (argc > 0)
  1047. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1048. if_show_description (vty, vrf_id);
  1049. return CMD_SUCCESS;
  1050. }
  1051. ALIAS (show_interface_desc,
  1052. show_interface_desc_vrf_cmd,
  1053. "show interface description " VRF_CMD_STR,
  1054. SHOW_STR
  1055. "Interface status and configuration\n"
  1056. "Interface description\n"
  1057. VRF_CMD_HELP_STR)
  1058. DEFUN (show_interface_desc_vrf_all,
  1059. show_interface_desc_vrf_all_cmd,
  1060. "show interface description " VRF_ALL_CMD_STR,
  1061. SHOW_STR
  1062. "Interface status and configuration\n"
  1063. "Interface description\n"
  1064. VRF_ALL_CMD_HELP_STR)
  1065. {
  1066. vrf_iter_t iter;
  1067. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1068. if (!list_isempty (vrf_iter2iflist (iter)))
  1069. {
  1070. vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE,
  1071. vrf_iter2id (iter),
  1072. VTY_NEWLINE, VTY_NEWLINE);
  1073. if_show_description (vty, vrf_iter2id (iter));
  1074. }
  1075. return CMD_SUCCESS;
  1076. }
  1077. DEFUN (multicast,
  1078. multicast_cmd,
  1079. "multicast",
  1080. "Set multicast flag to interface\n")
  1081. {
  1082. int ret;
  1083. struct interface *ifp;
  1084. struct zebra_if *if_data;
  1085. ifp = (struct interface *) vty->index;
  1086. if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  1087. {
  1088. ret = if_set_flags (ifp, IFF_MULTICAST);
  1089. if (ret < 0)
  1090. {
  1091. vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);
  1092. return CMD_WARNING;
  1093. }
  1094. if_refresh (ifp);
  1095. }
  1096. if_data = ifp->info;
  1097. if_data->multicast = IF_ZEBRA_MULTICAST_ON;
  1098. return CMD_SUCCESS;
  1099. }
  1100. DEFUN (no_multicast,
  1101. no_multicast_cmd,
  1102. "no multicast",
  1103. NO_STR
  1104. "Unset multicast flag to interface\n")
  1105. {
  1106. int ret;
  1107. struct interface *ifp;
  1108. struct zebra_if *if_data;
  1109. ifp = (struct interface *) vty->index;
  1110. if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  1111. {
  1112. ret = if_unset_flags (ifp, IFF_MULTICAST);
  1113. if (ret < 0)
  1114. {
  1115. vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);
  1116. return CMD_WARNING;
  1117. }
  1118. if_refresh (ifp);
  1119. }
  1120. if_data = ifp->info;
  1121. if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
  1122. return CMD_SUCCESS;
  1123. }
  1124. DEFUN (linkdetect,
  1125. linkdetect_cmd,
  1126. "link-detect",
  1127. "Enable link detection on interface\n")
  1128. {
  1129. struct interface *ifp;
  1130. int if_was_operative;
  1131. ifp = (struct interface *) vty->index;
  1132. if_was_operative = if_is_operative(ifp);
  1133. SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
  1134. /* When linkdetection is enabled, if might come down */
  1135. if (!if_is_operative(ifp) && if_was_operative) if_down(ifp);
  1136. /* FIXME: Will defer status change forwarding if interface
  1137. does not come down! */
  1138. return CMD_SUCCESS;
  1139. }
  1140. DEFUN (no_linkdetect,
  1141. no_linkdetect_cmd,
  1142. "no link-detect",
  1143. NO_STR
  1144. "Disable link detection on interface\n")
  1145. {
  1146. struct interface *ifp;
  1147. int if_was_operative;
  1148. ifp = (struct interface *) vty->index;
  1149. if_was_operative = if_is_operative(ifp);
  1150. UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
  1151. /* Interface may come up after disabling link detection */
  1152. if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
  1153. /* FIXME: see linkdetect_cmd */
  1154. return CMD_SUCCESS;
  1155. }
  1156. DEFUN (shutdown_if,
  1157. shutdown_if_cmd,
  1158. "shutdown",
  1159. "Shutdown the selected interface\n")
  1160. {
  1161. int ret;
  1162. struct interface *ifp;
  1163. struct zebra_if *if_data;
  1164. ifp = (struct interface *) vty->index;
  1165. if (ifp->ifindex != IFINDEX_INTERNAL)
  1166. {
  1167. ret = if_unset_flags (ifp, IFF_UP);
  1168. if (ret < 0)
  1169. {
  1170. vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
  1171. return CMD_WARNING;
  1172. }
  1173. if_refresh (ifp);
  1174. }
  1175. if_data = ifp->info;
  1176. if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
  1177. return CMD_SUCCESS;
  1178. }
  1179. DEFUN (no_shutdown_if,
  1180. no_shutdown_if_cmd,
  1181. "no shutdown",
  1182. NO_STR
  1183. "Shutdown the selected interface\n")
  1184. {
  1185. int ret;
  1186. struct interface *ifp;
  1187. struct zebra_if *if_data;
  1188. ifp = (struct interface *) vty->index;
  1189. if (ifp->ifindex != IFINDEX_INTERNAL)
  1190. {
  1191. ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
  1192. if (ret < 0)
  1193. {
  1194. vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
  1195. return CMD_WARNING;
  1196. }
  1197. if_refresh (ifp);
  1198. /* Some addresses (in particular, IPv6 addresses on Linux) get
  1199. * removed when the interface goes down. They need to be readded.
  1200. */
  1201. if_addr_wakeup(ifp);
  1202. }
  1203. if_data = ifp->info;
  1204. if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
  1205. return CMD_SUCCESS;
  1206. }
  1207. DEFUN (bandwidth_if,
  1208. bandwidth_if_cmd,
  1209. "bandwidth <1-10000000>",
  1210. "Set bandwidth informational parameter\n"
  1211. "Bandwidth in kilobits\n")
  1212. {
  1213. struct interface *ifp;
  1214. unsigned int bandwidth;
  1215. ifp = (struct interface *) vty->index;
  1216. bandwidth = strtol(argv[0], NULL, 10);
  1217. /* bandwidth range is <1-10000000> */
  1218. if (bandwidth < 1 || bandwidth > 10000000)
  1219. {
  1220. vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
  1221. return CMD_WARNING;
  1222. }
  1223. ifp->bandwidth = bandwidth;
  1224. /* force protocols to recalculate routes due to cost change */
  1225. if (if_is_operative (ifp))
  1226. zebra_interface_up_update (ifp);
  1227. return CMD_SUCCESS;
  1228. }
  1229. DEFUN (no_bandwidth_if,
  1230. no_bandwidth_if_cmd,
  1231. "no bandwidth",
  1232. NO_STR
  1233. "Set bandwidth informational parameter\n")
  1234. {
  1235. struct interface *ifp;
  1236. ifp = (struct interface *) vty->index;
  1237. ifp->bandwidth = 0;
  1238. /* force protocols to recalculate routes due to cost change */
  1239. if (if_is_operative (ifp))
  1240. zebra_interface_up_update (ifp);
  1241. return CMD_SUCCESS;
  1242. }
  1243. ALIAS (no_bandwidth_if,
  1244. no_bandwidth_if_val_cmd,
  1245. "no bandwidth <1-10000000>",
  1246. NO_STR
  1247. "Set bandwidth informational parameter\n"
  1248. "Bandwidth in kilobits\n")
  1249. struct cmd_node link_params_node =
  1250. {
  1251. LINK_PARAMS_NODE,
  1252. "%s(config-link-params)# ",
  1253. 1,
  1254. };
  1255. static void
  1256. link_param_cmd_set_uint32 (struct interface *ifp, uint32_t *field,
  1257. uint32_t type, uint32_t value)
  1258. {
  1259. /* Update field as needed */
  1260. if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value)
  1261. {
  1262. *field = value;
  1263. SET_PARAM(ifp->link_params, type);
  1264. /* force protocols to update LINK STATE due to parameters change */
  1265. if (if_is_operative (ifp))
  1266. zebra_interface_parameters_update (ifp);
  1267. }
  1268. }
  1269. static void
  1270. link_param_cmd_set_float (struct interface *ifp, float *field,
  1271. uint32_t type, float value)
  1272. {
  1273. /* Update field as needed */
  1274. if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value)
  1275. {
  1276. *field = value;
  1277. SET_PARAM(ifp->link_params, type);
  1278. /* force protocols to update LINK STATE due to parameters change */
  1279. if (if_is_operative (ifp))
  1280. zebra_interface_parameters_update (ifp);
  1281. }
  1282. }
  1283. static void
  1284. link_param_cmd_unset (struct interface *ifp, uint32_t type)
  1285. {
  1286. /* Unset field */
  1287. UNSET_PARAM(ifp->link_params, type);
  1288. /* force protocols to update LINK STATE due to parameters change */
  1289. if (if_is_operative (ifp))
  1290. zebra_interface_parameters_update (ifp);
  1291. }
  1292. DEFUN (link_params,
  1293. link_params_cmd,
  1294. "link-params",
  1295. LINK_PARAMS_STR)
  1296. {
  1297. vty->node = LINK_PARAMS_NODE;
  1298. return CMD_SUCCESS;
  1299. }
  1300. /* Specific Traffic Engineering parameters commands */
  1301. DEFUN (link_params_enable,
  1302. link_params_enable_cmd,
  1303. "enable",
  1304. "Activate link parameters on this interface\n")
  1305. {
  1306. struct interface *ifp = (struct interface *) vty->index;
  1307. /* This command could be issue at startup, when activate MPLS TE */
  1308. /* on a new interface or after a ON / OFF / ON toggle */
  1309. /* In all case, TE parameters are reset to their default factory */
  1310. if (IS_ZEBRA_DEBUG_EVENT)
  1311. zlog_debug ("Link-params: enable TE link parameters on interface %s", ifp->name);
  1312. if (!if_link_params_get (ifp))
  1313. {
  1314. if (IS_ZEBRA_DEBUG_EVENT)
  1315. zlog_debug ("Link-params: failed to init TE link parameters %s", ifp->name);
  1316. return CMD_WARNING;
  1317. }
  1318. /* force protocols to update LINK STATE due to parameters change */
  1319. if (if_is_operative (ifp))
  1320. zebra_interface_parameters_update (ifp);
  1321. return CMD_SUCCESS;
  1322. }
  1323. DEFUN (no_link_params_enable,
  1324. no_link_params_enable_cmd,
  1325. "no enable",
  1326. NO_STR
  1327. "Disable link parameters on this interface\n")
  1328. {
  1329. struct interface *ifp = (struct interface *) vty->index;
  1330. zlog_debug ("MPLS-TE: disable TE link parameters on interface %s", ifp->name);
  1331. if_link_params_free (ifp);
  1332. /* force protocols to update LINK STATE due to parameters change */
  1333. if (if_is_operative (ifp))
  1334. zebra_interface_parameters_update (ifp);
  1335. return CMD_SUCCESS;
  1336. }
  1337. /* STANDARD TE metrics */
  1338. DEFUN (link_params_metric,
  1339. link_params_metric_cmd,
  1340. "metric <0-4294967295>",
  1341. "Link metric for MPLS-TE purpose\n"
  1342. "Metric value in decimal\n")
  1343. {
  1344. struct interface *ifp = (struct interface *) vty->index;
  1345. struct if_link_params *iflp = if_link_params_get (ifp);
  1346. u_int32_t metric;
  1347. VTY_GET_ULONG("metric", metric, argv[0]);
  1348. /* Update TE metric if needed */
  1349. link_param_cmd_set_uint32 (ifp, &iflp->te_metric, LP_TE, metric);
  1350. return CMD_SUCCESS;
  1351. }
  1352. DEFUN (no_link_params_metric,
  1353. no_link_params_metric_cmd,
  1354. "no metric",
  1355. NO_STR
  1356. "Disbale Link Metric on this interface\n")
  1357. {
  1358. struct interface *ifp = (struct interface *) vty->index;
  1359. /* Unset TE Metric */
  1360. link_param_cmd_unset(ifp, LP_TE);
  1361. return CMD_SUCCESS;
  1362. }
  1363. DEFUN (link_params_maxbw,
  1364. link_params_maxbw_cmd,
  1365. "max-bw BANDWIDTH",
  1366. "Maximum bandwidth that can be used\n"
  1367. "Bytes/second (IEEE floating point format)\n")
  1368. {
  1369. struct interface *ifp = (struct interface *) vty->index;
  1370. struct if_link_params *iflp = if_link_params_get (ifp);
  1371. float bw;
  1372. if (sscanf (argv[0], "%g", &bw) != 1)
  1373. {
  1374. vty_out (vty, "link_params_maxbw: fscanf: %s%s", safe_strerror (errno),
  1375. VTY_NEWLINE);
  1376. return CMD_WARNING;
  1377. }
  1378. /* Check that Maximum bandwidth is not lower than other bandwidth parameters */
  1379. if ((bw <= iflp->max_rsv_bw)
  1380. || (bw <= iflp->unrsv_bw[0])
  1381. || (bw <= iflp->unrsv_bw[1])
  1382. || (bw <= iflp->unrsv_bw[2])
  1383. || (bw <= iflp->unrsv_bw[3])
  1384. || (bw <= iflp->unrsv_bw[4])
  1385. || (bw <= iflp->unrsv_bw[5])
  1386. || (bw <= iflp->unrsv_bw[6])
  1387. || (bw <= iflp->unrsv_bw[7])
  1388. || (bw <= iflp->ava_bw)
  1389. || (bw <= iflp->res_bw)
  1390. || (bw <= iflp->use_bw))
  1391. {
  1392. vty_out (vty,
  1393. "Maximum Bandwidth could not be lower than others bandwidth%s",
  1394. VTY_NEWLINE);
  1395. return CMD_WARNING;
  1396. }
  1397. /* Update Maximum Bandwidth if needed */
  1398. link_param_cmd_set_float (ifp, &iflp->max_bw, LP_MAX_BW, bw);
  1399. return CMD_SUCCESS;
  1400. }
  1401. DEFUN (link_params_max_rsv_bw,
  1402. link_params_max_rsv_bw_cmd,
  1403. "max-rsv-bw BANDWIDTH",
  1404. "Maximum bandwidth that may be reserved\n"
  1405. "Bytes/second (IEEE floating point format)\n")
  1406. {
  1407. struct interface *ifp = (struct interface *) vty->index;
  1408. struct if_link_params *iflp = if_link_params_get (ifp);
  1409. float bw;
  1410. if (sscanf (argv[0], "%g", &bw) != 1)
  1411. {
  1412. vty_out (vty, "link_params_max_rsv_bw: fscanf: %s%s", safe_strerror (errno),
  1413. VTY_NEWLINE);
  1414. return CMD_WARNING;
  1415. }
  1416. /* Check that bandwidth is not greater than maximum bandwidth parameter */
  1417. if (bw > iflp->max_bw)
  1418. {
  1419. vty_out (vty,
  1420. "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
  1421. iflp->max_bw, VTY_NEWLINE);
  1422. return CMD_WARNING;
  1423. }
  1424. /* Update Maximum Reservable Bandwidth if needed */
  1425. link_param_cmd_set_float (ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw);
  1426. return CMD_SUCCESS;
  1427. }
  1428. DEFUN (link_params_unrsv_bw,
  1429. link_params_unrsv_bw_cmd,
  1430. "unrsv-bw <0-7> BANDWIDTH",
  1431. "Unreserved bandwidth at each priority level\n"
  1432. "Priority\n"
  1433. "Bytes/second (IEEE floating point format)\n")
  1434. {
  1435. struct interface *ifp = (struct interface *) vty->index;
  1436. struct if_link_params *iflp = if_link_params_get (ifp);
  1437. int priority;
  1438. float bw;
  1439. /* We don't have to consider about range check here. */
  1440. if (sscanf (argv[0], "%d", &priority) != 1)
  1441. {
  1442. vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
  1443. VTY_NEWLINE);
  1444. return CMD_WARNING;
  1445. }
  1446. if (sscanf (argv[1], "%g", &bw) != 1)
  1447. {
  1448. vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
  1449. VTY_NEWLINE);
  1450. return CMD_WARNING;
  1451. }
  1452. /* Check that bandwidth is not greater than maximum bandwidth parameter */
  1453. if (bw > iflp->max_bw)
  1454. {
  1455. vty_out (vty,
  1456. "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
  1457. iflp->max_bw, VTY_NEWLINE);
  1458. return CMD_WARNING;
  1459. }
  1460. /* Update Unreserved Bandwidth if needed */
  1461. link_param_cmd_set_float (ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW, bw);
  1462. return CMD_SUCCESS;
  1463. }
  1464. DEFUN (link_params_admin_grp,
  1465. link_params_admin_grp_cmd,
  1466. "admin-grp BITPATTERN",
  1467. "Administrative group membership\n"
  1468. "32-bit Hexadecimal value (e.g. 0xa1)\n")
  1469. {
  1470. struct interface *ifp = (struct interface *) vty->index;
  1471. struct if_link_params *iflp = if_link_params_get (ifp);
  1472. unsigned long value;
  1473. if (sscanf (argv[0], "0x%lx", &value) != 1)
  1474. {
  1475. vty_out (vty, "link_params_admin_grp: fscanf: %s%s",
  1476. safe_strerror (errno), VTY_NEWLINE);
  1477. return CMD_WARNING;
  1478. }
  1479. /* Update Administrative Group if needed */
  1480. link_param_cmd_set_uint32 (ifp, &iflp->admin_grp, LP_ADM_GRP, value);
  1481. return CMD_SUCCESS;
  1482. }
  1483. DEFUN (no_link_params_admin_grp,
  1484. no_link_params_admin_grp_cmd,
  1485. "no admin-grp",
  1486. NO_STR
  1487. "Disbale Administrative group membership on this interface\n")
  1488. {
  1489. struct interface *ifp = (struct interface *) vty->index;
  1490. /* Unset Admin Group */
  1491. link_param_cmd_unset(ifp, LP_ADM_GRP);
  1492. return CMD_SUCCESS;
  1493. }
  1494. /* RFC5392 & RFC5316: INTER-AS */
  1495. DEFUN (link_params_inter_as,
  1496. link_params_inter_as_cmd,
  1497. "neighbor A.B.C.D as <1-4294967295>",
  1498. "Configure remote ASBR information (Neighbor IP address and AS number)\n"
  1499. "Remote IP address in dot decimal A.B.C.D\n"
  1500. "Remote AS number\n"
  1501. "AS number in the range <1-4294967295>\n")
  1502. {
  1503. struct interface *ifp = (struct interface *) vty->index;
  1504. struct if_link_params *iflp = if_link_params_get (ifp);
  1505. struct in_addr addr;
  1506. u_int32_t as;
  1507. if (!inet_aton (argv[0], &addr))
  1508. {
  1509. vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
  1510. return CMD_WARNING;
  1511. }
  1512. VTY_GET_ULONG("AS number", as, argv[1]);
  1513. /* Update Remote IP and Remote AS fields if needed */
  1514. if (IS_PARAM_UNSET(iflp, LP_RMT_AS)
  1515. || iflp->rmt_as != as
  1516. || iflp->rmt_ip.s_addr != addr.s_addr)
  1517. {
  1518. iflp->rmt_as = as;
  1519. iflp->rmt_ip.s_addr = addr.s_addr;
  1520. SET_PARAM(iflp, LP_RMT_AS);
  1521. /* force protocols to update LINK STATE due to parameters change */
  1522. if (if_is_operative (ifp))
  1523. zebra_interface_parameters_update (ifp);
  1524. }
  1525. return CMD_SUCCESS;
  1526. }
  1527. DEFUN (no_link_params_inter_as,
  1528. no_link_params_inter_as_cmd,
  1529. "no neighbor",
  1530. NO_STR
  1531. "Remove Neighbor IP address and AS number for Inter-AS TE\n")
  1532. {
  1533. struct interface *ifp = (struct interface *) vty->index;
  1534. struct if_link_params *iflp = if_link_params_get (ifp);
  1535. /* Reset Remote IP and AS neighbor */
  1536. iflp->rmt_as = 0;
  1537. iflp->rmt_ip.s_addr = 0;
  1538. UNSET_PARAM(iflp, LP_RMT_AS);
  1539. /* force protocols to update LINK STATE due to parameters change */
  1540. if (if_is_operative (ifp))
  1541. zebra_interface_parameters_update (ifp);
  1542. return CMD_SUCCESS;
  1543. }
  1544. /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions & draft-ietf-isis-metric-extensions-07.txt */
  1545. DEFUN (link_params_delay,
  1546. link_params_delay_cmd,
  1547. "delay <0-16777215>",
  1548. "Unidirectional Average Link Delay\n"
  1549. "Average delay in micro-second as decimal (0...16777215)\n")
  1550. {
  1551. struct interface *ifp = (struct interface *) vty->index;
  1552. struct if_link_params *iflp = if_link_params_get (ifp);
  1553. u_int32_t delay = 0, low = 0, high = 0;
  1554. u_int8_t update = 0;
  1555. /* Get and Check new delay values */
  1556. VTY_GET_ULONG("delay", delay, argv[0]);
  1557. switch (argc)
  1558. {
  1559. case 1:
  1560. /* Check new delay value against old Min and Max delays if set */
  1561. if (IS_PARAM_SET(iflp, LP_MM_DELAY)
  1562. && (delay <= iflp->min_delay || delay >= iflp->max_delay))
  1563. {
  1564. vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s",
  1565. iflp->min_delay, iflp->max_delay, VTY_NEWLINE);
  1566. return CMD_WARNING;
  1567. }
  1568. /* Update delay if value is not set or change */
  1569. if (IS_PARAM_UNSET(iflp, LP_DELAY)|| iflp->av_delay != delay)
  1570. {
  1571. iflp->av_delay = delay;
  1572. SET_PARAM(iflp, LP_DELAY);
  1573. update = 1;
  1574. }
  1575. /* Unset Min and Max delays if already set */
  1576. if (IS_PARAM_SET(iflp, LP_MM_DELAY))
  1577. {
  1578. iflp->min_delay = 0;
  1579. iflp->max_delay = 0;
  1580. UNSET_PARAM(iflp, LP_MM_DELAY);
  1581. update = 1;
  1582. }
  1583. break;
  1584. case 2:
  1585. vty_out (vty, "You should specify both Minimum and Maximum delay with Average delay%s",
  1586. VTY_NEWLINE);
  1587. return CMD_WARNING;
  1588. break;
  1589. case 3:
  1590. VTY_GET_ULONG("minimum delay", low, argv[1]);
  1591. VTY_GET_ULONG("maximum delay", high, argv[2]);
  1592. /* Check new delays value coherency */
  1593. if (delay <= low || delay >= high)
  1594. {
  1595. vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s",
  1596. low, high, VTY_NEWLINE);
  1597. return CMD_WARNING;
  1598. }
  1599. /* Update Delays if needed */
  1600. if (IS_PARAM_UNSET(iflp, LP_DELAY)
  1601. || IS_PARAM_UNSET(iflp, LP_MM_DELAY)
  1602. || iflp->av_delay != delay
  1603. || iflp->min_delay != low
  1604. || iflp->max_delay != high)
  1605. {
  1606. iflp->av_delay = delay;
  1607. SET_PARAM(iflp, LP_DELAY);
  1608. iflp->min_delay = low;
  1609. iflp->max_delay = high;
  1610. SET_PARAM(iflp, LP_MM_DELAY);
  1611. update = 1;
  1612. }
  1613. break;
  1614. default:
  1615. return CMD_WARNING;
  1616. break;
  1617. }
  1618. /* force protocols to update LINK STATE due to parameters change */
  1619. if (update == 1 && if_is_operative (ifp))
  1620. zebra_interface_parameters_update (ifp);
  1621. return CMD_SUCCESS;
  1622. }
  1623. ALIAS (link_params_delay,
  1624. link_params_delay_mm_cmd,
  1625. "delay <0-16777215> min <0-16777215> max <0-16777215>",
  1626. "Unidirectional Average Link Delay (optionally Minimum and Maximum delays)\n"
  1627. "Average delay in micro-second as decimal (0...16777215)\n"
  1628. "Minimum delay\n"
  1629. "Minimum delay in micro-second as decimal (0...16777215)\n"
  1630. "Maximum delay\n"
  1631. "Maximum delay in micro-second as decimal (0...16777215)\n")
  1632. DEFUN (no_link_params_delay,
  1633. no_link_params_delay_cmd,
  1634. "no delay",
  1635. NO_STR
  1636. "Disbale Unidirectional Average, Min & Max Link Delay on this interface\n")
  1637. {
  1638. struct interface *ifp = (struct interface *) vty->index;
  1639. struct if_link_params *iflp = if_link_params_get (ifp);
  1640. /* Unset Delays */
  1641. iflp->av_delay = 0;
  1642. UNSET_PARAM(iflp, LP_DELAY);
  1643. iflp->min_delay = 0;
  1644. iflp->max_delay = 0;
  1645. UNSET_PARAM(iflp, LP_MM_DELAY);
  1646. /* force protocols to update LINK STATE due to parameters change */
  1647. if (if_is_operative (ifp))
  1648. zebra_interface_parameters_update (ifp);
  1649. return CMD_SUCCESS;
  1650. }
  1651. DEFUN (link_params_delay_var,
  1652. link_params_delay_var_cmd,
  1653. "delay-variation <0-16777215>",
  1654. "Unidirectional Link Delay Variation\n"
  1655. "delay variation in micro-second as decimal (0...16777215)\n")
  1656. {
  1657. struct interface *ifp = (struct interface *) vty->index;
  1658. struct if_link_params *iflp = if_link_params_get (ifp);
  1659. u_int32_t value;
  1660. VTY_GET_ULONG("delay variation", value, argv[0]);
  1661. /* Update Delay Variation if needed */
  1662. link_param_cmd_set_uint32 (ifp, &iflp->delay_var, LP_DELAY_VAR, value);
  1663. return CMD_SUCCESS;
  1664. }
  1665. DEFUN (no_link_params_delay_var,
  1666. no_link_params_delay_var_cmd,
  1667. "no delay-variation",
  1668. NO_STR
  1669. "Disbale Unidirectional Delay Variation on this interface\n")
  1670. {
  1671. struct interface *ifp = (struct interface *) vty->index;
  1672. /* Unset Delay Variation */
  1673. link_param_cmd_unset(ifp, LP_DELAY_VAR);
  1674. return CMD_SUCCESS;
  1675. }
  1676. DEFUN (link_params_pkt_loss,
  1677. link_params_pkt_loss_cmd,
  1678. "packet-loss PERCENTAGE",
  1679. "Unidirectional Link Packet Loss\n"
  1680. "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
  1681. {
  1682. struct interface *ifp = (struct interface *) vty->index;
  1683. struct if_link_params *iflp = if_link_params_get (ifp);
  1684. float fval;
  1685. if (sscanf (argv[0], "%g", &fval) != 1)
  1686. {
  1687. vty_out (vty, "link_params_pkt_loss: fscanf: %s%s", safe_strerror (errno),
  1688. VTY_NEWLINE);
  1689. return CMD_WARNING;
  1690. }
  1691. if (fval > MAX_PKT_LOSS)
  1692. fval = MAX_PKT_LOSS;
  1693. /* Update Packet Loss if needed */
  1694. link_param_cmd_set_float (ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);
  1695. return CMD_SUCCESS;
  1696. }
  1697. DEFUN (no_link_params_pkt_loss,
  1698. no_link_params_pkt_loss_cmd,
  1699. "no packet-loss",
  1700. NO_STR
  1701. "Disbale Unidirectional Link Packet Loss on this interface\n")
  1702. {
  1703. struct interface *ifp = (struct interface *) vty->index;
  1704. /* Unset Packet Loss */
  1705. link_param_cmd_unset(ifp, LP_PKT_LOSS);
  1706. return CMD_SUCCESS;
  1707. }
  1708. DEFUN (link_params_res_bw,
  1709. link_params_res_bw_cmd,
  1710. "res-bw BANDWIDTH",
  1711. "Unidirectional Residual Bandwidth\n"
  1712. "Bytes/second (IEEE floating point format)\n")
  1713. {
  1714. struct interface *ifp = (struct interface *) vty->index;
  1715. struct if_link_params *iflp = if_link_params_get (ifp);
  1716. float bw;
  1717. if (sscanf (argv[0], "%g", &bw) != 1)
  1718. {
  1719. vty_out (vty, "link_params_res_bw: fscanf: %s%s", safe_strerror (errno),
  1720. VTY_NEWLINE);
  1721. return CMD_WARNING;
  1722. }
  1723. /* Check that bandwidth is not greater than maximum bandwidth parameter */
  1724. if (bw > iflp->max_bw)
  1725. {
  1726. vty_out (vty,
  1727. "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
  1728. iflp->max_bw, VTY_NEWLINE);
  1729. return CMD_WARNING;
  1730. }
  1731. /* Update Residual Bandwidth if needed */
  1732. link_param_cmd_set_float (ifp, &iflp->res_bw, LP_RES_BW, bw);
  1733. return CMD_SUCCESS;
  1734. }
  1735. DEFUN (no_link_params_res_bw,
  1736. no_link_params_res_bw_cmd,
  1737. "no res-bw",
  1738. NO_STR
  1739. "Disbale Unidirectional Residual Bandwidth on this interface\n")
  1740. {
  1741. struct interface *ifp = (struct interface *) vty->index;
  1742. /* Unset Residual Bandwidth */
  1743. link_param_cmd_unset(ifp, LP_RES_BW);
  1744. return CMD_SUCCESS;
  1745. }
  1746. DEFUN (link_params_ava_bw,
  1747. link_params_ava_bw_cmd,
  1748. "ava-bw BANDWIDTH",
  1749. "Unidirectional Available Bandwidth\n"
  1750. "Bytes/second (IEEE floating point format)\n")
  1751. {
  1752. struct interface *ifp = (struct interface *) vty->index;
  1753. struct if_link_params *iflp = if_link_params_get (ifp);
  1754. float bw;
  1755. if (sscanf (argv[0], "%g", &bw) != 1)
  1756. {
  1757. vty_out (vty, "link_params_ava_bw: fscanf: %s%s", safe_strerror (errno),
  1758. VTY_NEWLINE);
  1759. return CMD_WARNING;
  1760. }
  1761. /* Check that bandwidth is not greater than maximum bandwidth parameter */
  1762. if (bw > iflp->max_bw)
  1763. {
  1764. vty_out (vty,
  1765. "Available Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
  1766. iflp->max_bw, VTY_NEWLINE);
  1767. return CMD_WARNING;
  1768. }
  1769. /* Update Residual Bandwidth if needed */
  1770. link_param_cmd_set_float (ifp, &iflp->ava_bw, LP_AVA_BW, bw);
  1771. return CMD_SUCCESS;
  1772. }
  1773. DEFUN (no_link_params_ava_bw,
  1774. no_link_params_ava_bw_cmd,
  1775. "no ava-bw",
  1776. NO_STR
  1777. "Disbale Unidirectional Available Bandwidth on this interface\n")
  1778. {
  1779. struct interface *ifp = (struct interface *) vty->index;
  1780. /* Unset Available Bandwidth */
  1781. link_param_cmd_unset(ifp, LP_AVA_BW);
  1782. return CMD_SUCCESS;
  1783. }
  1784. DEFUN (link_params_use_bw,
  1785. link_params_use_bw_cmd,
  1786. "use-bw BANDWIDTH",
  1787. "Unidirectional Utilised Bandwidth\n"
  1788. "Bytes/second (IEEE floating point format)\n")
  1789. {
  1790. struct interface *ifp = (struct interface *) vty->index;
  1791. struct if_link_params *iflp = if_link_params_get (ifp);
  1792. float bw;
  1793. if (sscanf (argv[0], "%g", &bw) != 1)
  1794. {
  1795. vty_out (vty, "link_params_use_bw: fscanf: %s%s", safe_strerror (errno),
  1796. VTY_NEWLINE);
  1797. return CMD_WARNING;
  1798. }
  1799. /* Check that bandwidth is not greater than maximum bandwidth parameter */
  1800. if (bw > iflp->max_bw)
  1801. {
  1802. vty_out (vty,
  1803. "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
  1804. iflp->max_bw, VTY_NEWLINE);
  1805. return CMD_WARNING;
  1806. }
  1807. /* Update Utilized Bandwidth if needed */
  1808. link_param_cmd_set_float (ifp, &iflp->use_bw, LP_USE_BW, bw);
  1809. return CMD_SUCCESS;
  1810. }
  1811. DEFUN (no_link_params_use_bw,
  1812. no_link_params_use_bw_cmd,
  1813. "no use-bw",
  1814. NO_STR
  1815. "Disbale Unidirectional Utilised Bandwidth on this interface\n")
  1816. {
  1817. struct interface *ifp = (struct interface *) vty->index;
  1818. /* Unset Utilised Bandwidth */
  1819. link_param_cmd_unset(ifp, LP_USE_BW);
  1820. return CMD_SUCCESS;
  1821. }
  1822. static int
  1823. ip_address_install (struct vty *vty, struct interface *ifp,
  1824. const char *addr_str, const char *peer_str,
  1825. const char *label)
  1826. {
  1827. struct zebra_if *if_data;
  1828. struct prefix_ipv4 cp;
  1829. struct connected *ifc;
  1830. struct prefix_ipv4 *p;
  1831. int ret;
  1832. if_data = ifp->info;
  1833. ret = str2prefix_ipv4 (addr_str, &cp);
  1834. if (ret <= 0)
  1835. {
  1836. vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
  1837. return CMD_WARNING;
  1838. }
  1839. ifc = connected_check (ifp, (struct prefix *) &cp);
  1840. if (! ifc)
  1841. {
  1842. ifc = connected_new ();
  1843. ifc->ifp = ifp;
  1844. /* Address. */
  1845. p = prefix_ipv4_new ();
  1846. *p = cp;
  1847. ifc->address = (struct prefix *) p;
  1848. /* Broadcast. */
  1849. if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
  1850. {
  1851. p = prefix_ipv4_new ();
  1852. *p = cp;
  1853. p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen);
  1854. ifc->destination = (struct prefix *) p;
  1855. }
  1856. /* Label. */
  1857. if (label)
  1858. ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
  1859. /* Add to linked list. */
  1860. listnode_add (ifp->connected, ifc);
  1861. }
  1862. /* This address is configured from zebra. */
  1863. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  1864. SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
  1865. /* In case of this route need to install kernel. */
  1866. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
  1867. && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
  1868. && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
  1869. {
  1870. /* Some system need to up the interface to set IP address. */
  1871. if (! if_is_up (ifp))
  1872. {
  1873. if_set_flags (ifp, IFF_UP | IFF_RUNNING);
  1874. if_refresh (ifp);
  1875. }
  1876. ret = if_set_prefix (ifp, ifc);
  1877. if (ret < 0)
  1878. {
  1879. vty_out (vty, "%% Can't set interface IP address: %s.%s",
  1880. safe_strerror(errno), VTY_NEWLINE);
  1881. return CMD_WARNING;
  1882. }
  1883. SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  1884. /* The address will be advertised to zebra clients when the notification
  1885. * from the kernel has been received.
  1886. * It will also be added to the subnet chain list, then. */
  1887. }
  1888. return CMD_SUCCESS;
  1889. }
  1890. static int
  1891. ip_address_uninstall (struct vty *vty, struct interface *ifp,
  1892. const char *addr_str, const char *peer_str,
  1893. const char *label)
  1894. {
  1895. struct prefix_ipv4 cp;
  1896. struct connected *ifc;
  1897. int ret;
  1898. /* Convert to prefix structure. */
  1899. ret = str2prefix_ipv4 (addr_str, &cp);
  1900. if (ret <= 0)
  1901. {
  1902. vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
  1903. return CMD_WARNING;
  1904. }
  1905. /* Check current interface address. */
  1906. ifc = connected_check (ifp, (struct prefix *) &cp);
  1907. if (! ifc)
  1908. {
  1909. vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
  1910. return CMD_WARNING;
  1911. }
  1912. /* This is not configured address. */
  1913. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  1914. return CMD_WARNING;
  1915. UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
  1916. /* This is not real address or interface is not active. */
  1917. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
  1918. || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  1919. {
  1920. listnode_delete (ifp->connected, ifc);
  1921. connected_free (ifc);
  1922. return CMD_WARNING;
  1923. }
  1924. /* This is real route. */
  1925. ret = if_unset_prefix (ifp, ifc);
  1926. if (ret < 0)
  1927. {
  1928. vty_out (vty, "%% Can't unset interface IP address: %s.%s",
  1929. safe_strerror(errno), VTY_NEWLINE);
  1930. return CMD_WARNING;
  1931. }
  1932. UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  1933. /* we will receive a kernel notification about this route being removed.
  1934. * this will trigger its removal from the connected list. */
  1935. return CMD_SUCCESS;
  1936. }
  1937. DEFUN (ip_address,
  1938. ip_address_cmd,
  1939. "ip address A.B.C.D/M",
  1940. "Interface Internet Protocol config commands\n"
  1941. "Set the IP address of an interface\n"
  1942. "IP address (e.g. 10.0.0.1/8)\n")
  1943. {
  1944. return ip_address_install (vty, vty->index, argv[0], NULL, NULL);
  1945. }
  1946. DEFUN (no_ip_address,
  1947. no_ip_address_cmd,
  1948. "no ip address A.B.C.D/M",
  1949. NO_STR
  1950. "Interface Internet Protocol config commands\n"
  1951. "Set the IP address of an interface\n"
  1952. "IP Address (e.g. 10.0.0.1/8)")
  1953. {
  1954. return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL);
  1955. }
  1956. #ifdef HAVE_NETLINK
  1957. DEFUN (ip_address_label,
  1958. ip_address_label_cmd,
  1959. "ip address A.B.C.D/M label LINE",
  1960. "Interface Internet Protocol config commands\n"
  1961. "Set the IP address of an interface\n"
  1962. "IP address (e.g. 10.0.0.1/8)\n"
  1963. "Label of this address\n"
  1964. "Label\n")
  1965. {
  1966. return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]);
  1967. }
  1968. DEFUN (no_ip_address_label,
  1969. no_ip_address_label_cmd,
  1970. "no ip address A.B.C.D/M label LINE",
  1971. NO_STR
  1972. "Interface Internet Protocol config commands\n"
  1973. "Set the IP address of an interface\n"
  1974. "IP address (e.g. 10.0.0.1/8)\n"
  1975. "Label of this address\n"
  1976. "Label\n")
  1977. {
  1978. return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]);
  1979. }
  1980. #endif /* HAVE_NETLINK */
  1981. #ifdef HAVE_IPV6
  1982. static int
  1983. ipv6_address_install (struct vty *vty, struct interface *ifp,
  1984. const char *addr_str, const char *peer_str,
  1985. const char *label, int secondary)
  1986. {
  1987. struct zebra_if *if_data;
  1988. struct prefix_ipv6 cp;
  1989. struct connected *ifc;
  1990. struct prefix_ipv6 *p;
  1991. int ret;
  1992. if_data = ifp->info;
  1993. ret = str2prefix_ipv6 (addr_str, &cp);
  1994. if (ret <= 0)
  1995. {
  1996. vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
  1997. return CMD_WARNING;
  1998. }
  1999. ifc = connected_check (ifp, (struct prefix *) &cp);
  2000. if (! ifc)
  2001. {
  2002. ifc = connected_new ();
  2003. ifc->ifp = ifp;
  2004. /* Address. */
  2005. p = prefix_ipv6_new ();
  2006. *p = cp;
  2007. ifc->address = (struct prefix *) p;
  2008. /* Secondary. */
  2009. if (secondary)
  2010. SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
  2011. /* Label. */
  2012. if (label)
  2013. ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
  2014. /* Add to linked list. */
  2015. listnode_add (ifp->connected, ifc);
  2016. }
  2017. /* This address is configured from zebra. */
  2018. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  2019. SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
  2020. /* In case of this route need to install kernel. */
  2021. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
  2022. && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
  2023. && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
  2024. {
  2025. /* Some system need to up the interface to set IP address. */
  2026. if (! if_is_up (ifp))
  2027. {
  2028. if_set_flags (ifp, IFF_UP | IFF_RUNNING);
  2029. if_refresh (ifp);
  2030. }
  2031. ret = if_prefix_add_ipv6 (ifp, ifc);
  2032. if (ret < 0)
  2033. {
  2034. vty_out (vty, "%% Can't set interface IP address: %s.%s",
  2035. safe_strerror(errno), VTY_NEWLINE);
  2036. return CMD_WARNING;
  2037. }
  2038. SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  2039. /* The address will be advertised to zebra clients when the notification
  2040. * from the kernel has been received. */
  2041. }
  2042. return CMD_SUCCESS;
  2043. }
  2044. static int
  2045. ipv6_address_uninstall (struct vty *vty, struct interface *ifp,
  2046. const char *addr_str, const char *peer_str,
  2047. const char *label, int secondry)
  2048. {
  2049. struct prefix_ipv6 cp;
  2050. struct connected *ifc;
  2051. int ret;
  2052. /* Convert to prefix structure. */
  2053. ret = str2prefix_ipv6 (addr_str, &cp);
  2054. if (ret <= 0)
  2055. {
  2056. vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
  2057. return CMD_WARNING;
  2058. }
  2059. /* Check current interface address. */
  2060. ifc = connected_check (ifp, (struct prefix *) &cp);
  2061. if (! ifc)
  2062. {
  2063. vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
  2064. return CMD_WARNING;
  2065. }
  2066. /* This is not configured address. */
  2067. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  2068. return CMD_WARNING;
  2069. UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
  2070. /* This is not real address or interface is not active. */
  2071. if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
  2072. || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  2073. {
  2074. listnode_delete (ifp->connected, ifc);
  2075. connected_free (ifc);
  2076. return CMD_WARNING;
  2077. }
  2078. /* This is real route. */
  2079. ret = if_prefix_delete_ipv6 (ifp, ifc);
  2080. if (ret < 0)
  2081. {
  2082. vty_out (vty, "%% Can't unset interface IP address: %s.%s",
  2083. safe_strerror(errno), VTY_NEWLINE);
  2084. return CMD_WARNING;
  2085. }
  2086. UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
  2087. /* This information will be propagated to the zclients when the
  2088. * kernel notification is received. */
  2089. return CMD_SUCCESS;
  2090. }
  2091. DEFUN (ipv6_address,
  2092. ipv6_address_cmd,
  2093. "ipv6 address X:X::X:X/M",
  2094. "Interface IPv6 config commands\n"
  2095. "Set the IP address of an interface\n"
  2096. "IPv6 address (e.g. 3ffe:506::1/48)\n")
  2097. {
  2098. return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
  2099. }
  2100. DEFUN (no_ipv6_address,
  2101. no_ipv6_address_cmd,
  2102. "no ipv6 address X:X::X:X/M",
  2103. NO_STR
  2104. "Interface IPv6 config commands\n"
  2105. "Set the IP address of an interface\n"
  2106. "IPv6 address (e.g. 3ffe:506::1/48)\n")
  2107. {
  2108. return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
  2109. }
  2110. #endif /* HAVE_IPV6 */
  2111. static int
  2112. link_params_config_write (struct vty *vty, struct interface *ifp)
  2113. {
  2114. int i;
  2115. if ((ifp == NULL) || !HAS_LINK_PARAMS(ifp))
  2116. return -1;
  2117. struct if_link_params *iflp = ifp->link_params;
  2118. vty_out (vty, " link-params%s", VTY_NEWLINE);
  2119. vty_out(vty, " enable%s", VTY_NEWLINE);
  2120. if (IS_PARAM_SET(iflp, LP_TE))
  2121. vty_out(vty, " metric %u%s",iflp->te_metric, VTY_NEWLINE);
  2122. if (IS_PARAM_SET(iflp, LP_MAX_BW))
  2123. vty_out(vty, " max-bw %g%s", iflp->max_bw, VTY_NEWLINE);
  2124. if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
  2125. vty_out(vty, " max-rsv-bw %g%s", iflp->max_rsv_bw, VTY_NEWLINE);
  2126. if (IS_PARAM_SET(iflp, LP_UNRSV_BW))
  2127. {
  2128. for (i = 0; i < 8; i++)
  2129. vty_out(vty, " unrsv-bw %d %g%s",
  2130. i, iflp->unrsv_bw[i], VTY_NEWLINE);
  2131. }
  2132. if (IS_PARAM_SET(iflp, LP_ADM_GRP))
  2133. vty_out(vty, " admin-grp %u%s", iflp->admin_grp, VTY_NEWLINE);
  2134. if (IS_PARAM_SET(iflp, LP_DELAY))
  2135. {
  2136. vty_out(vty, " delay %u", iflp->av_delay);
  2137. if (IS_PARAM_SET(iflp, LP_MM_DELAY))
  2138. {
  2139. vty_out(vty, " min %u", iflp->min_delay);
  2140. vty_out(vty, " max %u", iflp->max_delay);
  2141. }
  2142. vty_out(vty, "%s", VTY_NEWLINE);
  2143. }
  2144. if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
  2145. vty_out(vty, " delay-variation %u%s", iflp->delay_var, VTY_NEWLINE);
  2146. if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
  2147. vty_out(vty, " packet-loss %g%s", iflp->pkt_loss, VTY_NEWLINE);
  2148. if (IS_PARAM_SET(iflp, LP_AVA_BW))
  2149. vty_out(vty, " ava-bw %g%s", iflp->ava_bw, VTY_NEWLINE);
  2150. if (IS_PARAM_SET(iflp, LP_RES_BW))
  2151. vty_out(vty, " res-bw %g%s", iflp->res_bw, VTY_NEWLINE);
  2152. if (IS_PARAM_SET(iflp, LP_USE_BW))
  2153. vty_out(vty, " use-bw %g%s", iflp->use_bw, VTY_NEWLINE);
  2154. if (IS_PARAM_SET(iflp, LP_RMT_AS))
  2155. vty_out(vty, " neighbor %s as %u%s", inet_ntoa(iflp->rmt_ip),
  2156. iflp->rmt_as, VTY_NEWLINE);
  2157. return 0;
  2158. }
  2159. static int
  2160. if_config_write (struct vty *vty)
  2161. {
  2162. struct listnode *node;
  2163. struct interface *ifp;
  2164. vrf_iter_t iter;
  2165. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2166. for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
  2167. {
  2168. struct zebra_if *if_data;
  2169. struct listnode *addrnode;
  2170. struct connected *ifc;
  2171. struct prefix *p;
  2172. if_data = ifp->info;
  2173. if (ifp->vrf_id == VRF_DEFAULT)
  2174. vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE);
  2175. else
  2176. vty_out (vty, "interface %s vrf %u%s", ifp->name, ifp->vrf_id,
  2177. VTY_NEWLINE);
  2178. if (if_data)
  2179. {
  2180. if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
  2181. vty_out (vty, " shutdown%s", VTY_NEWLINE);
  2182. }
  2183. if (ifp->desc)
  2184. vty_out (vty, " description %s%s", ifp->desc,
  2185. VTY_NEWLINE);
  2186. /* Assign bandwidth here to avoid unnecessary interface flap
  2187. while processing config script */
  2188. if (ifp->bandwidth != 0)
  2189. vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
  2190. if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
  2191. vty_out(vty, " link-detect%s", VTY_NEWLINE);
  2192. else
  2193. vty_out(vty, " no link-detect%s", VTY_NEWLINE);
  2194. for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc))
  2195. {
  2196. if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
  2197. {
  2198. char buf[INET6_ADDRSTRLEN];
  2199. p = ifc->address;
  2200. vty_out (vty, " ip%s address %s",
  2201. p->family == AF_INET ? "" : "v6",
  2202. prefix2str (p, buf, sizeof(buf)));
  2203. if (ifc->label)
  2204. vty_out (vty, " label %s", ifc->label);
  2205. vty_out (vty, "%s", VTY_NEWLINE);
  2206. }
  2207. }
  2208. if (if_data)
  2209. {
  2210. if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
  2211. vty_out (vty, " %smulticast%s",
  2212. if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
  2213. VTY_NEWLINE);
  2214. }
  2215. #if defined (HAVE_RTADV)
  2216. rtadv_config_write (vty, ifp);
  2217. #endif /* HAVE_RTADV */
  2218. #ifdef HAVE_IRDP
  2219. irdp_config_write (vty, ifp);
  2220. #endif /* IRDP */
  2221. link_params_config_write (vty, ifp);
  2222. vty_out (vty, "!%s", VTY_NEWLINE);
  2223. }
  2224. return 0;
  2225. }
  2226. /* Allocate and initialize interface vector. */
  2227. void
  2228. zebra_if_init (void)
  2229. {
  2230. /* Initialize interface and new hook. */
  2231. if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
  2232. if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
  2233. /* Install configuration write function. */
  2234. install_node (&interface_node, if_config_write);
  2235. install_node (&link_params_node, NULL);
  2236. install_element (VIEW_NODE, &show_interface_cmd);
  2237. install_element (VIEW_NODE, &show_interface_vrf_cmd);
  2238. install_element (VIEW_NODE, &show_interface_vrf_all_cmd);
  2239. install_element (VIEW_NODE, &show_interface_name_cmd);
  2240. install_element (VIEW_NODE, &show_interface_name_vrf_cmd);
  2241. install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd);
  2242. install_element (CONFIG_NODE, &zebra_interface_cmd);
  2243. install_element (CONFIG_NODE, &zebra_interface_vrf_cmd);
  2244. install_element (CONFIG_NODE, &no_interface_cmd);
  2245. install_element (CONFIG_NODE, &no_interface_vrf_cmd);
  2246. install_default (INTERFACE_NODE);
  2247. install_element (INTERFACE_NODE, &interface_desc_cmd);
  2248. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  2249. install_element (INTERFACE_NODE, &multicast_cmd);
  2250. install_element (INTERFACE_NODE, &no_multicast_cmd);
  2251. install_element (INTERFACE_NODE, &linkdetect_cmd);
  2252. install_element (INTERFACE_NODE, &no_linkdetect_cmd);
  2253. install_element (INTERFACE_NODE, &shutdown_if_cmd);
  2254. install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
  2255. install_element (INTERFACE_NODE, &bandwidth_if_cmd);
  2256. install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
  2257. install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
  2258. install_element (INTERFACE_NODE, &ip_address_cmd);
  2259. install_element (INTERFACE_NODE, &no_ip_address_cmd);
  2260. #ifdef HAVE_IPV6
  2261. install_element (INTERFACE_NODE, &ipv6_address_cmd);
  2262. install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
  2263. #endif /* HAVE_IPV6 */
  2264. #ifdef HAVE_NETLINK
  2265. install_element (INTERFACE_NODE, &ip_address_label_cmd);
  2266. install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
  2267. #endif /* HAVE_NETLINK */
  2268. install_element(INTERFACE_NODE, &link_params_cmd);
  2269. install_default(LINK_PARAMS_NODE);
  2270. install_element(LINK_PARAMS_NODE, &link_params_enable_cmd);
  2271. install_element(LINK_PARAMS_NODE, &no_link_params_enable_cmd);
  2272. install_element(LINK_PARAMS_NODE, &link_params_metric_cmd);
  2273. install_element(LINK_PARAMS_NODE, &link_params_maxbw_cmd);
  2274. install_element(LINK_PARAMS_NODE, &link_params_max_rsv_bw_cmd);
  2275. install_element(LINK_PARAMS_NODE, &link_params_unrsv_bw_cmd);
  2276. install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd);
  2277. install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd);
  2278. install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd);
  2279. install_element(LINK_PARAMS_NODE, &link_params_delay_cmd);
  2280. install_element(LINK_PARAMS_NODE, &link_params_delay_mm_cmd);
  2281. install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd);
  2282. install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd);
  2283. install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd);
  2284. install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd);
  2285. install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
  2286. }