-/* $OpenBSD: ospfe.c,v 1.68 2023/03/08 04:43:14 guenther Exp $ */
+/* $OpenBSD: ospfe.c,v 1.69 2023/06/21 07:45:47 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
fatal("orig_rtr_lsa");
/* reserve space for LSA header and LSA Router header */
- if (ibuf_reserve(buf, sizeof(lsa_hdr)) == NULL)
- fatal("orig_rtr_lsa: ibuf_reserve failed");
+ if (ibuf_add_zero(buf, sizeof(lsa_hdr)) == -1)
+ fatal("orig_rtr_lsa: ibuf_add_zero failed");
- if (ibuf_reserve(buf, sizeof(lsa_rtr)) == NULL)
- fatal("orig_rtr_lsa: ibuf_reserve failed");
+ if (ibuf_add_zero(buf, sizeof(lsa_rtr)) == -1)
+ fatal("orig_rtr_lsa: ibuf_add_zero failed");
/* links */
LIST_FOREACH(iface, &area->iface_list, entry) {
LSA_24_SETLO(lsa_rtr.opts, area_ospf_options(area));
LSA_24_SETHI(lsa_rtr.opts, flags);
lsa_rtr.opts = htonl(lsa_rtr.opts);
- memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_rtr)),
- &lsa_rtr, sizeof(lsa_rtr));
+ if (ibuf_set(buf, sizeof(lsa_hdr), &lsa_rtr, sizeof(lsa_rtr)) == -1)
+ fatal("orig_rtr_lsa: ibuf_set failed");
/* LSA header */
lsa_hdr.age = htons(DEFAULT_AGE);
lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
lsa_hdr.len = htons(buf->wpos);
lsa_hdr.ls_chksum = 0; /* updated later */
- memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr));
+ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
+ fatal("orig_rtr_lsa: ibuf_set failed");
- chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET));
- memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)),
- &chksum, sizeof(chksum));
+ chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+ if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
+ fatal("orig_rtr_lsa: ibuf_set_n16 failed");
if (self)
imsg_compose_event(iev_rde, IMSG_LS_UPD, self->peerid, 0,
fatal("orig_net_lsa");
/* reserve space for LSA header and options field */
- if (ibuf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_net)) == NULL)
- fatal("orig_net_lsa: ibuf_reserve failed");
+ if (ibuf_add_zero(buf, sizeof(lsa_hdr) + sizeof(lsa_net)) == -1)
+ fatal("orig_net_lsa: ibuf_add_zero failed");
lsa_net.opts = 0;
/* fully adjacent neighbors + self */
lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
lsa_hdr.len = htons(buf->wpos);
lsa_hdr.ls_chksum = 0; /* updated later */
- memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr));
+ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
+ fatal("orig_net_lsa: ibuf_set failed");
lsa_net.opts &= lsa_net.opts & htonl(LSA_24_MASK);
- memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_net)), &lsa_net,
- sizeof(lsa_net));
+ if (ibuf_set(buf, sizeof(lsa_hdr), &lsa_net, sizeof(lsa_net)) == -1)
+ fatal("orig_net_lsa: ibuf_set failed");
- chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET));
- memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)),
- &chksum, sizeof(chksum));
+ chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+ if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
+ fatal("orig_net_lsa: ibuf_set_n16 failed");
imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0,
-1, buf->buf, buf->wpos);
fatal("orig_link_lsa");
/* reserve space for LSA header and LSA link header */
- if (ibuf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_link)) == NULL)
- fatal("orig_link_lsa: ibuf_reserve failed");
+ if (ibuf_add_zero(buf, sizeof(lsa_hdr) + sizeof(lsa_link)) == -1)
+ fatal("orig_link_lsa: ibuf_add_zero failed");
/* link-local address, and all prefixes configured on interface */
TAILQ_FOREACH(ia, &iface->ifa_list, entry) {
LSA_24_SETLO(lsa_link.opts, options);
lsa_link.opts = htonl(lsa_link.opts);
lsa_link.numprefix = htonl(num_prefix);
- memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_link)),
- &lsa_link, sizeof(lsa_link));
+ if (ibuf_set(buf, sizeof(lsa_hdr), &lsa_link, sizeof(lsa_link)) == -1)
+ fatal("orig_link_lsa: ibuf_set failed");
/* LSA header */
lsa_hdr.age = htons(DEFAULT_AGE);
lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
lsa_hdr.len = htons(buf->wpos);
lsa_hdr.ls_chksum = 0; /* updated later */
- memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr));
+ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
+ fatal("orig_link_lsa: ibuf_set failed");
- chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET));
- memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)),
- &chksum, sizeof(chksum));
+ chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+ if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
+ fatal("orig_link_lsa: ibuf_set_n16 failed");
imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0,
-1, buf->buf, buf->wpos);