Skip to content

Commit 1cadbe0

Browse files
committed
pping: Make parsed protocols configurable
Add command-line flags for each protocol that pping should attempt to parse and report RTTs for (currently -T/--tcp and -C/--icmp). If no protocol is specified assume TCP. To clarify this, output a message before start on how ePPing has been configured (stating output format, tracked protocols and which interface to run on). Additionally, as the ppviz format was only designed for TCP it does not have any field for which protocol an entry belongs to. Therefore, emit a warning in case the user selects the ppviz format with anything other than TCP. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
1 parent bd6ded5 commit 1cadbe0

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

pping/pping.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ static const struct option long_options[] = {
104104
{ "cleanup-interval", required_argument, NULL, 'c' }, // Map cleaning interval in s, 0 to disable
105105
{ "format", required_argument, NULL, 'F' }, // Which format to output in (standard/json/ppviz)
106106
{ "ingress-hook", required_argument, NULL, 'I' }, // Use tc or XDP as ingress hook
107+
{ "tcp", no_argument, NULL, 'T' }, // Calculate and report RTTs for TCP traffic (with TCP timestamps)
108+
{ "icmp", no_argument, NULL, 'C' }, // Calculate and report RTTs for ICMP echo-reply traffic
107109
{ 0, 0, NULL, 0 }
108110
};
109111

@@ -169,8 +171,10 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config)
169171

170172
config->ifindex = 0;
171173
config->force = false;
174+
config->bpf_config.track_tcp = false;
175+
config->bpf_config.track_icmp = false;
172176

173-
while ((opt = getopt_long(argc, argv, "hfi:r:c:F:I:", long_options,
177+
while ((opt = getopt_long(argc, argv, "hfTCi:r:c:F:I:", long_options,
174178
NULL)) != -1) {
175179
switch (opt) {
176180
case 'i':
@@ -235,6 +239,12 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config)
235239
config->force = true;
236240
config->xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
237241
break;
242+
case 'T':
243+
config->bpf_config.track_tcp = true;
244+
break;
245+
case 'C':
246+
config->bpf_config.track_icmp = true;
247+
break;
238248
case 'h':
239249
printf("HELP:\n");
240250
print_usage(argv);
@@ -254,6 +264,23 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config)
254264
return 0;
255265
}
256266

267+
const char *tracked_protocols_to_str(struct pping_config *config)
268+
{
269+
bool tcp = config->bpf_config.track_tcp;
270+
bool icmp = config->bpf_config.track_icmp;
271+
return tcp && icmp ? "TCP, ICMP" : tcp ? "TCP" : "ICMP";
272+
}
273+
274+
const char *output_format_to_str(enum PPING_OUTPUT_FORMAT format)
275+
{
276+
switch (format) {
277+
case PPING_OUTPUT_STANDARD: return "standard";
278+
case PPING_OUTPUT_JSON: return "json";
279+
case PPING_OUTPUT_PPVIZ: return "ppviz";
280+
default: return "unkown format";
281+
}
282+
}
283+
257284
void abort_program(int sig)
258285
{
259286
keep_running = 0;
@@ -985,6 +1012,14 @@ int main(int argc, char *argv[])
9851012
return EXIT_FAILURE;
9861013
}
9871014

1015+
if (!config.bpf_config.track_tcp && !config.bpf_config.track_icmp)
1016+
config.bpf_config.track_tcp = true;
1017+
1018+
if (config.bpf_config.track_icmp &&
1019+
config.output_format == PPING_OUTPUT_PPVIZ)
1020+
fprintf(stderr,
1021+
"Warning: ppviz format mainly intended for TCP traffic, but may now include ICMP traffic as well\n");
1022+
9881023
switch (config.output_format) {
9891024
case PPING_OUTPUT_STANDARD:
9901025
print_event_func = print_event_standard;
@@ -997,6 +1032,10 @@ int main(int argc, char *argv[])
9971032
break;
9981033
}
9991034

1035+
fprintf(stderr, "Starting ePPing in %s mode tracking %s on %s\n",
1036+
output_format_to_str(config.output_format),
1037+
tracked_protocols_to_str(&config), config.ifname);
1038+
10001039
err = load_attach_bpfprogs(&obj, &config);
10011040
if (err) {
10021041
fprintf(stderr,

pping/pping.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ enum __attribute__((__packed__)) flow_event_source {
3434

3535
struct bpf_config {
3636
__u64 rate_limit;
37+
bool track_tcp;
38+
bool track_icmp;
39+
__u8 reserved[6];
3740
};
3841

3942
/*

pping/pping_kern.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,15 @@ static int parse_packet_identifier(struct parsing_context *ctx,
286286
}
287287

288288
// Parse identifer from suitable protocol
289-
if (p_id->flow.proto == IPPROTO_TCP)
289+
if (config.track_tcp && p_id->flow.proto == IPPROTO_TCP)
290290
err = parse_tcp_identifier(ctx, &saddr->port, &daddr->port, fei,
291291
&p_id->identifier);
292-
else if (p_id->flow.proto == IPPROTO_ICMPV6 &&
292+
else if (config.track_icmp && p_id->flow.proto == IPPROTO_ICMPV6 &&
293293
p_id->flow.ipv == AF_INET6)
294294
err = parse_icmp6_identifier(ctx, &saddr->port, &daddr->port,
295295
fei, &p_id->identifier);
296-
else if (p_id->flow.proto == IPPROTO_ICMP && p_id->flow.ipv == AF_INET)
296+
else if (config.track_icmp && p_id->flow.proto == IPPROTO_ICMP &&
297+
p_id->flow.ipv == AF_INET)
297298
err = parse_icmp_identifier(ctx, &saddr->port, &daddr->port,
298299
fei, &p_id->identifier);
299300
else

0 commit comments

Comments
 (0)