jnielsendotnet / isboot

FreeBSD kernel module to support booting from iSCSI via IBFT
4 stars 7 forks source link

Renaming interface #14

Open jwmullally opened 1 year ago

jwmullally commented 1 year ago

Renaming the boot interface is useful to apply specific network configuration to the iBFT interface and to prevent it from being configured by other services (e.g. DHCP).

This is similar to the behavior of the dracut ifname= cmdline argument.

Here is an rc.d script I use which does this:

#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: isbootifname
# BEFORE: dhclient netif
# KEYWORD: nojail

. /etc/rc.subr

name="isbootifname"
rcvar="isbootifname_enable"

start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name 
: ${isbootifname_enable:=yes}

isbootifname_start()
{
    _isboot_nic="$(sysctl -bi net.isboot.nic)"
    if [ -n "$_isboot_nic" ]; then
        echo "${name}: Renaming interface ${_isboot_nic} to bootnet0"
        ifconfig "${_isboot_nic}" name "bootnet0"
    fi
}

isbootifname_stop()
{
    _isboot_nic="$(sysctl -bi net.isboot.nic)"
    if [ -n "$_isboot_nic" ]; then
        echo "${name}: Renaming interface bootnet0 back to ${_isboot_nic}"
        ifconfig "bootnet0" name "${_isboot_nic}"
    fi
}

run_rc_command "$1"

It might be useful to include this in the documentation.

E.g. Then you can disable automatic DHCP on that interface, regardless of what the original interface name is.

sysrc ifconfig_bootnet0="NOAUTO"

Another possibility is to add a new loader tunable (e.g. hw.ibft.ifname=bootnet0) that internally uses something equivalent to SIOCSIFNAME. net.isboot.nic would also probably need to be set to match this, to take into account any scripts already reading that sysctl.