diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-06-26 14:07:20 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-06-26 14:07:20 +0000 |
commit | 47146460fed2d0c6b3fc2b77955b33c6ca6e8458 (patch) | |
tree | 889747d8cbf2401143d9134a0d2dc5eb1a943af8 | |
parent | 6fa9b443073a1e992172554b63dfbfeed096debb (diff) |
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@
-rw-r--r-- | usr.sbin/eigrpd/packet.c | 11 | ||||
-rw-r--r-- | 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 <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) { 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 <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); } |