summaryrefslogtreecommitdiff
path: root/net/ipv4/udp_tunnel.c
diff options
context:
space:
mode:
authorAlexander Duyck <aduyck@mirantis.com>2016-06-16 12:20:52 -0700
committerDavid S. Miller <davem@davemloft.net>2016-06-17 20:23:29 -0700
commite7b3db5e60e8f471c3f5ef93b497bafe5863e56a (patch)
tree7cc8ee25fc39778069825cc8b87de542d7938d3e /net/ipv4/udp_tunnel.c
parent86a98057256020e75e1be0f88d7617491a06e8f1 (diff)
net: Combine GENEVE and VXLAN port notifiers into single functions
This patch merges the GENEVE and VXLAN code so that both functions pass through a shared code path. This way we can start the effort of using a single function on the network device drivers to handle both of these tunnel types. Signed-off-by: Alexander Duyck <aduyck@mirantis.com> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/udp_tunnel.c')
-rw-r--r--net/ipv4/udp_tunnel.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c
index 47f12c73d959..8174753e6494 100644
--- a/net/ipv4/udp_tunnel.c
+++ b/net/ipv4/udp_tunnel.c
@@ -76,6 +76,108 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
}
EXPORT_SYMBOL_GPL(setup_udp_tunnel_sock);
+static void __udp_tunnel_push_rx_port(struct net_device *dev,
+ struct udp_tunnel_info *ti)
+{
+ switch (ti->type) {
+ case UDP_TUNNEL_TYPE_VXLAN:
+ if (!dev->netdev_ops->ndo_add_vxlan_port)
+ break;
+
+ dev->netdev_ops->ndo_add_vxlan_port(dev,
+ ti->sa_family,
+ ti->port);
+ break;
+ case UDP_TUNNEL_TYPE_GENEVE:
+ if (!dev->netdev_ops->ndo_add_geneve_port)
+ break;
+
+ dev->netdev_ops->ndo_add_geneve_port(dev,
+ ti->sa_family,
+ ti->port);
+ break;
+ default:
+ break;
+ }
+}
+
+void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
+ unsigned short type)
+{
+ struct sock *sk = sock->sk;
+ struct udp_tunnel_info ti;
+
+ ti.type = type;
+ ti.sa_family = sk->sk_family;
+ ti.port = inet_sk(sk)->inet_sport;
+
+ __udp_tunnel_push_rx_port(dev, &ti);
+}
+EXPORT_SYMBOL_GPL(udp_tunnel_push_rx_port);
+
+/* Notify netdevs that UDP port started listening */
+void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type)
+{
+ struct sock *sk = sock->sk;
+ struct net *net = sock_net(sk);
+ struct udp_tunnel_info ti;
+ struct net_device *dev;
+
+ ti.type = type;
+ ti.sa_family = sk->sk_family;
+ ti.port = inet_sk(sk)->inet_sport;
+
+ rcu_read_lock();
+ for_each_netdev_rcu(net, dev)
+ __udp_tunnel_push_rx_port(dev, &ti);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(udp_tunnel_notify_add_rx_port);
+
+static void __udp_tunnel_pull_rx_port(struct net_device *dev,
+ struct udp_tunnel_info *ti)
+{
+ switch (ti->type) {
+ case UDP_TUNNEL_TYPE_VXLAN:
+ if (!dev->netdev_ops->ndo_del_vxlan_port)
+ break;
+
+ dev->netdev_ops->ndo_del_vxlan_port(dev,
+ ti->sa_family,
+ ti->port);
+ break;
+ case UDP_TUNNEL_TYPE_GENEVE:
+ if (!dev->netdev_ops->ndo_del_geneve_port)
+ break;
+
+ dev->netdev_ops->ndo_del_geneve_port(dev,
+ ti->sa_family,
+ ti->port);
+ break;
+ default:
+ break;
+ }
+}
+
+/* Notify netdevs that UDP port is no more listening */
+void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type)
+{
+ struct sock *sk = sock->sk;
+ struct net *net = sock_net(sk);
+ struct udp_tunnel_info ti;
+ struct net_device *dev;
+
+ ti.type = type;
+ ti.sa_family = sk->sk_family;
+ ti.port = inet_sk(sk)->inet_sport;
+
+ rcu_read_lock();
+ for_each_netdev_rcu(net, dev)
+ __udp_tunnel_pull_rx_port(dev, &ti);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(udp_tunnel_notify_del_rx_port);
+
void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
__be16 df, __be16 src_port, __be16 dst_port,