summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2018-04-25 11:24:58 -0700
committerChenbo Feng <fengc@google.com>2018-05-01 19:35:17 -0700
commit155d4dd0c429b66441c76268ff3152b1037b2b4c (patch)
treeabef8a273de49dcabc5a84f59ff4a8062a866b30
parentb9c3fdb02c283724d8809771ab45096229fa8561 (diff)
downloadnetd-155d4dd0c429b66441c76268ff3152b1037b2b4c.tar.gz
Do not count dropped packet on egress side
In the configuration of firewall controller and bandwidth controller, we count inbound packets even if we later drop them, but we count outbound packets only if we don't drop them. The eBPF program should be consistent with that configuration. Also, we should always use the socket uid to do the owner match. Bug: 77990419 Bug: 30950746 Test: bpf program load when device boot Change-Id: If5a6ca21fb76001d28190c5996a14391cbfff0a2 Merged-In: If5a6ca21fb76001d28190c5996a14391cbfff0a2 (cherry picked from aosp commit ec17ee7181ee2cc945b77f19fc8de14a745a8993)
-rw-r--r--bpfloader/bpf_kern.h12
-rw-r--r--bpfloader/bpf_kern.obin6232 -> 6264 bytes
2 files changed, 10 insertions, 2 deletions
diff --git a/bpfloader/bpf_kern.h b/bpfloader/bpf_kern.h
index 8fb6046f..975f4655 100644
--- a/bpfloader/bpf_kern.h
+++ b/bpfloader/bpf_kern.h
@@ -150,6 +150,14 @@ static inline int bpf_owner_match(struct __sk_buff* skb, uint32_t uid) {
}
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);
+ if ((direction == BPF_EGRESS) && (match == BPF_DROP)) {
+ // If an outbound packet is going to be dropped, we do not count that
+ // traffic.
+ return match;
+ }
+
uint64_t cookie = get_socket_cookie(skb);
struct uid_tag* utag = find_map_entry(COOKIE_TAG_MAP, &cookie);
uint32_t uid, tag;
@@ -157,7 +165,7 @@ static __always_inline inline int bpf_traffic_account(struct __sk_buff* skb, int
uid = utag->uid;
tag = utag->tag;
} else {
- uid = get_socket_uid(skb);
+ uid = sock_uid;
tag = 0;
}
@@ -174,5 +182,5 @@ static __always_inline inline int bpf_traffic_account(struct __sk_buff* skb, int
key.tag = 0;
bpf_update_stats(skb, UID_STATS_MAP, direction, &key);
- return bpf_owner_match(skb, uid);
+ return match;
}
diff --git a/bpfloader/bpf_kern.o b/bpfloader/bpf_kern.o
index 32d8e876..7b60514e 100644
--- a/bpfloader/bpf_kern.o
+++ b/bpfloader/bpf_kern.o
Binary files differ