diff options
| author | Roy Marples <roy@marples.name> | 2018-07-15 14:20:16 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2018-07-15 14:20:16 +0100 |
| commit | d12865885becbbbefcb155751fcf883cd2de327c (patch) | |
| tree | a30f8358364887740db8b5d935234f4d34ca1344 | |
| parent | e7f46d3a27d7bed1ebdbc1f733afc82660588f4f (diff) | |
| download | dhcpcd-d12865885becbbbefcb155751fcf883cd2de327c.tar.xz | |
Some systems mark a host route using RTF_HOST and some use an
all-ones netmask.
For the former, only test netmask for equality if both routes
lack the RTF_HOST marking.
| -rw-r--r-- | src/route.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/route.c b/src/route.c index 09545cdc..8dc86392 100644 --- a/src/route.c +++ b/src/route.c @@ -44,6 +44,21 @@ #include "route.h" #include "sa.h" +/* + * On some systems, host routes have no need for a netmask. + * However DHCP specifies host routes using an all-ones netmask. + * This handy function allows easy comparison when the two + * differ. + */ +static int +rt_cmp_netmask(const struct rt *rt1, const struct rt *rt2) +{ + + if (rt1->rt_flags & RTF_HOST && rt2->rt_flags & RTF_HOST) + return 0; + return sa_cmp(&rt1->rt_netmask, &rt2->rt_netmask); +} + void rt_init(struct dhcpcd_ctx *ctx) { @@ -63,14 +78,12 @@ rt_desc(const char *cmd, const struct rt *rt) assert(cmd != NULL); assert(rt != NULL); - assert(rt->rt_ifp != NULL); - ifname = rt->rt_ifp->name; sa_addrtop(&rt->rt_dest, dest, sizeof(dest)); prefix = sa_toprefix(&rt->rt_netmask); sa_addrtop(&rt->rt_gateway, gateway, sizeof(gateway)); - gateway_unspec = sa_is_unspecified(&rt->rt_gateway); + ifname = rt->rt_ifp == NULL ? "(null)" : rt->rt_ifp->name; if (rt->rt_flags & RTF_HOST) { if (gateway_unspec) @@ -236,7 +249,7 @@ rt_find(struct rt_head *rts, const struct rt *f) (f->rt_ifp == NULL || rt->rt_ifp->metric == f->rt_ifp->metric) && #endif - sa_cmp(&rt->rt_netmask, &f->rt_netmask) == 0) + rt_cmp_netmask(f, rt) == 0) return rt; } return NULL; @@ -345,7 +358,7 @@ rt_add(struct rt *nrt, struct rt *ort) ort->rt_metric == nrt->rt_metric && #endif sa_cmp(&ort->rt_dest, &nrt->rt_dest) == 0 && - sa_cmp(&ort->rt_netmask, &nrt->rt_netmask) == 0 && + rt_cmp_netmask(ort, nrt) == 0 && sa_cmp(&ort->rt_gateway, &nrt->rt_gateway) == 0) { if (ort->rt_mtu == nrt->rt_mtu) |
