summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2018-12-04 16:54:56 -0800
committerChenbo Feng <fengc@google.com>2019-01-22 18:40:10 -0800
commit9cd8f14ed0ed01675b18b4880fcf465782b5ffd7 (patch)
tree4a915f9367da16c5199bf3171e1a32716297d108 /progs
parentd3ec87101702727f74f3d7c09d7f8cb038b16252 (diff)
downloadbpf-9cd8f14ed0ed01675b18b4880fcf465782b5ffd7.tar.gz
Do not take cumulative network stats anymore
Use two maps to record the details of network stats and swap and clean up after system server pulls the stats. The kernel program checks the bpf map currently enabled before updating the stats and updates on the corresponding map. Remove the TAG_STATS_MAP since we don't need to worry about uid stats overflow problem. All the stats can be stored in the same map until system server scrapes the stats and clean it up. Bug: 79171384 Test: dumpsys netd trafficcontroller CtsUsageStatsTestCases Change-Id: Ic79e382f51bf21eee78c4cac5a8a97edaf3654cd
Diffstat (limited to 'progs')
-rw-r--r--progs/netd.h35
1 files changed, 25 insertions, 10 deletions
diff --git a/progs/netd.h b/progs/netd.h
index 6b2d103..ff97753 100644
--- a/progs/netd.h
+++ b/progs/netd.h
@@ -110,21 +110,21 @@ struct bpf_map_def SEC("maps") app_uid_stats_map = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct stats_value),
- .max_entries = UID_STATS_MAP_SIZE,
+ .max_entries = APP_STATS_MAP_SIZE,
};
-struct bpf_map_def SEC("maps") uid_stats_map = {
+struct bpf_map_def SEC("maps") stats_map_A = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(struct stats_key),
.value_size = sizeof(struct stats_value),
- .max_entries = UID_STATS_MAP_SIZE,
+ .max_entries = STATS_MAP_SIZE,
};
-struct bpf_map_def SEC("maps") tag_stats_map = {
+struct bpf_map_def SEC("maps") stats_map_B = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(struct stats_key),
.value_size = sizeof(struct stats_value),
- .max_entries = TAG_STATS_MAP_SIZE,
+ .max_entries = STATS_MAP_SIZE,
};
struct bpf_map_def SEC("maps") iface_stats_map = {
@@ -218,8 +218,8 @@ static inline bool skip_owner_match(struct __sk_buff* skb) {
return false;
}
-static __always_inline BpfConfig getConfig() {
- uint32_t mapSettingKey = CONFIGURATION_KEY;
+static __always_inline BpfConfig getConfig(uint32_t configKey) {
+ uint32_t mapSettingKey = configKey;
BpfConfig* config = find_map_entry(&configuration_map, &mapSettingKey);
if (!config) {
// Couldn't read configuration entry. Assume everything is disabled.
@@ -233,7 +233,7 @@ static inline int bpf_owner_match(struct __sk_buff* skb, uint32_t uid) {
if ((uid <= MAX_SYSTEM_UID) && (uid >= MIN_SYSTEM_UID)) return BPF_PASS;
- BpfConfig enabledRules = getConfig();
+ BpfConfig enabledRules = getConfig(UID_RULES_CONFIGURATION_KEY);
if (!enabledRules) {
return BPF_PASS;
}
@@ -252,6 +252,15 @@ static inline int bpf_owner_match(struct __sk_buff* skb, uint32_t uid) {
return BPF_PASS;
}
+static __always_inline inline void update_stats_with_config(struct __sk_buff* skb, int direction,
+ void* key, uint8_t selectedMap) {
+ if (selectedMap == SELECT_MAP_A) {
+ bpf_update_stats(skb, &stats_map_A, direction, key);
+ } else if (selectedMap == SELECT_MAP_B) {
+ bpf_update_stats(skb, &stats_map_B, direction, key);
+ }
+}
+
static __always_inline inline int bpf_traffic_account(struct __sk_buff* skb, int direction) {
uint32_t sock_uid = get_socket_uid(skb);
int match = bpf_owner_match(skb, sock_uid);
@@ -277,12 +286,18 @@ static __always_inline inline int bpf_traffic_account(struct __sk_buff* skb, int
uint8_t* counterSet = find_map_entry(&uid_counterset_map, &uid);
if (counterSet) key.counterSet = (uint32_t)*counterSet;
+ uint32_t mapSettingKey = CURRENT_STATS_MAP_CONFIGURATION_KEY;
+ uint8_t* selectedMap = find_map_entry(&configuration_map, &mapSettingKey);
+ if (!selectedMap) {
+ return match;
+ }
+
if (tag) {
- bpf_update_stats(skb, &tag_stats_map, direction, &key);
+ update_stats_with_config(skb, direction, &key, *selectedMap);
}
key.tag = 0;
- bpf_update_stats(skb, &uid_stats_map, direction, &key);
+ update_stats_with_config(skb, direction, &key, *selectedMap);
bpf_update_stats(skb, &app_uid_stats_map, direction, &uid);
return match;
}