@@ -105,6 +105,18 @@ namespace pcpp
105105 0x6D , 0x5A , 0x6D , 0x5A , 0x6D , 0x5A , 0x6D , 0x5A , 0x6D , 0x5A , 0x6D , 0x5A ,
106106 };
107107
108+ static bool getDeviceInfo (uint16_t devId, rte_eth_dev_info& devInfo)
109+ {
110+ auto ret = rte_eth_dev_info_get (devId, &devInfo);
111+ if (ret < 0 )
112+ {
113+ PCPP_LOG_ERROR (" Couldn't get device info, error was: " << rte_strerror (ret) << " (" << ret << " )" );
114+ return false ;
115+ }
116+
117+ return true ;
118+ }
119+
108120 DpdkDevice::DpdkDevice (int port, uint32_t mBufPoolSize , uint16_t mBufDataSize )
109121 : m_Id(port), m_MacAddress(MacAddress::Zero),
110122 m_MBufDataSize (mBufDataSize < 1 ? RTE_MBUF_DEFAULT_BUF_SIZE : mBufDataSize )
@@ -273,6 +285,8 @@ namespace pcpp
273285 {
274286 PCPP_LOG_DEBUG (" PMD '" << m_PMDName << " ' doesn't support RSS, setting RSS hash functions to 0" );
275287 m_Config.rssHashFunction = RSS_NONE;
288+ m_Config.rssKey = nullptr ;
289+ m_Config.rssKeyLength = 0 ;
276290 }
277291
278292 if (!isDeviceSupportRssHashFunction (getConfiguredRssHashFunction ()))
@@ -346,7 +360,11 @@ namespace pcpp
346360 bool DpdkDevice::initQueues (uint8_t numOfRxQueuesToInit, uint8_t numOfTxQueuesToInit)
347361 {
348362 rte_eth_dev_info devInfo;
349- rte_eth_dev_info_get (m_Id, &devInfo);
363+ if (!getDeviceInfo (m_Id, devInfo))
364+ {
365+ return false ;
366+ }
367+
350368 if (numOfRxQueuesToInit > devInfo.max_rx_queues )
351369 {
352370 PCPP_LOG_ERROR (" Num of RX queues requested for open [" << numOfRxQueuesToInit
@@ -500,7 +518,11 @@ namespace pcpp
500518 void DpdkDevice::setDeviceInfo ()
501519 {
502520 rte_eth_dev_info portInfo;
503- rte_eth_dev_info_get (m_Id, &portInfo);
521+ if (!getDeviceInfo (m_Id, portInfo))
522+ {
523+ return ;
524+ }
525+
504526 m_PMDName = std::string (portInfo.driver_name );
505527
506528 if (m_PMDName == " eth_bond" )
@@ -579,14 +601,22 @@ namespace pcpp
579601 }
580602 }
581603
582- void DpdkDevice::getLinkStatus (LinkStatus& linkStatus) const
604+ bool DpdkDevice::getLinkStatus (LinkStatus& linkStatus) const
583605 {
584606 struct rte_eth_link link;
585- rte_eth_link_get ((uint8_t )m_Id, &link);
607+ auto ret = rte_eth_link_get ((uint8_t )m_Id, &link);
608+ if (ret < 0 )
609+ {
610+ PCPP_LOG_ERROR (" Couldn't get link info, error was: " << rte_strerror (ret) << " (" << ret << " )" );
611+ return false ;
612+ }
613+
586614 linkStatus.linkUp = link.link_status ;
587615 linkStatus.linkSpeedMbps = (unsigned )link.link_speed ;
588616 linkStatus.linkDuplex =
589617 (link.link_duplex == DPDK_CONFIG_ETH_LINK_FULL_DUPLEX) ? LinkStatus::FULL_DUPLEX : LinkStatus::HALF_DUPLEX;
618+
619+ return true ;
590620 }
591621
592622 bool DpdkDevice::initCoreConfigurationByCoreMask (CoreMask coreMask)
@@ -1054,7 +1084,7 @@ namespace pcpp
10541084 return 0 ;
10551085 }
10561086
1057- rte_mbuf* mBufArr [MAX_BURST_SIZE];
1087+ rte_mbuf* mBufArr [MAX_BURST_SIZE] = {} ;
10581088
10591089 int packetIndex = 0 ;
10601090 int mBufArrIndex = 0 ;
@@ -1278,7 +1308,11 @@ namespace pcpp
12781308 if (rssHF == (uint64_t )-1 )
12791309 {
12801310 rte_eth_dev_info devInfo;
1281- rte_eth_dev_info_get (m_Id, &devInfo);
1311+ if (!getDeviceInfo (m_Id, devInfo))
1312+ {
1313+ return 0 ;
1314+ }
1315+
12821316 return devInfo.flow_type_rss_offloads ;
12831317 }
12841318
@@ -1424,15 +1458,21 @@ namespace pcpp
14241458 uint64_t dpdkRssHF = convertRssHfToDpdkRssHf (rssHFMask);
14251459
14261460 rte_eth_dev_info devInfo;
1427- rte_eth_dev_info_get (m_Id, &devInfo);
1461+ if (!getDeviceInfo (m_Id, devInfo))
1462+ {
1463+ return false ;
1464+ }
14281465
14291466 return ((devInfo.flow_type_rss_offloads & dpdkRssHF) == dpdkRssHF);
14301467 }
14311468
14321469 uint64_t DpdkDevice::getSupportedRssHashFunctions () const
14331470 {
14341471 rte_eth_dev_info devInfo;
1435- rte_eth_dev_info_get (m_Id, &devInfo);
1472+ if (!getDeviceInfo (m_Id, devInfo))
1473+ {
1474+ return 0 ;
1475+ }
14361476
14371477 return convertDpdkRssHfToRssHf (devInfo.flow_type_rss_offloads );
14381478 }
0 commit comments