2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIPng daemon
|
|
|
|
* Copyright (C) 1998, 1999 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "log.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "memory.h"
|
|
|
|
#include "if.h"
|
|
|
|
#include "stream.h"
|
2018-08-03 19:22:48 +02:00
|
|
|
#include "agg_table.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "command.h"
|
|
|
|
#include "sockopt.h"
|
|
|
|
#include "distribute.h"
|
|
|
|
#include "plist.h"
|
|
|
|
#include "routemap.h"
|
2003-05-24 23:41:49 +02:00
|
|
|
#include "if_rmap.h"
|
2003-11-17 10:04:53 +01:00
|
|
|
#include "privs.h"
|
2018-06-18 16:05:16 +02:00
|
|
|
#include "lib_errors.h"
|
2018-11-29 03:49:49 +01:00
|
|
|
#include "northbound_cli.h"
|
2020-04-17 15:35:15 +02:00
|
|
|
#include "network.h"
|
2024-01-26 23:40:55 +01:00
|
|
|
#include "mgmt_be_client.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#include "ripngd/ripngd.h"
|
|
|
|
#include "ripngd/ripng_route.h"
|
|
|
|
#include "ripngd/ripng_debug.h"
|
2003-05-25 19:10:12 +02:00
|
|
|
#include "ripngd/ripng_nexthop.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-06-21 08:44:11 +02:00
|
|
|
DEFINE_MGROUP(RIPNGD, "ripngd");
|
|
|
|
DEFINE_MTYPE_STATIC(RIPNGD, RIPNG, "RIPng structure");
|
|
|
|
DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_VRF_NAME, "RIPng VRF name");
|
|
|
|
DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_ROUTE, "RIPng route info");
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
enum { ripng_all_route,
|
|
|
|
ripng_changed_route,
|
|
|
|
};
|
|
|
|
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
static void ripng_distribute_update(struct distribute_ctx *ctx,
|
|
|
|
struct distribute *dist);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Prototypes. */
|
2003-05-25 19:10:12 +02:00
|
|
|
void ripng_output_process(struct interface *, struct sockaddr_in6 *, int);
|
2019-01-04 22:08:10 +01:00
|
|
|
static void ripng_instance_enable(struct ripng *ripng, struct vrf *vrf,
|
|
|
|
int sock);
|
|
|
|
static void ripng_instance_disable(struct ripng *ripng);
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_triggered_update(struct event *);
|
2019-01-14 08:58:36 +01:00
|
|
|
static void ripng_if_rmap_update(struct if_rmap_ctx *ctx,
|
|
|
|
struct if_rmap *if_rmap);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Generate rb-tree of RIPng instances. */
|
|
|
|
static inline int ripng_instance_compare(const struct ripng *a,
|
|
|
|
const struct ripng *b)
|
|
|
|
{
|
|
|
|
return strcmp(a->vrf_name, b->vrf_name);
|
|
|
|
}
|
|
|
|
RB_GENERATE(ripng_instance_head, ripng, entry, ripng_instance_compare)
|
|
|
|
|
|
|
|
struct ripng_instance_head ripng_instances = RB_INITIALIZER(&ripng_instances);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIPng next hop specification. */
|
|
|
|
struct ripng_nexthop {
|
|
|
|
enum ripng_nexthop_type {
|
|
|
|
RIPNG_NEXTHOP_UNSPEC,
|
|
|
|
RIPNG_NEXTHOP_ADDRESS
|
|
|
|
} flag;
|
|
|
|
struct in6_addr address;
|
|
|
|
};
|
|
|
|
|
2018-11-29 16:24:26 +01:00
|
|
|
int ripng_route_rte(struct ripng_info *rinfo)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
return (rinfo->type == ZEBRA_ROUTE_RIPNG
|
|
|
|
&& rinfo->sub_type == RIPNG_ROUTE_RTE);
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Allocate new ripng information. */
|
2019-01-24 10:12:36 +01:00
|
|
|
struct ripng_info *ripng_info_new(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct ripng_info *new;
|
|
|
|
|
|
|
|
new = XCALLOC(MTYPE_RIPNG_ROUTE, sizeof(struct ripng_info));
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free ripng information. */
|
|
|
|
void ripng_info_free(struct ripng_info *rinfo)
|
|
|
|
{
|
|
|
|
XFREE(MTYPE_RIPNG_ROUTE, rinfo);
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng_info_get_instance(const struct ripng_info *rinfo)
|
|
|
|
{
|
|
|
|
return agg_get_table_info(agg_get_table(rinfo->rp));
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Create ripng socket. */
|
2019-01-04 22:08:10 +01:00
|
|
|
int ripng_make_socket(struct vrf *vrf)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int sock;
|
|
|
|
struct sockaddr_in6 ripaddr;
|
2019-01-04 22:08:10 +01:00
|
|
|
const char *vrf_dev = NULL;
|
|
|
|
|
|
|
|
/* Make datagram socket. */
|
|
|
|
if (vrf->vrf_id != VRF_DEFAULT)
|
|
|
|
vrf_dev = vrf->name;
|
2019-08-13 15:47:23 +02:00
|
|
|
frr_with_privs(&ripngd_privs) {
|
2019-01-04 22:08:10 +01:00
|
|
|
sock = vrf_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP,
|
|
|
|
vrf->vrf_id, vrf_dev);
|
|
|
|
if (sock < 0) {
|
|
|
|
flog_err_sys(EC_LIB_SOCKET,
|
|
|
|
"Cannot create UDP socket: %s",
|
|
|
|
safe_strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
sockopt_reuseaddr(sock);
|
|
|
|
sockopt_reuseport(sock);
|
2016-12-07 16:21:46 +01:00
|
|
|
setsockopt_so_recvbuf(sock, 8096);
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = setsockopt_ipv6_pktinfo(sock, 1);
|
|
|
|
if (ret < 0)
|
2017-10-23 01:14:21 +02:00
|
|
|
goto error;
|
2011-09-28 12:23:35 +02:00
|
|
|
#ifdef IPTOS_PREC_INTERNETCONTROL
|
|
|
|
ret = setsockopt_ipv6_tclass(sock, IPTOS_PREC_INTERNETCONTROL);
|
|
|
|
if (ret < 0)
|
2017-10-23 01:14:21 +02:00
|
|
|
goto error;
|
2011-09-28 12:23:35 +02:00
|
|
|
#endif
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = setsockopt_ipv6_multicast_hops(sock, 255);
|
|
|
|
if (ret < 0)
|
2017-10-23 01:14:21 +02:00
|
|
|
goto error;
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = setsockopt_ipv6_multicast_loop(sock, 0);
|
|
|
|
if (ret < 0)
|
2017-10-23 01:14:21 +02:00
|
|
|
goto error;
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = setsockopt_ipv6_hoplimit(sock, 1);
|
|
|
|
if (ret < 0)
|
2017-10-23 01:14:21 +02:00
|
|
|
goto error;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
memset(&ripaddr, 0, sizeof(ripaddr));
|
|
|
|
ripaddr.sin6_family = AF_INET6;
|
|
|
|
#ifdef SIN6_LEN
|
|
|
|
ripaddr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
#endif /* SIN6_LEN */
|
|
|
|
ripaddr.sin6_port = htons(RIPNG_PORT_DEFAULT);
|
|
|
|
|
2019-08-13 15:47:23 +02:00
|
|
|
frr_with_privs(&ripngd_privs) {
|
2018-08-10 18:36:43 +02:00
|
|
|
ret = bind(sock, (struct sockaddr *)&ripaddr, sizeof(ripaddr));
|
|
|
|
if (ret < 0) {
|
2018-08-13 19:52:57 +02:00
|
|
|
zlog_err("Can't bind ripng socket: %s.",
|
|
|
|
safe_strerror(errno));
|
2018-08-10 18:36:43 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2003-11-17 10:04:53 +01:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
return sock;
|
2017-10-23 01:14:21 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
close(sock);
|
|
|
|
return ret;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send RIPng packet. */
|
|
|
|
int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
|
|
|
|
struct interface *ifp)
|
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_interface *ri = ifp->info;
|
|
|
|
struct ripng *ripng = ri->ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
int ret;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov;
|
|
|
|
struct cmsghdr *cmsgptr;
|
2019-01-04 22:08:09 +01:00
|
|
|
char adata[256] = {};
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in6_pktinfo *pkt;
|
|
|
|
struct sockaddr_in6 addr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (IS_RIPNG_DEBUG_SEND) {
|
|
|
|
if (to)
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_debug("send to %pI6", &to->sin6_addr);
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug(" send interface %s", ifp->name);
|
|
|
|
zlog_debug(" send packet size %d", bufsize);
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
2002-12-13 21:15:29 +01:00
|
|
|
addr.sin6_family = AF_INET6;
|
|
|
|
#ifdef SIN6_LEN
|
|
|
|
addr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
#endif /* SIN6_LEN */
|
|
|
|
addr.sin6_flowinfo = htonl(RIPNG_PRIORITY_DEFAULT);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* When destination is specified. */
|
|
|
|
if (to != NULL) {
|
|
|
|
addr.sin6_addr = to->sin6_addr;
|
|
|
|
addr.sin6_port = to->sin6_port;
|
|
|
|
} else {
|
|
|
|
inet_pton(AF_INET6, RIPNG_GROUP, &addr.sin6_addr);
|
|
|
|
addr.sin6_port = htons(RIPNG_PORT_DEFAULT);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-08-25 02:43:29 +02:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
2002-12-13 21:15:29 +01:00
|
|
|
msg.msg_name = (void *)&addr;
|
|
|
|
msg.msg_namelen = sizeof(struct sockaddr_in6);
|
|
|
|
msg.msg_iov = &iov;
|
|
|
|
msg.msg_iovlen = 1;
|
2022-05-08 15:07:42 +02:00
|
|
|
msg.msg_control = adata;
|
2002-12-13 21:15:29 +01:00
|
|
|
msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
iov.iov_base = buf;
|
|
|
|
iov.iov_len = bufsize;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
cmsgptr = (struct cmsghdr *)adata;
|
|
|
|
cmsgptr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
|
|
|
|
cmsgptr->cmsg_level = IPPROTO_IPV6;
|
|
|
|
cmsgptr->cmsg_type = IPV6_PKTINFO;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
pkt = (struct in6_pktinfo *)CMSG_DATA(cmsgptr);
|
|
|
|
memset(&pkt->ipi6_addr, 0, sizeof(struct in6_addr));
|
|
|
|
pkt->ipi6_ifindex = ifp->ifindex;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = sendmsg(ripng->sock, &msg, 0);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
if (to)
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err_sys(EC_LIB_SOCKET,
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng send fail on %s to %pI6: %s",
|
|
|
|
ifp->name, &to->sin6_addr,
|
2018-08-06 18:36:50 +02:00
|
|
|
safe_strerror(errno));
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2018-09-13 21:38:57 +02:00
|
|
|
flog_err_sys(EC_LIB_SOCKET, "RIPng send fail on %s: %s",
|
|
|
|
ifp->name, safe_strerror(errno));
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive UDP RIPng packet from socket. */
|
2018-03-27 21:13:34 +02:00
|
|
|
static int ripng_recv_packet(int sock, uint8_t *buf, int bufsize,
|
2016-01-18 11:12:10 +01:00
|
|
|
struct sockaddr_in6 *from, ifindex_t *ifindex,
|
2002-12-13 21:15:29 +01:00
|
|
|
int *hoplimit)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov;
|
|
|
|
struct cmsghdr *cmsgptr;
|
2015-03-03 09:07:25 +01:00
|
|
|
struct in6_addr dst = {.s6_addr = {0}};
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&dst, 0, sizeof(dst));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Ancillary data. This store cmsghdr and in6_pktinfo. But at this
|
|
|
|
point I can't determine size of cmsghdr */
|
|
|
|
char adata[1024];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Fill in message and iovec. */
|
2017-08-25 02:43:29 +02:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
2002-12-13 21:15:29 +01:00
|
|
|
msg.msg_name = (void *)from;
|
|
|
|
msg.msg_namelen = sizeof(struct sockaddr_in6);
|
|
|
|
msg.msg_iov = &iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
msg.msg_control = (void *)adata;
|
2020-03-08 20:43:26 +01:00
|
|
|
msg.msg_controllen = sizeof(adata);
|
2002-12-13 21:15:29 +01:00
|
|
|
iov.iov_base = buf;
|
|
|
|
iov.iov_len = bufsize;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* If recvmsg fail return minus value. */
|
|
|
|
ret = recvmsg(sock, &msg, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-15 21:06:53 +02:00
|
|
|
for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
|
|
|
|
/* I want interface index which this packet comes from. */
|
|
|
|
if (cmsgptr->cmsg_level == IPPROTO_IPV6
|
|
|
|
&& cmsgptr->cmsg_type == IPV6_PKTINFO) {
|
|
|
|
struct in6_pktinfo *ptr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ptr = (struct in6_pktinfo *)CMSG_DATA(cmsgptr);
|
|
|
|
*ifindex = ptr->ipi6_ifindex;
|
|
|
|
dst = ptr->ipi6_addr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (*ifindex == 0)
|
|
|
|
zlog_warn(
|
|
|
|
"Interface index returned by IPV6_PKTINFO is zero");
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Incoming packet's multicast hop limit. */
|
|
|
|
if (cmsgptr->cmsg_level == IPPROTO_IPV6
|
|
|
|
&& cmsgptr->cmsg_type == IPV6_HOPLIMIT) {
|
2009-12-10 13:52:33 +01:00
|
|
|
int *phoplimit = (int *)CMSG_DATA(cmsgptr);
|
|
|
|
*hoplimit = *phoplimit;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2009-12-10 13:52:33 +01:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Hoplimit check shold be done when destination address is
|
|
|
|
multicast address. */
|
|
|
|
if (!IN6_IS_ADDR_MULTICAST(&dst))
|
|
|
|
*hoplimit = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump rip packet */
|
2004-10-08 08:32:23 +02:00
|
|
|
void ripng_packet_dump(struct ripng_packet *packet, int size,
|
|
|
|
const char *sndrcv)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
caddr_t lim;
|
|
|
|
struct rte *rte;
|
2004-10-08 08:32:23 +02:00
|
|
|
const char *command_str;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Set command string. */
|
|
|
|
if (packet->command == RIPNG_REQUEST)
|
|
|
|
command_str = "request";
|
|
|
|
else if (packet->command == RIPNG_RESPONSE)
|
|
|
|
command_str = "response";
|
|
|
|
else
|
|
|
|
command_str = "unknown";
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Dump packet header. */
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug("%s %s version %d packet size %d", sndrcv, command_str,
|
2002-12-13 21:15:29 +01:00
|
|
|
packet->version, size);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Dump each routing table entry. */
|
|
|
|
rte = packet->rte;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
for (lim = (caddr_t)packet + size; (caddr_t)rte < lim; rte++) {
|
|
|
|
if (rte->metric == RIPNG_METRIC_NEXTHOP)
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_debug(" nexthop %pI6/%d", &rte->addr,
|
2005-04-08 03:30:51 +02:00
|
|
|
rte->prefixlen);
|
2002-12-13 21:15:29 +01:00
|
|
|
else
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_debug(" %pI6/%d metric %d tag %" ROUTE_TAG_PRI,
|
|
|
|
&rte->addr, rte->prefixlen,
|
2016-10-01 20:42:34 +02:00
|
|
|
rte->metric, (route_tag_t)ntohs(rte->tag));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIPng next hop address RTE (Route Table Entry). */
|
|
|
|
static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from,
|
|
|
|
struct ripng_nexthop *nexthop)
|
|
|
|
{
|
|
|
|
/* Logging before checking RTE. */
|
|
|
|
if (IS_RIPNG_DEBUG_RECV)
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_debug("RIPng nexthop RTE address %pI6 tag %" ROUTE_TAG_PRI
|
2016-10-01 20:42:34 +02:00
|
|
|
" prefixlen %d",
|
2021-03-31 14:28:30 +02:00
|
|
|
&rte->addr, (route_tag_t)ntohs(rte->tag),
|
2016-10-01 20:42:34 +02:00
|
|
|
rte->prefixlen);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RFC2080 2.1.1 Next Hop:
|
|
|
|
The route tag and prefix length in the next hop RTE must be
|
|
|
|
set to zero on sending and ignored on receiption. */
|
|
|
|
if (ntohs(rte->tag) != 0)
|
2016-10-01 20:42:34 +02:00
|
|
|
zlog_warn(
|
|
|
|
"RIPng nexthop RTE with non zero tag value %" ROUTE_TAG_PRI
|
2021-03-31 14:28:30 +02:00
|
|
|
" from %pI6",
|
|
|
|
(route_tag_t)ntohs(rte->tag), &from->sin6_addr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rte->prefixlen != 0)
|
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng nexthop RTE with non zero prefixlen value %d from %pI6",
|
|
|
|
rte->prefixlen, &from->sin6_addr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
|
|
|
|
next hop RTE indicates that the next hop address should be the
|
|
|
|
originator of the RIPng advertisement. An address specified as a
|
|
|
|
next hop must be a link-local address. */
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&rte->addr)) {
|
|
|
|
nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
|
|
|
|
memset(&nexthop->address, 0, sizeof(struct in6_addr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&rte->addr)) {
|
|
|
|
nexthop->flag = RIPNG_NEXTHOP_ADDRESS;
|
|
|
|
IPV6_ADDR_COPY(&nexthop->address, &rte->addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The purpose of the next hop RTE is to eliminate packets being
|
|
|
|
routed through extra hops in the system. It is particularly useful
|
|
|
|
when RIPng is not being run on all of the routers on a network.
|
|
|
|
Note that next hop RTE is "advisory". That is, if the provided
|
|
|
|
information is ignored, a possibly sub-optimal, but absolutely
|
|
|
|
valid, route may be taken. If the received next hop address is not
|
|
|
|
a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("RIPng nexthop RTE with non link-local address %pI6 from %pI6",
|
|
|
|
&rte->addr, &from->sin6_addr);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
|
|
|
|
memset(&nexthop->address, 0, sizeof(struct in6_addr));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If ifp has same link-local address then return 1. */
|
|
|
|
static int ripng_lladdr_check(struct interface *ifp, struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
struct connected *connected;
|
|
|
|
struct prefix *p;
|
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, connected) {
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
p = connected->address;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
if (p->family == AF_INET6
|
|
|
|
&& IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)
|
|
|
|
&& IN6_ARE_ADDR_EQUAL(&p->u.prefix6, addr))
|
|
|
|
return 1;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIPng route garbage collect timer. */
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_garbage_collect(struct event *t)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct ripng_info *rinfo;
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
rinfo = EVENT_ARG(t);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Off timeout timer. */
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Get route_node pointer. */
|
|
|
|
rp = rinfo->rp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Unlock route_node. */
|
2015-05-22 11:39:53 +02:00
|
|
|
listnode_delete(rp->info, rinfo);
|
|
|
|
if (list_isempty((struct list *)rp->info)) {
|
2018-10-02 11:39:51 +02:00
|
|
|
list_delete((struct list **)&rp->info);
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2015-05-22 11:39:53 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Free RIPng routing information. */
|
|
|
|
ripng_info_free(rinfo);
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
static void ripng_timeout_update(struct ripng *ripng, struct ripng_info *rinfo);
|
2015-05-22 11:39:53 +02:00
|
|
|
|
|
|
|
/* Add new route to the ECMP list.
|
2015-05-22 11:39:54 +02:00
|
|
|
* RETURN: the new entry added in the list, or NULL if it is not the first
|
|
|
|
* entry and ECMP is not allowed.
|
2015-05-22 11:39:53 +02:00
|
|
|
*/
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_info *ripng_ecmp_add(struct ripng *ripng,
|
|
|
|
struct ripng_info *rinfo_new)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp = rinfo_new->rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *rinfo = NULL;
|
2023-05-16 09:34:22 +02:00
|
|
|
struct ripng_info *rinfo_exist = NULL;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = NULL;
|
2023-05-16 09:34:22 +02:00
|
|
|
struct listnode *node = NULL;
|
|
|
|
struct listnode *nnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (rp->info == NULL)
|
|
|
|
rp->info = list_new();
|
|
|
|
list = (struct list *)rp->info;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* If ECMP is not allowed and some entry already exists in the list,
|
|
|
|
* do nothing. */
|
|
|
|
if (listcount(list) && !ripng->ecmp)
|
|
|
|
return NULL;
|
|
|
|
|
2023-05-16 09:34:22 +02:00
|
|
|
/* Add or replace an existing ECMP path with lower neighbor IP */
|
|
|
|
if (listcount(list) && listcount(list) >= ripng->ecmp) {
|
|
|
|
struct ripng_info *from_highest = NULL;
|
|
|
|
|
|
|
|
/* Find the rip_info struct that has the highest nexthop IP */
|
|
|
|
for (ALL_LIST_ELEMENTS(list, node, nnode, rinfo_exist))
|
|
|
|
if (!from_highest ||
|
|
|
|
(from_highest &&
|
|
|
|
IPV6_ADDR_CMP(&rinfo_exist->from,
|
|
|
|
&from_highest->from) > 0)) {
|
|
|
|
from_highest = rinfo_exist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a route in ECMP group, delete the old
|
|
|
|
* one that has a higher next-hop address. Lower IP is
|
|
|
|
* preferred.
|
|
|
|
*/
|
|
|
|
if (ripng->ecmp > 1 && from_highest &&
|
|
|
|
IPV6_ADDR_CMP(&from_highest->from, &rinfo_new->from) > 0) {
|
|
|
|
ripng_ecmp_delete(ripng, from_highest);
|
|
|
|
goto add_or_replace;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_or_replace:
|
2015-05-22 11:39:53 +02:00
|
|
|
rinfo = ripng_info_new();
|
|
|
|
memcpy(rinfo, rinfo_new, sizeof(struct ripng_info));
|
|
|
|
listnode_add(list, rinfo);
|
|
|
|
|
|
|
|
if (ripng_route_rte(rinfo)) {
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_timeout_update(ripng, rinfo);
|
|
|
|
ripng_zebra_ipv6_add(ripng, rp);
|
2015-05-22 11:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ripng_aggregate_increment(rp, rinfo);
|
|
|
|
|
|
|
|
/* Set the route change flag on the first entry. */
|
|
|
|
rinfo = listgetdata(listhead(list));
|
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2015-05-22 11:39:53 +02:00
|
|
|
|
|
|
|
return rinfo;
|
|
|
|
}
|
|
|
|
|
2023-05-16 09:34:22 +02:00
|
|
|
/* Update ECMP routes to zebra when `allow-ecmp` changed. */
|
|
|
|
void ripng_ecmp_change(struct ripng *ripng)
|
|
|
|
{
|
|
|
|
struct agg_node *rp;
|
|
|
|
struct ripng_info *rinfo;
|
|
|
|
struct list *list;
|
|
|
|
struct listnode *node, *nextnode;
|
|
|
|
|
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
|
|
|
|
list = rp->info;
|
|
|
|
if (list && listcount(list) > 1) {
|
|
|
|
while (listcount(list) > ripng->ecmp) {
|
|
|
|
struct ripng_info *from_highest = NULL;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS(list, node, nextnode,
|
|
|
|
rinfo)) {
|
|
|
|
if (!from_highest ||
|
|
|
|
(from_highest &&
|
|
|
|
IPV6_ADDR_CMP(
|
|
|
|
&rinfo->from,
|
|
|
|
&from_highest->from) > 0))
|
|
|
|
from_highest = rinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
ripng_ecmp_delete(ripng, from_highest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Replace the ECMP list with the new route.
|
|
|
|
* RETURN: the new entry added in the list
|
|
|
|
*/
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_info *ripng_ecmp_replace(struct ripng *ripng,
|
|
|
|
struct ripng_info *rinfo_new)
|
2015-05-22 11:39:53 +02:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp = rinfo_new->rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = (struct list *)rp->info;
|
|
|
|
struct ripng_info *rinfo = NULL, *tmp_rinfo = NULL;
|
|
|
|
struct listnode *node = NULL, *nextnode = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (list == NULL || listcount(list) == 0)
|
2019-01-04 22:08:10 +01:00
|
|
|
return ripng_ecmp_add(ripng, rinfo_new);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Get the first entry */
|
|
|
|
rinfo = listgetdata(listhead(list));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Learnt route replaced by a local one. Delete it from zebra. */
|
|
|
|
if (ripng_route_rte(rinfo) && !ripng_route_rte(rinfo_new))
|
|
|
|
if (CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_zebra_ipv6_delete(ripng, rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (rinfo->metric != RIPNG_METRIC_INFINITY)
|
|
|
|
ripng_aggregate_decrement_list(rp, list);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Re-use the first entry, and delete the others. */
|
|
|
|
for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo != rinfo) {
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(tmp_rinfo->t_timeout);
|
|
|
|
EVENT_OFF(tmp_rinfo->t_garbage_collect);
|
2015-05-22 11:39:53 +02:00
|
|
|
list_delete_node(list, node);
|
|
|
|
ripng_info_free(tmp_rinfo);
|
|
|
|
}
|
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
|
|
|
EVENT_OFF(rinfo->t_garbage_collect);
|
2015-05-22 11:39:53 +02:00
|
|
|
memcpy(rinfo, rinfo_new, sizeof(struct ripng_info));
|
|
|
|
|
|
|
|
if (ripng_route_rte(rinfo)) {
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_timeout_update(ripng, rinfo);
|
2015-05-22 11:39:53 +02:00
|
|
|
/* The ADD message implies an update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_zebra_ipv6_add(ripng, rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
ripng_aggregate_increment(rp, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Set the route change flag. */
|
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
return rinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete one route from the ECMP list.
|
|
|
|
* RETURN:
|
|
|
|
* null - the entry is freed, and other entries exist in the list
|
|
|
|
* the entry - the entry is the last one in the list; its metric is set
|
|
|
|
* to INFINITY, and the garbage collector is started for it
|
|
|
|
*/
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
|
|
|
|
struct ripng_info *rinfo)
|
2015-05-22 11:39:53 +02:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp = rinfo->rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = (struct list *)rp->info;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (rinfo->metric != RIPNG_METRIC_INFINITY)
|
|
|
|
ripng_aggregate_decrement(rp, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (listcount(list) > 1) {
|
|
|
|
/* Some other ECMP entries still exist. Just delete this entry.
|
|
|
|
*/
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_garbage_collect);
|
2015-05-22 11:39:53 +02:00
|
|
|
listnode_delete(list, rinfo);
|
2023-06-14 20:24:07 +02:00
|
|
|
if (ripng_route_rte(rinfo) &&
|
|
|
|
CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
|
2015-05-22 11:39:53 +02:00
|
|
|
/* The ADD message implies the update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_zebra_ipv6_add(ripng, rp);
|
2015-05-22 11:39:53 +02:00
|
|
|
ripng_info_free(rinfo);
|
|
|
|
rinfo = NULL;
|
|
|
|
} else {
|
|
|
|
assert(rinfo == listgetdata(listhead(list)));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* This is the only entry left in the list. We must keep it in
|
|
|
|
* the list for garbage collection time, with INFINITY metric.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
rinfo->metric = RIPNG_METRIC_INFINITY;
|
|
|
|
RIPNG_TIMER_ON(rinfo->t_garbage_collect, ripng_garbage_collect,
|
|
|
|
ripng->garbage_time);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-06-14 20:24:07 +02:00
|
|
|
if (ripng_route_rte(rinfo) &&
|
|
|
|
CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_zebra_ipv6_delete(ripng, rp);
|
2015-05-22 11:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the route change flag on the first entry. */
|
|
|
|
rinfo = listgetdata(listhead(list));
|
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2015-05-22 11:39:53 +02:00
|
|
|
|
|
|
|
return rinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Timeout RIPng routes. */
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_timeout(struct event *t)
|
2015-05-22 11:39:53 +02:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct ripng_info *rinfo = EVENT_ARG(t);
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng = ripng_info_get_instance(rinfo);
|
|
|
|
|
|
|
|
ripng_ecmp_delete(ripng, rinfo);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
static void ripng_timeout_update(struct ripng *ripng, struct ripng_info *rinfo)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (rinfo->metric != RIPNG_METRIC_INFINITY) {
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, ripng_timeout, rinfo,
|
|
|
|
ripng->timeout_time, &rinfo->t_timeout);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 23:11:06 +02:00
|
|
|
static int ripng_filter(int ripng_distribute, struct prefix_ipv6 *p,
|
|
|
|
struct ripng_interface *ri)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct distribute *dist;
|
|
|
|
struct access_list *alist;
|
|
|
|
struct prefix_list *plist;
|
2016-09-22 23:11:06 +02:00
|
|
|
int distribute = ripng_distribute == RIPNG_FILTER_OUT
|
2016-09-22 23:11:07 +02:00
|
|
|
? DISTRIBUTE_V6_OUT
|
|
|
|
: DISTRIBUTE_V6_IN;
|
2016-09-22 23:11:06 +02:00
|
|
|
const char *inout = ripng_distribute == RIPNG_FILTER_OUT ? "out" : "in";
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Input distribute-list filtering. */
|
2016-09-22 23:11:06 +02:00
|
|
|
if (ri->list[ripng_distribute]) {
|
|
|
|
if (access_list_apply(ri->list[ripng_distribute],
|
2023-06-14 20:24:07 +02:00
|
|
|
(struct prefix *)p) == FILTER_DENY) {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2020-10-14 19:16:23 +02:00
|
|
|
zlog_debug("%pFX filtered by distribute %s", p,
|
2016-09-22 23:11:06 +02:00
|
|
|
inout);
|
2003-05-25 19:10:12 +02:00
|
|
|
return -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-22 23:11:06 +02:00
|
|
|
if (ri->prefix[ripng_distribute]) {
|
|
|
|
if (prefix_list_apply(ri->prefix[ripng_distribute],
|
2023-06-14 20:24:07 +02:00
|
|
|
(struct prefix *)p) == PREFIX_DENY) {
|
2016-09-22 23:11:06 +02:00
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2020-10-14 19:16:23 +02:00
|
|
|
zlog_debug("%pFX filtered by prefix-list %s", p,
|
2017-07-17 14:03:14 +02:00
|
|
|
inout);
|
2003-05-25 19:10:12 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All interface filter check. */
|
2019-01-04 22:08:10 +01:00
|
|
|
dist = distribute_lookup(ri->ripng->distribute_ctx, NULL);
|
2003-05-25 19:10:12 +02:00
|
|
|
if (dist) {
|
2016-09-22 23:11:06 +02:00
|
|
|
if (dist->list[distribute]) {
|
|
|
|
alist = access_list_lookup(AFI_IP6,
|
|
|
|
dist->list[distribute]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (alist) {
|
|
|
|
if (access_list_apply(alist, (struct prefix *)p)
|
|
|
|
== FILTER_DENY) {
|
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2016-09-22 23:11:06 +02:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"%pFX filtered by distribute %s",
|
|
|
|
p, inout);
|
2003-05-25 19:10:12 +02:00
|
|
|
return -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
2016-09-22 23:11:06 +02:00
|
|
|
if (dist->prefix[distribute]) {
|
|
|
|
plist = prefix_list_lookup(AFI_IP6,
|
|
|
|
dist->prefix[distribute]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (plist) {
|
|
|
|
if (prefix_list_apply(plist, (struct prefix *)p)
|
|
|
|
== PREFIX_DENY) {
|
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2016-09-22 23:11:06 +02:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"%pFX filtered by prefix-list %s",
|
|
|
|
p, inout);
|
2003-05-25 19:10:12 +02:00
|
|
|
return -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Process RIPng route according to RFC2080. */
|
|
|
|
static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from,
|
|
|
|
struct ripng_nexthop *ripng_nexthop,
|
|
|
|
struct interface *ifp)
|
|
|
|
{
|
2003-05-25 19:10:12 +02:00
|
|
|
int ret;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct prefix_ipv6 p;
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *rinfo = NULL, newinfo;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_interface *ri;
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in6_addr *nexthop;
|
|
|
|
int same = 0;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *node = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make prefix structure. */
|
|
|
|
memset(&p, 0, sizeof(struct prefix_ipv6));
|
|
|
|
p.family = AF_INET6;
|
|
|
|
/* p.prefix = rte->addr; */
|
|
|
|
IPV6_ADDR_COPY(&p.prefix, &rte->addr);
|
|
|
|
p.prefixlen = rte->prefixlen;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make sure mask is applied. */
|
|
|
|
/* XXX We have to check the prefix is valid or not before call
|
|
|
|
apply_mask_ipv6. */
|
|
|
|
apply_mask_ipv6(&p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ri = ifp->info;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng = ri->ripng;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Apply input filters. */
|
2016-09-22 23:11:06 +02:00
|
|
|
ret = ripng_filter(RIPNG_FILTER_IN, &p, ri);
|
2015-05-22 11:39:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
memset(&newinfo, 0, sizeof(newinfo));
|
|
|
|
newinfo.type = ZEBRA_ROUTE_RIPNG;
|
|
|
|
newinfo.sub_type = RIPNG_ROUTE_RTE;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
|
|
|
|
newinfo.nexthop = ripng_nexthop->address;
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2015-05-22 11:39:53 +02:00
|
|
|
newinfo.nexthop = from->sin6_addr;
|
|
|
|
newinfo.from = from->sin6_addr;
|
2002-12-13 21:15:29 +01:00
|
|
|
newinfo.ifindex = ifp->ifindex;
|
2015-05-22 11:39:53 +02:00
|
|
|
newinfo.metric = rte->metric;
|
2002-12-13 21:15:29 +01:00
|
|
|
newinfo.metric_out = rte->metric; /* XXX */
|
2004-12-08 20:51:16 +01:00
|
|
|
newinfo.tag = ntohs(rte->tag); /* XXX */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-12-08 20:51:16 +01:00
|
|
|
/* Modify entry. */
|
|
|
|
if (ri->routemap[RIPNG_FILTER_IN]) {
|
2003-05-25 19:10:12 +02:00
|
|
|
ret = route_map_apply(ri->routemap[RIPNG_FILTER_IN],
|
2020-11-14 01:35:20 +01:00
|
|
|
(struct prefix *)&p, &newinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (ret == RMAP_DENYMATCH) {
|
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
|
|
|
zlog_debug(
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng %pFX is filtered by route-map in",
|
|
|
|
&p);
|
2003-05-25 19:10:12 +02:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Get back the object */
|
|
|
|
if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS) {
|
|
|
|
if (!IPV6_ADDR_SAME(&newinfo.nexthop,
|
|
|
|
&ripng_nexthop->address)) {
|
2002-12-13 21:15:29 +01:00
|
|
|
/* the nexthop get changed by the routemap */
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop))
|
|
|
|
ripng_nexthop->address =
|
|
|
|
newinfo.nexthop;
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng_nexthop->address = in6addr_any;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2015-05-22 11:39:53 +02:00
|
|
|
} else {
|
|
|
|
if (!IPV6_ADDR_SAME(&newinfo.nexthop,
|
|
|
|
&from->sin6_addr)) {
|
|
|
|
/* the nexthop get changed by the routemap */
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop)) {
|
|
|
|
ripng_nexthop->flag =
|
|
|
|
RIPNG_NEXTHOP_ADDRESS;
|
|
|
|
ripng_nexthop->address =
|
|
|
|
newinfo.nexthop;
|
|
|
|
}
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
rte->tag = htons(newinfo.tag_out); /* XXX */
|
2023-06-14 20:24:07 +02:00
|
|
|
rte->metric = newinfo.metric_out; /* XXX: the routemap uses the
|
|
|
|
metric_out field */
|
2015-05-22 11:39:53 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Once the entry has been validated, update the metric by
|
|
|
|
* adding the cost of the network on wich the message
|
|
|
|
* arrived. If the result is greater than infinity, use infinity
|
|
|
|
* (RFC2453 Sec. 3.9.2)
|
2017-07-17 14:03:14 +02:00
|
|
|
**/
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Zebra ripngd can handle offset-list in. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ret = ripng_offset_list_apply_in(ripng, &p, ifp, &rte->metric);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* If offset-list does not modify the metric use interface's
|
2003-05-25 19:10:12 +02:00
|
|
|
* one. */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (!ret)
|
|
|
|
rte->metric += ifp->metric ? ifp->metric : 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rte->metric > RIPNG_METRIC_INFINITY)
|
2015-05-22 11:39:53 +02:00
|
|
|
rte->metric = RIPNG_METRIC_INFINITY;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Set nexthop pointer. */
|
|
|
|
if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
|
|
|
|
nexthop = &ripng_nexthop->address;
|
|
|
|
else
|
|
|
|
nexthop = &from->sin6_addr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Lookup RIPng routing table. */
|
2018-08-03 19:22:48 +02:00
|
|
|
rp = agg_node_get(ripng->table, (struct prefix *)&p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
newinfo.rp = rp;
|
2016-11-16 19:14:45 +01:00
|
|
|
newinfo.nexthop = *nexthop;
|
|
|
|
newinfo.metric = rte->metric;
|
|
|
|
newinfo.tag = ntohs(rte->tag);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-11-16 19:14:45 +01:00
|
|
|
/* Check to see whether there is already RIPng route on the table. */
|
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
|
|
|
|
/* Need to compare with redistributed entry or local
|
|
|
|
* entry */
|
|
|
|
if (!ripng_route_rte(rinfo))
|
|
|
|
break;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IPV6_ADDR_SAME(&rinfo->from, &from->sin6_addr)
|
|
|
|
&& IPV6_ADDR_SAME(&rinfo->nexthop, nexthop))
|
|
|
|
break;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (!listnextnode(node)) {
|
|
|
|
/* Not found in the list */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-11-16 19:14:45 +01:00
|
|
|
if (rte->metric > rinfo->metric) {
|
2015-05-22 11:39:53 +02:00
|
|
|
/* New route has a greater metric.
|
|
|
|
* Discard it. */
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2015-05-22 11:39:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (rte->metric < rinfo->metric)
|
|
|
|
/* New route has a smaller metric.
|
|
|
|
* Replace the ECMP list
|
|
|
|
* with the new one in below. */
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Metrics are same. Unless ECMP is disabled,
|
|
|
|
* keep "rinfo" null and
|
2002-12-13 21:15:29 +01:00
|
|
|
* the new route is added in the ECMP list in
|
|
|
|
* below. */
|
|
|
|
if (!ripng->ecmp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rinfo) {
|
|
|
|
/* Redistributed route check. */
|
|
|
|
if (rinfo->type != ZEBRA_ROUTE_RIPNG
|
2003-05-25 19:10:12 +02:00
|
|
|
&& rinfo->metric != RIPNG_METRIC_INFINITY) {
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2003-05-25 19:10:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Local static route. */
|
|
|
|
if (rinfo->type == ZEBRA_ROUTE_RIPNG
|
2004-12-08 20:51:16 +01:00
|
|
|
&& ((rinfo->sub_type == RIPNG_ROUTE_STATIC)
|
|
|
|
|| (rinfo->sub_type == RIPNG_ROUTE_DEFAULT))
|
|
|
|
&& rinfo->metric != RIPNG_METRIC_INFINITY) {
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-03-11 13:47:46 +01:00
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (!rinfo) {
|
|
|
|
/* Now, check to see whether there is already an explicit route
|
2015-05-22 11:39:54 +02:00
|
|
|
for the destination prefix. If there is no such route, add
|
2002-12-13 21:15:29 +01:00
|
|
|
this route to the routing table, unless the metric is
|
|
|
|
infinity (there is no point in adding a route which
|
|
|
|
unusable). */
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rte->metric != RIPNG_METRIC_INFINITY)
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_add(ripng, &newinfo);
|
2017-10-04 13:55:58 +02:00
|
|
|
else
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
2003-05-25 19:10:12 +02:00
|
|
|
/* If there is an existing route, compare the next hop address
|
2002-12-13 21:15:29 +01:00
|
|
|
to the address of the router from which the datagram came.
|
|
|
|
If this datagram is from the same router as the existing
|
|
|
|
route, reinitialize the timeout. */
|
2015-05-22 11:39:53 +02:00
|
|
|
same = (IN6_ARE_ADDR_EQUAL(&rinfo->from, &from->sin6_addr)
|
2003-05-25 19:10:12 +02:00
|
|
|
&& (rinfo->ifindex == ifp->ifindex));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/*
|
2016-11-16 19:14:45 +01:00
|
|
|
* RFC 2080 - Section 2.4.2:
|
|
|
|
* "If the new metric is the same as the old one, examine the
|
2015-05-22 11:39:53 +02:00
|
|
|
* timeout
|
2015-05-22 11:39:54 +02:00
|
|
|
* for the existing route. If it is at least halfway to the
|
2017-07-17 14:03:14 +02:00
|
|
|
* expiration
|
2016-11-16 19:14:45 +01:00
|
|
|
* point, switch to the new route. This heuristic is optional,
|
2017-07-17 14:03:14 +02:00
|
|
|
* but
|
2003-05-25 19:10:12 +02:00
|
|
|
* highly recommended".
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2022-12-11 14:19:00 +01:00
|
|
|
if (!ripng->ecmp && !same && rinfo->metric == rte->metric &&
|
|
|
|
rinfo->t_timeout &&
|
|
|
|
(event_timer_remain_second(rinfo->t_timeout) <
|
|
|
|
(ripng->timeout_time / 2))) {
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_replace(ripng, &newinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Next, compare the metrics. If the datagram is from the same
|
2003-05-25 19:10:12 +02:00
|
|
|
router as the existing route, and the new metric is different
|
2002-12-13 21:15:29 +01:00
|
|
|
than the old one; or, if the new metric is lower than the old
|
|
|
|
one; do the following actions: */
|
2022-12-11 14:19:00 +01:00
|
|
|
else if ((same && rinfo->metric != rte->metric) ||
|
|
|
|
rte->metric < rinfo->metric) {
|
2015-05-22 11:39:53 +02:00
|
|
|
if (listcount(list) == 1) {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (newinfo.metric != RIPNG_METRIC_INFINITY)
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_replace(ripng, &newinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_delete(ripng, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (newinfo.metric < rinfo->metric)
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_replace(ripng, &newinfo);
|
2015-05-22 11:39:53 +02:00
|
|
|
else /* newinfo.metric > rinfo->metric */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_delete(ripng, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
} else /* same & no change */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_timeout_update(ripng, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Unlock tempolary lock of the route. */
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add redistributed route to RIPng table. */
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_redistribute_add(struct ripng *ripng, int type, int sub_type,
|
|
|
|
struct prefix_ipv6 *p, ifindex_t ifindex,
|
|
|
|
struct in6_addr *nexthop, route_tag_t tag)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_info *rinfo = NULL, newinfo;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Redistribute route */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&p->prefix))
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IN6_IS_ADDR_LOOPBACK(&p->prefix))
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
rp = agg_node_get(ripng->table, (struct prefix *)p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&newinfo, 0, sizeof(newinfo));
|
2015-05-22 11:39:53 +02:00
|
|
|
newinfo.type = type;
|
|
|
|
newinfo.sub_type = sub_type;
|
|
|
|
newinfo.ifindex = ifindex;
|
|
|
|
newinfo.metric = 1;
|
2016-10-01 22:35:32 +02:00
|
|
|
if (tag <= UINT16_MAX) /* RIPng only supports 16 bit tags */
|
|
|
|
newinfo.tag = tag;
|
2015-05-22 11:39:53 +02:00
|
|
|
newinfo.rp = rp;
|
|
|
|
if (nexthop && IN6_IS_ADDR_LINKLOCAL(nexthop))
|
|
|
|
newinfo.nexthop = *nexthop;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if ((list = rp->info) != NULL && listcount(list) != 0) {
|
|
|
|
rinfo = listgetdata(listhead(list));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rinfo->type == ZEBRA_ROUTE_CONNECT
|
|
|
|
&& rinfo->sub_type == RIPNG_ROUTE_INTERFACE
|
|
|
|
&& rinfo->metric != RIPNG_METRIC_INFINITY) {
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Manually configured RIPng route check.
|
|
|
|
* They have the precedence on all the other entries.
|
2017-07-17 14:03:14 +02:00
|
|
|
**/
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rinfo->type == ZEBRA_ROUTE_RIPNG
|
|
|
|
&& ((rinfo->sub_type == RIPNG_ROUTE_STATIC)
|
|
|
|
|| (rinfo->sub_type == RIPNG_ROUTE_DEFAULT))) {
|
|
|
|
if (type != ZEBRA_ROUTE_RIPNG
|
|
|
|
|| ((sub_type != RIPNG_ROUTE_STATIC)
|
|
|
|
&& (sub_type != RIPNG_ROUTE_DEFAULT))) {
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_replace(ripng, &newinfo);
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
} else
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_ecmp_add(ripng, &newinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IS_RIPNG_DEBUG_EVENT) {
|
|
|
|
if (!nexthop)
|
2015-05-22 11:39:53 +02:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"Redistribute new prefix %pFX on the interface %s",
|
|
|
|
p, ifindex2ifname(ifindex, ripng->vrf->vrf_id));
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2002-12-13 21:15:29 +01:00
|
|
|
zlog_debug(
|
2021-03-31 14:28:30 +02:00
|
|
|
"Redistribute new prefix %pFX with nexthop %pI6 on the interface %s",
|
|
|
|
p, nexthop,
|
2019-01-04 22:08:10 +01:00
|
|
|
ifindex2ifname(ifindex, ripng->vrf->vrf_id));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Delete redistributed route to RIPng table. */
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_redistribute_delete(struct ripng *ripng, int type, int sub_type,
|
|
|
|
struct prefix_ipv6 *p, ifindex_t ifindex)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *rinfo;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&p->prefix))
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IN6_IS_ADDR_LOOPBACK(&p->prefix))
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
rp = agg_node_lookup(ripng->table, (struct prefix *)p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rp) {
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = rp->info;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (list != NULL && listcount(list) != 0) {
|
|
|
|
rinfo = listgetdata(listhead(list));
|
|
|
|
if (rinfo != NULL && rinfo->type == type
|
|
|
|
&& rinfo->sub_type == sub_type
|
|
|
|
&& rinfo->ifindex == ifindex) {
|
|
|
|
/* Perform poisoned reverse. */
|
|
|
|
rinfo->metric = RIPNG_METRIC_INFINITY;
|
|
|
|
RIPNG_TIMER_ON(rinfo->t_garbage_collect,
|
|
|
|
ripng_garbage_collect,
|
|
|
|
ripng->garbage_time);
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
/* Aggregate count decrement. */
|
|
|
|
ripng_aggregate_decrement(rp, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-06-14 20:24:07 +02:00
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"Poisone %pFX on the interface %s with an infinity metric [delete]",
|
|
|
|
p,
|
2019-01-04 22:08:10 +01:00
|
|
|
ifindex2ifname(
|
|
|
|
ifindex,
|
|
|
|
ripng->vrf->vrf_id));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2015-05-22 11:39:53 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Withdraw redistributed route. */
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_redistribute_withdraw(struct ripng *ripng, int type)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp))
|
2015-05-22 11:39:53 +02:00
|
|
|
if ((list = rp->info) != NULL) {
|
|
|
|
rinfo = listgetdata(listhead(list));
|
2003-05-25 19:10:12 +02:00
|
|
|
if ((rinfo->type == type)
|
|
|
|
&& (rinfo->sub_type != RIPNG_ROUTE_INTERFACE)) {
|
|
|
|
/* Perform poisoned reverse. */
|
|
|
|
rinfo->metric = RIPNG_METRIC_INFINITY;
|
|
|
|
RIPNG_TIMER_ON(rinfo->t_garbage_collect,
|
|
|
|
ripng_garbage_collect,
|
|
|
|
ripng->garbage_time);
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Aggregate count decrement. */
|
|
|
|
ripng_aggregate_decrement(rp, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-06-14 20:24:07 +02:00
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (IS_RIPNG_DEBUG_EVENT) {
|
|
|
|
struct prefix_ipv6 *p =
|
2020-03-22 04:37:24 +01:00
|
|
|
(struct prefix_ipv6 *)
|
|
|
|
agg_node_get_prefix(rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"Poisone %pFX on the interface %s [withdraw]",
|
|
|
|
p,
|
2019-01-04 22:08:10 +01:00
|
|
|
ifindex2ifname(
|
|
|
|
rinfo->ifindex,
|
|
|
|
ripng->vrf->vrf_id));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* RIP routing information. */
|
|
|
|
static void ripng_response_process(struct ripng_packet *packet, int size,
|
|
|
|
struct sockaddr_in6 *from,
|
|
|
|
struct interface *ifp, int hoplimit)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_interface *ri = ifp->info;
|
|
|
|
struct ripng *ripng = ri->ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
caddr_t lim;
|
|
|
|
struct rte *rte;
|
|
|
|
struct ripng_nexthop nexthop;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RFC2080 2.4.2 Response Messages:
|
2015-05-22 11:39:53 +02:00
|
|
|
The Response must be ignored if it is not from the RIPng port. */
|
2003-05-25 19:10:12 +02:00
|
|
|
if (ntohs(from->sin6_port) != RIPNG_PORT_DEFAULT) {
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("RIPng packet comes from non RIPng port %d from %pI6",
|
|
|
|
ntohs(from->sin6_port), &from->sin6_addr);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, from);
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* The datagram's IPv6 source address should be checked to see
|
2002-12-13 21:15:29 +01:00
|
|
|
whether the datagram is from a valid neighbor; the source of the
|
2003-05-25 19:10:12 +02:00
|
|
|
datagram must be a link-local address. */
|
|
|
|
if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("RIPng packet comes from non link local address %pI6",
|
|
|
|
&from->sin6_addr);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, from);
|
2003-05-25 19:10:12 +02:00
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* It is also worth checking to see whether the response is from one
|
2002-12-13 21:15:29 +01:00
|
|
|
of the router's own addresses. Interfaces on broadcast networks
|
|
|
|
may receive copies of their own multicasts immediately. If a
|
2003-05-25 19:10:12 +02:00
|
|
|
router processes its own output as new input, confusion is likely,
|
|
|
|
and such datagrams must be ignored. */
|
|
|
|
if (ripng_lladdr_check(ifp, &from->sin6_addr)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng packet comes from my own link local address %pI6",
|
|
|
|
&from->sin6_addr);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, from);
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* As an additional check, periodic advertisements must have their
|
2003-05-25 19:10:12 +02:00
|
|
|
hop counts set to 255, and inbound, multicast packets sent from the
|
|
|
|
RIPng port (i.e. periodic advertisement or triggered update
|
|
|
|
packets) must be examined to ensure that the hop count is 255. */
|
|
|
|
if (hoplimit >= 0 && hoplimit != 255) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng packet comes with non 255 hop count %d from %pI6",
|
|
|
|
hoplimit, &from->sin6_addr);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, from);
|
2003-05-25 19:10:12 +02:00
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-12-08 20:51:16 +01:00
|
|
|
/* Update RIPng peer. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_update(ripng, from, packet->version);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* Reset nexthop. */
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&nexthop, 0, sizeof(nexthop));
|
2003-05-25 19:10:12 +02:00
|
|
|
nexthop.flag = RIPNG_NEXTHOP_UNSPEC;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Set RTE pointer. */
|
|
|
|
rte = packet->rte;
|
|
|
|
|
|
|
|
for (lim = ((caddr_t)packet) + size; (caddr_t)rte < lim; rte++) {
|
|
|
|
/* First of all, we have to check this RTE is next hop RTE or
|
|
|
|
not. Next hop RTE is completely different with normal RTE so
|
|
|
|
we need special treatment. */
|
|
|
|
if (rte->metric == RIPNG_METRIC_NEXTHOP) {
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_nexthop_rte(rte, from, &nexthop);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RTE information validation. */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* - is the destination prefix valid (e.g., not a multicast
|
|
|
|
prefix and not a link-local address) A link-local address
|
|
|
|
should never be present in an RTE. */
|
|
|
|
if (IN6_IS_ADDR_MULTICAST(&rte->addr)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"Destination prefix is a multicast address %pI6/%d [%d]",
|
|
|
|
&rte->addr, rte->prefixlen, rte->metric);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_route(ripng, from);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&rte->addr)) {
|
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"Destination prefix is a link-local address %pI6/%d [%d]",
|
|
|
|
&rte->addr, rte->prefixlen, rte->metric);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_route(ripng, from);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2005-04-08 03:30:51 +02:00
|
|
|
if (IN6_IS_ADDR_LOOPBACK(&rte->addr)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2021-03-31 14:28:30 +02:00
|
|
|
"Destination prefix is a loopback address %pI6/%d [%d]",
|
|
|
|
&rte->addr, rte->prefixlen, rte->metric);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_route(ripng, from);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - is the prefix length valid (i.e., between 0 and 128,
|
|
|
|
inclusive) */
|
2021-07-01 16:53:21 +02:00
|
|
|
if (rte->prefixlen > IPV6_MAX_BITLEN) {
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("Invalid prefix length %pI6/%d from %pI6%%%s",
|
|
|
|
&rte->addr, rte->prefixlen,
|
|
|
|
&from->sin6_addr, ifp->name);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_route(ripng, from);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* - is the metric valid (i.e., between 1 and 16, inclusive) */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (!(rte->metric >= 1 && rte->metric <= 16)) {
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("Invalid metric %d from %pI6%%%s",
|
|
|
|
rte->metric, &from->sin6_addr, ifp->name);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_route(ripng, from);
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Vincent: XXX Should we compute the direclty reachable nexthop
|
|
|
|
* for our RIPng network ?
|
|
|
|
**/
|
|
|
|
|
|
|
|
/* Routing table updates. */
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_route_process(rte, from, &nexthop, ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Response to request message. */
|
|
|
|
static void ripng_request_process(struct ripng_packet *packet, int size,
|
|
|
|
struct sockaddr_in6 *from,
|
|
|
|
struct interface *ifp)
|
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
caddr_t lim;
|
|
|
|
struct rte *rte;
|
|
|
|
struct prefix_ipv6 p;
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_info *rinfo;
|
|
|
|
struct ripng_interface *ri;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Does not reponse to the requests on the loopback interfaces */
|
|
|
|
if (if_is_loopback(ifp))
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Check RIPng process is enabled on this interface. */
|
|
|
|
ri = ifp->info;
|
|
|
|
if (!ri->running)
|
|
|
|
return;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng = ri->ripng;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* When passive interface is specified, suppress responses */
|
|
|
|
if (ri->passive)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* RIPng peer update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_update(ripng, from, packet->version);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
lim = ((caddr_t)packet) + size;
|
|
|
|
rte = packet->rte;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* The Request is processed entry by entry. If there are no
|
|
|
|
entries, no response is given. */
|
|
|
|
if (lim == (caddr_t)rte)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* There is one special case. If there is exactly one entry in the
|
|
|
|
request, and it has a destination prefix of zero, a prefix length
|
|
|
|
of zero, and a metric of infinity (i.e., 16), then this is a
|
|
|
|
request to send the entire routing table. In that case, a call
|
|
|
|
is made to the output process to send the routing table to the
|
|
|
|
requesting address/port. */
|
|
|
|
if (lim == ((caddr_t)(rte + 1)) && IN6_IS_ADDR_UNSPECIFIED(&rte->addr)
|
|
|
|
&& rte->prefixlen == 0 && rte->metric == RIPNG_METRIC_INFINITY) {
|
|
|
|
/* All route with split horizon */
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_output_process(ifp, from, ripng_all_route);
|
2002-12-13 21:15:29 +01:00
|
|
|
} else {
|
|
|
|
/* Except for this special case, processing is quite simple.
|
|
|
|
Examine the list of RTEs in the Request one by one. For each
|
|
|
|
entry, look up the destination in the router's routing
|
|
|
|
database and, if there is a route, put that route's metric in
|
|
|
|
the metric field of the RTE. If there is no explicit route
|
|
|
|
to the specified destination, put infinity in the metric
|
|
|
|
field. Once all the entries have been filled in, change the
|
|
|
|
command from Request to Response and send the datagram back
|
|
|
|
to the requestor. */
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&p, 0, sizeof(p));
|
2002-12-13 21:15:29 +01:00
|
|
|
p.family = AF_INET6;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
for (; ((caddr_t)rte) < lim; rte++) {
|
|
|
|
p.prefix = rte->addr;
|
|
|
|
p.prefixlen = rte->prefixlen;
|
|
|
|
apply_mask_ipv6(&p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
rp = agg_node_lookup(ripng->table, (struct prefix *)&p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rp) {
|
2015-05-22 11:39:53 +02:00
|
|
|
rinfo = listgetdata(
|
|
|
|
listhead((struct list *)rp->info));
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->metric = rinfo->metric;
|
2018-08-03 19:22:48 +02:00
|
|
|
agg_unlock_node(rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
} else
|
|
|
|
rte->metric = RIPNG_METRIC_INFINITY;
|
|
|
|
}
|
|
|
|
packet->command = RIPNG_RESPONSE;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng_send_packet((caddr_t)packet, size, from, ifp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First entry point of reading RIPng packet. */
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_read(struct event *thread)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct ripng *ripng = EVENT_ARG(thread);
|
2002-12-13 21:15:29 +01:00
|
|
|
int len;
|
|
|
|
int sock;
|
|
|
|
struct sockaddr_in6 from;
|
|
|
|
struct ripng_packet *packet;
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t ifindex = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
int hoplimit = -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Check ripng is active and alive. */
|
|
|
|
assert(ripng != NULL);
|
|
|
|
assert(ripng->sock >= 0);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Fetch thread data and set read pointer to empty for event
|
|
|
|
managing. `sock' sould be same as ripng->sock. */
|
2022-12-25 16:26:52 +01:00
|
|
|
sock = EVENT_FD(thread);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Add myself to the next event. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_READ, sock);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Read RIPng packet. */
|
|
|
|
len = ripng_recv_packet(sock, STREAM_DATA(ripng->ibuf),
|
|
|
|
STREAM_SIZE(ripng->ibuf), &from, &ifindex,
|
|
|
|
&hoplimit);
|
|
|
|
if (len < 0) {
|
2019-01-04 22:08:10 +01:00
|
|
|
zlog_warn("RIPng recvfrom failed (VRF %s): %s.",
|
|
|
|
ripng->vrf_name, safe_strerror(errno));
|
2022-02-23 01:04:25 +01:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check RTE boundary. RTE size (Packet length - RIPng header size
|
|
|
|
(4)) must be multiple size of one RTE size (20). */
|
|
|
|
if (((len - 4) % 20) != 0) {
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_warn("RIPng invalid packet size %d from %pI6 (VRF %s)",
|
|
|
|
len, &from.sin6_addr, ripng->vrf_name);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, &from);
|
2022-02-23 01:04:25 +01:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
packet = (struct ripng_packet *)STREAM_DATA(ripng->ibuf);
|
2019-01-04 22:08:10 +01:00
|
|
|
ifp = if_lookup_by_index(ifindex, ripng->vrf->vrf_id);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* RIPng packet received. */
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
2019-01-04 22:08:10 +01:00
|
|
|
zlog_debug(
|
2021-03-31 14:28:30 +02:00
|
|
|
"RIPng packet received from %pI6 port %d on %s (VRF %s)",
|
|
|
|
&from.sin6_addr, ntohs(from.sin6_port),
|
2019-01-04 22:08:10 +01:00
|
|
|
ifp ? ifp->name : "unknown", ripng->vrf_name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Logging before packet checking. */
|
|
|
|
if (IS_RIPNG_DEBUG_RECV)
|
|
|
|
ripng_packet_dump(packet, len, "RECV");
|
|
|
|
|
|
|
|
/* Packet comes from unknown interface. */
|
|
|
|
if (ifp == NULL) {
|
2019-01-04 22:08:10 +01:00
|
|
|
zlog_warn(
|
|
|
|
"RIPng packet comes from unknown interface %d (VRF %s)",
|
|
|
|
ifindex, ripng->vrf_name);
|
2022-02-23 01:04:25 +01:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Packet version mismatch checking. */
|
|
|
|
if (packet->version != ripng->version) {
|
|
|
|
zlog_warn(
|
2019-01-04 22:08:10 +01:00
|
|
|
"RIPng packet version %d doesn't fit to my version %d (VRF %s)",
|
|
|
|
packet->version, ripng->version, ripng->vrf_name);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, &from);
|
2022-02-23 01:04:25 +01:00
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process RIPng packet. */
|
|
|
|
switch (packet->command) {
|
|
|
|
case RIPNG_REQUEST:
|
|
|
|
ripng_request_process(packet, len, &from, ifp);
|
|
|
|
break;
|
|
|
|
case RIPNG_RESPONSE:
|
|
|
|
ripng_response_process(packet, len, &from, ifp, hoplimit);
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-04 22:08:10 +01:00
|
|
|
zlog_warn("Invalid RIPng command %d (VRF %s)", packet->command,
|
|
|
|
ripng->vrf_name);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_bad_packet(ripng, &from);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk down the RIPng routing table then clear changed flag. */
|
2019-01-04 22:08:10 +01:00
|
|
|
static void ripng_clear_changed_flag(struct ripng *ripng)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp))
|
2015-05-22 11:39:53 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
|
|
|
|
UNSET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
|
|
|
/* This flag can be set only on the first entry.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Regular update of RIPng route. Send all routing formation to RIPng
|
|
|
|
enabled interface. */
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_update(struct event *t)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct ripng *ripng = EVENT_ARG(t);
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct ripng_interface *ri;
|
|
|
|
|
|
|
|
/* Logging update event. */
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug("RIPng update timer expired!");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Supply routes to each interface. */
|
2019-01-04 22:08:10 +01:00
|
|
|
FOR_ALL_INTERFACES (ripng->vrf, ifp) {
|
2002-12-13 21:15:29 +01:00
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if (if_is_loopback(ifp) || !if_is_up(ifp))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!ri->running)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* When passive interface is specified, suppress announce to the
|
|
|
|
interface. */
|
|
|
|
if (ri->passive)
|
|
|
|
continue;
|
|
|
|
|
2020-03-10 16:50:03 +01:00
|
|
|
#ifdef RIPNG_ADVANCED
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ri->ri_send == RIPNG_SEND_OFF) {
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
*: get rid of zlog(*, LOG_LEVEL, ...)
Result of running the following Coccinelle patch + fixups:
<<EOF
/* long-forms: zlog(NULL, <level>, ...)
* => zlog_level(...)
*/
@@
expression list args;
@@
- zlog(NULL, LOG_DEBUG, args)
+ zlog_debug(args)
@@
expression list args;
@@
- zlog(NULL, LOG_NOTICE, args)
+ zlog_notice(args)
@@
expression list args;
@@
- zlog(NULL, LOG_INFO, args)
+ zlog_info(args)
@@
expression list args;
@@
- zlog(NULL, LOG_WARNING, args)
+ zlog_warn(args)
@@
expression list args;
@@
- zlog(NULL, LOG_ERR, args)
+ zlog_err(args)
/* long-forms: zlog(base->log, <level>, ...)
* => zlog_level(...)
*/
@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_DEBUG, args)
+ zlog_debug(args)
@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_NOTICE, args)
+ zlog_notice(args)
@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_INFO, args)
+ zlog_info(args)
@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_WARNING, args)
+ zlog_warn(args)
@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_ERR, args)
+ zlog_err(args)
EOF
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-13 04:19:14 +01:00
|
|
|
zlog_debug(
|
|
|
|
"[Event] RIPng send to if %d is suppressed by config",
|
2002-12-13 21:15:29 +01:00
|
|
|
ifp->ifindex);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* RIPNG_ADVANCED */
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_output_process(ifp, NULL, ripng_all_route);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Triggered updates may be suppressed if a regular update is due by
|
|
|
|
the time the triggered update would be sent. */
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(ripng->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng->trigger = 0;
|
|
|
|
|
|
|
|
/* Reset flush event. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_UPDATE_EVENT, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Triggered update interval timer. */
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_triggered_interval(struct event *t)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct ripng *ripng = EVENT_ARG(t);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ripng->trigger) {
|
|
|
|
ripng->trigger = 0;
|
|
|
|
ripng_triggered_update(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute triggered update. */
|
2022-03-01 22:18:12 +01:00
|
|
|
void ripng_triggered_update(struct event *t)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct ripng *ripng = EVENT_ARG(t);
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct ripng_interface *ri;
|
|
|
|
int interval;
|
|
|
|
|
|
|
|
/* Cancel interval timer. */
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(ripng->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng->trigger = 0;
|
|
|
|
|
|
|
|
/* Logging triggered update. */
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug("RIPng triggered update!");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Split Horizon processing is done when generating triggered
|
|
|
|
updates as well as normal updates (see section 2.6). */
|
2019-01-04 22:08:10 +01:00
|
|
|
FOR_ALL_INTERFACES (ripng->vrf, ifp) {
|
2002-12-13 21:15:29 +01:00
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if (if_is_loopback(ifp) || !if_is_up(ifp))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!ri->running)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* When passive interface is specified, suppress announce to the
|
|
|
|
interface. */
|
|
|
|
if (ri->passive)
|
|
|
|
continue;
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_output_process(ifp, NULL, ripng_changed_route);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Once all of the triggered updates have been generated, the route
|
|
|
|
change flags should be cleared. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_clear_changed_flag(ripng);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* After a triggered update is sent, a timer should be set for a
|
|
|
|
random interval between 1 and 5 seconds. If other changes that
|
|
|
|
would trigger updates occur before the timer expires, a single
|
|
|
|
update is triggered when the timer expires. */
|
2020-04-17 15:35:15 +02:00
|
|
|
interval = (frr_weak_random() % 5) + 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, ripng_triggered_interval, ripng, interval,
|
|
|
|
&ripng->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write routing table entry to the stream and return next index of
|
|
|
|
the routing table entry in the stream. */
|
|
|
|
int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
|
2018-03-27 21:13:34 +02:00
|
|
|
struct in6_addr *nexthop, uint16_t tag, uint8_t metric)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* RIPng packet header. */
|
|
|
|
if (num == 0) {
|
|
|
|
stream_putc(s, RIPNG_RESPONSE);
|
|
|
|
stream_putc(s, RIPNG_V1);
|
|
|
|
stream_putw(s, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write routing table entry. */
|
2018-07-03 15:39:50 +02:00
|
|
|
if (!nexthop) {
|
|
|
|
assert(p);
|
2018-03-27 21:13:34 +02:00
|
|
|
stream_write(s, (uint8_t *)&p->prefix, sizeof(struct in6_addr));
|
2018-07-03 15:39:50 +02:00
|
|
|
} else
|
2018-03-27 21:13:34 +02:00
|
|
|
stream_write(s, (uint8_t *)nexthop, sizeof(struct in6_addr));
|
2002-12-13 21:15:29 +01:00
|
|
|
stream_putw(s, tag);
|
2003-05-25 19:10:12 +02:00
|
|
|
if (p)
|
|
|
|
stream_putc(s, p->prefixlen);
|
|
|
|
else
|
|
|
|
stream_putc(s, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
stream_putc(s, metric);
|
|
|
|
|
|
|
|
return ++num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send RESPONSE message to specified destination. */
|
|
|
|
void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to,
|
2003-05-25 19:10:12 +02:00
|
|
|
int route_type)
|
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
int ret;
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_info *rinfo;
|
|
|
|
struct ripng_interface *ri;
|
2003-05-25 19:10:12 +02:00
|
|
|
struct ripng_aggregate *aggregate;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct prefix_ipv6 *p;
|
2016-09-22 23:11:06 +02:00
|
|
|
struct list *ripng_rte_list;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if (IS_RIPNG_DEBUG_EVENT) {
|
|
|
|
if (to)
|
2021-03-31 14:28:30 +02:00
|
|
|
zlog_debug("RIPng update routes to neighbor %pI6",
|
|
|
|
&to->sin6_addr);
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug("RIPng update routes on interface %s",
|
2003-05-25 19:10:12 +02:00
|
|
|
ifp->name);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Get RIPng interface and instance. */
|
2002-12-13 21:15:29 +01:00
|
|
|
ri = ifp->info;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng = ri->ripng;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_rte_list = ripng_rte_new();
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
|
2015-05-22 11:39:53 +02:00
|
|
|
if ((list = rp->info) != NULL
|
2003-05-25 19:10:12 +02:00
|
|
|
&& (rinfo = listgetdata(listhead(list))) != NULL
|
2015-05-22 11:39:53 +02:00
|
|
|
&& rinfo->suppress == 0) {
|
2003-05-25 19:10:12 +02:00
|
|
|
/* If no route-map are applied, the RTE will be these
|
|
|
|
* following
|
2018-10-25 20:06:59 +02:00
|
|
|
* information.
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2020-03-22 04:37:24 +01:00
|
|
|
p = (struct prefix_ipv6 *)agg_node_get_prefix(rp);
|
2003-05-25 19:10:12 +02:00
|
|
|
rinfo->metric_out = rinfo->metric;
|
|
|
|
rinfo->tag_out = rinfo->tag;
|
|
|
|
memset(&rinfo->nexthop_out, 0,
|
|
|
|
sizeof(rinfo->nexthop_out));
|
|
|
|
/* In order to avoid some local loops,
|
|
|
|
* if the RIPng route has a nexthop via this interface,
|
|
|
|
* keep the nexthop,
|
|
|
|
* otherwise set it to 0. The nexthop should not be
|
|
|
|
* propagated
|
|
|
|
* beyond the local broadcast/multicast area in order
|
|
|
|
* to avoid an IGP multi-level recursive look-up.
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rinfo->ifindex == ifp->ifindex)
|
|
|
|
rinfo->nexthop_out = rinfo->nexthop;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Apply output filters. */
|
2016-09-22 23:11:06 +02:00
|
|
|
ret = ripng_filter(RIPNG_FILTER_OUT, p, ri);
|
2003-05-25 19:10:12 +02:00
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Changed route only output. */
|
2023-06-14 20:24:07 +02:00
|
|
|
if (route_type == ripng_changed_route &&
|
|
|
|
(!CHECK_FLAG(rinfo->flags, RIPNG_RTF_CHANGED)))
|
2003-05-25 19:10:12 +02:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Split horizon. */
|
|
|
|
if (ri->split_horizon == RIPNG_SPLIT_HORIZON) {
|
2003-05-25 19:10:12 +02:00
|
|
|
/* We perform split horizon for RIPng routes. */
|
2015-05-22 11:39:53 +02:00
|
|
|
int suppress = 0;
|
|
|
|
struct ripng_info *tmp_rinfo = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, listnode,
|
|
|
|
tmp_rinfo))
|
2023-06-14 20:24:07 +02:00
|
|
|
if (tmp_rinfo->type ==
|
|
|
|
ZEBRA_ROUTE_RIPNG &&
|
|
|
|
tmp_rinfo->ifindex ==
|
|
|
|
ifp->ifindex) {
|
2015-05-22 11:39:53 +02:00
|
|
|
suppress = 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
if (suppress)
|
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Preparation for route-map. */
|
2003-05-25 19:10:12 +02:00
|
|
|
rinfo->metric_set = 0;
|
|
|
|
/* nexthop_out,
|
|
|
|
* metric_out
|
|
|
|
* and tag_out are already initialized.
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Interface route-map */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ri->routemap[RIPNG_FILTER_OUT]) {
|
2003-05-25 19:10:12 +02:00
|
|
|
ret = route_map_apply(
|
2002-12-13 21:15:29 +01:00
|
|
|
ri->routemap[RIPNG_FILTER_OUT],
|
2020-11-14 01:35:20 +01:00
|
|
|
(struct prefix *)p, rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret == RMAP_DENYMATCH) {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"RIPng %pFX is filtered by route-map out",
|
|
|
|
p);
|
2003-05-25 19:10:12 +02:00
|
|
|
continue;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Redistribute route-map. */
|
2019-01-04 22:08:10 +01:00
|
|
|
if (ripng->redist[rinfo->type].route_map.name) {
|
|
|
|
ret = route_map_apply(ripng->redist[rinfo->type]
|
|
|
|
.route_map.map,
|
|
|
|
(struct prefix *)p,
|
2020-11-14 01:35:20 +01:00
|
|
|
rinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret == RMAP_DENYMATCH) {
|
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"RIPng %pFX is filtered by route-map",
|
|
|
|
p);
|
2003-05-25 19:10:12 +02:00
|
|
|
continue;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* When the route-map does not set metric. */
|
|
|
|
if (!rinfo->metric_set) {
|
|
|
|
/* If the redistribute metric is set. */
|
2019-01-04 22:08:10 +01:00
|
|
|
if (ripng->redist[rinfo->type].metric_config
|
2003-05-25 19:10:12 +02:00
|
|
|
&& rinfo->metric != RIPNG_METRIC_INFINITY) {
|
|
|
|
rinfo->metric_out =
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->redist[rinfo->type]
|
2003-05-25 19:10:12 +02:00
|
|
|
.metric;
|
|
|
|
} else {
|
|
|
|
/* If the route is not connected or
|
|
|
|
localy generated
|
|
|
|
one, use default-metric value */
|
2023-06-14 20:24:07 +02:00
|
|
|
if (rinfo->type != ZEBRA_ROUTE_RIPNG &&
|
|
|
|
rinfo->type !=
|
|
|
|
ZEBRA_ROUTE_CONNECT &&
|
|
|
|
rinfo->metric !=
|
|
|
|
RIPNG_METRIC_INFINITY)
|
2003-05-25 19:10:12 +02:00
|
|
|
rinfo->metric_out =
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng->default_metric;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Apply offset-list */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rinfo->metric_out != RIPNG_METRIC_INFINITY)
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_offset_list_apply_out(ripng, p, ifp,
|
2003-05-25 19:10:12 +02:00
|
|
|
&rinfo->metric_out);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rinfo->metric_out > RIPNG_METRIC_INFINITY)
|
|
|
|
rinfo->metric_out = RIPNG_METRIC_INFINITY;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Perform split-horizon with poisoned reverse
|
|
|
|
* for RIPng routes.
|
2017-07-17 14:03:14 +02:00
|
|
|
**/
|
2023-06-14 20:24:07 +02:00
|
|
|
if (ri->split_horizon ==
|
|
|
|
RIPNG_SPLIT_HORIZON_POISONED_REVERSE) {
|
2015-05-22 11:39:53 +02:00
|
|
|
struct ripng_info *tmp_rinfo = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, listnode,
|
|
|
|
tmp_rinfo))
|
2023-06-14 20:24:07 +02:00
|
|
|
if ((tmp_rinfo->type ==
|
|
|
|
ZEBRA_ROUTE_RIPNG) &&
|
|
|
|
tmp_rinfo->ifindex == ifp->ifindex)
|
2003-05-25 19:10:12 +02:00
|
|
|
rinfo->metric_out =
|
|
|
|
RIPNG_METRIC_INFINITY;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Add RTE to the list */
|
|
|
|
ripng_rte_add(ripng_rte_list, p, rinfo, NULL);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* Process the aggregated RTE entry */
|
2002-12-13 21:15:29 +01:00
|
|
|
if ((aggregate = rp->aggregate) != NULL && aggregate->count > 0
|
|
|
|
&& aggregate->suppress == 0) {
|
2003-05-25 19:10:12 +02:00
|
|
|
/* If no route-map are applied, the RTE will be these
|
|
|
|
* following
|
2018-10-25 20:06:59 +02:00
|
|
|
* information.
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2020-03-22 04:37:24 +01:00
|
|
|
p = (struct prefix_ipv6 *)agg_node_get_prefix(rp);
|
2003-05-25 19:10:12 +02:00
|
|
|
aggregate->metric_set = 0;
|
|
|
|
aggregate->metric_out = aggregate->metric;
|
|
|
|
aggregate->tag_out = aggregate->tag;
|
|
|
|
memset(&aggregate->nexthop_out, 0,
|
|
|
|
sizeof(aggregate->nexthop_out));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Apply output filters.*/
|
2016-09-22 23:11:06 +02:00
|
|
|
ret = ripng_filter(RIPNG_FILTER_OUT, p, ri);
|
2003-05-25 19:10:12 +02:00
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Interface route-map */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ri->routemap[RIPNG_FILTER_OUT]) {
|
|
|
|
struct ripng_info newinfo;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* let's cast the aggregate structure to
|
|
|
|
* ripng_info */
|
2002-12-13 21:15:29 +01:00
|
|
|
memset(&newinfo, 0, sizeof(struct ripng_info));
|
2003-05-25 19:10:12 +02:00
|
|
|
/* the nexthop is :: */
|
|
|
|
newinfo.metric = aggregate->metric;
|
|
|
|
newinfo.metric_out = aggregate->metric_out;
|
|
|
|
newinfo.tag = aggregate->tag;
|
|
|
|
newinfo.tag_out = aggregate->tag_out;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ret = route_map_apply(
|
|
|
|
ri->routemap[RIPNG_FILTER_OUT],
|
2020-11-14 01:35:20 +01:00
|
|
|
(struct prefix *)p, &newinfo);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret == RMAP_DENYMATCH) {
|
|
|
|
if (IS_RIPNG_DEBUG_PACKET)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug(
|
2020-10-14 19:16:23 +02:00
|
|
|
"RIPng %pFX is filtered by route-map out",
|
|
|
|
p);
|
2003-05-25 19:10:12 +02:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
aggregate->metric_out = newinfo.metric_out;
|
|
|
|
aggregate->tag_out = newinfo.tag_out;
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop_out))
|
|
|
|
aggregate->nexthop_out =
|
|
|
|
newinfo.nexthop_out;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* There is no redistribute routemap for the aggregated
|
2017-07-17 14:03:14 +02:00
|
|
|
* RTE */
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Changed route only output. */
|
2003-05-25 19:10:12 +02:00
|
|
|
/* XXX, vincent, in order to increase time convergence,
|
|
|
|
* it should be announced if a child has changed.
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2002-12-13 21:15:29 +01:00
|
|
|
if (route_type == ripng_changed_route)
|
2003-05-25 19:10:12 +02:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Apply offset-list */
|
|
|
|
if (aggregate->metric_out != RIPNG_METRIC_INFINITY)
|
|
|
|
ripng_offset_list_apply_out(
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng, p, ifp, &aggregate->metric_out);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (aggregate->metric_out > RIPNG_METRIC_INFINITY)
|
|
|
|
aggregate->metric_out = RIPNG_METRIC_INFINITY;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Add RTE to the list */
|
|
|
|
ripng_rte_add(ripng_rte_list, p, NULL, aggregate);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Flush the list */
|
|
|
|
ripng_rte_send(ripng_rte_list, ifp, to);
|
|
|
|
ripng_rte_free(ripng_rte_list);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
if (!vrf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return vrf->info;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng_lookup_by_vrf_name(const char *vrf_name)
|
|
|
|
{
|
|
|
|
struct ripng ripng;
|
|
|
|
|
|
|
|
ripng.vrf_name = (char *)vrf_name;
|
|
|
|
|
|
|
|
return RB_FIND(ripng_instance_head, &ripng_instances, &ripng);
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Create new RIPng instance and set it to global variable. */
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng_create(const char *vrf_name, struct vrf *vrf, int socket)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Allocaste RIPng instance. */
|
2008-08-18 23:13:29 +02:00
|
|
|
ripng = XCALLOC(MTYPE_RIPNG, sizeof(struct ripng));
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->vrf_name = XSTRDUP(MTYPE_RIPNG_VRF_NAME, vrf_name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Default version and timer values. */
|
|
|
|
ripng->version = RIPNG_V1;
|
2018-11-29 03:49:49 +01:00
|
|
|
ripng->update_time = yang_get_default_uint32(
|
|
|
|
"%s/timers/update-interval", RIPNG_INSTANCE);
|
|
|
|
ripng->timeout_time = yang_get_default_uint32(
|
|
|
|
"%s/timers/holddown-interval", RIPNG_INSTANCE);
|
|
|
|
ripng->garbage_time = yang_get_default_uint32(
|
|
|
|
"%s/timers/flush-interval", RIPNG_INSTANCE);
|
|
|
|
ripng->default_metric =
|
|
|
|
yang_get_default_uint8("%s/default-metric", RIPNG_INSTANCE);
|
2023-05-16 09:34:22 +02:00
|
|
|
ripng->ecmp = yang_get_default_uint8("%s/allow-ecmp", RIPNG_INSTANCE);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make buffer. */
|
|
|
|
ripng->ibuf = stream_new(RIPNG_MAX_PACKET_SIZE * 5);
|
|
|
|
ripng->obuf = stream_new(RIPNG_MAX_PACKET_SIZE);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Initialize RIPng data structures. */
|
2018-08-03 19:22:48 +02:00
|
|
|
ripng->table = agg_table_init();
|
2019-01-04 22:08:10 +01:00
|
|
|
agg_set_table_info(ripng->table, ripng);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->peer_list = list_new();
|
|
|
|
ripng->peer_list->cmp = (int (*)(void *, void *))ripng_peer_list_cmp;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->peer_list->del = ripng_peer_list_del;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->enable_if = vector_init(1);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->enable_network = agg_table_init();
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->passive_interface = vector_init(1);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->offset_list_master = list_new();
|
|
|
|
ripng->offset_list_master->cmp =
|
|
|
|
(int (*)(void *, void *))offset_list_cmp;
|
|
|
|
ripng->offset_list_master->del =
|
2019-04-18 17:32:19 +02:00
|
|
|
(void (*)(void *))ripng_offset_list_free;
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->distribute_ctx = distribute_list_ctx_create(vrf);
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
distribute_list_add_hook(ripng->distribute_ctx,
|
|
|
|
ripng_distribute_update);
|
|
|
|
distribute_list_delete_hook(ripng->distribute_ctx,
|
|
|
|
ripng_distribute_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
/* if rmap install. */
|
2019-03-02 19:00:46 +01:00
|
|
|
ripng->if_rmap_ctx = if_rmap_ctx_create(vrf_name);
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap_hook_add(ripng->if_rmap_ctx, ripng_if_rmap_update);
|
|
|
|
if_rmap_hook_delete(ripng->if_rmap_ctx, ripng_if_rmap_update);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Enable the routing instance if possible. */
|
|
|
|
if (vrf && vrf_is_enabled(vrf))
|
|
|
|
ripng_instance_enable(ripng, vrf, socket);
|
|
|
|
else {
|
|
|
|
ripng->vrf = NULL;
|
|
|
|
ripng->sock = -1;
|
2019-01-04 22:08:10 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
RB_INSERT(ripng_instance_head, &ripng_instances, ripng);
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
return ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Send RIPng request to the interface. */
|
2002-12-13 21:15:29 +01:00
|
|
|
int ripng_request(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct rte *rte;
|
|
|
|
struct ripng_packet ripng_packet;
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* In default ripd doesn't send RIP_REQUEST to the loopback interface.
|
|
|
|
*/
|
|
|
|
if (if_is_loopback(ifp))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If interface is down, don't send RIP packet. */
|
|
|
|
if (!if_is_up(ifp))
|
|
|
|
return 0;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
2004-12-08 20:51:16 +01:00
|
|
|
zlog_debug("RIPng send request to %s", ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
memset(&ripng_packet, 0, sizeof(ripng_packet));
|
|
|
|
ripng_packet.command = RIPNG_REQUEST;
|
|
|
|
ripng_packet.version = RIPNG_V1;
|
|
|
|
rte = ripng_packet.rte;
|
|
|
|
rte->metric = RIPNG_METRIC_INFINITY;
|
|
|
|
|
|
|
|
return ripng_send_packet((caddr_t)&ripng_packet, sizeof(ripng_packet),
|
|
|
|
NULL, ifp);
|
|
|
|
}
|
|
|
|
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
static int ripng_update_jitter(int time)
|
|
|
|
{
|
2020-04-17 15:35:15 +02:00
|
|
|
return ((frr_weak_random() % (time + 1)) - (time / 2));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_event(struct ripng *ripng, enum ripng_event event, int sock)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int jitter = 0;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case RIPNG_READ:
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_read(master, ripng_read, ripng, sock, &ripng->t_read);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIPNG_UPDATE_EVENT:
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(ripng->t_update);
|
2020-07-06 18:55:03 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Update timer jitter. */
|
|
|
|
jitter = ripng_update_jitter(ripng->update_time);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, ripng_update, ripng,
|
|
|
|
sock ? 2 : ripng->update_time + jitter,
|
|
|
|
&ripng->t_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIPNG_TRIGGERED_UPDATE:
|
|
|
|
if (ripng->t_triggered_interval)
|
|
|
|
ripng->trigger = 1;
|
2017-04-25 00:33:25 +02:00
|
|
|
else
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_event(master, ripng_triggered_update, ripng,
|
|
|
|
0, &ripng->t_triggered_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
2023-01-30 16:11:15 +01:00
|
|
|
case RIPNG_ZEBRA:
|
|
|
|
case RIPNG_REQUEST_EVENT:
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Print out routes update time. */
|
|
|
|
static void ripng_vty_out_uptime(struct vty *vty, struct ripng_info *rinfo)
|
|
|
|
{
|
|
|
|
time_t clock;
|
2020-03-05 17:42:12 +01:00
|
|
|
struct tm tm;
|
2002-12-13 21:15:29 +01:00
|
|
|
#define TIME_BUF 25
|
|
|
|
char timebuf[TIME_BUF];
|
2022-03-01 22:18:12 +01:00
|
|
|
struct event *thread;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if ((thread = rinfo->t_timeout) != NULL) {
|
2022-12-11 14:19:00 +01:00
|
|
|
clock = event_timer_remain_second(thread);
|
2020-03-05 17:42:12 +01:00
|
|
|
gmtime_r(&clock, &tm);
|
|
|
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
2002-12-13 21:15:29 +01:00
|
|
|
vty_out(vty, "%5s", timebuf);
|
|
|
|
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
|
2022-12-11 14:19:00 +01:00
|
|
|
clock = event_timer_remain_second(thread);
|
2020-03-05 17:42:12 +01:00
|
|
|
gmtime_r(&clock, &tm);
|
|
|
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
2002-12-13 21:15:29 +01:00
|
|
|
vty_out(vty, "%5s", timebuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
static char *ripng_route_subtype_print(struct ripng_info *rinfo)
|
|
|
|
{
|
|
|
|
static char str[3];
|
|
|
|
memset(str, 0, 3);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (rinfo->suppress)
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "S", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
switch (rinfo->sub_type) {
|
|
|
|
case RIPNG_ROUTE_RTE:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "n", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
2003-05-25 19:10:12 +02:00
|
|
|
case RIPNG_ROUTE_STATIC:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "s", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
2003-05-25 19:10:12 +02:00
|
|
|
case RIPNG_ROUTE_DEFAULT:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "d", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
2003-05-25 19:10:12 +02:00
|
|
|
case RIPNG_ROUTE_REDISTRIBUTE:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "r", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
2003-05-25 19:10:12 +02:00
|
|
|
case RIPNG_ROUTE_INTERFACE:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "i", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-05-06 23:11:22 +02:00
|
|
|
strlcat(str, "?", sizeof(str));
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
DEFUN (show_ipv6_ripng,
|
|
|
|
show_ipv6_ripng_cmd,
|
2019-01-04 22:08:10 +01:00
|
|
|
"show ipv6 ripng [vrf NAME]",
|
2002-12-13 21:15:29 +01:00
|
|
|
SHOW_STR
|
2004-09-11 18:33:28 +02:00
|
|
|
IPV6_STR
|
2019-01-04 22:08:10 +01:00
|
|
|
"Show RIPng routes\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_info *rinfo;
|
|
|
|
struct ripng_aggregate *aggregate;
|
2015-05-22 11:39:53 +02:00
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
int len;
|
2019-01-04 22:08:10 +01:00
|
|
|
const char *vrf_name;
|
|
|
|
int idx = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
if (argv_find(argv, argc, "vrf", &idx))
|
|
|
|
vrf_name = argv[idx + 1]->arg;
|
|
|
|
else
|
|
|
|
vrf_name = VRF_DEFAULT_NAME;
|
|
|
|
|
|
|
|
ripng = ripng_lookup_by_vrf_name(vrf_name);
|
|
|
|
if (!ripng) {
|
|
|
|
vty_out(vty, "%% RIPng instance not found\n");
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
if (!ripng->enabled) {
|
|
|
|
vty_out(vty, "%% RIPng instance is disabled\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
return CMD_SUCCESS;
|
2019-01-04 22:08:10 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Header of display. */
|
2017-07-13 20:17:06 +02:00
|
|
|
vty_out(vty,
|
ripngd: adjust header for display command
Both rip and ripng can import routes from other protocols, e.g. ISIS.
But their header doesn't list the description for these abbreviations.
Adjust `show ipv6 ripng` 's header for display command.
Before:
```
Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP
Sub-codes:
```
After:
```
Codes: K - kernel route, C - connected, L - local, S - static,
R - RIPng, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,
f - OpenFabric, t - Table-Direct
Sub-codes:
```
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2024-06-16 07:20:00 +02:00
|
|
|
"Codes: K - kernel route, C - connected, L - local, S - static,\n"
|
|
|
|
" R - RIPng, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,\n"
|
|
|
|
" T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,\n"
|
|
|
|
" f - OpenFabric, t - Table-Direct\n"
|
2017-07-13 20:17:06 +02:00
|
|
|
"Sub-codes:\n"
|
|
|
|
" (n) - normal, (s) - static, (d) - default, (r) - redistribute,\n"
|
|
|
|
" (i) - interface, (a/S) - aggregated/Suppressed\n\n"
|
|
|
|
" Network Next Hop Via Metric Tag Time\n");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
|
2002-12-13 21:15:29 +01:00
|
|
|
if ((aggregate = rp->aggregate) != NULL) {
|
|
|
|
#ifdef DEBUG
|
2020-03-22 04:37:24 +01:00
|
|
|
vty_out(vty, "R(a) %d/%d %pRN ", aggregate->count,
|
|
|
|
aggregate->suppress, rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
#else
|
2020-03-22 04:37:24 +01:00
|
|
|
vty_out(vty, "R(a) %pRN ", rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
#endif /* DEBUG */
|
2017-07-13 19:04:25 +02:00
|
|
|
vty_out(vty, "\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
vty_out(vty, "%*s", 18, " ");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
vty_out(vty, "%*s", 28, " ");
|
2017-07-13 18:50:29 +02:00
|
|
|
vty_out(vty, "self %2d %3" ROUTE_TAG_PRI "\n",
|
2017-06-21 05:10:57 +02:00
|
|
|
aggregate->metric, (route_tag_t)aggregate->tag);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:53 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
|
2002-12-13 21:15:29 +01:00
|
|
|
#ifdef DEBUG
|
2020-03-22 04:37:24 +01:00
|
|
|
vty_out(vty, "%c(%s) 0/%d %pRN ",
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
zebra_route_char(rinfo->type),
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_route_subtype_print(rinfo),
|
2020-03-22 04:37:24 +01:00
|
|
|
rinfo->suppress, rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
#else
|
2020-03-22 04:37:24 +01:00
|
|
|
vty_out(vty, "%c(%s) %pRN ",
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
zebra_route_char(rinfo->type),
|
2020-03-22 04:37:24 +01:00
|
|
|
ripng_route_subtype_print(rinfo), rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
#endif /* DEBUG */
|
2017-07-13 19:04:25 +02:00
|
|
|
vty_out(vty, "\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
vty_out(vty, "%*s", 18, " ");
|
2021-03-31 14:28:30 +02:00
|
|
|
len = vty_out(vty, "%pI6",
|
|
|
|
&rinfo->nexthop);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
len = 28 - len;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (len > 0)
|
2017-10-08 23:40:36 +02:00
|
|
|
vty_out(vty, "%*s", len, " ");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* from */
|
|
|
|
if ((rinfo->type == ZEBRA_ROUTE_RIPNG)
|
|
|
|
&& (rinfo->sub_type == RIPNG_ROUTE_RTE)) {
|
2017-03-11 13:47:46 +01:00
|
|
|
len = vty_out(
|
|
|
|
vty, "%s",
|
2019-01-04 22:08:10 +01:00
|
|
|
ifindex2ifname(
|
|
|
|
rinfo->ifindex,
|
|
|
|
ripng->vrf->vrf_id));
|
2003-05-25 19:10:12 +02:00
|
|
|
} else if (rinfo->metric
|
|
|
|
== RIPNG_METRIC_INFINITY) {
|
|
|
|
len = vty_out(vty, "kill");
|
|
|
|
} else
|
|
|
|
len = vty_out(vty, "self");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
len = 9 - len;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (len > 0)
|
|
|
|
vty_out(vty, "%*s", len, " ");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-10-01 20:42:34 +02:00
|
|
|
vty_out(vty, " %2d %3" ROUTE_TAG_PRI " ",
|
|
|
|
rinfo->metric, (route_tag_t)rinfo->tag);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* time */
|
|
|
|
if ((rinfo->type == ZEBRA_ROUTE_RIPNG)
|
|
|
|
&& (rinfo->sub_type == RIPNG_ROUTE_RTE)) {
|
|
|
|
/* RTE from remote RIP routers */
|
2002-12-13 21:15:29 +01:00
|
|
|
ripng_vty_out_uptime(vty, rinfo);
|
2003-05-25 19:10:12 +02:00
|
|
|
} else if (rinfo->metric
|
|
|
|
== RIPNG_METRIC_INFINITY) {
|
|
|
|
/* poisonous reversed routes (gc) */
|
|
|
|
ripng_vty_out_uptime(vty, rinfo);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-07-13 19:04:25 +02:00
|
|
|
vty_out(vty, "\n");
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
DEFUN (show_ipv6_ripng_status,
|
|
|
|
show_ipv6_ripng_status_cmd,
|
2019-01-04 22:08:10 +01:00
|
|
|
"show ipv6 ripng [vrf NAME] status",
|
2003-05-25 19:10:12 +02:00
|
|
|
SHOW_STR
|
2004-09-11 18:33:28 +02:00
|
|
|
IPV6_STR
|
2003-05-25 19:10:12 +02:00
|
|
|
"Show RIPng routes\n"
|
2019-01-04 22:08:10 +01:00
|
|
|
VRF_CMD_HELP_STR
|
2003-05-25 19:10:12 +02:00
|
|
|
"IPv6 routing protocol process parameters and statistics\n")
|
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
struct interface *ifp;
|
2019-01-04 22:08:10 +01:00
|
|
|
const char *vrf_name;
|
|
|
|
int idx = 0;
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
if (argv_find(argv, argc, "vrf", &idx))
|
|
|
|
vrf_name = argv[idx + 1]->arg;
|
|
|
|
else
|
|
|
|
vrf_name = VRF_DEFAULT_NAME;
|
|
|
|
|
|
|
|
ripng = ripng_lookup_by_vrf_name(vrf_name);
|
|
|
|
if (!ripng) {
|
|
|
|
vty_out(vty, "%% RIPng instance not found\n");
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
if (!ripng->enabled) {
|
|
|
|
vty_out(vty, "%% RIPng instance is disabled\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
return CMD_SUCCESS;
|
2019-01-04 22:08:10 +01:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2017-07-13 18:50:29 +02:00
|
|
|
vty_out(vty, "Routing Protocol is \"RIPng\"\n");
|
2018-11-29 14:21:13 +01:00
|
|
|
vty_out(vty, " Sending updates every %u seconds with +/-50%%,",
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng->update_time);
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " next due in %lu seconds\n",
|
2022-12-11 14:19:00 +01:00
|
|
|
event_timer_remain_second(ripng->t_update));
|
2018-11-29 14:21:13 +01:00
|
|
|
vty_out(vty, " Timeout after %u seconds,", ripng->timeout_time);
|
|
|
|
vty_out(vty, " garbage collect after %u seconds\n",
|
2017-07-13 17:49:13 +02:00
|
|
|
ripng->garbage_time);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* Filtering status show. */
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
config_show_distribute(vty, ripng->distribute_ctx);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* Default metric information. */
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " Default redistribution metric is %d\n",
|
2017-06-21 05:10:57 +02:00
|
|
|
ripng->default_metric);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
/* Redistribute information. */
|
|
|
|
vty_out(vty, " Redistributing:");
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_redistribute_write(vty, ripng);
|
2017-07-13 19:04:25 +02:00
|
|
|
vty_out(vty, "\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
vty_out(vty, " Default version control: send version %d,",
|
|
|
|
ripng->version);
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " receive version %d \n", ripng->version);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " Interface Send Recv\n");
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
FOR_ALL_INTERFACES (ripng->vrf, ifp) {
|
2003-05-25 19:10:12 +02:00
|
|
|
struct ripng_interface *ri;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if (ri->enable_network || ri->enable_interface) {
|
|
|
|
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " %-17s%-3d %-3d\n", ifp->name,
|
2017-06-21 05:10:57 +02:00
|
|
|
ripng->version, ripng->version);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " Routing for Networks:\n");
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_network_write(vty, ripng);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " Routing Information Sources:\n");
|
|
|
|
vty_out(vty,
|
|
|
|
" Gateway BadPackets BadRoutes Distance Last Update\n");
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_peer_display(vty, ripng);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* Update ECMP routes to zebra when ECMP is disabled. */
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_ecmp_disable(struct ripng *ripng)
|
2015-05-22 11:39:54 +02:00
|
|
|
{
|
2018-08-03 19:22:48 +02:00
|
|
|
struct agg_node *rp;
|
2015-05-22 11:39:54 +02:00
|
|
|
struct ripng_info *rinfo, *tmp_rinfo;
|
|
|
|
struct list *list;
|
|
|
|
struct listnode *node, *nextnode;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
if (!ripng)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-03 19:22:48 +02:00
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp))
|
2015-05-22 11:39:54 +02:00
|
|
|
if ((list = rp->info) != NULL && listcount(list) > 1) {
|
|
|
|
rinfo = listgetdata(listhead(list));
|
|
|
|
if (!ripng_route_rte(rinfo))
|
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* Drop all other entries, except the first one. */
|
|
|
|
for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo != rinfo) {
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(tmp_rinfo->t_timeout);
|
|
|
|
EVENT_OFF(tmp_rinfo->t_garbage_collect);
|
2015-05-22 11:39:54 +02:00
|
|
|
list_delete_node(list, node);
|
|
|
|
ripng_info_free(tmp_rinfo);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* Update zebra. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_zebra_ipv6_add(ripng, rp);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* Set the route change flag. */
|
|
|
|
SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-22 11:39:54 +02:00
|
|
|
/* Signal the output process to trigger an update. */
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_event(ripng, RIPNG_TRIGGERED_UPDATE, 0);
|
2015-05-22 11:39:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
static void ripng_distribute_update(struct distribute_ctx *ctx,
|
|
|
|
struct distribute *dist)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
struct ripng_interface *ri;
|
|
|
|
struct access_list *alist;
|
|
|
|
struct prefix_list *plist;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
if (!ctx->vrf || !dist->ifname)
|
2002-12-13 21:15:29 +01:00
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-06-24 01:46:39 +02:00
|
|
|
ifp = if_lookup_by_name(dist->ifname, ctx->vrf->vrf_id);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ifp == NULL)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ri = ifp->info;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->list[DISTRIBUTE_V6_IN]) {
|
|
|
|
alist = access_list_lookup(AFI_IP6,
|
|
|
|
dist->list[DISTRIBUTE_V6_IN]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (alist)
|
|
|
|
ri->list[RIPNG_FILTER_IN] = alist;
|
|
|
|
else
|
|
|
|
ri->list[RIPNG_FILTER_IN] = NULL;
|
|
|
|
} else
|
|
|
|
ri->list[RIPNG_FILTER_IN] = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->list[DISTRIBUTE_V6_OUT]) {
|
|
|
|
alist = access_list_lookup(AFI_IP6,
|
|
|
|
dist->list[DISTRIBUTE_V6_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (alist)
|
|
|
|
ri->list[RIPNG_FILTER_OUT] = alist;
|
|
|
|
else
|
|
|
|
ri->list[RIPNG_FILTER_OUT] = NULL;
|
|
|
|
} else
|
|
|
|
ri->list[RIPNG_FILTER_OUT] = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->prefix[DISTRIBUTE_V6_IN]) {
|
|
|
|
plist = prefix_list_lookup(AFI_IP6,
|
|
|
|
dist->prefix[DISTRIBUTE_V6_IN]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (plist)
|
|
|
|
ri->prefix[RIPNG_FILTER_IN] = plist;
|
|
|
|
else
|
|
|
|
ri->prefix[RIPNG_FILTER_IN] = NULL;
|
|
|
|
} else
|
|
|
|
ri->prefix[RIPNG_FILTER_IN] = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->prefix[DISTRIBUTE_V6_OUT]) {
|
|
|
|
plist = prefix_list_lookup(AFI_IP6,
|
|
|
|
dist->prefix[DISTRIBUTE_V6_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (plist)
|
|
|
|
ri->prefix[RIPNG_FILTER_OUT] = plist;
|
|
|
|
else
|
|
|
|
ri->prefix[RIPNG_FILTER_OUT] = NULL;
|
|
|
|
} else
|
|
|
|
ri->prefix[RIPNG_FILTER_OUT] = NULL;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
void ripng_distribute_update_interface(struct interface *ifp)
|
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_interface *ri = ifp->info;
|
|
|
|
struct ripng *ripng = ri->ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct distribute *dist;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
if (!ripng)
|
|
|
|
return;
|
|
|
|
dist = distribute_lookup(ripng->distribute_ctx, ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (dist)
|
lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-04 15:45:57 +01:00
|
|
|
ripng_distribute_update(ripng->distribute_ctx, dist);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update all interface's distribute list. */
|
2004-09-26 18:09:34 +02:00
|
|
|
static void ripng_distribute_update_all(struct prefix_list *notused)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
ripng_distribute_update_interface(ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2004-09-26 18:09:34 +02:00
|
|
|
|
|
|
|
static void ripng_distribute_update_all_wrapper(struct access_list *notused)
|
|
|
|
{
|
|
|
|
ripng_distribute_update_all(NULL);
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* delete all the added ripng routes. */
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_clean(struct ripng *ripng)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
2020-10-09 14:14:58 +02:00
|
|
|
ripng_interface_clean(ripng);
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
if (ripng->enabled)
|
|
|
|
ripng_instance_disable(ripng);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < ZEBRA_ROUTE_MAX; i++)
|
2019-01-04 22:08:10 +01:00
|
|
|
if (ripng->redist[i].route_map.name)
|
|
|
|
free(ripng->redist[i].route_map.name);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
agg_table_finish(ripng->table);
|
2019-01-04 22:08:10 +01:00
|
|
|
list_delete(&ripng->peer_list);
|
2019-01-04 22:08:10 +01:00
|
|
|
distribute_list_delete(&ripng->distribute_ctx);
|
2019-03-02 19:00:46 +01:00
|
|
|
if_rmap_ctx_delete(ripng->if_rmap_ctx);
|
2017-06-06 17:47:49 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
stream_free(ripng->ibuf);
|
|
|
|
stream_free(ripng->obuf);
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_clean_network(ripng);
|
|
|
|
ripng_passive_interface_clean(ripng);
|
2019-01-04 22:08:10 +01:00
|
|
|
vector_free(ripng->enable_if);
|
2019-01-04 22:08:10 +01:00
|
|
|
agg_table_finish(ripng->enable_network);
|
2019-01-04 22:08:10 +01:00
|
|
|
vector_free(ripng->passive_interface);
|
2019-01-04 22:08:10 +01:00
|
|
|
list_delete(&ripng->offset_list_master);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
RB_REMOVE(ripng_instance_head, &ripng_instances, ripng);
|
|
|
|
XFREE(MTYPE_RIPNG_VRF_NAME, ripng->vrf_name);
|
2019-01-04 22:08:10 +01:00
|
|
|
XFREE(MTYPE_RIPNG, ripng);
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
static void ripng_if_rmap_update(struct if_rmap_ctx *ctx,
|
|
|
|
struct if_rmap *if_rmap)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-02-19 21:08:43 +01:00
|
|
|
struct interface *ifp = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct ripng_interface *ri;
|
|
|
|
struct route_map *rmap;
|
2019-02-19 21:08:43 +01:00
|
|
|
struct vrf *vrf = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-02-19 21:08:43 +01:00
|
|
|
if (ctx->name)
|
|
|
|
vrf = vrf_lookup_by_name(ctx->name);
|
|
|
|
if (vrf)
|
2019-06-24 01:46:39 +02:00
|
|
|
ifp = if_lookup_by_name(if_rmap->ifname, vrf->vrf_id);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ifp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if (if_rmap->routemap[IF_RMAP_IN]) {
|
|
|
|
rmap = route_map_lookup_by_name(if_rmap->routemap[IF_RMAP_IN]);
|
|
|
|
if (rmap)
|
|
|
|
ri->routemap[IF_RMAP_IN] = rmap;
|
|
|
|
else
|
|
|
|
ri->routemap[IF_RMAP_IN] = NULL;
|
|
|
|
} else
|
|
|
|
ri->routemap[RIPNG_FILTER_IN] = NULL;
|
|
|
|
|
|
|
|
if (if_rmap->routemap[IF_RMAP_OUT]) {
|
|
|
|
rmap = route_map_lookup_by_name(if_rmap->routemap[IF_RMAP_OUT]);
|
|
|
|
if (rmap)
|
|
|
|
ri->routemap[IF_RMAP_OUT] = rmap;
|
|
|
|
else
|
|
|
|
ri->routemap[IF_RMAP_OUT] = NULL;
|
|
|
|
} else
|
|
|
|
ri->routemap[RIPNG_FILTER_OUT] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ripng_if_rmap_update_interface(struct interface *ifp)
|
|
|
|
{
|
2019-03-02 19:00:46 +01:00
|
|
|
struct ripng_interface *ri = ifp->info;
|
|
|
|
struct ripng *ripng = ri->ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct if_rmap *if_rmap;
|
2019-01-14 08:58:36 +01:00
|
|
|
struct if_rmap_ctx *ctx;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if (!ripng)
|
|
|
|
return;
|
|
|
|
ctx = ripng->if_rmap_ctx;
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
if_rmap = if_rmap_lookup(ctx, ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (if_rmap)
|
2019-01-14 08:58:36 +01:00
|
|
|
ripng_if_rmap_update(ctx, if_rmap);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
static void ripng_routemap_update_redistribute(struct ripng *ripng)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-04 22:08:10 +01:00
|
|
|
for (int i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
2019-03-02 19:00:46 +01:00
|
|
|
if (ripng->redist[i].route_map.name) {
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng->redist[i].route_map.map =
|
|
|
|
route_map_lookup_by_name(
|
|
|
|
ripng->redist[i].route_map.name);
|
2019-03-02 19:00:46 +01:00
|
|
|
route_map_counter_increment(
|
|
|
|
ripng->redist[i].route_map.map);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-11 14:57:57 +02:00
|
|
|
static void ripng_routemap_update(const char *unused)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng *ripng;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
ripng_if_rmap_update_interface(ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng = vrf->info;
|
|
|
|
if (ripng)
|
|
|
|
ripng_routemap_update_redistribute(ripng);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Link RIPng instance to VRF. */
|
|
|
|
static void ripng_vrf_link(struct ripng *ripng, struct vrf *vrf)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
ripng->vrf = vrf;
|
|
|
|
ripng->distribute_ctx->vrf = vrf;
|
|
|
|
vrf->info = ripng;
|
|
|
|
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
|
|
|
ripng_interface_sync(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlink RIPng instance from VRF. */
|
|
|
|
static void ripng_vrf_unlink(struct ripng *ripng, struct vrf *vrf)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
ripng->vrf = NULL;
|
|
|
|
ripng->distribute_ctx->vrf = NULL;
|
|
|
|
vrf->info = NULL;
|
|
|
|
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
|
|
|
ripng_interface_sync(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ripng_instance_enable(struct ripng *ripng, struct vrf *vrf,
|
|
|
|
int sock)
|
|
|
|
{
|
|
|
|
ripng->sock = sock;
|
|
|
|
|
|
|
|
ripng_vrf_link(ripng, vrf);
|
|
|
|
ripng->enabled = true;
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Resend all redistribute requests. */
|
|
|
|
ripng_redistribute_enable(ripng);
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Create read and timer thread. */
|
|
|
|
ripng_event(ripng, RIPNG_READ, ripng->sock);
|
|
|
|
ripng_event(ripng, RIPNG_UPDATE_EVENT, 1);
|
|
|
|
|
|
|
|
ripng_zebra_vrf_register(vrf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ripng_instance_disable(struct ripng *ripng)
|
|
|
|
{
|
|
|
|
struct vrf *vrf = ripng->vrf;
|
|
|
|
struct agg_node *rp;
|
|
|
|
|
|
|
|
/* Clear RIPng routes */
|
|
|
|
for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
|
|
|
|
struct ripng_aggregate *aggregate;
|
|
|
|
struct list *list;
|
|
|
|
|
|
|
|
if ((list = rp->info) != NULL) {
|
|
|
|
struct ripng_info *rinfo;
|
|
|
|
struct listnode *listnode;
|
|
|
|
|
|
|
|
rinfo = listgetdata(listhead(list));
|
|
|
|
if (ripng_route_rte(rinfo))
|
|
|
|
ripng_zebra_ipv6_delete(ripng, rp);
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(rinfo->t_timeout);
|
|
|
|
EVENT_OFF(rinfo->t_garbage_collect);
|
2019-01-04 22:08:10 +01:00
|
|
|
ripng_info_free(rinfo);
|
|
|
|
}
|
|
|
|
list_delete(&list);
|
|
|
|
rp->info = NULL;
|
|
|
|
agg_unlock_node(rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((aggregate = rp->aggregate) != NULL) {
|
|
|
|
ripng_aggregate_free(aggregate);
|
|
|
|
rp->aggregate = NULL;
|
|
|
|
agg_unlock_node(rp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Flush all redistribute requests. */
|
|
|
|
ripng_redistribute_disable(ripng);
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
/* Cancel the RIPng timers */
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(ripng->t_update);
|
|
|
|
EVENT_OFF(ripng->t_triggered_update);
|
|
|
|
EVENT_OFF(ripng->t_triggered_interval);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
|
|
|
/* Cancel the read thread */
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(ripng->t_read);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
|
|
|
/* Close the RIPng socket */
|
|
|
|
if (ripng->sock >= 0) {
|
|
|
|
close(ripng->sock);
|
|
|
|
ripng->sock = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear existing peers. */
|
|
|
|
list_delete_all_node(ripng->peer_list);
|
|
|
|
|
|
|
|
ripng_zebra_vrf_deregister(vrf);
|
|
|
|
|
|
|
|
ripng_vrf_unlink(ripng, vrf);
|
|
|
|
ripng->enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ripng_vrf_new(struct vrf *vrf)
|
|
|
|
{
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
|
|
|
zlog_debug("%s: VRF created: %s(%u)", __func__, vrf->name,
|
|
|
|
vrf->vrf_id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ripng_vrf_delete(struct vrf *vrf)
|
|
|
|
{
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
|
|
|
zlog_debug("%s: VRF deleted: %s(%u)", __func__, vrf->name,
|
|
|
|
vrf->vrf_id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ripng_vrf_enable(struct vrf *vrf)
|
|
|
|
{
|
|
|
|
struct ripng *ripng;
|
|
|
|
int socket;
|
|
|
|
|
|
|
|
ripng = ripng_lookup_by_vrf_name(vrf->name);
|
*: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.
In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.
To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.
Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 23:22:55 +01:00
|
|
|
if (!ripng || ripng->enabled)
|
2019-01-04 22:08:10 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
|
|
|
zlog_debug("%s: VRF %s(%u) enabled", __func__, vrf->name,
|
|
|
|
vrf->vrf_id);
|
|
|
|
|
|
|
|
/* Activate the VRF RIPng instance. */
|
2019-08-27 17:00:54 +02:00
|
|
|
socket = ripng_make_socket(vrf);
|
|
|
|
if (socket < 0)
|
|
|
|
return -1;
|
2019-01-04 22:08:10 +01:00
|
|
|
|
2019-08-27 17:00:54 +02:00
|
|
|
ripng_instance_enable(ripng, vrf, socket);
|
2019-01-04 22:08:10 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ripng_vrf_disable(struct vrf *vrf)
|
|
|
|
{
|
|
|
|
struct ripng *ripng;
|
|
|
|
|
|
|
|
ripng = ripng_lookup_by_vrf_name(vrf->name);
|
|
|
|
if (!ripng || !ripng->enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IS_RIPNG_DEBUG_EVENT)
|
|
|
|
zlog_debug("%s: VRF %s(%u) disabled", __func__, vrf->name,
|
|
|
|
vrf->vrf_id);
|
|
|
|
|
|
|
|
/* Deactivate the VRF RIPng instance. */
|
|
|
|
if (ripng->enabled)
|
|
|
|
ripng_instance_disable(ripng);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ripng_vrf_init(void)
|
|
|
|
{
|
|
|
|
vrf_init(ripng_vrf_new, ripng_vrf_enable, ripng_vrf_disable,
|
*: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.
In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.
To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.
Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 23:22:55 +01:00
|
|
|
ripng_vrf_delete);
|
2019-01-04 22:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ripng_vrf_terminate(void)
|
|
|
|
{
|
|
|
|
vrf_terminate();
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Initialize ripng structure and set commands. */
|
2019-01-24 10:12:36 +01:00
|
|
|
void ripng_init(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Install ripng commands. */
|
|
|
|
install_element(VIEW_NODE, &show_ipv6_ripng_cmd);
|
2003-05-25 19:10:12 +02:00
|
|
|
install_element(VIEW_NODE, &show_ipv6_ripng_status_cmd);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
ripng_if_init();
|
|
|
|
ripng_debug_init();
|
|
|
|
|
2024-01-26 23:40:55 +01:00
|
|
|
/* Enable mgmt be debug */
|
|
|
|
mgmt_be_client_lib_vty_init();
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Access list install. */
|
2024-01-26 23:40:55 +01:00
|
|
|
access_list_init_new(true);
|
2004-09-26 18:09:34 +02:00
|
|
|
access_list_add_hook(ripng_distribute_update_all_wrapper);
|
|
|
|
access_list_delete_hook(ripng_distribute_update_all_wrapper);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Prefix list initialize.*/
|
|
|
|
prefix_list_init();
|
|
|
|
prefix_list_add_hook(ripng_distribute_update_all);
|
|
|
|
prefix_list_delete_hook(ripng_distribute_update_all);
|
|
|
|
|
|
|
|
/* Route-map for interface. */
|
|
|
|
ripng_route_map_init();
|
2003-05-25 19:10:12 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
route_map_add_hook(ripng_routemap_update);
|
|
|
|
route_map_delete_hook(ripng_routemap_update);
|
|
|
|
}
|