Skip to content

Commit 1cada72

Browse files
committed
include port names in SDT probes (#99)
want USDT support for probes (#56)
1 parent d8c305a commit 1cada72

18 files changed

+874
-660
lines changed

dtrace/lib/common.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ typedef struct flow_id_sdt_arg {
1313
} flow_id_sdt_arg_t;
1414

1515
typedef struct rule_match_sdt_arg {
16+
char *port;
1617
char *layer;
1718
char *dir;
1819
flow_id_sdt_arg_t *flow;
1920
char *rule_type;
2021
} rule_match_sdt_arg_t;
2122

2223
typedef struct rule_no_match_sdt_arg {
24+
char *port;
2325
char *layer;
2426
char *dir;
2527
flow_id_sdt_arg_t *flow;

dtrace/opte-flow-expire.d

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "common.h"
99
#include <sys/inttypes.h>
1010

11-
#define HDR_FMT "%-12s %s\n"
11+
#define HDR_FMT "%-24s %-18s %s\n"
1212

1313
BEGIN {
1414
/*
@@ -19,16 +19,17 @@ BEGIN {
1919
protos[6] = "TCP";
2020
protos[17] = "UDP";
2121

22-
printf(HDR_FMT, "LAYER", "FLOW");
22+
printf(HDR_FMT, "PORT", "FT NAME", "FLOW");
2323
num = 0;
2424
}
2525

2626
sdt:opte::flow-expired {
27-
this->name = stringof(arg0);
28-
this->flow = (flow_id_sdt_arg_t *)arg1;
27+
this->port = stringof(arg0);
28+
this->name = stringof(arg1);
29+
this->flow = (flow_id_sdt_arg_t *)arg2;
2930

3031
if (num >= 10) {
31-
printf(HDR_FMT, "NAME", "FLOW");
32+
printf(HDR_FMT, "PORT", "FT NAME", "FLOW");
3233
num = 0;
3334
}
3435

@@ -41,13 +42,13 @@ sdt:opte::flow-expired {
4142

4243
sdt:opte::flow-expired /this->af == AF_INET/ {
4344
FLOW_FMT(this->s, this->flow);
44-
printf(HDR_FMT, this->name, this->s);
45+
printf(HDR_FMT, this->port, this->name, this->s);
4546
num++;
4647
}
4748

4849
sdt:opte::flow-expired /this->af == AF_INET6/ {
4950
FLOW_FMT6(this->s, this->flow);
50-
printf(HDR_FMT, this->name, this->s);
51+
printf(HDR_FMT, this->port, this->name, this->s);
5152
num++;
5253
}
5354

dtrace/opte-layer-process.d

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
#include "common.h"
1010

11-
#define HDR_FMT "%-3s %-12s %-43s %s\n"
11+
#define HDR_FMT "%-16s %-16s %-3s %-48s %s\n"
1212

1313
BEGIN {
1414
/*
@@ -20,18 +20,19 @@ BEGIN {
2020
protos[17] = "UDP";
2121
protos[255] = "XXX";
2222

23-
printf(HDR_FMT, "DIR", "NAME", "FLOW", "RES");
23+
printf(HDR_FMT, "PORT", "LAYER", "DIR", "FLOW", "RES");
2424
num = 0;
2525
}
2626

27-
sdt:opte::layer-process-return {
27+
layer-process-return {
2828
this->dir = stringof(arg0);
29-
this->name = stringof(arg1);
30-
this->flow = (flow_id_sdt_arg_t *)arg2;
31-
this->res = stringof(arg3);
29+
this->port = stringof(arg1);
30+
this->layer = stringof(arg2);
31+
this->flow = (flow_id_sdt_arg_t *)arg3;
32+
this->res = stringof(arg4);
3233

3334
if (num >= 10) {
34-
printf(HDR_FMT, "DIR", "NAME", "FLOW", "RES");
35+
printf(HDR_FMT, "PORT", "LAYER", "DIR", "FLOW", "RES");
3536
num = 0;
3637
}
3738

@@ -42,14 +43,14 @@ sdt:opte::layer-process-return {
4243
}
4344
}
4445

45-
sdt:opte::layer-process-return /this->af == AF_INET/ {
46+
layer-process-return /this->af == AF_INET/ {
4647
FLOW_FMT(this->s, this->flow);
47-
printf(HDR_FMT, this->dir, this->name, this->s, this->res);
48+
printf(HDR_FMT, this->port, this->layer, this->dir, this->s, this->res);
4849
num++;
4950
}
5051

51-
sdt:opte::layer-process-return /this->af == AF_INET6/ {
52+
layer-process-return /this->af == AF_INET6/ {
5253
FLOW_FMT6(this->s, this->flow);
53-
printf(HDR_FMT, this->dir, this->name, this->s, this->res);
54+
printf(HDR_FMT, this->port, this->layer, this->dir, this->s, this->res);
5455
num++;
5556
}

dtrace/opte-port-process.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
#include "common.h"
77

8-
#define HDR_FMT "%-3s %-12s %-43s %-18s %s\n"
9-
#define LINE_FMT "%-3s %-12s %-43s 0x%-16p %s\n"
8+
#define HDR_FMT "%-12s %-3s %-43s %-18s %s\n"
9+
#define LINE_FMT "%-12s %-3s %-43s 0x%-16p %s\n"
1010

1111
BEGIN {
1212
/*
@@ -18,7 +18,7 @@ BEGIN {
1818
protos[17] = "UDP";
1919
protos[255] = "XXX";
2020

21-
printf(HDR_FMT, "DIR", "NAME", "FLOW", "MBLK", "RESULT");
21+
printf(HDR_FMT, "NAME", "DIR", "FLOW", "MBLK", "RESULT");
2222
num = 0;
2323
}
2424

@@ -30,7 +30,7 @@ port-process-return {
3030
this->res = stringof(arg4);
3131

3232
if (num >= 10) {
33-
printf(HDR_FMT, "DIR", "NAME", "FLOW", "MBLK", "RESULT");
33+
printf(HDR_FMT, "NAME", "DIR", "FLOW", "MBLK", "RESULT");
3434
num = 0;
3535
}
3636

@@ -43,13 +43,13 @@ port-process-return {
4343

4444
port-process-return /this->af == AF_INET/ {
4545
FLOW_FMT(this->s, this->flow);
46-
printf(LINE_FMT, this->dir, this->name, this->s, this->mp, this->res);
46+
printf(LINE_FMT, this->name, this->dir, this->s, this->mp, this->res);
4747
num++;
4848
}
4949

5050
port-process-return /this->af == AF_INET6/ {
5151
FLOW_FMT6(this->s, this->flow);
52-
printf(LINE_FMT, this->dir, this->name, this->s, this->mp, this->res);
52+
printf(LINE_FMT, this->name, this->dir, this->s, this->mp, this->res);
5353
num++;
5454
}
5555

dtrace/opte-rule-match.d

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#include "common.h"
77

8-
#define HDR_FMT "%-6s %-3s %-12s %-43s %s\n"
8+
#define HDR_FMT "%-8s %-12s %-6s %-3s %-43s %s\n"
99

1010
BEGIN {
1111
/*
@@ -17,33 +17,35 @@ BEGIN {
1717
protos[17] = "UDP";
1818
protos[255] = "XXX";
1919

20-
printf(HDR_FMT, "MATCH", "DIR", "LAYER", "FLOW", "ACTION");
20+
printf(HDR_FMT, "PORT", "LAYER", "MATCH", "DIR", "FLOW", "ACTION");
2121
num = 0;
2222
}
2323

2424
rule-match {
2525
this->match = (rule_match_sdt_arg_t *)arg0;
26+
this->port = stringof(this->match->port);
27+
this->layer = stringof(this->match->layer);
2628
this->flow = this->match->flow;
2729
this->dir = stringof(this->match->dir);
28-
this->layer = stringof(this->match->layer);
2930
this->af = this->flow->af;
3031
num++;
3132

3233
if (num >= 10) {
33-
printf(HDR_FMT, "MATCH", "DIR", "LAYER", "FLOW", "ACTION");
34+
printf(HDR_FMT, "PORT", "LAYER", "MATCH", "DIR", "FLOW",
35+
"ACTION");
3436
num = 0;
3537
}
3638
}
3739

3840
rule-match /this->af == AF_INET/ {
3941
FLOW_FMT(this->s, this->flow);
40-
printf(HDR_FMT, "YES", this->dir, this->layer, this->s,
42+
printf(HDR_FMT, this->port, this->layer, "YES", this->dir, this->s,
4143
stringof(this->match->rule_type));
4244
}
4345

4446
rule-match /this->af == AF_INET6/ {
4547
FLOW_FMT6(this->s, this->flow);
46-
printf(HDR_FMT, "YES", this->dir, this->layer, this->s,
48+
printf(HDR_FMT, this->port, this->layer, "YES", this->dir, this->s,
4749
stringof(this->match->rule_type));
4850
}
4951

@@ -58,10 +60,12 @@ rule-no-match {
5860

5961
rule-no-match /this->af == AF_INET/ {
6062
FLOW_FMT(this->s, this->flow);
61-
printf(HDR_FMT, "NO", this->dir, this->layer, this->s, "--");
63+
printf(HDR_FMT, this->port, this->layer, "NO", this->dir, this->s,
64+
"--");
6265
}
6366

6467
rule-no-match /this->af == AF_INET6/ {
6568
FLOW_FMT6(this->s, this->flow);
66-
printf(HDR_FMT, "NO", this->dir, this->layer, this->s, "--");
69+
printf(HDR_FMT, this->port, this->layer, "NO", this->dir, this->s,
70+
"--");
6771
}

dtrace/opte-tcp-flow-state.d

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
*/
66
#include "common.h"
77

8-
#define FMT "%-16s %-16s %s\n"
8+
#define FMT "%-16s %-8s %-8s %s\n"
99

1010
BEGIN {
1111
/*
1212
* Use an associative array to stringify the protocol number.
1313
* It's always going to be TCP but we need this declared so
1414
* the FLOW_FMT macros work.
1515
*/
16-
protos[1]= "ICMP";
17-
protos[2] = "IGMP";
1816
protos[6] = "TCP";
19-
protos[17] = "UDP";
2017

2118
/*
2219
* Use an associative array to stringify the TCP state
@@ -32,21 +29,32 @@ BEGIN {
3229
tcp_states[7] = "FIN_WAIT_1";
3330
tcp_states[8] = "FIN_WAIT_2";
3431
tcp_states[9] = "TIME_WAIT";
32+
33+
printf(FMT, "PORT", "CURR", "NEW", "FLOW");
34+
num = 0;
3535
}
3636

3737
tcp-flow-state {
38-
this->flow = (flow_id_sdt_arg_t *)arg0;
38+
this->port = stringof(arg0);
39+
this->flow = (flow_id_sdt_arg_t *)arg1;
3940
this->af = this->flow->af;
40-
this->bstate = tcp_states[arg1];
41-
this->astate = tcp_states[arg2];
41+
this->curr = tcp_states[arg2];
42+
this->new = tcp_states[arg3];
43+
44+
if (num >= 10) {
45+
printf(FMT, "PORT", "CURR", "NEW", "FLOW");
46+
num = 0;
47+
}
48+
49+
num++;
4250
}
4351

4452
tcp-flow-state /this->af == AF_INET/ {
4553
FLOW_FMT(this->s, this->flow);
46-
printf(FMT, this->bstate, this->astate, this->s);
54+
printf(FMT, this->port, this->curr, this->new, this->s);
4755
}
4856

4957
tcp-flow-state /this->af == AF_INET6/ {
5058
FLOW_FMT6(this->s, this->flow);
51-
printf(FMT, this->bstate, this->astate, this->s);
59+
printf(FMT, this->port, this->curr, this->new, this->s);
5260
}

dtrace/usdt-opte-flow-expire.d

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Track flow expiration.
3+
*
4+
* dtrace -ZCqs ./usdt-opte-flow-expire.d
5+
*/
6+
#define HDR_FMT "%-24s %-18s %s\n"
7+
8+
BEGIN {
9+
printf(HDR_FMT, "PORT", "FT NAME", "FLOW");
10+
num = 0;
11+
}
12+
13+
flow-expired {
14+
this->port = copyinstr(arg0);
15+
this->layer = copyinstr(arg1);
16+
this->flow = copyinstr(arg2);
17+
18+
printf(HDR_FMT, this->port, this->layer, this->flow);
19+
}

dtrace/usdt-opte-layer-process.d

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Track layer processing.
3+
*
4+
* dtrace -ZCqs ./usdt-opte-layer-process.d
5+
*/
6+
#define HDR_FMT "%-16s %-16s %-3s %-48s %s\n"
7+
8+
BEGIN {
9+
printf(HDR_FMT, "PORT", "LAYER", "DIR", "FLOW", "RES");
10+
num = 0;
11+
}
12+
13+
layer-process-return {
14+
this->dir = json(copyinstr(arg0), "ok");
15+
this->port = copyinstr(arg1);
16+
this->layer = copyinstr(arg2);
17+
this->flow = copyinstr(arg3);
18+
this->res = copyinstr(arg4);
19+
num++;
20+
21+
printf(HDR_FMT, this->port, this->layer, this->dir, this->flow,
22+
this->res);
23+
24+
if (num >= 10) {
25+
printf(HDR_FMT, "PORT", "LAYER", "DIR", "FLOW", "RES");
26+
num = 0;
27+
}
28+
}

dtrace/usdt-opte-rule-match.d

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,40 @@
44
*
55
* dtrace -ZCqs ./usdt-opte-rule-match.d
66
*/
7-
#define HDR_FMT "%-6s %-3s %-12s %-43s %s\n"
7+
#define HDR_FMT "%-8s %-12s %-6s %-3s %-43s %s\n"
88

99
BEGIN {
10-
printf(HDR_FMT, "MATCH", "DIR", "LAYER", "FLOW", "ACTION");
10+
printf(HDR_FMT, "PORT", "LAYER", "MATCH", "DIR", "FLOW", "ACTION");
1111
num = 0;
1212
}
1313

1414
rule-match {
15-
this->layer = copyinstr(arg0);
16-
this->dir = json(copyinstr(arg1), "ok");
17-
this->flow = copyinstr(arg2);
18-
this->action = copyinstr(arg3);
19-
num++;
20-
21-
if (num >= 10) {
22-
printf(HDR_FMT, "MATCH", "DIR", "LAYER", "FLOW", "ACTION");
23-
num = 0;
24-
}
15+
this->port = copyinstr(arg0);
16+
this->layer = copyinstr(arg1);
17+
this->dir = json(copyinstr(arg2), "ok");
18+
this->flow = copyinstr(arg3);
19+
this->action = copyinstr(arg4);
2520

26-
printf(HDR_FMT, "YES", this->dir, this->layer, this->flow,
21+
printf(HDR_FMT, this->port, this->layer, "YES", this->dir, this->flow,
2722
this->action);
2823
}
2924

3025
rule-no-match {
31-
this->layer = copyinstr(arg0);
32-
this->dir = json(copyinstr(arg1), "ok");
33-
this->flow = copyinstr(arg2);
34-
num++;
26+
this->port = copyinstr(arg0);
27+
this->layer = copyinstr(arg1);
28+
this->dir = json(copyinstr(arg2), "ok");
29+
this->flow = copyinstr(arg3);
30+
31+
printf(HDR_FMT, this->port, this->layer, "NO", this->dir, this->flow,
32+
"--");
33+
}
3534

35+
rule-match,rule-no-match {
3636
if (num >= 10) {
37-
printf(HDR_FMT, "MATCH", "DIR", "LAYER", "FLOW", "ACTION");
37+
printf(HDR_FMT, "PORT", "LAYER", "MATCH", "DIR", "FLOW",
38+
"ACTION");
3839
num = 0;
3940
}
4041

41-
printf(HDR_FMT, "NO", this->dir, this->layer, this->flow, "--");
42+
num++;
4243
}

0 commit comments

Comments
 (0)