Index | Thread | Search

From:
Denis Fondras <denis@openbsd.org>
Subject:
Re: bgpd: fix chash on big-endian archs
To:
tech@openbsd.org
Cc:
claudio@openbsd.org
Date:
Sat, 22 Nov 2025 16:21:51 +0100

Download raw body.

Thread
Le Sat, Nov 22, 2025 at 02:39:34PM +0100, Claudio Jeker a écrit :
> Oups, found by denis@ chash did not work on big-endian archs :(
> 
> The problem is cg_meta_set_hash() that did an array access into the 64bit
> cg_meta value. That is not endian safe. Instead do the write with a
> combination of shift and mask operations like all the other functions do.
> 
> With this the chash regress test pass both on sparc64 and amd64.
> Further tests welcome.

tested succesfully on octeon. Thanks for the fix.
OK denis@

> -- 
> :wq Claudio
> 
> Index: chash.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpd/chash.c,v
> diff -u -p -r1.4 chash.c
> --- chash.c	4 Nov 2025 13:07:14 -0000	1.4
> +++ chash.c	22 Nov 2025 13:26:28 -0000
> @@ -121,9 +121,13 @@ cg_meta_check_flags(const struct ch_grou
>  }
>  
>  static inline void
> -cg_meta_set_hash(struct ch_group *g, int slot, uint8_t hash)
> +cg_meta_set_hash(struct ch_group *g, int slot, uint64_t hash)
>  {
> -	((uint8_t *)&g->cg_meta)[slot] = hash;
> +	uint64_t newval;
> +
> +	newval = g->cg_meta & ~(0xffULL << (slot * 8));
> +	newval |= hash << (slot * 8);
> +	g->cg_meta = newval;
>  }
>  
>  /*
>