From patchwork Fri Apr 1 17:22:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 15953 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [127.0.0.1]) by open-mesh.org (Postfix) with ESMTP id 25A9581A7D; Fri, 1 Apr 2016 19:22:46 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=WNNHFFbC; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 17A0381530 for ; Fri, 1 Apr 2016 19:22:43 +0200 (CEST) Received: from sven-desktop.home.narfation.org (xd9ba8664.dyn.telefonica.de [217.186.134.100]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 8CFF71C8001; Fri, 1 Apr 2016 19:22:43 +0200 (CEST) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=20121; t=1459531363; bh=anBqW+YbBVya7MLLdOIQf0cyZPUtCZ1X/hba2Ql+2aw=; h=From:To:Cc:Subject:Date:From; b=WNNHFFbCg6VjuhqkG0gGth3zDdh9cxua+KtW30QqbEzsd/iQ6XFGIgXj9LbPLMbwm SgyzoceE2CmchER49IAvpF9xonIFJ/bTASLHpH25fDz1XIU5cOJrbA1+LDZQcewgb1 r5S6lZ/kTuADX8gLCEyLzWcAaFLytn9BwNzb7NdM= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 1 Apr 2016 19:22:35 +0200 Message-Id: <1459531356-8361-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.8.0.rc3 Subject: [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "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 --- 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 #include #include +#include #include #include #include @@ -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 #include @@ -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 +#include #include #include #include @@ -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; +}