Network improvement: better IPv6 handling

This commit is contained in:
bergware
2023-07-04 15:55:16 +02:00
parent 42875c1a68
commit e5b25761ea
4 changed files with 9 additions and 10 deletions

View File

@@ -49,8 +49,8 @@ $include = $include6 = $address = $address6 = $gateway = $gateway6 = $unset = $p
$wide = false;
foreach ($custom as $network) {
if (in_array($network,$slaves)) continue;
$ip4 = exec("ip -4 addr show $network|awk '/inet /{print $2;exit}'");
$ip6 = exec("ip -6 addr show $network scope global|awk '/inet6 /{print $2;exit}'");
$ip4 = exec("ip -br -4 addr show $network scope global|awk '{print $3}'");
$ip6 = exec("ip -br -6 addr show $network scope global|awk '{print $3}'");
$gw4 = $ip4 ? exec("ip -4 route show dev $network default|awk '{print $3;exit}'") : '';
$gw6 = $ip6 ? exec("ip -6 route show dev $network default|awk '{print $3;exit}'") : '';
$route4 = $ip4 ? exec("ip -4 route show dev $network $ip4|awk '{print $1;exit}'") : '';

View File

@@ -20,10 +20,10 @@ $etc = '/etc/wireguard';
$tmp = '/tmp/list.tmp';
unset($subnets,$hosts,$subnets6,$hosts6,$vtuns,$filter,$docker);
exec("ip -4 route show scope link|awk '/^[^d].+ dev (eth|br|bond)[0-9]+/{print \$1}'",$subnets);
exec("ip -4 addr show scope global|awk '/inet .+ (eth|br|bond)[0-9]+/{split(\$2,ip,\"/\");print ip[1]}'",$hosts);
exec("ip -6 route show type unicast|grep -Pv 'expires|shim-'|awk '/^[^dfm:]/{print \$1}'",$subnets6);
exec("ip -6 addr show scope global|grep -PA2 ': (eth|br|bond)\d+'|awk '/inet6 .+ (global|noprefixroute) \$/{split(\$2,ip,\"/\");print ip[1]}'",$hosts6);
exec("ip -4 route show scope link|awk '/^[^d].+ dev (eth|br|bond)[0-9]+(\\.[0-9]+)?/{print \$1}'",$subnets);
exec("ip -6 route show type unicast|awk '\$0 !~ \"expires\" && \$3 !~ \"^shim-\" && /^[^dfm:]/{print \$1}'",$subnets6);
exec("ip -br -4 addr show scope global|awk '/^(br|bond|eth)[0-9]+(\\.[0-9]+)?/{split(\$3,ip,\"/\");print ip[1]}'",$hosts);
exec("ip -br -6 addr show scope global|awk '/^(br|bond|eth)[0-9]+(\\.[0-9]+)?/{split(\$3,ip,\"/\");print ip[1]}'",$hosts6);
exec("ls --indicator-style=none $etc/wg*.conf*|grep -Po wg[0-9]+",$vtuns);
exec("docker network ls --filter driver='macvlan' --filter driver='ipvlan' --format='{{.Name}}' 2>/dev/null",$filter);

View File

@@ -274,8 +274,7 @@ start_network(){
GATEWAY=$(ip -4 route show dev $NETWORK default|awk '{print $3;exit}')
fi
SUBNET6=; GATEWAY6=; SERVER6=; RANGE6=;
IPV6=$(ip -6 addr show $NETWORK mngtmpaddr|awk '/^ +inet6 /{print $2;exit}')
[[ -z $IPV6 ]] && IPV6=$(ip -6 addr show $NETWORK scope global permanent|awk '/^ +inet6 /{print $2;exit}')
IPV6=$(ip -br -6 addr show $NETWORK scope global|awk '{print $3}')
if [[ -n $IPV6 ]]; then
SUBNET6=$(ip -6 route show dev $NETWORK $IPV6|awk '{print $1;exit}')
SERVER6=${IPV6%%/*}

View File

@@ -234,8 +234,8 @@ if [[ -z $interface || "eth0 br0 bond0" =~ $interface ]]; then
# find management interface
[[ -e /sys/class/net/bond0 ]] && dev=bond0 || dev=eth0
[[ -e /sys/class/net/br0 ]] && dev=br0
IPv4=$(ip -br -4 addr show $dev|awk '{print $3}')
IPv6=$(ip -br -6 addr show $dev|awk '$3 !~ "^fe80" {print $3}')
IPv4=$(ip -br -4 addr show $dev scope global|awk '{print $3}')
IPv6=$(ip -br -6 addr show $dev scope global|awk '{print $3}')
[[ -n $IPv4 ]] && echo " IPv4 address: ${IPv4%/*}">>/etc/issue || echo " IPv4 address: not set">>/etc/issue
[[ -n $IPv6 ]] && echo " IPv6 address: ${IPv6%/*}">>/etc/issue || echo " IPv6 address: not set">>/etc/issue
echo >>/etc/issue