2013-02-21 21:52:04 -08:00
|
|
|
/*
|
2015-12-03 11:40:53 -08:00
|
|
|
* Copyright (c) 2015 Nicira, Inc.
|
2013-02-21 21:52:04 -08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
2015-12-03 11:40:53 -08:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
2013-02-21 21:52:04 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/net.h>
|
2013-03-04 13:00:25 -08:00
|
|
|
#include <linux/rculist.h>
|
2013-02-21 21:52:04 -08:00
|
|
|
#include <linux/udp.h>
|
2015-12-03 11:40:53 -08:00
|
|
|
#include <linux/if_vlan.h>
|
|
|
|
#include <linux/module.h>
|
2013-02-21 21:52:04 -08:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
#include <net/lisp.h>
|
2013-02-21 21:52:04 -08:00
|
|
|
#include <net/icmp.h>
|
|
|
|
#include <net/ip.h>
|
2013-08-13 00:19:53 -07:00
|
|
|
#include <net/route.h>
|
2013-02-21 21:52:04 -08:00
|
|
|
#include <net/udp.h>
|
2013-08-13 00:19:53 -07:00
|
|
|
#include <net/xfrm.h>
|
2013-02-21 21:52:04 -08:00
|
|
|
|
|
|
|
#include "datapath.h"
|
|
|
|
#include "vport.h"
|
2015-12-03 11:40:53 -08:00
|
|
|
#include "vport-netdev.h"
|
2013-02-21 21:52:04 -08:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
static struct vport_ops ovs_lisp_vport_ops;
|
2013-02-21 21:52:04 -08:00
|
|
|
/**
|
|
|
|
* struct lisp_port - Keeps track of open UDP ports
|
2015-12-03 11:40:53 -08:00
|
|
|
* @dst_port: destination port.
|
2013-02-21 21:52:04 -08:00
|
|
|
*/
|
|
|
|
struct lisp_port {
|
2015-12-03 11:40:53 -08:00
|
|
|
u16 port_no;
|
2013-02-21 21:52:04 -08:00
|
|
|
};
|
|
|
|
|
2013-05-06 10:29:08 -07:00
|
|
|
static inline struct lisp_port *lisp_vport(const struct vport *vport)
|
|
|
|
{
|
|
|
|
return vport_priv(vport);
|
|
|
|
}
|
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
static int lisp_get_options(const struct vport *vport,
|
|
|
|
struct sk_buff *skb)
|
2013-02-21 21:52:04 -08:00
|
|
|
{
|
2013-05-06 10:29:08 -07:00
|
|
|
struct lisp_port *lisp_port = lisp_vport(vport);
|
2013-02-21 21:52:04 -08:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, lisp_port->port_no))
|
2013-05-06 10:29:08 -07:00
|
|
|
return -EMSGSIZE;
|
|
|
|
return 0;
|
2013-02-21 21:52:04 -08:00
|
|
|
}
|
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
static int lisp_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
|
|
|
|
struct dp_upcall_info *upcall)
|
2013-02-21 21:52:04 -08:00
|
|
|
{
|
2013-05-06 10:29:08 -07:00
|
|
|
struct lisp_port *lisp_port = lisp_vport(vport);
|
2015-12-03 11:40:53 -08:00
|
|
|
struct net *net = ovs_dp_get_net(vport->dp);
|
|
|
|
__be16 dport = htons(lisp_port->port_no);
|
|
|
|
__be16 sport = udp_flow_src_port(net, skb, 1, USHRT_MAX, true);
|
2013-05-06 10:29:08 -07:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
return ovs_tunnel_get_egress_info(upcall, ovs_dp_get_net(vport->dp),
|
|
|
|
skb, IPPROTO_UDP, sport, dport);
|
2013-03-04 13:00:25 -08:00
|
|
|
}
|
|
|
|
|
2013-05-06 10:29:08 -07:00
|
|
|
static struct vport *lisp_tnl_create(const struct vport_parms *parms)
|
2013-03-04 13:00:25 -08:00
|
|
|
{
|
2013-05-06 10:29:08 -07:00
|
|
|
struct net *net = ovs_dp_get_net(parms->dp);
|
|
|
|
struct nlattr *options = parms->options;
|
2013-03-04 13:00:25 -08:00
|
|
|
struct lisp_port *lisp_port;
|
2015-12-03 11:40:53 -08:00
|
|
|
struct net_device *dev;
|
2013-05-06 10:29:08 -07:00
|
|
|
struct vport *vport;
|
2013-02-21 21:52:04 -08:00
|
|
|
struct nlattr *a;
|
|
|
|
u16 dst_port;
|
2015-12-03 11:40:53 -08:00
|
|
|
int err;
|
2013-02-21 21:52:04 -08:00
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
err = -EINVAL;
|
2013-05-06 10:29:08 -07:00
|
|
|
goto error;
|
2013-02-21 21:52:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
a = nla_find_nested(options, OVS_TUNNEL_ATTR_DST_PORT);
|
|
|
|
if (a && nla_len(a) == sizeof(u16)) {
|
|
|
|
dst_port = nla_get_u16(a);
|
|
|
|
} else {
|
|
|
|
/* Require destination port from userspace. */
|
|
|
|
err = -EINVAL;
|
2013-05-06 10:29:08 -07:00
|
|
|
goto error;
|
2013-02-21 21:52:04 -08:00
|
|
|
}
|
|
|
|
|
2013-05-06 10:29:08 -07:00
|
|
|
vport = ovs_vport_alloc(sizeof(struct lisp_port),
|
|
|
|
&ovs_lisp_vport_ops, parms);
|
|
|
|
if (IS_ERR(vport))
|
|
|
|
return vport;
|
2013-02-21 21:52:04 -08:00
|
|
|
|
2013-05-06 10:29:08 -07:00
|
|
|
lisp_port = lisp_vport(vport);
|
2015-12-03 11:40:53 -08:00
|
|
|
lisp_port->port_no = dst_port;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
dev = lisp_dev_create_fb(net, parms->name, NET_NAME_USER, dst_port);
|
|
|
|
if (IS_ERR(dev)) {
|
|
|
|
rtnl_unlock();
|
|
|
|
ovs_vport_free(vport);
|
|
|
|
return ERR_CAST(dev);
|
|
|
|
}
|
2013-02-21 21:52:04 -08:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
dev_change_flags(dev, dev->flags | IFF_UP);
|
|
|
|
rtnl_unlock();
|
2013-05-06 10:29:08 -07:00
|
|
|
return vport;
|
2013-02-21 21:52:04 -08:00
|
|
|
error:
|
2013-05-06 10:29:08 -07:00
|
|
|
return ERR_PTR(err);
|
2013-02-21 21:52:04 -08:00
|
|
|
}
|
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
static struct vport *lisp_create(const struct vport_parms *parms)
|
2013-02-21 21:52:04 -08:00
|
|
|
{
|
2015-12-03 11:40:53 -08:00
|
|
|
struct vport *vport;
|
2014-08-17 20:19:36 -07:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
vport = lisp_tnl_create(parms);
|
|
|
|
if (IS_ERR(vport))
|
|
|
|
return vport;
|
2014-08-17 20:19:36 -07:00
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
return ovs_netdev_link(vport, parms->name);
|
2014-08-17 20:19:36 -07:00
|
|
|
}
|
|
|
|
|
2015-04-04 08:24:13 +02:00
|
|
|
static struct vport_ops ovs_lisp_vport_ops = {
|
2015-12-03 11:40:53 -08:00
|
|
|
.type = OVS_VPORT_TYPE_LISP,
|
|
|
|
.create = lisp_create,
|
|
|
|
.destroy = ovs_netdev_tunnel_destroy,
|
|
|
|
.get_options = lisp_get_options,
|
|
|
|
.send = lisp_xmit,
|
2014-08-17 20:19:36 -07:00
|
|
|
.get_egress_tun_info = lisp_get_egress_tun_info,
|
2013-02-21 21:52:04 -08:00
|
|
|
};
|
2015-04-04 08:24:13 +02:00
|
|
|
|
|
|
|
static int __init ovs_lisp_tnl_init(void)
|
|
|
|
{
|
|
|
|
return ovs_vport_ops_register(&ovs_lisp_vport_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ovs_lisp_tnl_exit(void)
|
|
|
|
{
|
|
|
|
ovs_vport_ops_unregister(&ovs_lisp_vport_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ovs_lisp_tnl_init);
|
|
|
|
module_exit(ovs_lisp_tnl_exit);
|
|
|
|
|
2015-12-03 11:40:53 -08:00
|
|
|
MODULE_DESCRIPTION("OVS: Lisp switching port");
|
2015-04-04 08:24:13 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("vport-type-105");
|