resolv-retry w/ multiple remote arguments
A message that is not in the archive (sent off-list or not yet received): [email protected]...
A message that is not in the archive (sent off-list or not yet received): [email protected]...
I'm trying to put together a patch to implement my desired behaviour wrt resolv-retry and multiple remote hosts.
So far, I've made the following changes:
Setting the default resolv-retry count:
* Create a new constant, RESOLV_RETRY_UNSET
* Initialize resolve_retry_seconds to RESOLV_RETRY_UNSET rather than RESOLV_RETRY_INFINITE
* In options_postprocess(), set resolve_retry_seconds appropriately based on the number of remote hosts provided
Retrying on DNS failures with resolv-retry 0 and multiple hosts:
* Modify resolve_remote() to accept a boolean argument multiple_remotes
* In the phase-specific handlers within that same function, treat multiple_remotes as an alternative to resolve_retry_seconds when determining whether GETADDR_FATAL and GETADDR_MENTION_RESOLVE_RETRY should be set (in phase 1) and whether to fail out with an assertion error (in phase 2).
Thing is, this doesn't actually work: When I run it in a test case in with the first remote specified by DNS and the second host specified by IP, it tries to resolve the first host in phase 1; fails; tries again in phase 2; and fails again (fatally, there, because GETADDR_FATAL is set).
I presume that it's supposed to loop around to trying phase1 with the next host if getaddr fails (on account of using all the available retries on the current host) rather than proceeding to phase 2 -- but what's the mechanism?
My work-in-progress, known-broken patch is attached, just for reference.
init.c +2 -1
@@ -1687,7 +1687,8 @@ do_init_socket_2 (struct context *c) {link_socket_init_phase2 (c->c2.link_socket, &c->c2.frame, - &c->sig->signal_received); + &c->sig->signal_received, +remote_list_len (c->c1.remote_list) >1 ); }/*
options.c +14 -1
@@ -533,7 +533,7 @@ o->mtu_discover_type =-1 ; o->mssfix =MSSFIX_DEFAULT ; o->route_delay_window =30 ; - o->resolve_retry_seconds =RESOLV_RETRY_INFINITE ; + o->resolve_retry_seconds =RESOLV_RETRY_UNSET ;#ifdef ENABLE_OCC o->occ = true;#endif
@@ -1203,6 +1203,19 @@ }/* +* Set resolv_retry value if not provided +*/ +if ((options->resolve_retry_seconds ==RESOLV_RETRY_UNSET ) && + (remote_list_len (options->remote_list) >1 )) + { + options->resolve_retry_seconds =RESOLV_RETRY_INFINITE ; + } +else + { + options->resolve_retry_seconds =0 ; + } + +/* * If --mssfix is supplied without a parameter, default * it to --fragment value, if --fragment is specified. */
socket.c +9 -7
@@ -746,7 +746,8 @@ resolve_remote (struct link_socket *sock, int phase, const char **remote_dynamic, - volatile int *signal_received) + volatile int *signal_received, + bool multiple_remotes) { struct gc_arena gc = gc_new ();
@@ -766,7 +767,7 @@if (phase ==1 ) { -if (sock->resolve_retry_seconds) +if (sock->resolve_retry_seconds || multiple_remotes) { flags =GETADDR_RESOLVE ; retry =0 ;
@@ -779,7 +780,7 @@ }else if (phase ==2 ) { -if (sock->resolve_retry_seconds) +if (sock->resolve_retry_seconds || multiple_remotes) { flags =GETADDR_RESOLVE |GETADDR_FATAL ; retry = sock->resolve_retry_seconds;
@@ -1007,7 +1008,7 @@ {create_socket (sock);resolve_bind_local (sock); -resolve_remote (sock,1 ,NULL ,NULL ); +resolve_remote (sock,1 ,NULL ,NULL , (remote_list_len (remote_list) >1 )); } }
@@ -1015,7 +1016,8 @@void link_socket_init_phase2 (struct link_socket *sock,const struct frame *frame, -volatile int *signal_received) +volatile int *signal_received, +bool multiple_remotes) {struct gc_arena gc =gc_new ();const char *remote_dynamic =NULL ;
@@ -1053,7 +1055,7 @@ }else { -resolve_remote (sock,2 , &remote_dynamic, signal_received); +resolve_remote (sock,2 , &remote_dynamic, signal_received, multiple_remotes);if (*signal_received) goto done;
@@ -1159,7 +1161,7 @@ sock->info.lsa->actual.sin_addr.s_addr =0 ; sock->info.lsa->remote.sin_addr.s_addr =0 ; -resolve_remote (sock,1 ,NULL , signal_received); +resolve_remote (sock,1 ,NULL , signal_received, multiple_remotes);if (*signal_received) goto done;
socket.h +3 -1
@@ -47,6 +47,7 @@* represents. */ #define RESOLV_RETRY_INFINITE 1000000000 +#define RESOLV_RETRY_UNSET 999999999#define REMOTE_LIST_SIZE 64
@@ -281,7 +282,8 @@void link_socket_init_phase2 (struct link_socket *sock,const struct frame *frame, -volatile int *signal_received); +volatile int *signal_received, +bool multiple_remotes);void link_socket_post_fork (const struct link_socket *sock,const struct sockaddr_in *remote);
Quoted 26 lines · Charles Duffy
I'm trying to put together a patch to implement my desired behaviour wrt resolv-retry and multiple remote hosts.
So far, I've made the following changes:
Setting the default resolv-retry count:
* Create a new constant,RESOLV_RETRY_UNSET
* Initializeresolve_retry_secondstoRESOLV_RETRY_UNSETrather thanRESOLV_RETRY_INFINITE
* Inoptions_postprocess(), setresolve_retry_secondsappropriately based on the number of remote hosts providedRetrying on DNS failures with resolv-retry 0 and multiple hosts:
* Modifyresolve_remote()to accept a boolean argumentmultiple_remotes
* In the phase-specific handlers within that same function, treatmultiple_remotesas an alternative toresolve_retry_secondswhen determining whetherGETADDR_FATALandGETADDR_MENTION_RESOLVE_RETRYshould be set (in phase 1) and whether to fail out with an assertion error (in phase 2).Thing is, this doesn't actually work: When I run it in a test case in with the first remote specified by DNS and the second host specified by IP, it tries to resolve the first host in phase 1; fails; tries again in phase 2; and fails again (fatally, there, because
GETADDR_FATALis set).
Quoted 4 lines
I presume that it's supposed to loop around to trying phase1 with the next host if getaddr fails (on account of using all the available retries on the current host) rather than proceeding to phase 2 -- but what's the mechanism?
Not really. phase1 and phase2 are meant to be called only once per restart.
I would take a different approach (see attached patch). Rather than change the defaulting of resolve_retry_seconds, I would just change the interpretation of RESOLV_RETRY_INFINITE when the remote list > 1 to something that makes more sense, i.e. apply the infinite timeout to the list as a whole, but resolve each list member with GETADDR_TRY_ONCE.
James
socket.c +9 -2
@@ -94,7 +94,7 @@if (status !=OIA_IP )/* parse as IP address failed? */ {const int fail_wait_interval =5 ;/* seconds */ -int resolve_retries = resolve_retry_seconds / fail_wait_interval; +int resolve_retries = (flags &GETADDR_TRY_ONCE ) ?1 : (resolve_retry_seconds / fail_wait_interval);struct hostent *h;const char *fmt;int level =0 ;
@@ -764,7 +764,14 @@int retry =0 ;bool status = false; -if (phase ==1 ) +if (remote_list_len (sock->remote_list) >1 && sock->resolve_retry_seconds ==RESOLV_RETRY_INFINITE ) + { + flags =GETADDR_RESOLVE ; +if (phase ==2 ) + flags |= (GETADDR_TRY_ONCE |GETADDR_FATAL ); + retry =0 ; + } +else if (phase ==1 ) {if (sock->resolve_retry_seconds) {
socket.h +1 -0
@@ -363,6 +363,7 @@#define GETADDR_FATAL_ON_SIGNAL (1<<4)#define GETADDR_WARN_ON_SIGNAL (1<<5)#define GETADDR_MSG_VIRT_OUT (1<<6) +#define GETADDR_TRY_ONCE (1<<7) in_addr_t getaddr (unsigned int flags, const char *hostname,