Skip to content

Rename hostname and ssid with EUI of mac address#1370

Closed
rosysong wants to merge 3 commits intoopenwrt:masterfrom
rosysong:rename
Closed

Rename hostname and ssid with EUI of mac address#1370
rosysong wants to merge 3 commits intoopenwrt:masterfrom
rosysong:rename

Conversation

@rosysong
Copy link
Copy Markdown
Contributor

@rosysong rosysong commented Sep 11, 2018

This commit can meet the need of users who has more than 1 routers running with OpenWrt,
so that they can better distinguish between routers running OpenWrt without renaming the hostname and wifi ssid one by one.

@rosysong
Copy link
Copy Markdown
Contributor Author

@blogic

@dedeckeh dedeckeh added the core packages pull request/issue for core (in-tree) packages label Sep 11, 2018
@rosysong rosysong force-pushed the rename branch 2 times, most recently from 8f34906 to bdf62df Compare October 13, 2018 05:55
@ynezz
Copy link
Copy Markdown
Member

ynezz commented Dec 3, 2018

@rosysong I think, that for this feature to be widely useful, it would be handy to get EUI from the primary MAC address, the MAC address which is usually printed on the sticker somewhere on the router. Otherwise the router is going to welcome me with nice OpenWrt_4a66a8 (I would prefer the OpenWrt-4a66a8 hostname), but how can I confirm, that it's actually the router I'm looking at? So I'm afraid, that at its current state, this PR doesn't provide any added value to what we've now.

For that primary MAC address we would probably need to add something to DTS?

aliases {
    primary-mac-address = &eth0;
};

and I think, that such primary-mac-address property/alias would be handy not just for this hostname use case, but for other derived projects as well, for example in Gluon.

Maybe a nitpick, but you've probably missed to add macaddr_geteui in separate commit, as I was looking at mac80211 patch first and then started looking at OpenWrt where is this function defined, but later found out it's in the other base-files patch.

@rosysong
Copy link
Copy Markdown
Contributor Author

rosysong commented Dec 4, 2018

This commit does need to add something in DTS file, the ssid and hostname will set as long as you has relevant mac address in /proc/sys/xxx/macaddress.

@ynezz
Copy link
Copy Markdown
Member

ynezz commented Dec 4, 2018

the ssid and hostname will set as long as you has relevant mac address in /proc/sys/xxx/macaddress.

SSID is probably ok, since you're taking that MAC address from the phy. But for the hostname, I would expect, that it would be set to something I can verify physically on the device, so if I connect to device with hostname OpenWrt-4a66a8, then I can take a look at some sticker on the device and can actually confirm, that there is MAC address xx:xx:xx:4a:66:a8 written on the sticker.

Some of the devices have all MAC addresses printed on the sticker, some of the devices have only WiFi MAC on the sticker, some of the devices have LAN or WAN MAC address. So you shouldn't use just eth0 MAC address for the hostname, but you should consider phy0, phy1, eth1, eth0 as well (list taken from Gluon primary_mac). And how do you know which one of them is the primary MAC address, the MAC address printed on the sticker?

@rosysong
Copy link
Copy Markdown
Contributor Author

rosysong commented Dec 7, 2018

I list the interfaces under /sys/class/net and get one of them as ifname, if succeed, we got the hostname. @ynezz

@ynezz
Copy link
Copy Markdown
Member

ynezz commented Mar 20, 2019

Well, it seems like you don't get my comments at all.

@rosysong
Copy link
Copy Markdown
Contributor Author

For that primary MAC address we would probably need to add something to DTS ?
...
And how do you know which one of them is the primary MAC address ?
...

Yes, I think you are right, we should do something to specify which mac is the primary mac address. I agree with your opinion, but how can I get its value after I add the alias in DTS file ??
This is very import.!

but you've probably missed to add macaddr_geteui in separate commit,
...
I would prefer the OpenWrt-4a66a8 hostname
...

OK, will update them.

@ynezz

@rosysong
Copy link
Copy Markdown
Contributor Author

rosysong commented Apr 16, 2019

@ynezz Here is the newer commit, it provides a new implementation for renaming hostname and eui.
The variable primarynetif indicates to the users and system that which is the primary net interface, so that we can rename the hostname and ssid with this, otherwise, nothing will change to the default.

@rosysong rosysong force-pushed the rename branch 4 times, most recently from b305e32 to 9b48f3d Compare April 17, 2019 06:22
@adschm
Copy link
Copy Markdown
Member

adschm commented Jun 22, 2019

For that primary MAC address we would probably need to add something to DTS?

aliases {
primary-mac-address = &eth0;
};
and I think, that such primary-mac-address property/alias would be handy not just for this hostname use case, but for other derived projects as well, for example in Gluon.

@ynezz I like that idea, as I need the "sticker MAC address" in a similar use-case as you referenced from Gluon.

So, if one defined an alias as suggested, I could then access it via
cat /proc/device-tree/aliases/primary-mac-address
and thus derive the "sticker MAC address"?

I will play around with this a litte bit.
If I then start an RFC PR just for adding such a setting, do you see a chance for it being merged or would it be wasted time?

@adschm
Copy link
Copy Markdown
Member

adschm commented Jun 23, 2019

Well, actually it is as easy as adding

get_mac_primary() {
	local basepath="/proc/device-tree"
	local macdevice="$(cat "$basepath/aliases/primary-mac-address" 2>/dev/null)"
	[ -n "$macdevice" ] && get_mac_binary "$basepath/$macdevice/mac-address" 0
}

to lib/functions/system.sh

I will try my luck with a PR.

@rosysong
Copy link
Copy Markdown
Contributor Author

For that primary MAC address we would probably need to add something to DTS?
aliases {
primary-mac-address = &eth0;
};
and I think, that such primary-mac-address property/alias would be handy not just for this hostname use case, but for other derived projects as well, for example in Gluon.

@ynezz I like that idea, as I need the "sticker MAC address" in a similar use-case as you referenced from Gluon.

So, if one defined an alias as suggested, I could then access it via
cat /proc/device-tree/aliases/primary-mac-address
and thus derive the "sticker MAC address"?

I will play around with this a litte bit.
If I then start an RFC PR just for adding such a setting, do you see a chance for it being merged or would it be wasted time?

for this PR, users do not need to update the DTS files but to set the primary mac address in the preinit scripts (e.g. target/linux/ath79/base-files/etc/board.d/02_network) with "ucidef_set_primarynetif ethxx".

@adschm
Copy link
Copy Markdown
Member

adschm commented Jun 24, 2019

for this PR, users do not need to update the DTS files but to set the primary mac address in the preinit scripts (e.g. target/linux/ath79/base-files/etc/board.d/02_network) with "ucidef_set_primarynetif ethxx".

Yes. I just picked the improvement suggestion from ynezz, as it serves well to solve another problem I have. (And I also prefer specifying the primary-mac device in DTS).

I actually like your initial idea of providing specific SSID/Hostname, so let's see how this goes on ...

@ynezz
Copy link
Copy Markdown
Member

ynezz commented Jun 24, 2019

I actually like your initial idea of providing specific SSID/Hostname, so let's see how this goes on ...

Once we figure out PR #2159 this PR could simply use get_mac_primary to get the right MAC address for the SSID/hostname.

@adschm
Copy link
Copy Markdown
Member

adschm commented Jun 26, 2019

Note that it looks like not every device is storing the relevant MAC addresses in device_tree. Here we will (maybe only after PR #2159 is sorted out) have to decide whether

  • we bring the MAC address to device tree in those cases (maybe introducing redundancy)
  • we follow the approach here and add a second option to specify primary MAC address in 02_network or similar (this will be comparable to the led or WiFi MAC fixes done in board.d already, as those are not solely DTS-based, too). get_mac_primary would then first check device_tree and after that look for other options
  • we live with a (small?) fraction of devices not being covered by the DTS-based get_mac_primary (won't hurt much for Freifunk/Gluon, but will lead to no device-specific hostname/SSID for the aim of this PR)

So far, I'm personally far from having a preference.

@adschm
Copy link
Copy Markdown
Member

adschm commented Sep 19, 2019

@rosysong My PR #2159 for adding label MAC addresses has just been accepted.
So, you can exploit the MAC address set there by just calling get_mac_primary function.

Do you want to update this PR based on it or should I take over from here?

Note that only a fraction of devices are supported, so the features introduced here will be limited to a (hopefully growing) subset of devices; I would suggest to keep the rest with the default "OpenWrt".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indent.

Copy link
Copy Markdown
Member

@adschm adschm Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would become:

local labelmac=$(get_mac_label)
local ssid=OpenWrt_11${mode_band}
[ -n "$labelmac" ] && ssid="${ssid}_$(macaddr_geteui $labelmac)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you would delete the set system.@system[-1].hostname='OpenWrt' in the uci batch above and then add

local labelmac=$(get_mac_label)
if [ -n "$labelmac" ]; then
   set system.@system[-1].hostname="OpenWrt_$(macaddr_geteui $labelmac)"
else
   set system.@system[-1].hostname=OpenWrt
fi

before the "if json_is_a ..." block.

The remaining changes in this patch can be dropped.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch can be dropped entirely, as MAC address will come from get_mac_binary directly (which internally uses something similar ...)

@rosysong
Copy link
Copy Markdown
Contributor Author

@adrianschmutzler Thanks, will update this PR later! Glad to see this.

@rosysong
Copy link
Copy Markdown
Contributor Author

@adrianschmutzler @ynezz It's done, please check it again, thanks for your reivews!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brackets for $ssid seem to be wrong here.

@adschm
Copy link
Copy Markdown
Member

adschm commented Sep 22, 2019

For the last commit, maybe rephrase "Once the label is valid" into something like "If a label MAC address is provided for device".
For the first and second commit, you should also add a commit description about what you are doing and why.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK underscores are not allowed in the hostnames, so this should be a hyphen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add bands to SSIDs, you're effectively creating two different networks, forbidding band steering etc.

@rosysong
Copy link
Copy Markdown
Contributor Author

Thanks, here is the newer commit.

@rosysong
Copy link
Copy Markdown
Contributor Author

It's done, thansk! ping @adrianschmutzler @ynezz

Copy link
Copy Markdown
Member

@adschm adschm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

This commit add a function for getting the external
unique identifier of a mac address.

Signed-off-by: Rosy Song <[email protected]>
If the label MAC is provided for device, the SSID
would be OpenWrt_{the eui of the mac address}

Signed-off-by: Rosy Song <[email protected]>
If a label MAC address is provided for device, system
will rename the hostname with OpenWrt_{eui mac address}.
This helps to distinguish between different devices.

Signed-off-by: Rosy Song <[email protected]>
@rosysong
Copy link
Copy Markdown
Contributor Author

rosysong commented Nov 3, 2019

@adrianschmutzler Well, I updated it, replace "set" with "uci set".

@adschm
Copy link
Copy Markdown
Member

adschm commented Nov 4, 2019

I've merged the geteui patch and a rebased version of the hostname patch together and sent it to the mailing list:
https://patchwork.ozlabs.org/patch/1188868/

This was necessary as I plan to alter the label MAC address retrieval from get_mac_label function to uci config beforehand:
https://patchwork.ozlabs.org/patch/1188867/

Despite, I tried to test the WiFi patch, but found that this won't work for addresses being set up via /etc/board.json or /etc/config/system as mac80211.sh runs way earlier.
I do not have a solution for that at the moment, but expect this topic to be discussed deeply in #2408

@mgiganto
Copy link
Copy Markdown

mgiganto commented Nov 4, 2019

Despite, I tried to test the WiFi patch, but found that this won't work for addresses being set up via /etc/board.json or /etc/config/system as mac80211.sh runs way earlier.

Could you give me more details on what you want/need, so I can make sure it will work properly :)

@adschm
Copy link
Copy Markdown
Member

adschm commented Nov 4, 2019

@mgiganto Well, essentially have a look at the second patch here. This will work if label MAC address is stored in device tree, and won't work if it's stored in board.json or uci config.
Both cases are relevant depending on which MAC address the vendor uses.

@mgiganto
Copy link
Copy Markdown

mgiganto commented Nov 4, 2019

@mgiganto Well, essentially have a look at the second patch here. This will work if label MAC address is stored in device tree, and won't work if it's stored in board.json or uci config.
Both cases are relevant depending on which MAC address the vendor uses.

It looks to be related with board.json being generated just after wifi config... I'll keep you update with the fix

@adschm
Copy link
Copy Markdown
Member

adschm commented Nov 7, 2019

There has been demand for discussing this further in the mailing list. Despite, SSID name changes in mac80211.sh won't work as done here, as board.json is not available reliably. I will implement a solution with uci-defaults and submit that together with the hostname patch.
Thus, I will close this PR, as the discussion will continue elsewhere. Thank for your work.

@adschm adschm closed this Nov 7, 2019
@adschm
Copy link
Copy Markdown
Member

adschm commented Nov 21, 2019

Based on the feedback on the mailing list, this feature seems to be not desired. I've marked my/our patches as "Rejected". However, due to the introduction of the label MAC address one may easily do a similar adjustment of SSID/hostname in a short local uci-defaults script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants