Export vxlan_create_socket() so that other modules, like Open vSwitch, can have configurable destination port for VXLAN.
Signed-off-by: Pravin B Shelar <pshe...@nicira.com> --- drivers/net/vxlan.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index dacd20f..a56e00d 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -39,6 +39,7 @@ #include <net/inet_ecn.h> #include <net/net_namespace.h> #include <net/netns/generic.h> +#include <net/vxlan.h> #define VXLAN_VERSION "0.1" @@ -49,19 +50,6 @@ #define FDB_AGE_DEFAULT 300 /* 5 min */ #define FDB_AGE_INTERVAL (10 * HZ) /* rescan interval */ -#define VXLAN_N_VID (1u << 24) -#define VXLAN_VID_MASK (VXLAN_N_VID - 1) -/* VLAN + IP header + UDP + VXLAN */ -#define VXLAN_HEADROOM (4 + 20 + 8 + 8) - -#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ - -/* VXLAN protocol header */ -struct vxlanhdr { - __be32 vx_flags; - __be32 vx_vni; -}; - /* UDP port for VXLAN traffic. */ static unsigned int vxlan_port __read_mostly = 8472; module_param_named(udp_port, vxlan_port, uint, 0444); @@ -1144,37 +1132,35 @@ static struct rtnl_link_ops vxlan_link_ops __read_mostly = { .fill_info = vxlan_fill_info, }; -static __net_init int vxlan_init_net(struct net *net) +struct socket *vxlan_create_socket(struct net *net, int portno) { - struct vxlan_net *vn = net_generic(net, vxlan_net_id); + struct socket *sock; struct sock *sk; struct sockaddr_in vxlan_addr = { .sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_ANY), }; int rc; - unsigned h; /* Create UDP socket for encapsulation receive. */ - rc = sock_create_kern(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &vn->sock); + rc = sock_create_kern(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock); if (rc < 0) { pr_debug("UDP socket create failed\n"); - return rc; + return ERR_PTR(rc); } /* Put in proper namespace */ - sk = vn->sock->sk; + sk = sock->sk; sk_change_net(sk, net); - vxlan_addr.sin_port = htons(vxlan_port); + vxlan_addr.sin_port = htons(portno); - rc = kernel_bind(vn->sock, (struct sockaddr *) &vxlan_addr, + rc = kernel_bind(sock, (struct sockaddr *) &vxlan_addr, sizeof(vxlan_addr)); if (rc < 0) { pr_debug("bind for UDP socket %pI4:%u (%d)\n", &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc); sk_release_kernel(sk); - vn->sock = NULL; - return rc; + return ERR_PTR(rc); } /* Disable multicast loopback */ @@ -1185,6 +1171,20 @@ static __net_init int vxlan_init_net(struct net *net) udp_sk(sk)->encap_rcv = vxlan_udp_encap_recv; udp_encap_enable(); + return sock; +} +EXPORT_SYMBOL(vxlan_create_socket); + +static __net_init int vxlan_init_net(struct net *net) +{ + struct vxlan_net *vn = net_generic(net, vxlan_net_id); + unsigned h; + + vn->sock = vxlan_create_socket(net, vxlan_port); + if (IS_ERR(vn->sock)) { + vn->sock = NULL; + return PTR_ERR(vn->sock); + } for (h = 0; h < VNI_HASH_SIZE; ++h) INIT_HLIST_HEAD(&vn->vni_list[h]); -- 1.7.10 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev