Este conteúdo não está disponível no idioma selecionado.
Chapter 45. Network tracing using the BPF compiler collection
BPF Compiler Collection (BCC) is a library, which facilitates the creation of the extended Berkeley Packet Filter (eBPF) programs. The main utility of eBPF programs is analyzing the operating system performance and network performance without experiencing overhead or security issues.
BCC removes the need for users to know deep technical details of eBPF, and provides many out-of-the-box starting points, such as the bcc-tools
package with pre-created eBPF programs.
The eBPF programs are triggered on events, such as disk I/O, TCP connections, and process creations. It is unlikely that the programs should cause the kernel to crash, loop or become unresponsive because they run in a safe virtual machine in the kernel.
45.1. Installing the bcc-tools package Copiar o linkLink copiado para a área de transferência!
Install the bcc-tools
package, which also installs the BPF Compiler Collection (BCC) library as a dependency.
Procedure
Install
bcc-tools
.yum install bcc-tools
# yum install bcc-tools
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The BCC tools are installed in the
/usr/share/bcc/tools/
directory.
Verification
Inspect the installed tools:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
doc
directory in the listing provides documentation for each tool.
45.2. Displaying TCP connections added to the Kernel’s accept queue Copiar o linkLink copiado para a área de transferência!
By using the tcpaccept
utility, you can monitor newly accepted connections by tracing the kernel’s accept()
function.
After the kernel receives the ACK
packet in a TCP 3-way handshake, the kernel moves the connection from the SYN
queue to the accept
queue after the connection’s state changes to ESTABLISHED
. Therefore, only successful TCP connections are visible in this queue.
The tcpaccept
utility uses eBPF features to display all connections the kernel adds to the accept
queue. The utility is lightweight because it traces the accept()
function of the kernel instead of capturing packets and filtering them. For example, use tcpaccept
for general troubleshooting to display new connections the server has accepted.
Procedure
Enter the following command to start the tracing the kernel
accept
queue:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel accepts a connection,
tcpaccept
displays the details of the connections.- Press Ctrl+C to stop the tracing process.
45.3. Tracing outgoing TCP connection attempts Copiar o linkLink copiado para a área de transferência!
The tcpconnect
utility uses eBPF features to trace outgoing TCP connection attempts. The output of the utility also includes connections that failed.
The tcpconnect
utility is lightweight because it traces, for example, the connect()
function of the kernel instead of capturing packets and filtering them.
Procedure
Enter the following command to start the tracing process that displays all outgoing connections:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel processes an outgoing connection,
tcpconnect
displays the details of the connections.- Press Ctrl+C to stop the tracing process.
45.4. Measuring the latency of outgoing TCP connections Copiar o linkLink copiado para a área de transferência!
The tcpconnlat
utility uses eBPF features to measure the time between a sent SYN
packet and the received response packet.
The TCP connection latency is the time taken to establish a connection. This typically involves the kernel TCP/IP processing and network round trip time, and not the application runtime.
Procedure
Start measuring the latency of outgoing connections:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel processes an outgoing connection,
tcpconnlat
displays the details of the connection after the kernel receives the response packet.- Press Ctrl+C to stop the tracing process.
45.5. Displaying details about TCP packets and segments that were dropped by the kernel Copiar o linkLink copiado para a área de transferência!
The tcpdrop
utility enables administrators to display details about TCP packets and segments that were dropped by the kernel. Use this utility to debug high rates of dropped packets that can cause the remote system to send timer-based retransmits.
High rates of dropped packets and segments can impact the performance of a server. Instead of capturing and filtering packets, which is resource-intensive, the tcpdrop
utility uses eBPF features to retrieve the information directly from the kernel.
Procedure
Enter the following command to start displaying details about dropped TCP packets and segments:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel drops TCP packets and segments,
tcpdrop
displays the details of the connection, including the kernel stack trace that led to the dropped package.- Press Ctrl+C to stop the tracing process.
45.6. Tracing TCP sessions Copiar o linkLink copiado para a área de transferência!
The tcplife
utility uses eBPF to trace TCP sessions that open and close, and prints a line of output to summarize each one. Administrators can use tcplife
to identify connections and the amount of transferred traffic.
For example, you can display connections to port 22
(SSH) to retrieve the following information:
- The local process ID (PID)
- The local process name
- The local IP address and port number
- The remote IP address and port number
- The amount of received and transmitted traffic in KB.
- The time in milliseconds the connection was active
Procedure
Enter the following command to start the tracing of connections to the local port
22
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time a connection is closed,
tcplife
displays the details of the connections.- Press Ctrl+C to stop the tracing process.
45.7. Tracing TCP retransmissions Copiar o linkLink copiado para a área de transferência!
The tcpretrans
utility displays details about TCP retransmissions, such as the local and remote IP address and port number, as well as the TCP state at the time of the retransmissions.
The utility uses eBPF features and, therefore, has a very low overhead.
Procedure
Use the following command to start displaying TCP retransmission details:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel calls the TCP retransmit function,
tcpretrans
displays the details of the connection.- Press Ctrl+C to stop the tracing process.
45.8. Displaying TCP state change information Copiar o linkLink copiado para a área de transferência!
During a TCP session, the TCP state changes. The tcpstates
utility uses eBPF functions to trace these state changes, and prints details including the duration in each state. For example, use tcpstates
to identify if connections spend too much time in the initialization state.
Procedure
Use the following command to start tracing TCP state changes:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time a connection changes its state,
tcpstates
displays a new line with updated connection details.If multiple connections change their state at the same time, use the socket address in the first column (
SKADDR
) to determine which entries belong to the same connection.- Press Ctrl+C to stop the tracing process.
45.9. Summarizing and aggregating TCP traffic sent to specific subnets Copiar o linkLink copiado para a área de transferência!
The tcpsubnet
utility summarizes and aggregates IPv4 TCP traffic that the local host sends to subnets and displays the output on a fixed interval. The utility uses eBPF features to collect and summarize the data to reduce the overhead.
By default, tcpsubnet
summarizes traffic for the following subnets:
-
127.0.0.1/32
-
10.0.0.0/8
-
172.16.0.0/12
-
192.0.2.0/24/16
-
0.0.0.0/0
Note that the last subnet (0.0.0.0/0
) is a catch-all option. The tcpsubnet
utility counts all traffic for subnets different than the first four in this catch-all entry.
Follow the procedure to count the traffic for the 192.0.2.0/24
and 198.51.100.0/24
subnets. Traffic to other subnets will be tracked in the 0.0.0.0/0
catch-all subnet entry.
Procedure
Start monitoring the amount of traffic sent to the
192.0.2.0/24
,198.51.100.0/24
, and other subnets:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command displays the traffic in bytes for the specified subnets once per second.
- Press Ctrl+C to stop the tracing process.
45.10. Displaying the network throughput by IP address and port Copiar o linkLink copiado para a área de transferência!
The tcptop
utility displays TCP traffic the host sends and receives in kilobytes. The report automatically refreshes and contains only active TCP connections. The utility uses eBPF features and, therefore, has only a very low overhead.
Procedure
To monitor the sent and received traffic, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output of the command includes only active TCP connections. If the local or remote system closes a connection, the connection is no longer visible in the output.
- Press Ctrl+C to stop the tracing process.
45.11. Tracing established TCP connections Copiar o linkLink copiado para a área de transferência!
The tcptracer
utility traces the kernel functions that connect, accept, and close TCP connections. The utility uses eBPF features and, therefore, has a very low overhead.
Procedure
Use the following command to start the tracing process:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each time the kernel connects, accepts, or closes a connection,
tcptracer
displays the details of the connections.- Press Ctrl+C to stop the tracing process.
45.12. Tracing IPv4 and IPv6 listen attempts Copiar o linkLink copiado para a área de transferência!
The solisten
utility traces all IPv4 and IPv6 listen attempts. It traces the attempts including which ultimately fail or the listening program that does not accept the connection. The utility traces functions that the kernel calls when a program wants to listen for TCP connections.
Procedure
Enter the following command to start the tracing process that displays all listen TCP attempts:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Press Ctrl+C to stop the tracing process.
45.13. Summarizing the service time of soft interrupts Copiar o linkLink copiado para a área de transferência!
The softirqs
utility summarizes the time spent servicing soft interrupts (soft IRQs) and shows this time as either totals or histogram distributions. This utility uses the irq:softirq_enter
and irq:softirq_exit
kernel tracepoints, which is a stable tracing mechanism.
Procedure
Enter the following command to start the tracing
soft irq
event time:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Press Ctrl+C to stop the tracing process.
45.14. Summarizing packets size and count on a network interface Copiar o linkLink copiado para a área de transferência!
The netqtop
utility displays statistics about the attributes of received (RX) and transmitted (TX) packets on each network queue of a particular network interface.
The statistics include:
- Bytes per second (BPS)
- Packets per second (PPS)
- The average packet size
- Total number of packets
To generate these statistics, netqtop
traces the kernel functions that perform events of transmitted packets net_dev_start_xmit
and received packets netif_receive_skb
.
Procedure
Display the number of packets within the range of bytes size of the time interval of
2
seconds:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Press Ctrl+C to stop
netqtop
.