19.2. 纳帕泰克

19.2.1. 目录

  • 介绍

  • 程序包安装

  • 基本配置

  • 高级多线程配置

19.2.2. 介绍

napatech数据包捕获加速卡可以使用以下基于硬件的功能显著提高Suricata部署的性能:

  • 车载突发缓冲(高达12GB)

  • 零拷贝内核绕过DMA

  • 无阻塞PCIe性能

  • 端口合并

  • 最多128个主机缓冲区的负载分配

  • 精确时间戳

  • 精确的时间同步

该包使用专有的shell脚本来处理安装过程。在这两种情况下,需要gcc、make和内核头文件来编译内核模块和安装软件。

19.2.3. 程序包安装

注意make、gcc和内核头是安装所必需的

还需要根权限

最新的驱动程序和工具安装包可从:https://www.napatech.com/downloads下载。

请注意,系统将提示您安装napatech libpcap库。如果要使用napatech卡在wireshark、tcpdump或其他基于pcap的应用程序中捕获数据包,请回答“是”。Suricata不需要libpcap,因为包含本机napatech API支持

基于Red Hat的发行版:

$ yum install kernel-devel-$(uname -r) gcc make
       $ ./package_install_3gd.sh

基于Debian的发行版:

$ apt-get install linux-headers-$(uname .r) gcc make
       $ ./package_install_3gd.sh

完成所有发行版的安装 ntservice ::

$ /opt/napatech3/bin/ntstart.sh -m

19.2.4. 测量装置

下载并提取suricata tarball后,需要运行configure以启用napatech支持并准备编译:

$ ./configure --enable-napatech --with-napatech-includes=/opt/napatech3/include --with-napatech-libraries=/opt/napatech3/lib
$ make
$ make install-full

19.2.5. 测量配置

现在编辑suricata.yaml文件以配置系统。系统有三种配置方式:

1.无CPU关联的自动配置:在此模式下,您在suricata.yaml文件中指定流配置,并允许线程自由漫游。这适用于单处理器系统,其中numa节点配置不是性能问题。

2.第二步。使用CPU关联进行自动配置:在此模式下,您使用工作线程的CPU关联来控制流的创建和配置。将为suricata.yaml中标识的每个CPU创建一个流和一个工作线程。这在具有多个numa节点(即多处理器系统)的系统中是最好的,因为主机缓冲区的numa节点与线程运行的核心相匹配。

三。手动配置(传统):在这种模式下,通过在运行Suricata之前发出NTPL命令来配置底层Napatech流。Suricata然后在启动时连接到现有的流。

19.2.6. 示例配置-不带CPU关联的自动配置:

如果不使用cpu关联,则有必要在Suricata配置文件中显式定义流。要使用此选项,应在Suricata配置文件中设置以下选项:

  1. 关闭CPU关联

  2. 启用Napatech“自动配置”选项

  3. 指定启动时应创建的流

  4. 指定将为Suricata提供流量的端口

  5. 指定用于将流量分配到流的哈希模式

下面是要设置的选项:

threading:
  set-cpu-affinity: no
    .
    .
    .
napatech:
    auto-config: yes
    streams: ["0-3"]
    ports: [all]
    hashmode: hash5tuplesorted

现在修改 ntservice.ini . 您还需要确保在中分配了足够的主机缓冲区 ntservice.ini 为了溪流。同时设置 TimeSyncReferencePriority . 为此,请对进行以下更改服务.ini:

主机BuffersRx= [4,16,-1] γ [主机缓冲区数、大小(MB)、numa节点] timesyncreferencepriority=ostime时间戳时钟与操作系统同步

停止并重新启动 ntservice 更改ntservice后:

$ /opt/napatech3/bin/ntstop.sh
$ /opt/napatech3/bin/ntstart.sh

现在你准备好开始苏瑞卡塔了:

$ suricata -c /usr/local/etc/suricata/suricata.yaml --napatech --runmode workers

19.2.7. 配置示例-具有CPU关联的自动配置:

此选项将为在中定义的每个CPU创建一个工作线程和流 worker-cpu-set . 要使用此选项,请对苏瑞塔亚姆:

  1. 打开CPU关联

  2. 指定工作CPU集

  3. 启用Napatech“自动配置”选项

  4. 指定将为Suricata提供流量的端口

  5. 指定将用于控制到不同流/CPU的流量分布的哈希模式。

完成后,应该与以下内容类似:

threading:
  set-cpu-affinity: yes
  cpu-affinity:
    management-cpu-set:
      cpu: [ 0 ]
    receive-cpu-set:
      cpu: [ 0 ]
    worker-cpu-set:
      cpu: [ all ]
      .
      .
      .
napatech:
  auto-config: yes
  ports: [all]
  hashmode: hash5tuplesorted

在此模式下运行suricata之前,还需要在每个numa节点上配置足够数量的主机缓冲区。因此,例如,如果您有一个总共32个核心的双处理器服务器,并且计划使用所有核心,那么您需要在每个NUMA节点上分配16个主机缓冲区。还需要将napatech卡的时间源设置为操作系统。

为此,请对ntservice.ini进行以下更改:

TimeSyncReferencePriority = OSTime  # Timestamp clock synchronized to the OS
HostBuffersRx = [16,16,0],[16,16,1] # [number of host buffers, Size(MB), NUMA node]

停止并重新启动 ntservice 更改ntservice后:

$ /opt/napatech3/bin/ntstop.sh -m
$ /opt/napatech3/bin/ntstart.sh -m

现在你准备好开始苏瑞卡塔了:

$ suricata -c /usr/local/etc/suricata/suricata.yaml --napatech --runmode workers

19.2.8. 配置示例-手动配置

对于手动配置,Napatech流是在运行Suricata之前通过运行NTPL命令创建的。

请注意,此选项主要用于传统配置,因为以前这是配置Napatech产品的唯一方法。更新的功能,如流感知和内联处理,不能手动配置。

在本例中,我们将设置Napatech捕获加速器来合并所有物理端口,然后将合并的流量分配到Suricata将接收的四个流中。

此配置的步骤如下:
  1. 在中禁用Napatech auto config选项苏瑞塔亚姆

  2. 指定Suricata要在中使用的流苏瑞塔亚姆

  3. 使用ntpl命令创建文件以创建底层napatech流。

first suricata.yaml的配置应类似于以下内容:

napatech:
  auto-config: no
  streams: ["0-3"]

接下来,您需要确保在ntservice.ini中定义了足够的主机缓冲区。因为设置时间同步也是一个好主意。以下是要更改的行:

TimeSyncReferencePriority = OSTime      # Timestamp clock synchronized to the OS
HostBuffersRx = [4,16,-1]               # [number of host buffers, Size(MB), NUMA node]

更改ntservice后停止并重新启动ntservice::

$ /opt/napatech3/bin/ntstop.sh
$ /opt/napatech3/bin/ntstart.sh

现在ntservice正在运行,我们需要执行一些ntpl(napatech编程语言)命令来完成设置。创建文件将使用以下命令:

Delete=All                              # Delete any existing filters
Assign[streamid=(0..3)]= all    # Assign all physical ports to stream ID 0

接下来使用 ntpl 工具:

$ /opt/napatech3/bin/ntpl -f <my_ntpl_file>

现在你准备好开始苏瑞卡塔了:

$ suricata -c /usr/local/etc/suricata/suricata.yaml --napatech --runmode workers

使用此选项可以指定更详细的配置。只需创建适当的NTPL文件并将Suricata附加到流中。

19.2.9. 旁路流量

在流感知Napatech产品上,来自各个流的流量可以自动丢弃,或者在内联配置的情况下,在Suricata检查流的初始包之后,由硬件转发。这将节省CPU周期,因为Suricata不处理已经判定的流的数据包。这是通过配置文件的Napatech部分中的hardware bypass选项启用的。

当使用硬件旁路时,重要的是,接收来自网络的上游和下游流量的端口配置连接双方将到达哪个端口的信息。这是硬件正确处理两个方向的流量所必需的。这在“端口”部分显示为将接收上游和下游流量的端口对列表,例如:

napatech:
  hardware-bypass: true
  ports[0-1,2-3]

注意,这些“端口对”对于IDS配置也是必需的,因为硬件需要知道连接的两个端口将到达哪个端口。

对于依赖于光抽头的配置,配对的两侧通常是不同的端口。两个端口的上游和下游端口配置都是相同的。

例如,抽头配置的形式与此类似:

ports[0-1,2-3]

而SPAN端口配置与此类似:

ports[0-0,1-1,2-2,3-3]

请注意,SPAN和tap配置可以组合在同一适配器上。

有多种方法可以配置Suricata来绕过流量。一种方法是分流在配置文件中。例如。::

stream:
  bypass: true

一旦Suricata评估了流的第一个块(大小也是可配置的)后,它将指示流中的其余包可以被绕过。在IDS模式下,这意味着流的后续数据包将被丢弃,而不会被传递到Suricata。在内联操作中,数据包将在输出端口上传输,但不会传送到Suricata。

另一种方法是在规则中指定“bypass”关键字。当使用此关键字触发规则时,“pass”或“drop”操作将自动应用于流的后续数据包,而无需Suricata进行进一步分析。例如给定规则:

drop tcp any 443 <> any any (msg: "SURICATA Test rule"; bypass; sid:1000001; rev:2;)

一旦Suricata最初评估第一个包并识别出流,来自流的所有后续包都将被硬件丢弃;从而为更重要的任务节省CPU周期。

从硬件流表中逐出过时流之前等待多长时间的超时值可以通过中的FlowTimeout属性指定服务.ini.

19.2.10. 内联操作

Napatech流感知产品可以配置为内联操作。这是在配置文件中指定的。启用时,端口被指定为端口对。从一个端口接收到的流量在Suricata检查后被传输到对等端口。E、 g.配置:

napatech:
 inline: enabled
 ports[0-1, 2-3]

将端口0和1、2和3配对为对等端口。可以定义规则来传递与给定签名匹配的流量。例如,给定规则:

pass tcp any 443 <> any any (msg: "SURICATA Test rule";  bypass; sid:1000001; rev:2;)

Suricata将评估流的初始包,并将流编程到硬件中。来自流的后续数据包将自动从一个端口分流到它的对等端。

19.2.11. 计数器

以下计数器可用:

  • 纳帕_总计.pkts-卡接收的数据包总数。

  • 纳帕_总计.byte-卡接收的字节总数。

  • 纳帕_总溢出量-由于主机缓冲区已满而丢弃的数据包数。(即应用程序无法足够快地处理数据包。)

  • 纳帕_溢出总字节-由于主机缓冲区已满而丢弃的字节数。(即应用程序无法足够快地处理数据包。)

在流量感知产品上,还提供以下计数器:

  • 纳帕湖调度_主机.pkts,纳帕湖调度_主机.byte:

    由Suricata调度到主机缓冲区进行处理的数据包/字节总数。(注意:此计数包括在主机缓冲区中没有空间时可能随后丢弃的数据包。)

  • 纳帕湖调度_删除.pkts,纳帕湖调度_删除.byte:

    由于Suricata“删除”旁路规则或Suricata判定流数据包应被丢弃而在硬件上丢弃的数据包/字节总数。这些数据包不会传递到应用程序。

  • 纳帕湖调度_前进包装,纳帕湖调度_前进字节:

    配置内联操作时,这是由于Suricata“pass”旁路规则或由于在配置文件中启用流或加密旁路而转发的数据包/字节总数。这些数据包未传递到应用程序。

  • 纳帕_旁路有效流量:

    在要转发或丢弃的硬件上活动编程的流数。

  • 纳帕_旁路总流量:

    自应用程序启动以来编程的流总数。

如果在配置文件中启用了enable stream stats,那么对于正在处理的每个流,将在中输出以下计数器统计日志:

  • napa<streamid>.pkts:流接收的数据包数。

  • napa<streamid>.bytes:流接收的总字节数。

  • napa<streamid>。drop_pkts:由于缓冲区溢出情况而从此流中丢弃的数据包数。

  • napa<streamid>.dropu byte:由于缓冲区溢出情况而从此流中删除的字节数。

这对于细粒度调试非常有用,以确定特定的CPU内核或线程是否落后,从而导致数据包丢失。

如果启用了HBA,还将提供以下计数器:

  • napa<streamid>.hbaudrop:由于达到主机缓冲区允许高水位线而丢弃的数据包数。

除了计数器之外,还跟踪和记录主机缓冲区利用率。这对于调试也很有用。当达到使用率的25%、50%、75%时,主机和板载缓冲区都会输出日志消息。当利用率降低时,输出相应的消息。

调试:

对于调试配置,可以查看正在流动的流量以及创建和接收的流量。/opt/napatech3/bin中有两个工具可用于此操作:

  • 监控:此工具将显示到达端口接口的流量。

  • 分析:这将显示主机缓冲区、流和流到流的流量。

如果Suricata异常终止流定义(通常在关闭时删除)可能仍然有效。如果发生这种情况,可以通过发出“delete=all”NTPL命令清除它们,如下所示:

# /opt/napatech3/bin/ntpl -e "delete=all"

19.2.12. napatech配置选项:

以下是Suricata配置文件中提供的Napatech选项:

napatech:
  # The Host Buffer Allowance for all streams
  # (-1 = OFF, 1 - 100 = percentage of the host buffer that can be held back)
  # This may be enabled when sharing streams with another application.
  # Otherwise, it should be turned off.
  #
  # Note: hba will be deprecated in Suricata 7
  #
  #hba: -1

  # When use_all_streams is set to "yes" the initialization code will query
  # the Napatech service for all configured streams and listen on all of them.
  # When set to "no" the streams config array will be used.
  #
  # This option necessitates running the appropriate NTPL commands to create
  # the desired streams prior to running Suricata.
  #use-all-streams: no

  # The streams to listen on when auto-config is disabled or when threading
  # cpu-affinity is disabled. This can be either:
  #   an individual stream (e.g. streams: [0])
  # or
  #   a range of streams (e.g. streams: ["0-3"])
  #
  streams: ["0-3"]

  # Stream stats can be enabled to provide fine grain packet and byte counters
  # for each thread/stream that is configured.
  #
  enable-stream-stats: no

  # When auto-config is enabled the streams will be created and assigned
  # automatically to the NUMA node where the thread resides. If cpu-affinity
  # is enabled in the threading section, then the streams will be created
  # according to the number of worker threads specified in the worker cpu set.
  # Otherwise, the streams array is used to define the streams.
  #
  # This option cannot be used simultaneous with "use-all-streams".
  #
  auto-config: yes

  # Enable hardware level flow bypass.
  #
  hardware-bypass: yes

  # Enable inline operation. When enabled traffic arriving on a given port is
  # automatically forwarded out it's peer port after analysis by Suricata.
  # hardware-bypass must be enabled when this is enabled.
  #
  inline: no

  # Ports indicates which napatech ports are to be used in auto-config mode.
  # these are the port ID's of the ports that will be merged prior to the
  # traffic being distributed to the streams.
  #
  # When hardware-bypass is enabled the ports must be configured as a segment
  # specify the port(s) on which upstream and downstream traffic will arrive.
  # This information is necessary for the hardware to properly process flows.
  #
  # When using a tap configuration one of the ports will receive inbound traffic
  # for the network and the other will receive outbound traffic. The two ports on a
  # given segment must reside on the same network adapter.
  #
  # When using a SPAN-port configuration the upstream and downstream traffic
  # arrives on a single port. This is configured by setting the two sides of the
  # segment to reference the same port.  (e.g. 0-0 to configure a SPAN port on
  # port 0).
  #
  # port segments are specified in the form:
  #    ports: [0-1,2-3,4-5,6-6,7-7]
  #
  # For legacy systems when hardware-bypass is disabled this can be specified in any
  # of the following ways:
  #
  #   a list of individual ports (e.g. ports: [0,1,2,3])
  #
  #   a range of ports (e.g. ports: [0-3])
  #
  #   "all" to indicate that all ports are to be merged together
  #   (e.g. ports: [all])
  #
  # This parameter has no effect if auto-config is disabled.
  #
  ports: [0-1,2-3]

  # When auto-config is enabled the hashmode specifies the algorithm for
  # determining to which stream a given packet is to be delivered.
  # This can be any valid Napatech NTPL hashmode command.
  #
  # The most common hashmode commands are: hash2tuple, hash2tuplesorted,
  # hash5tuple, hash5tuplesorted and roundrobin.
  #
  # See Napatech NTPL documentation other hashmodes and details on their use.
  #
  # This parameter has no effect if auto-config is disabled.
  #
  hashmode: hash5tuplesorted

Note: hba is useful only when a stream is shared with another application. When hba is enabled packets will be dropped (i.e. not delivered to Suricata) when the host-buffer utilization reaches the high-water mark indicated by the hba value. This insures that, should Suricata get behind in its packet processing, the other application will still receive all of the packets. If this is enabled without another application sharing the stream it will result in sub-optimal packet buffering.

请确保在中声明了足够的主机缓冲区 ntservice.ini 以适应正在使用的核心/流的数量。

19.2.13. 支持

联系支持工程师:ntsupport@napatech.com

napatech文档可在以下网址找到:https://docs.napatech.com(单击搜索图标,无搜索文本,查看门户中的所有文档。)