aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2024-04-30 15:33:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-30 15:33:33 +0000
commit412209c7b4e6ea918d0942cfb9959356c54811eb (patch)
tree69ef2137cbee72a5827f46a7b50be8498017de72
parentdd2aa5f27f2921008600437528e5d02bf668649d (diff)
parent3ba4c00179fcf904e8aed1a4a4d06048b9fb4f5b (diff)
downloadcuttlefish-412209c7b4e6ea918d0942cfb9959356c54811eb.tar.gz
Merge changes I64714643,Id6cb304f,Ib1b86a74,I850cf4d4,Icab278e4, ... into main
* changes: Remove unused libcuttlefish_device_config dep in assemble_cvd Remove unused libcuttlefish_device_config dep in run_cvd Update qemu_manager to read RIL settings from CuttlefishConfig Update modem_simulator to read RIL settings from CuttlefishConfig Move RIL settings to CuttlefishConfig Remove unused libcuttlefish_device_config dep in cvd_env Remove unused libcuttlefish_device_config dep in health Remove unused libcuttlefish_device_config dep in log_tee Remove unused libcuttlefish_device_config dep in host_bugreport
-rw-r--r--common/libs/device_config/host_device_config.cpp126
-rw-r--r--host/commands/assemble_cvd/Android.bp3
-rw-r--r--host/commands/assemble_cvd/flags.cc5
-rw-r--r--host/commands/assemble_cvd/network_flags.cpp160
-rw-r--r--host/commands/assemble_cvd/network_flags.h28
-rw-r--r--host/commands/cvd_env/Android.bp1
-rw-r--r--host/commands/health/Android.bp2
-rw-r--r--host/commands/host_bugreport/Android.bp4
-rw-r--r--host/commands/log_tee/Android.bp4
-rw-r--r--host/commands/modem_simulator/Android.bp2
-rw-r--r--host/commands/modem_simulator/cf_device_config.cpp28
-rw-r--r--host/commands/run_cvd/Android.bp2
-rw-r--r--host/libs/config/cuttlefish_config.h12
-rw-r--r--host/libs/config/cuttlefish_config_instance.cpp36
-rw-r--r--host/libs/vm_manager/Android.bp2
-rw-r--r--host/libs/vm_manager/qemu_manager.cpp16
16 files changed, 258 insertions, 173 deletions
diff --git a/common/libs/device_config/host_device_config.cpp b/common/libs/device_config/host_device_config.cpp
index 3e977c177..913430ca1 100644
--- a/common/libs/device_config/host_device_config.cpp
+++ b/common/libs/device_config/host_device_config.cpp
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-#include <arpa/inet.h>
#include <android-base/logging.h>
-#include <ifaddrs.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
@@ -27,130 +25,16 @@ namespace cuttlefish {
namespace {
-uint8_t number_of_ones(unsigned long val) {
- uint8_t ret = 0;
- while (val) {
- ret += val % 2;
- val >>= 1;
- }
- return ret;
-}
-
-class NetConfig {
- public:
- uint8_t ril_prefixlen = -1;
- std::string ril_ipaddr;
- std::string ril_gateway;
- std::string ril_dns;
- std::string ril_broadcast;
-
- bool ObtainConfig(const std::string& interface, const std::string& dns) {
- bool ret = ParseInterfaceAttributes(interface);
- if (ret) {
- ril_dns = dns;
- LOG(DEBUG) << "Network config:";
- LOG(DEBUG) << "ipaddr = " << ril_ipaddr;
- LOG(DEBUG) << "gateway = " << ril_gateway;
- LOG(DEBUG) << "dns = " << ril_dns;
- LOG(DEBUG) << "broadcast = " << ril_broadcast;
- LOG(DEBUG) << "prefix length = " << static_cast<int>(ril_prefixlen);
- }
- return ret;
- }
-
- private:
- bool ParseInterfaceAttributes(struct ifaddrs* ifa) {
- struct sockaddr_in* sa;
- char* addr_str;
-
- // Gateway
- sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
- addr_str = inet_ntoa(sa->sin_addr);
- this->ril_gateway = strtok(addr_str, "\n");
- auto gateway_s_addr = ntohl(sa->sin_addr.s_addr);
-
- // Broadcast
- sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_broadaddr);
- addr_str = inet_ntoa(sa->sin_addr);
- this->ril_broadcast = strtok(addr_str, "\n");
- auto broadcast_s_addr = ntohl(sa->sin_addr.s_addr);
-
- // Detect misconfigured network interfaces. All network interfaces must
- // have a valid broadcast address set; if there is none set, glibc may
- // return the interface address in the broadcast field. This causes
- // no packets to be routed correctly from the guest.
- if (this->ril_gateway == this->ril_broadcast) {
- LOG(ERROR) << "Gateway and Broadcast addresses are the same on "
- << ifa->ifa_name << ", which is invalid.";
- return false;
- }
-
- // Netmask
- sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_netmask);
- this->ril_prefixlen = number_of_ones(sa->sin_addr.s_addr);
- auto netmask_s_addr = ntohl(sa->sin_addr.s_addr);
-
- // Address (Find an address in the network different than the network, the
- // gateway and the broadcast)
- auto network = gateway_s_addr & netmask_s_addr;
- auto s_addr = network + 1;
- // s_addr & ~netmask_s_addr is zero when s_addr wraps around the network
- while (s_addr & ~netmask_s_addr) {
- if (s_addr != gateway_s_addr && s_addr != broadcast_s_addr) {
- break;
- }
- ++s_addr;
- }
- if (s_addr == network) {
- LOG(ERROR) << "No available address found in interface " << ifa->ifa_name;
- return false;
- }
- struct in_addr addr;
- addr.s_addr = htonl(s_addr);
- addr_str = inet_ntoa(addr);
- this->ril_ipaddr = strtok(addr_str, "\n");
- return true;
- }
-
- bool ParseInterfaceAttributes(const std::string& interface) {
- struct ifaddrs *ifa_list{}, *ifa{};
- bool ret = false;
- getifaddrs(&ifa_list);
- for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
- if (strcmp(ifa->ifa_name, interface.c_str()) == 0 &&
- ifa->ifa_addr->sa_family == AF_INET) {
- ret = ParseInterfaceAttributes(ifa);
- break;
- }
- }
- freeifaddrs(ifa_list);
- return ret;
- }
-};
-
bool InitializeNetworkConfiguration(const CuttlefishConfig& cuttlefish_config,
DeviceConfig* device_config) {
auto instance = cuttlefish_config.ForDefaultInstance();
- NetConfig netconfig;
- // Check the mobile bridge first; this was the traditional way we configured
- // the mobile interface. If that fails, it probably means we are using a
- // newer version of cuttlefish-common, and we can use the tap device
- // directly instead.
- if (!netconfig.ObtainConfig(instance.mobile_bridge_name(),
- instance.ril_dns())) {
- if (!netconfig.ObtainConfig(instance.mobile_tap_name(),
- instance.ril_dns())) {
- LOG(ERROR) << "Unable to obtain the network configuration";
- return false;
- }
- }
DeviceConfig::RILConfig* ril_config = device_config->mutable_ril_config();
- ril_config->set_ipaddr(netconfig.ril_ipaddr);
- ril_config->set_gateway(netconfig.ril_gateway);
- ril_config->set_dns(netconfig.ril_dns);
- ril_config->set_broadcast(netconfig.ril_broadcast);
- ril_config->set_prefixlen(netconfig.ril_prefixlen);
+ ril_config->set_ipaddr(instance.ril_ipaddr());
+ ril_config->set_gateway(instance.ril_gateway());
+ ril_config->set_dns(instance.ril_dns());
+ ril_config->set_broadcast(instance.ril_broadcast());
+ ril_config->set_prefixlen(instance.ril_prefixlen());
return true;
}
diff --git a/host/commands/assemble_cvd/Android.bp b/host/commands/assemble_cvd/Android.bp
index 9f07eab3b..b90a8be0b 100644
--- a/host/commands/assemble_cvd/Android.bp
+++ b/host/commands/assemble_cvd/Android.bp
@@ -40,6 +40,7 @@ cc_binary_host {
"graphics_flags.cc",
"kernel_module_parser.cc",
"misc_info.cc",
+ "network_flags.cpp",
"super_image_mixer.cc",
"touchpad.cpp",
"vendor_dlkm_utils.cc",
@@ -51,8 +52,6 @@ cc_binary_host {
"libbase",
"libcuttlefish_allocd_utils",
"libcuttlefish_command_util",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
"libcuttlefish_fs",
"libcuttlefish_utils",
"libext2_blkid",
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 531e890e0..65da11350 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -52,6 +52,7 @@
#include "host/commands/assemble_cvd/flags_defaults.h"
#include "host/commands/assemble_cvd/graphics_flags.h"
#include "host/commands/assemble_cvd/misc_info.h"
+#include "host/commands/assemble_cvd/network_flags.h"
#include "host/commands/assemble_cvd/touchpad.h"
#include "host/libs/config/config_flag.h"
#include "host/libs/config/cuttlefish_config.h"
@@ -1363,7 +1364,6 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
instance.set_qemu_binary_dir(qemu_binary_dir_vec[instance_index]);
// wifi, bluetooth, connectivity setup
- instance.set_ril_dns(ril_dns_vec[instance_index]);
instance.set_vhost_net(vhost_net_vec[instance_index]);
@@ -1504,6 +1504,9 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
instance.set_ethernet_bridge_name("cvd-ebr");
instance.set_mobile_tap_name(iface_config.mobile_tap.name);
+ CF_EXPECT(ConfigureNetworkSettings(ril_dns_vec[instance_index],
+ const_instance, instance));
+
if (NetworkInterfaceExists(iface_config.non_bridged_wireless_tap.name) &&
tmp_config_obj.virtio_mac80211_hwsim()) {
instance.set_use_bridged_wifi_tap(false);
diff --git a/host/commands/assemble_cvd/network_flags.cpp b/host/commands/assemble_cvd/network_flags.cpp
new file mode 100644
index 000000000..055bd94b5
--- /dev/null
+++ b/host/commands/assemble_cvd/network_flags.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "host/commands/assemble_cvd/network_flags.h"
+
+#include <arpa/inet.h>
+#include <ifaddrs.h>
+
+#include <android-base/logging.h>
+
+namespace cuttlefish {
+namespace {
+
+uint8_t number_of_ones(unsigned long val) {
+ uint8_t ret = 0;
+ while (val) {
+ ret += val % 2;
+ val >>= 1;
+ }
+ return ret;
+}
+
+class NetConfig {
+ public:
+ uint8_t ril_prefixlen = -1;
+ std::string ril_ipaddr;
+ std::string ril_gateway;
+ std::string ril_dns;
+ std::string ril_broadcast;
+
+ bool ObtainConfig(const std::string& interface, const std::string& dns) {
+ bool ret = ParseInterfaceAttributes(interface);
+ if (ret) {
+ ril_dns = dns;
+ LOG(DEBUG) << "Network config:";
+ LOG(DEBUG) << "ipaddr = " << ril_ipaddr;
+ LOG(DEBUG) << "gateway = " << ril_gateway;
+ LOG(DEBUG) << "dns = " << ril_dns;
+ LOG(DEBUG) << "broadcast = " << ril_broadcast;
+ LOG(DEBUG) << "prefix length = " << static_cast<int>(ril_prefixlen);
+ }
+ return ret;
+ }
+
+ private:
+ bool ParseInterfaceAttributes(struct ifaddrs* ifa) {
+ struct sockaddr_in* sa;
+ char* addr_str;
+
+ // Gateway
+ sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
+ addr_str = inet_ntoa(sa->sin_addr);
+ this->ril_gateway = strtok(addr_str, "\n");
+ auto gateway_s_addr = ntohl(sa->sin_addr.s_addr);
+
+ // Broadcast
+ sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_broadaddr);
+ addr_str = inet_ntoa(sa->sin_addr);
+ this->ril_broadcast = strtok(addr_str, "\n");
+ auto broadcast_s_addr = ntohl(sa->sin_addr.s_addr);
+
+ // Detect misconfigured network interfaces. All network interfaces must
+ // have a valid broadcast address set; if there is none set, glibc may
+ // return the interface address in the broadcast field. This causes
+ // no packets to be routed correctly from the guest.
+ if (this->ril_gateway == this->ril_broadcast) {
+ LOG(ERROR) << "Gateway and Broadcast addresses are the same on "
+ << ifa->ifa_name << ", which is invalid.";
+ return false;
+ }
+
+ // Netmask
+ sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_netmask);
+ this->ril_prefixlen = number_of_ones(sa->sin_addr.s_addr);
+ auto netmask_s_addr = ntohl(sa->sin_addr.s_addr);
+
+ // Address (Find an address in the network different than the network, the
+ // gateway and the broadcast)
+ auto network = gateway_s_addr & netmask_s_addr;
+ auto s_addr = network + 1;
+ // s_addr & ~netmask_s_addr is zero when s_addr wraps around the network
+ while (s_addr & ~netmask_s_addr) {
+ if (s_addr != gateway_s_addr && s_addr != broadcast_s_addr) {
+ break;
+ }
+ ++s_addr;
+ }
+ if (s_addr == network) {
+ LOG(ERROR) << "No available address found in interface " << ifa->ifa_name;
+ return false;
+ }
+ struct in_addr addr;
+ addr.s_addr = htonl(s_addr);
+ addr_str = inet_ntoa(addr);
+ this->ril_ipaddr = strtok(addr_str, "\n");
+ return true;
+ }
+
+ bool ParseInterfaceAttributes(const std::string& interface) {
+ struct ifaddrs *ifa_list{}, *ifa{};
+ bool ret = false;
+ getifaddrs(&ifa_list);
+ for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
+ if (strcmp(ifa->ifa_name, interface.c_str()) == 0 &&
+ ifa->ifa_addr->sa_family == AF_INET) {
+ ret = ParseInterfaceAttributes(ifa);
+ break;
+ }
+ }
+ freeifaddrs(ifa_list);
+ return ret;
+ }
+};
+
+} // namespace
+
+Result<void> ConfigureNetworkSettings(
+ const std::string& ril_dns_arg,
+ const CuttlefishConfig::InstanceSpecific& const_instance,
+ CuttlefishConfig::MutableInstanceSpecific& instance) {
+ NetConfig netconfig;
+ // Check the mobile bridge first; this was the traditional way we configured
+ // the mobile interface. If that fails, it probably means we are using a
+ // newer version of cuttlefish-common, and we can use the tap device
+ // directly instead.
+ if (!netconfig.ObtainConfig(const_instance.mobile_bridge_name(),
+ ril_dns_arg)) {
+ if (!netconfig.ObtainConfig(const_instance.mobile_tap_name(),
+ ril_dns_arg)) {
+ LOG(ERROR) << "Unable to get the network config. Assuming defaults.";
+ instance.set_ril_dns("8.8.8.8");
+ instance.set_ril_gateway("10.0.2.2");
+ instance.set_ril_ipaddr("10.0.2.15");
+ instance.set_ril_prefixlen(24);
+ }
+ }
+
+ instance.set_ril_broadcast(netconfig.ril_broadcast);
+ instance.set_ril_dns(netconfig.ril_dns);
+ instance.set_ril_gateway(netconfig.ril_gateway);
+ instance.set_ril_ipaddr(netconfig.ril_ipaddr);
+ instance.set_ril_prefixlen(netconfig.ril_prefixlen);
+
+ return {};
+}
+
+} // namespace cuttlefish \ No newline at end of file
diff --git a/host/commands/assemble_cvd/network_flags.h b/host/commands/assemble_cvd/network_flags.h
new file mode 100644
index 000000000..1de720e47
--- /dev/null
+++ b/host/commands/assemble_cvd/network_flags.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "common/libs/utils/result.h"
+#include "host/libs/config/cuttlefish_config.h"
+
+namespace cuttlefish {
+
+Result<void> ConfigureNetworkSettings(
+ const std::string& ril_dns_arg,
+ const CuttlefishConfig::InstanceSpecific& const_instance,
+ CuttlefishConfig::MutableInstanceSpecific& instance);
+
+} // namespace cuttlefish \ No newline at end of file
diff --git a/host/commands/cvd_env/Android.bp b/host/commands/cvd_env/Android.bp
index 5ab3f898f..58c485208 100644
--- a/host/commands/cvd_env/Android.bp
+++ b/host/commands/cvd_env/Android.bp
@@ -24,7 +24,6 @@ cc_binary_host {
],
shared_libs: [
"libbase",
- "libcuttlefish_device_config",
"libcuttlefish_utils",
"libgrpc++",
"libjsoncpp",
diff --git a/host/commands/health/Android.bp b/host/commands/health/Android.bp
index c580152b1..afeddca96 100644
--- a/host/commands/health/Android.bp
+++ b/host/commands/health/Android.bp
@@ -25,8 +25,6 @@ cc_binary {
shared_libs: [
"libbase",
"libcuttlefish_command_util",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
"libcuttlefish_fs",
"libcuttlefish_utils",
"libfruit",
diff --git a/host/commands/host_bugreport/Android.bp b/host/commands/host_bugreport/Android.bp
index 6880fba0b..24c9b68ff 100644
--- a/host/commands/host_bugreport/Android.bp
+++ b/host/commands/host_bugreport/Android.bp
@@ -25,9 +25,7 @@ cc_binary {
],
shared_libs: [
"libbase",
- "libcuttlefish_command_util",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
+ "libcuttlefish_command_util",
"libcuttlefish_fs",
"libcuttlefish_utils",
"libfruit",
diff --git a/host/commands/log_tee/Android.bp b/host/commands/log_tee/Android.bp
index 7c1267b2b..c17d71e14 100644
--- a/host/commands/log_tee/Android.bp
+++ b/host/commands/log_tee/Android.bp
@@ -24,9 +24,7 @@ cc_binary {
],
shared_libs: [
"libbase",
- "libcuttlefish_command_util",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
+ "libcuttlefish_command_util",
"libcuttlefish_fs",
"libcuttlefish_utils",
"libfruit",
diff --git a/host/commands/modem_simulator/Android.bp b/host/commands/modem_simulator/Android.bp
index c0d03718e..0f684e825 100644
--- a/host/commands/modem_simulator/Android.bp
+++ b/host/commands/modem_simulator/Android.bp
@@ -43,8 +43,6 @@ cc_defaults {
"libbase",
"libjsoncpp",
"libnl",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
],
static_libs: [
"libcuttlefish_host_config",
diff --git a/host/commands/modem_simulator/cf_device_config.cpp b/host/commands/modem_simulator/cf_device_config.cpp
index 1201db51a..58a740a23 100644
--- a/host/commands/modem_simulator/cf_device_config.cpp
+++ b/host/commands/modem_simulator/cf_device_config.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "common/libs/device_config/device_config.h"
#include "host/commands/modem_simulator/device_config.h"
#include "host/libs/config/cuttlefish_config.h"
@@ -45,30 +44,21 @@ std::string DeviceConfig::DefaultHostArtifactsPath(const std::string& file) {
}
std::string DeviceConfig::ril_address_and_prefix() {
- auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
- if (!device_config_helper) {
- return "10.0.2.15/24";
- }
- const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
- return ril_config.ipaddr() + "/" + std::to_string(ril_config.prefixlen());
+ auto config = cuttlefish::CuttlefishConfig::Get();
+ auto instance = config->ForDefaultInstance();
+ return instance.ril_ipaddr() + "/" + std::to_string(instance.ril_prefixlen());
};
std::string DeviceConfig::ril_gateway() {
- auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
- if (!device_config_helper) {
- return "10.0.2.2";
- }
- const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
- return ril_config.gateway();
+ auto config = cuttlefish::CuttlefishConfig::Get();
+ auto instance = config->ForDefaultInstance();
+ return instance.ril_gateway();
}
std::string DeviceConfig::ril_dns() {
- auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
- if (!device_config_helper) {
- return "8.8.8.8";
- }
- const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
- return ril_config.dns();
+ auto config = cuttlefish::CuttlefishConfig::Get();
+ auto instance = config->ForDefaultInstance();
+ return instance.ril_dns();
}
std::ifstream DeviceConfig::open_ifstream_crossplat(const char* filename) {
diff --git a/host/commands/run_cvd/Android.bp b/host/commands/run_cvd/Android.bp
index 0f7217d6c..5f30d3910 100644
--- a/host/commands/run_cvd/Android.bp
+++ b/host/commands/run_cvd/Android.bp
@@ -55,8 +55,6 @@ cc_binary_host {
],
shared_libs: [
"libbase",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
"libcuttlefish_fs",
"libcuttlefish_kernel_log_monitor_utils",
"libcuttlefish_run_cvd_proto",
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index 71448ea97..7fec650fd 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -572,8 +572,12 @@ class CuttlefishConfig {
bool vhost_net() const;
bool vhost_user_vsock() const;
- // The dns address of mobile network (RIL)
+ // Mobile network info (RIL)
std::string ril_dns() const;
+ std::string ril_ipaddr() const;
+ std::string ril_gateway() const;
+ std::string ril_broadcast() const;
+ uint8_t ril_prefixlen() const;
bool enable_webrtc() const;
std::string webrtc_assets_dir() const;
@@ -797,8 +801,12 @@ class CuttlefishConfig {
void set_vhost_net(bool vhost_net);
void set_vhost_user_vsock(bool vhost_user_vsock);
- // The dns address of mobile network (RIL)
+ // Mobile network (RIL)
void set_ril_dns(const std::string& ril_dns);
+ void set_ril_ipaddr(const std::string& ril_ipaddr);
+ void set_ril_gateway(const std::string& ril_gateway);
+ void set_ril_broadcast(const std::string& ril_broadcast);
+ void set_ril_prefixlen(uint8_t ril_prefixlen);
// Configuration flags for a minimal device
void set_enable_minimal_mode(bool enable_minimal_mode);
diff --git a/host/libs/config/cuttlefish_config_instance.cpp b/host/libs/config/cuttlefish_config_instance.cpp
index 455f53af5..ace76e8ef 100644
--- a/host/libs/config/cuttlefish_config_instance.cpp
+++ b/host/libs/config/cuttlefish_config_instance.cpp
@@ -1054,6 +1054,42 @@ std::string CuttlefishConfig::InstanceSpecific::ril_dns() const {
return (*Dictionary())[kRilDns].asString();
}
+static constexpr char kRilIpaddr[] = "ril_ipaddr";
+void CuttlefishConfig::MutableInstanceSpecific::set_ril_ipaddr(
+ const std::string& ril_ipaddr) {
+ (*Dictionary())[kRilIpaddr] = ril_ipaddr;
+}
+std::string CuttlefishConfig::InstanceSpecific::ril_ipaddr() const {
+ return (*Dictionary())[kRilIpaddr].asString();
+}
+
+static constexpr char kRilGateway[] = "ril_gateway";
+void CuttlefishConfig::MutableInstanceSpecific::set_ril_gateway(
+ const std::string& ril_gateway) {
+ (*Dictionary())[kRilGateway] = ril_gateway;
+}
+std::string CuttlefishConfig::InstanceSpecific::ril_gateway() const {
+ return (*Dictionary())[kRilGateway].asString();
+}
+
+static constexpr char kRilBroadcast[] = "ril_broadcast";
+void CuttlefishConfig::MutableInstanceSpecific::set_ril_broadcast(
+ const std::string& ril_broadcast) {
+ (*Dictionary())[kRilBroadcast] = ril_broadcast;
+}
+std::string CuttlefishConfig::InstanceSpecific::ril_broadcast() const {
+ return (*Dictionary())[kRilBroadcast].asString();
+}
+
+static constexpr char kRilPrefixlen[] = "ril_prefixlen";
+void CuttlefishConfig::MutableInstanceSpecific::set_ril_prefixlen(
+ uint8_t ril_prefixlen) {
+ (*Dictionary())[kRilPrefixlen] = static_cast<Json::UInt>(ril_prefixlen);
+}
+uint8_t CuttlefishConfig::InstanceSpecific::ril_prefixlen() const {
+ return static_cast<uint8_t>((*Dictionary())[kRilPrefixlen].asUInt());
+}
+
static constexpr char kDisplayConfigs[] = "display_configs";
static constexpr char kXRes[] = "x_res";
static constexpr char kYRes[] = "y_res";
diff --git a/host/libs/vm_manager/Android.bp b/host/libs/vm_manager/Android.bp
index 3325e6544..7cd03297f 100644
--- a/host/libs/vm_manager/Android.bp
+++ b/host/libs/vm_manager/Android.bp
@@ -33,8 +33,6 @@ cc_library {
shared_libs: [
"libbase",
"libcuttlefish_command_util",
- "libcuttlefish_device_config",
- "libcuttlefish_device_config_proto",
"libcuttlefish_fs",
"libcuttlefish_utils",
"libfruit",
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index 0f300d41d..332023d77 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -35,7 +35,6 @@
#include <android-base/logging.h>
#include <vulkan/vulkan.h>
-#include "common/libs/device_config/device_config.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/result.h"
#include "common/libs/utils/subprocess.h"
@@ -729,18 +728,9 @@ Result<std::vector<MonitorCommand>> QemuManager::StartCommands(
}
break;
case cuttlefish::ExternalNetworkMode::kSlirp: {
- // TODO(schuffelen): Deduplicate with modem_simulator/cf_device_config.cpp
- // The configuration here needs to match the ip address reported by the
- // modem simulator, which the guest uses to statically assign an IP
- // address to its virtio-net ethernet device.
- std::string net = "10.0.2.15/24";
- std::string host = "10.0.2.2";
- auto device_config_helper = DeviceConfigHelper::Get();
- if (device_config_helper) {
- const auto& cfg = device_config_helper->GetDeviceConfig().ril_config();
- net = fmt::format("{}/{}", cfg.ipaddr(), cfg.prefixlen());
- host = cfg.gateway();
- }
+ const std::string net =
+ fmt::format("{}/{}", instance.ril_ipaddr(), instance.ril_prefixlen());
+ const std::string& host = instance.ril_gateway();
qemu_cmd.AddParameter("-netdev");
// TODO(schuffelen): `dns` needs to match the first `nameserver` in
// `/etc/resolv.conf`. Implement something that generalizes beyond gLinux.