From: W.C.A. Wijngaards Date: Wed, 9 Dec 2020 10:34:39 +0000 (+0100) Subject: For TCP store picked outgoing interface and pass it. X-Git-Tag: release-1.13.2rc1~254^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91bec32cdcafbef382054e97b0e1fe14ef10c96c;p=thirdparty%2Funbound.git For TCP store picked outgoing interface and pass it. --- diff --git a/services/outside_network.c b/services/outside_network.c index 2afa7a42c..5e7bd3124 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -194,15 +194,17 @@ waiting_tcp_delete(struct waiting_tcp* w) * Pick random outgoing-interface of that family, and bind it. * port set to 0 so OS picks a port number for us. * if it is the ANY address, do not bind. + * @param pend: pending tcp structure, for storing the local address choice. * @param w: tcp structure with destination address. * @param s: socket fd. * @return false on error, socket closed. */ static int -pick_outgoing_tcp(struct waiting_tcp* w, int s) +pick_outgoing_tcp(struct pending_tcp* pend, struct waiting_tcp* w, int s) { struct port_if* pi = NULL; int num; + pend->pi = NULL; #ifdef INET6 if(addr_is_ip6(&w->addr, w->addrlen)) num = w->outnet->num_ip6; @@ -222,6 +224,7 @@ pick_outgoing_tcp(struct waiting_tcp* w, int s) #endif pi = &w->outnet->ip4_ifs[ub_random_max(w->outnet->rnd, num)]; log_assert(pi); + pend->pi = pi; if(addr_is_any(&pi->addr, pi->addrlen)) { /* binding to the ANY interface is for listening sockets */ return 1; @@ -560,7 +563,7 @@ outnet_tcp_take_into_use(struct waiting_tcp* w) if(s == -1) return 0; - if(!pick_outgoing_tcp(w, s)) + if(!pick_outgoing_tcp(pend, w, s)) return 0; fd_set_nonblock(s); @@ -2211,8 +2214,9 @@ pending_tcp_query(struct serviced_query* sq, sldns_buffer* packet, if(sq->outnet->dtenv && (sq->outnet->dtenv->log_resolver_query_messages || sq->outnet->dtenv->log_forwarder_query_messages)) - dt_msg_send_outside_query(sq->outnet->dtenv, &sq->addr, NULL, - comm_tcp, sq->zone, sq->zonelen, packet); + dt_msg_send_outside_query(sq->outnet->dtenv, &sq->addr, + &pend->pi->addr, comm_tcp, sq->zone, sq->zonelen, + packet); #endif return w; } diff --git a/services/outside_network.h b/services/outside_network.h index 2fe97fa6c..d49d33e5d 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -344,6 +344,8 @@ struct pending { struct pending_tcp { /** next in list of free tcp comm points, or NULL. */ struct pending_tcp* next_free; + /** port for of the outgoing interface that is used */ + struct port_if* pi; /** tcp comm point it was sent on (and reply must come back on). */ struct comm_point* c; /** the query being serviced, NULL if the pending_tcp is unused. */