From: Roy Marples Date: Mon, 9 Oct 2017 19:11:36 +0000 (+0100) Subject: Set DHCP routes as DHCP in supported OS's. X-Git-Tag: v7.0.0-rc4~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=351c9b6bbbd85727c4e871965ac9ba5317a058cf;p=thirdparty%2Fdhcpcd.git Set DHCP routes as DHCP in supported OS's. --- diff --git a/src/dhcp.c b/src/dhcp.c index 27951ae4..6be689fd 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -428,7 +428,7 @@ decode_rfc3442_rt(struct rt_head *routes, struct interface *ifp, if ((rt = rt_new(ifp)) == NULL) return -1; - TAILQ_INSERT_TAIL(routes, rt, rt_next); + rt->rt_dflags |= RTDF_DHCP; /* If we have ocets then we have a destination and netmask */ dest.s_addr = 0; @@ -461,6 +461,8 @@ decode_rfc3442_rt(struct rt_head *routes, struct interface *ifp, /* If CIDR is 32 then it's a host route. */ if (cidr == 32) rt->rt_flags = RTF_HOST; + + TAILQ_INSERT_TAIL(routes, rt, rt_next); n++; } return n; @@ -631,6 +633,7 @@ get_option_routes(struct rt_head *routes, struct interface *ifp, continue; if ((rt = rt_new(ifp)) == NULL) return -1; + rt->rt_dflags |= RTDF_DHCP; /* A host route is normally set by having the * gateway match the destination or assigned address */ @@ -663,6 +666,7 @@ get_option_routes(struct rt_head *routes, struct interface *ifp, while (p < e) { if ((rt = rt_new(ifp)) == NULL) return -1; + rt->rt_dflags |= RTDF_DHCP; memcpy(&gateway.s_addr, p, sizeof(gateway.s_addr)); p += 4; sa_in_init(&rt->rt_dest, &dest); diff --git a/src/if-linux.c b/src/if-linux.c index debbabaa..b5e30eb9 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -1225,6 +1225,11 @@ if_route(unsigned char cmd, const struct rt *rt) if (rt->rt_dflags & RTDF_RA) nlm.rt.rtm_protocol = RTPROT_RA; else +#endif +#ifdef RTPROT_DHCP + if (rt->rt_dflags & RTDF_DHCP) + nlm.rt.rtm_protocol = RTPROT_DHCP; + else #endif if (rt->rt_dflags & RTDF_IFA_ROUTE) nlm.rt.rtm_protocol = RTPROT_KERNEL; diff --git a/src/ipv6.c b/src/ipv6.c index a9543dd6..c98a8f34 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -2136,10 +2136,8 @@ inet6_makeroute(struct interface *ifp, const struct ra *rap) #ifdef HAVE_ROUTE_METRIC rt->rt_metric = ifp->metric; #endif - if (rap != NULL) { + if (rap != NULL) rt->rt_mtu = rap->mtu; - rt->rt_dflags |= RTDF_RA; - } return rt; } @@ -2256,12 +2254,15 @@ inet6_raroutes(struct rt_head *routes, struct dhcpcd_ctx *ctx, int expired, if (addr->prefix_vltime == 0) continue; rt = inet6_makeprefix(rap->iface, rap, addr); - if (rt) + if (rt) { + rt->rt_dflags |= RTDF_RA; TAILQ_INSERT_TAIL(routes, rt, rt_next); + } } if (rap->lifetime) { rt = inet6_makerouter(rap); if (rt) { + rt->rt_dflags |= RTDF_RA; TAILQ_INSERT_TAIL(routes, rt, rt_next); if (have_default) *have_default = true; @@ -2285,8 +2286,10 @@ inet6_dhcproutes(struct rt_head *routes, struct dhcpcd_ctx *ctx, if (d6_state && d6_state->state == dstate) { TAILQ_FOREACH(addr, &d6_state->addrs, next) { rt = inet6_makeprefix(ifp, NULL, addr); - if (rt) + if (rt) { + rt->rt_dflags |= RTDF_DHCP; TAILQ_INSERT_TAIL(routes, rt, rt_next); + } } } } diff --git a/src/route.h b/src/route.h index ec4ea1c3..6080c9d9 100644 --- a/src/route.h +++ b/src/route.h @@ -76,6 +76,7 @@ struct rt { #define RTDF_IFA_ROUTE 0x02 /* Address generated route */ #define RTDF_FAKE 0x04 /* Maybe us on lease reboot */ #define RTDF_RA 0x08 /* Router Advertisement */ +#define RTDF_DHCP 0x10 /* DHCP route */ }; TAILQ_HEAD(rt_head, rt);