mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-06-01 00:00:02 +08:00
Add support to option "dhcp-option" in ovpn file
This commit is contained in:
@@ -663,6 +663,14 @@ namespace openvpn {
|
||||
se.friendlyName = i->friendlyName;
|
||||
eval.serverList.push_back(se);
|
||||
}
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
for (ParseClientConfig::DhcpOptionList::const_iterator i = cc.dhcpOptionList().begin(); i != cc.dhcpOptionList().end(); ++i)
|
||||
{
|
||||
DhcpOptionEntry de;
|
||||
de.type = i->type;
|
||||
de.address = i->address;
|
||||
eval.dhcpOptionList.push_back(de);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,15 @@ namespace openvpn {
|
||||
std::string friendlyName;
|
||||
};
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
// Represents an "dhcp-option" with its type (DNS, WINS, etc) and its address
|
||||
// (client reads)
|
||||
struct DhcpOptionEntry
|
||||
{
|
||||
std::string type;
|
||||
std::string address;
|
||||
};
|
||||
|
||||
// return properties of config
|
||||
// (client reads)
|
||||
struct EvalConfig
|
||||
@@ -91,6 +100,10 @@ namespace openvpn {
|
||||
|
||||
// optional list of user-selectable VPN servers
|
||||
std::vector<ServerEntry> serverList;
|
||||
|
||||
// Added by Dener Araújo - 2020-09-06
|
||||
// optional list of "dhcp-option"
|
||||
std::vector<DhcpOptionEntry> dhcpOptionList;
|
||||
};
|
||||
|
||||
// used to pass credentials to VPN core
|
||||
|
||||
@@ -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