net/mlx5e: Re-order route and encap header memory allocation

Change the order to first route IPv4/6 and return if error. Only after
successful route continue to allocate an encap header, with no
functional change.

Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
This commit is contained in:
Eli Britstein 2018-12-03 17:09:54 +02:00 committed by Saeed Mahameed
parent 05ada1adb6
commit c7bcb277bd
1 changed files with 34 additions and 28 deletions

View File

@ -198,28 +198,16 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
struct mlx5e_encap_entry *e) struct mlx5e_encap_entry *e)
{ {
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size); int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
int ipv4_encap_size = ETH_HLEN +
sizeof(struct iphdr) +
e->tunnel_hlen;
struct ip_tunnel_key *tun_key = &e->tun_info.key; struct ip_tunnel_key *tun_key = &e->tun_info.key;
struct net_device *out_dev; struct net_device *out_dev;
struct neighbour *n = NULL; struct neighbour *n = NULL;
struct flowi4 fl4 = {}; struct flowi4 fl4 = {};
int ipv4_encap_size;
char *encap_header; char *encap_header;
u8 nud_state, ttl; u8 nud_state, ttl;
struct iphdr *ip; struct iphdr *ip;
int err; int err;
if (max_encap_size < ipv4_encap_size) {
mlx5_core_warn(priv->mdev, "encap size %d too big, max supported is %d\n",
ipv4_encap_size, max_encap_size);
return -EOPNOTSUPP;
}
encap_header = kzalloc(ipv4_encap_size, GFP_KERNEL);
if (!encap_header)
return -ENOMEM;
/* add the IP fields */ /* add the IP fields */
fl4.flowi4_tos = tun_key->tos; fl4.flowi4_tos = tun_key->tos;
fl4.daddr = tun_key->u.ipv4.dst; fl4.daddr = tun_key->u.ipv4.dst;
@ -229,7 +217,22 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
err = mlx5e_route_lookup_ipv4(priv, mirred_dev, &out_dev, err = mlx5e_route_lookup_ipv4(priv, mirred_dev, &out_dev,
&fl4, &n, &ttl); &fl4, &n, &ttl);
if (err) if (err)
goto free_encap; return err;
ipv4_encap_size =
ETH_HLEN +
sizeof(struct iphdr) +
e->tunnel_hlen;
if (max_encap_size < ipv4_encap_size) {
mlx5_core_warn(priv->mdev, "encap size %d too big, max supported is %d\n",
ipv4_encap_size, max_encap_size);
return -EOPNOTSUPP;
}
encap_header = kzalloc(ipv4_encap_size, GFP_KERNEL);
if (!encap_header)
return -ENOMEM;
/* used by mlx5e_detach_encap to lookup a neigh hash table /* used by mlx5e_detach_encap to lookup a neigh hash table
* entry in the neigh hash table when a user deletes a rule * entry in the neigh hash table when a user deletes a rule
@ -308,28 +311,16 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
struct mlx5e_encap_entry *e) struct mlx5e_encap_entry *e)
{ {
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size); int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
int ipv6_encap_size = ETH_HLEN +
sizeof(struct ipv6hdr) +
e->tunnel_hlen;
struct ip_tunnel_key *tun_key = &e->tun_info.key; struct ip_tunnel_key *tun_key = &e->tun_info.key;
struct net_device *out_dev; struct net_device *out_dev;
struct neighbour *n = NULL; struct neighbour *n = NULL;
struct flowi6 fl6 = {}; struct flowi6 fl6 = {};
struct ipv6hdr *ip6h; struct ipv6hdr *ip6h;
int ipv6_encap_size;
char *encap_header; char *encap_header;
u8 nud_state, ttl; u8 nud_state, ttl;
int err; int err;
if (max_encap_size < ipv6_encap_size) {
mlx5_core_warn(priv->mdev, "encap size %d too big, max supported is %d\n",
ipv6_encap_size, max_encap_size);
return -EOPNOTSUPP;
}
encap_header = kzalloc(ipv6_encap_size, GFP_KERNEL);
if (!encap_header)
return -ENOMEM;
ttl = tun_key->ttl; ttl = tun_key->ttl;
fl6.flowlabel = ip6_make_flowinfo(RT_TOS(tun_key->tos), tun_key->label); fl6.flowlabel = ip6_make_flowinfo(RT_TOS(tun_key->tos), tun_key->label);
@ -339,7 +330,22 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
err = mlx5e_route_lookup_ipv6(priv, mirred_dev, &out_dev, err = mlx5e_route_lookup_ipv6(priv, mirred_dev, &out_dev,
&fl6, &n, &ttl); &fl6, &n, &ttl);
if (err) if (err)
goto free_encap; return err;
ipv6_encap_size =
ETH_HLEN +
sizeof(struct ipv6hdr) +
e->tunnel_hlen;
if (max_encap_size < ipv6_encap_size) {
mlx5_core_warn(priv->mdev, "encap size %d too big, max supported is %d\n",
ipv6_encap_size, max_encap_size);
return -EOPNOTSUPP;
}
encap_header = kzalloc(ipv6_encap_size, GFP_KERNEL);
if (!encap_header)
return -ENOMEM;
/* used by mlx5e_detach_encap to lookup a neigh hash table /* used by mlx5e_detach_encap to lookup a neigh hash table
* entry in the neigh hash table when a user deletes a rule * entry in the neigh hash table when a user deletes a rule