FS#64766 - [netctl] interface_add missing a way to specify the link MAC address if in need

Attached to Project: Arch Linux
Opened by Javier (je-vv) - Saturday, 07 December 2019, 22:09 GMT
Last edited by Doug Newgard (Scimmia) - Saturday, 28 March 2020, 13:04 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Evangelos Foutras (foutrelis)
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

Several added devices link bonding ones, can be set a specific link MAC address, which is what one need if the DHCP provider configures fixed IP addresses for specified MAC addresses. I believe that also applies to other sort of created devices like bridges and tap or tun devices.

That said, the netctl function in charge of adding new defices:

/usr/lib/netctl/interface
...
interface_add() {
local type="$1" name="$2" link="$3"
do_debug ip link add ${link:+link "$link"} name "$name" type "$type" "${@:4}" $LinkOptions || return
load_interface_config "$name"
}

Does not offer a way to specify such MAC address, which has to be specified before the "type <type>" parameter of the ip command, otherwise the ip command fails, believing those are parameters for the specific type of device, which is not the case.

I propose a simple fix on interface_add:

interface_add() {
local type="$1" name="$2" link="$3"
do_debug ip link add ${link:+link "$link"} name "$name" ${LinkMACAddress:+address "$LinkMACAddress"} type "$type" "${@:4}" $LinkOptions || return
load_interface_config "$name"
}

So that now one can set the LinkMACAddress shell variable on the netctl profile, and then if set, it gets applied to the "ip add" command. So one can get a profile like:

Description="Wired interface which fails over a wireless one"
Interface=bond0
Connection=bond
BindsToInterfaces=(<wired-ifc> <wireless-ifc>)
IP=dhcp
Mode="active-backup"
LinkOptions="miimon 100 primary in-wired-0 fail_over_mac none"
LinkMACAddress="<required-MAD-address>"
ExecUpPost="/usr/bin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant-<wireless-ifc>.conf -i <wireless-ifc>"
ExecDownPre="/usr/bin/pkill wpa_supplicant"

Additional info:
* package version(s)
netctl 1.20-2
This task depends upon

Closed by  Doug Newgard (Scimmia)
Saturday, 28 March 2020, 13:04 GMT
Reason for closing:  Implemented
Additional comments about closing:  Implemented in b5335f4350015d7c8b0cc66349d1290b7251bd9d
Comment by Jouke Witteveen (jouke) - Wednesday, 25 December 2019, 13:16 GMT
Thanks for taking the time to contribute to netctl! I like your idea (it would also fix https://github.com/joukewitteveen/netctl/issues/111). Would you like to turn your idea into a proper patch? There are a few shortcomings with your current proposal.

1)
In the case of a bridge interface, netctl can reuse an existing interface. This requires us to set the address after the fact in case the interface already exists.

2)
We need to add some documentation of this new functionality.

3)
An interesting request in https://github.com/joukewitteveen/netctl/pull/171 is to have the ability to get the MAC address from another interface. Of course, this can be achieved also by setting LinkMACAddress=$(cat /sys/class/net/$MACAddressOf/address), but maybe we want to support it nonetheless.

4)
For the MACVLAN connection type, we already have a MACAddress variable that does pretty much what we want (but only for macvlan connections). If possible, I would like to reuse and extend that variable name rather than introduce a new one. To me, it looks like the variable serves the exact same purpose.
Comment by Jouke Witteveen (jouke) - Saturday, 28 March 2020, 11:31 GMT
This is implemented in netctl 1.21 via the MACAddress= option.

Loading...