rtadv.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. /* Router advertisement
  2. * Copyright (C) 2005 6WIND <jean-mickael.guerin@6wind.com>
  3. * Copyright (C) 1999 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "memory.h"
  24. #include "sockopt.h"
  25. #include "thread.h"
  26. #include "if.h"
  27. #include "log.h"
  28. #include "prefix.h"
  29. #include "linklist.h"
  30. #include "command.h"
  31. #include "privs.h"
  32. #include "zebra/interface.h"
  33. #include "zebra/rtadv.h"
  34. #include "zebra/debug.h"
  35. #include "zebra/rib.h"
  36. #include "zebra/zserv.h"
  37. extern struct zebra_privs_t zserv_privs;
  38. #if defined (HAVE_IPV6) && defined (RTADV)
  39. #ifdef OPEN_BSD
  40. #include <netinet/icmp6.h>
  41. #endif
  42. /* If RFC2133 definition is used. */
  43. #ifndef IPV6_JOIN_GROUP
  44. #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
  45. #endif
  46. #ifndef IPV6_LEAVE_GROUP
  47. #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
  48. #endif
  49. #define ALLNODE "ff02::1"
  50. #define ALLROUTER "ff02::2"
  51. extern struct zebra_t zebrad;
  52. enum rtadv_event {RTADV_START, RTADV_STOP, RTADV_TIMER,
  53. RTADV_TIMER_MSEC, RTADV_READ};
  54. static void rtadv_event (enum rtadv_event, int);
  55. static int if_join_all_router (int, struct interface *);
  56. static int if_leave_all_router (int, struct interface *);
  57. /* Structure which hold status of router advertisement. */
  58. struct rtadv
  59. {
  60. int sock;
  61. int adv_if_count;
  62. int adv_msec_if_count;
  63. struct thread *ra_read;
  64. struct thread *ra_timer;
  65. };
  66. struct rtadv *rtadv = NULL;
  67. static struct rtadv *
  68. rtadv_new (void)
  69. {
  70. return XCALLOC (MTYPE_TMP, sizeof (struct rtadv));
  71. }
  72. static int
  73. rtadv_recv_packet (int sock, u_char *buf, int buflen,
  74. struct sockaddr_in6 *from, unsigned int *ifindex,
  75. int *hoplimit)
  76. {
  77. int ret;
  78. struct msghdr msg;
  79. struct iovec iov;
  80. struct cmsghdr *cmsgptr;
  81. struct in6_addr dst;
  82. char adata[1024];
  83. /* Fill in message and iovec. */
  84. msg.msg_name = (void *) from;
  85. msg.msg_namelen = sizeof (struct sockaddr_in6);
  86. msg.msg_iov = &iov;
  87. msg.msg_iovlen = 1;
  88. msg.msg_control = (void *) adata;
  89. msg.msg_controllen = sizeof adata;
  90. iov.iov_base = buf;
  91. iov.iov_len = buflen;
  92. /* If recvmsg fail return minus value. */
  93. ret = recvmsg (sock, &msg, 0);
  94. if (ret < 0)
  95. return ret;
  96. for (cmsgptr = ZCMSG_FIRSTHDR(&msg); cmsgptr != NULL;
  97. cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
  98. {
  99. /* I want interface index which this packet comes from. */
  100. if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
  101. cmsgptr->cmsg_type == IPV6_PKTINFO)
  102. {
  103. struct in6_pktinfo *ptr;
  104. ptr = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
  105. *ifindex = ptr->ipi6_ifindex;
  106. memcpy(&dst, &ptr->ipi6_addr, sizeof(ptr->ipi6_addr));
  107. }
  108. /* Incoming packet's hop limit. */
  109. if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
  110. cmsgptr->cmsg_type == IPV6_HOPLIMIT)
  111. {
  112. int *hoptr = (int *) CMSG_DATA (cmsgptr);
  113. *hoplimit = *hoptr;
  114. }
  115. }
  116. return ret;
  117. }
  118. #define RTADV_MSG_SIZE 4096
  119. /* Send router advertisement packet. */
  120. static void
  121. rtadv_send_packet (int sock, struct interface *ifp)
  122. {
  123. struct msghdr msg;
  124. struct iovec iov;
  125. struct cmsghdr *cmsgptr;
  126. struct in6_pktinfo *pkt;
  127. struct sockaddr_in6 addr;
  128. #ifdef HAVE_STRUCT_SOCKADDR_DL
  129. struct sockaddr_dl *sdl;
  130. #endif /* HAVE_STRUCT_SOCKADDR_DL */
  131. static void *adata = NULL;
  132. unsigned char buf[RTADV_MSG_SIZE];
  133. struct nd_router_advert *rtadv;
  134. int ret;
  135. int len = 0;
  136. struct zebra_if *zif;
  137. struct rtadv_prefix *rprefix;
  138. u_char all_nodes_addr[] = {0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
  139. struct listnode *node;
  140. u_int16_t pkt_RouterLifetime;
  141. /*
  142. * Allocate control message bufffer. This is dynamic because
  143. * CMSG_SPACE is not guaranteed not to call a function. Note that
  144. * the size will be different on different architectures due to
  145. * differing alignment rules.
  146. */
  147. if (adata == NULL)
  148. {
  149. /* XXX Free on shutdown. */
  150. adata = malloc(CMSG_SPACE(sizeof(struct in6_pktinfo)));
  151. if (adata == NULL)
  152. zlog_err("rtadv_send_packet: can't malloc control data\n");
  153. }
  154. /* Logging of packet. */
  155. if (IS_ZEBRA_DEBUG_PACKET)
  156. zlog_debug ("Router advertisement send to %s", ifp->name);
  157. /* Fill in sockaddr_in6. */
  158. memset (&addr, 0, sizeof (struct sockaddr_in6));
  159. addr.sin6_family = AF_INET6;
  160. #ifdef SIN6_LEN
  161. addr.sin6_len = sizeof (struct sockaddr_in6);
  162. #endif /* SIN6_LEN */
  163. addr.sin6_port = htons (IPPROTO_ICMPV6);
  164. IPV6_ADDR_COPY (&addr.sin6_addr, all_nodes_addr);
  165. /* Fetch interface information. */
  166. zif = ifp->info;
  167. /* Make router advertisement message. */
  168. rtadv = (struct nd_router_advert *) buf;
  169. rtadv->nd_ra_type = ND_ROUTER_ADVERT;
  170. rtadv->nd_ra_code = 0;
  171. rtadv->nd_ra_cksum = 0;
  172. rtadv->nd_ra_curhoplimit = 64;
  173. /* RFC4191: Default Router Preference is 0 if Router Lifetime is 0. */
  174. rtadv->nd_ra_flags_reserved =
  175. zif->rtadv.AdvDefaultLifetime == 0 ? 0 : zif->rtadv.DefaultPreference;
  176. rtadv->nd_ra_flags_reserved <<= 3;
  177. if (zif->rtadv.AdvManagedFlag)
  178. rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_MANAGED;
  179. if (zif->rtadv.AdvOtherConfigFlag)
  180. rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_OTHER;
  181. if (zif->rtadv.AdvHomeAgentFlag)
  182. rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_HOME_AGENT;
  183. /* Note that according to Neighbor Discovery (RFC 4861 [18]),
  184. * AdvDefaultLifetime is by default based on the value of
  185. * MaxRtrAdvInterval. AdvDefaultLifetime is used in the Router Lifetime
  186. * field of Router Advertisements. Given that this field is expressed
  187. * in seconds, a small MaxRtrAdvInterval value can result in a zero
  188. * value for this field. To prevent this, routers SHOULD keep
  189. * AdvDefaultLifetime in at least one second, even if the use of
  190. * MaxRtrAdvInterval would result in a smaller value. -- RFC6275, 7.5 */
  191. pkt_RouterLifetime = zif->rtadv.AdvDefaultLifetime != -1 ?
  192. zif->rtadv.AdvDefaultLifetime :
  193. MAX (1, 0.003 * zif->rtadv.MaxRtrAdvInterval);
  194. rtadv->nd_ra_router_lifetime = htons (pkt_RouterLifetime);
  195. rtadv->nd_ra_reachable = htonl (zif->rtadv.AdvReachableTime);
  196. rtadv->nd_ra_retransmit = htonl (0);
  197. len = sizeof (struct nd_router_advert);
  198. /* If both the Home Agent Preference and Home Agent Lifetime are set to
  199. * their default values specified above, this option SHOULD NOT be
  200. * included in the Router Advertisement messages sent by this home
  201. * agent. -- RFC6275, 7.4 */
  202. if
  203. (
  204. zif->rtadv.AdvHomeAgentFlag &&
  205. (zif->rtadv.HomeAgentPreference || zif->rtadv.HomeAgentLifetime != -1)
  206. )
  207. {
  208. struct nd_opt_homeagent_info *ndopt_hai =
  209. (struct nd_opt_homeagent_info *)(buf + len);
  210. ndopt_hai->nd_opt_hai_type = ND_OPT_HA_INFORMATION;
  211. ndopt_hai->nd_opt_hai_len = 1;
  212. ndopt_hai->nd_opt_hai_reserved = 0;
  213. ndopt_hai->nd_opt_hai_preference = htons(zif->rtadv.HomeAgentPreference);
  214. /* 16-bit unsigned integer. The lifetime associated with the home
  215. * agent in units of seconds. The default value is the same as the
  216. * Router Lifetime, as specified in the main body of the Router
  217. * Advertisement. The maximum value corresponds to 18.2 hours. A
  218. * value of 0 MUST NOT be used. -- RFC6275, 7.5 */
  219. ndopt_hai->nd_opt_hai_lifetime = htons
  220. (
  221. zif->rtadv.HomeAgentLifetime != -1 ?
  222. zif->rtadv.HomeAgentLifetime :
  223. MAX (1, pkt_RouterLifetime) /* 0 is OK for RL, but not for HAL*/
  224. );
  225. len += sizeof(struct nd_opt_homeagent_info);
  226. }
  227. if (zif->rtadv.AdvIntervalOption)
  228. {
  229. struct nd_opt_adv_interval *ndopt_adv =
  230. (struct nd_opt_adv_interval *)(buf + len);
  231. ndopt_adv->nd_opt_ai_type = ND_OPT_ADV_INTERVAL;
  232. ndopt_adv->nd_opt_ai_len = 1;
  233. ndopt_adv->nd_opt_ai_reserved = 0;
  234. ndopt_adv->nd_opt_ai_interval = htonl(zif->rtadv.MaxRtrAdvInterval);
  235. len += sizeof(struct nd_opt_adv_interval);
  236. }
  237. /* Fill in prefix. */
  238. for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix))
  239. {
  240. struct nd_opt_prefix_info *pinfo;
  241. pinfo = (struct nd_opt_prefix_info *) (buf + len);
  242. pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
  243. pinfo->nd_opt_pi_len = 4;
  244. pinfo->nd_opt_pi_prefix_len = rprefix->prefix.prefixlen;
  245. pinfo->nd_opt_pi_flags_reserved = 0;
  246. if (rprefix->AdvOnLinkFlag)
  247. pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_ONLINK;
  248. if (rprefix->AdvAutonomousFlag)
  249. pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO;
  250. if (rprefix->AdvRouterAddressFlag)
  251. pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;
  252. pinfo->nd_opt_pi_valid_time = htonl (rprefix->AdvValidLifetime);
  253. pinfo->nd_opt_pi_preferred_time = htonl (rprefix->AdvPreferredLifetime);
  254. pinfo->nd_opt_pi_reserved2 = 0;
  255. IPV6_ADDR_COPY (&pinfo->nd_opt_pi_prefix, &rprefix->prefix.prefix);
  256. #ifdef DEBUG
  257. {
  258. u_char buf[INET6_ADDRSTRLEN];
  259. zlog_debug ("DEBUG %s", inet_ntop (AF_INET6, &pinfo->nd_opt_pi_prefix,
  260. buf, INET6_ADDRSTRLEN));
  261. }
  262. #endif /* DEBUG */
  263. len += sizeof (struct nd_opt_prefix_info);
  264. }
  265. /* Hardware address. */
  266. #ifdef HAVE_STRUCT_SOCKADDR_DL
  267. sdl = &ifp->sdl;
  268. if (sdl != NULL && sdl->sdl_alen != 0)
  269. {
  270. buf[len++] = ND_OPT_SOURCE_LINKADDR;
  271. /* Option length should be rounded up to next octet if
  272. the link address does not end on an octet boundary. */
  273. buf[len++] = (sdl->sdl_alen + 9) >> 3;
  274. memcpy (buf + len, LLADDR (sdl), sdl->sdl_alen);
  275. len += sdl->sdl_alen;
  276. /* Pad option to end on an octet boundary. */
  277. memset (buf + len, 0, -(sdl->sdl_alen + 2) & 0x7);
  278. len += -(sdl->sdl_alen + 2) & 0x7;
  279. }
  280. #else
  281. if (ifp->hw_addr_len != 0)
  282. {
  283. buf[len++] = ND_OPT_SOURCE_LINKADDR;
  284. /* Option length should be rounded up to next octet if
  285. the link address does not end on an octet boundary. */
  286. buf[len++] = (ifp->hw_addr_len + 9) >> 3;
  287. memcpy (buf + len, ifp->hw_addr, ifp->hw_addr_len);
  288. len += ifp->hw_addr_len;
  289. /* Pad option to end on an octet boundary. */
  290. memset (buf + len, 0, -(ifp->hw_addr_len + 2) & 0x7);
  291. len += -(ifp->hw_addr_len + 2) & 0x7;
  292. }
  293. #endif /* HAVE_STRUCT_SOCKADDR_DL */
  294. /* MTU */
  295. if (zif->rtadv.AdvLinkMTU)
  296. {
  297. struct nd_opt_mtu * opt = (struct nd_opt_mtu *) (buf + len);
  298. opt->nd_opt_mtu_type = ND_OPT_MTU;
  299. opt->nd_opt_mtu_len = 1;
  300. opt->nd_opt_mtu_reserved = 0;
  301. opt->nd_opt_mtu_mtu = htonl (zif->rtadv.AdvLinkMTU);
  302. len += sizeof (struct nd_opt_mtu);
  303. }
  304. msg.msg_name = (void *) &addr;
  305. msg.msg_namelen = sizeof (struct sockaddr_in6);
  306. msg.msg_iov = &iov;
  307. msg.msg_iovlen = 1;
  308. msg.msg_control = (void *) adata;
  309. msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
  310. msg.msg_flags = 0;
  311. iov.iov_base = buf;
  312. iov.iov_len = len;
  313. cmsgptr = ZCMSG_FIRSTHDR(&msg);
  314. cmsgptr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
  315. cmsgptr->cmsg_level = IPPROTO_IPV6;
  316. cmsgptr->cmsg_type = IPV6_PKTINFO;
  317. pkt = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
  318. memset (&pkt->ipi6_addr, 0, sizeof (struct in6_addr));
  319. pkt->ipi6_ifindex = ifp->ifindex;
  320. ret = sendmsg (sock, &msg, 0);
  321. if (ret < 0)
  322. {
  323. zlog_err ("rtadv_send_packet: sendmsg %d (%s)\n",
  324. errno, safe_strerror(errno));
  325. }
  326. }
  327. static int
  328. rtadv_timer (struct thread *thread)
  329. {
  330. struct listnode *node, *nnode;
  331. struct interface *ifp;
  332. struct zebra_if *zif;
  333. int period;
  334. rtadv->ra_timer = NULL;
  335. if (rtadv->adv_msec_if_count == 0)
  336. {
  337. period = 1000; /* 1 s */
  338. rtadv_event (RTADV_TIMER, 1 /* 1 s */);
  339. }
  340. else
  341. {
  342. period = 10; /* 10 ms */
  343. rtadv_event (RTADV_TIMER_MSEC, 10 /* 10 ms */);
  344. }
  345. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  346. {
  347. if (if_is_loopback (ifp) || ! if_is_operative (ifp))
  348. continue;
  349. zif = ifp->info;
  350. if (zif->rtadv.AdvSendAdvertisements)
  351. {
  352. zif->rtadv.AdvIntervalTimer -= period;
  353. if (zif->rtadv.AdvIntervalTimer <= 0)
  354. {
  355. /* FIXME: using MaxRtrAdvInterval each time isn't what section
  356. 6.2.4 of RFC4861 tells to do. */
  357. zif->rtadv.AdvIntervalTimer = zif->rtadv.MaxRtrAdvInterval;
  358. rtadv_send_packet (rtadv->sock, ifp);
  359. }
  360. }
  361. }
  362. return 0;
  363. }
  364. static void
  365. rtadv_process_solicit (struct interface *ifp)
  366. {
  367. zlog_info ("Router solicitation received on %s", ifp->name);
  368. rtadv_send_packet (rtadv->sock, ifp);
  369. }
  370. static void
  371. rtadv_process_advert (void)
  372. {
  373. zlog_info ("Router advertisement received");
  374. }
  375. static void
  376. rtadv_process_packet (u_char *buf, unsigned int len, unsigned int ifindex, int hoplimit)
  377. {
  378. struct icmp6_hdr *icmph;
  379. struct interface *ifp;
  380. struct zebra_if *zif;
  381. /* Interface search. */
  382. ifp = if_lookup_by_index (ifindex);
  383. if (ifp == NULL)
  384. {
  385. zlog_warn ("Unknown interface index: %d", ifindex);
  386. return;
  387. }
  388. if (if_is_loopback (ifp))
  389. return;
  390. /* Check interface configuration. */
  391. zif = ifp->info;
  392. if (! zif->rtadv.AdvSendAdvertisements)
  393. return;
  394. /* ICMP message length check. */
  395. if (len < sizeof (struct icmp6_hdr))
  396. {
  397. zlog_warn ("Invalid ICMPV6 packet length: %d", len);
  398. return;
  399. }
  400. icmph = (struct icmp6_hdr *) buf;
  401. /* ICMP message type check. */
  402. if (icmph->icmp6_type != ND_ROUTER_SOLICIT &&
  403. icmph->icmp6_type != ND_ROUTER_ADVERT)
  404. {
  405. zlog_warn ("Unwanted ICMPV6 message type: %d", icmph->icmp6_type);
  406. return;
  407. }
  408. /* Hoplimit check. */
  409. if (hoplimit >= 0 && hoplimit != 255)
  410. {
  411. zlog_warn ("Invalid hoplimit %d for router advertisement ICMP packet",
  412. hoplimit);
  413. return;
  414. }
  415. /* Check ICMP message type. */
  416. if (icmph->icmp6_type == ND_ROUTER_SOLICIT)
  417. rtadv_process_solicit (ifp);
  418. else if (icmph->icmp6_type == ND_ROUTER_ADVERT)
  419. rtadv_process_advert ();
  420. return;
  421. }
  422. static int
  423. rtadv_read (struct thread *thread)
  424. {
  425. int sock;
  426. int len;
  427. u_char buf[RTADV_MSG_SIZE];
  428. struct sockaddr_in6 from;
  429. unsigned int ifindex = 0;
  430. int hoplimit = -1;
  431. sock = THREAD_FD (thread);
  432. rtadv->ra_read = NULL;
  433. /* Register myself. */
  434. rtadv_event (RTADV_READ, sock);
  435. len = rtadv_recv_packet (sock, buf, BUFSIZ, &from, &ifindex, &hoplimit);
  436. if (len < 0)
  437. {
  438. zlog_warn ("router solicitation recv failed: %s.", safe_strerror (errno));
  439. return len;
  440. }
  441. rtadv_process_packet (buf, (unsigned)len, ifindex, hoplimit);
  442. return 0;
  443. }
  444. static int
  445. rtadv_make_socket (void)
  446. {
  447. int sock;
  448. int ret;
  449. struct icmp6_filter filter;
  450. if ( zserv_privs.change (ZPRIVS_RAISE) )
  451. zlog_err ("rtadv_make_socket: could not raise privs, %s",
  452. safe_strerror (errno) );
  453. sock = socket (AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
  454. if ( zserv_privs.change (ZPRIVS_LOWER) )
  455. zlog_err ("rtadv_make_socket: could not lower privs, %s",
  456. safe_strerror (errno) );
  457. /* When we can't make ICMPV6 socket simply back. Router
  458. advertisement feature will not be supported. */
  459. if (sock < 0)
  460. return -1;
  461. ret = setsockopt_ipv6_pktinfo (sock, 1);
  462. if (ret < 0)
  463. return ret;
  464. ret = setsockopt_ipv6_multicast_loop (sock, 0);
  465. if (ret < 0)
  466. return ret;
  467. ret = setsockopt_ipv6_unicast_hops (sock, 255);
  468. if (ret < 0)
  469. return ret;
  470. ret = setsockopt_ipv6_multicast_hops (sock, 255);
  471. if (ret < 0)
  472. return ret;
  473. ret = setsockopt_ipv6_hoplimit (sock, 1);
  474. if (ret < 0)
  475. return ret;
  476. ICMP6_FILTER_SETBLOCKALL(&filter);
  477. ICMP6_FILTER_SETPASS (ND_ROUTER_SOLICIT, &filter);
  478. ICMP6_FILTER_SETPASS (ND_ROUTER_ADVERT, &filter);
  479. ret = setsockopt (sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
  480. sizeof (struct icmp6_filter));
  481. if (ret < 0)
  482. {
  483. zlog_info ("ICMP6_FILTER set fail: %s", safe_strerror (errno));
  484. return ret;
  485. }
  486. return sock;
  487. }
  488. static struct rtadv_prefix *
  489. rtadv_prefix_new (void)
  490. {
  491. return XCALLOC (MTYPE_RTADV_PREFIX, sizeof (struct rtadv_prefix));
  492. }
  493. static void
  494. rtadv_prefix_free (struct rtadv_prefix *rtadv_prefix)
  495. {
  496. XFREE (MTYPE_RTADV_PREFIX, rtadv_prefix);
  497. }
  498. static struct rtadv_prefix *
  499. rtadv_prefix_lookup (struct list *rplist, struct prefix_ipv6 *p)
  500. {
  501. struct listnode *node;
  502. struct rtadv_prefix *rprefix;
  503. for (ALL_LIST_ELEMENTS_RO (rplist, node, rprefix))
  504. if (prefix_same ((struct prefix *) &rprefix->prefix, (struct prefix *) p))
  505. return rprefix;
  506. return NULL;
  507. }
  508. static struct rtadv_prefix *
  509. rtadv_prefix_get (struct list *rplist, struct prefix_ipv6 *p)
  510. {
  511. struct rtadv_prefix *rprefix;
  512. rprefix = rtadv_prefix_lookup (rplist, p);
  513. if (rprefix)
  514. return rprefix;
  515. rprefix = rtadv_prefix_new ();
  516. memcpy (&rprefix->prefix, p, sizeof (struct prefix_ipv6));
  517. listnode_add (rplist, rprefix);
  518. return rprefix;
  519. }
  520. static void
  521. rtadv_prefix_set (struct zebra_if *zif, struct rtadv_prefix *rp)
  522. {
  523. struct rtadv_prefix *rprefix;
  524. rprefix = rtadv_prefix_get (zif->rtadv.AdvPrefixList, &rp->prefix);
  525. /* Set parameters. */
  526. rprefix->AdvValidLifetime = rp->AdvValidLifetime;
  527. rprefix->AdvPreferredLifetime = rp->AdvPreferredLifetime;
  528. rprefix->AdvOnLinkFlag = rp->AdvOnLinkFlag;
  529. rprefix->AdvAutonomousFlag = rp->AdvAutonomousFlag;
  530. rprefix->AdvRouterAddressFlag = rp->AdvRouterAddressFlag;
  531. }
  532. static int
  533. rtadv_prefix_reset (struct zebra_if *zif, struct rtadv_prefix *rp)
  534. {
  535. struct rtadv_prefix *rprefix;
  536. rprefix = rtadv_prefix_lookup (zif->rtadv.AdvPrefixList, &rp->prefix);
  537. if (rprefix != NULL)
  538. {
  539. listnode_delete (zif->rtadv.AdvPrefixList, (void *) rprefix);
  540. rtadv_prefix_free (rprefix);
  541. return 1;
  542. }
  543. else
  544. return 0;
  545. }
  546. DEFUN (ipv6_nd_suppress_ra,
  547. ipv6_nd_suppress_ra_cmd,
  548. "ipv6 nd suppress-ra",
  549. "Interface IPv6 config commands\n"
  550. "Neighbor discovery\n"
  551. "Suppress Router Advertisement\n")
  552. {
  553. struct interface *ifp;
  554. struct zebra_if *zif;
  555. ifp = vty->index;
  556. zif = ifp->info;
  557. if (if_is_loopback (ifp))
  558. {
  559. vty_out (vty, "Invalid interface%s", VTY_NEWLINE);
  560. return CMD_WARNING;
  561. }
  562. if (zif->rtadv.AdvSendAdvertisements)
  563. {
  564. zif->rtadv.AdvSendAdvertisements = 0;
  565. zif->rtadv.AdvIntervalTimer = 0;
  566. rtadv->adv_if_count--;
  567. if_leave_all_router (rtadv->sock, ifp);
  568. if (rtadv->adv_if_count == 0)
  569. rtadv_event (RTADV_STOP, 0);
  570. }
  571. return CMD_SUCCESS;
  572. }
  573. DEFUN (no_ipv6_nd_suppress_ra,
  574. no_ipv6_nd_suppress_ra_cmd,
  575. "no ipv6 nd suppress-ra",
  576. NO_STR
  577. "Interface IPv6 config commands\n"
  578. "Neighbor discovery\n"
  579. "Suppress Router Advertisement\n")
  580. {
  581. struct interface *ifp;
  582. struct zebra_if *zif;
  583. ifp = vty->index;
  584. zif = ifp->info;
  585. if (if_is_loopback (ifp))
  586. {
  587. vty_out (vty, "Invalid interface%s", VTY_NEWLINE);
  588. return CMD_WARNING;
  589. }
  590. if (! zif->rtadv.AdvSendAdvertisements)
  591. {
  592. zif->rtadv.AdvSendAdvertisements = 1;
  593. zif->rtadv.AdvIntervalTimer = 0;
  594. rtadv->adv_if_count++;
  595. if_join_all_router (rtadv->sock, ifp);
  596. if (rtadv->adv_if_count == 1)
  597. rtadv_event (RTADV_START, rtadv->sock);
  598. }
  599. return CMD_SUCCESS;
  600. }
  601. DEFUN (ipv6_nd_ra_interval_msec,
  602. ipv6_nd_ra_interval_msec_cmd,
  603. "ipv6 nd ra-interval msec <70-1800000>",
  604. "Interface IPv6 config commands\n"
  605. "Neighbor discovery\n"
  606. "Router Advertisement interval\n"
  607. "Router Advertisement interval in milliseconds\n")
  608. {
  609. unsigned interval;
  610. struct interface *ifp = (struct interface *) vty->index;
  611. struct zebra_if *zif = ifp->info;
  612. VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[0], 70, 1800000);
  613. if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime * 1000))
  614. {
  615. vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE);
  616. return CMD_WARNING;
  617. }
  618. if (zif->rtadv.MaxRtrAdvInterval % 1000)
  619. rtadv->adv_msec_if_count--;
  620. if (interval % 1000)
  621. rtadv->adv_msec_if_count++;
  622. zif->rtadv.MaxRtrAdvInterval = interval;
  623. zif->rtadv.MinRtrAdvInterval = 0.33 * interval;
  624. zif->rtadv.AdvIntervalTimer = 0;
  625. return CMD_SUCCESS;
  626. }
  627. DEFUN (ipv6_nd_ra_interval,
  628. ipv6_nd_ra_interval_cmd,
  629. "ipv6 nd ra-interval <1-1800>",
  630. "Interface IPv6 config commands\n"
  631. "Neighbor discovery\n"
  632. "Router Advertisement interval\n"
  633. "Router Advertisement interval in seconds\n")
  634. {
  635. unsigned interval;
  636. struct interface *ifp = (struct interface *) vty->index;
  637. struct zebra_if *zif = ifp->info;
  638. VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[0], 1, 1800);
  639. if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime))
  640. {
  641. vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE);
  642. return CMD_WARNING;
  643. }
  644. if (zif->rtadv.MaxRtrAdvInterval % 1000)
  645. rtadv->adv_msec_if_count--;
  646. /* convert to milliseconds */
  647. interval = interval * 1000;
  648. zif->rtadv.MaxRtrAdvInterval = interval;
  649. zif->rtadv.MinRtrAdvInterval = 0.33 * interval;
  650. zif->rtadv.AdvIntervalTimer = 0;
  651. return CMD_SUCCESS;
  652. }
  653. DEFUN (no_ipv6_nd_ra_interval,
  654. no_ipv6_nd_ra_interval_cmd,
  655. "no ipv6 nd ra-interval",
  656. NO_STR
  657. "Interface IPv6 config commands\n"
  658. "Neighbor discovery\n"
  659. "Router Advertisement interval\n")
  660. {
  661. struct interface *ifp;
  662. struct zebra_if *zif;
  663. ifp = (struct interface *) vty->index;
  664. zif = ifp->info;
  665. if (zif->rtadv.MaxRtrAdvInterval % 1000)
  666. rtadv->adv_msec_if_count--;
  667. zif->rtadv.MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
  668. zif->rtadv.MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
  669. zif->rtadv.AdvIntervalTimer = zif->rtadv.MaxRtrAdvInterval;
  670. return CMD_SUCCESS;
  671. }
  672. ALIAS (no_ipv6_nd_ra_interval,
  673. no_ipv6_nd_ra_interval_val_cmd,
  674. "no ipv6 nd ra-interval <1-1800>",
  675. NO_STR
  676. "Interface IPv6 config commands\n"
  677. "Neighbor discovery\n"
  678. "Router Advertisement interval\n")
  679. ALIAS (no_ipv6_nd_ra_interval,
  680. no_ipv6_nd_ra_interval_msec_val_cmd,
  681. "no ipv6 nd ra-interval msec <1-1800000>",
  682. NO_STR
  683. "Interface IPv6 config commands\n"
  684. "Neighbor discovery\n"
  685. "Router Advertisement interval\n"
  686. "Router Advertisement interval in milliseconds\n")
  687. DEFUN (ipv6_nd_ra_lifetime,
  688. ipv6_nd_ra_lifetime_cmd,
  689. "ipv6 nd ra-lifetime <0-9000>",
  690. "Interface IPv6 config commands\n"
  691. "Neighbor discovery\n"
  692. "Router lifetime\n"
  693. "Router lifetime in seconds (0 stands for a non-default gw)\n")
  694. {
  695. int lifetime;
  696. struct interface *ifp;
  697. struct zebra_if *zif;
  698. ifp = (struct interface *) vty->index;
  699. zif = ifp->info;
  700. VTY_GET_INTEGER_RANGE ("router lifetime", lifetime, argv[0], 0, 9000);
  701. /* The value to be placed in the Router Lifetime field
  702. * of Router Advertisements sent from the interface,
  703. * in seconds. MUST be either zero or between
  704. * MaxRtrAdvInterval and 9000 seconds. -- RFC4861, 6.2.1 */
  705. if ((lifetime != 0 && lifetime * 1000 < zif->rtadv.MaxRtrAdvInterval))
  706. {
  707. vty_out (vty, "This ra-lifetime would conflict with configured ra-interval%s", VTY_NEWLINE);
  708. return CMD_WARNING;
  709. }
  710. zif->rtadv.AdvDefaultLifetime = lifetime;
  711. return CMD_SUCCESS;
  712. }
  713. DEFUN (no_ipv6_nd_ra_lifetime,
  714. no_ipv6_nd_ra_lifetime_cmd,
  715. "no ipv6 nd ra-lifetime",
  716. NO_STR
  717. "Interface IPv6 config commands\n"
  718. "Neighbor discovery\n"
  719. "Router lifetime\n")
  720. {
  721. struct interface *ifp;
  722. struct zebra_if *zif;
  723. ifp = (struct interface *) vty->index;
  724. zif = ifp->info;
  725. zif->rtadv.AdvDefaultLifetime = -1;
  726. return CMD_SUCCESS;
  727. }
  728. ALIAS (no_ipv6_nd_ra_lifetime,
  729. no_ipv6_nd_ra_lifetime_val_cmd,
  730. "no ipv6 nd ra-lifetime <0-9000>",
  731. NO_STR
  732. "Interface IPv6 config commands\n"
  733. "Neighbor discovery\n"
  734. "Router lifetime\n"
  735. "Router lifetime in seconds (0 stands for a non-default gw)\n")
  736. DEFUN (ipv6_nd_reachable_time,
  737. ipv6_nd_reachable_time_cmd,
  738. "ipv6 nd reachable-time <1-3600000>",
  739. "Interface IPv6 config commands\n"
  740. "Neighbor discovery\n"
  741. "Reachable time\n"
  742. "Reachable time in milliseconds\n")
  743. {
  744. struct interface *ifp = (struct interface *) vty->index;
  745. struct zebra_if *zif = ifp->info;
  746. VTY_GET_INTEGER_RANGE ("reachable time", zif->rtadv.AdvReachableTime, argv[0], 1, RTADV_MAX_REACHABLE_TIME);
  747. return CMD_SUCCESS;
  748. }
  749. DEFUN (no_ipv6_nd_reachable_time,
  750. no_ipv6_nd_reachable_time_cmd,
  751. "no ipv6 nd reachable-time",
  752. NO_STR
  753. "Interface IPv6 config commands\n"
  754. "Neighbor discovery\n"
  755. "Reachable time\n")
  756. {
  757. struct interface *ifp;
  758. struct zebra_if *zif;
  759. ifp = (struct interface *) vty->index;
  760. zif = ifp->info;
  761. zif->rtadv.AdvReachableTime = 0;
  762. return CMD_SUCCESS;
  763. }
  764. ALIAS (no_ipv6_nd_reachable_time,
  765. no_ipv6_nd_reachable_time_val_cmd,
  766. "no ipv6 nd reachable-time <1-3600000>",
  767. NO_STR
  768. "Interface IPv6 config commands\n"
  769. "Neighbor discovery\n"
  770. "Reachable time\n"
  771. "Reachable time in milliseconds\n")
  772. DEFUN (ipv6_nd_homeagent_preference,
  773. ipv6_nd_homeagent_preference_cmd,
  774. "ipv6 nd home-agent-preference <0-65535>",
  775. "Interface IPv6 config commands\n"
  776. "Neighbor discovery\n"
  777. "Home Agent preference\n"
  778. "preference value (default is 0, least preferred)\n")
  779. {
  780. struct interface *ifp = (struct interface *) vty->index;
  781. struct zebra_if *zif = ifp->info;
  782. VTY_GET_INTEGER_RANGE ("home agent preference", zif->rtadv.HomeAgentPreference, argv[0], 0, 65535);
  783. return CMD_SUCCESS;
  784. }
  785. DEFUN (no_ipv6_nd_homeagent_preference,
  786. no_ipv6_nd_homeagent_preference_cmd,
  787. "no ipv6 nd home-agent-preference",
  788. NO_STR
  789. "Interface IPv6 config commands\n"
  790. "Neighbor discovery\n"
  791. "Home Agent preference\n")
  792. {
  793. struct interface *ifp;
  794. struct zebra_if *zif;
  795. ifp = (struct interface *) vty->index;
  796. zif = ifp->info;
  797. zif->rtadv.HomeAgentPreference = 0;
  798. return CMD_SUCCESS;
  799. }
  800. ALIAS (no_ipv6_nd_homeagent_preference,
  801. no_ipv6_nd_homeagent_preference_val_cmd,
  802. "no ipv6 nd home-agent-preference <0-65535>",
  803. NO_STR
  804. "Interface IPv6 config commands\n"
  805. "Neighbor discovery\n"
  806. "Home Agent preference\n"
  807. "preference value (default is 0, least preferred)\n")
  808. DEFUN (ipv6_nd_homeagent_lifetime,
  809. ipv6_nd_homeagent_lifetime_cmd,
  810. "ipv6 nd home-agent-lifetime <0-65520>",
  811. "Interface IPv6 config commands\n"
  812. "Neighbor discovery\n"
  813. "Home Agent lifetime\n"
  814. "Home Agent lifetime in seconds (0 to track ra-lifetime)\n")
  815. {
  816. struct interface *ifp = (struct interface *) vty->index;
  817. struct zebra_if *zif = ifp->info;
  818. VTY_GET_INTEGER_RANGE ("home agent lifetime", zif->rtadv.HomeAgentLifetime, argv[0], 0, RTADV_MAX_HALIFETIME);
  819. return CMD_SUCCESS;
  820. }
  821. DEFUN (no_ipv6_nd_homeagent_lifetime,
  822. no_ipv6_nd_homeagent_lifetime_cmd,
  823. "no ipv6 nd home-agent-lifetime",
  824. NO_STR
  825. "Interface IPv6 config commands\n"
  826. "Neighbor discovery\n"
  827. "Home Agent lifetime\n")
  828. {
  829. struct interface *ifp;
  830. struct zebra_if *zif;
  831. ifp = (struct interface *) vty->index;
  832. zif = ifp->info;
  833. zif->rtadv.HomeAgentLifetime = -1;
  834. return CMD_SUCCESS;
  835. }
  836. ALIAS (no_ipv6_nd_homeagent_lifetime,
  837. no_ipv6_nd_homeagent_lifetime_val_cmd,
  838. "no ipv6 nd home-agent-lifetime <0-65520>",
  839. NO_STR
  840. "Interface IPv6 config commands\n"
  841. "Neighbor discovery\n"
  842. "Home Agent lifetime\n"
  843. "Home Agent lifetime in seconds (0 to track ra-lifetime)\n")
  844. DEFUN (ipv6_nd_managed_config_flag,
  845. ipv6_nd_managed_config_flag_cmd,
  846. "ipv6 nd managed-config-flag",
  847. "Interface IPv6 config commands\n"
  848. "Neighbor discovery\n"
  849. "Managed address configuration flag\n")
  850. {
  851. struct interface *ifp;
  852. struct zebra_if *zif;
  853. ifp = (struct interface *) vty->index;
  854. zif = ifp->info;
  855. zif->rtadv.AdvManagedFlag = 1;
  856. return CMD_SUCCESS;
  857. }
  858. DEFUN (no_ipv6_nd_managed_config_flag,
  859. no_ipv6_nd_managed_config_flag_cmd,
  860. "no ipv6 nd managed-config-flag",
  861. NO_STR
  862. "Interface IPv6 config commands\n"
  863. "Neighbor discovery\n"
  864. "Managed address configuration flag\n")
  865. {
  866. struct interface *ifp;
  867. struct zebra_if *zif;
  868. ifp = (struct interface *) vty->index;
  869. zif = ifp->info;
  870. zif->rtadv.AdvManagedFlag = 0;
  871. return CMD_SUCCESS;
  872. }
  873. DEFUN (ipv6_nd_homeagent_config_flag,
  874. ipv6_nd_homeagent_config_flag_cmd,
  875. "ipv6 nd home-agent-config-flag",
  876. "Interface IPv6 config commands\n"
  877. "Neighbor discovery\n"
  878. "Home Agent configuration flag\n")
  879. {
  880. struct interface *ifp;
  881. struct zebra_if *zif;
  882. ifp = (struct interface *) vty->index;
  883. zif = ifp->info;
  884. zif->rtadv.AdvHomeAgentFlag = 1;
  885. return CMD_SUCCESS;
  886. }
  887. DEFUN (no_ipv6_nd_homeagent_config_flag,
  888. no_ipv6_nd_homeagent_config_flag_cmd,
  889. "no ipv6 nd home-agent-config-flag",
  890. NO_STR
  891. "Interface IPv6 config commands\n"
  892. "Neighbor discovery\n"
  893. "Home Agent configuration flag\n")
  894. {
  895. struct interface *ifp;
  896. struct zebra_if *zif;
  897. ifp = (struct interface *) vty->index;
  898. zif = ifp->info;
  899. zif->rtadv.AdvHomeAgentFlag = 0;
  900. return CMD_SUCCESS;
  901. }
  902. DEFUN (ipv6_nd_adv_interval_config_option,
  903. ipv6_nd_adv_interval_config_option_cmd,
  904. "ipv6 nd adv-interval-option",
  905. "Interface IPv6 config commands\n"
  906. "Neighbor discovery\n"
  907. "Advertisement Interval Option\n")
  908. {
  909. struct interface *ifp;
  910. struct zebra_if *zif;
  911. ifp = (struct interface *) vty->index;
  912. zif = ifp->info;
  913. zif->rtadv.AdvIntervalOption = 1;
  914. return CMD_SUCCESS;
  915. }
  916. DEFUN (no_ipv6_nd_adv_interval_config_option,
  917. no_ipv6_nd_adv_interval_config_option_cmd,
  918. "no ipv6 nd adv-interval-option",
  919. NO_STR
  920. "Interface IPv6 config commands\n"
  921. "Neighbor discovery\n"
  922. "Advertisement Interval Option\n")
  923. {
  924. struct interface *ifp;
  925. struct zebra_if *zif;
  926. ifp = (struct interface *) vty->index;
  927. zif = ifp->info;
  928. zif->rtadv.AdvIntervalOption = 0;
  929. return CMD_SUCCESS;
  930. }
  931. DEFUN (ipv6_nd_other_config_flag,
  932. ipv6_nd_other_config_flag_cmd,
  933. "ipv6 nd other-config-flag",
  934. "Interface IPv6 config commands\n"
  935. "Neighbor discovery\n"
  936. "Other statefull configuration flag\n")
  937. {
  938. struct interface *ifp;
  939. struct zebra_if *zif;
  940. ifp = (struct interface *) vty->index;
  941. zif = ifp->info;
  942. zif->rtadv.AdvOtherConfigFlag = 1;
  943. return CMD_SUCCESS;
  944. }
  945. DEFUN (no_ipv6_nd_other_config_flag,
  946. no_ipv6_nd_other_config_flag_cmd,
  947. "no ipv6 nd other-config-flag",
  948. NO_STR
  949. "Interface IPv6 config commands\n"
  950. "Neighbor discovery\n"
  951. "Other statefull configuration flag\n")
  952. {
  953. struct interface *ifp;
  954. struct zebra_if *zif;
  955. ifp = (struct interface *) vty->index;
  956. zif = ifp->info;
  957. zif->rtadv.AdvOtherConfigFlag = 0;
  958. return CMD_SUCCESS;
  959. }
  960. DEFUN (ipv6_nd_prefix,
  961. ipv6_nd_prefix_cmd,
  962. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  963. "(<0-4294967295>|infinite) (off-link|) (no-autoconfig|) (router-address|)",
  964. "Interface IPv6 config commands\n"
  965. "Neighbor discovery\n"
  966. "Prefix information\n"
  967. "IPv6 prefix\n"
  968. "Valid lifetime in seconds\n"
  969. "Infinite valid lifetime\n"
  970. "Preferred lifetime in seconds\n"
  971. "Infinite preferred lifetime\n"
  972. "Do not use prefix for onlink determination\n"
  973. "Do not use prefix for autoconfiguration\n"
  974. "Set Router Address flag\n")
  975. {
  976. int i;
  977. int ret;
  978. int cursor = 1;
  979. struct interface *ifp;
  980. struct zebra_if *zebra_if;
  981. struct rtadv_prefix rp;
  982. ifp = (struct interface *) vty->index;
  983. zebra_if = ifp->info;
  984. ret = str2prefix_ipv6 (argv[0], &rp.prefix);
  985. if (!ret)
  986. {
  987. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  988. return CMD_WARNING;
  989. }
  990. apply_mask_ipv6 (&rp.prefix); /* RFC4861 4.6.2 */
  991. rp.AdvOnLinkFlag = 1;
  992. rp.AdvAutonomousFlag = 1;
  993. rp.AdvRouterAddressFlag = 0;
  994. rp.AdvValidLifetime = RTADV_VALID_LIFETIME;
  995. rp.AdvPreferredLifetime = RTADV_PREFERRED_LIFETIME;
  996. if (argc > 1)
  997. {
  998. if ((isdigit(argv[1][0])) || strncmp (argv[1], "i", 1) == 0)
  999. {
  1000. if ( strncmp (argv[1], "i", 1) == 0)
  1001. rp.AdvValidLifetime = UINT32_MAX;
  1002. else
  1003. rp.AdvValidLifetime = (u_int32_t) strtoll (argv[1],
  1004. (char **)NULL, 10);
  1005. if ( strncmp (argv[2], "i", 1) == 0)
  1006. rp.AdvPreferredLifetime = UINT32_MAX;
  1007. else
  1008. rp.AdvPreferredLifetime = (u_int32_t) strtoll (argv[2],
  1009. (char **)NULL, 10);
  1010. if (rp.AdvPreferredLifetime > rp.AdvValidLifetime)
  1011. {
  1012. vty_out (vty, "Invalid preferred lifetime%s", VTY_NEWLINE);
  1013. return CMD_WARNING;
  1014. }
  1015. cursor = cursor + 2;
  1016. }
  1017. if (argc > cursor)
  1018. {
  1019. for (i = cursor; i < argc; i++)
  1020. {
  1021. if (strncmp (argv[i], "of", 2) == 0)
  1022. rp.AdvOnLinkFlag = 0;
  1023. if (strncmp (argv[i], "no", 2) == 0)
  1024. rp.AdvAutonomousFlag = 0;
  1025. if (strncmp (argv[i], "ro", 2) == 0)
  1026. rp.AdvRouterAddressFlag = 1;
  1027. }
  1028. }
  1029. }
  1030. rtadv_prefix_set (zebra_if, &rp);
  1031. return CMD_SUCCESS;
  1032. }
  1033. ALIAS (ipv6_nd_prefix,
  1034. ipv6_nd_prefix_val_nortaddr_cmd,
  1035. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1036. "(<0-4294967295>|infinite) (off-link|) (no-autoconfig|)",
  1037. "Interface IPv6 config commands\n"
  1038. "Neighbor discovery\n"
  1039. "Prefix information\n"
  1040. "IPv6 prefix\n"
  1041. "Valid lifetime in seconds\n"
  1042. "Infinite valid lifetime\n"
  1043. "Preferred lifetime in seconds\n"
  1044. "Infinite preferred lifetime\n"
  1045. "Do not use prefix for onlink determination\n"
  1046. "Do not use prefix for autoconfiguration\n")
  1047. ALIAS (ipv6_nd_prefix,
  1048. ipv6_nd_prefix_val_rev_cmd,
  1049. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1050. "(<0-4294967295>|infinite) (no-autoconfig|) (off-link|)",
  1051. "Interface IPv6 config commands\n"
  1052. "Neighbor discovery\n"
  1053. "Prefix information\n"
  1054. "IPv6 prefix\n"
  1055. "Valid lifetime in seconds\n"
  1056. "Infinite valid lifetime\n"
  1057. "Preferred lifetime in seconds\n"
  1058. "Infinite preferred lifetime\n"
  1059. "Do not use prefix for autoconfiguration\n"
  1060. "Do not use prefix for onlink determination\n")
  1061. ALIAS (ipv6_nd_prefix,
  1062. ipv6_nd_prefix_val_rev_rtaddr_cmd,
  1063. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1064. "(<0-4294967295>|infinite) (no-autoconfig|) (off-link|) (router-address|)",
  1065. "Interface IPv6 config commands\n"
  1066. "Neighbor discovery\n"
  1067. "Prefix information\n"
  1068. "IPv6 prefix\n"
  1069. "Valid lifetime in seconds\n"
  1070. "Infinite valid lifetime\n"
  1071. "Preferred lifetime in seconds\n"
  1072. "Infinite preferred lifetime\n"
  1073. "Do not use prefix for autoconfiguration\n"
  1074. "Do not use prefix for onlink determination\n"
  1075. "Set Router Address flag\n")
  1076. ALIAS (ipv6_nd_prefix,
  1077. ipv6_nd_prefix_val_noauto_cmd,
  1078. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1079. "(<0-4294967295>|infinite) (no-autoconfig|)",
  1080. "Interface IPv6 config commands\n"
  1081. "Neighbor discovery\n"
  1082. "Prefix information\n"
  1083. "IPv6 prefix\n"
  1084. "Valid lifetime in seconds\n"
  1085. "Infinite valid lifetime\n"
  1086. "Preferred lifetime in seconds\n"
  1087. "Infinite preferred lifetime\n"
  1088. "Do not use prefix for autoconfiguration")
  1089. ALIAS (ipv6_nd_prefix,
  1090. ipv6_nd_prefix_val_offlink_cmd,
  1091. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1092. "(<0-4294967295>|infinite) (off-link|)",
  1093. "Interface IPv6 config commands\n"
  1094. "Neighbor discovery\n"
  1095. "Prefix information\n"
  1096. "IPv6 prefix\n"
  1097. "Valid lifetime in seconds\n"
  1098. "Infinite valid lifetime\n"
  1099. "Preferred lifetime in seconds\n"
  1100. "Infinite preferred lifetime\n"
  1101. "Do not use prefix for onlink determination\n")
  1102. ALIAS (ipv6_nd_prefix,
  1103. ipv6_nd_prefix_val_rtaddr_cmd,
  1104. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1105. "(<0-4294967295>|infinite) (router-address|)",
  1106. "Interface IPv6 config commands\n"
  1107. "Neighbor discovery\n"
  1108. "Prefix information\n"
  1109. "IPv6 prefix\n"
  1110. "Valid lifetime in seconds\n"
  1111. "Infinite valid lifetime\n"
  1112. "Preferred lifetime in seconds\n"
  1113. "Infinite preferred lifetime\n"
  1114. "Set Router Address flag\n")
  1115. ALIAS (ipv6_nd_prefix,
  1116. ipv6_nd_prefix_val_cmd,
  1117. "ipv6 nd prefix X:X::X:X/M (<0-4294967295>|infinite) "
  1118. "(<0-4294967295>|infinite)",
  1119. "Interface IPv6 config commands\n"
  1120. "Neighbor discovery\n"
  1121. "Prefix information\n"
  1122. "IPv6 prefix\n"
  1123. "Valid lifetime in seconds\n"
  1124. "Infinite valid lifetime\n"
  1125. "Preferred lifetime in seconds\n"
  1126. "Infinite preferred lifetime\n")
  1127. ALIAS (ipv6_nd_prefix,
  1128. ipv6_nd_prefix_noval_cmd,
  1129. "ipv6 nd prefix X:X::X:X/M (no-autoconfig|) (off-link|)",
  1130. "Interface IPv6 config commands\n"
  1131. "Neighbor discovery\n"
  1132. "Prefix information\n"
  1133. "IPv6 prefix\n"
  1134. "Do not use prefix for autoconfiguration\n"
  1135. "Do not use prefix for onlink determination\n")
  1136. ALIAS (ipv6_nd_prefix,
  1137. ipv6_nd_prefix_noval_rev_cmd,
  1138. "ipv6 nd prefix X:X::X:X/M (off-link|) (no-autoconfig|)",
  1139. "Interface IPv6 config commands\n"
  1140. "Neighbor discovery\n"
  1141. "Prefix information\n"
  1142. "IPv6 prefix\n"
  1143. "Do not use prefix for onlink determination\n"
  1144. "Do not use prefix for autoconfiguration\n")
  1145. ALIAS (ipv6_nd_prefix,
  1146. ipv6_nd_prefix_noval_noauto_cmd,
  1147. "ipv6 nd prefix X:X::X:X/M (no-autoconfig|)",
  1148. "Interface IPv6 config commands\n"
  1149. "Neighbor discovery\n"
  1150. "Prefix information\n"
  1151. "IPv6 prefix\n"
  1152. "Do not use prefix for autoconfiguration\n")
  1153. ALIAS (ipv6_nd_prefix,
  1154. ipv6_nd_prefix_noval_offlink_cmd,
  1155. "ipv6 nd prefix X:X::X:X/M (off-link|)",
  1156. "Interface IPv6 config commands\n"
  1157. "Neighbor discovery\n"
  1158. "Prefix information\n"
  1159. "IPv6 prefix\n"
  1160. "Do not use prefix for onlink determination\n")
  1161. ALIAS (ipv6_nd_prefix,
  1162. ipv6_nd_prefix_noval_rtaddr_cmd,
  1163. "ipv6 nd prefix X:X::X:X/M (router-address|)",
  1164. "Interface IPv6 config commands\n"
  1165. "Neighbor discovery\n"
  1166. "Prefix information\n"
  1167. "IPv6 prefix\n"
  1168. "Set Router Address flag\n")
  1169. ALIAS (ipv6_nd_prefix,
  1170. ipv6_nd_prefix_prefix_cmd,
  1171. "ipv6 nd prefix X:X::X:X/M",
  1172. "Interface IPv6 config commands\n"
  1173. "Neighbor discovery\n"
  1174. "Prefix information\n"
  1175. "IPv6 prefix\n")
  1176. DEFUN (no_ipv6_nd_prefix,
  1177. no_ipv6_nd_prefix_cmd,
  1178. "no ipv6 nd prefix IPV6PREFIX",
  1179. NO_STR
  1180. "Interface IPv6 config commands\n"
  1181. "Neighbor discovery\n"
  1182. "Prefix information\n"
  1183. "IPv6 prefix\n")
  1184. {
  1185. int ret;
  1186. struct interface *ifp;
  1187. struct zebra_if *zebra_if;
  1188. struct rtadv_prefix rp;
  1189. ifp = (struct interface *) vty->index;
  1190. zebra_if = ifp->info;
  1191. ret = str2prefix_ipv6 (argv[0], &rp.prefix);
  1192. if (!ret)
  1193. {
  1194. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  1195. return CMD_WARNING;
  1196. }
  1197. apply_mask_ipv6 (&rp.prefix); /* RFC4861 4.6.2 */
  1198. ret = rtadv_prefix_reset (zebra_if, &rp);
  1199. if (!ret)
  1200. {
  1201. vty_out (vty, "Non-exist IPv6 prefix%s", VTY_NEWLINE);
  1202. return CMD_WARNING;
  1203. }
  1204. return CMD_SUCCESS;
  1205. }
  1206. DEFUN (ipv6_nd_router_preference,
  1207. ipv6_nd_router_preference_cmd,
  1208. "ipv6 nd router-preference (high|medium|low)",
  1209. "Interface IPv6 config commands\n"
  1210. "Neighbor discovery\n"
  1211. "Default router preference\n"
  1212. "High default router preference\n"
  1213. "Low default router preference\n"
  1214. "Medium default router preference (default)\n")
  1215. {
  1216. struct interface *ifp;
  1217. struct zebra_if *zif;
  1218. int i = 0;
  1219. ifp = (struct interface *) vty->index;
  1220. zif = ifp->info;
  1221. while (0 != rtadv_pref_strs[i])
  1222. {
  1223. if (strncmp (argv[0], rtadv_pref_strs[i], 1) == 0)
  1224. {
  1225. zif->rtadv.DefaultPreference = i;
  1226. return CMD_SUCCESS;
  1227. }
  1228. i++;
  1229. }
  1230. return CMD_ERR_NO_MATCH;
  1231. }
  1232. DEFUN (no_ipv6_nd_router_preference,
  1233. no_ipv6_nd_router_preference_cmd,
  1234. "no ipv6 nd router-preference",
  1235. NO_STR
  1236. "Interface IPv6 config commands\n"
  1237. "Neighbor discovery\n"
  1238. "Default router preference\n")
  1239. {
  1240. struct interface *ifp;
  1241. struct zebra_if *zif;
  1242. ifp = (struct interface *) vty->index;
  1243. zif = ifp->info;
  1244. zif->rtadv.DefaultPreference = RTADV_PREF_MEDIUM; /* Default per RFC4191. */
  1245. return CMD_SUCCESS;
  1246. }
  1247. ALIAS (no_ipv6_nd_router_preference,
  1248. no_ipv6_nd_router_preference_val_cmd,
  1249. "no ipv6 nd router-preference (high|medium|low",
  1250. NO_STR
  1251. "Interface IPv6 config commands\n"
  1252. "Neighbor discovery\n"
  1253. "Default router preference\n"
  1254. "High default router preference\n"
  1255. "Low default router preference\n"
  1256. "Medium default router preference (default)\n")
  1257. DEFUN (ipv6_nd_mtu,
  1258. ipv6_nd_mtu_cmd,
  1259. "ipv6 nd mtu <1-65535>",
  1260. "Interface IPv6 config commands\n"
  1261. "Neighbor discovery\n"
  1262. "Advertised MTU\n"
  1263. "MTU in bytes\n")
  1264. {
  1265. struct interface *ifp = (struct interface *) vty->index;
  1266. struct zebra_if *zif = ifp->info;
  1267. VTY_GET_INTEGER_RANGE ("MTU", zif->rtadv.AdvLinkMTU, argv[0], 1, 65535);
  1268. return CMD_SUCCESS;
  1269. }
  1270. DEFUN (no_ipv6_nd_mtu,
  1271. no_ipv6_nd_mtu_cmd,
  1272. "no ipv6 nd mtu",
  1273. NO_STR
  1274. "Interface IPv6 config commands\n"
  1275. "Neighbor discovery\n"
  1276. "Advertised MTU\n")
  1277. {
  1278. struct interface *ifp = (struct interface *) vty->index;
  1279. struct zebra_if *zif = ifp->info;
  1280. zif->rtadv.AdvLinkMTU = 0;
  1281. return CMD_SUCCESS;
  1282. }
  1283. ALIAS (no_ipv6_nd_mtu,
  1284. no_ipv6_nd_mtu_val_cmd,
  1285. "no ipv6 nd mtu <1-65535>",
  1286. NO_STR
  1287. "Interface IPv6 config commands\n"
  1288. "Neighbor discovery\n"
  1289. "Advertised MTU\n"
  1290. "MTU in bytes\n")
  1291. /* Write configuration about router advertisement. */
  1292. void
  1293. rtadv_config_write (struct vty *vty, struct interface *ifp)
  1294. {
  1295. struct zebra_if *zif;
  1296. struct listnode *node;
  1297. struct rtadv_prefix *rprefix;
  1298. u_char buf[INET6_ADDRSTRLEN];
  1299. int interval;
  1300. if (! rtadv)
  1301. return;
  1302. zif = ifp->info;
  1303. if (! if_is_loopback (ifp))
  1304. {
  1305. if (zif->rtadv.AdvSendAdvertisements)
  1306. vty_out (vty, " no ipv6 nd suppress-ra%s", VTY_NEWLINE);
  1307. else
  1308. vty_out (vty, " ipv6 nd suppress-ra%s", VTY_NEWLINE);
  1309. }
  1310. interval = zif->rtadv.MaxRtrAdvInterval;
  1311. if (interval % 1000)
  1312. vty_out (vty, " ipv6 nd ra-interval msec %d%s", interval,
  1313. VTY_NEWLINE);
  1314. else
  1315. if (interval != RTADV_MAX_RTR_ADV_INTERVAL)
  1316. vty_out (vty, " ipv6 nd ra-interval %d%s", interval / 1000,
  1317. VTY_NEWLINE);
  1318. if (zif->rtadv.AdvIntervalOption)
  1319. vty_out (vty, " ipv6 nd adv-interval-option%s", VTY_NEWLINE);
  1320. if (zif->rtadv.AdvDefaultLifetime != -1)
  1321. vty_out (vty, " ipv6 nd ra-lifetime %d%s", zif->rtadv.AdvDefaultLifetime,
  1322. VTY_NEWLINE);
  1323. if (zif->rtadv.HomeAgentPreference)
  1324. vty_out (vty, " ipv6 nd home-agent-preference %u%s",
  1325. zif->rtadv.HomeAgentPreference, VTY_NEWLINE);
  1326. if (zif->rtadv.HomeAgentLifetime != -1)
  1327. vty_out (vty, " ipv6 nd home-agent-lifetime %u%s",
  1328. zif->rtadv.HomeAgentLifetime, VTY_NEWLINE);
  1329. if (zif->rtadv.AdvHomeAgentFlag)
  1330. vty_out (vty, " ipv6 nd home-agent-config-flag%s", VTY_NEWLINE);
  1331. if (zif->rtadv.AdvReachableTime)
  1332. vty_out (vty, " ipv6 nd reachable-time %d%s", zif->rtadv.AdvReachableTime,
  1333. VTY_NEWLINE);
  1334. if (zif->rtadv.AdvManagedFlag)
  1335. vty_out (vty, " ipv6 nd managed-config-flag%s", VTY_NEWLINE);
  1336. if (zif->rtadv.AdvOtherConfigFlag)
  1337. vty_out (vty, " ipv6 nd other-config-flag%s", VTY_NEWLINE);
  1338. if (zif->rtadv.DefaultPreference != RTADV_PREF_MEDIUM)
  1339. vty_out (vty, " ipv6 nd router-preference %s%s",
  1340. rtadv_pref_strs[zif->rtadv.DefaultPreference],
  1341. VTY_NEWLINE);
  1342. if (zif->rtadv.AdvLinkMTU)
  1343. vty_out (vty, " ipv6 nd mtu %d%s", zif->rtadv.AdvLinkMTU, VTY_NEWLINE);
  1344. for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix))
  1345. {
  1346. vty_out (vty, " ipv6 nd prefix %s/%d",
  1347. inet_ntop (AF_INET6, &rprefix->prefix.prefix,
  1348. (char *) buf, INET6_ADDRSTRLEN),
  1349. rprefix->prefix.prefixlen);
  1350. if ((rprefix->AdvValidLifetime != RTADV_VALID_LIFETIME) ||
  1351. (rprefix->AdvPreferredLifetime != RTADV_PREFERRED_LIFETIME))
  1352. {
  1353. if (rprefix->AdvValidLifetime == UINT32_MAX)
  1354. vty_out (vty, " infinite");
  1355. else
  1356. vty_out (vty, " %u", rprefix->AdvValidLifetime);
  1357. if (rprefix->AdvPreferredLifetime == UINT32_MAX)
  1358. vty_out (vty, " infinite");
  1359. else
  1360. vty_out (vty, " %u", rprefix->AdvPreferredLifetime);
  1361. }
  1362. if (!rprefix->AdvOnLinkFlag)
  1363. vty_out (vty, " off-link");
  1364. if (!rprefix->AdvAutonomousFlag)
  1365. vty_out (vty, " no-autoconfig");
  1366. if (rprefix->AdvRouterAddressFlag)
  1367. vty_out (vty, " router-address");
  1368. vty_out (vty, "%s", VTY_NEWLINE);
  1369. }
  1370. }
  1371. static void
  1372. rtadv_event (enum rtadv_event event, int val)
  1373. {
  1374. switch (event)
  1375. {
  1376. case RTADV_START:
  1377. if (! rtadv->ra_read)
  1378. rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val);
  1379. if (! rtadv->ra_timer)
  1380. rtadv->ra_timer = thread_add_event (zebrad.master, rtadv_timer,
  1381. NULL, 0);
  1382. break;
  1383. case RTADV_STOP:
  1384. if (rtadv->ra_timer)
  1385. {
  1386. thread_cancel (rtadv->ra_timer);
  1387. rtadv->ra_timer = NULL;
  1388. }
  1389. if (rtadv->ra_read)
  1390. {
  1391. thread_cancel (rtadv->ra_read);
  1392. rtadv->ra_read = NULL;
  1393. }
  1394. break;
  1395. case RTADV_TIMER:
  1396. if (! rtadv->ra_timer)
  1397. rtadv->ra_timer = thread_add_timer (zebrad.master, rtadv_timer, NULL,
  1398. val);
  1399. break;
  1400. case RTADV_TIMER_MSEC:
  1401. if (! rtadv->ra_timer)
  1402. rtadv->ra_timer = thread_add_timer_msec (zebrad.master, rtadv_timer,
  1403. NULL, val);
  1404. break;
  1405. case RTADV_READ:
  1406. if (! rtadv->ra_read)
  1407. rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val);
  1408. break;
  1409. default:
  1410. break;
  1411. }
  1412. return;
  1413. }
  1414. void
  1415. rtadv_init (void)
  1416. {
  1417. int sock;
  1418. sock = rtadv_make_socket ();
  1419. if (sock < 0)
  1420. return;
  1421. rtadv = rtadv_new ();
  1422. rtadv->sock = sock;
  1423. install_element (INTERFACE_NODE, &ipv6_nd_suppress_ra_cmd);
  1424. install_element (INTERFACE_NODE, &no_ipv6_nd_suppress_ra_cmd);
  1425. install_element (INTERFACE_NODE, &ipv6_nd_ra_interval_cmd);
  1426. install_element (INTERFACE_NODE, &ipv6_nd_ra_interval_msec_cmd);
  1427. install_element (INTERFACE_NODE, &no_ipv6_nd_ra_interval_cmd);
  1428. install_element (INTERFACE_NODE, &no_ipv6_nd_ra_interval_val_cmd);
  1429. install_element (INTERFACE_NODE, &no_ipv6_nd_ra_interval_msec_val_cmd);
  1430. install_element (INTERFACE_NODE, &ipv6_nd_ra_lifetime_cmd);
  1431. install_element (INTERFACE_NODE, &no_ipv6_nd_ra_lifetime_cmd);
  1432. install_element (INTERFACE_NODE, &no_ipv6_nd_ra_lifetime_val_cmd);
  1433. install_element (INTERFACE_NODE, &ipv6_nd_reachable_time_cmd);
  1434. install_element (INTERFACE_NODE, &no_ipv6_nd_reachable_time_cmd);
  1435. install_element (INTERFACE_NODE, &no_ipv6_nd_reachable_time_val_cmd);
  1436. install_element (INTERFACE_NODE, &ipv6_nd_managed_config_flag_cmd);
  1437. install_element (INTERFACE_NODE, &no_ipv6_nd_managed_config_flag_cmd);
  1438. install_element (INTERFACE_NODE, &ipv6_nd_other_config_flag_cmd);
  1439. install_element (INTERFACE_NODE, &no_ipv6_nd_other_config_flag_cmd);
  1440. install_element (INTERFACE_NODE, &ipv6_nd_homeagent_config_flag_cmd);
  1441. install_element (INTERFACE_NODE, &no_ipv6_nd_homeagent_config_flag_cmd);
  1442. install_element (INTERFACE_NODE, &ipv6_nd_homeagent_preference_cmd);
  1443. install_element (INTERFACE_NODE, &no_ipv6_nd_homeagent_preference_cmd);
  1444. install_element (INTERFACE_NODE, &no_ipv6_nd_homeagent_preference_val_cmd);
  1445. install_element (INTERFACE_NODE, &ipv6_nd_homeagent_lifetime_cmd);
  1446. install_element (INTERFACE_NODE, &no_ipv6_nd_homeagent_lifetime_cmd);
  1447. install_element (INTERFACE_NODE, &no_ipv6_nd_homeagent_lifetime_val_cmd);
  1448. install_element (INTERFACE_NODE, &ipv6_nd_adv_interval_config_option_cmd);
  1449. install_element (INTERFACE_NODE, &no_ipv6_nd_adv_interval_config_option_cmd);
  1450. install_element (INTERFACE_NODE, &ipv6_nd_prefix_cmd);
  1451. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_rev_rtaddr_cmd);
  1452. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_nortaddr_cmd);
  1453. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_rev_cmd);
  1454. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_noauto_cmd);
  1455. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_offlink_cmd);
  1456. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_rtaddr_cmd);
  1457. install_element (INTERFACE_NODE, &ipv6_nd_prefix_val_cmd);
  1458. install_element (INTERFACE_NODE, &ipv6_nd_prefix_noval_cmd);
  1459. install_element (INTERFACE_NODE, &ipv6_nd_prefix_noval_rev_cmd);
  1460. install_element (INTERFACE_NODE, &ipv6_nd_prefix_noval_noauto_cmd);
  1461. install_element (INTERFACE_NODE, &ipv6_nd_prefix_noval_offlink_cmd);
  1462. install_element (INTERFACE_NODE, &ipv6_nd_prefix_noval_rtaddr_cmd);
  1463. install_element (INTERFACE_NODE, &ipv6_nd_prefix_prefix_cmd);
  1464. install_element (INTERFACE_NODE, &no_ipv6_nd_prefix_cmd);
  1465. install_element (INTERFACE_NODE, &ipv6_nd_router_preference_cmd);
  1466. install_element (INTERFACE_NODE, &no_ipv6_nd_router_preference_cmd);
  1467. install_element (INTERFACE_NODE, &no_ipv6_nd_router_preference_val_cmd);
  1468. install_element (INTERFACE_NODE, &ipv6_nd_mtu_cmd);
  1469. install_element (INTERFACE_NODE, &no_ipv6_nd_mtu_cmd);
  1470. install_element (INTERFACE_NODE, &no_ipv6_nd_mtu_val_cmd);
  1471. }
  1472. static int
  1473. if_join_all_router (int sock, struct interface *ifp)
  1474. {
  1475. int ret;
  1476. struct ipv6_mreq mreq;
  1477. memset (&mreq, 0, sizeof (struct ipv6_mreq));
  1478. inet_pton (AF_INET6, ALLROUTER, &mreq.ipv6mr_multiaddr);
  1479. mreq.ipv6mr_interface = ifp->ifindex;
  1480. ret = setsockopt (sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
  1481. (char *) &mreq, sizeof mreq);
  1482. if (ret < 0)
  1483. zlog_warn ("can't setsockopt IPV6_JOIN_GROUP: %s", safe_strerror (errno));
  1484. zlog_info ("rtadv: %s join to all-routers multicast group", ifp->name);
  1485. return 0;
  1486. }
  1487. static int
  1488. if_leave_all_router (int sock, struct interface *ifp)
  1489. {
  1490. int ret;
  1491. struct ipv6_mreq mreq;
  1492. memset (&mreq, 0, sizeof (struct ipv6_mreq));
  1493. inet_pton (AF_INET6, ALLROUTER, &mreq.ipv6mr_multiaddr);
  1494. mreq.ipv6mr_interface = ifp->ifindex;
  1495. ret = setsockopt (sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
  1496. (char *) &mreq, sizeof mreq);
  1497. if (ret < 0)
  1498. zlog_warn ("can't setsockopt IPV6_LEAVE_GROUP: %s", safe_strerror (errno));
  1499. zlog_info ("rtadv: %s leave from all-routers multicast group", ifp->name);
  1500. return 0;
  1501. }
  1502. #else
  1503. void
  1504. rtadv_init (void)
  1505. {
  1506. /* Empty.*/;
  1507. }
  1508. #endif /* RTADV && HAVE_IPV6 */