Bug 212480 - [NEW PORT] sysutils/ethname: boot-time (re)naming of ethernet devices by MAC address
Summary: [NEW PORT] sysutils/ethname: boot-time (re)naming of ethernet devices by MAC ...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
URL:
Keywords: feature
Depends on:
Blocks:
 
Reported: 2016-09-08 05:08 UTC by eborisch+FreeBSD
Modified: 2021-07-15 01:10 UTC (History)
9 users (show)

See Also:
kevans: merge-quarterly-


Attachments
shar-file of potential new port. (v2.0.1) (1.35 KB, text/plain)
2020-03-09 19:30 UTC, eborisch+FreeBSD
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description eborisch+FreeBSD 2016-09-08 05:08:45 UTC
I've put together a rc.d script [1] for renaming ethernet devices at boot time, keeping MAC address <-> devname mappings consistent.

This isn't typically needed on PCIe systems, but for systems with multiple USB ethernet (ue) devices, which seem to like to come up in non-deterministic order, it is very helpful; doubly so when the system in question is a router / firewall where the network config and security concerns vary wildly from one device to the next.

It could also be of use for traditional NICs (PCIe) when adding a new card to a system, for example, and ensuring that the existing, previously configured device sticks to the MAC address, and not having to worry about which ends up /dev/xxxN vs /dev/xxxM.

The script inserts itself before netif, waits an adjustable delay for the expected devices to appear, and then renames them as requested by the user. All of the device configuration, pf, etc., can be written with the new names. It does not attempt to automatically handle devices added after boot.

Perhaps there is some other (pre-existing) way to handle this, but all of the Google-fu I've thrown at it returns "you could write a script to rename then at boot" ... so I did. If there is a simple knob I've missed, please point me at it close this at.

It came up recently [2] in freebsd-stable, and a suggestion was made to file a PR for either base / port inclusion, so here we are.

Having never gone through the process here before, please let me know if there are any changes I can make on my end to accommodate this. As the installation is placement of a single rc.d script, I don't have any installation scripts currently in place. 

[1] https://github.com/eborisch/ethname
[2] https://lists.freebsd.org/pipermail/freebsd-stable/2016-September/085479.html
Comment 1 Nikolai Lifanov freebsd_committer freebsd_triage 2017-01-24 16:01:03 UTC
take
Comment 2 Nikolai Lifanov freebsd_committer freebsd_triage 2017-01-24 16:14:03 UTC
Would you like this as a port or would you prefer this in base?
Comment 3 eborisch+FreeBSD 2017-01-24 16:23:04 UTC
My initial reaction would be ports. If enough people use it and decide it's the best thing since sliced bread, it can always be moved into base.

That said, I'll defer to your judgement.
Comment 4 eborisch+FreeBSD 2017-03-10 03:29:59 UTC
This tool was mentioned on the BSDNow podcast. Alan mentioned in passing avoiding a config file and doing it all in rc. Seemed like a good idea, so I did it.
Comment 5 Thomas Hurst 2017-04-14 23:00:16 UTC
See also my PR from 2007, trying to get similar functionality in base: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=118111

There I added to the existing /etc/network.subr ifnet_rename() function, which is called from /etc/rc.d/netif start.
Comment 6 Nikolai Lifanov freebsd_committer freebsd_triage 2017-04-17 14:19:18 UTC
I'll take a look at it. Thanks!
Comment 7 Walter Schwarzenfeld freebsd_triage 2018-02-10 15:24:46 UTC
ping!
Comment 8 Nikolai Lifanov freebsd_committer freebsd_triage 2018-02-12 13:59:39 UTC
Hi! Thanks for the ping. This one slipped through the cracks.
Comment 9 eborisch+FreeBSD 2018-02-12 15:54:14 UTC
If the desire is to move this functionality into base, Thomas's patch in bug #118111 is likely the right way to go -- integrated as part of netif, as opposed to a precursor to netif.
Comment 10 Farid 2018-07-03 08:03:10 UTC
What is the status of this one?
I'm in the exact same situation as Thomas Hurst in bug #18111.
Comment 11 Thomas Hurst 2018-07-13 23:42:23 UTC
I've just updated #118111 with a patch that applies against CURRENT.
Comment 12 eborisch+FreeBSD 2019-08-12 16:59:36 UTC
I've updated ethname to have a more succinct configuration:

ethname_enable="YES"
ethname_external_mac="aa:bb:cc:dd:ee:00"

Will make sure the ethernet device with the matching MAC will be named 'external'.
Comment 13 Kubilay Kocak freebsd_committer freebsd_triage 2020-03-09 06:15:18 UTC
If someone can QA this (portlint, poudriere), I can look to commit it to ports.

^Triage:

  - Can't be in progress without an Assignee, set to Open accordingly
Comment 14 eborisch+FreeBSD 2020-03-09 19:30:38 UTC
Created attachment 212287 [details]
shar-file of potential new port. (v2.0.1)

Here is a shar file with a port for this package.

There isn't much to it; runs make install, which installs ${DESTDIR}${PREFIX}/etc/rc.d/ethname and ${DESTDIR}${PREFIX}/share/ethname/README.md.
Comment 15 eborisch+FreeBSD 2020-08-04 22:33:14 UTC
Portlint passes with:

WARN: /usr/ports/sysutils/ethname/pkg-descr: contains less than 3 lines, make it longer if possible.(currently 1 line)
0 fatal errors and 1 warning found.

"Building" (trivial since the make only makes directories and copies the script and help files) succeeds with Synth.
Comment 16 eborisch+FreeBSD 2020-10-29 15:05:07 UTC
Anything I can do to move this forward?

I recently migrated a machine where I wasn't using this, and was quickly reminded how nice it is to have; the ethernet device on the new machine is a different vendor; so there are multiple places to go through and fix up the name after update, while on system with this, it's a single place to update the MAC address...
Comment 17 eborisch+FreeBSD 2020-10-29 16:35:21 UTC
The (much smaller) patch in bug #118111 is still a great option, too, but requires changes in base, while this exists as a stand-alone port. Either way, it would be nice to see something move forward for this.

This version also permits renaming interfaces to each other (swap en0 and en1, for example) if you wanted to do that for some reason.
Comment 18 Michael Muenz 2020-10-31 06:30:11 UTC
Hi,

Just stumbled upon this one via Twitter (like others too) :)
Would love to see it in ports so everyone can choose on his/her own how to handle it. 

Added the port to my build env

- portlint -A claims about too few lines which should be easy to fix
- poudriere testport runs fine on 12.1 and 11.3 64bit
- poudriere bulk builds pkg on 12.1 and 11.3 64bit

Best,
Michael
Comment 19 commit-hook freebsd_committer freebsd_triage 2020-11-07 05:24:31 UTC
A commit references this bug:

Author: kevans
Date: Sat Nov  7 05:24:07 UTC 2020
New revision: 554342
URL: https://svnweb.freebsd.org/changeset/ports/554342

Log:
  [NEW PORT] sysutils/ethname: boot-time (re)naming of ethernet devices by MAC

  An rc-script for pinning an ethernet network name to a MAC address.

  --

  This isn't typically needed on PCIe systems, but for systems with multiple
  USB ethernet (ue) devices, which seem to like to come up in
  non-deterministic order, it is very helpful; doubly so when the system in
  question is a router / firewall where the network config and security
  concerns vary wildly from one device to the next.

  It could also be of use for traditional NICs (PCIe) when adding a new card
  to a system, for example, and ensuring that the existing, previously
  configured device sticks to the MAC address, and not having to worry about
  which ends up /dev/xxxN vs /dev/xxxM.

  The script inserts itself before netif, waits an adjustable delay for the
  expected devices to appear, and then renames them as requested by the user.
  All of the device configuration, pf, etc., can be written with the new
  names. It does not attempt to automatically handle devices added after boot.

  --

  Usage is described in the script, but effectively:

  $ cat /etc/rc.conf
  ethname_enable="YES"
  ethname_foo0_mac="aa:bb:cc:dd:ee:00"
  ethname_bar_mac="aa:bb:cc:dd:ee:01"

  # Optionally, otherwise it'll just enumerate all ethname_*_mac vars:
  ethname_names="foo0 bar"

  PR:		212480
  Submitted by:	eborisch gmail com

Changes:
  head/sysutils/Makefile
  head/sysutils/ethname/
  head/sysutils/ethname/Makefile
  head/sysutils/ethname/distinfo
  head/sysutils/ethname/pkg-descr
Comment 20 Kyle Evans freebsd_committer freebsd_triage 2020-11-07 05:26:05 UTC
It's not critical, but I would perhaps encourage you to write a manpage for this when you get a chance. Obviously it will not be a massive one, and it'll probably nearly be verbatim the instructions included in the script, but it would be good for discovery of said instructions.

Committed as r554342, though- thanks!
Comment 21 eborisch+FreeBSD 2021-07-15 01:10:22 UTC
(In reply to Kyle Evans from comment #20)

I’ve added a manpage if you want to take a look (up on GitHub). If it looks good to you, I can tag it as a release.