[PATCH 5/6] Add hash support to neigh cache

Thomas Graf tgraf at suug.ch
Mon Nov 5 07:13:44 EST 2012


On 11/04/12 at 09:13pm, roopa at cumulusnetworks.com wrote:
> +static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
> +			 uint32_t table_sz)
> +{
> +	struct rtnl_neigh *neigh = (struct rtnl_neigh *) obj;
> +	struct neigh_hash_key *_key;
> +	char *_key_b;
> +	unsigned int _key_sz;
> +	unsigned int sz_dst = 0;
> +	void *dst = NULL;
> +	struct neigh_hash_key {
> +		uint32_t	n_family;
> +		uint32_t	n_ifindex;
> +		void 		*n_addr;
> +	};
> +
> +	if (neigh->n_dst) {
> +	    sz_dst = nl_addr_get_len(neigh->n_dst);
> +	    dst = nl_addr_get_binary_addr(neigh->n_dst);
> +	}
> +
> +	_key_sz = sizeof(struct neigh_hash_key) -
> +			sizeof(void *) + sz_dst;

Can you write the keygen functions like this:

struct neigh_hash_key {
	uint32_t	n_family;
	uint32_t	n_ifindex;
	void *		n_addr[0];
};

key_sz = sizeof(struct neigh_hash_key);
if (neigh->n_dst)
	key_sz += nl_addr_get_len(neigh->n_dst);

key = alloca(key_sz);
[...]

if (neigh->n_dst)
        memcpy(key->n_addr, nl_addr_get_binary_addr(neigh->n_dst),
	       nl_addr_get_len(neigh->n_dst));
[...]

That puts the key structure onto the stack which is fine for this.



More information about the libnl mailing list