From 6e5fef78ef7f1b190226417b690a8639108cf1a0 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 26 Jun 2023 14:07:19 +0000 Subject: [PATCH] Start using the new ibuf API in eigrpd. One ibuf_seek() still left since the change is not trivial and I don't have a eigrp testbed. OK tb@ --- usr.sbin/eigrpd/packet.c | 11 +++++------ usr.sbin/eigrpd/tlv.c | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/usr.sbin/eigrpd/packet.c b/usr.sbin/eigrpd/packet.c index 1b2a15d1330..848b8cf7618 100644 --- a/usr.sbin/eigrpd/packet.c +++ b/usr.sbin/eigrpd/packet.c @@ -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 @@ -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) { diff --git a/usr.sbin/eigrpd/tlv.c b/usr.sbin/eigrpd/tlv.c index 6715a8f4061..8b7cc72ff16 100644 --- a/usr.sbin/eigrpd/tlv.c +++ b/usr.sbin/eigrpd/tlv.c @@ -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 @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -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); } -- 2.20.1