frr/zebra/redistribute.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

923 lines
23 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
2002-12-13 21:15:29 +01:00
/* Redistribution Handler
* Copyright (C) 1998 Kunihiro Ishiguro
*/
#include <zebra.h>
#include "vector.h"
#include "vty.h"
#include "command.h"
#include "prefix.h"
#include "table.h"
#include "stream.h"
#include "zclient.h"
#include "linklist.h"
#include "log.h"
lib, zebra: move "struct vrf" to be a lib module Previously "struct vrf" is defined locally in zebra. Now it is moved to be a lib module. This is the first step to support multi-VRF in quagga. The implementation is splitted into small patches for the purpose of easy review. * lib: "struct vrf" with basic members is defined in vrf.c. The member "void *info" is for user data. Some basic functions are defined in vrf.c for adding/deleting/ looking up a VRF, scanning the VRF table and initializing the VRF module. The type "vrf_id_t" is defined specificly for VRF ID. * zebra: The previous "struct vrf" is re-defined as "struct zebra_vrf"; and previous "vrf" variables are renamed to "zvrf". The previous "struct vrf" related functions are removed from zbera_rib.c. New functions are defined to maintain the new "struct zebra_vrf". The names vrf_xxx are reserved for the functions in VRF module. So: - the previous vrf_table() are renamed to zebra_vrf_table(); - the previous vrf_static_table() are renamed to zebra_vrf_static_table(). The main logic is not changed. BTW: Add a statement to zebra_snmp.c telling that the SNMP is running only for the MIBs in the default VRF. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Conflicts: lib/Makefile.am zebra/zebra_rib.c zebra/zebra_vty.c Conflicts: lib/Makefile.am lib/memtypes.c zebra/rib.h zebra/zebra_rib.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zebra_vty.c
2015-05-22 11:39:56 +02:00
#include "vrf.h"
#include "srcdest_table.h"
2002-12-13 21:15:29 +01:00
#include "zebra/rib.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_ns.h"
#include "zebra/zebra_vrf.h"
#include "zebra/zebra_routemap.h"
2002-12-13 21:15:29 +01:00
#include "zebra/redistribute.h"
#include "zebra/debug.h"
2004-10-03 20:18:34 +02:00
#include "zebra/router-id.h"
#include "zebra/zapi_msg.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_errors.h"
2002-12-13 21:15:29 +01:00
#define ZEBRA_PTM_SUPPORT
/* array holding redistribute info about table redistribution */
/* bit AFI is set if that AFI is redistributing routes from this table */
static int zebra_import_table_used[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX];
static uint32_t zebra_import_table_distance[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX];
int is_zebra_import_table_enabled(afi_t afi, vrf_id_t vrf_id, uint32_t table_id)
{
/*
* Make sure that what we are called with actualy makes sense
*/
if (afi == AFI_MAX)
return 0;
if (is_zebra_valid_kernel_table(table_id) &&
table_id < ZEBRA_KERNEL_TABLE_MAX)
return zebra_import_table_used[afi][table_id];
return 0;
}
*: add VRF ID in the API message header The API messages are used by zebra to exchange the interfaces, addresses, routes and router-id information with its clients. To distinguish which VRF the information belongs to, a new field "VRF ID" is added in the message header. And hence the message version is increased to 3. * The new field "VRF ID" in the message header: Length (2 bytes) Marker (1 byte) Version (1 byte) VRF ID (2 bytes, newly added) Command (2 bytes) - Client side: - zclient_create_header() adds the VRF ID in the message header. - zclient_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the callback functions registered to the API messages. - All relative functions are appended with a new parameter "vrf_id", including all the callback functions. - "vrf_id" is also added to "struct zapi_ipv4" and "struct zapi_ipv6". Clients need to correctly set the VRF ID when using the API functions zapi_ipv4_route() and zapi_ipv6_route(). - Till now all messages sent from a client have the default VRF ID "0" in the header. - The HELLO message is special, which is used as the heart-beat of a client, and has no relation with VRF. The VRF ID in the HELLO message header will always be 0 and ignored by zebra. - Zebra side: - zserv_create_header() adds the VRF ID in the message header. - zebra_client_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the functions which process the received messages. - All relative functions are appended with a new parameter "vrf_id". * Suppress the messages in a VRF which a client does not care: Some clients may not care about the information in the VRF X, and zebra should not send the messages in the VRF X to those clients. Extra flags are used to indicate which VRF is registered by a client, and a new message ZEBRA_VRF_UNREGISTER is introduced to let a client can unregister a VRF when it does not need any information in that VRF. A client sends any message other than ZEBRA_VRF_UNREGISTER in a VRF will automatically register to that VRF. - lib/vrf: A new utility "VRF bit-map" is provided to manage the flags for VRFs, one bit per VRF ID. - Use vrf_bitmap_init()/vrf_bitmap_free() to initialize/free a bit-map; - Use vrf_bitmap_set()/vrf_bitmap_unset() to set/unset a flag in the given bit-map, corresponding to the given VRF ID; - Use vrf_bitmap_check() to test whether the flag, in the given bit-map and for the given VRF ID, is set. - Client side: - In "struct zclient", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] default_information These flags are extended for each VRF, and controlled by the clients themselves (or with the help of zclient_redistribute() and zclient_redistribute_default()). - Zebra side: - In "struct zserv", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] redist_default ifinfo ridinfo These flags are extended for each VRF, as the VRF registration flags. They are maintained on receiving a ZEBRA_XXX_ADD or ZEBRA_XXX_DELETE message. When sending an interface/address/route/router-id message in a VRF to a client, if the corresponding VRF registration flag is not set, this message will not be dropped by zebra. - A new function zread_vrf_unregister() is introduced to process the new command ZEBRA_VRF_UNREGISTER. All the VRF registration flags are cleared for the requested VRF. Those clients, who support only the default VRF, will never receive a message in a non-default VRF, thanks to the filter in zebra. * New callback for the event of successful connection to zebra: - zclient_start() is splitted, keeping only the code of connecting to zebra. - Now zclient_init()=>zclient_connect()=>zclient_start() operations are purely dealing with the connection to zbera. - Once zebra is successfully connected, at the end of zclient_start(), a new callback is used to inform the client about connection. - Till now, in the callback of connect-to-zebra event, all clients send messages to zebra to request the router-id/interface/routes information in the default VRF. Of corse in future the client can do anything it wants in this callback. For example, it may send requests for both default VRF and some non-default VRFs. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com> Conflicts: lib/zclient.h lib/zebra.h zebra/zserv.c zebra/zserv.h Conflicts: bgpd/bgp_nexthop.c bgpd/bgp_nht.c bgpd/bgp_zebra.c isisd/isis_zebra.c lib/zclient.c lib/zclient.h lib/zebra.h nhrpd/nhrp_interface.c nhrpd/nhrp_route.c nhrpd/nhrpd.h ospf6d/ospf6_zebra.c ospf6d/ospf6_zebra.h ospfd/ospf_vty.c ospfd/ospf_zebra.c pimd/pim_zebra.c pimd/pim_zlookup.c ripd/rip_zebra.c ripngd/ripng_zebra.c zebra/redistribute.c zebra/rt_netlink.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zserv.c zebra/zserv.h
2014-10-16 03:52:36 +02:00
static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id)
2002-12-13 21:15:29 +01:00
{
int afi;
struct prefix p;
2002-12-13 21:15:29 +01:00
struct route_table *table;
struct route_node *rn;
struct route_entry *newre;
for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
if (!vrf_bitmap_check(&client->redist_default[afi], vrf_id))
continue;
/* Lookup table. */
table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
if (!table)
continue;
/* Lookup default route. */
memset(&p, 0, sizeof(p));
p.family = afi2family(afi);
rn = route_node_lookup(table, &p);
if (!rn)
continue;
RNODE_FOREACH_RE (rn, newre) {
if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED))
zsend_redistribute_route(
ZEBRA_REDISTRIBUTE_ROUTE_ADD, client,
rn, newre);
}
route_unlock_node(rn);
2002-12-13 21:15:29 +01:00
}
}
/* Redistribute routes. */
static void zebra_redistribute(struct zserv *client, int type,
unsigned short instance, vrf_id_t vrf_id,
int afi)
2002-12-13 21:15:29 +01:00
{
struct route_entry *newre;
2002-12-13 21:15:29 +01:00
struct route_table *table;
struct route_node *rn;
table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
if (!table)
return;
for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
RNODE_FOREACH_RE (rn, newre) {
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug(
"%s: client %s %pRN(%u:%u) checking: selected=%d, type=%s, instance=%u, distance=%d, metric=%d zebra_check_addr=%d",
__func__,
zebra_route_string(client->proto), rn,
vrf_id, newre->instance,
!!CHECK_FLAG(newre->flags,
ZEBRA_FLAG_SELECTED),
zebra_route_string(newre->type),
newre->instance,
newre->distance,
newre->metric,
zebra_check_addr(&rn->p));
if (!CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED))
continue;
if ((type != ZEBRA_ROUTE_ALL
&& (newre->type != type
|| newre->instance != instance)))
continue;
if (!zebra_check_addr(&rn->p))
continue;
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
client, rn, newre);
}
2002-12-13 21:15:29 +01:00
}
/*
* Function to check if prefix is candidate for
* redistribute.
*/
static bool zebra_redistribute_check(const struct route_node *rn,
const struct route_entry *re,
struct zserv *client)
{
struct zebra_vrf *zvrf;
afi_t afi;
/* Process only if there is valid re */
if (!re)
return false;
afi = family2afi(rn->p.family);
zvrf = zebra_vrf_lookup_by_id(re->vrf_id);
if (re->vrf_id == VRF_DEFAULT && zvrf->table_id != re->table)
return false;
/* If default route and redistributed */
if (is_default_prefix(&rn->p) &&
vrf_bitmap_check(&client->redist_default[afi], re->vrf_id))
return true;
/* If redistribute in enabled for zebra route all */
if (vrf_bitmap_check(&client->redist[afi][ZEBRA_ROUTE_ALL], re->vrf_id))
return true;
/*
* If multi-instance then check for route
* redistribution for given instance.
*/
zebra: Do not allow instance redistribution to happen no matter what If you have this setup: router ospf 3 redistribute sharp ! and then install: sharp install route 4.5.6.7 nexthop 192.168.100.1 1 sharp install route 4.5.6.8 nexthop 192.168.100.1 1 instance 3 sharp install route 4.5.6.9 nexthop 192.168.100.1 1 instance 4 The .8 and .9 routes are auto redistributed into ospf instance 3: eva# show ip ospf data OSPF Instance: 3 OSPF Router with ID (192.168.122.1) AS External Link States Link ID ADV Router Age Seq# CkSum Route 4.5.6.7 192.168.122.1 13 0x80000001 0x477c E2 4.5.6.7/32 [0x0] 4.5.6.8 192.168.122.1 5 0x80000001 0x3d85 E2 4.5.6.8/32 [0x0] 4.5.6.9 192.168.122.1 5 0x80000001 0x338e E2 4.5.6.9/32 [0x0] This cannot be correct behavior. When redistributing in the absense of an instance number the default instance of 0 should be used and should be the only route redistributed. Here is the correct behavior: eva# show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure K>* 0.0.0.0/0 [0/100] via 192.168.119.1, enp39s0, 00:00:28 D>* 4.5.6.7/32 [150/0] via 192.168.100.1, virbr1, weight 1, 00:00:02 D[3]>* 4.5.6.8/32 [150/0] via 192.168.100.1, virbr1, weight 1, 00:00:02 D[4]>* 4.5.6.9/32 [150/0] via 192.168.100.1, virbr1, weight 1, 00:00:02 C>* 192.168.100.0/24 is directly connected, virbr1, 00:00:28 C>* 192.168.110.0/24 is directly connected, virbr2, 00:00:28 C>* 192.168.119.0/24 is directly connected, enp39s0, 00:00:28 C>* 192.168.122.0/24 is directly connected, virbr0, 00:00:28 eva# show ip ospf data OSPF Instance: 3 OSPF Router with ID (192.168.122.1) AS External Link States Link ID ADV Router Age Seq# CkSum Route 4.5.6.7 192.168.122.1 6 0x80000001 0x477c E2 4.5.6.7/32 [0x0] Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-04 12:57:53 +01:00
if (re->instance) {
if (redist_check_instance(&client->mi_redist[afi][re->type],
re->instance))
return true;
else
return false;
}
/* If redistribution is enabled for give route type. */
if (vrf_bitmap_check(&client->redist[afi][re->type], re->vrf_id))
return true;
return false;
}
/* Either advertise a route for redistribution to registered clients or */
/* withdraw redistribution if add cannot be done for client */
void redistribute_update(const struct route_node *rn,
const struct route_entry *re,
const struct route_entry *prev_re)
2002-12-13 21:15:29 +01:00
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug(
"(%u:%u):%pRN(%u): Redist update re %p (%s), old %p (%s)",
re->vrf_id, re->table, rn, re->instance, re,
zebra_route_string(re->type), prev_re,
prev_re ? zebra_route_string(prev_re->type) : "None");
if (!zebra_check_addr(&rn->p)) {
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug("Redist update filter prefix %pRN", rn);
return;
}
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
if (zebra_redistribute_check(rn, re, client)) {
if (IS_ZEBRA_DEBUG_RIB) {
zlog_debug(
"%s: client %s %pRN(%u:%u), type=%d, distance=%d, metric=%d",
__func__,
zebra_route_string(client->proto), rn,
re->vrf_id, re->table, re->type,
re->distance, re->metric);
}
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
client, rn, re);
} else if (zebra_redistribute_check(rn, prev_re, client))
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
client, rn, prev_re);
}
2002-12-13 21:15:29 +01:00
}
/*
* During a route delete, where 'new_re' is NULL, redist a delete to all
* clients registered for the type of 'old_re'.
* During a route update, redist a delete to any clients who will not see
* an update when the new route is installed. There are cases when a client
* may have seen a redist for 'old_re', but will not see
* the redist for 'new_re'.
*/
void redistribute_delete(const struct route_node *rn,
const struct route_entry *old_re,
const struct route_entry *new_re)
2002-12-13 21:15:29 +01:00
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
vrf_id_t vrfid;
if (old_re)
vrfid = old_re->vrf_id;
else if (new_re)
vrfid = new_re->vrf_id;
else
return;
if (IS_ZEBRA_DEBUG_RIB) {
uint8_t old_inst, new_inst;
uint32_t table = 0;
old_inst = new_inst = 0;
if (old_re) {
old_inst = old_re->instance;
table = old_re->table;
}
if (new_re) {
new_inst = new_re->instance;
table = new_re->table;
}
zlog_debug("(%u:%u):%pRN: Redist del: re %p (%u:%s), new re %p (%u:%s)",
vrfid, table, rn, old_re, old_inst,
old_re ? zebra_route_string(old_re->type) : "None",
new_re, new_inst,
new_re ? zebra_route_string(new_re->type) : "None");
}
/* Skip invalid (e.g. linklocal) prefix */
if (!zebra_check_addr(&rn->p)) {
if (IS_ZEBRA_DEBUG_RIB) {
zlog_debug(
"%u:%pRN: Redist del old: skipping invalid prefix",
vrfid, rn);
}
return;
}
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
/*
* Skip this client if it will receive an update for the
* 'new' re
*/
if (zebra_redistribute_check(rn, new_re, client))
continue;
/* Send a delete for the 'old' re to any subscribed client. */
if (zebra_redistribute_check(rn, old_re, client))
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
client, rn, old_re);
}
2002-12-13 21:15:29 +01:00
}
void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
2002-12-13 21:15:29 +01:00
{
afi_t afi = 0;
int type = 0;
unsigned short instance;
STREAM_GETC(msg, afi);
STREAM_GETC(msg, type);
STREAM_GETW(msg, instance);
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
__func__, zebra_route_string(client->proto), afi,
zebra_route_string(type), VRF_LOGNAME(zvrf->vrf),
zvrf_id(zvrf), instance);
if (afi == 0 || afi >= AFI_MAX) {
flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
"%s: Specified afi %d does not exist", __func__, afi);
return;
}
if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
zlog_debug("%s: Specified Route Type %d does not exist",
__func__, type);
return;
}
if (instance) {
if (!redist_check_instance(&client->mi_redist[afi][type],
instance)) {
redist_add_instance(&client->mi_redist[afi][type],
instance);
zebra_redistribute(client, type, instance,
zvrf_id(zvrf), afi);
}
} else {
if (!vrf_bitmap_check(&client->redist[afi][type],
zvrf_id(zvrf))) {
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"%s: setting vrf %s(%u) redist bitmap",
__func__, VRF_LOGNAME(zvrf->vrf),
zvrf_id(zvrf));
vrf_bitmap_set(&client->redist[afi][type],
zvrf_id(zvrf));
zebra_redistribute(client, type, 0, zvrf_id(zvrf), afi);
}
}
stream_failure:
return;
}
2002-12-13 21:15:29 +01:00
void zebra_redistribute_delete(ZAPI_HANDLER_ARGS)
2002-12-13 21:15:29 +01:00
{
afi_t afi = 0;
int type = 0;
unsigned short instance;
STREAM_GETC(msg, afi);
STREAM_GETC(msg, type);
STREAM_GETW(msg, instance);
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
__func__, zebra_route_string(client->proto), afi,
zebra_route_string(type), VRF_LOGNAME(zvrf->vrf),
zvrf_id(zvrf), instance);
if (afi == 0 || afi >= AFI_MAX) {
flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
"%s: Specified afi %d does not exist", __func__, afi);
return;
}
if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
zlog_debug("%s: Specified Route Type %d does not exist",
__func__, type);
return;
}
/*
* NOTE: no need to withdraw the previously advertised routes. The
* clients
* themselves should keep track of the received routes from zebra and
* withdraw them when necessary.
*/
if (instance)
redist_del_instance(&client->mi_redist[afi][type], instance);
else
vrf_bitmap_unset(&client->redist[afi][type], zvrf_id(zvrf));
stream_failure:
return;
}
2002-12-13 21:15:29 +01:00
void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS)
2002-12-13 21:15:29 +01:00
{
afi_t afi = 0;
STREAM_GETC(msg, afi);
if (afi == 0 || afi >= AFI_MAX) {
flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
"%s: Specified afi %u does not exist", __func__, afi);
return;
}
vrf_bitmap_set(&client->redist_default[afi], zvrf_id(zvrf));
zebra_redistribute_default(client, zvrf_id(zvrf));
stream_failure:
return;
2002-12-13 21:15:29 +01:00
}
void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS)
2002-12-13 21:15:29 +01:00
{
afi_t afi = 0;
STREAM_GETC(msg, afi);
if (afi == 0 || afi >= AFI_MAX) {
flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
"%s: Specified afi %u does not exist", __func__, afi);
return;
}
vrf_bitmap_unset(&client->redist_default[afi], zvrf_id(zvrf));
stream_failure:
return;
2002-12-13 21:15:29 +01:00
}
/* Interface up information. */
void zebra_interface_up_update(struct interface *ifp)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
2002-12-13 21:15:29 +01:00
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
if (ifp->ptm_status || !ifp->ptm_enable) {
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode,
client)) {
/* Do not send unsolicited messages to synchronous
* clients.
*/
if (client->synchronous)
continue;
zsend_interface_update(ZEBRA_INTERFACE_UP,
client, ifp);
zsend_interface_link_params(client, ifp);
}
Update Traffic Engineering Support for OSPFD NOTE: I am squashing several commits together because they do not independently compile and we need this ability to do any type of sane testing on the patches. Since this series builds together I am doing this. -DBS This new structure is the basis to get new link parameters for Traffic Engineering from Zebra/interface layer to OSPFD and ISISD for the support of Traffic Engineering * lib/if.[c,h]: link parameters struture and get/set functions * lib/command.[c,h]: creation of a new link-node * lib/zclient.[c,h]: modification to the ZBUS message to convey the link parameters structure * lib/zebra.h: New ZBUS message Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support for IEEE 754 format * lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to safely convert between big-endian IEEE-754 single and double binary format, as used in IETF RFCs, and C99. Implementation depends on host using __STDC_IEC_559__, which should be everything we care about. Should correctly error out otherwise. * lib/network.[c,h]: Add ntohf and htonf converter * lib/memtypes.c: Add new memeory type for Traffic Engineering support Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add link parameters support to Zebra * zebra/interface.c: - Add new link-params CLI commands - Add new functions to set/get link parameters for interface * zebra/redistribute.[c,h]: Add new function to propagate link parameters to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering. * zebra/redistribute_null.c: Add new function zebra_interface_parameters_update() * zebra/zserv.[c,h]: Add new functions to send link parameters Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support of new link-params CLI to vtysh In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue to use the ordered version for adding line i.e. config_add_line_uniq() to print Interface CLI commands as it completely break the new LINK_PARAMS_NODE. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Update Traffic Engineering support for OSPFD These patches update original code to RFC3630 (OSPF-TE) and add support of RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support of RFC6827 (ASON - GMPLS). * ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering * ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392 * ospfd/ospf_packet.c: Update checking of OSPF_OPTION * ospfd/ospf_vty.[c,h]: Update ospf_str2area_id * ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get Link Parameters information from the interface to populate Traffic Engineering metrics * ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN) * ospfd/ospf_te.[c,h]: Major modifications to update the code to new link parameters structure and new RFCs Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> tmp
2016-04-19 16:21:46 +02:00
}
2002-12-13 21:15:29 +01:00
}
/* Interface down information. */
void zebra_interface_down_update(struct interface *ifp)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
2002-12-13 21:15:29 +01:00
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
}
2002-12-13 21:15:29 +01:00
}
/* Interface information update. */
void zebra_interface_add_update(struct interface *ifp)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
2002-12-13 21:15:29 +01:00
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
client->ifadd_cnt++;
zsend_interface_add(client, ifp);
zsend_interface_link_params(client, ifp);
}
2002-12-13 21:15:29 +01:00
}
void zebra_interface_delete_update(struct interface *ifp)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
2002-12-13 21:15:29 +01:00
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
client->ifdel_cnt++;
zsend_interface_delete(client, ifp);
}
2002-12-13 21:15:29 +01:00
}
/* Interface address addition. */
void zebra_interface_address_add_update(struct interface *ifp,
struct connected *ifc)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s vrf %s(%u)",
ifc->address, ifp->name, ifp->vrf->name,
ifp->vrf->vrf_id);
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
flog_warn(
EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR,
"advertising address to clients that is not yet usable.");
zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 1);
2004-10-03 20:18:34 +02:00
router_id_add_address(ifc);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) {
client->connected_rt_add_cnt++;
zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD,
client, ifp, ifc);
}
}
/* interface associated NHGs may have been deleted,
* re-sync zebra -> dplane NHGs
*/
zebra_interface_nhg_reinstall(ifp);
2002-12-13 21:15:29 +01:00
}
/* Interface address deletion. */
void zebra_interface_address_delete_update(struct interface *ifp,
struct connected *ifc)
{
struct listnode *node, *nnode;
2002-12-13 21:15:29 +01:00
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s vrf %s(%u)",
ifc->address, ifp->name, ifp->vrf->name,
ifp->vrf->vrf_id);
zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0);
2004-10-03 20:18:34 +02:00
router_id_del_address(ifc);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) {
client->connected_rt_del_cnt++;
zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE,
client, ifp, ifc);
}
}
2002-12-13 21:15:29 +01:00
}
/* Interface VRF change. May need to delete from clients not interested in
* the new VRF. Note that this function is invoked *prior* to the VRF change.
*/
void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
{
struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
ifp->name, ifp->vrf->vrf_id, new_vrf_id);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
/* Need to delete if the client is not interested in the new
* VRF. */
zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
client->ifdel_cnt++;
zsend_interface_delete(client, ifp);
zsend_interface_vrf_update(client, ifp, new_vrf_id);
}
}
/* Interface VRF change. This function is invoked *post* VRF change and sends an
* add to clients who are interested in the new VRF but not in the old VRF.
*/
void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id)
{
struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug(
"MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
ifp->name, old_vrf_id, ifp->vrf->vrf_id);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
/* Need to add if the client is interested in the new VRF. */
client->ifadd_cnt++;
zsend_interface_add(client, ifp);
zsend_interface_addresses(client, ifp);
}
}
int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn,
struct route_entry *re, const char *rmap_name)
{
struct route_entry *newre;
struct route_entry *same;
struct prefix p;
struct nexthop_group *ng;
lib: Introducing a 3rd state for route-map match cmd: RMAP_NOOP Introducing a 3rd state for route_map_apply library function: RMAP_NOOP Traditionally route map MATCH rule apis were designed to return a binary response, consisting of either RMAP_MATCH or RMAP_NOMATCH. (Route-map SET rule apis return RMAP_OKAY or RMAP_ERROR). Depending on this response, the following statemachine decided the course of action: State1: If match cmd returns RMAP_MATCH then, keep existing behaviour. If routemap type is PERMIT, execute set cmds or call cmds if applicable, otherwise PERMIT! Else If routemap type is DENY, we DENYMATCH right away State2: If match cmd returns RMAP_NOMATCH, continue on to next route-map. If there are no other rules or if all the rules return RMAP_NOMATCH, return DENYMATCH We require a 3rd state because of the following situation: The issue - what if, the rule api needs to abort or ignore a rule?: "match evpn vni xx" route-map filter can be applied to incoming routes regardless of whether the tunnel type is vxlan or mpls. This rule should be N/A for mpls based evpn route, but applicable to only vxlan based evpn route. Also, this rule should be applicable for routes with VNI label only, and not for routes without labels. For example, type 3 and type 4 EVPN routes do not have labels, so, this match cmd should let them through. Today, the filter produces either a match or nomatch response regardless of whether it is mpls/vxlan, resulting in either permitting or denying the route.. So an mpls evpn route may get filtered out incorrectly. Eg: "route-map RM1 permit 10 ; match evpn vni 20" or "route-map RM2 deny 20 ; match vni 20" With the introduction of the 3rd state, we can abort this rule check safely. How? The rules api can now return RMAP_NOOP to indicate that it encountered an invalid check, and needs to abort just that rule, but continue with other rules. As a result we have a 3rd state: State3: If match cmd returned RMAP_NOOP Then, proceed to other route-map, otherwise if there are no more rules or if all the rules return RMAP_NOOP, then, return RMAP_PERMITMATCH. Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-06-19 23:04:36 +02:00
route_map_result_t ret = RMAP_PERMITMATCH;
afi_t afi;
afi = family2afi(rn->p.family);
if (rmap_name)
ret = zebra_import_table_route_map_check(afi, re, re->instance,
&rn->p,
zebra: import table match against interface name could fail If an import table route-map is trying to match against a particular interface, The code is matching against the actual vrf the route entry is in -vs- the vrf the nexthop entry is in. Let's modify the code to actually allow the import table entry to match against the nexthops vrf. Not working: ip import-table 91 ip import-table 93 route-map FOO no service integrated-vtysh-config ! debug zebra events ! interface green ip address 192.168.4.3/24 exit ! route-map FOO permit 10 match interface green exit eva# show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure K>* 0.0.0.0/0 [0/100] via 192.168.119.1, enp13s0, 1d10h07m T[91]>* 1.2.3.5/32 [15/0] via 192.168.119.1, enp13s0, 00:00:05 K>* 169.254.0.0/16 [0/1000] is directly connected, virbr0 linkdown, 1d16h34m C>* 192.168.44.0/24 is directly connected, virbr1, 01:30:51 C>* 192.168.45.0/24 is directly connected, virbr2, 01:30:51 C>* 192.168.119.0/24 is directly connected, enp13s0, 1d16h34m C>* 192.168.122.0/24 is directly connected, virbr0 linkdown, 01:30:51 eva# show ip route table 91 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure VRF default table 91: K>* 1.2.3.5/32 [0/0] via 192.168.119.1, enp13s0, 00:00:15 eva# show ip route table 93 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure VRF default table 93: K * 1.2.3.4/32 [0/0] via 192.168.4.5, green (vrf green), 00:03:05 Working: eva# show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure K>* 0.0.0.0/0 [0/100] via 192.168.119.1, enp13s0, 00:03:09 T[93]>* 1.2.3.4/32 [15/0] via 192.168.4.5, green (vrf green), 00:02:21 T[91]>* 1.2.3.5/32 [15/0] via 192.168.119.1, enp13s0, 00:02:26 K>* 169.254.0.0/16 [0/1000] is directly connected, virbr0, 00:03:09 C>* 192.168.44.0/24 is directly connected, virbr1, 00:03:09 C>* 192.168.45.0/24 is directly connected, virbr2, 00:03:09 C>* 192.168.119.0/24 is directly connected, enp13s0, 00:03:09 C>* 192.168.122.0/24 is directly connected, virbr0, 00:03:09 eva# show ip route table 91 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure VRF default table 91: K * 1.2.3.5/32 [0/0] via 192.168.119.1, enp13s0, 00:03:12 eva# show ip route table 93 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure VRF default table 93: K * 1.2.3.4/32 [0/0] via 192.168.4.5, green (vrf green), 00:03:14 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-11 16:18:41 +02:00
re->nhe->nhg.nexthop,
re->tag, rmap_name);
lib: Introducing a 3rd state for route-map match cmd: RMAP_NOOP Introducing a 3rd state for route_map_apply library function: RMAP_NOOP Traditionally route map MATCH rule apis were designed to return a binary response, consisting of either RMAP_MATCH or RMAP_NOMATCH. (Route-map SET rule apis return RMAP_OKAY or RMAP_ERROR). Depending on this response, the following statemachine decided the course of action: State1: If match cmd returns RMAP_MATCH then, keep existing behaviour. If routemap type is PERMIT, execute set cmds or call cmds if applicable, otherwise PERMIT! Else If routemap type is DENY, we DENYMATCH right away State2: If match cmd returns RMAP_NOMATCH, continue on to next route-map. If there are no other rules or if all the rules return RMAP_NOMATCH, return DENYMATCH We require a 3rd state because of the following situation: The issue - what if, the rule api needs to abort or ignore a rule?: "match evpn vni xx" route-map filter can be applied to incoming routes regardless of whether the tunnel type is vxlan or mpls. This rule should be N/A for mpls based evpn route, but applicable to only vxlan based evpn route. Also, this rule should be applicable for routes with VNI label only, and not for routes without labels. For example, type 3 and type 4 EVPN routes do not have labels, so, this match cmd should let them through. Today, the filter produces either a match or nomatch response regardless of whether it is mpls/vxlan, resulting in either permitting or denying the route.. So an mpls evpn route may get filtered out incorrectly. Eg: "route-map RM1 permit 10 ; match evpn vni 20" or "route-map RM2 deny 20 ; match vni 20" With the introduction of the 3rd state, we can abort this rule check safely. How? The rules api can now return RMAP_NOOP to indicate that it encountered an invalid check, and needs to abort just that rule, but continue with other rules. As a result we have a 3rd state: State3: If match cmd returned RMAP_NOOP Then, proceed to other route-map, otherwise if there are no more rules or if all the rules return RMAP_NOOP, then, return RMAP_PERMITMATCH. Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-06-19 23:04:36 +02:00
if (ret != RMAP_PERMITMATCH) {
UNSET_FLAG(re->flags, ZEBRA_FLAG_SELECTED);
zebra_del_import_table_entry(zvrf, rn, re);
return 0;
}
prefix_copy(&p, &rn->p);
RNODE_FOREACH_RE (rn, same) {
if (CHECK_FLAG(same->status, ROUTE_ENTRY_REMOVED))
continue;
if (same->type == re->type && same->instance == re->instance
&& same->table == re->table
&& same->type != ZEBRA_ROUTE_CONNECT)
break;
}
if (same) {
UNSET_FLAG(same->flags, ZEBRA_FLAG_SELECTED);
zebra_del_import_table_entry(zvrf, rn, same);
}
UNSET_FLAG(re->flags, ZEBRA_FLAG_RR_USE_DISTANCE);
newre = zebra_rib_route_entry_new(
0, ZEBRA_ROUTE_TABLE, re->table, re->flags, re->nhe_id,
zvrf->table_id, re->metric, re->mtu,
zebra_import_table_distance[afi][re->table], re->tag);
ng = nexthop_group_new();
copy_nexthops(&ng->nexthop, re->nhe->nhg.nexthop, NULL);
rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre, ng, false);
return 0;
}
int zebra_del_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn,
struct route_entry *re)
{
struct prefix p;
afi_t afi;
afi = family2afi(rn->p.family);
prefix_copy(&p, &rn->p);
rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_TABLE,
re->table, re->flags, &p, NULL, re->nhe->nhg.nexthop,
re->nhe_id, zvrf->table_id, re->metric, re->distance,
false);
return 0;
}
/* Assuming no one calls this with the main routing table */
int zebra_import_table(afi_t afi, vrf_id_t vrf_id, uint32_t table_id,
uint32_t distance, const char *rmap_name, int add)
{
struct route_table *table;
struct route_entry *re;
struct route_node *rn;
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(vrf_id);
if (!is_zebra_valid_kernel_table(table_id)
|| (table_id == RT_TABLE_MAIN))
return -1;
if (afi >= AFI_MAX)
return -1;
zebra: separate zebra_vrf_lookup_table_with_id() We were creating `other` tables in rib_del(), vty commands, and dataplane return callback via the zebra_vrf_table_with_table_id() API. Seperate the API into only a lookup, never create and added another with `get` in the name (following the standard we use in other table APIs). Then changed the rib_del(), rib_find_rn_from_ctx(), and show route summary vty command to use the lookup API instead. This was found via a crash where two different vrfs though they owned the table. On delete, one free'd all the nodes, and then the other tried to use them. It required specific timing of a VRF existing, going away, and coming back again to cause the crash. =23464== Invalid read of size 8 ==23464== at 0x179EA4: rib_dest_from_rnode (rib.h:433) ==23464== by 0x17ACB1: zebra_vrf_delete (zebra_vrf.c:253) ==23464== by 0x48F3D45: vrf_delete (vrf.c:243) ==23464== by 0x48F4468: vrf_terminate (vrf.c:532) ==23464== by 0x13D8C5: sigint (main.c:172) ==23464== by 0x48DD25C: quagga_sigevent_process (sigevent.c:105) ==23464== by 0x48F0502: thread_fetch (thread.c:1417) ==23464== by 0x48AC82B: frr_run (libfrr.c:1023) ==23464== by 0x13DD02: main (main.c:483) ==23464== Address 0x5152788 is 104 bytes inside a block of size 112 free'd ==23464== at 0x48369AB: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==23464== by 0x48B25B8: qfree (memory.c:129) ==23464== by 0x48EA335: route_node_destroy (table.c:500) ==23464== by 0x48E967F: route_node_free (table.c:90) ==23464== by 0x48E9742: route_table_free (table.c:124) ==23464== by 0x48E9599: route_table_finish (table.c:60) ==23464== by 0x170CEA: zebra_router_free_table (zebra_router.c:165) ==23464== by 0x170DB4: zebra_router_release_table (zebra_router.c:188) ==23464== by 0x17AAD2: zebra_vrf_disable (zebra_vrf.c:222) ==23464== by 0x48F3F0C: vrf_disable (vrf.c:313) ==23464== by 0x48F3CCF: vrf_delete (vrf.c:223) ==23464== by 0x48F4468: vrf_terminate (vrf.c:532) ==23464== Block was alloc'd at ==23464== at 0x4837B65: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==23464== by 0x48B24A2: qcalloc (memory.c:110) ==23464== by 0x48EA2FE: route_node_create (table.c:488) ==23464== by 0x48E95C7: route_node_new (table.c:66) ==23464== by 0x48E95E5: route_node_set (table.c:75) ==23464== by 0x48E9EA9: route_node_get (table.c:326) ==23464== by 0x48E1EDB: srcdest_rnode_get (srcdest_table.c:244) ==23464== by 0x16EA4B: rib_add_multipath (zebra_rib.c:2730) ==23464== by 0x1A5310: zread_route_add (zapi_msg.c:1592) ==23464== by 0x1A7B8E: zserv_handle_commands (zapi_msg.c:2579) ==23464== by 0x19D689: zserv_process_messages (zserv.c:523) ==23464== by 0x48F09F8: thread_call (thread.c:1599) Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-11-01 20:52:47 +01:00
table = zebra_vrf_get_table_with_table_id(afi, SAFI_UNICAST, vrf_id,
table_id);
if (table == NULL) {
return 0;
} else if (IS_ZEBRA_DEBUG_RIB) {
zlog_debug("%s routes from table %d",
add ? "Importing" : "Unimporting", table_id);
}
if (add) {
if (rmap_name)
zebra_add_import_table_route_map(afi, rmap_name,
table_id);
else {
rmap_name =
zebra_get_import_table_route_map(afi, table_id);
if (rmap_name) {
zebra_del_import_table_route_map(afi, table_id);
rmap_name = NULL;
}
}
zebra_import_table_used[afi][table_id] = 1;
zebra_import_table_distance[afi][table_id] = distance;
} else {
zebra_import_table_used[afi][table_id] = 0;
zebra_import_table_distance[afi][table_id] =
ZEBRA_TABLE_DISTANCE_DEFAULT;
rmap_name = zebra_get_import_table_route_map(afi, table_id);
if (rmap_name) {
zebra_del_import_table_route_map(afi, table_id);
rmap_name = NULL;
}
}
for (rn = route_top(table); rn; rn = route_next(rn)) {
/* For each entry in the non-default routing table,
* add the entry in the main table
*/
if (!rn->info)
continue;
RNODE_FOREACH_RE (rn, re) {
if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
continue;
break;
}
if (!re)
continue;
if (((afi == AFI_IP) && (rn->p.family == AF_INET))
|| ((afi == AFI_IP6) && (rn->p.family == AF_INET6))) {
if (add)
zebra_add_import_table_entry(zvrf, rn, re,
rmap_name);
else
zebra_del_import_table_entry(zvrf, rn, re);
}
}
return 0;
}
int zebra_import_table_config(struct vty *vty, vrf_id_t vrf_id)
{
int i;
afi_t afi;
int write = 0;
char afi_str[AFI_MAX][10] = {"", "ip", "ipv6", "ethernet"};
const char *rmap_name;
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
for (i = 1; i < ZEBRA_KERNEL_TABLE_MAX; i++) {
if (!is_zebra_import_table_enabled(afi, vrf_id, i))
continue;
if (zebra_import_table_distance[afi][i]
!= ZEBRA_TABLE_DISTANCE_DEFAULT) {
vty_out(vty, "%s import-table %d distance %d",
afi_str[afi], i,
zebra_import_table_distance[afi][i]);
} else {
vty_out(vty, "%s import-table %d", afi_str[afi],
i);
}
rmap_name = zebra_get_import_table_route_map(afi, i);
if (rmap_name)
vty_out(vty, " route-map %s", rmap_name);
vty_out(vty, "\n");
write = 1;
}
}
return write;
}
static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf *zvrf,
afi_t afi, int table_id,
const char *rmap)
{
struct route_table *table;
struct route_entry *re;
struct route_node *rn;
const char *rmap_name;
rmap_name = zebra_get_import_table_route_map(afi, table_id);
if ((!rmap_name) || (strcmp(rmap_name, rmap) != 0))
return;
zebra: separate zebra_vrf_lookup_table_with_id() We were creating `other` tables in rib_del(), vty commands, and dataplane return callback via the zebra_vrf_table_with_table_id() API. Seperate the API into only a lookup, never create and added another with `get` in the name (following the standard we use in other table APIs). Then changed the rib_del(), rib_find_rn_from_ctx(), and show route summary vty command to use the lookup API instead. This was found via a crash where two different vrfs though they owned the table. On delete, one free'd all the nodes, and then the other tried to use them. It required specific timing of a VRF existing, going away, and coming back again to cause the crash. =23464== Invalid read of size 8 ==23464== at 0x179EA4: rib_dest_from_rnode (rib.h:433) ==23464== by 0x17ACB1: zebra_vrf_delete (zebra_vrf.c:253) ==23464== by 0x48F3D45: vrf_delete (vrf.c:243) ==23464== by 0x48F4468: vrf_terminate (vrf.c:532) ==23464== by 0x13D8C5: sigint (main.c:172) ==23464== by 0x48DD25C: quagga_sigevent_process (sigevent.c:105) ==23464== by 0x48F0502: thread_fetch (thread.c:1417) ==23464== by 0x48AC82B: frr_run (libfrr.c:1023) ==23464== by 0x13DD02: main (main.c:483) ==23464== Address 0x5152788 is 104 bytes inside a block of size 112 free'd ==23464== at 0x48369AB: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==23464== by 0x48B25B8: qfree (memory.c:129) ==23464== by 0x48EA335: route_node_destroy (table.c:500) ==23464== by 0x48E967F: route_node_free (table.c:90) ==23464== by 0x48E9742: route_table_free (table.c:124) ==23464== by 0x48E9599: route_table_finish (table.c:60) ==23464== by 0x170CEA: zebra_router_free_table (zebra_router.c:165) ==23464== by 0x170DB4: zebra_router_release_table (zebra_router.c:188) ==23464== by 0x17AAD2: zebra_vrf_disable (zebra_vrf.c:222) ==23464== by 0x48F3F0C: vrf_disable (vrf.c:313) ==23464== by 0x48F3CCF: vrf_delete (vrf.c:223) ==23464== by 0x48F4468: vrf_terminate (vrf.c:532) ==23464== Block was alloc'd at ==23464== at 0x4837B65: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==23464== by 0x48B24A2: qcalloc (memory.c:110) ==23464== by 0x48EA2FE: route_node_create (table.c:488) ==23464== by 0x48E95C7: route_node_new (table.c:66) ==23464== by 0x48E95E5: route_node_set (table.c:75) ==23464== by 0x48E9EA9: route_node_get (table.c:326) ==23464== by 0x48E1EDB: srcdest_rnode_get (srcdest_table.c:244) ==23464== by 0x16EA4B: rib_add_multipath (zebra_rib.c:2730) ==23464== by 0x1A5310: zread_route_add (zapi_msg.c:1592) ==23464== by 0x1A7B8E: zserv_handle_commands (zapi_msg.c:2579) ==23464== by 0x19D689: zserv_process_messages (zserv.c:523) ==23464== by 0x48F09F8: thread_call (thread.c:1599) Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-11-01 20:52:47 +01:00
table = zebra_vrf_get_table_with_table_id(afi, SAFI_UNICAST,
zvrf->vrf->vrf_id, table_id);
if (!table) {
if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug("%s: Table id=%d not found", __func__,
table_id);
return;
}
for (rn = route_top(table); rn; rn = route_next(rn)) {
/*
* For each entry in the non-default routing table,
* add the entry in the main table
*/
if (!rn->info)
continue;
RNODE_FOREACH_RE (rn, re) {
if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
continue;
break;
}
if (!re)
continue;
if (((afi == AFI_IP) && (rn->p.family == AF_INET))
|| ((afi == AFI_IP6) && (rn->p.family == AF_INET6)))
zebra_add_import_table_entry(zvrf, rn, re, rmap_name);
}
return;
}
static void zebra_import_table_rm_update_vrf(struct zebra_vrf *zvrf,
const char *rmap)
{
afi_t afi;
int i;
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
for (i = 1; i < ZEBRA_KERNEL_TABLE_MAX; i++) {
if (!is_zebra_import_table_enabled(
afi, zvrf->vrf->vrf_id, i))
continue;
zebra_import_table_rm_update_vrf_afi(zvrf, afi, i,
rmap);
}
}
}
void zebra_import_table_rm_update(const char *rmap)
{
struct vrf *vrf;
struct zebra_vrf *zvrf;
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
zvrf = vrf->info;
if (!zvrf)
continue;
zebra_import_table_rm_update_vrf(zvrf, rmap);
}
}
Update Traffic Engineering Support for OSPFD NOTE: I am squashing several commits together because they do not independently compile and we need this ability to do any type of sane testing on the patches. Since this series builds together I am doing this. -DBS This new structure is the basis to get new link parameters for Traffic Engineering from Zebra/interface layer to OSPFD and ISISD for the support of Traffic Engineering * lib/if.[c,h]: link parameters struture and get/set functions * lib/command.[c,h]: creation of a new link-node * lib/zclient.[c,h]: modification to the ZBUS message to convey the link parameters structure * lib/zebra.h: New ZBUS message Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support for IEEE 754 format * lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to safely convert between big-endian IEEE-754 single and double binary format, as used in IETF RFCs, and C99. Implementation depends on host using __STDC_IEC_559__, which should be everything we care about. Should correctly error out otherwise. * lib/network.[c,h]: Add ntohf and htonf converter * lib/memtypes.c: Add new memeory type for Traffic Engineering support Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add link parameters support to Zebra * zebra/interface.c: - Add new link-params CLI commands - Add new functions to set/get link parameters for interface * zebra/redistribute.[c,h]: Add new function to propagate link parameters to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering. * zebra/redistribute_null.c: Add new function zebra_interface_parameters_update() * zebra/zserv.[c,h]: Add new functions to send link parameters Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support of new link-params CLI to vtysh In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue to use the ordered version for adding line i.e. config_add_line_uniq() to print Interface CLI commands as it completely break the new LINK_PARAMS_NODE. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Update Traffic Engineering support for OSPFD These patches update original code to RFC3630 (OSPF-TE) and add support of RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support of RFC6827 (ASON - GMPLS). * ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering * ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392 * ospfd/ospf_packet.c: Update checking of OSPF_OPTION * ospfd/ospf_vty.[c,h]: Update ospf_str2area_id * ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get Link Parameters information from the interface to populate Traffic Engineering metrics * ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN) * ospfd/ospf_te.[c,h]: Major modifications to update the code to new link parameters structure and new RFCs Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> tmp
2016-04-19 16:21:46 +02:00
/* Interface parameters update */
void zebra_interface_parameters_update(struct interface *ifp)
{
struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
Update Traffic Engineering Support for OSPFD NOTE: I am squashing several commits together because they do not independently compile and we need this ability to do any type of sane testing on the patches. Since this series builds together I am doing this. -DBS This new structure is the basis to get new link parameters for Traffic Engineering from Zebra/interface layer to OSPFD and ISISD for the support of Traffic Engineering * lib/if.[c,h]: link parameters struture and get/set functions * lib/command.[c,h]: creation of a new link-node * lib/zclient.[c,h]: modification to the ZBUS message to convey the link parameters structure * lib/zebra.h: New ZBUS message Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support for IEEE 754 format * lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to safely convert between big-endian IEEE-754 single and double binary format, as used in IETF RFCs, and C99. Implementation depends on host using __STDC_IEC_559__, which should be everything we care about. Should correctly error out otherwise. * lib/network.[c,h]: Add ntohf and htonf converter * lib/memtypes.c: Add new memeory type for Traffic Engineering support Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add link parameters support to Zebra * zebra/interface.c: - Add new link-params CLI commands - Add new functions to set/get link parameters for interface * zebra/redistribute.[c,h]: Add new function to propagate link parameters to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering. * zebra/redistribute_null.c: Add new function zebra_interface_parameters_update() * zebra/zserv.[c,h]: Add new functions to send link parameters Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support of new link-params CLI to vtysh In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue to use the ordered version for adding line i.e. config_add_line_uniq() to print Interface CLI commands as it completely break the new LINK_PARAMS_NODE. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Update Traffic Engineering support for OSPFD These patches update original code to RFC3630 (OSPF-TE) and add support of RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support of RFC6827 (ASON - GMPLS). * ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering * ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392 * ospfd/ospf_packet.c: Update checking of OSPF_OPTION * ospfd/ospf_vty.[c,h]: Update ospf_str2area_id * ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get Link Parameters information from the interface to populate Traffic Engineering metrics * ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN) * ospfd/ospf_te.[c,h]: Major modifications to update the code to new link parameters structure and new RFCs Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> tmp
2016-04-19 16:21:46 +02:00
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
zsend_interface_link_params(client, ifp);
}
Update Traffic Engineering Support for OSPFD NOTE: I am squashing several commits together because they do not independently compile and we need this ability to do any type of sane testing on the patches. Since this series builds together I am doing this. -DBS This new structure is the basis to get new link parameters for Traffic Engineering from Zebra/interface layer to OSPFD and ISISD for the support of Traffic Engineering * lib/if.[c,h]: link parameters struture and get/set functions * lib/command.[c,h]: creation of a new link-node * lib/zclient.[c,h]: modification to the ZBUS message to convey the link parameters structure * lib/zebra.h: New ZBUS message Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support for IEEE 754 format * lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to safely convert between big-endian IEEE-754 single and double binary format, as used in IETF RFCs, and C99. Implementation depends on host using __STDC_IEC_559__, which should be everything we care about. Should correctly error out otherwise. * lib/network.[c,h]: Add ntohf and htonf converter * lib/memtypes.c: Add new memeory type for Traffic Engineering support Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add link parameters support to Zebra * zebra/interface.c: - Add new link-params CLI commands - Add new functions to set/get link parameters for interface * zebra/redistribute.[c,h]: Add new function to propagate link parameters to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering. * zebra/redistribute_null.c: Add new function zebra_interface_parameters_update() * zebra/zserv.[c,h]: Add new functions to send link parameters Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support of new link-params CLI to vtysh In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue to use the ordered version for adding line i.e. config_add_line_uniq() to print Interface CLI commands as it completely break the new LINK_PARAMS_NODE. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Update Traffic Engineering support for OSPFD These patches update original code to RFC3630 (OSPF-TE) and add support of RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support of RFC6827 (ASON - GMPLS). * ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering * ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392 * ospfd/ospf_packet.c: Update checking of OSPF_OPTION * ospfd/ospf_vty.[c,h]: Update ospf_str2area_id * ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get Link Parameters information from the interface to populate Traffic Engineering metrics * ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN) * ospfd/ospf_te.[c,h]: Major modifications to update the code to new link parameters structure and new RFCs Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> tmp
2016-04-19 16:21:46 +02:00
}