mlxsw: spectrum_ipip: Split accessor functions
To implement NETDEV_CHANGE notifications on IP-in-IP tunnels, the handler needs to figure out what actually changed, to understand how exactly to update the offloads. It will do so by storing struct ip_tunnel_parm with previous configuration, and comparing that to the new version. To facilitate these comparisons, extract the code that operates on struct ip_tunnel_parm from the existing accessor functions, and make those a thin wrapper that extracts tunnel parameters and dispatches. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>hifive-unleashed-5.1
parent
474f0ff618
commit
9fb7bd77d1
|
@ -36,89 +36,123 @@
|
||||||
|
|
||||||
#include "spectrum_ipip.h"
|
#include "spectrum_ipip.h"
|
||||||
|
|
||||||
static bool
|
struct ip_tunnel_parm
|
||||||
mlxsw_sp_ipip_netdev_has_ikey(const struct net_device *ol_dev)
|
mlxsw_sp_ipip_netdev_parms(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.i_flags & TUNNEL_KEY);
|
return tun->parms;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool mlxsw_sp_ipip_parms_has_ikey(struct ip_tunnel_parm parms)
|
||||||
mlxsw_sp_ipip_netdev_has_okey(const struct net_device *ol_dev)
|
|
||||||
{
|
{
|
||||||
struct ip_tunnel *tun = netdev_priv(ol_dev);
|
return !!(parms.i_flags & TUNNEL_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
return !!(tun->parms.o_flags & TUNNEL_KEY);
|
static bool mlxsw_sp_ipip_parms_has_okey(struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
return !!(parms.o_flags & TUNNEL_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 mlxsw_sp_ipip_parms_ikey(struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
return mlxsw_sp_ipip_parms_has_ikey(parms) ?
|
||||||
|
be32_to_cpu(parms.i_key) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 mlxsw_sp_ipip_parms_okey(struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
return mlxsw_sp_ipip_parms_has_okey(parms) ?
|
||||||
|
be32_to_cpu(parms.o_key) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __be32 mlxsw_sp_ipip_parms_saddr4(struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
return parms.iph.saddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static union mlxsw_sp_l3addr
|
||||||
|
mlxsw_sp_ipip_parms_saddr(enum mlxsw_sp_l3proto proto,
|
||||||
|
struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
switch (proto) {
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return parms.iph.daddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static union mlxsw_sp_l3addr
|
||||||
|
mlxsw_sp_ipip_parms_daddr(enum mlxsw_sp_l3proto proto,
|
||||||
|
struct ip_tunnel_parm parms)
|
||||||
|
{
|
||||||
|
switch (proto) {
|
||||||
|
case MLXSW_SP_L3_PROTO_IPV4:
|
||||||
|
return (union mlxsw_sp_l3addr) {
|
||||||
|
.addr4 = mlxsw_sp_ipip_parms_daddr4(parms),
|
||||||
|
};
|
||||||
|
case MLXSW_SP_L3_PROTO_IPV6:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
WARN_ON(1);
|
||||||
|
return (union mlxsw_sp_l3addr) {
|
||||||
|
.addr4 = 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool mlxsw_sp_ipip_netdev_has_ikey(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)
|
static u32 mlxsw_sp_ipip_netdev_ikey(const struct net_device *ol_dev)
|
||||||
{
|
{
|
||||||
struct ip_tunnel *tun = netdev_priv(ol_dev);
|
return mlxsw_sp_ipip_parms_ikey(mlxsw_sp_ipip_netdev_parms(ol_dev));
|
||||||
|
|
||||||
return mlxsw_sp_ipip_netdev_has_ikey(ol_dev) ?
|
|
||||||
be32_to_cpu(tun->parms.i_key) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 mlxsw_sp_ipip_netdev_okey(const struct net_device *ol_dev)
|
static u32 mlxsw_sp_ipip_netdev_okey(const struct net_device *ol_dev)
|
||||||
{
|
{
|
||||||
struct ip_tunnel *tun = netdev_priv(ol_dev);
|
return mlxsw_sp_ipip_parms_okey(mlxsw_sp_ipip_netdev_parms(ol_dev));
|
||||||
|
|
||||||
return mlxsw_sp_ipip_netdev_has_okey(ol_dev) ?
|
|
||||||
be32_to_cpu(tun->parms.o_key) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __be32
|
|
||||||
mlxsw_sp_ipip_netdev_saddr4(const struct net_device *ol_dev)
|
|
||||||
{
|
|
||||||
struct ip_tunnel *tun = netdev_priv(ol_dev);
|
|
||||||
|
|
||||||
return tun->parms.iph.saddr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
const struct net_device *ol_dev)
|
const struct net_device *ol_dev)
|
||||||
{
|
{
|
||||||
switch (proto) {
|
return mlxsw_sp_ipip_parms_saddr(proto,
|
||||||
case MLXSW_SP_L3_PROTO_IPV4:
|
mlxsw_sp_ipip_netdev_parms(ol_dev));
|
||||||
return (union mlxsw_sp_l3addr) {
|
|
||||||
.addr4 = mlxsw_sp_ipip_netdev_saddr4(ol_dev),
|
|
||||||
};
|
|
||||||
case MLXSW_SP_L3_PROTO_IPV6:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
WARN_ON(1);
|
|
||||||
return (union mlxsw_sp_l3addr) {
|
|
||||||
.addr4 = 0,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static __be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev)
|
static __be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev)
|
||||||
{
|
{
|
||||||
struct ip_tunnel *tun = netdev_priv(ol_dev);
|
return mlxsw_sp_ipip_parms_daddr4(mlxsw_sp_ipip_netdev_parms(ol_dev));
|
||||||
|
|
||||||
return tun->parms.iph.daddr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
switch (proto) {
|
return mlxsw_sp_ipip_parms_daddr(proto,
|
||||||
case MLXSW_SP_L3_PROTO_IPV4:
|
mlxsw_sp_ipip_netdev_parms(ol_dev));
|
||||||
return (union mlxsw_sp_l3addr) {
|
|
||||||
.addr4 = mlxsw_sp_ipip_netdev_daddr4(ol_dev),
|
|
||||||
};
|
|
||||||
case MLXSW_SP_L3_PROTO_IPV6:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
WARN_ON(1);
|
|
||||||
return (union mlxsw_sp_l3addr) {
|
|
||||||
.addr4 = 0,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
#include "spectrum_router.h"
|
#include "spectrum_router.h"
|
||||||
#include <net/ip_fib.h>
|
#include <net/ip_fib.h>
|
||||||
|
|
||||||
|
struct ip_tunnel_parm
|
||||||
|
mlxsw_sp_ipip_netdev_parms(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,
|
||||||
const struct net_device *ol_dev);
|
const struct net_device *ol_dev);
|
||||||
|
|
Loading…
Reference in New Issue