1# Copyright (c) 2022-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//foundation/communication/netmanager_base/netmanager_base_config.gni")
16
17ohos_bpf("netsys") {
18  sources = [ "src/netsys.c" ]
19
20  include_dirs = [ "include" ]
21
22  if (netmanager_base_enable_feature_net_firewall) {
23    defines = [
24      "FEATURE_NET_FIREWALL_ENABLE",
25      "NET_FIREWALL_DEBUG=0",
26      "NET_FIREWALL_DEBUG_TUPLE=0",
27    ]
28  }
29
30  subsystem_name = "communication"
31  part_name = "netmanager_base"
32}
33
34ohos_shared_library("netsys_bpf_utils") {
35  sanitize = {
36    cfi = true
37    cfi_cross_dso = true
38    boundary_sanitize = true
39    ubsan = true
40    debug = false
41  }
42
43  branch_protector_ret = "pac_ret"
44
45  sources = [
46    "$NETSTATSMANAGER_INNERKITS_SOURCE_DIR/src/net_stats_info.cpp",
47    "src/bpf_loader.cpp",
48    "src/bpf_ring_buffer.cpp",
49    "src/bpf_stats.cpp",
50  ]
51
52  include_dirs = [
53    "include",
54    "$NETMANAGER_BASE_ROOT/interfaces/innerkits/include",
55    "$NETMANAGER_BASE_ROOT/interfaces/innerkits/netmanagernative/include",
56    "$NETMANAGER_BASE_ROOT/interfaces/innerkits/netstatsclient/include",
57    "$NETMANAGER_BASE_ROOT/utils/common_utils/include",
58    "$NETMANAGER_BASE_ROOT/utils/log/include",
59    "$NETPOLICYMANAGER_SOURCE_DIR/include",
60  ]
61
62  cflags = [
63    "-fstack-protector-strong",
64    "-D_FORTIFY_SOURCE=2",
65    "-O2",
66  ]
67
68  cflags_cc = [
69    "-fstack-protector-strong",
70    "-D_FORTIFY_SOURCE=2",
71    "-O2",
72  ]
73
74  defines = [
75    "NETMGRNATIVE_LOG_TAG = \"NetSysBpf\"",
76    "LOG_DOMAIN = 0xD0015B0",
77  ]
78
79  external_deps = [
80    "c_utils:utils",
81    "elfio:elfio",
82    "ffrt:libffrt",
83    "hilog:libhilog",
84    "ipc:ipc_core",
85    "libbpf:libbpf",
86  ]
87  use_exceptions = true
88  deps = [ "$INNERKITS_ROOT/netpolicyclient:net_policy_manager_if" ]
89
90  if (netmanager_base_enable_feature_net_firewall) {
91    public_configs = [ "$NETMANAGER_BASE_ROOT/resource:coverage_flags" ]
92    sources += [
93      "src/bitmap_manager.cpp",
94      "src/bpf_netfirewall.cpp",
95    ]
96
97    defines += [ "FEATURE_NET_FIREWALL_ENABLE" ]
98
99    deps += [ "$INNERKITS_ROOT/netmanagernative:net_native_parcel" ]
100
101    external_deps += [
102      "ipc:ipc_core",
103      "safwk:system_ability_fwk",
104      "samgr:samgr_proxy",
105    ]
106  }
107
108  innerapi_tags = [ "platformsdk_indirect" ]
109  part_name = "netmanager_base"
110  subsystem_name = "communication"
111}
112