]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/babel_main.c
Merge pull request #4027 from pguibert6WIND/fix_interface_rtadv
[mirror_frr.git] / babeld / babel_main.c
index 6a8f9bb75f59f110e1362dde592d18614fa2ad9a..eaff97a49565a59644eeaee58f5141f10a944e0c 100644 (file)
@@ -33,6 +33,7 @@ THE SOFTWARE.
 #include "vty.h"
 #include "memory.h"
 #include "libfrr.h"
+#include "lib_errors.h"
 
 #include "babel_main.h"
 #include "babeld.h"
@@ -45,6 +46,7 @@ THE SOFTWARE.
 #include "message.h"
 #include "resend.h"
 #include "babel_zebra.h"
+#include "babel_errors.h"
 
 static void babel_fail(void);
 static void babel_init_random(void);
@@ -73,7 +75,6 @@ int protocol_port;                /* babel's port */
 int protocol_socket = -1;         /* socket: communicate with others babeld */
 
 static char babel_config_default[] = SYSCONFDIR BABEL_DEFAULT_CONFIG;
-static char *babel_config_file = NULL;
 static char *babel_vty_addr = NULL;
 static int babel_vty_port = BABEL_VTY_PORT;
 
@@ -84,7 +85,7 @@ static zebra_capabilities_t _caps_p [] =
     ZCAP_BIND
 };
 
-static struct zebra_privs_t babeld_privs =
+struct zebra_privs_t babeld_privs =
 {
 #if defined(FRR_USER)
     .user = FRR_USER,
@@ -135,6 +136,11 @@ struct option longopts[] =
     { 0 }
   };
 
+static const struct frr_yang_module_info *babeld_yang_modules[] =
+  {
+    &frr_interface_info,
+  };
+
 FRR_DAEMON_INFO(babeld, BABELD,
                .vty_port = BABEL_VTY_PORT,
                .proghelp = "Implementation of the BABEL routing protocol.",
@@ -143,6 +149,9 @@ FRR_DAEMON_INFO(babeld, BABELD,
                .n_signals = array_size(babel_signals),
 
                .privs = &babeld_privs,
+
+               .yang_modules = babeld_yang_modules,
+               .n_yang_modules = array_size(babeld_yang_modules),
                )
 
 int
@@ -152,7 +161,7 @@ main(int argc, char **argv)
 
     frr_preinit (&babeld_di, argc, argv);
     frr_opt_add ("", longopts, "");
-  
+
     babel_init_random();
 
     /* set the Babel's default link-local multicast address and Babel's port */
@@ -182,9 +191,7 @@ main(int argc, char **argv)
     master = frr_init ();
 
     /* Library inits. */
-    zprivs_init (&babeld_privs);
-    cmd_init (1);
-    vty_init (master);
+    babel_error_init();
 
     resend_delay = BABEL_DEFAULT_RESEND_DELAY;
     change_smoothing_half_life(BABEL_DEFAULT_SMOOTHING_HALF_LIFE);
@@ -197,9 +204,6 @@ main(int argc, char **argv)
     /* this replace kernel_setup && kernel_setup_socket */
     babelz_zebra_init ();
 
-    /* Get zebra configuration file. */
-    vty_read_config (babel_config_file, babel_config_default);
-
     /* init buffer */
     rc = resize_receive_buffer(1500);
     if(rc < 0)
@@ -229,7 +233,8 @@ babel_init_random(void)
 
     rc = read_random_bytes(&seed, sizeof(seed));
     if(rc < 0) {
-        zlog_err("read(random): %s", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "read(random): %s",
+                 safe_strerror(errno));
         seed = 42;
     }
 
@@ -249,13 +254,14 @@ babel_replace_by_null(int fd)
 
     fd_null = open("/dev/null", O_RDONLY);
     if(fd_null < 0) {
-        zlog_err("open(null): %s", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "open(null): %s", safe_strerror(errno));
         exit(1);
     }
 
     rc = dup2(fd_null, fd);
     if(rc < 0) {
-        zlog_err("dup2(null, 0): %s", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "dup2(null, 0): %s",
+                 safe_strerror(errno));
         exit(1);
     }
 
@@ -274,13 +280,14 @@ babel_load_state_file(void)
 
     fd = open(state_file, O_RDONLY);
     if(fd < 0 && errno != ENOENT)
-        zlog_err("open(babel-state: %s)", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "open(babel-state: %s)",
+                 safe_strerror(errno));
     rc = unlink(state_file);
     if(fd >= 0 && rc < 0) {
-        zlog_err("unlink(babel-state): %s", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "unlink(babel-state): %s",
+                 safe_strerror(errno));
         /* If we couldn't unlink it, it's probably stale. */
-        close(fd);
-        fd = -1;
+        goto fini;
     }
     if(fd >= 0) {
         char buf[100];
@@ -289,7 +296,8 @@ babel_load_state_file(void)
         long t;
         rc = read(fd, buf, 99);
         if(rc < 0) {
-            zlog_err("read(babel-state): %s", safe_strerror(errno));
+            flog_err_sys(EC_LIB_SYSTEM_CALL, "read(babel-state): %s",
+                     safe_strerror(errno));
         } else {
             buf[rc] = '\0';
             rc = sscanf(buf, "%99s %d %ld\n", buf2, &s, &t);
@@ -297,7 +305,7 @@ babel_load_state_file(void)
                 unsigned char sid[8];
                 rc = parse_eui64(buf2, sid);
                 if(rc < 0) {
-                    zlog_err("Couldn't parse babel-state.");
+                    flog_err(EC_BABEL_CONFIG, "Couldn't parse babel-state.");
                 } else {
                     struct timeval realnow;
                     debugf(BABEL_DEBUG_COMMON,
@@ -307,17 +315,21 @@ babel_load_state_file(void)
                     if(memcmp(sid, myid, 8) == 0)
                         myseqno = seqno_plus(s, 1);
                     else
-                        zlog_err("ID mismatch in babel-state. id=%s; old=%s",
+                        flog_err(EC_BABEL_CONFIG,
+                                "ID mismatch in babel-state. id=%s; old=%s",
                                  format_eui64(myid),
                                  format_eui64(sid));
                 }
             } else {
-                zlog_err("Couldn't parse babel-state.");
+                flog_err(EC_BABEL_CONFIG, "Couldn't parse babel-state.");
             }
         }
-        close(fd);
-        fd = -1;
+        goto fini;
     }
+fini:
+    if (fd >= 0)
+        close(fd);
+    return ;
 }
 
 static void
@@ -349,7 +361,8 @@ babel_save_state_file(void)
     debugf(BABEL_DEBUG_COMMON, "Save state file.");
     fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
     if(fd < 0) {
-        zlog_err("creat(babel-state): %s", safe_strerror(errno));
+        flog_err_sys(EC_LIB_SYSTEM_CALL, "creat(babel-state): %s",
+                 safe_strerror(errno));
         unlink(state_file);
     } else {
         struct timeval realnow;
@@ -359,12 +372,13 @@ babel_save_state_file(void)
                       format_eui64(myid), (int)myseqno,
                       (long)realnow.tv_sec);
         if(rc < 0 || rc >= 100) {
-            zlog_err("write(babel-state): overflow.");
+            flog_err(EC_BABEL_CONFIG, "write(babel-state): overflow.");
             unlink(state_file);
         } else {
             rc = write(fd, buf, rc);
             if(rc < 0) {
-                zlog_err("write(babel-state): %s", safe_strerror(errno));
+                flog_err(EC_BABEL_CONFIG, "write(babel-state): %s",
+                         safe_strerror(errno));
                 unlink(state_file);
             }
             fsync(fd);
@@ -379,7 +393,7 @@ show_babel_main_configuration (struct vty *vty)
     vty_out (vty,
             "state file              = %s\n"
             "configuration file      = %s\n"
-            "protocol informations:\n"
+            "protocol information:\n"
             "  multicast address     = %s\n"
             "  port                  = %d\n"
             "vty address             = %s\n"
@@ -387,7 +401,7 @@ show_babel_main_configuration (struct vty *vty)
             "id                      = %s\n"
             "kernel_metric           = %d\n",
             state_file,
-            babel_config_file ? babel_config_file : babel_config_default,
+            babeld_di.config_file ? babeld_di.config_file : babel_config_default,
             format_address(protocol_group),
             protocol_port,
             babel_vty_addr ? babel_vty_addr : "None",