1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NETSYS_NATIVE_SERVICE_PROXY_H 17 #define NETSYS_NATIVE_SERVICE_PROXY_H 18 19 #include "i_netsys_service.h" 20 #include "iremote_proxy.h" 21 22 #define NET_SYMBOL_VISIBLE __attribute__ ((visibility("default"))) 23 namespace OHOS { 24 namespace NetsysNative { 25 class NET_SYMBOL_VISIBLE NetsysNativeServiceProxy : public IRemoteProxy<INetsysService> { 26 public: NetsysNativeServiceProxy(const sptr<IRemoteObject> & impl)27 explicit NetsysNativeServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<INetsysService>(impl) {} ~NetsysNativeServiceProxy()28 ~NetsysNativeServiceProxy() override {} 29 bool WriteInterfaceToken(MessageParcel &data); 30 int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount, 31 const std::vector<std::string> &servers, 32 const std::vector<std::string> &domains) override; 33 int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, std::vector<std::string> &domains, 34 uint16_t &baseTimeoutMsec, uint8_t &retryCount) override; 35 int32_t CreateNetworkCache(uint16_t netId) override; 36 int32_t DestroyNetworkCache(uint16_t netId) override; 37 int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints, 38 uint16_t netId, std::vector<AddrInfo> &res) override; 39 int32_t SetInterfaceMtu(const std::string &interfaceName, int32_t mtu) override; 40 int32_t GetInterfaceMtu(const std::string &interfaceName) override; 41 42 int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override; 43 44 int32_t RegisterNotifyCallback(sptr<INotifyCallback> &callback) override; 45 int32_t UnRegisterNotifyCallback(sptr<INotifyCallback> &callback) override; 46 47 int32_t NetworkAddRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 48 const std::string &nextHop) override; 49 int32_t NetworkRemoveRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 50 const std::string &nextHop) override; 51 int32_t NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override; 52 int32_t NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override; 53 int32_t NetworkSetDefault(int32_t netId) override; 54 int32_t NetworkGetDefault() override; 55 int32_t NetworkClearDefault() override; 56 int32_t GetProcSysNet(int32_t family, int32_t which, const std::string &ifname, const std::string ¶meter, 57 std::string &value) override; 58 int32_t SetProcSysNet(int32_t family, int32_t which, const std::string &ifname, const std::string ¶meter, 59 std::string &value) override; 60 int32_t SetInternetPermission(uint32_t uid, uint8_t allow, uint8_t isBroker) override; 61 int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) override; 62 int32_t NetworkCreateVirtual(int32_t netId, bool hasDns) override; 63 int32_t NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges) override; 64 int32_t NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges) override; 65 int32_t AddInterfaceAddress(const std::string &interfaceName, const std::string &addrString, 66 int32_t prefixLength) override; 67 int32_t DelInterfaceAddress(const std::string &interfaceName, const std::string &addrString, 68 int32_t prefixLength) override; 69 int32_t DelInterfaceAddress(const std::string &interfaceName, const std::string &addrString, 70 int32_t prefixLength, const std::string &netCapabilities) override; 71 int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) override; 72 int32_t InterfaceSetIffUp(const std::string &ifaceName) override; 73 int32_t NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType) override; 74 int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) override; 75 int32_t NetworkDestroy(int32_t netId) override; 76 int32_t CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix, 77 const std::set<int32_t> &uids) override; 78 int32_t DestroyVnic() override; 79 int32_t GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel) override; 80 int32_t SetInterfaceConfig(const InterfaceConfigurationParcel &cfg) override; 81 int32_t GetInterfaceConfig(InterfaceConfigurationParcel &cfg) override; 82 int32_t StartDhcpClient(const std::string &iface, bool bIpv6) override; 83 int32_t InterfaceGetList(std::vector<std::string> &ifaces) override; 84 int32_t StopDhcpClient(const std::string &iface, bool bIpv6) override; 85 int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) override; 86 int32_t StopDhcpService(const std::string &iface) override; 87 int32_t IpEnableForwarding(const std::string &requestor) override; 88 int32_t IpDisableForwarding(const std::string &requestor) override; 89 int32_t EnableNat(const std::string &downstreamIface, const std::string &upstreamIface) override; 90 int32_t DisableNat(const std::string &downstreamIface, const std::string &upstreamIface) override; 91 int32_t IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) override; 92 int32_t IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) override; 93 int32_t FirewallEnableChain(uint32_t chain, bool enable) override; 94 int32_t FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule) override; 95 int32_t BandwidthRemoveAllowedList(uint32_t uid) override; 96 int32_t FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override; 97 int32_t FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override; 98 int32_t BandwidthRemoveIfaceQuota(const std::string &ifName) override; 99 int32_t BandwidthRemoveDeniedList(uint32_t uid) override; 100 int32_t BandwidthAddDeniedList(uint32_t uid) override; 101 int32_t BandwidthAddAllowedList(uint32_t uid) override; 102 int32_t BandwidthEnableDataSaver(bool enable) override; 103 int32_t BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) override; 104 int32_t ShareDnsSet(uint16_t netId) override; 105 int32_t StartDnsProxyListen() override; 106 int32_t StopDnsProxyListen() override; 107 int32_t GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface, 108 NetworkSharingTraffic &traffic) override; 109 int32_t GetTotalStats(uint64_t &stats, uint32_t type) override; 110 int32_t GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid) override; 111 int32_t GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName) override; 112 int32_t GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override; 113 int32_t DeleteStatsInfo(uint32_t uid) override; 114 int32_t GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override; 115 int32_t DeleteSimStatsInfo(uint32_t uid) override; 116 int32_t SetIptablesCommandForRes(const std::string &cmd, std::string &respond, IptablesType ipType) override; 117 int32_t NetDiagPingHost(const NetDiagPingOption &pingOption, const sptr<INetDiagCallback> &callback) override; 118 int32_t NetDiagGetRouteTable(std::list<NetDiagRouteTable> &routeTables) override; 119 int32_t NetDiagGetSocketsInfo(NetDiagProtocolType socketType, NetDiagSocketsInfo &socketsInfo) override; 120 int32_t NetDiagGetInterfaceConfig(std::list<NetDiagIfaceConfig> &configs, const std::string &ifaceName) override; 121 int32_t NetDiagUpdateInterfaceConfig(const NetDiagIfaceConfig &config, const std::string &ifaceName, 122 bool add) override; 123 int32_t NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up) override; 124 int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr, 125 const std::string &ifName) override; 126 int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr, 127 const std::string &ifName) override; 128 129 int32_t RegisterDnsResultCallback(const sptr<INetDnsResultCallback> &callback, uint32_t delay) override; 130 int32_t UnregisterDnsResultCallback(const sptr<INetDnsResultCallback> &callback) override; 131 int32_t RegisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback) override; 132 int32_t UnregisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback) override; 133 int32_t GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie) override; 134 int32_t GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn) override; 135 int32_t UpdateNetworkSharingType(uint32_t type, bool isOpen) override; 136 #ifdef FEATURE_NET_FIREWALL_ENABLE 137 int32_t SetFirewallRules(NetFirewallRuleType type, const std::vector<sptr<NetFirewallBaseRule>> &ruleList, 138 bool isFinish) override; 139 int32_t SetFirewallDefaultAction(FirewallRuleAction inDefault, FirewallRuleAction outDefault) override; 140 int32_t SetFirewallCurrentUserId(int32_t userId) override; 141 int32_t ClearFirewallRules(NetFirewallRuleType type) override; 142 int32_t RegisterNetFirewallCallback(const sptr<INetFirewallCallback> &callback) override; 143 int32_t UnRegisterNetFirewallCallback(const sptr<INetFirewallCallback> &callback) override; 144 #endif 145 int32_t SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag, 146 bool isBroker) override; 147 int32_t DeleteNetworkAccessPolicy(uint32_t uid) override; 148 int32_t NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes) override; 149 150 int32_t SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on) override; 151 int32_t SetEnableIpv6(const std::string &interfaceName, const uint32_t on) override; 152 int32_t StartClat(const std::string &interfaceName, int32_t netId, const std::string &nat64PrefixStr) override; 153 int32_t StopClat(const std::string &interfaceName) override; 154 int32_t ClearFirewallAllRules() override; 155 int32_t SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status) override; 156 private: 157 int32_t DealBandwidth(uint32_t uid, uint32_t code); 158 static inline BrokerDelegator<NetsysNativeServiceProxy> delegator_; 159 }; 160 } // namespace NetsysNative 161 } // namespace OHOS 162 #endif // NETSYS_NATIVE_SERVICE_PROXY_H 163