Re: update ripd to use new ibuf API

2023-06-22 Thread Claudio Jeker
On Thu, Jun 22, 2023 at 11:15:31AM +0200, Theo Buehler wrote:
> On Thu, Jun 22, 2023 at 10:26:29AM +0200, Claudio Jeker wrote:
> > Another ibuf_seek() -> ibuf_set_n16() conversions.
> > While there also switch to ibuf_data() and ibuf_size().
> 
> Reads fine. ok. a test would indeed be nice.

I did a quick test myself and configured three ripd with auth-type crypt.
It seems to work as well as before.

-- 
:wq Claudio



Re: update ripd to use new ibuf API

2023-06-22 Thread Theo Buehler
On Thu, Jun 22, 2023 at 10:26:29AM +0200, Claudio Jeker wrote:
> Another ibuf_seek() -> ibuf_set_n16() conversions.
> While there also switch to ibuf_data() and ibuf_size().

Reads fine. ok. a test would indeed be nice.



update ripd to use new ibuf API

2023-06-22 Thread Claudio Jeker
Another ibuf_seek() -> ibuf_set_n16() conversions.
While there also switch to ibuf_data() and ibuf_size().

Anyone still uses ripd that can test this?
-- 
:wq Claudio

Index: auth.c
===
RCS file: /cvs/src/usr.sbin/ripd/auth.c,v
retrieving revision 1.12
diff -u -p -r1.12 auth.c
--- auth.c  19 Dec 2019 16:47:14 -  1.12
+++ auth.c  16 Jun 2023 10:29:23 -
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -236,14 +237,14 @@ auth_add_trailer(struct ibuf *buf, struc
MD5_CTX  hash;
u_int8_t digest[MD5_DIGEST_LENGTH];
struct auth_md  *md;
-   struct md5_auth *a;
-   int  pos;
+   size_t   pos;
 
-   pos = sizeof(struct rip_hdr) + sizeof(struct rip_auth);
+   pos = sizeof(struct rip_hdr) + sizeof(struct rip_auth) +
+   offsetof(struct md5_auth, auth_offset);
 
/* add offset to header */
-   a = ibuf_seek(buf, pos, sizeof(*a));
-   a->auth_offset = htons(buf->wpos);
+   if (ibuf_set_n16(buf, pos, ibuf_size(buf)) == -1)
+   return (-1);
 
/* insert plaintext key */
if ((md = md_list_find(>auth_md_list,
@@ -259,7 +260,7 @@ auth_add_trailer(struct ibuf *buf, struc
 
/* calculate MD5 digest */
MD5Init();
-   MD5Update(, buf->buf, buf->wpos);
+   MD5Update(, ibuf_data(buf), ibuf_size(buf));
MD5Update(, digest, MD5_DIGEST_LENGTH);
MD5Final(digest, );