1 /* 2 * Copyright (c) 2022 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 #ifndef I_NETSYS_SERVICE_H 16 #define I_NETSYS_SERVICE_H 17 18 #include <netdb.h> 19 #include <string> 20 21 #include "dns_config_client.h" 22 #include "i_notify_callback.h" 23 #include "interface_type.h" 24 #include "iremote_broker.h" 25 #include "route_type.h" 26 #include "network_sharing.h" 27 28 namespace OHOS { 29 namespace NetsysNative { 30 using namespace nmd; 31 class INetsysService : public IRemoteBroker { 32 public: 33 enum { 34 NETSYS_SET_RESOLVER_CONFIG_PARCEL, 35 NETSYS_SET_RESOLVER_CONFIG, 36 NETSYS_GET_RESOLVER_CONFIG, 37 NETSYS_CREATE_NETWORK_CACHE, 38 NETSYS_FLUSH_NETWORK_CACHE, 39 NETSYS_DESTROY_NETWORK_CACHE, 40 NETSYS_GET_ADDR_INFO, 41 NETSYS_INTERFACE_SET_MTU, 42 NETSYS_INTERFACE_GET_MTU, 43 NETSYS_REGISTER_NOTIFY_CALLBACK, 44 NETSYS_UNREGISTER_NOTIFY_CALLBACK, 45 NETSYS_NETWORK_ADD_ROUTE, 46 NETSYS_NETWORK_REMOVE_ROUTE, 47 NETSYS_NETWORK_ADD_ROUTE_PARCEL, 48 NETSYS_NETWORK_REMOVE_ROUTE_PARCEL, 49 NETSYS_NETWORK_SET_DEFAULT, 50 NETSYS_NETWORK_GET_DEFAULT, 51 NETSYS_NETWORK_CLEAR_DEFAULT, 52 NETSYS_GET_PROC_SYS_NET, 53 NETSYS_SET_PROC_SYS_NET, 54 NETSYS_NETWORK_CREATE_PHYSICAL, 55 NETSYS_INTERFACE_ADD_ADDRESS, 56 NETSYS_INTERFACE_DEL_ADDRESS, 57 NETSYS_INTERFACE_SET_IP_ADDRESS, 58 NETSYS_INTERFACE_SET_IFF_UP, 59 NETSYS_NETWORK_ADD_INTERFACE, 60 NETSYS_NETWORK_REMOVE_INTERFACE, 61 NETSYS_NETWORK_DESTROY, 62 NETSYS_GET_FWMARK_FOR_NETWORK, 63 NETSYS_INTERFACE_SET_CONFIG, 64 NETSYS_INTERFACE_GET_CONFIG, 65 NETSYS_INTERFACE_GET_LIST, 66 NETSYS_START_DHCP_CLIENT, 67 NETSYS_STOP_DHCP_CLIENT, 68 NETSYS_START_DHCP_SERVICE, 69 NETSYS_STOP_DHCP_SERVICE, 70 NETSYS_IPENABLE_FORWARDING, 71 NETSYS_IPDISABLE_FORWARDING, 72 NETSYS_ENABLE_NAT, 73 NETSYS_DISABLE_NAT, 74 NETSYS_IPFWD_ADD_INTERFACE_FORWARD, 75 NETSYS_IPFWD_REMOVE_INTERFACE_FORWARD, 76 NETSYS_BANDWIDTH_ENABLE_DATA_SAVER, 77 NETSYS_BANDWIDTH_SET_IFACE_QUOTA, 78 NETSYS_BANDWIDTH_REMOVE_IFACE_QUOTA, 79 NETSYS_BANDWIDTH_ADD_DENIED_LIST, 80 NETSYS_BANDWIDTH_REMOVE_DENIED_LIST, 81 NETSYS_BANDWIDTH_ADD_ALLOWED_LIST, 82 NETSYS_BANDWIDTH_REMOVE_ALLOWED_LIST, 83 NETSYS_FIREWALL_SET_UID_ALLOWED_LIST_CHAIN, 84 NETSYS_FIREWALL_SET_UID_DENIED_LIST_CHAIN, 85 NETSYS_FIREWALL_ENABLE_CHAIN, 86 NETSYS_FIREWALL_SET_UID_RULE, 87 NETSYS_TETHER_DNS_SET, 88 NETSYS_START_DNS_PROXY_LISTEN, 89 NETSYS_STOP_DNS_PROXY_LISTEN, 90 NETSYS_GET_SHARING_NETWORK_TRAFFIC, 91 }; 92 93 virtual int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount, 94 const std::vector<std::string> &servers, 95 const std::vector<std::string> &domains) = 0; 96 virtual int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, 97 std::vector<std::string> &domains, uint16_t &baseTimeoutMsec, 98 uint8_t &retryCount) = 0; 99 virtual int32_t CreateNetworkCache(uint16_t netId) = 0; 100 virtual int32_t DestroyNetworkCache(uint16_t netId) = 0; 101 102 virtual int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints, 103 uint16_t netId, std::vector<AddrInfo> &res) = 0; 104 virtual int32_t InterfaceSetMtu(const std::string &interfaceName, int mtu) = 0; 105 virtual int32_t InterfaceGetMtu(const std::string &interfaceName) = 0; 106 107 virtual int32_t RegisterNotifyCallback(sptr<INotifyCallback> &callback) = 0; 108 virtual int32_t UnRegisterNotifyCallback(sptr<INotifyCallback> &callback) = 0; 109 110 virtual int32_t NetworkAddRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 111 const std::string &nextHop) = 0; 112 virtual int32_t NetworkRemoveRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 113 const std::string &nextHop) = 0; 114 virtual int32_t NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) = 0; 115 virtual int32_t NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) = 0; 116 virtual int32_t NetworkSetDefault(int32_t netId) = 0; 117 virtual int32_t NetworkGetDefault() = 0; 118 virtual int32_t NetworkClearDefault() = 0; 119 virtual int32_t GetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname, 120 const std::string ¶meter, std::string &value) = 0; 121 virtual int32_t SetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname, 122 const std::string ¶meter, std::string &value) = 0; 123 virtual int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) = 0; 124 virtual int32_t InterfaceAddAddress(const std::string &interfaceName, const std::string &addrString, 125 int32_t prefixLength) = 0; 126 virtual int32_t InterfaceDelAddress(const std::string &interfaceName, const std::string &addrString, 127 int32_t prefixLength) = 0; 128 virtual int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) = 0; 129 virtual int32_t InterfaceSetIffUp(const std::string &ifaceName) = 0; 130 virtual int32_t NetworkAddInterface(int32_t netId, const std::string &iface) = 0; 131 virtual int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) = 0; 132 virtual int32_t NetworkDestroy(int32_t netId) = 0; 133 virtual int32_t GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel) = 0; 134 virtual int32_t InterfaceSetConfig(const InterfaceConfigurationParcel &cfg) = 0; 135 virtual int32_t InterfaceGetConfig(InterfaceConfigurationParcel &cfg) = 0; 136 virtual int32_t InterfaceGetList(std::vector<std::string> &ifaces) = 0; 137 virtual int32_t StartDhcpClient(const std::string &iface, bool bIpv6) = 0; 138 virtual int32_t StopDhcpClient(const std::string &iface, bool bIpv6) = 0; 139 virtual int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) = 0; 140 virtual int32_t StopDhcpService(const std::string &iface) = 0; 141 virtual int32_t IpEnableForwarding(const std::string &requestor) = 0; 142 virtual int32_t IpDisableForwarding(const std::string &requestor) = 0; 143 virtual int32_t EnableNat(const std::string &downstreamIface, const std::string &upstreamIface) = 0; 144 virtual int32_t DisableNat(const std::string &downstreamIface, const std::string &upstreamIface) = 0; 145 virtual int32_t IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) = 0; 146 virtual int32_t IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) = 0; 147 virtual int32_t BandwidthAddAllowedList(uint32_t uid) = 0; 148 virtual int32_t BandwidthRemoveAllowedList(uint32_t uid) = 0; 149 virtual int32_t BandwidthEnableDataSaver(bool enable) = 0; 150 virtual int32_t BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) = 0; 151 virtual int32_t BandwidthAddDeniedList(uint32_t uid) = 0; 152 virtual int32_t BandwidthRemoveDeniedList(uint32_t uid) = 0; 153 virtual int32_t BandwidthRemoveIfaceQuota(const std::string &ifName) = 0; 154 virtual int32_t FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) = 0; 155 virtual int32_t FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) = 0; 156 virtual int32_t FirewallEnableChain(uint32_t chain, bool enable) = 0; 157 virtual int32_t FirewallSetUidRule(uint32_t chain, uint32_t uid, uint32_t firewallRule) = 0; 158 virtual int32_t ShareDnsSet(uint16_t netId) = 0; 159 virtual int32_t StartDnsProxyListen() = 0; 160 virtual int32_t StopDnsProxyListen() = 0; 161 virtual int32_t GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface, 162 NetworkSharingTraffic &traffic) = 0; 163 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetsysNative.INetsysService") 164 }; 165 } // namespace NetsysNative 166 } // namespace OHOS 167 #endif // I_NETSYS_SERVICE_H 168