🚀 Sync 2026-03-20 14:18:42

This commit is contained in:
github-actions[bot] committed 2026-03-20 14:18:42 +08:00
1 parent 3f5e547363
commit 72b1d9508b
81 files changed
+2797 -975

No files matched your search

+80 -88
View File
@@ -3,8 +3,8 @@
USE_PROCD=1
START=99
extra_command "uciadd" "<interface> <device> <zone> Add docker bridge configuration to network and firewall uci config"
extra_command "ucidel" "<interface> <device> <zone> Delete docker bridge configuration from network and firewall uci config"
extra_command "uciadd" "<ignored> <device> <zone> Add docker bridge configuration to firewall uci config"
extra_command "ucidel" "<ignored> <device> <zone> Delete docker bridge configuration from firewall uci config"
DOCKER_CONF_DIR="/tmp/dockerd"
DOCKERD_CONF="${DOCKER_CONF_DIR}/daemon.json"
@@ -17,94 +17,85 @@ json_add_array_string() {
json_add_string "" "${1}"
}
find_network_device() {
local device="${1}"
local device_section=""
check_device() {
local cfg="${1}"
local device="${2}"
local type name
config_get type "${cfg}" type
config_get name "${cfg}" name
[ "${type}" = "bridge" ] && [ "${name}" = "${device}" ] \
&& device_section="${cfg}"
}
config_load network
config_foreach check_device device "${device}"
echo "${device_section}"
}
boot() {
uciadd
rc_procd start_service
}
uciadd() {
local iface="${1}"
local device="${2}"
local zone="${3}"
[ -z "${iface}" ] && {
iface="docker"
[ -z "${device}" ] && {
device="docker0"
zone="docker"
}
/etc/init.d/dockerd running && {
echo "Please stop dockerd service first"
exit 0
}
# Add network interface
if ! uci_quiet get network.${iface}; then
logger -t "dockerd-init" -p notice "Adding interface '${iface}' to network config"
uci_quiet add network interface
uci_quiet rename network.@interface[-1]="${iface}"
uci_quiet set network.@interface[-1].device="${device}"
uci_quiet set network.@interface[-1].proto="none"
uci_quiet set network.@interface[-1].auto="0"
uci_quiet commit network
fi
# Add docker bridge device
if [ "$(find_network_device "$device")" = "" ]; then
logger -t "dockerd-init" -p notice "Adding bridge device '${device}' to network config"
uci_quiet add network device
uci_quiet set network.@device[-1].type="bridge"
uci_quiet set network.@device[-1].name="${device}"
uci_quiet commit network
else
logger -t "dockerd-init" -p notice "Bridge device '${device}' already defined in network config"
fi
# Add firewall zone
if ! uci_quiet get firewall.${zone}; then
logger -t "dockerd-init" -p notice "Adding firewall zone '${zone}' to firewall config"
uci_quiet add firewall zone
uci_quiet rename firewall.@zone[-1]="${zone}"
uci_quiet set firewall.@zone[-1].name="${zone}"
uci_quiet set firewall.@zone[-1].input="ACCEPT"
uci_quiet set firewall.@zone[-1].output="ACCEPT"
uci_quiet set firewall.@zone[-1].forward="ACCEPT"
uci_quiet set firewall.@zone[-1].name="${zone}"
uci_quiet set firewall.dockerd=forwarding
uci_quiet set firewall.@forwarding[-1].src="${zone}"
uci_quiet set firewall.@forwarding[-1].dest='wan'
uci_quiet commit firewall
fi
# Add interface to firewall zone
# Add device to firewall zone
if uci_quiet get firewall.${zone}; then
uci_quiet del_list firewall.${zone}.network="${iface}"
uci_quiet add_list firewall.${zone}.network="${iface}"
uci_quiet del_list firewall.${zone}.device="${device}"
if [ docker0 = "$device" ]; then
uci_quiet del_list firewall.${zone}.subnet="172.16.0.0/12"
uci_quiet add_list firewall.${zone}.subnet="172.16.0.0/12"
else
uci_quiet add_list firewall.${zone}.device="${device}"
fi
uci_quiet commit firewall
fi
reload_config
# Add forwarding rules
local forwarding_section
check_forwarding() {
local cfg="${1}"
local srcm="${2}"
local destm="${3}"
local src dest
config_get src "${cfg}" src
config_get dest "${cfg}" dest
[[ "${src}" = "${srcm}" && "${dest}" = "${destm}" ]] \
&& forwarding_section="${cfg}"
}
config_load firewall
forwarding_section=""
config_foreach check_forwarding forwarding ${zone} wan
[[ -n "${forwarding_section}" ]] || {
uci_quiet set firewall.${zone}_to_wan=forwarding
uci_quiet set firewall.${zone}_to_wan.src=${zone}
uci_quiet set firewall.${zone}_to_wan.dest=wan
}
forwarding_section=""
config_foreach check_forwarding forwarding ${zone} lan
[[ -n "${forwarding_section}" ]] || {
uci_quiet set firewall.${zone}_to_lan=forwarding
uci_quiet set firewall.${zone}_to_lan.src=${zone}
uci_quiet set firewall.${zone}_to_lan.dest=lan
}
forwarding_section=""
config_foreach check_forwarding forwarding lan ${zone}
[[ -n "${forwarding_section}" ]] || {
uci_quiet set firewall.lan_to_${zone}=forwarding
uci_quiet set firewall.lan_to_${zone}.src=lan
uci_quiet set firewall.lan_to_${zone}.dest=${zone}
}
uci_quiet commit firewall
/etc/init.d/firewall reload
}
ucidel() {
@@ -112,44 +103,28 @@ ucidel() {
local device="${2}"
local zone="${3}"
[ -z "${iface}" ] && {
iface="docker"
[ -z "${device}" ] && {
device="docker0"
zone="docker"
}
/etc/init.d/dockerd running && {
echo "Please stop dockerd service first"
exit 0
}
# Remove network device
if uci_quiet delete network.$(find_network_device "${device}"); then
logger -t "dockerd-init" -p notice "Deleting bridge device '${device}' from network config"
uci_quiet commit network
fi
# Remove network interface
if uci_quiet get network.${iface}; then
logger -t "dockerd-init" -p notice "Deleting interface '${iface}' from network config"
uci_quiet delete network.${iface}
uci_quiet commit network
fi
# Remove interface from firewall zone
if uci_quiet get firewall.${zone}; then
logger -t "dockerd-init" -p notice "Deleting network interface '${iface}' in zone '${zone}' from firewall config"
uci_quiet del_list firewall.${zone}.network="${iface}"
logger -t "dockerd-init" -p notice "Deleting network device '${device}' in zone '${zone}' from firewall config"
uci_quiet del_list firewall.${zone}.device="${device}"
uci_quiet commit firewall
# Remove Firewall zone if network is empty
if ! uci_quiet get firewall.${zone}.network; then
if ! uci_quiet get firewall.${zone}.device; then
logger -t "dockerd-init" -p notice "Deleting firewall zone '${zone}' from firewall config"
uci_quiet delete firewall.${zone}
uci_quiet delete firewall.${zone}_to_wan
uci_quiet delete firewall.${zone}_to_lan
uci_quiet delete firewall.lan_to_${zone}
fi
uci_quiet commit firewall
fi
reload_config
/etc/init.d/firewall reload
}
process_config() {
@@ -174,7 +149,7 @@ process_config() {
config_get data_root globals data_root "/opt/docker/"
config_get log_level globals log_level "warn"
config_get_bool iptables globals iptables "1"
config_get_bool iptables globals iptables "0"
config_get_bool ip6tables globals ip6tables "0"
# Don't add these options by default
@@ -193,6 +168,7 @@ process_config() {
config_get https_proxy proxies https_proxy "${https_proxy}"
config_get no_proxy proxies no_proxy "${no_proxy}"
config_get storage_driver globals storage_driver ""
config_get max_concurrent_downloads globals max_concurrent_downloads ""
. /usr/share/libubox/jshn.sh
json_init
@@ -223,6 +199,14 @@ process_config() {
json_close_object
fi
[ -z "${storage_driver}" ] || json_add_string "storage-driver" "${storage_driver}"
[ "${max_concurrent_downloads:-0}" -eq "0" ] || json_add_int "max-concurrent-downloads" "${max_concurrent_downloads}"
json_add_string "log-driver" "json-file"
json_add_object "log-opts"
json_add_string "max-size" "50m"
json_add_string "max-file" "2"
json_close_object
json_dump > "${DOCKERD_CONF}"
[ "${iptables}" -eq "1" ] && config_foreach iptables_add_blocking_rule firewall
@@ -245,6 +229,14 @@ start_service() {
}
reload_service() {
if [ -f "${DOCKERD_CONF}" -a -f /etc/config/dockerd ]; then
local oldroot=`jsonfilter -i "${DOCKERD_CONF}" -e @[\"data-root\"]`
local newroot=`uci get dockerd.globals.data_root`
if [ "$oldroot" != "$newroot" ]; then
restart
return 0
fi
fi
process_config
procd_send_signal dockerd
}