Skip to content

Commit

Permalink
Merge pull request #95 from OpenCloudOS/dev
Browse files Browse the repository at this point in the history
fixes: check if trampoline supported for arm
  • Loading branch information
menglongdong authored Mar 20, 2024
2 parents 88f85a5 + 00ccc38 commit 5d8f699
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
76 changes: 76 additions & 0 deletions shared/bpf/vmlinux_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -123632,6 +123632,82 @@ struct tcp_info {
__u32 tcpi_snd_wnd;
};

enum skb_drop_reason {
SKB_NOT_DROPPED_YET = 0,
SKB_DROP_REASON_NOT_SPECIFIED = 1,
SKB_DROP_REASON_NO_SOCKET = 2,
SKB_DROP_REASON_PKT_TOO_SMALL = 3,
SKB_DROP_REASON_TCP_CSUM = 4,
SKB_DROP_REASON_SOCKET_FILTER = 5,
SKB_DROP_REASON_UDP_CSUM = 6,
SKB_DROP_REASON_NETFILTER_DROP = 7,
SKB_DROP_REASON_OTHERHOST = 8,
SKB_DROP_REASON_IP_CSUM = 9,
SKB_DROP_REASON_IP_INHDR = 10,
SKB_DROP_REASON_IP_RPFILTER = 11,
SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST = 12,
SKB_DROP_REASON_XFRM_POLICY = 13,
SKB_DROP_REASON_IP_NOPROTO = 14,
SKB_DROP_REASON_SOCKET_RCVBUFF = 15,
SKB_DROP_REASON_PROTO_MEM = 16,
SKB_DROP_REASON_TCP_MD5NOTFOUND = 17,
SKB_DROP_REASON_TCP_MD5UNEXPECTED = 18,
SKB_DROP_REASON_TCP_MD5FAILURE = 19,
SKB_DROP_REASON_SOCKET_BACKLOG = 20,
SKB_DROP_REASON_TCP_FLAGS = 21,
SKB_DROP_REASON_TCP_ZEROWINDOW = 22,
SKB_DROP_REASON_TCP_OLD_DATA = 23,
SKB_DROP_REASON_TCP_OVERWINDOW = 24,
SKB_DROP_REASON_TCP_OFOMERGE = 25,
SKB_DROP_REASON_TCP_RFC7323_PAWS = 26,
SKB_DROP_REASON_TCP_INVALID_SEQUENCE = 27,
SKB_DROP_REASON_TCP_RESET = 28,
SKB_DROP_REASON_TCP_INVALID_SYN = 29,
SKB_DROP_REASON_TCP_CLOSE = 30,
SKB_DROP_REASON_TCP_FASTOPEN = 31,
SKB_DROP_REASON_TCP_OLD_ACK = 32,
SKB_DROP_REASON_TCP_TOO_OLD_ACK = 33,
SKB_DROP_REASON_TCP_ACK_UNSENT_DATA = 34,
SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE = 35,
SKB_DROP_REASON_TCP_OFO_DROP = 36,
SKB_DROP_REASON_IP_OUTNOROUTES = 37,
SKB_DROP_REASON_BPF_CGROUP_EGRESS = 38,
SKB_DROP_REASON_IPV6DISABLED = 39,
SKB_DROP_REASON_NEIGH_CREATEFAIL = 40,
SKB_DROP_REASON_NEIGH_FAILED = 41,
SKB_DROP_REASON_NEIGH_QUEUEFULL = 42,
SKB_DROP_REASON_NEIGH_DEAD = 43,
SKB_DROP_REASON_TC_EGRESS = 44,
SKB_DROP_REASON_QDISC_DROP = 45,
SKB_DROP_REASON_CPU_BACKLOG = 46,
SKB_DROP_REASON_XDP = 47,
SKB_DROP_REASON_TC_INGRESS = 48,
SKB_DROP_REASON_UNHANDLED_PROTO = 49,
SKB_DROP_REASON_SKB_CSUM = 50,
SKB_DROP_REASON_SKB_GSO_SEG = 51,
SKB_DROP_REASON_SKB_UCOPY_FAULT = 52,
SKB_DROP_REASON_DEV_HDR = 53,
SKB_DROP_REASON_DEV_READY = 54,
SKB_DROP_REASON_FULL_RING = 55,
SKB_DROP_REASON_NOMEM = 56,
SKB_DROP_REASON_HDR_TRUNC = 57,
SKB_DROP_REASON_TAP_FILTER = 58,
SKB_DROP_REASON_TAP_TXFILTER = 59,
SKB_DROP_REASON_ICMP_CSUM = 60,
SKB_DROP_REASON_INVALID_PROTO = 61,
SKB_DROP_REASON_IP_INADDRERRORS = 62,
SKB_DROP_REASON_IP_INNOROUTES = 63,
SKB_DROP_REASON_PKT_TOO_BIG = 64,
SKB_DROP_REASON_SOCKET_DESTROYED = 65,
SKB_DROP_REASON_TCP_PAWSACTIVEREJECTED = 66,
SKB_DROP_REASON_TCP_LINGER = 67,
SKB_DROP_REASON_LISTENOVERFLOWS = 68,
SKB_DROP_REASON_TCP_REQQFULLDROP = 69,
SKB_DROP_REASON_TIMEWAIT = 70,
SKB_DROP_REASON_LSM = 71,
SKB_DROP_REASON_MAX = 72,
};

enum {
TCP_NLA_PAD = 0,
TCP_NLA_BUSY = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/nettrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int main(int argc, char *argv[])
goto err;

if (trace_bpf_load_and_attach()) {
pr_err("failed to load kprobe-based bpf\n");
pr_err("failed to load bpf\n");
goto err;
}

Expand Down
27 changes: 25 additions & 2 deletions src/trace_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#include "nettrace.h"
#include "analysis.h"

/* check whether trampoline is supported by current arch */
static bool tracing_arch_supported()
{
return simple_exec("cat /proc/kallsyms | "
"grep arch_prepare_bpf_trampoline | "
"grep T") == 0;
}

static bool tracing_trace_supported()
{
#ifdef COMPAT_MODE
Expand All @@ -20,6 +28,11 @@ static bool tracing_trace_supported()
if (!libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_TRACING, NULL))
goto failed;

if (!tracing_arch_supported()) {
pr_warn("trampoline is not supported, skip TRACING\n");
goto failed;
}

return true;
failed:
pr_verb("TRACING is not supported, trying others\n");
Expand Down Expand Up @@ -62,7 +75,7 @@ static void tracing_trace_attach_manual(char *prog_name, char *func)
bpf_program__set_attach_target(prog, 0, func);
}

static int tracing_trace_attach()
static void tracing_adjust_target()
{
char kret_name[128];
trace_t *trace;
Expand All @@ -79,6 +92,10 @@ static int tracing_trace_attach()
sprintf(kret_name, "ret%s", trace->prog);
tracing_trace_attach_manual(kret_name, trace->name);
}
}

static int tracing_trace_attach()
{
return tracing__attach(skel);
}

Expand Down Expand Up @@ -165,7 +182,13 @@ static int tracing_trace_load()
tracing_load_rules();
tracing_check_args();

if (trace_pre_load() || tracing__load(skel)) {
if (trace_pre_load()) {
pr_err("failed to prepare load\n");
goto err;
}

tracing_adjust_target();
if (tracing__load(skel)) {
pr_err("failed to load tracing-based eBPF\n");
goto err;
}
Expand Down

0 comments on commit 5d8f699

Please sign in to comment.