]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_routemap_nb_config.c
Revert "bgpd: Free only subattributes, not the whole attr_extra pointer"
[mirror_frr.git] / bgpd / bgp_routemap_nb_config.c
index 398e7323db8b4f9598f66dc0ad5aa13216bffebd..773538ee41dd354291e6b4bbba95004f2afa3387 100644 (file)
@@ -25,7 +25,6 @@
 #include "lib/routemap.h"
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_routemap_nb.h"
-#include "bgpd/bgp_ecommunity.h"
 
 /* Add bgp route map rule. */
 static int bgp_route_match_add(struct route_map_index *index,
@@ -1036,6 +1035,7 @@ lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish(
        char *argstr;
        const char *condition;
        route_map_event_t event;
+       int ret;
 
        /* Add configuration. */
        rhc = nb_running_get_entry(args->dnode, NULL, true);
@@ -1073,8 +1073,14 @@ lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish(
                rhc->rhc_event = RMAP_EVENT_ECLIST_DELETED;
        }
 
-       bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, event,
-                           args->errmsg, args->errmsg_len);
+       ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, event,
+                                 args->errmsg, args->errmsg_len);
+       /*
+        * At this point if this is not a successful operation
+        * bgpd is about to crash.  Let's just cut to the
+        * chase and do it.
+        */
+       assert(ret == RMAP_COMPILE_SUCCESS);
 
        if (argstr != value)
                XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
@@ -1228,7 +1234,7 @@ lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_modify(
 
                /* Set destroy information. */
                rhc->rhc_mhook = bgp_route_match_delete;
-               rhc->rhc_rule = "ipv6 next-hop";
+               rhc->rhc_rule = "ipv6 next-hop address";
                rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
 
                ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule,
@@ -2441,6 +2447,7 @@ void lib_route_map_entry_set_action_rmap_set_action_aggregator_finish(
        const char *asn;
        const char *addr;
        char *argstr;
+       int ret;
 
        /* Add configuration. */
        rhc = nb_running_get_entry(args->dnode, NULL, true);
@@ -2457,8 +2464,15 @@ void lib_route_map_entry_set_action_rmap_set_action_aggregator_finish(
        rhc->rhc_rule = "aggregator as";
        rhc->rhc_event = RMAP_EVENT_SET_DELETED;
 
-       generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, argstr,
-                       args->errmsg, args->errmsg_len);
+       ret = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, args->errmsg,
+                             args->errmsg_len);
+       /*
+        * At this point if this is not a successful operation
+        * bgpd is about to crash.  Let's just cut to the
+        * chase and do it.
+        */
+       assert(ret == CMD_SUCCESS);
+
        XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
 }
 /*
@@ -2605,6 +2619,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish(
        enum ecommunity_lb_type lb_type;
        char str[VTY_BUFSIZ];
        uint16_t bandwidth;
+       int ret;
 
        /* Add configuration. */
        rhc = nb_running_get_entry(args->dnode, NULL, true);
@@ -2630,9 +2645,14 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish(
        if (yang_dnode_get_bool(args->dnode, "./two-octet-as-specific"))
                strlcat(str, " non-transitive", sizeof(str));
 
-       generic_set_add(rhc->rhc_rmi,
-                       "extcommunity bandwidth", str,
-                       args->errmsg, args->errmsg_len);
+       ret = generic_set_add(rhc->rhc_rmi, "extcommunity bandwidth", str,
+                             args->errmsg, args->errmsg_len);
+       /*
+        * At this point if this is not a successful operation
+        * bgpd is about to crash.  Let's just cut to the
+        * chase and do it.
+        */
+       assert(ret == CMD_SUCCESS);
 }
 
 /*
@@ -2689,6 +2709,64 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_two_octet_as_spec
        return lib_route_map_entry_set_destroy(args);
 }
 
+/*
+ * XPath:
+ * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-none
+ */
+int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct routemap_hook_context *rhc;
+       bool none = false;
+       int rv;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               /* Add configuration. */
+               rhc = nb_running_get_entry(args->dnode, NULL, true);
+               none = yang_dnode_get_bool(args->dnode, NULL);
+
+               /* Set destroy information. */
+               rhc->rhc_shook = generic_set_delete;
+               rhc->rhc_rule = "extcommunity";
+               rhc->rhc_event = RMAP_EVENT_SET_DELETED;
+
+               if (none) {
+                       rv = generic_set_add(rhc->rhc_rmi, "extcommunity",
+                                            "none", args->errmsg,
+                                            args->errmsg_len);
+                       if (rv != CMD_SUCCESS) {
+                               rhc->rhc_shook = NULL;
+                               return NB_ERR_INCONSISTENCY;
+                       }
+                       return NB_OK;
+               }
+
+               return NB_ERR_INCONSISTENCY;
+       }
+
+       return NB_OK;
+}
+
+int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               return lib_route_map_entry_set_destroy(args);
+       }
+
+       return NB_OK;
+}
+
 /*
  * XPath:
  * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4