]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_encap_tlv.c
bgpd: Allow v6 LL peers to work when connected to as well
[mirror_frr.git] / bgpd / bgp_encap_tlv.c
index 4457501613a1b25dde212471c3293a35cebac5bb..fd429120e69575b1f168ea352f446592ee1d5c12 100644 (file)
@@ -47,7 +47,7 @@ static struct bgp_attr_encap_subtlv *subtlv_encode_encap_l2tpv3_over_ip(
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
        new->length = total;
@@ -72,7 +72,7 @@ subtlv_encode_encap_gre(struct bgp_tea_subtlv_encap_gre_key *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
        new->length = total;
@@ -95,7 +95,7 @@ subtlv_encode_encap_pbb(struct bgp_tea_subtlv_encap_pbb *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
        new->length = total;
@@ -128,7 +128,7 @@ subtlv_encode_proto_type(struct bgp_tea_subtlv_proto_type *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE;
        new->length = total;
@@ -150,7 +150,7 @@ subtlv_encode_color(struct bgp_tea_subtlv_color *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_COLOR;
        new->length = total;
@@ -182,7 +182,7 @@ subtlv_encode_ipsec_ta(struct bgp_tea_subtlv_ipsec_ta *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA;
        new->length = total;
@@ -206,18 +206,18 @@ subtlv_encode_remote_endpoint(struct bgp_tea_subtlv_remote_endpoint *st)
        assert(total <= 0xff);
 
        new = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + total);
+                     sizeof(struct bgp_attr_encap_subtlv) + total);
        assert(new);
        new->type = BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT;
        new->length = total;
        p = new->value;
        if (st->family == AF_INET) {
-               memcpy(p, &(st->ip_address.v4.s_addr), 4);
-               p += 4;
+               memcpy(p, &(st->ip_address.v4.s_addr), IPV4_MAX_BYTELEN);
+               p += IPV4_MAX_BYTELEN;
        } else {
                assert(st->family == AF_INET6);
-               memcpy(p, &(st->ip_address.v6.s6_addr), 16);
-               p += 16;
+               memcpy(p, &(st->ip_address.v6.s6_addr), IPV6_MAX_BYTELEN);
+               p += IPV6_MAX_BYTELEN;
        }
        memcpy(p, &(st->as4), 4);
        return new;
@@ -401,10 +401,9 @@ void bgp_encap_type_vxlan_to_tlv(
 
        if (bet == NULL || !bet->vnid)
                return;
-       if (attr->encap_subtlvs)
-               XFREE(MTYPE_ENCAP_TLV, attr->encap_subtlvs);
+       XFREE(MTYPE_ENCAP_TLV, attr->encap_subtlvs);
        tlv = XCALLOC(MTYPE_ENCAP_TLV,
-                     sizeof(struct bgp_attr_encap_subtlv) - 1 + 12);
+                     sizeof(struct bgp_attr_encap_subtlv) + 12);
        tlv->type = 1; /* encapsulation type */
        tlv->length = 12;
        if (bet->vnid) {
@@ -578,10 +577,12 @@ subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv *subtlv,
        }
        if (subtlv->length == 8) {
                st->family = AF_INET;
-               memcpy(&st->ip_address.v4.s_addr, subtlv->value, 4);
+               memcpy(&st->ip_address.v4.s_addr, subtlv->value,
+                      IPV4_MAX_BYTELEN);
        } else {
                st->family = AF_INET6;
-               memcpy(&(st->ip_address.v6.s6_addr), subtlv->value, 16);
+               memcpy(&(st->ip_address.v6.s6_addr), subtlv->value,
+                      IPV6_MAX_BYTELEN);
        }
        i = subtlv->length - 4;
        ptr_get_be32(subtlv->value + i, &st->as4);