Commit 944d4980 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix issues with switching gateways when metric is the same.

Tracked down by Julien Cristau.
parent 9673e4aa
...@@ -671,14 +671,30 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -671,14 +671,30 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
if(newmetric == metric && memcmp(newgate, gate, 16) == 0 && if(newmetric == metric && memcmp(newgate, gate, 16) == 0 &&
newifindex == ifindex) newifindex == ifindex)
return 0; return 0;
rc = kernel_route(ROUTE_ADD, dest, plen, newgate, newifindex, newmetric, /* It is better to add the new route before removing the old
one, to avoid losing packets. However, this only appears
to work if the metrics are different. */
if(newmetric != metric) {
rc = kernel_route(ROUTE_ADD, dest, plen,
newgate, newifindex, newmetric,
NULL, 0, 0); NULL, 0, 0);
if(rc < 0 && errno != EEXIST) if(rc < 0 && errno != EEXIST)
return rc; return rc;
rc = kernel_route(ROUTE_FLUSH, dest, plen, gate, ifindex, metric, rc = kernel_route(ROUTE_FLUSH, dest, plen,
gate, ifindex, metric,
NULL, 0, 0); NULL, 0, 0);
if(rc < 0 && (errno == ENOENT || errno == ESRCH)) if(rc < 0 && (errno == ENOENT || errno == ESRCH))
rc = 1; rc = 1;
} else {
rc = kernel_route(ROUTE_FLUSH, dest, plen,
gate, ifindex, metric,
NULL, 0, 0);
rc = kernel_route(ROUTE_ADD, dest, plen,
newgate, newifindex, newmetric,
NULL, 0, 0);
if(rc < 0 && errno == EEXIST)
rc = 1;
}
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment