-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for containers connected to multiple networks
- In the container entrypoint: - Itemise network interfaces and save their configuration - Save any additional non-link-scope non-default routes to support networks with multiple subnets - Create a bridge to join each interface to a tap device in the VM - Restore network and gateway routes via each bridge - In the VM: - Identify each interface by MAC address and rename devices to match the original configuration in the underlying container - Restore device configuration and routes
- Loading branch information
Showing
8 changed files
with
204 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
#!/bin/bash | ||
|
||
RUNCVM=/opt/runcvm | ||
RUNCVM_PATH=$RUNCVM/usr/sbin:$RUNCVM/usr/bin:$RUNCVM/sbin:$RUNCVM/bin:$RUNCVM/usr/lib/qemu | ||
|
||
QEMU_IFUP="$RUNCVM/scripts/runcvm-ctr-qemu-ifup" | ||
QEMU_IFDOWN="$RUNCVM/scripts/runcvm-ctr-qemu-ifdown" | ||
QEMU_BRIDGE='q0' | ||
|
||
QEMU_VIRTIOFSD_SOCKET=/run/.virtiofs.sock | ||
QEMU_GUEST_AGENT=/run/.qemu-guest-agent | ||
QEMU_MONITOR_SOCKET=/run/.qemu-monitor-socket | ||
|
||
clean_env() { | ||
export -n \ | ||
RUNCVM_BREAK RUNCVM_INIT \ | ||
RUNCVM_RUNTIME_DEBUG RUNCVM_BIOS_DEBUG RUNCVM_KERNEL_DEBUG \ | ||
RUNCVM_KERNEL RUNCVM_KERNEL_ROOT RUNCVM_KERNEL_APPEND RUNCVM_KERNEL_INITRAMFS_PATH RUNCVM_KERNEL_PATH RUNCVM_DISKS \ | ||
RUNCVM_UIDGID RUNCVM_VM_MOUNTPOINT RUNCVM_TMPFS \ | ||
RUNCVM_CPUS RUNCVM_MEM_SIZE RUNCVM_HAS_HOME | ||
export -n \ | ||
RUNCVM_BREAK RUNCVM_INIT \ | ||
RUNCVM_RUNTIME_DEBUG RUNCVM_BIOS_DEBUG RUNCVM_KERNEL_DEBUG \ | ||
RUNCVM_KERNEL RUNCVM_KERNEL_ROOT RUNCVM_KERNEL_APPEND RUNCVM_KERNEL_INITRAMFS_PATH RUNCVM_KERNEL_PATH RUNCVM_DISKS \ | ||
RUNCVM_UIDGID RUNCVM_VM_MOUNTPOINT RUNCVM_TMPFS \ | ||
RUNCVM_CPUS RUNCVM_MEM_SIZE RUNCVM_HAS_HOME | ||
|
||
# May be set in VM by busybox init process | ||
export -n USER | ||
# May be set in VM by busybox init process | ||
export -n USER | ||
} | ||
|
||
load_network() { | ||
[ -s /.runcvm/network ] || return 1 | ||
read -r DOCKER_IF DOCKER_IF_MAC DOCKER_IF_MTU DOCKER_IF_IP DOCKER_IF_IP_NETPREFIX DOCKER_IF_IP_GW </.runcvm/network | ||
return 0 | ||
local if="${1:-default}" | ||
[ -d /.runcvm/network/devices ] && [ -s /.runcvm/network/devices/$if ] || return 1 | ||
read -r DOCKER_IF DOCKER_IF_MAC DOCKER_IF_MTU DOCKER_IF_IP DOCKER_IF_IP_NETPREFIX DOCKER_IF_IP_GW </.runcvm/network/devices/$if | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
cidr_to_int() { | ||
echo "$(( 0xffffffff ^ ((1 << (32 - $1)) - 1) ))" | ||
} | ||
|
||
int_to_ip() { | ||
local value="$1" | ||
echo "$(( ($1 >> 24) & 0xff )).$(( ($1 >> 16) & 0xff )).$(( ($1 >> 8) & 0xff )).$(( $1 & 0xff ))" | ||
} | ||
|
||
cidr_to_netmask() { | ||
local value=$(cidr_to_int "$1") | ||
int_to_ip "$value" | ||
} | ||
|
||
ip_prefix_to_network() { | ||
local IFS i1 i2 i3 i4 m1 m2 m3 m4 | ||
IFS=. read -r i1 i2 i3 i4 <<< "$1" | ||
|
||
local mask=$(cidr_to_netmask "$2") | ||
IFS=. read -r m1 m2 m3 m4 <<< "$mask" | ||
|
||
printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))" | ||
} | ||
|
||
cidr_to_bcastmask() { | ||
local value=$(( (1 << 32) - $(cidr_to_int "$1") - 1 )) | ||
int_to_ip "$value" | ||
} | ||
|
||
ip_prefix_to_bcast() { | ||
local IFS i1 i2 i3 i4 m1 m2 m3 m4 | ||
IFS=. read -r i1 i2 i3 i4 <<< "$1" | ||
|
||
local mask=$(cidr_to_bcastmask "$2") | ||
IFS=. read -r m1 m2 m3 m4 <<< "$mask" | ||
|
||
printf "%d.%d.%d.%d\n" "$((i1 | m1))" "$((i2 | m2))" "$((i3 | m3))" "$((i4 | m4))" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.