]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: fix overload state location
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 25 Jan 2024 15:47:35 +0000 (16:47 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Sat, 27 Jan 2024 18:02:52 +0000 (19:02 +0100)
This belongs in `/var/lib`, not `/var/run`.  Also the filename was
typo'd (`isid-restart.json`).

Change to proper location and fall back to previous in case it's the
first restart after an FRR update from a version with the bugged path.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
configure.ac
isisd/isis_main.c
isisd/isisd.c

index dd143d0fb45e5c36a8e0694f388d733eb3c2d486..b6438889adf35f0644fcfcbfc8d18620001ed0db 100644 (file)
@@ -2743,7 +2743,6 @@ AC_DEFINE_UNQUOTED([WATCHFRR_SH_PATH], ["${CFG_SBIN%/}/watchfrr.sh"], [path to w
 
 AC_DEFINE_UNQUOTED([OSPFD_GR_STATE], ["$CFG_STATE%s/ospfd-gr.json"], [ospfd GR state information])
 AC_DEFINE_UNQUOTED([OSPF6D_GR_STATE], ["$CFG_STATE/ospf6d-gr.json"], [ospf6d GR state information])
-AC_DEFINE_UNQUOTED([ISISD_RESTART], ["$CFG_STATE%s/isid-restart.json"], [isisd restart information])
 AC_DEFINE_UNQUOTED([OSPF6_AUTH_SEQ_NUM_FILE], ["$CFG_STATE/ospf6d-at-seq-no.dat"], [ospf6d AT Sequence number information])
 AC_DEFINE_UNQUOTED([DAEMON_DB_DIR], ["$CFG_STATE"], [daemon database directory])
 
index b9f80991232b751bf34fcd1ae806cd54235b56a2..47e5f6dc933abbcb763d7973c877ef6e26ab0c28 100644 (file)
 #define ISISD_VTY_PORT       2608
 #define FABRICD_VTY_PORT     2618
 
+#define FABRICD_STATE_NAME "%s/fabricd.json", frr_libstatedir
+#define ISISD_STATE_NAME   "%s/isisd.json", frr_libstatedir
+
+/* The typo was there before.  Do not fix it!  The point is to load mis-saved
+ * state files from older versions.
+ *
+ * Also fabricd was using the same file.  Sigh.
+ */
+#define ISISD_COMPAT_STATE_NAME "%s/isid-restart.json", frr_runstatedir
+
 /* isisd privileges */
 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
 
@@ -212,6 +222,15 @@ static void isis_config_end(void)
        isis_config_finish(t_isis_cfg);
 }
 
+/* actual paths filled in main() */
+static char state_path[512];
+static char state_compat_path[512];
+static char *state_paths[] = {
+       state_path,
+       state_compat_path,
+       NULL,
+};
+
 /* clang-format off */
 FRR_DAEMON_INFO(
 #ifdef FABRICD
@@ -234,6 +253,8 @@ FRR_DAEMON_INFO(
 
        .yang_modules = isisd_yang_modules,
        .n_yang_modules = array_size(isisd_yang_modules),
+
+       .state_paths = state_paths,
 );
 /* clang-format on */
 
@@ -275,6 +296,14 @@ int main(int argc, char **argv, char **envp)
                }
        }
 
+#ifdef FABRICD
+       snprintf(state_path, sizeof(state_path), FABRICD_STATE_NAME);
+#else
+       snprintf(state_path, sizeof(state_path), ISISD_STATE_NAME);
+#endif
+       snprintf(state_compat_path, sizeof(state_compat_path),
+                ISISD_COMPAT_STATE_NAME);
+
        /* thread master */
        isis_master_init(frr_init());
        master = im->master;
index b1064d894199da056c6b44e82131d42b5280a44d..772eb9708dfc450fc2c9fbe279b9d0f20a1136f4 100644 (file)
@@ -3345,36 +3345,20 @@ void isis_area_advertise_high_metrics_set(struct isis_area *area,
        }
 }
 
-/*
- * Returns the path of the file (non-volatile memory) that contains restart
- * information.
- */
-char *isis_restart_filepath(void)
-{
-       static char filepath[MAXPATHLEN];
-       snprintf(filepath, sizeof(filepath), ISISD_RESTART, "");
-       return filepath;
-}
-
 /*
  * Record in non-volatile memory the overload on startup time.
  */
 void isis_restart_write_overload_time(struct isis_area *isis_area,
                                      uint32_t overload_time)
 {
-       char *filepath;
        const char *area_name;
        json_object *json;
        json_object *json_areas;
        json_object *json_area;
 
-       filepath = isis_restart_filepath();
+       json = frr_daemon_state_load();
        area_name = isis_area->area_tag;
 
-       json = json_object_from_file(filepath);
-       if (json == NULL)
-               json = json_object_new_object();
-
        json_object_object_get_ex(json, "areas", &json_areas);
        if (!json_areas) {
                json_areas = json_object_new_object();
@@ -3389,8 +3373,8 @@ void isis_restart_write_overload_time(struct isis_area *isis_area,
 
        json_object_int_add(json_area, "overload_time",
                            isis_area->overload_on_startup_time);
-       json_object_to_file_ext(filepath, json, JSON_C_TO_STRING_PRETTY);
-       json_object_free(json);
+
+       frr_daemon_state_save(&json);
 }
 
 /*
@@ -3398,7 +3382,6 @@ void isis_restart_write_overload_time(struct isis_area *isis_area,
  */
 uint32_t isis_restart_read_overload_time(struct isis_area *isis_area)
 {
-       char *filepath;
        const char *area_name;
        json_object *json;
        json_object *json_areas;
@@ -3406,12 +3389,9 @@ uint32_t isis_restart_read_overload_time(struct isis_area *isis_area)
        json_object *json_overload_time;
        uint32_t overload_time = 0;
 
-       filepath = isis_restart_filepath();
        area_name = isis_area->area_tag;
 
-       json = json_object_from_file(filepath);
-       if (json == NULL)
-               json = json_object_new_object();
+       json = frr_daemon_state_load();
 
        json_object_object_get_ex(json, "areas", &json_areas);
        if (!json_areas) {
@@ -3433,8 +3413,7 @@ uint32_t isis_restart_read_overload_time(struct isis_area *isis_area)
 
        json_object_object_del(json_areas, area_name);
 
-       json_object_to_file_ext(filepath, json, JSON_C_TO_STRING_PRETTY);
-       json_object_free(json);
+       frr_daemon_state_save(&json);
 
        return overload_time;
 }