dracut.8: fix rd_LVM_LV description
[dracut.git] / modules.d / 40network / parse-ip-opts.sh
blob327ba5e027b79ac8ddfbd09140b32d78c4c0cc55
1 #!/bin/sh
3 # Format:
4 # ip=[dhcp|on|any]
6 # ip=<interface>:[dhcp|on|any]
8 # ip=<client-IP-number>:<server-id>:<gateway-IP-number>:<netmask>:<client-hostname>:<interface>:[dhcp|on|any|none|off]
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 . /lib/dracut-lib.sh
17 # Check if ip= lines should be used
18 if getarg ip= >/dev/null ; then
19 if [ -z "$netroot" ] ; then
20 echo "Warning: No netboot configured, ignoring ip= lines"
21 return;
25 # Don't mix BOOTIF=macaddr from pxelinux and ip= lines
26 getarg ip= >/dev/null && getarg BOOTIF= >/dev/null && \
27 die "Mixing BOOTIF and ip= lines is dangerous"
29 # No more parsing stuff, BOOTIF says everything
30 [ -n "$(getarg BOOTIF)" ] && return
32 if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] ; then
33 # No ip= argument(s) for netroot provided, defaulting to DHCP
34 return;
37 # Count ip= lines to decide whether we need bootdev= or not
38 if [ -z "$NEEDBOOTDEV" ] ; then
39 local count=0
40 for p in $(getargs ip=); do
41 count=$(( $count + 1 ))
42 done
43 [ $count -gt 1 ] && NEEDBOOTDEV=1
46 # If needed, check if bootdev= contains anything usable
47 if [ -n "$NEEDBOOTDEV" ] ; then
48 BOOTDEV=$(getarg bootdev=) || die "Please supply bootdev argument for multiple ip= lines"
49 [ -z "$BOOTDEV" ] && die "Bootdev argument is empty"
52 # Check ip= lines
53 # XXX Would be nice if we could errorcheck ip addresses here as well
54 for p in $(getargs ip=); do
55 ip_to_var $p
57 # We need to have an ip= line for the specified bootdev
58 [ -n "$NEEDBOOTDEV" ] && [ "$dev" = "$BOOTDEV" ] && BOOTDEVOK=1
60 # Empty autoconf defaults to 'dhcp'
61 if [ -z "$autoconf" ] ; then
62 warn "Empty autoconf values default to dhcp"
63 autoconf="dhcp"
66 # Error checking for autoconf in combination with other values
67 case $autoconf in
68 error) die "Error parsing option 'ip=$p'";;
69 bootp|rarp|both) die "Sorry, ip=$autoconf is currenty unsupported";;
70 none|off) \
71 [ -z "$ip" ] && \
72 die "For argument 'ip=$p'\nValue '$autoconf' without static configuration does not make sense"
73 [ -z "$mask" ] && \
74 die "Sorry, automatic calculation of netmask is not yet supported"
76 dhcp|on|any) \
77 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
78 die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
79 [ -n "$ip" ] && \
80 die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoconf'"
82 *) die "For argument 'ip=$p'\nSorry, unknown value '$autoconf'";;
83 esac
85 if [ -n "$dev" ] ; then
86 # We don't like duplicate device configs
87 if [ -n "$IFACES" ] ; then
88 for i in $IFACES ; do
89 [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'"
90 done
92 # IFACES list for later use
93 IFACES="$IFACES $dev"
96 # Small optimization for udev rules
97 [ -z "$NEEDBOOTDEV" ] && [ -n "$dev" ] && BOOTDEV=$dev
99 # Do we need to check for specific options?
100 if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then
101 # Correct device? (Empty is ok as well)
102 [ "$dev" = "$BOOTDEV" ] || continue
103 # Server-ip is there?
104 [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue
105 # dhcp? (It's simpler to check for a set ip. Checks above ensure that if
106 # ip is there, we're static
107 [ -z "$ip" ] && continue
108 # Not good!
109 die "Server-ip or dhcp for netboot needed, but current arguments say otherwise"
112 done
114 # This ensures that BOOTDEV is always first in IFACES
115 if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
116 IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
117 IFACES="$BOOTDEV $IFACES"
120 # Store BOOTDEV and IFACES for later use
121 [ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
122 [ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces
124 # We need a ip= line for the configured bootdev=
125 [ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEVOK" ] && die "Bootdev Argument '$BOOTDEV' not found"