From 258a0d6ec71e318691600547d7faf2003df33c05 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 26 Jun 2018 09:54:09 -0700 Subject: [PATCH] Dynamically determine overlay network mtu Not all clouds will provide us with MTUs of 1500. Instead of assuming a 1500 - 50 byte MTU to accomodate for vxlan overhead we list all interface MTUs, filter by those that appear to be "real" interfaces (to avoid those we ourselves may have created), take the smallest one and subtract it by 50 to accomodate for vxlan overhead. You can still set an explicitl bridge_mtu value if necessary. Change-Id: If899a1bee3b4b69df8c2905a219b41e119d8f652 --- roles/multi-node-bridge/README.rst | 7 +++-- roles/multi-node-bridge/defaults/main.yaml | 1 - roles/multi-node-bridge/tasks/common.yaml | 34 ++++++++++++++++++++++ roles/multi-node-bridge/tasks/main.yaml | 6 ++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/roles/multi-node-bridge/README.rst b/roles/multi-node-bridge/README.rst index fe6266f8b..aa1b0c35a 100644 --- a/roles/multi-node-bridge/README.rst +++ b/roles/multi-node-bridge/README.rst @@ -34,9 +34,12 @@ inventory in order to work: VXLAN Network Identifier offset (openvswitch key). .. zuul:rolevar:: bridge_mtu - :default: 1450 + :default: Smallest mtu less 50 bytes for vxlan overhead - Bridge interface MTU. + Bridge interface MTU. By default we determine this value by checking + all interfaces on host, taking the smallest MTU and subtracting by + 50 for vxlan overhead. Can be overridden explicitly if this does not + work. .. zuul:rolevar:: bridge_name :default: br-infra diff --git a/roles/multi-node-bridge/defaults/main.yaml b/roles/multi-node-bridge/defaults/main.yaml index dc93e7b81..1ba0c86ee 100644 --- a/roles/multi-node-bridge/defaults/main.yaml +++ b/roles/multi-node-bridge/defaults/main.yaml @@ -1,5 +1,4 @@ bridge_vni_offset: 1000000 -bridge_mtu: 1450 bridge_name: br-infra bridge_authorize_internal_traffic: false diff --git a/roles/multi-node-bridge/tasks/common.yaml b/roles/multi-node-bridge/tasks/common.yaml index 2cc66e18a..facd51a81 100644 --- a/roles/multi-node-bridge/tasks/common.yaml +++ b/roles/multi-node-bridge/tasks/common.yaml @@ -52,3 +52,37 @@ when: - bridge_configure_address | bool - bridge_authorize_internal_traffic | bool + +- when: bridge_mtu is not defined + block: + - name: Determine bridge mtu + shell: | + # Find all interfaces with a permanent mac address type. + # Permanent mac addrs imply "real" hardware and not interfaces we have + # created through this system. This makes our MTU determination mostly + # idempotent allowing us to create multiple overlays without + # perpetually smaller MTUs. + SMALLEST_MTU="" + for X in $(ls /sys/class/net) ; do + MAC_TYPE=$(cat "/sys/class/net/${X}/addr_assign_type") + if [ "$MAC_TYPE" -ne "0" ] ; then + # Type 0 is a permanent address implying a "real" + # interface. We ignore other interfaces as that is what we + # create here + continue + fi + MTU=$(cat "/sys/class/net/${X}/mtu") + if [ -z "$SMALLEST_MTU" ] || [ "$SMALLEST_MTU" -gt "$MTU" ] ; then + SMALLEST_MTU=$MTU + fi + done + # 50 byte overhead for vxlan + echo $(( SMALLEST_MTU - 50 )) + args: + executable: /bin/bash + environment: + PATH: '{{ ansible_env.PATH }}:/bin:/sbin:/usr/sbin' + register: mtu_output + - name: Set bridge_mtu + set_fact: + bridge_mtu: "{{ mtu_output.stdout }}" diff --git a/roles/multi-node-bridge/tasks/main.yaml b/roles/multi-node-bridge/tasks/main.yaml index 70b1f79d8..384d1abf8 100644 --- a/roles/multi-node-bridge/tasks/main.yaml +++ b/roles/multi-node-bridge/tasks/main.yaml @@ -1,8 +1,10 @@ -- include: common.yaml - # Note (dmsimard) # We explicitely declare a PATH environment variable because '/sbin' is not in # PATH when using 'become: yes' on some distributions +- include: common.yaml + environment: + PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin" + - include: switch.yaml environment: PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"