[ovs-dev] [PATCH] dpif-netlink-rtnl: Set suitable value to ovs geneve and vxlan interfaces' mtu.

JunhanYan juyan at redhat.com
Tue Oct 17 09:53:37 UTC 2017


>From af5c8a50141c7e1a7723a7f992a9e71ad531274d Mon Sep 17 00:00:00 2001
From: JunhanYan <juyan at redhat.com>
Date: Tue, 17 Oct 2017 17:26:20 +0800
Subject: [PATCH] In ovs mtu of ovs geneve interface genev_sys_6081 is always
  0xffff, mtu of vxlan vxlan_sys_4789 is good for ipv4 vxlan, but for ipv6
  vxlan, it is still 65470 as ipv4 vxlan, it's not resonable.

For vxlan, linux kernel do some work for the mtu, so the mtu of
ipv4 vxlan looks good.
This patch fixed this issue in ovs, for the udp tunnel,
calculate the tunnel interface in ovs, and send the final
value to the kernel from rtnetlink.

Signed-off-by: JunhanYan <juyan at redhat.com>
---
  lib/dpif-netlink-rtnl.c | 19 ++++++++++++++++++-
  lib/packets.h           |  6 ++++++
  2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/dpif-netlink-rtnl.c b/lib/dpif-netlink-rtnl.c
index 0c32e7d..d1b227a 100644
--- a/lib/dpif-netlink-rtnl.c
+++ b/lib/dpif-netlink-rtnl.c
@@ -58,6 +58,12 @@ VLOG_DEFINE_THIS_MODULE(dpif_netlink_rtnl);
  #define IFLA_GENEVE_UDP_ZERO_CSUM6_RX 10
  #endif

+#define IP_MAX_MTU      0xFFF0U
+/* IP header + UDP + VXLAN/GENEVE + Ethernet header */
+#define UDP_TNL_HEADROOM (20 + 8 + 8 + 14)
+/* IPv6 header + UDP + VXLAN/GENEVE + Ethernet header */
+#define UDP6_TNL_HEADROOM (40 + 8 + 8 + 14)
+
  static const struct nl_policy rtlink_policy[] = {
      [IFLA_LINKINFO] = { .type = NL_A_NESTED },
  };
@@ -281,13 +287,24 @@ dpif_netlink_rtnl_create(const struct 
netdev_tunnel_config *tnl_cfg,
      struct ifinfomsg *ifinfo;
      struct ofpbuf request;
      int err;
+    uint16_t tnl_mtu;

      ofpbuf_init(&request, 0);
      nl_msg_put_nlmsghdr(&request, 0, RTM_NEWLINK, flags);
      ifinfo = ofpbuf_put_zeros(&request, sizeof(struct ifinfomsg));
      ifinfo->ifi_change = ifinfo->ifi_flags = IFF_UP;
      nl_msg_put_string(&request, IFLA_IFNAME, name);
-    nl_msg_put_u32(&request, IFLA_MTU, UINT16_MAX);
+    /* set mtu for udp tunnel*/
+    if (type == OVS_VPORT_TYPE_VXLAN || type == OVS_VPORT_TYPE_GENEVE){
+       if (in6_addr_is_mapped_ipv4(&tnl_cfg->ipv6_dst)){
+           tnl_mtu = IP_MAX_MTU - UDP_TNL_HEADROOM;
+       }else{
+           tnl_mtu = IP_MAX_MTU - UDP6_TNL_HEADROOM;
+       }
+    }else{
+           tnl_mtu = UINT16_MAX;
+    }
+    nl_msg_put_u32(&request, IFLA_MTU, tnl_mtu);
      linkinfo_off = nl_msg_start_nested(&request, IFLA_LINKINFO);
      nl_msg_put_string(&request, IFLA_INFO_KIND, kind);
      infodata_off = nl_msg_start_nested(&request, IFLA_INFO_DATA);
diff --git a/lib/packets.h b/lib/packets.h
index 705d0b2..9d56b42 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -1115,6 +1115,12 @@ in6_addr_get_mapped_ipv4(const struct in6_addr *addr)
      }
  }

+static inline bool
+in6_addr_is_mapped_ipv4(const struct in6_addr *ipv6_addr)
+{
+    return IN6_IS_ADDR_V4MAPPED(ipv6_addr);
+}
+
  static inline void
  in6_addr_solicited_node(struct in6_addr *addr, const struct in6_addr *ip6)
  {
-- 
2.9.3



More information about the dev mailing list