network-generator: support BOOTIF= and rd.bootif=0 options (#41028)

The network generator currently supports many of the options described
by dracut.cmdline(7), but not everything.

This commit adds support for the BOOTIF= option (and the related
rd.bootif= option) used in PXE setups.

This is implemented by treating BOOTIF as a special name/placeholder
when used as an interface name, and expecting a MAC address to be set in
the BOOTIF= parameter. The resulting .network file then uses MACAddress=
in the [Match] section, instead of Name=.
This commit is contained in:
Lennart Poettering
2026-04-02 16:17:11 +02:00
committed by GitHub
8 changed files with 231 additions and 25 deletions
+24
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <net/ethernet.h>
#include <net/if_arp.h>
#include <stdio.h>
#include "ether-addr-util.h"
@@ -68,6 +69,29 @@ bool hw_addr_is_null(const struct hw_addr_data *addr) {
return addr->length == 0 || memeqzero(addr->bytes, addr->length);
}
bool hw_addr_is_valid(const struct hw_addr_data *addr, uint16_t iftype) {
assert(addr);
switch (iftype) {
case ARPHRD_ETHER:
/* Refuse all zero and all 0xFF. */
if (addr->length != ETH_ALEN)
return false;
return !ether_addr_is_null(&addr->ether) && !ether_addr_is_broadcast(&addr->ether);
case ARPHRD_INFINIBAND:
/* The last 8 bytes cannot be zero. */
if (addr->length != INFINIBAND_ALEN)
return false;
return !memeqzero(addr->bytes + INFINIBAND_ALEN - 8, 8);
default:
return false;
}
}
DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare);
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(hw_addr_hash_ops_free, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare, free);
+1
View File
@@ -57,6 +57,7 @@ static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_a
return hw_addr_compare(a, b) == 0;
}
bool hw_addr_is_null(const struct hw_addr_data *addr) _pure_;
bool hw_addr_is_valid(const struct hw_addr_data *addr, uint16_t iftype);
extern const struct hash_ops hw_addr_hash_ops;
extern const struct hash_ops hw_addr_hash_ops_free;