]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/parse-ip-opts.sh
6 # ip=<interface>:[dhcp|on|any][:[<mtu>][:<macaddr>]]
8 # ip=<client-IP-number>:<server-IP-number>:<gateway-IP-number>:<netmask>:<client-hostname>:<interface>:{dhcp|on|any|none|off}[:[<mtu>][:<macaddr>]]
10 # When supplying more than only ip= line, <interface> is mandatory and
11 # bootdev= must contain the name of the primary interface to use for
12 # routing,dns,dhcp-options,etc.
15 command -v getarg
>/dev
/null || .
/lib
/dracut-lib.sh
17 if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then
18 # No ip= argument(s) for netroot provided, defaulting to DHCP
22 # Count ip= lines to decide whether we need bootdev= or not
23 if [ -z "$NEEDBOOTDEV" ] ; then
25 for p
in $
(getargs ip
=); do
30 count
=$
(( $count + 1 ))
32 [ $count -gt 1 ] && NEEDBOOTDEV
=1
36 # If needed, check if bootdev= contains anything usable
37 BOOTDEV
=$
(getarg bootdev
=)
39 if [ -n "$NEEDBOOTDEV" ] && getargbool
1 rd.neednet
; then
40 #[ -z "$BOOTDEV" ] && warn "Please supply bootdev argument for multiple ip= lines"
41 echo "rd.neednet=1" > /etc
/cmdline.d
/dracut-neednet.conf
42 info
"Multiple ip= arguments: assuming rd.neednet=1"
48 # XXX Would be nice if we could errorcheck ip addresses here as well
49 for p
in $
(getargs ip
=); do
52 # make first device specified the BOOTDEV
53 if [ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEV" ] && [ -n "$dev" ]; then
55 info
"Setting bootdev to '$BOOTDEV'"
58 # skip ibft since we did it above
59 [ "$autoconf" = "ibft" ] && continue
61 # Empty autoconf defaults to 'dhcp'
62 if [ -z "$autoconf" ] ; then
63 warn
"Empty autoconf values default to dhcp"
67 # Error checking for autoconf in combination with other values
68 for autoopt
in $
(str_replace
"$autoconf" "," " "); do
70 error
) die
"Error parsing option 'ip=$p'";;
71 bootp|rarp|both
) die
"Sorry, ip=$autoopt is currenty unsupported";;
74 die
"For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense"
76 die
"Sorry, automatic calculation of netmask is not yet supported"
81 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
82 die
"Sorry, 'ip=$p' does not make sense for multiple interface configurations"
84 die
"For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'"
86 *) die
"For argument 'ip=$p'\nSorry, unknown value '$autoopt'";;
90 if [ -n "$dev" ] ; then
91 # We don't like duplicate device configs
92 if [ -n "$IFACES" ] ; then
94 [ "$dev" = "$i" ] && die
"For argument 'ip=$p'\nDuplication configurations for '$dev'"
97 # IFACES list for later use
101 # Do we need to check for specific options?
102 if [ -n "$NEEDDHCP" ] ||
[ -n "$DHCPORSERVER" ] ; then
103 # Correct device? (Empty is ok as well)
104 [ "$dev" = "$BOOTDEV" ] ||
continue
105 # Server-ip is there?
106 [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue
107 # dhcp? (It's simpler to check for a set ip. Checks above ensure that if
108 # ip is there, we're static
109 [ -z "$ip" ] && continue
111 die
"Server-ip or dhcp for netboot needed, but current arguments say otherwise"
114 if str_starts
"$dev" "enx" && [ ${#dev} -eq 15 ]; then
115 printf -- "ifname=%s:%s:%s:%s:%s:%s:%s\n" \
122 "${dev:13:2}" >> /etc
/cmdline.d
/80-enx.conf
126 # put BOOTIF in IFACES to make sure it comes up
127 if getargbool
1 "rd.bootif" && BOOTIF
="$(getarg BOOTIF=)"; then
128 BOOTDEV
=$
(fix_bootif
$BOOTIF)
129 IFACES
="$BOOTDEV $IFACES"
132 # This ensures that BOOTDEV is always first in IFACES
133 if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
134 IFACES
="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
135 IFACES
="$BOOTDEV $IFACES"
138 # Store BOOTDEV and IFACES for later use
139 [ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp
/net.bootdev
140 [ -n "$IFACES" ] && echo $IFACES > /tmp
/net.ifaces