2002-12-13 21:15:29 +01:00
|
|
|
/* RIP version 1 and 2.
|
2005-09-29 13:25:50 +02:00
|
|
|
* Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
|
2002-12-13 21:15:29 +01:00
|
|
|
* Copyright (C) 1997, 98, 99 Kunihiro Ishiguro <kunihiro@zebra.org>
|
|
|
|
*
|
|
|
|
* This file is part of GNU Zebra.
|
|
|
|
*
|
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Zebra; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
2016-04-08 15:16:14 +02:00
|
|
|
#include "vrf.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "if.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "table.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "sockunion.h"
|
2004-09-26 18:11:14 +02:00
|
|
|
#include "sockopt.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "routemap.h"
|
2003-05-25 16:49:19 +02:00
|
|
|
#include "if_rmap.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "plist.h"
|
|
|
|
#include "distribute.h"
|
2005-09-28 17:47:44 +02:00
|
|
|
#include "md5.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "keychain.h"
|
2003-06-04 15:59:38 +02:00
|
|
|
#include "privs.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#include "ripd/ripd.h"
|
|
|
|
#include "ripd/rip_debug.h"
|
|
|
|
|
2016-12-07 16:01:47 +01:00
|
|
|
DEFINE_QOBJ_TYPE(rip)
|
|
|
|
|
2004-09-17 10:39:08 +02:00
|
|
|
/* UDP receive buffer size */
|
|
|
|
#define RIP_UDP_RCV_BUF 41600
|
|
|
|
|
|
|
|
/* privileges global */
|
2003-06-04 15:59:38 +02:00
|
|
|
extern struct zebra_privs_t ripd_privs;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP Structure. */
|
|
|
|
struct rip *rip = NULL;
|
|
|
|
|
|
|
|
/* RIP neighbor address table. */
|
|
|
|
struct route_table *rip_neighbor_table;
|
|
|
|
|
|
|
|
/* RIP route changes. */
|
|
|
|
long rip_global_route_changes = 0;
|
|
|
|
|
|
|
|
/* RIP queries. */
|
|
|
|
long rip_global_queries = 0;
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Prototypes. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void rip_event (enum rip_event, int);
|
|
|
|
static void rip_output_process (struct connected *, struct sockaddr_in *, int, u_char);
|
|
|
|
static int rip_triggered_update (struct thread *);
|
|
|
|
static int rip_update_jitter (unsigned long);
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP output routes type. */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
rip_all_route,
|
|
|
|
rip_changed_route
|
|
|
|
};
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP command strings. */
|
2008-08-14 18:59:25 +02:00
|
|
|
static const struct message rip_msg[] =
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
{RIP_REQUEST, "REQUEST"},
|
|
|
|
{RIP_RESPONSE, "RESPONSE"},
|
|
|
|
{RIP_TRACEON, "TRACEON"},
|
|
|
|
{RIP_TRACEOFF, "TRACEOFF"},
|
|
|
|
{RIP_POLL, "POLL"},
|
|
|
|
{RIP_POLL_ENTRY, "POLL ENTRY"},
|
2008-08-14 18:59:25 +02:00
|
|
|
{0, NULL},
|
2002-12-13 21:15:29 +01:00
|
|
|
};
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Utility function to set boradcast option to the socket. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
sockopt_broadcast (int sock)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int on = 1;
|
|
|
|
|
|
|
|
ret = setsockopt (sock, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof on);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
zlog_warn ("can't set sockopt SO_BROADCAST to socket %d", sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_route_rte (struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
return (rinfo->type == ZEBRA_ROUTE_RIP && rinfo->sub_type == RIP_ROUTE_RTE);
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static struct rip_info *
|
2008-08-18 23:13:29 +02:00
|
|
|
rip_info_new (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2008-08-18 23:13:29 +02:00
|
|
|
return XCALLOC (MTYPE_RIP_INFO, sizeof (struct rip_info));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rip_info_free (struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
XFREE (MTYPE_RIP_INFO, rinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP route garbage collect timer. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_garbage_collect (struct thread *t)
|
|
|
|
{
|
|
|
|
struct rip_info *rinfo;
|
|
|
|
struct route_node *rp;
|
|
|
|
|
|
|
|
rinfo = THREAD_ARG (t);
|
|
|
|
rinfo->t_garbage_collect = NULL;
|
|
|
|
|
|
|
|
/* Off timeout timer. */
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
|
|
|
|
/* Get route_node pointer. */
|
|
|
|
rp = rinfo->rp;
|
|
|
|
|
|
|
|
/* Unlock route_node. */
|
2014-07-18 08:13:18 +02:00
|
|
|
listnode_delete (rp->info, rinfo);
|
|
|
|
if (list_isempty ((struct list *)rp->info))
|
|
|
|
{
|
|
|
|
list_free (rp->info);
|
|
|
|
rp->info = NULL;
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Free RIP routing information. */
|
|
|
|
rip_info_free (rinfo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
static void rip_timeout_update (struct rip_info *rinfo);
|
|
|
|
|
|
|
|
/* Add new route to the ECMP list.
|
2014-07-18 08:13:19 +02:00
|
|
|
* RETURN: the new entry added in the list, or NULL if it is not the first
|
|
|
|
* entry and ECMP is not allowed.
|
2014-07-18 08:13:18 +02:00
|
|
|
*/
|
|
|
|
struct rip_info *
|
|
|
|
rip_ecmp_add (struct rip_info *rinfo_new)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
struct route_node *rp = rinfo_new->rp;
|
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
if (rp->info == NULL)
|
|
|
|
rp->info = list_new ();
|
|
|
|
list = (struct list *)rp->info;
|
|
|
|
|
2014-07-18 08:13:19 +02:00
|
|
|
/* If ECMP is not allowed and some entry already exists in the list,
|
|
|
|
* do nothing. */
|
|
|
|
if (listcount (list) && !rip->ecmp)
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = rip_info_new ();
|
|
|
|
memcpy (rinfo, rinfo_new, sizeof (struct rip_info));
|
|
|
|
listnode_add (list, rinfo);
|
|
|
|
|
|
|
|
if (rip_route_rte (rinfo))
|
|
|
|
{
|
|
|
|
rip_timeout_update (rinfo);
|
|
|
|
rip_zebra_ipv4_add (rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the route change flag on the first entry. */
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
SET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update (see section 2.5). */
|
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
return rinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace the ECMP list with the new route.
|
|
|
|
* RETURN: the new entry added in the list
|
|
|
|
*/
|
|
|
|
struct rip_info *
|
|
|
|
rip_ecmp_replace (struct rip_info *rinfo_new)
|
|
|
|
{
|
|
|
|
struct route_node *rp = rinfo_new->rp;
|
|
|
|
struct list *list = (struct list *)rp->info;
|
|
|
|
struct rip_info *rinfo = NULL, *tmp_rinfo = NULL;
|
|
|
|
struct listnode *node = NULL, *nextnode = NULL;
|
|
|
|
|
|
|
|
if (list == NULL || listcount (list) == 0)
|
|
|
|
return rip_ecmp_add (rinfo_new);
|
|
|
|
|
|
|
|
/* Get the first entry */
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
|
|
|
|
/* Learnt route replaced by a local one. Delete it from zebra. */
|
|
|
|
if (rip_route_rte (rinfo) && !rip_route_rte (rinfo_new))
|
|
|
|
if (CHECK_FLAG (rinfo->flags, RIP_RTF_FIB))
|
|
|
|
rip_zebra_ipv4_delete (rp);
|
|
|
|
|
|
|
|
/* Re-use the first entry, and delete the others. */
|
|
|
|
for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo != rinfo)
|
|
|
|
{
|
|
|
|
RIP_TIMER_OFF (tmp_rinfo->t_timeout);
|
|
|
|
RIP_TIMER_OFF (tmp_rinfo->t_garbage_collect);
|
|
|
|
list_delete_node (list, node);
|
|
|
|
rip_info_free (tmp_rinfo);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
RIP_TIMER_OFF (rinfo->t_garbage_collect);
|
|
|
|
memcpy (rinfo, rinfo_new, sizeof (struct rip_info));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
if (rip_route_rte (rinfo))
|
|
|
|
{
|
|
|
|
rip_timeout_update (rinfo);
|
|
|
|
/* The ADD message implies an update. */
|
|
|
|
rip_zebra_ipv4_add (rp);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
/* Set the route change flag. */
|
|
|
|
SET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
/* Signal the output process to trigger an update (see section 2.5). */
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
|
2014-07-18 08:13:18 +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
|
|
|
|
*/
|
|
|
|
struct rip_info *
|
|
|
|
rip_ecmp_delete (struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
struct route_node *rp = rinfo->rp;
|
|
|
|
struct list *list = (struct list *)rp->info;
|
|
|
|
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
|
|
|
|
if (listcount (list) > 1)
|
|
|
|
{
|
|
|
|
/* Some other ECMP entries still exist. Just delete this entry. */
|
|
|
|
RIP_TIMER_OFF (rinfo->t_garbage_collect);
|
|
|
|
listnode_delete (list, rinfo);
|
|
|
|
if (rip_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIP_RTF_FIB))
|
|
|
|
/* The ADD message implies the update. */
|
|
|
|
rip_zebra_ipv4_add (rp);
|
|
|
|
rip_info_free (rinfo);
|
|
|
|
rinfo = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert (rinfo == listgetdata (listhead (list)));
|
|
|
|
|
|
|
|
/* This is the only entry left in the list. We must keep it in
|
|
|
|
* the list for garbage collection time, with INFINITY metric. */
|
|
|
|
|
|
|
|
rinfo->metric = RIP_METRIC_INFINITY;
|
|
|
|
RIP_TIMER_ON (rinfo->t_garbage_collect,
|
|
|
|
rip_garbage_collect, rip->garbage_time);
|
|
|
|
|
|
|
|
if (rip_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIP_RTF_FIB))
|
|
|
|
rip_zebra_ipv4_delete (rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the route change flag on the first entry. */
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
SET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update (see section 2.5). */
|
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
|
|
|
|
return rinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Timeout RIP routes. */
|
|
|
|
static int
|
|
|
|
rip_timeout (struct thread *t)
|
|
|
|
{
|
|
|
|
rip_ecmp_delete ((struct rip_info *)THREAD_ARG (t));
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_timeout_update (struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
if (rinfo->metric != RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
RIP_TIMER_ON (rinfo->t_timeout, rip_timeout, rip->timeout_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2016-09-22 23:11:05 +02:00
|
|
|
rip_filter (int rip_distribute, struct prefix_ipv4 *p, struct rip_interface *ri)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct distribute *dist;
|
|
|
|
struct access_list *alist;
|
|
|
|
struct prefix_list *plist;
|
2016-09-22 23:11:05 +02:00
|
|
|
int distribute = rip_distribute == RIP_FILTER_OUT ?
|
2016-09-22 23:11:07 +02:00
|
|
|
DISTRIBUTE_V4_OUT : DISTRIBUTE_V4_IN;
|
2016-09-22 23:11:05 +02:00
|
|
|
const char *inout = rip_distribute == RIP_FILTER_OUT ? "out" : "in";
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Input distribute-list filtering. */
|
2016-09-22 23:11:05 +02:00
|
|
|
if (ri->list[rip_distribute])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
if (access_list_apply (ri->list[rip_distribute],
|
2002-12-13 21:15:29 +01:00
|
|
|
(struct prefix *) p) == FILTER_DENY)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2016-09-22 23:11:05 +02:00
|
|
|
zlog_debug ("%s/%d filtered by distribute %s",
|
|
|
|
inet_ntoa (p->prefix), p->prefixlen, inout);
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 23:11:05 +02:00
|
|
|
if (ri->prefix[rip_distribute])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
if (prefix_list_apply (ri->prefix[rip_distribute],
|
2002-12-13 21:15:29 +01:00
|
|
|
(struct prefix *) p) == PREFIX_DENY)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2016-09-22 23:11:05 +02:00
|
|
|
zlog_debug ("%s/%d filtered by prefix-list %s",
|
|
|
|
inet_ntoa (p->prefix), p->prefixlen, inout);
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All interface filter check. */
|
|
|
|
dist = distribute_lookup (NULL);
|
|
|
|
if (dist)
|
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
if (dist->list[distribute])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
alist = access_list_lookup (AFI_IP, dist->list[distribute]);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (alist)
|
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
if (access_list_apply (alist, (struct prefix *) p) == FILTER_DENY)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2016-09-22 23:11:05 +02:00
|
|
|
zlog_debug ("%s/%d filtered by distribute %s",
|
|
|
|
inet_ntoa (p->prefix), p->prefixlen, inout);
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 23:11:05 +02:00
|
|
|
if (dist->prefix[distribute])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:05 +02:00
|
|
|
plist = prefix_list_lookup (AFI_IP, dist->prefix[distribute]);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (plist)
|
|
|
|
{
|
|
|
|
if (prefix_list_apply (plist,
|
|
|
|
(struct prefix *) p) == PREFIX_DENY)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2016-09-22 23:11:05 +02:00
|
|
|
zlog_debug ("%s/%d filtered by prefix-list %s",
|
|
|
|
inet_ntoa (p->prefix), p->prefixlen, inout);
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check nexthop address validity. */
|
|
|
|
static int
|
|
|
|
rip_nexthop_check (struct in_addr *addr)
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
struct listnode *node;
|
|
|
|
struct listnode *cnode;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *ifc;
|
|
|
|
struct prefix *p;
|
|
|
|
|
|
|
|
/* If nexthop address matches local configured address then it is
|
|
|
|
invalid nexthop. */
|
2016-04-08 15:16:14 +02:00
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
|
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
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
p = ifc->address;
|
|
|
|
|
|
|
|
if (p->family == AF_INET
|
|
|
|
&& IPV4_ADDR_SAME (&p->u.prefix4, addr))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP add route to routing table. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_rte_process (struct rte *rte, struct sockaddr_in *from,
|
2004-05-03 22:00:17 +02:00
|
|
|
struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *rp;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL, newinfo;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct rip_interface *ri;
|
|
|
|
struct in_addr *nexthop;
|
|
|
|
int same = 0;
|
2005-09-29 13:25:50 +02:00
|
|
|
unsigned char old_dist, new_dist;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *node = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Make prefix structure. */
|
|
|
|
memset (&p, 0, sizeof (struct prefix_ipv4));
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.prefix = rte->prefix;
|
|
|
|
p.prefixlen = ip_masklen (rte->mask);
|
|
|
|
|
|
|
|
/* Make sure mask is applied. */
|
|
|
|
apply_mask_ipv4 (&p);
|
|
|
|
|
|
|
|
/* Apply input filters. */
|
|
|
|
ri = ifp->info;
|
|
|
|
|
2016-09-22 23:11:05 +02:00
|
|
|
ret = rip_filter (RIP_FILTER_IN, &p, ri);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
memset (&newinfo, 0, sizeof (newinfo));
|
|
|
|
newinfo.type = ZEBRA_ROUTE_RIP;
|
|
|
|
newinfo.sub_type = RIP_ROUTE_RTE;
|
|
|
|
newinfo.nexthop = rte->nexthop;
|
|
|
|
newinfo.from = from->sin_addr;
|
|
|
|
newinfo.ifindex = ifp->ifindex;
|
|
|
|
newinfo.metric = rte->metric;
|
|
|
|
newinfo.metric_out = rte->metric; /* XXX */
|
|
|
|
newinfo.tag = ntohs (rte->tag); /* XXX */
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Modify entry according to the interface routemap. */
|
|
|
|
if (ri->routemap[RIP_FILTER_IN])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* The object should be of the type of rip_info */
|
2004-05-03 22:00:17 +02:00
|
|
|
ret = route_map_apply (ri->routemap[RIP_FILTER_IN],
|
|
|
|
(struct prefix *) &p, RMAP_RIP, &newinfo);
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
if (ret == RMAP_DENYMATCH)
|
2004-05-03 22:00:17 +02:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIP %s/%d is filtered by route-map in",
|
2004-05-03 22:00:17 +02:00
|
|
|
inet_ntoa (p.prefix), p.prefixlen);
|
|
|
|
return;
|
|
|
|
}
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
/* Get back the object */
|
2004-05-03 22:00:17 +02:00
|
|
|
rte->nexthop = newinfo.nexthop_out;
|
|
|
|
rte->tag = htons (newinfo.tag_out); /* XXX */
|
|
|
|
rte->metric = newinfo.metric_out; /* XXX: the routemap uses the metric_out field */
|
2003-05-25 16:49:19 +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) */
|
|
|
|
/* Zebra ripd can handle offset-list in. */
|
|
|
|
ret = rip_offset_list_apply_in (&p, ifp, &rte->metric);
|
|
|
|
|
|
|
|
/* If offset-list does not modify the metric use interface's
|
|
|
|
metric. */
|
2004-05-03 22:00:17 +02:00
|
|
|
if (!ret)
|
2014-04-14 10:09:29 +02:00
|
|
|
rte->metric += ifp->metric ? ifp->metric : 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (rte->metric > RIP_METRIC_INFINITY)
|
|
|
|
rte->metric = RIP_METRIC_INFINITY;
|
|
|
|
|
|
|
|
/* Set nexthop pointer. */
|
|
|
|
if (rte->nexthop.s_addr == 0)
|
|
|
|
nexthop = &from->sin_addr;
|
|
|
|
else
|
|
|
|
nexthop = &rte->nexthop;
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Check if nexthop address is myself, then do nothing. */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rip_nexthop_check (nexthop) < 0)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Nexthop address %s is myself", inet_ntoa (*nexthop));
|
2002-12-13 21:15:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get index for the prefix. */
|
|
|
|
rp = route_node_get (rip->table, (struct prefix *) &p);
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
newinfo.rp = rp;
|
|
|
|
newinfo.nexthop = *nexthop;
|
|
|
|
newinfo.metric = rte->metric;
|
|
|
|
newinfo.tag = ntohs (rte->tag);
|
|
|
|
newinfo.distance = rip_distance_apply (&newinfo);
|
|
|
|
|
|
|
|
new_dist = newinfo.distance ? newinfo.distance : ZEBRA_RIP_DISTANCE_DEFAULT;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Check to see whether there is already RIP route on the table. */
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
|
|
|
|
{
|
|
|
|
/* Need to compare with redistributed entry or local entry */
|
|
|
|
if (!rip_route_rte (rinfo))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (IPV4_ADDR_SAME (&rinfo->from, &from->sin_addr) &&
|
|
|
|
IPV4_ADDR_SAME (&rinfo->nexthop, nexthop))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!listnextnode (node))
|
|
|
|
{
|
|
|
|
/* Not found in the list */
|
|
|
|
|
|
|
|
if (rte->metric > rinfo->metric)
|
|
|
|
{
|
|
|
|
/* New route has a greater metric. Discard it. */
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rte->metric < rinfo->metric)
|
|
|
|
/* New route has a smaller metric. Replace the ECMP list
|
|
|
|
* with the new one in below. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Metrics are same. We compare the distances. */
|
|
|
|
old_dist = rinfo->distance ? \
|
|
|
|
rinfo->distance : ZEBRA_RIP_DISTANCE_DEFAULT;
|
|
|
|
|
|
|
|
if (new_dist > old_dist)
|
|
|
|
{
|
|
|
|
/* New route has a greater distance. Discard it. */
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_dist < old_dist)
|
|
|
|
/* New route has a smaller distance. Replace the ECMP list
|
|
|
|
* with the new one in below. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Metrics and distances are both same. Keep "rinfo" null and
|
|
|
|
* the new route is added in the ECMP list in below. */
|
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (rinfo)
|
|
|
|
{
|
|
|
|
/* Local static route. */
|
|
|
|
if (rinfo->type == ZEBRA_ROUTE_RIP
|
2004-05-03 22:00:17 +02:00
|
|
|
&& ((rinfo->sub_type == RIP_ROUTE_STATIC) ||
|
|
|
|
(rinfo->sub_type == RIP_ROUTE_DEFAULT))
|
|
|
|
&& rinfo->metric != RIP_METRIC_INFINITY)
|
2005-09-29 13:25:50 +02:00
|
|
|
{
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redistributed route check. */
|
|
|
|
if (rinfo->type != ZEBRA_ROUTE_RIP
|
|
|
|
&& rinfo->metric != RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
old_dist = rinfo->distance;
|
2013-02-28 22:17:00 +01:00
|
|
|
/* Only routes directly connected to an interface (nexthop == 0)
|
|
|
|
* may have a valid NULL distance */
|
|
|
|
if (rinfo->nexthop.s_addr != 0)
|
2006-01-30 19:12:42 +01:00
|
|
|
old_dist = old_dist ? old_dist : ZEBRA_RIP_DISTANCE_DEFAULT;
|
2005-09-29 13:25:50 +02:00
|
|
|
/* If imported route does not have STRICT precedence,
|
|
|
|
mark it as a ghost */
|
2014-07-18 08:13:18 +02:00
|
|
|
if (new_dist <= old_dist && rte->metric != RIP_METRIC_INFINITY)
|
|
|
|
rip_ecmp_replace (&newinfo);
|
|
|
|
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
2005-09-29 13:25:50 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2004-05-03 22:00:17 +02:00
|
|
|
|
|
|
|
if (!rinfo)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
if (rp->info)
|
|
|
|
route_unlock_node (rp);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Now, check to see whether there is already an explicit route
|
2004-05-03 22:00:17 +02:00
|
|
|
for the destination prefix. If there is no such route, add
|
|
|
|
this route to the routing table, unless the metric is
|
|
|
|
infinity (there is no point in adding a route which
|
|
|
|
unusable). */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rte->metric != RIP_METRIC_INFINITY)
|
2014-07-18 08:13:18 +02:00
|
|
|
rip_ecmp_add (&newinfo);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Route is there but we are not sure the route is RIP or not. */
|
2004-05-03 22:00:17 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* If there is an existing route, compare the next hop address
|
2004-05-03 22:00:17 +02: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. */
|
2003-05-25 16:49:19 +02:00
|
|
|
same = (IPV4_ADDR_SAME (&rinfo->from, &from->sin_addr)
|
2004-05-03 22:00:17 +02:00
|
|
|
&& (rinfo->ifindex == ifp->ifindex));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
old_dist = rinfo->distance ? \
|
|
|
|
rinfo->distance : ZEBRA_RIP_DISTANCE_DEFAULT;
|
2004-05-01 22:45:38 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Next, compare the metrics. If the datagram is from the same
|
2004-05-03 22:00:17 +02:00
|
|
|
router as the existing route, and the new metric is different
|
|
|
|
than the old one; or, if the new metric is lower than the old
|
|
|
|
one, or if the tag has been changed; or if there is a route
|
|
|
|
with a lower administrave distance; or an update of the
|
|
|
|
distance on the actual route; do the following actions: */
|
|
|
|
if ((same && rinfo->metric != rte->metric)
|
|
|
|
|| (rte->metric < rinfo->metric)
|
|
|
|
|| ((same)
|
|
|
|
&& (rinfo->metric == rte->metric)
|
2014-07-18 08:13:18 +02:00
|
|
|
&& (newinfo.tag != rinfo->tag))
|
|
|
|
|| (old_dist > new_dist)
|
|
|
|
|| ((old_dist != new_dist) && same))
|
2004-05-03 22:00:17 +02:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
if (listcount (list) == 1)
|
2004-05-03 22:00:17 +02:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
if (newinfo.metric != RIP_METRIC_INFINITY)
|
|
|
|
rip_ecmp_replace (&newinfo);
|
|
|
|
else
|
|
|
|
rip_ecmp_delete (rinfo);
|
2004-05-03 22:00:17 +02:00
|
|
|
}
|
2014-07-18 08:13:18 +02:00
|
|
|
else
|
2004-05-03 22:00:17 +02:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
if (newinfo.metric < rinfo->metric)
|
|
|
|
rip_ecmp_replace (&newinfo);
|
|
|
|
else if (newinfo.metric > rinfo->metric)
|
|
|
|
rip_ecmp_delete (rinfo);
|
|
|
|
else if (new_dist < old_dist)
|
|
|
|
rip_ecmp_replace (&newinfo);
|
|
|
|
else if (new_dist > old_dist)
|
|
|
|
rip_ecmp_delete (rinfo);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int update = CHECK_FLAG (rinfo->flags, RIP_RTF_FIB) ? 1 : 0;
|
2004-05-03 22:00:17 +02:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
assert (newinfo.metric != RIP_METRIC_INFINITY);
|
2004-05-03 22:00:17 +02:00
|
|
|
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
2014-07-18 08:13:18 +02:00
|
|
|
RIP_TIMER_OFF (rinfo->t_garbage_collect);
|
|
|
|
memcpy (rinfo, &newinfo, sizeof (struct rip_info));
|
|
|
|
rip_timeout_update (rinfo);
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
rip_zebra_ipv4_add (rp);
|
2004-05-03 22:00:17 +02:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
/* - Set the route change flag on the first entry. */
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
SET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
2004-05-03 22:00:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-18 08:13:18 +02:00
|
|
|
else /* same & no change */
|
|
|
|
rip_timeout_update (rinfo);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Unlock tempolary lock of the route. */
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump RIP packet */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2004-10-08 08:36:38 +02:00
|
|
|
rip_packet_dump (struct rip_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:36:38 +02:00
|
|
|
const char *command_str;
|
2002-12-13 21:15:29 +01:00
|
|
|
char pbuf[BUFSIZ], nbuf[BUFSIZ];
|
|
|
|
u_char netmask = 0;
|
|
|
|
u_char *p;
|
|
|
|
|
|
|
|
/* Set command string. */
|
|
|
|
if (packet->command > 0 && packet->command < RIP_COMMAND_MAX)
|
|
|
|
command_str = lookup (rip_msg, packet->command);
|
|
|
|
else
|
|
|
|
command_str = "unknown";
|
|
|
|
|
|
|
|
/* Dump packet header. */
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("%s %s version %d packet size %d",
|
2002-12-13 21:15:29 +01:00
|
|
|
sndrcv, command_str, packet->version, size);
|
|
|
|
|
|
|
|
/* Dump each routing table entry. */
|
|
|
|
rte = packet->rte;
|
|
|
|
|
|
|
|
for (lim = (caddr_t) packet + size; (caddr_t) rte < lim; rte++)
|
|
|
|
{
|
|
|
|
if (packet->version == RIPv2)
|
|
|
|
{
|
|
|
|
netmask = ip_masklen (rte->mask);
|
|
|
|
|
2004-06-07 00:06:33 +02:00
|
|
|
if (rte->family == htons (RIP_FAMILY_AUTH))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-06-07 00:06:33 +02:00
|
|
|
if (rte->tag == htons (RIP_AUTH_SIMPLE_PASSWORD))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
p = (u_char *)&rte->prefix;
|
|
|
|
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" family 0x%X type %d auth string: %s",
|
2002-12-13 21:15:29 +01:00
|
|
|
ntohs (rte->family), ntohs (rte->tag), p);
|
|
|
|
}
|
2004-06-07 00:06:33 +02:00
|
|
|
else if (rte->tag == htons (RIP_AUTH_MD5))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct rip_md5_info *md5;
|
|
|
|
|
|
|
|
md5 = (struct rip_md5_info *) &packet->rte;
|
|
|
|
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" family 0x%X type %d (MD5 authentication)",
|
2002-12-13 21:15:29 +01:00
|
|
|
ntohs (md5->family), ntohs (md5->type));
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" RIP-2 packet len %d Key ID %d"
|
2004-06-07 00:06:33 +02:00
|
|
|
" Auth Data len %d",
|
|
|
|
ntohs (md5->packet_len), md5->keyid,
|
|
|
|
md5->auth_len);
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" Sequence Number %ld",
|
2004-06-07 00:06:33 +02:00
|
|
|
(u_long) ntohl (md5->sequence));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2004-06-07 00:06:33 +02:00
|
|
|
else if (rte->tag == htons (RIP_AUTH_DATA))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
p = (u_char *)&rte->prefix;
|
|
|
|
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" family 0x%X type %d (MD5 data)",
|
2002-12-13 21:15:29 +01:00
|
|
|
ntohs (rte->family), ntohs (rte->tag));
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
|
2016-06-14 20:07:08 +02:00
|
|
|
"%02X%02X%02X%02X%02X%02X%02X%02X",
|
2004-06-07 00:06:33 +02:00
|
|
|
p[0], p[1], p[2], p[3], p[4], p[5], p[6],
|
2016-06-14 20:07:08 +02:00
|
|
|
p[7], p[8], p[9], p[10], p[11], p[12], p[13],
|
2004-06-07 00:06:33 +02:00
|
|
|
p[14], p[15]);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug (" family 0x%X type %d (Unknown auth type)",
|
2002-12-13 21:15:29 +01:00
|
|
|
ntohs (rte->family), ntohs (rte->tag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-10-01 20:42:34 +02:00
|
|
|
zlog_debug (" %s/%d -> %s family %d tag %"ROUTE_TAG_PRI" metric %ld",
|
2004-06-07 00:06:33 +02:00
|
|
|
inet_ntop (AF_INET, &rte->prefix, pbuf, BUFSIZ),
|
|
|
|
netmask, inet_ntop (AF_INET, &rte->nexthop, nbuf,
|
|
|
|
BUFSIZ), ntohs (rte->family),
|
2016-10-01 20:42:34 +02:00
|
|
|
(route_tag_t)ntohs (rte->tag),
|
|
|
|
(u_long) ntohl (rte->metric));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-01 20:42:34 +02:00
|
|
|
zlog_debug (" %s family %d tag %"ROUTE_TAG_PRI" metric %ld",
|
2002-12-13 21:15:29 +01:00
|
|
|
inet_ntop (AF_INET, &rte->prefix, pbuf, BUFSIZ),
|
2016-10-01 20:42:34 +02:00
|
|
|
ntohs (rte->family), (route_tag_t)ntohs (rte->tag),
|
2002-12-13 21:15:29 +01:00
|
|
|
(u_long)ntohl (rte->metric));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the destination address is valid (unicast; not net 0
|
|
|
|
or 127) (RFC2453 Section 3.9.2 - Page 26). But we don't
|
|
|
|
check net 0 because we accept default route. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_destination_check (struct in_addr addr)
|
|
|
|
{
|
|
|
|
u_int32_t destination;
|
|
|
|
|
|
|
|
/* Convert to host byte order. */
|
|
|
|
destination = ntohl (addr.s_addr);
|
|
|
|
|
|
|
|
if (IPV4_NET127 (destination))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Net 0 may match to the default route. */
|
|
|
|
if (IPV4_NET0 (destination) && destination != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Unicast address must belong to class A, B, C. */
|
|
|
|
if (IN_CLASSA (destination))
|
|
|
|
return 1;
|
|
|
|
if (IN_CLASSB (destination))
|
|
|
|
return 1;
|
|
|
|
if (IN_CLASSC (destination))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP version 2 authentication. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_auth_simple_password (struct rte *rte, struct sockaddr_in *from,
|
|
|
|
struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct rip_interface *ri;
|
2016-11-10 15:53:21 +01:00
|
|
|
char *auth_str = (char *) &rte->prefix;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* reject passwords with zeros in the middle of the string */
|
|
|
|
for (i = strlen (auth_str); i < 16; i++)
|
|
|
|
{
|
|
|
|
if (auth_str[i] != '\0')
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIPv2 simple password authentication from %s",
|
2002-12-13 21:15:29 +01:00
|
|
|
inet_ntoa (from->sin_addr));
|
|
|
|
|
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if (ri->auth_type != RIP_AUTH_SIMPLE_PASSWORD
|
2004-06-07 00:06:33 +02:00
|
|
|
|| rte->tag != htons(RIP_AUTH_SIMPLE_PASSWORD))
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Simple password authentication. */
|
|
|
|
if (ri->auth_str)
|
|
|
|
{
|
|
|
|
if (strncmp (auth_str, ri->auth_str, 16) == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ri->key_chain)
|
|
|
|
{
|
|
|
|
struct keychain *keychain;
|
|
|
|
struct key *key;
|
|
|
|
|
|
|
|
keychain = keychain_lookup (ri->key_chain);
|
|
|
|
if (keychain == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-10 15:53:21 +01:00
|
|
|
key = key_match_for_accept (keychain, auth_str);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (key)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP version 2 authentication with MD5. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_auth_md5 (struct rip_packet *packet, struct sockaddr_in *from,
|
2004-06-07 00:06:33 +02:00
|
|
|
int length, struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct rip_interface *ri;
|
|
|
|
struct rip_md5_info *md5;
|
|
|
|
struct rip_md5_data *md5data;
|
|
|
|
struct keychain *keychain;
|
|
|
|
struct key *key;
|
2005-09-28 17:47:44 +02:00
|
|
|
MD5_CTX ctx;
|
2002-12-13 21:15:29 +01:00
|
|
|
u_char digest[RIP_AUTH_MD5_SIZE];
|
|
|
|
u_int16_t packet_len;
|
2006-01-17 18:26:25 +01:00
|
|
|
char auth_str[RIP_AUTH_MD5_SIZE];
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIPv2 MD5 authentication from %s",
|
2004-06-07 00:06:33 +02:00
|
|
|
inet_ntoa (from->sin_addr));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
ri = ifp->info;
|
|
|
|
md5 = (struct rip_md5_info *) &packet->rte;
|
|
|
|
|
|
|
|
/* Check auth type. */
|
2004-06-07 00:06:33 +02:00
|
|
|
if (ri->auth_type != RIP_AUTH_MD5 || md5->type != htons(RIP_AUTH_MD5))
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
|
2004-06-07 00:06:33 +02:00
|
|
|
/* If the authentication length is less than 16, then it must be wrong for
|
|
|
|
* any interpretation of rfc2082. Some implementations also interpret
|
|
|
|
* this as RIP_HEADER_SIZE+ RIP_AUTH_MD5_SIZE, aka RIP_AUTH_MD5_COMPAT_SIZE.
|
2006-01-17 18:26:25 +01:00
|
|
|
*/
|
2004-06-07 00:06:33 +02:00
|
|
|
if ( !((md5->auth_len == RIP_AUTH_MD5_SIZE)
|
|
|
|
|| (md5->auth_len == RIP_AUTH_MD5_COMPAT_SIZE)))
|
2004-06-04 03:42:38 +02:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIPv2 MD5 authentication, strange authentication "
|
2004-06-07 00:06:33 +02:00
|
|
|
"length field %d", md5->auth_len);
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
2004-06-04 03:42:38 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-06-07 00:06:33 +02:00
|
|
|
/* grab and verify check packet length */
|
|
|
|
packet_len = ntohs (md5->packet_len);
|
|
|
|
|
|
|
|
if (packet_len > (length - RIP_HEADER_SIZE - RIP_AUTH_MD5_SIZE))
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIPv2 MD5 authentication, packet length field %d "
|
2004-06-07 00:06:33 +02:00
|
|
|
"greater than received length %d!",
|
|
|
|
md5->packet_len, length);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve authentication data */
|
|
|
|
md5data = (struct rip_md5_data *) (((u_char *) packet) + packet_len);
|
2006-01-17 18:26:25 +01:00
|
|
|
|
|
|
|
memset (auth_str, 0, RIP_AUTH_MD5_SIZE);
|
2004-06-07 00:06:33 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ri->key_chain)
|
|
|
|
{
|
|
|
|
keychain = keychain_lookup (ri->key_chain);
|
|
|
|
if (keychain == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
key = key_lookup_for_accept (keychain, md5->keyid);
|
|
|
|
if (key == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2006-01-17 18:26:25 +01:00
|
|
|
strncpy (auth_str, key->string, RIP_AUTH_MD5_SIZE);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2006-01-17 18:26:25 +01:00
|
|
|
else if (ri->auth_str)
|
|
|
|
strncpy (auth_str, ri->auth_str, RIP_AUTH_MD5_SIZE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2008-05-29 21:03:08 +02:00
|
|
|
if (auth_str[0] == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
2006-01-17 18:26:25 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* MD5 digest authentication. */
|
2005-09-28 17:47:44 +02:00
|
|
|
memset (&ctx, 0, sizeof(ctx));
|
|
|
|
MD5Init(&ctx);
|
2006-01-17 18:26:25 +01:00
|
|
|
MD5Update(&ctx, packet, packet_len + RIP_HEADER_SIZE);
|
|
|
|
MD5Update(&ctx, auth_str, RIP_AUTH_MD5_SIZE);
|
2005-09-28 17:47:44 +02:00
|
|
|
MD5Final(digest, &ctx);
|
2006-01-17 18:26:25 +01:00
|
|
|
|
|
|
|
if (memcmp (md5data->digest, digest, RIP_AUTH_MD5_SIZE) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
return packet_len;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
/* Pick correct auth string for sends, prepare auth_str buffer for use.
|
|
|
|
* (left justified and padded).
|
|
|
|
*
|
|
|
|
* presumes one of ri or key is valid, and that the auth strings they point
|
|
|
|
* to are nul terminated. If neither are present, auth_str will be fully
|
|
|
|
* zero padded.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
rip_auth_prepare_str_send (struct rip_interface *ri, struct key *key,
|
|
|
|
char *auth_str, int len)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2005-02-05 00:42:41 +01:00
|
|
|
assert (ri || key);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
memset (auth_str, 0, len);
|
|
|
|
if (key && key->string)
|
|
|
|
strncpy (auth_str, key->string, len);
|
|
|
|
else if (ri->auth_str)
|
|
|
|
strncpy (auth_str, ri->auth_str, len);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
/* Write RIPv2 simple password authentication information
|
|
|
|
*
|
|
|
|
* auth_str is presumed to be 2 bytes and correctly prepared
|
|
|
|
* (left justified and zero padded).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
rip_auth_simple_write (struct stream *s, char *auth_str, int len)
|
|
|
|
{
|
|
|
|
assert (s && len == RIP_AUTH_SIMPLE_SIZE);
|
|
|
|
|
|
|
|
stream_putw (s, RIP_FAMILY_AUTH);
|
|
|
|
stream_putw (s, RIP_AUTH_SIMPLE_PASSWORD);
|
|
|
|
stream_put (s, auth_str, RIP_AUTH_SIMPLE_SIZE);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
/* write RIPv2 MD5 "authentication header"
|
|
|
|
* (uses the auth key data field)
|
|
|
|
*
|
|
|
|
* Digest offset field is set to 0.
|
|
|
|
*
|
|
|
|
* returns: offset of the digest offset field, which must be set when
|
|
|
|
* length to the auth-data MD5 digest is known.
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
rip_auth_md5_ah_write (struct stream *s, struct rip_interface *ri,
|
|
|
|
struct key *key)
|
|
|
|
{
|
2006-01-17 18:26:25 +01:00
|
|
|
size_t doff = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
assert (s && ri && ri->auth_type == RIP_AUTH_MD5);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* MD5 authentication. */
|
2004-06-07 00:06:33 +02:00
|
|
|
stream_putw (s, RIP_FAMILY_AUTH);
|
2002-12-13 21:15:29 +01:00
|
|
|
stream_putw (s, RIP_AUTH_MD5);
|
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
/* MD5 AH digest offset field.
|
|
|
|
*
|
|
|
|
* Set to placeholder value here, to true value when RIP-2 Packet length
|
|
|
|
* is known. Actual value is set in .....().
|
|
|
|
*/
|
2006-01-17 18:26:25 +01:00
|
|
|
doff = stream_get_endp(s);
|
2005-02-05 00:42:41 +01:00
|
|
|
stream_putw (s, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Key ID. */
|
|
|
|
if (key)
|
|
|
|
stream_putc (s, key->index % 256);
|
|
|
|
else
|
|
|
|
stream_putc (s, 1);
|
|
|
|
|
2004-06-07 00:06:33 +02:00
|
|
|
/* Auth Data Len. Set 16 for MD5 authentication data. Older ripds
|
|
|
|
* however expect RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE so we allow for this
|
|
|
|
* to be configurable.
|
|
|
|
*/
|
|
|
|
stream_putc (s, ri->md5_auth_len);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Sequence Number (non-decreasing). */
|
|
|
|
/* RFC2080: The value used in the sequence number is
|
|
|
|
arbitrary, but two suggestions are the time of the
|
|
|
|
message's creation or a simple message counter. */
|
|
|
|
stream_putl (s, time (NULL));
|
|
|
|
|
|
|
|
/* Reserved field must be zero. */
|
|
|
|
stream_putl (s, 0);
|
|
|
|
stream_putl (s, 0);
|
|
|
|
|
2006-01-17 18:26:25 +01:00
|
|
|
return doff;
|
2005-02-05 00:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If authentication is in used, write the appropriate header
|
|
|
|
* returns stream offset to which length must later be written
|
|
|
|
* or 0 if this is not required
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
rip_auth_header_write (struct stream *s, struct rip_interface *ri,
|
|
|
|
struct key *key, char *auth_str, int len)
|
|
|
|
{
|
|
|
|
assert (ri->auth_type != RIP_NO_AUTH);
|
|
|
|
|
|
|
|
switch (ri->auth_type)
|
|
|
|
{
|
|
|
|
case RIP_AUTH_SIMPLE_PASSWORD:
|
|
|
|
rip_auth_prepare_str_send (ri, key, auth_str, len);
|
|
|
|
rip_auth_simple_write (s, auth_str, len);
|
|
|
|
return 0;
|
|
|
|
case RIP_AUTH_MD5:
|
|
|
|
return rip_auth_md5_ah_write (s, ri, key);
|
|
|
|
}
|
|
|
|
assert (1);
|
2006-01-17 18:26:25 +01:00
|
|
|
return 0;
|
2005-02-05 00:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write RIPv2 MD5 authentication data trailer */
|
|
|
|
static void
|
|
|
|
rip_auth_md5_set (struct stream *s, struct rip_interface *ri, size_t doff,
|
|
|
|
char *auth_str, int authlen)
|
|
|
|
{
|
|
|
|
unsigned long len;
|
2005-09-28 17:47:44 +02:00
|
|
|
MD5_CTX ctx;
|
2005-02-05 00:42:41 +01:00
|
|
|
unsigned char digest[RIP_AUTH_MD5_SIZE];
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-02-05 00:42:41 +01:00
|
|
|
/* Make it sure this interface is configured as MD5
|
|
|
|
authentication. */
|
|
|
|
assert ((ri->auth_type == RIP_AUTH_MD5) && (authlen == RIP_AUTH_MD5_SIZE));
|
|
|
|
assert (doff > 0);
|
|
|
|
|
|
|
|
/* Get packet length. */
|
|
|
|
len = stream_get_endp(s);
|
|
|
|
|
|
|
|
/* Check packet length. */
|
|
|
|
if (len < (RIP_HEADER_SIZE + RIP_RTE_SIZE))
|
|
|
|
{
|
|
|
|
zlog_err ("rip_auth_md5_set(): packet length %ld is less than minimum length.", len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the digest offset length in the header */
|
|
|
|
stream_putw_at (s, doff, len);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Set authentication data. */
|
2004-06-07 00:06:33 +02:00
|
|
|
stream_putw (s, RIP_FAMILY_AUTH);
|
|
|
|
stream_putw (s, RIP_AUTH_DATA);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Generate a digest for the RIP packet. */
|
2005-09-28 17:47:44 +02:00
|
|
|
memset(&ctx, 0, sizeof(ctx));
|
|
|
|
MD5Init(&ctx);
|
2006-01-17 18:26:25 +01:00
|
|
|
MD5Update(&ctx, STREAM_DATA (s), stream_get_endp (s));
|
2005-09-28 17:47:44 +02:00
|
|
|
MD5Update(&ctx, auth_str, RIP_AUTH_MD5_SIZE);
|
|
|
|
MD5Final(digest, &ctx);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Copy the digest to the packet. */
|
|
|
|
stream_write (s, digest, RIP_AUTH_MD5_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP routing information. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_response_process (struct rip_packet *packet, int size,
|
2004-10-22 12:27:28 +02:00
|
|
|
struct sockaddr_in *from, struct connected *ifc)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
caddr_t lim;
|
|
|
|
struct rte *rte;
|
2002-12-13 21:50:29 +01:00
|
|
|
struct prefix_ipv4 ifaddr;
|
|
|
|
struct prefix_ipv4 ifaddrclass;
|
|
|
|
int subnetted;
|
2015-09-29 15:19:30 +02:00
|
|
|
|
|
|
|
memset(&ifaddr, 0, sizeof(ifaddr));
|
2002-12-13 21:50:29 +01:00
|
|
|
/* We don't know yet. */
|
|
|
|
subnetted = -1;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* The Response must be ignored if it is not from the RIP
|
|
|
|
port. (RFC2453 - Sec. 3.9.2)*/
|
2004-06-07 00:06:33 +02:00
|
|
|
if (from->sin_port != htons(RIP_PORT_DEFAULT))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
zlog_info ("response doesn't come from RIP port: %d",
|
|
|
|
from->sin_port);
|
|
|
|
rip_peer_bad_packet (from);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The datagram's IPv4 source address should be checked to see
|
|
|
|
whether the datagram is from a valid neighbor; the source of the
|
2005-10-31 00:51:32 +01:00
|
|
|
datagram must be on a directly connected network (RFC2453 - Sec. 3.9.2) */
|
2017-03-10 21:54:53 +01:00
|
|
|
if (if_lookup_address((void *)&from->sin_addr, AF_INET, VRF_DEFAULT) == NULL)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
zlog_info ("This datagram doesn't came from a valid neighbor: %s",
|
|
|
|
inet_ntoa (from->sin_addr));
|
|
|
|
rip_peer_bad_packet (from);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It is also worth checking to see whether the response is from one
|
|
|
|
of the router's own addresses. */
|
|
|
|
|
|
|
|
; /* Alredy done in rip_read () */
|
|
|
|
|
|
|
|
/* Update RIP peer. */
|
|
|
|
rip_peer_update (from, packet->version);
|
|
|
|
|
|
|
|
/* Set RTE pointer. */
|
|
|
|
rte = packet->rte;
|
|
|
|
|
|
|
|
for (lim = (caddr_t) packet + size; (caddr_t) rte < lim; rte++)
|
|
|
|
{
|
|
|
|
/* RIPv2 authentication check. */
|
|
|
|
/* If the Address Family Identifier of the first (and only the
|
|
|
|
first) entry in the message is 0xFFFF, then the remainder of
|
|
|
|
the entry contains the authentication. */
|
|
|
|
/* If the packet gets here it means authentication enabled */
|
|
|
|
/* Check is done in rip_read(). So, just skipping it */
|
|
|
|
if (packet->version == RIPv2 &&
|
|
|
|
rte == packet->rte &&
|
2004-06-07 00:06:33 +02:00
|
|
|
rte->family == htons(RIP_FAMILY_AUTH))
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
|
2004-06-07 00:06:33 +02:00
|
|
|
if (rte->family != htons(AF_INET))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Address family check. RIP only supports AF_INET. */
|
|
|
|
zlog_info ("Unsupported family %d from %s.",
|
|
|
|
ntohs (rte->family), inet_ntoa (from->sin_addr));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - is the destination address valid (e.g., unicast; not net 0
|
|
|
|
or 127) */
|
|
|
|
if (! rip_destination_check (rte->prefix))
|
|
|
|
{
|
|
|
|
zlog_info ("Network is net 0 or net 127 or it is not unicast network");
|
|
|
|
rip_peer_bad_route (from);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert metric value to host byte order. */
|
|
|
|
rte->metric = ntohl (rte->metric);
|
|
|
|
|
|
|
|
/* - is the metric valid (i.e., between 1 and 16, inclusive) */
|
|
|
|
if (! (rte->metric >= 1 && rte->metric <= 16))
|
|
|
|
{
|
|
|
|
zlog_info ("Route's metric is not in the 1-16 range.");
|
|
|
|
rip_peer_bad_route (from);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIPv1 does not have nexthop value. */
|
|
|
|
if (packet->version == RIPv1 && rte->nexthop.s_addr != 0)
|
|
|
|
{
|
|
|
|
zlog_info ("RIPv1 packet with nexthop value %s",
|
|
|
|
inet_ntoa (rte->nexthop));
|
|
|
|
rip_peer_bad_route (from);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* That is, if the provided information is ignored, a possibly
|
|
|
|
sub-optimal, but absolutely valid, route may be taken. If
|
|
|
|
the received Next Hop is not directly reachable, it should be
|
|
|
|
treated as 0.0.0.0. */
|
|
|
|
if (packet->version == RIPv2 && rte->nexthop.s_addr != 0)
|
|
|
|
{
|
|
|
|
u_int32_t addrval;
|
|
|
|
|
|
|
|
/* Multicast address check. */
|
|
|
|
addrval = ntohl (rte->nexthop.s_addr);
|
|
|
|
if (IN_CLASSD (addrval))
|
|
|
|
{
|
|
|
|
zlog_info ("Nexthop %s is multicast address, skip this rte",
|
|
|
|
inet_ntoa (rte->nexthop));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-10 21:54:53 +01:00
|
|
|
if (! if_lookup_address ((void *)&rte->nexthop, AF_INET, VRF_DEFAULT))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_info *rinfo;
|
|
|
|
|
|
|
|
rn = route_node_match_ipv4 (rip->table, &rte->nexthop);
|
|
|
|
|
|
|
|
if (rn)
|
|
|
|
{
|
|
|
|
rinfo = rn->info;
|
|
|
|
|
|
|
|
if (rinfo->type == ZEBRA_ROUTE_RIP
|
|
|
|
&& rinfo->sub_type == RIP_ROUTE_RTE)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Next hop %s is on RIP network. Set nexthop to the packet's originator", inet_ntoa (rte->nexthop));
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->nexthop = rinfo->from;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte->nexthop));
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->nexthop.s_addr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
route_unlock_node (rn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte->nexthop));
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->nexthop.s_addr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For RIPv1, there won't be a valid netmask.
|
|
|
|
|
|
|
|
This is a best guess at the masks. If everyone was using old
|
|
|
|
Ciscos before the 'ip subnet zero' option, it would be almost
|
|
|
|
right too :-)
|
|
|
|
|
|
|
|
Cisco summarize ripv1 advertisments to the classful boundary
|
|
|
|
(/16 for class B's) except when the RIP packet does to inside
|
|
|
|
the classful network in question. */
|
|
|
|
|
|
|
|
if ((packet->version == RIPv1 && rte->prefix.s_addr != 0)
|
|
|
|
|| (packet->version == RIPv2
|
|
|
|
&& (rte->prefix.s_addr != 0 && rte->mask.s_addr == 0)))
|
|
|
|
{
|
|
|
|
u_int32_t destination;
|
|
|
|
|
2002-12-13 21:50:29 +01:00
|
|
|
if (subnetted == -1)
|
2004-10-22 12:27:28 +02:00
|
|
|
{
|
|
|
|
memcpy (&ifaddr, ifc->address, sizeof (struct prefix_ipv4));
|
|
|
|
memcpy (&ifaddrclass, &ifaddr, sizeof (struct prefix_ipv4));
|
|
|
|
apply_classful_mask_ipv4 (&ifaddrclass);
|
|
|
|
subnetted = 0;
|
|
|
|
if (ifaddr.prefixlen > ifaddrclass.prefixlen)
|
|
|
|
subnetted = 1;
|
|
|
|
}
|
2002-12-13 21:50:29 +01:00
|
|
|
|
|
|
|
destination = ntohl (rte->prefix.s_addr);
|
|
|
|
|
|
|
|
if (IN_CLASSA (destination))
|
|
|
|
masklen2ip (8, &rte->mask);
|
|
|
|
else if (IN_CLASSB (destination))
|
|
|
|
masklen2ip (16, &rte->mask);
|
|
|
|
else if (IN_CLASSC (destination))
|
2002-12-13 21:15:29 +01:00
|
|
|
masklen2ip (24, &rte->mask);
|
2002-12-13 21:50:29 +01:00
|
|
|
|
|
|
|
if (subnetted == 1)
|
|
|
|
masklen2ip (ifaddrclass.prefixlen,
|
|
|
|
(struct in_addr *) &destination);
|
|
|
|
if ((subnetted == 1) && ((rte->prefix.s_addr & destination) ==
|
|
|
|
ifaddrclass.prefix.s_addr))
|
|
|
|
{
|
|
|
|
masklen2ip (ifaddr.prefixlen, &rte->mask);
|
|
|
|
if ((rte->prefix.s_addr & rte->mask.s_addr) != rte->prefix.s_addr)
|
|
|
|
masklen2ip (32, &rte->mask);
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Subnetted route %s", inet_ntoa (rte->prefix));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2002-12-13 21:50:29 +01:00
|
|
|
else
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2002-12-13 21:50:29 +01:00
|
|
|
if ((rte->prefix.s_addr & rte->mask.s_addr) != rte->prefix.s_addr)
|
|
|
|
continue;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2002-12-13 21:50:29 +01:00
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Resultant route %s", inet_ntoa (rte->prefix));
|
|
|
|
zlog_debug ("Resultant mask %s", inet_ntoa (rte->mask));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In case of RIPv2, if prefix in RTE is not netmask applied one
|
|
|
|
ignore the entry. */
|
|
|
|
if ((packet->version == RIPv2)
|
|
|
|
&& (rte->mask.s_addr != 0)
|
|
|
|
&& ((rte->prefix.s_addr & rte->mask.s_addr) != rte->prefix.s_addr))
|
|
|
|
{
|
|
|
|
zlog_warn ("RIPv2 address %s is not mask /%d applied one",
|
|
|
|
inet_ntoa (rte->prefix), ip_masklen (rte->mask));
|
|
|
|
rip_peer_bad_route (from);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default route's netmask is ignored. */
|
|
|
|
if (packet->version == RIPv2
|
|
|
|
&& (rte->prefix.s_addr == 0)
|
|
|
|
&& (rte->mask.s_addr != 0))
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Default route with non-zero netmask. Set zero to netmask");
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->mask.s_addr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Routing table updates. */
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_rte_process (rte, from, ifc->ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-03 19:46:49 +02:00
|
|
|
/* Make socket for RIP protocol. */
|
2005-06-03 20:01:50 +02:00
|
|
|
static int
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
rip_create_socket (void)
|
2005-06-03 19:46:49 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int sock;
|
|
|
|
struct sockaddr_in addr;
|
2005-06-03 20:01:50 +02:00
|
|
|
|
2005-08-16 17:22:14 +02:00
|
|
|
memset (&addr, 0, sizeof (struct sockaddr_in));
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_addr.s_addr = INADDR_ANY;
|
[autoconf] bugs 162,303,178: Fix 'present but can not be compiled' warnings
2007-05-09 Paul Jakma <paul.jakma@sun.com>
* configure.ac: sys/conf.h depends on sys/param.h, at least on
FBSD 6.2.
(bug #363) Should check for in_pktinfo for IRDP
2006-05-27 Paul Jakma <paul.jakma@sun.com>
* configure.ac: General cleanup of header and type checks, introducing
an internal define, QUAGGA_INCLUDES, to build up a list of
stuff to include so as to avoid 'present but cant be compiled'
warnings.
Misc additional checks of things missing according to autoscan.
Add LIBM, for bgpd's use of libm, so as to avoid burdening
LIBS, and all the binaries, with libm linkage.
Remove the bad practice of using m4 changequote(), just
quote the []'s in the case statements properly.
This should fix bugs 162, 303 and 178.
* */*.{c,h}: Update all HAVE_* to the standard autoconf namespaced
HAVE_* defines. I.e. HAVE_SA_LEN -> HAVE_STRUCT_SOCKADDR_SA_LEN,
* bgpd/Makefile.am: Add LIBM to bgpd's LDADD, for pow().
2007-05-10 04:38:51 +02:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
addr.sin_len = sizeof (struct sockaddr_in);
|
[autoconf] bugs 162,303,178: Fix 'present but can not be compiled' warnings
2007-05-09 Paul Jakma <paul.jakma@sun.com>
* configure.ac: sys/conf.h depends on sys/param.h, at least on
FBSD 6.2.
(bug #363) Should check for in_pktinfo for IRDP
2006-05-27 Paul Jakma <paul.jakma@sun.com>
* configure.ac: General cleanup of header and type checks, introducing
an internal define, QUAGGA_INCLUDES, to build up a list of
stuff to include so as to avoid 'present but cant be compiled'
warnings.
Misc additional checks of things missing according to autoscan.
Add LIBM, for bgpd's use of libm, so as to avoid burdening
LIBS, and all the binaries, with libm linkage.
Remove the bad practice of using m4 changequote(), just
quote the []'s in the case statements properly.
This should fix bugs 162, 303 and 178.
* */*.{c,h}: Update all HAVE_* to the standard autoconf namespaced
HAVE_* defines. I.e. HAVE_SA_LEN -> HAVE_STRUCT_SOCKADDR_SA_LEN,
* bgpd/Makefile.am: Add LIBM to bgpd's LDADD, for pow().
2007-05-10 04:38:51 +02:00
|
|
|
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
|
2005-08-16 17:22:14 +02:00
|
|
|
/* sending port must always be the RIP port */
|
|
|
|
addr.sin_port = htons (RIP_PORT_DEFAULT);
|
|
|
|
|
2005-06-03 19:46:49 +02:00
|
|
|
/* Make datagram socket. */
|
2016-11-12 22:34:37 +01:00
|
|
|
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
2005-06-03 19:46:49 +02:00
|
|
|
if (sock < 0)
|
|
|
|
{
|
|
|
|
zlog_err("Cannot create UDP socket: %s", safe_strerror(errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sockopt_broadcast (sock);
|
|
|
|
sockopt_reuseaddr (sock);
|
|
|
|
sockopt_reuseport (sock);
|
2016-11-12 22:11:13 +01:00
|
|
|
setsockopt_ipv4_multicast_loop (sock, 0);
|
2005-06-03 19:46:49 +02:00
|
|
|
#ifdef RIP_RECVMSG
|
|
|
|
setsockopt_pktinfo (sock);
|
|
|
|
#endif /* RIP_RECVMSG */
|
2009-07-22 01:27:26 +02:00
|
|
|
#ifdef IPTOS_PREC_INTERNETCONTROL
|
|
|
|
setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
|
|
|
|
#endif
|
2005-06-03 19:46:49 +02:00
|
|
|
|
|
|
|
if (ripd_privs.change (ZPRIVS_RAISE))
|
|
|
|
zlog_err ("rip_create_socket: could not raise privs");
|
2005-06-03 20:01:50 +02:00
|
|
|
setsockopt_so_recvbuf (sock, RIP_UDP_RCV_BUF);
|
|
|
|
if ( (ret = bind (sock, (struct sockaddr *) & addr, sizeof (addr))) < 0)
|
|
|
|
|
2005-06-03 19:46:49 +02:00
|
|
|
{
|
|
|
|
int save_errno = errno;
|
|
|
|
if (ripd_privs.change (ZPRIVS_LOWER))
|
|
|
|
zlog_err ("rip_create_socket: could not lower privs");
|
2005-08-16 17:22:14 +02:00
|
|
|
|
|
|
|
zlog_err("%s: Can't bind socket %d to %s port %d: %s", __func__,
|
|
|
|
sock, inet_ntoa(addr.sin_addr),
|
|
|
|
(int) ntohs(addr.sin_port),
|
|
|
|
safe_strerror(save_errno));
|
|
|
|
|
2005-06-03 20:01:50 +02:00
|
|
|
close (sock);
|
2005-06-03 19:46:49 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2005-06-03 20:01:50 +02:00
|
|
|
|
2005-06-03 19:46:49 +02:00
|
|
|
if (ripd_privs.change (ZPRIVS_LOWER))
|
|
|
|
zlog_err ("rip_create_socket: could not lower privs");
|
|
|
|
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
/* RIP packet send to destination address, on interface denoted by
|
|
|
|
* by connected argument. NULL to argument denotes destination should be
|
|
|
|
* should be RIP multicast group
|
|
|
|
*/
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_send_packet (u_char * buf, int size, struct sockaddr_in *to,
|
|
|
|
struct connected *ifc)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
int ret;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct sockaddr_in sin;
|
2004-10-22 12:27:28 +02:00
|
|
|
|
|
|
|
assert (ifc != NULL);
|
|
|
|
|
2004-01-23 16:31:42 +01:00
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
{
|
2005-06-03 20:01:50 +02:00
|
|
|
#define ADDRESS_SIZE 20
|
|
|
|
char dst[ADDRESS_SIZE];
|
|
|
|
dst[ADDRESS_SIZE - 1] = '\0';
|
|
|
|
|
2004-01-23 16:31:42 +01:00
|
|
|
if (to)
|
|
|
|
{
|
2005-06-03 20:01:50 +02:00
|
|
|
strncpy (dst, inet_ntoa(to->sin_addr), ADDRESS_SIZE - 1);
|
2004-01-23 16:31:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
|
2005-06-03 20:01:50 +02:00
|
|
|
strncpy (dst, inet_ntoa(sin.sin_addr), ADDRESS_SIZE - 1);
|
2004-01-23 16:31:42 +01:00
|
|
|
}
|
2005-06-03 20:01:50 +02:00
|
|
|
#undef ADDRESS_SIZE
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug("rip_send_packet %s > %s (%s)",
|
2004-10-22 12:27:28 +02:00
|
|
|
inet_ntoa(ifc->address->u.prefix4),
|
|
|
|
dst, ifc->ifp->name);
|
2004-01-23 16:31:42 +01:00
|
|
|
}
|
2005-06-03 20:01:50 +02:00
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
if ( CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY) )
|
2004-01-23 16:31:42 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ZEBRA_IFA_SECONDARY is set on linux when an interface is configured
|
|
|
|
* with multiple addresses on the same subnet: the first address
|
|
|
|
* on the subnet is configured "primary", and all subsequent addresses
|
|
|
|
* on that subnet are treated as "secondary" addresses.
|
|
|
|
* In order to avoid routing-table bloat on other rip listeners,
|
|
|
|
* we do not send out RIP packets with ZEBRA_IFA_SECONDARY source addrs.
|
|
|
|
* XXX Since Linux is the only system for which the ZEBRA_IFA_SECONDARY
|
|
|
|
* flag is set, we would end up sending a packet for a "secondary"
|
|
|
|
* source address on non-linux systems.
|
|
|
|
*/
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug("duplicate dropped");
|
2004-01-23 16:31:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make destination address. */
|
|
|
|
memset (&sin, 0, sizeof (struct sockaddr_in));
|
|
|
|
sin.sin_family = AF_INET;
|
[autoconf] bugs 162,303,178: Fix 'present but can not be compiled' warnings
2007-05-09 Paul Jakma <paul.jakma@sun.com>
* configure.ac: sys/conf.h depends on sys/param.h, at least on
FBSD 6.2.
(bug #363) Should check for in_pktinfo for IRDP
2006-05-27 Paul Jakma <paul.jakma@sun.com>
* configure.ac: General cleanup of header and type checks, introducing
an internal define, QUAGGA_INCLUDES, to build up a list of
stuff to include so as to avoid 'present but cant be compiled'
warnings.
Misc additional checks of things missing according to autoscan.
Add LIBM, for bgpd's use of libm, so as to avoid burdening
LIBS, and all the binaries, with libm linkage.
Remove the bad practice of using m4 changequote(), just
quote the []'s in the case statements properly.
This should fix bugs 162, 303 and 178.
* */*.{c,h}: Update all HAVE_* to the standard autoconf namespaced
HAVE_* defines. I.e. HAVE_SA_LEN -> HAVE_STRUCT_SOCKADDR_SA_LEN,
* bgpd/Makefile.am: Add LIBM to bgpd's LDADD, for pow().
2007-05-10 04:38:51 +02:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
2002-12-13 21:15:29 +01:00
|
|
|
sin.sin_len = sizeof (struct sockaddr_in);
|
[autoconf] bugs 162,303,178: Fix 'present but can not be compiled' warnings
2007-05-09 Paul Jakma <paul.jakma@sun.com>
* configure.ac: sys/conf.h depends on sys/param.h, at least on
FBSD 6.2.
(bug #363) Should check for in_pktinfo for IRDP
2006-05-27 Paul Jakma <paul.jakma@sun.com>
* configure.ac: General cleanup of header and type checks, introducing
an internal define, QUAGGA_INCLUDES, to build up a list of
stuff to include so as to avoid 'present but cant be compiled'
warnings.
Misc additional checks of things missing according to autoscan.
Add LIBM, for bgpd's use of libm, so as to avoid burdening
LIBS, and all the binaries, with libm linkage.
Remove the bad practice of using m4 changequote(), just
quote the []'s in the case statements properly.
This should fix bugs 162, 303 and 178.
* */*.{c,h}: Update all HAVE_* to the standard autoconf namespaced
HAVE_* defines. I.e. HAVE_SA_LEN -> HAVE_STRUCT_SOCKADDR_SA_LEN,
* bgpd/Makefile.am: Add LIBM to bgpd's LDADD, for pow().
2007-05-10 04:38:51 +02:00
|
|
|
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* When destination is specified, use it's port and address. */
|
|
|
|
if (to)
|
|
|
|
{
|
|
|
|
sin.sin_port = to->sin_port;
|
|
|
|
sin.sin_addr = to->sin_addr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sin.sin_port = htons (RIP_PORT_DEFAULT);
|
|
|
|
sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
|
|
|
|
rip_interface_multicast_set (rip->sock, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
ret = sendto (rip->sock, buf, size, 0, (struct sockaddr *)&sin,
|
2002-12-13 21:15:29 +01:00
|
|
|
sizeof (struct sockaddr_in));
|
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("SEND to %s.%d", inet_ntoa(sin.sin_addr),
|
2003-10-16 01:20:17 +02:00
|
|
|
ntohs (sin.sin_port));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (ret < 0)
|
2004-11-20 03:06:59 +01:00
|
|
|
zlog_warn ("can't send packet : %s", safe_strerror (errno));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add redistributed route to RIP table. */
|
|
|
|
void
|
|
|
|
rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p,
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t ifindex, struct in_addr *nexthop,
|
2016-10-01 21:43:17 +02:00
|
|
|
unsigned int metric, unsigned char distance,
|
|
|
|
route_tag_t tag)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct route_node *rp = NULL;
|
|
|
|
struct rip_info *rinfo = NULL, newinfo;
|
|
|
|
struct list *list = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Redistribute route */
|
|
|
|
ret = rip_destination_check (p->prefix);
|
|
|
|
if (! ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rp = route_node_get (rip->table, (struct prefix *) p);
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
memset (&newinfo, 0, sizeof (struct rip_info));
|
|
|
|
newinfo.type = type;
|
|
|
|
newinfo.sub_type = sub_type;
|
|
|
|
newinfo.ifindex = ifindex;
|
|
|
|
newinfo.metric = 1;
|
|
|
|
newinfo.external_metric = metric;
|
|
|
|
newinfo.distance = distance;
|
2016-10-01 21:43:17 +02:00
|
|
|
if (tag <= UINT16_MAX) /* RIP only supports 16 bit tags */
|
|
|
|
newinfo.tag = tag;
|
2014-07-18 08:13:18 +02:00
|
|
|
newinfo.rp = rp;
|
|
|
|
if (nexthop)
|
|
|
|
newinfo.nexthop = *nexthop;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL && listcount (list) != 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rinfo->type == ZEBRA_ROUTE_CONNECT
|
|
|
|
&& rinfo->sub_type == RIP_ROUTE_INTERFACE
|
|
|
|
&& rinfo->metric != RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Manually configured RIP route check. */
|
|
|
|
if (rinfo->type == ZEBRA_ROUTE_RIP
|
2003-05-25 16:49:19 +02:00
|
|
|
&& ((rinfo->sub_type == RIP_ROUTE_STATIC) ||
|
|
|
|
(rinfo->sub_type == RIP_ROUTE_DEFAULT)) )
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2003-05-25 16:49:19 +02:00
|
|
|
if (type != ZEBRA_ROUTE_RIP || ((sub_type != RIP_ROUTE_STATIC) &&
|
|
|
|
(sub_type != RIP_ROUTE_DEFAULT)))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
route_unlock_node (rp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = rip_ecmp_replace (&newinfo);
|
|
|
|
route_unlock_node (rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2014-07-18 08:13:18 +02:00
|
|
|
else
|
|
|
|
rinfo = rip_ecmp_add (&newinfo);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
if (IS_RIP_DEBUG_EVENT) {
|
|
|
|
if (!nexthop)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
|
2017-03-11 13:47:46 +01:00
|
|
|
inet_ntoa(p->prefix), p->prefixlen,
|
|
|
|
ifindex2ifname(ifindex, VRF_DEFAULT));
|
2003-05-25 16:49:19 +02:00
|
|
|
else
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
|
2017-03-11 13:47:46 +01:00
|
|
|
inet_ntoa(p->prefix), p->prefixlen, inet_ntoa(rinfo->nexthop),
|
|
|
|
ifindex2ifname(ifindex, VRF_DEFAULT));
|
2003-05-25 16:49:19 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete redistributed route from RIP table. */
|
|
|
|
void
|
|
|
|
rip_redistribute_delete (int type, int sub_type, struct prefix_ipv4 *p,
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t ifindex)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct route_node *rp;
|
|
|
|
struct rip_info *rinfo;
|
|
|
|
|
|
|
|
ret = rip_destination_check (p->prefix);
|
|
|
|
if (! ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rp = route_node_lookup (rip->table, (struct prefix *) p);
|
|
|
|
if (rp)
|
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
struct list *list = rp->info;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +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 = RIP_METRIC_INFINITY;
|
|
|
|
RIP_TIMER_ON (rinfo->t_garbage_collect,
|
|
|
|
rip_garbage_collect, rip->garbage_time);
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
rinfo->flags |= RIP_RTF_CHANGED;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
|
|
|
zlog_debug ("Poisone %s/%d on the interface %s with an "
|
|
|
|
"infinity metric [delete]",
|
|
|
|
inet_ntoa(p->prefix), p->prefixlen,
|
2017-03-11 13:47:46 +01:00
|
|
|
ifindex2ifname(ifindex, VRF_DEFAULT));
|
2003-05-25 16:49:19 +02:00
|
|
|
|
2014-07-18 08:13:18 +02:00
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
route_unlock_node (rp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Response to request called from rip_read ().*/
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_request_process (struct rip_packet *packet, int size,
|
2004-10-22 12:27:28 +02:00
|
|
|
struct sockaddr_in *from, struct connected *ifc)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
caddr_t lim;
|
|
|
|
struct rte *rte;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *rp;
|
|
|
|
struct rip_info *rinfo;
|
|
|
|
struct rip_interface *ri;
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Does not reponse to the requests on the loopback interfaces */
|
2004-10-22 12:27:28 +02:00
|
|
|
if (if_is_loopback (ifc->ifp))
|
2003-05-25 16:49:19 +02:00
|
|
|
return;
|
|
|
|
|
2004-02-23 00:42:22 +01:00
|
|
|
/* Check RIP process is enabled on this interface. */
|
2004-10-22 12:27:28 +02:00
|
|
|
ri = ifc->ifp->info;
|
2003-05-25 16:49:19 +02:00
|
|
|
if (! ri->running)
|
|
|
|
return;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* When passive interface is specified, suppress responses */
|
|
|
|
if (ri->passive)
|
|
|
|
return;
|
2004-10-22 12:27:28 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP peer update. */
|
|
|
|
rip_peer_update (from, packet->version);
|
|
|
|
|
|
|
|
lim = ((caddr_t) packet) + size;
|
|
|
|
rte = packet->rte;
|
|
|
|
|
|
|
|
/* The Request is processed entry by entry. If there are no
|
|
|
|
entries, no response is given. */
|
|
|
|
if (lim == (caddr_t) rte)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* There is one special case. If there is exactly one entry in the
|
|
|
|
request, and it has an address family identifier of zero and a
|
|
|
|
metric of infinity (i.e., 16), then this is a request to send the
|
|
|
|
entire routing table. */
|
|
|
|
if (lim == ((caddr_t) (rte + 1)) &&
|
|
|
|
ntohs (rte->family) == 0 &&
|
|
|
|
ntohl (rte->metric) == RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
/* All route with split horizon */
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_output_process (ifc, from, rip_all_route, packet->version);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 15:54:07 +01:00
|
|
|
if (ntohs (rte->family) != AF_INET)
|
|
|
|
return;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* 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. */
|
|
|
|
p.family = AF_INET;
|
|
|
|
|
|
|
|
for (; ((caddr_t) rte) < lim; rte++)
|
|
|
|
{
|
|
|
|
p.prefix = rte->prefix;
|
|
|
|
p.prefixlen = ip_masklen (rte->mask);
|
|
|
|
apply_mask_ipv4 (&p);
|
|
|
|
|
|
|
|
rp = route_node_lookup (rip->table, (struct prefix *) &p);
|
|
|
|
if (rp)
|
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = listgetdata (listhead ((struct list *)rp->info));
|
2002-12-13 21:15:29 +01:00
|
|
|
rte->metric = htonl (rinfo->metric);
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rte->metric = htonl (RIP_METRIC_INFINITY);
|
|
|
|
}
|
|
|
|
packet->command = RIP_RESPONSE;
|
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_send_packet ((u_char *)packet, size, from, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
rip_global_queries++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if RIP_RECVMSG
|
|
|
|
/* Set IPv6 packet info to the socket. */
|
|
|
|
static int
|
|
|
|
setsockopt_pktinfo (int sock)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int val = 1;
|
|
|
|
|
|
|
|
ret = setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &val, sizeof(val));
|
|
|
|
if (ret < 0)
|
2004-11-20 03:06:59 +01:00
|
|
|
zlog_warn ("Can't setsockopt IP_PKTINFO : %s", safe_strerror (errno));
|
2002-12-13 21:15:29 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read RIP packet by recvmsg function. */
|
|
|
|
int
|
|
|
|
rip_recvmsg (int sock, u_char *buf, int size, struct sockaddr_in *from,
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t *ifindex)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov;
|
|
|
|
struct cmsghdr *ptr;
|
|
|
|
char adata[1024];
|
|
|
|
|
|
|
|
msg.msg_name = (void *) from;
|
|
|
|
msg.msg_namelen = sizeof (struct sockaddr_in);
|
|
|
|
msg.msg_iov = &iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
msg.msg_control = (void *) adata;
|
|
|
|
msg.msg_controllen = sizeof adata;
|
|
|
|
iov.iov_base = buf;
|
|
|
|
iov.iov_len = size;
|
|
|
|
|
|
|
|
ret = recvmsg (sock, &msg, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2005-01-04 17:24:43 +01:00
|
|
|
for (ptr = ZCMSG_FIRSTHDR(&msg); ptr != NULL; ptr = CMSG_NXTHDR(&msg, ptr))
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ptr->cmsg_level == IPPROTO_IP && ptr->cmsg_type == IP_PKTINFO)
|
|
|
|
{
|
|
|
|
struct in_pktinfo *pktinfo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pktinfo = (struct in_pktinfo *) CMSG_DATA (ptr);
|
|
|
|
i = pktinfo->ipi_ifindex;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP packet read function. */
|
|
|
|
int
|
|
|
|
rip_read_new (struct thread *t)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int sock;
|
|
|
|
char buf[RIP_PACKET_MAXSIZ];
|
|
|
|
struct sockaddr_in from;
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t ifindex;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Fetch socket then register myself. */
|
|
|
|
sock = THREAD_FD (t);
|
|
|
|
rip_event (RIP_READ, sock);
|
|
|
|
|
|
|
|
/* Read RIP packet. */
|
|
|
|
ret = rip_recvmsg (sock, buf, RIP_PACKET_MAXSIZ, &from, (int *)&ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2004-11-20 03:06:59 +01:00
|
|
|
zlog_warn ("Can't read RIP packet: %s", safe_strerror (errno));
|
2002-12-13 21:15:29 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* RIP_RECVMSG */
|
|
|
|
|
|
|
|
/* First entry point of RIP packet. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_read (struct thread *t)
|
|
|
|
{
|
|
|
|
int sock;
|
|
|
|
int ret;
|
|
|
|
int rtenum;
|
|
|
|
union rip_buf rip_buf;
|
|
|
|
struct rip_packet *packet;
|
|
|
|
struct sockaddr_in from;
|
2004-05-31 16:00:00 +02:00
|
|
|
int len;
|
2006-09-11 04:10:40 +02:00
|
|
|
int vrecv;
|
2004-05-31 16:00:00 +02:00
|
|
|
socklen_t fromlen;
|
2016-11-10 18:35:47 +01:00
|
|
|
struct interface *ifp = NULL;
|
2004-10-22 12:27:28 +02:00
|
|
|
struct connected *ifc;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct rip_interface *ri;
|
2016-05-12 00:52:30 +02:00
|
|
|
struct prefix p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Fetch socket then register myself. */
|
|
|
|
sock = THREAD_FD (t);
|
|
|
|
rip->t_read = NULL;
|
|
|
|
|
|
|
|
/* Add myself to tne next event */
|
|
|
|
rip_event (RIP_READ, sock);
|
|
|
|
|
|
|
|
/* RIPd manages only IPv4. */
|
|
|
|
memset (&from, 0, sizeof (struct sockaddr_in));
|
|
|
|
fromlen = sizeof (struct sockaddr_in);
|
|
|
|
|
|
|
|
len = recvfrom (sock, (char *)&rip_buf.buf, sizeof (rip_buf.buf), 0,
|
|
|
|
(struct sockaddr *) &from, &fromlen);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
2004-11-20 03:06:59 +01:00
|
|
|
zlog_info ("recvfrom failed: %s", safe_strerror (errno));
|
2002-12-13 21:15:29 +01:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check is this packet comming from myself? */
|
2003-09-29 21:54:53 +02:00
|
|
|
if (if_check_address (from.sin_addr))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("ignore packet comes from myself");
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Which interface is this packet comes from. */
|
2017-03-10 21:54:53 +01:00
|
|
|
ifc = if_lookup_address ((void *)&from.sin_addr, AF_INET, VRF_DEFAULT);
|
2016-11-10 18:35:47 +01:00
|
|
|
if (ifc)
|
|
|
|
ifp = ifc->ifp;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP packet received */
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RECV packet from %s port %d on %s",
|
2002-12-13 21:15:29 +01:00
|
|
|
inet_ntoa (from.sin_addr), ntohs (from.sin_port),
|
|
|
|
ifp ? ifp->name : "unknown");
|
|
|
|
|
|
|
|
/* If this packet come from unknown interface, ignore it. */
|
|
|
|
if (ifp == NULL)
|
|
|
|
{
|
2004-12-15 15:55:51 +01:00
|
|
|
zlog_info ("rip_read: cannot find interface for packet from %s port %d",
|
|
|
|
inet_ntoa(from.sin_addr), ntohs (from.sin_port));
|
2004-10-22 12:27:28 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-05-12 00:52:30 +02:00
|
|
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.u.prefix4 = from.sin_addr;
|
|
|
|
p.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
|
|
|
|
ifc = connected_lookup_prefix (ifp, &p);
|
2004-10-22 12:27:28 +02:00
|
|
|
|
|
|
|
if (ifc == NULL)
|
|
|
|
{
|
2004-12-15 15:55:51 +01:00
|
|
|
zlog_info ("rip_read: cannot find connected address for packet from %s "
|
|
|
|
"port %d on interface %s",
|
|
|
|
inet_ntoa(from.sin_addr), ntohs (from.sin_port), ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Packet length check. */
|
|
|
|
if (len < RIP_PACKET_MINSIZ)
|
|
|
|
{
|
|
|
|
zlog_warn ("packet size %d is smaller than minimum size %d",
|
|
|
|
len, RIP_PACKET_MINSIZ);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
if (len > RIP_PACKET_MAXSIZ)
|
|
|
|
{
|
|
|
|
zlog_warn ("packet size %d is larger than max size %d",
|
|
|
|
len, RIP_PACKET_MAXSIZ);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Packet alignment check. */
|
|
|
|
if ((len - RIP_PACKET_MINSIZ) % 20)
|
|
|
|
{
|
|
|
|
zlog_warn ("packet size %d is wrong for RIP packet alignment", len);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set RTE number. */
|
|
|
|
rtenum = ((len - RIP_PACKET_MINSIZ) / 20);
|
|
|
|
|
|
|
|
/* For easy to handle. */
|
|
|
|
packet = &rip_buf.rip_packet;
|
|
|
|
|
|
|
|
/* RIP version check. */
|
|
|
|
if (packet->version == 0)
|
|
|
|
{
|
|
|
|
zlog_info ("version 0 with command %d received.", packet->command);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump RIP packet. */
|
|
|
|
if (IS_RIP_DEBUG_RECV)
|
|
|
|
rip_packet_dump (packet, len, "RECV");
|
|
|
|
|
|
|
|
/* RIP version adjust. This code should rethink now. RFC1058 says
|
|
|
|
that "Version 1 implementations are to ignore this extra data and
|
|
|
|
process only the fields specified in this document.". So RIPv3
|
|
|
|
packet should be treated as RIPv1 ignoring must be zero field. */
|
|
|
|
if (packet->version > RIPv2)
|
|
|
|
packet->version = RIPv2;
|
|
|
|
|
|
|
|
/* Is RIP running or is this RIP neighbor ?*/
|
|
|
|
ri = ifp->info;
|
|
|
|
if (! ri->running && ! rip_neighbor_lookup (&from))
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIP is not enabled on interface %s.", ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-05-04 09:36:34 +02:00
|
|
|
/* RIP Version check. RFC2453, 4.6 and 5.1 */
|
2006-09-11 04:10:40 +02:00
|
|
|
vrecv = ((ri->ri_receive == RI_RIP_UNSPEC) ?
|
|
|
|
rip->version_recv : ri->ri_receive);
|
2016-11-10 16:15:43 +01:00
|
|
|
if (vrecv == RI_RIP_VERSION_NONE ||
|
|
|
|
((packet->version == RIPv1) && !(vrecv & RIPv1)) ||
|
|
|
|
((packet->version == RIPv2) && !(vrecv & RIPv2)))
|
2006-05-04 09:36:34 +02:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug (" packet's v%d doesn't fit to if version spec",
|
|
|
|
packet->version);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RFC2453 5.2 If the router is not configured to authenticate RIP-2
|
|
|
|
messages, then RIP-1 and unauthenticated RIP-2 messages will be
|
|
|
|
accepted; authenticated RIP-2 messages shall be discarded. */
|
|
|
|
if ((ri->auth_type == RIP_NO_AUTH)
|
|
|
|
&& rtenum
|
2004-06-07 00:06:33 +02:00
|
|
|
&& (packet->version == RIPv2)
|
|
|
|
&& (packet->rte->family == htons(RIP_FAMILY_AUTH)))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("packet RIPv%d is dropped because authentication disabled",
|
2002-12-13 21:15:29 +01:00
|
|
|
packet->version);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-05-04 09:36:34 +02:00
|
|
|
|
|
|
|
/* RFC:
|
|
|
|
If the router is configured to authenticate RIP-2 messages, then
|
2002-12-13 21:15:29 +01:00
|
|
|
RIP-1 messages and RIP-2 messages which pass authentication
|
|
|
|
testing shall be accepted; unauthenticated and failed
|
|
|
|
authentication RIP-2 messages shall be discarded. For maximum
|
|
|
|
security, RIP-1 messages should be ignored when authentication is
|
|
|
|
in use (see section 4.1); otherwise, the routing information from
|
|
|
|
authenticated messages will be propagated by RIP-1 routers in an
|
2006-05-04 09:36:34 +02:00
|
|
|
unauthenticated manner.
|
|
|
|
*/
|
|
|
|
/* We make an exception for RIPv1 REQUEST packets, to which we'll
|
|
|
|
* always reply regardless of authentication settings, because:
|
|
|
|
*
|
|
|
|
* - if there other authorised routers on-link, the REQUESTor can
|
|
|
|
* passively obtain the routing updates anyway
|
|
|
|
* - if there are no other authorised routers on-link, RIP can
|
|
|
|
* easily be disabled for the link to prevent giving out information
|
|
|
|
* on state of this routers RIP routing table..
|
|
|
|
*
|
|
|
|
* I.e. if RIPv1 has any place anymore these days, it's as a very
|
|
|
|
* simple way to distribute routing information (e.g. to embedded
|
|
|
|
* hosts / appliances) and the ability to give out RIPv1
|
|
|
|
* routing-information freely, while still requiring RIPv2
|
|
|
|
* authentication for any RESPONSEs might be vaguely useful.
|
|
|
|
*/
|
|
|
|
if (ri->auth_type != RIP_NO_AUTH
|
|
|
|
&& packet->version == RIPv1)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2006-05-04 09:36:34 +02:00
|
|
|
/* Discard RIPv1 messages other than REQUESTs */
|
|
|
|
if (packet->command != RIP_REQUEST)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv1" " dropped because authentication enabled");
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ri->auth_type != RIP_NO_AUTH)
|
|
|
|
{
|
|
|
|
const char *auth_desc;
|
|
|
|
|
|
|
|
if (rtenum == 0)
|
|
|
|
{
|
|
|
|
/* There definitely is no authentication in the packet. */
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv2 authentication failed: no auth RTE in packet");
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First RTE must be an Authentication Family RTE */
|
|
|
|
if (packet->rte->family != htons(RIP_FAMILY_AUTH))
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv2" " dropped because authentication enabled");
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
2006-05-04 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Check RIPv2 authentication. */
|
2006-05-04 09:36:34 +02:00
|
|
|
switch (ntohs(packet->rte->tag))
|
|
|
|
{
|
|
|
|
case RIP_AUTH_SIMPLE_PASSWORD:
|
|
|
|
auth_desc = "simple";
|
|
|
|
ret = rip_auth_simple_password (packet->rte, &from, ifp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIP_AUTH_MD5:
|
|
|
|
auth_desc = "MD5";
|
|
|
|
ret = rip_auth_md5 (packet, &from, len, ifp);
|
|
|
|
/* Reset RIP packet length to trim MD5 data. */
|
|
|
|
len = ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
auth_desc = "unknown type";
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv2 Unknown authentication type %d",
|
|
|
|
ntohs (packet->rte->tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv2 %s authentication success", auth_desc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
|
|
|
zlog_debug ("RIPv2 %s authentication failure", auth_desc);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process each command. */
|
|
|
|
switch (packet->command)
|
|
|
|
{
|
|
|
|
case RIP_RESPONSE:
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_response_process (packet, len, &from, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIP_REQUEST:
|
|
|
|
case RIP_POLL:
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_request_process (packet, len, &from, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIP_TRACEON:
|
|
|
|
case RIP_TRACEOFF:
|
|
|
|
zlog_info ("Obsolete command %s received, please sent it to routed",
|
|
|
|
lookup (rip_msg, packet->command));
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
break;
|
|
|
|
case RIP_POLL_ENTRY:
|
|
|
|
zlog_info ("Obsolete command %s received",
|
|
|
|
lookup (rip_msg, packet->command));
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
zlog_info ("Unknown RIP command %d received", packet->command);
|
|
|
|
rip_peer_bad_packet (&from);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write routing table entry to the stream and return next index of
|
|
|
|
the routing table entry in the stream. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_write_rte (int num, struct stream *s, struct prefix_ipv4 *p,
|
2005-02-05 00:42:41 +01:00
|
|
|
u_char version, struct rip_info *rinfo)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct in_addr mask;
|
|
|
|
|
|
|
|
/* Write routing table entry. */
|
|
|
|
if (version == RIPv1)
|
|
|
|
{
|
|
|
|
stream_putw (s, AF_INET);
|
|
|
|
stream_putw (s, 0);
|
|
|
|
stream_put_ipv4 (s, p->prefix.s_addr);
|
|
|
|
stream_put_ipv4 (s, 0);
|
|
|
|
stream_put_ipv4 (s, 0);
|
|
|
|
stream_putl (s, rinfo->metric_out);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
masklen2ip (p->prefixlen, &mask);
|
|
|
|
|
|
|
|
stream_putw (s, AF_INET);
|
2003-05-25 16:49:19 +02:00
|
|
|
stream_putw (s, rinfo->tag_out);
|
2002-12-13 21:15:29 +01:00
|
|
|
stream_put_ipv4 (s, p->prefix.s_addr);
|
|
|
|
stream_put_ipv4 (s, mask.s_addr);
|
|
|
|
stream_put_ipv4 (s, rinfo->nexthop_out.s_addr);
|
|
|
|
stream_putl (s, rinfo->metric_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ++num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send update to the ifp or spcified neighbor. */
|
|
|
|
void
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_output_process (struct connected *ifc, struct sockaddr_in *to,
|
|
|
|
int route_type, u_char version)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct stream *s;
|
|
|
|
struct route_node *rp;
|
|
|
|
struct rip_info *rinfo;
|
|
|
|
struct rip_interface *ri;
|
|
|
|
struct prefix_ipv4 *p;
|
|
|
|
struct prefix_ipv4 classfull;
|
2002-12-13 21:50:29 +01:00
|
|
|
struct prefix_ipv4 ifaddrclass;
|
2005-02-05 00:42:41 +01:00
|
|
|
struct key *key = NULL;
|
|
|
|
/* this might need to made dynamic if RIP ever supported auth methods
|
|
|
|
with larger key string sizes */
|
|
|
|
char auth_str[RIP_AUTH_SIMPLE_SIZE];
|
2005-10-26 01:31:05 +02:00
|
|
|
size_t doff = 0; /* offset of digest offset field */
|
2005-08-16 17:22:14 +02:00
|
|
|
int num = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
int rtemax;
|
2003-06-08 23:22:18 +02:00
|
|
|
int subnetted = 0;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Logging output event. */
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
|
|
|
{
|
|
|
|
if (to)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("update routes to neighbor %s", inet_ntoa (to->sin_addr));
|
2002-12-13 21:15:29 +01:00
|
|
|
else
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("update routes on interface %s ifindex %d",
|
2004-10-22 12:27:28 +02:00
|
|
|
ifc->ifp->name, ifc->ifp->ifindex);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set output stream. */
|
|
|
|
s = rip->obuf;
|
|
|
|
|
|
|
|
/* Reset stream and RTE counter. */
|
|
|
|
stream_reset (s);
|
2014-06-25 09:43:15 +02:00
|
|
|
rtemax = RIP_MAX_RTE;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Get RIP interface. */
|
2004-10-22 12:27:28 +02:00
|
|
|
ri = ifc->ifp->info;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* If output interface is in simple password authentication mode, we
|
|
|
|
need space for authentication data. */
|
|
|
|
if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD)
|
|
|
|
rtemax -= 1;
|
|
|
|
|
|
|
|
/* If output interface is in MD5 authentication mode, we need space
|
|
|
|
for authentication header and data. */
|
|
|
|
if (ri->auth_type == RIP_AUTH_MD5)
|
|
|
|
rtemax -= 2;
|
|
|
|
|
|
|
|
/* If output interface is in simple password authentication mode
|
|
|
|
and string or keychain is specified we need space for auth. data */
|
2005-02-05 00:42:41 +01:00
|
|
|
if (ri->auth_type != RIP_NO_AUTH)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (ri->key_chain)
|
|
|
|
{
|
|
|
|
struct keychain *keychain;
|
|
|
|
|
|
|
|
keychain = keychain_lookup (ri->key_chain);
|
|
|
|
if (keychain)
|
2005-02-05 00:42:41 +01:00
|
|
|
key = key_lookup_for_send (keychain);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2005-02-05 00:42:41 +01:00
|
|
|
/* to be passed to auth functions later */
|
|
|
|
rip_auth_prepare_str_send (ri, key, auth_str, RIP_AUTH_SIMPLE_SIZE);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:50:29 +01:00
|
|
|
if (version == RIPv1)
|
|
|
|
{
|
2004-10-22 12:27:28 +02:00
|
|
|
memcpy (&ifaddrclass, ifc->address, sizeof (struct prefix_ipv4));
|
2002-12-13 21:50:29 +01:00
|
|
|
apply_classful_mask_ipv4 (&ifaddrclass);
|
|
|
|
subnetted = 0;
|
2004-10-22 12:27:28 +02:00
|
|
|
if (ifc->address->prefixlen > ifaddrclass.prefixlen)
|
2003-06-08 23:22:18 +02:00
|
|
|
subnetted = 1;
|
2002-12-13 21:50:29 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
for (rp = route_top (rip->table); rp; rp = route_next (rp))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL && listcount (list) != 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = listgetdata (listhead (list));
|
2002-12-13 21:50:29 +01:00
|
|
|
/* For RIPv1, if we are subnetted, output subnets in our network */
|
|
|
|
/* that have the same mask as the output "interface". For other */
|
|
|
|
/* networks, only the classfull version is output. */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (version == RIPv1)
|
|
|
|
{
|
2002-12-13 21:50:29 +01:00
|
|
|
p = (struct prefix_ipv4 *) &rp->p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug("RIPv1 mask check, %s/%d considered for output",
|
2002-12-13 21:50:29 +01:00
|
|
|
inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2002-12-13 21:50:29 +01:00
|
|
|
if (subnetted &&
|
|
|
|
prefix_match ((struct prefix *) &ifaddrclass, &rp->p))
|
|
|
|
{
|
2004-10-22 12:27:28 +02:00
|
|
|
if ((ifc->address->prefixlen != rp->p.prefixlen) &&
|
2002-12-13 21:50:29 +01:00
|
|
|
(rp->p.prefixlen != 32))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy (&classfull, &rp->p, sizeof(struct prefix_ipv4));
|
|
|
|
apply_classful_mask_ipv4(&classfull);
|
|
|
|
if (rp->p.u.prefix4.s_addr != 0 &&
|
|
|
|
classfull.prefixlen != rp->p.prefixlen)
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug("RIPv1 mask check, %s/%d made it through",
|
2002-12-13 21:50:29 +01:00
|
|
|
inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
p = (struct prefix_ipv4 *) &rp->p;
|
|
|
|
|
|
|
|
/* Apply output filters. */
|
2016-09-22 23:11:05 +02:00
|
|
|
ret = rip_filter (RIP_FILTER_OUT, p, ri);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Changed route only output. */
|
|
|
|
if (route_type == rip_changed_route &&
|
|
|
|
(! (rinfo->flags & RIP_RTF_CHANGED)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Split horizon. */
|
|
|
|
/* if (split_horizon == rip_split_horizon) */
|
2003-05-25 16:49:19 +02:00
|
|
|
if (ri->split_horizon == RIP_SPLIT_HORIZON)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2003-11-17 10:15:18 +01:00
|
|
|
/*
|
|
|
|
* We perform split horizon for RIP and connected route.
|
|
|
|
* For rip routes, we want to suppress the route if we would
|
|
|
|
* end up sending the route back on the interface that we
|
|
|
|
* learned it from, with a higher metric. For connected routes,
|
|
|
|
* we suppress the route if the prefix is a subset of the
|
|
|
|
* source address that we are going to use for the packet
|
|
|
|
* (in order to handle the case when multiple subnets are
|
|
|
|
* configured on the same interface).
|
|
|
|
*/
|
2014-07-18 08:13:18 +02:00
|
|
|
int suppress = 0;
|
|
|
|
struct rip_info *tmp_rinfo = NULL;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo->type == ZEBRA_ROUTE_RIP &&
|
|
|
|
tmp_rinfo->ifindex == ifc->ifp->ifindex)
|
|
|
|
{
|
|
|
|
suppress = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!suppress && rinfo->type == ZEBRA_ROUTE_CONNECT &&
|
2004-10-22 12:27:28 +02:00
|
|
|
prefix_match((struct prefix *)p, ifc->address))
|
2014-07-18 08:13:18 +02:00
|
|
|
suppress = 1;
|
|
|
|
|
|
|
|
if (suppress)
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Preparation for route-map. */
|
|
|
|
rinfo->metric_set = 0;
|
|
|
|
rinfo->nexthop_out.s_addr = 0;
|
|
|
|
rinfo->metric_out = rinfo->metric;
|
2003-05-25 16:49:19 +02:00
|
|
|
rinfo->tag_out = rinfo->tag;
|
2004-10-22 12:27:28 +02:00
|
|
|
rinfo->ifindex_out = ifc->ifp->ifindex;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* In order to avoid some local loops,
|
|
|
|
* if the RIP 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.
|
|
|
|
* see (4.4)
|
|
|
|
*/
|
2004-10-22 12:27:28 +02:00
|
|
|
if (rinfo->ifindex == ifc->ifp->ifindex)
|
2002-12-13 21:15:29 +01:00
|
|
|
rinfo->nexthop_out = rinfo->nexthop;
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
/* Interface route-map */
|
|
|
|
if (ri->routemap[RIP_FILTER_OUT])
|
|
|
|
{
|
|
|
|
ret = route_map_apply (ri->routemap[RIP_FILTER_OUT],
|
|
|
|
(struct prefix *) p, RMAP_RIP,
|
|
|
|
rinfo);
|
|
|
|
|
|
|
|
if (ret == RMAP_DENYMATCH)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("RIP %s/%d is filtered by route-map out",
|
2017-02-03 14:20:14 +01:00
|
|
|
inet_ntoa (p->prefix), p->prefixlen);
|
|
|
|
continue;
|
2003-05-25 16:49:19 +02:00
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Apply redistribute route map - continue, if deny */
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rip->route_map[rinfo->type].name
|
|
|
|
&& rinfo->sub_type != RIP_ROUTE_INTERFACE)
|
|
|
|
{
|
|
|
|
ret = route_map_apply (rip->route_map[rinfo->type].map,
|
|
|
|
(struct prefix *)p, RMAP_RIP, rinfo);
|
|
|
|
|
|
|
|
if (ret == RMAP_DENYMATCH)
|
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_PACKET)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("%s/%d is filtered by route-map",
|
2002-12-13 21:15:29 +01:00
|
|
|
inet_ntoa (p->prefix), p->prefixlen);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When route-map does not set metric. */
|
|
|
|
if (! rinfo->metric_set)
|
|
|
|
{
|
|
|
|
/* If redistribute metric is set. */
|
|
|
|
if (rip->route_map[rinfo->type].metric_config
|
|
|
|
&& rinfo->metric != RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
rinfo->metric_out = rip->route_map[rinfo->type].metric;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the route is not connected or localy generated
|
|
|
|
one, use default-metric value*/
|
|
|
|
if (rinfo->type != ZEBRA_ROUTE_RIP
|
|
|
|
&& rinfo->type != ZEBRA_ROUTE_CONNECT
|
|
|
|
&& rinfo->metric != RIP_METRIC_INFINITY)
|
|
|
|
rinfo->metric_out = rip->default_metric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply offset-list */
|
|
|
|
if (rinfo->metric != RIP_METRIC_INFINITY)
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_offset_list_apply_out (p, ifc->ifp, &rinfo->metric_out);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (rinfo->metric_out > RIP_METRIC_INFINITY)
|
|
|
|
rinfo->metric_out = RIP_METRIC_INFINITY;
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
/* Perform split-horizon with poisoned reverse
|
|
|
|
* for RIP and connected routes.
|
|
|
|
**/
|
|
|
|
if (ri->split_horizon == RIP_SPLIT_HORIZON_POISONED_REVERSE) {
|
2003-11-17 10:15:18 +01:00
|
|
|
/*
|
|
|
|
* We perform split horizon for RIP and connected route.
|
|
|
|
* For rip routes, we want to suppress the route if we would
|
|
|
|
* end up sending the route back on the interface that we
|
|
|
|
* learned it from, with a higher metric. For connected routes,
|
|
|
|
* we suppress the route if the prefix is a subset of the
|
|
|
|
* source address that we are going to use for the packet
|
|
|
|
* (in order to handle the case when multiple subnets are
|
|
|
|
* configured on the same interface).
|
|
|
|
*/
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *tmp_rinfo = NULL;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo->type == ZEBRA_ROUTE_RIP &&
|
|
|
|
tmp_rinfo->ifindex == ifc->ifp->ifindex)
|
|
|
|
rinfo->metric_out = RIP_METRIC_INFINITY;
|
|
|
|
if (tmp_rinfo->type == ZEBRA_ROUTE_CONNECT &&
|
2004-10-22 12:27:28 +02:00
|
|
|
prefix_match((struct prefix *)p, ifc->address))
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo->metric_out = RIP_METRIC_INFINITY;
|
2003-05-25 16:49:19 +02:00
|
|
|
}
|
2005-02-05 00:42:41 +01:00
|
|
|
|
|
|
|
/* Prepare preamble, auth headers, if needs be */
|
|
|
|
if (num == 0)
|
|
|
|
{
|
|
|
|
stream_putc (s, RIP_RESPONSE);
|
|
|
|
stream_putc (s, version);
|
|
|
|
stream_putw (s, 0);
|
|
|
|
|
2005-05-29 13:27:24 +02:00
|
|
|
/* auth header for !v1 && !no_auth */
|
|
|
|
if ( (ri->auth_type != RIP_NO_AUTH) && (version != RIPv1) )
|
2005-02-05 00:42:41 +01:00
|
|
|
doff = rip_auth_header_write (s, ri, key, auth_str,
|
|
|
|
RIP_AUTH_SIMPLE_SIZE);
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Write RTE to the stream. */
|
2005-02-05 00:42:41 +01:00
|
|
|
num = rip_write_rte (num, s, p, version, rinfo);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (num == rtemax)
|
|
|
|
{
|
|
|
|
if (version == RIPv2 && ri->auth_type == RIP_AUTH_MD5)
|
2005-02-05 00:42:41 +01:00
|
|
|
rip_auth_md5_set (s, ri, doff, auth_str, RIP_AUTH_SIMPLE_SIZE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
ret = rip_send_packet (STREAM_DATA (s), stream_get_endp (s),
|
2004-10-22 12:27:28 +02:00
|
|
|
to, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (ret >= 0 && IS_RIP_DEBUG_SEND)
|
|
|
|
rip_packet_dump ((struct rip_packet *)STREAM_DATA (s),
|
|
|
|
stream_get_endp(s), "SEND");
|
|
|
|
num = 0;
|
|
|
|
stream_reset (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush unwritten RTE. */
|
|
|
|
if (num != 0)
|
|
|
|
{
|
|
|
|
if (version == RIPv2 && ri->auth_type == RIP_AUTH_MD5)
|
2005-02-05 00:42:41 +01:00
|
|
|
rip_auth_md5_set (s, ri, doff, auth_str, RIP_AUTH_SIMPLE_SIZE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
ret = rip_send_packet (STREAM_DATA (s), stream_get_endp (s), to, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (ret >= 0 && IS_RIP_DEBUG_SEND)
|
|
|
|
rip_packet_dump ((struct rip_packet *)STREAM_DATA (s),
|
|
|
|
stream_get_endp (s), "SEND");
|
|
|
|
stream_reset (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Statistics updates. */
|
|
|
|
ri->sent_updates++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send RIP packet to the interface. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_update_interface (struct connected *ifc, u_char version, int route_type)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-11-10 15:55:09 +01:00
|
|
|
struct interface *ifp = ifc->ifp;
|
|
|
|
struct rip_interface *ri = ifp->info;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct sockaddr_in to;
|
|
|
|
|
|
|
|
/* When RIP version is 2 and multicast enable interface. */
|
2016-11-10 15:55:09 +01:00
|
|
|
if (version == RIPv2 && !ri->v2_broadcast && if_is_multicast (ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2016-11-10 15:55:09 +01:00
|
|
|
zlog_debug ("multicast announce on %s ", ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_output_process (ifc, NULL, route_type, version);
|
2002-12-13 21:15:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-10-22 12:27:28 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* If we can't send multicast packet, send it with unicast. */
|
2016-11-10 15:55:09 +01:00
|
|
|
if (if_is_broadcast (ifp) || if_is_pointopoint (ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-10-22 12:27:28 +02:00
|
|
|
if (ifc->address->family == AF_INET)
|
|
|
|
{
|
|
|
|
/* Destination address and port setting. */
|
|
|
|
memset (&to, 0, sizeof (struct sockaddr_in));
|
|
|
|
if (ifc->destination)
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
/* use specified broadcast or peer destination addr */
|
2004-10-22 12:27:28 +02:00
|
|
|
to.sin_addr = ifc->destination->u.prefix4;
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
else if (ifc->address->prefixlen < IPV4_MAX_PREFIXLEN)
|
2004-10-22 12:27:28 +02:00
|
|
|
/* calculate the appropriate broadcast address */
|
|
|
|
to.sin_addr.s_addr =
|
|
|
|
ipv4_broadcast_addr(ifc->address->u.prefix4.s_addr,
|
|
|
|
ifc->address->prefixlen);
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
else
|
|
|
|
/* do not know where to send the packet */
|
|
|
|
return;
|
2004-10-22 12:27:28 +02:00
|
|
|
to.sin_port = htons (RIP_PORT_DEFAULT);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
zlog_debug("%s announce to %s on %s",
|
|
|
|
CONNECTED_PEER(ifc) ? "unicast" : "broadcast",
|
2016-11-10 15:55:09 +01:00
|
|
|
inet_ntoa (to.sin_addr), ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_output_process (ifc, &to, route_type, version);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update send to all interface and neighbor. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_update_process (int route_type)
|
|
|
|
{
|
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;
|
|
|
|
struct listnode *ifnode, *ifnnode;
|
2003-10-16 01:20:17 +02:00
|
|
|
struct connected *connected;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct rip_interface *ri;
|
|
|
|
struct route_node *rp;
|
|
|
|
struct sockaddr_in to;
|
2016-05-12 00:52:30 +02:00
|
|
|
struct prefix *p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Send RIP update to each interface. */
|
2016-04-08 15:16:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
if (if_is_loopback (ifp))
|
|
|
|
continue;
|
|
|
|
|
2002-12-13 22:03:13 +01:00
|
|
|
if (! if_is_operative (ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Fetch RIP interface information. */
|
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
/* When passive interface is specified, suppress announce to the
|
|
|
|
interface. */
|
|
|
|
if (ri->passive)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ri->running)
|
|
|
|
{
|
2006-04-28 18:22:36 +02:00
|
|
|
/*
|
|
|
|
* If there is no version configuration in the interface,
|
|
|
|
* use rip's version setting.
|
|
|
|
*/
|
|
|
|
int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ?
|
|
|
|
rip->version_send : ri->ri_send);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2006-04-28 18:22:36 +02:00
|
|
|
zlog_debug("SEND UPDATE to %s ifindex %d",
|
2015-11-10 17:45:03 +01:00
|
|
|
ifp->name, ifp->ifindex);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-10-16 01:20:17 +02:00
|
|
|
/* send update on each connected network */
|
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
|
|
|
for (ALL_LIST_ELEMENTS (ifp->connected, ifnode, ifnnode, connected))
|
2003-10-16 01:20:17 +02:00
|
|
|
{
|
2006-04-28 18:22:36 +02:00
|
|
|
if (connected->address->family == AF_INET)
|
|
|
|
{
|
|
|
|
if (vsend & RIPv1)
|
|
|
|
rip_update_interface (connected, RIPv1, route_type);
|
|
|
|
if ((vsend & RIPv2) && if_is_multicast(ifp))
|
|
|
|
rip_update_interface (connected, RIPv2, route_type);
|
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP send updates to each neighbor. */
|
|
|
|
for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
|
|
|
|
if (rp->info != NULL)
|
|
|
|
{
|
2016-05-12 00:52:30 +02:00
|
|
|
p = &rp->p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-03-10 21:54:53 +01:00
|
|
|
connected = if_lookup_address (&p->u.prefix4, AF_INET, VRF_DEFAULT);
|
2016-11-10 18:35:47 +01:00
|
|
|
if (! connected)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-10-22 12:27:28 +02:00
|
|
|
zlog_warn ("Neighbor %s doesnt have connected interface!",
|
2016-05-12 00:52:30 +02:00
|
|
|
inet_ntoa (p->u.prefix4));
|
2002-12-13 21:15:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-22 12:27:28 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Set destination address and port */
|
|
|
|
memset (&to, 0, sizeof (struct sockaddr_in));
|
2016-05-12 00:52:30 +02:00
|
|
|
to.sin_addr = p->u.prefix4;
|
2002-12-13 21:15:29 +01:00
|
|
|
to.sin_port = htons (RIP_PORT_DEFAULT);
|
|
|
|
|
|
|
|
/* RIP version is rip's configuration. */
|
2004-10-22 12:27:28 +02:00
|
|
|
rip_output_process (connected, &to, route_type, rip->version_send);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP's periodical timer. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_update (struct thread *t)
|
|
|
|
{
|
|
|
|
/* Clear timer pointer. */
|
|
|
|
rip->t_update = NULL;
|
|
|
|
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("update timer fire!");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Process update output. */
|
|
|
|
rip_update_process (rip_all_route);
|
|
|
|
|
|
|
|
/* Triggered updates may be suppressed if a regular update is due by
|
|
|
|
the time the triggered update would be sent. */
|
2016-11-12 22:34:37 +01:00
|
|
|
RIP_TIMER_OFF (rip->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
rip->trigger = 0;
|
|
|
|
|
|
|
|
/* Register myself. */
|
|
|
|
rip_event (RIP_UPDATE_EVENT, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk down the RIP routing table then clear changed flag. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_clear_changed_flag (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct route_node *rp;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
for (rp = route_top (rip->table); rp; rp = route_next (rp))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
|
|
|
|
{
|
|
|
|
UNSET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
|
|
|
/* This flag can be set only on the first entry. */
|
|
|
|
break;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Triggered update interval timer. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_triggered_interval (struct thread *t)
|
|
|
|
{
|
|
|
|
int rip_triggered_update (struct thread *);
|
|
|
|
|
|
|
|
rip->t_triggered_interval = NULL;
|
|
|
|
|
|
|
|
if (rip->trigger)
|
|
|
|
{
|
|
|
|
rip->trigger = 0;
|
|
|
|
rip_triggered_update (t);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute triggered update. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_triggered_update (struct thread *t)
|
|
|
|
{
|
|
|
|
int interval;
|
|
|
|
|
|
|
|
/* Clear thred pointer. */
|
|
|
|
rip->t_triggered_update = NULL;
|
|
|
|
|
|
|
|
/* Cancel interval timer. */
|
2016-11-12 22:34:37 +01:00
|
|
|
RIP_TIMER_OFF (rip->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
rip->trigger = 0;
|
|
|
|
|
|
|
|
/* Logging triggered update. */
|
|
|
|
if (IS_RIP_DEBUG_EVENT)
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("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). */
|
|
|
|
rip_update_process (rip_changed_route);
|
|
|
|
|
|
|
|
/* Once all of the triggered updates have been generated, the route
|
|
|
|
change flags should be cleared. */
|
|
|
|
rip_clear_changed_flag ();
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
interval = (random () % 5) + 1;
|
|
|
|
|
2017-05-05 23:22:25 +02:00
|
|
|
rip->t_triggered_interval = NULL;
|
|
|
|
thread_add_timer(master, rip_triggered_interval, NULL, interval,
|
|
|
|
&rip->t_triggered_interval);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Withdraw redistributed route. */
|
|
|
|
void
|
|
|
|
rip_redistribute_withdraw (int type)
|
|
|
|
{
|
|
|
|
struct route_node *rp;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (!rip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (rp = route_top (rip->table); rp; rp = route_next (rp))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2014-07-18 08:13:18 +02:00
|
|
|
rinfo = listgetdata (listhead (list));
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rinfo->type == type
|
|
|
|
&& rinfo->sub_type != RIP_ROUTE_INTERFACE)
|
|
|
|
{
|
|
|
|
/* Perform poisoned reverse. */
|
|
|
|
rinfo->metric = RIP_METRIC_INFINITY;
|
|
|
|
RIP_TIMER_ON (rinfo->t_garbage_collect,
|
|
|
|
rip_garbage_collect, rip->garbage_time);
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
rinfo->flags |= RIP_RTF_CHANGED;
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
if (IS_RIP_DEBUG_EVENT) {
|
|
|
|
struct prefix_ipv4 *p = (struct prefix_ipv4 *) &rp->p;
|
|
|
|
|
2004-12-08 20:24:06 +01:00
|
|
|
zlog_debug ("Poisone %s/%d on the interface %s with an infinity metric [withdraw]",
|
2017-03-11 13:47:46 +01:00
|
|
|
inet_ntoa(p->prefix), p->prefixlen,
|
|
|
|
ifindex2ifname(rinfo->ifindex, VRF_DEFAULT));
|
2003-05-25 16:49:19 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new RIP instance and set it to global variable. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
|
|
|
rip_create (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2008-08-18 23:13:29 +02:00
|
|
|
rip = XCALLOC (MTYPE_RIP, sizeof (struct rip));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Set initial value. */
|
2003-06-07 03:10:00 +02:00
|
|
|
rip->version_send = RI_RIP_VERSION_2;
|
|
|
|
rip->version_recv = RI_RIP_VERSION_1_AND_2;
|
2002-12-13 21:15:29 +01:00
|
|
|
rip->update_time = RIP_UPDATE_TIMER_DEFAULT;
|
|
|
|
rip->timeout_time = RIP_TIMEOUT_TIMER_DEFAULT;
|
|
|
|
rip->garbage_time = RIP_GARBAGE_TIMER_DEFAULT;
|
|
|
|
rip->default_metric = RIP_DEFAULT_METRIC_DEFAULT;
|
|
|
|
|
|
|
|
/* Initialize RIP routig table. */
|
|
|
|
rip->table = route_table_init ();
|
|
|
|
rip->route = route_table_init ();
|
|
|
|
rip->neighbor = route_table_init ();
|
|
|
|
|
|
|
|
/* Make output stream. */
|
|
|
|
rip->obuf = stream_new (1500);
|
|
|
|
|
|
|
|
/* Make socket. */
|
ripd: fix race condition on input processing
In the early days of ripd, we supported running RIP on secondary IP
addresses. To do that, everytime we needed to send a multicast packet,
we would create a new temporary socket for each of the interface's
addresses and call bind() to change the source IP of the outgoing packets.
The problem with these temporary sockets is that they are more specific
than the global RIP socket (bound to INADDR_ANY). Then, even though these
sockets only exist for a short amount of time, they can receive some RIP
packets that were supposed to be received on the global RIP socket. And
since we never read from the temporary sockets, these packets are dropped.
Since we don't support secondary addresses anymore, the simplest way to
fix this problem is to stop using temporary sockets for sending multicast
packets. We are already setting IP_MULTICAST_IF before sending each
multicast packet, and in this case the primary address of the selected
interface is used as the source IP of the outgoing packets, which is
exactly what we want.
If we decide to reintroduce support for secondary addresses in the future,
we should try one of the following:
* Use IP_SENDSRCADDR/IP_PKTINFO to set the source address of the outgoing
multicast packets;
* Create one permanent UDP socket for each possible interface address,
and enable reading on all sockets.
Fixes the following IxANVL RIP tests: 7.10 and 14.1.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-11 23:19:13 +01:00
|
|
|
rip->sock = rip_create_socket ();
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rip->sock < 0)
|
|
|
|
return rip->sock;
|
|
|
|
|
|
|
|
/* Create read and timer thread. */
|
|
|
|
rip_event (RIP_READ, rip->sock);
|
|
|
|
rip_event (RIP_UPDATE_EVENT, 1);
|
|
|
|
|
2016-12-07 16:01:47 +01:00
|
|
|
QOBJ_REG (rip, rip);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sned RIP request to the destination. */
|
|
|
|
int
|
|
|
|
rip_request_send (struct sockaddr_in *to, struct interface *ifp,
|
2004-01-23 16:31:42 +01:00
|
|
|
u_char version, struct connected *connected)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct rte *rte;
|
|
|
|
struct rip_packet rip_packet;
|
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;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
memset (&rip_packet, 0, sizeof (rip_packet));
|
|
|
|
|
|
|
|
rip_packet.command = RIP_REQUEST;
|
|
|
|
rip_packet.version = version;
|
|
|
|
rte = rip_packet.rte;
|
|
|
|
rte->metric = htonl (RIP_METRIC_INFINITY);
|
|
|
|
|
2004-01-23 16:31:42 +01:00
|
|
|
if (connected)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* connected is only sent for ripv1 case, or when
|
|
|
|
* interface does not support multicast. Caller loops
|
|
|
|
* over each connected address for this case.
|
|
|
|
*/
|
2004-05-31 16:00:00 +02:00
|
|
|
if (rip_send_packet ((u_char *) &rip_packet, sizeof (rip_packet),
|
2004-10-22 12:27:28 +02:00
|
|
|
to, connected) != sizeof (rip_packet))
|
2004-01-23 16:31:42 +01:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return sizeof (rip_packet);
|
|
|
|
}
|
|
|
|
|
2003-10-16 01:20:17 +02:00
|
|
|
/* send request on each connected network */
|
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
|
|
|
for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected))
|
2003-10-16 01:20:17 +02:00
|
|
|
{
|
|
|
|
struct prefix_ipv4 *p;
|
|
|
|
|
|
|
|
p = (struct prefix_ipv4 *) connected->address;
|
|
|
|
|
|
|
|
if (p->family != AF_INET)
|
|
|
|
continue;
|
|
|
|
|
2004-05-31 16:00:00 +02:00
|
|
|
if (rip_send_packet ((u_char *) &rip_packet, sizeof (rip_packet),
|
2004-10-22 12:27:28 +02:00
|
|
|
to, connected) != sizeof (rip_packet))
|
2003-10-16 01:20:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return sizeof (rip_packet);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_update_jitter (unsigned long time)
|
|
|
|
{
|
2004-05-05 16:09:37 +02:00
|
|
|
#define JITTER_BOUND 4
|
|
|
|
/* We want to get the jitter to +/- 1/JITTER_BOUND the interval.
|
|
|
|
Given that, we cannot let time be less than JITTER_BOUND seconds.
|
|
|
|
The RIPv2 RFC says jitter should be small compared to
|
|
|
|
update_time. We consider 1/JITTER_BOUND to be small.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int jitter_input = time;
|
|
|
|
int jitter;
|
|
|
|
|
|
|
|
if (jitter_input < JITTER_BOUND)
|
|
|
|
jitter_input = JITTER_BOUND;
|
|
|
|
|
2015-06-20 01:26:19 +02:00
|
|
|
jitter = (((random () % ((jitter_input * 2) + 1)) - jitter_input));
|
2004-05-05 16:09:37 +02:00
|
|
|
|
|
|
|
return jitter/JITTER_BOUND;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rip_event (enum rip_event event, int sock)
|
|
|
|
{
|
|
|
|
int jitter = 0;
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case RIP_READ:
|
2017-05-05 23:22:25 +02:00
|
|
|
rip->t_read = NULL;
|
|
|
|
thread_add_read(master, rip_read, NULL, sock, &rip->t_read);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIP_UPDATE_EVENT:
|
2016-11-12 22:34:37 +01:00
|
|
|
RIP_TIMER_OFF (rip->t_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
jitter = rip_update_jitter (rip->update_time);
|
2017-05-05 23:22:25 +02:00
|
|
|
thread_add_timer(master, rip_update, NULL, sock ? 2 : rip->update_time + jitter,
|
|
|
|
&rip->t_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
case RIP_TRIGGERED_UPDATE:
|
|
|
|
if (rip->t_triggered_interval)
|
2017-05-05 23:22:25 +02:00
|
|
|
rip->trigger = 1;
|
2017-04-25 00:33:25 +02:00
|
|
|
else thread_add_event(master, rip_triggered_update, NULL, 0,
|
|
|
|
&rip->t_triggered_update);
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2017-03-22 10:38:22 +01:00
|
|
|
DEFUN_NOSH (router_rip,
|
2002-12-13 21:15:29 +01:00
|
|
|
router_rip_cmd,
|
|
|
|
"router rip",
|
|
|
|
"Enable a routing process\n"
|
|
|
|
"Routing Information Protocol (RIP)\n")
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* If rip is not enabled before. */
|
|
|
|
if (! rip)
|
|
|
|
{
|
|
|
|
ret = rip_create ();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
zlog_info ("Can't create RIP");
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 17:15:32 +01:00
|
|
|
VTY_PUSH_CONTEXT(RIP_NODE, rip);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_router_rip,
|
|
|
|
no_router_rip_cmd,
|
|
|
|
"no router rip",
|
|
|
|
NO_STR
|
|
|
|
"Enable a routing process\n"
|
|
|
|
"Routing Information Protocol (RIP)\n")
|
|
|
|
{
|
|
|
|
if (rip)
|
|
|
|
rip_clean ();
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (rip_version,
|
|
|
|
rip_version_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"version (1-2)",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Set routing protocol version\n"
|
|
|
|
"version\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
int version;
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
version = atoi (argv[idx_number]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (version != RIPv1 && version != RIPv2)
|
|
|
|
{
|
|
|
|
vty_out (vty, "invalid rip version %d%s", version,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
2003-06-07 03:10:00 +02:00
|
|
|
rip->version_send = version;
|
|
|
|
rip->version_recv = version;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
2016-09-23 22:06:40 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
DEFUN (no_rip_version,
|
|
|
|
no_rip_version_cmd,
|
2016-09-27 02:10:31 +02:00
|
|
|
"no version [(1-2)]",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
2016-09-27 02:10:31 +02:00
|
|
|
"Set routing protocol version\n"
|
|
|
|
"Version\n")
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Set RIP version to the default. */
|
2003-06-07 03:10:00 +02:00
|
|
|
rip->version_send = RI_RIP_VERSION_2;
|
|
|
|
rip->version_recv = RI_RIP_VERSION_1_AND_2;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
2016-09-23 22:06:40 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
DEFUN (rip_route,
|
|
|
|
rip_route_cmd,
|
|
|
|
"route A.B.C.D/M",
|
|
|
|
"RIP static route configuration\n"
|
|
|
|
"IP prefix <network>/<length>\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_ipv4_prefixlen = 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
int ret;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *node;
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
ret = str2prefix_ipv4 (argv[idx_ipv4_prefixlen]->arg, &p);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
vty_out (vty, "Malformed address%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
apply_mask_ipv4 (&p);
|
|
|
|
|
|
|
|
/* For router rip configuration. */
|
|
|
|
node = route_node_get (rip->route, (struct prefix *) &p);
|
|
|
|
|
|
|
|
if (node->info)
|
|
|
|
{
|
|
|
|
vty_out (vty, "There is already same static route.%s", VTY_NEWLINE);
|
|
|
|
route_unlock_node (node);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
2015-05-20 03:29:14 +02:00
|
|
|
node->info = (void *)1;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2016-10-01 21:43:17 +02:00
|
|
|
rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0, NULL, 0, 0, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_route,
|
|
|
|
no_rip_route_cmd,
|
|
|
|
"no route A.B.C.D/M",
|
|
|
|
NO_STR
|
|
|
|
"RIP static route configuration\n"
|
|
|
|
"IP prefix <network>/<length>\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_ipv4_prefixlen = 2;
|
2002-12-13 21:15:29 +01:00
|
|
|
int ret;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *node;
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
ret = str2prefix_ipv4 (argv[idx_ipv4_prefixlen]->arg, &p);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
vty_out (vty, "Malformed address%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
apply_mask_ipv4 (&p);
|
|
|
|
|
|
|
|
/* For router rip configuration. */
|
|
|
|
node = route_node_lookup (rip->route, (struct prefix *) &p);
|
|
|
|
if (! node)
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
vty_out (vty, "Can't find route %s.%s", argv[idx_ipv4_prefixlen]->arg,
|
2002-12-13 21:15:29 +01:00
|
|
|
VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0);
|
|
|
|
route_unlock_node (node);
|
|
|
|
|
|
|
|
node->info = NULL;
|
|
|
|
route_unlock_node (node);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-12-10 17:16:05 +01:00
|
|
|
#if 0
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_update_default_metric (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct route_node *np;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
for (np = route_top (rip->table); np; np = route_next (np))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = np->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
|
|
|
|
if (rinfo->type != ZEBRA_ROUTE_RIP && rinfo->type != ZEBRA_ROUTE_CONNECT)
|
|
|
|
rinfo->metric = rip->default_metric;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2009-12-10 17:16:05 +01:00
|
|
|
#endif
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
DEFUN (rip_default_metric,
|
|
|
|
rip_default_metric_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"default-metric (1-16)",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Set a metric of redistribute routes\n"
|
|
|
|
"Default metric\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rip)
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
rip->default_metric = atoi (argv[idx_number]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
/* rip_update_default_metric (); */
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_default_metric,
|
|
|
|
no_rip_default_metric_cmd,
|
2016-09-27 02:10:31 +02:00
|
|
|
"no default-metric [(1-16)]",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Set a metric of redistribute routes\n"
|
|
|
|
"Default metric\n")
|
|
|
|
{
|
|
|
|
if (rip)
|
|
|
|
{
|
|
|
|
rip->default_metric = RIP_DEFAULT_METRIC_DEFAULT;
|
|
|
|
/* rip_update_default_metric (); */
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN (rip_timers,
|
|
|
|
rip_timers_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Adjust routing timers\n"
|
|
|
|
"Basic routing protocol update timers\n"
|
|
|
|
"Routing table update timer value in second. Default is 30.\n"
|
|
|
|
"Routing information timeout timer. Default is 180.\n"
|
|
|
|
"Garbage collection timer. Default is 120.\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 2;
|
|
|
|
int idx_number_2 = 3;
|
|
|
|
int idx_number_3 = 4;
|
2002-12-13 21:15:29 +01:00
|
|
|
unsigned long update;
|
|
|
|
unsigned long timeout;
|
|
|
|
unsigned long garbage;
|
|
|
|
char *endptr = NULL;
|
|
|
|
unsigned long RIP_TIMER_MAX = 2147483647;
|
|
|
|
unsigned long RIP_TIMER_MIN = 5;
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
update = strtoul (argv[idx_number]->arg, &endptr, 10);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (update > RIP_TIMER_MAX || update < RIP_TIMER_MIN || *endptr != '\0')
|
|
|
|
{
|
|
|
|
vty_out (vty, "update timer value error%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
timeout = strtoul (argv[idx_number_2]->arg, &endptr, 10);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (timeout > RIP_TIMER_MAX || timeout < RIP_TIMER_MIN || *endptr != '\0')
|
|
|
|
{
|
|
|
|
vty_out (vty, "timeout timer value error%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
2016-09-23 22:06:40 +02:00
|
|
|
garbage = strtoul (argv[idx_number_3]->arg, &endptr, 10);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (garbage > RIP_TIMER_MAX || garbage < RIP_TIMER_MIN || *endptr != '\0')
|
|
|
|
{
|
|
|
|
vty_out (vty, "garbage timer value error%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set each timer value. */
|
|
|
|
rip->update_time = update;
|
|
|
|
rip->timeout_time = timeout;
|
|
|
|
rip->garbage_time = garbage;
|
|
|
|
|
|
|
|
/* Reset update timer thread. */
|
|
|
|
rip_event (RIP_UPDATE_EVENT, 0);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_timers,
|
|
|
|
no_rip_timers_cmd,
|
2016-09-27 02:10:31 +02:00
|
|
|
"no timers basic [(0-65535) (0-65535) (0-65535)]",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Adjust routing timers\n"
|
2016-09-27 02:10:31 +02:00
|
|
|
"Basic routing protocol update timers\n"
|
|
|
|
"Routing table update timer value in second. Default is 30.\n"
|
|
|
|
"Routing information timeout timer. Default is 180.\n"
|
|
|
|
"Garbage collection timer. Default is 120.\n")
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Set each timer value to the default. */
|
|
|
|
rip->update_time = RIP_UPDATE_TIMER_DEFAULT;
|
|
|
|
rip->timeout_time = RIP_TIMEOUT_TIMER_DEFAULT;
|
|
|
|
rip->garbage_time = RIP_GARBAGE_TIMER_DEFAULT;
|
|
|
|
|
|
|
|
/* Reset update timer thread. */
|
|
|
|
rip_event (RIP_UPDATE_EVENT, 0);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
struct route_table *rip_distance_table;
|
|
|
|
|
|
|
|
struct rip_distance
|
|
|
|
{
|
|
|
|
/* Distance value for the IP source prefix. */
|
|
|
|
u_char distance;
|
|
|
|
|
|
|
|
/* Name of the access-list to be matched. */
|
|
|
|
char *access_list;
|
|
|
|
};
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static struct rip_distance *
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_distance_new (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2008-08-18 23:13:29 +02:00
|
|
|
return XCALLOC (MTYPE_RIP_DISTANCE, sizeof (struct rip_distance));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_distance_free (struct rip_distance *rdistance)
|
|
|
|
{
|
|
|
|
XFREE (MTYPE_RIP_DISTANCE, rdistance);
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2004-10-11 14:57:57 +02:00
|
|
|
rip_distance_set (struct vty *vty, const char *distance_str, const char *ip_str,
|
|
|
|
const char *access_list_str)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
u_char distance;
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
|
|
|
|
ret = str2prefix_ipv4 (ip_str, &p);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
distance = atoi (distance_str);
|
|
|
|
|
|
|
|
/* Get RIP distance node. */
|
|
|
|
rn = route_node_get (rip_distance_table, (struct prefix *) &p);
|
|
|
|
if (rn->info)
|
|
|
|
{
|
|
|
|
rdistance = rn->info;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rdistance = rip_distance_new ();
|
|
|
|
rn->info = rdistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set distance value. */
|
|
|
|
rdistance->distance = distance;
|
|
|
|
|
|
|
|
/* Reset access-list configuration. */
|
|
|
|
if (rdistance->access_list)
|
|
|
|
{
|
|
|
|
free (rdistance->access_list);
|
|
|
|
rdistance->access_list = NULL;
|
|
|
|
}
|
|
|
|
if (access_list_str)
|
|
|
|
rdistance->access_list = strdup (access_list_str);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2004-10-11 14:57:57 +02:00
|
|
|
rip_distance_unset (struct vty *vty, const char *distance_str,
|
|
|
|
const char *ip_str, const char *access_list_str)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
|
|
|
|
ret = str2prefix_ipv4 (ip_str, &p);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rn = route_node_lookup (rip_distance_table, (struct prefix *)&p);
|
|
|
|
if (! rn)
|
|
|
|
{
|
|
|
|
vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdistance = rn->info;
|
|
|
|
|
|
|
|
if (rdistance->access_list)
|
|
|
|
free (rdistance->access_list);
|
|
|
|
rip_distance_free (rdistance);
|
|
|
|
|
|
|
|
rn->info = NULL;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_distance_reset (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
|
|
|
|
for (rn = route_top (rip_distance_table); rn; rn = route_next (rn))
|
|
|
|
if ((rdistance = rn->info) != NULL)
|
|
|
|
{
|
|
|
|
if (rdistance->access_list)
|
|
|
|
free (rdistance->access_list);
|
|
|
|
rip_distance_free (rdistance);
|
|
|
|
rn->info = NULL;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply RIP information to distance method. */
|
|
|
|
u_char
|
|
|
|
rip_distance_apply (struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
struct access_list *alist;
|
|
|
|
|
|
|
|
if (! rip)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memset (&p, 0, sizeof (struct prefix_ipv4));
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.prefix = rinfo->from;
|
|
|
|
p.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
|
|
|
|
/* Check source address. */
|
|
|
|
rn = route_node_match (rip_distance_table, (struct prefix *) &p);
|
|
|
|
if (rn)
|
|
|
|
{
|
|
|
|
rdistance = rn->info;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
|
|
|
if (rdistance->access_list)
|
|
|
|
{
|
|
|
|
alist = access_list_lookup (AFI_IP, rdistance->access_list);
|
|
|
|
if (alist == NULL)
|
|
|
|
return 0;
|
|
|
|
if (access_list_apply (alist, &rinfo->rp->p) == FILTER_DENY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return rdistance->distance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return rdistance->distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rip->distance)
|
|
|
|
return rip->distance;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_distance_show (struct vty *vty)
|
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
int header = 1;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
vty_out (vty, " Distance: (default is %d)%s",
|
|
|
|
rip->distance ? rip->distance :ZEBRA_RIP_DISTANCE_DEFAULT,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
|
|
|
for (rn = route_top (rip_distance_table); rn; rn = route_next (rn))
|
|
|
|
if ((rdistance = rn->info) != NULL)
|
|
|
|
{
|
|
|
|
if (header)
|
|
|
|
{
|
|
|
|
vty_out (vty, " Address Distance List%s",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
header = 0;
|
|
|
|
}
|
|
|
|
sprintf (buf, "%s/%d", inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
|
|
|
|
vty_out (vty, " %-20s %4d %s%s",
|
|
|
|
buf, rdistance->distance,
|
|
|
|
rdistance->access_list ? rdistance->access_list : "",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (rip_distance,
|
|
|
|
rip_distance_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"distance (1-255)",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 1;
|
|
|
|
rip->distance = atoi (argv[idx_number]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_distance,
|
|
|
|
no_rip_distance_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"no distance (1-255)",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n")
|
|
|
|
{
|
|
|
|
rip->distance = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (rip_distance_source,
|
|
|
|
rip_distance_source_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"distance (1-255) A.B.C.D/M",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n"
|
|
|
|
"IP source prefix\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 1;
|
|
|
|
int idx_ipv4_prefixlen = 2;
|
|
|
|
rip_distance_set (vty, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_distance_source,
|
|
|
|
no_rip_distance_source_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"no distance (1-255) A.B.C.D/M",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n"
|
|
|
|
"IP source prefix\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 2;
|
|
|
|
int idx_ipv4_prefixlen = 3;
|
|
|
|
rip_distance_unset (vty, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (rip_distance_source_access_list,
|
|
|
|
rip_distance_source_access_list_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"distance (1-255) A.B.C.D/M WORD",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n"
|
|
|
|
"IP source prefix\n"
|
|
|
|
"Access list name\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 1;
|
|
|
|
int idx_ipv4_prefixlen = 2;
|
|
|
|
int idx_word = 3;
|
|
|
|
rip_distance_set (vty, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_distance_source_access_list,
|
|
|
|
no_rip_distance_source_access_list_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"no distance (1-255) A.B.C.D/M WORD",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Administrative distance\n"
|
|
|
|
"Distance value\n"
|
|
|
|
"IP source prefix\n"
|
|
|
|
"Access list name\n")
|
|
|
|
{
|
2016-09-23 22:06:40 +02:00
|
|
|
int idx_number = 2;
|
|
|
|
int idx_ipv4_prefixlen = 3;
|
|
|
|
int idx_word = 4;
|
|
|
|
rip_distance_unset (vty, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2014-07-18 08:13:19 +02:00
|
|
|
/* Update ECMP routes to zebra when ECMP is disabled. */
|
|
|
|
static void
|
|
|
|
rip_ecmp_disable (void)
|
|
|
|
{
|
|
|
|
struct route_node *rp;
|
|
|
|
struct rip_info *rinfo, *tmp_rinfo;
|
|
|
|
struct list *list;
|
|
|
|
struct listnode *node, *nextnode;
|
|
|
|
|
|
|
|
if (!rip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (rp = route_top (rip->table); rp; rp = route_next (rp))
|
|
|
|
if ((list = rp->info) != NULL && listcount (list) > 1)
|
|
|
|
{
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
if (!rip_route_rte (rinfo))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Drop all other entries, except the first one. */
|
|
|
|
for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
|
|
|
|
if (tmp_rinfo != rinfo)
|
|
|
|
{
|
|
|
|
RIP_TIMER_OFF (tmp_rinfo->t_timeout);
|
|
|
|
RIP_TIMER_OFF (tmp_rinfo->t_garbage_collect);
|
|
|
|
list_delete_node (list, node);
|
|
|
|
rip_info_free (tmp_rinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update zebra. */
|
|
|
|
rip_zebra_ipv4_add (rp);
|
|
|
|
|
|
|
|
/* Set the route change flag. */
|
|
|
|
SET_FLAG (rinfo->flags, RIP_RTF_CHANGED);
|
|
|
|
|
|
|
|
/* Signal the output process to trigger an update. */
|
|
|
|
rip_event (RIP_TRIGGERED_UPDATE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (rip_allow_ecmp,
|
|
|
|
rip_allow_ecmp_cmd,
|
|
|
|
"allow-ecmp",
|
|
|
|
"Allow Equal Cost MultiPath\n")
|
|
|
|
{
|
|
|
|
if (rip->ecmp)
|
|
|
|
{
|
|
|
|
vty_out (vty, "ECMP is already enabled.%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rip->ecmp = 1;
|
|
|
|
zlog_info ("ECMP is enabled.");
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (no_rip_allow_ecmp,
|
|
|
|
no_rip_allow_ecmp_cmd,
|
|
|
|
"no allow-ecmp",
|
|
|
|
NO_STR
|
|
|
|
"Allow Equal Cost MultiPath\n")
|
|
|
|
{
|
|
|
|
if (!rip->ecmp)
|
|
|
|
{
|
|
|
|
vty_out (vty, "ECMP is already disabled.%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rip->ecmp = 0;
|
|
|
|
zlog_info ("ECMP is disabled.");
|
|
|
|
rip_ecmp_disable ();
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Print out routes update time. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_vty_out_uptime (struct vty *vty, struct rip_info *rinfo)
|
|
|
|
{
|
|
|
|
time_t clock;
|
|
|
|
struct tm *tm;
|
|
|
|
#define TIME_BUF 25
|
|
|
|
char timebuf [TIME_BUF];
|
|
|
|
struct thread *thread;
|
|
|
|
|
|
|
|
if ((thread = rinfo->t_timeout) != NULL)
|
|
|
|
{
|
2007-04-11 17:12:05 +02:00
|
|
|
clock = thread_timer_remain_second (thread);
|
2002-12-13 21:15:29 +01:00
|
|
|
tm = gmtime (&clock);
|
|
|
|
strftime (timebuf, TIME_BUF, "%M:%S", tm);
|
|
|
|
vty_out (vty, "%5s", timebuf);
|
|
|
|
}
|
|
|
|
else if ((thread = rinfo->t_garbage_collect) != NULL)
|
|
|
|
{
|
2007-04-11 17:12:05 +02:00
|
|
|
clock = thread_timer_remain_second (thread);
|
2002-12-13 21:15:29 +01:00
|
|
|
tm = gmtime (&clock);
|
|
|
|
strftime (timebuf, TIME_BUF, "%M:%S", tm);
|
|
|
|
vty_out (vty, "%5s", timebuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static const char *
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_route_type_print (int sub_type)
|
|
|
|
{
|
|
|
|
switch (sub_type)
|
|
|
|
{
|
|
|
|
case RIP_ROUTE_RTE:
|
|
|
|
return "n";
|
|
|
|
case RIP_ROUTE_STATIC:
|
|
|
|
return "s";
|
|
|
|
case RIP_ROUTE_DEFAULT:
|
|
|
|
return "d";
|
|
|
|
case RIP_ROUTE_REDISTRIBUTE:
|
|
|
|
return "r";
|
|
|
|
case RIP_ROUTE_INTERFACE:
|
|
|
|
return "i";
|
|
|
|
default:
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN (show_ip_rip,
|
|
|
|
show_ip_rip_cmd,
|
|
|
|
"show ip rip",
|
|
|
|
SHOW_STR
|
|
|
|
IP_STR
|
|
|
|
"Show RIP routes\n")
|
|
|
|
{
|
|
|
|
struct route_node *np;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (! rip)
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
vty_out (vty, "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP%s"
|
|
|
|
"Sub-codes:%s"
|
|
|
|
" (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
|
2002-12-13 21:15:29 +01:00
|
|
|
" (i) - interface%s%s"
|
2004-03-03 20:36:24 +01:00
|
|
|
" Network Next Hop Metric From Tag Time%s",
|
2003-05-25 16:49:19 +02:00
|
|
|
VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
for (np = route_top (rip->table); np; np = route_next (np))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = np->info) != NULL)
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
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
|
|
|
len = vty_out (vty, "%c(%s) %s/%d",
|
2002-12-13 21:15:29 +01:00
|
|
|
/* np->lock, For debugging. */
|
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),
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_route_type_print (rinfo->sub_type),
|
|
|
|
inet_ntoa (np->p.u.prefix4), np->p.prefixlen);
|
|
|
|
|
2004-03-03 20:36:24 +01:00
|
|
|
len = 24 - len;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
vty_out (vty, "%*s", len, " ");
|
|
|
|
|
|
|
|
if (rinfo->nexthop.s_addr)
|
|
|
|
vty_out (vty, "%-20s %2d ", inet_ntoa (rinfo->nexthop),
|
|
|
|
rinfo->metric);
|
|
|
|
else
|
|
|
|
vty_out (vty, "0.0.0.0 %2d ", rinfo->metric);
|
|
|
|
|
|
|
|
/* Route which exist in kernel routing table. */
|
|
|
|
if ((rinfo->type == ZEBRA_ROUTE_RIP) &&
|
|
|
|
(rinfo->sub_type == RIP_ROUTE_RTE))
|
|
|
|
{
|
|
|
|
vty_out (vty, "%-15s ", inet_ntoa (rinfo->from));
|
2016-10-01 20:42:34 +02:00
|
|
|
vty_out (vty, "%3"ROUTE_TAG_PRI" ", (route_tag_t)rinfo->tag);
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_vty_out_uptime (vty, rinfo);
|
|
|
|
}
|
|
|
|
else if (rinfo->metric == RIP_METRIC_INFINITY)
|
|
|
|
{
|
|
|
|
vty_out (vty, "self ");
|
2016-10-01 20:42:34 +02:00
|
|
|
vty_out (vty, "%3"ROUTE_TAG_PRI" ", (route_tag_t)rinfo->tag);
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_vty_out_uptime (vty, rinfo);
|
|
|
|
}
|
|
|
|
else
|
2003-05-25 16:49:19 +02:00
|
|
|
{
|
2005-09-29 13:25:50 +02:00
|
|
|
if (rinfo->external_metric)
|
|
|
|
{
|
|
|
|
len = vty_out (vty, "self (%s:%d)",
|
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_string(rinfo->type),
|
2005-09-29 13:25:50 +02:00
|
|
|
rinfo->external_metric);
|
|
|
|
len = 16 - len;
|
|
|
|
if (len > 0)
|
|
|
|
vty_out (vty, "%*s", len, " ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vty_out (vty, "self ");
|
2016-10-01 20:42:34 +02:00
|
|
|
vty_out (vty, "%3"ROUTE_TAG_PRI, (route_tag_t)rinfo->tag);
|
2003-05-25 16:49:19 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
vty_out (vty, "%s", VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
|
|
|
|
DEFUN (show_ip_rip_status,
|
|
|
|
show_ip_rip_status_cmd,
|
|
|
|
"show ip rip status",
|
2002-12-13 21:15:29 +01:00
|
|
|
SHOW_STR
|
|
|
|
IP_STR
|
2003-05-25 16:49:19 +02:00
|
|
|
"Show RIP routes\n"
|
2002-12-13 21:15:29 +01:00
|
|
|
"IP routing protocol process parameters and statistics\n")
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
struct listnode *node;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct rip_interface *ri;
|
2008-08-14 18:59:25 +02:00
|
|
|
extern const struct message ri_version_msg[];
|
2004-10-08 08:36:38 +02:00
|
|
|
const char *send_version;
|
|
|
|
const char *receive_version;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (! rip)
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
|
|
|
vty_out (vty, "Routing Protocol is \"rip\"%s", VTY_NEWLINE);
|
|
|
|
vty_out (vty, " Sending updates every %ld seconds with +/-50%%,",
|
|
|
|
rip->update_time);
|
2007-03-21 19:57:38 +01:00
|
|
|
vty_out (vty, " next due in %lu seconds%s",
|
|
|
|
thread_timer_remain_second(rip->t_update),
|
2002-12-13 21:15:29 +01:00
|
|
|
VTY_NEWLINE);
|
|
|
|
vty_out (vty, " Timeout after %ld seconds,", rip->timeout_time);
|
|
|
|
vty_out (vty, " garbage collect after %ld seconds%s", rip->garbage_time,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* Filtering status show. */
|
|
|
|
config_show_distribute (vty);
|
|
|
|
|
|
|
|
/* Default metric information. */
|
|
|
|
vty_out (vty, " Default redistribution metric is %d%s",
|
|
|
|
rip->default_metric, VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* Redistribute information. */
|
|
|
|
vty_out (vty, " Redistributing:");
|
|
|
|
config_write_rip_redistribute (vty, 0);
|
|
|
|
vty_out (vty, "%s", VTY_NEWLINE);
|
|
|
|
|
2003-06-07 03:10:00 +02:00
|
|
|
vty_out (vty, " Default version control: send version %s,",
|
|
|
|
lookup(ri_version_msg,rip->version_send));
|
|
|
|
if (rip->version_recv == RI_RIP_VERSION_1_AND_2)
|
|
|
|
vty_out (vty, " receive any version %s", VTY_NEWLINE);
|
|
|
|
else
|
|
|
|
vty_out (vty, " receive version %s %s",
|
|
|
|
lookup(ri_version_msg,rip->version_recv), VTY_NEWLINE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
vty_out (vty, " Interface Send Recv Key-chain%s", VTY_NEWLINE);
|
|
|
|
|
2016-04-08 15:16:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
ri = ifp->info;
|
|
|
|
|
2009-04-08 00:00:46 +02:00
|
|
|
if (!ri->running)
|
|
|
|
continue;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ri->enable_network || ri->enable_interface)
|
|
|
|
{
|
|
|
|
if (ri->ri_send == RI_RIP_UNSPEC)
|
2003-06-07 03:10:00 +02:00
|
|
|
send_version = lookup (ri_version_msg, rip->version_send);
|
2002-12-13 21:15:29 +01:00
|
|
|
else
|
|
|
|
send_version = lookup (ri_version_msg, ri->ri_send);
|
|
|
|
|
|
|
|
if (ri->ri_receive == RI_RIP_UNSPEC)
|
2003-06-07 03:10:00 +02:00
|
|
|
receive_version = lookup (ri_version_msg, rip->version_recv);
|
2002-12-13 21:15:29 +01:00
|
|
|
else
|
|
|
|
receive_version = lookup (ri_version_msg, ri->ri_receive);
|
|
|
|
|
|
|
|
vty_out (vty, " %-17s%-3s %-3s %s%s", ifp->name,
|
|
|
|
send_version,
|
|
|
|
receive_version,
|
|
|
|
ri->key_chain ? ri->key_chain : "",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vty_out (vty, " Routing for Networks:%s", VTY_NEWLINE);
|
|
|
|
config_write_rip_network (vty, 0);
|
|
|
|
|
2003-06-07 03:04:45 +02:00
|
|
|
{
|
|
|
|
int found_passive = 0;
|
2016-04-08 15:16:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
|
2003-06-07 03:04:45 +02:00
|
|
|
{
|
|
|
|
ri = ifp->info;
|
|
|
|
|
|
|
|
if ((ri->enable_network || ri->enable_interface) && ri->passive)
|
|
|
|
{
|
|
|
|
if (!found_passive)
|
|
|
|
{
|
|
|
|
vty_out (vty, " Passive Interface(s):%s", VTY_NEWLINE);
|
|
|
|
found_passive = 1;
|
|
|
|
}
|
|
|
|
vty_out (vty, " %s%s", ifp->name, VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
vty_out (vty, " Routing Information Sources:%s", VTY_NEWLINE);
|
|
|
|
vty_out (vty, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE);
|
|
|
|
rip_peer_display (vty);
|
|
|
|
|
|
|
|
rip_distance_show (vty);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP configuration write function. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static int
|
2002-12-13 21:15:29 +01:00
|
|
|
config_write_rip (struct vty *vty)
|
|
|
|
{
|
|
|
|
int write = 0;
|
|
|
|
struct route_node *rn;
|
|
|
|
struct rip_distance *rdistance;
|
|
|
|
|
|
|
|
if (rip)
|
|
|
|
{
|
|
|
|
/* Router RIP statement. */
|
|
|
|
vty_out (vty, "router rip%s", VTY_NEWLINE);
|
|
|
|
write++;
|
|
|
|
|
|
|
|
/* RIP version statement. Default is RIP version 2. */
|
2003-06-07 03:10:00 +02:00
|
|
|
if (rip->version_send != RI_RIP_VERSION_2
|
|
|
|
|| rip->version_recv != RI_RIP_VERSION_1_AND_2)
|
|
|
|
vty_out (vty, " version %d%s", rip->version_send,
|
2002-12-13 21:15:29 +01:00
|
|
|
VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* RIP timer configuration. */
|
|
|
|
if (rip->update_time != RIP_UPDATE_TIMER_DEFAULT
|
|
|
|
|| rip->timeout_time != RIP_TIMEOUT_TIMER_DEFAULT
|
|
|
|
|| rip->garbage_time != RIP_GARBAGE_TIMER_DEFAULT)
|
|
|
|
vty_out (vty, " timers basic %lu %lu %lu%s",
|
|
|
|
rip->update_time,
|
|
|
|
rip->timeout_time,
|
|
|
|
rip->garbage_time,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* Default information configuration. */
|
|
|
|
if (rip->default_information)
|
|
|
|
{
|
|
|
|
if (rip->default_information_route_map)
|
|
|
|
vty_out (vty, " default-information originate route-map %s%s",
|
|
|
|
rip->default_information_route_map, VTY_NEWLINE);
|
|
|
|
else
|
|
|
|
vty_out (vty, " default-information originate%s",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redistribute configuration. */
|
|
|
|
config_write_rip_redistribute (vty, 1);
|
|
|
|
|
|
|
|
/* RIP offset-list configuration. */
|
|
|
|
config_write_rip_offset_list (vty);
|
|
|
|
|
|
|
|
/* RIP enabled network and interface configuration. */
|
|
|
|
config_write_rip_network (vty, 1);
|
|
|
|
|
|
|
|
/* RIP default metric configuration */
|
|
|
|
if (rip->default_metric != RIP_DEFAULT_METRIC_DEFAULT)
|
|
|
|
vty_out (vty, " default-metric %d%s",
|
|
|
|
rip->default_metric, VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* Distribute configuration. */
|
|
|
|
write += config_write_distribute (vty);
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Interface routemap configuration */
|
|
|
|
write += config_write_if_rmap (vty);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Distance configuration. */
|
|
|
|
if (rip->distance)
|
|
|
|
vty_out (vty, " distance %d%s", rip->distance, VTY_NEWLINE);
|
|
|
|
|
|
|
|
/* RIP source IP prefix distance configuration. */
|
|
|
|
for (rn = route_top (rip_distance_table); rn; rn = route_next (rn))
|
|
|
|
if ((rdistance = rn->info) != NULL)
|
|
|
|
vty_out (vty, " distance %d %s/%d %s%s", rdistance->distance,
|
|
|
|
inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
|
|
|
|
rdistance->access_list ? rdistance->access_list : "",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2014-07-18 08:13:19 +02:00
|
|
|
/* ECMP configuration. */
|
|
|
|
if (rip->ecmp)
|
|
|
|
vty_out (vty, " allow-ecmp%s", VTY_NEWLINE);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIP static route configuration. */
|
|
|
|
for (rn = route_top (rip->route); rn; rn = route_next (rn))
|
|
|
|
if (rn->info)
|
|
|
|
vty_out (vty, " route %s/%d%s",
|
|
|
|
inet_ntoa (rn->p.u.prefix4),
|
|
|
|
rn->p.prefixlen,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
|
|
|
}
|
|
|
|
return write;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP node structure. */
|
2008-12-01 20:10:34 +01:00
|
|
|
static struct cmd_node rip_node =
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
RIP_NODE,
|
|
|
|
"%s(config-router)# ",
|
|
|
|
1
|
|
|
|
};
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Distribute-list update functions. */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_distribute_update (struct distribute *dist)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
struct rip_interface *ri;
|
|
|
|
struct access_list *alist;
|
|
|
|
struct prefix_list *plist;
|
|
|
|
|
|
|
|
if (! dist->ifname)
|
|
|
|
return;
|
|
|
|
|
2017-03-11 13:27:15 +01:00
|
|
|
ifp = if_lookup_by_name (dist->ifname, VRF_DEFAULT);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ifp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ri = ifp->info;
|
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->list[DISTRIBUTE_V4_IN])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:07 +02:00
|
|
|
alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_V4_IN]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (alist)
|
|
|
|
ri->list[RIP_FILTER_IN] = alist;
|
|
|
|
else
|
|
|
|
ri->list[RIP_FILTER_IN] = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ri->list[RIP_FILTER_IN] = NULL;
|
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->list[DISTRIBUTE_V4_OUT])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:07 +02:00
|
|
|
alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_V4_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (alist)
|
|
|
|
ri->list[RIP_FILTER_OUT] = alist;
|
|
|
|
else
|
|
|
|
ri->list[RIP_FILTER_OUT] = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ri->list[RIP_FILTER_OUT] = NULL;
|
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->prefix[DISTRIBUTE_V4_IN])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:07 +02:00
|
|
|
plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_V4_IN]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (plist)
|
|
|
|
ri->prefix[RIP_FILTER_IN] = plist;
|
|
|
|
else
|
|
|
|
ri->prefix[RIP_FILTER_IN] = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ri->prefix[RIP_FILTER_IN] = NULL;
|
|
|
|
|
2016-09-22 23:11:07 +02:00
|
|
|
if (dist->prefix[DISTRIBUTE_V4_OUT])
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-22 23:11:07 +02:00
|
|
|
plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_V4_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (plist)
|
|
|
|
ri->prefix[RIP_FILTER_OUT] = plist;
|
|
|
|
else
|
|
|
|
ri->prefix[RIP_FILTER_OUT] = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ri->prefix[RIP_FILTER_OUT] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rip_distribute_update_interface (struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct distribute *dist;
|
|
|
|
|
|
|
|
dist = distribute_lookup (ifp->name);
|
|
|
|
if (dist)
|
|
|
|
rip_distribute_update (dist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update all interface's distribute list. */
|
2004-06-11 13:27:03 +02:00
|
|
|
/* ARGSUSED */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2004-06-11 13:27:03 +02:00
|
|
|
rip_distribute_update_all (struct prefix_list *notused)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct interface *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
|
|
|
struct listnode *node, *nnode;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2016-04-08 15:16:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, 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
|
|
|
rip_distribute_update_interface (ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2004-05-31 16:00:00 +02:00
|
|
|
/* ARGSUSED */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2004-05-31 16:00:00 +02:00
|
|
|
rip_distribute_update_all_wrapper(struct access_list *notused)
|
|
|
|
{
|
2004-06-11 13:27:03 +02:00
|
|
|
rip_distribute_update_all(NULL);
|
2004-05-31 16:00:00 +02:00
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Delete all added rip route. */
|
|
|
|
void
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_clean (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct route_node *rp;
|
2014-07-18 08:13:18 +02:00
|
|
|
struct rip_info *rinfo = NULL;
|
|
|
|
struct list *list = NULL;
|
|
|
|
struct listnode *listnode = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
if (rip)
|
|
|
|
{
|
2016-12-07 16:01:47 +01:00
|
|
|
QOBJ_UNREG (rip);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Clear RIP routes */
|
|
|
|
for (rp = route_top (rip->table); rp; rp = route_next (rp))
|
2014-07-18 08:13:18 +02:00
|
|
|
if ((list = rp->info) != NULL)
|
|
|
|
{
|
|
|
|
rinfo = listgetdata (listhead (list));
|
|
|
|
if (rip_route_rte (rinfo))
|
|
|
|
rip_zebra_ipv4_delete (rp);
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
|
|
|
|
{
|
|
|
|
RIP_TIMER_OFF (rinfo->t_timeout);
|
|
|
|
RIP_TIMER_OFF (rinfo->t_garbage_collect);
|
|
|
|
rip_info_free (rinfo);
|
|
|
|
}
|
|
|
|
list_delete (list);
|
|
|
|
rp->info = NULL;
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Cancel RIP related timers. */
|
|
|
|
RIP_TIMER_OFF (rip->t_update);
|
|
|
|
RIP_TIMER_OFF (rip->t_triggered_update);
|
|
|
|
RIP_TIMER_OFF (rip->t_triggered_interval);
|
|
|
|
|
|
|
|
/* Cancel read thread. */
|
2016-11-12 22:34:37 +01:00
|
|
|
THREAD_READ_OFF (rip->t_read);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Close RIP socket. */
|
|
|
|
if (rip->sock >= 0)
|
|
|
|
{
|
|
|
|
close (rip->sock);
|
|
|
|
rip->sock = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Static RIP route configuration. */
|
|
|
|
for (rp = route_top (rip->route); rp; rp = route_next (rp))
|
|
|
|
if (rp->info)
|
|
|
|
{
|
|
|
|
rp->info = NULL;
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIP neighbor configuration. */
|
|
|
|
for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
|
|
|
|
if (rp->info)
|
|
|
|
{
|
|
|
|
rp->info = NULL;
|
|
|
|
route_unlock_node (rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redistribute related clear. */
|
|
|
|
if (rip->default_information_route_map)
|
|
|
|
free (rip->default_information_route_map);
|
|
|
|
|
|
|
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
|
|
|
|
if (rip->route_map[i].name)
|
|
|
|
free (rip->route_map[i].name);
|
|
|
|
|
|
|
|
XFREE (MTYPE_ROUTE_TABLE, rip->table);
|
|
|
|
XFREE (MTYPE_ROUTE_TABLE, rip->route);
|
|
|
|
XFREE (MTYPE_ROUTE_TABLE, rip->neighbor);
|
|
|
|
|
|
|
|
XFREE (MTYPE_RIP, rip);
|
|
|
|
rip = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rip_clean_network ();
|
2003-06-07 03:04:45 +02:00
|
|
|
rip_passive_nondefault_clean ();
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_offset_clean ();
|
ripd: split-horizon default differed between rip_interface_new and _reset
* rip_interface.c: Default for split_horizon_default differed between
rip_interface_new and rip_interface_reset, causing at least some issues
after interface events. See patchwork #604. Fix, and consolidate code.
(rip_interface_{reset,clean}) rename these to 'interface', as that's more
appropriate. Spin the ri specific bodies of these functions out to
rip_interface_{reset,clean} helpers. Factor out the overlaps, so
rip_interface_reset uses rip_interface_clean.
(rip_interface_new) just use rip_interface_reset.
* ripd.h: Update for (rip_interface_{reset,clean})
Reported by xufeng zhang, with a suggested fix on which this commit expands.
See patchwork #604. This commit addresses only the split-horizon
discrepency, issue #2. The other issue they reported, #1, is not addressed,
though suggested fix seems inappropriate.
Cc: xufeng.zhang@windriver.com
2016-05-25 15:47:00 +02:00
|
|
|
rip_interfaces_clean ();
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_distance_reset ();
|
|
|
|
rip_redistribute_clean ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset all values to the default settings. */
|
|
|
|
void
|
2005-10-26 01:35:28 +02:00
|
|
|
rip_reset (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Reset global counters. */
|
|
|
|
rip_global_route_changes = 0;
|
|
|
|
rip_global_queries = 0;
|
|
|
|
|
|
|
|
/* Call ripd related reset functions. */
|
|
|
|
rip_debug_reset ();
|
|
|
|
rip_route_map_reset ();
|
|
|
|
|
|
|
|
/* Call library reset functions. */
|
|
|
|
vty_reset ();
|
|
|
|
access_list_reset ();
|
|
|
|
prefix_list_reset ();
|
|
|
|
|
|
|
|
distribute_list_reset ();
|
|
|
|
|
ripd: split-horizon default differed between rip_interface_new and _reset
* rip_interface.c: Default for split_horizon_default differed between
rip_interface_new and rip_interface_reset, causing at least some issues
after interface events. See patchwork #604. Fix, and consolidate code.
(rip_interface_{reset,clean}) rename these to 'interface', as that's more
appropriate. Spin the ri specific bodies of these functions out to
rip_interface_{reset,clean} helpers. Factor out the overlaps, so
rip_interface_reset uses rip_interface_clean.
(rip_interface_new) just use rip_interface_reset.
* ripd.h: Update for (rip_interface_{reset,clean})
Reported by xufeng zhang, with a suggested fix on which this commit expands.
See patchwork #604. This commit addresses only the split-horizon
discrepency, issue #2. The other issue they reported, #1, is not addressed,
though suggested fix seems inappropriate.
Cc: xufeng.zhang@windriver.com
2016-05-25 15:47:00 +02:00
|
|
|
rip_interfaces_reset ();
|
2002-12-13 21:15:29 +01:00
|
|
|
rip_distance_reset ();
|
|
|
|
|
|
|
|
rip_zclient_reset ();
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2003-05-25 16:49:19 +02:00
|
|
|
rip_if_rmap_update (struct if_rmap *if_rmap)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
struct rip_interface *ri;
|
|
|
|
struct route_map *rmap;
|
|
|
|
|
2017-03-11 13:27:15 +01:00
|
|
|
ifp = if_lookup_by_name (if_rmap->ifname, VRF_DEFAULT);
|
2003-05-25 16:49:19 +02: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[RIP_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[RIP_FILTER_OUT] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rip_if_rmap_update_interface (struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct if_rmap *if_rmap;
|
|
|
|
|
|
|
|
if_rmap = if_rmap_lookup (ifp->name);
|
|
|
|
if (if_rmap)
|
|
|
|
rip_if_rmap_update (if_rmap);
|
|
|
|
}
|
|
|
|
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2003-05-25 16:49:19 +02:00
|
|
|
rip_routemap_update_redistribute (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (rip)
|
|
|
|
{
|
|
|
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
|
|
|
|
{
|
|
|
|
if (rip->route_map[i].name)
|
|
|
|
rip->route_map[i].map =
|
|
|
|
route_map_lookup_by_name (rip->route_map[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-31 16:00:00 +02:00
|
|
|
/* ARGSUSED */
|
2005-10-26 01:31:05 +02:00
|
|
|
static void
|
2004-10-11 14:57:57 +02:00
|
|
|
rip_routemap_update (const char *notused)
|
2003-05-25 16:49:19 +02:00
|
|
|
{
|
|
|
|
struct interface *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
|
|
|
struct listnode *node, *nnode;
|
2003-05-25 16:49:19 +02:00
|
|
|
|
2016-04-08 15:16:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, 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
|
|
|
rip_if_rmap_update_interface (ifp);
|
2003-05-25 16:49:19 +02:00
|
|
|
|
|
|
|
rip_routemap_update_redistribute ();
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Allocate new rip structure and set default value. */
|
|
|
|
void
|
2005-10-26 01:31:05 +02:00
|
|
|
rip_init (void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
/* Install top nodes. */
|
|
|
|
install_node (&rip_node, config_write_rip);
|
|
|
|
|
|
|
|
/* Install rip commands. */
|
|
|
|
install_element (VIEW_NODE, &show_ip_rip_cmd);
|
2003-05-25 16:49:19 +02:00
|
|
|
install_element (VIEW_NODE, &show_ip_rip_status_cmd);
|
2002-12-13 21:15:29 +01:00
|
|
|
install_element (CONFIG_NODE, &router_rip_cmd);
|
|
|
|
install_element (CONFIG_NODE, &no_router_rip_cmd);
|
|
|
|
|
|
|
|
install_default (RIP_NODE);
|
|
|
|
install_element (RIP_NODE, &rip_version_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_version_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_default_metric_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_default_metric_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_timers_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_timers_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_route_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_route_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_distance_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_distance_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_distance_source_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_distance_source_cmd);
|
|
|
|
install_element (RIP_NODE, &rip_distance_source_access_list_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_distance_source_access_list_cmd);
|
2014-07-18 08:13:19 +02:00
|
|
|
install_element (RIP_NODE, &rip_allow_ecmp_cmd);
|
|
|
|
install_element (RIP_NODE, &no_rip_allow_ecmp_cmd);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Debug related init. */
|
|
|
|
rip_debug_init ();
|
|
|
|
|
|
|
|
/* Access list install. */
|
|
|
|
access_list_init ();
|
2004-05-31 16:00:00 +02:00
|
|
|
access_list_add_hook (rip_distribute_update_all_wrapper);
|
|
|
|
access_list_delete_hook (rip_distribute_update_all_wrapper);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Prefix list initialize.*/
|
|
|
|
prefix_list_init ();
|
|
|
|
prefix_list_add_hook (rip_distribute_update_all);
|
|
|
|
prefix_list_delete_hook (rip_distribute_update_all);
|
|
|
|
|
|
|
|
/* Distribute list install. */
|
|
|
|
distribute_list_init (RIP_NODE);
|
|
|
|
distribute_list_add_hook (rip_distribute_update);
|
|
|
|
distribute_list_delete_hook (rip_distribute_update);
|
|
|
|
|
2003-05-25 16:49:19 +02:00
|
|
|
/* Route-map */
|
|
|
|
rip_route_map_init ();
|
|
|
|
rip_offset_init ();
|
|
|
|
|
|
|
|
route_map_add_hook (rip_routemap_update);
|
|
|
|
route_map_delete_hook (rip_routemap_update);
|
|
|
|
|
|
|
|
if_rmap_init (RIP_NODE);
|
|
|
|
if_rmap_hook_add (rip_if_rmap_update);
|
|
|
|
if_rmap_hook_delete (rip_if_rmap_update);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Distance control. */
|
|
|
|
rip_distance_table = route_table_init ();
|
|
|
|
}
|