コード例 #1
0
ファイル: vxlan.c プロジェクト: 020gzh/linux
int mlx5e_vxlan_add_port(struct mlx5e_priv *priv, u16 port)
{
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	struct mlx5e_vxlan *vxlan;
	int err;

	err = mlx5e_vxlan_core_add_port_cmd(priv->mdev, port);
	if (err)
		return err;

	vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
	if (!vxlan) {
		err = -ENOMEM;
		goto err_delete_port;
	}

	vxlan->udp_port = port;

	spin_lock_irq(&vxlan_db->lock);
	err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan);
	spin_unlock_irq(&vxlan_db->lock);
	if (err)
		goto err_free;

	return 0;

err_free:
	kfree(vxlan);
err_delete_port:
	mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
	return err;
}
コード例 #2
0
ファイル: vxlan.c プロジェクト: 545191228/linux
static void mlx5e_vxlan_add_port(struct work_struct *work)
{
	struct mlx5e_vxlan_work *vxlan_work =
		container_of(work, struct mlx5e_vxlan_work, work);
	struct mlx5e_priv *priv = vxlan_work->priv;
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	u16 port = vxlan_work->port;
	struct mlx5e_vxlan *vxlan;
	int err;

	if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port))
		goto free_work;

	vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
	if (!vxlan)
		goto err_delete_port;

	vxlan->udp_port = port;

	spin_lock_irq(&vxlan_db->lock);
	err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan);
	spin_unlock_irq(&vxlan_db->lock);
	if (err)
		goto err_free;

	goto free_work;

err_free:
	kfree(vxlan);
err_delete_port:
	mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
free_work:
	kfree(vxlan_work);
}
コード例 #3
0
ファイル: vxlan.c プロジェクト: jelaas/bifrost-build-x86_64
static void mlx5e_vxlan_add_port(struct mlx5e_priv *priv, sa_family_t sa_family, u16 port)
{
	int err;
	u16 ethertype;
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	struct mlx5e_vxlan *vxlan;

	if (sa_family == AF_INET)
		ethertype = ETH_P_IP;
	else if (sa_family == AF_INET6)
		ethertype = ETH_P_IPV6;
	else
		return;

	if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port))
		return;

	vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
	if (!vxlan)
		goto err_delete_port;

	vxlan->udp_port = port;

	err = mlx5e_add_tunneling_rule(priv, MLX5E_TUNNEL_RULE_TYPE_VXLAN, port,
				       ethertype, &vxlan->flow_rule);
	if (err) {
		mlx5_core_warn(priv->mdev, "failed to add tunneling rule\n");
		goto err_free;
	}

	spin_lock_irq(&vxlan_db->lock);
	err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan);
	spin_unlock_irq(&vxlan_db->lock);
	if (err)
		goto err_free;

	if (mlx5_vxlan_debugfs_add(priv->mdev, vxlan))
		pr_warn("Failed to add VXLAN port %d to debugfs\n", vxlan->udp_port);

	return;

err_free:
	kfree(vxlan);
err_delete_port:
	mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
}