Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions board/common/rootfs/usr/libexec/infix/hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh
# Deterministically set system hostname from /etc/hostname.d/
#
# Highest numbered file wins (lexicographic sort, 90-dhcp > 50-configured > 10-default)
#
# Priority scheme:
# 10-default - Bootstrap/factory default (%h-%m format)
# 50-configured - From confd /system/hostname
# 90-dhcp-<iface> - From DHCP clietn on interface (highest priority)

HOSTNAME_D="/etc/hostname.d"

# Ensure directory exists
mkdir -p "$HOSTNAME_D"

# Find the highest priority file (reverse sort, take first)
hostname_file=$(ls -1 "$HOSTNAME_D" 2>/dev/null | sort -r | head -1)

if [ -z "$hostname_file" ]; then
logger -it confd "No hostname sources found in $HOSTNAME_D"
exit 1
fi

# Read hostname from the file (first line only, strip whitespace)
new_hostname=$(cat "$HOSTNAME_D/$hostname_file" | head -1 | tr -d '\n\r\t ')
if [ -z "$new_hostname" ]; then
logger -it confd "Empty hostname in $hostname_file"
exit 1
fi

if [ ${#new_hostname} -gt 64 ]; then
logger -it confd "Hostname too long (${#new_hostname} > 64) in $hostname_file"
exit 1
fi

# Check if hostname has actually changed
current_hostname=$(hostname)
if [ "$new_hostname" = "$current_hostname" ]; then
# No change needed, exit silently
exit 0
fi

# Set the hostname
logger -it confd "Setting hostname to '$new_hostname' from $hostname_file"
hostname "$new_hostname"

# Update /etc/hostname (for persistence across reboots)
echo "$new_hostname" > /etc/hostname

# Update /etc/hosts (127.0.1.1 entry for proper name resolution)
if grep -q "^127\.0\.1\.1" /etc/hosts; then
sed -i -E "s/^(127\.0\.1\.1\s+).*/\1$new_hostname/" /etc/hosts
else
# Add entry if it doesn't exist
echo "127.0.1.1 $new_hostname" >> /etc/hosts
fi

# Notify services of hostname change, skip while in bootstrap
initctl -nbq touch sysklogd
if ! runlevel >/dev/null 2>&1; then
exit 0
fi

initctl -bq status lldpd && lldpcli configure system hostname "$new_hostname" 2>/dev/null
initctl -bq status mdns && avahi-set-host-name "$new_hostname" 2>/dev/null
initctl -bq touch netbrowse 2>/dev/null

# If called from dhcp script we need to reload to activate new name in syslogd
# Otherwise we're called from confd, which does the reload when all is done.
if [ -n "$1" ]; then
initctl -b reload
fi

exit 0
18 changes: 18 additions & 0 deletions board/common/rootfs/usr/libexec/infix/init.d/05-hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Initialize default hostname for hostname.d pattern
# This runs very early in boot to set up the default hostname entry

HOSTNAME_D="/etc/hostname.d"

# Ensure directory exists
mkdir -p "$HOSTNAME_D"

# If no default exists yet, create it from /etc/hostname (from squashfs)
if [ ! -f "$HOSTNAME_D/10-default" ] && [ -f /etc/hostname ]; then
cp /etc/hostname "$HOSTNAME_D/10-default"
fi

# Apply hostname using the deterministic helper
if [ -x /usr/libexec/infix/hostname ]; then
/usr/libexec/infix/hostname
fi
111 changes: 84 additions & 27 deletions board/common/rootfs/usr/share/udhcpc/default.script
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,52 @@ wait_for_ipv6_default_route()
err "Timed out waiting for IPv6 default route!"
}

# Check if a DHCP option was requested in the parameter request list
# Returns: 0 if requested, 1 if not requested or config unavailable
was_option_requested()
{
local opt_num="$1"
local config="/etc/finit.d/available/dhcp-client-${interface}.conf"

if [ ! -f "$config" ]; then
dbg "config file not found: $config"
return 1
fi

# Extract udhcpc command line and check for -O <option_num>
if grep -q -- "-O ${opt_num}\b" "$config"; then
return 0
fi

return 1
}

# RFC3442: If the DHCP server returns both a Classless
# Static Routes option and a Router option, the DHCP
# client MUST ignore the Router option.
set_dhcp_routes()
{
echo "! Generated by udhcpc" > "$NEXT"
if [ -n "$staticroutes" ]; then
# format: dest1/mask gw1 ... destn/mask gwn
set -- $staticroutes
while [ -n "$1" -a -n "$2" ]; do
dbg "adding route $1 via $2 metric $metric tag 100"
echo "ip route $1 $2 $metric tag 100" >> "$NEXT"
shift 2
done
if was_option_requested 121; then
# format: dest1/mask gw1 ... destn/mask gwn
set -- $staticroutes
while [ -n "$1" -a -n "$2" ]; do
dbg "adding route $1 via $2 metric $metric tag 100"
echo "ip route $1 $2 $metric tag 100" >> "$NEXT"
shift 2
done
else
log "ignoring unrequested staticroutes (option 121)"
fi
elif [ -n "$router" ] ; then
for i in $router ; do
echo "ip route 0.0.0.0/0 $i $metric tag 100" >> "$NEXT"
done
if was_option_requested 3; then
for i in $router ; do
echo "ip route 0.0.0.0/0 $i $metric tag 100" >> "$NEXT"
done
else
log "ignoring unrequested router (option 3)"
fi
fi

# Reduce changes needed by comparing with previous route(s)
Expand Down Expand Up @@ -109,6 +137,11 @@ case "$ACTION" in
# drop info from this interface
rm -f "$RESOLV_CONF"
rm -f "$NTPFILE"
if [ -f "/etc/hostname.d/90-dhcp-${interface}" ]; then
log "removing /etc/hostname.d/90-dhcp-${interface}"
rm -f "/etc/hostname.d/90-dhcp-${interface}"
/usr/libexec/infix/hostname dhcp
fi
if [ -x /usr/sbin/avahi-autoipd ]; then
/usr/sbin/avahi-autoipd -c $interface && /usr/sbin/avahi-autoipd -k $interface
fi
Expand All @@ -134,41 +167,65 @@ case "$ACTION" in

set_dhcp_routes

# set hostname if given
# set hostname if given and requested
if [ -n "$hostname" ]; then
log "setting new hostname: $hostname"
hostname "$hostname"
sed -i -E "s/^(127\.0\.1\.1\s+).*/\1$hostname/" /etc/hosts
if was_option_requested 12; then
log "received DHCP hostname: $hostname"
mkdir -p /etc/hostname.d
echo "$hostname" > "/etc/hostname.d/90-dhcp-${interface}"
/usr/libexec/infix/hostname dhcp
else
log "ignoring unrequested hostname (option 12): $hostname"
fi
fi

# drop info from this interface
truncate -s 0 "$RESOLV_CONF"

# prefer rfc3397 domain search list (option 119) if available
search_list=""
if [ -n "$search" ]; then
search_list=$search
if was_option_requested 119; then
search_list=$search
else
log "ignoring unrequested search (option 119): $search"
fi
elif [ -n "$domain" ]; then
search_list=$domain
if was_option_requested 15; then
search_list=$domain
else
log "ignoring unrequested domain (option 15): $domain"
fi
fi

if [ -n "$search_list" ]; then
dbg "adding search $search_list"
echo "search $search_list # $interface" >> $RESOLV_CONF
fi

for i in $dns ; do
dbg "adding dns $i"
echo "nameserver $i # $interface" >> $RESOLV_CONF
resolvconf -u
done
if [ -n "$dns" ]; then
if was_option_requested 6; then
for i in $dns ; do
dbg "adding dns $i"
echo "nameserver $i # $interface" >> $RESOLV_CONF
resolvconf -u
done
else
log "ignoring unrequested dns (option 6): $dns"
fi
fi

if [ -n "$ntpsrv" ]; then
truncate -s 0 "$NTPFILE"
for srv in $ntpsrv; do
dbg "got NTP server $srv"
echo "server $srv iburst" >> "$NTPFILE"
done
chronyc reload sources >/dev/null
if was_option_requested 42; then
truncate -s 0 "$NTPFILE"
for srv in $ntpsrv; do
dbg "got NTP server $srv"
echo "server $srv iburst" >> "$NTPFILE"
done
chronyc reload sources >/dev/null
else
log "ignoring unrequested ntpsrv (option 42): $ntpsrv"
fi
fi
esac

Expand Down
6 changes: 4 additions & 2 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ All notable changes to the project are documented in this file.
### Fixes

- Fix #855: User admin sometimes fails to be added to `wheel` group
- Fix #1112: setting hostname via DHCP client sometimes gets overridden by the
configured system hostname
- Fix #1247: Prevent invalid configuration of OSPF backbone area (0.0.0.0) as
stub or NSSA. The backbone must always be a normal area per RFC 2328. Any
existing invalid configurations are automatically corrected during upgrade
- Fix serious regression in boot time, introduced in v25.10, delays the
boot step "Mounting filesystems ..." with up to 30 seconds!
- Fix #1255: serious regression in boot time, introduced in v25.10, delays the
boot step "Mounting filesystems ...", from 30 seconds up to five minutes!
- Fix broken intra-document links in container and tunnel documentation

[lastest-boot]: https://github.com/kernelkit/infix/releases/latest-boot
Expand Down
Loading