Skip to content

Commit 9152c9f

Browse files
committed
router: do not add route to local (connected) network for /32 addresses
1 parent 079dbf1 commit 9152c9f

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

src/services/pcn-router/src/Router.cpp

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -549,45 +549,43 @@ void Router::add_local_route(const std::string &interface_ip,
549549
"Added route [network: {0}/32 - nexthop: {1} - interface: {2}]",
550550
ip_route, "0.0.0.0", port_name);
551551

552-
/*
553-
* Add a route to the local network, i.e., to the network directly reachable
554-
* through the inteface
555-
*/
556-
557-
// Add the route in the fast path
558-
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
559-
ip_string_to_nbo_uint(netmask_route);
560-
std::string network = nbo_uint_to_ip_string(networkDec);
561-
rt_k key2{
562-
.netmask_len = get_netmask_length(netmask_route),
563-
.network = networkDec,
564-
};
565-
566-
rt_v value2{
567-
.port = uint32_t(port_index),
568-
.nexthop = 0, /* 0.0.0.0 */
569-
.type = TYPE_NOLOCALINTERFACE,
570-
};
571-
572-
routing_table.set(key2, value2);
573-
574-
logger()->info(
575-
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
576-
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);
577-
578-
// Add the route in the table of the control plane
579-
580-
std::string nexthop("local");
581-
std::string route = network + "/" +
582-
std::to_string(get_netmask_length(netmask_route));
583-
std::tuple<string, string> keyF(route, nexthop);
584-
uint32_t pathcost = 0;
585-
586-
routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
587-
std::forward_as_tuple(*this, route, nexthop,
588-
port_name, pathcost));
589-
590-
// FIXME: add also the /32 route?
552+
// If the new address is not a /32, add a route to the local network
553+
// (i.e. the network directly reachable through the inteface)
554+
if (netmask_route != "255.255.255.255") {
555+
556+
// Add the route in the fast path
557+
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
558+
ip_string_to_nbo_uint(netmask_route);
559+
std::string network = nbo_uint_to_ip_string(networkDec);
560+
rt_k key2{
561+
.netmask_len = get_netmask_length(netmask_route),
562+
.network = networkDec,
563+
};
564+
565+
rt_v value2{
566+
.port = uint32_t(port_index),
567+
.nexthop = 0, /* 0.0.0.0 */
568+
.type = TYPE_NOLOCALINTERFACE,
569+
};
570+
571+
routing_table.set(key2, value2);
572+
573+
logger()->info(
574+
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
575+
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);
576+
577+
// Add the route in the table of the control plane
578+
579+
std::string nexthop("local");
580+
std::string route = network + "/" +
581+
std::to_string(get_netmask_length(netmask_route));
582+
std::tuple<string, string> keyF(route, nexthop);
583+
uint32_t pathcost = 0;
584+
585+
routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
586+
std::forward_as_tuple(*this, route, nexthop,
587+
port_name, pathcost));
588+
}
591589
}
592590

593591
/*

0 commit comments

Comments
 (0)