]> git.proxmox.com Git - mirror_frr.git/blobdiff - isisd/isis_tlvs.c
*: auto-convert to SPDX License IDs
[mirror_frr.git] / isisd / isis_tlvs.c
index d3d59fb4353d807b50a3fd694d7ba5042fc198e8..3ed2fe6eeb6d87e8b35225719aa482c3c66ee29d 100644 (file)
@@ -1,29 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * IS-IS TLV Serializer/Deserializer
  *
  * Copyright (C) 2015,2017 Christian Franke
  *
  * Copyright (C) 2019 Olivier Dugeon - Orange Labs (for TE and SR)
- *
- * This file is part of FRR.
- *
- * FRR 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.
- *
- * FRR 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 FRR; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
  */
-#include <json-c/json_object.h>
+
 #include <zebra.h>
+#include <json-c/json_object.h>
 
 #ifdef CRYPTO_INTERNAL
 #include "md5.h"
@@ -118,6 +103,14 @@ static const struct tlv_ops *const tlv_table[ISIS_CONTEXT_MAX][ISIS_TLV_MAX];
 static void append_item(struct isis_item_list *dest, struct isis_item *item);
 static void init_item_list(struct isis_item_list *items);
 
+/* For tests/isisd, TLV text requires ipv4-unicast instead of standard */
+static const char *isis_mtid2str_fake(uint16_t mtid)
+{
+       if (mtid == ISIS_MT_STANDARD)
+               return "ipv4-unicast";
+       return isis_mtid2str(mtid);
+}
+
 /* Functions for Extended IS Reachability SubTLVs a.k.a Traffic Engineering */
 struct isis_ext_subtlvs *isis_alloc_ext_subtlvs(void)
 {
@@ -130,6 +123,25 @@ struct isis_ext_subtlvs *isis_alloc_ext_subtlvs(void)
        return ext;
 }
 
+void isis_del_ext_subtlvs(struct isis_ext_subtlvs *ext)
+{
+       struct isis_item *item, *next_item;
+
+       if (!ext)
+               return;
+
+       /* First, free Adj SID and LAN Adj SID list if needed */
+       for (item = ext->adj_sid.head; item; item = next_item) {
+               next_item = item->next;
+               XFREE(MTYPE_ISIS_SUBTLV, item);
+       }
+       for (item = ext->lan_sid.head; item; item = next_item) {
+               next_item = item->next;
+               XFREE(MTYPE_ISIS_SUBTLV, item);
+       }
+       XFREE(MTYPE_ISIS_SUBTLV, ext);
+}
+
 /*
  * mtid parameter is used to determine if Adjacency is related to IPv4 or IPv6
  * Multi-Topology. Special 4096 value i.e. first R flag set is used to indicate
@@ -639,18 +651,7 @@ static void format_item_ext_subtlvs(struct isis_ext_subtlvs *exts,
 
 static void free_item_ext_subtlvs(struct  isis_ext_subtlvs *exts)
 {
-       struct isis_item *item, *next_item;
-
-       /* First, free Adj SID and LAN Adj SID list if needed */
-       for (item = exts->adj_sid.head; item; item = next_item) {
-               next_item = item->next;
-               XFREE(MTYPE_ISIS_SUBTLV, item);
-       }
-       for (item = exts->lan_sid.head; item; item = next_item) {
-               next_item = item->next;
-               XFREE(MTYPE_ISIS_SUBTLV, item);
-       }
-       XFREE(MTYPE_ISIS_SUBTLV, exts);
+       isis_del_ext_subtlvs(exts);
 }
 
 static int pack_item_ext_subtlvs(struct isis_ext_subtlvs *exts,
@@ -1050,6 +1051,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s,
                                                log, indent,
                                                "TLV size does not match expected size for Adjacency SID!\n");
                                        stream_forward_getp(s, subtlv_len - 2);
+                                       XFREE(MTYPE_ISIS_SUBTLV, adj);
                                        break;
                                }
 
@@ -1061,6 +1063,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s,
                                                log, indent,
                                                "TLV size does not match expected size for Adjacency SID!\n");
                                        stream_forward_getp(s, subtlv_len - 2);
+                                       XFREE(MTYPE_ISIS_SUBTLV, adj);
                                        break;
                                }
 
@@ -1105,6 +1108,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s,
                                        stream_forward_getp(
                                                s, subtlv_len - 2
                                                           - ISIS_SYS_ID_LEN);
+                                       XFREE(MTYPE_ISIS_SUBTLV, lan);
                                        break;
                                }
 
@@ -1118,6 +1122,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s,
                                        stream_forward_getp(
                                                s, subtlv_len - 2
                                                           - ISIS_SYS_ID_LEN);
+                                       XFREE(MTYPE_ISIS_SUBTLV, lan);
                                        break;
                                }
 
@@ -1883,6 +1888,7 @@ static void format_item_extended_reach(uint16_t mtid, struct isis_item *i,
 static void free_item_extended_reach(struct isis_item *i)
 {
        struct isis_extended_reach *item = (struct isis_extended_reach *)i;
+
        if (item->subtlvs != NULL)
                free_item_ext_subtlvs(item->subtlvs);
        XFREE(MTYPE_ISIS_TLV, item);
@@ -2390,7 +2396,7 @@ static void format_item_mt_router_info(uint16_t mtid, struct isis_item *i,
                json_object_string_add(mt_json, "attached", info->attached?"true":"false");
        } else
                sbuf_push(buf, indent, "MT Router Info: %s%s%s\n",
-                         isis_mtid2str(info->mtid),
+                         isis_mtid2str_fake(info->mtid),
                          info->overload ? " Overload" : "",
                          info->attached ? " Attached" : "");
 }
@@ -3571,9 +3577,9 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap,
 }
 
 static int unpack_tlv_router_cap(enum isis_tlv_context context,
-                                      uint8_t tlv_type, uint8_t tlv_len,
-                                      struct stream *s, struct sbuf *log,
-                                      void *dest, int indent)
+                                uint8_t tlv_type, uint8_t tlv_len,
+                                struct stream *s, struct sbuf *log, void *dest,
+                                int indent)
 {
        struct isis_tlvs *tlvs = dest;
        struct isis_router_cap *rcap;
@@ -3618,7 +3624,7 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context,
                                log, indent,
                                "WARNING: Router Capability subTLV length too large compared to expected size\n");
                        stream_forward_getp(s, STREAM_READABLE(s));
-
+                       XFREE(MTYPE_ISIS_TLV, rcap);
                        return 0;
                }
 
@@ -4305,7 +4311,7 @@ static int unpack_tlv_with_items(enum isis_tlv_context context,
                mtid = stream_getw(s) & ISIS_MT_MASK;
                tlv_pos += 2;
                sbuf_push(log, indent, "Unpacking as MT %s item TLV...\n",
-                         isis_mtid2str(mtid));
+                         isis_mtid2str_fake(mtid));
        } else {
                sbuf_push(log, indent, "Unpacking as item TLV...\n");
                mtid = ISIS_MT_IPV4_UNICAST;