# xdpdump > [!NOTE] > **WHAT TO EXPECT** > > `xdpdump` is a packet capture tool, similar to tcpdump, for interfaces that run an XDP (eXpress Data Path) program. It shows each packet as the XDP program receives it and, optionally, as the program leaves it, together with the action the program took. > > **In this article**, users will learn when to use xdpdump, how to capture packets with it, and how to save a capture to a file. ### Where xdpdump is installed `xdpdump` is part of [swx-tools](swx-tools.md), so it is available on Linux VMs with an xNIC, on swXtchBridge VMs, and on any Linux VM where swx-tools is installed. It is not installed on the cloudSwXtch VM, and there is no Windows version. ```shell $ xdpdump --version Couldn't find runtime libbpf version - falling back to compile-time value! xdpdump version 1.5.3 using libbpf version 1.4.0 ``` The first line is a warning and can be ignored. xdpdump must run as root, so use `sudo`; otherwise it stops with `This program must be run as root.` ### When to use xdpdump An xNIC Type 2 attaches an XDP program, `xdp_ingress`, to the data interface of the VM. That program receives the traffic from the cloudSwXtch and turns it into the original multicast packets. xdpdump attaches to that program, so it can show both sides: the packet as it arrived from the cloudSwXtch, and the packet the program delivered to the VM. To check whether an interface has an XDP program, list the interfaces with `-D`: ```shell $ sudo xdpdump -D Interface Prio Program name Mode ID Tag Chain actions -------------------------------------------------------------------------------------- lo enp39s0 enp40s0 xdp_ingress skb 32 2e6eaa6ecc9c1269 swxip41087 ``` In this example, from a VM with an xNIC Type 2, `enp40s0` is the data interface with the `xdp_ingress` program; the other interfaces have none. > [!NOTE] > **NOTE** > > On an interface without an XDP program (for example, the `swx0` interface of an xNIC Type 1), xdpdump captures in legacy mode, and prints only the time and size of each packet. For those interfaces, [swx-tcpdump](swx-tcpdump.md) gives more information. > > **Example:** xdpdump in legacy mode on an interface without an XDP program > > ``` > $ sudo xdpdump -i enp39s0 > WARNING: Specified interface does not have an XDP program loaded, > capturing in legacy mode! > listening on enp39s0, link-type EN10MB (Ethernet), capture size 262144 bytes > > 36 packets captured > 0 packets dropped by kernel > 1790689286.904534: packet size 1354 bytes on if_name "enp39s0" > 1790689286.904845: packet size 628 bytes on if_name "enp39s0" > 1790689286.904849: packet size 66 bytes on if_name "enp39s0" > ... > ``` ### Capturing packets Run xdpdump with the interface to capture on. It prints one line per packet, and keeps running until it is stopped with `Ctrl+C` (there is no option to stop after a number of packets): ```shell sudo xdpdump -i ``` **Example:** Capture on the data interface of an xNIC Type 2 ```shell $ sudo xdpdump -i enp40s0 listening on enp40s0, ingress XDP program ID 32 func xdp_ingress, capture mode entry, capture size 262144 bytes 1790689354.136625934: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 1 1790689354.186611734: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 2 1790689354.236631744: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 3 1790689354.286603454: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 4 1790689354.336622944: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 5 1790689354.386603934: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 6 1790689354.436612934: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 7 ... ``` Each line shows the time stamp, the XDP program and the capture point, the size of the packet, the interface index, the receive queue and a packet counter. #### Capture points: entry and exit `--rx-capture` selects where the packet is captured: | Value | What is captured | | --- | --- | | `entry` (default) | The packet as it arrives at the XDP program. On the data interface of an xNIC Type 2, this is the packet sent by the cloudSwXtch, with the swXtch encapsulation. | | `exit` | The packet as the XDP program leaves it, with the action the program took in brackets (for example, `[PASS]`). On the data interface of an xNIC Type 2, this is the original multicast packet delivered to the VM. | | `entry,exit` | Both, one line each. | **Example:** Capture at the entry and the exit of the XDP program ```shell $ sudo xdpdump -i enp40s0 --rx-capture entry,exit listening on enp40s0, ingress XDP program ID 32 func xdp_ingress, capture mode entry/exit, capture size 262144 bytes 1790689358.161449052: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 1 1790689358.161459402: xdp_ingress()@exit[PASS]: packet size 242 bytes on if_index 3, rx queue 3, id 1 1790689358.211454652: xdp_ingress()@entry: packet size 274 bytes on if_index 3, rx queue 3, id 2 1790689358.211464772: xdp_ingress()@exit[PASS]: packet size 242 bytes on if_index 3, rx queue 3, id 2 1790689358.253541912: xdp_ingress()@entry: packet size 83 bytes on if_index 3, rx queue 0, id 3 1790689358.253551402: xdp_ingress()@exit[PASS]: packet size 83 bytes on if_index 3, rx queue 0, id 3 ... ``` In this example, each multicast packet is 274 bytes at the entry and 242 bytes at the exit: the XDP program removed the 32 bytes of the swXtch encapsulation and passed the original packet to the VM. The 83-byte packet is control traffic from the cloudSwXtch, which the program passes unchanged. #### Showing the packet content `-x` prints each packet in hex and ASCII. `-s` limits how many bytes of each packet are captured. **Example:** Content of a multicast packet at the exit of the XDP program ```shell $ sudo xdpdump -i enp40s0 --rx-capture exit -x listening on enp40s0, ingress XDP program ID 32 func xdp_ingress, capture mode exit, capture size 262144 bytes 1790689429.145957744: xdp_ingress()@exit[PASS]: packet size 242 bytes, captured 242 bytes on if_index 3, rx queue 0, id 1 0x0000: 01 00 5e 01 01 3d 06 c9 04 2e 11 2b 08 00 45 00 ..^..=.....+..E. 0x0010: 00 e4 00 00 00 00 40 11 15 32 0a cb 69 ce ef 01 ......@..2..i... 0x0020: 01 3d fd 14 27 10 00 d0 00 00 53 57 58 32 02 04 .=..'.....SWX2.. 0x0030: c8 00 00 00 00 00 55 00 00 00 00 00 00 00 f8 18 ......U......... 0x0040: 05 30 e8 9a 15 6e 3d 49 54 a1 8f 8b c8 dc 65 ee .0...n=IT.....e. 0x0050: f1 e5 4d 17 47 bc 47 69 76 b7 c6 03 02 b8 d9 29 ..M.G.Giv......) 0x0060: 0d be e2 64 13 90 5a 97 78 9d 9e 8d 23 ab 0e 6e ...d..Z.x...#..n 0x0070: f0 0c 77 b9 b9 e2 28 c7 95 1c fe c3 39 b0 c9 2b ..w...(.....9..+ 0x0080: 3e f9 db 0e be e2 a8 cc 03 d1 6e fa 48 a8 06 94 >.........n.H... 0x0090: 02 18 2a 3a d6 45 97 0a 74 dc 6c cb 2c d6 09 74 ..*:.E..t.l.,..t 0x00a0: e3 51 ea 4b 60 25 53 77 ba 61 f3 17 a3 04 8c a7 .Q.K`%Sw.a...... 0x00b0: 98 ea 8e 3a f5 10 eb 82 a1 b9 cf ae ab 23 d7 28 ...:.........#.( 0x00c0: ea 7d cc c9 04 0f fe 0a 47 7c 91 8f 6a da cc 77 .}......G|..j..w 0x00d0: 08 81 ea 59 42 8e b9 ae e6 51 8d 35 9c 37 95 c6 ...YB....Q.5.7.. 0x00e0: 23 ee d5 a7 e1 a6 b8 36 d9 c3 b6 e5 fe c5 ae a5 #......6........ 0x00f0: 95 4b .K ... ``` **Example:** First 64 bytes of each packet at the entry ```shell $ sudo xdpdump -i enp40s0 -s 64 -x listening on enp40s0, ingress XDP program ID 32 func xdp_ingress, capture mode entry, capture size 64 bytes 1790689363.169770806: xdp_ingress()@entry: packet size 274 bytes, captured 64 bytes on if_index 3, rx queue 3, id 1 0x0000: 06 13 8d 33 1a 33 06 c9 04 2e 11 2b 08 00 45 00 ...3.3.....+..E. 0x0010: 01 04 00 00 00 00 40 11 5f 23 ac 1f 62 31 ac 1f ......@._#..b1.. 0x0020: 60 56 10 2b 27 0f 00 f0 37 a8 ea 01 01 00 01 00 `V.+'...7....... 0x0030: 00 00 00 00 00 f6 00 00 00 00 00 00 00 00 0a cb ................ ... ``` ### Saving a capture to a file `-w` writes the captured packets to a file instead of printing them. The file can then be read with tcpdump or [swx-tcpdump](swx-tcpdump.md). The file is created with root-only permissions, so read it with `sudo` or change its owner. For example, to capture the multicast packets delivered to the VM and read them back: ```shell $ sudo xdpdump -i enp40s0 --rx-capture exit -w /tmp/xdp3.pcap 67 packets captured 0 packets dropped by perf ring $ sudo tcpdump -r /tmp/xdp3.pcap -n -c 3 'greater 200' reading from file /tmp/xdp3.pcap, link-type EN10MB (Ethernet), snapshot length 262144 13:43:53.144444 IP 10.203.105.206.64788 > 239.1.1.61.10000: UDP, length 200 13:43:53.194433 IP 10.203.105.206.64788 > 239.1.1.61.10000: UDP, length 200 13:43:53.244438 IP 10.203.105.206.64788 > 239.1.1.61.10000: UDP, length 200 ``` The `greater 200` filter leaves out the small control packets. The same capture at the entry (`sudo xdpdump -i enp40s0 -w /tmp/xdp2.pcap`) shows the packets between the cloudSwXtch and the xNIC instead: ```shell $ sudo tcpdump -r /tmp/xdp2.pcap -n -c 3 'greater 200' reading from file /tmp/xdp2.pcap, link-type EN10MB (Ethernet), snapshot length 262144 13:43:50.161205 IP 172.31.98.49.4878 > 172.31.96.86.9999: UDP, length 232 13:43:50.211210 IP 172.31.98.49.4878 > 172.31.96.86.9999: UDP, length 232 13:43:50.261203 IP 172.31.98.49.4878 > 172.31.96.86.9999: UDP, length 232 ``` ### Arguments ```shell $ xdpdump --help Usage: xdpdump [options] XDPDump tool to dump network traffic Options: --rx-capture Capture point for the rx direction (valid values: entry,exit) -D, --list-interfaces Print the list of available interfaces --load-xdp-mode Mode used for --load-xdp-mode, default native (valid values: native,skb,hw,unspecified) --load-xdp-program Load XDP trace program if no XDP program is loaded -i, --interface Name of interface to capture on --perf-wakeup Wake up xdpdump every packets -p, --program-names Specific program to attach to -P, --promiscuous-mode Open interface in promiscuous mode -s, --snapshot-length Minimum bytes of packet to capture --use-pcap Use legacy pcap format for XDP traces -w, --write Write raw packets to pcap file -x, --hex Print the full packet in hex -v, --verbose Enable verbose logging (-vv: more verbose) --version Display version information -h, --help Show this help ``` > [!WARNING] > **PLEASE NOTE** > > In the current release, `--load-xdp-program` (load a capture program on an interface that has none) stops with `ERROR: Can't open XDP trace program: No such file or directory(-2)`.