From efd97c9165ca27c1b54b2c582cd325c8bcd2dcf4 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 10:45:20 -0700 Subject: Remove unused libcuttlefish_device_config dep in host_bugreport Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: I8d80111847ebd1ad1ad54064964a1fb6b7d3aa0c --- host/commands/host_bugreport/Android.bp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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", -- cgit v1.2.3 From e09218aa370e95539dc9523015e305cd406c9b4a Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 10:50:04 -0700 Subject: Remove unused libcuttlefish_device_config dep in log_tee Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: Ia6925dfc36fe333ac05025dfe699f7425f84acab --- host/commands/log_tee/Android.bp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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", -- cgit v1.2.3 From 0c41b2271d5fa2b0d6e0ad6672d3cda84f048ef7 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 10:53:16 -0700 Subject: Remove unused libcuttlefish_device_config dep in health Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: Ie7872676d23c5ea838133a9ddffcd492dc793ba6 --- host/commands/health/Android.bp | 2 -- 1 file changed, 2 deletions(-) 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", -- cgit v1.2.3 From 629d5c6a04ef8b7b4a6c0164d579d3c5fc3dd0e6 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 11:00:18 -0700 Subject: Remove unused libcuttlefish_device_config dep in cvd_env Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: Icac7dd626c866969abc06a025b2e9b6cd46cf48c --- host/commands/cvd_env/Android.bp | 1 - 1 file changed, 1 deletion(-) 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", -- cgit v1.2.3 From 4444f3f2aad73718fa9674251f365b6c907ac986 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 12:41:24 -0700 Subject: Move RIL settings to CuttlefishConfig Bug: b/261231681 Test: build Change-Id: Icab278e490f40d5225c6167b8135e69fd5d9628c --- common/libs/device_config/host_device_config.cpp | 126 +----------------- host/commands/assemble_cvd/Android.bp | 1 + host/commands/assemble_cvd/flags.cc | 5 +- host/commands/assemble_cvd/network_flags.cpp | 160 +++++++++++++++++++++++ host/commands/assemble_cvd/network_flags.h | 28 ++++ host/libs/config/cuttlefish_config.h | 12 +- host/libs/config/cuttlefish_config_instance.cpp | 36 +++++ 7 files changed, 244 insertions(+), 124 deletions(-) create mode 100644 host/commands/assemble_cvd/network_flags.cpp create mode 100644 host/commands/assemble_cvd/network_flags.h 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 #include -#include #include #include #include @@ -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(ril_prefixlen); - } - return ret; - } - - private: - bool ParseInterfaceAttributes(struct ifaddrs* ifa) { - struct sockaddr_in* sa; - char* addr_str; - - // Gateway - sa = reinterpret_cast(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(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(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..e699362a5 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", 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 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 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 +#include + +#include + +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(ril_prefixlen); + } + return ret; + } + + private: + bool ParseInterfaceAttributes(struct ifaddrs* ifa) { + struct sockaddr_in* sa; + char* addr_str; + + // Gateway + sa = reinterpret_cast(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(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(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 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 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/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(ril_prefixlen); +} +uint8_t CuttlefishConfig::InstanceSpecific::ril_prefixlen() const { + return static_cast((*Dictionary())[kRilPrefixlen].asUInt()); +} + static constexpr char kDisplayConfigs[] = "display_configs"; static constexpr char kXRes[] = "x_res"; static constexpr char kYRes[] = "y_res"; -- cgit v1.2.3 From bfb414a562d2e65a87220f9d8287c779e24dfe14 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 12:41:43 -0700 Subject: Update modem_simulator to read RIL settings from CuttlefishConfig ... in order to remove modem_simulator's dependency on device config. Bug: b/261231681 Test: launch Cuttlefish and open Youtube in browser Change-Id: I850cf4d4bf9fdbe24fc261ac597878ee93d22f3f --- host/commands/modem_simulator/Android.bp | 2 -- host/commands/modem_simulator/cf_device_config.cpp | 28 +++++++--------------- 2 files changed, 9 insertions(+), 21 deletions(-) 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) { -- cgit v1.2.3 From 20e2971d4507345a9af69b9012f86a561944eb8f Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 12:42:20 -0700 Subject: Update qemu_manager to read RIL settings from CuttlefishConfig ... in order to remove vm_manager's dependency on device config. Bug: b/261231681 Test: build Change-Id: Ib1b86a74f57a207e8b57e3012a56ba56054bfb6c --- host/libs/vm_manager/Android.bp | 2 -- host/libs/vm_manager/qemu_manager.cpp | 16 +++------------- 2 files changed, 3 insertions(+), 15 deletions(-) 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 #include -#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> 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. -- cgit v1.2.3 From f642209d2d9b9a1b38dbe702d6d90636fe2ab01f Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 12:48:21 -0700 Subject: Remove unused libcuttlefish_device_config dep in run_cvd Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: Id6cb304fd1c4a50135cae3cd1b6123b82bbf3c41 --- host/commands/run_cvd/Android.bp | 2 -- 1 file changed, 2 deletions(-) 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", -- cgit v1.2.3 From 3ba4c00179fcf904e8aed1a4a4d06048b9fb4f5b Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 29 Apr 2024 12:54:03 -0700 Subject: Remove unused libcuttlefish_device_config dep in assemble_cvd Bug: b/261231681 Test: cd device/google/cuttlefish && mma Change-Id: I64714643a0f4d28ac138ac2365f9fd6959527f08 --- host/commands/assemble_cvd/Android.bp | 2 -- 1 file changed, 2 deletions(-) diff --git a/host/commands/assemble_cvd/Android.bp b/host/commands/assemble_cvd/Android.bp index e699362a5..b90a8be0b 100644 --- a/host/commands/assemble_cvd/Android.bp +++ b/host/commands/assemble_cvd/Android.bp @@ -52,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", -- cgit v1.2.3