From 3e67ceadb2f756ecb797504500bf03b9fb9cc36d Mon Sep 17 00:00:00 2001
From: Hyunkook Cho <hk0713.cho@samsung.com>
Date: Mon, 18 Mar 2019 19:14:05 +0900
Subject: [PATCH] change the way to get tunnel device

to set local_ip in osh, you have to use nic name.
but some devices can have different nic name.
so I add new option for getting tunnel device by cidr.

Added value:
network:
  interface:
    tunnel: null
    tunnel_network_cidr: "0/0"

Change-Id: I8bffae640dfe0086de0b5274bb8c3cdce9754160
Signed-off-by: Hyunkook Cho <hk0713.cho@samsung.com>
---
 .../bin/_neutron-linuxbridge-agent-init.sh.tpl        | 11 ++++++++---
 .../bin/_neutron-openvswitch-agent-init.sh.tpl        | 11 ++++++++---
 neutron/values.yaml                                   |  7 ++++---
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/neutron/templates/bin/_neutron-linuxbridge-agent-init.sh.tpl b/neutron/templates/bin/_neutron-linuxbridge-agent-init.sh.tpl
index 71a2b6bf29..fb8123bc6e 100644
--- a/neutron/templates/bin/_neutron-linuxbridge-agent-init.sh.tpl
+++ b/neutron/templates/bin/_neutron-linuxbridge-agent-init.sh.tpl
@@ -37,9 +37,14 @@ done
 
 tunnel_interface="{{- .Values.network.interface.tunnel -}}"
 if [ -z "${tunnel_interface}" ] ; then
-    # search for interface with default routing
-    # If there is not default gateway, exit
-    tunnel_interface=$(ip -4 route list 0/0 | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1
+    # search for interface with tunnel network routing
+    tunnel_network_cidr="{{- .Values.network.interface.tunnel_network_cidr -}}"
+    if [ -z "${tunnel_network_cidr}" ] ; then
+        tunnel_network_cidr="0/0"
+    fi
+    # If there is not tunnel network gateway, exit
+    tunnel_interface=$(ip -4 route list ${tunnel_network_cidr} | awk -F 'dev' '{ print $2; exit }' \
+        | awk '{ print $1 }') || exit 1
 fi
 
 # determine local-ip dynamically based on interface provided but only if tunnel_types is not null
diff --git a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl
index 4dfb0ffd4c..b9c4b78d65 100644
--- a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl
+++ b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl
@@ -51,9 +51,14 @@ done
 
 tunnel_interface="{{- .Values.network.interface.tunnel -}}"
 if [ -z "${tunnel_interface}" ] ; then
-    # search for interface with default routing
-    # If there is not default gateway, exit
-    tunnel_interface=$(ip -4 route list 0/0 | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1
+    # search for interface with tunnel network routing
+    tunnel_network_cidr="{{- .Values.network.interface.tunnel_network_cidr -}}"
+    if [ -z "${tunnel_network_cidr}" ] ; then
+        tunnel_network_cidr="0/0"
+    fi
+    # If there is not tunnel network gateway, exit
+    tunnel_interface=$(ip -4 route list ${tunnel_network_cidr} | awk -F 'dev' '{ print $2; exit }' \
+        | awk '{ print $1 }') || exit 1
 fi
 
 # determine local-ip dynamically based on interface provided but only if tunnel_types is not null
diff --git a/neutron/values.yaml b/neutron/values.yaml
index 5ab4ca120b..836807e4f2 100644
--- a/neutron/values.yaml
+++ b/neutron/values.yaml
@@ -91,10 +91,11 @@ network:
   # debugging. This feature requires mount propagation support.
   share_namespaces: true
   interface:
-  # Tunnel interface will be used for VXLAN tunneling. If null
-  # (default) there is a fallback mechanism to search for interface
-  # with default routing.
+  # Tunnel interface will be used for VXLAN tunneling.
     tunnel: null
+  # If tunnel is null there is a fallback mechanism to search
+  # for interface with routing using tunnel network cidr.
+    tunnel_network_cidr: "0/0"
   sriov:
   # To perform setup of network interfaces using the SR-IOV init
   # container you can use a section similar to: