2 * Copyright (c) 2015 Nicira, Inc.
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.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/net.h>
15 #include <linux/rculist.h>
16 #include <linux/udp.h>
17 #include <linux/if_vlan.h>
18 #include <linux/module.h>
23 #include <net/route.h>
30 #include "vport-netdev.h"
33 static struct vport_ops ovs_stt_vport_ops
;
35 * struct stt_port - Keeps track of open UDP ports
36 * @dst_port: destination port.
42 static inline struct stt_port
*stt_vport(const struct vport
*vport
)
44 return vport_priv(vport
);
47 static int stt_get_options(const struct vport
*vport
,
50 struct stt_port
*stt_port
= stt_vport(vport
);
52 if (nla_put_u16(skb
, OVS_TUNNEL_ATTR_DST_PORT
, stt_port
->port_no
))
57 static struct vport
*stt_tnl_create(const struct vport_parms
*parms
)
59 struct net
*net
= ovs_dp_get_net(parms
->dp
);
60 struct nlattr
*options
= parms
->options
;
61 struct stt_port
*stt_port
;
62 struct net_device
*dev
;
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
);
77 /* Require destination port from userspace. */
82 vport
= ovs_vport_alloc(sizeof(struct stt_port
),
83 &ovs_stt_vport_ops
, parms
);
87 stt_port
= stt_vport(vport
);
88 stt_port
->port_no
= dst_port
;
91 dev
= stt_dev_create_fb(net
, parms
->name
, NET_NAME_USER
, dst_port
);
94 ovs_vport_free(vport
);
98 dev_change_flags(dev
, dev
->flags
| IFF_UP
);
105 static struct vport
*stt_create(const struct vport_parms
*parms
)
109 vport
= stt_tnl_create(parms
);
113 return ovs_netdev_link(vport
, parms
->name
);
116 static struct vport_ops ovs_stt_vport_ops
= {
117 .type
= OVS_VPORT_TYPE_STT
,
118 .create
= stt_create
,
119 .destroy
= ovs_netdev_tunnel_destroy
,
120 .get_options
= stt_get_options
,
121 #ifndef USE_UPSTREAM_TUNNEL
122 .fill_metadata_dst
= stt_fill_metadata_dst
,
124 .send
= ovs_stt_xmit
,
127 static int __init
ovs_stt_tnl_init(void)
129 return ovs_vport_ops_register(&ovs_stt_vport_ops
);
132 static void __exit
ovs_stt_tnl_exit(void)
134 ovs_vport_ops_unregister(&ovs_stt_vport_ops
);
137 module_init(ovs_stt_tnl_init
);
138 module_exit(ovs_stt_tnl_exit
);
140 MODULE_DESCRIPTION("OVS: STT switching port");
141 MODULE_LICENSE("GPL");
142 MODULE_ALIAS("vport-type-106");