]> git.ipfire.org Git - thirdparty/libvirt.git/commit
network: truncate bridges' dummy tap device names to IFNAMSIZ (15) chars
authorLaine Stump <laine@laine.org>
Wed, 13 Apr 2011 16:38:58 +0000 (12:38 -0400)
committerLaine Stump <laine@laine.org>
Thu, 14 Apr 2011 19:24:17 +0000 (15:24 -0400)
commit020ad8d1a272a7974cdcd897706fa12744802533
treea933ba846e6f43e786dbc36089a18d331ad169f1
parentd21f9d5a641aa6e2cc0539374c6b579941f98dba
network: truncate bridges' dummy tap device names to IFNAMSIZ (15) chars

This patch addresses:

   https://bugzilla.redhat.com/show_bug.cgi?id=694382

In order to give each libvirt-created bridge a fixed MAC address,
commit 5754dbd56d4738112a86776c09e810e32f7c3224, added code to create
a dummy tap device with guaranteed lowest MAC address and attach it to
the bridge. This tap device was given the name "${bridgename}-nic".
However, an interface device name must be IFNAMSIZ (15) characters or
less, so a valid ${bridgename} such as "verylongname123" (15
characters) would lead to an invalid tap device name
("verylongname123-nic" - 19 characters), and that in turn led to a
failure to bring up the network.

The solution is to shorten the part of the original name used to
generate the tap device name. However, simply truncating it is
insufficient, because the last few characters of an interface name are
often a number used to indicate one of a list of several similar
devices (for example, "verylongname123", "verylongname124", etc) and
simple truncation would lead to duplicate names (eg "verlongnam-nic"
and "verylongnam-nic"). So instead we take the first 8 characters of
$bridgename ("verylong" in the example), add on the final 3 bytes
("123"), then add "-nic" (so "verylong123-nic").  Not pretty, but it
is much more likely to generate a unique name, and is reproducible
(unlike, say, a random number).
src/network/bridge_driver.c