]>
Commit | Line | Data |
---|---|---|
4237026e PS |
1 | /* |
2 | * Copyright (c) 2015 Nicira, Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
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. | |
8 | */ | |
9 | ||
10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
11 | ||
4237026e PS |
12 | #include <linux/in.h> |
13 | #include <linux/ip.h> | |
4237026e PS |
14 | #include <linux/net.h> |
15 | #include <linux/rculist.h> | |
16 | #include <linux/udp.h> | |
e23775f2 PS |
17 | #include <linux/if_vlan.h> |
18 | #include <linux/module.h> | |
4237026e | 19 | |
e23775f2 | 20 | #include <net/stt.h> |
4237026e PS |
21 | #include <net/icmp.h> |
22 | #include <net/ip.h> | |
23 | #include <net/route.h> | |
4237026e | 24 | #include <net/udp.h> |
e23775f2 PS |
25 | #include <net/xfrm.h> |
26 | #include <net/stt.h> | |
4237026e PS |
27 | |
28 | #include "datapath.h" | |
29 | #include "vport.h" | |
e23775f2 | 30 | #include "vport-netdev.h" |
4237026e PS |
31 | |
32 | #ifdef OVS_STT | |
33 | static struct vport_ops ovs_stt_vport_ops; | |
4237026e | 34 | /** |
e23775f2 PS |
35 | * struct stt_port - Keeps track of open UDP ports |
36 | * @dst_port: destination port. | |
4237026e PS |
37 | */ |
38 | struct stt_port { | |
e23775f2 | 39 | u16 port_no; |
4237026e PS |
40 | }; |
41 | ||
42 | static inline struct stt_port *stt_vport(const struct vport *vport) | |
43 | { | |
44 | return vport_priv(vport); | |
45 | } | |
46 | ||
e23775f2 PS |
47 | static int stt_get_options(const struct vport *vport, |
48 | struct sk_buff *skb) | |
4237026e PS |
49 | { |
50 | struct stt_port *stt_port = stt_vport(vport); | |
4237026e | 51 | |
e23775f2 | 52 | if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, stt_port->port_no)) |
4237026e PS |
53 | return -EMSGSIZE; |
54 | return 0; | |
55 | } | |
56 | ||
4237026e PS |
57 | static struct vport *stt_tnl_create(const struct vport_parms *parms) |
58 | { | |
59 | struct net *net = ovs_dp_get_net(parms->dp); | |
60 | struct nlattr *options = parms->options; | |
61 | struct stt_port *stt_port; | |
e23775f2 | 62 | struct net_device *dev; |
4237026e PS |
63 | struct vport *vport; |
64 | struct nlattr *a; | |
4237026e | 65 | u16 dst_port; |
e23775f2 | 66 | int err; |
4237026e PS |
67 | |
68 | if (!options) { | |
69 | err = -EINVAL; | |
70 | goto error; | |
71 | } | |
72 | ||
73 | a = nla_find_nested(options, OVS_TUNNEL_ATTR_DST_PORT); | |
74 | if (a && nla_len(a) == sizeof(u16)) { | |
75 | dst_port = nla_get_u16(a); | |
76 | } else { | |
77 | /* Require destination port from userspace. */ | |
78 | err = -EINVAL; | |
79 | goto error; | |
80 | } | |
81 | ||
82 | vport = ovs_vport_alloc(sizeof(struct stt_port), | |
83 | &ovs_stt_vport_ops, parms); | |
84 | if (IS_ERR(vport)) | |
85 | return vport; | |
86 | ||
87 | stt_port = stt_vport(vport); | |
e23775f2 | 88 | stt_port->port_no = dst_port; |
4237026e | 89 | |
e23775f2 PS |
90 | rtnl_lock(); |
91 | dev = stt_dev_create_fb(net, parms->name, NET_NAME_USER, dst_port); | |
92 | if (IS_ERR(dev)) { | |
93 | rtnl_unlock(); | |
4237026e | 94 | ovs_vport_free(vport); |
e23775f2 | 95 | return ERR_CAST(dev); |
4237026e | 96 | } |
4237026e | 97 | |
e23775f2 PS |
98 | dev_change_flags(dev, dev->flags | IFF_UP); |
99 | rtnl_unlock(); | |
4237026e PS |
100 | return vport; |
101 | error: | |
102 | return ERR_PTR(err); | |
103 | } | |
104 | ||
e23775f2 | 105 | static struct vport *stt_create(const struct vport_parms *parms) |
4237026e | 106 | { |
e23775f2 | 107 | struct vport *vport; |
4237026e | 108 | |
e23775f2 PS |
109 | vport = stt_tnl_create(parms); |
110 | if (IS_ERR(vport)) | |
111 | return vport; | |
4237026e | 112 | |
e23775f2 | 113 | return ovs_netdev_link(vport, parms->name); |
4237026e PS |
114 | } |
115 | ||
116 | static struct vport_ops ovs_stt_vport_ops = { | |
e23775f2 PS |
117 | .type = OVS_VPORT_TYPE_STT, |
118 | .create = stt_create, | |
119 | .destroy = ovs_netdev_tunnel_destroy, | |
120 | .get_options = stt_get_options, | |
564666e9 | 121 | #ifndef USE_UPSTREAM_TUNNEL |
aad7cb91 | 122 | .fill_metadata_dst = stt_fill_metadata_dst, |
564666e9 | 123 | #endif |
e23775f2 | 124 | .send = ovs_stt_xmit, |
4237026e PS |
125 | }; |
126 | ||
127 | static int __init ovs_stt_tnl_init(void) | |
128 | { | |
e23775f2 | 129 | return ovs_vport_ops_register(&ovs_stt_vport_ops); |
4237026e PS |
130 | } |
131 | ||
132 | static void __exit ovs_stt_tnl_exit(void) | |
133 | { | |
134 | ovs_vport_ops_unregister(&ovs_stt_vport_ops); | |
4237026e PS |
135 | } |
136 | ||
137 | module_init(ovs_stt_tnl_init); | |
138 | module_exit(ovs_stt_tnl_exit); | |
139 | ||
140 | MODULE_DESCRIPTION("OVS: STT switching port"); | |
141 | MODULE_LICENSE("GPL"); | |
142 | MODULE_ALIAS("vport-type-106"); | |
143 | #endif |