15#ifndef OPENVPN_CLIENT_UNIX_CMDAGENT_H
16#define OPENVPN_CLIENT_UNIX_CMDAGENT_H
31#define OVPNAGENT_NAME_STRING OPENVPN_STRINGIZE(OVPNAGENT_NAME)
33#define OVPNAGENT_NAME_STRING "ovpnagent"
54 std::ostringstream
os;
55 os <<
"UnixCommandAgent: transmitting bypass route to " <<
config.uds_name << std::endl;
58 Json::Value jreq(Json::objectValue);
59 jreq[
"pid"] = Json::Value(getpid());
60 jreq[
"host"] = Json::Value(endpoint.
to_string());
61 jreq[
"ipv6"] = Json::Value(endpoint.
is_ipv6());
62 const std::string jtxt = jreq.toStyledString();
71 return ts->http_status_success();
75 struct Config :
public RC<thread_unsafe_refcount>
102 hc->connect_timeout = 10;
103 hc->general_timeout = 60;
106 ts->host.host =
host;
107 ts->host.port =
"unix";
108 ts->http_config = hc;
109 ts->debug_level = debug_level;
114 if (sock.peercreds(creds))
127 const std::string &content,
128 const bool keepalive,
132 t->req.method =
"POST";
133 t->req.uri =
"/" + method;
134 t->ci.keepalive = keepalive;
135 t->ci.type =
"application/json";
137 ts->transactions.push_back(std::move(t));
144 std::ostream &
os)
override
146 os <<
"SetupClient: transmitting tun setup list to " <<
config->uds_name << std::endl;
149 Json::Value jreq(Json::objectValue);
150 jreq[
"pid"] = Json::Value(getpid());
154 Json::Value jconf = tbs_config->
to_json();
156 jreq[
"config"] = std::move(jconf);
158 const std::string jtxt = jreq.toStyledString();
168 if (!ts.http_status_success())
173 const int fd = ts.hsc.unix_fd();
186 catch (
const std::exception &e)
203 const Json::Value &jconf = jres[
"config"];
204 os << jconf.toStyledString();
218 os <<
"SetupClient: transmitting tun destroy request to " <<
config->uds_name << std::endl;
226 t->req.method =
"GET";
227 t->req.uri =
"/tun-destroy";
228 ts->transactions.push_back(std::move(t));
246 throw ovpnagent(
"unexpected transaction set size");
265 throw ovpnagent(
"unexpected content-type");
272 if (!jres.isObject())
273 throw ovpnagent(
"returned JSON content is not a dictionary");
276 catch (
const json::json_parse &e)
std::string to_string() const
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
void reset(const int fd_arg)
Json::Value to_json() const
Serializes the tunnel configuration to a JSON object.
void destroy(std::ostream &os) override
SetupClient(const Config::Ptr &config_arg)
int establish(const TunBuilderCapture &pull, TunBuilderSetup::Config *tbs_config, Stop *stop, std::ostream &os) override
Json::Value get_json_result(std::ostream &os, WS::ClientSet::TransactionSet &ts)
static void make_transaction(const std::string &method, const std::string &content, const bool keepalive, WS::ClientSet::TransactionSet::Ptr ts)
static WS::ClientSet::TransactionSet::Ptr new_transaction_set(const std::string &host, int debug_level)
static TunBuilderSetup::Factory::Ptr new_agent(const OptionList &opt)
RCPtr< UnixCommandAgent > Ptr
TunBuilderSetup::Base::Ptr new_setup_obj() override
OPENVPN_EXCEPTION(ovpnagent)
static bool add_bypass_route(IP::Addr endpoint)
UnixCommandAgent(const OptionList &opt_parent)
static void new_request_synchronous(const TransactionSet::Ptr ts, Stop *stop=nullptr, RandomAPI *prng=nullptr, const bool sps=false)
static int recv_fd(const int sock_fd, std::string &message, const size_t buf_size, const int timeout_ms)
static void xmit_fd(const int sock_fd, const int payload_fd, const std::string &message, const int timeout_ms)
#define OPENVPN_THROW_EXCEPTION(stuff)
#define OPENVPN_THROW(exc, stuff)
#define OPENVPN_LOG(args)
int ovpnagent(const char *sock_fn, const char *log_fn, const bool log_append, const char *pid_fn, const char *user, const char *group)
Json::Value parse(const std::string &str, const TITLE &title)
std::string get_string(const Json::Value &root, const NAME &name, const TITLE &title)
Frame::Ptr frame_init_simple(const size_t payload)
BufferPtr buf_from_string(const std::string &str)
std::string to_string() const
virtual Json::Value to_json()=0
virtual void from_json(const Json::Value &root, const std::string &title)=0
bool request_status_success() const
std::string format_status(const TransactionSet &ts) const
bool comm_status_success() const
#define OVPNAGENT_NAME_STRING