Start using the new ibuf API in eigrpd. One ibuf_seek() still left since
authorclaudio <claudio@openbsd.org>
Mon, 26 Jun 2023 14:07:19 +0000 (14:07 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 26 Jun 2023 14:07:19 +0000 (14:07 +0000)
the change is not trivial and I don't have a eigrp testbed.
OK tb@

usr.sbin/eigrpd/packet.c
usr.sbin/eigrpd/tlv.c

index 1b2a15d..848b8cf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: packet.c,v 1.20 2021/01/19 11:49:26 claudio Exp $ */
+/*     $OpenBSD: packet.c,v 1.21 2023/06/26 14:07:19 claudio Exp $ */
 
 /*
  * Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
@@ -172,12 +172,11 @@ send_packet(struct eigrp_iface *ei, struct nbr *nbr, uint32_t flags,
                eigrp_hdr->ack_num = htonl(nbr->recv_seq);
                rtp_ack_stop_timer(nbr);
        }
-       if (flags) {
-               eigrp_hdr->flags = ntohl(eigrp_hdr->flags) | flags;
-               eigrp_hdr->flags = htonl(eigrp_hdr->flags);
-       }
+       if (flags)
+               eigrp_hdr->flags |= htonl(flags);
+       
        eigrp_hdr->chksum = 0;
-       eigrp_hdr->chksum = in_cksum(buf->buf, ibuf_size(buf));
+       eigrp_hdr->chksum = in_cksum(ibuf_data(buf), ibuf_size(buf));
 
        /* log packet being sent */
        if (eigrp_hdr->opcode != EIGRP_OPC_HELLO) {
index 6715a8f..8b7cc72 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tlv.c,v 1.16 2021/11/03 13:48:46 deraadt Exp $ */
+/*     $OpenBSD: tlv.c,v 1.17 2023/06/26 14:07:19 claudio Exp $ */
 
 /*
  * Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include <sys/utsname.h>
 
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -51,13 +52,14 @@ gen_parameter_tlv(struct ibuf *buf, struct eigrp_iface *ei, int peerterm)
 int
 gen_sequence_tlv(struct ibuf *buf, struct seq_addr_head *seq_addr_list)
 {
-       struct tlv               tlv, *tlvp;
+       struct tlv               tlv;
        struct seq_addr_entry   *sa;
        uint8_t                  alen;
        uint16_t                 len = TLV_HDR_LEN;
-       size_t                   original_size = ibuf_size(buf);
+       size_t                   off;
 
        tlv.type = htons(TLV_TYPE_SEQ);
+       off = ibuf_size(buf) + offsetof(struct tlv, length);
        if (ibuf_add(buf, &tlv, sizeof(tlv))) {
                log_warn("%s: ibuf_add failed", __func__);
                return (-1);
@@ -85,9 +87,8 @@ gen_sequence_tlv(struct ibuf *buf, struct seq_addr_head *seq_addr_list)
        }
 
        /* adjust tlv length */
-       if ((tlvp = ibuf_seek(buf, original_size, sizeof(*tlvp))) == NULL)
-                fatalx("gen_sequence_tlv: buf_seek failed");
-       tlvp->length = htons(len);
+       if (ibuf_set_n16(buf, off, len) == -1)
+                fatalx("gen_sequence_tlv: buf_set_n16 failed");
 
        return (0);
 }
@@ -158,13 +159,13 @@ len_route_tlv(struct rinfo *ri)
 int
 gen_route_tlv(struct ibuf *buf, struct rinfo *ri)
 {
-       struct tlv               tlv, *tlvp;
+       struct tlv               tlv;
        struct in_addr           addr;
        struct classic_metric    metric;
        struct classic_emetric   emetric;
        uint16_t                 tlvlen;
        uint8_t                  pflen;
-       size_t                   original_size = ibuf_size(buf);
+       size_t                   off;
 
        switch (ri->af) {
        case AF_INET:
@@ -189,6 +190,7 @@ gen_route_tlv(struct ibuf *buf, struct rinfo *ri)
        }
        tlv.type = htons(tlv.type);
 
+       off = ibuf_size(buf) + offsetof(struct tlv, length);
        if (ibuf_add(buf, &tlv, sizeof(tlv)))
                return (-1);
        tlvlen = TLV_HDR_LEN;
@@ -251,9 +253,8 @@ gen_route_tlv(struct ibuf *buf, struct rinfo *ri)
        tlvlen += sizeof(pflen) + pflen;
 
        /* adjust tlv length */
-       if ((tlvp = ibuf_seek(buf, original_size, sizeof(*tlvp))) == NULL)
-                fatalx("gen_route_tlv: buf_seek failed");
-       tlvp->length = htons(tlvlen);
+       if (ibuf_set_n16(buf, off, tlvlen) == -1)
+                fatalx("gen_route_tlv: buf_set_n16 failed");
 
        return (0);
 }