meta-google: gbmc-bridge: skip gbmcbr config if ip does not change

GBMC bridge ip is set up via different sources at different moments.
This change skips the unnecessary reconfiguration so that the network
will be less disturbed.

Change-Id: I0ecbad0693398b32037c6be7228444a7d7f89076
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh
index d3bf95d..95516d6 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh
@@ -70,6 +70,9 @@
     return 0
   fi
 
+  # Remove legacy network configuration
+  rm -rf /etc/systemd/network/{00,}-bmc-gbmcbr.network.d
+
   local pfx_bytes=()
   if ! ip_to_bytes pfx_bytes "$ip"; then
     echo "Ignoring Invalid IPv6: $ip" >&2
@@ -111,17 +114,17 @@
 
 gbmc_br_set_ip() {
   local ip="${1-}"
-
+  local old_ip=
   if [ -n "$ip" ]; then
+    old_ip="$(cat /var/google/gbmc-br-ip 2>/dev/null)"
+    [ "$old_ip" != "$ip" ] || return
     mkdir -p /var/google || return
     echo "$ip" >/var/google/gbmc-br-ip || return
   else
+    [ -f "/var/google/gbmc-br-ip" ] || return
     rm -rf /var/google/gbmc-br-ip
   fi
 
-  # Remove legacy network configuration
-  rm -rf /etc/systemd/network/{00,}-bmc-gbmcbr.network.d
-
   gbmc_br_run_hooks GBMC_BR_LIB_SET_IP_HOOKS "$ip" || return
 
   gbmc_br_reload_ip "$ip"