Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 May 2004 10:04:23 +0300
From:      Peter Pentchev <roam@ringlet.net>
To:        Brooks Davis <brooks@one-eyed-alien.net>
Cc:        freebsd-net@freebsd.org
Subject:   Re: [RFC] ifconfig: match by link-level address
Message-ID:  <20040521070422.GA1292@straylight.m.ringlet.net>
In-Reply-To: <20040520171833.GA22494@Odin.AC.HMC.Edu>
References:  <20040520162919.GA1971@straylight.m.ringlet.net> <20040520171833.GA22494@Odin.AC.HMC.Edu>

next in thread | previous in thread | raw e-mail | index | archive | help

--XF85m9dhOBO43t/C
Content-Type: multipart/mixed; boundary="CE+1k2dSO48ffgeK"
Content-Disposition: inline


--CE+1k2dSO48ffgeK
Content-Type: text/plain; charset=windows-1251
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, May 20, 2004 at 10:18:38AM -0700, Brooks Davis wrote:
> On Thu, May 20, 2004 at 07:29:19PM +0300, Peter Pentchev wrote:
> > Hi,
> >=20
> > I found out recently that the Linux (or at least recent RedHat) startup
> > scripts could be configured to not bring up an Ethernet interface unless
> > it has a specified MAC address.  This, combined with the wonderful
> > interface renaming functionality recently committed to -CURRENT, led me
> > to the idea of interface renaming on boot-up, by hardware addresses -
> > something like 'I don't care how you detected this network card, or how
> > many others like it are there, but the card with MAC address
> > 00:03:0d:08:dc:a7 will be known as sis0int from now on'.
> >=20
> > The main missing piece was the ability to find an interface by MAC
> > address; hence the attached patch, also available at
> > http://www.ringlet.net/~roam/bsd-patches/src5/sbin-ifconfig-hwmatch.pat=
ch
> > http://people.FreeBSD.org/~roam/bsd-patches/src5/sbin-ifconfig-hwmatch.=
patch
> >=20
> > It teaches ifconfig(8) to treat interface "names" beginning with 'hw-'
> > as link-level addresses; ifconfig tries to find an interface with this
> > address and behaves as if its name was specified on the command line:
> >=20
> > [roam@straylight ~/fbsd/r/src/sbin/ifconfig]> ./ifconfig hw-00:03:0d:08=
:dc:a7
> > sis0: flags=3D8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> >         options=3D8<VLAN_MTU>
> >         inet 10.0.8.129 netmask 0xffff0000 broadcast 10.0.255.255
> >         inet 192.168.1.13 netmask 0xffffff00 broadcast 192.168.1.255
> >         ether 00:03:0d:08:dc:a7
> >         media: Ethernet autoselect (100baseTX <full-duplex>)
> >         status: active
> > [roam@straylight ~/fbsd/r/src/sbin/ifconfig]>
> >=20
> > This could be the first step towards teaching rc.conf about something l=
ike
> > network_interfaces_rename=3D"hw-00:03:0d:08:dc:a7 sis0int"
> >=20
> > I had initially written my own function for parsing the user-supplied
> > address into a sequence of bytes instead of using ether_aton(); it would
> > have the advantage of being able to specify 'hw-' to match lo0's empty
> > link-level "address".  However, the odds of somebody actually wishing to
> > rename lo0 don't seem to be so high :)
>=20
> I don't really like the idea of adding magic values to the interface
> namespace that only work with ifconfig.  If you want ifconfig to match
> the lladdr, I'd suggest adding a flag that means match interface by
> address instead of by name.  That would be a fairly simple change to
> your patch and seems like a potentialy useful feature.

Agreed, I don't like the magic hw- too much either, but.. see below for
more comments on this and interface renaming on startup.

> FWIW, I've talked to Warner about automaticly renaming interfaces based
> on things like their MAC address or their PCI slot and we think devd
> will eventually be the place to do this.  We're probably going to have
> to rethink interface configuration for this to work though.

Well, it turned out that adding basic interface renaming support to our
startup scripts wasn't all that hard - the attached patch, also at
http://www.ringlet.net/~roam/bsd-patches/src5/etc-iface-rename.patch
http://people.FreeBSD.org/~roam/bsd-patches/src5/etc-iface-rename.patch
seems to work for both 'sis0 ethlocal xl0 ethext' and
'hw-00:03:0d:08:dc:a7 ethlocal', since it just passes the interface name
to ifconfig(8).

If the link-level address matching should be done with a separate
ifconfig(8) option, the interface renaming may need to be split into two
stages controlled by two configuration variables - one specifying the
'source' interface by name, the other one by address, with the latter
code using the new ifconfig option.

Of course, this still leaves a problem with specifying the address for
an interface that has not yet been 'found' - after all, we can't
ifmaybeload() a driver on just the link-level address of the card.  This
is a case when devd might be a better solution indeed.  However, I don't
think that people who use interface renaming will depend on the system
automatically discovering the *types* of network cards: if you know the
MAC address of the card, you'll probably know just what brand and model
it is, too :)

G'luck,
Peter

--=20
Peter Pentchev	roam@ringlet.net    roam@sbnd.net    roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
This sentence contradicts itself - or rather - well, no, actually it doesn'=
t!

--CE+1k2dSO48ffgeK
Content-Type: text/plain; charset=windows-1251
Content-Disposition: attachment; filename="etc-iface-rename.patch"
Content-Transfer-Encoding: quoted-printable

Index: src/etc/defaults/rc.conf
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.205
diff -u -r1.205 rc.conf
--- src/etc/defaults/rc.conf	10 Apr 2004 22:13:27 -0000	1.205
+++ src/etc/defaults/rc.conf	20 May 2004 17:43:07 -0000
@@ -120,6 +120,7 @@
 				# NOTE: this violates the TCP specification
 icmp_drop_redirect=3D"NO" 	# Set to YES to ignore ICMP REDIRECT packets
 icmp_log_redirect=3D"NO"		# Set to YES to log ICMP REDIRECT packets
+network_interfaces_rename=3D"NO"	# Network interface name pairs (or "NO")
 network_interfaces=3D"auto"	# List of network interfaces (or "auto").
 cloned_interfaces=3D""		# List of cloned network interfaces to create.
 #cloned_interfaces=3D"gif0 gif1 gif2 gif3" # Pre-cloning GENERIC config.
Index: src/etc/network.subr
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/etc/network.subr,v
retrieving revision 1.153
diff -u -r1.153 network.subr
--- src/etc/network.subr	11 Aug 2003 20:32:00 -0000	1.153
+++ src/etc/network.subr	21 May 2004 06:40:15 -0000
@@ -623,3 +623,35 @@
 		esac
 	done
 }
+
+# Rename interfaces if the network_interfaces_rename variable is set
+# to 'old new' pair(s), e.g. 'sis0 ethlocal xl0 ethext'.
+rename_ifaces()
+{
+	echo -n 'Renaming interfaces: '
+	case "${network_interfaces_rename}" in
+		[Nn][Oo] | '')
+			echo 'none'
+			;;
+
+		*)
+			if [ "$1" =3D 'stop' ]; then
+				set ${network_interfaces_rename}
+				_v=3D''
+				while [ -n "$1" ]; do
+					_v=3D"$1 ${_v}"
+					shift
+				done
+				set ${_v}
+			else
+				set ${network_interfaces_rename}
+			fi
+			while [ -n "$2" ]; do
+				echo -n "$1 -> $2 "
+				ifconfig "$1" name "$2"=09
+				shift 2
+			done
+			echo 'done'
+			;;
+	esac
+}
Index: src/etc/rc.d/netif
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/etc/rc.d/netif,v
retrieving revision 1.7
diff -u -r1.7 netif
--- src/etc/rc.d/netif	28 Apr 2004 13:20:15 -0000	1.7
+++ src/etc/rc.d/netif	21 May 2004 06:42:25 -0000
@@ -47,6 +47,9 @@
 		# We're operating as a general network start routine.
 		#
=20
+		# Rename interfaces if requested
+		rename_ifaces start
+
 		# Create cloned interfaces
 		clone_up
=20
@@ -70,6 +73,9 @@
 	# Deconfigure the interface(s)
 	network_common ifn_stop
 	echo '.'
+=09
+	# Rename interfaces back if needed
+	rename_ifaces stop
 }
=20
 # network_common routine verbose
Index: src/share/man/man5/rc.conf.5
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/share/man/man5/rc.conf.5,v
retrieving revision 1.216
diff -u -r1.216 rc.conf.5
--- src/share/man/man5/rc.conf.5	28 Apr 2004 23:16:06 -0000	1.216
+++ src/share/man/man5/rc.conf.5	20 May 2004 17:54:22 -0000
@@ -860,6 +860,31 @@
 Refer to
 .Xr ip 4
 for more information.
+.It Va network_interfaces_rename
+.Pq Vt str
+Set to a list of pairs of network interface names to rename on boot.
+For example, if you want the
+.Li sis0
+interface to be actually seen as
+.Li ethlocal
+and the
+.Li xl0
+interface to be seen as
+.Li ethext ,
+this could be set to
+.Dq Li "sis0 ethlocal xl0 ethext" .
+.Pp
+Additionally,
+.Xr ifconfig 8
+may allow specifying interfaces by link-level address by prefixing the
+address with
+.Dq hw- ,
+e.g.
+.Dq Li hw-00:03:0d:08:dc:a7 .
+In this case, you can set the
+.Va network_interfaces_rename
+variable to
+.Dq Li "hw-00:03:0d:08:dc:a7 ethlocal" .
 .It Va network_interfaces
 .Pq Vt str
 Set to the list of network interfaces to configure on this host.

--CE+1k2dSO48ffgeK--

--XF85m9dhOBO43t/C
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAran27Ri2jRYZRVMRAi1QAKCiNo3BJvujhO3U8Hoa4gNs2mE2FACfdseW
Cfk29nwRNk6FXB/GlH0uwc4=
=x3b5
-----END PGP SIGNATURE-----

--XF85m9dhOBO43t/C--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040521070422.GA1292>