# Filtering Terabytes of pcaps using nBPF and Wireshark | ntop

> In a previous post we introduced our new nBPF library that able to convert a BPF filter to hardware rules for offloading traffic filtering to the network card

[Blog](https://www.ntop.org/blog/)[n2disk](https://www.ntop.org/category/n2disk/)

# Filtering Terabytes of pcaps using nBPF and Wireshark

October 11, 20163 min read

In a [previous post](https://www.ntop.org/introducing-nbpf-line-rate-hardware-packet-filtering-yes-wireshark-at-100g-is-possible/) we introduced our new nBPF library that able to convert a BPF filter to hardware rules for offloading traffic filtering to the network card. We did not mention that the same engine can be used for accelerating traffic extraction from an indexed dump set produced by [n2disk](https://www.ntop.org/products/traffic-recording/n2disk/). n2disk is a traffic recording application able to produce multiple PCAP files (a per-file limit in duration or size can be used to control the file size) together with an index (for accelerating extraction) and a timeline (for keeping all the files in chronological order).

Until last month the only way to efficiently extract traffic out of the terabytes of raw data produced by n2disk in PCAP format was the npcapextract tool, which can be used from command like or through our nBox GUI. With this tool you can retrieve specific packets matching a BPF filter in a given time interval very quickly. This proved to be really useful, however the difficulty of integrating this tool with other applications led us to the development of a PF\_RING “timeline” module that can be used to seamlessly do the same job using the PF\_RING API (and consequently also the PCAP API thanks to our libpcap-over-PF\_RING).

One of the most common use cases for the timeline module is the Wireshark integration. In fact it is very convenient to run Wireshark directly on a n2disk timeline, specifying a BPF filter for extracting a small portion of the whole dump set, and starting the analysis task while the extraction is progressing.

In order to test this module you should install pfring and n2disk following the instruction at [http://packages.ntop.org](http://packages.ntop.org/). Please note that the extraction module needs an index and a timeline in order to work, thus you should instruct n2disk to create them on-the-fly using -I and -A options. For additional options please refer to the [n2disk documentation](https://www.ntop.org/support/documentation/). Example:

`n2disk -i eth1 -o /storage/n2disk/eth1 -I -A /storage/n2disk/eth1/timeline`

In order to tell PF\_RING that you want to select the timeline module, you should use the “timeline:” prefix followed by the timeline path as interface name. In addition to this, it is mandatory to provide a BPF filter containing at the beginning the time interval using “start” and “end” tokens, followed by the actual packet filter (a subset of the BPF syntax is supported, please refer to the [n2disk documentation](https://www.ntop.org/support/documentation/)) as in the example below:

`pfcount -i timeline:/storage/n2disk/eth1/timeline -f "start 2016-09-22 8:40:53 and end 2016-09-22 10:43:54 and host 192.168.2.130"`

If you want to do the same in Wireshark, since you cannot use “timeline:” as interface name (Wireshark lets you choose PCAP files and devices as traffic sources, but it is not aware of n2disk timelines), you have to create a virtual interface bound to your actual timeline, and select it as traffic source. The libpcap-over-PF\_RING will do all the rest. In order to create the virtual interface you should use the “[n2if](https://github.com/ntop/PF_RING/blob/dev/tools/n2if)” tool, part of the PF\_RING package:

`n2if up -t /storage/n2disk/eth1/timeline -d timeline0`

After creating the virtual interface bound to the timeline, you should be able to run the extraction using Wireshark (or tshark). Please note you should set the env var LD\_LIBRARY\_PATH with the PCAP-over-PF\_RING library installation path (default is /usr/local/lib/) in order to force Wireshark to load the correct libpcap. Please also note that the Wireshark provided by most distros are compiled across libpcap.so.0.8, thus you probably need to create an ad-hoc symlink:

`ln -s /usr/local/lib/libpcap.so /usr/local/lib/libpcap.so.0.8`

At this point you should be able to run Wireshark providing the virtual interface created with n2if and a BPF filter containing the time interval as described above:

`LD_LIBRARY_PATH=/usr/local/lib/ tshark -i timeline0 -f "start 2016-09-22 8:40:53 and end 2016-09-22 10:43:54 and host 192.168.2.130"`

If you are using the Wireshark GUI, you should run just the wireshark command without any option:

`LD_LIBRARY_PATH=/usr/local/lib/ wireshark`

Select the virtual interface from the GUI:

[![screen-shot-2016-10-09-at-16-06-05](/images/2016/10/Screen-Shot-2016-10-09-at-16.06.05.webp)](https://www.ntop.org/images/2016/10/Screen-Shot-2016-10-09-at-16.06.05.webp)

Set a capture filter specifying time interval and BPF:

[![screen-shot-2016-10-11-at-14-00-33](/images/2016/10/Screen-Shot-2016-10-11-at-14.00.33.webp)](https://www.ntop.org/images/2016/10/Screen-Shot-2016-10-11-at-14.00.33.webp)

Then you can start the packet capture (extraction) and start analysing your traffic:

[![screen-shot-2016-10-09-at-16-08-47](/images/2016/10/Screen-Shot-2016-10-09-at-16.08.47.webp)](https://www.ntop.org/images/2016/10/Screen-Shot-2016-10-09-at-16.08.47.webp)

We will present also this at the upcoming [Sharkfest Europe](https://sharkfesteurope.wireshark.org/) conference, where we will organise a free half-day workshop. See you next week!

## Keep reading

n2diskJan 7, 2025

### [Introducing n2disk 3.8: NVIDIA Support, Smart Recording, Traffic Deduplication](https://www.ntop.org/introducing-n2disk-3-8-nvidia-support-smart-recording-traffic-deduplication/)

We’re excited to announce a new stable release of n2disk v. 3.8. This release is bringing significant new capabilities to the network monitoring and recording landscape, and it is packed with features…

n2diskJul 1, 2024

### [Howto Build a (Cheaper) 100 Gbit Continuous Packet Recorder using Commodity Hardware](https://www.ntop.org/howto-build-a-cheaper-100-gbit-packet-recorder-using-commodity-hardware/)

Those who follow this blog probably read a few posts where we described how to build a 100 Gbit continuous packet recorder using n2disk and PF\_RING, providing specs for recommended hardware and…

AnnounceMay 2, 2023

### [Introducing Smart Recording in n2disk: Combining Cybersecurity with Packet-to-Disk](https://www.ntop.org/introducing-smart-recording-in-n2disk-combining-cybersecurity-with-packet-to-disk/)

In short Continuous network traffic recorders are applications (or appliances) that write network traffic on disk. In case of issues (e.g. security breach or network outage) they enable network and security analysts…

## Try it on your own network

Download the free Community edition and see your first flows in five minutes.

[Download ntopng free](https://www.ntop.org/support/documentation/software-installation/)[Talk to an engineer](https://www.ntop.org/support/need-help/contacts/)
Source: https://www.ntop.org/filtering-terabyte-of-pcaps-using-nbpf-and-wireshark/