[v2] alfred: Allow setting the source mac via unix sock

Message ID 1457715768-14863-1-git-send-email-dominik@heidler.eu (mailing list archive)
State Accepted, archived
Delegated to: Simon Wunderlich
Headers

Commit Message

Dominik Heidler March 11, 2016, 5:02 p.m. UTC
  The server will only overwrite the mac if it is zero.
Ths allows acting in place of (non-alfred) legacy clients
by injecting their data with the correct source mac.

Signed-off-by: Dominik Heidler <dominik@heidler.eu>
---
 unix_sock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Simon Wunderlich March 11, 2016, 5:19 p.m. UTC | #1
On Friday 11 March 2016 18:02:48 Dominik Heidler wrote:
> The server will only overwrite the mac if it is zero.
> Ths allows acting in place of (non-alfred) legacy clients
> by injecting their data with the correct source mac.
> 
> Signed-off-by: Dominik Heidler <dominik@heidler.eu>

Thanks! I've did some style changes (declaration up, !memcmp -> memcmp() == 0) 
and applied it in revision 58e1099

Thank you!
      Simon
  

Patch

diff --git a/unix_sock.c b/unix_sock.c
index 3c7e583..d7578a3 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -119,7 +119,13 @@  static int unix_sock_add_data(struct globals *globals,
 
 	data = push->data;
 	data_len = ntohs(data->header.length);
-	memcpy(data->source, &interface->hwaddr, sizeof(interface->hwaddr));
+
+	/* clients should set the source mac to 00:00:00:00:00:00
+	 * to make the server set the source for them
+	 */
+	static const char zero[ETH_ALEN] = { 0 };
+	if (!memcmp(zero, data->source, sizeof(data->source)))
+		memcpy(data->source, &interface->hwaddr, sizeof(interface->hwaddr));
 
 	if ((int)(data_len + sizeof(*data)) > len)
 		goto err;