diff options
author | 2023-07-25 08:00:57 -0400 | |
---|---|---|
committer | 2023-07-25 08:00:57 -0400 | |
commit | 97d6993f35c0cc1434c8dccc4bad49c37b84a655 (patch) | |
tree | 0b89f5e714fdee694fed70a4921beab0f9db186c /src/fnettrace/main.c | |
parent | Merge branch 'master' of ssh://github.com/netblue30/firejail (diff) | |
download | firejail-97d6993f35c0cc1434c8dccc4bad49c37b84a655.tar.gz firejail-97d6993f35c0cc1434c8dccc4bad49c37b84a655.tar.zst firejail-97d6993f35c0cc1434c8dccc4bad49c37b84a655.zip |
cleanup
Diffstat (limited to 'src/fnettrace/main.c')
-rw-r--r-- | src/fnettrace/main.c | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/src/fnettrace/main.c b/src/fnettrace/main.c index 54ef54314..22da429af 100644 --- a/src/fnettrace/main.c +++ b/src/fnettrace/main.c | |||
@@ -294,23 +294,23 @@ typedef struct port_type_t { | |||
294 | char *service; | 294 | char *service; |
295 | } PortType; | 295 | } PortType; |
296 | static PortType ports[] = { | 296 | static PortType ports[] = { |
297 | {20, "(FTP)"}, | 297 | {20, "FTP"}, |
298 | {21, "(FTP)"}, | 298 | {21, "FTP"}, |
299 | {22, "(SSH)"}, | 299 | {22, "SSH"}, |
300 | {23, "(telnet)"}, | 300 | {23, "telnet"}, |
301 | {25, "(SMTP)"}, | 301 | {25, "SMTP"}, |
302 | {43, "(WHOIS)"}, | 302 | {43, "WHOIS"}, |
303 | {67, "(DHCP)"}, | 303 | {67, "DHCP"}, |
304 | {68, "(DHCP)"}, | 304 | {68, "DHCP"}, |
305 | {69, "(TFTP)"}, | 305 | {69, "TFTP"}, |
306 | {80, "(HTTP)"}, | 306 | {80, "HTTP"}, |
307 | {109, "(POP2)"}, | 307 | {109, "POP2"}, |
308 | {110, "(POP3)"}, | 308 | {110, "POP3"}, |
309 | {113, "(IRC)"}, | 309 | {113, "IRC"}, |
310 | {123, "(NTP)"}, | 310 | {123, "NTP"}, |
311 | {161, "(SNMP)"}, | 311 | {161, "SNMP"}, |
312 | {162, "(SNMP)"}, | 312 | {162, "SNMP"}, |
313 | {194, "(IRC)"}, | 313 | {194, "IRC"}, |
314 | {0, NULL}, | 314 | {0, NULL}, |
315 | }; | 315 | }; |
316 | 316 | ||
@@ -318,27 +318,27 @@ static PortType ports[] = { | |||
318 | static inline const char *common_port(uint16_t port) { | 318 | static inline const char *common_port(uint16_t port) { |
319 | if (port >= 6660 && port <= 10162) { | 319 | if (port >= 6660 && port <= 10162) { |
320 | if (port >= 6660 && port <= 6669) | 320 | if (port >= 6660 && port <= 6669) |
321 | return "(IRC)"; | 321 | return "IRC"; |
322 | else if (port == 6679) | 322 | else if (port == 6679) |
323 | return "(IRC)"; | 323 | return "IRC"; |
324 | else if (port == 6771) | 324 | else if (port == 6771) |
325 | return "(BitTorrent)"; | 325 | return "BitTorrent"; |
326 | else if (port >= 6881 && port <= 6999) | 326 | else if (port >= 6881 && port <= 6999) |
327 | return "(BitTorrent)"; | 327 | return "BitTorrent"; |
328 | else if (port == 9001) | 328 | else if (port == 9001) |
329 | return "(Tor)"; | 329 | return "Tor"; |
330 | else if (port == 9030) | 330 | else if (port == 9030) |
331 | return "(Tor)"; | 331 | return "Tor"; |
332 | else if (port == 9050) | 332 | else if (port == 9050) |
333 | return "(Tor)"; | 333 | return "Tor"; |
334 | else if (port == 9051) | 334 | else if (port == 9051) |
335 | return "(Tor)"; | 335 | return "Tor"; |
336 | else if (port == 9150) | 336 | else if (port == 9150) |
337 | return "(Tor)"; | 337 | return "Tor"; |
338 | else if (port == 10161) | 338 | else if (port == 10161) |
339 | return "(secure SNMP)"; | 339 | return "secure SNMP"; |
340 | else if (port == 10162) | 340 | else if (port == 10162) |
341 | return "(secure SNMP)"; | 341 | return "secure SNMP"; |
342 | return NULL; | 342 | return NULL; |
343 | } | 343 | } |
344 | 344 | ||
@@ -388,7 +388,7 @@ static void hnode_print(unsigned bw) { | |||
388 | else | 388 | else |
389 | sprintf(stats, "%u KB/s ", bw / (1024 * DISPLAY_INTERVAL)); | 389 | sprintf(stats, "%u KB/s ", bw / (1024 * DISPLAY_INTERVAL)); |
390 | // int len = snprintf(line, LINE_MAX, "%32s geoip %d, IP database %d\n", stats, geoip_calls, radix_nodes); | 390 | // int len = snprintf(line, LINE_MAX, "%32s geoip %d, IP database %d\n", stats, geoip_calls, radix_nodes); |
391 | int len = snprintf(line, LINE_MAX, "%32s address:port (protocol) network (packets)\n", stats); | 391 | int len = snprintf(line, LINE_MAX, "%32s address:port (protocol) network\n", stats); |
392 | adjust_line(line, len, cols); | 392 | adjust_line(line, len, cols); |
393 | printf("%s", line); | 393 | printf("%s", line); |
394 | 394 | ||
@@ -422,59 +422,57 @@ static void hnode_print(unsigned bw) { | |||
422 | 422 | ||
423 | const char *protocol = NULL; | 423 | const char *protocol = NULL; |
424 | if (ptr->port_src == 443 && ptr->protocol == 0x06) { // TCP | 424 | if (ptr->port_src == 443 && ptr->protocol == 0x06) { // TCP |
425 | protocol = "(TLS)"; | 425 | protocol = "TLS"; |
426 | stats_tls += ptr->pkts; | 426 | stats_tls += ptr->pkts; |
427 | if (strstr(ptr->rnode->name, "DNS")) { | ||
428 | protocol = "DoH"; | ||
429 | stats_dns_doh += ptr->pkts; | ||
430 | } | ||
431 | |||
427 | } | 432 | } |
428 | else if (ptr->port_src == 443 && ptr->protocol == 0x11) { // UDP | 433 | else if (ptr->port_src == 443 && ptr->protocol == 0x11) { // UDP |
429 | protocol = "(QUIC)"; | 434 | protocol = "QUIC"; |
430 | stats_quic += ptr->pkts; | 435 | stats_quic += ptr->pkts; |
436 | if (strstr(ptr->rnode->name, "DNS")) { | ||
437 | protocol = "DoQ"; | ||
438 | stats_dns_doq += ptr->pkts; | ||
439 | } | ||
431 | } | 440 | } |
432 | else if (ptr->port_src == 53) { | 441 | else if (ptr->port_src == 53) { |
442 | protocol = "DNS"; | ||
433 | stats_dns += ptr->pkts; | 443 | stats_dns += ptr->pkts; |
434 | if (ptr->protocol == 0x06) | ||
435 | protocol = "(TCP/DNS)"; | ||
436 | else if (ptr->protocol == 0x11) | ||
437 | protocol = "(UDP/DNS)"; | ||
438 | else | ||
439 | protocol = NULL; | ||
440 | } | 444 | } |
441 | else if (ptr->port_src == 853) { | 445 | else if (ptr->port_src == 853) { |
442 | if (ptr->protocol == 0x06) { | 446 | if (ptr->protocol == 0x06) { |
443 | protocol = "(DoT)"; | 447 | protocol = "DoT"; |
444 | stats_dns_dot += ptr->pkts; | 448 | stats_dns_dot += ptr->pkts; |
445 | } | 449 | } |
446 | else if (ptr->protocol == 0x11) { | 450 | else if (ptr->protocol == 0x11) { |
447 | protocol = "(DoQ)"; | 451 | protocol = "DoQ"; |
448 | stats_dns_doq += ptr->pkts; | 452 | stats_dns_doq += ptr->pkts; |
449 | } | 453 | } |
450 | else | 454 | else |
451 | protocol = NULL; | 455 | protocol = NULL; |
452 | } | 456 | } |
453 | else if ((protocol = common_port(ptr->port_src)) != NULL) { | 457 | else if ((protocol = common_port(ptr->port_src)) != NULL) { |
454 | if (strcmp(protocol, "(HTTP)") == 0) | 458 | if (strcmp(protocol, "HTTP") == 0) |
455 | stats_http += ptr->pkts; | 459 | stats_http += ptr->pkts; |
456 | else if (strcmp(protocol, "(Tor)") == 0) | 460 | else if (strcmp(protocol, "Tor") == 0) |
457 | stats_tor += ptr->pkts; | 461 | stats_tor += ptr->pkts; |
458 | } | 462 | } |
459 | else if (ptr->protocol == 0x11) | 463 | else if (ptr->protocol == 0x11) |
460 | protocol = "(UDP)"; | 464 | protocol = "UDP"; |
461 | else if (ptr->protocol == 0x06) | 465 | else if (ptr->protocol == 0x06) |
462 | protocol = "(TCP)"; | 466 | protocol = "TCP"; |
463 | 467 | ||
464 | if (protocol == NULL) | 468 | if (protocol == NULL) |
465 | protocol = ""; | 469 | protocol = ""; |
466 | if (ptr->port_src == 0) | 470 | if (ptr->port_src == 0) |
467 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d (ICMP) %s\n", | 471 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d (ICMP) %s\n", |
468 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->rnode->name); | 472 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->rnode->name); |
469 | else if (ptr->rnode->pkts > 1000000) | ||
470 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u%s %s (%.01fM)\n", | ||
471 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->rnode->name, ((double) ptr->rnode->pkts) / 1000000); | ||
472 | else if (ptr->rnode->pkts > 1000) | ||
473 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u%s %s (%.01fK)\n", | ||
474 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->rnode->name, ((double) ptr->rnode->pkts) / 1000); | ||
475 | else | 473 | else |
476 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u%s %s (%u)\n", | 474 | len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u (%s) %s\n", |
477 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->rnode->name, ptr->rnode->pkts); | 475 | bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->rnode->name); |
478 | adjust_line(line, len, cols); | 476 | adjust_line(line, len, cols); |
479 | printf("%s", line); | 477 | printf("%s", line); |
480 | 478 | ||