shill: vpn: Create a IPv6 blackhole route for IPv4 L2TP/IPsec VPN.
BUG=chromium-os:34383
TEST=Tested the following:
1. Build and run unit tests.
2. Manually test IPv4 LT2P/IPsec VPN on an network interface with IPv4
and IPv6 addresses as follows:
- Before connecting to the VPN, run `ip -6 route` to verify that no
blackhole route exists. Confirm via http://ipv6test.google.com that
IPv6 connectivity is available.
- After connecting to the VPN, run `ip -6 route` to verify that the
blackhole route is installed. Confirm via
http://ipv6test.google.com that IPv6 connectivity is not available.
- After disconnecting from the VPN, run `ip -6 route` to verify that
no blackhole route exists. Confirm via http://ipv6test.google.com
that IPv6 connectivity is available.
Change-Id: I7ae4fab5319b5f06a6a3f5a28f439551f2825044
Reviewed-on: https://gerrit.chromium.org/gerrit/34053
Commit-Ready: Ben Chan <benchan@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
diff --git a/routing_table.cc b/routing_table.cc
index a3418f5..31f2096 100644
--- a/routing_table.cc
+++ b/routing_table.cc
@@ -532,6 +532,41 @@
return true;
}
+bool RoutingTable::CreateBlackholeRoute(int interface_index,
+ const IPAddress::Family &family,
+ uint32 metric) {
+
+ SLOG(Route, 2) << base::StringPrintf(
+ "%s: index %d family %s metric %d",
+ __func__, interface_index,
+ IPAddress::GetAddressFamilyName(family).c_str(), metric);
+
+ RTNLMessage message(
+ RTNLMessage::kTypeRoute,
+ RTNLMessage::kModeAdd,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL,
+ 0,
+ 0,
+ 0,
+ family);
+
+ message.set_route_status(RTNLMessage::RouteStatus(
+ 0,
+ 0,
+ RT_TABLE_MAIN,
+ RTPROT_BOOT,
+ RT_SCOPE_UNIVERSE,
+ RTN_BLACKHOLE,
+ 0));
+
+ message.SetAttribute(RTA_PRIORITY,
+ ByteString::CreateFromCPUUInt32(metric));
+ message.SetAttribute(RTA_OIF,
+ ByteString::CreateFromCPUUInt32(interface_index));
+
+ return rtnl_handler_->SendMessage(&message);
+}
+
bool RoutingTable::CreateLinkRoute(int interface_index,
const IPAddress &local_address,
const IPAddress &remote_address) {