Skip to content

Commit

Permalink
library: Export VPN configuration info to callers
Browse files Browse the repository at this point in the history
Make a new library call to obtain IP configuration and X-{CSTP,DTLS}-*
parameters.  Use the new call from main.c instead of directly accessing
the private vpninfo elements.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent d86782e commit 71099be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions libopenconnect.map.in
Expand Up @@ -47,6 +47,7 @@ OPENCONNECT_3.1 {
openconnect_set_server_cert_sha1;
openconnect_get_ifname;
openconnect_set_reqmtu;
openconnect_get_ip_info;
} OPENCONNECT_3.0;

OPENCONNECT_PRIVATE {
Expand Down
14 changes: 14 additions & 0 deletions library.c
Expand Up @@ -244,6 +244,20 @@ void openconnect_set_reqmtu(struct openconnect_info *vpninfo, int reqmtu)
vpninfo->reqmtu = reqmtu;
}

int openconnect_get_ip_info(struct openconnect_info *vpninfo,
const struct oc_ip_info **info,
const struct oc_vpn_option **cstp_options,
const struct oc_vpn_option **dtls_options)
{
if (info)
*info = &vpninfo->ip_info;
if (cstp_options)
*cstp_options = vpninfo->cstp_options;
if (dtls_options)
*dtls_options = vpninfo->dtls_options;
return 0;
}

void openconnect_setup_csd(struct openconnect_info *vpninfo, uid_t uid, int silent, char *wrapper)
{
vpninfo->uid_csd = uid;
Expand Down
8 changes: 5 additions & 3 deletions main.c
Expand Up @@ -510,6 +510,7 @@ int main(int argc, char **argv)
char *proxy = getenv("https_proxy");
int script_tun = 0;
char *vpnc_script = NULL, *ifname = NULL;
const struct oc_ip_info *ip_info;
int autoproxy = 0;
uid_t uid = getuid();
int opt;
Expand Down Expand Up @@ -932,11 +933,12 @@ int main(int argc, char **argv)
if (use_dtls && openconnect_setup_dtls(vpninfo, 60))
fprintf(stderr, _("Set up DTLS failed; using SSL instead\n"));

openconnect_get_ip_info(vpninfo, &ip_info, NULL, NULL);
vpn_progress(vpninfo, PRG_INFO,
_("Connected %s as %s%s%s, using %s\n"), openconnect_get_ifname(vpninfo),
vpninfo->ip_info.addr?:"",
(vpninfo->ip_info.addr6 && vpninfo->ip_info.addr) ? " + " : "",
vpninfo->ip_info.addr6 ? : "",
ip_info->addr?:"",
(ip_info->addr6 && ip_info->addr) ? " + " : "",
ip_info->addr6 ? : "",
(vpninfo->dtls_fd == -1) ?
(vpninfo->deflate ? "SSL + deflate" : "SSL")
: "DTLS");
Expand Down
9 changes: 9 additions & 0 deletions openconnect.h
Expand Up @@ -257,6 +257,15 @@ void openconnect_set_server_cert_sha1(struct openconnect_info *, char *);
const char *openconnect_get_ifname(struct openconnect_info *);
void openconnect_set_reqmtu(struct openconnect_info *, int reqmtu);

/* The returned structures are owned by the library and may be freed/replaced
due to rekey or reconnect. Assume that once the mainloop starts, the
pointers are no longer valid. For similar reasons, it is unsafe to call
this function from another thread. */
int openconnect_get_ip_info(struct openconnect_info *,
const struct oc_ip_info **info,
const struct oc_vpn_option **cstp_options,
const struct oc_vpn_option **dtls_options);

/* This is *not* yours and must not be destroyed with X509_free(). It
* will be valid when a cookie has been obtained successfully, and will
* be valid until the connection is destroyed or another attempt it made
Expand Down

0 comments on commit 71099be

Please sign in to comment.