Creates VXLAN devices using rtnetlink and tunnel metadata. Co-Authored-by: Thadeu Lima de Souza Cascardo <casca...@redhat.com> Signed-off-by: Thadeu Lima de Souza Cascardo <casca...@redhat.com> Signed-off-by: Eric Garver <e...@erig.me> --- lib/dpif-netlink-rtnl.c | 80 ++++++++++++++++++++++++++++++++++++++++++++----- lib/dpif-netlink-rtnl.h | 3 +- 2 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/lib/dpif-netlink-rtnl.c b/lib/dpif-netlink-rtnl.c index 906e05145190..6ab882c73756 100644 --- a/lib/dpif-netlink-rtnl.c +++ b/lib/dpif-netlink-rtnl.c @@ -26,6 +26,18 @@ #include "netdev-vport.h" #include "netlink-socket.h" +/* On some older systems, these enums are not defined. */ +#ifndef IFLA_VXLAN_MAX +#define IFLA_VXLAN_MAX 0 +#endif +#if IFLA_VXLAN_MAX < 25 +#define IFLA_VXLAN_LEARNING 7 +#define IFLA_VXLAN_PORT 15 +#define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20 +#define IFLA_VXLAN_GBP 23 +#define IFLA_VXLAN_COLLECT_METADATA 25 +#endif + static const struct nl_policy rtlink_policy[] = { [IFLA_LINKINFO] = { .type = NL_A_NESTED }, }; @@ -33,6 +45,12 @@ static const struct nl_policy linkinfo_policy[] = { [IFLA_INFO_KIND] = { .type = NL_A_STRING }, [IFLA_INFO_DATA] = { .type = NL_A_NESTED }, }; +static const struct nl_policy vxlan_policy[] = { + [IFLA_VXLAN_COLLECT_METADATA] = { .type = NL_A_U8 }, + [IFLA_VXLAN_LEARNING] = { .type = NL_A_U8 }, + [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NL_A_U8 }, + [IFLA_VXLAN_PORT] = { .type = NL_A_U16 }, +}; static int rtnl_transact(uint32_t type, uint32_t flags, const char *name, @@ -58,13 +76,13 @@ dpif_netlink_rtnl_destroy(const char *name) return rtnl_transact(RTM_DELLINK, NLM_F_REQUEST | NLM_F_ACK, name, NULL); } -static int OVS_UNUSED +static int dpif_netlink_rtnl_getlink(const char *name, struct ofpbuf **reply) { return rtnl_transact(RTM_GETLINK, NLM_F_REQUEST, name, reply); } -static int OVS_UNUSED +static int rtnl_policy_parse(const char *kind, struct ofpbuf *reply, const struct nl_policy *policy, struct nlattr *tnl_info[], @@ -90,11 +108,48 @@ rtnl_policy_parse(const char *kind, struct ofpbuf *reply, } static int -dpif_netlink_rtnl_verify(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, - enum ovs_vport_type type, const char OVS_UNUSED *name) +dpif_netlink_rtnl_vxlan_verify(const struct netdev_tunnel_config *tnl_cfg, + const char *name, const char *kind) +{ + struct ofpbuf *reply; + int err; + + err = dpif_netlink_rtnl_getlink(name, &reply); + + if (!err) { + struct nlattr *vxlan[ARRAY_SIZE(vxlan_policy)]; + + err = rtnl_policy_parse(kind, reply, vxlan_policy, vxlan, + ARRAY_SIZE(vxlan_policy)); + if (!err) { + if (0 != nl_attr_get_u8(vxlan[IFLA_VXLAN_LEARNING]) + || 1 != nl_attr_get_u8(vxlan[IFLA_VXLAN_COLLECT_METADATA]) + || 1 != nl_attr_get_u8(vxlan[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) + || (tnl_cfg->dst_port + != nl_attr_get_be16(vxlan[IFLA_VXLAN_PORT]))) { + err = EINVAL; + } + } + if (!err) { + if (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP) + && !nl_attr_get_flag(vxlan[IFLA_VXLAN_GBP])) { + err = EINVAL; + } + } + ofpbuf_delete(reply); + } + + return err; +} + + +static int +dpif_netlink_rtnl_verify(const struct netdev_tunnel_config *tnl_cfg, + enum ovs_vport_type type, const char *name) { switch (type) { case OVS_VPORT_TYPE_VXLAN: + return dpif_netlink_rtnl_vxlan_verify(tnl_cfg, name, "vxlan"); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -110,8 +165,8 @@ dpif_netlink_rtnl_verify(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, return 0; } -static int OVS_UNUSED -dpif_netlink_rtnl_create(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, +static int +dpif_netlink_rtnl_create(const struct netdev_tunnel_config *tnl_cfg, const char *name, enum ovs_vport_type type, const char *kind, uint32_t flags) { @@ -133,6 +188,14 @@ dpif_netlink_rtnl_create(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, /* tunnel unique info */ switch (type) { case OVS_VPORT_TYPE_VXLAN: + nl_msg_put_u8(&request, IFLA_VXLAN_LEARNING, 0); + nl_msg_put_u8(&request, IFLA_VXLAN_COLLECT_METADATA, 1); + nl_msg_put_u8(&request, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 1); + if (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP)) { + nl_msg_put_flag(&request, IFLA_VXLAN_GBP); + } + nl_msg_put_be16(&request, IFLA_VXLAN_PORT, tnl_cfg->dst_port); + break; case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -180,6 +243,8 @@ dpif_netlink_rtnl_port_create(struct netdev *netdev) try_again: switch (type) { case OVS_VPORT_TYPE_VXLAN: + err = dpif_netlink_rtnl_create(tnl_cfg, name, type, "vxlan", flags); + break; case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -208,10 +273,11 @@ try_again: } int -dpif_netlink_rtnl_port_destroy(const char *name OVS_UNUSED, const char *type) +dpif_netlink_rtnl_port_destroy(const char *name, const char *type) { switch (netdev_to_ovs_vport_type(type)) { case OVS_VPORT_TYPE_VXLAN: + return dpif_netlink_rtnl_destroy(name); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: diff --git a/lib/dpif-netlink-rtnl.h b/lib/dpif-netlink-rtnl.h index 5fef314a20f6..952c0d4187e5 100644 --- a/lib/dpif-netlink-rtnl.h +++ b/lib/dpif-netlink-rtnl.h @@ -23,8 +23,7 @@ /* Declare these to keep sparse happy. */ int dpif_netlink_rtnl_port_create(struct netdev *netdev); -int dpif_netlink_rtnl_port_destroy(const char *name OVS_UNUSED, - const char *type); +int dpif_netlink_rtnl_port_destroy(const char *name, const char *type); #ifndef __linux__ /* Dummy implementations for non Linux builds. */ -- 2.12.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev