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

Felix Fietkau nbd at nbd.name
Fri Nov 4 07:09:14 PDT 2016


On 2016-11-03 13:49, Günther Kelleter wrote:
> 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));
> +		}
I think this is somewhat quirky. Depending on the time when this device
is brought up, it could either get an original device mac address, or
one that has been modified via UCI. This is also not taken into account
on reload.

What's your use case for this?

- Felix



More information about the Lede-dev mailing list