env/darwin/aws: assign static IPs to each guest

Currently, DHCP assigns a dynamic IP to each guest. This means that the
parent program doesn't know the IP of the guest in order to do
health checks.

Add a static IP assignment based on the guest MAC address.

For golang/go#48945.

Change-Id: Icafa4aa5a0b87ab815c882bc8215d5932d1377c0
Reviewed-on: https://go-review.googlesource.com/c/build/+/449875
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/env/darwin/aws/README.md b/env/darwin/aws/README.md
index 48826e0..0ad5d84 100644
--- a/env/darwin/aws/README.md
+++ b/env/darwin/aws/README.md
@@ -143,8 +143,10 @@
 2. Download the UTM QEMU fork and extract to `~/sysroot-macos-x86_64`.
    1. Available as `Sysroot-macos-x86_64` in
       https://github.com/utmapp/UTM/actions?query=event%3Arelease builds.
-3. Copy `qemu.sh` and `start-snapshot.sh` to `$HOME`.
-4. Create `$HOME/loop1.sh`:
+3. Copy `bootptab` to `/etc/bootptab`.
+4. Restart the system DHCP server to pick up the new `bootptab`: `sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist && sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist`.
+4. Copy `qemu.sh` and `start-snapshot.sh` to `$HOME`.
+5. Create `$HOME/loop1.sh`:
 
 ```sh
 #!/bin/bash
diff --git a/env/darwin/aws/bootptab b/env/darwin/aws/bootptab
new file mode 100644
index 0000000..98d709b
--- /dev/null
+++ b/env/darwin/aws/bootptab
@@ -0,0 +1,7 @@
+# Copyright 2022 Go Authors All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+%%
+# hostname      hwtype  hwaddr              ipaddr          bootfile
+builder-guest-1 1       52:54:00:c9:18:01   192.168.64.101
+builder-guest-2 1       52:54:00:c9:18:02   192.168.64.102
diff --git a/env/darwin/aws/qemu.sh b/env/darwin/aws/qemu.sh
index 61e4bee..499fba9 100755
--- a/env/darwin/aws/qemu.sh
+++ b/env/darwin/aws/qemu.sh
@@ -35,7 +35,9 @@
   -device ich9-ahci,id=sata
   -drive id=MacHDD,if=none,format=qcow2,file="$DISK"
   -device ide-hd,bus=sata.2,drive=MacHDD
-  -netdev vmnet-shared,id=net0
+  # DHCP range is a dummy range. The actual guest IP is assigned statically
+  # based on the MAC address matching an entry in /etc/bootptab.
+  -netdev vmnet-shared,id=net0,start-address=192.168.64.1,end-address=192.168.64.100,subnet-mask=255.255.255.0
   -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:0$PORT # for macOS >= 11
   # -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:0$PORT # for macOS < 11
   -monitor stdio