public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH] batctl: Don't translate multicast and zero mac addresses
Date: Thu, 19 Apr 2018 20:14:20 +0200	[thread overview]
Message-ID: <20180419181420.3167-1-sven@narfation.org> (raw)

The IP to mac translation code already skips zero and multicast mac
addressses because there might be multiple entries in the global
translation table which would match this entry. There is no "best" entry
originator for such an entry and such the result is basically a random
pick.

Translating such an input mac address (from ping/traceoute/translate) to a
single originator address is therefore not appropriate.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 functions.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/functions.c b/functions.c
index 3c340a2..e0e9978 100644
--- a/functions.c
+++ b/functions.c
@@ -194,6 +194,19 @@ static int str_is_mcast_addr(char *addr)
 		mac_addr->ether_addr_octet[0] & 0x01;
 }
 
+static bool ether_addr_valid(const uint8_t *addr)
+{
+	/* no multicast address */
+	if (addr[0] & 0x01)
+		return false;
+
+	/* no zero address */
+	if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0)
+		return false;
+
+	return true;
+}
+
 int read_file(const char *dir, const char *fname, int read_opt,
 	      float orig_timeout, float watch_interval, size_t header_lines)
 {
@@ -475,6 +488,9 @@ struct ether_addr *translate_mac(const char *mesh_iface,
 	memcpy(&out_mac, mac, sizeof(out_mac));
 	mac_result = &out_mac;
 
+	if (!ether_addr_valid(in_mac.ether_addr_octet))
+		return mac_result;
+
 	ret = translate_mac_netlink(mesh_iface, &in_mac, mac_result);
 
 	if (ret == -EOPNOTSUPP)
@@ -571,19 +587,6 @@ static struct nla_policy neigh_policy[NDA_MAX+1] = {
 	[NDA_PROBES]    = { .type = NLA_U32 },
 };
 
-static bool ether_addr_valid(const uint8_t *addr)
-{
-	/* no multicast address */
-	if (addr[0] & 0x01)
-		return false;
-
-	/* no zero address */
-	if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0)
-		return false;
-
-	return true;
-}
-
 static int resolve_mac_from_parse(struct nl_msg *msg, void *arg)
 {
 	struct nlattr *tb[NDA_MAX + 1];
-- 
2.17.0


             reply	other threads:[~2018-04-19 18:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 18:14 Sven Eckelmann [this message]
2018-04-25 17:20 ` [B.A.T.M.A.N.] [PATCH] batctl: Don't translate multicast and zero mac addresses Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180419181420.3167-1-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox