PcapPlusPlus  21.05
KniDevice.h File Reference

This file and KniDeviceList.h provide PcapPlusPlus C++ wrapper for DPDK KNI (Kernel Network Interace) library (librte_kni). The main propose of the rte_kni library is to provide a way to forward packets received by DPDK application to Linux kernel (a.e. to processes that have opened some kind of a net socket) for further processing and to obtain packets from Linux kernel. The KNI device is the bridge that accomplish the translation between DPDK packets (mbuf) and Linux kernel/socket packets (skbuf). Currently KNI devices report speeds upto 10 GBit/s.
KNI device is a virtual network interface so it can be created and destroyed programmatically at will. As a real network interface KNI deivice must be managed appropriately like other interfaces. To start operate it MUST be given an IP address for example by the means of ip a command and MUST be put up for example by ip l set [interface] up.
Additionally KNI interfaces support 4 other settings (depends on DPDK version used): More...

#include <string>
#include "Device.h"
#include "MacAddress.h"
#include "MBufRawPacket.h"
#include "LinuxNicInformationSocket.h"

Go to the source code of this file.

Classes

class  pcpp::KniDevice
 
struct  pcpp::KniDevice::KniIoctlCallbacks
 New callbacks for KNI device events. This structure MUST be used ONLY when KniDeviceList::callbackVersion returns KniDeviceList::KniCallbackVersion::CALLBACKS_NEW. Or if You are sure that DPDK version used is 17.11 or higher. If some callback is not provided (NULL) the request will always succeeds if other is not specified in callback description. More...
 
struct  pcpp::KniDevice::KniOldIoctlCallbacks
 Old callbacks for KNI device events. This structure MUST be used ONLY when KniDeviceList::callbackVersion returns KniDeviceList::KniCallbackVersion::CALLBACKS_OLD. Or if You are sure that DPDK version used is lower than 17.11. If some callback is not provided (NULL) the request will always succeeds. More...
 
struct  pcpp::KniDevice::KniDeviceConfiguration
 KNI device initialization data. Used to create new KNI device. Usage of callbacks member or oldCallbacks member is defined by result of KniDeviceList::callbackVersion. More...
 

Namespaces

 pcpp
 The main namespace for the PcapPlusPlus lib.
 

Typedefs

typedef bool(* pcpp::OnKniPacketArriveCallback) (MBufRawPacket *packets, uint32_t numOfPackets, KniDevice *device, void *userCookie)
 

Detailed Description

This file and KniDeviceList.h provide PcapPlusPlus C++ wrapper for DPDK KNI (Kernel Network Interace) library (librte_kni). The main propose of the rte_kni library is to provide a way to forward packets received by DPDK application to Linux kernel (a.e. to processes that have opened some kind of a net socket) for further processing and to obtain packets from Linux kernel. The KNI device is the bridge that accomplish the translation between DPDK packets (mbuf) and Linux kernel/socket packets (skbuf). Currently KNI devices report speeds upto 10 GBit/s.
KNI device is a virtual network interface so it can be created and destroyed programmatically at will. As a real network interface KNI deivice must be managed appropriately like other interfaces. To start operate it MUST be given an IP address for example by the means of ip a command and MUST be put up for example by ip l set [interface] up.
Additionally KNI interfaces support 4 other settings (depends on DPDK version used):

  • change link state: ip l set [interface] up/down
  • change MTU: ip l set dev [interface] mtu [mtu_count]
  • change MAC address: ip l set [interface] address [new_mac]
  • change promiscuous mode: ip l set [interface] promisc on/off

Changes of each of this settings generates an event/request that must be handled by an application that have created the KNI device in 3 second period or it will be rejected and Linux kernel will not apply the change. The way that this requests MUST be handeled is defined by DPDK and so for each type of request the application tht creates the KNI device must provide the callback function to call. This callbacks are set in time of KNI device creation via KniIoctlCallbacks or KniOldIoctlCallbacks structures (the structure used is dependent on DPDK version).
There is a way to enable ethtool on KNI devices that include recompilation of DPDK and strict correspondence between KNI port id and DPDK port id, but it is not currently supported by PcapPlusPlus.

Known issues:

  • KNI device may not be able to set/update it's link status up (LINK_ERROR returned): The problem is laying in DPDK in rte_kni_update_link function (it is DPDK BUG if rte_kni_update_link is __rte_experimental). It is recommended to load rte_kni.ko module with "carrier=on" DPDK default is "carrier=off", provided setup-dpdk.sh by default loads with "carrier=on" if Your DPDK version supports it. The good indication of this issue are "DPDK KNI Failed to update links state for device" messages when Pcap++Test application is being run.
  • Packets may not be seen by applications that have open sockets on KNI device: Check your iptables settings and other packet filters - KNI device is traditional network device so all caveats apply;
  • I see a lot of unknown traffic - what is it? This must be Linux kernel trying to communicate with other devices from KNI device and it will do so as long as You give the KNI device any IP address via ip command or by record in /etc/networking/interfaces;
  • On old versions of DPDK only 4 KNI devices may be created: Yep this is a limitation. You can change MAX_KNI_DEVICES constant in KniDeviceList.cpp to unlock this limit;
  • Any set* method never succeeds: You may forgot that they generate KNI requests that Your application MUST handle. Just use KniDevice::startRequestHandlerThread to handle all requests automatically. Or user running the application don't have suitable access rights (must have CAP_NET_ADMIN).

Usefull links: