summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2017-05-20 13:51:41 +0100
committerRoy Marples <roy@marples.name>2017-05-22 09:50:21 +0100
commitf58a7db77fd3dfec7f0d5c3630ecf906f300e9c1 (patch)
treedb9a3cf9bc03e6cec6f82352d7a791da4ef43fcb /src/if.c
parent3cf33877235502a3998fae72d4a1ac657ceb815e (diff)
downloaddhcpcd-f58a7db77fd3dfec7f0d5c3630ecf906f300e9c1.tar.xz
Hardware Address validation
Summary: The all zero's and all one's hardware address are reserved. As such, they should not be used in dhcpcd. Likewise, Router Solicitation messages should not contain an all zero source address option. Fixes T119. Test Plan: Request IPv6RA over a PPP interface on a suitable OS which assigns an all zero's or all one's hardware address. Maniphest Tasks: T119 Differential Revision: https://dev.marples.name/D114
Diffstat (limited to 'src/if.c')
-rw-r--r--src/if.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/if.c b/src/if.c
index bcf14f2d..2ae50793 100644
--- a/src/if.c
+++ b/src/if.c
@@ -264,6 +264,24 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
}
}
+bool
+if_valid_hwaddr(const uint8_t *hwaddr, size_t hwlen)
+{
+ size_t i;
+ bool all_zeros, all_ones;
+
+ all_zeros = all_ones = true;
+ for (i = 0; i < hwlen; i++) {
+ if (hwaddr[i] != 0x00)
+ all_zeros = false;
+ if (hwaddr[i] != 0xff)
+ all_ones = false;
+ if (!all_zeros && !all_ones)
+ return true;
+ }
+ return false;
+}
+
struct if_head *
if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
{
@@ -469,6 +487,10 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
ifp->index = if_nametoindex(ifp->name);
#endif
+ /* Ensure hardware address is valid. */
+ if (!if_valid_hwaddr(ifp->hwaddr, ifp->hwlen))
+ ifp->hwlen = 0;
+
/* We only work on ethernet by default */
if (ifp->family != ARPHRD_ETHER) {
if ((argc == 0 || argc == -1) &&