finir implémentation de network_config

This commit is contained in:
Jephte CLAIN 2014-02-09 22:44:22 +04:00
parent ac63d8456a
commit 71d1308188
1 changed files with 77 additions and 87 deletions

View File

@ -915,10 +915,11 @@ function network_config() {
# défini ou la première interface définie.
# $5 (reset_interfaces) spécifie de ne pas chercher à mettre à jour le
# fichier /etc/network/interfaces, mais de le recréer depuis zéro.
# $6 (oldhost) est le nom d'hôte actuel, avant la modification
# Si un des arguments n'est pas spécifié, il est ignoré.
# Le tableau confips doit contenir des définitions d'une des formes
# suivantes:
# [iface:]address[/suffix][+gateway],...
# [[iface][//gateway]:]address[/suffix],...
# [iface:]dhcp
# La deuxième forme est pour spécifier qu'une interface est configurée par
# DHCP. iface vaut par défaut eth0, sauf si une définition de bridge
@ -932,28 +933,22 @@ function network_config() {
# séparées par une virgule. e.g. br0:eth0,eth1
# Bien que ce soit techniquement possible, ce script interdit que l'on
# définisse une adresse IP pour une interface faisant partie d'un bridge.
urequire ipcalc conf
local -a __nc_confips __nc_confbrs
[ -n "$2" ] && array_copy __nc_confips "$2"
[ -n "$3" ] && array_copy __nc_confbrs "$3"
local host="$1" mainiface="$4" reset_interfaces="$5"
local -a confips confbrs
array_copy confips __nc_confips
array_copy confbrs __nc_confbrs
local host="$1"
local -a confips; array_copy confips __nc_confips
local -a confbrs; array_copy confbrs __nc_confbrs
local mainiface="$4" reset_interfaces="$5" oldhost="$6"
local modified
network_fix_confips confips
network_fix_confbrs confbrs
network_fix_confs confbrs confips "$mainiface"
local mainbr # bridge principal
local mainip # adresse IP principale de l'interface principale
local confbr confip br iface suffix gateway
local -a ipspecs
__old_network_resolve_mainiface mainiface "${confbrs[0]}" "${confips[0]}"
__old_network_parse_confbr "${confbrs[0]}" mainbr
[ -n "$mainbr" ] || mainbr=br0
local confbr br; local -a ifaces
local confip iface gateway mainip suffix; local -a ipsuffixes
network_parse_confip "${confips[0]}" iface gateway ipsuffixes
network_parse_ipsuffix "${ipsuffixes[0]}" mainip suffix
if [ -n "${confips[*]}" -o -n "${confbrs[*]}" ]; then
# Vérifier qu'une interface avec une adresse IP ne figure pas dans les
@ -965,11 +960,11 @@ function network_config() {
local -a brifaces
ifaces_with_ips=()
for confip in "${confips[@]}"; do
__old_network_parse_confip "$confip" iface
network_parse_confip "$confip" iface gateway ipsuffixes
array_addu ifaces_with_ips "$iface"
done
for confbr in "${confbrs[@]}"; do
__old_network_parse_confbr "$confbr" br ifaces
network_parse_confbr "$confbr" br ifaces
array_add brifaces "$br"
for iface in "${ifaces[@]}"; do
if array_contains ifaces_with_ips "$iface"; then
@ -978,25 +973,34 @@ function network_config() {
fi
done
done
local -a confstdips confbrips
for confip in "${confips[@]}"; do
__old_network_parse_confip "$confip" iface
[ -n "$iface" ] || iface="$mainiface"
if array_contains brifaces "$iface"; then
array_add confbrips "$confip"
else
array_add confstdips "$confip"
# vérifier si une modification est nécessaire
local modify
for confbr in "${confbrs[@]}"; do
network_parse_confbr "$confbr" br ifaces
if ! network_interfaces_check_confbr "$br" iface; then
modify=1
break
fi
done
if [ -z "$modify" ]; then
for confip in "${confips[@]}"; do
network_parse_confip "$confip" iface gateway ipsuffixes
if ! network_interfaces_check_confip "$iface" "$gateway" ipsuffixes; then
modify=1
break
fi
done
fi
# maintenant, configurer /etc/network/interfaces: faire une copie de travail
local interfaces workfile
ac_set_tmpfile interfaces
ac_set_tmpfile workfile
cat /etc/network/interfaces >"$interfaces"
# yes! il faut refaire la configuration
if [ -n "$modify" ]; then
# faire une copie de travail
local interfaces; ac_set_tmpfile interfaces
cat /etc/network/interfaces >"$interfaces"
if [ -n "$reset_interfaces" ]; then
echo >"$interfaces" "\
if [ -n "$reset_interfaces" ]; then
echo >"$interfaces" "\
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
@ -1004,66 +1008,51 @@ function network_config() {
auto lo
iface lo inet loopback
"
fi
# configurer chaque bridge
local -a tmpifaces
local tmpbr
for confip in "${confbrips[@]}"; do
__old_network_parse_confip "$confip" br ipspecs
[ -n "$br" ] || br="$mainbr"
if [ -z "$mainip" -a "$br" == "$mainiface" ]; then
__old_network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
fi
ifaces=()
# d'abord supprimer l'ancienne configuration
for confbr in "${confbrs[@]}"; do
__old_network_parse_confbr "$confbr" tmpbr tmpifaces
if [ "$tmpbr" == "$br" ]; then
array_copy ifaces tmpifaces
break
network_parse_confbr "$confbr" br ifaces
network_interfaces_remove_confbr "$br" ifaces "$interfaces"
done
for confip in "${confips[@]}"; do
network_parse_confip "$confip" iface gateway ipsuffixes
network_interfaces_remove_confip "$iface"
done
# puis recréer la configuration
for confbr in "${confbrs[@]}"; do
network_parse_confbr "$confbr" br ifaces
network_interfaces_add_confbr "$br" ifaces confips "$interfaces"
done
for confip in "${confips[@]}"; do
network_parse_confip "$confip" iface gateway ipsuffixes
if ! array_contains brifaces "$iface"; then
network_interfaces_add_confip "$iface" "$gateway" ipsuffixes "$interfaces"
fi
done
if __old_network_update_bridge "$interfaces" "$workfile" "$br" ipspecs ifaces; then
cat "$workfile" >"$interfaces"
# Fin de traitement
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
if testdiff "$interfaces" /etc/network/interfaces; then
uecho "Setting /etc/network/interfaces to:"
cat "$interfaces" | sed 's/^/ /g' 1>&2
else
uecho "/etc/network/interfaces: pas de modifications"
fi
elif testdiff "$interfaces" /etc/network/interfaces; then
__network_backup /etc/network/interfaces
if show_debug; then
edebug "Setting /etc/network/interfaces to:"
cat "$interfaces" | sed 's/^/ /g' 1>&2
else
estep /etc/network/interfaces
fi
cat "$interfaces" >/etc/network/interfaces
modified=1
fi
done
# configurer chaque interface classique
for confip in "${confstdips[@]}"; do
__old_network_parse_confip "$confip" iface ipspecs
[ -n "$iface" ] || iface="$mainiface"
if [ -z "$mainip" -a "$iface" == "$mainiface" ]; then
__old_network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
fi
if __old_network_update_iface "$interfaces" "$workfile" "$iface" ipspecs; then
cat "$workfile" >"$interfaces"
fi
done
# Fin de traitement
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
if testdiff "$interfaces" /etc/network/interfaces; then
uecho "Setting /etc/network/interfaces to:"
cat "$interfaces" | sed 's/^/ /g' 1>&2
else
uecho "/etc/network/interfaces: pas de modifications"
fi
elif testdiff "$interfaces" /etc/network/interfaces; then
__network_backup /etc/network/interfaces
if show_debug; then
edebug "Setting /etc/network/interfaces to:"
cat "$interfaces" | sed 's/^/ /g' 1>&2
else
estep /etc/network/interfaces
fi
cat "$interfaces" >/etc/network/interfaces
ac_clean "$interfaces"
fi
ac_clean "$interfaces" "$workfile"
eend
fi
@ -1097,5 +1086,6 @@ iface lo inet loopback
eend
fi
[ -z "$modified" ] && return 10
return 0
}