Add dummy tethering offload eBPF map
Preparation for eBPF tethering offload
Test:
build and check that the eBPF objects exist in sysfs:
$ adb shell ls /sys/fs/bpf | grep offload
map_offload_tether_ingress_map
prog_offload_schedcls_ingress_tether
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Hungming Chen <nuccachen@google.com>
Change-Id: I47004fde644a697bd9c2979603c7bbc9eadd807f
diff --git a/bpf_progs/Android.bp b/bpf_progs/Android.bp
index 7b1f015..8ce924b 100644
--- a/bpf_progs/Android.bp
+++ b/bpf_progs/Android.bp
@@ -47,3 +47,16 @@
"system/netd/libnetdutils/include",
],
}
+
+bpf {
+ name: "offload.o",
+ srcs: ["offload.c"],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ include_dirs: [
+ "system/netd/libnetdbpf/include",
+ "system/netd/libnetdutils/include",
+ ],
+}
diff --git a/bpf_progs/offload.c b/bpf_progs/offload.c
new file mode 100644
index 0000000..95765ff
--- /dev/null
+++ b/bpf_progs/offload.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <linux/if.h>
+#include <linux/pkt_cls.h>
+
+#include "bpf_helpers.h"
+#include "netdbpf/bpf_shared.h"
+
+DEFINE_BPF_MAP(tether_ingress_map, HASH, TetherIngressKey, TetherIngressValue, 64)
+
+SEC("schedcls/ingress/tether_ether")
+int sched_cls_ingress_tether_ether(struct __sk_buff* skb) {
+ // TODO
+ return TC_ACT_OK;
+}
+
+SEC("schedcls/ingress/tether_rawip")
+int sched_cls_ingress_tether_rawip(struct __sk_buff* skb) {
+ // TODO
+ return TC_ACT_OK;
+}
+
+char _license[] SEC("license") = "Apache 2.0";
diff --git a/libnetdbpf/include/netdbpf/bpf_shared.h b/libnetdbpf/include/netdbpf/bpf_shared.h
index 3813e62..a5e7a27 100644
--- a/libnetdbpf/include/netdbpf/bpf_shared.h
+++ b/libnetdbpf/include/netdbpf/bpf_shared.h
@@ -17,6 +17,7 @@
#ifndef NETDBPF_BPF_SHARED_H
#define NETDBPF_BPF_SHARED_H
+#include <linux/if_ether.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <netdutils/UidConstants.h>
@@ -185,4 +186,25 @@
bool oifIsEthernet; // Whether the output interface requires ethernet header
} ClatEgressValue;
+#define TETHER_INGRESS_PROG_RAWIP_NAME "prog_offload_schedcls_ingress_tether_rawip"
+#define TETHER_INGRESS_PROG_ETHER_NAME "prog_offload_schedcls_ingress_tether_ether"
+
+#define TETHER_INGRESS_PROG_RAWIP_PATH BPF_PATH "/" TETHER_INGRESS_PROG_RAWIP_NAME
+#define TETHER_INGRESS_PROG_ETHER_PATH BPF_PATH "/" TETHER_INGRESS_PROG_ETHER_NAME
+
+#define TETHER_INGRESS_MAP_PATH BPF_PATH "/map_offload_tether_ingress_map"
+
+typedef struct {
+ uint32_t iif; // The input interface index
+ struct in6_addr neigh6; // The destination IPv6 address
+} TetherIngressKey;
+
+typedef struct {
+ uint32_t oif; // The output interface to redirect to
+ // For now tethering offload only needs to support downstreams that use 6-byte MAC addresses,
+ // because all downstream types that are currently supported (WiFi, USB, Bluetooth and
+ // Ethernet) have 6-byte MAC addresses.
+ struct ethhdr macHeader; // includes dst/src mac and ethertype
+} TetherIngressValue;
+
#endif // NETDBPF_BPF_SHARED_H