Blame view
net/openvswitch/vport-geneve.c
3.13 KB
f57966840 openvswitch: Add ... |
1 2 3 4 5 6 7 8 9 10 |
/* * Copyright (c) 2014 Nicira, Inc. * * This program is free software; you can redistribute it and/or * 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. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
f57966840 openvswitch: Add ... |
11 12 13 14 15 16 |
#include <linux/in.h> #include <linux/ip.h> #include <linux/net.h> #include <linux/rculist.h> #include <linux/udp.h> #include <linux/if_vlan.h> |
62b9c8d03 ovs: Turn vports ... |
17 |
#include <linux/module.h> |
f57966840 openvswitch: Add ... |
18 19 20 21 22 23 24 25 26 27 |
#include <net/geneve.h> #include <net/icmp.h> #include <net/ip.h> #include <net/route.h> #include <net/udp.h> #include <net/xfrm.h> #include "datapath.h" #include "vport.h" |
6b001e682 openvswitch: Use ... |
28 |
#include "vport-netdev.h" |
f57966840 openvswitch: Add ... |
29 |
|
62b9c8d03 ovs: Turn vports ... |
30 |
static struct vport_ops ovs_geneve_vport_ops; |
f57966840 openvswitch: Add ... |
31 32 |
/** * struct geneve_port - Keeps track of open UDP ports |
6b001e682 openvswitch: Use ... |
33 |
* @dst_port: destination port. |
f57966840 openvswitch: Add ... |
34 35 |
*/ struct geneve_port { |
2f7066ada openvswitch: fix ... |
36 |
u16 dst_port; |
f57966840 openvswitch: Add ... |
37 |
}; |
f57966840 openvswitch: Add ... |
38 39 40 41 |
static inline struct geneve_port *geneve_vport(const struct vport *vport) { return vport_priv(vport); } |
f57966840 openvswitch: Add ... |
42 43 44 45 |
static int geneve_get_options(const struct vport *vport, struct sk_buff *skb) { struct geneve_port *geneve_port = geneve_vport(vport); |
f57966840 openvswitch: Add ... |
46 |
|
2f7066ada openvswitch: fix ... |
47 |
if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, geneve_port->dst_port)) |
f57966840 openvswitch: Add ... |
48 49 50 |
return -EMSGSIZE; return 0; } |
f57966840 openvswitch: Add ... |
51 52 53 54 55 |
static struct vport *geneve_tnl_create(const struct vport_parms *parms) { struct net *net = ovs_dp_get_net(parms->dp); struct nlattr *options = parms->options; struct geneve_port *geneve_port; |
6b001e682 openvswitch: Use ... |
56 |
struct net_device *dev; |
f57966840 openvswitch: Add ... |
57 58 |
struct vport *vport; struct nlattr *a; |
f57966840 openvswitch: Add ... |
59 |
u16 dst_port; |
6b001e682 openvswitch: Use ... |
60 |
int err; |
f57966840 openvswitch: Add ... |
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
if (!options) { err = -EINVAL; goto error; } 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; goto error; } vport = ovs_vport_alloc(sizeof(struct geneve_port), &ovs_geneve_vport_ops, parms); if (IS_ERR(vport)) return vport; geneve_port = geneve_vport(vport); |
2f7066ada openvswitch: fix ... |
82 |
geneve_port->dst_port = dst_port; |
f57966840 openvswitch: Add ... |
83 |
|
6b001e682 openvswitch: Use ... |
84 85 86 87 |
rtnl_lock(); dev = geneve_dev_create_fb(net, parms->name, NET_NAME_USER, dst_port); if (IS_ERR(dev)) { rtnl_unlock(); |
f57966840 openvswitch: Add ... |
88 |
ovs_vport_free(vport); |
6b001e682 openvswitch: Use ... |
89 |
return ERR_CAST(dev); |
f57966840 openvswitch: Add ... |
90 |
} |
f57966840 openvswitch: Add ... |
91 |
|
4b5b9ba55 openvswitch: do n... |
92 93 94 95 96 97 98 |
err = dev_change_flags(dev, dev->flags | IFF_UP); if (err < 0) { rtnl_delete_link(dev); rtnl_unlock(); ovs_vport_free(vport); goto error; } |
6b001e682 openvswitch: Use ... |
99 |
rtnl_unlock(); |
f57966840 openvswitch: Add ... |
100 101 102 103 |
return vport; error: return ERR_PTR(err); } |
6b001e682 openvswitch: Use ... |
104 |
static struct vport *geneve_create(const struct vport_parms *parms) |
f57966840 openvswitch: Add ... |
105 |
{ |
6b001e682 openvswitch: Use ... |
106 |
struct vport *vport; |
f57966840 openvswitch: Add ... |
107 |
|
6b001e682 openvswitch: Use ... |
108 109 110 |
vport = geneve_tnl_create(parms); if (IS_ERR(vport)) return vport; |
8f0aad6f3 openvswitch: Exte... |
111 |
|
6b001e682 openvswitch: Use ... |
112 |
return ovs_netdev_link(vport, parms->name); |
8f0aad6f3 openvswitch: Exte... |
113 |
} |
62b9c8d03 ovs: Turn vports ... |
114 |
static struct vport_ops ovs_geneve_vport_ops = { |
f57966840 openvswitch: Add ... |
115 |
.type = OVS_VPORT_TYPE_GENEVE, |
6b001e682 openvswitch: Use ... |
116 117 |
.create = geneve_create, .destroy = ovs_netdev_tunnel_destroy, |
f57966840 openvswitch: Add ... |
118 |
.get_options = geneve_get_options, |
aec159247 openvswitch: Use ... |
119 |
.send = dev_queue_xmit, |
f57966840 openvswitch: Add ... |
120 |
}; |
62b9c8d03 ovs: Turn vports ... |
121 122 123 124 125 126 127 128 129 130 131 132 133 |
static int __init ovs_geneve_tnl_init(void) { return ovs_vport_ops_register(&ovs_geneve_vport_ops); } static void __exit ovs_geneve_tnl_exit(void) { ovs_vport_ops_unregister(&ovs_geneve_vport_ops); } module_init(ovs_geneve_tnl_init); module_exit(ovs_geneve_tnl_exit); |
fc4fa6e11 treewide: Fix typ... |
134 |
MODULE_DESCRIPTION("OVS: Geneve switching port"); |
62b9c8d03 ovs: Turn vports ... |
135 136 |
MODULE_LICENSE("GPL"); MODULE_ALIAS("vport-type-5"); |