mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-06 00:00:03 +08:00
Add support to option "dhcp-option" in ovpn file
This commit is contained in:
@@ -59,6 +59,17 @@ namespace openvpn {
|
||||
{
|
||||
};
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
struct DhcpOptionEntry {
|
||||
std::string type;
|
||||
std::string address;
|
||||
};
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
struct DhcpOptionList : public std::vector<DhcpOptionEntry>
|
||||
{
|
||||
};
|
||||
|
||||
struct RemoteItem {
|
||||
std::string host;
|
||||
std::string port;
|
||||
@@ -283,6 +294,30 @@ namespace openvpn {
|
||||
}
|
||||
}
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
// dhpc-option
|
||||
{
|
||||
const OptionList::IndexList *dhcpList = options.get_index_ptr("dhcp-option");
|
||||
|
||||
if (dhcpList)
|
||||
{
|
||||
for (OptionList::IndexList::const_iterator i = dhcpList->begin(); i != dhcpList->end(); ++i)
|
||||
{
|
||||
const Option& o = options[*i];
|
||||
o.touch();
|
||||
|
||||
const std::string arg1 = o.get_optional(1, 256);
|
||||
const std::string arg2 = o.get_optional(2, 256);
|
||||
|
||||
DhcpOptionEntry dhcp;
|
||||
dhcp.type = arg1;
|
||||
dhcp.address = arg2;
|
||||
|
||||
dhcpOptionList_.push_back(std::move(dhcp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protocol configuration
|
||||
{
|
||||
protoConfig.reset(new ProtoContext::Config());
|
||||
@@ -435,6 +470,10 @@ namespace openvpn {
|
||||
|
||||
// return first remote directive in config
|
||||
const RemoteItem& firstRemoteListItem() const { return firstRemoteListItem_; }
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
// dhpc-option
|
||||
const DhcpOptionList& dhcpOptionList() const { return dhcpOptionList_; }
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
@@ -524,6 +563,18 @@ namespace openvpn {
|
||||
|
||||
root["mode"] = Json::Value("client");
|
||||
root["dev"] = Json::Value(dev);
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
root["dhcp-options"] = Json::Value(Json::arrayValue);
|
||||
for (size_t i = 0; i < dhcpOptionList_.size(); i++)
|
||||
{
|
||||
const DhcpOptionEntry& item = dhcpOptionList_[i];
|
||||
|
||||
Json::Value el = Json::Value(Json::objectValue);
|
||||
el["type"] = Json::Value(item.type);
|
||||
el["address"] = Json::Value(item.address);
|
||||
|
||||
root["dhcp-options"].append(el);
|
||||
}
|
||||
root["dev-type"] = Json::Value(protoConfig->layer.dev_type());
|
||||
root["remotes"] = Json::Value(Json::arrayValue);
|
||||
for (size_t i = 0; i < remoteList->size(); i++)
|
||||
@@ -716,6 +767,7 @@ namespace openvpn {
|
||||
ProtoContext::Config::Ptr protoConfig;
|
||||
SSLLib::SSLAPI::Config::Ptr sslConfig;
|
||||
std::string dev;
|
||||
DhcpOptionList dhcpOptionList_; // Added by Dener Araújo - 2020-09-06
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user