]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/parse-ip-opts.sh
network: fix an error message
[thirdparty/dracut.git] / modules.d / 40network / parse-ip-opts.sh
1 #!/bin/sh
2 #
3 # Format:
4 # ip=[dhcp|on|any]
5 #
6 # ip=<interface>:[dhcp|on|any][:[<mtu>][:<macaddr>]]
7 #
8 # ip=<client-IP-number>:<server-IP-number>:<gateway-IP-number>:<netmask>:<client-hostname>:<interface>:{dhcp|on|any|none|off}[:[<mtu>][:<macaddr>]]
9 #
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.
13 #
14
15 command -v getarg >/dev/null || . /lib/dracut-lib.sh
16
17 if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then
18 # No ip= argument(s) for netroot provided, defaulting to DHCP
19 return;
20 fi
21
22 # Count ip= lines to decide whether we need bootdev= or not
23 if [ -z "$NEEDBOOTDEV" ] ; then
24 count=0
25 for p in $(getargs ip=); do
26 case "$p" in
27 ibft)
28 continue;;
29 esac
30 count=$(( $count + 1 ))
31 done
32 [ $count -gt 1 ] && NEEDBOOTDEV=1
33 fi
34 unset count
35
36 # If needed, check if bootdev= contains anything usable
37 BOOTDEV=$(getarg bootdev=)
38
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"
43 else
44 unset NEEDBOOTDEV
45 fi
46
47 # Check ip= lines
48 # XXX Would be nice if we could errorcheck ip addresses here as well
49 for p in $(getargs ip=); do
50 ip_to_var $p
51
52 # make first device specified the BOOTDEV
53 if [ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEV" ] && [ -n "$dev" ]; then
54 BOOTDEV="$dev"
55 info "Setting bootdev to '$BOOTDEV'"
56 fi
57
58 # skip ibft since we did it above
59 [ "$autoconf" = "ibft" ] && continue
60
61 # Empty autoconf defaults to 'dhcp'
62 if [ -z "$autoconf" ] ; then
63 warn "Empty autoconf values default to dhcp"
64 autoconf="dhcp"
65 fi
66
67 # Error checking for autoconf in combination with other values
68 for autoopt in $(str_replace "$autoconf" "," " "); do
69 case $autoopt in
70 error) die "Error parsing option 'ip=$p'";;
71 bootp|rarp|both) die "Sorry, ip=$autoopt is currenty unsupported";;
72 none|off)
73 [ -z "$ip" ] && \
74 die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense"
75 [ -z "$mask" ] && \
76 die "Sorry, automatic calculation of netmask is not yet supported"
77 ;;
78 auto6);;
79 either6);;
80 dhcp|dhcp6|on|any) \
81 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
82 die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
83 [ -n "$ip" ] && \
84 die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'"
85 ;;
86 *) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'";;
87 esac
88 done
89
90 if [ -n "$dev" ] ; then
91 # We don't like duplicate device configs
92 if [ -n "$IFACES" ] ; then
93 for i in $IFACES ; do
94 [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'"
95 done
96 fi
97 # IFACES list for later use
98 IFACES="$IFACES $dev"
99 fi
100
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
110 # Not good!
111 die "Server-ip or dhcp for netboot needed, but current arguments say otherwise"
112 fi
113
114 if str_starts "$dev" "enx" && [ ${#dev} -eq 15 ]; then
115 printf -- "ifname=%s:%s:%s:%s:%s:%s:%s\n" \
116 "$dev" \
117 "${dev:3:2}" \
118 "${dev:5:2}" \
119 "${dev:7:2}" \
120 "${dev:9:2}" \
121 "${dev:11:2}" \
122 "${dev:13:2}" >> /etc/cmdline.d/80-enx.conf
123 fi
124 done
125
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"
130 fi
131
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"
136 fi
137
138 # Store BOOTDEV and IFACES for later use
139 [ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
140 [ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces