Skip to content

Commit

Permalink
src/net_info: Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Insinger committed Aug 14, 2024
1 parent 401746d commit d407b8d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/eth_rxtx_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ struct AF_XDP_OPTS {

using NICType = EthRxTx<NIC_OPTS>;

// template class EthRxTx<AF_XDP_OPTS>;
// template class EthRxTx<I40E_OPTS>;
3 changes: 2 additions & 1 deletion src/dns_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ tl::expected<ResourceRecord, DNSParseError> ParseResourceRecord(std::span<const
r_data.tag = UNWRAP_OR_RETURN(
ParseFixedName<CAA_TAG_MAX_SIZE>(rdata_bytes, reader, tag_length));

if (contains_unprintable_chars_or_space(std::string_view(r_data.tag))) [[unlikely]]
if (contains_unprintable_chars_or_space(std::string_view(r_data.tag)))
[[unlikely]]
return tl::unexpected(DNSParseError::InvalidChar);

uint16_t value_len = rdata_bytes.end() - reader;
Expand Down
14 changes: 10 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ std::optional<UserConfig> InitConfigFromArgs(int argc, char** argv) {
auto& num_concurrent =
parser["num-concurrent"]
.abbreviation('c')
.description("max number of concurrent DNS requests\n (default: rate/5)")
.description("max number of concurrent DNS requests\n (default: rate)")
.type(po::u32)
.fallback(200);

Expand Down Expand Up @@ -819,9 +819,9 @@ int main(int argc, char** argv) {

// auto rxtx_if2 = ({
// tl::expected res =
// EthRxTx<I40E_OPTS>::init(eth_config2, "0000:2e:00.1", rxtx_pool.get());
// EthRxTx<I40E_OPTS>::init(eth_config2, "0000:2e:00.0", rxtx_pool.get());
// if (!res) {
// spdlog::error("Failed to initialize NIC: {}", res.error());
// fmt::print("{} Failed to initialize NIC: {}", error_str, res.error());
// return -1;
// }
// std::move(*res);
Expand All @@ -833,6 +833,9 @@ int main(int argc, char** argv) {
// uint64_t total_packets{};
// while (!stp.stop_requested()) {
// auto recvd = rxtx_if2.RcvPackets<RX_PKT_BURST>(0);
// if(recvd.size())
// spdlog::info("{}", recvd.size());

// for (auto& pkt : recvd) {
// auto eth_hdr = &pkt.data<struct rte_ether_hdr>();
// rte_ipv4_hdr* ipv4_hdr = (rte_ipv4_hdr*) (eth_hdr + 1);
Expand All @@ -849,7 +852,7 @@ int main(int argc, char** argv) {
// udp_hdr->dst_port = src_port_old;

// dns_hdr->qr = 1;
// dns_hdr->rcode = (unsigned char) DnsRCode::R_NXDOMAIN;
// dns_hdr->rcode = (unsigned char) DnsRCode::NXDOMAIN;

// pkt.l2_len = sizeof(rte_ether_hdr);
// pkt.l3_len = sizeof(rte_ipv4_hdr);
Expand All @@ -861,6 +864,8 @@ int main(int argc, char** argv) {
// .PreparePktCksums<DefaultPacket, L3Type::Ipv4, L4Type::UDP>(
// pkt);
// total_packets++;

// spdlog::info("a");
// }

// rxtx_if2.PreparePackets(0, recvd);
Expand Down Expand Up @@ -1050,6 +1055,7 @@ int main(int argc, char** argv) {
// std::cout << "\nRxTx if stats:\n\n";

rxtx_if.PrintStats();
// rxtx_if2.PrintStats();

std::cout << "\n\nRunning scanner took " << duration.count() << " ms\n";
}
9 changes: 5 additions & 4 deletions src/net_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ tl::expected<net_info::RouteInfo, std::string> net_info::get_route_info(

auto iface = UNWRAP_OR_RETURN(get_if_to_use(if_name, default_interface));

if (!routes_map.contains(iface))
return tl::unexpected(
fmt::format("Cannot find routes for interface {}", default_interface->c_str()));

close(sock);

if (!routes_map.contains(iface)) {
spdlog::warn("Cannot get routes for {}, returning empty RouteInfo", iface);
return net_info::RouteInfo{.if_name = iface};
}

return routes_map[iface];
}

Expand Down
8 changes: 4 additions & 4 deletions utils/dpdk_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,11 @@ class RTERing {

template <size_t N>
RTEMbufArray<Elem, N, type> dequeue_burst(size_t num = N) {
std::array<typename RTEMbufArray<Elem, N, type>::pointer, N> ptrs;
auto ptr = reinterpret_cast<void **>(ptrs.data());
auto res = rte_ring_dequeue_burst(ptr_, ptr, num, nullptr);
std::array<typename RTEMbufArray<Elem, N, type>::pointer, N> objs;
auto objs_ptr = reinterpret_cast<void **>(objs.data());
auto res = rte_ring_dequeue_burst(ptr_, objs_ptr, num, nullptr);

return RTEMbufArray<Elem, N, type>{mempool_, std::span{ptrs.begin(), res}};
return RTEMbufArray<Elem, N, type>{mempool_, std::span{objs.begin(), res}};
}

/**
Expand Down

0 comments on commit d407b8d

Please sign in to comment.