X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/7eb0e5d2b8453f753bd2d8e2e77cf4b7e0b24b1b..f3ebb786e451da973560f1c9d8cdb151d25108b5:/src/src/routers/iplookup.c diff --git a/src/src/routers/iplookup.c b/src/src/routers/iplookup.c index 1af2a77b9..4ceb1f59a 100644 --- a/src/src/routers/iplookup.c +++ b/src/src/routers/iplookup.c @@ -2,7 +2,7 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2015 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -160,7 +160,7 @@ uschar *reply; uschar *hostname, *reroute, *domain; const uschar *listptr; uschar host_buffer[256]; -host_item *host = store_get(sizeof(host_item)); +host_item *host = store_get(sizeof(host_item), FALSE); address_item *new_addr; iplookup_router_options_block *ob = (iplookup_router_options_block *)(rblock->options_block); @@ -176,7 +176,7 @@ pw = pw; DEBUG(D_route) debug_printf("%s router called for %s: domain = %s\n", rblock->name, addr->address, addr->domain); -reply = store_get(256); +reply = store_get(256, TRUE); /* tainted data */ /* Build the query string to send. If not explicitly given, a default of "user@domain user@domain" is used. */ @@ -230,7 +230,8 @@ while ((hostname = string_nextinlist(&listptr, &sep, host_buffer, for (h = host; h; h = h->next) { - int host_af, query_socket; + int host_af; + client_conn_ctx query_cctx = {0}; /* Skip any hosts for which we have no address */ @@ -241,9 +242,9 @@ while ((hostname = string_nextinlist(&listptr, &sep, host_buffer, host_af = (Ustrchr(h->address, ':') != NULL)? AF_INET6 : AF_INET; - query_socket = ip_socket(ob->protocol == ip_udp ? SOCK_DGRAM:SOCK_STREAM, + query_cctx.sock = ip_socket(ob->protocol == ip_udp ? SOCK_DGRAM:SOCK_STREAM, host_af); - if (query_socket < 0) + if (query_cctx.sock < 0) { if (ob->optional) return PASS; addr->message = string_sprintf("failed to create socket in %s router", @@ -254,11 +255,12 @@ while ((hostname = string_nextinlist(&listptr, &sep, host_buffer, /* Connect to the remote host, under a timeout. In fact, timeouts can occur here only for TCP calls; for a UDP socket, "connect" always works (the router will timeout later on the read call). */ +/*XXX could take advantage of TFO */ - if (ip_connect(query_socket, host_af, h->address,ob->port, ob->timeout, - ob->protocol != ip_udp) < 0) + if (ip_connect(query_cctx.sock, host_af, h->address,ob->port, ob->timeout, + ob->protocol == ip_udp ? NULL : &tcp_fastopen_nodata) < 0) { - close(query_socket); + close(query_cctx.sock); DEBUG(D_route) debug_printf("connection to %s failed: %s\n", h->address, strerror(errno)); @@ -267,18 +269,18 @@ while ((hostname = string_nextinlist(&listptr, &sep, host_buffer, /* Send the query. If it fails, just continue with the next address. */ - if (send(query_socket, query, query_len, 0) < 0) + if (send(query_cctx.sock, query, query_len, 0) < 0) { DEBUG(D_route) debug_printf("send to %s failed\n", h->address); - (void)close(query_socket); + (void)close(query_cctx.sock); continue; } /* Read the response and close the socket. If the read fails, try the next IP address. */ - count = ip_recv(query_socket, reply, sizeof(reply) - 1, ob->timeout); - (void)close(query_socket); + count = ip_recv(&query_cctx, reply, sizeof(reply) - 1, time(NULL) + ob->timeout); + (void)close(query_cctx.sock); if (count <= 0) { DEBUG(D_route) debug_printf("%s from %s\n", (errno == ETIMEDOUT)? @@ -402,7 +404,7 @@ addr->child_count++; new_addr->next = *addr_new; *addr_new = new_addr; -/* Set up the errors address, if any, and the additional and removeable headers +/* Set up the errors address, if any, and the additional and removable headers for this new address. */ rc = rf_get_errors_address(addr, rblock, verify, &new_addr->prop.errors_address);