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