Skip to content

Commit

Permalink
connectd: resolve ADDR_TYPE_DNS
Browse files Browse the repository at this point in the history
This will resolve ADDR_TYPE_DNS wireaddr by expanding connect->addrs with one
new wireaddr ADDR_INTERNAL_WIREADDR per DNS result and calling recursion
  • Loading branch information
m-schmoock committed Oct 7, 2021
1 parent a3ec7d6 commit 1193fae
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,9 @@ static void try_connect_one_addr(struct connecting *connect)
bool use_proxy = connect->daemon->always_use_proxy;
const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum];
struct io_conn *conn;
struct addrinfo hints, *ais, *aii;
struct wireaddr_internal addrhint;
int gai_err;

/* In case we fail without a connection, make destroy_io_conn happy */
connect->conn = NULL;
Expand Down Expand Up @@ -836,8 +839,45 @@ static void try_connect_one_addr(struct connecting *connect)
af = AF_INET6;
break;
case ADDR_TYPE_DNS:
// TODO: resolve with getaddrinfo and set af
break;
/* Resolve with getaddrinfo */
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
hints.ai_protocol = 0;
hints.ai_flags = AI_ADDRCONFIG;
gai_err = getaddrinfo((char *)addr->u.wireaddr.addr,
tal_fmt(tmpctx, "%d",
addr->u.wireaddr.port),
&hints, &ais);
if (gai_err != 0)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
gai_strerror(gai_err));
/* create new addrhints on-the-fly per result ... */
for (aii = ais; aii; aii = aii->ai_next) {
memset(&addrhint, 0, sizeof(addrhint));
addrhint.itype = ADDR_INTERNAL_WIREADDR;
addrhint.u.wireaddr.port = addr->u.wireaddr.port;
if (aii->ai_family == AF_INET) {
addrhint.u.wireaddr.type = ADDR_TYPE_IPV4;
addrhint.u.wireaddr.addrlen = 4;
memcpy(&addrhint.u.wireaddr.addr,
aii->ai_addr, 4);
} else if (aii->ai_family == AF_INET6) {
addrhint.u.wireaddr.type = ADDR_TYPE_IPV6;
addrhint.u.wireaddr.addrlen = 16;
memcpy(&addrhint.u.wireaddr.addr,
aii->ai_addr, 16);
} else {
/* skip unsupported ai_family */
continue;
}
tal_arr_expand(&connect->addrs, addrhint);
}
freeaddrinfo(ais);
/* ... and continue recursion */
connect->addrnum++;
try_connect_one_addr(connect);
return;
}
}

Expand Down

0 comments on commit 1193fae

Please sign in to comment.