ripngd.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092
  1. /* RIPng daemon
  2. * Copyright (C) 1998, 1999 Kunihiro Ishiguro
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "prefix.h"
  23. #include "filter.h"
  24. #include "log.h"
  25. #include "thread.h"
  26. #include "memory.h"
  27. #include "if.h"
  28. #include "stream.h"
  29. #include "table.h"
  30. #include "command.h"
  31. #include "sockopt.h"
  32. #include "distribute.h"
  33. #include "plist.h"
  34. #include "routemap.h"
  35. #include "if_rmap.h"
  36. #include "privs.h"
  37. #include "ripngd/ripngd.h"
  38. #include "ripngd/ripng_route.h"
  39. #include "ripngd/ripng_debug.h"
  40. #include "ripngd/ripng_nexthop.h"
  41. /* RIPng structure which includes many parameters related to RIPng
  42. protocol. If ripng couldn't active or ripng doesn't configured,
  43. ripng->fd must be negative value. */
  44. struct ripng *ripng = NULL;
  45. enum
  46. {
  47. ripng_all_route,
  48. ripng_changed_route,
  49. };
  50. extern struct zebra_privs_t ripngd_privs;
  51. /* Prototypes. */
  52. void
  53. ripng_output_process (struct interface *, struct sockaddr_in6 *, int);
  54. int
  55. ripng_triggered_update (struct thread *);
  56. /* RIPng next hop specification. */
  57. struct ripng_nexthop
  58. {
  59. enum ripng_nexthop_type
  60. {
  61. RIPNG_NEXTHOP_UNSPEC,
  62. RIPNG_NEXTHOP_ADDRESS
  63. } flag;
  64. struct in6_addr address;
  65. };
  66. static int
  67. ripng_route_rte (struct ripng_info *rinfo)
  68. {
  69. return (rinfo->type == ZEBRA_ROUTE_RIPNG && rinfo->sub_type == RIPNG_ROUTE_RTE);
  70. }
  71. /* Allocate new ripng information. */
  72. struct ripng_info *
  73. ripng_info_new ()
  74. {
  75. struct ripng_info *new;
  76. new = XCALLOC (MTYPE_RIPNG_ROUTE, sizeof (struct ripng_info));
  77. return new;
  78. }
  79. /* Free ripng information. */
  80. void
  81. ripng_info_free (struct ripng_info *rinfo)
  82. {
  83. XFREE (MTYPE_RIPNG_ROUTE, rinfo);
  84. }
  85. /* Create ripng socket. */
  86. static int
  87. ripng_make_socket (void)
  88. {
  89. int ret;
  90. int sock;
  91. struct sockaddr_in6 ripaddr;
  92. sock = socket (AF_INET6, SOCK_DGRAM, 0);
  93. if (sock < 0)
  94. {
  95. zlog (NULL, LOG_ERR, "Can't make ripng socket");
  96. return sock;
  97. }
  98. ret = setsockopt_so_recvbuf (sock, 8096);
  99. if (ret < 0)
  100. return ret;
  101. ret = setsockopt_ipv6_pktinfo (sock, 1);
  102. if (ret < 0)
  103. return ret;
  104. #ifdef IPTOS_PREC_INTERNETCONTROL
  105. ret = setsockopt_ipv6_tclass (sock, IPTOS_PREC_INTERNETCONTROL);
  106. if (ret < 0)
  107. return ret;
  108. #endif
  109. ret = setsockopt_ipv6_multicast_hops (sock, 255);
  110. if (ret < 0)
  111. return ret;
  112. ret = setsockopt_ipv6_multicast_loop (sock, 0);
  113. if (ret < 0)
  114. return ret;
  115. ret = setsockopt_ipv6_hoplimit (sock, 1);
  116. if (ret < 0)
  117. return ret;
  118. memset (&ripaddr, 0, sizeof (ripaddr));
  119. ripaddr.sin6_family = AF_INET6;
  120. #ifdef SIN6_LEN
  121. ripaddr.sin6_len = sizeof (struct sockaddr_in6);
  122. #endif /* SIN6_LEN */
  123. ripaddr.sin6_port = htons (RIPNG_PORT_DEFAULT);
  124. if (ripngd_privs.change (ZPRIVS_RAISE))
  125. zlog_err ("ripng_make_socket: could not raise privs");
  126. ret = bind (sock, (struct sockaddr *) &ripaddr, sizeof (ripaddr));
  127. if (ret < 0)
  128. {
  129. zlog (NULL, LOG_ERR, "Can't bind ripng socket: %s.", safe_strerror (errno));
  130. if (ripngd_privs.change (ZPRIVS_LOWER))
  131. zlog_err ("ripng_make_socket: could not lower privs");
  132. return ret;
  133. }
  134. if (ripngd_privs.change (ZPRIVS_LOWER))
  135. zlog_err ("ripng_make_socket: could not lower privs");
  136. return sock;
  137. }
  138. /* Send RIPng packet. */
  139. int
  140. ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to,
  141. struct interface *ifp)
  142. {
  143. int ret;
  144. struct msghdr msg;
  145. struct iovec iov;
  146. struct cmsghdr *cmsgptr;
  147. char adata [256];
  148. struct in6_pktinfo *pkt;
  149. struct sockaddr_in6 addr;
  150. if (IS_RIPNG_DEBUG_SEND) {
  151. if (to)
  152. zlog_debug ("send to %s", inet6_ntoa (to->sin6_addr));
  153. zlog_debug (" send interface %s", ifp->name);
  154. zlog_debug (" send packet size %d", bufsize);
  155. }
  156. memset (&addr, 0, sizeof (struct sockaddr_in6));
  157. addr.sin6_family = AF_INET6;
  158. #ifdef SIN6_LEN
  159. addr.sin6_len = sizeof (struct sockaddr_in6);
  160. #endif /* SIN6_LEN */
  161. addr.sin6_flowinfo = htonl (RIPNG_PRIORITY_DEFAULT);
  162. /* When destination is specified. */
  163. if (to != NULL)
  164. {
  165. addr.sin6_addr = to->sin6_addr;
  166. addr.sin6_port = to->sin6_port;
  167. }
  168. else
  169. {
  170. inet_pton(AF_INET6, RIPNG_GROUP, &addr.sin6_addr);
  171. addr.sin6_port = htons (RIPNG_PORT_DEFAULT);
  172. }
  173. msg.msg_name = (void *) &addr;
  174. msg.msg_namelen = sizeof (struct sockaddr_in6);
  175. msg.msg_iov = &iov;
  176. msg.msg_iovlen = 1;
  177. msg.msg_control = (void *) adata;
  178. msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
  179. iov.iov_base = buf;
  180. iov.iov_len = bufsize;
  181. cmsgptr = (struct cmsghdr *)adata;
  182. cmsgptr->cmsg_len = CMSG_LEN(sizeof (struct in6_pktinfo));
  183. cmsgptr->cmsg_level = IPPROTO_IPV6;
  184. cmsgptr->cmsg_type = IPV6_PKTINFO;
  185. pkt = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
  186. memset (&pkt->ipi6_addr, 0, sizeof (struct in6_addr));
  187. pkt->ipi6_ifindex = ifp->ifindex;
  188. ret = sendmsg (ripng->sock, &msg, 0);
  189. if (ret < 0) {
  190. if (to)
  191. zlog_err ("RIPng send fail on %s to %s: %s", ifp->name,
  192. inet6_ntoa (to->sin6_addr), safe_strerror (errno));
  193. else
  194. zlog_err ("RIPng send fail on %s: %s", ifp->name, safe_strerror (errno));
  195. }
  196. return ret;
  197. }
  198. /* Receive UDP RIPng packet from socket. */
  199. static int
  200. ripng_recv_packet (int sock, u_char *buf, int bufsize,
  201. struct sockaddr_in6 *from, ifindex_t *ifindex,
  202. int *hoplimit)
  203. {
  204. int ret;
  205. struct msghdr msg;
  206. struct iovec iov;
  207. struct cmsghdr *cmsgptr;
  208. struct in6_addr dst = { .s6_addr = { 0 } };
  209. /* Ancillary data. This store cmsghdr and in6_pktinfo. But at this
  210. point I can't determine size of cmsghdr */
  211. char adata[1024];
  212. /* Fill in message and iovec. */
  213. msg.msg_name = (void *) from;
  214. msg.msg_namelen = sizeof (struct sockaddr_in6);
  215. msg.msg_iov = &iov;
  216. msg.msg_iovlen = 1;
  217. msg.msg_control = (void *) adata;
  218. msg.msg_controllen = sizeof adata;
  219. iov.iov_base = buf;
  220. iov.iov_len = bufsize;
  221. /* If recvmsg fail return minus value. */
  222. ret = recvmsg (sock, &msg, 0);
  223. if (ret < 0)
  224. return ret;
  225. for (cmsgptr = ZCMSG_FIRSTHDR(&msg); cmsgptr != NULL;
  226. cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
  227. {
  228. /* I want interface index which this packet comes from. */
  229. if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
  230. cmsgptr->cmsg_type == IPV6_PKTINFO)
  231. {
  232. struct in6_pktinfo *ptr;
  233. ptr = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
  234. *ifindex = ptr->ipi6_ifindex;
  235. dst = ptr->ipi6_addr;
  236. if (*ifindex == 0)
  237. zlog_warn ("Interface index returned by IPV6_PKTINFO is zero");
  238. }
  239. /* Incoming packet's multicast hop limit. */
  240. if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
  241. cmsgptr->cmsg_type == IPV6_HOPLIMIT)
  242. {
  243. int *phoplimit = (int *) CMSG_DATA (cmsgptr);
  244. *hoplimit = *phoplimit;
  245. }
  246. }
  247. /* Hoplimit check shold be done when destination address is
  248. multicast address. */
  249. if (! IN6_IS_ADDR_MULTICAST (&dst))
  250. *hoplimit = -1;
  251. return ret;
  252. }
  253. /* Dump rip packet */
  254. void
  255. ripng_packet_dump (struct ripng_packet *packet, int size, const char *sndrcv)
  256. {
  257. caddr_t lim;
  258. struct rte *rte;
  259. const char *command_str;
  260. /* Set command string. */
  261. if (packet->command == RIPNG_REQUEST)
  262. command_str = "request";
  263. else if (packet->command == RIPNG_RESPONSE)
  264. command_str = "response";
  265. else
  266. command_str = "unknown";
  267. /* Dump packet header. */
  268. zlog_debug ("%s %s version %d packet size %d",
  269. sndrcv, command_str, packet->version, size);
  270. /* Dump each routing table entry. */
  271. rte = packet->rte;
  272. for (lim = (caddr_t) packet + size; (caddr_t) rte < lim; rte++)
  273. {
  274. if (rte->metric == RIPNG_METRIC_NEXTHOP)
  275. zlog_debug (" nexthop %s/%d", inet6_ntoa (rte->addr), rte->prefixlen);
  276. else
  277. zlog_debug (" %s/%d metric %d tag %d",
  278. inet6_ntoa (rte->addr), rte->prefixlen,
  279. rte->metric, ntohs (rte->tag));
  280. }
  281. }
  282. /* RIPng next hop address RTE (Route Table Entry). */
  283. static void
  284. ripng_nexthop_rte (struct rte *rte,
  285. struct sockaddr_in6 *from,
  286. struct ripng_nexthop *nexthop)
  287. {
  288. char buf[INET6_BUFSIZ];
  289. /* Logging before checking RTE. */
  290. if (IS_RIPNG_DEBUG_RECV)
  291. zlog_debug ("RIPng nexthop RTE address %s tag %d prefixlen %d",
  292. inet6_ntoa (rte->addr), ntohs (rte->tag), rte->prefixlen);
  293. /* RFC2080 2.1.1 Next Hop:
  294. The route tag and prefix length in the next hop RTE must be
  295. set to zero on sending and ignored on receiption. */
  296. if (ntohs (rte->tag) != 0)
  297. zlog_warn ("RIPng nexthop RTE with non zero tag value %d from %s",
  298. ntohs (rte->tag), inet6_ntoa (from->sin6_addr));
  299. if (rte->prefixlen != 0)
  300. zlog_warn ("RIPng nexthop RTE with non zero prefixlen value %d from %s",
  301. rte->prefixlen, inet6_ntoa (from->sin6_addr));
  302. /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
  303. next hop RTE indicates that the next hop address should be the
  304. originator of the RIPng advertisement. An address specified as a
  305. next hop must be a link-local address. */
  306. if (IN6_IS_ADDR_UNSPECIFIED (&rte->addr))
  307. {
  308. nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
  309. memset (&nexthop->address, 0, sizeof (struct in6_addr));
  310. return;
  311. }
  312. if (IN6_IS_ADDR_LINKLOCAL (&rte->addr))
  313. {
  314. nexthop->flag = RIPNG_NEXTHOP_ADDRESS;
  315. IPV6_ADDR_COPY (&nexthop->address, &rte->addr);
  316. return;
  317. }
  318. /* The purpose of the next hop RTE is to eliminate packets being
  319. routed through extra hops in the system. It is particularly useful
  320. when RIPng is not being run on all of the routers on a network.
  321. Note that next hop RTE is "advisory". That is, if the provided
  322. information is ignored, a possibly sub-optimal, but absolutely
  323. valid, route may be taken. If the received next hop address is not
  324. a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */
  325. zlog_warn ("RIPng nexthop RTE with non link-local address %s from %s",
  326. inet6_ntoa (rte->addr),
  327. inet_ntop (AF_INET6, &from->sin6_addr, buf, INET6_BUFSIZ));
  328. nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
  329. memset (&nexthop->address, 0, sizeof (struct in6_addr));
  330. return;
  331. }
  332. /* If ifp has same link-local address then return 1. */
  333. static int
  334. ripng_lladdr_check (struct interface *ifp, struct in6_addr *addr)
  335. {
  336. struct listnode *node;
  337. struct connected *connected;
  338. struct prefix *p;
  339. for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
  340. {
  341. p = connected->address;
  342. if (p->family == AF_INET6 &&
  343. IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6) &&
  344. IN6_ARE_ADDR_EQUAL (&p->u.prefix6, addr))
  345. return 1;
  346. }
  347. return 0;
  348. }
  349. /* RIPng route garbage collect timer. */
  350. static int
  351. ripng_garbage_collect (struct thread *t)
  352. {
  353. struct ripng_info *rinfo;
  354. struct route_node *rp;
  355. rinfo = THREAD_ARG (t);
  356. rinfo->t_garbage_collect = NULL;
  357. /* Off timeout timer. */
  358. RIPNG_TIMER_OFF (rinfo->t_timeout);
  359. /* Get route_node pointer. */
  360. rp = rinfo->rp;
  361. /* Unlock route_node. */
  362. listnode_delete (rp->info, rinfo);
  363. if (list_isempty ((struct list *)rp->info))
  364. {
  365. list_free (rp->info);
  366. rp->info = NULL;
  367. route_unlock_node (rp);
  368. }
  369. /* Free RIPng routing information. */
  370. ripng_info_free (rinfo);
  371. return 0;
  372. }
  373. static void ripng_timeout_update (struct ripng_info *rinfo);
  374. /* Add new route to the ECMP list.
  375. * RETURN: the new entry added in the list, or NULL if it is not the first
  376. * entry and ECMP is not allowed.
  377. */
  378. struct ripng_info *
  379. ripng_ecmp_add (struct ripng_info *rinfo_new)
  380. {
  381. struct route_node *rp = rinfo_new->rp;
  382. struct ripng_info *rinfo = NULL;
  383. struct list *list = NULL;
  384. if (rp->info == NULL)
  385. rp->info = list_new ();
  386. list = (struct list *)rp->info;
  387. /* If ECMP is not allowed and some entry already exists in the list,
  388. * do nothing. */
  389. if (listcount (list) && !ripng->ecmp)
  390. return NULL;
  391. rinfo = ripng_info_new ();
  392. memcpy (rinfo, rinfo_new, sizeof (struct ripng_info));
  393. listnode_add (list, rinfo);
  394. if (ripng_route_rte (rinfo))
  395. {
  396. ripng_timeout_update (rinfo);
  397. ripng_zebra_ipv6_add (rp);
  398. }
  399. ripng_aggregate_increment (rp, rinfo);
  400. /* Set the route change flag on the first entry. */
  401. rinfo = listgetdata (listhead (list));
  402. SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
  403. /* Signal the output process to trigger an update. */
  404. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  405. return rinfo;
  406. }
  407. /* Replace the ECMP list with the new route.
  408. * RETURN: the new entry added in the list
  409. */
  410. struct ripng_info *
  411. ripng_ecmp_replace (struct ripng_info *rinfo_new)
  412. {
  413. struct route_node *rp = rinfo_new->rp;
  414. struct list *list = (struct list *)rp->info;
  415. struct ripng_info *rinfo = NULL, *tmp_rinfo = NULL;
  416. struct listnode *node = NULL, *nextnode = NULL;
  417. if (list == NULL || listcount (list) == 0)
  418. return ripng_ecmp_add (rinfo_new);
  419. /* Get the first entry */
  420. rinfo = listgetdata (listhead (list));
  421. /* Learnt route replaced by a local one. Delete it from zebra. */
  422. if (ripng_route_rte (rinfo) && !ripng_route_rte (rinfo_new))
  423. if (CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
  424. ripng_zebra_ipv6_delete (rp);
  425. if (rinfo->metric != RIPNG_METRIC_INFINITY)
  426. ripng_aggregate_decrement_list (rp, list);
  427. /* Re-use the first entry, and delete the others. */
  428. for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
  429. if (tmp_rinfo != rinfo)
  430. {
  431. RIPNG_TIMER_OFF (tmp_rinfo->t_timeout);
  432. RIPNG_TIMER_OFF (tmp_rinfo->t_garbage_collect);
  433. list_delete_node (list, node);
  434. ripng_info_free (tmp_rinfo);
  435. }
  436. RIPNG_TIMER_OFF (rinfo->t_timeout);
  437. RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
  438. memcpy (rinfo, rinfo_new, sizeof (struct ripng_info));
  439. if (ripng_route_rte (rinfo))
  440. {
  441. ripng_timeout_update (rinfo);
  442. /* The ADD message implies an update. */
  443. ripng_zebra_ipv6_add (rp);
  444. }
  445. ripng_aggregate_increment (rp, rinfo);
  446. /* Set the route change flag. */
  447. SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
  448. /* Signal the output process to trigger an update. */
  449. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  450. return rinfo;
  451. }
  452. /* Delete one route from the ECMP list.
  453. * RETURN:
  454. * null - the entry is freed, and other entries exist in the list
  455. * the entry - the entry is the last one in the list; its metric is set
  456. * to INFINITY, and the garbage collector is started for it
  457. */
  458. struct ripng_info *
  459. ripng_ecmp_delete (struct ripng_info *rinfo)
  460. {
  461. struct route_node *rp = rinfo->rp;
  462. struct list *list = (struct list *)rp->info;
  463. RIPNG_TIMER_OFF (rinfo->t_timeout);
  464. if (rinfo->metric != RIPNG_METRIC_INFINITY)
  465. ripng_aggregate_decrement (rp, rinfo);
  466. if (listcount (list) > 1)
  467. {
  468. /* Some other ECMP entries still exist. Just delete this entry. */
  469. RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
  470. listnode_delete (list, rinfo);
  471. if (ripng_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
  472. /* The ADD message implies the update. */
  473. ripng_zebra_ipv6_add (rp);
  474. ripng_info_free (rinfo);
  475. rinfo = NULL;
  476. }
  477. else
  478. {
  479. assert (rinfo == listgetdata (listhead (list)));
  480. /* This is the only entry left in the list. We must keep it in
  481. * the list for garbage collection time, with INFINITY metric. */
  482. rinfo->metric = RIPNG_METRIC_INFINITY;
  483. RIPNG_TIMER_ON (rinfo->t_garbage_collect,
  484. ripng_garbage_collect, ripng->garbage_time);
  485. if (ripng_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
  486. ripng_zebra_ipv6_delete (rp);
  487. }
  488. /* Set the route change flag on the first entry. */
  489. rinfo = listgetdata (listhead (list));
  490. SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
  491. /* Signal the output process to trigger an update. */
  492. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  493. return rinfo;
  494. }
  495. /* Timeout RIPng routes. */
  496. static int
  497. ripng_timeout (struct thread *t)
  498. {
  499. ripng_ecmp_delete ((struct ripng_info *)THREAD_ARG (t));
  500. return 0;
  501. }
  502. static void
  503. ripng_timeout_update (struct ripng_info *rinfo)
  504. {
  505. if (rinfo->metric != RIPNG_METRIC_INFINITY)
  506. {
  507. RIPNG_TIMER_OFF (rinfo->t_timeout);
  508. RIPNG_TIMER_ON (rinfo->t_timeout, ripng_timeout, ripng->timeout_time);
  509. }
  510. }
  511. static int
  512. ripng_filter (int ripng_distribute, struct prefix_ipv6 *p,
  513. struct ripng_interface *ri)
  514. {
  515. struct distribute *dist;
  516. struct access_list *alist;
  517. struct prefix_list *plist;
  518. int distribute = ripng_distribute == RIPNG_FILTER_OUT ?
  519. DISTRIBUTE_OUT : DISTRIBUTE_IN;
  520. const char *inout = ripng_distribute == RIPNG_FILTER_OUT ? "out" : "in";
  521. /* Input distribute-list filtering. */
  522. if (ri->list[ripng_distribute])
  523. {
  524. if (access_list_apply (ri->list[ripng_distribute],
  525. (struct prefix *) p) == FILTER_DENY)
  526. {
  527. if (IS_RIPNG_DEBUG_PACKET)
  528. zlog_debug ("%s/%d filtered by distribute %s",
  529. inet6_ntoa (p->prefix), p->prefixlen, inout);
  530. return -1;
  531. }
  532. }
  533. if (ri->prefix[ripng_distribute])
  534. {
  535. if (prefix_list_apply (ri->prefix[ripng_distribute],
  536. (struct prefix *) p) == PREFIX_DENY)
  537. {
  538. if (IS_RIPNG_DEBUG_PACKET)
  539. zlog_debug ("%s/%d filtered by prefix-list %s",
  540. inet6_ntoa (p->prefix), p->prefixlen, inout);
  541. return -1;
  542. }
  543. }
  544. /* All interface filter check. */
  545. dist = distribute_lookup (NULL);
  546. if (dist)
  547. {
  548. if (dist->list[distribute])
  549. {
  550. alist = access_list_lookup (AFI_IP6, dist->list[distribute]);
  551. if (alist)
  552. {
  553. if (access_list_apply (alist,
  554. (struct prefix *) p) == FILTER_DENY)
  555. {
  556. if (IS_RIPNG_DEBUG_PACKET)
  557. zlog_debug ("%s/%d filtered by distribute %s",
  558. inet6_ntoa (p->prefix), p->prefixlen, inout);
  559. return -1;
  560. }
  561. }
  562. }
  563. if (dist->prefix[distribute])
  564. {
  565. plist = prefix_list_lookup (AFI_IP6, dist->prefix[distribute]);
  566. if (plist)
  567. {
  568. if (prefix_list_apply (plist,
  569. (struct prefix *) p) == PREFIX_DENY)
  570. {
  571. if (IS_RIPNG_DEBUG_PACKET)
  572. zlog_debug ("%s/%d filtered by prefix-list %s",
  573. inet6_ntoa (p->prefix), p->prefixlen, inout);
  574. return -1;
  575. }
  576. }
  577. }
  578. }
  579. return 0;
  580. }
  581. /* Process RIPng route according to RFC2080. */
  582. static void
  583. ripng_route_process (struct rte *rte, struct sockaddr_in6 *from,
  584. struct ripng_nexthop *ripng_nexthop,
  585. struct interface *ifp)
  586. {
  587. int ret;
  588. struct prefix_ipv6 p;
  589. struct route_node *rp;
  590. struct ripng_info *rinfo = NULL, newinfo;
  591. struct ripng_interface *ri;
  592. struct in6_addr *nexthop;
  593. int same = 0;
  594. struct list *list = NULL;
  595. struct listnode *node = NULL;
  596. /* Make prefix structure. */
  597. memset (&p, 0, sizeof (struct prefix_ipv6));
  598. p.family = AF_INET6;
  599. /* p.prefix = rte->addr; */
  600. IPV6_ADDR_COPY (&p.prefix, &rte->addr);
  601. p.prefixlen = rte->prefixlen;
  602. /* Make sure mask is applied. */
  603. /* XXX We have to check the prefix is valid or not before call
  604. apply_mask_ipv6. */
  605. apply_mask_ipv6 (&p);
  606. /* Apply input filters. */
  607. ri = ifp->info;
  608. ret = ripng_filter (RIPNG_FILTER_IN, &p, ri);
  609. if (ret < 0)
  610. return;
  611. memset (&newinfo, 0, sizeof (newinfo));
  612. newinfo.type = ZEBRA_ROUTE_RIPNG;
  613. newinfo.sub_type = RIPNG_ROUTE_RTE;
  614. if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
  615. newinfo.nexthop = ripng_nexthop->address;
  616. else
  617. newinfo.nexthop = from->sin6_addr;
  618. newinfo.from = from->sin6_addr;
  619. newinfo.ifindex = ifp->ifindex;
  620. newinfo.metric = rte->metric;
  621. newinfo.metric_out = rte->metric; /* XXX */
  622. newinfo.tag = ntohs (rte->tag); /* XXX */
  623. /* Modify entry. */
  624. if (ri->routemap[RIPNG_FILTER_IN])
  625. {
  626. int ret;
  627. ret = route_map_apply (ri->routemap[RIPNG_FILTER_IN],
  628. (struct prefix *)&p, RMAP_RIPNG, &newinfo);
  629. if (ret == RMAP_DENYMATCH)
  630. {
  631. if (IS_RIPNG_DEBUG_PACKET)
  632. zlog_debug ("RIPng %s/%d is filtered by route-map in",
  633. inet6_ntoa (p.prefix), p.prefixlen);
  634. return;
  635. }
  636. /* Get back the object */
  637. if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS) {
  638. if (! IPV6_ADDR_SAME(&newinfo.nexthop, &ripng_nexthop->address) ) {
  639. /* the nexthop get changed by the routemap */
  640. if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop))
  641. ripng_nexthop->address = newinfo.nexthop;
  642. else
  643. ripng_nexthop->address = in6addr_any;
  644. }
  645. } else {
  646. if (! IPV6_ADDR_SAME(&newinfo.nexthop, &from->sin6_addr) ) {
  647. /* the nexthop get changed by the routemap */
  648. if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop)) {
  649. ripng_nexthop->flag = RIPNG_NEXTHOP_ADDRESS;
  650. ripng_nexthop->address = newinfo.nexthop;
  651. }
  652. }
  653. }
  654. rte->tag = htons(newinfo.tag_out); /* XXX */
  655. rte->metric = newinfo.metric_out; /* XXX: the routemap uses the metric_out field */
  656. }
  657. /* Once the entry has been validated, update the metric by
  658. * adding the cost of the network on wich the message
  659. * arrived. If the result is greater than infinity, use infinity
  660. * (RFC2453 Sec. 3.9.2)
  661. **/
  662. /* Zebra ripngd can handle offset-list in. */
  663. ret = ripng_offset_list_apply_in (&p, ifp, &rte->metric);
  664. /* If offset-list does not modify the metric use interface's
  665. * one. */
  666. if (! ret)
  667. rte->metric += ifp->metric ? ifp->metric : 1;
  668. if (rte->metric > RIPNG_METRIC_INFINITY)
  669. rte->metric = RIPNG_METRIC_INFINITY;
  670. /* Set nexthop pointer. */
  671. if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
  672. nexthop = &ripng_nexthop->address;
  673. else
  674. nexthop = &from->sin6_addr;
  675. /* Lookup RIPng routing table. */
  676. rp = route_node_get (ripng->table, (struct prefix *) &p);
  677. newinfo.rp = rp;
  678. newinfo.nexthop = *nexthop;
  679. newinfo.metric = rte->metric;
  680. newinfo.tag = ntohs (rte->tag);
  681. /* Check to see whether there is already RIPng route on the table. */
  682. if ((list = rp->info) != NULL)
  683. for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
  684. {
  685. /* Need to compare with redistributed entry or local entry */
  686. if (!ripng_route_rte (rinfo))
  687. break;
  688. if (IPV6_ADDR_SAME (&rinfo->from, &from->sin6_addr) &&
  689. IPV6_ADDR_SAME (&rinfo->nexthop, nexthop))
  690. break;
  691. if (!listnextnode (node))
  692. {
  693. /* Not found in the list */
  694. if (rte->metric > rinfo->metric)
  695. {
  696. /* New route has a greater metric. Discard it. */
  697. route_unlock_node (rp);
  698. return;
  699. }
  700. if (rte->metric < rinfo->metric)
  701. /* New route has a smaller metric. Replace the ECMP list
  702. * with the new one in below. */
  703. break;
  704. /* Metrics are same. Keep "rinfo" null and the new route
  705. * is added in the ECMP list in below. */
  706. }
  707. }
  708. if (rinfo)
  709. {
  710. /* Redistributed route check. */
  711. if (rinfo->type != ZEBRA_ROUTE_RIPNG
  712. && rinfo->metric != RIPNG_METRIC_INFINITY)
  713. {
  714. route_unlock_node (rp);
  715. return;
  716. }
  717. /* Local static route. */
  718. if (rinfo->type == ZEBRA_ROUTE_RIPNG
  719. && ((rinfo->sub_type == RIPNG_ROUTE_STATIC) ||
  720. (rinfo->sub_type == RIPNG_ROUTE_DEFAULT))
  721. && rinfo->metric != RIPNG_METRIC_INFINITY)
  722. {
  723. route_unlock_node (rp);
  724. return;
  725. }
  726. }
  727. if (!rinfo)
  728. {
  729. /* Now, check to see whether there is already an explicit route
  730. for the destination prefix. If there is no such route, add
  731. this route to the routing table, unless the metric is
  732. infinity (there is no point in adding a route which
  733. unusable). */
  734. if (rte->metric != RIPNG_METRIC_INFINITY)
  735. ripng_ecmp_add (&newinfo);
  736. }
  737. else
  738. {
  739. /* If there is an existing route, compare the next hop address
  740. to the address of the router from which the datagram came.
  741. If this datagram is from the same router as the existing
  742. route, reinitialize the timeout. */
  743. same = (IN6_ARE_ADDR_EQUAL (&rinfo->from, &from->sin6_addr)
  744. && (rinfo->ifindex == ifp->ifindex));
  745. /* Next, compare the metrics. If the datagram is from the same
  746. router as the existing route, and the new metric is different
  747. than the old one; or, if the new metric is lower than the old
  748. one; do the following actions: */
  749. if ((same && rinfo->metric != rte->metric) ||
  750. rte->metric < rinfo->metric)
  751. {
  752. if (listcount (list) == 1)
  753. {
  754. if (newinfo.metric != RIPNG_METRIC_INFINITY)
  755. ripng_ecmp_replace (&newinfo);
  756. else
  757. ripng_ecmp_delete (rinfo);
  758. }
  759. else
  760. {
  761. if (newinfo.metric < rinfo->metric)
  762. ripng_ecmp_replace (&newinfo);
  763. else /* newinfo.metric > rinfo->metric */
  764. ripng_ecmp_delete (rinfo);
  765. }
  766. }
  767. else /* same & no change */
  768. ripng_timeout_update (rinfo);
  769. /* Unlock tempolary lock of the route. */
  770. route_unlock_node (rp);
  771. }
  772. }
  773. /* Add redistributed route to RIPng table. */
  774. void
  775. ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p,
  776. ifindex_t ifindex, struct in6_addr *nexthop)
  777. {
  778. struct route_node *rp;
  779. struct ripng_info *rinfo = NULL, newinfo;
  780. struct list *list = NULL;
  781. /* Redistribute route */
  782. if (IN6_IS_ADDR_LINKLOCAL (&p->prefix))
  783. return;
  784. if (IN6_IS_ADDR_LOOPBACK (&p->prefix))
  785. return;
  786. rp = route_node_get (ripng->table, (struct prefix *) p);
  787. memset (&newinfo, 0, sizeof (struct ripng_info));
  788. newinfo.type = type;
  789. newinfo.sub_type = sub_type;
  790. newinfo.ifindex = ifindex;
  791. newinfo.metric = 1;
  792. newinfo.rp = rp;
  793. if (nexthop && IN6_IS_ADDR_LINKLOCAL(nexthop))
  794. newinfo.nexthop = *nexthop;
  795. if ((list = rp->info) != NULL && listcount (list) != 0)
  796. {
  797. rinfo = listgetdata (listhead (list));
  798. if (rinfo->type == ZEBRA_ROUTE_CONNECT
  799. && rinfo->sub_type == RIPNG_ROUTE_INTERFACE
  800. && rinfo->metric != RIPNG_METRIC_INFINITY) {
  801. route_unlock_node (rp);
  802. return;
  803. }
  804. /* Manually configured RIPng route check.
  805. * They have the precedence on all the other entries.
  806. **/
  807. if (rinfo->type == ZEBRA_ROUTE_RIPNG
  808. && ((rinfo->sub_type == RIPNG_ROUTE_STATIC) ||
  809. (rinfo->sub_type == RIPNG_ROUTE_DEFAULT)) ) {
  810. if (type != ZEBRA_ROUTE_RIPNG || ((sub_type != RIPNG_ROUTE_STATIC) &&
  811. (sub_type != RIPNG_ROUTE_DEFAULT))) {
  812. route_unlock_node (rp);
  813. return;
  814. }
  815. }
  816. rinfo = ripng_ecmp_replace (&newinfo);
  817. route_unlock_node (rp);
  818. }
  819. else
  820. rinfo = ripng_ecmp_add (&newinfo);
  821. if (IS_RIPNG_DEBUG_EVENT) {
  822. if (!nexthop)
  823. zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
  824. inet6_ntoa(p->prefix), p->prefixlen,
  825. ifindex2ifname(ifindex));
  826. else
  827. zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
  828. inet6_ntoa(p->prefix), p->prefixlen, inet6_ntoa(*nexthop),
  829. ifindex2ifname(ifindex));
  830. }
  831. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  832. }
  833. /* Delete redistributed route to RIPng table. */
  834. void
  835. ripng_redistribute_delete (int type, int sub_type, struct prefix_ipv6 *p,
  836. ifindex_t ifindex)
  837. {
  838. struct route_node *rp;
  839. struct ripng_info *rinfo;
  840. if (IN6_IS_ADDR_LINKLOCAL (&p->prefix))
  841. return;
  842. if (IN6_IS_ADDR_LOOPBACK (&p->prefix))
  843. return;
  844. rp = route_node_lookup (ripng->table, (struct prefix *) p);
  845. if (rp)
  846. {
  847. struct list *list = rp->info;
  848. if (list != NULL && listcount (list) != 0)
  849. {
  850. rinfo = listgetdata (listhead (list));
  851. if (rinfo != NULL
  852. && rinfo->type == type
  853. && rinfo->sub_type == sub_type
  854. && rinfo->ifindex == ifindex)
  855. {
  856. /* Perform poisoned reverse. */
  857. rinfo->metric = RIPNG_METRIC_INFINITY;
  858. RIPNG_TIMER_ON (rinfo->t_garbage_collect,
  859. ripng_garbage_collect, ripng->garbage_time);
  860. RIPNG_TIMER_OFF (rinfo->t_timeout);
  861. /* Aggregate count decrement. */
  862. ripng_aggregate_decrement (rp, rinfo);
  863. rinfo->flags |= RIPNG_RTF_CHANGED;
  864. if (IS_RIPNG_DEBUG_EVENT)
  865. zlog_debug ("Poisone %s/%d on the interface %s with an "
  866. "infinity metric [delete]",
  867. inet6_ntoa (p->prefix), p->prefixlen,
  868. ifindex2ifname (ifindex));
  869. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  870. }
  871. }
  872. route_unlock_node (rp);
  873. }
  874. }
  875. /* Withdraw redistributed route. */
  876. void
  877. ripng_redistribute_withdraw (int type)
  878. {
  879. struct route_node *rp;
  880. struct ripng_info *rinfo = NULL;
  881. struct list *list = NULL;
  882. if (!ripng)
  883. return;
  884. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  885. if ((list = rp->info) != NULL)
  886. {
  887. rinfo = listgetdata (listhead (list));
  888. if ((rinfo->type == type)
  889. && (rinfo->sub_type != RIPNG_ROUTE_INTERFACE))
  890. {
  891. /* Perform poisoned reverse. */
  892. rinfo->metric = RIPNG_METRIC_INFINITY;
  893. RIPNG_TIMER_ON (rinfo->t_garbage_collect,
  894. ripng_garbage_collect, ripng->garbage_time);
  895. RIPNG_TIMER_OFF (rinfo->t_timeout);
  896. /* Aggregate count decrement. */
  897. ripng_aggregate_decrement (rp, rinfo);
  898. rinfo->flags |= RIPNG_RTF_CHANGED;
  899. if (IS_RIPNG_DEBUG_EVENT) {
  900. struct prefix_ipv6 *p = (struct prefix_ipv6 *) &rp->p;
  901. zlog_debug ("Poisone %s/%d on the interface %s [withdraw]",
  902. inet6_ntoa(p->prefix), p->prefixlen,
  903. ifindex2ifname(rinfo->ifindex));
  904. }
  905. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  906. }
  907. }
  908. }
  909. /* RIP routing information. */
  910. static void
  911. ripng_response_process (struct ripng_packet *packet, int size,
  912. struct sockaddr_in6 *from, struct interface *ifp,
  913. int hoplimit)
  914. {
  915. caddr_t lim;
  916. struct rte *rte;
  917. struct ripng_nexthop nexthop;
  918. /* RFC2080 2.4.2 Response Messages:
  919. The Response must be ignored if it is not from the RIPng port. */
  920. if (ntohs (from->sin6_port) != RIPNG_PORT_DEFAULT)
  921. {
  922. zlog_warn ("RIPng packet comes from non RIPng port %d from %s",
  923. ntohs (from->sin6_port), inet6_ntoa (from->sin6_addr));
  924. ripng_peer_bad_packet (from);
  925. return;
  926. }
  927. /* The datagram's IPv6 source address should be checked to see
  928. whether the datagram is from a valid neighbor; the source of the
  929. datagram must be a link-local address. */
  930. if (! IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr))
  931. {
  932. zlog_warn ("RIPng packet comes from non link local address %s",
  933. inet6_ntoa (from->sin6_addr));
  934. ripng_peer_bad_packet (from);
  935. return;
  936. }
  937. /* It is also worth checking to see whether the response is from one
  938. of the router's own addresses. Interfaces on broadcast networks
  939. may receive copies of their own multicasts immediately. If a
  940. router processes its own output as new input, confusion is likely,
  941. and such datagrams must be ignored. */
  942. if (ripng_lladdr_check (ifp, &from->sin6_addr))
  943. {
  944. zlog_warn ("RIPng packet comes from my own link local address %s",
  945. inet6_ntoa (from->sin6_addr));
  946. ripng_peer_bad_packet (from);
  947. return;
  948. }
  949. /* As an additional check, periodic advertisements must have their
  950. hop counts set to 255, and inbound, multicast packets sent from the
  951. RIPng port (i.e. periodic advertisement or triggered update
  952. packets) must be examined to ensure that the hop count is 255. */
  953. if (hoplimit >= 0 && hoplimit != 255)
  954. {
  955. zlog_warn ("RIPng packet comes with non 255 hop count %d from %s",
  956. hoplimit, inet6_ntoa (from->sin6_addr));
  957. ripng_peer_bad_packet (from);
  958. return;
  959. }
  960. /* Update RIPng peer. */
  961. ripng_peer_update (from, packet->version);
  962. /* Reset nexthop. */
  963. memset (&nexthop, 0, sizeof (struct ripng_nexthop));
  964. nexthop.flag = RIPNG_NEXTHOP_UNSPEC;
  965. /* Set RTE pointer. */
  966. rte = packet->rte;
  967. for (lim = ((caddr_t) packet) + size; (caddr_t) rte < lim; rte++)
  968. {
  969. /* First of all, we have to check this RTE is next hop RTE or
  970. not. Next hop RTE is completely different with normal RTE so
  971. we need special treatment. */
  972. if (rte->metric == RIPNG_METRIC_NEXTHOP)
  973. {
  974. ripng_nexthop_rte (rte, from, &nexthop);
  975. continue;
  976. }
  977. /* RTE information validation. */
  978. /* - is the destination prefix valid (e.g., not a multicast
  979. prefix and not a link-local address) A link-local address
  980. should never be present in an RTE. */
  981. if (IN6_IS_ADDR_MULTICAST (&rte->addr))
  982. {
  983. zlog_warn ("Destination prefix is a multicast address %s/%d [%d]",
  984. inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
  985. ripng_peer_bad_route (from);
  986. continue;
  987. }
  988. if (IN6_IS_ADDR_LINKLOCAL (&rte->addr))
  989. {
  990. zlog_warn ("Destination prefix is a link-local address %s/%d [%d]",
  991. inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
  992. ripng_peer_bad_route (from);
  993. continue;
  994. }
  995. if (IN6_IS_ADDR_LOOPBACK (&rte->addr))
  996. {
  997. zlog_warn ("Destination prefix is a loopback address %s/%d [%d]",
  998. inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
  999. ripng_peer_bad_route (from);
  1000. continue;
  1001. }
  1002. /* - is the prefix length valid (i.e., between 0 and 128,
  1003. inclusive) */
  1004. if (rte->prefixlen > 128)
  1005. {
  1006. zlog_warn ("Invalid prefix length %s/%d from %s%%%s",
  1007. inet6_ntoa (rte->addr), rte->prefixlen,
  1008. inet6_ntoa (from->sin6_addr), ifp->name);
  1009. ripng_peer_bad_route (from);
  1010. continue;
  1011. }
  1012. /* - is the metric valid (i.e., between 1 and 16, inclusive) */
  1013. if (! (rte->metric >= 1 && rte->metric <= 16))
  1014. {
  1015. zlog_warn ("Invalid metric %d from %s%%%s", rte->metric,
  1016. inet6_ntoa (from->sin6_addr), ifp->name);
  1017. ripng_peer_bad_route (from);
  1018. continue;
  1019. }
  1020. /* Vincent: XXX Should we compute the direclty reachable nexthop
  1021. * for our RIPng network ?
  1022. **/
  1023. /* Routing table updates. */
  1024. ripng_route_process (rte, from, &nexthop, ifp);
  1025. }
  1026. }
  1027. /* Response to request message. */
  1028. static void
  1029. ripng_request_process (struct ripng_packet *packet,int size,
  1030. struct sockaddr_in6 *from, struct interface *ifp)
  1031. {
  1032. caddr_t lim;
  1033. struct rte *rte;
  1034. struct prefix_ipv6 p;
  1035. struct route_node *rp;
  1036. struct ripng_info *rinfo;
  1037. struct ripng_interface *ri;
  1038. /* Does not reponse to the requests on the loopback interfaces */
  1039. if (if_is_loopback (ifp))
  1040. return;
  1041. /* Check RIPng process is enabled on this interface. */
  1042. ri = ifp->info;
  1043. if (! ri->running)
  1044. return;
  1045. /* When passive interface is specified, suppress responses */
  1046. if (ri->passive)
  1047. return;
  1048. /* RIPng peer update. */
  1049. ripng_peer_update (from, packet->version);
  1050. lim = ((caddr_t) packet) + size;
  1051. rte = packet->rte;
  1052. /* The Request is processed entry by entry. If there are no
  1053. entries, no response is given. */
  1054. if (lim == (caddr_t) rte)
  1055. return;
  1056. /* There is one special case. If there is exactly one entry in the
  1057. request, and it has a destination prefix of zero, a prefix length
  1058. of zero, and a metric of infinity (i.e., 16), then this is a
  1059. request to send the entire routing table. In that case, a call
  1060. is made to the output process to send the routing table to the
  1061. requesting address/port. */
  1062. if (lim == ((caddr_t) (rte + 1)) &&
  1063. IN6_IS_ADDR_UNSPECIFIED (&rte->addr) &&
  1064. rte->prefixlen == 0 &&
  1065. rte->metric == RIPNG_METRIC_INFINITY)
  1066. {
  1067. /* All route with split horizon */
  1068. ripng_output_process (ifp, from, ripng_all_route);
  1069. }
  1070. else
  1071. {
  1072. /* Except for this special case, processing is quite simple.
  1073. Examine the list of RTEs in the Request one by one. For each
  1074. entry, look up the destination in the router's routing
  1075. database and, if there is a route, put that route's metric in
  1076. the metric field of the RTE. If there is no explicit route
  1077. to the specified destination, put infinity in the metric
  1078. field. Once all the entries have been filled in, change the
  1079. command from Request to Response and send the datagram back
  1080. to the requestor. */
  1081. memset (&p, 0, sizeof (struct prefix_ipv6));
  1082. p.family = AF_INET6;
  1083. for (; ((caddr_t) rte) < lim; rte++)
  1084. {
  1085. p.prefix = rte->addr;
  1086. p.prefixlen = rte->prefixlen;
  1087. apply_mask_ipv6 (&p);
  1088. rp = route_node_lookup (ripng->table, (struct prefix *) &p);
  1089. if (rp)
  1090. {
  1091. rinfo = listgetdata (listhead ((struct list *)rp->info));
  1092. rte->metric = rinfo->metric;
  1093. route_unlock_node (rp);
  1094. }
  1095. else
  1096. rte->metric = RIPNG_METRIC_INFINITY;
  1097. }
  1098. packet->command = RIPNG_RESPONSE;
  1099. ripng_send_packet ((caddr_t) packet, size, from, ifp);
  1100. }
  1101. }
  1102. /* First entry point of reading RIPng packet. */
  1103. static int
  1104. ripng_read (struct thread *thread)
  1105. {
  1106. int len;
  1107. int sock;
  1108. struct sockaddr_in6 from;
  1109. struct ripng_packet *packet;
  1110. ifindex_t ifindex = 0;
  1111. struct interface *ifp;
  1112. int hoplimit = -1;
  1113. /* Check ripng is active and alive. */
  1114. assert (ripng != NULL);
  1115. assert (ripng->sock >= 0);
  1116. /* Fetch thread data and set read pointer to empty for event
  1117. managing. `sock' sould be same as ripng->sock. */
  1118. sock = THREAD_FD (thread);
  1119. ripng->t_read = NULL;
  1120. /* Add myself to the next event. */
  1121. ripng_event (RIPNG_READ, sock);
  1122. /* Read RIPng packet. */
  1123. len = ripng_recv_packet (sock, STREAM_DATA (ripng->ibuf),
  1124. STREAM_SIZE (ripng->ibuf), &from, &ifindex,
  1125. &hoplimit);
  1126. if (len < 0)
  1127. {
  1128. zlog_warn ("RIPng recvfrom failed: %s.", safe_strerror (errno));
  1129. return len;
  1130. }
  1131. /* Check RTE boundary. RTE size (Packet length - RIPng header size
  1132. (4)) must be multiple size of one RTE size (20). */
  1133. if (((len - 4) % 20) != 0)
  1134. {
  1135. zlog_warn ("RIPng invalid packet size %d from %s", len,
  1136. inet6_ntoa (from.sin6_addr));
  1137. ripng_peer_bad_packet (&from);
  1138. return 0;
  1139. }
  1140. packet = (struct ripng_packet *) STREAM_DATA (ripng->ibuf);
  1141. ifp = if_lookup_by_index (ifindex);
  1142. /* RIPng packet received. */
  1143. if (IS_RIPNG_DEBUG_EVENT)
  1144. zlog_debug ("RIPng packet received from %s port %d on %s",
  1145. inet6_ntoa (from.sin6_addr), ntohs (from.sin6_port),
  1146. ifp ? ifp->name : "unknown");
  1147. /* Logging before packet checking. */
  1148. if (IS_RIPNG_DEBUG_RECV)
  1149. ripng_packet_dump (packet, len, "RECV");
  1150. /* Packet comes from unknown interface. */
  1151. if (ifp == NULL)
  1152. {
  1153. zlog_warn ("RIPng packet comes from unknown interface %d", ifindex);
  1154. return 0;
  1155. }
  1156. /* Packet version mismatch checking. */
  1157. if (packet->version != ripng->version)
  1158. {
  1159. zlog_warn ("RIPng packet version %d doesn't fit to my version %d",
  1160. packet->version, ripng->version);
  1161. ripng_peer_bad_packet (&from);
  1162. return 0;
  1163. }
  1164. /* Process RIPng packet. */
  1165. switch (packet->command)
  1166. {
  1167. case RIPNG_REQUEST:
  1168. ripng_request_process (packet, len, &from, ifp);
  1169. break;
  1170. case RIPNG_RESPONSE:
  1171. ripng_response_process (packet, len, &from, ifp, hoplimit);
  1172. break;
  1173. default:
  1174. zlog_warn ("Invalid RIPng command %d", packet->command);
  1175. ripng_peer_bad_packet (&from);
  1176. break;
  1177. }
  1178. return 0;
  1179. }
  1180. /* Walk down the RIPng routing table then clear changed flag. */
  1181. static void
  1182. ripng_clear_changed_flag (void)
  1183. {
  1184. struct route_node *rp;
  1185. struct ripng_info *rinfo = NULL;
  1186. struct list *list = NULL;
  1187. struct listnode *listnode = NULL;
  1188. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  1189. if ((list = rp->info) != NULL)
  1190. for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
  1191. {
  1192. UNSET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
  1193. /* This flag can be set only on the first entry. */
  1194. break;
  1195. }
  1196. }
  1197. /* Regular update of RIPng route. Send all routing formation to RIPng
  1198. enabled interface. */
  1199. static int
  1200. ripng_update (struct thread *t)
  1201. {
  1202. struct listnode *node;
  1203. struct interface *ifp;
  1204. struct ripng_interface *ri;
  1205. /* Clear update timer thread. */
  1206. ripng->t_update = NULL;
  1207. /* Logging update event. */
  1208. if (IS_RIPNG_DEBUG_EVENT)
  1209. zlog_debug ("RIPng update timer expired!");
  1210. /* Supply routes to each interface. */
  1211. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  1212. {
  1213. ri = ifp->info;
  1214. if (if_is_loopback (ifp) || ! if_is_up (ifp))
  1215. continue;
  1216. if (! ri->running)
  1217. continue;
  1218. /* When passive interface is specified, suppress announce to the
  1219. interface. */
  1220. if (ri->passive)
  1221. continue;
  1222. #if RIPNG_ADVANCED
  1223. if (ri->ri_send == RIPNG_SEND_OFF)
  1224. {
  1225. if (IS_RIPNG_DEBUG_EVENT)
  1226. zlog (NULL, LOG_DEBUG,
  1227. "[Event] RIPng send to if %d is suppressed by config",
  1228. ifp->ifindex);
  1229. continue;
  1230. }
  1231. #endif /* RIPNG_ADVANCED */
  1232. ripng_output_process (ifp, NULL, ripng_all_route);
  1233. }
  1234. /* Triggered updates may be suppressed if a regular update is due by
  1235. the time the triggered update would be sent. */
  1236. if (ripng->t_triggered_interval)
  1237. {
  1238. thread_cancel (ripng->t_triggered_interval);
  1239. ripng->t_triggered_interval = NULL;
  1240. }
  1241. ripng->trigger = 0;
  1242. /* Reset flush event. */
  1243. ripng_event (RIPNG_UPDATE_EVENT, 0);
  1244. return 0;
  1245. }
  1246. /* Triggered update interval timer. */
  1247. static int
  1248. ripng_triggered_interval (struct thread *t)
  1249. {
  1250. ripng->t_triggered_interval = NULL;
  1251. if (ripng->trigger)
  1252. {
  1253. ripng->trigger = 0;
  1254. ripng_triggered_update (t);
  1255. }
  1256. return 0;
  1257. }
  1258. /* Execute triggered update. */
  1259. int
  1260. ripng_triggered_update (struct thread *t)
  1261. {
  1262. struct listnode *node;
  1263. struct interface *ifp;
  1264. struct ripng_interface *ri;
  1265. int interval;
  1266. ripng->t_triggered_update = NULL;
  1267. /* Cancel interval timer. */
  1268. if (ripng->t_triggered_interval)
  1269. {
  1270. thread_cancel (ripng->t_triggered_interval);
  1271. ripng->t_triggered_interval = NULL;
  1272. }
  1273. ripng->trigger = 0;
  1274. /* Logging triggered update. */
  1275. if (IS_RIPNG_DEBUG_EVENT)
  1276. zlog_debug ("RIPng triggered update!");
  1277. /* Split Horizon processing is done when generating triggered
  1278. updates as well as normal updates (see section 2.6). */
  1279. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  1280. {
  1281. ri = ifp->info;
  1282. if (if_is_loopback (ifp) || ! if_is_up (ifp))
  1283. continue;
  1284. if (! ri->running)
  1285. continue;
  1286. /* When passive interface is specified, suppress announce to the
  1287. interface. */
  1288. if (ri->passive)
  1289. continue;
  1290. ripng_output_process (ifp, NULL, ripng_changed_route);
  1291. }
  1292. /* Once all of the triggered updates have been generated, the route
  1293. change flags should be cleared. */
  1294. ripng_clear_changed_flag ();
  1295. /* After a triggered update is sent, a timer should be set for a
  1296. random interval between 1 and 5 seconds. If other changes that
  1297. would trigger updates occur before the timer expires, a single
  1298. update is triggered when the timer expires. */
  1299. interval = (random () % 5) + 1;
  1300. ripng->t_triggered_interval =
  1301. thread_add_timer (master, ripng_triggered_interval, NULL, interval);
  1302. return 0;
  1303. }
  1304. /* Write routing table entry to the stream and return next index of
  1305. the routing table entry in the stream. */
  1306. int
  1307. ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
  1308. struct in6_addr *nexthop, u_int16_t tag, u_char metric)
  1309. {
  1310. /* RIPng packet header. */
  1311. if (num == 0)
  1312. {
  1313. stream_putc (s, RIPNG_RESPONSE);
  1314. stream_putc (s, RIPNG_V1);
  1315. stream_putw (s, 0);
  1316. }
  1317. /* Write routing table entry. */
  1318. if (!nexthop)
  1319. stream_write (s, (u_char *) &p->prefix, sizeof (struct in6_addr));
  1320. else
  1321. stream_write (s, (u_char *) nexthop, sizeof (struct in6_addr));
  1322. stream_putw (s, tag);
  1323. if (p)
  1324. stream_putc (s, p->prefixlen);
  1325. else
  1326. stream_putc (s, 0);
  1327. stream_putc (s, metric);
  1328. return ++num;
  1329. }
  1330. /* Send RESPONSE message to specified destination. */
  1331. void
  1332. ripng_output_process (struct interface *ifp, struct sockaddr_in6 *to,
  1333. int route_type)
  1334. {
  1335. int ret;
  1336. struct route_node *rp;
  1337. struct ripng_info *rinfo;
  1338. struct ripng_interface *ri;
  1339. struct ripng_aggregate *aggregate;
  1340. struct prefix_ipv6 *p;
  1341. struct list * ripng_rte_list;
  1342. struct list *list = NULL;
  1343. struct listnode *listnode = NULL;
  1344. if (IS_RIPNG_DEBUG_EVENT) {
  1345. if (to)
  1346. zlog_debug ("RIPng update routes to neighbor %s",
  1347. inet6_ntoa(to->sin6_addr));
  1348. else
  1349. zlog_debug ("RIPng update routes on interface %s", ifp->name);
  1350. }
  1351. /* Get RIPng interface. */
  1352. ri = ifp->info;
  1353. ripng_rte_list = ripng_rte_new();
  1354. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  1355. {
  1356. if ((list = rp->info) != NULL &&
  1357. (rinfo = listgetdata (listhead (list))) != NULL &&
  1358. rinfo->suppress == 0)
  1359. {
  1360. /* If no route-map are applied, the RTE will be these following
  1361. * informations.
  1362. */
  1363. p = (struct prefix_ipv6 *) &rp->p;
  1364. rinfo->metric_out = rinfo->metric;
  1365. rinfo->tag_out = rinfo->tag;
  1366. memset(&rinfo->nexthop_out, 0, sizeof(rinfo->nexthop_out));
  1367. /* In order to avoid some local loops,
  1368. * if the RIPng route has a nexthop via this interface, keep the nexthop,
  1369. * otherwise set it to 0. The nexthop should not be propagated
  1370. * beyond the local broadcast/multicast area in order
  1371. * to avoid an IGP multi-level recursive look-up.
  1372. */
  1373. if (rinfo->ifindex == ifp->ifindex)
  1374. rinfo->nexthop_out = rinfo->nexthop;
  1375. /* Apply output filters. */
  1376. ret = ripng_filter (RIPNG_FILTER_OUT, p, ri);
  1377. if (ret < 0)
  1378. continue;
  1379. /* Changed route only output. */
  1380. if (route_type == ripng_changed_route &&
  1381. (! (rinfo->flags & RIPNG_RTF_CHANGED)))
  1382. continue;
  1383. /* Split horizon. */
  1384. if (ri->split_horizon == RIPNG_SPLIT_HORIZON)
  1385. {
  1386. /* We perform split horizon for RIPng routes. */
  1387. int suppress = 0;
  1388. struct ripng_info *tmp_rinfo = NULL;
  1389. for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
  1390. if (tmp_rinfo->type == ZEBRA_ROUTE_RIPNG &&
  1391. tmp_rinfo->ifindex == ifp->ifindex)
  1392. {
  1393. suppress = 1;
  1394. break;
  1395. }
  1396. if (suppress)
  1397. continue;
  1398. }
  1399. /* Preparation for route-map. */
  1400. rinfo->metric_set = 0;
  1401. /* nexthop_out,
  1402. * metric_out
  1403. * and tag_out are already initialized.
  1404. */
  1405. /* Interface route-map */
  1406. if (ri->routemap[RIPNG_FILTER_OUT])
  1407. {
  1408. int ret;
  1409. ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT],
  1410. (struct prefix *) p, RMAP_RIPNG,
  1411. rinfo);
  1412. if (ret == RMAP_DENYMATCH)
  1413. {
  1414. if (IS_RIPNG_DEBUG_PACKET)
  1415. zlog_debug ("RIPng %s/%d is filtered by route-map out",
  1416. inet6_ntoa (p->prefix), p->prefixlen);
  1417. continue;
  1418. }
  1419. }
  1420. /* Redistribute route-map. */
  1421. if (ripng->route_map[rinfo->type].name)
  1422. {
  1423. int ret;
  1424. ret = route_map_apply (ripng->route_map[rinfo->type].map,
  1425. (struct prefix *) p, RMAP_RIPNG,
  1426. rinfo);
  1427. if (ret == RMAP_DENYMATCH)
  1428. {
  1429. if (IS_RIPNG_DEBUG_PACKET)
  1430. zlog_debug ("RIPng %s/%d is filtered by route-map",
  1431. inet6_ntoa (p->prefix), p->prefixlen);
  1432. continue;
  1433. }
  1434. }
  1435. /* When the route-map does not set metric. */
  1436. if (! rinfo->metric_set)
  1437. {
  1438. /* If the redistribute metric is set. */
  1439. if (ripng->route_map[rinfo->type].metric_config
  1440. && rinfo->metric != RIPNG_METRIC_INFINITY)
  1441. {
  1442. rinfo->metric_out = ripng->route_map[rinfo->type].metric;
  1443. }
  1444. else
  1445. {
  1446. /* If the route is not connected or localy generated
  1447. one, use default-metric value */
  1448. if (rinfo->type != ZEBRA_ROUTE_RIPNG
  1449. && rinfo->type != ZEBRA_ROUTE_CONNECT
  1450. && rinfo->metric != RIPNG_METRIC_INFINITY)
  1451. rinfo->metric_out = ripng->default_metric;
  1452. }
  1453. }
  1454. /* Apply offset-list */
  1455. if (rinfo->metric_out != RIPNG_METRIC_INFINITY)
  1456. ripng_offset_list_apply_out (p, ifp, &rinfo->metric_out);
  1457. if (rinfo->metric_out > RIPNG_METRIC_INFINITY)
  1458. rinfo->metric_out = RIPNG_METRIC_INFINITY;
  1459. /* Perform split-horizon with poisoned reverse
  1460. * for RIPng routes.
  1461. **/
  1462. if (ri->split_horizon == RIPNG_SPLIT_HORIZON_POISONED_REVERSE) {
  1463. struct ripng_info *tmp_rinfo = NULL;
  1464. for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
  1465. if ((tmp_rinfo->type == ZEBRA_ROUTE_RIPNG) &&
  1466. tmp_rinfo->ifindex == ifp->ifindex)
  1467. rinfo->metric_out = RIPNG_METRIC_INFINITY;
  1468. }
  1469. /* Add RTE to the list */
  1470. ripng_rte_add(ripng_rte_list, p, rinfo, NULL);
  1471. }
  1472. /* Process the aggregated RTE entry */
  1473. if ((aggregate = rp->aggregate) != NULL &&
  1474. aggregate->count > 0 &&
  1475. aggregate->suppress == 0)
  1476. {
  1477. /* If no route-map are applied, the RTE will be these following
  1478. * informations.
  1479. */
  1480. p = (struct prefix_ipv6 *) &rp->p;
  1481. aggregate->metric_set = 0;
  1482. aggregate->metric_out = aggregate->metric;
  1483. aggregate->tag_out = aggregate->tag;
  1484. memset(&aggregate->nexthop_out, 0, sizeof(aggregate->nexthop_out));
  1485. /* Apply output filters.*/
  1486. ret = ripng_filter (RIPNG_FILTER_OUT, p, ri);
  1487. if (ret < 0)
  1488. continue;
  1489. /* Interface route-map */
  1490. if (ri->routemap[RIPNG_FILTER_OUT])
  1491. {
  1492. int ret;
  1493. struct ripng_info newinfo;
  1494. /* let's cast the aggregate structure to ripng_info */
  1495. memset (&newinfo, 0, sizeof (struct ripng_info));
  1496. /* the nexthop is :: */
  1497. newinfo.metric = aggregate->metric;
  1498. newinfo.metric_out = aggregate->metric_out;
  1499. newinfo.tag = aggregate->tag;
  1500. newinfo.tag_out = aggregate->tag_out;
  1501. ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT],
  1502. (struct prefix *) p, RMAP_RIPNG,
  1503. &newinfo);
  1504. if (ret == RMAP_DENYMATCH)
  1505. {
  1506. if (IS_RIPNG_DEBUG_PACKET)
  1507. zlog_debug ("RIPng %s/%d is filtered by route-map out",
  1508. inet6_ntoa (p->prefix), p->prefixlen);
  1509. continue;
  1510. }
  1511. aggregate->metric_out = newinfo.metric_out;
  1512. aggregate->tag_out = newinfo.tag_out;
  1513. if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop_out))
  1514. aggregate->nexthop_out = newinfo.nexthop_out;
  1515. }
  1516. /* There is no redistribute routemap for the aggregated RTE */
  1517. /* Changed route only output. */
  1518. /* XXX, vincent, in order to increase time convergence,
  1519. * it should be announced if a child has changed.
  1520. */
  1521. if (route_type == ripng_changed_route)
  1522. continue;
  1523. /* Apply offset-list */
  1524. if (aggregate->metric_out != RIPNG_METRIC_INFINITY)
  1525. ripng_offset_list_apply_out (p, ifp, &aggregate->metric_out);
  1526. if (aggregate->metric_out > RIPNG_METRIC_INFINITY)
  1527. aggregate->metric_out = RIPNG_METRIC_INFINITY;
  1528. /* Add RTE to the list */
  1529. ripng_rte_add(ripng_rte_list, p, NULL, aggregate);
  1530. }
  1531. }
  1532. /* Flush the list */
  1533. ripng_rte_send(ripng_rte_list, ifp, to);
  1534. ripng_rte_free(ripng_rte_list);
  1535. }
  1536. /* Create new RIPng instance and set it to global variable. */
  1537. static int
  1538. ripng_create (void)
  1539. {
  1540. /* ripng should be NULL. */
  1541. assert (ripng == NULL);
  1542. /* Allocaste RIPng instance. */
  1543. ripng = XCALLOC (MTYPE_RIPNG, sizeof (struct ripng));
  1544. /* Default version and timer values. */
  1545. ripng->version = RIPNG_V1;
  1546. ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
  1547. ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
  1548. ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
  1549. ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
  1550. /* Make buffer. */
  1551. ripng->ibuf = stream_new (RIPNG_MAX_PACKET_SIZE * 5);
  1552. ripng->obuf = stream_new (RIPNG_MAX_PACKET_SIZE);
  1553. /* Initialize RIPng routig table. */
  1554. ripng->table = route_table_init ();
  1555. ripng->route = route_table_init ();
  1556. ripng->aggregate = route_table_init ();
  1557. /* Make socket. */
  1558. ripng->sock = ripng_make_socket ();
  1559. if (ripng->sock < 0)
  1560. return ripng->sock;
  1561. /* Threads. */
  1562. ripng_event (RIPNG_READ, ripng->sock);
  1563. ripng_event (RIPNG_UPDATE_EVENT, 1);
  1564. return 0;
  1565. }
  1566. /* Send RIPng request to the interface. */
  1567. int
  1568. ripng_request (struct interface *ifp)
  1569. {
  1570. struct rte *rte;
  1571. struct ripng_packet ripng_packet;
  1572. /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
  1573. if (if_is_loopback(ifp))
  1574. return 0;
  1575. /* If interface is down, don't send RIP packet. */
  1576. if (! if_is_up (ifp))
  1577. return 0;
  1578. if (IS_RIPNG_DEBUG_EVENT)
  1579. zlog_debug ("RIPng send request to %s", ifp->name);
  1580. memset (&ripng_packet, 0, sizeof (ripng_packet));
  1581. ripng_packet.command = RIPNG_REQUEST;
  1582. ripng_packet.version = RIPNG_V1;
  1583. rte = ripng_packet.rte;
  1584. rte->metric = RIPNG_METRIC_INFINITY;
  1585. return ripng_send_packet ((caddr_t) &ripng_packet, sizeof (ripng_packet),
  1586. NULL, ifp);
  1587. }
  1588. static int
  1589. ripng_update_jitter (int time)
  1590. {
  1591. return ((random () % (time + 1)) - (time / 2));
  1592. }
  1593. void
  1594. ripng_event (enum ripng_event event, int sock)
  1595. {
  1596. int jitter = 0;
  1597. switch (event)
  1598. {
  1599. case RIPNG_READ:
  1600. if (!ripng->t_read)
  1601. ripng->t_read = thread_add_read (master, ripng_read, NULL, sock);
  1602. break;
  1603. case RIPNG_UPDATE_EVENT:
  1604. if (ripng->t_update)
  1605. {
  1606. thread_cancel (ripng->t_update);
  1607. ripng->t_update = NULL;
  1608. }
  1609. /* Update timer jitter. */
  1610. jitter = ripng_update_jitter (ripng->update_time);
  1611. ripng->t_update =
  1612. thread_add_timer (master, ripng_update, NULL,
  1613. sock ? 2 : ripng->update_time + jitter);
  1614. break;
  1615. case RIPNG_TRIGGERED_UPDATE:
  1616. if (ripng->t_triggered_interval)
  1617. ripng->trigger = 1;
  1618. else if (! ripng->t_triggered_update)
  1619. ripng->t_triggered_update =
  1620. thread_add_event (master, ripng_triggered_update, NULL, 0);
  1621. break;
  1622. default:
  1623. break;
  1624. }
  1625. }
  1626. /* Print out routes update time. */
  1627. static void
  1628. ripng_vty_out_uptime (struct vty *vty, struct ripng_info *rinfo)
  1629. {
  1630. time_t clock;
  1631. struct tm *tm;
  1632. #define TIME_BUF 25
  1633. char timebuf [TIME_BUF];
  1634. struct thread *thread;
  1635. if ((thread = rinfo->t_timeout) != NULL)
  1636. {
  1637. clock = thread_timer_remain_second (thread);
  1638. tm = gmtime (&clock);
  1639. strftime (timebuf, TIME_BUF, "%M:%S", tm);
  1640. vty_out (vty, "%5s", timebuf);
  1641. }
  1642. else if ((thread = rinfo->t_garbage_collect) != NULL)
  1643. {
  1644. clock = thread_timer_remain_second (thread);
  1645. tm = gmtime (&clock);
  1646. strftime (timebuf, TIME_BUF, "%M:%S", tm);
  1647. vty_out (vty, "%5s", timebuf);
  1648. }
  1649. }
  1650. static char *
  1651. ripng_route_subtype_print (struct ripng_info *rinfo)
  1652. {
  1653. static char str[3];
  1654. memset(str, 0, 3);
  1655. if (rinfo->suppress)
  1656. strcat(str, "S");
  1657. switch (rinfo->sub_type)
  1658. {
  1659. case RIPNG_ROUTE_RTE:
  1660. strcat(str, "n");
  1661. break;
  1662. case RIPNG_ROUTE_STATIC:
  1663. strcat(str, "s");
  1664. break;
  1665. case RIPNG_ROUTE_DEFAULT:
  1666. strcat(str, "d");
  1667. break;
  1668. case RIPNG_ROUTE_REDISTRIBUTE:
  1669. strcat(str, "r");
  1670. break;
  1671. case RIPNG_ROUTE_INTERFACE:
  1672. strcat(str, "i");
  1673. break;
  1674. default:
  1675. strcat(str, "?");
  1676. break;
  1677. }
  1678. return str;
  1679. }
  1680. DEFUN (show_ipv6_ripng,
  1681. show_ipv6_ripng_cmd,
  1682. "show ipv6 ripng",
  1683. SHOW_STR
  1684. IPV6_STR
  1685. "Show RIPng routes\n")
  1686. {
  1687. struct route_node *rp;
  1688. struct ripng_info *rinfo;
  1689. struct ripng_aggregate *aggregate;
  1690. struct prefix_ipv6 *p;
  1691. struct list *list = NULL;
  1692. struct listnode *listnode = NULL;
  1693. int len;
  1694. if (! ripng)
  1695. return CMD_SUCCESS;
  1696. /* Header of display. */
  1697. vty_out (vty, "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP%s"
  1698. "Sub-codes:%s"
  1699. " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
  1700. " (i) - interface, (a/S) - aggregated/Suppressed%s%s"
  1701. " Network Next Hop Via Metric Tag Time%s",
  1702. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE,
  1703. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  1704. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  1705. {
  1706. if ((aggregate = rp->aggregate) != NULL)
  1707. {
  1708. p = (struct prefix_ipv6 *) &rp->p;
  1709. #ifdef DEBUG
  1710. len = vty_out (vty, "R(a) %d/%d %s/%d ",
  1711. aggregate->count, aggregate->suppress,
  1712. inet6_ntoa (p->prefix), p->prefixlen);
  1713. #else
  1714. len = vty_out (vty, "R(a) %s/%d ",
  1715. inet6_ntoa (p->prefix), p->prefixlen);
  1716. #endif /* DEBUG */
  1717. vty_out (vty, "%s", VTY_NEWLINE);
  1718. vty_out (vty, "%*s", 18, " ");
  1719. vty_out (vty, "%*s", 28, " ");
  1720. vty_out (vty, "self %2d %3d%s", aggregate->metric,
  1721. aggregate->tag,
  1722. VTY_NEWLINE);
  1723. }
  1724. if ((list = rp->info) != NULL)
  1725. for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
  1726. {
  1727. p = (struct prefix_ipv6 *) &rp->p;
  1728. #ifdef DEBUG
  1729. len = vty_out (vty, "%c(%s) 0/%d %s/%d ",
  1730. zebra_route_char(rinfo->type),
  1731. ripng_route_subtype_print(rinfo),
  1732. rinfo->suppress,
  1733. inet6_ntoa (p->prefix), p->prefixlen);
  1734. #else
  1735. len = vty_out (vty, "%c(%s) %s/%d ",
  1736. zebra_route_char(rinfo->type),
  1737. ripng_route_subtype_print(rinfo),
  1738. inet6_ntoa (p->prefix), p->prefixlen);
  1739. #endif /* DEBUG */
  1740. vty_out (vty, "%s", VTY_NEWLINE);
  1741. vty_out (vty, "%*s", 18, " ");
  1742. len = vty_out (vty, "%s", inet6_ntoa (rinfo->nexthop));
  1743. len = 28 - len;
  1744. if (len > 0)
  1745. len = vty_out (vty, "%*s", len, " ");
  1746. /* from */
  1747. if ((rinfo->type == ZEBRA_ROUTE_RIPNG) &&
  1748. (rinfo->sub_type == RIPNG_ROUTE_RTE))
  1749. {
  1750. len = vty_out (vty, "%s", ifindex2ifname(rinfo->ifindex));
  1751. } else if (rinfo->metric == RIPNG_METRIC_INFINITY)
  1752. {
  1753. len = vty_out (vty, "kill");
  1754. } else
  1755. len = vty_out (vty, "self");
  1756. len = 9 - len;
  1757. if (len > 0)
  1758. vty_out (vty, "%*s", len, " ");
  1759. vty_out (vty, " %2d %3d ",
  1760. rinfo->metric, rinfo->tag);
  1761. /* time */
  1762. if ((rinfo->type == ZEBRA_ROUTE_RIPNG) &&
  1763. (rinfo->sub_type == RIPNG_ROUTE_RTE))
  1764. {
  1765. /* RTE from remote RIP routers */
  1766. ripng_vty_out_uptime (vty, rinfo);
  1767. } else if (rinfo->metric == RIPNG_METRIC_INFINITY)
  1768. {
  1769. /* poisonous reversed routes (gc) */
  1770. ripng_vty_out_uptime (vty, rinfo);
  1771. }
  1772. vty_out (vty, "%s", VTY_NEWLINE);
  1773. }
  1774. }
  1775. return CMD_SUCCESS;
  1776. }
  1777. DEFUN (show_ipv6_ripng_status,
  1778. show_ipv6_ripng_status_cmd,
  1779. "show ipv6 ripng status",
  1780. SHOW_STR
  1781. IPV6_STR
  1782. "Show RIPng routes\n"
  1783. "IPv6 routing protocol process parameters and statistics\n")
  1784. {
  1785. struct listnode *node;
  1786. struct interface *ifp;
  1787. if (! ripng)
  1788. return CMD_SUCCESS;
  1789. vty_out (vty, "Routing Protocol is \"RIPng\"%s", VTY_NEWLINE);
  1790. vty_out (vty, " Sending updates every %ld seconds with +/-50%%,",
  1791. ripng->update_time);
  1792. vty_out (vty, " next due in %lu seconds%s",
  1793. thread_timer_remain_second (ripng->t_update),
  1794. VTY_NEWLINE);
  1795. vty_out (vty, " Timeout after %ld seconds,", ripng->timeout_time);
  1796. vty_out (vty, " garbage collect after %ld seconds%s", ripng->garbage_time,
  1797. VTY_NEWLINE);
  1798. /* Filtering status show. */
  1799. config_show_distribute (vty);
  1800. /* Default metric information. */
  1801. vty_out (vty, " Default redistribution metric is %d%s",
  1802. ripng->default_metric, VTY_NEWLINE);
  1803. /* Redistribute information. */
  1804. vty_out (vty, " Redistributing:");
  1805. ripng_redistribute_write (vty, 0);
  1806. vty_out (vty, "%s", VTY_NEWLINE);
  1807. vty_out (vty, " Default version control: send version %d,", ripng->version);
  1808. vty_out (vty, " receive version %d %s", ripng->version,
  1809. VTY_NEWLINE);
  1810. vty_out (vty, " Interface Send Recv%s", VTY_NEWLINE);
  1811. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  1812. {
  1813. struct ripng_interface *ri;
  1814. ri = ifp->info;
  1815. if (ri->enable_network || ri->enable_interface)
  1816. {
  1817. vty_out (vty, " %-17s%-3d %-3d%s", ifp->name,
  1818. ripng->version,
  1819. ripng->version,
  1820. VTY_NEWLINE);
  1821. }
  1822. }
  1823. vty_out (vty, " Routing for Networks:%s", VTY_NEWLINE);
  1824. ripng_network_write (vty, 0);
  1825. vty_out (vty, " Routing Information Sources:%s", VTY_NEWLINE);
  1826. vty_out (vty, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE);
  1827. ripng_peer_display (vty);
  1828. return CMD_SUCCESS;
  1829. }
  1830. DEFUN (router_ripng,
  1831. router_ripng_cmd,
  1832. "router ripng",
  1833. "Enable a routing process\n"
  1834. "Make RIPng instance command\n")
  1835. {
  1836. int ret;
  1837. vty->node = RIPNG_NODE;
  1838. if (!ripng)
  1839. {
  1840. ret = ripng_create ();
  1841. /* Notice to user we couldn't create RIPng. */
  1842. if (ret < 0)
  1843. {
  1844. zlog_warn ("can't create RIPng");
  1845. return CMD_WARNING;
  1846. }
  1847. }
  1848. return CMD_SUCCESS;
  1849. }
  1850. DEFUN (no_router_ripng,
  1851. no_router_ripng_cmd,
  1852. "no router ripng",
  1853. NO_STR
  1854. "Enable a routing process\n"
  1855. "Make RIPng instance command\n")
  1856. {
  1857. if(ripng)
  1858. ripng_clean();
  1859. return CMD_SUCCESS;
  1860. }
  1861. DEFUN (ripng_route,
  1862. ripng_route_cmd,
  1863. "route IPV6ADDR",
  1864. "Static route setup\n"
  1865. "Set static RIPng route announcement\n")
  1866. {
  1867. int ret;
  1868. struct prefix_ipv6 p;
  1869. struct route_node *rp;
  1870. ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p);
  1871. if (ret <= 0)
  1872. {
  1873. vty_out (vty, "Malformed address%s", VTY_NEWLINE);
  1874. return CMD_WARNING;
  1875. }
  1876. apply_mask_ipv6 (&p);
  1877. rp = route_node_get (ripng->route, (struct prefix *) &p);
  1878. if (rp->info)
  1879. {
  1880. vty_out (vty, "There is already same static route.%s", VTY_NEWLINE);
  1881. route_unlock_node (rp);
  1882. return CMD_WARNING;
  1883. }
  1884. rp->info = (void *)1;
  1885. ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0, NULL);
  1886. return CMD_SUCCESS;
  1887. }
  1888. DEFUN (no_ripng_route,
  1889. no_ripng_route_cmd,
  1890. "no route IPV6ADDR",
  1891. NO_STR
  1892. "Static route setup\n"
  1893. "Delete static RIPng route announcement\n")
  1894. {
  1895. int ret;
  1896. struct prefix_ipv6 p;
  1897. struct route_node *rp;
  1898. ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p);
  1899. if (ret <= 0)
  1900. {
  1901. vty_out (vty, "Malformed address%s", VTY_NEWLINE);
  1902. return CMD_WARNING;
  1903. }
  1904. apply_mask_ipv6 (&p);
  1905. rp = route_node_lookup (ripng->route, (struct prefix *) &p);
  1906. if (! rp)
  1907. {
  1908. vty_out (vty, "Can't find static route.%s", VTY_NEWLINE);
  1909. return CMD_WARNING;
  1910. }
  1911. ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0);
  1912. route_unlock_node (rp);
  1913. rp->info = NULL;
  1914. route_unlock_node (rp);
  1915. return CMD_SUCCESS;
  1916. }
  1917. DEFUN (ripng_aggregate_address,
  1918. ripng_aggregate_address_cmd,
  1919. "aggregate-address X:X::X:X/M",
  1920. "Set aggregate RIPng route announcement\n"
  1921. "Aggregate network\n")
  1922. {
  1923. int ret;
  1924. struct prefix p;
  1925. struct route_node *node;
  1926. ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p);
  1927. if (ret <= 0)
  1928. {
  1929. vty_out (vty, "Malformed address%s", VTY_NEWLINE);
  1930. return CMD_WARNING;
  1931. }
  1932. /* Check aggregate alredy exist or not. */
  1933. node = route_node_get (ripng->aggregate, &p);
  1934. if (node->info)
  1935. {
  1936. vty_out (vty, "There is already same aggregate route.%s", VTY_NEWLINE);
  1937. route_unlock_node (node);
  1938. return CMD_WARNING;
  1939. }
  1940. node->info = (void *)1;
  1941. ripng_aggregate_add (&p);
  1942. return CMD_SUCCESS;
  1943. }
  1944. DEFUN (no_ripng_aggregate_address,
  1945. no_ripng_aggregate_address_cmd,
  1946. "no aggregate-address X:X::X:X/M",
  1947. NO_STR
  1948. "Delete aggregate RIPng route announcement\n"
  1949. "Aggregate network")
  1950. {
  1951. int ret;
  1952. struct prefix p;
  1953. struct route_node *rn;
  1954. ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *) &p);
  1955. if (ret <= 0)
  1956. {
  1957. vty_out (vty, "Malformed address%s", VTY_NEWLINE);
  1958. return CMD_WARNING;
  1959. }
  1960. rn = route_node_lookup (ripng->aggregate, &p);
  1961. if (! rn)
  1962. {
  1963. vty_out (vty, "Can't find aggregate route.%s", VTY_NEWLINE);
  1964. return CMD_WARNING;
  1965. }
  1966. route_unlock_node (rn);
  1967. rn->info = NULL;
  1968. route_unlock_node (rn);
  1969. ripng_aggregate_delete (&p);
  1970. return CMD_SUCCESS;
  1971. }
  1972. DEFUN (ripng_default_metric,
  1973. ripng_default_metric_cmd,
  1974. "default-metric <1-16>",
  1975. "Set a metric of redistribute routes\n"
  1976. "Default metric\n")
  1977. {
  1978. if (ripng)
  1979. {
  1980. ripng->default_metric = atoi (argv[0]);
  1981. }
  1982. return CMD_SUCCESS;
  1983. }
  1984. DEFUN (no_ripng_default_metric,
  1985. no_ripng_default_metric_cmd,
  1986. "no default-metric",
  1987. NO_STR
  1988. "Set a metric of redistribute routes\n"
  1989. "Default metric\n")
  1990. {
  1991. if (ripng)
  1992. {
  1993. ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
  1994. }
  1995. return CMD_SUCCESS;
  1996. }
  1997. ALIAS (no_ripng_default_metric,
  1998. no_ripng_default_metric_val_cmd,
  1999. "no default-metric <1-16>",
  2000. NO_STR
  2001. "Set a metric of redistribute routes\n"
  2002. "Default metric\n")
  2003. #if 0
  2004. /* RIPng update timer setup. */
  2005. DEFUN (ripng_update_timer,
  2006. ripng_update_timer_cmd,
  2007. "update-timer SECOND",
  2008. "Set RIPng update timer in seconds\n"
  2009. "Seconds\n")
  2010. {
  2011. unsigned long update;
  2012. char *endptr = NULL;
  2013. update = strtoul (argv[0], &endptr, 10);
  2014. if (update == ULONG_MAX || *endptr != '\0')
  2015. {
  2016. vty_out (vty, "update timer value error%s", VTY_NEWLINE);
  2017. return CMD_WARNING;
  2018. }
  2019. ripng->update_time = update;
  2020. ripng_event (RIPNG_UPDATE_EVENT, 0);
  2021. return CMD_SUCCESS;
  2022. }
  2023. DEFUN (no_ripng_update_timer,
  2024. no_ripng_update_timer_cmd,
  2025. "no update-timer SECOND",
  2026. NO_STR
  2027. "Unset RIPng update timer in seconds\n"
  2028. "Seconds\n")
  2029. {
  2030. ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
  2031. ripng_event (RIPNG_UPDATE_EVENT, 0);
  2032. return CMD_SUCCESS;
  2033. }
  2034. /* RIPng timeout timer setup. */
  2035. DEFUN (ripng_timeout_timer,
  2036. ripng_timeout_timer_cmd,
  2037. "timeout-timer SECOND",
  2038. "Set RIPng timeout timer in seconds\n"
  2039. "Seconds\n")
  2040. {
  2041. unsigned long timeout;
  2042. char *endptr = NULL;
  2043. timeout = strtoul (argv[0], &endptr, 10);
  2044. if (timeout == ULONG_MAX || *endptr != '\0')
  2045. {
  2046. vty_out (vty, "timeout timer value error%s", VTY_NEWLINE);
  2047. return CMD_WARNING;
  2048. }
  2049. ripng->timeout_time = timeout;
  2050. return CMD_SUCCESS;
  2051. }
  2052. DEFUN (no_ripng_timeout_timer,
  2053. no_ripng_timeout_timer_cmd,
  2054. "no timeout-timer SECOND",
  2055. NO_STR
  2056. "Unset RIPng timeout timer in seconds\n"
  2057. "Seconds\n")
  2058. {
  2059. ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
  2060. return CMD_SUCCESS;
  2061. }
  2062. /* RIPng garbage timer setup. */
  2063. DEFUN (ripng_garbage_timer,
  2064. ripng_garbage_timer_cmd,
  2065. "garbage-timer SECOND",
  2066. "Set RIPng garbage timer in seconds\n"
  2067. "Seconds\n")
  2068. {
  2069. unsigned long garbage;
  2070. char *endptr = NULL;
  2071. garbage = strtoul (argv[0], &endptr, 10);
  2072. if (garbage == ULONG_MAX || *endptr != '\0')
  2073. {
  2074. vty_out (vty, "garbage timer value error%s", VTY_NEWLINE);
  2075. return CMD_WARNING;
  2076. }
  2077. ripng->garbage_time = garbage;
  2078. return CMD_SUCCESS;
  2079. }
  2080. DEFUN (no_ripng_garbage_timer,
  2081. no_ripng_garbage_timer_cmd,
  2082. "no garbage-timer SECOND",
  2083. NO_STR
  2084. "Unset RIPng garbage timer in seconds\n"
  2085. "Seconds\n")
  2086. {
  2087. ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
  2088. return CMD_SUCCESS;
  2089. }
  2090. #endif /* 0 */
  2091. DEFUN (ripng_timers,
  2092. ripng_timers_cmd,
  2093. "timers basic <0-65535> <0-65535> <0-65535>",
  2094. "RIPng timers setup\n"
  2095. "Basic timer\n"
  2096. "Routing table update timer value in second. Default is 30.\n"
  2097. "Routing information timeout timer. Default is 180.\n"
  2098. "Garbage collection timer. Default is 120.\n")
  2099. {
  2100. unsigned long update;
  2101. unsigned long timeout;
  2102. unsigned long garbage;
  2103. VTY_GET_INTEGER_RANGE("update timer", update, argv[0], 0, 65535);
  2104. VTY_GET_INTEGER_RANGE("timeout timer", timeout, argv[1], 0, 65535);
  2105. VTY_GET_INTEGER_RANGE("garbage timer", garbage, argv[2], 0, 65535);
  2106. /* Set each timer value. */
  2107. ripng->update_time = update;
  2108. ripng->timeout_time = timeout;
  2109. ripng->garbage_time = garbage;
  2110. /* Reset update timer thread. */
  2111. ripng_event (RIPNG_UPDATE_EVENT, 0);
  2112. return CMD_SUCCESS;
  2113. }
  2114. DEFUN (no_ripng_timers,
  2115. no_ripng_timers_cmd,
  2116. "no timers basic",
  2117. NO_STR
  2118. "RIPng timers setup\n"
  2119. "Basic timer\n")
  2120. {
  2121. /* Set each timer value to the default. */
  2122. ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
  2123. ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
  2124. ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
  2125. /* Reset update timer thread. */
  2126. ripng_event (RIPNG_UPDATE_EVENT, 0);
  2127. return CMD_SUCCESS;
  2128. }
  2129. ALIAS (no_ripng_timers,
  2130. no_ripng_timers_val_cmd,
  2131. "no timers basic <0-65535> <0-65535> <0-65535>",
  2132. NO_STR
  2133. "RIPng timers setup\n"
  2134. "Basic timer\n"
  2135. "Routing table update timer value in second. Default is 30.\n"
  2136. "Routing information timeout timer. Default is 180.\n"
  2137. "Garbage collection timer. Default is 120.\n")
  2138. DEFUN (show_ipv6_protocols, show_ipv6_protocols_cmd,
  2139. "show ipv6 protocols",
  2140. SHOW_STR
  2141. IPV6_STR
  2142. "Routing protocol information")
  2143. {
  2144. if (! ripng)
  2145. return CMD_SUCCESS;
  2146. vty_out (vty, "Routing Protocol is \"ripng\"%s", VTY_NEWLINE);
  2147. vty_out (vty, "Sending updates every %ld seconds, next due in %d seconds%s",
  2148. ripng->update_time, 0,
  2149. VTY_NEWLINE);
  2150. vty_out (vty, "Timerout after %ld seconds, garbage correct %ld%s",
  2151. ripng->timeout_time,
  2152. ripng->garbage_time,
  2153. VTY_NEWLINE);
  2154. vty_out (vty, "Outgoing update filter list for all interfaces is not set");
  2155. vty_out (vty, "Incoming update filter list for all interfaces is not set");
  2156. return CMD_SUCCESS;
  2157. }
  2158. /* Please be carefull to use this command. */
  2159. DEFUN (ripng_default_information_originate,
  2160. ripng_default_information_originate_cmd,
  2161. "default-information originate",
  2162. "Default route information\n"
  2163. "Distribute default route\n")
  2164. {
  2165. struct prefix_ipv6 p;
  2166. if (! ripng ->default_information) {
  2167. ripng->default_information = 1;
  2168. str2prefix_ipv6 ("::/0", &p);
  2169. ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT, &p, 0, NULL);
  2170. }
  2171. return CMD_SUCCESS;
  2172. }
  2173. DEFUN (no_ripng_default_information_originate,
  2174. no_ripng_default_information_originate_cmd,
  2175. "no default-information originate",
  2176. NO_STR
  2177. "Default route information\n"
  2178. "Distribute default route\n")
  2179. {
  2180. struct prefix_ipv6 p;
  2181. if (ripng->default_information) {
  2182. ripng->default_information = 0;
  2183. str2prefix_ipv6 ("::/0", &p);
  2184. ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT, &p, 0);
  2185. }
  2186. return CMD_SUCCESS;
  2187. }
  2188. /* Update ECMP routes to zebra when ECMP is disabled. */
  2189. static void
  2190. ripng_ecmp_disable (void)
  2191. {
  2192. struct route_node *rp;
  2193. struct ripng_info *rinfo, *tmp_rinfo;
  2194. struct list *list;
  2195. struct listnode *node, *nextnode;
  2196. if (!ripng)
  2197. return;
  2198. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  2199. if ((list = rp->info) != NULL && listcount (list) > 1)
  2200. {
  2201. rinfo = listgetdata (listhead (list));
  2202. if (!ripng_route_rte (rinfo))
  2203. continue;
  2204. /* Drop all other entries, except the first one. */
  2205. for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
  2206. if (tmp_rinfo != rinfo)
  2207. {
  2208. RIPNG_TIMER_OFF (tmp_rinfo->t_timeout);
  2209. RIPNG_TIMER_OFF (tmp_rinfo->t_garbage_collect);
  2210. list_delete_node (list, node);
  2211. ripng_info_free (tmp_rinfo);
  2212. }
  2213. /* Update zebra. */
  2214. ripng_zebra_ipv6_add (rp);
  2215. /* Set the route change flag. */
  2216. SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
  2217. /* Signal the output process to trigger an update. */
  2218. ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
  2219. }
  2220. }
  2221. DEFUN (ripng_allow_ecmp,
  2222. ripng_allow_ecmp_cmd,
  2223. "allow-ecmp",
  2224. "Allow Equal Cost MultiPath\n")
  2225. {
  2226. if (ripng->ecmp)
  2227. {
  2228. vty_out (vty, "ECMP is already enabled.%s", VTY_NEWLINE);
  2229. return CMD_WARNING;
  2230. }
  2231. ripng->ecmp = 1;
  2232. zlog_info ("ECMP is enabled.");
  2233. return CMD_SUCCESS;
  2234. }
  2235. DEFUN (no_ripng_allow_ecmp,
  2236. no_ripng_allow_ecmp_cmd,
  2237. "no allow-ecmp",
  2238. NO_STR
  2239. "Allow Equal Cost MultiPath\n")
  2240. {
  2241. if (!ripng->ecmp)
  2242. {
  2243. vty_out (vty, "ECMP is already disabled.%s", VTY_NEWLINE);
  2244. return CMD_WARNING;
  2245. }
  2246. ripng->ecmp = 0;
  2247. zlog_info ("ECMP is disabled.");
  2248. ripng_ecmp_disable ();
  2249. return CMD_SUCCESS;
  2250. }
  2251. /* RIPng configuration write function. */
  2252. static int
  2253. ripng_config_write (struct vty *vty)
  2254. {
  2255. int ripng_network_write (struct vty *, int);
  2256. void ripng_redistribute_write (struct vty *, int);
  2257. int write = 0;
  2258. struct route_node *rp;
  2259. if (ripng)
  2260. {
  2261. /* RIPng router. */
  2262. vty_out (vty, "router ripng%s", VTY_NEWLINE);
  2263. if (ripng->default_information)
  2264. vty_out (vty, " default-information originate%s", VTY_NEWLINE);
  2265. ripng_network_write (vty, 1);
  2266. /* RIPng default metric configuration */
  2267. if (ripng->default_metric != RIPNG_DEFAULT_METRIC_DEFAULT)
  2268. vty_out (vty, " default-metric %d%s",
  2269. ripng->default_metric, VTY_NEWLINE);
  2270. ripng_redistribute_write (vty, 1);
  2271. /* RIP offset-list configuration. */
  2272. config_write_ripng_offset_list (vty);
  2273. /* RIPng aggregate routes. */
  2274. for (rp = route_top (ripng->aggregate); rp; rp = route_next (rp))
  2275. if (rp->info != NULL)
  2276. vty_out (vty, " aggregate-address %s/%d%s",
  2277. inet6_ntoa (rp->p.u.prefix6),
  2278. rp->p.prefixlen,
  2279. VTY_NEWLINE);
  2280. /* ECMP configuration. */
  2281. if (ripng->ecmp)
  2282. vty_out (vty, " allow-ecmp%s", VTY_NEWLINE);
  2283. /* RIPng static routes. */
  2284. for (rp = route_top (ripng->route); rp; rp = route_next (rp))
  2285. if (rp->info != NULL)
  2286. vty_out (vty, " route %s/%d%s", inet6_ntoa (rp->p.u.prefix6),
  2287. rp->p.prefixlen,
  2288. VTY_NEWLINE);
  2289. /* RIPng timers configuration. */
  2290. if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT ||
  2291. ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT ||
  2292. ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
  2293. {
  2294. vty_out (vty, " timers basic %ld %ld %ld%s",
  2295. ripng->update_time,
  2296. ripng->timeout_time,
  2297. ripng->garbage_time,
  2298. VTY_NEWLINE);
  2299. }
  2300. #if 0
  2301. if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT)
  2302. vty_out (vty, " update-timer %d%s", ripng->update_time,
  2303. VTY_NEWLINE);
  2304. if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT)
  2305. vty_out (vty, " timeout-timer %d%s", ripng->timeout_time,
  2306. VTY_NEWLINE);
  2307. if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
  2308. vty_out (vty, " garbage-timer %d%s", ripng->garbage_time,
  2309. VTY_NEWLINE);
  2310. #endif /* 0 */
  2311. write += config_write_distribute (vty);
  2312. write += config_write_if_rmap (vty);
  2313. write++;
  2314. }
  2315. return write;
  2316. }
  2317. /* RIPng node structure. */
  2318. static struct cmd_node cmd_ripng_node =
  2319. {
  2320. RIPNG_NODE,
  2321. "%s(config-router)# ",
  2322. 1,
  2323. };
  2324. static void
  2325. ripng_distribute_update (struct distribute *dist)
  2326. {
  2327. struct interface *ifp;
  2328. struct ripng_interface *ri;
  2329. struct access_list *alist;
  2330. struct prefix_list *plist;
  2331. if (! dist->ifname)
  2332. return;
  2333. ifp = if_lookup_by_name (dist->ifname);
  2334. if (ifp == NULL)
  2335. return;
  2336. ri = ifp->info;
  2337. if (dist->list[DISTRIBUTE_IN])
  2338. {
  2339. alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_IN]);
  2340. if (alist)
  2341. ri->list[RIPNG_FILTER_IN] = alist;
  2342. else
  2343. ri->list[RIPNG_FILTER_IN] = NULL;
  2344. }
  2345. else
  2346. ri->list[RIPNG_FILTER_IN] = NULL;
  2347. if (dist->list[DISTRIBUTE_OUT])
  2348. {
  2349. alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_OUT]);
  2350. if (alist)
  2351. ri->list[RIPNG_FILTER_OUT] = alist;
  2352. else
  2353. ri->list[RIPNG_FILTER_OUT] = NULL;
  2354. }
  2355. else
  2356. ri->list[RIPNG_FILTER_OUT] = NULL;
  2357. if (dist->prefix[DISTRIBUTE_IN])
  2358. {
  2359. plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_IN]);
  2360. if (plist)
  2361. ri->prefix[RIPNG_FILTER_IN] = plist;
  2362. else
  2363. ri->prefix[RIPNG_FILTER_IN] = NULL;
  2364. }
  2365. else
  2366. ri->prefix[RIPNG_FILTER_IN] = NULL;
  2367. if (dist->prefix[DISTRIBUTE_OUT])
  2368. {
  2369. plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_OUT]);
  2370. if (plist)
  2371. ri->prefix[RIPNG_FILTER_OUT] = plist;
  2372. else
  2373. ri->prefix[RIPNG_FILTER_OUT] = NULL;
  2374. }
  2375. else
  2376. ri->prefix[RIPNG_FILTER_OUT] = NULL;
  2377. }
  2378. void
  2379. ripng_distribute_update_interface (struct interface *ifp)
  2380. {
  2381. struct distribute *dist;
  2382. dist = distribute_lookup (ifp->name);
  2383. if (dist)
  2384. ripng_distribute_update (dist);
  2385. }
  2386. /* Update all interface's distribute list. */
  2387. static void
  2388. ripng_distribute_update_all (struct prefix_list *notused)
  2389. {
  2390. struct interface *ifp;
  2391. struct listnode *node;
  2392. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  2393. ripng_distribute_update_interface (ifp);
  2394. }
  2395. static void
  2396. ripng_distribute_update_all_wrapper (struct access_list *notused)
  2397. {
  2398. ripng_distribute_update_all(NULL);
  2399. }
  2400. /* delete all the added ripng routes. */
  2401. void
  2402. ripng_clean()
  2403. {
  2404. int i;
  2405. struct route_node *rp;
  2406. struct ripng_info *rinfo;
  2407. struct ripng_aggregate *aggregate;
  2408. struct list *list = NULL;
  2409. struct listnode *listnode = NULL;
  2410. if (ripng) {
  2411. /* Clear RIPng routes */
  2412. for (rp = route_top (ripng->table); rp; rp = route_next (rp))
  2413. {
  2414. if ((list = rp->info) != NULL)
  2415. {
  2416. rinfo = listgetdata (listhead (list));
  2417. if (ripng_route_rte (rinfo))
  2418. ripng_zebra_ipv6_delete (rp);
  2419. for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
  2420. {
  2421. RIPNG_TIMER_OFF (rinfo->t_timeout);
  2422. RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
  2423. ripng_info_free (rinfo);
  2424. }
  2425. list_delete (list);
  2426. rp->info = NULL;
  2427. route_unlock_node (rp);
  2428. }
  2429. if ((aggregate = rp->aggregate) != NULL)
  2430. {
  2431. ripng_aggregate_free (aggregate);
  2432. rp->aggregate = NULL;
  2433. route_unlock_node (rp);
  2434. }
  2435. }
  2436. /* Cancel the RIPng timers */
  2437. RIPNG_TIMER_OFF (ripng->t_update);
  2438. RIPNG_TIMER_OFF (ripng->t_triggered_update);
  2439. RIPNG_TIMER_OFF (ripng->t_triggered_interval);
  2440. /* Cancel the read thread */
  2441. if (ripng->t_read) {
  2442. thread_cancel (ripng->t_read);
  2443. ripng->t_read = NULL;
  2444. }
  2445. /* Close the RIPng socket */
  2446. if (ripng->sock >= 0) {
  2447. close(ripng->sock);
  2448. ripng->sock = -1;
  2449. }
  2450. /* Static RIPng route configuration. */
  2451. for (rp = route_top (ripng->route); rp; rp = route_next (rp))
  2452. if (rp->info) {
  2453. rp->info = NULL;
  2454. route_unlock_node (rp);
  2455. }
  2456. /* RIPng aggregated prefixes */
  2457. for (rp = route_top (ripng->aggregate); rp; rp = route_next (rp))
  2458. if (rp->info) {
  2459. rp->info = NULL;
  2460. route_unlock_node (rp);
  2461. }
  2462. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  2463. if (ripng->route_map[i].name)
  2464. free (ripng->route_map[i].name);
  2465. XFREE (MTYPE_ROUTE_TABLE, ripng->table);
  2466. XFREE (MTYPE_ROUTE_TABLE, ripng->route);
  2467. XFREE (MTYPE_ROUTE_TABLE, ripng->aggregate);
  2468. XFREE (MTYPE_RIPNG, ripng);
  2469. ripng = NULL;
  2470. } /* if (ripng) */
  2471. ripng_clean_network();
  2472. ripng_passive_interface_clean ();
  2473. ripng_offset_clean ();
  2474. ripng_interface_clean ();
  2475. ripng_redistribute_clean ();
  2476. }
  2477. /* Reset all values to the default settings. */
  2478. void
  2479. ripng_reset ()
  2480. {
  2481. /* Call ripd related reset functions. */
  2482. ripng_debug_reset ();
  2483. ripng_route_map_reset ();
  2484. /* Call library reset functions. */
  2485. vty_reset ();
  2486. access_list_reset ();
  2487. prefix_list_reset ();
  2488. distribute_list_reset ();
  2489. ripng_interface_reset ();
  2490. ripng_zclient_reset ();
  2491. }
  2492. static void
  2493. ripng_if_rmap_update (struct if_rmap *if_rmap)
  2494. {
  2495. struct interface *ifp;
  2496. struct ripng_interface *ri;
  2497. struct route_map *rmap;
  2498. ifp = if_lookup_by_name (if_rmap->ifname);
  2499. if (ifp == NULL)
  2500. return;
  2501. ri = ifp->info;
  2502. if (if_rmap->routemap[IF_RMAP_IN])
  2503. {
  2504. rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_IN]);
  2505. if (rmap)
  2506. ri->routemap[IF_RMAP_IN] = rmap;
  2507. else
  2508. ri->routemap[IF_RMAP_IN] = NULL;
  2509. }
  2510. else
  2511. ri->routemap[RIPNG_FILTER_IN] = NULL;
  2512. if (if_rmap->routemap[IF_RMAP_OUT])
  2513. {
  2514. rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_OUT]);
  2515. if (rmap)
  2516. ri->routemap[IF_RMAP_OUT] = rmap;
  2517. else
  2518. ri->routemap[IF_RMAP_OUT] = NULL;
  2519. }
  2520. else
  2521. ri->routemap[RIPNG_FILTER_OUT] = NULL;
  2522. }
  2523. void
  2524. ripng_if_rmap_update_interface (struct interface *ifp)
  2525. {
  2526. struct if_rmap *if_rmap;
  2527. if_rmap = if_rmap_lookup (ifp->name);
  2528. if (if_rmap)
  2529. ripng_if_rmap_update (if_rmap);
  2530. }
  2531. static void
  2532. ripng_routemap_update_redistribute (void)
  2533. {
  2534. int i;
  2535. if (ripng)
  2536. {
  2537. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  2538. {
  2539. if (ripng->route_map[i].name)
  2540. ripng->route_map[i].map =
  2541. route_map_lookup_by_name (ripng->route_map[i].name);
  2542. }
  2543. }
  2544. }
  2545. static void
  2546. ripng_routemap_update (const char *unused)
  2547. {
  2548. struct interface *ifp;
  2549. struct listnode *node;
  2550. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  2551. ripng_if_rmap_update_interface (ifp);
  2552. ripng_routemap_update_redistribute ();
  2553. }
  2554. /* Initialize ripng structure and set commands. */
  2555. void
  2556. ripng_init ()
  2557. {
  2558. /* Randomize. */
  2559. srandom (time (NULL));
  2560. /* Install RIPNG_NODE. */
  2561. install_node (&cmd_ripng_node, ripng_config_write);
  2562. /* Install ripng commands. */
  2563. install_element (VIEW_NODE, &show_ipv6_ripng_cmd);
  2564. install_element (VIEW_NODE, &show_ipv6_ripng_status_cmd);
  2565. install_element (ENABLE_NODE, &show_ipv6_ripng_cmd);
  2566. install_element (ENABLE_NODE, &show_ipv6_ripng_status_cmd);
  2567. install_element (CONFIG_NODE, &router_ripng_cmd);
  2568. install_element (CONFIG_NODE, &no_router_ripng_cmd);
  2569. install_default (RIPNG_NODE);
  2570. install_element (RIPNG_NODE, &ripng_route_cmd);
  2571. install_element (RIPNG_NODE, &no_ripng_route_cmd);
  2572. install_element (RIPNG_NODE, &ripng_aggregate_address_cmd);
  2573. install_element (RIPNG_NODE, &no_ripng_aggregate_address_cmd);
  2574. install_element (RIPNG_NODE, &ripng_default_metric_cmd);
  2575. install_element (RIPNG_NODE, &no_ripng_default_metric_cmd);
  2576. install_element (RIPNG_NODE, &no_ripng_default_metric_val_cmd);
  2577. install_element (RIPNG_NODE, &ripng_timers_cmd);
  2578. install_element (RIPNG_NODE, &no_ripng_timers_cmd);
  2579. install_element (RIPNG_NODE, &no_ripng_timers_val_cmd);
  2580. #if 0
  2581. install_element (RIPNG_NODE, &ripng_update_timer_cmd);
  2582. install_element (RIPNG_NODE, &no_ripng_update_timer_cmd);
  2583. install_element (RIPNG_NODE, &ripng_timeout_timer_cmd);
  2584. install_element (RIPNG_NODE, &no_ripng_timeout_timer_cmd);
  2585. install_element (RIPNG_NODE, &ripng_garbage_timer_cmd);
  2586. install_element (RIPNG_NODE, &no_ripng_garbage_timer_cmd);
  2587. #endif /* 0 */
  2588. install_element (RIPNG_NODE, &ripng_default_information_originate_cmd);
  2589. install_element (RIPNG_NODE, &no_ripng_default_information_originate_cmd);
  2590. install_element (RIPNG_NODE, &ripng_allow_ecmp_cmd);
  2591. install_element (RIPNG_NODE, &no_ripng_allow_ecmp_cmd);
  2592. ripng_if_init ();
  2593. ripng_debug_init ();
  2594. /* Access list install. */
  2595. access_list_init ();
  2596. access_list_add_hook (ripng_distribute_update_all_wrapper);
  2597. access_list_delete_hook (ripng_distribute_update_all_wrapper);
  2598. /* Prefix list initialize.*/
  2599. prefix_list_init ();
  2600. prefix_list_add_hook (ripng_distribute_update_all);
  2601. prefix_list_delete_hook (ripng_distribute_update_all);
  2602. /* Distribute list install. */
  2603. distribute_list_init (RIPNG_NODE);
  2604. distribute_list_add_hook (ripng_distribute_update);
  2605. distribute_list_delete_hook (ripng_distribute_update);
  2606. /* Route-map for interface. */
  2607. ripng_route_map_init ();
  2608. ripng_offset_init ();
  2609. route_map_add_hook (ripng_routemap_update);
  2610. route_map_delete_hook (ripng_routemap_update);
  2611. if_rmap_init (RIPNG_NODE);
  2612. if_rmap_hook_add (ripng_if_rmap_update);
  2613. if_rmap_hook_delete (ripng_if_rmap_update);
  2614. }