suite de la nouvelle implémentation
This commit is contained in:
parent
136b8e225e
commit
071032b20a
453
ulib/debian
453
ulib/debian
|
@ -114,49 +114,164 @@ END {
|
||||||
|
|
||||||
__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS=
|
__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS=
|
||||||
|
|
||||||
|
function __network_parse_confbr() {
|
||||||
|
local br; local -a ifaces
|
||||||
|
splitpair "$1" br ifaces
|
||||||
|
array_split ifaces "$ifaces" ,
|
||||||
|
|
||||||
|
__npc_br="$br"
|
||||||
|
array_copy __npc_ifaces ifaces
|
||||||
|
}
|
||||||
function network_parse_confbr() {
|
function network_parse_confbr() {
|
||||||
:
|
# network_parse_confbr "$confbr" br ifaces
|
||||||
|
local __npc_br; local -a __npc_ifaces
|
||||||
|
__network_parse_confbr "$1"
|
||||||
|
|
||||||
|
set_var "${2:-br}" "$__npc_br"
|
||||||
|
array_copy "${3:-ifaces}" __npc_ifaces
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_format_confbr() {
|
function network_format_confbr() {
|
||||||
:
|
# network_format_confbr "$br" ifaces --> "br:ifaces"
|
||||||
|
echo "$1:$(array_join "${2:-ifaces}" ,)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __network_parse_confip() {
|
||||||
|
local tmpig iface gateway; local -a ipsuffixes
|
||||||
|
splitfsep2 "$1" : tmpig ipsuffixes
|
||||||
|
splitfsep "$tmpig" // iface gateway
|
||||||
|
array_split ipsuffixes "$ipsuffixes" ,
|
||||||
|
|
||||||
|
__npc_iface="$iface"
|
||||||
|
__npc_gateway="$gateway"
|
||||||
|
array_copy __npc_ipsuffixes ipsuffixes
|
||||||
|
}
|
||||||
function network_parse_confip() {
|
function network_parse_confip() {
|
||||||
:
|
# network_parse_confip "$confip" iface gateway ipsuffixes
|
||||||
|
local __npc_iface __npc_gateway; local -a __npc_ipsuffixes
|
||||||
|
__network_parse_confip "$1"
|
||||||
|
|
||||||
|
set_var "${2:-iface}" "$__npc_iface"
|
||||||
|
set_var "${3:-gateway}" "$__npc_gateway"
|
||||||
|
array_copy "${4:-ipsuffixes}" __npc_ipsuffixes
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_parse_ipsuffix() {
|
function network_parse_ipsuffix() {
|
||||||
:
|
# network_parse_ipsuffix "$ipsuffix" ip suffix
|
||||||
|
splitfsep "$1" / "${2:-ip}" "${3:-suffix}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_format_confip() {
|
function network_format_confip() {
|
||||||
:
|
# network_format_confip "$iface" "$gateway" ipsuffixes --> "iface//gateway:ipsuffixes"
|
||||||
|
local tmpig="$1${2:+//$2}"
|
||||||
|
echo "${tmpig:+$tmpig:}$(array_join "${3:-ipsuffixes}" ,)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_format_ipsuffix() {
|
function network_format_ipsuffix() {
|
||||||
:
|
# network_format_ipsuffix "$ip" "$suffix" --> "ip:suffix"
|
||||||
|
if [ "${1,,}" == "dhcp" ]; then
|
||||||
|
echo "${1,,}"
|
||||||
|
else
|
||||||
|
echo "$1${2:+/$2}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_set_confbrs() {
|
function __network_fix_confbrs() {
|
||||||
:
|
local -a confbrs ifaces brs ips
|
||||||
}
|
local confbr br iface
|
||||||
|
# recenser les bridges et créer les tableaux __BR_ifaces
|
||||||
|
for confbr in "${__nfc_confbrs[@]}"; do
|
||||||
|
network_parse_confbr "$confbr" br ifaces
|
||||||
|
array_addu brs "$br"
|
||||||
|
eval "local -a ${br}_ifaces"
|
||||||
|
done
|
||||||
|
# puis constuire la liste des interfaces associées à chaque bridge
|
||||||
|
for confbr in "${__nfc_confbrs[@]}"; do
|
||||||
|
network_parse_confbr "$confbr" br ifaces
|
||||||
|
array_extendu "${br}_ifaces" ifaces
|
||||||
|
done
|
||||||
|
# puis construire le tableau final
|
||||||
|
array_new confbrs
|
||||||
|
for br in "${brs[@]}"; do
|
||||||
|
array_add confbrs "$(network_format_confbr "$br" "${br}_ifaces")"
|
||||||
|
done
|
||||||
|
|
||||||
function network_set_confips() {
|
array_copy __nfc_confbrs confbrs
|
||||||
:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_fix_confbrs() {
|
function network_fix_confbrs() {
|
||||||
:
|
# normaliser le tableau $1(=confbrs): fusionner les doublons
|
||||||
|
local -a __nfc_confbrs
|
||||||
|
array_copy __nfc_confbrs "${1:-confbrs}"
|
||||||
|
__network_fix_confbrs
|
||||||
|
|
||||||
|
array_copy "${1:-confbrs}" __nfc_confbrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __network_fix_confips() {
|
||||||
|
local -a confips ipsuffixes ifaces ips
|
||||||
|
local confip iface gateway ip suffix mainip
|
||||||
|
|
||||||
|
# recenser les interfaces et créer les tableaux __IFACE_ipspecs
|
||||||
|
for confip in "${__nfc_confips[@]}"; do
|
||||||
|
network_parse_confip "$confip" iface gateway ipsuffixes
|
||||||
|
[ -n "$iface" ] || iface="$mainiface"
|
||||||
|
array_addu ifaces "$iface"
|
||||||
|
eval "local ${iface}_gateway; local -a ${iface}_ipsuffixes"
|
||||||
|
done
|
||||||
|
# puis construire la liste des adresses IP associées à chaque interface
|
||||||
|
for confip in "${__nfc_confips[@]}"; do
|
||||||
|
network_parse_confip "$confip" iface gateway ipsuffixes
|
||||||
|
[ -n "$iface" ] || iface="$mainiface"
|
||||||
|
# si la passerelle a déjà été spécifiée, la récupérer
|
||||||
|
local tmpgw="${iface}_gateway"
|
||||||
|
[ -n "${!tmpgw}" ] && gateway="${!tmpgw}"
|
||||||
|
# calculer l'adresse ip principale, pour pouvoir traiter le cas où
|
||||||
|
# l'adresse ip principale est l'adresse de la passerelle.
|
||||||
|
mainip=
|
||||||
|
for ipsuffix in "${ipsuffixes[@]}"; do
|
||||||
|
network_parse_ipsuffix "$ipsuffix" ip suffix
|
||||||
|
if ! array_contains ips "$ip"; then
|
||||||
|
[ -n "$suffix" ] || suffix=24
|
||||||
|
if [ -z "$mainip" ]; then
|
||||||
|
[ -n "$gateway" ] || gateway="$(ipcalc_gateway "$ip" "$suffix")"
|
||||||
|
mainip="$ip"
|
||||||
|
fi
|
||||||
|
array_add "${iface}_ipsuffixes" "$(network_format_ipsuffix "$ip" "$suffix")"
|
||||||
|
array_add ips "$ip"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[ "$gateway" == "$mainip" ] && gateway=
|
||||||
|
# si l'adresse ip principale est obtenue par dhcp, il ne faut pas
|
||||||
|
# spécifier la passerelle: elle sera fournie par le serveur DHCP.
|
||||||
|
# Utiliser le marqueur "none" pour que la valeur ne soit pas modifiée.
|
||||||
|
[ "${ipsuffixes[0]}" == "dhcp" ] && gateway=none
|
||||||
|
set_var "${iface}_gateway" "$gateway"
|
||||||
|
done
|
||||||
|
# puis construire le tableau final
|
||||||
|
array_new confips
|
||||||
|
for iface in "${ifaces[@]}"; do
|
||||||
|
gateway="${iface}_gateway"; gateway="${!gateway}"
|
||||||
|
[ "$gateway" == "none" ] && gateway=
|
||||||
|
array_add confips "$(network_format_confip "$iface" "$gateway" "${iface}_ipsuffixes")"
|
||||||
|
done
|
||||||
|
|
||||||
|
array_copy __nfc_confips confips
|
||||||
|
}
|
||||||
function network_fix_confips() {
|
function network_fix_confips() {
|
||||||
# $2==mainiface, l'interface associée aux adresses ip non qualifiées
|
# normaliser le tableau $1(=confips): fusionner les doublons, spécifier le
|
||||||
:
|
# suffixe /24 par défaut, etc. $2 est le cas échéant l'interface associée
|
||||||
|
# aux adresses ip non qualifiées
|
||||||
|
local -a __nfc_confips
|
||||||
|
array_copy __nfc_confips "${1:-confips}"
|
||||||
|
local mainiface="$2"
|
||||||
|
__network_fix_confips
|
||||||
|
|
||||||
|
array_copy "${1:-confips}" __nfc_confips
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_fix_mainiface() {
|
function network_fix_mainiface() {
|
||||||
# confips[0] est la configuration ip de l'interface principale
|
# réorganiser les tableaux de façon que confips[0] devienne la configuration
|
||||||
|
# ip de l'interface principale
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +281,84 @@ function network_fix_confs() {
|
||||||
network_fix_mainiface "${1:-confbrs}" "${2:-confips}" "$3"
|
network_fix_mainiface "${1:-confbrs}" "${2:-confips}" "$3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __network_valid_ifaces() {
|
||||||
|
ip link | awk '/<.*>/ {
|
||||||
|
flags = $0; sub(/^.*</, ",", flags); sub(/>.*$/, ",", flags)
|
||||||
|
if (flags ~ /,LOOPBACK,/) next
|
||||||
|
if (flags !~ /,UP,/) next
|
||||||
|
sub(/:$/, "", $2); print $2
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
|
function __network_set_confbrs() {
|
||||||
|
local -a ifaces tmpconfbrs confbrs
|
||||||
|
local confbr br iface
|
||||||
|
array_from_lines ifaces "$(__network_valid_ifaces)"
|
||||||
|
array_from_lines tmpconfbrs "$(brctl show 2>/dev/null | awk '
|
||||||
|
BEGIN { confbrs = "" }
|
||||||
|
NR == 1 { next }
|
||||||
|
{
|
||||||
|
if ($1 != "" && $2 != "") {
|
||||||
|
if (confbr != "") print confbr
|
||||||
|
confbr = $1 ":" $4
|
||||||
|
} else {
|
||||||
|
confbr = confbr "," $1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
if (confbr != "") print confbr
|
||||||
|
}
|
||||||
|
')"
|
||||||
|
for confbr in "${tmpconfbrs[@]}"; do
|
||||||
|
splitpair "$confbr" br iface
|
||||||
|
array_contains ifaces "$br" || continue
|
||||||
|
array_add confbrs "$confbr"
|
||||||
|
done
|
||||||
|
|
||||||
|
array_copy __nsc_confbrs confbrs
|
||||||
|
}
|
||||||
|
function network_set_confbrs() {
|
||||||
|
# initialiser $1(=confbrs) avec l'état des bridges sur le système courant
|
||||||
|
local -a __nsc_confbrs
|
||||||
|
__network_set_confbrs
|
||||||
|
|
||||||
|
array_copy "${1:-confbrs}" __nsc_confbrs
|
||||||
|
}
|
||||||
|
|
||||||
|
function __network_set_gateway() {
|
||||||
|
# initialiser la variable gateway avec la passerelle associée à l'interface
|
||||||
|
# $1
|
||||||
|
gateway="$(route -n | awk -v iface="$1" '$1 == "0.0.0.0" && $8 == iface { print $2 }')"
|
||||||
|
}
|
||||||
|
function __network_set_confip() {
|
||||||
|
# initialiser la variable confip avec l'état de l'interface $1.
|
||||||
|
# retourner 1 si l'interface n'a pas d'adresse ip associée
|
||||||
|
local -a ipsuffixes
|
||||||
|
array_from_lines ipsuffixes "$(ip addr show dev "$1" | awk '$1 == "inet" { print $2 }')"
|
||||||
|
__network_set_gateway "$1"
|
||||||
|
confip="$(network_format_confip "$iface" "$gateway" ipsuffixes)"
|
||||||
|
[ "${#ipsuffixes[*]}" -gt 0 ]
|
||||||
|
}
|
||||||
|
function __network_set_confips() {
|
||||||
|
local -a confips ifaces
|
||||||
|
local iface
|
||||||
|
array_from_lines ifaces "$(__network_valid_ifaces)"
|
||||||
|
for iface in "${ifaces[@]}"; do
|
||||||
|
__network_set_confip "$iface" || continue
|
||||||
|
array_add confips "$confip"
|
||||||
|
done
|
||||||
|
|
||||||
|
array_copy __nsc_confips confips
|
||||||
|
}
|
||||||
|
function network_set_confips() {
|
||||||
|
# initialiser le tableau $1(=confips) avec l'état des interfaces sur le
|
||||||
|
# système courant
|
||||||
|
local -a __nsc_confips
|
||||||
|
__network_set_confips
|
||||||
|
|
||||||
|
array_copy "${1:-confips}" __nsc_confips
|
||||||
|
}
|
||||||
|
|
||||||
function network_interfaces_check_confbr() {
|
function network_interfaces_check_confbr() {
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
@ -187,19 +380,19 @@ function network_interfaces_add_confip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#XXX
|
#XXX
|
||||||
function network_backup() {
|
function __old_network_backup() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local backup="$file.orig$(date +%Y%m%d)"
|
local backup="$file.orig$(date +%Y%m%d)"
|
||||||
[ -f "$backup" ] || cat "$file" >"$backup" 2>/dev/null
|
[ -f "$backup" ] || cat "$file" >"$backup" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_hostname() {
|
function __old_network_hostname() {
|
||||||
local hostname="${1%%.*}"
|
local hostname="${1%%.*}"
|
||||||
[ -f /etc/hostname ] || touch /etc/hostname
|
[ -f /etc/hostname ] || touch /etc/hostname
|
||||||
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
|
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
|
||||||
uecho "Setting /etc/hostname to $hostname"
|
uecho "Setting /etc/hostname to $hostname"
|
||||||
elif [ "$(</etc/hostname)" != "$hostname" ]; then
|
elif [ "$(</etc/hostname)" != "$hostname" ]; then
|
||||||
network_backup /etc/hostname
|
__old_network_backup /etc/hostname
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/hostname to $hostname"
|
edebug "Setting /etc/hostname to $hostname"
|
||||||
else
|
else
|
||||||
|
@ -209,13 +402,13 @@ function network_hostname() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_mailname() {
|
function __old_network_mailname() {
|
||||||
local host="$1"
|
local host="$1"
|
||||||
[ -f /etc/mailname ] || touch /etc/mailname
|
[ -f /etc/mailname ] || touch /etc/mailname
|
||||||
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
|
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
|
||||||
uecho "Setting /etc/mailname to $host"
|
uecho "Setting /etc/mailname to $host"
|
||||||
elif [ "$(</etc/mailname)" != "$host" ]; then
|
elif [ "$(</etc/mailname)" != "$host" ]; then
|
||||||
network_backup /etc/mailname
|
__old_network_backup /etc/mailname
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/mailname to $host"
|
edebug "Setting /etc/mailname to $host"
|
||||||
else
|
else
|
||||||
|
@ -225,7 +418,7 @@ function network_mailname() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_fix_exim4() {
|
function __old_network_fix_exim4() {
|
||||||
local host="$1" oldhost="$2"
|
local host="$1" oldhost="$2"
|
||||||
local tmpfile; ac_set_tmpfile tmpfile
|
local tmpfile; ac_set_tmpfile tmpfile
|
||||||
|
|
||||||
|
@ -240,7 +433,7 @@ dc_other_hostnames='$host'"
|
||||||
uecho "/etc/exim4/update-exim4.conf.conf: pas de modifications"
|
uecho "/etc/exim4/update-exim4.conf.conf: pas de modifications"
|
||||||
fi
|
fi
|
||||||
elif testdiff "$tmpfile" /etc/exim4/update-exim4.conf.conf; then
|
elif testdiff "$tmpfile" /etc/exim4/update-exim4.conf.conf; then
|
||||||
network_backup /etc/exim4/update-exim4.conf.conf
|
__old_network_backup /etc/exim4/update-exim4.conf.conf
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/exim4/update-exim4.conf.conf to:"
|
edebug "Setting /etc/exim4/update-exim4.conf.conf to:"
|
||||||
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
||||||
|
@ -253,7 +446,7 @@ dc_other_hostnames='$host'"
|
||||||
ac_clean "$tmpfile"
|
ac_clean "$tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_fix_postfix() {
|
function __old_network_fix_postfix() {
|
||||||
local host="$1" oldhost="$2"
|
local host="$1" oldhost="$2"
|
||||||
local tmpfile; ac_set_tmpfile tmpfile
|
local tmpfile; ac_set_tmpfile tmpfile
|
||||||
|
|
||||||
|
@ -274,7 +467,7 @@ function network_fix_postfix() {
|
||||||
uecho "/etc/postfix/main.cf: pas de modifications"
|
uecho "/etc/postfix/main.cf: pas de modifications"
|
||||||
fi
|
fi
|
||||||
elif testdiff "$tmpfile" /etc/postfix/main.cf; then
|
elif testdiff "$tmpfile" /etc/postfix/main.cf; then
|
||||||
network_backup /etc/postfix/main.cf
|
__old_network_backup /etc/postfix/main.cf
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/postfix/main.cf to:"
|
edebug "Setting /etc/postfix/main.cf to:"
|
||||||
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
||||||
|
@ -286,7 +479,7 @@ function network_fix_postfix() {
|
||||||
ac_clean "$tmpfile"
|
ac_clean "$tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_hosts() {
|
function __old_network_hosts() {
|
||||||
local host="$1" hostname="${1%%.*}" ip="$2"
|
local host="$1" hostname="${1%%.*}" ip="$2"
|
||||||
local shost="${host//./\\.}"
|
local shost="${host//./\\.}"
|
||||||
local tmpfile; ac_set_tmpfile tmpfile
|
local tmpfile; ac_set_tmpfile tmpfile
|
||||||
|
@ -313,7 +506,7 @@ $ip$TAB$host $hostname" "$tmpfile"
|
||||||
uecho "/etc/hosts: pas de modifications"
|
uecho "/etc/hosts: pas de modifications"
|
||||||
fi
|
fi
|
||||||
elif testdiff "$tmpfile" /etc/hosts; then
|
elif testdiff "$tmpfile" /etc/hosts; then
|
||||||
network_backup /etc/hosts
|
__old_network_backup /etc/hosts
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/hosts to:"
|
edebug "Setting /etc/hosts to:"
|
||||||
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
cat "$tmpfile" | sed 's/^/ /g' 1>&2
|
||||||
|
@ -325,173 +518,13 @@ $ip$TAB$host $hostname" "$tmpfile"
|
||||||
ac_clean "$tmpfile"
|
ac_clean "$tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_parse_confip() {
|
function __old_network_resolve_mainiface() {
|
||||||
# confip --> iface [ipspecs@] [ipspecs]
|
|
||||||
local __npc_tmp
|
|
||||||
splitfsep2 "$1" : "${2:-iface}" __npc_tmp
|
|
||||||
[ -n "$3" ] && array_split "$3" "$__npc_tmp" ,
|
|
||||||
[ -n "$4" ] && set_var "$4" "$__npc_tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_parse_ipspec() {
|
|
||||||
# ipspec --> ip suffix gateway
|
|
||||||
local __npi_tmp
|
|
||||||
splitfsep "$1" / "${2:-ip}" __npi_tmp
|
|
||||||
splitfsep "$__npi_tmp" + "${3:-suffix}" "${4:-gateway}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_parse_confbr() {
|
|
||||||
# confbr --> br [ifaces@] [ifaces]
|
|
||||||
local __npc_tmp
|
|
||||||
splitfsep "$1" : "${2:-br}" __npc_tmp
|
|
||||||
[ -n "$3" ] && array_split "$3" "$__npc_tmp" ,
|
|
||||||
[ -n "$4" ] && set_var "$4" "$__npc_tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_fix_confips() {
|
|
||||||
# confips@
|
|
||||||
local -a __nfc_confips __nfc_ipspecs __nfc_ifaces __nfc_ips
|
|
||||||
local __nfc_confip __nfc_iface __nfc_ipspec __nfc_ip __nfc_suffix __nfc_gateway __nfc_first
|
|
||||||
|
|
||||||
array_copy __nfc_confips "${1:-confips}"
|
|
||||||
# recenser les interfaces et créer les tableaux __IFACE_ipspecs
|
|
||||||
for __nfc_confip in "${__nfc_confips[@]}"; do
|
|
||||||
network_parse_confip "$__nfc_confip" __nfc_iface __nfc_ipspecs
|
|
||||||
array_addu __nfc_ifaces "$__nfc_iface"
|
|
||||||
eval "local -a __nfc_${__nfc_iface}_ipspecs"
|
|
||||||
done
|
|
||||||
# puis constuire la liste des adresses IP associées à chaque interface
|
|
||||||
for __nfc_confip in "${__nfc_confips[@]}"; do
|
|
||||||
network_parse_confip "$__nfc_confip" __nfc_iface __nfc_ipspecs
|
|
||||||
for __nfc_ipspec in "${__nfc_ipspecs[@]}"; do
|
|
||||||
network_parse_ipspec "$__nfc_ipspec" __nfc_ip __nfc_suffix __nfc_gateway
|
|
||||||
if ! array_contains __nfc_ips "$__nfc_ip"; then
|
|
||||||
[ -n "$__nfc_suffix" ] || __nfc_suffix=24
|
|
||||||
if [ -z "$__nfc_gateway" ] && array_isempty "__nfc_${__nfc_iface}_ipspecs"; then
|
|
||||||
# premier ipspec, il faut spécifier le gateway
|
|
||||||
__nfc_gateway="$(ipcalc_gateway "$__nfc_ip" "$__nfc_suffix")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
eval "array_add __nfc_${__nfc_iface}_ipspecs \"$__nfc_ip/$__nfc_suffix${__nfc_gateway:++$__nfc_gateway}\""
|
|
||||||
array_add __nfc_ips "$__nfc_ip"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
# puis construire le tableau final
|
|
||||||
array_new __nfc_confips
|
|
||||||
for __nfc_iface in "${__nfc_ifaces[@]}"; do
|
|
||||||
array_add __nfc_confips "$__nfc_iface:$(array_join "__nfc_${__nfc_iface}_ipspecs" ,)"
|
|
||||||
done
|
|
||||||
|
|
||||||
array_copy "${1:-confips}" __nfc_confips
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_fix_confbrs() {
|
|
||||||
# confbrs@
|
|
||||||
local -a __nfc_confbrs __nfc_ifaces __nfc_brs __nfc_ips
|
|
||||||
local __nfc_confbr __nfc_br __nfc_iface __nfc_ip __nfc_suffix __nfc_gateway
|
|
||||||
|
|
||||||
array_copy __nfc_confbrs "${1:-confbrs}"
|
|
||||||
# recenser les bridges et créer les tableaux __BR_ifaces
|
|
||||||
for __nfc_confbr in "${__nfc_confbrs[@]}"; do
|
|
||||||
network_parse_confbr "$__nfc_confbr" __nfc_br __nfc_ifaces
|
|
||||||
array_addu __nfc_brs "$__nfc_br"
|
|
||||||
eval "local -a __nfc_${__nfc_br}_ifaces"
|
|
||||||
done
|
|
||||||
# puis constuire la liste des interfaces associées à chaque bridge
|
|
||||||
for __nfc_confbr in "${__nfc_confbrs[@]}"; do
|
|
||||||
network_parse_confbr "$__nfc_confbr" __nfc_br __nfc_ifaces
|
|
||||||
array_extendu "__nfc_${__nfc_br}_ifaces" __nfc_ifaces
|
|
||||||
done
|
|
||||||
# puis construire le tableau final
|
|
||||||
array_new __nfc_confbrs
|
|
||||||
for __nfc_br in "${__nfc_brs[@]}"; do
|
|
||||||
array_add __nfc_confbrs "$__nfc_br:$(array_join "__nfc_${__nfc_br}_ifaces" ,)"
|
|
||||||
done
|
|
||||||
|
|
||||||
array_copy "${1:-confbrs}" __nfc_confbrs
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_resolve_mainiface() {
|
|
||||||
local __nrm_mainiface="${1:-mainiface}" __nrm_mainconfbr="$2" __nrm_mainconfip="$3"
|
local __nrm_mainiface="${1:-mainiface}" __nrm_mainconfbr="$2" __nrm_mainconfip="$3"
|
||||||
[ -n "${!__nrm_mainiface}" ] || network_parse_confbr "$__nrm_mainconfbr" "$__nrm_mainiface"
|
[ -n "${!__nrm_mainiface}" ] || __old_network_parse_confbr "$__nrm_mainconfbr" "$__nrm_mainiface"
|
||||||
[ -n "${!__nrm_mainiface}" ] || network_parse_confip "$__nrm_mainconfip" "$__nrm_mainiface"
|
[ -n "${!__nrm_mainiface}" ] || __old_network_parse_confip "$__nrm_mainconfip" "$__nrm_mainiface"
|
||||||
[ -n "${!__nrm_mainiface}" ] || set_var "$__nrm_mainiface" eth0
|
[ -n "${!__nrm_mainiface}" ] || set_var "$__nrm_mainiface" eth0
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_set_confip() {
|
|
||||||
eval "$(ip addr show dev "$1" | awk "BEGIN {
|
|
||||||
mainipvar = \"${2:-mainip}\"
|
|
||||||
supplipsvar = \"${3:-supplips}\"
|
|
||||||
"'
|
|
||||||
print mainipvar "="
|
|
||||||
print supplipsvar "=()"
|
|
||||||
mainip = ""
|
|
||||||
supplips = 0
|
|
||||||
}
|
|
||||||
$1 == "inet" {
|
|
||||||
if (mainip == "") {
|
|
||||||
mainip = $2
|
|
||||||
print mainipvar "=\"" mainip "\""
|
|
||||||
} else {
|
|
||||||
if (!supplips) {
|
|
||||||
supplips = 1
|
|
||||||
print supplipsvar "=("
|
|
||||||
}
|
|
||||||
print "\"" $2 "\""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
if (supplips) {
|
|
||||||
print ")"
|
|
||||||
}
|
|
||||||
}')"
|
|
||||||
set_var "$2" "$(array_join "$2" ,)"
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_set_gateway() {
|
|
||||||
eval "$(route -n | awk "BEGIN {
|
|
||||||
iface = \"$1\"
|
|
||||||
gatewayvar = \"${2:-gateway}\"
|
|
||||||
"'
|
|
||||||
print gatewayvar "="
|
|
||||||
}
|
|
||||||
$1 == "0.0.0.0" && $8 == iface {
|
|
||||||
print gatewayvar "=\"" $2 "\""
|
|
||||||
}')"
|
|
||||||
}
|
|
||||||
#BUG)"
|
|
||||||
|
|
||||||
function network_set_confips() {
|
|
||||||
local -a __nsc_confips __nsc_ifaces __nsc_supplips
|
|
||||||
local __nsc_iface __nsc_mainip __nsc_gateway
|
|
||||||
array_from_lines __nsc_ifaces "$(ip link | grep -v '<.*LOOPBACK.*>' | grep '<.*UP.*>' | awk '{ sub(/:$/, "", $2); print $2}')"
|
|
||||||
for __nsc_iface in "${__nsc_ifaces[@]}"; do
|
|
||||||
network_set_confip "$__nsc_iface" __nsc_mainip __nsc_supplips
|
|
||||||
[ -n "$__nsc_mainip" ] || continue
|
|
||||||
network_set_gateway "$__nsc_iface" __nsc_gateway
|
|
||||||
array_add __nsc_confips "$__nsc_iface:$__nsc_mainip${__nsc_gateway:++$__nsc_gateway}${__nsc_supplips:+,$__nsc_supplips}"
|
|
||||||
done
|
|
||||||
array_copy "${1:-confips}" __nsc_confips
|
|
||||||
}
|
|
||||||
|
|
||||||
function network_set_confbrs() {
|
|
||||||
local -a __nsc_ifaces __nsc_tmpconfbrs __nsc_confbrs
|
|
||||||
local __nsc_confbr __nsc_br __nsc_iface
|
|
||||||
array_from_lines __nsc_ifaces "$(ip link | grep -v '<.*LOOPBACK.*>' | grep '<.*UP.*>' | awk '{ sub(/:$/, "", $2); print $2}')"
|
|
||||||
array_from_lines __nsc_tmpconfbrs "$(brctl show 2>/dev/null | awk 'BEGIN { br = "" }
|
|
||||||
NR == 1 { next }
|
|
||||||
$1 != "" { br = $1 }
|
|
||||||
{ print br ":" $4 }
|
|
||||||
')"
|
|
||||||
for __nsc_confbr in "${__nsc_tmpconfbrs[@]}"; do
|
|
||||||
splitpair "$__nsc_confbr" __nsc_br __nsc_iface
|
|
||||||
array_contains __nsc_ifaces "$__nsc_br" || continue
|
|
||||||
array_add __nsc_confbrs "$__nsc_confbr"
|
|
||||||
done
|
|
||||||
array_copy "${1:-confbrs}" __nsc_confbrs
|
|
||||||
}
|
|
||||||
|
|
||||||
__DEBIAN_NETWORK_UPDATE_BASE_SCRIPT='
|
__DEBIAN_NETWORK_UPDATE_BASE_SCRIPT='
|
||||||
BEGIN {
|
BEGIN {
|
||||||
method = "dhcp"
|
method = "dhcp"
|
||||||
|
@ -622,7 +655,7 @@ BEGIN {
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
|
||||||
function network_update_bridge() {
|
function __old_network_update_bridge() {
|
||||||
# vérifier la configuration (interfaces de ifaces[@] en manual, présence du
|
# vérifier la configuration (interfaces de ifaces[@] en manual, présence du
|
||||||
# bridge, bridge en auto, adresse ip principale statique ou en dhcp,
|
# bridge, bridge en auto, adresse ip principale statique ou en dhcp,
|
||||||
# adresses ip supplémentaires), puis si nécessaire, supprimer l'ancienne
|
# adresses ip supplémentaires), puis si nécessaire, supprimer l'ancienne
|
||||||
|
@ -856,7 +889,7 @@ END {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function network_update_iface() {
|
function __old_network_update_iface() {
|
||||||
# vérifier la configuration (présence de l'interface, interface en auto,
|
# vérifier la configuration (présence de l'interface, interface en auto,
|
||||||
# adresse ip principale statique ou en dhcp, adresses ip supplémentaires),
|
# adresse ip principale statique ou en dhcp, adresses ip supplémentaires),
|
||||||
# puis si nécessaire, supprimer l'ancienne configuration et créer la
|
# puis si nécessaire, supprimer l'ancienne configuration et créer la
|
||||||
|
@ -1019,16 +1052,16 @@ function network_config() {
|
||||||
array_copy confips __nc_confips
|
array_copy confips __nc_confips
|
||||||
array_copy confbrs __nc_confbrs
|
array_copy confbrs __nc_confbrs
|
||||||
|
|
||||||
network_fix_confips confips
|
__old_network_fix_confips confips
|
||||||
network_fix_confbrs confbrs
|
__old_network_fix_confbrs confbrs
|
||||||
|
|
||||||
local mainbr # bridge principal
|
local mainbr # bridge principal
|
||||||
local mainip # adresse IP principale de l'interface principale
|
local mainip # adresse IP principale de l'interface principale
|
||||||
local confbr confip br iface suffix gateway
|
local confbr confip br iface suffix gateway
|
||||||
local -a ipspecs
|
local -a ipspecs
|
||||||
|
|
||||||
network_resolve_mainiface mainiface "${confbrs[0]}" "${confips[0]}"
|
__old_network_resolve_mainiface mainiface "${confbrs[0]}" "${confips[0]}"
|
||||||
network_parse_confbr "${confbrs[0]}" mainbr
|
__old_network_parse_confbr "${confbrs[0]}" mainbr
|
||||||
[ -n "$mainbr" ] || mainbr=br0
|
[ -n "$mainbr" ] || mainbr=br0
|
||||||
|
|
||||||
if [ -n "${confips[*]}" -o -n "${confbrs[*]}" ]; then
|
if [ -n "${confips[*]}" -o -n "${confbrs[*]}" ]; then
|
||||||
|
@ -1041,11 +1074,11 @@ function network_config() {
|
||||||
local -a brifaces
|
local -a brifaces
|
||||||
ifaces_with_ips=()
|
ifaces_with_ips=()
|
||||||
for confip in "${confips[@]}"; do
|
for confip in "${confips[@]}"; do
|
||||||
network_parse_confip "$confip" iface
|
__old_network_parse_confip "$confip" iface
|
||||||
array_addu ifaces_with_ips "$iface"
|
array_addu ifaces_with_ips "$iface"
|
||||||
done
|
done
|
||||||
for confbr in "${confbrs[@]}"; do
|
for confbr in "${confbrs[@]}"; do
|
||||||
network_parse_confbr "$confbr" br ifaces
|
__old_network_parse_confbr "$confbr" br ifaces
|
||||||
array_add brifaces "$br"
|
array_add brifaces "$br"
|
||||||
for iface in "${ifaces[@]}"; do
|
for iface in "${ifaces[@]}"; do
|
||||||
if array_contains ifaces_with_ips "$iface"; then
|
if array_contains ifaces_with_ips "$iface"; then
|
||||||
|
@ -1056,7 +1089,7 @@ function network_config() {
|
||||||
done
|
done
|
||||||
local -a confstdips confbrips
|
local -a confstdips confbrips
|
||||||
for confip in "${confips[@]}"; do
|
for confip in "${confips[@]}"; do
|
||||||
network_parse_confip "$confip" iface
|
__old_network_parse_confip "$confip" iface
|
||||||
[ -n "$iface" ] || iface="$mainiface"
|
[ -n "$iface" ] || iface="$mainiface"
|
||||||
if array_contains brifaces "$iface"; then
|
if array_contains brifaces "$iface"; then
|
||||||
array_add confbrips "$confip"
|
array_add confbrips "$confip"
|
||||||
|
@ -1086,37 +1119,37 @@ iface lo inet loopback
|
||||||
local -a tmpifaces
|
local -a tmpifaces
|
||||||
local tmpbr
|
local tmpbr
|
||||||
for confip in "${confbrips[@]}"; do
|
for confip in "${confbrips[@]}"; do
|
||||||
network_parse_confip "$confip" br ipspecs
|
__old_network_parse_confip "$confip" br ipspecs
|
||||||
[ -n "$br" ] || br="$mainbr"
|
[ -n "$br" ] || br="$mainbr"
|
||||||
|
|
||||||
if [ -z "$mainip" -a "$br" == "$mainiface" ]; then
|
if [ -z "$mainip" -a "$br" == "$mainiface" ]; then
|
||||||
network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
|
__old_network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ifaces=()
|
ifaces=()
|
||||||
for confbr in "${confbrs[@]}"; do
|
for confbr in "${confbrs[@]}"; do
|
||||||
network_parse_confbr "$confbr" tmpbr tmpifaces
|
__old_network_parse_confbr "$confbr" tmpbr tmpifaces
|
||||||
if [ "$tmpbr" == "$br" ]; then
|
if [ "$tmpbr" == "$br" ]; then
|
||||||
array_copy ifaces tmpifaces
|
array_copy ifaces tmpifaces
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if network_update_bridge "$interfaces" "$workfile" "$br" ipspecs ifaces; then
|
if __old_network_update_bridge "$interfaces" "$workfile" "$br" ipspecs ifaces; then
|
||||||
cat "$workfile" >"$interfaces"
|
cat "$workfile" >"$interfaces"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# configurer chaque interface classique
|
# configurer chaque interface classique
|
||||||
for confip in "${confstdips[@]}"; do
|
for confip in "${confstdips[@]}"; do
|
||||||
network_parse_confip "$confip" iface ipspecs
|
__old_network_parse_confip "$confip" iface ipspecs
|
||||||
[ -n "$iface" ] || iface="$mainiface"
|
[ -n "$iface" ] || iface="$mainiface"
|
||||||
|
|
||||||
if [ -z "$mainip" -a "$iface" == "$mainiface" ]; then
|
if [ -z "$mainip" -a "$iface" == "$mainiface" ]; then
|
||||||
network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
|
__old_network_parse_ipspec "${ipspecs[0]}" mainip suffix gateway
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if network_update_iface "$interfaces" "$workfile" "$iface" ipspecs; then
|
if __old_network_update_iface "$interfaces" "$workfile" "$iface" ipspecs; then
|
||||||
cat "$workfile" >"$interfaces"
|
cat "$workfile" >"$interfaces"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -1130,7 +1163,7 @@ iface lo inet loopback
|
||||||
uecho "/etc/network/interfaces: pas de modifications"
|
uecho "/etc/network/interfaces: pas de modifications"
|
||||||
fi
|
fi
|
||||||
elif testdiff "$interfaces" /etc/network/interfaces; then
|
elif testdiff "$interfaces" /etc/network/interfaces; then
|
||||||
network_backup /etc/network/interfaces
|
__old_network_backup /etc/network/interfaces
|
||||||
if show_debug; then
|
if show_debug; then
|
||||||
edebug "Setting /etc/network/interfaces to:"
|
edebug "Setting /etc/network/interfaces to:"
|
||||||
cat "$interfaces" | sed 's/^/ /g' 1>&2
|
cat "$interfaces" | sed 's/^/ /g' 1>&2
|
||||||
|
@ -1164,10 +1197,10 @@ iface lo inet loopback
|
||||||
mainip="${mainips[0]}"
|
mainip="${mainips[0]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
network_hostname "$host"
|
__old_network_hostname "$host"
|
||||||
network_mailname "$host"
|
__old_network_mailname "$host"
|
||||||
if [ -n "$mainip" ]; then
|
if [ -n "$mainip" ]; then
|
||||||
network_hosts "$host" "$mainip"
|
__old_network_hosts "$host" "$mainip"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eend
|
eend
|
||||||
|
|
Loading…
Reference in New Issue