From dc8b083d9fd2c55dec4412fd6116804064d826b6 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 10 Jul 2013 11:22:57 +0200 Subject: [PATCH] kernel-pfroute: Retry route lookup without source address on failure The known source address might be gone resulting in an error, making learning a new source address impossible. --- .../plugins/kernel_pfroute/kernel_pfroute_net.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c index c05ca56ecc..2d0e252ac7 100644 --- a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c +++ b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c @@ -1118,8 +1118,10 @@ static host_t *get_route(private_kernel_pfroute_net_t *this, bool nexthop, host_t *host = NULL; enumerator_t *enumerator; struct sockaddr *addr; + bool failed = FALSE; int type; +retry: msg.hdr.rtm_msglen = sizeof(struct rt_msghdr); for (type = 0; type < RTAX_MAX; type++) { @@ -1196,13 +1198,26 @@ static host_t *get_route(private_kernel_pfroute_net_t *this, bool nexthop, } else { - DBG1(DBG_KNL, "PF_ROUTE lookup failed: %s", strerror(errno)); + failed = TRUE; } /* signal completion of query to a waiting thread */ this->waiting_seq = 0; this->condvar->signal(this->condvar); this->mutex->unlock(this->mutex); + if (failed) + { + if (src) + { /* the given source address might be gone, try again without */ + src = NULL; + msg.hdr.rtm_seq = ++this->seq; + msg.hdr.rtm_addrs = 0; + memset(msg.buf, sizeof(msg.buf), 0); + goto retry; + } + DBG1(DBG_KNL, "PF_ROUTE lookup failed: %s", strerror(errno)); + } + if (host) { DBG2(DBG_KNL, "using %H as %s to reach %H", host, -- 2.47.2