diff --git a/playbooks/roles/ovs_vxlan_bridge_peers/defaults/main.yaml b/playbooks/roles/ovs_vxlan_bridge_peers/defaults/main.yaml index efa04952..6d1057f9 100644 --- a/playbooks/roles/ovs_vxlan_bridge_peers/defaults/main.yaml +++ b/playbooks/roles/ovs_vxlan_bridge_peers/defaults/main.yaml @@ -1,3 +1,6 @@ ovs_starting_offset: 1 ovs_vni_offset: 1000000 -ovs_bridge_mtu: 1450 + +# This value can be set to override the dynamic determinication +# of this value. +# ovs_bridge_mtu: 1450 diff --git a/playbooks/roles/ovs_vxlan_bridge_peers/tasks/main.yaml b/playbooks/roles/ovs_vxlan_bridge_peers/tasks/main.yaml index 71b0b7cb..25ac723b 100644 --- a/playbooks/roles/ovs_vxlan_bridge_peers/tasks/main.yaml +++ b/playbooks/roles/ovs_vxlan_bridge_peers/tasks/main.yaml @@ -26,6 +26,40 @@ openvswitch_bridge: bridge: "{{ bridge_name }}" +- when: ovs_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 ovs_bridge_mtu + set_fact: + ovs_bridge_mtu: "{{ mtu_output.stdout }}" + - name: Set MTU on subnode bridge command: ip link set mtu {{ ovs_bridge_mtu }} dev {{ bridge_name }} diff --git a/playbooks/roles/ovs_vxlan_bridge_primary/defaults/main.yaml b/playbooks/roles/ovs_vxlan_bridge_primary/defaults/main.yaml index b3be0eed..88de8e67 100644 --- a/playbooks/roles/ovs_vxlan_bridge_primary/defaults/main.yaml +++ b/playbooks/roles/ovs_vxlan_bridge_primary/defaults/main.yaml @@ -1,2 +1,5 @@ ovs_starting_offset: 1 -ovs_bridge_mtu: 1450 + +# This value can be set to override the dynamic determinication +# of this value. +# ovs_bridge_mtu: 1450 diff --git a/playbooks/roles/ovs_vxlan_bridge_primary/tasks/main.yaml b/playbooks/roles/ovs_vxlan_bridge_primary/tasks/main.yaml index ddf2d207..ca64fd95 100644 --- a/playbooks/roles/ovs_vxlan_bridge_primary/tasks/main.yaml +++ b/playbooks/roles/ovs_vxlan_bridge_primary/tasks/main.yaml @@ -2,6 +2,40 @@ openvswitch_bridge: bridge: "{{ bridge_name }}" +- when: ovs_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 ovs_bridge_mtu + set_fact: + ovs_bridge_mtu: "{{ mtu_output.stdout }}" + - name: Set bridge MTU command: ip link set mtu {{ ovs_bridge_mtu }} dev {{ bridge_name }}