Merge pull request #73 from OpenNebula/ipv6

Improved IPv6 support
pull/74/head
Vlastimil Holer 8 years ago committed by GitHub
commit f84361abc8

@ -155,8 +155,8 @@ EOT
gen_iface6_conf() { gen_iface6_conf() {
cat <<EOT cat <<EOT
iface $DEV inet6 static iface $DEV inet6 static
address $IPV6 address $IP6
netmask 64 netmask ${IP6_PREFIX_LENGTH:-64}
autoconf 0 autoconf 0
accept_ra 0 accept_ra 0
EOT EOT
@ -169,6 +169,22 @@ EOT
echo " gateway $GATEWAY6" echo " gateway $GATEWAY6"
fi fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT
iface $DEV inet6 static
address $IP6_ULA
netmask 64
autoconf 0
accept_ra 0
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
fi
echo "" echo ""
} }
@ -214,17 +230,19 @@ EOT
MTU=$(get_mtu) MTU=$(get_mtu)
GATEWAY=$(get_gateway) GATEWAY=$(get_gateway)
IPV6=$(get_iface_var "IPV6") IP6=$(get_iface_var "IP6")
[[ -z $IPV6 ]] && IPV6=$(get_iface_var "IP6") [[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6) GATEWAY6=$(get_gateway6)
[ -z "${IP}${IPV6}" ] && continue [ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue [ -z "${DEV}" ] && continue
echo "auto $DEV" echo "auto $DEV"
[[ -n $IP ]] && gen_iface_conf [[ -n $IP ]] && gen_iface_conf
[[ -n $IPV6 ]] && gen_iface6_conf [[ -n $IP6 ]] && gen_iface6_conf
done done
} }

@ -103,33 +103,34 @@ gen_iface_conf() {
NETMASK=$MASK NETMASK=$MASK
IPADDR=$IP IPADDR=$IP
EOT EOT
if [ -n "$MTU" ]; then
echo "MTU=$MTU"
fi
if [ -n "$GATEWAY" ]; then if [ -n "$GATEWAY" ]; then
echo "GATEWAY=$GATEWAY" echo "GATEWAY=$GATEWAY"
fi fi
echo "" if [ -n "$MTU" ]; then
echo "MTU=$MTU"
fi
} }
gen_iface6_conf() { gen_iface6_conf() {
cat <<EOT cat <<EOT
IPV6INIT=yes IPV6INIT=yes
IPV6ADDR=$IPV6 IPV6ADDR=$IP6/${IP6_PREFIX_LENGTH:-64}
IPV6_AUTOCONF=no IPV6_AUTOCONF=no
EOT EOT
if [ -n "$MTU" ]; then if [ -n "$IP6_ULA" ]; then
echo "MTU=$MTU" echo "IPV6ADDR_SECONDARIES=$IP6_ULA/64"
fi fi
if [ -n "$GATEWAY6" ]; then if [ -n "$GATEWAY6" ]; then
echo "IPV6_DEFAULTGW=$GATEWAY6" echo "IPV6_DEFAULTGW=$GATEWAY6"
fi fi
echo "" if [ -n "$MTU" ]; then
echo "IPV6_MTU=$MTU"
fi
} }
get_interface_mac() get_interface_mac()
@ -168,11 +169,13 @@ gen_network_configuration()
MTU=$(get_mtu) MTU=$(get_mtu)
GATEWAY=$(get_gateway) GATEWAY=$(get_gateway)
IPV6=$(get_iface_var "IPV6") IP6=$(get_iface_var "IP6")
[[ -z $IPV6 ]] && IPV6=$(get_iface_var "IP6") [[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6) GATEWAY6=$(get_gateway6)
[ -z "${IP}${IPV6}" ] && continue [ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue [ -z "${DEV}" ] && continue
( (
@ -184,7 +187,7 @@ NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
EOT EOT
[[ -n $IP ]] && gen_iface_conf [[ -n $IP ]] && gen_iface_conf
[[ -n $IPV6 ]] && gen_iface6_conf [[ -n $IP6 ]] && gen_iface6_conf
) > /etc/sysconfig/network-scripts/ifcfg-${DEV} ) > /etc/sysconfig/network-scripts/ifcfg-${DEV}

@ -38,7 +38,6 @@ get_dev_from_pci()
return return
fi fi
if [ `echo "$DEV" | wc -l` -gt 1 ]; then if [ `echo "$DEV" | wc -l` -gt 1 ]; then
echo "More than one PCI Device $1 found" >&2 echo "More than one PCI Device $1 found" >&2
return return
@ -52,26 +51,62 @@ PCI_INTERFACES=$(get_pci_interfaces)
for pci in $PCI_INTERFACES; do for pci in $PCI_INTERFACES; do
UPCASE_DEV=$pci UPCASE_DEV=$pci
MAC=$(get_iface_var "MAC")
IP=$(get_iface_var "IP") IP=$(get_iface_var "IP")
IPV6=$(get_iface_var "IP6") MAC=$(get_iface_var "MAC")
MASK=$(get_iface_var "MASK")
MASK=${MASK:-255.255.255.0}
GATEWAY=$(get_iface_var "GATEWAY")
MTU=$(get_iface_var "MTU")
MTU=${MTU:-1500}
VLAN_ID=$(get_iface_var "VLAN_ID") VLAN_ID=$(get_iface_var "VLAN_ID")
IP6=$(get_iface_var "IP6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_PREFIX_LENGTH=${IP6_PREFIX_LENGTH:-64}
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_iface_var "GATEWAY6")
ADDRESS=$(get_iface_var "ADDRESS") ADDRESS=$(get_iface_var "ADDRESS")
[ -z "$ADDRESS" ] && continue [ -z "$ADDRESS" ] && continue
DEV=$(get_dev_from_pci "$ADDRESS") DEV=$(get_dev_from_pci "$ADDRESS")
[ -z "$DEV" ] && continue [ -z "$DEV" ] && continue
# MAC
ip link set dev $DEV address $MAC ip link set dev $DEV address $MAC
ip link set dev $DEV up ip link set dev $DEV up
# MTU
if [ -n "$MTU" ]; then
ip link set dev $DEV mtu $MTU
fi
# VLAN (802.1Q)
if [ -n "$VLAN_ID" ]; then if [ -n "$VLAN_ID" ]; then
ip link add link $DEV name $DEV.$VLAN_ID type vlan id $VLAN_ID ip link add link $DEV name $DEV.$VLAN_ID type vlan id $VLAN_ID
ip link set dev $DEV.$VLAN_ID up ip link set dev $DEV.$VLAN_ID up
DEV=$DEV.$VLAN_ID DEV=$DEV.$VLAN_ID
fi fi
[ -n "$IP" ] && ip address add $IP/24 dev $DEV # IPv4
[ -n "$IPV6" ] && ip address add $IPV6 dev $DEV if [ -n "$IP" ]; then
ip address add $IP/$MASK dev $DEV
if [ -n "$GATEWAY" ]; then
ip route add default via $GATEWAY dev $DEV
fi
fi
# IPv6
if [ -n "$IP6" ]; then
ip -6 address add $IP6/$IP6_PREFIX_LENGTH dev $DEV
if [ -n "$IP6_ULA" ]; then
ip -6 address add $IP6_ULA/64 dev $DEV
fi
if [ -n "$GATEWAY6" ]; then
ip -6 route add default via $GATEWAY6 dev $DEV
fi
fi
done done

Loading…
Cancel
Save