Re: [PATCH rdma-next v1 1/2] RDMA/core: Add an rb_tree that stores cm_ids sorted by ifindex and remote IP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 19, 2022 at 07:41:22AM +0300, Leon Romanovsky wrote:

> +static int compare_netdev_and_ip(int ifindex_a, struct sockaddr *sa,
> +				 struct id_table_entry *entry_b)
> +{
> +	struct rdma_id_private *id_priv = list_first_entry(
> +		&entry_b->id_list, struct rdma_id_private, id_list_entry);
> +	int ifindex_b = id_priv->id.route.addr.dev_addr.bound_dev_if;
> +	struct sockaddr *sb = cma_dst_addr(id_priv);
> +
> +	if (ifindex_a != ifindex_b)
> +		return (ifindex_a > ifindex_b) ? 1 : -1;
> +
> +	if (sa->sa_family != sb->sa_family)
> +		return sa->sa_family - sb->sa_family;
> +
> +	if (sa->sa_family == AF_INET)
> +		return (int)__be32_to_cpu(
> +			       ((struct sockaddr_in *)sa)->sin_addr.s_addr) -
> +		       (int)__be32_to_cpu(
> +			       ((struct sockaddr_in *)sb)->sin_addr.s_addr);

This still overflows, just use memcmp

> +	return memcmp((char *)&((struct sockaddr_in6 *)sa)->sin6_addr,
> +		      (char *)&((struct sockaddr_in6 *)sb)->sin6_addr,
> +		      sizeof(((struct sockaddr_in6 *)sa)->sin6_addr));

This is ipv6_addr_cmp()

Jason



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux