From 4f61f118790709d3923d1ead334e95fc41a8a86d Mon Sep 17 00:00:00 2001 From: bergware Date: Wed, 9 Aug 2023 23:26:21 +0200 Subject: [PATCH 01/85] networking: use new macvtap network instead of macvlan Minor fixes --- .../plugins/dynamix.vm.manager/include/libvirt.php | 4 ++-- .../dynamix.vm.manager/include/libvirt_helpers.php | 4 ++-- etc/rc.d/rc.inet1 | 14 +++++++------- etc/rc.d/rc.libvirt | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 264662525..b359871ce 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -661,11 +661,11 @@ $netmodel = $nic['model'] ?: 'virtio-net'; $net_res =$this->libvirt_get_net_res($this->conn, $nic['network']); - $vhost = file_exists("/boot/config/network.cfg") && exec("grep -Po '^BRNICS\[0\]=\"\K[^\"]+' /boot/config/network.cfg")==''; + $vhost = file_exists("/boot/config/network.cfg") && exec("grep -Po '^BRNICS\\[0\\]=\"\\K[^\"]+' /boot/config/network.cfg")==''; if ($vhost) { exec("ip -br a|grep -Po '^vhost[0-9][^@]*'",$br); } else { - exec("brctl show | cut -f1| awk NF | sed -n '1!p'", $br); + exec("brctl show|grep -Po '^(vir)?br[0-9]+(\.[0-9]+)?'", $br); } if ($nic["boot"] != NULL) $nicboot = "" ; else $nicboot = "" ; if($net_res) { diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php index 3780401ba..8f7d643e8 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php @@ -1066,10 +1066,10 @@ private static $encoding = 'UTF-8'; function getValidNetworks() { global $lv; $arrValidNetworks = []; - if (file_exists("/boot/config/network.cfg") && exec("grep -Po '^BRNICS\[0\]=\"\K[^\"]+' /boot/config/network.cfg")=='') { + if (file_exists("/boot/config/network.cfg") && exec("grep -Pom1 '^BRNICS\\[0\\]=\"\\K[^\"]+' /boot/config/network.cfg")=='') { exec("ip -br a|grep -Po '^(virbr|vhost)[0-9][^@ ]*'",$arrBridges); } else { - exec("brctl show|grep -Po '^(vir)?br\d\S*'", $arrBridges); + exec("brctl show|grep -Po '^(vir)?br[0-9]+(\.[0-9]+)?'", $arrBridges); } if (!is_array($arrBridges)) { $arrBridges = []; diff --git a/etc/rc.d/rc.inet1 b/etc/rc.d/rc.inet1 index 4d79574c5..ae8ac31c2 100755 --- a/etc/rc.d/rc.inet1 +++ b/etc/rc.d/rc.inet1 @@ -53,7 +53,7 @@ # - added persistent option to dhcpcd # Adapted by Bergware for use in unRAID - August 2023 -# - added macvlan network creation +# - added macvtap network creation ############################ # READ NETWORK CONFIG FILE # @@ -252,8 +252,8 @@ vlan_down(){ done } -# function to create macvlan interfaces -macvlan_up(){ +# function to create macvtap interfaces +macvtap_up(){ PARENT=${IFNAME[$i]} [[ -n ${BONDNICS[$i]} ]] && PARENT=${BONDNAME[$i]} [[ -n ${BRNICS[$i]} ]] && PARENT=${BRNAME[$i]} @@ -269,8 +269,8 @@ macvlan_up(){ done } -# function to delete macvlan interfaces -macvlan_down(){ +# function to delete macvtap interfaces +macvtap_down(){ PARENT=${IFNAME[$i]} [[ -n ${BONDNICS[$i]} ]] && PARENT=${BONDNAME[$i]} [[ -n ${BRNICS[$i]} ]] && PARENT=${BRNAME[$i]} @@ -431,7 +431,7 @@ if_up(){ [[ -n ${BONDNICS[$i]} ]] && bond_up # create interface as bond [[ -n ${VLANS[$i]} ]] && vlan_up # create interface VLANs [[ -n ${BRNICS[$i]} ]] && br_up # create interface as bridge - macvlan_up # create macvlan interfaces + macvtap_up # create macvtap interfaces # if the interface isn't in the kernel yet # but there's an alias for it in modules.conf # then it should be loaded first @@ -530,7 +530,7 @@ if_down(){ [[ $DEBUG_ETH_UP == yes ]] && log "interface $IFACE not present, can't take down" fi done - macvlan_down # delete macvlan interfaces + macvtap_down # delete macvtap interfaces [[ -n ${BRNICS[$i]} ]] && br_down # delete interface as bridge [[ -n ${VLANS[$i]} ]] && vlan_down # delete interface VLANs [[ -n ${BONDNICS[$i]} ]] && bond_down # delete interface as bond diff --git a/etc/rc.d/rc.libvirt b/etc/rc.d/rc.libvirt index cb0a1cffd..3163c9d8d 100755 --- a/etc/rc.d/rc.libvirt +++ b/etc/rc.d/rc.libvirt @@ -173,11 +173,11 @@ start_libvirtd() { sed -ri "s///g" /etc/libvirt/qemu/*.xml &> /dev/null # update interface section of VM configuration files if [[ -f /boot/config/network.cfg && -z $(grep -Po '^BRNICS\[0\]="\K[^"]+' /boot/config/network.cfg) ]]; then - # bridge interface to macvlan interface - sed -ri "s///;s///" /etc/libvirt/qemu/*.xml &> /dev/null + # bridge interface to macvtap interface + sed -ri "s///;s///" /etc/libvirt/qemu/*.xml &> /dev/null else - # macvlan interface to bridge interface - sed -ri "s///;s///" /etc/libvirt/qemu/*.xml &> /dev/null + # macvtap interface to bridge interface + sed -ri "s///;s///" /etc/libvirt/qemu/*.xml &> /dev/null fi # copy any new conf files we dont currently have cp -n /etc/libvirt-/*.conf /etc/libvirt &> /dev/null From 5e6f8656ac3f8dfa6224496eac47d09b9f5960a9 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 10 Aug 2023 02:08:15 +0200 Subject: [PATCH 02/85] Fix container starts when no auto-start is set --- emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container | 2 ++ 1 file changed, 2 insertions(+) diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container b/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container index e357d8752..533670ee8 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container +++ b/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container @@ -19,6 +19,7 @@ $DockerClient = new DockerClient(); $DockerUpdate = new DockerUpdate(); $DockerTemplates = new DockerTemplates(); +$start = array_map(function($row){return strtok($row,' ');},@file('/var/lib/docker/unraid-autostart',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) ?: []); $custom = DockerUtil::custom(); $subnet = DockerUtil::network($custom); $cpus = DockerUtil::cpus(); @@ -30,6 +31,7 @@ $old = $DockerClient->getImageID($repository); removeContainer($name,false,false); execCommand(str_replace('/docker create ','/docker run -d ',$cmd),false); +if (!in_array($name,$start)) stopContainer($name,false,false); $DockerClient->flushCaches(); $new = $DockerClient->getImageID($repository); if ($old && $old != $new) removeImage($old,false); From 180c4c2e912d18567b6338d02e4e1e92ee4c0bde Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 10 Aug 2023 03:26:04 +0200 Subject: [PATCH 03/85] Re-introduce macvlan / ipvlan selection when bridge is enabled --- .../DockerSettings.page | 19 ++++++++++++++ .../dynamix.vm.manager/include/libvirt.php | 2 +- .../include/libvirt_helpers.php | 6 ++--- etc/rc.d/rc.docker | 26 ++++++++++++++----- etc/rc.d/rc.inet1 | 4 +-- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/DockerSettings.page b/emhttp/plugins/dynamix.docker.manager/DockerSettings.page index f33437337..79f593ab3 100644 --- a/emhttp/plugins/dynamix.docker.manager/DockerSettings.page +++ b/emhttp/plugins/dynamix.docker.manager/DockerSettings.page @@ -23,6 +23,8 @@ require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php"; $DockerClient = new DockerClient(); exec("/etc/rc.d/rc.docker status >/dev/null",$dummy,$DockerStopped); +$bridge = file_exists('/sys/class/net/br0'); + function strposX($s, $c, $n=1) { $p = 0; while ($n && $p=strpos($s,$c,$p)!==false) {$n--; $p+=strlen($c);} @@ -254,6 +256,16 @@ _(Template Authoring Mode)_: :docker_authoring_mode_help: + +_(Docker custom network type)_: +:  _(Please read the Help carefully)_. _(Misconfiguration can cause problems)_. + +:docker_custom_network_type_help: + + _(Host access to custom networks)_: :