]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/40network/parse-ip-opts.sh
ssh-client: s/key/$key
[thirdparty/dracut.git] / modules.d / 40network / parse-ip-opts.sh
CommitLineData
1b31fc14
PS
1#!/bin/sh
2#
3# Format:
cc02093d 4# ip=[dhcp|on|any]
1b31fc14 5#
990e945f 6# ip=<interface>:[dhcp|on|any][:[<mtu>][:<macaddr>]]
1b31fc14 7#
990e945f 8# ip=<client-IP-number>:<server-IP-number>:<gateway-IP-number>:<netmask>:<client-hostname>:<interface>:{dhcp|on|any|none|off}[:[<mtu>][:<macaddr>]]
1b31fc14 9#
8ecd9d01
PS
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#
1b31fc14 14
25aa3c5a 15command -v getarg >/dev/null || . /lib/dracut-lib.sh
1b31fc14 16
b819f519 17if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then
1c709728 18 # No ip= argument(s) for netroot provided, defaulting to DHCP
1b31fc14
PS
19 return;
20fi
21
8ecd9d01
PS
22# Count ip= lines to decide whether we need bootdev= or not
23if [ -z "$NEEDBOOTDEV" ] ; then
edd3262e 24 count=0
3e6d2b31 25 for p in $(getargs ip=); do
5580e4c1
HH
26 case "$p" in
27 ibft)
28 continue;;
29 esac
cc02093d 30 count=$(( $count + 1 ))
8ecd9d01
PS
31 done
32 [ $count -gt 1 ] && NEEDBOOTDEV=1
33fi
edd3262e 34unset count
8ecd9d01
PS
35
36# If needed, check if bootdev= contains anything usable
7081e997
HH
37BOOTDEV=$(getarg bootdev=)
38
8ecd9d01 39if [ -n "$NEEDBOOTDEV" ] ; then
7081e997 40 [ -z "$BOOTDEV" ] && warn "Please supply bootdev argument for multiple ip= lines"
8ecd9d01
PS
41fi
42
1b31fc14
PS
43# Check ip= lines
44# XXX Would be nice if we could errorcheck ip addresses here as well
3e6d2b31
HH
45for p in $(getargs ip=); do
46 ip_to_var $p
1b31fc14 47
feaf30ff
HH
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
25aa3c5a 54 # skip ibft since we did it above
38ba0d7a
HH
55 [ "$autoconf" = "ibft" ] && continue
56
8ecd9d01
PS
57 # We need to have an ip= line for the specified bootdev
58 [ -n "$NEEDBOOTDEV" ] && [ "$dev" = "$BOOTDEV" ] && BOOTDEVOK=1
59
1b31fc14
PS
60 # Empty autoconf defaults to 'dhcp'
61 if [ -z "$autoconf" ] ; then
cc02093d
HH
62 warn "Empty autoconf values default to dhcp"
63 autoconf="dhcp"
1b31fc14
PS
64 fi
65
66 # Error checking for autoconf in combination with other values
67 case $autoconf in
cc02093d
HH
68 error) die "Error parsing option 'ip=$p'";;
69 bootp|rarp|both) die "Sorry, ip=$autoconf is currenty unsupported";;
25aa3c5a 70 none|off)
cc02093d
HH
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"
75 ;;
76 auto6);;
77 dhcp|dhcp6|on|any) \
78 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
79 die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
80 [ -n "$ip" ] && \
81 die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoconf'"
82 ;;
83 *) die "For argument 'ip=$p'\nSorry, unknown value '$autoconf'";;
1b31fc14
PS
84 esac
85
1b31fc14 86 if [ -n "$dev" ] ; then
8ecd9d01 87 # We don't like duplicate device configs
cc02093d
HH
88 if [ -n "$IFACES" ] ; then
89 for i in $IFACES ; do
90 [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'"
91 done
92 fi
93 # IFACES list for later use
94 IFACES="$IFACES $dev"
1b31fc14
PS
95 fi
96
8ecd9d01
PS
97 # Do we need to check for specific options?
98 if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then
cc02093d
HH
99 # Correct device? (Empty is ok as well)
100 [ "$dev" = "$BOOTDEV" ] || continue
101 # Server-ip is there?
102 [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue
103 # dhcp? (It's simpler to check for a set ip. Checks above ensure that if
104 # ip is there, we're static
105 [ -z "$ip" ] && continue
106 # Not good!
107 die "Server-ip or dhcp for netboot needed, but current arguments say otherwise"
1b31fc14
PS
108 fi
109
110done
111
d8a69871 112# put BOOTIF in IFACES to make sure it comes up
ee993857 113if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then
b819f519
HH
114 BOOTDEV=$(fix_bootif $BOOTIF)
115 IFACES="$BOOTDEV $IFACES"
d8a69871
WW
116fi
117
8ecd9d01 118# This ensures that BOOTDEV is always first in IFACES
3b403b32 119if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
8ecd9d01
PS
120 IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
121 IFACES="$BOOTDEV $IFACES"
122fi
123
124# Store BOOTDEV and IFACES for later use
125[ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
126[ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces