On Sun, Jul 16, 2023 at 04:24:15PM +0200, Claudio Jeker wrote:
> Rename ibuf_get() to ibuf_getdata() by merging the two functions together.
> I want to use ibuf_get() as part of the ibuf API so this needs to move.
> Also use ibuf_add_zero() in a place of ibuf_reserve() and remove a check
> for buf->buf == NULL in ibuf_length() which has nothing to do there.
> 
> -- 
> :wq Claudio

ok tobhe@

> 
> Index: iked.h
> ===================================================================
> RCS file: /cvs/src/sbin/iked/iked.h,v
> retrieving revision 1.220
> diff -u -p -r1.220 iked.h
> --- iked.h    28 Jun 2023 14:10:24 -0000      1.220
> +++ iked.h    16 Jul 2023 13:45:20 -0000
> @@ -1271,9 +1271,8 @@ struct ibuf *
>  int   ibuf_cat(struct ibuf *, struct ibuf *);
>  size_t        ibuf_length(struct ibuf *);
>  int   ibuf_setsize(struct ibuf *, size_t);
> -void *ibuf_getdata(struct ibuf *, size_t);
>  struct ibuf *
> -      ibuf_get(struct ibuf *, size_t);
> +      ibuf_getdata(struct ibuf *, size_t);
>  struct ibuf *
>        ibuf_dup(struct ibuf *);
>  struct ibuf *
> Index: ikev2.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/ikev2.c,v
> retrieving revision 1.372
> diff -u -p -r1.372 ikev2.c
> --- ikev2.c   28 Jun 2023 14:10:24 -0000      1.372
> +++ ikev2.c   16 Jul 2023 13:54:01 -0000
> @@ -5829,16 +5829,20 @@ ikev2_sa_keys(struct iked *env, struct i
>               goto done;
>       }
>  
> -     /* ibuf_get() returns a new buffer from the next read offset */
> -     if ((sa->sa_key_d = ibuf_get(t, hash_length(prf))) == NULL ||
> +     /* ibuf_getdata() returns a new buffer from the next read offset */
> +     if ((sa->sa_key_d = ibuf_getdata(t, hash_length(prf))) == NULL ||
>           (!isaead &&
> -         (sa->sa_key_iauth = ibuf_get(t, hash_keylength(integr))) == NULL) ||
> +         (sa->sa_key_iauth = ibuf_getdata(t, hash_keylength(integr))) ==
> +         NULL) ||
>           (!isaead &&
> -         (sa->sa_key_rauth = ibuf_get(t, hash_keylength(integr))) == NULL) ||
> -         (sa->sa_key_iencr = ibuf_get(t, cipher_keylength(encr))) == NULL ||
> -         (sa->sa_key_rencr = ibuf_get(t, cipher_keylength(encr))) == NULL ||
> -         (sa->sa_key_iprf = ibuf_get(t, hash_length(prf))) == NULL ||
> -         (sa->sa_key_rprf = ibuf_get(t, hash_length(prf))) == NULL) {
> +         (sa->sa_key_rauth = ibuf_getdata(t, hash_keylength(integr))) ==
> +         NULL) ||
> +         (sa->sa_key_iencr = ibuf_getdata(t, cipher_keylength(encr))) ==
> +         NULL ||
> +         (sa->sa_key_rencr = ibuf_getdata(t, cipher_keylength(encr))) ==
> +         NULL ||
> +         (sa->sa_key_iprf = ibuf_getdata(t, hash_length(prf))) == NULL ||
> +         (sa->sa_key_rprf = ibuf_getdata(t, hash_length(prf))) == NULL) {
>               log_debug("%s: failed to get SA keys", SPI_SA(sa, __func__));
>               goto done;
>       }
> @@ -6307,13 +6311,13 @@ ikev2_childsa_negotiate(struct iked *env
>                       csa->csa_spi.spi_size = 4;
>               }
>  
> -             if (encrxf && (csa->csa_encrkey = ibuf_get(keymat,
> +             if (encrxf && (csa->csa_encrkey = ibuf_getdata(keymat,
>                   encrxf->xform_keylength / 8)) == NULL) {
>                       log_debug("%s: failed to get CHILD SA encryption key",
>                           __func__);
>                       goto done;
>               }
> -             if (integrxf && (csa->csa_integrkey = ibuf_get(keymat,
> +             if (integrxf && (csa->csa_integrkey = ibuf_getdata(keymat,
>                   integrxf->xform_keylength / 8)) == NULL) {
>                       log_debug("%s: failed to get CHILD SA integrity key",
>                           __func__);
> @@ -6340,13 +6344,13 @@ ikev2_childsa_negotiate(struct iked *env
>               csb->csa_local = csa->csa_peer;
>               csb->csa_peer = csa->csa_local;
>  
> -             if (encrxf && (csb->csa_encrkey = ibuf_get(keymat,
> +             if (encrxf && (csb->csa_encrkey = ibuf_getdata(keymat,
>                   encrxf->xform_keylength / 8)) == NULL) {
>                       log_debug("%s: failed to get CHILD SA encryption key",
>                           __func__);
>                       goto done;
>               }
> -             if (integrxf && (csb->csa_integrkey = ibuf_get(keymat,
> +             if (integrxf && (csb->csa_integrkey = ibuf_getdata(keymat,
>                   integrxf->xform_keylength / 8)) == NULL) {
>                       log_debug("%s: failed to get CHILD SA integrity key",
>                           __func__);
> Index: imsg_util.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/imsg_util.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 imsg_util.c
> --- imsg_util.c       19 Jun 2023 17:19:50 -0000      1.19
> +++ imsg_util.c       16 Jul 2023 13:59:29 -0000
> @@ -55,7 +55,7 @@ ibuf_new(const void *data, size_t len)
>               return (buf);
>  
>       if (data == NULL) {
> -             if (ibuf_reserve(buf, len) == NULL) {
> +             if (ibuf_add_zero(buf, len) != 0) {
>                       ibuf_free(buf);
>                       return (NULL);
>               }
> @@ -78,12 +78,12 @@ ibuf_static(void)
>  size_t
>  ibuf_length(struct ibuf *buf)
>  {
> -     if (buf == NULL || buf->buf == NULL)
> +     if (buf == NULL)
>               return (0);
>       return (ibuf_size(buf));
>  }
>  
> -void *
> +struct ibuf *
>  ibuf_getdata(struct ibuf *buf, size_t len)
>  {
>       void    *data;
> @@ -91,17 +91,6 @@ ibuf_getdata(struct ibuf *buf, size_t le
>       if ((data = ibuf_seek(buf, buf->rpos, len)) == NULL)
>               return (NULL);
>       buf->rpos += len;
> -
> -     return (data);
> -}
> -
> -struct ibuf *
> -ibuf_get(struct ibuf *buf, size_t len)
> -{
> -     void            *data;
> -
> -     if ((data = ibuf_getdata(buf, len)) == NULL)
> -             return (NULL);
>  
>       return (ibuf_new(data, len));
>  }
> 

Reply via email to