• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 NET_FIREWALL_RULE_NATIVE_HELPER_H
17 #define NET_FIREWALL_RULE_NATIVE_HELPER_H
18 
19 #include <string>
20 #include <mutex>
21 
22 #include "netfirewall_common.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 class NetFirewallRuleNativeHelper {
27 public:
28     static NetFirewallRuleNativeHelper &GetInstance();
29     NetFirewallRuleNativeHelper();
30     ~NetFirewallRuleNativeHelper();
31 
32     /**
33      * Set firewall rules to bpf maps
34      *
35      * @param ruleList list of NetFirewallIpRule
36      * @return 0 if success or -1 if an error occurred
37      */
38     int32_t SetFirewallIpRules(const std::vector<sptr<NetFirewallIpRule>> &ruleList);
39 
40     /**
41      * Set firewall default action
42      *
43      * @param userId user id
44      * @param inDefault  Default action of NetFirewallRuleDirection:RULE_IN
45      * @param outDefault Default action of NetFirewallRuleDirection:RULE_OUT
46      * @return 0 if success or -1 if an error occurred
47      */
48     int32_t SetFirewallDefaultAction(int32_t userId, FirewallRuleAction inDefault, FirewallRuleAction outDefault);
49 
50     /* *
51      * Clear firewall rules by type
52      *
53      * @param type ip, dns, domain, all
54      * @return 0 if success or -1 if an error occurred
55      */
56     int32_t ClearFirewallRules(NetFirewallRuleType type);
57 
58     /**
59      * Set the Firewall DNS rules
60      *
61      * @param ruleList firewall rules
62      * @return 0 if success or-1 if an error occurred
63      */
64     int32_t SetFirewallDnsRules(const std::vector<sptr<NetFirewallDnsRule>> &ruleList);
65 
66     /**
67      * Set the Firewall domain rules
68      *
69      * @param  ruleList firewall rules
70      * @return 0 if success or-1 if an error occurred
71      */
72     int32_t SetFirewallDomainRules(const std::vector<sptr<NetFirewallDomainRule>> &ruleList);
73 
74     /**
75      * Set the Firewall current user id
76      *
77      * @param  userId firewall user id
78      * @return 0 if success or-1 if an error occurred
79      */
80     int32_t SetCurrentUserId(int32_t userId);
81 
82 private:
83     int32_t SetFirewallRulesInner(NetFirewallRuleType type, const std::vector<sptr<NetFirewallBaseRule>> &ruleList,
84                                   uint32_t pageSize);
85     std::mutex callNetSysController_;
86 };
87 } // namespace NetManagerStandard
88 } // namespace OHOS
89 #endif /* NET_FIREWALL_RULE_NATIVE_HELPER_H */
90