Merge pull request #1405 from bergware/master

Revert: Revised networking and docker macvlan usage
This commit is contained in:
tom mortensen
2023-08-08 11:03:18 -07:00
committed by GitHub
3 changed files with 26 additions and 47 deletions

View File

@@ -254,6 +254,14 @@ _(Template Authoring Mode)_:
:docker_authoring_mode_help:
_(Docker custom network type)_:
: <select name="DOCKER_NETWORK_TYPE">
<?=mk_option(_var($dockercfg,'DOCKER_NETWORK_TYPE'), '1', _('ipvlan'))?>
<?=mk_option(_var($dockercfg,'DOCKER_NETWORK_TYPE'), '', _('macvlan'))?>
</select>&nbsp;_(Please read the Help carefully)_. _(Misconfiguration can cause problems)_.
:docker_custom_network_type_help:
_(Host access to custom networks)_:
: <select name="DOCKER_ALLOW_ACCESS">
<?=mk_option(_var($dockercfg,'DOCKER_ALLOW_ACCESS'), '', _('Disabled'))?>
@@ -452,6 +460,11 @@ _(Docker LOG rotation)_:
:docker_log_rotation_active_help:
_(Docker custom network type)_:
: <?=_var($dockercfg,'DOCKER_NETWORK_TYPE')=='1' ? _('ipvlan') : _('macvlan')?>
:docker_custom_network_type_help:
_(Host access to custom networks)_:
: <?=_var($dockercfg,'DOCKER_ALLOW_ACCESS')=='yes' ? _('Enabled') : _('Disabled')?>

View File

@@ -73,9 +73,15 @@ else
[[ -e $SYSTEM/docker0 ]] && echo 1 > $CONF6/docker0/disable_ipv6
fi
DETACH='ipvlan'
ATTACH='macvlan'
MODE='bridge'
if [[ -z $DOCKER_NETWORK_TYPE ]]; then
DETACH='ipvlan'
ATTACH='macvlan'
MODE='bridge'
else
DETACH='macvlan'
ATTACH='ipvlan'
MODE='l2 bridge'
fi
export DOCKER_RAMDISK=true
@@ -398,8 +404,7 @@ start_network(){
[[ -n $RANGE ]] && SERVER="--aux-address=server=${R4%/*}" || SERVER="--aux-address=server=${SHIM_HIGH%/*}"
fi
fi
VHOST=vhost${NETWORK//[^0-9.]/}
docker network create -d $ATTACH $SUBNET $GATEWAY $SERVER $RANGE $SUBNET6 $GATEWAY6 $SERVER6 $RANGE6 -o parent=$VHOST $NETWORK | xargs docker network inspect -f 'created network {{.Name}} with subnets: {{range .IPAM.Config}}{{.Subnet}}; {{end}}' 2>/dev/null | logger -t $(basename $0)
docker network create -d $ATTACH $SUBNET $GATEWAY $SERVER $RANGE $SUBNET6 $GATEWAY6 $SERVER6 $RANGE6 -o parent=$NETWORK $NETWORK | xargs docker network inspect -f 'created network {{.Name}} with subnets: {{range .IPAM.Config}}{{.Subnet}}; {{end}}' 2>/dev/null | logger -t $(basename $0)
# connect containers to this new network
for CONNECT in ${NETRESTORE[$NETWORK]}; do
THIS_ID=${CONNECT%,*}

View File

@@ -51,9 +51,7 @@
# - reverted iptables and ip6tables and arp-tables inclusion to bridge interfaces
# - removed promiscuous mode setting for bridge interfaces
# - added persistent option to dhcpcd
# Adapted by Bergware for use in unRAID - August 2023
# - added macvlan network creation
#
############################
# READ NETWORK CONFIG FILE #
@@ -246,44 +244,12 @@ vlan_up(){
vlan_down(){
for PORT in ${BRNICS[$i]:-${IFNAME[$i]}}; do
for VLAN in $(ls --indicator-style=none $SYSTEM|grep -Po "$PORT\.\d+"); do
run ip link set $VLAN down 2>/dev/null
run ip link del $VLAN 2>/dev/null
run ip link set $VLAN down
run ip link del $VLAN
done
done
}
# function to create macvlan interfaces
macvlan_up(){
PARENT=${IFNAME[$i]}
[[ -n ${BONDNICS[$i]} ]] && PARENT=${BONDNAME[$i]}
[[ -n ${BRNICS[$i]} ]] && PARENT=${BRNAME[$i]}
VHOST=vhost${PARENT//[^0-9]/}
run ip link add link $PARENT name $VHOST type macvlan mode bridge
set_mtu $VHOST
run ip link set $VHOST up 2>/dev/null
for ((j=1;j<${VLANS[$i]:-0};j++)); do
VLAN=${VLANID[$i,$j]}
run ip link add link $PARENT.$VLAN name $VHOST.$VLAN type macvlan mode bridge
set_mtu $VHOST.$VLAN
run ip link set $VHOST.$VLAN up 2>/dev/null
done
}
# function to delete macvlan interfaces
macvlan_down(){
PARENT=${IFNAME[$i]}
[[ -n ${BONDNICS[$i]} ]] && PARENT=${BONDNAME[$i]}
[[ -n ${BRNICS[$i]} ]] && PARENT=${BRNAME[$i]}
VHOST=vhost${PARENT//[^0-9]/}
for ((j=1;j<${VLANS[$i]:-0};j++)); do
VLAN=${VLANID[$i,$j]}
run ip link set $VHOST.$VLAN down 2>/dev/null
run ip link del $VHOST.$VLAN 2>/dev/null
done
run ip link set $VHOST down 2>/dev/null
run ip link del $VHOST 2>/dev/null
}
# function to enable/disable ipv6 protocol per interface
ipv6_up(){
[[ -d $CONF6/${IFACE/$1/$2} ]] && echo $4 >$CONF6/${IFACE/$1/$2}/disable_ipv6
@@ -306,7 +272,6 @@ ipv6_conf(){
# function to enable/disable ipv6 assignment per interface
ipv6_addr(){
ipv6_ra $IFACE $1 $2
ipv6_ra vhost${IFACE//[^0-9.]} $1 $2
# repeat action on related interfaces
if [[ ${IFACE:0:4} == bond ]]; then
ipv6_conf bond br eth $1 $2
@@ -323,7 +288,6 @@ ipaddr_up(){
# disable IPv6 per interface when IPv4 only
[[ $IP == ipv4 ]] && DISABLE6=1 || DISABLE6=0
echo $DISABLE6 >$CONF6/$IFACE/disable_ipv6
echo $DISABLE6 >$CONF6/vhost${IFACE//[^0-9.]}/disable_ipv6
# repeat action on related interfaces
if [[ ${IFACE:0:4} == bond ]]; then
ipv6_up bond br eth $DISABLE6
@@ -392,7 +356,6 @@ ipaddr_conf(){
ipaddr_flush(){
run ip -$1 addr flush dev $IFACE
run ip -$1 route flush dev $IFACE
run ip -$1 addr flush dev vhost${IFACE//[^0-9.]}
if [[ ${IFACE:0:4} == bond ]]; then
ipaddr_conf bond br eth $1
elif [[ ${IFACE:0:2} == br ]]; then
@@ -431,7 +394,6 @@ 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
# 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 +492,6 @@ if_down(){
[[ $DEBUG_ETH_UP == yes ]] && log "interface $IFACE not present, can't take down"
fi
done
macvlan_down # delete macvlan 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