]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_mlag_private.c
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / zebra / zebra_mlag_private.c
index a5637c67aef0f5ea1c107ae78dd580365282ac70..3024407ada0b2ea23dbbc5f1e61153904d46cad1 100644 (file)
@@ -1,29 +1,32 @@
-/* Zebra Mlag Code.
- * Copyright (C) 2018 Cumulus Networks, Inc.
- *                    Donald Sharp
+/*
+ * This is an implementation of MLAG Functionality
+ *
+ * Module name: Zebra MLAG
+ *
+ * Author: sathesh Kumar karra <sathk@cumulusnetworks.com>
  *
- * This file is part of FRR.
+ * Copyright (C) 2019 Cumulus Networks http://www.cumulusnetworks.com
  *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
  *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with FRR; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "zebra.h"
 
 #include "hook.h"
 #include "module.h"
 #include "thread.h"
+#include "frr_pthread.h"
 #include "libfrr.h"
 #include "version.h"
 #include "network.h"
@@ -33,7 +36,6 @@
 #include "zebra/debug.h"
 #include "zebra/zebra_router.h"
 #include "zebra/zebra_mlag.h"
-#include "zebra/zebra_mlag_private.h"
 
 #include <sys/un.h>
 
@@ -43,8 +45,6 @@
  *
  */
 
-#ifdef HAVE_CUMULUS
-
 static struct thread_master *zmlag_master;
 static int mlag_socket;
 
@@ -52,9 +52,9 @@ static int zebra_mlag_connect(struct thread *thread);
 static int zebra_mlag_read(struct thread *thread);
 
 /*
- * Write teh data to MLAGD
+ * Write the data to MLAGD
  */
-int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
+static int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
 {
        int rc = 0;
 
@@ -78,8 +78,6 @@ static int zebra_mlag_read(struct thread *thread)
        uint32_t h_msglen;
        uint32_t tot_len, curr_len = mlag_rd_buf_offset;
 
-       zrouter.mlag_info.t_read = NULL;
-
        /*
         * Received message in sock_stream looks like below
         * | len-1 (4 Bytes) | payload-1 (len-1) |
@@ -101,7 +99,8 @@ static int zebra_mlag_read(struct thread *thread)
                        zebra_mlag_handle_process_state(MLAG_DOWN);
                        return -1;
                }
-               if (data_len != (ssize_t)ZEBRA_MLAG_LEN_SIZE - curr_len) {
+               mlag_rd_buf_offset += data_len;
+               if (data_len != (ssize_t)(ZEBRA_MLAG_LEN_SIZE - curr_len)) {
                        /* Try again later */
                        zebra_mlag_sched_read();
                        return 0;
@@ -129,7 +128,8 @@ static int zebra_mlag_read(struct thread *thread)
                        zebra_mlag_handle_process_state(MLAG_DOWN);
                        return -1;
                }
-               if (data_len != (ssize_t)tot_len - curr_len) {
+               mlag_rd_buf_offset += data_len;
+               if (data_len != (ssize_t)(tot_len - curr_len)) {
                        /* Try again later */
                        zebra_mlag_sched_read();
                        return 0;
@@ -156,15 +156,13 @@ static int zebra_mlag_read(struct thread *thread)
 
 static int zebra_mlag_connect(struct thread *thread)
 {
-       struct sockaddr_un svr;
+       struct sockaddr_un svr = {0};
        struct ucred ucred;
        socklen_t len = 0;
 
        /* Reset the Timer-running flag */
        zrouter.mlag_info.timer_running = false;
 
-       zrouter.mlag_info.t_read = NULL;
-       memset(&svr, 0, sizeof(svr));
        svr.sun_family = AF_UNIX;
 #define MLAG_SOCK_NAME "/var/run/clag-zebra.socket"
        strlcpy(svr.sun_path, MLAG_SOCK_NAME, sizeof(MLAG_SOCK_NAME) + 1);
@@ -206,13 +204,14 @@ static int zebra_mlag_connect(struct thread *thread)
 /*
  * Currently we are doing polling later we will look for better options
  */
-void zebra_mlag_private_monitor_state(void)
+static int zebra_mlag_private_monitor_state(void)
 {
        thread_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
                         &zrouter.mlag_info.t_read);
+       return 0;
 }
 
-int zebra_mlag_private_open_channel(void)
+static int zebra_mlag_private_open_channel(void)
 {
        zmlag_master = zrouter.mlag_info.th_master;
 
@@ -241,7 +240,7 @@ int zebra_mlag_private_open_channel(void)
        return 0;
 }
 
-int zebra_mlag_private_close_channel(void)
+static int zebra_mlag_private_close_channel(void)
 {
        if (zmlag_master == NULL)
                return -1;
@@ -262,37 +261,34 @@ int zebra_mlag_private_close_channel(void)
        return 0;
 }
 
-void zebra_mlag_private_cleanup_data(void)
+static int zebra_mlag_private_cleanup_data(void)
 {
        zmlag_master = NULL;
        zrouter.mlag_info.connected = false;
        zrouter.mlag_info.timer_running = false;
 
        close(mlag_socket);
-}
-
-#else  /*HAVE_CUMULUS */
-
-int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
-{
        return 0;
 }
 
-void zebra_mlag_private_monitor_state(void)
-{
-}
-
-int zebra_mlag_private_open_channel(void)
+static int zebra_mlag_module_init(void)
 {
+       hook_register(zebra_mlag_private_write_data,
+                     zebra_mlag_private_write_data);
+       hook_register(zebra_mlag_private_monitor_state,
+                     zebra_mlag_private_monitor_state);
+       hook_register(zebra_mlag_private_open_channel,
+                     zebra_mlag_private_open_channel);
+       hook_register(zebra_mlag_private_close_channel,
+                     zebra_mlag_private_close_channel);
+       hook_register(zebra_mlag_private_cleanup_data,
+                     zebra_mlag_private_cleanup_data);
        return 0;
 }
 
-int zebra_mlag_private_close_channel(void)
-{
-       return 0;
-}
-
-void zebra_mlag_private_cleanup_data(void)
-{
-}
-#endif /*HAVE_CUMULUS*/
+FRR_MODULE_SETUP(
+       .name = "zebra_cumulus_mlag",
+       .version = FRR_VERSION,
+       .description = "zebra Cumulus MLAG interface",
+       .init = zebra_mlag_module_init,
+)