2 * Copyright (c) 2014 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>
20 #include <net/geneve.h>
23 #include <net/route.h>
29 #include "vport-netdev.h"
31 static struct vport_ops ovs_geneve_vport_ops
;
33 * struct geneve_port - Keeps track of open UDP ports
34 * @dst_port: destination port.
40 static inline struct geneve_port
*geneve_vport(const struct vport
*vport
)
42 return vport_priv(vport
);
45 static int geneve_get_options(const struct vport
*vport
,
48 struct geneve_port
*geneve_port
= geneve_vport(vport
);
50 if (nla_put_u16(skb
, OVS_TUNNEL_ATTR_DST_PORT
, geneve_port
->port_no
))
55 static struct vport
*geneve_tnl_create(const struct vport_parms
*parms
)
57 struct net
*net
= ovs_dp_get_net(parms
->dp
);
58 struct nlattr
*options
= parms
->options
;
59 struct geneve_port
*geneve_port
;
60 struct net_device
*dev
;
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
);
75 /* Require destination port from userspace. */
80 vport
= ovs_vport_alloc(sizeof(struct geneve_port
),
81 &ovs_geneve_vport_ops
, parms
);
85 geneve_port
= geneve_vport(vport
);
86 geneve_port
->port_no
= dst_port
;
89 dev
= geneve_dev_create_fb(net
, parms
->name
, NET_NAME_USER
, dst_port
);
92 ovs_vport_free(vport
);
96 dev_change_flags(dev
, dev
->flags
| IFF_UP
);
103 static struct vport
*geneve_create(const struct vport_parms
*parms
)
107 vport
= geneve_tnl_create(parms
);
111 return ovs_netdev_link(vport
, parms
->name
);
114 static struct vport_ops ovs_geneve_vport_ops
= {
115 .type
= OVS_VPORT_TYPE_GENEVE
,
116 .create
= geneve_create
,
117 .destroy
= ovs_netdev_tunnel_destroy
,
118 .get_options
= geneve_get_options
,
119 .send
= ovs_netdev_send
,
120 .owner
= THIS_MODULE
,
123 static int __init
ovs_geneve_tnl_init(void)
125 return ovs_vport_ops_register(&ovs_geneve_vport_ops
);
128 static void __exit
ovs_geneve_tnl_exit(void)
130 ovs_vport_ops_unregister(&ovs_geneve_vport_ops
);
133 module_init(ovs_geneve_tnl_init
);
134 module_exit(ovs_geneve_tnl_exit
);
136 MODULE_DESCRIPTION("OVS: Geneve swiching port");
137 MODULE_LICENSE("GPL");
138 MODULE_ALIAS("vport-type-5");