]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: Cleanup oi->obuf to always be created
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 30 Aug 2019 20:14:38 +0000 (16:14 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 30 Aug 2019 20:48:07 +0000 (16:48 -0400)
This looks like a finish up of the partial cleanup that
ocurred at some point in time in the past.  When we
alloc oi also always alloc the oi->obuf.  When we delete
oi always delete the oi->obuf right before.

This cleans up a bunch of code to be simpler and hopefully
easier to follow.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
ospfd/ospf_interface.c
ospfd/ospf_interface.h
ospfd/ospf_packet.c

index ce1604a5b1c5a667058f549739f54dd7a39c3c4b..387770870811b45a0867c63bb210648695d80beb 100644 (file)
@@ -225,12 +225,14 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
 {
        struct ospf_interface *oi;
 
-       if ((oi = ospf_if_table_lookup(ifp, p)) == NULL) {
-               oi = XCALLOC(MTYPE_OSPF_IF, sizeof(struct ospf_interface));
-               memset(oi, 0, sizeof(struct ospf_interface));
-       } else
+       oi = ospf_if_table_lookup(ifp, p);
+       if (oi)
                return oi;
 
+       oi = XCALLOC(MTYPE_OSPF_IF, sizeof(struct ospf_interface));
+
+       oi->obuf = ospf_fifo_new();
+
        /* Set zebra interface pointer. */
        oi->ifp = ifp;
        oi->address = p;
@@ -264,8 +266,6 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
 
        oi->ospf = ospf;
 
-       ospf_if_stream_set(oi);
-
        QOBJ_REG(oi, ospf_interface);
 
        if (IS_DEBUG_OSPF_EVENT)
@@ -325,8 +325,7 @@ void ospf_if_free(struct ospf_interface *oi)
 {
        ospf_if_down(oi);
 
-       if (oi->obuf)
-               ospf_fifo_free(oi->obuf);
+       ospf_fifo_free(oi->obuf);
 
        assert(oi->state == ISM_Down);
 
@@ -490,29 +489,20 @@ static void ospf_if_reset_stats(struct ospf_interface *oi)
        oi->ls_ack_in = oi->ls_ack_out = 0;
 }
 
-void ospf_if_stream_set(struct ospf_interface *oi)
-{
-       /* set output fifo queue. */
-       if (oi->obuf == NULL)
-               oi->obuf = ospf_fifo_new();
-}
-
 void ospf_if_stream_unset(struct ospf_interface *oi)
 {
        struct ospf *ospf = oi->ospf;
 
-       if (oi->obuf) {
-               /* flush the interface packet queue */
-               ospf_fifo_flush(oi->obuf);
-               /*reset protocol stats */
-               ospf_if_reset_stats(oi);
-
-               if (oi->on_write_q) {
-                       listnode_delete(ospf->oi_write_q, oi);
-                       if (list_isempty(ospf->oi_write_q))
-                               OSPF_TIMER_OFF(ospf->t_write);
-                       oi->on_write_q = 0;
-               }
+       /* flush the interface packet queue */
+       ospf_fifo_flush(oi->obuf);
+       /*reset protocol stats */
+       ospf_if_reset_stats(oi);
+
+       if (oi->on_write_q) {
+               listnode_delete(ospf->oi_write_q, oi);
+               if (list_isempty(ospf->oi_write_q))
+                       OSPF_TIMER_OFF(ospf->t_write);
+               oi->on_write_q = 0;
        }
 }
 
@@ -903,8 +893,6 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
 
        ospf_area_add_if(voi->area, voi);
 
-       ospf_if_stream_set(voi);
-
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug("ospf_vl_new(): Stop");
        return voi;
index b88d405875a5f4fee04695f828c0241562b41f0b..0c903954d321b2aab78d3bd63085e7d933e967de 100644 (file)
@@ -285,7 +285,6 @@ extern void ospf_if_update_params(struct interface *, struct in_addr);
 
 extern int ospf_if_new_hook(struct interface *);
 extern void ospf_if_init(void);
-extern void ospf_if_stream_set(struct ospf_interface *);
 extern void ospf_if_stream_unset(struct ospf_interface *);
 extern void ospf_if_reset_variables(struct ospf_interface *);
 extern int ospf_if_is_enable(struct ospf_interface *);
index 00ddd06d7d1770be3eb3680d76ff4f6564094a8a..5a29c1fb07abb2c511875e581d74ffe015308a17 100644 (file)
@@ -233,20 +233,6 @@ void ospf_fifo_free(struct ospf_fifo *fifo)
 
 static void ospf_packet_add(struct ospf_interface *oi, struct ospf_packet *op)
 {
-       if (!oi->obuf) {
-               flog_err(
-                       EC_OSPF_PKT_PROCESS,
-                       "ospf_packet_add(interface %s in state %d [%s], packet type %s, "
-                       "destination %s) called with NULL obuf, ignoring "
-                       "(please report this bug)!\n",
-                       IF_NAME(oi), oi->state,
-                       lookup_msg(ospf_ism_state_msg, oi->state, NULL),
-                       lookup_msg(ospf_packet_type_str,
-                                  stream_getc_from(op->s, 1), NULL),
-                       inet_ntoa(op->dst));
-               return;
-       }
-
        /* Add packet to end of queue. */
        ospf_fifo_push(oi->obuf, op);
 
@@ -257,20 +243,6 @@ static void ospf_packet_add(struct ospf_interface *oi, struct ospf_packet *op)
 static void ospf_packet_add_top(struct ospf_interface *oi,
                                struct ospf_packet *op)
 {
-       if (!oi->obuf) {
-               flog_err(
-                       EC_OSPF_PKT_PROCESS,
-                       "ospf_packet_add(interface %s in state %d [%s], packet type %s, "
-                       "destination %s) called with NULL obuf, ignoring "
-                       "(please report this bug)!\n",
-                       IF_NAME(oi), oi->state,
-                       lookup_msg(ospf_ism_state_msg, oi->state, NULL),
-                       lookup_msg(ospf_packet_type_str,
-                                  stream_getc_from(op->s, 1), NULL),
-                       inet_ntoa(op->dst));
-               return;
-       }
-
        /* Add packet to head of queue. */
        ospf_fifo_push_head(oi->obuf, op);