src/dpdk/drivers/common/mlx5/linux/mlx5_nl.c
static int
mlx5_nl_switch_info_cb(struct nlmsghdr *nh, void *arg)
{
	struct mlx5_switch_info info = {
		.master = 0,
		.representor = 0,
		.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET,
		.port_name = 0,
		.switch_id = 0,
	};
	size_t off = NLMSG_LENGTH(sizeof(struct ifinfomsg));
	bool switch_id_set = false;
	bool num_vf_set = false;

	if (nh->nlmsg_type != RTM_NEWLINK)
		goto error;
	while (off < nh->nlmsg_len) {
		struct rtattr *ra = (void *)((uintptr_t)nh + off);
		void *payload = RTA_DATA(ra);
		unsigned int i;

		if (ra->rta_len > nh->nlmsg_len - off)
			goto error;
		switch (ra->rta_type) {
		case IFLA_NUM_VF:
			num_vf_set = true;
			break;
		case IFLA_PHYS_PORT_NAME:
			mlx5_translate_port_name((char *)payload, &info);
			break;
		case IFLA_PHYS_SWITCH_ID:
			info.switch_id = 0;
			for (i = 0; i < RTA_PAYLOAD(ra); ++i) {
				info.switch_id <<= 8;
				info.switch_id |= ((uint8_t *)payload)[i];
			}
			switch_id_set = true;
			break;
		}
		off += RTA_ALIGN(ra->rta_len);
	}
	if (switch_id_set) {
		/* We have some E-Switch configuration. */
		mlx5_nl_check_switch_info(num_vf_set, &info);
	}
	MLX5_ASSERT(!(info.master && info.representor));
	memcpy(arg, &info, sizeof(info));
	return 0;
error:
	rte_errno = EINVAL;
	return -rte_errno;
}
/**
 * Process switch 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 switch 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 switch 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_switch_info_cb(struct nlmsghdr *nh, void *arg)
{
	struct mlx5_switch_info info = {
		.master = 0,
		.representor = 0,
		.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET,
		.port_name = 0,
		.switch_id = 0,
	};
	size_t off = NLMSG_LENGTH(sizeof(struct ifinfomsg));
	bool switch_id_set = false;
	bool num_vf_set = false;
	if (nh->nlmsg_type != RTM_NEWLINK)
		goto error;
	while (off < nh->nlmsg_len) {
		struct rtattr *ra = (void *)((uintptr_t)nh + off);
		void *payload = RTA_DATA(ra);
		unsigned int i;
		if (ra->rta_len > nh->nlmsg_len - off)
			goto error;
		switch (ra->rta_type) {
		case IFLA_NUM_VF:
			num_vf_set = true;
			break;
		case IFLA_PHYS_PORT_NAME:
			mlx5_translate_port_name((char *)payload, &info);
			break;
		case IFLA_PHYS_SWITCH_ID:
			info.switch_id = 0;
			for (i = 0; i < RTA_PAYLOAD(ra); ++i) {
				info.switch_id <<= 8;
				info.switch_id |= ((uint8_t *)payload)[i];
			}
			switch_id_set = true;
			break;
		}
		off += RTA_ALIGN(ra->rta_len);
	}
	if (switch_id_set) {
		mlx5_nl_check_switch_info(num_vf_set, &info);
	}
	MLX5_ASSERT(!(info.master && info.representor));
	memcpy(arg, &info, sizeof(info));
	return 0;
error:
	rte_errno = EINVAL;
	return -rte_errno;
}
static int mlx5_nl_switch_info_cb ( struct nlmsghdr * nh , void * arg ) { struct mlx5_switch_info info = { . master = 0 , . representor = 0 , . name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET , . port_name = 0 , . switch_id = 0 , } ; size_t off = NLMSG_LENGTH ( sizeof ( struct ifinfomsg ) ) ; bool switch_id_set = false ; bool num_vf_set = false ; if ( nh -> nlmsg_type != RTM_NEWLINK ) goto error ; while ( off < nh -> nlmsg_len ) { struct rtattr * ra = ( void * ) ( ( uintptr_t ) nh + off ) ; void * payload = RTA_DATA ( ra ) ; unsigned int i ; if ( ra -> rta_len > nh -> nlmsg_len - off ) goto error ; switch ( ra -> rta_type ) { case IFLA_NUM_VF : num_vf_set = true ; break ; case IFLA_PHYS_PORT_NAME : mlx5_translate_port_name ( ( char * ) payload , & info ) ; break ; case IFLA_PHYS_SWITCH_ID : info . switch_id = 0 ; for ( i = 0 ; i < RTA_PAYLOAD ( ra ) ; ++ i ) { info . switch_id <<= 8 ; info . switch_id |= ( ( uint8_t * ) payload ) [ i ] ; } switch_id_set = true ; break ; } off += RTA_ALIGN ( ra -> rta_len ) ; } if ( switch_id_set ) { mlx5_nl_check_switch_info ( num_vf_set , & info ) ; } MLX5_ASSERT ( ! ( info . master && info . representor ) ) ; memcpy ( arg , & info , sizeof ( info ) ) ; return 0 ; error : rte_errno = EINVAL ; return - rte_errno ; }
Process switch information from Netlink message.
Process switch information from Netlink message .
/* We have some E-Switch configuration. */