-/* $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>
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) {
-/* $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>
#include <sys/types.h>
#include <sys/utsname.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
}
/* 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);
}
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:
}
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;
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);
}