From 10f53b784798b8d310b73dc18a36c821815bd1fc Mon Sep 17 00:00:00 2001 From: Arjun Dhaliwal Date: Tue, 1 Sep 2026 15:14:24 -0700 Subject: [PATCH 1/2] Add switches to the host init script to toggle legacy behaviour --- ...ish-base.cuttlefish-host-resources.default | 17 ++ ...lefish-base.cuttlefish-host-resources.init | 161 ++++++++++-------- 2 files changed, 106 insertions(+), 72 deletions(-) diff --git a/base/debian/cuttlefish-base.cuttlefish-host-resources.default b/base/debian/cuttlefish-base.cuttlefish-host-resources.default index a6f0cfad7df..c825f0e1b41 100644 --- a/base/debian/cuttlefish-base.cuttlefish-host-resources.default +++ b/base/debian/cuttlefish-base.cuttlefish-host-resources.default @@ -36,3 +36,20 @@ #wifi_ipv6_prefix_length= #ethernet_ipv6_prefix= #ethernet_ipv6_prefix_length= + +# Behavioural settings during the transition to cvdalloc. +# +# allocate_static_resources sets up all of the resources +# expected by the legacy flow. initialize_cvdalloc simply invokes +# cvdalloc to perform its own per-install setup. +# Note that for cvd itself to use cvdalloc, it will need the +# use_cvdalloc flag to be set on its own end. +# +# Static resources are disjoint to those allocated by cvdalloc. +# Thus, the legacy behaviour is maintained by the below defaults. +# +# The only invalid combination is `allocate_static_resources=0` +# with the cvd flag `use_cvdalloc` flipped off. +# +#allocate_static_resources=1 +#initialize_cvdalloc=0 \ No newline at end of file diff --git a/base/debian/cuttlefish-base.cuttlefish-host-resources.init b/base/debian/cuttlefish-base.cuttlefish-host-resources.init index 26fd1e409b1..c0a27f2c6da 100755 --- a/base/debian/cuttlefish-base.cuttlefish-host-resources.init +++ b/base/debian/cuttlefish-base.cuttlefish-host-resources.init @@ -44,6 +44,8 @@ ipv4_bridge=${ipv4_bridge:-1} ipv6_bridge=${ipv6_bridge:-1} dns_servers=${dns_servers:-8.8.8.8,8.8.4.4} dns6_servers=${dns6_servers:-2001:4860:4860::8888,2001:4860:4860::8844} +allocate_static_resources=${allocate_static_resources:-1} +initialize_cvdalloc=${initialize_cvdalloc:-0} readonly CUTTLEFISH_RUN_DIR="/run/cuttlefish" @@ -109,18 +111,30 @@ destroy_tap() { setup_nftables() { mkdir -p "$CUTTLEFISH_RUN_DIR" - # Ensure nftables tables and chains exist. - nft add table ip cuttlefish_nat - nft add chain ip cuttlefish_nat postrouting '{ type nat hook postrouting priority 100 ; }' + if [ "${initialize_cvdalloc}" = "1" ] && [ -x /usr/lib/cuttlefish-common/bin/cvdalloc ]; then + /usr/lib/cuttlefish-common/bin/cvdalloc --setup + fi + + if [ "${allocate_static_resources}" = "1" ]; then + # Ensure nftables tables and chains exist. + nft add table ip cuttlefish_nat + nft add chain ip cuttlefish_nat postrouting '{ type nat hook postrouting priority 100 ; }' - nft add table bridge cuttlefish_bridge - nft add chain bridge cuttlefish_bridge prerouting '{ type filter hook prerouting priority -250 ; }' - nft add chain bridge cuttlefish_bridge forward '{ type filter hook forward priority 0 ; }' + nft add table bridge cuttlefish_bridge + nft add chain bridge cuttlefish_bridge prerouting '{ type filter hook prerouting priority -250 ; }' + nft add chain bridge cuttlefish_bridge forward '{ type filter hook forward priority 0 ; }' + fi } delete_nftables() { - nft delete table ip cuttlefish_nat - nft delete table bridge cuttlefish_bridge + if [ "${initialize_cvdalloc}" = "1" ] && [ -x /usr/lib/cuttlefish-common/bin/cvdalloc ]; then + /usr/lib/cuttlefish-common/bin/cvdalloc --teardown + fi + + if [ "${allocate_static_resources}" = "1" ]; then + nft delete table ip cuttlefish_nat + nft delete table bridge cuttlefish_bridge + fi } @@ -331,43 +345,44 @@ start() { setup_nftables - - # Ethernet - # 192.168.98.X for cvd-ebr and cvd-etap-XX - create_bridged_interfaces \ - 192.168.98 "${ethernet_bridge_interface}" cvd-etap \ - "${ethernet_ipv6_prefix}" "${ethernet_ipv6_prefix_length}" - - # Mobile Network - # 192.168.97.X from cvd-mtap-01 to cvd-mtap-64 - # 192.168.93.X from cvd-mtap-65 to cvd-mtap-128 - for i in $(seq ${num_cvd_accounts}); do - tap="$(printf cvd-mtap-%02d $i)" - if [ $i -lt 65 ]; then - create_interface $tap 192.168.97 $i - elif [ $i -lt 129 ]; then - create_interface $tap 192.168.93 $(($i - 64)) - fi - done - - # Wireless Network - # cvd-wbr and cvd-wtap-XX for legacy wireless network without distinguished - # subnet between tap interfaces, cvd-wifiap-XX with distinguished subnet for - # running several OpenWRT instances simultaneously. - # 192.168.96.X for cvd-wbr and cvd-wtap-XX - # 192.168.94.X from cvd-wifiap-01 to cvd-wifiap-64 - # 192.168.95.X from cvd-wifiap-65 to cvd-wifiap-128 - create_bridged_interfaces \ - 192.168.96 "${wifi_bridge_interface}" cvd-wtap \ - "${wifi_ipv6_prefix}" "${wifi_ipv6_prefix_length}" - for i in $(seq ${num_cvd_accounts}); do - tap="$(printf cvd-wifiap-%02d $i)" - if [ $i -lt 65 ]; then - create_interface $tap 192.168.94 $i - elif [ $i -lt 129 ]; then - create_interface $tap 192.168.95 $(($i - 64)) - fi - done + if [ "${allocate_static_resources}" = "1" ]; then + # Ethernet + # 192.168.98.X for cvd-ebr and cvd-etap-XX + create_bridged_interfaces \ + 192.168.98 "${ethernet_bridge_interface}" cvd-etap \ + "${ethernet_ipv6_prefix}" "${ethernet_ipv6_prefix_length}" + + # Mobile Network + # 192.168.97.X from cvd-mtap-01 to cvd-mtap-64 + # 192.168.93.X from cvd-mtap-65 to cvd-mtap-128 + for i in $(seq ${num_cvd_accounts}); do + tap="$(printf cvd-mtap-%02d $i)" + if [ $i -lt 65 ]; then + create_interface $tap 192.168.97 $i + elif [ $i -lt 129 ]; then + create_interface $tap 192.168.93 $(($i - 64)) + fi + done + + # Wireless Network + # cvd-wbr and cvd-wtap-XX for legacy wireless network without distinguished + # subnet between tap interfaces, cvd-wifiap-XX with distinguished subnet for + # running several OpenWRT instances simultaneously. + # 192.168.96.X for cvd-wbr and cvd-wtap-XX + # 192.168.94.X from cvd-wifiap-01 to cvd-wifiap-64 + # 192.168.95.X from cvd-wifiap-65 to cvd-wifiap-128 + create_bridged_interfaces \ + 192.168.96 "${wifi_bridge_interface}" cvd-wtap \ + "${wifi_ipv6_prefix}" "${wifi_ipv6_prefix_length}" + for i in $(seq ${num_cvd_accounts}); do + tap="$(printf cvd-wifiap-%02d $i)" + if [ $i -lt 65 ]; then + create_interface $tap 192.168.94 $i + elif [ $i -lt 129 ]; then + create_interface $tap 192.168.95 $(($i - 64)) + fi + done + fi # When running inside a privileged container, set the ownership and access # of these device nodes. @@ -385,33 +400,35 @@ start() { } stop() { - # Ethernet - destroy_bridged_interfaces \ - 192.168.98 "${ethernet_bridge_interface}" cvd-etap \ - "${ethernet_ipv6_prefix}" "${ethernet_ipv6_prefix_length}" - - # Mobile Network - for i in $(seq ${num_cvd_accounts}); do - tap="$(printf cvd-mtap-%02d $i)" - if [ $i -lt 65 ]; then - destroy_interface $tap 192.168.97 $i - elif [ $i -lt 129 ]; then - destroy_interface $tap 192.168.93 $(($i - 64)) - fi - done - - # Wireless Network - destroy_bridged_interfaces \ - 192.168.96 "${wifi_bridge_interface}" cvd-wtap \ - "${wifi_ipv6_prefix}" "${wifi_ipv6_prefix_length}" - for i in $(seq ${num_cvd_accounts}); do - tap="$(printf cvd-wifiap-%02d $i)" - if [ $i -lt 65 ]; then - destroy_interface $tap 192.168.94 $i - elif [ $i -lt 129 ]; then - destroy_interface $tap 192.168.95 $(($i - 64)) - fi - done + if [ "${allocate_static_resources}" = "1" ]; then + # Ethernet + destroy_bridged_interfaces \ + 192.168.98 "${ethernet_bridge_interface}" cvd-etap \ + "${ethernet_ipv6_prefix}" "${ethernet_ipv6_prefix_length}" + + # Mobile Network + for i in $(seq ${num_cvd_accounts}); do + tap="$(printf cvd-mtap-%02d $i)" + if [ $i -lt 65 ]; then + destroy_interface $tap 192.168.97 $i + elif [ $i -lt 129 ]; then + destroy_interface $tap 192.168.93 $(($i - 64)) + fi + done + + # Wireless Network + destroy_bridged_interfaces \ + 192.168.96 "${wifi_bridge_interface}" cvd-wtap \ + "${wifi_ipv6_prefix}" "${wifi_ipv6_prefix_length}" + for i in $(seq ${num_cvd_accounts}); do + tap="$(printf cvd-wifiap-%02d $i)" + if [ $i -lt 65 ]; then + destroy_interface $tap 192.168.94 $i + elif [ $i -lt 129 ]; then + destroy_interface $tap 192.168.95 $(($i - 64)) + fi + done + fi delete_nftables } From 094f236afa7beaaa8d765ba559948f17109c9e0d Mon Sep 17 00:00:00 2001 From: Arjun Dhaliwal Date: Thu, 3 Sep 2026 16:55:03 -0700 Subject: [PATCH 2/2] flip the flag off to see if the test fails --- base/debian/cuttlefish-base.cuttlefish-host-resources.init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/debian/cuttlefish-base.cuttlefish-host-resources.init b/base/debian/cuttlefish-base.cuttlefish-host-resources.init index c0a27f2c6da..bbe87346daf 100755 --- a/base/debian/cuttlefish-base.cuttlefish-host-resources.init +++ b/base/debian/cuttlefish-base.cuttlefish-host-resources.init @@ -44,7 +44,7 @@ ipv4_bridge=${ipv4_bridge:-1} ipv6_bridge=${ipv6_bridge:-1} dns_servers=${dns_servers:-8.8.8.8,8.8.4.4} dns6_servers=${dns6_servers:-2001:4860:4860::8888,2001:4860:4860::8844} -allocate_static_resources=${allocate_static_resources:-1} +allocate_static_resources=${allocate_static_resources:-0} initialize_cvdalloc=${initialize_cvdalloc:-0} readonly CUTTLEFISH_RUN_DIR="/run/cuttlefish"