]> git.ipfire.org Git - thirdparty/dracut.git/blame_incremental - modules.d/40network/parse-ip-opts.sh
systemd: add systemd-run and systemd-escape
[thirdparty/dracut.git] / modules.d / 40network / parse-ip-opts.sh
... / ...
CommitLineData
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
15command -v getarg >/dev/null || . /lib/dracut-lib.sh
16
17if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then
18 # No ip= argument(s) for netroot provided, defaulting to DHCP
19 return;
20fi
21
22# Count ip= lines to decide whether we need bootdev= or not
23if [ -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
33fi
34unset count
35
36# If needed, check if bootdev= contains anything usable
37BOOTDEV=$(getarg bootdev=)
38
39if [ -n "$NEEDBOOTDEV" ] ; then
40 [ -z "$BOOTDEV" ] && warn "Please supply bootdev argument for multiple ip= lines"
41fi
42
43# Check ip= lines
44# XXX Would be nice if we could errorcheck ip addresses here as well
45for p in $(getargs ip=); do
46 ip_to_var $p
47
48 # make first device specified the BOOTDEV
49 if [ -z "$BOOTDEV" ] && [ -n "$dev" ]; then
50 BOOTDEV="$dev"
51 [ -n "$NEEDBOOTDEV" ] && warn "Setting bootdev to '$BOOTDEV'"
52 fi
53
54 # skip ibft since we did it above
55 [ "$autoconf" = "ibft" ] && continue
56
57 # We need to have an ip= line for the specified bootdev
58 [ -n "$NEEDBOOTDEV" ] && [ "$dev" = "$BOOTDEV" ] && BOOTDEVOK=1
59
60 # Empty autoconf defaults to 'dhcp'
61 if [ -z "$autoconf" ] ; then
62 warn "Empty autoconf values default to dhcp"
63 autoconf="dhcp"
64 fi
65
66 # Error checking for autoconf in combination with other values
67 for autoopt in $(str_replace "$autoconf" "," " "); do
68 case $autoopt in
69 error) die "Error parsing option 'ip=$p'";;
70 bootp|rarp|both) die "Sorry, ip=$autoopt is currenty unsupported";;
71 none|off)
72 [ -z "$ip" ] && \
73 die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense"
74 [ -z "$mask" ] && \
75 die "Sorry, automatic calculation of netmask is not yet supported"
76 ;;
77 auto6);;
78 dhcp|dhcp6|on|any) \
79 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
80 die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
81 [ -n "$ip" ] && \
82 die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'"
83 ;;
84 *) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'";;
85 esac
86 done
87
88 if [ -n "$dev" ] ; then
89 # We don't like duplicate device configs
90 if [ -n "$IFACES" ] ; then
91 for i in $IFACES ; do
92 [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'"
93 done
94 fi
95 # IFACES list for later use
96 IFACES="$IFACES $dev"
97 fi
98
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"
110 fi
111
112done
113
114# put BOOTIF in IFACES to make sure it comes up
115if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then
116 BOOTDEV=$(fix_bootif $BOOTIF)
117 IFACES="$BOOTDEV $IFACES"
118fi
119
120# This ensures that BOOTDEV is always first in IFACES
121if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
122 IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
123 IFACES="$BOOTDEV $IFACES"
124fi
125
126# Store BOOTDEV and IFACES for later use
127[ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
128[ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces