public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address
@ 2016-04-01 17:22 Sven Eckelmann
  2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
  2016-04-04 15:47 ` [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Simon Wunderlich
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Eckelmann @ 2016-04-01 17:22 UTC (permalink / raw)
  To: b.a.t.m.a.n

The ipv6_to_mac function currently only checks if the EUI64 markers are
present but not if the mac address is valid for a host. This has to be done
to avoid invalid data in the alfred data storage.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 alfred.h       |  2 ++
 batadv_query.c |  4 ++++
 util.c         | 15 +++++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/alfred.h b/alfred.h
index 7e5db16..8ed1ef0 100644
--- a/alfred.h
+++ b/alfred.h
@@ -26,6 +26,7 @@
 #include <net/ethernet.h>
 #include <netinet/in.h>
 #include <netinet/udp.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <time.h>
 #include <sys/select.h>
@@ -196,3 +197,4 @@ int time_diff(struct timespec *tv1, struct timespec *tv2,
 	      struct timespec *tvdiff);
 void time_random_seed(void);
 uint16_t get_random_id(void);
+bool is_valid_ether_addr(uint8_t *addr);
diff --git a/batadv_query.c b/batadv_query.c
index 2604503..6dc2cf4 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -19,6 +19,7 @@
  *
  */
 
+#include "alfred.h"
 #include "batadv_query.h"
 #include <errno.h>
 #include <net/ethernet.h>
@@ -85,6 +86,9 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac)
 	mac->ether_addr_octet[4] = addr->s6_addr[14];
 	mac->ether_addr_octet[5] = addr->s6_addr[15];
 
+	if (!is_valid_ether_addr(mac->ether_addr_octet))
+		return -EINVAL;
+
 	return 0;
 }
 
diff --git a/util.c b/util.c
index db6ec96..c7e11cc 100644
--- a/util.c
+++ b/util.c
@@ -19,6 +19,8 @@
  *
  */
 
+#include <netinet/ether.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -60,3 +62,16 @@ uint16_t get_random_id(void)
 {
 	return random();
 }
+
+bool is_valid_ether_addr(uint8_t addr[ETH_ALEN])
+{
+	/* multicast address */
+	if (addr[0] & 0x01)
+		return false;
+
+	/* 00:00:00:00:00:00 */
+	if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0)
+		return false;
+
+	return true;
+}
-- 
2.8.0.rc3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-04 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-01 17:22 [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Sven Eckelmann
2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
2016-04-04 15:48   ` Simon Wunderlich
2016-04-04 15:47 ` [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Simon Wunderlich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox