[LEDE-DEV] [PATCH netifd] device: extend interface.macaddr option to refer to another interface

Günther Kelleter guenther.kelleter at devolo.de
Thu Nov 3 05:49:45 PDT 2016


e.g. option macaddr "@eth0" tells netifd to use the MAC of interface eth0.
Use case: set MAC address of a bridge interface to a specific interface's
MAC regardless of bridge/interface initialization order.

Signed-off-by: Günther Kelleter <guenther.kelleter at devolo.de>
---
 device.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/device.c b/device.c
index 82596e4..c63ddc7 100644
--- a/device.c
+++ b/device.c
@@ -256,7 +256,21 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
 	}
 
 	if ((cur = tb[DEV_ATTR_MACADDR])) {
-		ea = ether_aton(blobmsg_data(cur));
+		const char *data = blobmsg_data(cur);
+		struct device_settings ds = {0};
+		if (data[0] == '@') {
+			struct device dev = {0};
+			strncpy(dev.ifname, data + 1, sizeof dev.ifname);
+			dev.ifname[sizeof dev.ifname - 1] = '\0';
+			system_if_get_settings(&dev, &ds);
+			if (ds.flags & DEV_OPT_MACADDR) {
+				ea = (struct ether_addr *)ds.macaddr;
+			} else {
+				ea = NULL;
+			}
+		} else {
+			ea = ether_aton(blobmsg_data(cur));
+		}
 		if (ea) {
 			memcpy(s->macaddr, ea, 6);
 			s->flags |= DEV_OPT_MACADDR;
-- 
2.10.0.100.gddd73ec




More information about the Lede-dev mailing list