Commit 6dab526c authored by David Woodhouse's avatar David Woodhouse

Make it possible to override getaddrinfo()

This will be used for implementing a '--resolve HOSTNAME:IP' argument to
allow bypassing DNS lookups while still putting the appropriate hostname
into SNI (which is important when proxies are routing requests based on
SNI).

Some fixes from David Ocon.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent cda04d3b
......@@ -73,6 +73,11 @@ OPENCONNECT_5_2 {
openconnect_set_http_auth;
} OPENCONNECT_5_1;
OPENCONNECT_5_3 {
global:
openconnect_override_getaddrinfo;
} OPENCONNECT_5_2;
OPENCONNECT_PRIVATE {
global: @SYMVER_TIME@ @SYMVER_GETLINE@ @SYMVER_JAVA@ @SYMVER_ASPRINTF@ @SYMVER_VASPRINTF@ @SYMVER_WIN32_STRERROR@
openconnect_fopen_utf8;
......
......@@ -754,6 +754,11 @@ void openconnect_set_protect_socket_handler(struct openconnect_info *vpninfo,
vpninfo->protect_socket = protect_socket;
}
void openconnect_override_getaddrinfo(struct openconnect_info *vpninfo, openconnect_getaddrinfo_vfn gai_fn)
{
vpninfo->getaddrinfo_override = gai_fn;
}
void openconnect_set_stats_handler(struct openconnect_info *vpninfo,
openconnect_stats_vfn stats_handler)
{
......
......@@ -600,6 +600,7 @@ struct openconnect_info {
openconnect_process_auth_form_vfn process_auth_form;
openconnect_progress_vfn progress;
openconnect_protect_socket_vfn protect_socket;
openconnect_getaddrinfo_vfn getaddrinfo_override;
int (*ssl_read)(struct openconnect_info *vpninfo, char *buf, size_t len);
int (*ssl_gets)(struct openconnect_info *vpninfo, char *buf, size_t len);
......
......@@ -29,9 +29,12 @@
#endif
#define OPENCONNECT_API_VERSION_MAJOR 5
#define OPENCONNECT_API_VERSION_MINOR 1
#define OPENCONNECT_API_VERSION_MINOR 3
/*
* API version 5.3:
* - Add openconnect_override_getaddrinfo().
*
* API version 5.2:
* - Add openconnect_set_http_auth(), openconnect_set_protocol().
*
......@@ -575,4 +578,9 @@ int openconnect_has_system_key_support(void);
int openconnect_set_protocol(struct openconnect_info *vpninfo, const char *protocol);
struct addrinfo;
typedef int (*openconnect_getaddrinfo_vfn) (void *privdata, const char *nost, const char *service,
const struct addrinfo *hints, struct addrinfo **res);
void openconnect_override_getaddrinfo(struct openconnect_info *vpninfo, openconnect_getaddrinfo_vfn gai_fn);
#endif /* __OPENCONNECT_H__ */
......@@ -247,7 +247,10 @@ int connect_https_socket(struct openconnect_info *vpninfo)
hints.ai_flags |= AI_NUMERICHOST;
}
err = getaddrinfo(hostname, port, &hints, &result);
if (vpninfo->getaddrinfo_override)
err = vpninfo->getaddrinfo_override(vpninfo->cbdata, hostname, port, &hints, &result);
else
err = getaddrinfo(hostname, port, &hints, &result);
if (err) {
vpn_progress(vpninfo, PRG_ERR,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment