]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/redistribute.c
Merge pull request #3503 from qlyoung/fix-bgpd-show-ip-neigh-json-double-free
[mirror_frr.git] / zebra / redistribute.c
index 5a6565aec9cf145c0c6a1f814047a0dd920dcd55..f48fc6addb6069b05a5199ee29c7e1ef76e5d807 100644 (file)
@@ -43,6 +43,7 @@
 #include "zebra/zapi_msg.h"
 #include "zebra/zebra_memory.h"
 #include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_errors.h"
 
 #define ZEBRA_PTM_SUPPORT
 
@@ -113,14 +114,14 @@ static void zebra_redistribute(struct zserv *client, int type,
 
        for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
                RNODE_FOREACH_RE (rn, newre) {
-                       struct prefix *dst_p, *src_p;
+                       const struct prefix *dst_p, *src_p;
                        char buf[PREFIX_STRLEN];
 
                        srcdest_rnode_prefixes(rn, &dst_p, &src_p);
 
                        if (IS_ZEBRA_DEBUG_EVENT)
                                zlog_debug(
-                                       "%s: client %s %s(%d) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
+                                       "%s: client %s %s(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
                                        __func__,
                                        zebra_route_string(client->proto),
                                        prefix2str(dst_p, buf, sizeof(buf)),
@@ -147,7 +148,7 @@ static void zebra_redistribute(struct zserv *client, int type,
 
 /* Either advertise a route for redistribution to registered clients or */
 /* withdraw redistribution if add cannot be done for client */
-void redistribute_update(struct prefix *p, struct prefix *src_p,
+void redistribute_update(const struct prefix *p, const struct prefix *src_p,
                         struct route_entry *re, struct route_entry *prev_re)
 {
        struct listnode *node, *nnode;
@@ -166,7 +167,8 @@ void redistribute_update(struct prefix *p, struct prefix *src_p,
 
        afi = family2afi(p->family);
        if (!afi) {
-               zlog_warn("%s: Unknown AFI/SAFI prefix received\n",
+               flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
+                         "%s: Unknown AFI/SAFI prefix received\n",
                          __FUNCTION__);
                return;
        }
@@ -192,7 +194,7 @@ void redistribute_update(struct prefix *p, struct prefix *src_p,
                if (send_redistribute) {
                        if (IS_ZEBRA_DEBUG_EVENT) {
                                zlog_debug(
-                                          "%s: client %s %s(%d), type=%d, distance=%d, metric=%d",
+                                          "%s: client %s %s(%u), type=%d, distance=%d, metric=%d",
                                           __func__,
                                           zebra_route_string(client->proto),
                                           prefix2str(p, buf, sizeof(buf)),
@@ -216,7 +218,7 @@ void redistribute_update(struct prefix *p, struct prefix *src_p,
        }
 }
 
-void redistribute_delete(struct prefix *p, struct prefix *src_p,
+void redistribute_delete(const struct prefix *p, const struct prefix *src_p,
                         struct route_entry *re)
 {
        struct listnode *node, *nnode;
@@ -236,7 +238,8 @@ void redistribute_delete(struct prefix *p, struct prefix *src_p,
 
        afi = family2afi(p->family);
        if (!afi) {
-               zlog_warn("%s: Unknown AFI/SAFI prefix received\n",
+               flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
+                         "%s: Unknown AFI/SAFI prefix received\n",
                          __FUNCTION__);
                return;
        }
@@ -270,19 +273,20 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug(
-                       "%s: client proto %s afi=%d, wants %s, vrf %d, instance=%d",
+                       "%s: client proto %s afi=%d, wants %s, vrf %u, instance=%d",
                        __func__, zebra_route_string(client->proto), afi,
                        zebra_route_string(type), zvrf_id(zvrf), instance);
 
-       if (afi == 0 || afi > AFI_MAX) {
-               zlog_warn("%s: Specified afi %d does not exist",
+       if (afi == 0 || afi >= AFI_MAX) {
+               flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
+                         "%s: Specified afi %d does not exist",
                          __PRETTY_FUNCTION__, afi);
                return;
        }
 
        if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
-               zlog_warn("%s: Specified Route Type %d does not exist",
-                         __PRETTY_FUNCTION__, type);
+               zlog_debug("%s: Specified Route Type %d does not exist",
+                          __PRETTY_FUNCTION__, type);
                return;
        }
 
@@ -298,7 +302,7 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
                if (!vrf_bitmap_check(client->redist[afi][type],
                                      zvrf_id(zvrf))) {
                        if (IS_ZEBRA_DEBUG_EVENT)
-                               zlog_debug("%s: setting vrf %d redist bitmap",
+                               zlog_debug("%s: setting vrf %u redist bitmap",
                                           __func__, zvrf_id(zvrf));
                        vrf_bitmap_set(client->redist[afi][type],
                                       zvrf_id(zvrf));
@@ -320,15 +324,16 @@ void zebra_redistribute_delete(ZAPI_HANDLER_ARGS)
        STREAM_GETC(msg, type);
        STREAM_GETW(msg, instance);
 
-       if (afi == 0 || afi > AFI_MAX) {
-               zlog_warn("%s: Specified afi %d does not exist",
+       if (afi == 0 || afi >= AFI_MAX) {
+               flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF,
+                         "%s: Specified afi %d does not exist",
                          __PRETTY_FUNCTION__, afi);
                return;
        }
 
        if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
-               zlog_warn("%s: Specified Route Type %d does not exist",
-                         __PRETTY_FUNCTION__, type);
+               zlog_debug("%s: Specified Route Type %d does not exist",
+                          __PRETTY_FUNCTION__, type);
                return;
        }
 
@@ -365,7 +370,8 @@ void zebra_interface_up_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        if (ifp->ptm_status || !ifp->ptm_enable) {
                for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
@@ -384,7 +390,8 @@ void zebra_interface_down_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
                zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
@@ -398,7 +405,7 @@ void zebra_interface_add_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s[%d]", ifp->name,
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp->name,
                           ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
@@ -415,7 +422,8 @@ void zebra_interface_delete_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
                client->ifdel_cnt++;
@@ -435,12 +443,14 @@ void zebra_interface_address_add_update(struct interface *ifp,
                char buf[PREFIX_STRLEN];
 
                p = ifc->address;
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s",
-                          prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)",
+                          prefix2str(p, buf, sizeof(buf)), ifp->name,
+                          ifp->vrf_id);
        }
 
        if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
-               zlog_warn(
+               flog_warn(
+                       EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR,
                        "WARNING: advertising address to clients that is not yet usable.");
 
        zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 1);
@@ -467,8 +477,9 @@ void zebra_interface_address_delete_update(struct interface *ifp,
                char buf[PREFIX_STRLEN];
 
                p = ifc->address;
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s",
-                          prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)",
+                          prefix2str(p, buf, sizeof(buf)),
+                          ifp->name, ifp->vrf_id);
        }
 
        zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0);
@@ -539,8 +550,8 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re,
        afi = family2afi(rn->p.family);
        if (rmap_name)
                ret = zebra_import_table_route_map_check(
-                       afi, re->type, &rn->p, re->ng.nexthop, re->vrf_id,
-                       re->tag, rmap_name);
+                       afi, re->type, re->instance, &rn->p, re->ng.nexthop,
+                       re->vrf_id, re->tag, rmap_name);
 
        if (ret != RMAP_MATCH) {
                UNSET_FLAG(re->flags, ZEBRA_FLAG_SELECTED);
@@ -592,7 +603,7 @@ int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re)
 
        rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE, re->table,
                   re->flags, &p, NULL, re->ng.nexthop,
-                  zebrad.rtm_table_default, re->metric, false);
+                  zebrad.rtm_table_default, re->metric, re->distance, false);
 
        return 0;
 }
@@ -710,7 +721,7 @@ int zebra_import_table_config(struct vty *vty)
        return write;
 }
 
-void zebra_import_table_rm_update()
+void zebra_import_table_rm_update(const char *rmap)
 {
        afi_t afi;
        int i;
@@ -725,9 +736,8 @@ void zebra_import_table_rm_update()
                                continue;
 
                        rmap_name = zebra_get_import_table_route_map(afi, i);
-                       if (!rmap_name)
-                               return;
-
+                       if ((!rmap_name) || (strcmp(rmap_name, rmap) != 0))
+                               continue;
                        table = zebra_vrf_other_route_table(afi, i,
                                                            VRF_DEFAULT);
                        for (rn = route_top(table); rn; rn = route_next(rn)) {
@@ -768,8 +778,8 @@ void zebra_interface_parameters_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s",
-                          ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
                if (client->ifinfo)