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>
29 #include "vport-netdev.h"
31 static struct vport_ops ovs_lisp_vport_ops
;
33 * struct lisp_port - Keeps track of open UDP ports
34 * @dst_port: destination port.
40 static inline struct lisp_port
*lisp_vport(const struct vport
*vport
)
42 return vport_priv(vport
);
45 static int lisp_get_options(const struct vport
*vport
,
48 struct lisp_port
*lisp_port
= lisp_vport(vport
);
50 if (nla_put_u16(skb
, OVS_TUNNEL_ATTR_DST_PORT
, lisp_port
->port_no
))
55 static int lisp_get_egress_tun_info(struct vport
*vport
, struct sk_buff
*skb
,
56 struct dp_upcall_info
*upcall
)
58 struct lisp_port
*lisp_port
= lisp_vport(vport
);
59 struct net
*net
= ovs_dp_get_net(vport
->dp
);
60 __be16 dport
= htons(lisp_port
->port_no
);
61 __be16 sport
= udp_flow_src_port(net
, skb
, 1, USHRT_MAX
, true);
63 return ovs_tunnel_get_egress_info(upcall
, ovs_dp_get_net(vport
->dp
),
64 skb
, IPPROTO_UDP
, sport
, dport
);
67 static struct vport
*lisp_tnl_create(const struct vport_parms
*parms
)
69 struct net
*net
= ovs_dp_get_net(parms
->dp
);
70 struct nlattr
*options
= parms
->options
;
71 struct lisp_port
*lisp_port
;
72 struct net_device
*dev
;
83 a
= nla_find_nested(options
, OVS_TUNNEL_ATTR_DST_PORT
);
84 if (a
&& nla_len(a
) == sizeof(u16
)) {
85 dst_port
= nla_get_u16(a
);
87 /* Require destination port from userspace. */
92 vport
= ovs_vport_alloc(sizeof(struct lisp_port
),
93 &ovs_lisp_vport_ops
, parms
);
97 lisp_port
= lisp_vport(vport
);
98 lisp_port
->port_no
= dst_port
;
101 dev
= lisp_dev_create_fb(net
, parms
->name
, NET_NAME_USER
, dst_port
);
104 ovs_vport_free(vport
);
105 return ERR_CAST(dev
);
108 dev_change_flags(dev
, dev
->flags
| IFF_UP
);
115 static struct vport
*lisp_create(const struct vport_parms
*parms
)
119 vport
= lisp_tnl_create(parms
);
123 return ovs_netdev_link(vport
, parms
->name
);
126 static struct vport_ops ovs_lisp_vport_ops
= {
127 .type
= OVS_VPORT_TYPE_LISP
,
128 .create
= lisp_create
,
129 .destroy
= ovs_netdev_tunnel_destroy
,
130 .get_options
= lisp_get_options
,
132 .get_egress_tun_info
= lisp_get_egress_tun_info
,
135 static int __init
ovs_lisp_tnl_init(void)
137 return ovs_vport_ops_register(&ovs_lisp_vport_ops
);
140 static void __exit
ovs_lisp_tnl_exit(void)
142 ovs_vport_ops_unregister(&ovs_lisp_vport_ops
);
145 module_init(ovs_lisp_tnl_init
);
146 module_exit(ovs_lisp_tnl_exit
);
148 MODULE_DESCRIPTION("OVS: Lisp switching port");
149 MODULE_LICENSE("GPL");
150 MODULE_ALIAS("vport-type-105");