summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungjae Yoo <seungjaeyoo@google.com>2023-01-03 01:13:10 +0000
committerSeungjae Yoo <seungjaeyoo@google.com>2023-01-12 17:33:19 +0900
commit6df3b6e14d060ed862687d93d44eb73d27504e80 (patch)
tree98ae543e0e6eb0aa7fba4aec12d98babbece4623
parentd60b534505b3c98eb9cc0827a084b224bdde85a0 (diff)
downloadopenwrt-prebuilts-6df3b6e14d060ed862687d93d44eb73d27504e80.tar.gz
Make OpenWRT IP address changable dynamically based on base_instance_num
Bug: 262703275 Test: launch_cvd --base_instance_num=2 using tap device setting with wireless bridge or not Change-Id: I1a54bb17efb5de29618f23f7fa25f9f3e0594208
-rw-r--r--shared/config/network15
-rw-r--r--shared/uci-defaults/0_default_config46
2 files changed, 51 insertions, 10 deletions
diff --git a/shared/config/network b/shared/config/network
index ab71eb2..1d76e21 100644
--- a/shared/config/network
+++ b/shared/config/network
@@ -33,21 +33,16 @@ config device
config interface 'wan'
option device 'br-lan'
option proto 'static'
- option netmask '255.255.255.0'
- option ipaddr '192.168.96.2'
+ option netmask '255.255.255.252'
option ip6assign '30'
- option gateway '192.168.96.1'
option dns '8.8.8.8'
- option broadcast '192.168.96.3'
config interface 'wifi0'
- option proto 'static'
- option ipaddr '192.168.2.1'
- option netmask '255.255.255.0'
option device 'br-wifi0'
+ option proto 'static'
+ option netmask '255.255.255.192'
config interface 'wifi1'
- option proto 'static'
- option ipaddr '192.168.3.1'
- option netmask '255.255.255.0'
option device 'br-wifi1'
+ option proto 'static'
+ option netmask '255.255.255.192'
diff --git a/shared/uci-defaults/0_default_config b/shared/uci-defaults/0_default_config
index 093006f..1f82066 100644
--- a/shared/uci-defaults/0_default_config
+++ b/shared/uci-defaults/0_default_config
@@ -1,4 +1,50 @@
#!/bin/sh
+
opkg install /ipks/*
ip link set eth0 mtu 1460
+
+# Extract instance_num of CF instance. The default value is 1.
+instance_num=1
+bridged_host_network=false
+words=$(cat /proc/cmdline)
+while
+ word=${words%%" "*}
+ if echo "$word" | grep "instance_num"; then
+ instance_num=${word#*"="}
+ fi
+ if echo "$word" | grep "bridged_host_network=true"; then
+ bridged_host_network=true
+ fi
+ next=${words#*" "}
+ [ "$words" != "$next" ]
+do
+ words=$next
+done
+
+# Setup wan based on instance_num. Interface wan will occupy 192.168.96.X.
+rule_name=$(uci add network rule)
+if $bridged_host_network; then
+ uci set network.wan.gateway="192.168.96.1"
+ uci set network.wan.ipaddr="192.168.96.2"
+ uci set network.wan.broadcast="192.168.96.3"
+else
+ d_class_wan_gateway=$(expr $instance_num \* 4 - 3);
+ d_class_wan_ipaddr=$(expr $instance_num \* 4 - 2);
+ d_class_wan_broadcast=$(expr $instance_num \* 4 - 1);
+ uci set network.wan.gateway="192.168.96."$d_class_wan_gateway
+ uci set network.wan.ipaddr="192.168.96."$d_class_wan_ipaddr
+ uci set network.wan.broadcast="192.168.96."$d_class_wan_broadcast
+fi
+
+# Setup wifi0 and wifi1 based on instance_num.
+# Interfaces wifi0 and wifi1 will occupy 192.168.2.X - 192.168.33.X.
+c_class_wifi=$(expr \( $instance_num + 3 \) / 2)
+d_class_wifi0=$(expr \( $instance_num % 2 \* 128 \) + 1)
+d_class_wifi1=$(expr \( $instance_num % 2 \* 128 \) + 65)
+uci set network.wifi0.ipaddr="192.168."$c_class_wifi"."$d_class_wifi0
+uci set network.wifi1.ipaddr="192.168."$c_class_wifi"."$d_class_wifi1
+
+uci commit
+
+# Regarding hostapd issue of OpenWRT 22.03.X versions, reboot it.
reboot