Commit 08ed4036 authored by Brendan Gregg's avatar Brendan Gregg Committed by GitHub

Merge pull request #1303 from pchaigno/remove-bpf_probe_reads

Remove unnecessary bpf_probe_reads
parents db8353b2 25212eea
...@@ -69,7 +69,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog) ...@@ -69,7 +69,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog)
{ {
// cast types. Intermediate cast not needed, kept for readability // cast types. Intermediate cast not needed, kept for readability
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = (struct inet_sock *)sk;
// Built event for userland // Built event for userland
struct listen_evt_t evt = { struct listen_evt_t evt = {
...@@ -91,7 +91,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog) ...@@ -91,7 +91,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog)
##FILTER_PID## ##FILTER_PID##
// Get port // Get port
bpf_probe_read(&evt.lport, sizeof(u16), &(inet->inet_sport)); evt.lport = inet->inet_sport;
evt.lport = ntohs(evt.lport); evt.lport = ntohs(evt.lport);
// Get network namespace id, if kernel supports it // Get network namespace id, if kernel supports it
...@@ -105,7 +105,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog) ...@@ -105,7 +105,7 @@ int kprobe__inet_listen(struct pt_regs *ctx, struct socket *sock, int backlog)
// Get IP // Get IP
if (family == AF_INET) { if (family == AF_INET) {
bpf_probe_read(evt.laddr, sizeof(u32), &(inet->inet_rcv_saddr)); evt.laddr[0] = inet->inet_rcv_saddr;
evt.laddr[0] = be32_to_cpu(evt.laddr[0]); evt.laddr[0] = be32_to_cpu(evt.laddr[0]);
} else if (family == AF_INET6) { } else if (family == AF_INET6) {
bpf_probe_read(evt.laddr, sizeof(evt.laddr), bpf_probe_read(evt.laddr, sizeof(evt.laddr),
......
...@@ -93,14 +93,14 @@ int trace_connect(struct pt_regs *ctx, struct sock *sk) ...@@ -93,14 +93,14 @@ int trace_connect(struct pt_regs *ctx, struct sock *sk)
// are fast path and processed elsewhere, and leftovers are processed by // are fast path and processed elsewhere, and leftovers are processed by
// tcp_rcv_state_process(). We can trace this for handshake completion. // tcp_rcv_state_process(). We can trace this for handshake completion.
// This should all be switched to static tracepoints when available. // This should all be switched to static tracepoints when available.
int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *sk) int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *skp)
{ {
// will be in TCP_SYN_SENT for handshake // will be in TCP_SYN_SENT for handshake
if (sk->__sk_common.skc_state != TCP_SYN_SENT) if (skp->__sk_common.skc_state != TCP_SYN_SENT)
return 0; return 0;
// check start and calculate delta // check start and calculate delta
struct info_t *infop = start.lookup(&sk); struct info_t *infop = start.lookup(&skp);
if (infop == 0) { if (infop == 0) {
return 0; // missed entry or filtered return 0; // missed entry or filtered
} }
...@@ -109,19 +109,15 @@ int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *sk) ...@@ -109,19 +109,15 @@ int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *sk)
// pull in details // pull in details
u16 family = 0, dport = 0; u16 family = 0, dport = 0;
struct sock *skp = NULL; family = skp->__sk_common.skc_family;
bpf_probe_read(&skp, sizeof(skp), &sk); dport = skp->__sk_common.skc_dport;
bpf_probe_read(&family, sizeof(family), &skp->__sk_common.skc_family);
bpf_probe_read(&dport, sizeof(dport), &skp->__sk_common.skc_dport);
// emit to appropriate data path // emit to appropriate data path
if (family == AF_INET) { if (family == AF_INET) {
struct ipv4_data_t data4 = {.pid = infop->pid, .ip = 4}; struct ipv4_data_t data4 = {.pid = infop->pid, .ip = 4};
data4.ts_us = now / 1000; data4.ts_us = now / 1000;
bpf_probe_read(&data4.saddr, sizeof(u32), data4.saddr = skp->__sk_common.skc_rcv_saddr;
&skp->__sk_common.skc_rcv_saddr); data4.daddr = skp->__sk_common.skc_daddr;
bpf_probe_read(&data4.daddr, sizeof(u32),
&skp->__sk_common.skc_daddr);
data4.dport = ntohs(dport); data4.dport = ntohs(dport);
data4.delta_us = (now - ts) / 1000; data4.delta_us = (now - ts) / 1000;
__builtin_memcpy(&data4.task, infop->task, sizeof(data4.task)); __builtin_memcpy(&data4.task, infop->task, sizeof(data4.task));
...@@ -131,16 +127,16 @@ int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *sk) ...@@ -131,16 +127,16 @@ int trace_tcp_rcv_state_process(struct pt_regs *ctx, struct sock *sk)
struct ipv6_data_t data6 = {.pid = infop->pid, .ip = 6}; struct ipv6_data_t data6 = {.pid = infop->pid, .ip = 6};
data6.ts_us = now / 1000; data6.ts_us = now / 1000;
bpf_probe_read(&data6.saddr, sizeof(data6.saddr), bpf_probe_read(&data6.saddr, sizeof(data6.saddr),
&skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32); skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
bpf_probe_read(&data6.daddr, sizeof(data6.daddr), bpf_probe_read(&data6.daddr, sizeof(data6.daddr),
&skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32); skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
data6.dport = ntohs(dport); data6.dport = ntohs(dport);
data6.delta_us = (now - ts) / 1000; data6.delta_us = (now - ts) / 1000;
__builtin_memcpy(&data6.task, infop->task, sizeof(data6.task)); __builtin_memcpy(&data6.task, infop->task, sizeof(data6.task));
ipv6_events.perf_submit(ctx, &data6, sizeof(data6)); ipv6_events.perf_submit(ctx, &data6, sizeof(data6));
} }
start.delete(&sk); start.delete(&skp);
return 0; return 0;
} }
......
...@@ -70,28 +70,22 @@ struct ipv6_data_t { ...@@ -70,28 +70,22 @@ struct ipv6_data_t {
}; };
BPF_PERF_OUTPUT(ipv6_events); BPF_PERF_OUTPUT(ipv6_events);
static int trace_event(struct pt_regs *ctx, struct sock *sk, int type) static int trace_event(struct pt_regs *ctx, struct sock *skp, int type)
{ {
if (sk == NULL) if (skp == NULL)
return 0; return 0;
u32 pid = bpf_get_current_pid_tgid(); u32 pid = bpf_get_current_pid_tgid();
struct sock *skp = NULL;
bpf_probe_read(&skp, sizeof(skp), &sk);
// pull in details // pull in details
u16 family = 0, lport = 0, dport = 0; u16 family = skp->__sk_common.skc_family;
char state = 0; u16 lport = skp->__sk_common.skc_num;
bpf_probe_read(&family, sizeof(family), &skp->__sk_common.skc_family); u16 dport = skp->__sk_common.skc_dport;
bpf_probe_read(&lport, sizeof(lport), &skp->__sk_common.skc_num); char state = skp->__sk_common.skc_state;
bpf_probe_read(&dport, sizeof(dport), &skp->__sk_common.skc_dport);
bpf_probe_read(&state, sizeof(state), (void *)&skp->__sk_common.skc_state);
if (family == AF_INET) { if (family == AF_INET) {
struct ipv4_data_t data4 = {.pid = pid, .ip = 4, .type = type}; struct ipv4_data_t data4 = {.pid = pid, .ip = 4, .type = type};
bpf_probe_read(&data4.saddr, sizeof(u32), data4.saddr = skp->__sk_common.skc_rcv_saddr;
&skp->__sk_common.skc_rcv_saddr); data4.daddr = skp->__sk_common.skc_daddr;
bpf_probe_read(&data4.daddr, sizeof(u32),
&skp->__sk_common.skc_daddr);
// lport is host order // lport is host order
data4.lport = lport; data4.lport = lport;
data4.dport = ntohs(dport); data4.dport = ntohs(dport);
...@@ -101,9 +95,9 @@ static int trace_event(struct pt_regs *ctx, struct sock *sk, int type) ...@@ -101,9 +95,9 @@ static int trace_event(struct pt_regs *ctx, struct sock *sk, int type)
} else if (family == AF_INET6) { } else if (family == AF_INET6) {
struct ipv6_data_t data6 = {.pid = pid, .ip = 6, .type = type}; struct ipv6_data_t data6 = {.pid = pid, .ip = 6, .type = type};
bpf_probe_read(&data6.saddr, sizeof(data6.saddr), bpf_probe_read(&data6.saddr, sizeof(data6.saddr),
&skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32); skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
bpf_probe_read(&data6.daddr, sizeof(data6.daddr), bpf_probe_read(&data6.daddr, sizeof(data6.daddr),
&skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32); skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
// lport is host order // lport is host order
data6.lport = lport; data6.lport = lport;
data6.dport = ntohs(dport); data6.dport = ntohs(dport);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment