diff --git a/frameworks/native/netmanagernative/netsys_native_service_proxy.cpp b/frameworks/native/netmanagernative/netsys_native_service_proxy.cpp index 150f9fe396555cffc67e67a3280cfc16f240b019..48badf9617ed4c0ca4243414945cc082f90a2d1d 100644 --- a/frameworks/native/netmanagernative/netsys_native_service_proxy.cpp +++ b/frameworks/native/netmanagernative/netsys_native_service_proxy.cpp @@ -244,6 +244,24 @@ int32_t NetsysNativeServiceProxy::SetInterfaceMtu(const std::string &interfaceNa return reply.ReadInt32(); } +int32_t NetsysNativeServiceProxy::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETNATIVE_LOGI("Begin to SetTcpBufferSizes"); + MessageParcel data; + if (!WriteInterfaceToken(data)) { + return ERR_FLATTEN_OBJECT; + } + if (!data.WriteString(tcpBufferSizes)) { + return ERR_FLATTEN_OBJECT; + } + + MessageParcel reply; + MessageOption option; + Remote()->SendRequest(static_cast(NetsysInterfaceCode::NETSYS_SET_TCP_BUFFER_SIZES), data, reply, option); + + return reply.ReadInt32(); +} + int32_t NetsysNativeServiceProxy::GetInterfaceMtu(const std::string &interfaceName) { NETNATIVE_LOGI("Begin to GetInterfaceMtu"); diff --git a/interfaces/innerkits/netmanagernative/include/i_netsys_service.h b/interfaces/innerkits/netmanagernative/include/i_netsys_service.h index 5c68c5e5676a6e39d566ec7175295ed65d33a114..84e47340d8390a969b0ebe5e543f146b2b0be518 100644 --- a/interfaces/innerkits/netmanagernative/include/i_netsys_service.h +++ b/interfaces/innerkits/netmanagernative/include/i_netsys_service.h @@ -48,6 +48,8 @@ public: virtual int32_t SetInterfaceMtu(const std::string &interfaceName, int mtu) = 0; virtual int32_t GetInterfaceMtu(const std::string &interfaceName) = 0; + virtual int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) = 0; + virtual int32_t RegisterNotifyCallback(sptr &callback) = 0; virtual int32_t UnRegisterNotifyCallback(sptr &callback) = 0; diff --git a/interfaces/innerkits/netmanagernative/include/netsys_ipc_interface_code.h b/interfaces/innerkits/netmanagernative/include/netsys_ipc_interface_code.h index 2f7939a1652630e0c2617eb61fb6a96ba9b1f36c..ffee81e031579fd09511486e1085c5ec9508282d 100644 --- a/interfaces/innerkits/netmanagernative/include/netsys_ipc_interface_code.h +++ b/interfaces/innerkits/netmanagernative/include/netsys_ipc_interface_code.h @@ -29,6 +29,7 @@ enum class NetsysInterfaceCode { NETSYS_GET_ADDR_INFO, NETSYS_INTERFACE_SET_MTU, NETSYS_INTERFACE_GET_MTU, + NETSYS_SET_TCP_BUFFER_SIZES, NETSYS_REGISTER_NOTIFY_CALLBACK, NETSYS_UNREGISTER_NOTIFY_CALLBACK, NETSYS_NETWORK_ADD_ROUTE, diff --git a/interfaces/innerkits/netmanagernative/include/netsys_native_service_proxy.h b/interfaces/innerkits/netmanagernative/include/netsys_native_service_proxy.h index ee3e70aca8b85b28220475abf119b95f8fa60368..44b66b9d2eb60fb0963e9f7a27c0b2590381aef1 100644 --- a/interfaces/innerkits/netmanagernative/include/netsys_native_service_proxy.h +++ b/interfaces/innerkits/netmanagernative/include/netsys_native_service_proxy.h @@ -39,6 +39,8 @@ public: int32_t SetInterfaceMtu(const std::string &interfaceName, int32_t mtu) override; int32_t GetInterfaceMtu(const std::string &interfaceName) override; + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override; + int32_t RegisterNotifyCallback(sptr &callback) override; int32_t UnRegisterNotifyCallback(sptr &callback) override; diff --git a/services/netconnmanager/include/network.h b/services/netconnmanager/include/network.h index c0fd78a8da9136f25747468db3d322ec69e346f5..0e813c2a5b0b8dfc1c7775c330715b64820bb6f3 100644 --- a/services/netconnmanager/include/network.h +++ b/services/netconnmanager/include/network.h @@ -48,6 +48,7 @@ public: void UpdateRoutes(const NetLinkInfo &newNetLinkInfo); void UpdateDns(const NetLinkInfo &netLinkInfo); void UpdateMtu(const NetLinkInfo &netLinkInfo); + void UpdateTcpBufferSize(const NetLinkInfo &netLinkInfo); void RegisterNetDetectionCallback(const sptr &callback); int32_t UnRegisterNetDetectionCallback(const sptr &callback); void StartNetDetection(bool needReport); diff --git a/services/netconnmanager/src/network.cpp b/services/netconnmanager/src/network.cpp index 7031e39e7b7145d4bd6f2cf7604713f2b67cd721..f49301bafdde84ad2bbbe6f8cc08dc243b678556 100644 --- a/services/netconnmanager/src/network.cpp +++ b/services/netconnmanager/src/network.cpp @@ -43,6 +43,7 @@ constexpr const char *ERROR_MSG_UPDATE_NET_ROUTES_FAILED = "Update netlink route constexpr const char *ERROR_MSG_SET_NET_RESOLVER_FAILED = "Set network resolver config failed"; constexpr const char *ERROR_MSG_UPDATE_NET_DNSES_FAILED = "Update netlink dns failed,dns list is empty"; constexpr const char *ERROR_MSG_SET_NET_MTU_FAILED = "Set netlink interface mtu failed"; +constexpr const char *ERROR_MSG_SET_NET_TCP_BUFFER_SIZE_FAILED = "Set netlink tcp buffer size failed"; constexpr const char *ERROR_MSG_SET_DEFAULT_NETWORK_FAILED = "Set default network failed"; constexpr const char *ERROR_MSG_CLEAR_DEFAULT_NETWORK_FAILED = "Clear default network failed"; constexpr const char *LOCAL_ROUTE_NEXT_HOP = "0.0.0.0"; @@ -178,6 +179,8 @@ bool Network::UpdateNetLinkInfo(const NetLinkInfo &netLinkInfo) UpdateRoutes(netLinkInfo); UpdateDns(netLinkInfo); UpdateMtu(netLinkInfo); + UpdateTcpBufferSize(netLinkInfo); + netLinkInfo_ = netLinkInfo; if (netSupplierType_ != BEARER_VPN) { StartNetDetection(false); @@ -358,6 +361,20 @@ void Network::UpdateMtu(const NetLinkInfo &netLinkInfo) NETMGR_LOG_D("Network UpdateMtu out."); } +void Network::UpdateTcpBufferSize(const NetLinkInfo &netLinkInfo) +{ + NETMGR_LOG_D("Network UpdateTcpBufferSize in."); + if (netLinkInfo.tcpBufferSizes_ == netLinkInfo_.tcpBufferSizes_) { + NETMGR_LOG_D("Network UpdateTcpBufferSize out. same with before."); + return; + } + int32_t ret = NetsysController::GetInstance().SetTcpBufferSizes(netLinkInfo.tcpBufferSizes_); + if (ret != NETMANAGER_SUCCESS) { + SendSupplierFaultHiSysEvent(FAULT_UPDATE_NETLINK_INFO_FAILED, ERROR_MSG_SET_NET_TCP_BUFFER_SIZE_FAILED); + } + NETMGR_LOG_D("Network UpdateTcpBufferSize out."); +} + void Network::RegisterNetDetectionCallback(const sptr &callback) { NETMGR_LOG_D("Enter RegisterNetDetectionCallback"); diff --git a/services/netmanagernative/include/netsys/net_manager_native.h b/services/netmanagernative/include/netsys/net_manager_native.h index 4a2f391cdd8b720b873b460c385a324fb2a39606..a5947b7950fa90d74264727f5c9679fc2fe30b8b 100644 --- a/services/netmanagernative/include/netsys/net_manager_native.h +++ b/services/netmanagernative/include/netsys/net_manager_native.h @@ -74,6 +74,7 @@ public: void ClearInterfaceAddrs(const std::string ifName); int32_t GetInterfaceMtu(std::string ifName); int32_t SetInterfaceMtu(std::string ifName, int32_t mtuValue); + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes); int32_t AddInterfaceAddress(std::string ifName, std::string addrString, int32_t prefixLength); int32_t DelInterfaceAddress(std::string ifName, std::string addrString, int32_t prefixLength); int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress); diff --git a/services/netmanagernative/include/netsys_native_service.h b/services/netmanagernative/include/netsys_native_service.h index 1bda288100199ece34e6b7a971a1f8884cda12d5..84171676ae6df9584bb159407a8f7ad5f54ec23e 100644 --- a/services/netmanagernative/include/netsys_native_service.h +++ b/services/netmanagernative/include/netsys_native_service.h @@ -57,6 +57,8 @@ public: int32_t SetInterfaceMtu(const std::string &interfaceName, int32_t mtu) override; int32_t GetInterfaceMtu(const std::string &interfaceName) override; + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override; + int32_t RegisterNotifyCallback(sptr &callback) override; int32_t UnRegisterNotifyCallback(sptr &callback) override; diff --git a/services/netmanagernative/include/netsys_native_service_stub.h b/services/netmanagernative/include/netsys_native_service_stub.h index 04c6df00505cdd8fd5519c2858a2767bf7940023..ffcfee1ab17c5c384e917266cd281246aa5da899 100644 --- a/services/netmanagernative/include/netsys_native_service_stub.h +++ b/services/netmanagernative/include/netsys_native_service_stub.h @@ -44,6 +44,7 @@ public: private: using ServiceInterface = int32_t (NetsysNativeServiceStub::*)(MessageParcel &data, MessageParcel &reply); std::map opToInterfaceMap_; + void InitNetInfoOpToInterfaceMap(); void InitBandwidthOpToInterfaceMap(); void InitFirewallOpToInterfaceMap(); void InitOpToInterfaceMapExt(); @@ -55,6 +56,7 @@ private: int32_t CmdGetAddrInfo(MessageParcel &data, MessageParcel &reply); int32_t CmdSetInterfaceMtu(MessageParcel &data, MessageParcel &reply); int32_t CmdGetInterfaceMtu(MessageParcel &data, MessageParcel &reply); + int32_t CmdSetTcpBufferSizes(MessageParcel &data, MessageParcel &reply); int32_t CmdRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply); int32_t CmdUnRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply); diff --git a/services/netmanagernative/src/netsys/net_manager_native.cpp b/services/netmanagernative/src/netsys/net_manager_native.cpp index 5bc0986d177526469f5a5a51bfe82d435b705aef..cc9e01a6ac053535fd57b972fbf097ed8ed07d36 100644 --- a/services/netmanagernative/src/netsys/net_manager_native.cpp +++ b/services/netmanagernative/src/netsys/net_manager_native.cpp @@ -32,6 +32,10 @@ namespace OHOS { namespace nmd { namespace { constexpr const char *TUN_CARD_NAME = "vpn-tun"; +constexpr const char *TCP_RMEM_PROC_FILE = "/proc/sys/net/ipv4/tcp_rmem"; +constexpr const char *TCP_WMEM_PROC_FILE = "/proc/sys/net/ipv4/tcp_wmem"; +constexpr uint32_t TCP_BUFFER_SIZES_TYPE = 2; +constexpr uint32_t MAX_TCP_BUFFER_SIZES_COUNT = 6; } // namespace NetManagerNative::NetManagerNative() @@ -201,6 +205,28 @@ int32_t NetManagerNative::SetInterfaceMtu(std::string ifName, int32_t mtuValue) return VpnManager::GetInstance().SetVpnMtu(ifName, mtuValue); } +int32_t NetManagerNative::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETNATIVE_LOGI("tcpBufferSizes:%{public}s", tcpBufferSizes.c_str()); + const std::vector vTcpBufferSizes = Split(tcpBufferSizes, ","); + if (vTcpBufferSizes.size() != MAX_TCP_BUFFER_SIZES_COUNT) { + NETNATIVE_LOGE("NetManagerNative::SetTcpBufferSizes size is not equals MAX_TCP_BUFFER_SIZES_COUNT"); + return -1; + } + std::string tcp_rwmem[TCP_BUFFER_SIZES_TYPE]; + for (size_t i = 0; i < TCP_BUFFER_SIZES_TYPE; i++) { + for (size_t j = 0; j < MAX_TCP_BUFFER_SIZES_COUNT / TCP_BUFFER_SIZES_TYPE; j++) { + tcp_rwmem[i] += Strip(vTcpBufferSizes[i * (MAX_TCP_BUFFER_SIZES_COUNT / TCP_BUFFER_SIZES_TYPE) + j]); + tcp_rwmem[i] += ' '; + } + } + if (!WriteFile(TCP_RMEM_PROC_FILE, tcp_rwmem[0]) || !WriteFile(TCP_WMEM_PROC_FILE, tcp_rwmem[1])) { + NETNATIVE_LOGE("NetManagerNative::SetTcpBufferSizes sysctlbyname fail %{public}d", errno); + return -1; + } + return 0; +} + int32_t NetManagerNative::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) { return InterfaceManager::SetIpAddress(ifaceName.c_str(), ipAddress.c_str()); diff --git a/services/netmanagernative/src/netsys_native_service.cpp b/services/netmanagernative/src/netsys_native_service.cpp index 69003d771b4b4e4f7641b8173848eaf3ccf67bc7..a073d91683f99bc5b1c69728addda0f0b37b038d 100644 --- a/services/netmanagernative/src/netsys_native_service.cpp +++ b/services/netmanagernative/src/netsys_native_service.cpp @@ -208,6 +208,12 @@ int32_t NetsysNativeService::GetInterfaceMtu(const std::string &interfaceName) return netsysService_->GetInterfaceMtu(interfaceName); } +int32_t NetsysNativeService::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETNATIVE_LOG_D("SetTcpBufferSizes Begin"); + return netsysService_->SetTcpBufferSizes(tcpBufferSizes); +} + int32_t NetsysNativeService::RegisterNotifyCallback(sptr &callback) { NETNATIVE_LOG_D("RegisterNotifyCallback"); diff --git a/services/netmanagernative/src/netsys_native_service_stub.cpp b/services/netmanagernative/src/netsys_native_service_stub.cpp index 0995666e421e7f6669708dd92236986226523782..271572ebc195410ab232d6500a2cf881f657ceba 100644 --- a/services/netmanagernative/src/netsys_native_service_stub.cpp +++ b/services/netmanagernative/src/netsys_native_service_stub.cpp @@ -40,6 +40,17 @@ constexpr uint32_t MAX_ROUTE_TABLE_SIZE = 128; } // namespace NetsysNativeServiceStub::NetsysNativeServiceStub() +{ + InitNetInfoOpToInterfaceMap(); + InitBandwidthOpToInterfaceMap(); + InitFirewallOpToInterfaceMap(); + InitOpToInterfaceMapExt(); + InitNetDiagOpToInterfaceMap(); + uids_ = {UID_ROOT, UID_SHELL, UID_NET_MANAGER, UID_WIFI, UID_RADIO, UID_HIDUMPER_SERVICE, + UID_SAMGR, UID_PARAM_WATCHER, UID_EDM}; +} + +void NetsysNativeServiceStub::InitNetInfoOpToInterfaceMap() { opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_SET_RESOLVER_CONFIG)] = &NetsysNativeServiceStub::CmdSetResolverConfig; @@ -55,6 +66,8 @@ NetsysNativeServiceStub::NetsysNativeServiceStub() &NetsysNativeServiceStub::CmdSetInterfaceMtu; opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_INTERFACE_GET_MTU)] = &NetsysNativeServiceStub::CmdGetInterfaceMtu; + opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_SET_TCP_BUFFER_SIZES)] = + &NetsysNativeServiceStub::CmdSetTcpBufferSizes; opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_REGISTER_NOTIFY_CALLBACK)] = &NetsysNativeServiceStub::CmdRegisterNotifyCallback; opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_UNREGISTER_NOTIFY_CALLBACK)] = @@ -83,13 +96,6 @@ NetsysNativeServiceStub::NetsysNativeServiceStub() &NetsysNativeServiceStub::CmdAddInterfaceAddress; opToInterfaceMap_[static_cast(NetsysInterfaceCode::NETSYS_INTERFACE_DEL_ADDRESS)] = &NetsysNativeServiceStub::CmdDelInterfaceAddress; - - InitBandwidthOpToInterfaceMap(); - InitFirewallOpToInterfaceMap(); - InitOpToInterfaceMapExt(); - InitNetDiagOpToInterfaceMap(); - uids_ = {UID_ROOT, UID_SHELL, UID_NET_MANAGER, UID_WIFI, UID_RADIO, UID_HIDUMPER_SERVICE, - UID_SAMGR, UID_PARAM_WATCHER, UID_EDM}; } void NetsysNativeServiceStub::InitBandwidthOpToInterfaceMap() @@ -436,6 +442,16 @@ int32_t NetsysNativeServiceStub::CmdGetInterfaceMtu(MessageParcel &data, Message return ERR_NONE; } +int32_t NetsysNativeServiceStub::CmdSetTcpBufferSizes(MessageParcel &data, MessageParcel &reply) +{ + std::string tcpBufferSizes = data.ReadString(); + int32_t result = SetTcpBufferSizes(tcpBufferSizes); + reply.WriteInt32(result); + NETNATIVE_LOG_D("SetTcpBufferSizes has recved result %{public}d", result); + + return ERR_NONE; +} + int32_t NetsysNativeServiceStub::CmdRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply) { NETNATIVE_LOG_D("Begin to dispatch cmd RegisterNotifyCallback"); diff --git a/services/netsyscontroller/include/i_netsys_controller_service.h b/services/netsyscontroller/include/i_netsys_controller_service.h index d8a629d8625d530dbe7e1c271ca922a4bbf038c0..1bfa8a241f2eeffe66af6316cfba2a07cd3628b9 100644 --- a/services/netsyscontroller/include/i_netsys_controller_service.h +++ b/services/netsyscontroller/include/i_netsys_controller_service.h @@ -172,6 +172,14 @@ public: */ virtual int32_t SetInterfaceMtu(const std::string &ifName, int32_t mtu) = 0; + /** + * Set tcp buffer sizes + * + * @param tcpBufferSizes tcpBufferSizes + * @return Return the return value of the netsys interface call + */ + virtual int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) = 0; + /** * Add ip address * diff --git a/services/netsyscontroller/include/netsys_controller.h b/services/netsyscontroller/include/netsys_controller.h index 713322c5eac3a54ab6a83a5d96a8d82ba039567a..4257b8f18b3642b96eaa0e25ecdb05ea8b422e6d 100644 --- a/services/netsyscontroller/include/netsys_controller.h +++ b/services/netsyscontroller/include/netsys_controller.h @@ -164,6 +164,14 @@ public: */ int32_t SetInterfaceMtu(const std::string &ifName, int32_t mtu); + /** + * @brief Set tcp buffer sizes + * + * @param tcpBufferSizes tcpBufferSizes + * @return Return the return value of the netsys interface call + */ + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes); + /** * Add ip address * diff --git a/services/netsyscontroller/include/netsys_controller_service_impl.h b/services/netsyscontroller/include/netsys_controller_service_impl.h index 4172a02c9c20acf0458b7e0dd8de89d508b0cc7c..e7bf9295ed332b221ee64682fd379be44b1fad9d 100644 --- a/services/netsyscontroller/include/netsys_controller_service_impl.h +++ b/services/netsyscontroller/include/netsys_controller_service_impl.h @@ -157,6 +157,14 @@ public: */ int32_t SetInterfaceMtu(const std::string &ifName, int32_t mtu) override; + /** + * Set tcp buffer sizes + * + * @param tcpBufferSizes tcpBufferSizes + * @return Return the return value of the netsys interface call + */ + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override; + /** * Add ip address * diff --git a/services/netsyscontroller/include/netsys_native_client.h b/services/netsyscontroller/include/netsys_native_client.h index 2b415eea3965903e4ce5c4cbd5897ed11318e82a..89337f95aeadddcf6fa1349c1c627e5cafa68bb1 100644 --- a/services/netsyscontroller/include/netsys_native_client.h +++ b/services/netsyscontroller/include/netsys_native_client.h @@ -186,6 +186,14 @@ public: */ int32_t SetInterfaceMtu(const std::string &ifName, int32_t mtu); + /** + * Set tcp buffer sizes + * + * @param tcpBufferSizes tcpBufferSizes + * @return Return the return value of the netsys interface call + */ + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes); + /** * Add ip address * diff --git a/services/netsyscontroller/src/netsys_controller.cpp b/services/netsyscontroller/src/netsys_controller.cpp index 8d94049b29fadd6eed1f8ffa5201fb1bdc8d416c..530dceb6801fe955a302f6b2a2fd4e95fb36717c 100644 --- a/services/netsyscontroller/src/netsys_controller.cpp +++ b/services/netsyscontroller/src/netsys_controller.cpp @@ -239,6 +239,16 @@ int32_t NetsysController::SetInterfaceMtu(const std::string &ifName, int32_t mtu return netsysService_->SetInterfaceMtu(ifName, mtu); } +int32_t NetsysController::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETMGR_LOG_D("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str()); + if (netsysService_ == nullptr) { + NETMGR_LOG_E("netsysService_ is null"); + return NETSYS_NETSYSSERVICE_NULL; + } + return netsysService_->SetTcpBufferSizes(tcpBufferSizes); +} + int32_t NetsysController::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength) { diff --git a/services/netsyscontroller/src/netsys_controller_service_impl.cpp b/services/netsyscontroller/src/netsys_controller_service_impl.cpp index fedde6093fbece18dc0c99bf5ca53173828f70dd..f9a02bd0976d2eb35dd2d51425aa2e915cd71bd1 100644 --- a/services/netsyscontroller/src/netsys_controller_service_impl.cpp +++ b/services/netsyscontroller/src/netsys_controller_service_impl.cpp @@ -164,6 +164,12 @@ int32_t NetsysControllerServiceImpl::SetInterfaceMtu(const std::string &ifName, return netsysClient_.SetInterfaceMtu(ifName, mtu); } +int32_t NetsysControllerServiceImpl::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETMGR_LOG_I("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str()); + return netsysClient_.SetTcpBufferSizes(tcpBufferSizes); +} + int32_t NetsysControllerServiceImpl::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength) { diff --git a/services/netsyscontroller/src/netsys_native_client.cpp b/services/netsyscontroller/src/netsys_native_client.cpp index 198fffdd20b2326ae620a6005f3df918de6d2778..4ae5d1f565fab4565c84ed729c8071dbd64b8a78 100644 --- a/services/netsyscontroller/src/netsys_native_client.cpp +++ b/services/netsyscontroller/src/netsys_native_client.cpp @@ -359,6 +359,17 @@ int32_t NetsysNativeClient::SetInterfaceMtu(const std::string &ifName, int32_t m return proxy->SetInterfaceMtu(ifName, mtu); } +int32_t NetsysNativeClient::SetTcpBufferSizes(const std::string &tcpBufferSizes) +{ + NETMGR_LOG_D("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str()); + auto proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_LOG_E("proxy is nullptr"); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + return proxy->SetTcpBufferSizes(tcpBufferSizes); +} + int32_t NetsysNativeClient::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength) { diff --git a/test/netconnmanager/unittest/net_conn_manager_test/net_conn_hievent_test.cpp b/test/netconnmanager/unittest/net_conn_manager_test/net_conn_hievent_test.cpp index 5d2a0e126d30ed15f2b41b3e91a6e3ec28f00ac5..5c58b6ab7ecb921f1e5cb472a5d805e24a7a624b 100644 --- a/test/netconnmanager/unittest/net_conn_manager_test/net_conn_hievent_test.cpp +++ b/test/netconnmanager/unittest/net_conn_manager_test/net_conn_hievent_test.cpp @@ -269,5 +269,19 @@ HWTEST_F(NetConnHiEventTest, NetConnHiEventTest_011, TestSize.Level1) int32_t ret = NetConnService::GetInstance()->RegisterNetConnCallback(nullptr, nullptr, 0); EXPECT_NE(ret, NETMANAGER_SUCCESS); } + +/** + * @tc.name: NetConnHiEventTest_012 + * @tc.desc: Test NetConnManager HiSysEvent:UpdateTcpBufferSize + * @tc.type: FUNC + */ +HWTEST_F(NetConnHiEventTest, NetConnHiEventTest_012, TestSize.Level1) +{ + sptr network = GetNetwork(); + ASSERT_NE(network, nullptr); + sptr netLinkInfo = GetNetLinkInfo(); + ASSERT_NE(netLinkInfo, nullptr); + network->UpdateTcpBufferSize(*netLinkInfo); +} } // namespace NetManagerStandard } // namespace OHOS diff --git a/test/netconnmanager/unittest/net_conn_manager_test/network_test.cpp b/test/netconnmanager/unittest/net_conn_manager_test/network_test.cpp index 3cdc9afed7075d77439b0144818b94927a8f7644..476dad3f5a4ac4ce8dd3e9027c6901ff5356f776 100644 --- a/test/netconnmanager/unittest/net_conn_manager_test/network_test.cpp +++ b/test/netconnmanager/unittest/net_conn_manager_test/network_test.cpp @@ -113,6 +113,7 @@ HWTEST_F(NetworkTest, UpdateTest001, TestSize.Level1) instance_->UpdateRoutes(info); instance_->UpdateDns(info); instance_->UpdateMtu(info); + instance_->UpdateTcpBufferSize(info); instance_->RegisterNetDetectionCallback(callabck_); int32_t ret = instance_->UnRegisterNetDetectionCallback(callabck_); EXPECT_EQ(ret, NETMANAGER_SUCCESS); diff --git a/test/netmanagernative/unit_test/resolver_config.cpp b/test/netmanagernative/unit_test/resolver_config.cpp index 07edd66a6c8bc98aef8640ecfe6a93553058da23..f2ad59a40052ab4981b6e0c88a18395b0163469b 100644 --- a/test/netmanagernative/unit_test/resolver_config.cpp +++ b/test/netmanagernative/unit_test/resolver_config.cpp @@ -171,3 +171,11 @@ void TestRegisterNotifyCallback() return; } + +void TestSetTcpBufferSizes() +{ + std::string tcpBufferSizes = "524288,1048576,2097152,262144,524288,1048576"; + std::cout << "begin to SetTcpBufferSizes" << std::endl; + ret = netsysServiceK_->SetTcpBufferSizes(tcpBufferSizes); + NETNATIVE_LOGE("NETSYS: SetTcpBufferSizes ret=%{public}d", ret); +} \ No newline at end of file diff --git a/test/netmanagernative/unit_test/test.cpp b/test/netmanagernative/unit_test/test.cpp index d1e40f4cc602fd39995a5aef19d58302097b6fe4..3bfdfb90b95897b42ec0518871533ffaebb13fb7 100644 --- a/test/netmanagernative/unit_test/test.cpp +++ b/test/netmanagernative/unit_test/test.cpp @@ -55,6 +55,7 @@ enum class InterfaceMenu { NETWORK_ADD_INTERFACE_WIFI = 27, NETWORK_REMOVE_INTERFACE_WIFI = 28, NETWORK_SET_DEFAULT_WIFI = 29, + SET_TCP_BUFFER_SIZES = 30, INPUT_QUIT = 100, }; @@ -92,6 +93,7 @@ void Init() g_memberFuncMap[InterfaceMenu::NETWORK_ADD_INTERFACE_WIFI] = TestNetworkAddInterfaceWIFI; g_memberFuncMap[InterfaceMenu::NETWORK_REMOVE_INTERFACE_WIFI] = TestNetworkRemoveInterfaceWIFI; g_memberFuncMap[InterfaceMenu::NETWORK_SET_DEFAULT_WIFI] = TestNetworkSetDefaultWIFI; + g_memberFuncMap[InterfaceMenu::SET_TCP_BUFFER_SIZES] = TestSetTcpBufferSizes; } void Prompt() @@ -127,6 +129,7 @@ void Prompt() "27 TestNetworkAddInterfaceWIFI\n" "28 TestNetworkRemoveInterfaceWIFI\n" "29 TestNetworkSetDefaultWIFI\n" + "30 SetTcpBufferSizes\n" "100:exit \n"); } diff --git a/test/netmanagernative/unit_test/test.h b/test/netmanagernative/unit_test/test.h index e51072bc0ceddb84a37aad08cdd336cc024db899..74bce33291a7489a3ff29a01b4e06b1351d6ed9d 100644 --- a/test/netmanagernative/unit_test/test.h +++ b/test/netmanagernative/unit_test/test.h @@ -52,6 +52,7 @@ void TestNetworkGetDefaultUnion(void); void TestNetworkSetDefaultWIFI(void); void TestNetworkAddInterfaceWIFI(void); void TestNetworkRemoveInterfaceWIFI(void); +void TestSetTcpBufferSizes(void); #endif // !NETSYS_MAIN_TEST_H__ diff --git a/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_service_impl_test.cpp b/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_service_impl_test.cpp index cf49a12e718745f1c1783251687797a25313849c..b088015062c3b0be63ccf62334561a1a817f721f 100644 --- a/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_service_impl_test.cpp +++ b/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_service_impl_test.cpp @@ -249,6 +249,10 @@ HWTEST_F(NetsysControllerServiceImplTest, SetInternetPermission, TestSize.Level1 auto ret = instance_->SetInternetPermission(uid, allow); EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERROR); + + std::string tcpBufferSizes = "524288,1048576,2097152,262144,524288,1048576"; + ret = instance_->SetTcpBufferSizes(tcpBufferSizes); + EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS); } } // namespace NetManagerStandard diff --git a/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_test.cpp b/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_test.cpp index 9468424bf03fd9d1145d514eda3bd458636d5001..2146025ad2b420c69b8b4d676ace91495677c1c7 100644 --- a/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_test.cpp +++ b/test/netmanagernative/unittest/netsys_manager_test/netsys_controller_test.cpp @@ -50,6 +50,7 @@ static constexpr const char *PARCEL_IPV4_ADDR = "192.168.55.121"; static constexpr const char *IP_ADDR = "172.17.5.245"; static constexpr const char *INTERFACE_NAME = ""; static constexpr const char *IF_NAME = "iface0"; +static constexpr const char *TCP_BUFFER_SIZES = "524288,1048576,2097152,262144,524288,1048576"; const int NET_ID = 2; const int PERMISSION = 5; const int PREFIX_LENGTH = 23; @@ -296,6 +297,9 @@ HWTEST_F(NetsysControllerTest, NetsysControllerTest006, TestSize.Level1) ret = NetsysController::GetInstance().GetInterfaceMtu(ETH0); EXPECT_EQ(ret, -1); + + ret = NetsysController::GetInstance().SetTcpBufferSizes(TCP_BUFFER_SIZES); + EXPECT_EQ(ret, -1); } HWTEST_F(NetsysControllerTest, NetsysControllerTest007, TestSize.Level1) @@ -864,6 +868,9 @@ HWTEST_F(NetsysControllerTest, NetsysControllerErr006, TestSize.Level1) ret = instance_->SetIptablesCommandForRes(iface, iface); EXPECT_EQ(ret, NetManagerStandard::NETSYS_NETSYSSERVICE_NULL); + + ret = instance_->SetTcpBufferSizes(""); + EXPECT_EQ(ret, NetManagerStandard::NETSYS_NETSYSSERVICE_NULL); } HWTEST_F(NetsysControllerTest, NetDiagGetRouteTable001, TestSize.Level1) diff --git a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_client_test.cpp b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_client_test.cpp index e8ad350530330e1c2fd05a920563f7c952182233..013588f81c2439066a151182d95bf53ca2c49553 100644 --- a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_client_test.cpp +++ b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_client_test.cpp @@ -35,6 +35,7 @@ static constexpr const char *IFACE = "test0"; static constexpr const char *IP_ADDR = "172.17.5.245"; static constexpr const char *INTERFACE_NAME = "interface_name"; static constexpr const char *REQUESTOR = "requestor"; +static constexpr const char *TCP_BUFFER_SIZES = "524288,1048576,2097152,262144,524288,1048576"; const int32_t MTU = 111; const int32_t NET_ID = 2; const int32_t IFACEFD = 5; @@ -111,6 +112,9 @@ HWTEST_F(NetsysNativeClientTest, NetsysNativeClientTest001, TestSize.Level1) ret = nativeClient_.SetInterfaceMtu(IF_NAME, MTU); EXPECT_EQ(ret, -1); + + ret = nativeClient_.SetTcpBufferSizes(TCP_BUFFER_SIZES); + EXPECT_EQ(ret, -1); } HWTEST_F(NetsysNativeClientTest, NetsysNativeClientTest002, TestSize.Level1) diff --git a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_stub_test.cpp b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_stub_test.cpp index c9d27e55cd5e5ed46549126f26d9a2b6569d525a..43c385389865250fd3b713b2c1b41d70e7f4b7be 100644 --- a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_stub_test.cpp +++ b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_stub_test.cpp @@ -188,6 +188,11 @@ public: return 0; } + int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override + { + return 0; + } + int32_t GetInterfaceMtu(const std::string &interfaceName) override { return 0; diff --git a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_test.cpp b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_test.cpp index 70d08555f4b50ecf9a62119d3fc725a51832bcd2..ce3e463d57c28b001cfb69ea3ec01d4e7820e446 100644 --- a/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_test.cpp +++ b/test/netmanagernative/unittest/netsys_manager_test/netsys_native_service_test.cpp @@ -236,6 +236,13 @@ HWTEST_F(NetsysNativeServiceTest, SetInterfaceMtu001, TestSize.Level1) EXPECT_EQ(ret, 0); } +HWTEST_F(NetsysNativeServiceTest, SetTcpBufferSizes001, TestSize.Level1) +{ + std::string tcpBufferSizes = "524288,1048576,2097152,262144,524288,1048576"; + int32_t ret = instance_->SetTcpBufferSizes(tcpBufferSizes); + EXPECT_EQ(ret, 0); +} + HWTEST_F(NetsysNativeServiceTest, GetInterfaceMtu001, TestSize.Level1) { std::string testName = "test0"; diff --git a/utils/common_utils/include/netmanager_base_common_utils.h b/utils/common_utils/include/netmanager_base_common_utils.h index 45199f6417ec535a2365df03dcd538e9afb6137e..19d1aad85489d50e37a319f5ff52a7e9b8d5b2f6 100644 --- a/utils/common_utils/include/netmanager_base_common_utils.h +++ b/utils/common_utils/include/netmanager_base_common_utils.h @@ -65,6 +65,8 @@ inline uint64_t GetCurrentSecond() return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) .count(); } + +bool WriteFile(const std::string &filePath, const std::string &fileContent); } // namespace OHOS::NetManagerStandard::CommonUtils #endif /* COMMUNICATIONNETMANAGER_BASE_COMMON_UTILS_H */ diff --git a/utils/common_utils/src/netmanager_base_common_utils.cpp b/utils/common_utils/src/netmanager_base_common_utils.cpp index 9905c45b8a26820b0a219e58e6488fbce2470cdf..c0b8fcf7b9a751469722467da90e3fc7fc8ff64f 100644 --- a/utils/common_utils/src/netmanager_base_common_utils.cpp +++ b/utils/common_utils/src/netmanager_base_common_utils.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "net_manager_constants.h" #include "net_mgr_log_wrapper.h" @@ -608,4 +609,17 @@ bool IsValidDomain(const std::string &domain) } return true; } + +bool WriteFile(const std::string &filePath, const std::string &fileContent) +{ + std::fstream file(filePath.c_str(), std::fstream::out | std::fstream::trunc); + if (!file.is_open()) { + NETMGR_LOG_E("write file=%{public}s fstream failed. err %{public}d %{public}s", + filePath.c_str(), errno, strerror(errno)); + return false; + } + file << fileContent.c_str(); + file.close(); + return true; +} } // namespace OHOS::NetManagerStandard::CommonUtils