Skip to content

Commit 0656e84

Browse files
committed
cvdalloc supports non-bridged Wi-Fi.
Most of this is plumbing the right arguments to OpenWRT to specify a network for the instance, as well as creating the non-bridged tap interfaces. The existing behavior is to use non-bridged Wi-Fi if the tap device exists and the 802.11 simulator is enabled; since the tap device doesn't exist by default for cvdalloc, we just use the use_cvdalloc flag as a proxy for that condition.
1 parent 97bad5a commit 0656e84

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,11 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
999999
CF_EXPECT(ConfigureNetworkSettings(ril_dns_vec[instance_index],
10001000
const_instance, instance));
10011001

1002-
if (NetworkInterfaceExists(iface_config.non_bridged_wireless_tap.name) &&
1003-
tmp_config_obj.virtio_mac80211_hwsim()) {
1002+
bool use_non_bridged_wireless =
1003+
(NetworkInterfaceExists(iface_config.non_bridged_wireless_tap.name) ||
1004+
const_instance.use_cvdalloc()) &&
1005+
tmp_config_obj.virtio_mac80211_hwsim();
1006+
if (use_non_bridged_wireless) {
10041007
instance.set_use_bridged_wifi_tap(false);
10051008
instance.set_wifi_tap_name(iface_config.non_bridged_wireless_tap.name);
10061009
} else {

base/cvd/cuttlefish/host/commands/cvdalloc/cvdalloc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Result<void> Allocate(int id, const std::string &bridge_name) {
4949
kCvdallocMobileIpPrefix));
5050
CF_EXPECT(CreateMobileIface(CvdallocInterfaceName("wtap", id), id,
5151
kCvdallocWirelessIpPrefix));
52+
CF_EXPECT(CreateMobileIface(CvdallocInterfaceName("wifiap", id), id,
53+
kCvdallocWirelessApIpPrefix));
5254
CF_EXPECT(CreateEthernetIface(CvdallocInterfaceName("etap", id), bridge_name,
5355
true, true, false));
5456

@@ -62,6 +64,8 @@ Result<void> Teardown(int id, const std::string &bridge_name) {
6264
kCvdallocMobileIpPrefix);
6365
DestroyMobileIface(CvdallocInterfaceName("wtap", id), id,
6466
kCvdallocWirelessIpPrefix);
67+
DestroyMobileIface(CvdallocInterfaceName("wifiap", id), id,
68+
kCvdallocWirelessApIpPrefix);
6569
DestroyEthernetIface(CvdallocInterfaceName("etap", id), true, true, false);
6670
DestroyBridge(bridge_name);
6771

base/cvd/cuttlefish/host/commands/cvdalloc/interface.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ std::string InstanceToMobileBroadcast(int num) {
3535
return absl::StrFormat("%s.%d", kCvdallocMobileIpPrefix, 4 * num - 1);
3636
}
3737

38+
std::string InstanceToWifiGatewayAddress(int num) {
39+
return absl::StrFormat("%s.%d", kCvdallocWirelessApIpPrefix, 4 * num - 3);
40+
}
41+
42+
std::string InstanceToWifiAddress(int num) {
43+
return absl::StrFormat("%s.%d", kCvdallocWirelessApIpPrefix, 4 * num - 2);
44+
}
45+
46+
std::string InstanceToWifiBroadcast(int num) {
47+
return absl::StrFormat("%s.%d", kCvdallocWirelessApIpPrefix, 4 * num - 1);
48+
}
3849
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvdalloc/interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ std::string CvdallocInterfaceName(const std::string &name, int num);
2929
std::string InstanceToMobileGatewayAddress(int num);
3030
std::string InstanceToMobileAddress(int num);
3131
std::string InstanceToMobileBroadcast(int num);
32+
std::string InstanceToWifiGatewayAddress(int num);
33+
std::string InstanceToWifiAddress(int num);
34+
std::string InstanceToWifiBroadcast(int num);
3235

3336
} // namespace cuttlefish

base/cvd/cuttlefish/host/libs/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ cf_cc_library(
283283
srcs = ["openwrt_args.cpp"],
284284
hdrs = ["openwrt_args.h"],
285285
deps = [
286+
"//cuttlefish/host/commands/cvdalloc:interface",
286287
"//cuttlefish/host/libs/config:cuttlefish_config",
287288
"//libbase",
288289
],

base/cvd/cuttlefish/host/libs/config/openwrt_args.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <android-base/parseint.h>
2323

24+
#include "cuttlefish/host/commands/cvdalloc/interface.h"
2425
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
2526

2627
namespace cuttlefish {
@@ -64,12 +65,19 @@ std::unordered_map<std::string, std::string> OpenwrtArgsFromConfig(
6465

6566
} else {
6667
openwrt_args["bridged_wifi_tap"] = "false";
67-
openwrt_args["wan_gateway"] =
68-
getIpAddress(94 + c_class_base, d_class_base + 1);
69-
openwrt_args["wan_ipaddr"] =
70-
getIpAddress(94 + c_class_base, d_class_base + 2);
71-
openwrt_args["wan_broadcast"] =
72-
getIpAddress(94 + c_class_base, d_class_base + 3);
68+
69+
if (instance.use_cvdalloc()) {
70+
openwrt_args["wan_gateway"] = InstanceToWifiGatewayAddress(instance_num);
71+
openwrt_args["wan_ipaddr"] = InstanceToWifiAddress(instance_num);
72+
openwrt_args["wan_broadcast"] = InstanceToWifiBroadcast(instance_num);
73+
} else {
74+
openwrt_args["wan_gateway"] =
75+
getIpAddress(94 + c_class_base, d_class_base + 1);
76+
openwrt_args["wan_ipaddr"] =
77+
getIpAddress(94 + c_class_base, d_class_base + 2);
78+
openwrt_args["wan_broadcast"] =
79+
getIpAddress(94 + c_class_base, d_class_base + 3);
80+
}
7381
}
7482

7583
return openwrt_args;

0 commit comments

Comments
 (0)