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