]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/40network/parse-ip-opts.sh
combine some instmods
[thirdparty/dracut.git] / modules.d / 40network / parse-ip-opts.sh
CommitLineData
1b31fc14 1#!/bin/sh
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
1b31fc14
PS
4#
5# Format:
cc02093d 6# ip=[dhcp|on|any]
1b31fc14 7#
990e945f 8# ip=<interface>:[dhcp|on|any][:[<mtu>][:<macaddr>]]
1b31fc14 9#
990e945f 10# ip=<client-IP-number>:<server-IP-number>:<gateway-IP-number>:<netmask>:<client-hostname>:<interface>:{dhcp|on|any|none|off}[:[<mtu>][:<macaddr>]]
1b31fc14 11#
8ecd9d01
PS
12# When supplying more than only ip= line, <interface> is mandatory and
13# bootdev= must contain the name of the primary interface to use for
14# routing,dns,dhcp-options,etc.
15#
1b31fc14 16
25aa3c5a
WW
17command -v getarg >/dev/null || . /lib/dracut-lib.sh
18command -v ibft_to_cmdline >/dev/null || . /lib/net-lib.sh
1b31fc14 19
3029be4d
PS
20# Don't mix BOOTIF=macaddr from pxelinux and ip= lines
21getarg ip= >/dev/null && getarg BOOTIF= >/dev/null && \
22 die "Mixing BOOTIF and ip= lines is dangerous"
23
24# No more parsing stuff, BOOTIF says everything
25[ -n "$(getarg BOOTIF)" ] && return
26
1b31fc14 27if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] ; then
1c709728 28 # No ip= argument(s) for netroot provided, defaulting to DHCP
1b31fc14
PS
29 return;
30fi
31
8ecd9d01
PS
32# Count ip= lines to decide whether we need bootdev= or not
33if [ -z "$NEEDBOOTDEV" ] ; then
edd3262e 34 count=0
3e6d2b31 35 for p in $(getargs ip=); do
cc02093d 36 count=$(( $count + 1 ))
8ecd9d01
PS
37 done
38 [ $count -gt 1 ] && NEEDBOOTDEV=1
39fi
edd3262e 40unset count
8ecd9d01
PS
41
42# If needed, check if bootdev= contains anything usable
43if [ -n "$NEEDBOOTDEV" ] ; then
44 BOOTDEV=$(getarg bootdev=) || die "Please supply bootdev argument for multiple ip= lines"
45 [ -z "$BOOTDEV" ] && die "Bootdev argument is empty"
46fi
47
25aa3c5a
WW
48# If ibft is requested, read ibft vals and write ip=XXX cmdline args
49[ "ibft" = "$(getarg ip=)" ] && ibft_to_cmdline
38ba0d7a 50
1b31fc14
PS
51# Check ip= lines
52# XXX Would be nice if we could errorcheck ip addresses here as well
3e6d2b31
HH
53for p in $(getargs ip=); do
54 ip_to_var $p
1b31fc14 55
25aa3c5a 56 # skip ibft since we did it above
38ba0d7a
HH
57 [ "$autoconf" = "ibft" ] && continue
58
8ecd9d01
PS
59 # We need to have an ip= line for the specified bootdev
60 [ -n "$NEEDBOOTDEV" ] && [ "$dev" = "$BOOTDEV" ] && BOOTDEVOK=1
61
1b31fc14
PS
62 # Empty autoconf defaults to 'dhcp'
63 if [ -z "$autoconf" ] ; then
cc02093d
HH
64 warn "Empty autoconf values default to dhcp"
65 autoconf="dhcp"
1b31fc14
PS
66 fi
67
68 # Error checking for autoconf in combination with other values
69 case $autoconf in
cc02093d
HH
70 error) die "Error parsing option 'ip=$p'";;
71 bootp|rarp|both) die "Sorry, ip=$autoconf is currenty unsupported";;
25aa3c5a 72 none|off)
cc02093d
HH
73 [ -z "$ip" ] && \
74 die "For argument 'ip=$p'\nValue '$autoconf' 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 dhcp|dhcp6|on|any) \
80 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
81 die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
82 [ -n "$ip" ] && \
83 die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoconf'"
84 ;;
85 *) die "For argument 'ip=$p'\nSorry, unknown value '$autoconf'";;
1b31fc14
PS
86 esac
87
1b31fc14 88 if [ -n "$dev" ] ; then
8ecd9d01 89 # We don't like duplicate device configs
cc02093d
HH
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"
1b31fc14
PS
97 fi
98
8ecd9d01
PS
99 # Small optimization for udev rules
100 [ -z "$NEEDBOOTDEV" ] && [ -n "$dev" ] && BOOTDEV=$dev
101
102 # Do we need to check for specific options?
103 if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then
cc02093d
HH
104 # Correct device? (Empty is ok as well)
105 [ "$dev" = "$BOOTDEV" ] || continue
106 # Server-ip is there?
107 [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue
108 # dhcp? (It's simpler to check for a set ip. Checks above ensure that if
109 # ip is there, we're static
110 [ -z "$ip" ] && continue
111 # Not good!
112 die "Server-ip or dhcp for netboot needed, but current arguments say otherwise"
1b31fc14
PS
113 fi
114
115done
116
8ecd9d01 117# This ensures that BOOTDEV is always first in IFACES
3b403b32 118if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
8ecd9d01
PS
119 IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
120 IFACES="$BOOTDEV $IFACES"
121fi
122
123# Store BOOTDEV and IFACES for later use
124[ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
125[ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces
1b31fc14 126
3b403b32 127# We need a ip= line for the configured bootdev=
1c709728 128[ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEVOK" ] && die "Bootdev Argument '$BOOTDEV' not found"