Skip to content

Commit f49224e

Browse files
committed
Pass DefaultNetworkInterfaces the config.
The IfaceConfig as returned by DefaultNetworkInterfaces informs the vmm about the network interfaces it can use, including the interface names, which embed the instance number. Instead of passing the interface number directly, pass the CuttlefishConfig instead. We will soon use the flag we generated earlier to tell the vmm to expect interfaces with different names when we are using cvdalloc, so that cvdalloc doesn't try to modify existing tap interfaces generated by the cuttlefish-host-resources service. We could that this by detecting if the service is running, but doing that effectively will be a pain.
1 parent a1a342d commit f49224e

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ cf_cc_library(
1010
hdrs = ["alloc.h"],
1111
deps = [
1212
"//cuttlefish/common/libs/fs",
13+
"//cuttlefish/common/libs/utils:result",
1314
"//cuttlefish/host/libs/allocd:allocd_utils",
15+
"//cuttlefish/host/libs/config:cuttlefish_config",
16+
"@abseil-cpp//absl/strings",
1417
],
1518
)
1619

base/cvd/cuttlefish/host/commands/assemble_cvd/alloc.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
#include <iomanip>
2020
#include <sstream>
2121

22+
#include "absl/strings/numbers.h"
23+
2224
#include "cuttlefish/common/libs/fs/shared_fd.h"
2325
#include "cuttlefish/host/libs/allocd/request.h"
2426
#include "cuttlefish/host/libs/allocd/utils.h"
2527

28+
2629
namespace cuttlefish {
2730

2831
static std::string StrForInstance(const std::string& prefix, int num) {
@@ -31,8 +34,13 @@ static std::string StrForInstance(const std::string& prefix, int num) {
3134
return stream.str();
3235
}
3336

34-
IfaceConfig DefaultNetworkInterfaces(int num) {
37+
Result<IfaceConfig> DefaultNetworkInterfaces(
38+
const CuttlefishConfig::InstanceSpecific& instance) {
3539
IfaceConfig config{};
40+
41+
int num;
42+
CF_EXPECT(absl::SimpleAtoi(instance.id(), &num));
43+
3644
config.mobile_tap.name = StrForInstance("cvd-mtap-", num);
3745
config.mobile_tap.resource_id = 0;
3846
config.mobile_tap.session_id = 0;

base/cvd/cuttlefish/host/commands/assemble_cvd/alloc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <optional>
2121
#include <string>
2222

23+
#include "cuttlefish/common/libs/utils/result.h"
24+
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
25+
2326
namespace cuttlefish {
2427

2528
struct IfaceData {
@@ -35,7 +38,8 @@ struct IfaceConfig {
3538
IfaceData ethernet_tap;
3639
};
3740

38-
IfaceConfig DefaultNetworkInterfaces(int num);
41+
Result<IfaceConfig> DefaultNetworkInterfaces(
42+
const CuttlefishConfig::InstanceSpecific &instance);
3943

4044
// Acquires interfaces from the resource allocator daemon.
4145
std::optional<IfaceConfig> AllocateNetworkInterfaces();

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,12 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
772772
CF_EXPECT(CreateNumToWebrtcDeviceIdMap(tmp_config_obj, instance_nums,
773773
FLAGS_webrtc_device_id));
774774
for (const auto& num : instance_nums) {
775+
auto instance = tmp_config_obj.ForInstance(num);
776+
auto const_instance =
777+
const_cast<const CuttlefishConfig&>(tmp_config_obj).ForInstance(num);
778+
779+
instance.set_use_cvdalloc(use_cvdalloc_vec[instance_index]);
780+
775781
IfaceConfig iface_config;
776782
if (use_allocd_vec[instance_index]) {
777783
auto iface_opt = AllocateNetworkInterfaces();
@@ -780,14 +786,9 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
780786
}
781787
iface_config = iface_opt.value();
782788
} else {
783-
iface_config = DefaultNetworkInterfaces(num);
789+
iface_config = CF_EXPECT(DefaultNetworkInterfaces(const_instance));
784790
}
785791

786-
auto instance = tmp_config_obj.ForInstance(num);
787-
auto const_instance =
788-
const_cast<const CuttlefishConfig&>(tmp_config_obj).ForInstance(num);
789-
790-
instance.set_use_cvdalloc(use_cvdalloc_vec[instance_index]);
791792
instance.set_crosvm_use_balloon(use_balloon_vec[instance_index]);
792793
instance.set_crosvm_use_rng(use_rng_vec[instance_index]);
793794
instance.set_crosvm_simple_media_device(simple_media_device_vec[instance_index]);

0 commit comments

Comments
 (0)