Commit 012a5729 authored by Pravin B Shelar's avatar Pravin B Shelar Committed by David S. Miller

vxlan: Extend vxlan handlers for openvswitch.

Following patch adds data field to vxlan socket and export
vxlan handler api.
vh->data is required to store private data per vxlan handler.
Signed-off-by: default avatarPravin B Shelar <pshelar@nicira.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5cfccc5a
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <net/inet_ecn.h> #include <net/inet_ecn.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
#include <net/vxlan.h>
#define VXLAN_VERSION "0.1" #define VXLAN_VERSION "0.1"
...@@ -83,20 +84,6 @@ static int vxlan_net_id; ...@@ -83,20 +84,6 @@ static int vxlan_net_id;
static const u8 all_zeros_mac[ETH_ALEN]; static const u8 all_zeros_mac[ETH_ALEN];
struct vxlan_sock;
typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key);
/* per UDP socket information */
struct vxlan_sock {
vxlan_rcv_t *rcv;
struct hlist_node hlist;
struct rcu_head rcu;
struct work_struct del_work;
atomic_t refcnt;
struct socket *sock;
struct hlist_head vni_list[VNI_HASH_SIZE];
};
/* per-network namespace private data for this module */ /* per-network namespace private data for this module */
struct vxlan_net { struct vxlan_net {
struct list_head vxlan_list; struct list_head vxlan_list;
...@@ -813,8 +800,10 @@ static void vxlan_sock_hold(struct vxlan_sock *vs) ...@@ -813,8 +800,10 @@ static void vxlan_sock_hold(struct vxlan_sock *vs)
atomic_inc(&vs->refcnt); atomic_inc(&vs->refcnt);
} }
static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs) void vxlan_sock_release(struct vxlan_sock *vs)
{ {
struct vxlan_net *vn = net_generic(sock_net(vs->sock->sk), vxlan_net_id);
if (!atomic_dec_and_test(&vs->refcnt)) if (!atomic_dec_and_test(&vs->refcnt))
return; return;
...@@ -824,6 +813,7 @@ static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs) ...@@ -824,6 +813,7 @@ static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs)
queue_work(vxlan_wq, &vs->del_work); queue_work(vxlan_wq, &vs->del_work);
} }
EXPORT_SYMBOL_GPL(vxlan_sock_release);
/* Callback to update multicast group membership when first VNI on /* Callback to update multicast group membership when first VNI on
* multicast asddress is brought up * multicast asddress is brought up
...@@ -832,7 +822,6 @@ static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs) ...@@ -832,7 +822,6 @@ static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs)
static void vxlan_igmp_join(struct work_struct *work) static void vxlan_igmp_join(struct work_struct *work)
{ {
struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_join); struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_join);
struct vxlan_net *vn = net_generic(dev_net(vxlan->dev), vxlan_net_id);
struct vxlan_sock *vs = vxlan->vn_sock; struct vxlan_sock *vs = vxlan->vn_sock;
struct sock *sk = vs->sock->sk; struct sock *sk = vs->sock->sk;
struct ip_mreqn mreq = { struct ip_mreqn mreq = {
...@@ -844,7 +833,7 @@ static void vxlan_igmp_join(struct work_struct *work) ...@@ -844,7 +833,7 @@ static void vxlan_igmp_join(struct work_struct *work)
ip_mc_join_group(sk, &mreq); ip_mc_join_group(sk, &mreq);
release_sock(sk); release_sock(sk);
vxlan_sock_release(vn, vs); vxlan_sock_release(vs);
dev_put(vxlan->dev); dev_put(vxlan->dev);
} }
...@@ -852,7 +841,6 @@ static void vxlan_igmp_join(struct work_struct *work) ...@@ -852,7 +841,6 @@ static void vxlan_igmp_join(struct work_struct *work)
static void vxlan_igmp_leave(struct work_struct *work) static void vxlan_igmp_leave(struct work_struct *work)
{ {
struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_leave); struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_leave);
struct vxlan_net *vn = net_generic(dev_net(vxlan->dev), vxlan_net_id);
struct vxlan_sock *vs = vxlan->vn_sock; struct vxlan_sock *vs = vxlan->vn_sock;
struct sock *sk = vs->sock->sk; struct sock *sk = vs->sock->sk;
struct ip_mreqn mreq = { struct ip_mreqn mreq = {
...@@ -864,7 +852,7 @@ static void vxlan_igmp_leave(struct work_struct *work) ...@@ -864,7 +852,7 @@ static void vxlan_igmp_leave(struct work_struct *work)
ip_mc_leave_group(sk, &mreq); ip_mc_leave_group(sk, &mreq);
release_sock(sk); release_sock(sk);
vxlan_sock_release(vn, vs); vxlan_sock_release(vs);
dev_put(vxlan->dev); dev_put(vxlan->dev);
} }
...@@ -1429,13 +1417,12 @@ static void vxlan_fdb_delete_default(struct vxlan_dev *vxlan) ...@@ -1429,13 +1417,12 @@ static void vxlan_fdb_delete_default(struct vxlan_dev *vxlan)
static void vxlan_uninit(struct net_device *dev) static void vxlan_uninit(struct net_device *dev)
{ {
struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_dev *vxlan = netdev_priv(dev);
struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
struct vxlan_sock *vs = vxlan->vn_sock; struct vxlan_sock *vs = vxlan->vn_sock;
vxlan_fdb_delete_default(vxlan); vxlan_fdb_delete_default(vxlan);
if (vs) if (vs)
vxlan_sock_release(vn, vs); vxlan_sock_release(vs);
free_percpu(dev->tstats); free_percpu(dev->tstats);
} }
...@@ -1653,7 +1640,7 @@ static void vxlan_del_work(struct work_struct *work) ...@@ -1653,7 +1640,7 @@ static void vxlan_del_work(struct work_struct *work)
} }
static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
vxlan_rcv_t *rcv) vxlan_rcv_t *rcv, void *data)
{ {
struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_net *vn = net_generic(net, vxlan_net_id);
struct vxlan_sock *vs; struct vxlan_sock *vs;
...@@ -1700,6 +1687,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, ...@@ -1700,6 +1687,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
} }
atomic_set(&vs->refcnt, 1); atomic_set(&vs->refcnt, 1);
vs->rcv = rcv; vs->rcv = rcv;
vs->data = data;
/* Disable multicast loopback */ /* Disable multicast loopback */
inet_sk(sk)->mc_loop = 0; inet_sk(sk)->mc_loop = 0;
...@@ -1714,16 +1702,20 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, ...@@ -1714,16 +1702,20 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
return vs; return vs;
} }
static struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
vxlan_rcv_t *rcv) vxlan_rcv_t *rcv, void *data,
bool no_share)
{ {
struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_net *vn = net_generic(net, vxlan_net_id);
struct vxlan_sock *vs; struct vxlan_sock *vs;
vs = vxlan_socket_create(net, port, rcv); vs = vxlan_socket_create(net, port, rcv, data);
if (!IS_ERR(vs)) if (!IS_ERR(vs))
return vs; return vs;
if (no_share) /* Return error if sharing is not allowed. */
return vs;
spin_lock(&vn->sock_lock); spin_lock(&vn->sock_lock);
vs = vxlan_find_sock(net, port); vs = vxlan_find_sock(net, port);
if (vs) { if (vs) {
...@@ -1739,6 +1731,7 @@ static struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, ...@@ -1739,6 +1731,7 @@ static struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
return vs; return vs;
} }
EXPORT_SYMBOL_GPL(vxlan_sock_add);
/* Scheduled at device creation to bind to a socket */ /* Scheduled at device creation to bind to a socket */
static void vxlan_sock_work(struct work_struct *work) static void vxlan_sock_work(struct work_struct *work)
...@@ -1749,7 +1742,7 @@ static void vxlan_sock_work(struct work_struct *work) ...@@ -1749,7 +1742,7 @@ static void vxlan_sock_work(struct work_struct *work)
__be16 port = vxlan->dst_port; __be16 port = vxlan->dst_port;
struct vxlan_sock *nvs; struct vxlan_sock *nvs;
nvs = vxlan_sock_add(net, port, vxlan_rcv); nvs = vxlan_sock_add(net, port, vxlan_rcv, NULL, false);
spin_lock(&vn->sock_lock); spin_lock(&vn->sock_lock);
if (!IS_ERR(nvs)) if (!IS_ERR(nvs))
vxlan_vs_add_dev(nvs, vxlan); vxlan_vs_add_dev(nvs, vxlan);
......
#ifndef __NET_VXLAN_H
#define __NET_VXLAN_H 1
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/udp.h>
#define VNI_HASH_BITS 10
#define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
struct vxlan_sock;
typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key);
/* per UDP socket information */
struct vxlan_sock {
struct hlist_node hlist;
vxlan_rcv_t *rcv;
void *data;
struct work_struct del_work;
struct socket *sock;
struct rcu_head rcu;
struct hlist_head vni_list[VNI_HASH_SIZE];
atomic_t refcnt;
};
struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
vxlan_rcv_t *rcv, void *data,
bool no_share);
void vxlan_sock_release(struct vxlan_sock *vs);
#endif
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