1 /* 2 * Copyright (c) 2021 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 <string> 19 #include <netdb.h> 20 #include "iremote_broker.h" 21 #include "dnsresolver_params_parcel.h" 22 #include "net_manager_native.h" 23 #include "i_notify_callback.h" 24 25 namespace OHOS { 26 namespace NetsysNative { 27 using namespace nmd; 28 class INetsysService : public IRemoteBroker { 29 public: 30 enum { 31 NETSYS_SET_RESOLVER_CONFIG_PARCEL, 32 NETSYS_SET_RESOLVER_CONFIG, 33 NETSYS_GET_RESOLVER_CONFIG, 34 NETSYS_CREATE_NETWORK_CACHE, 35 NETSYS_FLUSH_NETWORK_CACHE, 36 NETSYS_DESTROY_NETWORK_CACHE, 37 NETSYS_GET_ADDR_INFO, 38 NETSYS_INTERFACE_SET_MTU, 39 NETSYS_INTERFACE_GET_MTU, 40 NETSYS_REGISTER_NOTIFY_CALLBACK, 41 NETSYS_NETWORK_ADD_ROUTE, 42 NETSYS_NETWORK_REMOVE_ROUTE, 43 NETSYS_NETWORK_ADD_ROUTE_PARCEL, 44 NETSYS_NETWORK_REMOVE_ROUTE_PARCEL, 45 NETSYS_NETWORK_SET_DEFAULT, 46 NETSYS_NETWORK_GET_DEFAULT, 47 NETSYS_NETWORK_CLEAR_DEFAULT, 48 NETSYS_GET_PROC_SYS_NET, 49 NETSYS_SET_PROC_SYS_NET, 50 NETSYS_NETWORK_CREATE_PHYSICAL, 51 NETSYS_INTERFACE_ADD_ADDRESS, 52 NETSYS_INTERFACE_DEL_ADDRESS, 53 NETSYS_NETWORK_ADD_INTERFACE, 54 NETSYS_NETWORK_REMOVE_INTERFACE, 55 NETSYS_NETWORK_DESTROY, 56 NETSYS_GET_FWMARK_FOR_NETWORK, 57 NETSYS_INTERFACE_SET_CONFIG, 58 NETSYS_INTERFACE_GET_CONFIG, 59 NETSYS_INTERFACE_GET_LIST, 60 NETSYS_START_DHCP_CLIENT, 61 NETSYS_STOP_DHCP_CLIENT, 62 NETSYS_START_DHCP_SERVICE, 63 NETSYS_STOP_DHCP_SERVICE, 64 }; 65 66 virtual int32_t SetResolverConfigParcel(const DnsresolverParamsParcel& resolvParams) = 0; 67 virtual int32_t SetResolverConfig(const DnsresolverParams &resolvParams) = 0; 68 virtual int32_t GetResolverConfig(const uint16_t netid, std::vector<std::string> &servers, 69 std::vector<std::string> &domains, nmd::DnsResParams ¶m)=0; 70 virtual int32_t CreateNetworkCache(const uint16_t netid) = 0; 71 virtual int32_t FlushNetworkCache(const uint16_t netid) = 0; 72 virtual int32_t DestroyNetworkCache(const uint16_t netid) = 0; 73 virtual int32_t Getaddrinfo(const char* node, const char* service, const struct addrinfo* hints, 74 struct addrinfo** result, uint16_t netid) = 0; 75 virtual int32_t InterfaceSetMtu(const std::string &interfaceName, int mtu) = 0; 76 virtual int32_t InterfaceGetMtu(const std::string &interfaceName) = 0; 77 78 virtual int32_t RegisterNotifyCallback(sptr<INotifyCallback> &callback) = 0; 79 80 virtual int32_t NetworkAddRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 81 const std::string &nextHop) = 0; 82 virtual int32_t NetworkRemoveRoute(int32_t netId, const std::string &interfaceName, const std::string &destination, 83 const std::string &nextHop) = 0; 84 virtual int32_t NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) = 0; 85 virtual int32_t NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) = 0; 86 virtual int32_t NetworkSetDefault(int32_t netId) = 0; 87 virtual int32_t NetworkGetDefault() = 0; 88 virtual int32_t NetworkClearDefault() = 0; 89 virtual int32_t GetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname, 90 const std::string ¶meter, std::string &value) = 0; 91 virtual int32_t SetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname, 92 const std::string ¶meter, std::string &value) = 0; 93 virtual int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) = 0; 94 virtual int32_t InterfaceAddAddress(const std::string &interfaceName, const std::string &addrString, 95 int32_t prefixLength) = 0; 96 virtual int32_t InterfaceDelAddress(const std::string &interfaceName, const std::string &addrString, 97 int32_t prefixLength) = 0; 98 virtual int32_t NetworkAddInterface(int32_t netId, const std::string &iface) = 0; 99 virtual int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) = 0; 100 virtual int32_t NetworkDestroy(int32_t netId) = 0; 101 virtual int32_t GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel) = 0; 102 virtual int32_t InterfaceSetConfig(const InterfaceConfigurationParcel &cfg) = 0; 103 virtual int32_t InterfaceGetConfig(InterfaceConfigurationParcel &cfg) = 0; 104 virtual int32_t InterfaceGetList(std::vector<std::string> &ifaces) = 0; 105 virtual int32_t StartDhcpClient(const std::string &iface, bool bIpv6) = 0; 106 virtual int32_t StopDhcpClient(const std::string &iface, bool bIpv6) = 0; 107 virtual int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) = 0; 108 virtual int32_t StopDhcpService(const std::string &iface) = 0; 109 110 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetsysNative.INetsysService") 111 }; 112 } // namespace NetsysNative 113 } // namespace OHOS 114 #endif