]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: do not allocate lists on fs entries of bgp entries.
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 8 Feb 2019 13:48:28 +0000 (14:48 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 28 Mar 2019 15:57:59 +0000 (16:57 +0100)
bgp entries in bgp_extra_path structure will be allocated as lists, only
when needed, that is to say when bgp fs entries will be received and
installed on the underlying system.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_flowspec_vty.c
bgpd/bgp_pbr.c
bgpd/bgp_route.c
bgpd/bgp_zebra.c

index 72ee8bb4cee14c8b9c72506128ab752db65c2f9d..2d6523ed31ed5eb86ab1cc54e98affc21ac3225a 100644 (file)
@@ -332,14 +332,12 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
        if (display == NLRI_STRING_FORMAT_LARGE) {
                struct bgp_path_info_extra *extra =
                        bgp_path_info_extra_get(path);
+               bool list_began = false;
 
-               if (listcount(extra->bgp_fs_pbr) ||
-                   listcount(extra->bgp_fs_iprule)) {
+               if (extra->bgp_fs_pbr && listcount(extra->bgp_fs_pbr)) {
                        struct listnode *node;
                        struct bgp_pbr_match_entry *bpme;
-                       struct bgp_pbr_rule *bpr;
                        struct bgp_pbr_match *bpm;
-                       bool list_began = false;
                        struct list *list_bpm;
 
                        list_bpm = list_new();
@@ -357,6 +355,14 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
                                        vty_out(vty, ", ");
                                vty_out(vty, "%s", bpm->ipset_name);
                        }
+                       list_delete(&list_bpm);
+               }
+               if (extra->bgp_fs_iprule && listcount(extra->bgp_fs_iprule)) {
+                       struct listnode *node;
+                       struct bgp_pbr_rule *bpr;
+
+                       if (!list_began)
+                               vty_out(vty, "\tinstalled in PBR");
                        for (ALL_LIST_ELEMENTS_RO(extra->bgp_fs_iprule,
                                                  node, bpr)) {
                                if (!bpr->action)
@@ -373,8 +379,8 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
                        if (list_began)
                                vty_out(vty, ")");
                        vty_out(vty, "\n");
-                       list_delete(&list_bpm);
-               } else
+               }
+               if (!list_began)
                        vty_out(vty, "\tnot installed in PBR\n");
        }
 }
index c0be36ed3f4ad3b9b7d8483bc275dc2ed1cfacbf..27208ec99737eb48a830be0fd6a63c4dada02bb5 100644 (file)
@@ -1421,7 +1421,8 @@ static void bgp_pbr_flush_iprule(struct bgp *bgp, struct bgp_pbr_action *bpa,
                        /* unlink path to bpme */
                        path = (struct bgp_path_info *)bpr->path;
                        extra = bgp_path_info_extra_get(path);
-                       listnode_delete(extra->bgp_fs_iprule, bpr);
+                       if (extra->bgp_fs_iprule)
+                               listnode_delete(extra->bgp_fs_iprule, bpr);
                        bpr->path = NULL;
                }
        }
@@ -1458,7 +1459,8 @@ static void bgp_pbr_flush_entry(struct bgp *bgp, struct bgp_pbr_action *bpa,
                        /* unlink path to bpme */
                        path = (struct bgp_path_info *)bpme->path;
                        extra = bgp_path_info_extra_get(path);
-                       listnode_delete(extra->bgp_fs_pbr, bpme);
+                       if (extra->bgp_fs_pbr)
+                               listnode_delete(extra->bgp_fs_pbr, bpme);
                        bpme->path = NULL;
                }
        }
@@ -2065,7 +2067,8 @@ static void bgp_pbr_policyroute_add_to_zebra_unit(struct bgp *bgp,
                        struct bgp_path_info_extra *extra =
                                bgp_path_info_extra_get(path);
 
-                       if (extra && listnode_lookup(extra->bgp_fs_iprule,
+                       if (extra && extra->bgp_fs_iprule &&
+                           listnode_lookup(extra->bgp_fs_iprule,
                                                     bpr)) {
                                if (BGP_DEBUG(pbr, PBR_ERROR))
                                        zlog_err("%s: entry %p/%p already "
@@ -2213,7 +2216,8 @@ static void bgp_pbr_policyroute_add_to_zebra_unit(struct bgp *bgp,
                struct bgp_path_info_extra *extra =
                        bgp_path_info_extra_get(path);
 
-               if (extra && listnode_lookup(extra->bgp_fs_pbr, bpme)) {
+               if (extra && extra->bgp_fs_pbr &&
+                   listnode_lookup(extra->bgp_fs_pbr, bpme)) {
                        if (BGP_DEBUG(pbr, PBR_ERROR))
                                zlog_err(
                                        "%s: entry %p/%p already installed in bgp pbr",
index eca632dd448cf1601fb46375646f9682b686326b..f172558f7cb73217204b6b9215edc9608e2c95f4 100644 (file)
@@ -175,8 +175,8 @@ static struct bgp_path_info_extra *bgp_path_info_extra_new(void)
                      sizeof(struct bgp_path_info_extra));
        new->label[0] = MPLS_INVALID_LABEL;
        new->num_labels = 0;
-       new->bgp_fs_pbr = list_new();
-       new->bgp_fs_iprule = list_new();
+       new->bgp_fs_pbr = NULL;
+       new->bgp_fs_iprule = NULL;
        return new;
 }
 
index d9749863ecedf22cf182b3f7594c14fc3c6542c9..5c32d313485e9e7c77225d66b1c57e7c1345d279 100644 (file)
@@ -2156,6 +2156,8 @@ static int rule_notify_owner(int command, struct zclient *zclient,
                        /* link bgp_info to bgp_pbr */
                        path = (struct bgp_path_info *)bgp_pbr->path;
                        extra = bgp_path_info_extra_get(path);
+                       if (!extra->bgp_fs_iprule)
+                               extra->bgp_fs_iprule = list_new();
                        listnode_add(extra->bgp_fs_iprule, bgp_pbr);
                }
                if (BGP_DEBUG(zebra, ZEBRA))
@@ -2264,6 +2266,8 @@ static int ipset_entry_notify_owner(int command, struct zclient *zclient,
                /* link bgp_path_info to bpme */
                path = (struct bgp_path_info *)bgp_pbime->path;
                extra = bgp_path_info_extra_get(path);
+               if (!extra->bgp_fs_pbr)
+                       extra->bgp_fs_pbr = list_new();
                listnode_add(extra->bgp_fs_pbr, bgp_pbime);
                }
                break;