Skip to content

Commit

Permalink
Make it possible to override getaddrinfo()
Browse files Browse the repository at this point in the history
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: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Mar 26, 2015
1 parent cda04d3 commit 6dab526
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions libopenconnect.map.in
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions library.c
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion openconnect.h
Expand Up @@ -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().
*
Expand Down Expand Up @@ -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__ */
5 changes: 4 additions & 1 deletion ssl.c
Expand Up @@ -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,
Expand Down

0 comments on commit 6dab526

Please sign in to comment.