DPI Programming Guide

DPI Programming Guide (PDF)

NVIDIA DOCA DPI Programming Guide

The NVIDIA DOCA DPI Programming Guide provides developers instructions to deploy the DOCA DPI library.

Deep packet inspection (DPI) is a method of examining the full content of data packets as they traverse a monitored network checkpoint.

DPI provides a more robust mechanism for enforcing network packet filtering as it can be used to identify and block a range of complex threats hiding in network data streams more accurately. This includes:

  • Malicious applications
  • Malware data exfiltration attempts
  • Content policy violations
  • Application recognition
  • Load balancing

1.1. Intended Audience

This document is intended for software developers writing DPI-based applications such as application recognition (AR), intrusion prevention system (IPS), and intrusion detection system (IDS).

The document assumes familiarity with the TCP/UDP stack and data packet development kit (DPDK).

1.2. Changes and New Features in 0.1

This section provides information regarding the features added and changes made in this software version.

  • Added HTTP, DNS, SSL/TLS and FTP support
  • Added cross packet regex scanning support

DPI-based application can run either on the host machine, or on the BlueField DPU target. As the DPI leverages the Regular Expressions (RegEx) Engine, users must make sure it is enabled: Please refer to the NVIDIA BlueFIeld DPU Family Software Documentation and perform the following configurations:

  1. The RegEx engine is enabled by default on the DPU. However on the host, run the following commands:
    Copy
    Copied!
                

    host$ sudo /etc/init.d/openibd stop bluefield$ echo 1 > /sys/class/net/p0/smart_nic/pf/regex_en bluefield$ cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages 400 // make sure to allocate 200 additional hugepages bluefield$ echo 600 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages bluefield$ systemctl start mlx-regex // To verify the service is properly running, use "systemctl status mlx-regex" host$ sudo /etc/init.d/openibd start

  2. Make sure that the BlueField DPU runs in Ethernet mode, please refer to the DOCA Installation Guide to make sure that the device is running on the correct mode.
  3. Move BlueField DPU to run in embedded mode (default).
    Note:

    Refer to DPU Modes of Operation > "Configuring ECPF Mode from Separated Host Mode" under DPU Runtime Guides in the SDK DOCA Developer Zone documentation.

2.1. Known Issues

  • The DOCA DPI library only supports inspection of the following protocols:
    • http 1.1/1.0
    • TLS/SSL ClientHello and certificate messages
    • DNS
    • FTP
  • The DOCA DPI library does not support IP-based matching
  • TCP/UDP stream-based signatures may detect applications on other protocols
  • Non-TCP/UDP streams are not supported
  • IP-based signatures are not supported

The following diagram shows how packets are identified by the connection tracking protocol and then injected into the DPI library for processing.

dpi_architecture.png

3.1. Signature Database

The signature database is compiled into a CDO file by the DPI compiler. The CDO file includes:

  • Post-processing table
  • Compiled RegEx engine rules
  • Other signature information

The application may load a new database while the DPI is processing packets.

For more information on DPI compiler, please refer to the DOCA DPI Compiler document.

3.2. DPI Queue

A DPI queue is designed to be used by a worker thread. The DPI queue holds the flow’s state. Therefore, all packets from both directions of the flow must be submitted to the same DPI queue "in order". The connection tracking logic will handle out of order packets or retransmission.

3.3. Connection Tracking

For the DPI library to process cross-packet content, each packet must be injected along with a flow context and a direction. Packets from the same flow direction must be injected "in order". A flow direction is usually represented by a 5-tuple, but it can also be a 3-tuple for other protocols.

The connection tracking (CT) logic must handle out of order packets as well as fragmented packets. Once a connection has timed out or terminated, the application must notify the DPI library as well.

Before enqueueing packets for processing the DPI library must be initialized and loaded with signatures by the main thread:

Copy
Copied!
            

struct doca_dpi_ctx *dpi_ctx = doca_dpi_init(doca_dpi_config); doca_dpi_load_signatures(dpi_ctx, cdo_filename);

The following configurations are available:

  • nb_queues – number of DPI queues
  • max_packets_per_queue – maximum number of packets concurrently processing per queue
  • max_sig_match_len – maximum signature length guaranteed to be matched by the DPI library

    For example: A.*B and max_sig_match_len = 4 guarantees to match AxxB but does not guarantee to match AxxxB.

To close the DPI library, the user should call the following function:

Copy
Copied!
            

doca_dpi_destroy(dpi_ctx)


5.1. Flow Life Cycle

  • Once a new flow was detected by the connection tracking SW, the user should call doca_dpi_flow_create()
  • Every incoming packet classified for this flow should be enqueued by calling dpi_enqeue()
  • To poll for the results the application must call doca_dpi_dequeue(). The result will contain matching information (if matched).
  • When the connection tracking SW detected that the flow was terminated or aged-out the application should notify the DPI library by calling doca_dpi_flow_destroy()

5.2. Enqueueing Packets for Processing

A call to doca_dpi_enqueue() may reject packets for processing for the following reasons:

  • Packet is empty
  • DPI queue is full (doca_dpi_dequeue() must be called first)

5.2.1. Packet Ownership

For every mbuf injected, the DPI engine creates an indirect mbuf. This allows the user to free the mbuf at any time after injection. The mbuf mechanism ensures the mbuf returns to the pool only after both the direct and the indirect mbufs are free.

If an external attach is used, users must follow the DPDK guidelines for rte_pktmbuf_attach_extbuf() to make sure the mbuf is freed when both the user and the DPI free the mbuf.

5.2.2. Flow Matching

A flow may match one or more signatures. The match result will be available to the application on doca_dpi_dequeue(). The DPI library will only report the matched signature with the highest priority.

The application may query for the application name using doca_dpi_signature_get(). To preserve performance, it is not recommended to call those functions while packets are being processed.

It is recommended that the application calls doca_dpi_signatures_get() after loading the database to acquire a copy of the signature names.


6.1. Multithreading

The DPI library is designed to achieve optimal results in a multi-threaded environment. To achieve best performance, it is recommended that both the packet acquisition and the DPI processing will be done by the same thread.

Because some of the DPI work is offloaded to the HW, it is highly recommended that the worker thread will work in a pipeline mode, meaning, it should never wait for a DPI job to be completed but rather go and fetch more packets to be processed. This way the SW can best utilize the CPU while the RegEx accelerator is processing the job.

The following pseudocode shows the recommended way to call the DPI library: 

Copy
Copied!
            

while(true) { mbufs = rx_burst() foreach mbuf in mbufs { flow_id = connection_tacking(qid, mbuf) if (new flow) doca_dpi_flow_create(qid, flow_id, parsing_info) status = doca_dpi_enqueue(flow_ctx, mbuf, offset) if (status ....) } while(doca_dpi_dequeue(qid, &result) == DOCA_DPI_DEQUEUE_READY) ... inspect result ... // At this point processing may not be completed for all packets, so the worker // should continue handling more incoming packets. }

6.2. RSS and RTE_FLOW

Each flow’s packets must be submitted exclusively to the same queue, for both directions. To achieve that users must either use symmetric RSS or manually (using rte_flow) direct both directions of the flow to the same DPDK queue.

RSS_AND_RTE_FLOW.png

packet_life_cycle.png

  1. The packet is sent to the SFT for processing by calling sft_process_packet() to see if the hardware recognizes the flow.
  2. If the packet is not marked with a zone ID by the HW, the SW must explicitly inform the SFT the zone of the packet with sft_process_packet_with_zone().
  3. If the packet is not marked with a flow ID by the HW or the SW, a new flow is created by calling sft_activate().
  4. If a new flow ID is assigned by the SFT, doca_dpi_flow_create() must be invoked before enqueuing the packet.
  5. The packet is then processed by the DPI by calling doca_dpi_enqueue().
  6. If the packet is accepted by the DPI for processing, the result is dequeued by calling doca_dpi_dequeue().
  7. If a match is found, the result is printed and counted for statistics. The flow then is offloaded (sent directly to the host) because no further inspection is required.
  8. To retrieve the match from the DPI engine, doca_dpi_signature_get() allows access to the sig_data struct which contains the signature ID and string. This action might affect DPI performance.
  9. When the flow is terminated by the SFT, it should also be destroyed by invoking doca_dpi_flow_destroy() with the corresponding flow ID.
  10. Additional statistics can be retrieved using doca_dpi_stat_get().

Notice

This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. NVIDIA Corporation nor any of its direct or indirect subsidiaries (collectively: “NVIDIA”) make no representations or warranties, expressed or implied, as to the accuracy or completeness of the information contained in this document and assume no responsibility for any errors contained herein. NVIDIA shall have no liability for the consequences or use of such information or for any infringement of patents or other rights of third parties that may result from its use. This document is not a commitment to develop, release, or deliver any Material (defined below), code, or functionality.

NVIDIA reserves the right to make corrections, modifications, enhancements, improvements, and any other changes to this document, at any time without notice.

Customer should obtain the latest relevant information before placing orders and should verify that such information is current and complete.

NVIDIA products are sold subject to the NVIDIA standard terms and conditions of sale supplied at the time of order acknowledgement, unless otherwise agreed in an individual sales agreement signed by authorized representatives of NVIDIA and customer (“Terms of Sale”). NVIDIA hereby expressly objects to applying any customer general terms and conditions with regards to the purchase of the NVIDIA product referenced in this document. No contractual obligations are formed either directly or indirectly by this document.

NVIDIA products are not designed, authorized, or warranted to be suitable for use in medical, military, aircraft, space, or life support equipment, nor in applications where failure or malfunction of the NVIDIA product can reasonably be expected to result in personal injury, death, or property or environmental damage. NVIDIA accepts no liability for inclusion and/or use of NVIDIA products in such equipment or applications and therefore such inclusion and/or use is at customer’s own risk.

NVIDIA makes no representation or warranty that products based on this document will be suitable for any specified use. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to evaluate and determine the applicability of any information contained in this document, ensure the product is suitable and fit for the application planned by customer, and perform the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this document. NVIDIA accepts no liability related to any default, damage, costs, or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this document or (ii) customer product designs.

No license, either expressed or implied, is granted under any NVIDIA patent right, copyright, or other NVIDIA intellectual property right under this document. Information published by NVIDIA regarding third-party products or services does not constitute a license from NVIDIA to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property rights of the third party, or a license from NVIDIA under the patents or other intellectual property rights of NVIDIA.

Reproduction of information in this document is permissible only if approved in advance by NVIDIA in writing, reproduced without alteration and in full compliance with all applicable export laws and regulations, and accompanied by all associated conditions, limitations, and notices.

THIS DOCUMENT AND ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL NVIDIA BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF ANY USE OF THIS DOCUMENT, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms of Sale for the product.

Trademarks

NVIDIA, the NVIDIA logo, and Mellanox are trademarks and/or registered trademarks of Mellanox Technologies Ltd. and/or NVIDIA Corporation in the U.S. and in other countries. Other company and product names may be trademarks of the respective companies with which they are associated.

Copyright

© 2021 NVIDIA Corporation. All rights reserved.

© Copyright 2023, NVIDIA. Last updated on Apr 13, 2021.