[test] Assign unique MAC addresses for test network devices

Commit 19dffdc ("[efi] Allow for creating devices with no EFI parent
device") relaxed the restriction on attempting to create SNP devices
when no EFI parent device is available, with the result that the test
network devices created when running the IPv4 tests are now registered
as SNP devices.

Since the dummy EFI parent device path is fixed and the test network
device MAC addresses are empty, the SNP devices end up with identical
constructed device paths and registration of the second and subsequent
devices will fail since device paths must be unique.

Fix by assigning MAC addresses to the test network devices.

Reported-by: Miao Wang <shankerwangmiao@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2026-03-09 22:52:38 +00:00
parent 5edffb26b2
commit e180aa85e6
3 changed files with 15 additions and 7 deletions
+6 -6
View File
@@ -186,36 +186,36 @@ static void ipv4_route_okx ( const char *dest, struct testnet *scope,
__FILE__, __LINE__ ) __FILE__, __LINE__ )
/** net0: Single address and gateway (DHCP assignment) */ /** net0: Single address and gateway (DHCP assignment) */
TESTNET ( net0, TESTNET ( net0, "52:54:00:59:ba:c9",
{ "dhcp/ip", "192.168.0.1" }, { "dhcp/ip", "192.168.0.1" },
{ "dhcp/netmask", "255.255.255.0" }, { "dhcp/netmask", "255.255.255.0" },
{ "dhcp/gateway", "192.168.0.254" } ); { "dhcp/gateway", "192.168.0.254" } );
/** net1: Single address and gateway (DHCP assignment) */ /** net1: Single address and gateway (DHCP assignment) */
TESTNET ( net1, TESTNET ( net1, "52:54:00:1a:db:95",
{ "dhcp/ip", "192.168.0.2" }, { "dhcp/ip", "192.168.0.2" },
{ "dhcp/netmask", "255.255.255.0" }, { "dhcp/netmask", "255.255.255.0" },
{ "dhcp/gateway", "192.168.0.254" } ); { "dhcp/gateway", "192.168.0.254" } );
/** net2: Small /31 subnet mask */ /** net2: Small /31 subnet mask */
TESTNET ( net2, TESTNET ( net2, "52:54:00:f9:ee:21",
{ "ip", "10.31.31.0" }, { "ip", "10.31.31.0" },
{ "netmask", "255.255.255.254" }, { "netmask", "255.255.255.254" },
{ "gateway", "10.31.31.1" } ); { "gateway", "10.31.31.1" } );
/** net3: Small /32 subnet mask */ /** net3: Small /32 subnet mask */
TESTNET ( net3, TESTNET ( net3, "52:54:00:4a:88:ec",
{ "ip", "10.32.32.32" }, { "ip", "10.32.32.32" },
{ "netmask", "255.255.255.255" }, { "netmask", "255.255.255.255" },
{ "gateway", "192.168.32.254" } ); { "gateway", "192.168.32.254" } );
/** net4: Local subnet with no gateway */ /** net4: Local subnet with no gateway */
TESTNET ( net4, TESTNET ( net4, "52:54:00:68:ad:cd",
{ "ip", "192.168.86.1" }, { "ip", "192.168.86.1" },
{ "netmask", "255.255.240.0" } ); { "netmask", "255.255.240.0" } );
/** net5: Static routes */ /** net5: Static routes */
TESTNET ( net5, TESTNET ( net5, "52:54:00:b0:d5:07",
{ "ip", "10.42.0.1" }, { "ip", "10.42.0.1" },
{ "netmask", "255.255.0.0" }, { "netmask", "255.255.0.0" },
{ "gateway", "10.42.0.254" /* should be ignored */ }, { "gateway", "10.42.0.254" /* should be ignored */ },
+4
View File
@@ -36,6 +36,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdio.h> #include <stdio.h>
#include <ipxe/netdevice.h> #include <ipxe/netdevice.h>
#include <ipxe/ethernet.h> #include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/base16.h>
#include <ipxe/test.h> #include <ipxe/test.h>
#include "netdev_test.h" #include "netdev_test.h"
@@ -113,6 +115,8 @@ void testnet_okx ( struct testnet *testnet, const char *file,
testnet->netdev->dev = &testnet->dev; testnet->netdev->dev = &testnet->dev;
snprintf ( testnet->netdev->name, sizeof ( testnet->netdev->name ), snprintf ( testnet->netdev->name, sizeof ( testnet->netdev->name ),
"%s", testnet->dev.name ); "%s", testnet->dev.name );
okx ( hex_decode ( ':', testnet->hwaddr, testnet->netdev->hw_addr,
ETH_ALEN ) == ETH_ALEN, file, line );
/* Register device */ /* Register device */
okx ( register_netdev ( testnet->netdev ) == 0, file, line ); okx ( register_netdev ( testnet->netdev ) == 0, file, line );
+5 -1
View File
@@ -26,6 +26,8 @@ struct testnet {
struct net_device *netdev; struct net_device *netdev;
/** Dummy physical device */ /** Dummy physical device */
struct device dev; struct device dev;
/** MAC address */
const char *hwaddr;
/** Initial settings */ /** Initial settings */
struct testnet_setting *testset; struct testnet_setting *testset;
/** Number of initial settings */ /** Number of initial settings */
@@ -36,9 +38,10 @@ struct testnet {
* Declare a test network device * Declare a test network device
* *
* @v NAME Network device name * @v NAME Network device name
* @v HWADDR MAC address
* @v ... Initial network device settings * @v ... Initial network device settings
*/ */
#define TESTNET( NAME, ... ) \ #define TESTNET( NAME, HWADDR, ... ) \
static struct testnet_setting NAME ## _setting[] = { \ static struct testnet_setting NAME ## _setting[] = { \
__VA_ARGS__ \ __VA_ARGS__ \
}; \ }; \
@@ -51,6 +54,7 @@ struct testnet {
.children = \ .children = \
LIST_HEAD_INIT ( NAME.dev.children ), \ LIST_HEAD_INIT ( NAME.dev.children ), \
}, \ }, \
.hwaddr= HWADDR, \
.testset = NAME ## _setting, \ .testset = NAME ## _setting, \
.count = ( sizeof ( NAME ## _setting ) / \ .count = ( sizeof ( NAME ## _setting ) / \
sizeof ( NAME ## _setting[0] ) ), \ sizeof ( NAME ## _setting[0] ) ), \