]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zapi_msg.c
Merge pull request #13479 from ryndia/fix_leak
[mirror_frr.git] / zebra / zapi_msg.c
index d594512b3653fb29119c759cf3c590ab74922df6..4c6c336d417e11b44f324499f19923b3e4929584 100644 (file)
@@ -1,23 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Zebra API message creation & consumption.
  * Portions:
  *   Copyright (C) 1997-1999  Kunihiro Ishiguro
  *   Copyright (C) 2015-2018  Cumulus Networks, Inc.
  *   et al.
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -134,8 +121,6 @@ static int zserv_encode_nexthop(struct stream *s, struct nexthop *nexthop)
                stream_putl(s, nexthop->ifindex);
                break;
        case NEXTHOP_TYPE_IPV6:
-               stream_put(s, &nexthop->gate.ipv6, 16);
-               break;
        case NEXTHOP_TYPE_IPV6_IFINDEX:
                stream_put(s, &nexthop->gate.ipv6, 16);
                stream_putl(s, nexthop->ifindex);
@@ -143,7 +128,7 @@ static int zserv_encode_nexthop(struct stream *s, struct nexthop *nexthop)
        case NEXTHOP_TYPE_IFINDEX:
                stream_putl(s, nexthop->ifindex);
                break;
-       default:
+       case NEXTHOP_TYPE_BLACKHOLE:
                /* do nothing */
                break;
        }
@@ -576,7 +561,9 @@ int zsend_redistribute_route(int cmd, struct zserv *client,
                else
                        client->redist_v6_del_cnt++;
                break;
-       default:
+       case AFI_L2VPN:
+       case AFI_MAX:
+       case AFI_UNSPEC:
                break;
        }
 
@@ -1343,7 +1330,7 @@ static void zread_fec_register(ZAPI_HANDLER_ARGS)
        uint32_t label_index = MPLS_INVALID_LABEL_INDEX;
 
        s = msg;
-       zvrf = vrf_info_lookup(VRF_DEFAULT);
+       zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
        if (!zvrf)
                return;
 
@@ -1406,7 +1393,7 @@ static void zread_fec_unregister(ZAPI_HANDLER_ARGS)
        uint16_t flags;
 
        s = msg;
-       zvrf = vrf_info_lookup(VRF_DEFAULT);
+       zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
        if (!zvrf)
                return;
 
@@ -1777,13 +1764,19 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p,
                        nexthop->srte_color = api_nh->srte_color;
                }
 
-               /* MPLS labels for BGP-LU or Segment Routing */
+               /* Labels for MPLS BGP-LU or Segment Routing or EVPN */
                if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL)
                    && api_nh->type != NEXTHOP_TYPE_IFINDEX
                    && api_nh->type != NEXTHOP_TYPE_BLACKHOLE
                    && api_nh->label_num > 0) {
 
-                       label_type = lsp_type_from_re_type(client->proto);
+                       /* If label type was passed, use it */
+                       if (api_nh->label_type)
+                               label_type = api_nh->label_type;
+                       else
+                               label_type =
+                                       lsp_type_from_re_type(client->proto);
+
                        nexthop_add_labels(nexthop, label_type,
                                           api_nh->label_num,
                                           &api_nh->labels[0]);
@@ -1821,7 +1814,7 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p,
                                mpls_label2str(nexthop->nh_label->num_labels,
                                               nexthop->nh_label->label,
                                               labelbuf, sizeof(labelbuf),
-                                              false);
+                                              nexthop->nh_label_type, false);
                        }
 
                        zlog_debug("%s: nh=%s, vrf_id=%d %s",
@@ -2241,17 +2234,18 @@ static void zread_nexthop_lookup_mrib(ZAPI_HANDLER_ARGS)
 {
        struct ipaddr addr;
        struct route_entry *re = NULL;
+       union g_addr gaddr;
 
        STREAM_GET_IPADDR(msg, &addr);
 
        switch (addr.ipa_type) {
        case IPADDR_V4:
-               re = rib_match_ipv4_multicast(zvrf_id(zvrf), addr.ipaddr_v4,
-                                             NULL);
+               gaddr.ipv4 = addr.ipaddr_v4;
+               re = rib_match_multicast(AFI_IP, zvrf_id(zvrf), &gaddr, NULL);
                break;
        case IPADDR_V6:
-               re = rib_match_ipv6_multicast(zvrf_id(zvrf), addr.ipaddr_v6,
-                                             NULL);
+               gaddr.ipv6 = addr.ipaddr_v6;
+               re = rib_match_multicast(AFI_IP6, zvrf_id(zvrf), &gaddr, NULL);
                break;
        case IPADDR_NONE:
                /* ??? */
@@ -2343,7 +2337,7 @@ void zsend_capabilities_all_clients(void)
        struct zebra_vrf *zvrf;
        struct zserv *client;
 
-       zvrf = vrf_info_lookup(VRF_DEFAULT);
+       zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
@@ -3424,7 +3418,10 @@ static inline void zread_tc_filter(ZAPI_HANDLER_ARGS)
                        STREAM_GETL(s, filter.filter.u.flower.classid);
                        break;
                }
-               default:
+               case TC_FILTER_BPF:
+               case TC_FILTER_FLOW:
+               case TC_FILTER_U32:
+               case TC_FILTER_UNSPEC:
                        break;
                }
 
@@ -3698,7 +3695,7 @@ static inline void zebra_neigh_ip_del(ZAPI_HANDLER_ARGS)
 static inline void zread_iptable(ZAPI_HANDLER_ARGS)
 {
        struct zebra_pbr_iptable *zpi =
-               XCALLOC(MTYPE_TMP, sizeof(struct zebra_pbr_iptable));
+               XCALLOC(MTYPE_PBR_OBJ, sizeof(struct zebra_pbr_iptable));
        struct stream *s;
 
        s = msg;