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