patchpanel: make internal Datapath methods private
This patch moves Datapath internal methods from public to private in
preparation to remove those methods related to iptables setup.
BUG=b:161508179
TEST=unit tests
Change-Id: I98f9742d2b0845a805ef089e4f73a4583bb128b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2398356
Tested-by: Hugo Benichi <hugobenichi@google.com>
Commit-Queue: Hugo Benichi <hugobenichi@google.com>
Reviewed-by: Taoyu Li <taoyl@chromium.org>
Reviewed-by: Garrick Evans <garrick@chromium.org>
diff --git a/patchpanel/arc_service_test.cc b/patchpanel/arc_service_test.cc
index dd49675..676233e 100644
--- a/patchpanel/arc_service_test.cc
+++ b/patchpanel/arc_service_test.cc
@@ -134,11 +134,8 @@
.WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wwan0"), kFirstCellHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_, AddVirtualInterfacePair(StrEq("arc_netns"), _, _))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(_, true))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*datapath_, ConfigureInterface(_, _, _, _, _, _))
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), _, _, _, _, _, _))
.WillRepeatedly(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true));
@@ -157,11 +154,8 @@
.WillRepeatedly(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wlan0"), kFirstWifiHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_, AddVirtualInterfacePair(StrEq("arc_netns"), _, _))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(_, true))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*datapath_, ConfigureInterface(_, _, _, _, _, _))
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), _, _, _, _, _, _))
.WillRepeatedly(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true));
@@ -195,20 +189,14 @@
TEST_F(ArcServiceTest, ContainerImpl_Start) {
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
- // Expectations for arc0 setup.
- EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
.WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(true));
+ EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
+ .WillOnce(Return(true));
EXPECT_CALL(forwarder_, StartForwarding(_, _, _, _)).Times(0);
auto svc = NewService(GuestMessage::ARC);
@@ -219,31 +207,9 @@
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
.WillOnce(Return(false));
-
- EXPECT_CALL(*datapath_, ConfigureInterface(_, _, _, _, _, _)).Times(0);
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true)).Times(0);
- EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)).Times(0);
- EXPECT_CALL(*datapath_, RemoveBridge(_)).Times(0);
-
- auto svc = NewService(GuestMessage::ARC);
- svc->Start(kTestPID);
-}
-
-TEST_F(ArcServiceTest, ContainerImpl_FailsToConfigureInterface) {
- EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(false));
-
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true)).Times(0);
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)).Times(0);
EXPECT_CALL(*datapath_, RemoveBridge(_)).Times(0);
@@ -254,17 +220,12 @@
TEST_F(ArcServiceTest, ContainerImpl_FailsToAddInterfaceToBridge) {
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
+ .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(false));
@@ -279,30 +240,20 @@
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
// Expectations for arc0 setup.
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
+ .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(true));
// Expectations for eth0 setup.
- EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetheth0"),
- StrEq("eth0")))
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"),
+ StrEq("eth0"), _, kFirstEthGuestIP, 30, false))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ConfigureInterface(StrEq("eth0"), _, kFirstEthGuestIP,
- 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetheth0"), true))
+ EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
.WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0")))
.WillOnce(Return(true));
@@ -321,30 +272,20 @@
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
// Expectations for arc0 setup.
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
+ .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(true));
// Expectations for eth0 setup.
- EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetheth0"),
- StrEq("eth0")))
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"),
+ StrEq("eth0"), _, kFirstEthGuestIP, 30, false))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ConfigureInterface(StrEq("eth0"), _, kFirstEthGuestIP,
- 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetheth0"), true))
+ EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
.WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0")))
.WillOnce(Return(true));
@@ -365,17 +306,12 @@
EXPECT_CALL(*datapath_, NetnsDeleteName(StrEq("arc_netns")))
.WillOnce(Return(true));
// Expectations for arc0 setup.
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
+ .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(true));
// Expectations for arc0 teardown.
@@ -394,30 +330,20 @@
EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID))
.WillOnce(Return(true));
// Expectations for arc0 setup.
+ EXPECT_CALL(*datapath_,
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"),
+ StrEq("arc0"), _, kArcGuestIP, 30, false))
+ .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetharc0"),
- StrEq("arc0")))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_,
- ConfigureInterface(StrEq("arc0"), _, kArcGuestIP, 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetharc0"), true))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0")))
.WillOnce(Return(true));
// Expectations for eth0 setup.
- EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
- .WillOnce(Return(true));
EXPECT_CALL(*datapath_,
- AddVirtualInterfacePair(StrEq("arc_netns"), StrEq("vetheth0"),
- StrEq("eth0")))
+ ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"),
+ StrEq("eth0"), _, kFirstEthGuestIP, 30, false))
.WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ConfigureInterface(StrEq("eth0"), _, kFirstEthGuestIP,
- 30, true, _))
- .WillOnce(Return(true));
- EXPECT_CALL(*datapath_, ToggleInterface(StrEq("vetheth0"), true))
+ EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30))
.WillOnce(Return(true));
EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0")))
.WillOnce(Return(true));