summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Android.bp6
-rw-r--r--server/ClatdController.cpp2
-rw-r--r--server/NetworkController.cpp2
-rw-r--r--server/RouteController.cpp2
-rw-r--r--server/TcUtils.cpp (renamed from server/OffloadUtils.cpp)12
-rw-r--r--server/TcUtils.h (renamed from server/OffloadUtils.h)9
-rw-r--r--server/TcUtilsTest.cpp (renamed from server/OffloadUtilsTest.cpp)48
-rw-r--r--server/TetherController.cpp2
-rw-r--r--server/TetherControllerTest.cpp2
9 files changed, 43 insertions, 42 deletions
diff --git a/server/Android.bp b/server/Android.bp
index eff113c07..a05242943 100644
--- a/server/Android.bp
+++ b/server/Android.bp
@@ -30,7 +30,7 @@ filegroup {
"InterfaceController.cpp",
"NetlinkCommands.cpp",
"NetlinkListener.cpp",
- "OffloadUtils.cpp",
+ "TcUtils.cpp",
"SockDiag.cpp",
"XfrmController.cpp",
"TrafficController.cpp",
@@ -58,7 +58,7 @@ cc_library_static {
"NetlinkCommands.cpp",
"NetlinkListener.cpp",
"NetlinkManager.cpp",
- "OffloadUtils.cpp",
+ "TcUtils.cpp",
"RouteController.cpp",
"SockDiag.cpp",
"StrictController.cpp",
@@ -208,7 +208,7 @@ cc_test {
"IptablesBaseTest.cpp",
"IptablesRestoreControllerTest.cpp",
"NFLogListenerTest.cpp",
- "OffloadUtilsTest.cpp",
+ "TcUtilsTest.cpp",
"RouteControllerTest.cpp",
"SockDiagTest.cpp",
"StrictControllerTest.cpp",
diff --git a/server/ClatdController.cpp b/server/ClatdController.cpp
index 847a6db69..394ddbce3 100644
--- a/server/ClatdController.cpp
+++ b/server/ClatdController.cpp
@@ -49,7 +49,7 @@ extern "C" {
#include "Fwmark.h"
#include "NetdConstants.h"
#include "NetworkController.h"
-#include "OffloadUtils.h"
+#include "TcUtils.h"
#include "netid_client.h"
static const char* kClatdPath = "/system/bin/clatd";
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index 602639cb1..1b99556b8 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -36,9 +36,9 @@
#include "DummyNetwork.h"
#include "Fwmark.h"
#include "LocalNetwork.h"
-#include "OffloadUtils.h"
#include "PhysicalNetwork.h"
#include "RouteController.h"
+#include "TcUtils.h"
#include "UnreachableNetwork.h"
#include "VirtualNetwork.h"
#include "netdutils/DumpWriter.h"
diff --git a/server/RouteController.cpp b/server/RouteController.cpp
index ba305e69a..14bc926e5 100644
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -31,7 +31,7 @@
#include "Fwmark.h"
#include "NetdConstants.h"
#include "NetlinkCommands.h"
-#include "OffloadUtils.h"
+#include "TcUtils.h"
#include <android-base/file.h>
#include <android-base/stringprintf.h>
diff --git a/server/OffloadUtils.cpp b/server/TcUtils.cpp
index 0d9869fae..45d02bb85 100644
--- a/server/OffloadUtils.cpp
+++ b/server/TcUtils.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "OffloadUtils.h"
+#include "TcUtils.h"
#include <arpa/inet.h>
#include <linux/if.h>
@@ -27,7 +27,7 @@
#include <sys/types.h>
#include <unistd.h>
-#define LOG_TAG "OffloadUtils"
+#define LOG_TAG "TcUtils"
#include <log/log.h>
#include "NetlinkCommands.h"
@@ -204,9 +204,6 @@ int doTcQdiscClsact(int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags) {
return sendAndProcessNetlinkResponse(&req, sizeof(req));
}
-// The priority of clat hook - must be after tethering.
-constexpr uint16_t PRIO_CLAT = 4;
-
// tc filter add dev .. in/egress prio 4 protocol ipv6/ip bpf object-pinned /sys/fs/bpf/...
// direct-action
int tcFilterAddDevBpf(int ifIndex, bool ingress, uint16_t proto, int bpfFd, bool ethernet) {
@@ -359,7 +356,7 @@ int tcFilterAddDevBpf(int ifIndex, bool ingress, uint16_t proto, int bpfFd, bool
}
// tc filter del dev .. in/egress prio 4 protocol ..
-int tcFilterDelDev(int ifIndex, bool ingress, uint16_t proto) {
+int tcFilterDelDev(int ifIndex, bool ingress, uint16_t prio, uint16_t proto) {
const struct {
nlmsghdr n;
tcmsg t;
@@ -377,7 +374,8 @@ int tcFilterDelDev(int ifIndex, bool ingress, uint16_t proto) {
.tcm_handle = TC_H_UNSPEC,
.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
ingress ? TC_H_MIN_INGRESS : TC_H_MIN_EGRESS),
- .tcm_info = static_cast<__u32>((PRIO_CLAT << 16) | htons(proto)),
+ .tcm_info = (static_cast<uint32_t>(prio) << 16) |
+ static_cast<uint32_t>(htons(proto)),
},
};
diff --git a/server/OffloadUtils.h b/server/TcUtils.h
index 684ffb351..ef80fb04e 100644
--- a/server/OffloadUtils.h
+++ b/server/TcUtils.h
@@ -39,6 +39,9 @@ constexpr bool ETHER = true;
constexpr bool EGRESS = false;
constexpr bool INGRESS = true;
+// The priority of clat hook - must be after tethering.
+constexpr uint16_t PRIO_CLAT = 4;
+
// this returns an ARPHRD_* constant or a -errno
int hardwareAddressType(const std::string& interface);
@@ -98,16 +101,16 @@ inline int tcFilterAddDevEgressClatIpv4(int ifIndex, int bpfFd, bool ethernet) {
}
// tc filter del dev .. in/egress prio .. protocol ..
-int tcFilterDelDev(int ifIndex, bool ingress, uint16_t proto);
+int tcFilterDelDev(int ifIndex, bool ingress, uint16_t prio, uint16_t proto);
// tc filter del dev .. ingress prio 4 protocol ipv6
inline int tcFilterDelDevIngressClatIpv6(int ifIndex) {
- return tcFilterDelDev(ifIndex, INGRESS, ETH_P_IPV6);
+ return tcFilterDelDev(ifIndex, INGRESS, PRIO_CLAT, ETH_P_IPV6);
}
// tc filter del dev .. egress prio 4 protocol ip
inline int tcFilterDelDevEgressClatIpv4(int ifIndex) {
- return tcFilterDelDev(ifIndex, EGRESS, ETH_P_IP);
+ return tcFilterDelDev(ifIndex, EGRESS, PRIO_CLAT, ETH_P_IP);
}
} // namespace net
diff --git a/server/OffloadUtilsTest.cpp b/server/TcUtilsTest.cpp
index 16c108b42..c77fc416b 100644
--- a/server/OffloadUtilsTest.cpp
+++ b/server/TcUtilsTest.cpp
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * OffloadUtilsTest.cpp - unit tests for OffloadUtils.cpp
+ * TcUtilsTest.cpp - unit tests for TcUtils.cpp
*/
#include <gtest/gtest.h>
-#include "OffloadUtils.h"
+#include "TcUtils.h"
#include <linux/if_arp.h>
#include <stdlib.h>
@@ -30,21 +30,21 @@
namespace android {
namespace net {
-class OffloadUtilsTest : public ::testing::Test {
+class TcUtilsTest : public ::testing::Test {
public:
void SetUp() {}
};
-TEST_F(OffloadUtilsTest, HardwareAddressTypeOfNonExistingIf) {
+TEST_F(TcUtilsTest, HardwareAddressTypeOfNonExistingIf) {
ASSERT_EQ(-ENODEV, hardwareAddressType("not_existing_if"));
}
-TEST_F(OffloadUtilsTest, HardwareAddressTypeOfLoopback) {
+TEST_F(TcUtilsTest, HardwareAddressTypeOfLoopback) {
ASSERT_EQ(ARPHRD_LOOPBACK, hardwareAddressType("lo"));
}
// If wireless 'wlan0' interface exists it should be Ethernet.
-TEST_F(OffloadUtilsTest, HardwareAddressTypeOfWireless) {
+TEST_F(TcUtilsTest, HardwareAddressTypeOfWireless) {
int type = hardwareAddressType("wlan0");
if (type == -ENODEV) return;
@@ -53,7 +53,7 @@ TEST_F(OffloadUtilsTest, HardwareAddressTypeOfWireless) {
// If cellular 'rmnet_data0' interface exists it should
// *probably* not be Ethernet and instead be RawIp.
-TEST_F(OffloadUtilsTest, HardwareAddressTypeOfCellular) {
+TEST_F(TcUtilsTest, HardwareAddressTypeOfCellular) {
int type = hardwareAddressType("rmnet_data0");
if (type == -ENODEV) return;
@@ -65,13 +65,13 @@ TEST_F(OffloadUtilsTest, HardwareAddressTypeOfCellular) {
ASSERT_EQ(ARPHRD_RAWIP, type);
}
-TEST_F(OffloadUtilsTest, IsEthernetOfNonExistingIf) {
+TEST_F(TcUtilsTest, IsEthernetOfNonExistingIf) {
auto res = isEthernet("not_existing_if");
ASSERT_FALSE(res.ok());
ASSERT_EQ(ENODEV, res.error().code());
}
-TEST_F(OffloadUtilsTest, IsEthernetOfLoopback) {
+TEST_F(TcUtilsTest, IsEthernetOfLoopback) {
auto res = isEthernet("lo");
ASSERT_FALSE(res.ok());
ASSERT_EQ(EAFNOSUPPORT, res.error().code());
@@ -79,7 +79,7 @@ TEST_F(OffloadUtilsTest, IsEthernetOfLoopback) {
// If wireless 'wlan0' interface exists it should be Ethernet.
// See also HardwareAddressTypeOfWireless.
-TEST_F(OffloadUtilsTest, IsEthernetOfWireless) {
+TEST_F(TcUtilsTest, IsEthernetOfWireless) {
auto res = isEthernet("wlan0");
if (!res.ok() && res.error().code() == ENODEV) return;
@@ -90,7 +90,7 @@ TEST_F(OffloadUtilsTest, IsEthernetOfWireless) {
// If cellular 'rmnet_data0' interface exists it should
// *probably* not be Ethernet and instead be RawIp.
// See also HardwareAddressTypeOfCellular.
-TEST_F(OffloadUtilsTest, IsEthernetOfCellular) {
+TEST_F(TcUtilsTest, IsEthernetOfCellular) {
auto res = isEthernet("rmnet_data0");
if (!res.ok() && res.error().code() == ENODEV) return;
@@ -98,50 +98,50 @@ TEST_F(OffloadUtilsTest, IsEthernetOfCellular) {
ASSERT_FALSE(res.value());
}
-TEST_F(OffloadUtilsTest, DeviceMTUOfNonExistingIf) {
+TEST_F(TcUtilsTest, DeviceMTUOfNonExistingIf) {
ASSERT_EQ(-ENODEV, deviceMTU("not_existing_if"));
}
-TEST_F(OffloadUtilsTest, DeviceMTUofLoopback) {
+TEST_F(TcUtilsTest, DeviceMTUofLoopback) {
ASSERT_EQ(65536, deviceMTU("lo"));
}
-TEST_F(OffloadUtilsTest, GetClatEgress4MapFd) {
+TEST_F(TcUtilsTest, GetClatEgress4MapFd) {
int fd = getClatEgress4MapFd();
ASSERT_GE(fd, 3); // 0,1,2 - stdin/out/err, thus fd >= 3
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
close(fd);
}
-TEST_F(OffloadUtilsTest, GetClatEgress4RawIpProgFd) {
+TEST_F(TcUtilsTest, GetClatEgress4RawIpProgFd) {
int fd = getClatEgress4ProgFd(RAWIP);
ASSERT_GE(fd, 3);
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
close(fd);
}
-TEST_F(OffloadUtilsTest, GetClatEgress4EtherProgFd) {
+TEST_F(TcUtilsTest, GetClatEgress4EtherProgFd) {
int fd = getClatEgress4ProgFd(ETHER);
ASSERT_GE(fd, 3);
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
close(fd);
}
-TEST_F(OffloadUtilsTest, GetClatIngress6MapFd) {
+TEST_F(TcUtilsTest, GetClatIngress6MapFd) {
int fd = getClatIngress6MapFd();
ASSERT_GE(fd, 3); // 0,1,2 - stdin/out/err, thus fd >= 3
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
close(fd);
}
-TEST_F(OffloadUtilsTest, GetClatIngress6RawIpProgFd) {
+TEST_F(TcUtilsTest, GetClatIngress6RawIpProgFd) {
int fd = getClatIngress6ProgFd(RAWIP);
ASSERT_GE(fd, 3);
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
close(fd);
}
-TEST_F(OffloadUtilsTest, GetClatIngress6EtherProgFd) {
+TEST_F(TcUtilsTest, GetClatIngress6EtherProgFd) {
int fd = getClatIngress6ProgFd(ETHER);
ASSERT_GE(fd, 3);
EXPECT_EQ(FD_CLOEXEC, fcntl(fd, F_GETFD));
@@ -151,7 +151,7 @@ TEST_F(OffloadUtilsTest, GetClatIngress6EtherProgFd) {
// See Linux kernel source in include/net/flow.h
#define LOOPBACK_IFINDEX 1
-TEST_F(OffloadUtilsTest, AttachReplaceDetachClsactLo) {
+TEST_F(TcUtilsTest, AttachReplaceDetachClsactLo) {
// This attaches and detaches a configuration-less and thus no-op clsact
// qdisc to loopback interface (and it takes fractions of a second)
EXPECT_EQ(0, tcQdiscAddDevClsact(LOOPBACK_IFINDEX));
@@ -192,19 +192,19 @@ static void checkAttachDetachBpfFilterClsactLo(const bool ingress, const bool et
close(clatBpfFd);
}
-TEST_F(OffloadUtilsTest, CheckAttachBpfFilterRawIpClsactEgressLo) {
+TEST_F(TcUtilsTest, CheckAttachBpfFilterRawIpClsactEgressLo) {
checkAttachDetachBpfFilterClsactLo(EGRESS, RAWIP);
}
-TEST_F(OffloadUtilsTest, CheckAttachBpfFilterEthernetClsactEgressLo) {
+TEST_F(TcUtilsTest, CheckAttachBpfFilterEthernetClsactEgressLo) {
checkAttachDetachBpfFilterClsactLo(EGRESS, ETHER);
}
-TEST_F(OffloadUtilsTest, CheckAttachBpfFilterRawIpClsactIngressLo) {
+TEST_F(TcUtilsTest, CheckAttachBpfFilterRawIpClsactIngressLo) {
checkAttachDetachBpfFilterClsactLo(INGRESS, RAWIP);
}
-TEST_F(OffloadUtilsTest, CheckAttachBpfFilterEthernetClsactIngressLo) {
+TEST_F(TcUtilsTest, CheckAttachBpfFilterEthernetClsactIngressLo) {
checkAttachDetachBpfFilterClsactLo(INGRESS, ETHER);
}
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index 325fc4136..d8a690f9f 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -51,8 +51,8 @@
#include "InterfaceController.h"
#include "NetdConstants.h"
#include "NetworkController.h"
-#include "OffloadUtils.h"
#include "Permission.h"
+#include "TcUtils.h"
#include "TetherController.h"
#include "android/net/TetherOffloadRuleParcel.h"
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index e700f6056..0c72bb414 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -33,7 +33,7 @@
#include <netdutils/StatusOr.h>
#include "IptablesBaseTest.h"
-#include "OffloadUtils.h"
+#include "TcUtils.h"
#include "TetherController.h"
using android::base::Join;