To generate the IMSG_CTL_SHOW_RIB_ATTR message just use attr_writebuf()
instead of going via ibuf_reserve() and attr_write().

While there make a pointer != NULL check more obvious.
-- 
:wq Claudio

Index: rde.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.605
diff -u -p -r1.605 rde.c
--- rde.c       20 Apr 2023 15:44:45 -0000      1.605
+++ rde.c       10 Jun 2023 08:26:14 -0000
@@ -2828,7 +2828,6 @@ rde_dump_rib_as(struct prefix *p, struct
        struct rib_entry        *re;
        struct prefix           *xp;
        struct rde_peer         *peer;
-       void                    *bp;
        time_t                   staletime;
        size_t                   aslen;
        uint8_t                  l;
@@ -2934,12 +2933,8 @@ rde_dump_rib_as(struct prefix *p, struct
                            IMSG_CTL_SHOW_RIB_ATTR, 0, pid,
                            attr_optlen(a))) == NULL)
                                return;
-                       if ((bp = ibuf_reserve(wbuf, attr_optlen(a))) == NULL) {
-                               ibuf_free(wbuf);
-                               return;
-                       }
-                       if (attr_write(bp, attr_optlen(a), a->flags,
-                           a->type, a->data, a->len) == -1) {
+                       if (attr_writebuf(wbuf, a->flags, a->type, a->data,
+                           a->len) == -1) {
                                ibuf_free(wbuf);
                                return;
                        }
Index: rde_attr.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_attr.c,v
retrieving revision 1.132
diff -u -p -r1.132 rde_attr.c
--- rde_attr.c  14 Dec 2022 12:37:15 -0000      1.132
+++ rde_attr.c  10 Jun 2023 08:19:25 -0000
@@ -85,7 +85,7 @@ attr_writebuf(struct ibuf *buf, uint8_t 
 
        if (ibuf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1)
                return (-1);
-       if (data && ibuf_add(buf, data, data_len) == -1)
+       if (data != NULL && ibuf_add(buf, data, data_len) == -1)
                return (-1);
        return (0);
 }

Reply via email to