more changes for macvlan

pull/1/head
Jordan Sokolic 2020-02-16 09:01:20 +02:00
parent 62d03975d7
commit 34fbd5286f
2 changed files with 26 additions and 14 deletions

View File

@ -8,6 +8,10 @@ config 'interface' 'lan'
option 'type' 'bridge'
option 'ifname' 'eth0'
option 'proto' 'static'
option 'ipaddr' "${NET_ADDR}"
option 'gateway' "${NET_GW}"
option 'netmask' "${NET_NETMASK}"
option 'ipaddr' "${LAN_ADDR}"
option 'gateway' "${LAN_GW}"
option 'netmask' "${LAN_NETMASK}"
config 'interface' 'wan'
option 'ifname' 'eth1'
option 'proto' 'dhcp'

30
run.sh
View File

@ -21,6 +21,8 @@ function _cleanup {
echo -e "\n* cleaning up..."
echo "* stopping container"
docker stop openwrt_1 >/dev/null
echo "* deleting macvlan interface"
sudo ip link del macvlan0
echo -ne "* finished"
}
@ -30,8 +32,8 @@ function _gen_config {
source .env
_get_phy_from_dev
for file in etc/config/*.tpl; do
envsubst < ${file} > ${file%.tpl}.gen
docker cp ${file%.tpl}.gen $CONTAINER:/${file%.tpl}
envsubst < ${file} > ${file%.tpl}
docker cp ${file%.tpl} $CONTAINER:/${file%.tpl}
done
set +a
}
@ -39,15 +41,20 @@ function _gen_config {
function _init_network {
echo "* setting up docker network"
docker network create --driver macvlan \
-o parent=$NET_PARENT \
--gateway $NET_GW \
--subnet $NET_SUBNET \
$NET_NAME 2>/dev/null
-o parent=$LAN_PARENT \
--subnet $LAN_SUBNET \
--aux-address host=$LAN_HOST \
$LAN_NAME
sudo ip link add macvlan0 link $NET_PARENT type macvlan mode bridge
sudo ip addr add $NET_HOST/24 dev macvlan0
docker network create --driver macvlan \
-o parent=$WAN_PARENT \
--subnet $WAN_SUBNET \
$WAN_NAME
sudo ip link add macvlan0 link $LAN_PARENT type macvlan mode bridge
sudo ip addr add $LAN_HOST/24 dev macvlan0
sudo ip link set macvlan0 up
sudo ip route add $NET_ADDR/32 dev macvlan0
sudo ip route add $LAN_ADDR/32 dev macvlan0
}
function _create_or_start_container {
@ -58,11 +65,12 @@ function _create_or_start_container {
else
echo "* creating container $CONTAINER"
docker create \
--network $NET_NAME \
--network $LAN_NAME \
--cap-add NET_ADMIN \
--cap-add NET_RAW \
--hostname openwrt\
--name $CONTAINER openwrt >/dev/null
docker network connect $WAN_NAME $CONTAINER
_gen_config
docker start $CONTAINER
@ -76,7 +84,7 @@ function main {
echo "* setting interface '$WIFI_IFACE' to unmanaged"
nmcli dev set $WIFI_IFACE managed no
_init_network
_create_or_start_container