From: afresh1 Date: Mon, 5 Dec 2022 20:12:00 +0000 (+0000) Subject: Add support configuring hostname.if(5) by lladdr X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=af42e33e8d79789a4e4b961a017b8628901de670;p=openbsd Add support configuring hostname.if(5) by lladdr Original implementation by martijn@ Feedback and suggestions from kn@, sthen@, claudio@, florian@, and deraadt@. ok deraadt --- diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index f3883883117..c39b14ed54c 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sub,v 1.1214 2022/11/06 21:32:54 kn Exp $ +# $OpenBSD: install.sub,v 1.1215 2022/12/05 20:12:00 afresh1 Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer @@ -2431,6 +2431,12 @@ ifstart() { local _if=$1 _hn=/mnt/etc/hostname.$1 _cmds _i=0 _line set -A _cmds + if [[ $_if == ??:??:??:??:??:?? ]]; then + _if=$(ifconfig -M $_if) + [[ -z $_if ]] && return # invalid interface + [[ -e /mnt/etc/hostname.$_if ]] && return # duplicate config + fi + # Create interface if it does not yet exist. { ifconfig $_if || ifconfig $_if create; } >/dev/null 2>&1 || return @@ -2472,6 +2478,9 @@ enable_ifs() { svlan) _svlans="$_svlans $_if";; vlan) _vlans="$_vlans $_if";; esac + elif [[ $_if == ??:??:??:??:??:?? ]]; then + # start by lladdr + ifstart $_if else # 'Real' interfaces (if available) are done now. ifconfig $_if >/dev/null 2>&1 && ifstart $_if diff --git a/etc/netstart b/etc/netstart index 7e570c27489..7c4ab2b606d 100644 --- a/etc/netstart +++ b/etc/netstart @@ -1,6 +1,6 @@ #!/bin/sh - # -# $OpenBSD: netstart,v 1.229 2022/11/05 12:06:05 kn Exp $ +# $OpenBSD: netstart,v 1.230 2022/12/05 20:12:00 afresh1 Exp $ # Turn off Strict Bourne shell mode. set +o sh @@ -135,6 +135,22 @@ ifstart() { local _if=$1 _hn=/etc/hostname.$1 _cmds _i=0 _line _stat set -A _cmds + if [[ $_if == ??:??:??:??:??:?? ]]; then + if ! _line=$( ifconfig -M $_if ); then + print -u2 "${0##*/}: $_if is not unique." + return + fi + + [[ -z $_line ]] && return + _if=$_line + _line= + + if [[ -e /etc/hostname.$_if ]]; then + print -u2 "${0##*/}: $_hn: /etc/hostname.$_if overrides" + return + fi + fi + # Interface names must be alphanumeric only. We check to avoid # configuring backup or temp files, and to catch the "*" case. [[ $_if != +([[:alpha:]])+([[:digit:]]) ]] && return @@ -183,14 +199,16 @@ ifmstart() { local _sifs=$1 _xifs=$2 _hn _if _sif _xif for _sif in ${_sifs:-ALL}; do - for _hn in /etc/hostname.+([[:alpha:]])+([[:digit:]]); do + for _hn in /etc/hostname.@(+([[:alpha:]])+([[:digit:]])|??:??:??:??:??:??); do [[ -f $_hn ]] || continue _if=${_hn#/etc/hostname.} - # Skip unwanted ifs. - for _xif in $_xifs; do - [[ $_xif == ${_if%%[0-9]*} ]] && continue 2 - done + if [[ $_if == +([[:alpha:]])+([[:digit:]]) ]]; then + # Skip unwanted ifs. + for _xif in $_xifs; do + [[ $_xif == ${_if%%[0-9]*} ]] && continue 2 + done + fi # Start wanted ifs. [[ $_sif == @(ALL|${_if%%[0-9]*}) ]] && ifstart $_if diff --git a/share/man/man5/hostname.if.5 b/share/man/man5/hostname.if.5 index a7f54f9dbd7..452d562158d 100644 --- a/share/man/man5/hostname.if.5 +++ b/share/man/man5/hostname.if.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: hostname.if.5,v 1.79 2022/07/26 00:36:54 kn Exp $ +.\" $OpenBSD: hostname.if.5,v 1.80 2022/12/05 20:12:00 afresh1 Exp $ .\" $NetBSD: hosts.5,v 1.4 1994/11/30 19:31:20 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)hosts.5 8.2 (Berkeley) 12/11/93 .\" -.Dd $Mdocdate: July 26 2022 $ +.Dd $Mdocdate: December 5 2022 $ .Dt HOSTNAME.IF 5 .Os .Sh NAME @@ -40,10 +40,13 @@ The .Nm hostname.*\& files contain information regarding the configuration of each network interface. -One file should exist for each interface that is to be configured, such as -.Pa hostname.fxp0 +The interface can be referenced by name or lladdr, such as +.Pa hostname.fxp0 , +.Pa hostname.00:00:5e:00:53:af , or .Pa hostname.bridge0 . +One file should exist for each interface that is to be configured, +with priority given to configuration by interface name over lladdr. A configuration file is not needed for lo0. .Pp The configuration information is expressed in a line-by-line packed format