2014-07-21 14:41:52 +02:00
|
|
|
From 50f59d60577283b71da5424e30d0c5981fb74f71 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Hannes Reinecke <hare@suse.de>
|
|
|
|
Date: Fri, 18 Jul 2014 10:28:00 +0200
|
|
|
|
Subject: 40network: separate 'mask' and 'prefix'
|
|
|
|
|
|
|
|
The 'mask' parameter is used for both, the (IPv4) netmask and
|
|
|
|
the prefix length. As both are in different format separate them
|
|
|
|
out into 'mask' for the netmask and 'prefix' for the prefix length.
|
|
|
|
And also prefer the use of 'prefix' where possible to ease
|
|
|
|
calculation and better IPv6 support.
|
|
|
|
|
|
|
|
References: bnc#887542
|
|
|
|
|
|
|
|
Signed-off-by: Hannes Reinecke <hare@suse.de>
|
|
|
|
---
|
|
|
|
modules.d/40network/ifup.sh | 9 ++++----
|
|
|
|
modules.d/40network/net-lib.sh | 42 +++++++++++++++++++++++++++++++++---
|
|
|
|
modules.d/40network/parse-ip-opts.sh | 2 +-
|
|
|
|
3 files changed, 45 insertions(+), 8 deletions(-)
|
|
|
|
|
2015-03-31 16:12:12 +02:00
|
|
|
Index: dracut-041/modules.d/40network/ifup.sh
|
|
|
|
===================================================================
|
|
|
|
--- dracut-041.orig/modules.d/40network/ifup.sh 2015-03-18 11:57:28.788553583 +0100
|
|
|
|
+++ dracut-041/modules.d/40network/ifup.sh 2015-03-18 11:57:31.032679982 +0100
|
|
|
|
@@ -222,13 +222,14 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
linkup $netif
|
|
|
|
[ -n "$macaddr" ] && ip link set address $macaddr dev $netif
|
|
|
|
[ -n "$mtu" ] && ip link set mtu $mtu dev $netif
|
|
|
|
+ [ -n "$mask" -a -z "$prefix" ] && prefix=$(mask_to_prefix $mask)
|
|
|
|
if strglobin $ip '*:*:*'; then
|
|
|
|
# note no ip addr flush for ipv6
|
|
|
|
- ip addr add $ip/$mask ${srv:+peer $srv} dev $netif
|
|
|
|
+ ip addr add $ip/$prefix ${srv:+peer $srv} dev $netif
|
|
|
|
wait_for_ipv6_dad $netif
|
|
|
|
else
|
|
|
|
ip addr flush dev $netif
|
|
|
|
- ip addr add $ip/$mask ${srv:+peer $srv} brd + dev $netif
|
|
|
|
+ ip addr add $ip/$prefix ${srv:+peer $srv} brd + dev $netif
|
|
|
|
fi
|
|
|
|
|
2015-03-31 16:12:12 +02:00
|
|
|
[ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw
|
|
|
|
@@ -404,7 +405,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
# Pull in existing static configuration
|
|
|
|
. /etc/sysconfig/network/ifcfg-${netif}
|
|
|
|
ip=${IPADDR}
|
|
|
|
- mask=${PREFIXLEN}
|
|
|
|
+ prefix=${PREFIXLEN}
|
|
|
|
mtu=${MTU}
|
|
|
|
server=${REMOTE_IPADDR}
|
|
|
|
gw=${GATEWAY}
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -418,7 +419,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# Store config for later use
|
|
|
|
- for i in ip srv gw mask hostname macaddr dns1 dns2; do
|
|
|
|
+ for i in ip srv gw mask prefix hostname macaddr dns1 dns2; do
|
|
|
|
eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
|
|
|
|
done > /tmp/net.$netif.override
|
|
|
|
|
2015-03-31 16:12:12 +02:00
|
|
|
Index: dracut-041/modules.d/40network/net-lib.sh
|
|
|
|
===================================================================
|
|
|
|
--- dracut-041.orig/modules.d/40network/net-lib.sh 2015-03-18 11:57:28.792553808 +0100
|
|
|
|
+++ dracut-041/modules.d/40network/net-lib.sh 2015-03-18 11:57:31.036680206 +0100
|
|
|
|
@@ -7,6 +7,35 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
ip=${ip##* }
|
|
|
|
}
|
|
|
|
|
|
|
|
+mask_to_prefix() {
|
|
|
|
+ local mask="$1"
|
|
|
|
+ local prefix=0
|
|
|
|
+ local OLDIFS="$IFS"
|
|
|
|
+
|
|
|
|
+ IFS=:
|
|
|
|
+ set -- $mask
|
|
|
|
+ IFS="$OLDIFS"
|
|
|
|
+ for mask in $@ ; do
|
|
|
|
+ if [ "$mask" -eq 255 ] ; then
|
|
|
|
+ prefix=$(($prefix + 8))
|
|
|
|
+ elif [ "$mask" -eq 254 ] ; then
|
|
|
|
+ prefix=$(($prefix + 7))
|
|
|
|
+ elif [ "$mask" -eq 252 ] ; then
|
|
|
|
+ prefix=$(($prefix + 6))
|
|
|
|
+ elif [ "$mask" -eq 248 ] ; then
|
|
|
|
+ prefix=$(($prefix + 5))
|
|
|
|
+ elif [ "$mask" -eq 240 ] ; then
|
|
|
|
+ prefix=$(($prefix + 4))
|
|
|
|
+ elif [ "$mask" -eq 224 ] ; then
|
|
|
|
+ prefix=$(($prefix + 3))
|
|
|
|
+ elif [ "$mask" -eq 192 ] ; then
|
|
|
|
+ prefix=$(($prefix + 2))
|
|
|
|
+ elif [ "$mask" -eq 128 ] ; then
|
|
|
|
+ prefix=$(($prefix + 1))
|
|
|
|
+ fi
|
|
|
|
+ done
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
iface_for_remote_addr() {
|
|
|
|
set -- $(ip -o route get to $1)
|
|
|
|
echo $5
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -204,7 +233,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
for iface in /sys/firmware/ibft/ethernet*; do
|
|
|
|
local mac="" dev=""
|
|
|
|
local dhcp="" ip="" gw="" mask="" hostname=""
|
|
|
|
- local dns1 dns2
|
|
|
|
+ local dns1 dns2 prefix
|
|
|
|
|
|
|
|
[ -e ${iface}/mac ] || continue
|
|
|
|
mac=$(read a < ${iface}/mac; echo $a)
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -249,6 +278,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
[ -e ${iface}/hostname ] && hostname=$(read a < ${iface}/hostname; echo $a)
|
|
|
|
if [ "$family" = "ipv6" ] ; then
|
|
|
|
if [ -n "$ip" ] ; then
|
|
|
|
+ # Prefix defaults to 64 for IPv6
|
|
|
|
[ -n "$prefix" ] || prefix=64
|
|
|
|
ip="[${ip}/${prefix}]"
|
|
|
|
mask=
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -256,6 +286,11 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
if [ -n "$gw" ] ; then
|
|
|
|
gw="[${gw}]"
|
|
|
|
fi
|
|
|
|
+ else
|
|
|
|
+ if [ -n "$prefix" ] ; then
|
|
|
|
+ ip="$ip/$prefix"
|
|
|
|
+ mask=
|
|
|
|
+ fi
|
|
|
|
fi
|
|
|
|
if [ -n "$ip" ] && [ -n "$mask" -o -n "$prefix" ]; then
|
|
|
|
echo "ip=$ip::$gw:$mask:$hostname:$dev:none${dns1:+:$dns1}${dns2:+:$dns2}"
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -264,6 +299,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
warn "ip-addr=$ip"
|
|
|
|
warn "gateway=$gw"
|
|
|
|
warn "subnet-mask=$mask"
|
|
|
|
+ warn "prefix-len=$prefix"
|
|
|
|
warn "hostname=$hostname"
|
|
|
|
fi
|
|
|
|
else
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -411,7 +447,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
- unset ip srv gw mask hostname dev autoconf macaddr mtu dns1 dns2
|
|
|
|
+ unset ip srv gw mask prefix hostname dev autoconf macaddr mtu dns1 dns2
|
|
|
|
case $# in
|
|
|
|
0) autoconf="error" ;;
|
|
|
|
1) autoconf=$1 ;;
|
2015-03-31 16:12:12 +02:00
|
|
|
@@ -439,7 +475,7 @@
|
2014-07-21 14:41:52 +02:00
|
|
|
# Extract prefix length from CIDR notation
|
|
|
|
case $ip in
|
|
|
|
*/*)
|
|
|
|
- mask=${ip##*/}
|
|
|
|
+ prefix=${ip##*/}
|
|
|
|
ip=${ip%/*}
|
|
|
|
;;
|
|
|
|
esac
|
2015-03-31 16:12:12 +02:00
|
|
|
Index: dracut-041/modules.d/40network/parse-ip-opts.sh
|
|
|
|
===================================================================
|
|
|
|
--- dracut-041.orig/modules.d/40network/parse-ip-opts.sh 2015-03-18 11:57:31.044680739 +0100
|
|
|
|
+++ dracut-041/modules.d/40network/parse-ip-opts.sh 2015-03-18 11:58:13.727085881 +0100
|
|
|
|
@@ -77,7 +77,7 @@
|
|
|
|
none|off)
|
|
|
|
[ -z "$ip" ] && \
|
|
|
|
die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense"
|
|
|
|
- [ -z "$mask" ] && \
|
|
|
|
+ [ -z "$mask" -a -z "$prefix" ] && \
|
|
|
|
die "Sorry, automatic calculation of netmask is not yet supported"
|
|
|
|
;;
|
|
|
|
auto6);;
|