From 21856a773ac985a525583f025df58fe76c41c5aa Mon Sep 17 00:00:00 2001 From: Jordan Sokolic Date: Fri, 17 Apr 2020 16:10:59 +0300 Subject: [PATCH] rpi readme --- README.md | 14 ++++++-------- rpi.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 rpi.md diff --git a/README.md b/README.md index 838c6c6..18c89c8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# OpenWRT in Docker +# OpenWrt in Docker -Inspired by other projects that run `hostapd` in a Docker container. This goes one step further and boots a full network OS intended for embedded devices called [OpenWRT](https://openwrt.org/), so you can manage all aspects of your network from a user-friendly web UI. +Inspired by other projects that run `hostapd` in a Docker container. This goes one step further and boots a full network OS intended for embedded devices called [OpenWrt](https://openwrt.org/), so you can manage all aspects of your network from a user-friendly web UI. -I only tested this on x86_64, but it might work on ARM too with some minor tweaking. +For Raspberry Pi-specific build instructions, see [Building on Raspberry Pi](./rpi.md). ## Dependencies @@ -17,13 +17,13 @@ I only tested this on x86_64, but it might work on ARM too with some minor tweak ``` $ make build ``` -If you want additional OpenWRT packages to be present in the base image, add them to the Dockerfile. Otherwise you can install them with `opkg` after bringing up the container. +If you want additional OpenWrt packages to be present in the base image, add them to the Dockerfile. Otherwise you can install them with `opkg` after bringing up the container. A searchable package list is available on [openwrt.org](https://openwrt.org/packages/table/start). ## Configure -Initial configuration is performed using a config file, `openwrt.conf`. Values read from this file at runtime are used to generate OpenWRT format config files. +Initial configuration is performed using a config file, `openwrt.conf`. Values read from this file at runtime are used to generate OpenWrt format config files. To add or change the base configuration, modify the config templates in `etc/config/
.tpl`. @@ -58,10 +58,8 @@ This will delete the container and all associated Docker networks so you can sta ### Hairpinning -This took a couple of tries to get working. The most challenging issue was getting traffic from WLAN clients to reach each other. -In order for this to work, OpenWRT bridges all interfaces in the LAN zone and sets hairpin mode (aka [reflective relay](https://lwn.net/Articles/347344/)) on the WLAN interface, meaning packets arriving on that interface can be 'reflected' back out through the same interface. -OpenWRT is not able to set this mode from inside the container even with `NET_ADMIN` capabilities, so this must be done from the host. +In order for WLAN clients to see one another, OpenWrt bridges all interfaces in the LAN zone and sets hairpin mode (aka [reflective relay](https://lwn.net/Articles/347344/)) on the WLAN interface, meaning packets arriving on that interface can be 'reflected' back out through the same interface. `run.sh` tries to handle this, and prints a warning if it fails. diff --git a/rpi.md b/rpi.md new file mode 100644 index 0000000..5fd95c1 --- /dev/null +++ b/rpi.md @@ -0,0 +1,34 @@ +# Building on Raspberry Pi + +Turn your Pi into a pretty okay-ish travel router (or a very slow main router)! + +OpenWrt officially supports Raspberry Pi hardware if you want to run it as your OS. But running in a container brings many advantages, one of which is not having to re-flash your SD card. + +This has been tested on a Raspberry Pi Zero W running Raspbian Lite, but should work for other versions too. Just make sure you download the right image for your Pi version (refer to the notes in [build-rpi.sh](./build-rpi.sh)). + + +## IPv6 +By default Raspbian does not load the kernel module for IPv6 `iptables` on boot. + +Run `sudo modprobe ip6_tables` to load it immediately. + +To persist on reboot, run + + $ echo 'ip6_tables' | sudo tee /etc/modules-load.d/ip6-tables.conf + +--- +## Build +You can build the OpenWRT docker image on the Pi itself, or on your x86 PC with `qemu-arm` installed. + +First download and extract the OpenWRT factory image for your Pi. Refer to the [OpenWrt Table of Hardware](https://openwrt.org/toh/raspberry_pi_foundation/raspberry_pi) to choose the right image. Then run the `make` target. + +The variable `RPI_SOURCE_IMG` can be specified in openwrt.conf or on the command line: +``` +$ https://downloads.openwrt.org/releases/19.07.2/targets/brcm2708/bcm2708/openwrt-19.07.2-brcm2708-bcm2708-rpi-ext4-factory.img.gz +$ gzip -d openwrt-*.img.gz +$ make build-rpi RPI_SOURCE_IMG=openwrt-19.07.2-brcm2708-bcm2708-rpi-ext4-factory.img +``` + +If you built the image on your PC, send it to your Raspberry Pi (`$BUILD_TAG` is a config variable): +``` +$ docker save $BUILD_TAG | ssh docker load \ No newline at end of file