From 3c94994650bc642c9200f4aeb176b88109b7fd80 Mon Sep 17 00:00:00 2001 From: Hungming Chen Date: Wed, 5 May 2021 21:18:39 +0800 Subject: [PATCH] Fix attaching program failure on kernel 5.10 Attach BPF program may be failed with the netlink error message "Invalid argument". Per debug kernel trace, it is failed in comparing the kind name in tc_new_tfilter. Log: 05-05 19:44:42.329 1073 2332 2332 W tc_new_tfilter: Specified filter kind does not match existing one Test: enable usb tethering and check the follows $ adb shell tc filter show dev ingress filter protocol ipv6 pref 1 bpf chain 0 filter protocol ipv6 pref 1 bpf chain 0 handle 0x1 prog_offload_schedcls_tether_upstream6_ether:[*fsobj] direct-action not_in_hw id 3 tag 94ca9b12972fdea8 filter protocol ip pref 2 bpf chain 0 filter protocol ip pref 2 bpf chain 0 handle 0x1 prog_offload_schedcls_tether_upstream4_ether:[*fsobj] direct-action not_in_hw id 9 tag 992aa9bfd0503457 filter protocol ipv6 pref 1 bpf chain 0 filter protocol ipv6 pref 1 bpf chain 0 handle 0x1 prog_offload_schedcls_tether_downstream6_rawip:[*fsobj] direct-action not_in_hw id 4 tag 7fb60e556b8f3be7 filter protocol ip pref 2 bpf chain 0 filter protocol ip pref 2 bpf chain 0 handle 0x1 prog_offload_schedcls_tether_downstream4_rawip:[*fsobj] direct-action not_in_hw id 6 tag e41426095404fb64 Change-Id: I471a2e34c626a3737cbd2754e4d1b3000bcf6ba6 --- .../com_android_networkstack_tethering_BpfUtils.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tethering/jni/com_android_networkstack_tethering_BpfUtils.cpp b/Tethering/jni/com_android_networkstack_tethering_BpfUtils.cpp index 308dfb9c98..1611f9d514 100644 --- a/Tethering/jni/com_android_networkstack_tethering_BpfUtils.cpp +++ b/Tethering/jni/com_android_networkstack_tethering_BpfUtils.cpp @@ -36,6 +36,9 @@ // The maximum length of TCA_BPF_NAME. Sync from net/sched/cls_bpf.c. #define CLS_BPF_NAME_LEN 256 +// Classifier name. See cls_bpf_ops in net/sched/cls_bpf.c. +#define CLS_BPF_KIND_NAME "bpf" + namespace android { // Sync from system/netd/server/NetlinkCommands.h const uint16_t NETLINK_REQUEST_FLAGS = NLM_F_REQUEST | NLM_F_ACK; @@ -205,9 +208,9 @@ static void com_android_networkstack_tethering_BpfUtils_tcFilterAddDevBpf( tcmsg t; struct { nlattr attr; - // The maximum classifier name length is defined as IFNAMSIZ. - // See tcf_proto_ops in include/net/sch_generic.h. - char str[NLMSG_ALIGN(IFNAMSIZ)]; + // The maximum classifier name length is defined in + // tcf_proto_ops in include/net/sch_generic.h. + char str[NLMSG_ALIGN(sizeof(CLS_BPF_KIND_NAME))]; } kind; struct { nlattr attr; @@ -248,8 +251,7 @@ static void com_android_networkstack_tethering_BpfUtils_tcFilterAddDevBpf( .nla_len = sizeof(req.kind), .nla_type = TCA_KIND, }, - // Classifier name. See cls_bpf_ops in net/sched/cls_bpf.c. - .str = "bpf", + .str = CLS_BPF_KIND_NAME, }, .options = {