2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2003-05-25 19:10:12 +02:00
|
|
|
/* RIPng peer support
|
|
|
|
* Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* RIPng support added by Vincent Jardin <vincent.jardin@6wind.com>
|
|
|
|
* Copyright (C) 2002 6WIND
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "if.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "linklist.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2003-05-25 19:10:12 +02:00
|
|
|
#include "memory.h"
|
2023-11-04 09:47:46 +01:00
|
|
|
#include "frrdistance.h"
|
2003-05-25 19:10:12 +02:00
|
|
|
|
|
|
|
#include "ripngd/ripngd.h"
|
|
|
|
#include "ripngd/ripng_nexthop.h"
|
|
|
|
|
2019-06-21 08:44:11 +02:00
|
|
|
DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_PEER, "RIPng peer");
|
|
|
|
|
2008-08-15 14:45:30 +02:00
|
|
|
static struct ripng_peer *ripng_peer_new(void)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
2008-08-18 23:13:29 +02:00
|
|
|
return XCALLOC(MTYPE_RIPNG_PEER, sizeof(struct ripng_peer));
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ripng_peer_free(struct ripng_peer *peer)
|
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(peer->t_timeout);
|
2003-05-25 19:10:12 +02:00
|
|
|
XFREE(MTYPE_RIPNG_PEER, peer);
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_peer *ripng_peer_lookup(struct ripng *ripng, struct in6_addr *addr)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
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 listnode *node, *nnode;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
for (ALL_LIST_ELEMENTS(ripng->peer_list, node, nnode, peer)) {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (IPV6_ADDR_SAME(&peer->addr, addr))
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng,
|
|
|
|
struct in6_addr *addr)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
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 listnode *node, *nnode;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
for (ALL_LIST_ELEMENTS(ripng->peer_list, node, nnode, peer)) {
|
2003-05-25 19:10:12 +02:00
|
|
|
if (addr6_cmp(&peer->addr, addr) > 0)
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIPng peer is timeout.
|
|
|
|
* Garbage collector.
|
|
|
|
**/
|
2022-03-01 22:18:12 +01:00
|
|
|
static void ripng_peer_timeout(struct event *t)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
peer = EVENT_ARG(t);
|
2019-01-04 22:08:10 +01:00
|
|
|
listnode_delete(peer->ripng->peer_list, peer);
|
2003-05-25 19:10:12 +02:00
|
|
|
ripng_peer_free(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get RIPng peer. At the same time update timeout thread. */
|
2019-01-04 22:08:10 +01:00
|
|
|
static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
|
|
|
|
struct in6_addr *addr)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
peer = ripng_peer_lookup(ripng, addr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
if (peer) {
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(peer->t_timeout);
|
2003-05-25 19:10:12 +02:00
|
|
|
} else {
|
|
|
|
peer = ripng_peer_new();
|
2019-01-04 22:08:10 +01:00
|
|
|
peer->ripng = ripng;
|
|
|
|
peer->addr = *addr;
|
2019-01-04 22:08:10 +01:00
|
|
|
listnode_add_sort(ripng->peer_list, peer);
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Update timeout thread. */
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, ripng_peer_timeout, peer,
|
|
|
|
RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Last update time set. */
|
|
|
|
time(&peer->uptime);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_peer_update(struct ripng *ripng, struct sockaddr_in6 *from,
|
|
|
|
uint8_t version)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
2019-01-04 22:08:10 +01:00
|
|
|
peer = ripng_peer_get(ripng, &from->sin6_addr);
|
2003-05-25 19:10:12 +02:00
|
|
|
peer->version = version;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_peer_bad_route(struct ripng *ripng, struct sockaddr_in6 *from)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
2019-01-04 22:08:10 +01:00
|
|
|
peer = ripng_peer_get(ripng, &from->sin6_addr);
|
2003-05-25 19:10:12 +02:00
|
|
|
peer->recv_badroutes++;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_peer_bad_packet(struct ripng *ripng, struct sockaddr_in6 *from)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
2019-01-04 22:08:10 +01:00
|
|
|
peer = ripng_peer_get(ripng, &from->sin6_addr);
|
2003-05-25 19:10:12 +02:00
|
|
|
peer->recv_badpackets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Display peer uptime. */
|
|
|
|
static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
time_t uptime;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* If there is no connection has been done before print `never'. */
|
|
|
|
if (peer->uptime == 0) {
|
|
|
|
snprintf(buf, len, "never ");
|
|
|
|
return buf;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
/* Get current time. */
|
|
|
|
uptime = time(NULL);
|
|
|
|
uptime -= peer->uptime;
|
2020-03-05 20:06:46 +01:00
|
|
|
|
|
|
|
frrtime_to_interval(uptime, buf, len);
|
|
|
|
|
2003-05-25 19:10:12 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
void ripng_peer_display(struct vty *vty, struct ripng *ripng)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
|
|
|
struct ripng_peer *peer;
|
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 listnode *node, *nnode;
|
2003-05-25 19:10:12 +02:00
|
|
|
#define RIPNG_UPTIME_LEN 25
|
|
|
|
char timebuf[RIPNG_UPTIME_LEN];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
for (ALL_LIST_ELEMENTS(ripng->peer_list, node, nnode, peer)) {
|
2021-03-31 14:28:30 +02:00
|
|
|
vty_out(vty, " %pI6 \n%14s %10d %10d %10d %s\n",
|
|
|
|
&peer->addr, " ", peer->recv_badpackets,
|
2003-05-25 19:10:12 +02:00
|
|
|
peer->recv_badroutes, ZEBRA_RIPNG_DISTANCE_DEFAULT,
|
2017-06-21 05:10:57 +02:00
|
|
|
ripng_peer_uptime(peer, timebuf, RIPNG_UPTIME_LEN));
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2)
|
2003-05-25 19:10:12 +02:00
|
|
|
{
|
2018-10-17 21:31:09 +02:00
|
|
|
return memcmp(&p1->addr, &p2->addr, sizeof(struct in6_addr));
|
2003-05-25 19:10:12 +02:00
|
|
|
}
|
2019-01-04 22:08:10 +01:00
|
|
|
|
|
|
|
void ripng_peer_list_del(void *arg)
|
|
|
|
{
|
|
|
|
ripng_peer_free(arg);
|
|
|
|
}
|