]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: add dbdesc messages to tx FIFO
authorPat Ruddy <pat@voltanet.io>
Fri, 12 Mar 2021 10:58:22 +0000 (10:58 +0000)
committerPat Ruddy <pat@voltanet.io>
Fri, 18 Jun 2021 08:40:42 +0000 (09:40 +0100)
enqueue outgoing dbdesc messages to the end of the tx FIFO and
schedule the ospf6_write task to deal with them.

Signed-off-by: Pat Ruddy <pat@voltanet.io>
ospf6d/ospf6_message.c
ospf6d/ospf6_message.h
ospf6d/ospf6_network.h

index 16af80b5972e5a885a6982a1d73ea634df087cdf..10ce92f6556e6202d9f7c08989826b1895fdaa4e 100644 (file)
@@ -264,7 +264,7 @@ static struct ospf6_packet *ospf6_packet_new(size_t size)
        return new;
 }
 
-void ospf6_packet_free(struct ospf6_packet *op)
+static void ospf6_packet_free(struct ospf6_packet *op)
 {
        if (op->s)
                stream_free(op->s);
@@ -327,7 +327,7 @@ static struct ospf6_packet *ospf6_fifo_pop(struct ospf6_fifo *fifo)
 }
 
 /* Return first fifo entry. */
-struct ospf6_packet *ospf6_fifo_head(struct ospf6_fifo *fifo)
+static struct ospf6_packet *ospf6_fifo_head(struct ospf6_fifo *fifo)
 {
        return fifo->head;
 }
@@ -354,7 +354,8 @@ void ospf6_fifo_free(struct ospf6_fifo *fifo)
        XFREE(MTYPE_OSPF6_FIFO, fifo);
 }
 
-void ospf6_packet_add(struct ospf6_interface *oi, struct ospf6_packet *op)
+static void ospf6_packet_add(struct ospf6_interface *oi,
+                            struct ospf6_packet *op)
 {
        /* Add packet to end of queue. */
        ospf6_fifo_push(oi->obuf, op);
@@ -2137,41 +2138,15 @@ int ospf6_hello_send(struct thread *thread)
        thread_add_timer(master, ospf6_hello_send, oi, oi->hello_interval,
                         &oi->thread_send_hello);
 
-       OSPF6_MESSAGE_WRITE_ON(oi->area->ospf6);
+       OSPF6_MESSAGE_WRITE_ON(oi);
 
        return 0;
 }
 
-int ospf6_dbdesc_send(struct thread *thread)
+static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s)
 {
-       struct ospf6_neighbor *on;
-       struct ospf6_header *oh;
-       struct ospf6_dbdesc *dbdesc;
-       uint8_t *p;
+       uint16_t length = OSPF6_DB_DESC_MIN_SIZE;
        struct ospf6_lsa *lsa, *lsanext;
-       struct in6_addr *dst;
-
-       on = (struct ospf6_neighbor *)THREAD_ARG(thread);
-       on->thread_send_dbdesc = (struct thread *)NULL;
-
-       if (on->state < OSPF6_NEIGHBOR_EXSTART) {
-               if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_DBDESC, SEND_HDR))
-                       zlog_debug(
-                               "Quit to send DbDesc to neighbor %s state %s",
-                               on->name, ospf6_neighbor_state_str[on->state]);
-               return 0;
-       }
-
-       /* set next thread if master */
-       if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
-               thread_add_timer(master, ospf6_dbdesc_send, on,
-                                on->ospf6_if->rxmt_interval,
-                                &on->thread_send_dbdesc);
-
-       memset(sendbuf, 0, iobuflen);
-       oh = (struct ospf6_header *)sendbuf;
-       dbdesc = (struct ospf6_dbdesc *)((caddr_t)oh
-                                        + sizeof(struct ospf6_header));
 
        /* if this is initial one, initialize sequence number for DbDesc */
        if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
@@ -2179,45 +2154,79 @@ int ospf6_dbdesc_send(struct thread *thread)
                on->dbdesc_seqnum = monotime(NULL);
        }
 
-       dbdesc->options[0] = on->ospf6_if->area->options[0];
-       dbdesc->options[1] = on->ospf6_if->area->options[1];
-       dbdesc->options[2] = on->ospf6_if->area->options[2];
-       dbdesc->ifmtu = htons(on->ospf6_if->ifmtu);
-       dbdesc->bits = on->dbdesc_bits;
-       dbdesc->seqnum = htonl(on->dbdesc_seqnum);
+       /* reserved */
+       stream_putc(s, 0); /* reserved 1 */
+       stream_putc(s, on->ospf6_if->area->options[0]);
+       stream_putc(s, on->ospf6_if->area->options[1]);
+       stream_putc(s, on->ospf6_if->area->options[2]);
+       stream_putw(s, on->ospf6_if->ifmtu);
+       stream_putc(s, 0); /* reserved 2 */
+       stream_putc(s, on->dbdesc_bits);
+       stream_putl(s, on->dbdesc_seqnum);
 
        /* if this is not initial one, set LSA headers in dbdesc */
-       p = (uint8_t *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc));
        if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)) {
                for (ALL_LSDB(on->dbdesc_list, lsa, lsanext)) {
                        ospf6_lsa_age_update_to_send(lsa,
                                                     on->ospf6_if->transdelay);
 
                        /* MTU check */
-                       if (p - sendbuf + sizeof(struct ospf6_lsa_header)
+                       if ((length + sizeof(struct ospf6_lsa_header)
+                            + OSPF6_HEADER_SIZE)
                            > ospf6_packet_max(on->ospf6_if)) {
                                ospf6_lsa_unlock(lsa);
                                if (lsanext)
                                        ospf6_lsa_unlock(lsanext);
                                break;
                        }
-                       memcpy(p, lsa->header, sizeof(struct ospf6_lsa_header));
-                       p += sizeof(struct ospf6_lsa_header);
+                       stream_put(s, lsa->header,
+                                  sizeof(struct ospf6_lsa_header));
+                       length += sizeof(struct ospf6_lsa_header);
                }
        }
+       return length;
+}
+
+int ospf6_dbdesc_send(struct thread *thread)
+{
+       struct ospf6_neighbor *on;
+       uint16_t length = OSPF6_HEADER_SIZE;
+       struct ospf6_packet *op;
+
+       on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+       on->thread_send_dbdesc = (struct thread *)NULL;
+
+       if (on->state < OSPF6_NEIGHBOR_EXSTART) {
+               if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_DBDESC, SEND))
+                       zlog_debug(
+                               "Quit to send DbDesc to neighbor %s state %s",
+                               on->name, ospf6_neighbor_state_str[on->state]);
+               return 0;
+       }
 
-       oh->type = OSPF6_MESSAGE_TYPE_DBDESC;
-       oh->length = htons(p - sendbuf);
+       /* set next thread if master */
+       if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
+               thread_add_timer(master, ospf6_dbdesc_send, on,
+                                on->ospf6_if->rxmt_interval,
+                                &on->thread_send_dbdesc);
+
+       op = ospf6_packet_new(on->ospf6_if->ifmtu);
+       ospf6_make_header(OSPF6_MESSAGE_TYPE_DBDESC, on->ospf6_if, op->s);
 
+       length += ospf6_make_dbdesc(on, op->s);
+       ospf6_fill_header(on->ospf6_if, op->s, length);
+
+       /* Set packet length. */
+       op->length = length;
 
        if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
-               dst = &allspfrouters6;
+               op->dst = allspfrouters6;
        else
-               dst = &on->linklocal_addr;
+               op->dst = on->linklocal_addr;
 
-       on->ospf6_if->db_desc_out++;
+       ospf6_packet_add(on->ospf6_if, op);
 
-       ospf6_send(on->ospf6_if->linklocal_addr, dst, on->ospf6_if, oh);
+       OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
 
        return 0;
 }
index 447a90c7733310cbe459ff145780aea6856d0655..0cd10ef82519c34e837dbe3c7bc7429f0128f1a4 100644 (file)
@@ -157,16 +157,9 @@ extern void ospf6_lsreq_print(struct ospf6_header *, int action);
 extern void ospf6_lsupdate_print(struct ospf6_header *, int action);
 extern void ospf6_lsack_print(struct ospf6_header *, int action);
 
-extern void ospf6_packet_free(struct ospf6_packet *op);
 extern struct ospf6_fifo *ospf6_fifo_new(void);
 extern void ospf6_fifo_flush(struct ospf6_fifo *fifo);
 extern void ospf6_fifo_free(struct ospf6_fifo *fifo);
-struct ospf6_packet *ospf6_fifo_head(struct ospf6_fifo *fifo);
-
-/* temporary inclusinon of ospf6_interface.h for compile will be removed */
-#include "ospf6_interface.h"
-extern void ospf6_packet_add(struct ospf6_interface *oi,
-                            struct ospf6_packet *op);
 
 extern int ospf6_iobuf_size(unsigned int size);
 extern void ospf6_message_terminate(void);
index 5b476c459383499c1c167e484ac597ed7498b78b..3886a0d263261b6a45b3a2c44edb7c4caf8b257b 100644 (file)
@@ -36,7 +36,7 @@ extern int ospf6_recvmsg(struct in6_addr *src, struct in6_addr *dst,
                         ifindex_t *ifindex, struct iovec *message,
                         int ospf6_sock);
 
-#define OSPF6_MESSAGE_WRITE_ON(O)                                              \
+#define OSPF6_MESSAGE_WRITE_ON(oi)                                             \
        do {                                                                   \
                bool list_was_empty =                                          \
                        list_isempty(oi->area->ospf6->oi_write_q);             \