src/dpdk/drivers/common/mlx5/linux/mlx5_nl.c
static int
mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
{
	struct mlx5_nl_ifindex_data *data = arg;
	struct mlx5_nl_ifindex_data local = {
		.flags = 0,
	};
	size_t off = NLMSG_HDRLEN;

	if (nh->nlmsg_type !=
	    RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET) &&
	    nh->nlmsg_type !=
	    RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_PORT_GET))
		goto error;
	while (off < nh->nlmsg_len) {
		struct nlattr *na = (void *)((uintptr_t)nh + off);
		void *payload = (void *)((uintptr_t)na + NLA_HDRLEN);

		if (na->nla_len > nh->nlmsg_len - off)
			goto error;
		switch (na->nla_type) {
		case RDMA_NLDEV_ATTR_DEV_INDEX:
			local.ibindex = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_IB_INDEX;
			break;
		case RDMA_NLDEV_ATTR_DEV_NAME:
			if (!strcmp(payload, data->name))
				local.flags |= MLX5_NL_CMD_GET_IB_NAME;
			break;
		case RDMA_NLDEV_ATTR_NDEV_INDEX:
			local.ifindex = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_NET_INDEX;
			break;
		case RDMA_NLDEV_ATTR_PORT_INDEX:
			local.portnum = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_PORT_INDEX;
			break;
		default:
			break;
		}
		off += NLA_ALIGN(na->nla_len);
	}
	/*
	 * It is possible to have multiple messages for all
	 * Infiniband devices in the system with appropriate name.
	 * So we should gather parameters locally and copy to
	 * query context only in case of coinciding device name.
	 */
	if (local.flags & MLX5_NL_CMD_GET_IB_NAME) {
		data->flags = local.flags;
		data->ibindex = local.ibindex;
		data->ifindex = local.ifindex;
		data->portnum = local.portnum;
	}
	return 0;
error:
	rte_errno = EINVAL;
	return -rte_errno;
}
/**
 * Process network interface information from Netlink message.
 *
 * @param nh
 *   Pointer to Netlink message header.
 * @param arg
 *   Opaque data pointer for this callback.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
Process network interface information from Netlink message.
@param nh
Pointer to Netlink message header.
@param arg
Opaque data pointer for this callback.

@return
0 on success, a negative errno value otherwise and rte_errno is set.
Process network interface information from Netlink message . @param nh Pointer to Netlink message header . @param arg Opaque data pointer for this callback . @return 0 on success a negative errno value otherwise and rte_errno is set .
static int
mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
{
	struct mlx5_nl_ifindex_data *data = arg;
	struct mlx5_nl_ifindex_data local = {
		.flags = 0,
	};
	size_t off = NLMSG_HDRLEN;
	if (nh->nlmsg_type !=
	    RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET) &&
	    nh->nlmsg_type !=
	    RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_PORT_GET))
		goto error;
	while (off < nh->nlmsg_len) {
		struct nlattr *na = (void *)((uintptr_t)nh + off);
		void *payload = (void *)((uintptr_t)na + NLA_HDRLEN);
		if (na->nla_len > nh->nlmsg_len - off)
			goto error;
		switch (na->nla_type) {
		case RDMA_NLDEV_ATTR_DEV_INDEX:
			local.ibindex = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_IB_INDEX;
			break;
		case RDMA_NLDEV_ATTR_DEV_NAME:
			if (!strcmp(payload, data->name))
				local.flags |= MLX5_NL_CMD_GET_IB_NAME;
			break;
		case RDMA_NLDEV_ATTR_NDEV_INDEX:
			local.ifindex = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_NET_INDEX;
			break;
		case RDMA_NLDEV_ATTR_PORT_INDEX:
			local.portnum = *(uint32_t *)payload;
			local.flags |= MLX5_NL_CMD_GET_PORT_INDEX;
			break;
		default:
			break;
		}
		off += NLA_ALIGN(na->nla_len);
	}
	if (local.flags & MLX5_NL_CMD_GET_IB_NAME) {
		data->flags = local.flags;
		data->ibindex = local.ibindex;
		data->ifindex = local.ifindex;
		data->portnum = local.portnum;
	}
	return 0;
error:
	rte_errno = EINVAL;
	return -rte_errno;
}
static int mlx5_nl_cmdget_cb ( struct nlmsghdr * nh , void * arg ) { struct mlx5_nl_ifindex_data * data = arg ; struct mlx5_nl_ifindex_data local = { . flags = 0 , } ; size_t off = NLMSG_HDRLEN ; if ( nh -> nlmsg_type != RDMA_NL_GET_TYPE ( RDMA_NL_NLDEV , RDMA_NLDEV_CMD_GET ) && nh -> nlmsg_type != RDMA_NL_GET_TYPE ( RDMA_NL_NLDEV , RDMA_NLDEV_CMD_PORT_GET ) ) goto error ; while ( off < nh -> nlmsg_len ) { struct nlattr * na = ( void * ) ( ( uintptr_t ) nh + off ) ; void * payload = ( void * ) ( ( uintptr_t ) na + NLA_HDRLEN ) ; if ( na -> nla_len > nh -> nlmsg_len - off ) goto error ; switch ( na -> nla_type ) { case RDMA_NLDEV_ATTR_DEV_INDEX : local . ibindex = * ( uint32_t * ) payload ; local . flags |= MLX5_NL_CMD_GET_IB_INDEX ; break ; case RDMA_NLDEV_ATTR_DEV_NAME : if ( ! strcmp ( payload , data -> name ) ) local . flags |= MLX5_NL_CMD_GET_IB_NAME ; break ; case RDMA_NLDEV_ATTR_NDEV_INDEX : local . ifindex = * ( uint32_t * ) payload ; local . flags |= MLX5_NL_CMD_GET_NET_INDEX ; break ; case RDMA_NLDEV_ATTR_PORT_INDEX : local . portnum = * ( uint32_t * ) payload ; local . flags |= MLX5_NL_CMD_GET_PORT_INDEX ; break ; default : break ; } off += NLA_ALIGN ( na -> nla_len ) ; } if ( local . flags & MLX5_NL_CMD_GET_IB_NAME ) { data -> flags = local . flags ; data -> ibindex = local . ibindex ; data -> ifindex = local . ifindex ; data -> portnum = local . portnum ; } return 0 ; error : rte_errno = EINVAL ; return - rte_errno ; }
Process network interface information from Netlink message.
Process network interface information from Netlink message .
/*
	 * It is possible to have multiple messages for all
	 * Infiniband devices in the system with appropriate name.
	 * So we should gather parameters locally and copy to
	 * query context only in case of coinciding device name.
	 */