]>
Commit | Line | Data |
---|---|---|
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 | 15 | command -v getarg >/dev/null || . /lib/dracut-lib.sh |
1b31fc14 | 16 | |
b819f519 | 17 | if [ -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; |
20 | fi | |
21 | ||
8ecd9d01 PS |
22 | # Count ip= lines to decide whether we need bootdev= or not |
23 | if [ -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 | |
33 | fi | |
edd3262e | 34 | unset count |
8ecd9d01 PS |
35 | |
36 | # If needed, check if bootdev= contains anything usable | |
7081e997 HH |
37 | BOOTDEV=$(getarg bootdev=) |
38 | ||
8ecd9d01 | 39 | if [ -n "$NEEDBOOTDEV" ] ; then |
7081e997 | 40 | [ -z "$BOOTDEV" ] && warn "Please supply bootdev argument for multiple ip= lines" |
8ecd9d01 PS |
41 | fi |
42 | ||
1b31fc14 PS |
43 | # Check ip= lines |
44 | # XXX Would be nice if we could errorcheck ip addresses here as well | |
3e6d2b31 HH |
45 | for 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 | |
93342718 HH |
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 | |
1b31fc14 | 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 | # Do we need to check for specific options? |
100 | if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then | |
cc02093d HH |
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" | |
1b31fc14 PS |
110 | fi |
111 | ||
112 | done | |
113 | ||
d8a69871 | 114 | # put BOOTIF in IFACES to make sure it comes up |
ee993857 | 115 | if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then |
b819f519 HH |
116 | BOOTDEV=$(fix_bootif $BOOTIF) |
117 | IFACES="$BOOTDEV $IFACES" | |
d8a69871 WW |
118 | fi |
119 | ||
8ecd9d01 | 120 | # This ensures that BOOTDEV is always first in IFACES |
3b403b32 | 121 | if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then |
8ecd9d01 PS |
122 | IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}" |
123 | IFACES="$BOOTDEV $IFACES" | |
124 | fi | |
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 |