Skip to content

Commit

Permalink
Added the ability to use random source address in route tunnel
Browse files Browse the repository at this point in the history
A similar feature was available in tun64 and balancer. The ipv6 src address
from 65 to 96 bits is written to the ipv4 src of the original packet.
  • Loading branch information
stal76 committed Dec 15, 2024
1 parent 20ad724 commit c9f0cbb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class config_t
std::set<common::ip_prefix_t> local_prefixes; ///< for fallback to default
std::map<uint32_t, std::string> peers;
std::map<std::string, interface_t> interfaces;
bool random_source{};
};

}
Expand Down
3 changes: 2 additions & 1 deletion common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ namespace update_route
{
using tunnel = std::tuple<ipv4_address_t, ///< ipv4AddressSource
ipv6_address_t, ///< ipv6AddressSource
uint16_t>; ///< udpDestinationPort
uint16_t, ///< udpDestinationPort
bool>; ///< srcRndEnabled

using request = std::tuple<tRouteId,
std::optional<tunnel>>;
Expand Down
3 changes: 2 additions & 1 deletion controlplane/configconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ void config_converter_t::serializeRoutes()
{
tunnel = {route.ipv4_source_address,
route.ipv6_source_address,
route.udp_destination_port};
route.udp_destination_port,
route.random_source};
}

globalbase.emplace_back(common::idp::updateGlobalBase::requestType::update_route,
Expand Down
5 changes: 5 additions & 0 deletions controlplane/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ void config_parser_t::loadConfig_route(controlplane::base_t& baseNext,
route.tunnel_enabled = false;
}

if (exist(moduleJson, "random_source"))
{
route.random_source = moduleJson["random_source"].get<bool>();
}

//

route.routeId = routeId;
Expand Down
3 changes: 2 additions & 1 deletion dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,12 @@ eResult generation::update_route(const common::idp::updateGlobalBase::update_rou

if (tunnel)
{
const auto& [ipv4AddressSource, ipv6AddressSource, udpDestinationPort] = *tunnel;
const auto& [ipv4AddressSource, ipv6AddressSource, udpDestinationPort, randomSource] = *tunnel;

route.ipv4AddressSource = ipv4_address_t::convert(ipv4AddressSource);
route.ipv6AddressSource = ipv6_address_t::convert(ipv6AddressSource);
route.udpDestinationPort = rte_cpu_to_be_16(udpDestinationPort);
route.randomSource = randomSource;
}

return eResult::success;
Expand Down
1 change: 1 addition & 0 deletions dataplane/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ struct route_t
ipv4_address_t ipv4AddressSource;
ipv6_address_t ipv6AddressSource;
uint16_t udpDestinationPort;
bool randomSource;
};

struct tInterface
Expand Down
7 changes: 7 additions & 0 deletions dataplane/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2761,12 +2761,14 @@ inline void cWorker::route_tunnel_nexthop(rte_mbuf* mbuf,
{
uint32_t vtc_flow = 0;
uint16_t payload_len = 0;
uint32_t ipv4_src_addr;
if (is_ipv4)
{
rte_ipv4_hdr* ipv4HeaderInner = rte_pktmbuf_mtod_offset(mbuf, rte_ipv4_hdr*, metadata->network_headerOffset);
vtc_flow = rte_cpu_to_be_32((0x6 << 28) | (ipv4HeaderInner->type_of_service << 20)); ///< @todo: flow label
payload_len = rte_cpu_to_be_16((is_ipip_tunnel ? 0 : sizeof(rte_udp_hdr) + YADECAP_MPLS_HEADER_SIZE) + rte_be_to_cpu_16(ipv4HeaderInner->total_length));
payload_length = rte_be_to_cpu_16(ipv4HeaderInner->total_length);
ipv4_src_addr = ipv4HeaderInner->src_addr;
}
else
{
Expand Down Expand Up @@ -2797,6 +2799,11 @@ inline void cWorker::route_tunnel_nexthop(rte_mbuf* mbuf,
rte_memcpy(ipv6Header->src_addr, route.ipv6AddressSource.bytes, 16);
rte_memcpy(ipv6Header->dst_addr, nexthop.nexthop_address.bytes, 16);

if (route.randomSource && is_ipv4)
{
((uint32_t*)ipv6Header->src_addr)[2] = ipv4_src_addr;
}

metadata->transport_headerOffset = metadata->network_headerOffset + sizeof(rte_ipv6_hdr);
}

Expand Down

0 comments on commit c9f0cbb

Please sign in to comment.