mirror of
https://github.com/AlbrechtL/openwrt-docker.git
synced 2026-10-14 00:01:26 +00:00
Add "nofixedip" option to LAN_IF
This commit is contained in:
+2
-2
@@ -12,7 +12,6 @@ services:
|
||||
|
||||
environment:
|
||||
#DEBUG: "y"
|
||||
#IS_U_OS_APP: "true"
|
||||
|
||||
# Define number of VM CPUs
|
||||
CPU_COUNT: 2
|
||||
@@ -25,7 +24,8 @@ services:
|
||||
#WAN_IF: "enx00e04c0407a6" # Use this option to define a specific physical Ethernet interface
|
||||
# -
|
||||
#LAN_IF: "host" # Usage of container host Ethernet connection as LAN. WARNING: Bad performace because of user space Ethernet implementation.
|
||||
LAN_IF: "veth" # veth pair between OpenWrt and host system
|
||||
LAN_IF: "veth" # veth pair between OpenWrt and host system. The host Ethernet interface IP is fixed to 172.31.1.2/24
|
||||
#LAN_IF: "veth,nofixedip" # veth pair between OpenWrt and host system. No host Ethernet interface configuration
|
||||
#LAN_IF: "enx00e04d68033f" # Use this option to define a specific physical Ethernet interface
|
||||
|
||||
# Make LuCI OpenWrt web interface accessible via host LAN
|
||||
|
||||
@@ -60,12 +60,18 @@ set -e # Revert set +a
|
||||
cp -r /var/www/* /run/shm
|
||||
|
||||
# ******* LuCi forwarding handling *******
|
||||
if [[ $FORWARD_LUCI = "true" && $LAN_IF = "veth" ]]; then
|
||||
LAN_IF_NAME=$(echo $LAN_IF | cut -d',' -f1)
|
||||
LAN_IF_OPTION=$(echo $LAN_IF | cut -d',' -f2)
|
||||
if [[ $FORWARD_LUCI = "true" && $LAN_IF_NAME = "veth" ]]; then
|
||||
info "Enable LuCI forwarding to host LAN at port 9000"
|
||||
LUCI_COMMAND="nsenter --target 1 --uts --net --ipc nginx -c /var/www/nginx-luci.conf"
|
||||
|
||||
if [[ $LAN_IF_OPTION = "nofixedip" ]]; then
|
||||
warn "Please ensure that the virtual Ethernet interface is configured correctly. The LuCI reverse proxy is expecting OpenWrt at the IP address 172.31.1.1"
|
||||
fi
|
||||
else
|
||||
if [[ $FORWARD_LUCI = "true" ]]; then
|
||||
warn "LuCI forwarding is only available if environment variable is set to LAN_IF: 'veth'"
|
||||
warn "LuCI forwarding is only available if environment variable is set to LAN_IF: 'veth'. Currently LAN_IF=$LAN_IF."
|
||||
fi
|
||||
LUCI_COMMAND="sh -c 'sleep infinity'" # TODO: Find something better. Multirun needs something to run.
|
||||
fi
|
||||
|
||||
+8
-5
@@ -60,6 +60,7 @@ attach_veth_if () {
|
||||
VETH_IF_HOST=$1
|
||||
VETH_IF_CONTAINER=$2
|
||||
QEMU_IF=$3
|
||||
OPTION=$4
|
||||
|
||||
info "Creating virtual Ethernet interfaces pairs between host system ($VETH_IF_HOST) and container ($VETH_IF_CONTAINER)..."
|
||||
|
||||
@@ -68,7 +69,7 @@ attach_veth_if () {
|
||||
nsenter --target 1 --uts --net --ipc --mount ip link add $VETH_IF_HOST type veth peer name $VETH_IF_CONTAINER
|
||||
nsenter --target 1 --uts --net --ipc --mount ip link set $VETH_IF_HOST up
|
||||
|
||||
if [[ -z "${IS_U_OS_APP}" ]]; then
|
||||
if [[ -z "${IS_U_OS_APP}" && $OPTION != "nofixedip" ]]; then
|
||||
nsenter --target 1 --uts --net --ipc --mount ip addr add 172.31.1.2/24 dev $VETH_IF_HOST
|
||||
fi
|
||||
else
|
||||
@@ -148,15 +149,17 @@ fi
|
||||
|
||||
# Attach physical PHY to container
|
||||
LAN_ARGS=""
|
||||
if [[ -z "${LAN_IF}" || $LAN_IF = "host" ]]; then
|
||||
LAN_IF_NAME=$(echo $LAN_IF | cut -d',' -f1)
|
||||
LAN_IF_OPTION=$(echo $LAN_IF | cut -d',' -f2)
|
||||
if [[ -z "${LAN_IF_NAME}" || $LAN_IF_NAME = "host" ]]; then
|
||||
LAN_ARGS="-device virtio-net,netdev=qlan0 -netdev user,id=qlan0,net=192.168.1.0/24"
|
||||
elif [[ $LAN_IF = "veth" ]]; then
|
||||
attach_veth_if veth-openwrt0 veth1 qlan1
|
||||
elif [[ $LAN_IF_NAME = "veth" ]]; then
|
||||
attach_veth_if veth-openwrt0 veth1 qlan1 $LAN_IF_OPTION
|
||||
exec 30<>/dev/tap$(cat /sys/class/net/qlan1/ifindex)
|
||||
LAN_ARGS="-device virtio-net-pci,netdev=hostnet0,mac=$(cat /sys/class/net/qlan1/address) \
|
||||
-netdev tap,fd=30,id=hostnet0"
|
||||
else
|
||||
HOST_LAN_IF=$LAN_IF
|
||||
HOST_LAN_IF=$LAN_IF_NAME
|
||||
attach_eth_if $HOST_LAN_IF $HOST_LAN_IF qlan0
|
||||
exec 30<>/dev/tap$(cat /sys/class/net/qlan0/ifindex)
|
||||
LAN_ARGS="-device virtio-net-pci,netdev=hostnet0,mac=$(cat /sys/class/net/qlan0/address) \
|
||||
|
||||
@@ -235,8 +235,8 @@ def test_openwrt_booted(docker_services):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("parameter",
|
||||
[('LAN_IF','veth'),('LAN_IF','ens5'),('LAN_IF',''),('LAN_IF','host')], indirect=True,
|
||||
ids=['LAN_IF=veth', 'LAN_IF=ens5', 'LAN_IF=""', 'LAN_IF="host"'])
|
||||
[('LAN_IF','veth'),('LAN_IF','veth,nofixedip'),('LAN_IF','ens5'),('LAN_IF',''),('LAN_IF','host')], indirect=True,
|
||||
ids=['LAN_IF=veth','LAN_IF=veth,nofixedip', 'LAN_IF=ens5', 'LAN_IF=""', 'LAN_IF="host"'])
|
||||
def test_openwrt_lan(docker_services, parameter):
|
||||
wait_for_openwrt_startup(docker_services)
|
||||
|
||||
@@ -248,6 +248,18 @@ def test_openwrt_lan(docker_services, parameter):
|
||||
assert True, 'ping timeout'
|
||||
return
|
||||
|
||||
case 'veth,nofixedip':
|
||||
# Get all IPv4 addresses
|
||||
process = subprocess.run(['sh','-c','ip addr show veth-openwrt0 | grep -oP "(?<=inet\s)\d+(\.\d+){3}"'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
# No IP address shall be found
|
||||
assert ('' in process.stdout) == True
|
||||
return
|
||||
|
||||
|
||||
case '' | 'host':
|
||||
response = run_openwrt_shell_command("ip", "addr", "add", "192.168.1.15/24", "dev", "br-lan")
|
||||
assert response['exitcode'] == 0
|
||||
|
||||
Reference in New Issue
Block a user