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 #ifndef NETMANAGER_BASE_BPF_DEF_H 17 #define NETMANAGER_BASE_BPF_DEF_H 18 19 #include <linux/bpf.h> 20 21 static const int32_t APP_STATS_MAP_SIZE = 5000; 22 static const int32_t IFACE_STATS_MAP_SIZE = 1000; 23 static const int32_t IFACE_NAME_MAP_SIZE = 1000; 24 static const int32_t OH_SOCK_PERMISSION_MAP_SIZE = 1000; 25 static const int32_t BROKER_SOCK_PERMISSION_MAP_SIZE = 1000; 26 enum { IFNAME_SIZE = 32 }; 27 28 typedef struct { 29 enum bpf_map_type type; 30 __u32 key_size; 31 __u32 value_size; 32 __u32 max_entries; 33 __u32 map_flags; 34 __u32 inner_map_idx; 35 __u32 numa_node; 36 } bpf_map_def; 37 38 typedef struct { 39 __u32 uId; 40 __u32 ifIndex; 41 } stats_key; 42 43 typedef struct { 44 __u64 rxPackets; 45 __u64 rxBytes; 46 __u64 txPackets; 47 __u64 txBytes; 48 } stats_value; 49 50 typedef struct { 51 char name[IFNAME_SIZE]; 52 } iface_name; 53 54 // network stats begin 55 typedef __u64 iface_stats_key; 56 typedef stats_value iface_stats_value; 57 58 typedef __u64 app_uid_stats_key; 59 typedef stats_value app_uid_stats_value; 60 61 typedef stats_key app_uid_if_stats_key; 62 typedef stats_value app_uid_if_stats_value; 63 64 typedef __u64 socket_cookie_stats_key; 65 typedef stats_value app_cookie_stats_value; 66 // network stats end 67 68 // internet permission begin 69 typedef __u32 sock_permission_key; 70 typedef __u8 sock_permission_value; 71 // internet permission end 72 #endif /* NETMANAGER_BASE_BPF_DEF_H */ 73