]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgp, zebra: add some alignments with remarks from community
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 20 Apr 2020 16:02:46 +0000 (18:02 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 21 Aug 2020 11:37:08 +0000 (13:37 +0200)
align the code to remarks from community.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_attr.c
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h
bgpd/bgp_flowspec_vty.c
bgpd/bgp_vty.c
zebra/zebra_pbr.c

index a77d9467cbbbdaad63d7aa1c296fb8f33204d68f..cac3ab1ca72747fe6053db2417c7b83ae52b0a3d 100644 (file)
@@ -2296,13 +2296,12 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args)
 
        if (length == 0) {
                attr->ipv6_ecommunity = NULL;
-               /* Empty extcomm doesn't seem to be invalid per se */
-               return BGP_ATTR_PARSE_PROCEED;
+               return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
+                                         args->total);
        }
 
        attr->ipv6_ecommunity =
-               ecommunity_parse_ipv6((uint8_t *)stream_pnt(peer->curr),
-                                     length);
+               ecommunity_parse_ipv6(stream_pnt(peer->curr), length);
        /* XXX: fix ecommunity_parse to use stream API */
        stream_forward_getp(peer->curr, length);
 
index f45fa2bed5ab5185c7c86475befd600e5ff7eef2..ce67abd36410827e7317e0395eb19d2d914ef5f0 100644 (file)
@@ -792,6 +792,7 @@ static int ecommunity_rt_soo_str_internal(char *buf, size_t bufsz,
                        len = snprintf(buf, bufsz, "%s%u:%u", prefix, eas.as, eas.val);
                } else {
                        /* this is an IPv6 ext community
+                        * first 16 bytes stands for IPv6 addres
                         */
                        memcpy(&eip6.ip, pnt, 16);
                        pnt += 16;
index 4a1af0d203b943243ecfb27b9185419c58d8c23a..fe90efe1f7d1d749b48661ae23b8bfd36a28fe97 100644 (file)
@@ -94,7 +94,7 @@
 
 /* Extended Communities value is eight octet long.  */
 #define ECOMMUNITY_SIZE                        8
-#define IPV6_ECOMMUNITY_SIZE                   20
+#define IPV6_ECOMMUNITY_SIZE                  20
 
 /* Extended Communities type flag.  */
 #define ECOMMUNITY_FLAG_NON_TRANSITIVE      0x40
@@ -107,7 +107,7 @@ struct ecommunity {
        /* Size of Each Unit of Extended Communities attribute.
         * to differentiate between IPv6 ext comm and ext comm
         */
-       int unit_size;
+       uint8_t unit_size;
 
        /* Size of Extended Communities attribute.  */
        int size;
index cc6d1ed457324a50694550229d8c37e957712c0d..92bec6f88a32ea7e031aefd84411d8348556d91c 100644 (file)
@@ -263,7 +263,7 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
 {
        struct attr *attr;
        char return_string[BGP_FLOWSPEC_STRING_DISPLAY_MAX];
-       char *s = NULL, *s2 = NULL;
+       char *s1 = NULL, *s2 = NULL;
        json_object *json_nlri_path = NULL;
        json_object *json_ecom_path = NULL;
        json_object *json_time_path = NULL;
@@ -311,23 +311,23 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
                /* Print attribute */
                attr = path->attr;
                if (attr->ecommunity)
-                       s = ecommunity_ecom2str(attr->ecommunity,
+                       s1 = ecommunity_ecom2str(attr->ecommunity,
                                                ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
                if (attr->ipv6_ecommunity)
                        s2 = ecommunity_ecom2str(attr->ipv6_ecommunity,
                                                ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
-               if (!s && !s2)
+               if (!s1 && !s2)
                        return;
                if (display == NLRI_STRING_FORMAT_LARGE)
-                       vty_out(vty, "\t%s%s%s\n", s ? s : "",
-                               s2 && s ? " " : "", s2 ? s2 : "");
+                       vty_out(vty, "\t%s%s%s\n", s1 ? s1 : "",
+                               s2 && s1 ? " " : "", s2 ? s2 : "");
                else if (display == NLRI_STRING_FORMAT_MIN)
-                       vty_out(vty, "%s%s", s ? s : "", s2 ? s2 : "");
+                       vty_out(vty, "%s%s", s1 ? s1 : "", s2 ? s2 : "");
                else if (json_paths) {
                        json_ecom_path = json_object_new_object();
-                       if (s)
+                       if (s1)
                                json_object_string_add(json_ecom_path,
-                                                      "ecomlist", s);
+                                                      "ecomlist", s1);
                        if (s2)
                                json_object_string_add(json_ecom_path,
                                                       "ecom6list", s2);
@@ -357,7 +357,8 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
                                vty_out(vty, "\tNLRI NH %s\n",
                                        local_buff);
                }
-               XFREE(MTYPE_ECOMMUNITY_STR, s);
+               XFREE(MTYPE_ECOMMUNITY_STR, s1);
+               XFREE(MTYPE_ECOMMUNITY_STR, s2);
        }
        peer_uptime(path->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL);
        if (display == NLRI_STRING_FORMAT_LARGE) {
index 191c1a561ccf7711a104921d869010ec5fa8ed7d..1201b488fd8e5eb7a02cdd9e7edd4648bcc1ecd6 100644 (file)
@@ -7332,7 +7332,7 @@ DEFPY(
 }
 
 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
-                        struct ecommunity **list, int is_rt6)
+                        struct ecommunity **list, bool is_rt6)
 {
        struct ecommunity *ecom = NULL;
        struct ecommunity *ecomadd;
@@ -7425,10 +7425,10 @@ DEFPY (af_rd_vpn_export,
        int ret;
        afi_t afi;
        int idx = 0;
-       int yes = 1;
+       bool yes = true;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        if (yes) {
                ret = str2prefix_rd(rd_str, &prd);
@@ -7486,10 +7486,10 @@ DEFPY (af_label_vpn_export,
        mpls_label_t label = MPLS_LABEL_NONE;
        afi_t afi;
        int idx = 0;
-       int yes = 1;
+       bool yes = true;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        /* If "no ...", squash trailing parameter */
        if (!yes)
@@ -7581,7 +7581,6 @@ DEFPY (af_nexthop_vpn_export,
                        vty_out(vty, "%% Nexthop required\n");
                        return CMD_WARNING_CONFIG_FAILED;
                }
-
                if (!sockunion2hostprefix(nexthop_su, &p))
                        return CMD_WARNING_CONFIG_FAILED;
        }
@@ -7647,10 +7646,10 @@ DEFPY (af_rt_vpn_imexport,
        vpn_policy_direction_t dir;
        afi_t afi;
        int idx = 0;
-       int yes = 1;
+       bool yes = true;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        afi = vpn_policy_getafi(vty, bgp, false);
        if (afi == AFI_MAX)
@@ -7665,7 +7664,7 @@ DEFPY (af_rt_vpn_imexport,
                        vty_out(vty, "%% Missing RTLIST\n");
                        return CMD_WARNING_CONFIG_FAILED;
                }
-               ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, 0);
+               ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
                if (ret != CMD_SUCCESS) {
                        return ret;
                }
@@ -7727,10 +7726,10 @@ DEFPY (af_route_map_vpn_imexport,
        vpn_policy_direction_t dir;
        afi_t afi;
        int idx = 0;
-       int yes = 1;
+       bool yes = true;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        afi = vpn_policy_getafi(vty, bgp, false);
        if (afi == AFI_MAX)
@@ -7969,12 +7968,12 @@ DEFPY (bgp_imexport_vpn,
        afi_t afi;
        safi_t safi;
        int idx = 0;
-       int yes = 1;
+       bool yes = true;
        int flag;
        vpn_policy_direction_t dir;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
                BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
@@ -8037,15 +8036,15 @@ DEFPY (af_routetarget_import,
        struct ecommunity *ecom = NULL;
        afi_t afi;
        int idx = 0, idx_unused = 0;
-       int yes = 1;
-       int rt6 = 0;
+       bool yes = true;
+       bool rt6 = false;
 
        if (argv_find(argv, argc, "no", &idx))
-               yes = 0;
+               yes = false;
 
        if (argv_find(argv, argc, "rt6", &idx_unused) ||
            argv_find(argv, argc, "route-target6", &idx_unused))
-               rt6 = 1;
+               rt6 = true;
 
        afi = vpn_policy_getafi(vty, bgp, false);
        if (afi == AFI_MAX)
@@ -14594,7 +14593,7 @@ static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
 
                if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
                    != ECOMMUNITY_SIZE)
-                       vty_out(vty, "%*srt redirect import %s\n",
+                       vty_out(vty, "%*srt6 redirect import %s\n",
                                indent, "", b);
                else
                        vty_out(vty, "%*srt redirect import %s\n",
index 1bed0b48bbcc472526937689b2ad6986ce7ef4bd..95d241c59fbc2d09bdd346e8813f3b3f57ecfb4e 100644 (file)
@@ -1051,7 +1051,7 @@ static int zebra_pbr_show_ipset_walkcb(struct hash_bucket *bucket, void *arg)
 
        vty_out(vty, "IPset %s type %s family %s\n", zpi->ipset_name,
                zebra_pbr_ipset_type2str(zpi->type),
-               zpi->family == AF_INET ? "AF_INET" : "AF_INET6");
+               family2str(zpi->family));
        unique.vty = vty;
        unique.zpi = zpi;
        unique.zns = zns;
@@ -1098,7 +1098,7 @@ void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname)
                }
                vty_out(vty, "IPset %s type %s family %s\n", ipsetname,
                        zebra_pbr_ipset_type2str(zpi->type),
-                       zpi->family == AF_INET ? "AF_INET" : "AF_INET6");
+                       family2str(zpi->family));
                unique.vty = vty;
                unique.zpi = zpi;
                unique.zns = zns;