"option macaddr" has no effect on "config interface 'bat0'"

I want to set a (predefined) macaddr on an interface of type proto batadv:

config interface 'bat0'
    option  proto           'batadv'
    option  routing_algo    'BATMAN_IV'
    option  macaddr         '02:00:02:00:00:01'

But this has no effect. The interface comes up with a random address, again.

How ever, using ip link set bat0 down; ip link set bat0 address 02:00:02:00:00:01; ip link set bat0 up works.

Question 1: Is there maybe a bug or is 'interface' just the wrong place to configure the mac address for a batadv interface?
Question 2: Can I and if yes, how can I execute a script after bat0 is created and brought up, so I can change the mac address?

Take a look at the batman OpenWRT docs...

...and the Open-Mesh docs...

Did you have read the link you posted? The examples in that page do not set macaddr on the batadv interface...

So that probably means its not an option...

Keep researching.

config device 
  option name bat0
  option macaddr 02:00:00:00:00:01

Question 2: Can I and if yes, how can I execute a script after bat0 is created and brought up, so I can change the mac address?

See Run a script when an interface goes up and down - #4 by braian87b

/etc/hotplug.d/iface/10-bat0

#!/bin/sh
[ "$ACTION" = "ifup" -a "$INTERFACE" = "bat0" ] && {
        ip link set $INTERFACE down
        ip link set $INTERFACE address 02:00:02:00:00:01
        ip link set $INTERFACE up
}

But this is rather not not so nice. I would still prefer using option macaddr within /etc/config/network.

Thanks @jow!
I somehow did not realized to use config device as for instance it is done with br-lan and wan on the default config.

You can use something like this, you can remove the commit and sync if you don't want to persist the changes between reboots, and you can use uci revert network after that to clear the changes history too.

#!/bin/sh
[ "$ACTION" = "ifup" -a "$INTERFACE" = "bat0" ] && {
        uci set network.bat0.macaddr='02:00:02:00:00:01'
        uci commit
        sync
        ifdown bat0
        ifup bat0
}

Thanks for pointing out how to do it with uci, but... :wink:

  1. I'm really uncomfortable with using uci and like to change files, and restarting a service or at worst, a reboot. I find it really hard to interact with uci directly, but that's maybe a personal affair.
  2. In this case I want a persistent behavior, because it drives me nuts if I need to check and double check 3 times which mac address bat0 does have this time.
  3. The "not so nice" statement was meant that any extra fiddle script afterwards is not so nice. I would do this only with options or usecases not covered by the current openwrt scripts which build a config out of the /etc/config files.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.