]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripd/ripd.c
ripd: adapt to new YANG NB if_rmap conversion
[mirror_frr.git] / ripd / ripd.c
index 8a321d9a91f38ed1dc8c25dc811a2bc9d32f638e..7dbe2bbccf7d696bf0f127bc5049fa8e5e307670 100644 (file)
@@ -1,22 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* RIP version 1 and 2.
  * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
  * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro <kunihiro@zebra.org>
- *
- * 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>
@@ -26,7 +11,7 @@
 #include "command.h"
 #include "prefix.h"
 #include "table.h"
-#include "thread.h"
+#include "frrevent.h"
 #include "memory.h"
 #include "log.h"
 #include "stream.h"
@@ -65,7 +50,7 @@ DEFINE_MTYPE_STATIC(RIPD, RIP_DISTANCE, "RIP distance");
 /* Prototypes. */
 static void rip_output_process(struct connected *, struct sockaddr_in *, int,
                               uint8_t);
-static void rip_triggered_update(struct thread *);
+static void rip_triggered_update(struct event *);
 static int rip_update_jitter(unsigned long);
 static void rip_distance_table_node_cleanup(struct route_table *table,
                                            struct route_node *node);
@@ -136,15 +121,15 @@ struct rip *rip_info_get_instance(const struct rip_info *rinfo)
 }
 
 /* RIP route garbage collect timer. */
-static void rip_garbage_collect(struct thread *t)
+static void rip_garbage_collect(struct event *t)
 {
        struct rip_info *rinfo;
        struct route_node *rp;
 
-       rinfo = THREAD_ARG(t);
+       rinfo = EVENT_ARG(t);
 
        /* Off timeout timer. */
-       THREAD_OFF(rinfo->t_timeout);
+       EVENT_OFF(rinfo->t_timeout);
 
        /* Get route_node pointer. */
        rp = rinfo->rp;
@@ -226,14 +211,14 @@ struct rip_info *rip_ecmp_replace(struct rip *rip, struct rip_info *rinfo_new)
                if (tmp_rinfo == rinfo)
                        continue;
 
-               THREAD_OFF(tmp_rinfo->t_timeout);
-               THREAD_OFF(tmp_rinfo->t_garbage_collect);
+               EVENT_OFF(tmp_rinfo->t_timeout);
+               EVENT_OFF(tmp_rinfo->t_garbage_collect);
                list_delete_node(list, node);
                rip_info_free(tmp_rinfo);
        }
 
-       THREAD_OFF(rinfo->t_timeout);
-       THREAD_OFF(rinfo->t_garbage_collect);
+       EVENT_OFF(rinfo->t_timeout);
+       EVENT_OFF(rinfo->t_garbage_collect);
        memcpy(rinfo, rinfo_new, sizeof(struct rip_info));
 
        if (rip_route_rte(rinfo)) {
@@ -262,12 +247,12 @@ struct rip_info *rip_ecmp_delete(struct rip *rip, struct rip_info *rinfo)
        struct route_node *rp = rinfo->rp;
        struct list *list = (struct list *)rp->info;
 
-       THREAD_OFF(rinfo->t_timeout);
+       EVENT_OFF(rinfo->t_timeout);
 
        if (listcount(list) > 1) {
                /* Some other ECMP entries still exist. Just delete this entry.
                 */
-               THREAD_OFF(rinfo->t_garbage_collect);
+               EVENT_OFF(rinfo->t_garbage_collect);
                listnode_delete(list, rinfo);
                if (rip_route_rte(rinfo)
                    && CHECK_FLAG(rinfo->flags, RIP_RTF_FIB))
@@ -302,9 +287,9 @@ struct rip_info *rip_ecmp_delete(struct rip *rip, struct rip_info *rinfo)
 }
 
 /* Timeout RIP routes. */
-static void rip_timeout(struct thread *t)
+static void rip_timeout(struct event *t)
 {
-       struct rip_info *rinfo = THREAD_ARG(t);
+       struct rip_info *rinfo = EVENT_ARG(t);
        struct rip *rip = rip_info_get_instance(rinfo);
 
        rip_ecmp_delete(rip, rinfo);
@@ -313,9 +298,9 @@ static void rip_timeout(struct thread *t)
 static void rip_timeout_update(struct rip *rip, struct rip_info *rinfo)
 {
        if (rinfo->metric != RIP_METRIC_INFINITY) {
-               THREAD_OFF(rinfo->t_timeout);
-               thread_add_timer(master, rip_timeout, rinfo, rip->timeout_time,
-                                &rinfo->t_timeout);
+               EVENT_OFF(rinfo->t_timeout);
+               event_add_timer(master, rip_timeout, rinfo, rip->timeout_time,
+                               &rinfo->t_timeout);
        }
 }
 
@@ -659,8 +644,8 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from,
                                        assert(newinfo.metric
                                               != RIP_METRIC_INFINITY);
 
-                                       THREAD_OFF(rinfo->t_timeout);
-                                       THREAD_OFF(rinfo->t_garbage_collect);
+                                       EVENT_OFF(rinfo->t_timeout);
+                                       EVENT_OFF(rinfo->t_garbage_collect);
                                        memcpy(rinfo, &newinfo,
                                               sizeof(struct rip_info));
                                        rip_timeout_update(rip, rinfo);
@@ -1515,7 +1500,7 @@ static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to,
        ret = sendmsg(rip->sock, &msg, 0);
 
        if (IS_RIP_DEBUG_EVENT)
-               zlog_debug("SEND to  %pI4%d", &sin.sin_addr,
+               zlog_debug("SEND to %pI4 port %d", &sin.sin_addr,
                           ntohs(sin.sin_port));
 
        if (ret < 0)
@@ -1613,7 +1598,7 @@ void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
                                RIP_TIMER_ON(rinfo->t_garbage_collect,
                                             rip_garbage_collect,
                                             rip->garbage_time);
-                               THREAD_OFF(rinfo->t_timeout);
+                               EVENT_OFF(rinfo->t_timeout);
                                rinfo->flags |= RIP_RTF_CHANGED;
 
                                if (IS_RIP_DEBUG_EVENT)
@@ -1712,9 +1697,9 @@ static void rip_request_process(struct rip_packet *packet, int size,
 }
 
 /* First entry point of RIP packet. */
-static void rip_read(struct thread *t)
+static void rip_read(struct event *t)
 {
-       struct rip *rip = THREAD_ARG(t);
+       struct rip *rip = EVENT_ARG(t);
        int sock;
        int ret;
        int rtenum;
@@ -1730,7 +1715,7 @@ static void rip_read(struct thread *t)
        struct prefix p;
 
        /* Fetch socket then register myself. */
-       sock = THREAD_FD(t);
+       sock = EVENT_FD(t);
 
        /* Add myself to tne next event */
        rip_event(rip, RIP_READ, sock);
@@ -2493,9 +2478,9 @@ static void rip_update_process(struct rip *rip, int route_type)
 }
 
 /* RIP's periodical timer. */
-static void rip_update(struct thread *t)
+static void rip_update(struct event *t)
 {
-       struct rip *rip = THREAD_ARG(t);
+       struct rip *rip = EVENT_ARG(t);
 
        if (IS_RIP_DEBUG_EVENT)
                zlog_debug("update timer fire!");
@@ -2505,7 +2490,7 @@ static void rip_update(struct thread *t)
 
        /* Triggered updates may be suppressed if a regular update is due by
           the time the triggered update would be sent. */
-       THREAD_OFF(rip->t_triggered_interval);
+       EVENT_OFF(rip->t_triggered_interval);
        rip->trigger = 0;
 
        /* Register myself. */
@@ -2535,9 +2520,9 @@ static void rip_clear_changed_flag(struct rip *rip)
 }
 
 /* Triggered update interval timer. */
-static void rip_triggered_interval(struct thread *t)
+static void rip_triggered_interval(struct event *t)
 {
-       struct rip *rip = THREAD_ARG(t);
+       struct rip *rip = EVENT_ARG(t);
 
        if (rip->trigger) {
                rip->trigger = 0;
@@ -2546,13 +2531,13 @@ static void rip_triggered_interval(struct thread *t)
 }
 
 /* Execute triggered update. */
-static void rip_triggered_update(struct thread *t)
+static void rip_triggered_update(struct event *t)
 {
-       struct rip *rip = THREAD_ARG(t);
+       struct rip *rip = EVENT_ARG(t);
        int interval;
 
        /* Cancel interval timer. */
-       THREAD_OFF(rip->t_triggered_interval);
+       EVENT_OFF(rip->t_triggered_interval);
        rip->trigger = 0;
 
        /* Logging triggered update. */
@@ -2573,8 +2558,8 @@ static void rip_triggered_update(struct thread *t)
         update is triggered when the timer expires. */
        interval = (frr_weak_random() % 5) + 1;
 
-       thread_add_timer(master, rip_triggered_interval, rip, interval,
-                        &rip->t_triggered_interval);
+       event_add_timer(master, rip_triggered_interval, rip, interval,
+                       &rip->t_triggered_interval);
 }
 
 /* Withdraw redistributed route. */
@@ -2602,7 +2587,7 @@ void rip_redistribute_withdraw(struct rip *rip, int type)
                rinfo->metric = RIP_METRIC_INFINITY;
                RIP_TIMER_ON(rinfo->t_garbage_collect, rip_garbage_collect,
                             rip->garbage_time);
-               THREAD_OFF(rinfo->t_timeout);
+               EVENT_OFF(rinfo->t_timeout);
                rinfo->flags |= RIP_RTF_CHANGED;
 
                if (IS_RIP_DEBUG_EVENT) {
@@ -2781,21 +2766,21 @@ void rip_event(struct rip *rip, enum rip_event event, int sock)
 
        switch (event) {
        case RIP_READ:
-               thread_add_read(master, rip_read, rip, sock, &rip->t_read);
+               event_add_read(master, rip_read, rip, sock, &rip->t_read);
                break;
        case RIP_UPDATE_EVENT:
-               THREAD_OFF(rip->t_update);
+               EVENT_OFF(rip->t_update);
                jitter = rip_update_jitter(rip->update_time);
-               thread_add_timer(master, rip_update, rip,
-                                sock ? 2 : rip->update_time + jitter,
-                                &rip->t_update);
+               event_add_timer(master, rip_update, rip,
+                               sock ? 2 : rip->update_time + jitter,
+                               &rip->t_update);
                break;
        case RIP_TRIGGERED_UPDATE:
                if (rip->t_triggered_interval)
                        rip->trigger = 1;
                else
-                       thread_add_event(master, rip_triggered_update, rip, 0,
-                                        &rip->t_triggered_update);
+                       event_add_event(master, rip_triggered_update, rip, 0,
+                                       &rip->t_triggered_update);
                break;
        default:
                break;
@@ -2851,16 +2836,11 @@ uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo)
                        if (access_list_apply(alist, &rinfo->rp->p)
                            == FILTER_DENY)
                                return 0;
-
-                       return rdistance->distance;
-               } else
-                       return rdistance->distance;
+               }
+               return rdistance->distance;
        }
 
-       if (rip->distance)
-               return rip->distance;
-
-       return 0;
+       return rip->distance;
 }
 
 static void rip_distance_show(struct vty *vty, struct rip *rip)
@@ -2914,8 +2894,8 @@ void rip_ecmp_disable(struct rip *rip)
                        if (tmp_rinfo == rinfo)
                                continue;
 
-                       THREAD_OFF(tmp_rinfo->t_timeout);
-                       THREAD_OFF(tmp_rinfo->t_garbage_collect);
+                       EVENT_OFF(tmp_rinfo->t_timeout);
+                       EVENT_OFF(tmp_rinfo->t_garbage_collect);
                        list_delete_node(list, node);
                        rip_info_free(tmp_rinfo);
                }
@@ -2938,15 +2918,15 @@ static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo)
        struct tm tm;
 #define TIME_BUF 25
        char timebuf[TIME_BUF];
-       struct thread *thread;
+       struct event *thread;
 
        if ((thread = rinfo->t_timeout) != NULL) {
-               clock = thread_timer_remain_second(thread);
+               clock = event_timer_remain_second(thread);
                gmtime_r(&clock, &tm);
                strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
        } else if ((thread = rinfo->t_garbage_collect) != NULL) {
-               clock = thread_timer_remain_second(thread);
+               clock = event_timer_remain_second(thread);
                gmtime_r(&clock, &tm);
                strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
@@ -3121,7 +3101,7 @@ DEFUN (show_ip_rip_status,
        vty_out(vty, "  Sending updates every %u seconds with +/-50%%,",
                rip->update_time);
        vty_out(vty, " next due in %lu seconds\n",
-               thread_timer_remain_second(rip->t_update));
+               event_timer_remain_second(rip->t_update));
        vty_out(vty, "  Timeout after %u seconds,", rip->timeout_time);
        vty_out(vty, " garbage collect after %u seconds\n", rip->garbage_time);
 
@@ -3507,8 +3487,8 @@ static void rip_instance_disable(struct rip *rip)
                        rip_zebra_ipv4_delete(rip, rp);
 
                for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
-                       THREAD_OFF(rinfo->t_timeout);
-                       THREAD_OFF(rinfo->t_garbage_collect);
+                       EVENT_OFF(rinfo->t_timeout);
+                       EVENT_OFF(rinfo->t_garbage_collect);
                        rip_info_free(rinfo);
                }
                list_delete(&list);
@@ -3520,12 +3500,12 @@ static void rip_instance_disable(struct rip *rip)
        rip_redistribute_disable(rip);
 
        /* Cancel RIP related timers. */
-       THREAD_OFF(rip->t_update);
-       THREAD_OFF(rip->t_triggered_update);
-       THREAD_OFF(rip->t_triggered_interval);
+       EVENT_OFF(rip->t_update);
+       EVENT_OFF(rip->t_triggered_update);
+       EVENT_OFF(rip->t_triggered_interval);
 
        /* Cancel read thread. */
-       THREAD_OFF(rip->t_read);
+       EVENT_OFF(rip->t_read);
 
        /* Close RIP socket. */
        close(rip->sock);
@@ -3551,10 +3531,18 @@ static int rip_vrf_new(struct vrf *vrf)
 
 static int rip_vrf_delete(struct vrf *vrf)
 {
+       struct rip *rip;
+
        if (IS_RIP_DEBUG_EVENT)
                zlog_debug("%s: VRF deleted: %s(%u)", __func__, vrf->name,
                           vrf->vrf_id);
 
+       rip = rip_lookup_by_vrf_name(vrf->name);
+       if (!rip)
+               return 0;
+
+       rip_clean(rip);
+
        return 0;
 }