Skip to content

Commit 1cefd6d

Browse files
committed
tcp: support non-libctf environments
Commit 0fa93b3 ("tcp: new provider") and commit c08a5fc ("tcp provider: support tcp:::accept-established in absence of skb") both introduced code that uses ctf_func_type_info() without a pre-processor conditional to also support the case when libctf is not present on the system. When libctf is not present, it is assumed that the system is quite old and therefore is running an older kernel. Use of libdtrace-ctf (which has been deprecated in favour of libctf) on systems with recent kernels is not supported and may lead to unexpected results. Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com> Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
1 parent 3236319 commit 1cefd6d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

libdtrace/dt_prov_tcp.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,19 @@ static int populate(dtrace_hdl_t *dtp)
160160
*/
161161
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
162162
{
163-
dtrace_hdl_t *dtp = pcb->pcb_hdl;
164163
dt_irlist_t *dlp = &pcb->pcb_ir;
165164
dt_probe_t *prp = pcb->pcb_probe;
166165
dt_probe_t *uprp = pcb->pcb_parent_probe;
167166
int direction, have_iphdr;
168167
int skarg = 0, skbarg = 1, tcparg = 0;
169-
int skarg_maybe_null, have_skb = 1;
168+
int skarg_maybe_null = 0, have_skb = 1;
170169
int skstate = 0;
170+
#ifdef HAVE_LIBCTF
171+
dtrace_hdl_t *dtp = pcb->pcb_hdl;
171172
dtrace_typeinfo_t sym;
172173
ctf_funcinfo_t fi;
173174
int rc;
175+
#endif
174176

175177
/*
176178
* We construct the tcp::: probe arguments as follows:
@@ -262,6 +264,7 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
262264

263265
if (strcmp(prp->desc->prb, "accept-established") == 0) {
264266
direction = NET_PROBE_INBOUND;
267+
#ifdef HAVE_LIBCTF
265268
have_iphdr = 1;
266269
/* on older (5.4) kernels, tcp_init_transfer() only has 2
267270
* args, i.e. no struct skb * third argument.
@@ -274,11 +277,14 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
274277
fi.ctc_argc > 2) {
275278
/* skb in arg2 not arg1 */
276279
skbarg = 2;
277-
skarg_maybe_null = 0;
278280
} else {
279281
have_skb = 0;
280282
have_iphdr = 0;
281283
}
284+
#else
285+
have_skb = 0;
286+
have_iphdr = 0;
287+
#endif
282288
/* ensure arg1 is BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB */
283289
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_6, BPF_REG_7, DMST_ARG(1)));
284290
emit(dlp, BPF_BRANCH_IMM(BPF_JNE, BPF_REG_6,
@@ -291,20 +297,17 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
291297
if (strcmp(uprp->desc->fun, "tcp_v4_send_reset") == 0 ||
292298
strcmp(uprp->desc->fun, "tcp_v6_send_reset") == 0)
293299
skarg_maybe_null = 1;
294-
else
295-
skarg_maybe_null = 0;
296300
} else if (strcmp(prp->desc->prb, "connect-established") == 0) {
297301
direction = NET_PROBE_INBOUND;
298302
have_iphdr = 1;
299-
skarg_maybe_null = 0;
300303
} else if (strcmp(prp->desc->prb, "connect-refused") == 0) {
301304
direction = NET_PROBE_INBOUND;
302305
have_iphdr = 1;
303-
skarg_maybe_null = 0;
304306
skstate = BPF_TCP_SYN_SENT;
305307
} else {
306308
direction = NET_PROBE_OUTBOUND;
307309
if (strcmp(uprp->desc->fun, "ip_send_unicast_reply") == 0) {
310+
#ifdef HAVE_LIBCTF
308311
/* Newer kernels pass the original socket as second
309312
* arg to ip_send_unicast_reply(); if that function
310313
* has an extra (> 9) argument we know we have to
@@ -329,6 +332,11 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
329332
skbarg = 1;
330333
tcparg = 5;
331334
}
335+
#else
336+
skarg = 0;
337+
skbarg = 1;
338+
tcparg = 5;
339+
#endif
332340
have_iphdr = 1;
333341
tcparg = 6;
334342
skarg_maybe_null = 1;
@@ -340,11 +348,8 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
340348
} else if (strcmp(prp->desc->prb, "connect-request") == 0) {
341349
skstate = BPF_TCP_SYN_SENT;
342350
have_iphdr = 0;
343-
skarg_maybe_null = 0;
344-
} else {
351+
} else
345352
have_iphdr = 0;
346-
skarg_maybe_null = 0;
347-
}
348353
}
349354

350355
/* first save sk to args[3]; this avoids overwriting it when we

0 commit comments

Comments
 (0)