Commit dc9c0753 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

netdevsim: shared UDP tunnel port table support

Add the ability to simulate a device with a shared UDP tunnel port
table.

Try to reject the configurations and actions which are not supported
by the core, so we don't get syzcaller etc. warning reports.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 860e9d32
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/u64_stats_sync.h> #include <linux/u64_stats_sync.h>
#include <net/devlink.h> #include <net/devlink.h>
#include <net/udp_tunnel.h>
#include <net/xdp.h> #include <net/xdp.h>
#define DRV_NAME "netdevsim" #define DRV_NAME "netdevsim"
...@@ -84,7 +85,8 @@ struct netdevsim { ...@@ -84,7 +85,8 @@ struct netdevsim {
struct { struct {
u32 inject_error; u32 inject_error;
u32 sleep; u32 sleep;
u32 ports[2][NSIM_UDP_TUNNEL_N_PORTS]; u32 __ports[2][NSIM_UDP_TUNNEL_N_PORTS];
u32 (*ports)[NSIM_UDP_TUNNEL_N_PORTS];
struct debugfs_u32_array dfs_ports[2]; struct debugfs_u32_array dfs_ports[2];
} udp_ports; } udp_ports;
...@@ -209,9 +211,12 @@ struct nsim_dev { ...@@ -209,9 +211,12 @@ struct nsim_dev {
bool fail_trap_policer_set; bool fail_trap_policer_set;
bool fail_trap_policer_counter_get; bool fail_trap_policer_counter_get;
struct { struct {
struct udp_tunnel_nic_shared utn_shared;
u32 __ports[2][NSIM_UDP_TUNNEL_N_PORTS];
bool sync_all; bool sync_all;
bool open_only; bool open_only;
bool ipv4_only; bool ipv4_only;
bool shared;
u32 sleep; u32 sleep;
} udp_ports; } udp_ports;
}; };
......
...@@ -112,7 +112,7 @@ nsim_udp_tunnels_info_reset_write(struct file *file, const char __user *data, ...@@ -112,7 +112,7 @@ nsim_udp_tunnels_info_reset_write(struct file *file, const char __user *data,
struct net_device *dev = file->private_data; struct net_device *dev = file->private_data;
struct netdevsim *ns = netdev_priv(dev); struct netdevsim *ns = netdev_priv(dev);
memset(&ns->udp_ports.ports, 0, sizeof(ns->udp_ports.ports)); memset(ns->udp_ports.ports, 0, sizeof(ns->udp_ports.__ports));
rtnl_lock(); rtnl_lock();
udp_tunnel_nic_reset_ntf(dev); udp_tunnel_nic_reset_ntf(dev);
rtnl_unlock(); rtnl_unlock();
...@@ -132,6 +132,17 @@ int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev, ...@@ -132,6 +132,17 @@ int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,
struct netdevsim *ns = netdev_priv(dev); struct netdevsim *ns = netdev_priv(dev);
struct udp_tunnel_nic_info *info; struct udp_tunnel_nic_info *info;
if (nsim_dev->udp_ports.shared && nsim_dev->udp_ports.open_only) {
dev_err(&nsim_dev->nsim_bus_dev->dev,
"shared can't be used in conjunction with open_only\n");
return -EINVAL;
}
if (!nsim_dev->udp_ports.shared)
ns->udp_ports.ports = ns->udp_ports.__ports;
else
ns->udp_ports.ports = nsim_dev->udp_ports.__ports;
debugfs_create_u32("udp_ports_inject_error", 0600, debugfs_create_u32("udp_ports_inject_error", 0600,
ns->nsim_dev_port->ddir, ns->nsim_dev_port->ddir,
&ns->udp_ports.inject_error); &ns->udp_ports.inject_error);
...@@ -173,6 +184,8 @@ int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev, ...@@ -173,6 +184,8 @@ int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,
info->flags |= UDP_TUNNEL_NIC_INFO_OPEN_ONLY; info->flags |= UDP_TUNNEL_NIC_INFO_OPEN_ONLY;
if (nsim_dev->udp_ports.ipv4_only) if (nsim_dev->udp_ports.ipv4_only)
info->flags |= UDP_TUNNEL_NIC_INFO_IPV4_ONLY; info->flags |= UDP_TUNNEL_NIC_INFO_IPV4_ONLY;
if (nsim_dev->udp_ports.shared)
info->shared = &nsim_dev->udp_ports.utn_shared;
dev->udp_tunnel_nic_info = info; dev->udp_tunnel_nic_info = info;
return 0; return 0;
...@@ -192,6 +205,8 @@ void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev) ...@@ -192,6 +205,8 @@ void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev)
&nsim_dev->udp_ports.open_only); &nsim_dev->udp_ports.open_only);
debugfs_create_bool("udp_ports_ipv4_only", 0600, nsim_dev->ddir, debugfs_create_bool("udp_ports_ipv4_only", 0600, nsim_dev->ddir,
&nsim_dev->udp_ports.ipv4_only); &nsim_dev->udp_ports.ipv4_only);
debugfs_create_bool("udp_ports_shared", 0600, nsim_dev->ddir,
&nsim_dev->udp_ports.shared);
debugfs_create_u32("udp_ports_sleep", 0600, nsim_dev->ddir, debugfs_create_u32("udp_ports_sleep", 0600, nsim_dev->ddir,
&nsim_dev->udp_ports.sleep); &nsim_dev->udp_ports.sleep);
} }
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