]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/35network-legacy/parse-ip-opts.sh
network-legacy: split off from network module
[thirdparty/dracut.git] / modules.d / 35network-legacy / 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
4e9ba952
HH
39if [ -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"
f4f8fb5c
HH
43else
44 unset NEEDBOOTDEV
8ecd9d01
PS
45fi
46
1b31fc14
PS
47# Check ip= lines
48# XXX Would be nice if we could errorcheck ip addresses here as well
3e6d2b31
HH
49for p in $(getargs ip=); do
50 ip_to_var $p
1b31fc14 51
feaf30ff 52 # make first device specified the BOOTDEV
f4f8fb5c 53 if [ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEV" ] && [ -n "$dev" ]; then
feaf30ff 54 BOOTDEV="$dev"
f4f8fb5c 55 info "Setting bootdev to '$BOOTDEV'"
feaf30ff
HH
56 fi
57
25aa3c5a 58 # skip ibft since we did it above
38ba0d7a
HH
59 [ "$autoconf" = "ibft" ] && continue
60
1b31fc14
PS
61 # Empty autoconf defaults to 'dhcp'
62 if [ -z "$autoconf" ] ; then
cc02093d
HH
63 warn "Empty autoconf values default to dhcp"
64 autoconf="dhcp"
1b31fc14
PS
65 fi
66
67 # Error checking for autoconf in combination with other values
93342718
HH
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);;
67354eeb 79 either6);;
93342718
HH
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
1b31fc14 89
1b31fc14 90 if [ -n "$dev" ] ; then
8ecd9d01 91 # We don't like duplicate device configs
cc02093d
HH
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"
1b31fc14
PS
99 fi
100
8ecd9d01
PS
101 # Do we need to check for specific options?
102 if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then
cc02093d
HH
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"
1b31fc14
PS
112 fi
113
0c004c8e
HH
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
1b31fc14
PS
124done
125
d8a69871 126# put BOOTIF in IFACES to make sure it comes up
ee993857 127if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then
b819f519
HH
128 BOOTDEV=$(fix_bootif $BOOTIF)
129 IFACES="$BOOTDEV $IFACES"
d8a69871
WW
130fi
131
8ecd9d01 132# This ensures that BOOTDEV is always first in IFACES
3b403b32 133if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then
8ecd9d01
PS
134 IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
135 IFACES="$BOOTDEV $IFACES"
136fi
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