netd bpf: fix an error discovered by the next compiler update.
flags is uint16_t, but only the low byte is initialized and used.
Before the next compiler update, clang optimizes flags to uint8_t,
and thus the kernel doesn't complain.
But in the next compiler update, clang no longer tries to optimize
flags to uint8_t, because of https://reviews.llvm.org/D73997.
Then the kernel fails to load netd.o. Because netd.o tries to read the
upper byte of flags which was never initialized.
Bug: 149839606
Test: build and load netd.o successfully.
Change-Id: Ife6e2d7d8c3738e33841989a7f1ee7401bc3c963
Merged-In: Ife6e2d7d8c3738e33841989a7f1ee7401bc3c963
diff --git a/bpf_progs/netd.c b/bpf_progs/netd.c
index 91ab78f..d59e880 100644
--- a/bpf_progs/netd.c
+++ b/bpf_progs/netd.c
@@ -138,7 +138,7 @@
if (skb->protocol == htons(ETH_P_IP)) {
offset = IP_PROTO_OFF;
uint8_t proto, ihl;
- uint16_t flag;
+ uint8_t flag;
ret = bpf_skb_load_bytes(skb, offset, &proto, 1);
if (!ret) {
if (proto == IPPROTO_ESP) {
@@ -160,7 +160,7 @@
if (proto == IPPROTO_ESP) {
return true;
} else if (proto == IPPROTO_TCP) {
- uint16_t flag;
+ uint8_t flag;
ret = bpf_skb_load_bytes(skb, sizeof(struct ipv6hdr) + TCP_FLAG_OFF, &flag, 1);
if (ret == 0 && (flag >> RST_OFFSET & 1)) {
return true;