paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Router advertisement |
| 2 | * Copyright (C) 1999 Kunihiro Ishiguro |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify 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 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include "memory.h" |
| 25 | #include "sockopt.h" |
| 26 | #include "thread.h" |
| 27 | #include "if.h" |
| 28 | #include "log.h" |
| 29 | #include "prefix.h" |
| 30 | #include "linklist.h" |
| 31 | #include "command.h" |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 32 | #include "privs.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | #include "zebra/interface.h" |
| 35 | #include "zebra/rtadv.h" |
| 36 | #include "zebra/debug.h" |
paul | 537d8ea | 2003-08-27 06:45:32 +0000 | [diff] [blame] | 37 | #include "zebra/rib.h" |
gdt | 4b5e135 | 2003-12-03 17:54:34 +0000 | [diff] [blame] | 38 | #include "zebra/zserv.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 39 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 40 | extern struct zebra_privs_t zserv_privs; |
| 41 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 42 | #if defined (HAVE_IPV6) && defined (RTADV) |
| 43 | |
| 44 | /* If RFC2133 definition is used. */ |
| 45 | #ifndef IPV6_JOIN_GROUP |
| 46 | #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP |
| 47 | #endif |
| 48 | #ifndef IPV6_LEAVE_GROUP |
| 49 | #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP |
| 50 | #endif |
| 51 | |
| 52 | #define ALLNODE "ff02::1" |
| 53 | #define ALLROUTER "ff02::2" |
| 54 | |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 55 | extern struct zebra_t zebrad; |
| 56 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | enum rtadv_event {RTADV_START, RTADV_STOP, RTADV_TIMER, RTADV_READ}; |
| 58 | |
| 59 | void rtadv_event (enum rtadv_event, int); |
| 60 | |
| 61 | int if_join_all_router (int, struct interface *); |
| 62 | int if_leave_all_router (int, struct interface *); |
| 63 | |
| 64 | /* Structure which hold status of router advertisement. */ |
| 65 | struct rtadv |
| 66 | { |
| 67 | int sock; |
| 68 | |
| 69 | int adv_if_count; |
| 70 | |
| 71 | struct thread *ra_read; |
| 72 | struct thread *ra_timer; |
| 73 | }; |
| 74 | |
| 75 | struct rtadv *rtadv = NULL; |
| 76 | |
| 77 | struct rtadv * |
| 78 | rtadv_new () |
| 79 | { |
| 80 | struct rtadv *new; |
| 81 | new = XMALLOC (MTYPE_TMP, sizeof (struct rtadv)); |
| 82 | memset (new, 0, sizeof (struct rtadv)); |
| 83 | return new; |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | rtadv_free (struct rtadv *rtadv) |
| 88 | { |
| 89 | XFREE (MTYPE_TMP, rtadv); |
| 90 | } |
| 91 | |
| 92 | int |
| 93 | rtadv_recv_packet (int sock, u_char *buf, int buflen, |
| 94 | struct sockaddr_in6 *from, unsigned int *ifindex, |
| 95 | int *hoplimit) |
| 96 | { |
| 97 | int ret; |
| 98 | struct msghdr msg; |
| 99 | struct iovec iov; |
| 100 | struct cmsghdr *cmsgptr; |
| 101 | struct in6_addr dst; |
| 102 | |
| 103 | char adata[1024]; |
| 104 | |
| 105 | /* Fill in message and iovec. */ |
| 106 | msg.msg_name = (void *) from; |
| 107 | msg.msg_namelen = sizeof (struct sockaddr_in6); |
| 108 | msg.msg_iov = &iov; |
| 109 | msg.msg_iovlen = 1; |
| 110 | msg.msg_control = (void *) adata; |
| 111 | msg.msg_controllen = sizeof adata; |
| 112 | iov.iov_base = buf; |
| 113 | iov.iov_len = buflen; |
| 114 | |
| 115 | /* If recvmsg fail return minus value. */ |
| 116 | ret = recvmsg (sock, &msg, 0); |
| 117 | if (ret < 0) |
| 118 | return ret; |
| 119 | |
| 120 | for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; |
| 121 | cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) |
| 122 | { |
| 123 | /* I want interface index which this packet comes from. */ |
| 124 | if (cmsgptr->cmsg_level == IPPROTO_IPV6 && |
| 125 | cmsgptr->cmsg_type == IPV6_PKTINFO) |
| 126 | { |
| 127 | struct in6_pktinfo *ptr; |
| 128 | |
| 129 | ptr = (struct in6_pktinfo *) CMSG_DATA (cmsgptr); |
| 130 | *ifindex = ptr->ipi6_ifindex; |
| 131 | memcpy(&dst, &ptr->ipi6_addr, sizeof(ptr->ipi6_addr)); |
| 132 | } |
| 133 | |
| 134 | /* Incoming packet's hop limit. */ |
| 135 | if (cmsgptr->cmsg_level == IPPROTO_IPV6 && |
| 136 | cmsgptr->cmsg_type == IPV6_HOPLIMIT) |
| 137 | *hoplimit = *((int *) CMSG_DATA (cmsgptr)); |
| 138 | } |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | #define RTADV_MSG_SIZE 4096 |
| 143 | |
| 144 | /* Send router advertisement packet. */ |
| 145 | void |
| 146 | rtadv_send_packet (int sock, struct interface *ifp) |
| 147 | { |
| 148 | struct msghdr msg; |
| 149 | struct iovec iov; |
| 150 | struct cmsghdr *cmsgptr; |
| 151 | struct in6_pktinfo *pkt; |
| 152 | struct sockaddr_in6 addr; |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 153 | #ifdef HAVE_SOCKADDR_DL |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | struct sockaddr_dl *sdl; |
| 155 | #endif /* HAVE_SOCKADDR_DL */ |
| 156 | char adata [sizeof (struct cmsghdr) + sizeof (struct in6_pktinfo)]; |
| 157 | unsigned char buf[RTADV_MSG_SIZE]; |
| 158 | struct nd_router_advert *rtadv; |
| 159 | int ret; |
| 160 | int len = 0; |
| 161 | struct zebra_if *zif; |
| 162 | u_char all_nodes_addr[] = {0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; |
| 163 | listnode node; |
| 164 | |
| 165 | /* Logging of packet. */ |
| 166 | if (IS_ZEBRA_DEBUG_PACKET) |
| 167 | zlog_info ("Router advertisement send to %s", ifp->name); |
| 168 | |
| 169 | /* Fill in sockaddr_in6. */ |
| 170 | memset (&addr, 0, sizeof (struct sockaddr_in6)); |
| 171 | addr.sin6_family = AF_INET6; |
| 172 | #ifdef SIN6_LEN |
| 173 | addr.sin6_len = sizeof (struct sockaddr_in6); |
| 174 | #endif /* SIN6_LEN */ |
| 175 | addr.sin6_port = htons (IPPROTO_ICMPV6); |
| 176 | memcpy (&addr.sin6_addr, all_nodes_addr, sizeof (struct in6_addr)); |
| 177 | |
| 178 | /* Fetch interface information. */ |
| 179 | zif = ifp->info; |
| 180 | |
| 181 | /* Make router advertisement message. */ |
| 182 | rtadv = (struct nd_router_advert *) buf; |
| 183 | |
| 184 | rtadv->nd_ra_type = ND_ROUTER_ADVERT; |
| 185 | rtadv->nd_ra_code = 0; |
| 186 | rtadv->nd_ra_cksum = 0; |
| 187 | |
| 188 | rtadv->nd_ra_curhoplimit = 64; |
| 189 | rtadv->nd_ra_flags_reserved = 0; |
| 190 | if (zif->rtadv.AdvManagedFlag) |
| 191 | rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_MANAGED; |
| 192 | if (zif->rtadv.AdvOtherConfigFlag) |
| 193 | rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_OTHER; |
| 194 | rtadv->nd_ra_router_lifetime = htons (zif->rtadv.AdvDefaultLifetime); |
| 195 | rtadv->nd_ra_reachable = htonl (zif->rtadv.AdvReachableTime); |
| 196 | rtadv->nd_ra_retransmit = htonl (0); |
| 197 | |
| 198 | len = sizeof (struct nd_router_advert); |
| 199 | |
| 200 | /* Fill in prefix. */ |
| 201 | for (node = listhead (zif->rtadv.AdvPrefixList); node; node = nextnode (node)) |
| 202 | { |
| 203 | struct nd_opt_prefix_info *pinfo; |
| 204 | struct rtadv_prefix *rprefix; |
| 205 | |
| 206 | rprefix = getdata (node); |
| 207 | |
| 208 | pinfo = (struct nd_opt_prefix_info *) (buf + len); |
| 209 | |
| 210 | pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION; |
| 211 | pinfo->nd_opt_pi_len = 4; |
| 212 | pinfo->nd_opt_pi_prefix_len = rprefix->prefix.prefixlen; |
| 213 | |
| 214 | pinfo->nd_opt_pi_flags_reserved = 0; |
| 215 | if (rprefix->AdvOnLinkFlag) |
| 216 | pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_ONLINK; |
| 217 | if (rprefix->AdvAutonomousFlag) |
| 218 | pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO; |
| 219 | |
| 220 | pinfo->nd_opt_pi_valid_time = htonl (rprefix->AdvValidLifetime); |
| 221 | pinfo->nd_opt_pi_preferred_time = htonl (rprefix->AdvPreferredLifetime); |
| 222 | pinfo->nd_opt_pi_reserved2 = 0; |
| 223 | |
| 224 | memcpy (&pinfo->nd_opt_pi_prefix, &rprefix->prefix.u.prefix6, |
| 225 | sizeof (struct in6_addr)); |
| 226 | |
| 227 | #ifdef DEBUG |
| 228 | { |
| 229 | u_char buf[INET6_ADDRSTRLEN]; |
| 230 | |
| 231 | zlog_info ("DEBUG %s", inet_ntop (AF_INET6, &pinfo->nd_opt_pi_prefix, buf, INET6_ADDRSTRLEN)); |
| 232 | |
| 233 | } |
| 234 | #endif /* DEBUG */ |
| 235 | |
| 236 | len += sizeof (struct nd_opt_prefix_info); |
| 237 | } |
| 238 | |
| 239 | /* Hardware address. */ |
| 240 | #ifdef HAVE_SOCKADDR_DL |
| 241 | sdl = &ifp->sdl; |
| 242 | if (sdl != NULL && sdl->sdl_alen != 0) |
| 243 | { |
| 244 | buf[len++] = ND_OPT_SOURCE_LINKADDR; |
| 245 | buf[len++] = (sdl->sdl_alen + 2) >> 3; |
| 246 | |
| 247 | memcpy (buf + len, LLADDR (sdl), sdl->sdl_alen); |
| 248 | len += sdl->sdl_alen; |
| 249 | } |
| 250 | #else |
| 251 | if (ifp->hw_addr_len != 0) |
| 252 | { |
| 253 | buf[len++] = ND_OPT_SOURCE_LINKADDR; |
| 254 | buf[len++] = (ifp->hw_addr_len + 2) >> 3; |
| 255 | |
| 256 | memcpy (buf + len, ifp->hw_addr, ifp->hw_addr_len); |
| 257 | len += ifp->hw_addr_len; |
| 258 | } |
| 259 | #endif /* HAVE_SOCKADDR_DL */ |
| 260 | |
| 261 | msg.msg_name = (void *) &addr; |
| 262 | msg.msg_namelen = sizeof (struct sockaddr_in6); |
| 263 | msg.msg_iov = &iov; |
| 264 | msg.msg_iovlen = 1; |
| 265 | msg.msg_control = (void *) adata; |
| 266 | msg.msg_controllen = sizeof adata; |
| 267 | iov.iov_base = buf; |
| 268 | iov.iov_len = len; |
| 269 | |
| 270 | cmsgptr = (struct cmsghdr *)adata; |
| 271 | cmsgptr->cmsg_len = sizeof adata; |
| 272 | cmsgptr->cmsg_level = IPPROTO_IPV6; |
| 273 | cmsgptr->cmsg_type = IPV6_PKTINFO; |
| 274 | pkt = (struct in6_pktinfo *) CMSG_DATA (cmsgptr); |
| 275 | memset (&pkt->ipi6_addr, 0, sizeof (struct in6_addr)); |
| 276 | pkt->ipi6_ifindex = ifp->ifindex; |
| 277 | |
| 278 | ret = sendmsg (sock, &msg, 0); |
gdt | 9ccabd1 | 2004-01-06 18:23:02 +0000 | [diff] [blame] | 279 | if (ret < 0) |
| 280 | { |
| 281 | zlog_err ("rtadv_send_packet: sendmsg %d (%s)\n", |
| 282 | errno, strerror(errno)); |
| 283 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int |
| 287 | rtadv_timer (struct thread *thread) |
| 288 | { |
| 289 | listnode node; |
| 290 | struct interface *ifp; |
| 291 | struct zebra_if *zif; |
| 292 | |
| 293 | rtadv->ra_timer = NULL; |
| 294 | rtadv_event (RTADV_TIMER, 1); |
| 295 | |
| 296 | for (node = listhead (iflist); node; nextnode (node)) |
| 297 | { |
| 298 | ifp = getdata (node); |
| 299 | |
| 300 | if (if_is_loopback (ifp)) |
| 301 | continue; |
| 302 | |
| 303 | zif = ifp->info; |
| 304 | |
| 305 | if (zif->rtadv.AdvSendAdvertisements) |
| 306 | if (--zif->rtadv.AdvIntervalTimer <= 0) |
| 307 | { |
| 308 | zif->rtadv.AdvIntervalTimer = zif->rtadv.MaxRtrAdvInterval; |
| 309 | rtadv_send_packet (rtadv->sock, ifp); |
| 310 | } |
| 311 | } |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | void |
| 316 | rtadv_process_solicit (struct interface *ifp) |
| 317 | { |
| 318 | zlog_info ("Router solicitation received on %s", ifp->name); |
| 319 | |
| 320 | rtadv_send_packet (rtadv->sock, ifp); |
| 321 | } |
| 322 | |
| 323 | void |
| 324 | rtadv_process_advert () |
| 325 | { |
| 326 | zlog_info ("Router advertisement received"); |
| 327 | } |
| 328 | |
| 329 | void |
| 330 | rtadv_process_packet (u_char *buf, int len, unsigned int ifindex, int hoplimit) |
| 331 | { |
| 332 | struct icmp6_hdr *icmph; |
| 333 | struct interface *ifp; |
| 334 | struct zebra_if *zif; |
| 335 | |
| 336 | /* Interface search. */ |
| 337 | ifp = if_lookup_by_index (ifindex); |
| 338 | if (ifp == NULL) |
| 339 | { |
| 340 | zlog_warn ("Unknown interface index: %d", ifindex); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | if (if_is_loopback (ifp)) |
| 345 | return; |
| 346 | |
| 347 | /* Check interface configuration. */ |
| 348 | zif = ifp->info; |
| 349 | if (! zif->rtadv.AdvSendAdvertisements) |
| 350 | return; |
| 351 | |
| 352 | /* ICMP message length check. */ |
| 353 | if (len < sizeof (struct icmp6_hdr)) |
| 354 | { |
| 355 | zlog_warn ("Invalid ICMPV6 packet length: %d", len); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | icmph = (struct icmp6_hdr *) buf; |
| 360 | |
| 361 | /* ICMP message type check. */ |
| 362 | if (icmph->icmp6_type != ND_ROUTER_SOLICIT && |
| 363 | icmph->icmp6_type != ND_ROUTER_ADVERT) |
| 364 | { |
| 365 | zlog_warn ("Unwanted ICMPV6 message type: %d", icmph->icmp6_type); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | /* Hoplimit check. */ |
| 370 | if (hoplimit >= 0 && hoplimit != 255) |
| 371 | { |
| 372 | zlog_warn ("Invalid hoplimit %d for router advertisement ICMP packet", |
| 373 | hoplimit); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | /* Check ICMP message type. */ |
| 378 | if (icmph->icmp6_type == ND_ROUTER_SOLICIT) |
| 379 | rtadv_process_solicit (ifp); |
| 380 | else if (icmph->icmp6_type == ND_ROUTER_ADVERT) |
| 381 | rtadv_process_advert (); |
| 382 | |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | int |
| 387 | rtadv_read (struct thread *thread) |
| 388 | { |
| 389 | int sock; |
| 390 | int len; |
| 391 | u_char buf[RTADV_MSG_SIZE]; |
| 392 | struct sockaddr_in6 from; |
| 393 | unsigned int ifindex; |
| 394 | int hoplimit = -1; |
| 395 | |
| 396 | sock = THREAD_FD (thread); |
| 397 | rtadv->ra_read = NULL; |
| 398 | |
| 399 | /* Register myself. */ |
| 400 | rtadv_event (RTADV_READ, sock); |
| 401 | |
| 402 | len = rtadv_recv_packet (sock, buf, BUFSIZ, &from, &ifindex, &hoplimit); |
| 403 | |
| 404 | if (len < 0) |
| 405 | { |
| 406 | zlog_warn ("router solicitation recv failed: %s.", strerror (errno)); |
| 407 | return len; |
| 408 | } |
| 409 | |
| 410 | rtadv_process_packet (buf, len, ifindex, hoplimit); |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | int |
| 416 | rtadv_make_socket (void) |
| 417 | { |
| 418 | int sock; |
| 419 | int ret; |
| 420 | struct icmp6_filter filter; |
| 421 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 422 | if ( zserv_privs.change (ZPRIVS_RAISE) ) |
| 423 | zlog_err ("rtadv_make_socket: could not raise privs, %s", |
| 424 | strerror (errno) ); |
| 425 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 426 | sock = socket (AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); |
| 427 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 428 | if ( zserv_privs.change (ZPRIVS_LOWER) ) |
| 429 | zlog_err ("rtadv_make_socket: could not lower privs, %s", |
| 430 | strerror (errno) ); |
| 431 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | /* When we can't make ICMPV6 socket simply back. Router |
| 433 | advertisement feature will not be supported. */ |
| 434 | if (sock < 0) |
| 435 | return -1; |
| 436 | |
| 437 | ret = setsockopt_ipv6_pktinfo (sock, 1); |
| 438 | if (ret < 0) |
| 439 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 440 | ret = setsockopt_ipv6_multicast_loop (sock, 0); |
| 441 | if (ret < 0) |
| 442 | return ret; |
| 443 | ret = setsockopt_ipv6_unicast_hops (sock, 255); |
| 444 | if (ret < 0) |
| 445 | return ret; |
| 446 | ret = setsockopt_ipv6_multicast_hops (sock, 255); |
| 447 | if (ret < 0) |
| 448 | return ret; |
| 449 | ret = setsockopt_ipv6_hoplimit (sock, 1); |
| 450 | if (ret < 0) |
| 451 | return ret; |
| 452 | |
| 453 | ICMP6_FILTER_SETBLOCKALL(&filter); |
| 454 | ICMP6_FILTER_SETPASS (ND_ROUTER_SOLICIT, &filter); |
| 455 | ICMP6_FILTER_SETPASS (ND_ROUTER_ADVERT, &filter); |
| 456 | |
| 457 | ret = setsockopt (sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, |
| 458 | sizeof (struct icmp6_filter)); |
| 459 | if (ret < 0) |
| 460 | { |
| 461 | zlog_info ("ICMP6_FILTER set fail: %s", strerror (errno)); |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | return sock; |
| 466 | } |
| 467 | |
| 468 | struct rtadv_prefix * |
| 469 | rtadv_prefix_new () |
| 470 | { |
| 471 | struct rtadv_prefix *new; |
| 472 | |
| 473 | new = XMALLOC (MTYPE_RTADV_PREFIX, sizeof (struct rtadv_prefix)); |
| 474 | memset (new, 0, sizeof (struct rtadv_prefix)); |
| 475 | |
| 476 | return new; |
| 477 | } |
| 478 | |
| 479 | void |
| 480 | rtadv_prefix_free (struct rtadv_prefix *rtadv_prefix) |
| 481 | { |
| 482 | XFREE (MTYPE_RTADV_PREFIX, rtadv_prefix); |
| 483 | } |
| 484 | |
| 485 | struct rtadv_prefix * |
| 486 | rtadv_prefix_lookup (list rplist, struct prefix *p) |
| 487 | { |
| 488 | listnode node; |
| 489 | struct rtadv_prefix *rprefix; |
| 490 | |
| 491 | for (node = listhead (rplist); node; node = nextnode (node)) |
| 492 | { |
| 493 | rprefix = getdata (node); |
| 494 | if (prefix_same (&rprefix->prefix, p)) |
| 495 | return rprefix; |
| 496 | } |
| 497 | return NULL; |
| 498 | } |
| 499 | |
| 500 | struct rtadv_prefix * |
| 501 | rtadv_prefix_get (list rplist, struct prefix *p) |
| 502 | { |
| 503 | struct rtadv_prefix *rprefix; |
| 504 | |
| 505 | rprefix = rtadv_prefix_lookup (rplist, p); |
| 506 | if (rprefix) |
| 507 | return rprefix; |
| 508 | |
| 509 | rprefix = rtadv_prefix_new (); |
| 510 | memcpy (&rprefix->prefix, p, sizeof (struct prefix)); |
| 511 | listnode_add (rplist, rprefix); |
| 512 | |
| 513 | return rprefix; |
| 514 | } |
| 515 | |
| 516 | void |
| 517 | rtadv_prefix_set (struct zebra_if *zif, struct rtadv_prefix *rp) |
| 518 | { |
| 519 | struct rtadv_prefix *rprefix; |
| 520 | |
| 521 | rprefix = rtadv_prefix_get (zif->rtadv.AdvPrefixList, &rp->prefix); |
| 522 | |
| 523 | /* Set parameters. */ |
| 524 | rprefix->AdvValidLifetime = rp->AdvValidLifetime; |
| 525 | rprefix->AdvPreferredLifetime = rp->AdvPreferredLifetime; |
| 526 | rprefix->AdvOnLinkFlag = rp->AdvOnLinkFlag; |
| 527 | rprefix->AdvAutonomousFlag = rp->AdvAutonomousFlag; |
| 528 | } |
| 529 | |
| 530 | int |
| 531 | rtadv_prefix_reset (struct zebra_if *zif, struct rtadv_prefix *rp) |
| 532 | { |
| 533 | struct rtadv_prefix *rprefix; |
| 534 | |
| 535 | rprefix = rtadv_prefix_lookup (zif->rtadv.AdvPrefixList, &rp->prefix); |
| 536 | if (rprefix != NULL) |
| 537 | { |
| 538 | listnode_delete (zif->rtadv.AdvPrefixList, (void *) rprefix); |
| 539 | rtadv_prefix_free (rprefix); |
| 540 | return 1; |
| 541 | } |
| 542 | else |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | DEFUN (ipv6_nd_suppress_ra, |
| 547 | ipv6_nd_suppress_ra_cmd, |
| 548 | "ipv6 nd suppress-ra", |
| 549 | IP_STR |
| 550 | "Neighbor discovery\n" |
| 551 | "Suppress Router Advertisement\n") |
| 552 | { |
| 553 | struct interface *ifp; |
| 554 | struct zebra_if *zif; |
| 555 | |
| 556 | ifp = vty->index; |
| 557 | zif = ifp->info; |
| 558 | |
| 559 | if (if_is_loopback (ifp)) |
| 560 | { |
| 561 | vty_out (vty, "Invalid interface%s", VTY_NEWLINE); |
| 562 | return CMD_WARNING; |
| 563 | } |
| 564 | |
| 565 | if (zif->rtadv.AdvSendAdvertisements) |
| 566 | { |
| 567 | zif->rtadv.AdvSendAdvertisements = 0; |
| 568 | zif->rtadv.AdvIntervalTimer = 0; |
| 569 | rtadv->adv_if_count--; |
| 570 | |
| 571 | if_leave_all_router (rtadv->sock, ifp); |
| 572 | |
| 573 | if (rtadv->adv_if_count == 0) |
| 574 | rtadv_event (RTADV_STOP, 0); |
| 575 | } |
| 576 | |
| 577 | return CMD_SUCCESS; |
| 578 | } |
| 579 | |
| 580 | ALIAS (ipv6_nd_suppress_ra, |
| 581 | no_ipv6_nd_send_ra_cmd, |
| 582 | "no ipv6 nd send-ra", |
| 583 | NO_STR |
| 584 | IP_STR |
| 585 | "Neighbor discovery\n" |
| 586 | "Send Router Advertisement\n") |
| 587 | |
| 588 | DEFUN (no_ipv6_nd_suppress_ra, |
| 589 | no_ipv6_nd_suppress_ra_cmd, |
| 590 | "no ipv6 nd suppress-ra", |
| 591 | NO_STR |
| 592 | IP_STR |
| 593 | "Neighbor discovery\n" |
| 594 | "Suppress Router Advertisement\n") |
| 595 | { |
| 596 | struct interface *ifp; |
| 597 | struct zebra_if *zif; |
| 598 | |
| 599 | ifp = vty->index; |
| 600 | zif = ifp->info; |
| 601 | |
| 602 | if (if_is_loopback (ifp)) |
| 603 | { |
| 604 | vty_out (vty, "Invalid interface%s", VTY_NEWLINE); |
| 605 | return CMD_WARNING; |
| 606 | } |
| 607 | |
| 608 | if (! zif->rtadv.AdvSendAdvertisements) |
| 609 | { |
| 610 | zif->rtadv.AdvSendAdvertisements = 1; |
| 611 | zif->rtadv.AdvIntervalTimer = 0; |
| 612 | rtadv->adv_if_count++; |
| 613 | |
| 614 | if_join_all_router (rtadv->sock, ifp); |
| 615 | |
| 616 | if (rtadv->adv_if_count == 1) |
| 617 | rtadv_event (RTADV_START, rtadv->sock); |
| 618 | } |
| 619 | |
| 620 | return CMD_SUCCESS; |
| 621 | } |
| 622 | |
| 623 | ALIAS (no_ipv6_nd_suppress_ra, |
| 624 | ipv6_nd_send_ra_cmd, |
| 625 | "ipv6 nd send-ra", |
| 626 | IP_STR |
| 627 | "Neighbor discovery\n" |
| 628 | "Send Router Advertisement\n") |
| 629 | |
| 630 | DEFUN (ipv6_nd_ra_interval, |
| 631 | ipv6_nd_ra_interval_cmd, |
| 632 | "ipv6 nd ra-interval SECONDS", |
| 633 | IP_STR |
| 634 | "Neighbor discovery\n" |
| 635 | "Router Advertisement interval\n" |
| 636 | "Router Advertisement interval in seconds\n") |
| 637 | { |
| 638 | int interval; |
| 639 | struct interface *ifp; |
| 640 | struct zebra_if *zif; |
| 641 | |
| 642 | ifp = (struct interface *) vty->index; |
| 643 | zif = ifp->info; |
| 644 | |
| 645 | interval = atoi (argv[0]); |
| 646 | |
| 647 | if (interval < 0) |
| 648 | { |
| 649 | vty_out (vty, "Invalid Router Advertisement Interval%s", VTY_NEWLINE); |
| 650 | return CMD_WARNING; |
| 651 | } |
| 652 | |
| 653 | zif->rtadv.MaxRtrAdvInterval = interval; |
| 654 | zif->rtadv.MinRtrAdvInterval = 0.33 * interval; |
| 655 | zif->rtadv.AdvIntervalTimer = 0; |
| 656 | |
| 657 | return CMD_SUCCESS; |
| 658 | } |
| 659 | |
| 660 | DEFUN (no_ipv6_nd_ra_interval, |
| 661 | no_ipv6_nd_ra_interval_cmd, |
| 662 | "no ipv6 nd ra-interval", |
| 663 | NO_STR |
| 664 | IP_STR |
| 665 | "Neighbor discovery\n" |
| 666 | "Router Advertisement interval\n") |
| 667 | { |
| 668 | struct interface *ifp; |
| 669 | struct zebra_if *zif; |
| 670 | |
| 671 | ifp = (struct interface *) vty->index; |
| 672 | zif = ifp->info; |
| 673 | |
| 674 | zif->rtadv.MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL; |
| 675 | zif->rtadv.MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL; |
| 676 | zif->rtadv.AdvIntervalTimer = zif->rtadv.MaxRtrAdvInterval; |
| 677 | |
| 678 | return CMD_SUCCESS; |
| 679 | } |
| 680 | |
| 681 | DEFUN (ipv6_nd_ra_lifetime, |
| 682 | ipv6_nd_ra_lifetime_cmd, |
| 683 | "ipv6 nd ra-lifetime SECONDS", |
| 684 | IP_STR |
| 685 | "Neighbor discovery\n" |
| 686 | "Router lifetime\n" |
| 687 | "Router lifetime in seconds\n") |
| 688 | { |
| 689 | int lifetime; |
| 690 | struct interface *ifp; |
| 691 | struct zebra_if *zif; |
| 692 | |
| 693 | ifp = (struct interface *) vty->index; |
| 694 | zif = ifp->info; |
| 695 | |
| 696 | lifetime = atoi (argv[0]); |
| 697 | |
| 698 | if (lifetime < 0 || lifetime > 0xffff) |
| 699 | { |
| 700 | vty_out (vty, "Invalid Router Lifetime%s", VTY_NEWLINE); |
| 701 | return CMD_WARNING; |
| 702 | } |
| 703 | |
| 704 | zif->rtadv.AdvDefaultLifetime = lifetime; |
| 705 | |
| 706 | return CMD_SUCCESS; |
| 707 | } |
| 708 | |
| 709 | DEFUN (no_ipv6_nd_ra_lifetime, |
| 710 | no_ipv6_nd_ra_lifetime_cmd, |
| 711 | "no ipv6 nd ra-lifetime", |
| 712 | NO_STR |
| 713 | IP_STR |
| 714 | "Neighbor discovery\n" |
| 715 | "Router lifetime\n") |
| 716 | { |
| 717 | struct interface *ifp; |
| 718 | struct zebra_if *zif; |
| 719 | |
| 720 | ifp = (struct interface *) vty->index; |
| 721 | zif = ifp->info; |
| 722 | |
| 723 | zif->rtadv.AdvDefaultLifetime = RTADV_ADV_DEFAULT_LIFETIME; |
| 724 | |
| 725 | return CMD_SUCCESS; |
| 726 | } |
| 727 | |
| 728 | DEFUN (ipv6_nd_reachable_time, |
| 729 | ipv6_nd_reachable_time_cmd, |
| 730 | "ipv6 nd reachable-time MILLISECONDS", |
| 731 | IP_STR |
| 732 | "Neighbor discovery\n" |
| 733 | "Reachable time\n" |
| 734 | "Reachable time in milliseconds\n") |
| 735 | { |
| 736 | u_int32_t rtime; |
| 737 | struct interface *ifp; |
| 738 | struct zebra_if *zif; |
| 739 | |
| 740 | ifp = (struct interface *) vty->index; |
| 741 | zif = ifp->info; |
| 742 | |
| 743 | rtime = (u_int32_t) atol (argv[0]); |
| 744 | |
| 745 | if (rtime > RTADV_MAX_REACHABLE_TIME) |
| 746 | { |
| 747 | vty_out (vty, "Invalid Reachable time%s", VTY_NEWLINE); |
| 748 | return CMD_WARNING; |
| 749 | } |
| 750 | |
| 751 | zif->rtadv.AdvReachableTime = rtime; |
| 752 | |
| 753 | return CMD_SUCCESS; |
| 754 | } |
| 755 | |
| 756 | DEFUN (no_ipv6_nd_reachable_time, |
| 757 | no_ipv6_nd_reachable_time_cmd, |
| 758 | "no ipv6 nd reachable-time", |
| 759 | NO_STR |
| 760 | IP_STR |
| 761 | "Neighbor discovery\n" |
| 762 | "Reachable time\n") |
| 763 | { |
| 764 | struct interface *ifp; |
| 765 | struct zebra_if *zif; |
| 766 | |
| 767 | ifp = (struct interface *) vty->index; |
| 768 | zif = ifp->info; |
| 769 | |
| 770 | zif->rtadv.AdvReachableTime = 0; |
| 771 | |
| 772 | return CMD_SUCCESS; |
| 773 | } |
| 774 | |
| 775 | DEFUN (ipv6_nd_managed_config_flag, |
| 776 | ipv6_nd_managed_config_flag_cmd, |
| 777 | "ipv6 nd managed-config-flag", |
| 778 | IP_STR |
| 779 | "Neighbor discovery\n" |
| 780 | "Managed address configuration flag\n") |
| 781 | { |
| 782 | struct interface *ifp; |
| 783 | struct zebra_if *zif; |
| 784 | |
| 785 | ifp = (struct interface *) vty->index; |
| 786 | zif = ifp->info; |
| 787 | |
| 788 | zif->rtadv.AdvManagedFlag = 1; |
| 789 | |
| 790 | return CMD_SUCCESS; |
| 791 | } |
| 792 | |
| 793 | DEFUN (no_ipv6_nd_managed_config_flag, |
| 794 | no_ipv6_nd_managed_config_flag_cmd, |
| 795 | "no ipv6 nd managed-config-flag", |
| 796 | NO_STR |
| 797 | IP_STR |
| 798 | "Neighbor discovery\n" |
| 799 | "Managed address configuration flag\n") |
| 800 | { |
| 801 | struct interface *ifp; |
| 802 | struct zebra_if *zif; |
| 803 | |
| 804 | ifp = (struct interface *) vty->index; |
| 805 | zif = ifp->info; |
| 806 | |
| 807 | zif->rtadv.AdvManagedFlag = 0; |
| 808 | |
| 809 | return CMD_SUCCESS; |
| 810 | } |
| 811 | |
| 812 | DEFUN (ipv6_nd_other_config_flag, |
| 813 | ipv6_nd_other_config_flag_cmd, |
| 814 | "ipv6 nd other-config-flag", |
| 815 | IP_STR |
| 816 | "Neighbor discovery\n" |
| 817 | "Other statefull configuration flag\n") |
| 818 | { |
| 819 | struct interface *ifp; |
| 820 | struct zebra_if *zif; |
| 821 | |
| 822 | ifp = (struct interface *) vty->index; |
| 823 | zif = ifp->info; |
| 824 | |
| 825 | zif->rtadv.AdvOtherConfigFlag = 1; |
| 826 | |
| 827 | return CMD_SUCCESS; |
| 828 | } |
| 829 | |
| 830 | DEFUN (no_ipv6_nd_other_config_flag, |
| 831 | no_ipv6_nd_other_config_flag_cmd, |
| 832 | "no ipv6 nd other-config-flag", |
| 833 | NO_STR |
| 834 | IP_STR |
| 835 | "Neighbor discovery\n" |
| 836 | "Other statefull configuration flag\n") |
| 837 | { |
| 838 | struct interface *ifp; |
| 839 | struct zebra_if *zif; |
| 840 | |
| 841 | ifp = (struct interface *) vty->index; |
| 842 | zif = ifp->info; |
| 843 | |
| 844 | zif->rtadv.AdvOtherConfigFlag = 0; |
| 845 | |
| 846 | return CMD_SUCCESS; |
| 847 | } |
| 848 | |
| 849 | DEFUN (ipv6_nd_prefix_advertisement, |
| 850 | ipv6_nd_prefix_advertisement_cmd, |
| 851 | "ipv6 nd prefix-advertisement IPV6PREFIX VALID PREFERRED [onlink] [autoconfig]", |
| 852 | IP_STR |
| 853 | "Neighbor discovery\n" |
| 854 | "Prefix information\n" |
| 855 | "IPv6 prefix\n" |
| 856 | "Valid lifetime in seconds\n" |
| 857 | "Preferred lifetime in seconds\n" |
| 858 | "On link flag\n" |
| 859 | "Autonomous address-configuration flag\n") |
| 860 | { |
| 861 | int i; |
| 862 | int ret; |
| 863 | struct interface *ifp; |
| 864 | struct zebra_if *zebra_if; |
| 865 | struct rtadv_prefix rp; |
| 866 | |
| 867 | ifp = (struct interface *) vty->index; |
| 868 | zebra_if = ifp->info; |
| 869 | |
| 870 | ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *) &rp.prefix); |
| 871 | if (!ret) |
| 872 | { |
| 873 | vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE); |
| 874 | return CMD_WARNING; |
| 875 | } |
| 876 | |
| 877 | if (argc == 1) |
| 878 | { |
| 879 | rp.AdvValidLifetime = RTADV_VALID_LIFETIME; |
| 880 | rp.AdvPreferredLifetime = RTADV_PREFERRED_LIFETIME; |
| 881 | rp.AdvOnLinkFlag = 1; |
| 882 | rp.AdvAutonomousFlag = 1; |
| 883 | } |
| 884 | else |
| 885 | { |
| 886 | rp.AdvValidLifetime = (u_int32_t) atol (argv[1]); |
| 887 | rp.AdvPreferredLifetime = (u_int32_t) atol (argv[2]); |
| 888 | if (rp.AdvPreferredLifetime > rp.AdvValidLifetime) |
| 889 | { |
| 890 | vty_out (vty, "Invalid preferred lifetime%s", VTY_NEWLINE); |
| 891 | return CMD_WARNING; |
| 892 | } |
| 893 | |
| 894 | rp.AdvOnLinkFlag = 0; |
| 895 | rp.AdvAutonomousFlag = 0; |
| 896 | for (i = 3; i < argc; i++) |
| 897 | { |
| 898 | if (! strcmp (argv[i], "onlink")) |
| 899 | rp.AdvOnLinkFlag = 1; |
| 900 | else if (! strcmp (argv[i], "autoconfig")) |
| 901 | rp.AdvAutonomousFlag = 1; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | rtadv_prefix_set (zebra_if, &rp); |
| 906 | |
| 907 | return CMD_SUCCESS; |
| 908 | } |
| 909 | |
| 910 | ALIAS (ipv6_nd_prefix_advertisement, |
| 911 | ipv6_nd_prefix_advertisement_no_val_cmd, |
| 912 | "ipv6 nd prefix-advertisement IPV6PREFIX", |
| 913 | IP_STR |
| 914 | "Neighbor discovery\n" |
| 915 | "Prefix information\n" |
| 916 | "IPv6 prefix\n") |
| 917 | |
| 918 | DEFUN (no_ipv6_nd_prefix_advertisement, |
| 919 | no_ipv6_nd_prefix_advertisement_cmd, |
| 920 | "no ipv6 nd prefix-advertisement IPV6PREFIX", |
| 921 | NO_STR |
| 922 | IP_STR |
| 923 | "Neighbor discovery\n" |
| 924 | "Prefix information\n" |
| 925 | "IPv6 prefix\n") |
| 926 | { |
| 927 | int ret; |
| 928 | struct interface *ifp; |
| 929 | struct zebra_if *zebra_if; |
| 930 | struct rtadv_prefix rp; |
| 931 | |
| 932 | ifp = (struct interface *) vty->index; |
| 933 | zebra_if = ifp->info; |
| 934 | |
| 935 | ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *) &rp.prefix); |
| 936 | if (!ret) |
| 937 | { |
| 938 | vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE); |
| 939 | return CMD_WARNING; |
| 940 | } |
| 941 | |
| 942 | ret = rtadv_prefix_reset (zebra_if, &rp); |
| 943 | if (!ret) |
| 944 | { |
| 945 | vty_out (vty, "Non-exist IPv6 prefix%s", VTY_NEWLINE); |
| 946 | return CMD_WARNING; |
| 947 | } |
| 948 | |
| 949 | return CMD_SUCCESS; |
| 950 | } |
| 951 | |
| 952 | /* Write configuration about router advertisement. */ |
| 953 | void |
| 954 | rtadv_config_write (struct vty *vty, struct interface *ifp) |
| 955 | { |
| 956 | struct zebra_if *zif; |
| 957 | listnode node; |
| 958 | struct rtadv_prefix *rprefix; |
| 959 | u_char buf[INET6_ADDRSTRLEN]; |
| 960 | |
| 961 | if (! rtadv) |
| 962 | return; |
| 963 | |
| 964 | zif = ifp->info; |
| 965 | |
| 966 | if (! if_is_loopback (ifp)) |
| 967 | { |
| 968 | if (zif->rtadv.AdvSendAdvertisements) |
| 969 | vty_out (vty, " no ipv6 nd suppress-ra%s", VTY_NEWLINE); |
| 970 | else |
| 971 | vty_out (vty, " ipv6 nd suppress-ra%s", VTY_NEWLINE); |
| 972 | } |
| 973 | |
| 974 | if (zif->rtadv.MaxRtrAdvInterval != RTADV_MAX_RTR_ADV_INTERVAL) |
| 975 | vty_out (vty, " ipv6 nd ra-interval %d%s", zif->rtadv.MaxRtrAdvInterval, |
| 976 | VTY_NEWLINE); |
| 977 | |
| 978 | if (zif->rtadv.AdvDefaultLifetime != RTADV_ADV_DEFAULT_LIFETIME) |
| 979 | vty_out (vty, " ipv6 nd ra-lifetime %d%s", zif->rtadv.AdvDefaultLifetime, |
| 980 | VTY_NEWLINE); |
| 981 | |
| 982 | if (zif->rtadv.AdvReachableTime) |
| 983 | vty_out (vty, " ipv6 nd reachable-time %d%s", zif->rtadv.AdvReachableTime, |
| 984 | VTY_NEWLINE); |
| 985 | |
| 986 | if (zif->rtadv.AdvManagedFlag) |
| 987 | vty_out (vty, " ipv6 nd managed-config-flag%s", VTY_NEWLINE); |
| 988 | |
| 989 | if (zif->rtadv.AdvOtherConfigFlag) |
| 990 | vty_out (vty, " ipv6 nd other-config-flag%s", VTY_NEWLINE); |
| 991 | |
| 992 | for (node = listhead(zif->rtadv.AdvPrefixList); node; node = nextnode (node)) |
| 993 | { |
| 994 | rprefix = getdata (node); |
| 995 | vty_out (vty, " ipv6 nd prefix-advertisement %s/%d %d %d", |
| 996 | inet_ntop (AF_INET6, &rprefix->prefix.u.prefix6, |
| 997 | buf, INET6_ADDRSTRLEN), |
| 998 | rprefix->prefix.prefixlen, |
| 999 | rprefix->AdvValidLifetime, |
| 1000 | rprefix->AdvPreferredLifetime); |
| 1001 | if (rprefix->AdvOnLinkFlag) |
| 1002 | vty_out (vty, " onlink"); |
| 1003 | if (rprefix->AdvAutonomousFlag) |
| 1004 | vty_out (vty, " autoconfig"); |
| 1005 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1006 | } |
| 1007 | } |
| 1008 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1009 | |
| 1010 | void |
| 1011 | rtadv_event (enum rtadv_event event, int val) |
| 1012 | { |
| 1013 | switch (event) |
| 1014 | { |
| 1015 | case RTADV_START: |
| 1016 | if (! rtadv->ra_read) |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1017 | rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1018 | if (! rtadv->ra_timer) |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1019 | rtadv->ra_timer = thread_add_event (zebrad.master, rtadv_timer, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | case RTADV_STOP: |
| 1022 | if (rtadv->ra_timer) |
| 1023 | { |
| 1024 | thread_cancel (rtadv->ra_timer); |
| 1025 | rtadv->ra_timer = NULL; |
| 1026 | } |
| 1027 | if (rtadv->ra_read) |
| 1028 | { |
| 1029 | thread_cancel (rtadv->ra_read); |
| 1030 | rtadv->ra_read = NULL; |
| 1031 | } |
| 1032 | break; |
| 1033 | case RTADV_TIMER: |
| 1034 | if (! rtadv->ra_timer) |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1035 | rtadv->ra_timer = thread_add_timer (zebrad.master, rtadv_timer, NULL, val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1036 | break; |
| 1037 | case RTADV_READ: |
| 1038 | if (! rtadv->ra_read) |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1039 | rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1040 | break; |
| 1041 | default: |
| 1042 | break; |
| 1043 | } |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | void |
| 1048 | rtadv_init () |
| 1049 | { |
| 1050 | int sock; |
| 1051 | |
| 1052 | sock = rtadv_make_socket (); |
| 1053 | if (sock < 0) |
| 1054 | return; |
| 1055 | |
| 1056 | rtadv = rtadv_new (); |
| 1057 | rtadv->sock = sock; |
| 1058 | |
| 1059 | install_element (INTERFACE_NODE, &ipv6_nd_suppress_ra_cmd); |
| 1060 | install_element (INTERFACE_NODE, &no_ipv6_nd_suppress_ra_cmd); |
| 1061 | install_element (INTERFACE_NODE, &ipv6_nd_send_ra_cmd); |
| 1062 | install_element (INTERFACE_NODE, &no_ipv6_nd_send_ra_cmd); |
| 1063 | install_element (INTERFACE_NODE, &ipv6_nd_ra_interval_cmd); |
| 1064 | install_element (INTERFACE_NODE, &no_ipv6_nd_ra_interval_cmd); |
| 1065 | install_element (INTERFACE_NODE, &ipv6_nd_ra_lifetime_cmd); |
| 1066 | install_element (INTERFACE_NODE, &no_ipv6_nd_ra_lifetime_cmd); |
| 1067 | install_element (INTERFACE_NODE, &ipv6_nd_reachable_time_cmd); |
| 1068 | install_element (INTERFACE_NODE, &no_ipv6_nd_reachable_time_cmd); |
| 1069 | install_element (INTERFACE_NODE, &ipv6_nd_managed_config_flag_cmd); |
| 1070 | install_element (INTERFACE_NODE, &no_ipv6_nd_managed_config_flag_cmd); |
| 1071 | install_element (INTERFACE_NODE, &ipv6_nd_other_config_flag_cmd); |
| 1072 | install_element (INTERFACE_NODE, &no_ipv6_nd_other_config_flag_cmd); |
| 1073 | install_element (INTERFACE_NODE, &ipv6_nd_prefix_advertisement_cmd); |
| 1074 | install_element (INTERFACE_NODE, &ipv6_nd_prefix_advertisement_no_val_cmd); |
| 1075 | install_element (INTERFACE_NODE, &no_ipv6_nd_prefix_advertisement_cmd); |
| 1076 | } |
| 1077 | |
| 1078 | int |
| 1079 | if_join_all_router (int sock, struct interface *ifp) |
| 1080 | { |
| 1081 | int ret; |
| 1082 | |
| 1083 | struct ipv6_mreq mreq; |
| 1084 | |
| 1085 | memset (&mreq, 0, sizeof (struct ipv6_mreq)); |
| 1086 | inet_pton (AF_INET6, ALLROUTER, &mreq.ipv6mr_multiaddr); |
| 1087 | mreq.ipv6mr_interface = ifp->ifindex; |
| 1088 | |
| 1089 | ret = setsockopt (sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, |
| 1090 | (char *) &mreq, sizeof mreq); |
| 1091 | if (ret < 0) |
| 1092 | zlog_warn ("can't setsockopt IPV6_JOIN_GROUP: %s", strerror (errno)); |
| 1093 | |
| 1094 | zlog_info ("rtadv: %s join to all-routers multicast group", ifp->name); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | int |
| 1100 | if_leave_all_router (int sock, struct interface *ifp) |
| 1101 | { |
| 1102 | int ret; |
| 1103 | |
| 1104 | struct ipv6_mreq mreq; |
| 1105 | |
| 1106 | memset (&mreq, 0, sizeof (struct ipv6_mreq)); |
| 1107 | inet_pton (AF_INET6, ALLROUTER, &mreq.ipv6mr_multiaddr); |
| 1108 | mreq.ipv6mr_interface = ifp->ifindex; |
| 1109 | |
| 1110 | ret = setsockopt (sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, |
| 1111 | (char *) &mreq, sizeof mreq); |
| 1112 | if (ret < 0) |
| 1113 | zlog_warn ("can't setsockopt IPV6_LEAVE_GROUP: %s", strerror (errno)); |
| 1114 | |
| 1115 | zlog_info ("rtadv: %s leave from all-routers multicast group", ifp->name); |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | #else |
| 1121 | void |
| 1122 | rtadv_init () |
| 1123 | { |
| 1124 | /* Empty.*/; |
| 1125 | } |
| 1126 | #endif /* RTADV && HAVE_IPV6 */ |