]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_netns_notify.c
zebra: Refactor kernel_rtm to be a bit smarter about how it handles options
[mirror_frr.git] / zebra / zebra_netns_notify.c
index be36dc96bce285f7224d38b5afb8489925d0d492..a4e10221482012a9204287860f7c3a92a525c57d 100644 (file)
@@ -92,7 +92,7 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name)
                return;
        }
        if (vrf_handler_create(NULL, name, &vrf) != CMD_SUCCESS) {
-               flog_warn(ZEBRA_ERR_NS_VRF_CREATION_FAILED,
+               flog_warn(EC_ZEBRA_NS_VRF_CREATION_FAILED,
                          "NS notify : failed to create VRF %s", name);
                ns_map_nsid_with_external(ns_id, false);
                return;
@@ -102,7 +102,7 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name)
                                               ns_id_external, ns_id);
        }
        if (ret != CMD_SUCCESS) {
-               flog_warn(ZEBRA_ERR_NS_VRF_CREATION_FAILED,
+               flog_warn(EC_ZEBRA_NS_VRF_CREATION_FAILED,
                          "NS notify : failed to create NS %s", netnspath);
                ns_map_nsid_with_external(ns_id, false);
                vrf_delete(vrf);
@@ -133,7 +133,7 @@ static int zebra_ns_delete(char *name)
        struct ns *ns;
 
        if (!vrf) {
-               flog_warn(ZEBRA_ERR_NS_DELETION_FAILED_NO_VRF,
+               flog_warn(EC_ZEBRA_NS_DELETION_FAILED_NO_VRF,
                          "NS notify : no VRF found using NS %s", name);
                return 0;
        }
@@ -219,7 +219,7 @@ static int zebra_ns_ready_read(struct thread *t)
                zlog_warn(
                          "NS notify : NS %s is default VRF."
                          " Updating VRF Name", basename(netnspath));
-               vrf_set_default_name(basename(netnspath));
+               vrf_set_default_name(basename(netnspath), false);
                return zebra_ns_continue_read(zns_info, 1);
        }
 
@@ -239,7 +239,7 @@ static int zebra_ns_notify_read(struct thread *t)
                zebrad.master, zebra_ns_notify_read, NULL, fd_monitor, NULL);
        len = read(fd_monitor, buf, sizeof(buf));
        if (len < 0) {
-               flog_err_sys(ZEBRA_ERR_NS_NOTIFY_READ,
+               flog_err_sys(EC_ZEBRA_NS_NOTIFY_READ,
                             "NS notify read: failed to read (%s)",
                             safe_strerror(errno));
                return 0;
@@ -252,22 +252,23 @@ static int zebra_ns_notify_read(struct thread *t)
 
                if (!(event->mask & (IN_CREATE | IN_DELETE)))
                        continue;
-               if (event->mask & IN_DELETE)
-                       return zebra_ns_delete(event->name);
 
                if (offsetof(struct inotify_event, name) + event->len
                    >= sizeof(buf)) {
-                       flog_err(ZEBRA_ERR_NS_NOTIFY_READ,
+                       flog_err(EC_ZEBRA_NS_NOTIFY_READ,
                                 "NS notify read: buffer underflow");
                        break;
                }
 
                if (strnlen(event->name, event->len) == event->len) {
-                       flog_err(ZEBRA_ERR_NS_NOTIFY_READ,
+                       flog_err(EC_ZEBRA_NS_NOTIFY_READ,
                                 "NS notify error: bad event name");
                        break;
                }
 
+               if (event->mask & IN_DELETE)
+                       return zebra_ns_delete(event->name);
+
                netnspath = ns_netns_pathname(NULL, event->name);
                if (!netnspath)
                        continue;
@@ -288,7 +289,7 @@ void zebra_ns_notify_parse(void)
        DIR *srcdir = opendir(NS_RUN_DIR);
 
        if (srcdir == NULL) {
-               flog_err_sys(LIB_ERR_SYSTEM_CALL,
+               flog_err_sys(EC_LIB_SYSTEM_CALL,
                             "NS parsing init: failed to parse %s", NS_RUN_DIR);
                return;
        }
@@ -300,7 +301,7 @@ void zebra_ns_notify_parse(void)
                        continue;
                if (fstatat(dirfd(srcdir), dent->d_name, &st, 0) < 0) {
                        flog_err_sys(
-                               LIB_ERR_SYSTEM_CALL,
+                               EC_LIB_SYSTEM_CALL,
                                "NS parsing init: failed to parse entry %s",
                                dent->d_name);
                        continue;
@@ -314,7 +315,7 @@ void zebra_ns_notify_parse(void)
                        zlog_warn(
                                  "NS notify : NS %s is default VRF."
                                  " Updating VRF Name", dent->d_name);
-                       vrf_set_default_name(dent->d_name);
+                       vrf_set_default_name(dent->d_name, false);
                        continue;
                }
                zebra_ns_notify_create_context_from_entry_name(dent->d_name);
@@ -330,13 +331,13 @@ void zebra_ns_notify_init(void)
        fd_monitor = inotify_init();
        if (fd_monitor < 0) {
                flog_err_sys(
-                       LIB_ERR_SYSTEM_CALL,
+                       EC_LIB_SYSTEM_CALL,
                        "NS notify init: failed to initialize inotify (%s)",
                        safe_strerror(errno));
        }
        if (inotify_add_watch(fd_monitor, NS_RUN_DIR,
                              IN_CREATE | IN_DELETE) < 0) {
-               flog_err_sys(LIB_ERR_SYSTEM_CALL,
+               flog_err_sys(EC_LIB_SYSTEM_CALL,
                             "NS notify watch: failed to add watch (%s)",
                             safe_strerror(errno));
        }
@@ -353,8 +354,11 @@ void zebra_ns_notify_close(void)
 
        if (zebra_netns_notify_current->u.fd > 0)
                fd = zebra_netns_notify_current->u.fd;
-       thread_cancel(zebra_netns_notify_current);
-       /* auto-removal of inotify items */
+
+       if (zebra_netns_notify_current->master != NULL)
+               thread_cancel(zebra_netns_notify_current);
+
+       /* auto-removal of notify items */
        if (fd > 0)
                close(fd);
 }