summaryrefslogtreecommitdiffstats
path: root/if-linux.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-09-08 11:30:31 +0000
committerRoy Marples <roy@marples.name>2008-09-08 11:30:31 +0000
commitcf7a295fa370022c78bf971667e61f69450104a4 (patch)
tree3e8cd16b94b87f88e0b4c37066ef43d468169f87 /if-linux.c
parentc130b44207af00d374c6eee6c115b210a2b9bd49 (diff)
downloaddhcpcd-cf7a295fa370022c78bf971667e61f69450104a4.tar.xz
On Linux, fix replacing the kernel added subnet route correctly for metrics.
Diffstat (limited to 'if-linux.c')
-rw-r--r--if-linux.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/if-linux.c b/if-linux.c
index bece58cc..1353d7e6 100644
--- a/if-linux.c
+++ b/if-linux.c
@@ -351,7 +351,7 @@ if_route(const struct interface *iface,
nlm->hdr.nlmsg_type = RTM_NEWROUTE;
if (action == 0)
nlm->hdr.nlmsg_flags = NLM_F_REPLACE;
- else if (action > 0)
+ else if (action == 1)
nlm->hdr.nlmsg_flags = NLM_F_CREATE | NLM_F_EXCL;
else
nlm->hdr.nlmsg_type = RTM_DELROUTE;
@@ -359,11 +359,12 @@ if_route(const struct interface *iface,
nlm->rt.rtm_family = AF_INET;
nlm->rt.rtm_table = RT_TABLE_MAIN;
- if (action < 0)
+ if (action == -1 || action == -2)
nlm->rt.rtm_scope = RT_SCOPE_NOWHERE;
else {
nlm->hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
- nlm->rt.rtm_protocol = RTPROT_BOOT;
+ /* We only change route metrics for kernel routes */
+ nlm->rt.rtm_protocol = action ? RTPROT_BOOT : RTPROT_KERNEL;
if (gateway->s_addr == INADDR_ANY)
nlm->rt.rtm_scope = RT_SCOPE_LINK;
else
@@ -374,6 +375,10 @@ if_route(const struct interface *iface,
nlm->rt.rtm_dst_len = inet_ntocidr(*netmask);
add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_DST,
&destination->s_addr, sizeof(destination->s_addr));
+ if (action != 1) {
+ add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_PREFSRC,
+ &iface->addr.s_addr, sizeof(iface->addr.s_addr));
+ }
add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_GATEWAY,
&gateway->s_addr, sizeof(gateway->s_addr));