Commit e437f3b6 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

mlxsw: spectrum: Distinguish between IPv4/6 tunnels

struct ip_tunnel_parm, where GRE and several other tunnel types hold
information, is IPv4-specific. The current router / ipip code in mlxsw
however uses it as if it were generic.

Make it clear that it's not. Rename many functions from _params_ to
_params4_. mlxsw_sp_ipip_parms_saddr() and _daddr() take a proto
argument to dispatch on it. Move the dispatch logic to
mlxsw_sp_ipip_netdev_saddr() and _daddr(), and replace with
single-protocol functions.

In struct mlxsw_sp_ipip_entry, move the "parms" field to a (for the time
being, singleton) union. Update users throughout.
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fe735a3d
...@@ -37,122 +37,89 @@ ...@@ -37,122 +37,89 @@
#include "spectrum_ipip.h" #include "spectrum_ipip.h"
struct ip_tunnel_parm struct ip_tunnel_parm
mlxsw_sp_ipip_netdev_parms(const struct net_device *ol_dev) mlxsw_sp_ipip_netdev_parms4(const struct net_device *ol_dev)
{ {
struct ip_tunnel *tun = netdev_priv(ol_dev); struct ip_tunnel *tun = netdev_priv(ol_dev);
return tun->parms; return tun->parms;
} }
static bool mlxsw_sp_ipip_parms_has_ikey(struct ip_tunnel_parm parms) static bool mlxsw_sp_ipip_parms4_has_ikey(struct ip_tunnel_parm parms)
{ {
return !!(parms.i_flags & TUNNEL_KEY); return !!(parms.i_flags & TUNNEL_KEY);
} }
static bool mlxsw_sp_ipip_parms_has_okey(struct ip_tunnel_parm parms) static bool mlxsw_sp_ipip_parms4_has_okey(struct ip_tunnel_parm parms)
{ {
return !!(parms.o_flags & TUNNEL_KEY); return !!(parms.o_flags & TUNNEL_KEY);
} }
static u32 mlxsw_sp_ipip_parms_ikey(struct ip_tunnel_parm parms) static u32 mlxsw_sp_ipip_parms4_ikey(struct ip_tunnel_parm parms)
{ {
return mlxsw_sp_ipip_parms_has_ikey(parms) ? return mlxsw_sp_ipip_parms4_has_ikey(parms) ?
be32_to_cpu(parms.i_key) : 0; be32_to_cpu(parms.i_key) : 0;
} }
static u32 mlxsw_sp_ipip_parms_okey(struct ip_tunnel_parm parms) static u32 mlxsw_sp_ipip_parms4_okey(struct ip_tunnel_parm parms)
{ {
return mlxsw_sp_ipip_parms_has_okey(parms) ? return mlxsw_sp_ipip_parms4_has_okey(parms) ?
be32_to_cpu(parms.o_key) : 0; be32_to_cpu(parms.o_key) : 0;
} }
static __be32 mlxsw_sp_ipip_parms_saddr4(struct ip_tunnel_parm parms) static union mlxsw_sp_l3addr
mlxsw_sp_ipip_parms4_saddr(struct ip_tunnel_parm parms)
{ {
return parms.iph.saddr; return (union mlxsw_sp_l3addr) { .addr4 = parms.iph.saddr };
} }
static union mlxsw_sp_l3addr static union mlxsw_sp_l3addr
mlxsw_sp_ipip_parms_saddr(enum mlxsw_sp_l3proto proto, mlxsw_sp_ipip_parms4_daddr(struct ip_tunnel_parm parms)
struct ip_tunnel_parm parms)
{ {
switch (proto) { return (union mlxsw_sp_l3addr) { .addr4 = parms.iph.daddr };
case MLXSW_SP_L3_PROTO_IPV4:
return (union mlxsw_sp_l3addr) {
.addr4 = mlxsw_sp_ipip_parms_saddr4(parms),
};
case MLXSW_SP_L3_PROTO_IPV6:
break;
}
WARN_ON(1);
return (union mlxsw_sp_l3addr) {
.addr4 = 0,
};
} }
static __be32 mlxsw_sp_ipip_parms_daddr4(struct ip_tunnel_parm parms) union mlxsw_sp_l3addr
mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto,
const struct net_device *ol_dev)
{ {
return parms.iph.daddr; struct ip_tunnel_parm parms4;
}
static union mlxsw_sp_l3addr
mlxsw_sp_ipip_parms_daddr(enum mlxsw_sp_l3proto proto,
struct ip_tunnel_parm parms)
{
switch (proto) { switch (proto) {
case MLXSW_SP_L3_PROTO_IPV4: case MLXSW_SP_L3_PROTO_IPV4:
return (union mlxsw_sp_l3addr) { parms4 = mlxsw_sp_ipip_netdev_parms4(ol_dev);
.addr4 = mlxsw_sp_ipip_parms_daddr4(parms), return mlxsw_sp_ipip_parms4_saddr(parms4);
};
case MLXSW_SP_L3_PROTO_IPV6: case MLXSW_SP_L3_PROTO_IPV6:
break; break;
} }
WARN_ON(1); WARN_ON(1);
return (union mlxsw_sp_l3addr) { return (union mlxsw_sp_l3addr) {0};
.addr4 = 0,
};
} }
static bool mlxsw_sp_ipip_netdev_has_ikey(const struct net_device *ol_dev) static __be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev)
{
return mlxsw_sp_ipip_parms_has_ikey(mlxsw_sp_ipip_netdev_parms(ol_dev));
}
static bool mlxsw_sp_ipip_netdev_has_okey(const struct net_device *ol_dev)
{
return mlxsw_sp_ipip_parms_has_okey(mlxsw_sp_ipip_netdev_parms(ol_dev));
}
static u32 mlxsw_sp_ipip_netdev_ikey(const struct net_device *ol_dev)
{
return mlxsw_sp_ipip_parms_ikey(mlxsw_sp_ipip_netdev_parms(ol_dev));
}
static u32 mlxsw_sp_ipip_netdev_okey(const struct net_device *ol_dev)
{ {
return mlxsw_sp_ipip_parms_okey(mlxsw_sp_ipip_netdev_parms(ol_dev));
}
union mlxsw_sp_l3addr struct ip_tunnel_parm parms4 = mlxsw_sp_ipip_netdev_parms4(ol_dev);
mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto,
const struct net_device *ol_dev)
{
return mlxsw_sp_ipip_parms_saddr(proto,
mlxsw_sp_ipip_netdev_parms(ol_dev));
}
static __be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev) return mlxsw_sp_ipip_parms4_daddr(parms4).addr4;
{
return mlxsw_sp_ipip_parms_daddr4(mlxsw_sp_ipip_netdev_parms(ol_dev));
} }
static union mlxsw_sp_l3addr static union mlxsw_sp_l3addr
mlxsw_sp_ipip_netdev_daddr(enum mlxsw_sp_l3proto proto, mlxsw_sp_ipip_netdev_daddr(enum mlxsw_sp_l3proto proto,
const struct net_device *ol_dev) const struct net_device *ol_dev)
{ {
return mlxsw_sp_ipip_parms_daddr(proto, struct ip_tunnel_parm parms4;
mlxsw_sp_ipip_netdev_parms(ol_dev));
switch (proto) {
case MLXSW_SP_L3_PROTO_IPV4:
parms4 = mlxsw_sp_ipip_netdev_parms4(ol_dev);
return mlxsw_sp_ipip_parms4_daddr(parms4);
case MLXSW_SP_L3_PROTO_IPV6:
break;
}
WARN_ON(1);
return (union mlxsw_sp_l3addr) {0};
} }
static int static int
...@@ -176,12 +143,17 @@ mlxsw_sp_ipip_fib_entry_op_gre4_rtdp(struct mlxsw_sp *mlxsw_sp, ...@@ -176,12 +143,17 @@ mlxsw_sp_ipip_fib_entry_op_gre4_rtdp(struct mlxsw_sp *mlxsw_sp,
u32 tunnel_index, u32 tunnel_index,
struct mlxsw_sp_ipip_entry *ipip_entry) struct mlxsw_sp_ipip_entry *ipip_entry)
{ {
bool has_ikey = mlxsw_sp_ipip_netdev_has_ikey(ipip_entry->ol_dev);
u16 rif_index = mlxsw_sp_ipip_lb_rif_index(ipip_entry->ol_lb); u16 rif_index = mlxsw_sp_ipip_lb_rif_index(ipip_entry->ol_lb);
u32 ikey = mlxsw_sp_ipip_netdev_ikey(ipip_entry->ol_dev);
char rtdp_pl[MLXSW_REG_RTDP_LEN]; char rtdp_pl[MLXSW_REG_RTDP_LEN];
struct ip_tunnel_parm parms;
unsigned int type_check; unsigned int type_check;
bool has_ikey;
u32 daddr4; u32 daddr4;
u32 ikey;
parms = mlxsw_sp_ipip_netdev_parms4(ipip_entry->ol_dev);
has_ikey = mlxsw_sp_ipip_parms4_has_ikey(parms);
ikey = mlxsw_sp_ipip_parms4_ikey(parms);
mlxsw_reg_rtdp_pack(rtdp_pl, MLXSW_REG_RTDP_TYPE_IPIP, tunnel_index); mlxsw_reg_rtdp_pack(rtdp_pl, MLXSW_REG_RTDP_TYPE_IPIP, tunnel_index);
...@@ -273,14 +245,15 @@ static struct mlxsw_sp_rif_ipip_lb_config ...@@ -273,14 +245,15 @@ static struct mlxsw_sp_rif_ipip_lb_config
mlxsw_sp_ipip_ol_loopback_config_gre4(struct mlxsw_sp *mlxsw_sp, mlxsw_sp_ipip_ol_loopback_config_gre4(struct mlxsw_sp *mlxsw_sp,
const struct net_device *ol_dev) const struct net_device *ol_dev)
{ {
struct ip_tunnel_parm parms = mlxsw_sp_ipip_netdev_parms4(ol_dev);
enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt; enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt;
lb_ipipt = mlxsw_sp_ipip_netdev_has_okey(ol_dev) ? lb_ipipt = mlxsw_sp_ipip_parms4_has_okey(parms) ?
MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_KEY_IN_IP : MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_KEY_IN_IP :
MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_IN_IP; MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_IN_IP;
return (struct mlxsw_sp_rif_ipip_lb_config){ return (struct mlxsw_sp_rif_ipip_lb_config){
.lb_ipipt = lb_ipipt, .lb_ipipt = lb_ipipt,
.okey = mlxsw_sp_ipip_netdev_okey(ol_dev), .okey = mlxsw_sp_ipip_parms4_okey(parms),
.ul_protocol = MLXSW_SP_L3_PROTO_IPV4, .ul_protocol = MLXSW_SP_L3_PROTO_IPV4,
.saddr = mlxsw_sp_ipip_netdev_saddr(MLXSW_SP_L3_PROTO_IPV4, .saddr = mlxsw_sp_ipip_netdev_saddr(MLXSW_SP_L3_PROTO_IPV4,
ol_dev), ol_dev),
...@@ -300,16 +273,12 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp, ...@@ -300,16 +273,12 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp,
bool update_nhs = false; bool update_nhs = false;
int err = 0; int err = 0;
new_parms = mlxsw_sp_ipip_netdev_parms(ipip_entry->ol_dev); new_parms = mlxsw_sp_ipip_netdev_parms4(ipip_entry->ol_dev);
new_saddr = mlxsw_sp_ipip_parms_saddr(MLXSW_SP_L3_PROTO_IPV4, new_saddr = mlxsw_sp_ipip_parms4_saddr(new_parms);
new_parms); old_saddr = mlxsw_sp_ipip_parms4_saddr(ipip_entry->parms4);
old_saddr = mlxsw_sp_ipip_parms_saddr(MLXSW_SP_L3_PROTO_IPV4, new_daddr = mlxsw_sp_ipip_parms4_daddr(new_parms);
ipip_entry->parms); old_daddr = mlxsw_sp_ipip_parms4_daddr(ipip_entry->parms4);
new_daddr = mlxsw_sp_ipip_parms_daddr(MLXSW_SP_L3_PROTO_IPV4,
new_parms);
old_daddr = mlxsw_sp_ipip_parms_daddr(MLXSW_SP_L3_PROTO_IPV4,
ipip_entry->parms);
if (!mlxsw_sp_l3addr_eq(&new_saddr, &old_saddr)) { if (!mlxsw_sp_l3addr_eq(&new_saddr, &old_saddr)) {
u16 ul_tb_id = mlxsw_sp_ipip_dev_ul_tb_id(ipip_entry->ol_dev); u16 ul_tb_id = mlxsw_sp_ipip_dev_ul_tb_id(ipip_entry->ol_dev);
...@@ -326,14 +295,14 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp, ...@@ -326,14 +295,14 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp,
} }
update_tunnel = true; update_tunnel = true;
} else if ((mlxsw_sp_ipip_parms_okey(ipip_entry->parms) != } else if ((mlxsw_sp_ipip_parms4_okey(ipip_entry->parms4) !=
mlxsw_sp_ipip_parms_okey(new_parms)) || mlxsw_sp_ipip_parms4_okey(new_parms)) ||
ipip_entry->parms.link != new_parms.link) { ipip_entry->parms4.link != new_parms.link) {
update_tunnel = true; update_tunnel = true;
} else if (!mlxsw_sp_l3addr_eq(&new_daddr, &old_daddr)) { } else if (!mlxsw_sp_l3addr_eq(&new_daddr, &old_daddr)) {
update_nhs = true; update_nhs = true;
} else if (mlxsw_sp_ipip_parms_ikey(ipip_entry->parms) != } else if (mlxsw_sp_ipip_parms4_ikey(ipip_entry->parms4) !=
mlxsw_sp_ipip_parms_ikey(new_parms)) { mlxsw_sp_ipip_parms4_ikey(new_parms)) {
update_decap = true; update_decap = true;
} }
...@@ -350,7 +319,7 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp, ...@@ -350,7 +319,7 @@ mlxsw_sp_ipip_ol_netdev_change_gre4(struct mlxsw_sp *mlxsw_sp,
false, false, false, false, false, false,
extack); extack);
ipip_entry->parms = new_parms; ipip_entry->parms4 = new_parms;
return err; return err;
} }
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include <linux/if_tunnel.h> #include <linux/if_tunnel.h>
struct ip_tunnel_parm struct ip_tunnel_parm
mlxsw_sp_ipip_netdev_parms(const struct net_device *ol_dev); mlxsw_sp_ipip_netdev_parms4(const struct net_device *ol_dev);
union mlxsw_sp_l3addr union mlxsw_sp_l3addr
mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto, mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto,
...@@ -57,7 +57,9 @@ struct mlxsw_sp_ipip_entry { ...@@ -57,7 +57,9 @@ struct mlxsw_sp_ipip_entry {
struct mlxsw_sp_rif_ipip_lb *ol_lb; struct mlxsw_sp_rif_ipip_lb *ol_lb;
struct mlxsw_sp_fib_entry *decap_fib_entry; struct mlxsw_sp_fib_entry *decap_fib_entry;
struct list_head ipip_list_node; struct list_head ipip_list_node;
struct ip_tunnel_parm parms; union {
struct ip_tunnel_parm parms4;
};
}; };
struct mlxsw_sp_ipip_ops { struct mlxsw_sp_ipip_ops {
......
/* /*
* drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c * drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
* Copyright (c) 2016-2017 Mellanox Technologies. All rights reserved. * Copyright (c) 2016-2018 Mellanox Technologies. All rights reserved.
* Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com> * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
* Copyright (c) 2016 Ido Schimmel <idosch@mellanox.com> * Copyright (c) 2016 Ido Schimmel <idosch@mellanox.com>
* Copyright (c) 2016 Yotam Gigi <yotamg@mellanox.com> * Copyright (c) 2016 Yotam Gigi <yotamg@mellanox.com>
* Copyright (c) 2017 Petr Machata <petrm@mellanox.com> * Copyright (c) 2017-2018 Petr Machata <petrm@mellanox.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -1020,9 +1020,11 @@ mlxsw_sp_ipip_entry_alloc(struct mlxsw_sp *mlxsw_sp, ...@@ -1020,9 +1020,11 @@ mlxsw_sp_ipip_entry_alloc(struct mlxsw_sp *mlxsw_sp,
enum mlxsw_sp_ipip_type ipipt, enum mlxsw_sp_ipip_type ipipt,
struct net_device *ol_dev) struct net_device *ol_dev)
{ {
const struct mlxsw_sp_ipip_ops *ipip_ops;
struct mlxsw_sp_ipip_entry *ipip_entry; struct mlxsw_sp_ipip_entry *ipip_entry;
struct mlxsw_sp_ipip_entry *ret = NULL; struct mlxsw_sp_ipip_entry *ret = NULL;
ipip_ops = mlxsw_sp->router->ipip_ops_arr[ipipt];
ipip_entry = kzalloc(sizeof(*ipip_entry), GFP_KERNEL); ipip_entry = kzalloc(sizeof(*ipip_entry), GFP_KERNEL);
if (!ipip_entry) if (!ipip_entry)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -1036,7 +1038,15 @@ mlxsw_sp_ipip_entry_alloc(struct mlxsw_sp *mlxsw_sp, ...@@ -1036,7 +1038,15 @@ mlxsw_sp_ipip_entry_alloc(struct mlxsw_sp *mlxsw_sp,
ipip_entry->ipipt = ipipt; ipip_entry->ipipt = ipipt;
ipip_entry->ol_dev = ol_dev; ipip_entry->ol_dev = ol_dev;
ipip_entry->parms = mlxsw_sp_ipip_netdev_parms(ol_dev);
switch (ipip_ops->ul_proto) {
case MLXSW_SP_L3_PROTO_IPV4:
ipip_entry->parms4 = mlxsw_sp_ipip_netdev_parms4(ol_dev);
break;
case MLXSW_SP_L3_PROTO_IPV6:
WARN_ON(1);
break;
}
return ipip_entry; return ipip_entry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment