]> git.proxmox.com Git - mirror_frr.git/blobdiff - pceplib/pcep_msg_tlvs_encoding.c
Merge pull request #11194 from donaldsharp/untrusted
[mirror_frr.git] / pceplib / pcep_msg_tlvs_encoding.c
index 3322663dc3e32984ca11c707c5365222a7090c92..b5a65d457b4c853298248335ca5231e4d0a30570 100644 (file)
  * Encoding and decoding for PCEP Object TLVs.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef __FreeBSD__
+#include <sys/endian.h>
+#else
+#include <endian.h>
+#endif /* __FreeBSD__ */
 #include <stdlib.h>
 #include <string.h>
 
@@ -241,7 +250,7 @@ struct pcep_object_tlv_header *(*const tlv_decoders[MAX_TLV_ENCODER_INDEX])(
        [PCEP_OBJ_TLV_TYPE_OBJECTIVE_FUNCTION_LIST] = pcep_decode_tlv_of_list,
 };
 
-static void initialize_tlv_coders()
+static void initialize_tlv_coders(void)
 {
        static bool initialized = false;
 
@@ -829,7 +838,15 @@ struct pcep_object_tlv_header *pcep_decode_tlv(const uint8_t *tlv_buf)
                return NULL;
        }
 
-       tlv_decoder_funcptr tlv_decoder = tlv_decoders[tlv_hdr.type];
+       tlv_decoder_funcptr tlv_decoder = NULL;
+       if (tlv_hdr.type == PCEP_OBJ_TYPE_CISCO_BSID) {
+               pcep_log(LOG_INFO,
+                        "%s: Cisco BSID TLV decoder found for TLV type [%d]",
+                        __func__, tlv_hdr.type);
+               tlv_decoder = tlv_decoders[PCEP_OBJ_TLV_TYPE_ARBITRARY];
+       } else {
+               tlv_decoder = tlv_decoders[tlv_hdr.type];
+       }
        if (tlv_decoder == NULL) {
                pcep_log(LOG_INFO, "%s: No TLV decoder found for TLV type [%d]",
                         __func__, tlv_hdr.type);
@@ -1135,7 +1152,7 @@ struct pcep_object_tlv_header *pcep_decode_tlv_path_setup_type_capability(
        uint16_t buf_index = normalize_pcep_tlv_length(
                TLV_HEADER_LENGTH + LENGTH_1WORD + num_psts);
        while ((tlv->header.encoded_tlv_length - buf_index) > TLV_HEADER_LENGTH
-              && num_iterations++ > MAX_ITERATIONS) {
+              && num_iterations++ < MAX_ITERATIONS) {
                struct pcep_object_tlv_header *sub_tlv =
                        pcep_decode_tlv(tlv_body_buf + buf_index);
                if (sub_tlv == NULL) {
@@ -1168,8 +1185,7 @@ pcep_decode_tlv_pol_id(struct pcep_object_tlv_header *tlv_hdr,
                return (struct pcep_object_tlv_header *)ipv4;
        } else {
                ipv4->is_ipv4 = false;
-               struct pcep_object_tlv_srpag_pol_id *ipv6 =
-                       (struct pcep_object_tlv_srpag_pol_id *)ipv4;
+               struct pcep_object_tlv_srpag_pol_id *ipv6 = ipv4;
                ipv6->color = ntohl(uint32_ptr[0]);
                decode_ipv6(&uint32_ptr[1], &ipv6->end_point.ipv6);
                return (struct pcep_object_tlv_header *)ipv6;