meta-google: gbmc-ncsi-config: Allow BMC address assignment

We need to allow BMC address assignment so that we can deprecate the
impersonation assignment we are currently performing on the BMC.

Change-Id: Ia153d0a5692876ef2c36b71230d597e51904d467
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
index 7934033..9f008a9 100644
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
@@ -29,21 +29,30 @@
   local pfx_bytes=()
   if [ -n "$gbmc_ncsi_br_pub_addr_lastip" ]; then
     ip_to_bytes pfx_bytes "$gbmc_ncsi_br_pub_addr_lastip"
-    # Ensure we don't have more than a /64 address
-    local i
-    for (( i = 8; i < 16; ++i )); do
-      if (( pfx_bytes[$i] != 0 )); then
-        pfx_bytes=()
-        break
-      fi
-    done
+    # Ensure we have a /64 or an fdxx address
+    if (( pfx_bytes[8] != 0xfd || pfx_bytes[9] == 0 )); then
+      local i
+      for (( i = 8; i < 16; ++i )); do
+        if (( pfx_bytes[$i] != 0 )); then
+          pfx_bytes=()
+          break
+        fi
+      done
+    fi
   fi
 
   local contents=
   if (( ${#pfx_bytes[@]} != 0 )); then
     pfx_bytes[8]=0xfd
+    # Save our old prefix assuming we have one
+    local old_offset="${pfx_bytes[9]}"
+    if (( old_offset == 0 )); then
+      old_offset=0x01
+    else
+      pfx_bytes[9]=0x00
+    fi
     local stateless_pfx="$(ip_bytes_to_str pfx_bytes)"
-    pfx_bytes[9]=0x01
+    pfx_bytes[9]="$old_offset"
     local ncsi_pfx="$(ip_bytes_to_str pfx_bytes)"
     read -r -d '' contents <<EOF
 [Network]
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
index 074ec57..1f3ba25 100644
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
@@ -36,6 +36,13 @@
 
   local ip6="$gbmc_ncsi_nft_lastip6"
   if [ -n "$ip6" ]; then
+    # Normalize the provided ipv6 address to the impersonated ipv6 address
+    local ip6_bytes=()
+    ip_to_bytes ip6_bytes "$ip6"
+    for (( i=8; i<16; ++i )); do
+      ip6_bytes[$i]=0
+    done
+    ip6="$(ip_bytes_to_str ip6_bytes)"
     contents+="        ip6 daddr $ip6/128 goto ncsi_legacy_input"$'\n'
   fi