]> git.proxmox.com Git - mirror_ovs.git/blame - datapath/vport-lisp.c
datapath: Distribute switch variables for initialization
[mirror_ovs.git] / datapath / vport-lisp.c
CommitLineData
a6ae068b 1/*
e23775f2 2 * Copyright (c) 2015 Nicira, Inc.
a6ae068b
LJ
3 *
4 * This program is free software; you can redistribute it and/or
e23775f2
PS
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
a6ae068b
LJ
8 */
9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
a6ae068b
LJ
12#include <linux/in.h>
13#include <linux/ip.h>
a6ae068b 14#include <linux/net.h>
85c9de19 15#include <linux/rculist.h>
a6ae068b 16#include <linux/udp.h>
e23775f2
PS
17#include <linux/if_vlan.h>
18#include <linux/module.h>
a6ae068b 19
e23775f2 20#include <net/lisp.h>
a6ae068b
LJ
21#include <net/icmp.h>
22#include <net/ip.h>
11aa8dff 23#include <net/route.h>
a6ae068b 24#include <net/udp.h>
11aa8dff 25#include <net/xfrm.h>
a6ae068b
LJ
26
27#include "datapath.h"
a6ae068b 28#include "vport.h"
e23775f2 29#include "vport-netdev.h"
a6ae068b 30
e23775f2 31static struct vport_ops ovs_lisp_vport_ops;
a6ae068b
LJ
32/**
33 * struct lisp_port - Keeps track of open UDP ports
e23775f2 34 * @dst_port: destination port.
a6ae068b
LJ
35 */
36struct lisp_port {
e23775f2 37 u16 port_no;
a6ae068b
LJ
38};
39
c405d282
PS
40static inline struct lisp_port *lisp_vport(const struct vport *vport)
41{
42 return vport_priv(vport);
43}
44
e23775f2
PS
45static int lisp_get_options(const struct vport *vport,
46 struct sk_buff *skb)
a6ae068b 47{
c405d282 48 struct lisp_port *lisp_port = lisp_vport(vport);
a6ae068b 49
e23775f2 50 if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, lisp_port->port_no))
c405d282
PS
51 return -EMSGSIZE;
52 return 0;
a6ae068b
LJ
53}
54
c405d282 55static struct vport *lisp_tnl_create(const struct vport_parms *parms)
85c9de19 56{
c405d282
PS
57 struct net *net = ovs_dp_get_net(parms->dp);
58 struct nlattr *options = parms->options;
85c9de19 59 struct lisp_port *lisp_port;
e23775f2 60 struct net_device *dev;
c405d282 61 struct vport *vport;
a6ae068b 62 struct nlattr *a;
a6ae068b 63 u16 dst_port;
e23775f2 64 int err;
a6ae068b
LJ
65
66 if (!options) {
67 err = -EINVAL;
c405d282 68 goto error;
a6ae068b
LJ
69 }
70
71 a = nla_find_nested(options, OVS_TUNNEL_ATTR_DST_PORT);
72 if (a && nla_len(a) == sizeof(u16)) {
73 dst_port = nla_get_u16(a);
74 } else {
75 /* Require destination port from userspace. */
76 err = -EINVAL;
c405d282 77 goto error;
a6ae068b
LJ
78 }
79
c405d282
PS
80 vport = ovs_vport_alloc(sizeof(struct lisp_port),
81 &ovs_lisp_vport_ops, parms);
82 if (IS_ERR(vport))
83 return vport;
a6ae068b 84
c405d282 85 lisp_port = lisp_vport(vport);
e23775f2
PS
86 lisp_port->port_no = dst_port;
87
88 rtnl_lock();
89 dev = lisp_dev_create_fb(net, parms->name, NET_NAME_USER, dst_port);
90 if (IS_ERR(dev)) {
91 rtnl_unlock();
92 ovs_vport_free(vport);
93 return ERR_CAST(dev);
94 }
140c8971 95 err = dev_change_flags(dev, dev->flags | IFF_UP, NULL);
c59b72b5
PS
96 if (err < 0) {
97 rtnl_delete_link(dev);
98 rtnl_unlock();
99 ovs_vport_free(vport);
100 goto error;
101 }
a6ae068b 102
e23775f2 103 rtnl_unlock();
c405d282 104 return vport;
a6ae068b 105error:
c405d282 106 return ERR_PTR(err);
a6ae068b
LJ
107}
108
e23775f2 109static struct vport *lisp_create(const struct vport_parms *parms)
a6ae068b 110{
e23775f2 111 struct vport *vport;
8b7ea2d4 112
e23775f2
PS
113 vport = lisp_tnl_create(parms);
114 if (IS_ERR(vport))
115 return vport;
8b7ea2d4 116
e23775f2 117 return ovs_netdev_link(vport, parms->name);
8b7ea2d4
WZ
118}
119
5a38795f 120static struct vport_ops ovs_lisp_vport_ops = {
e23775f2
PS
121 .type = OVS_VPORT_TYPE_LISP,
122 .create = lisp_create,
123 .destroy = ovs_netdev_tunnel_destroy,
124 .get_options = lisp_get_options,
564666e9 125#ifndef USE_UPSTREAM_TUNNEL
aad7cb91 126 .fill_metadata_dst = lisp_fill_metadata_dst,
564666e9 127#endif
e23775f2 128 .send = lisp_xmit,
a6ae068b 129};
5a38795f
TG
130
131static int __init ovs_lisp_tnl_init(void)
132{
133 return ovs_vport_ops_register(&ovs_lisp_vport_ops);
134}
135
136static void __exit ovs_lisp_tnl_exit(void)
137{
138 ovs_vport_ops_unregister(&ovs_lisp_vport_ops);
139}
140
141module_init(ovs_lisp_tnl_init);
142module_exit(ovs_lisp_tnl_exit);
143
e23775f2 144MODULE_DESCRIPTION("OVS: Lisp switching port");
5a38795f
TG
145MODULE_LICENSE("GPL");
146MODULE_ALIAS("vport-type-105");