1 /*
2 * Copyright (c) 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 #include "domain_executer.h"
17
18 #include <iostream>
19 #include <sstream>
20 #include <utility>
21
22 #include "edm_log.h"
23
24 namespace OHOS {
25 namespace EDM {
26 namespace IPTABLES {
27
28 const std::string SELECT_TABLE_OPTION = "-t ";
29 const std::string JUMP_OPTION = " -j ";
30 const std::string INSERT_OPTION = " -I ";
31
DomainExecuter(std::string actualChainName,const std::string & chainName)32 DomainExecuter::DomainExecuter(std::string actualChainName, const std::string& chainName) : IExecuter(chainName),
33 actualChainName_(std::move(actualChainName))
34 {
35 }
36
37
Init()38 ErrCode DomainExecuter::Init()
39 {
40 std::ostringstream oss;
41 oss << SELECT_TABLE_OPTION << tableName_ << INSERT_OPTION << actualChainName_ << " -p udp --dport 53"
42 << JUMP_OPTION << chainName_;
43 std::string result;
44 ErrCode ret = ExecuterUtils::GetInstance()->Execute(oss.str(), result);
45 if (ret != ERR_OK) {
46 EDMLOGE("DomainExecuter:Init error.ret:%{public}d", ret);
47 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
48 }
49 return ERR_OK;
50 }
51 } // namespace IPTABLES
52 } // namespace EDM
53 } // namespace OHOS