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 16 #ifndef INCLUDE_FWMARK_CLIENT_H 17 #define INCLUDE_FWMARK_CLIENT_H 18 19 #include <cstdint> 20 21 #include "fwmark_command.h" 22 23 namespace OHOS { 24 namespace nmd { 25 class FwmarkClient { 26 public: 27 FwmarkClient(); 28 ~FwmarkClient(); 29 30 /** 31 * Binds {@code fd} to the network designated by {@code netId}. 32 * 33 * @param socketFd 34 * @param netId 35 * 36 * @return Return the return value of the netsys interface call 37 */ 38 int32_t BindSocket(int32_t fd, uint32_t netId); 39 40 /** 41 * Protect {@code socketFd} to the network bypass VPN. 42 * 43 * @param socketFd 44 */ 45 int32_t ProtectFromVpn(int32_t socketFd); 46 47 private: 48 // Sends |data| to the fwmark network, along with |fd| as ancillary data using cmsg(3). 49 int32_t Send(FwmarkCommand *data, int32_t fd); 50 int32_t HandleError(int32_t ret, int32_t errorCode, int32_t sock); 51 }; 52 #ifdef __cplusplus 53 extern "C" int32_t BindSocket(int32_t fd, uint32_t netId); 54 #endif 55 } // namespace nmd 56 } // namespace OHOS 57 #endif // INCLUDE_FWMARK_CLIENT_H 58