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