@ -83,6 +83,11 @@ void towire_wireaddr_internal(u8 **pptr, const struct wireaddr_internal *addr)
case ADDR_INTERNAL_WIREADDR :
case ADDR_INTERNAL_WIREADDR :
towire_wireaddr ( pptr , & addr - > u . wireaddr ) ;
towire_wireaddr ( pptr , & addr - > u . wireaddr ) ;
return ;
return ;
case ADDR_INTERNAL_FORPROXY :
towire_u8_array ( pptr , ( const u8 * ) addr - > u . unresolved . name ,
sizeof ( addr - > u . unresolved . name ) ) ;
towire_u16 ( pptr , addr - > u . unresolved . port ) ;
return ;
}
}
abort ( ) ;
abort ( ) ;
}
}
@ -106,6 +111,15 @@ bool fromwire_wireaddr_internal(const u8 **cursor, size_t *max,
return fromwire_wireaddr ( cursor , max , & addr - > u . torservice ) ;
return fromwire_wireaddr ( cursor , max , & addr - > u . torservice ) ;
case ADDR_INTERNAL_WIREADDR :
case ADDR_INTERNAL_WIREADDR :
return fromwire_wireaddr ( cursor , max , & addr - > u . wireaddr ) ;
return fromwire_wireaddr ( cursor , max , & addr - > u . wireaddr ) ;
case ADDR_INTERNAL_FORPROXY :
fromwire_u8_array ( cursor , max , ( u8 * ) addr - > u . unresolved . name ,
sizeof ( addr - > u . unresolved . name ) ) ;
/* Must be NUL terminated */
if ( ! memchr ( addr - > u . unresolved . name , 0 ,
sizeof ( addr - > u . unresolved . name ) ) )
fromwire_fail ( cursor , max ) ;
addr - > u . unresolved . port = fromwire_u16 ( cursor , max ) ;
return * cursor ! = NULL ;
}
}
fromwire_fail ( cursor , max ) ;
fromwire_fail ( cursor , max ) ;
return false ;
return false ;
@ -179,6 +193,9 @@ char *fmt_wireaddr_internal(const tal_t *ctx,
return tal_fmt ( ctx , " :%u " , a - > u . port ) ;
return tal_fmt ( ctx , " :%u " , a - > u . port ) ;
case ADDR_INTERNAL_WIREADDR :
case ADDR_INTERNAL_WIREADDR :
return fmt_wireaddr ( ctx , & a - > u . wireaddr ) ;
return fmt_wireaddr ( ctx , & a - > u . wireaddr ) ;
case ADDR_INTERNAL_FORPROXY :
return tal_fmt ( ctx , " %s:%u " ,
a - > u . unresolved . name , a - > u . unresolved . port ) ;
case ADDR_INTERNAL_AUTOTOR :
case ADDR_INTERNAL_AUTOTOR :
return tal_fmt ( ctx , " autotor:%s " ,
return tal_fmt ( ctx , " autotor:%s " ,
fmt_wireaddr ( tmpctx , & a - > u . torservice ) ) ;
fmt_wireaddr ( tmpctx , & a - > u . torservice ) ) ;
@ -383,11 +400,12 @@ finish:
bool parse_wireaddr_internal ( const char * arg , struct wireaddr_internal * addr ,
bool parse_wireaddr_internal ( const char * arg , struct wireaddr_internal * addr ,
u16 port , bool wildcard_ok , bool dns_ok ,
u16 port , bool wildcard_ok , bool dns_ok ,
bool unresolved_ok ,
const char * * err_msg )
const char * * err_msg )
{
{
u16 wild port;
u16 split port;
char * ip ;
char * ip ;
bool needed_dns ;
bool needed_dns = false ;
/* Addresses starting with '/' are local socket paths */
/* Addresses starting with '/' are local socket paths */
if ( arg [ 0 ] = = ' / ' ) {
if ( arg [ 0 ] = = ' / ' ) {
@ -405,12 +423,12 @@ bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr,
/* An empty string means IPv4 and IPv6 (which under Linux by default
/* An empty string means IPv4 and IPv6 (which under Linux by default
* means just IPv6 , and IPv4 gets autobound ) . */
* means just IPv6 , and IPv4 gets autobound ) . */
wild port = port ;
split port = port ;
if ( wildcard_ok
if ( wildcard_ok
& & separate_address_and_port ( tmpctx , arg , & ip , & wild port)
& & separate_address_and_port ( tmpctx , arg , & ip , & split port)
& & streq ( ip , " " ) ) {
& & streq ( ip , " " ) ) {
addr - > itype = ADDR_INTERNAL_ALLPROTO ;
addr - > itype = ADDR_INTERNAL_ALLPROTO ;
addr - > u . port = wild port;
addr - > u . port = split port;
return true ;
return true ;
}
}
@ -425,8 +443,33 @@ bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr,
}
}
addr - > itype = ADDR_INTERNAL_WIREADDR ;
addr - > itype = ADDR_INTERNAL_WIREADDR ;
return parse_wireaddr ( arg , & addr - > u . wireaddr , port ,
if ( parse_wireaddr ( arg , & addr - > u . wireaddr , port ,
dns_ok ? NULL : & needed_dns , err_msg ) ;
dns_ok ? NULL : & needed_dns , err_msg ) )
return true ;
if ( ! needed_dns | | ! unresolved_ok )
return false ;
/* We can't do DNS, so keep unresolved. */
if ( ! wireaddr_from_unresolved ( addr , ip , splitport ) ) {
if ( err_msg )
* err_msg = " Name too long " ;
return false ;
}
return true ;
}
bool wireaddr_from_unresolved ( struct wireaddr_internal * addr ,
const char * name , u16 port )
{
addr - > itype = ADDR_INTERNAL_FORPROXY ;
if ( strlen ( name ) > = sizeof ( addr - > u . unresolved . name ) )
return false ;
memset ( addr - > u . unresolved . name , 0 , sizeof ( addr - > u . unresolved . name ) ) ;
strcpy ( addr - > u . unresolved . name , name ) ;
addr - > u . unresolved . port = port ;
return true ;
}
}
void wireaddr_from_sockname ( struct wireaddr_internal * addr ,
void wireaddr_from_sockname ( struct wireaddr_internal * addr ,
@ -466,6 +509,7 @@ struct addrinfo *wireaddr_internal_to_addrinfo(const tal_t *ctx,
return ai ;
return ai ;
case ADDR_INTERNAL_ALLPROTO :
case ADDR_INTERNAL_ALLPROTO :
case ADDR_INTERNAL_AUTOTOR :
case ADDR_INTERNAL_AUTOTOR :
case ADDR_INTERNAL_FORPROXY :
break ;
break ;
case ADDR_INTERNAL_WIREADDR :
case ADDR_INTERNAL_WIREADDR :
return wireaddr_to_addrinfo ( ctx , & wireaddr - > u . wireaddr ) ;
return wireaddr_to_addrinfo ( ctx , & wireaddr - > u . wireaddr ) ;
@ -511,6 +555,8 @@ bool all_tor_addresses(const struct wireaddr_internal *wireaddr)
switch ( wireaddr [ i ] . itype ) {
switch ( wireaddr [ i ] . itype ) {
case ADDR_INTERNAL_SOCKNAME :
case ADDR_INTERNAL_SOCKNAME :
return false ;
return false ;
case ADDR_INTERNAL_FORPROXY :
abort ( ) ;
case ADDR_INTERNAL_ALLPROTO :
case ADDR_INTERNAL_ALLPROTO :
return false ;
return false ;
case ADDR_INTERNAL_AUTOTOR :
case ADDR_INTERNAL_AUTOTOR :