Skip to content

Commit

Permalink
tcp tools: finalize data type conversion (iovisor#1961)
Browse files Browse the repository at this point in the history
Finish the conversion started with commit 36ce112.

Minor tweaks to make the tools consistent within themselves.
  • Loading branch information
myllynen authored and yonghong-song committed Sep 11, 2018
1 parent 6b208d9 commit bfbf17e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
1 change: 0 additions & 1 deletion tools/tcpaccept.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
// separate data structs for ipv4 and ipv6
struct ipv4_data_t {
// XXX: switch some to u32's when supported
u64 ts_us;
u32 pid;
u32 saddr;
Expand Down
1 change: 0 additions & 1 deletion tools/tcpconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
// separate data structs for ipv4 and ipv6
struct ipv4_data_t {
// XXX: switch some to u32's when supported
u64 ts_us;
u32 pid;
u32 saddr;
Expand Down
1 change: 0 additions & 1 deletion tools/tcpconnlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def positive_float(val):
// separate data structs for ipv4 and ipv6
struct ipv4_data_t {
// XXX: switch some to u32's when supported
u64 ts_us;
u32 pid;
u32 saddr;
Expand Down
4 changes: 3 additions & 1 deletion tools/tcpdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
ipv4_events.perf_submit(ctx, &data4, sizeof(data4));
} else if (family == AF_INET6) {
struct ipv6_data_t data6 = {.pid = pid, .ip = 6};
struct ipv6_data_t data6 = {};
data6.pid = pid;
data6.ip = 6;
bpf_probe_read(&data6.saddr, sizeof(data6.saddr),
sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
bpf_probe_read(&data6.daddr, sizeof(data6.daddr),
Expand Down
13 changes: 8 additions & 5 deletions tools/tcplife.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
// separate data structs for ipv4 and ipv6
struct ipv4_data_t {
// XXX: switch some to u32's when supported
u64 ts_us;
u32 pid;
u32 saddr;
Expand Down Expand Up @@ -213,8 +212,10 @@
ipv4_events.perf_submit(ctx, &data4, sizeof(data4));
} else /* 6 */ {
struct ipv6_data_t data6 = {.span_us = delta_us,
.rx_b = rx_b, .tx_b = tx_b};
struct ipv6_data_t data6 = {};
data6.span_us = delta_us;
data6.rx_b = rx_b;
data6.tx_b = tx_b;
data6.ts_us = bpf_ktime_get_ns() / 1000;
bpf_probe_read(&data6.saddr, sizeof(data6.saddr),
sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
Expand Down Expand Up @@ -337,8 +338,10 @@
ipv4_events.perf_submit(args, &data4, sizeof(data4));
} else /* 6 */ {
struct ipv6_data_t data6 = {.span_us = delta_us,
.rx_b = rx_b, .tx_b = tx_b};
struct ipv6_data_t data6 = {};
data6.span_us = delta_us;
data6.rx_b = rx_b;
data6.tx_b = tx_b;
data6.ts_us = bpf_ktime_get_ns() / 1000;
__builtin_memcpy(&data6.saddr, args->saddr_v6, sizeof(data6.saddr));
__builtin_memcpy(&data6.daddr, args->daddr_v6, sizeof(data6.daddr));
Expand Down
6 changes: 4 additions & 2 deletions tools/tcpretrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
// separate data structs for ipv4 and ipv6
struct ipv4_data_t {
// XXX: switch some to u32's when supported
u32 pid;
u64 ip;
u32 saddr;
Expand Down Expand Up @@ -165,7 +164,10 @@
flow_key.lport = lport;
flow_key.dport = ntohs(dport);""",
'trace' : """
struct ipv6_data_t data6 = {.pid = pid, .ip = 6, .type = type};
struct ipv6_data_t data6 = {};
data6.pid = pid;
data6.ip = 6;
data6.type = type;
bpf_probe_read(&data6.saddr, sizeof(data6.saddr),
skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
bpf_probe_read(&data6.daddr, sizeof(data6.daddr),
Expand Down
6 changes: 4 additions & 2 deletions tools/tcpstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
if (args->family == AF_INET) {
struct ipv4_data_t data4 = {
.span_us = delta_us,
.oldstate = args->oldstate, .newstate = args->newstate};
.oldstate = args->oldstate,
.newstate = args->newstate };
data4.skaddr = (u64)args->skaddr;
data4.ts_us = bpf_ktime_get_ns() / 1000;
__builtin_memcpy(&data4.saddr, args->saddr, sizeof(data4.saddr));
Expand All @@ -141,7 +142,8 @@
} else /* 6 */ {
struct ipv6_data_t data6 = {
.span_us = delta_us,
.oldstate = args->oldstate, .newstate = args->newstate};
.oldstate = args->oldstate,
.newstate = args->newstate };
data6.skaddr = (u64)args->skaddr;
data6.ts_us = bpf_ktime_get_ns() / 1000;
__builtin_memcpy(&data6.saddr, args->saddr_v6, sizeof(data6.saddr));
Expand Down
30 changes: 12 additions & 18 deletions tools/tcptop.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ def range_check(string):
struct ipv6_key_t {
u32 pid;
// workaround until unsigned __int128 support:
u64 saddr0;
u64 saddr1;
u64 daddr0;
u64 daddr1;
unsigned __int128 saddr;
unsigned __int128 daddr;
u16 lport;
u16 dport;
};
Expand All @@ -116,16 +113,14 @@ def range_check(string):
} else if (family == AF_INET6) {
struct ipv6_key_t ipv6_key = {.pid = pid};
ipv6_key.saddr0 = *(u64 *)&sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32[0];
ipv6_key.saddr1 = *(u64 *)&sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32[2];
ipv6_key.daddr0 = *(u64 *)&sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32[0];
ipv6_key.daddr1 = *(u64 *)&sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32[2];
__builtin_memcpy(&ipv6_key.saddr,
sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32, sizeof(ipv6_key.saddr));
__builtin_memcpy(&ipv6_key.daddr,
sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32, sizeof(ipv6_key.daddr));
ipv6_key.lport = sk->__sk_common.skc_num;
dport = sk->__sk_common.skc_dport;
ipv6_key.dport = ntohs(dport);
ipv6_send_bytes.increment(ipv6_key, size);
}
// else drop
Expand Down Expand Up @@ -157,13 +152,12 @@ def range_check(string):
ipv4_key.dport = ntohs(dport);
ipv4_recv_bytes.increment(ipv4_key, copied);
} else if (family == AF_INET6) {
struct ipv6_key_t ipv6_key = {.pid = pid};
ipv6_key.saddr0 = *(u64 *)&sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32[0];
ipv6_key.saddr1 = *(u64 *)&sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32[2];
ipv6_key.daddr0 = *(u64 *)&sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32[0];
ipv6_key.daddr1 = *(u64 *)&sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32[2];
__builtin_memcpy(&ipv6_key.saddr,
sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32, sizeof(ipv6_key.saddr));
__builtin_memcpy(&ipv6_key.daddr,
sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32, sizeof(ipv6_key.daddr));
ipv6_key.lport = sk->__sk_common.skc_num;
dport = sk->__sk_common.skc_dport;
ipv6_key.dport = ntohs(dport);
Expand Down Expand Up @@ -204,9 +198,9 @@ def get_ipv4_session_key(k):

def get_ipv6_session_key(k):
return TCPSessionKey(pid=k.pid,
laddr=inet_ntop(AF_INET6, pack("QQ", k.saddr0, k.saddr1)),
laddr=inet_ntop(AF_INET6, k.saddr),
lport=k.lport,
daddr=inet_ntop(AF_INET6, pack("QQ", k.daddr0, k.daddr1)),
daddr=inet_ntop(AF_INET6, k.daddr),
dport=k.dport)

# initialize BPF
Expand Down

0 comments on commit bfbf17e

Please sign in to comment.