1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2014 Nicira, Inc.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/net.h>
11 #include <linux/rculist.h>
12 #include <linux/udp.h>
13 #include <linux/if_vlan.h>
14 #include <linux/module.h>
16 #include <net/geneve.h>
19 #include <net/route.h>
25 #include "vport-netdev.h"
27 static struct vport_ops ovs_geneve_vport_ops
;
29 * struct geneve_port - Keeps track of open UDP ports
30 * @dst_port: destination port.
36 static inline struct geneve_port
*geneve_vport(const struct vport
*vport
)
38 return vport_priv(vport
);
41 static int geneve_get_options(const struct vport
*vport
,
44 struct geneve_port
*geneve_port
= geneve_vport(vport
);
46 if (nla_put_u16(skb
, OVS_TUNNEL_ATTR_DST_PORT
, geneve_port
->dst_port
))
51 static struct vport
*geneve_tnl_create(const struct vport_parms
*parms
)
53 struct net
*net
= ovs_dp_get_net(parms
->dp
);
54 struct nlattr
*options
= parms
->options
;
55 struct geneve_port
*geneve_port
;
56 struct net_device
*dev
;
67 a
= nla_find_nested(options
, OVS_TUNNEL_ATTR_DST_PORT
);
68 if (a
&& nla_len(a
) == sizeof(u16
)) {
69 dst_port
= nla_get_u16(a
);
71 /* Require destination port from userspace. */
76 vport
= ovs_vport_alloc(sizeof(struct geneve_port
),
77 &ovs_geneve_vport_ops
, parms
);
81 geneve_port
= geneve_vport(vport
);
82 geneve_port
->dst_port
= dst_port
;
85 dev
= geneve_dev_create_fb(net
, parms
->name
, NET_NAME_USER
, dst_port
);
88 ovs_vport_free(vport
);
92 err
= dev_change_flags(dev
, dev
->flags
| IFF_UP
, NULL
);
94 rtnl_delete_link(dev
);
96 ovs_vport_free(vport
);
106 static struct vport
*geneve_create(const struct vport_parms
*parms
)
110 vport
= geneve_tnl_create(parms
);
114 return ovs_netdev_link(vport
, parms
->name
);
117 static struct vport_ops ovs_geneve_vport_ops
= {
118 .type
= OVS_VPORT_TYPE_GENEVE
,
119 .create
= geneve_create
,
120 .destroy
= ovs_netdev_tunnel_destroy
,
121 .get_options
= geneve_get_options
,
122 .send
= dev_queue_xmit
,
125 static int __init
ovs_geneve_tnl_init(void)
127 return ovs_vport_ops_register(&ovs_geneve_vport_ops
);
130 static void __exit
ovs_geneve_tnl_exit(void)
132 ovs_vport_ops_unregister(&ovs_geneve_vport_ops
);
135 module_init(ovs_geneve_tnl_init
);
136 module_exit(ovs_geneve_tnl_exit
);
138 MODULE_DESCRIPTION("OVS: Geneve switching port");
139 MODULE_LICENSE("GPL");
140 MODULE_ALIAS("vport-type-5");