]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_ptm.c
Merge pull request #13450 from patrasar/mld_core
[mirror_frr.git] / zebra / zebra_ptm.c
index fda5ef02cf1fb244e0afa653ad00ce8c6e879df1..a678e71734716bec5488ffed97636e3508bd9740 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* Kernel routing table updates using netlink over GNU/Linux system.
  * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra 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.
- *
- * GNU Zebra 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 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>
@@ -100,7 +85,7 @@ static ptm_lib_handle_t *ptm_hdl;
 struct zebra_ptm_cb ptm_cb;
 
 static int zebra_ptm_socket_init(void);
-void zebra_ptm_sock_read(struct thread *thread);
+void zebra_ptm_sock_read(struct event *thread);
 static void zebra_ptm_install_commands(void);
 static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt);
 void zebra_bfd_peer_replay_req(void);
@@ -157,9 +142,9 @@ void zebra_ptm_finish(void)
                free(ptm_cb.in_data);
 
        /* Cancel events. */
-       thread_cancel(&ptm_cb.t_read);
-       thread_cancel(&ptm_cb.t_write);
-       thread_cancel(&ptm_cb.t_timer);
+       EVENT_OFF(ptm_cb.t_read);
+       EVENT_OFF(ptm_cb.t_write);
+       EVENT_OFF(ptm_cb.t_timer);
 
        if (ptm_cb.wb)
                buffer_free(ptm_cb.wb);
@@ -168,7 +153,7 @@ void zebra_ptm_finish(void)
                close(ptm_cb.ptm_sock);
 }
 
-static void zebra_ptm_flush_messages(struct thread *thread)
+static void zebra_ptm_flush_messages(struct event *thread)
 {
        ptm_cb.t_write = NULL;
 
@@ -185,13 +170,13 @@ static void zebra_ptm_flush_messages(struct thread *thread)
                ptm_cb.ptm_sock = -1;
                zebra_ptm_reset_status(0);
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return;
        case BUFFER_PENDING:
                ptm_cb.t_write = NULL;
-               thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
-                                ptm_cb.ptm_sock, &ptm_cb.t_write);
+               event_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
+                               ptm_cb.ptm_sock, &ptm_cb.t_write);
                break;
        case BUFFER_EMPTY:
                break;
@@ -209,22 +194,22 @@ static int zebra_ptm_send_message(char *data, int size)
                ptm_cb.ptm_sock = -1;
                zebra_ptm_reset_status(0);
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return -1;
        case BUFFER_EMPTY:
-               thread_cancel(&ptm_cb.t_write);
+               EVENT_OFF(ptm_cb.t_write);
                break;
        case BUFFER_PENDING:
-               thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
-                                ptm_cb.ptm_sock, &ptm_cb.t_write);
+               event_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
+                               ptm_cb.ptm_sock, &ptm_cb.t_write);
                break;
        }
 
        return 0;
 }
 
-void zebra_ptm_connect(struct thread *t)
+void zebra_ptm_connect(struct event *t)
 {
        int init = 0;
 
@@ -236,8 +221,8 @@ void zebra_ptm_connect(struct thread *t)
        if (ptm_cb.ptm_sock != -1) {
                if (init) {
                        ptm_cb.t_read = NULL;
-                       thread_add_read(zrouter.master, zebra_ptm_sock_read,
-                                       NULL, ptm_cb.ptm_sock, &ptm_cb.t_read);
+                       event_add_read(zrouter.master, zebra_ptm_sock_read,
+                                      NULL, ptm_cb.ptm_sock, &ptm_cb.t_read);
                        zebra_bfd_peer_replay_req();
                }
                zebra_ptm_send_status_req();
@@ -248,8 +233,8 @@ void zebra_ptm_connect(struct thread *t)
                        ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_MAX;
 
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
        } else if (ptm_cb.reconnect_time >= ZEBRA_PTM_RECONNECT_TIME_MAX) {
                ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL;
        }
@@ -645,13 +630,13 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt)
        }
 }
 
-void zebra_ptm_sock_read(struct thread *thread)
+void zebra_ptm_sock_read(struct event *thread)
 {
        int sock;
        int rc;
 
        errno = 0;
-       sock = THREAD_FD(thread);
+       sock = EVENT_FD(thread);
 
        if (sock == -1)
                return;
@@ -672,15 +657,14 @@ void zebra_ptm_sock_read(struct thread *thread)
                ptm_cb.ptm_sock = -1;
                zebra_ptm_reset_status(0);
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time,
-                                &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return;
        }
 
        ptm_cb.t_read = NULL;
-       thread_add_read(zrouter.master, zebra_ptm_sock_read, NULL,
-                       ptm_cb.ptm_sock, &ptm_cb.t_read);
+       event_add_read(zrouter.master, zebra_ptm_sock_read, NULL,
+                      ptm_cb.ptm_sock, &ptm_cb.t_read);
 }
 
 /* BFD peer/dst register/update */
@@ -714,8 +698,8 @@ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS)
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return;
        }
 
@@ -873,8 +857,8 @@ void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS)
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return;
        }
 
@@ -1001,8 +985,8 @@ void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS)
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return;
        }
 
@@ -1060,8 +1044,8 @@ int zebra_ptm_bfd_client_deregister(struct zserv *client)
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
-               thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
-                                ptm_cb.reconnect_time, &ptm_cb.t_timer);
+               event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+                               ptm_cb.reconnect_time, &ptm_cb.t_timer);
                return 0;
        }
 
@@ -1201,7 +1185,7 @@ struct ptm_process {
 TAILQ_HEAD(ppqueue, ptm_process) ppqueue;
 
 DEFINE_MTYPE_STATIC(ZEBRA, ZEBRA_PTM_BFD_PROCESS,
-                   "PTM BFD process registration table.");
+                   "PTM BFD process reg table");
 
 /*
  * Prototypes.
@@ -1294,10 +1278,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
 
        /* Create copy for replication. */
        msgc = stream_dup(msg);
-       if (msgc == NULL) {
-               zlog_debug("%s: not enough memory", __func__);
-               return;
-       }
 
        /* Send message to all running BFDd daemons. */
        for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
@@ -1308,10 +1288,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
 
                /* Allocate more messages. */
                msg = stream_dup(msgc);
-               if (msg == NULL) {
-                       zlog_debug("%s: not enough memory", __func__);
-                       return;
-               }
        }
 
        stream_free(msgc);
@@ -1326,10 +1302,6 @@ static void zebra_ptm_send_clients(struct stream *msg)
 
        /* Create copy for replication. */
        msgc = stream_dup(msg);
-       if (msgc == NULL) {
-               zlog_debug("%s: not enough memory", __func__);
-               return;
-       }
 
        /* Send message to all running client daemons. */
        for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
@@ -1340,10 +1312,6 @@ static void zebra_ptm_send_clients(struct stream *msg)
 
                /* Allocate more messages. */
                msg = stream_dup(msgc);
-               if (msg == NULL) {
-                       zlog_debug("%s: not enough memory", __func__);
-                       return;
-               }
        }
 
        stream_free(msgc);