shill: vpn: Parse openvpn IP configuration options.
The options are pushed to shill over DBus through the .Task.notify service
method.
BUG=chromium-os:27056
TEST=unit tests
Change-Id: I98d7d49c275f49daba5a6dbe0af0878bf82038a6
Reviewed-on: https://gerrit.chromium.org/gerrit/17219
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/ip_address.cc b/ip_address.cc
index 1aa1111..8dda572 100644
--- a/ip_address.cc
+++ b/ip_address.cc
@@ -9,6 +9,8 @@
#include <string>
+#include <base/logging.h>
+
#include "shill/byte_string.h"
using std::string;
@@ -51,6 +53,28 @@
}
}
+// static
+int IPAddress::GetPrefixLengthFromMask(Family family, const string &mask) {
+ switch (family) {
+ case kFamilyIPv4: {
+ in_addr_t mask_val = inet_network(mask.c_str());
+ int subnet_cidr = 0;
+ while (mask_val) {
+ subnet_cidr++;
+ mask_val <<= 1;
+ }
+ return subnet_cidr;
+ }
+ case kFamilyIPv6:
+ NOTIMPLEMENTED();
+ break;
+ default:
+ LOG(WARNING) << "Unexpected address family: " << family;
+ break;
+ }
+ return 0;
+}
+
bool IPAddress::SetAddressFromString(const string &address_string) {
size_t address_length = GetAddressLength(family_);